2017-03-24 3 views
-1

저는 Wordpress 용 플러그인을 작성 중이며 게시물을 사용하고 있습니다. 기본적으로 대체 게시물 편집 페이지를 만들었습니다. 그게 문제 야 :wp_editor가 프런트 엔드에서 작동하지 않습니다.

항상 새 게시물 wp_editor 작업을 쓸 페이지를로드 할 때 게시물을 편집 할 때 헤더를 사용하면 내용이 흰색으로 표시되고 게시물이 사라집니다. 이로 인해 텍스트를 읽을 수 없게됩니다. 이다 남아

유일한 한 가지 일을 does't 버튼 ..

내 코드는 매우 간단하고 그렇게 나쁜 일을 왜 이해가 안 돼요 "미디어 추가".

public static function showNewTemplatePanel(){ 
    if (!current_user_can('manage_options')) { 
    wp_die(__('You cannot view this page')); 
    } 
    $template_id = null; 

    // Check if the user posted some data 
    echo '<div class="wrap">'; 

    if (isset($_POST['posted_data']) && $_POST['posted_data'] == 'Y'){ 
    $template = new CMS_Template(); 

    if (is_numeric($_POST['template_id']) && $_POST['template_id'] > 0) 
     $template = new CMS_Template($_POST['template_id']); 

    $template->template_name = $_POST['template_name']; 
    $template->template_content = $_POST['cms_template_editor']; 
    $template->template_role = $_POST['role']; 
    $template->template_subject = $_POST['template_subject']; 

    $return = $template->save(); 

    if (!$return || is_wp_error($return)) { 
     echo "<h1>Errore durante il salvataggio, ". $return ."</h1>"; 
     if (is_wp_error($return)) { 
     echo '<div class="error">'.$return->get_error_message()."</div>"; 
     } 
    } else { 
     echo "<h1>Template salvato correttamente!</h1>"; 
     $template_id = $return; 
    } 
    } 

    if (isset($_GET['template']) && is_numeric($_GET['template'])){ 
    $template_id = intval($_GET['template']); 
    } 

    if ($template_id != null) { 
    ?> 
    <h1>Edit Template</h1> 
    <?php 
    } else { 
    ?> 
    <h1>New Template</h1> 
     <ul> 
     <li> 

     </li> 
     </ul> 
    </p> 
    <?php 
    } 
    CMS::showTemplateEditor($template_id); 
    echo '</div>'; 
} 

CMS :: showTemplateEditor() 함수

public static function showTemplateEditor($id = null){ 
    $template = new CMS_Template($id); 
    ?> 
    <form name="form-1" method="post" action=""> 
    <input type="hidden" name="posted_data" value="Y"> 
    <input type="hidden" name="template_id" value="<?php echo $template->ID; ?>"> 
    <table class="form-table"> 
     <tr class="form-field form-required"> 
     <th scope="row"> 
      <label for="template_name">Template Name</label> 
     </th> 
     <td> 
      <input type="text" name="template_name" value="<?php echo $template->template_name; ?>"/> 
     </td> 
     </tr> 
     <tr class="form-field form-required"> 
     <th scope="row"> 
      <label for="template_role">Assigned Role</label> 
     </th> 
     <td> 
      <select name="role" id="role"> 
      <?php wp_dropdown_roles($template->template_role); ?> 
      </select> 
     </td> 
     </tr> 
     <tr class="form-field form-required"> 
     <th scope="row"> 
      <label for="template_name">Subject</label> 
     </th> 
     <td> 
      <input type="text" name="template_subject" value="<?php echo $template->template_subject; ?>"/> 
     </td> 
     </tr> 
     <tr class="form-field form-required"> 
     <th scope="row"> 
      <label for="template_name">Template Body</label> 
     </th> 
     <td> 
      <?php wp_editor($template->template_content, 'cms_template_editor' ); ?> 
     </td> 
     </tr> 
    </table> 
    <p class="submit"> 
     <input type="submit" class="button button-primary" value="Save"/> 
    </p> 
    </form> 
    <?php 
} 

CMS_Template 클래스

class CMS_Template { 
public $ID; 
public $template_name; 
public $template_role; 
public $template_subject; 
public $template_content; 

const ROLE_META = 'CMS_TEMPLATE_ROLE_META'; 
const SUBJECT_META = 'CMS_TEMPLATE_SUBJECT_META'; 

function __construct($id = null){ 
    $this->ID = 0; 
    $this->template_name = ""; 
    $this->template_role = get_editable_roles()[0]['name']; 
    $this->template_subject = ""; 
    $this->template_content = ""; 

    if ($id != null && is_numeric($id) && $id > 0) { 
    $this->load($id); 
    } 
} 

public function save(){ 

    if (trim($this->template_name) == "") 
    return false; 

    if (trim($this->template_content) == "") 
    return false; 

    $return = wp_insert_post(array(
    'ID'    => $this->ID, 
    'post_author'  => get_current_user_id(), 
    'post_content' => $this->template_content, 
    'post_title'  => $this->template_name, 
    'post_type'  => CMS::CMS_POST_TYPE, 
    'meta_input'  => array(ROLE_META  => $this->template_role, 
           SUBJECT_META => $this->template_subject), 
    'post_status'  => 'publish' 
)); 

    return $return; 
} 

public function load($id = null){ 
    if ($id != null && is_numeric($id) && $id > 0) { 
    $post = get_post($id); 
    if ($post != null && $post->post_type == CMS::CMS_POST_TYPE){ 
     $this->ID = $id; 
     $this->template_name = $post->post_title; 
     $this->template_content = $post->post_content; 
     $this->template_role = get_post_meta($post->ID, ROLE_META, true); 
     $this->template_subject = get_post_meta($post->ID, SUBJECT_META, true); 
    } 
    } 
} 

}

답변

0

내가 찾은 문제 : 여기에 코드 조각입니다.

다른 파일 인 CMS_List_Table.php가 있습니다. 벌크 함수 핸들러에서 이런

if('edit'===$this->current_action()) { 
    CMS::showNewTemplatePanel(); 
} 

if('edit'===$this->current_action()) { 
    CMS::showNewTemplatePanel(); 
    wp_die(); 
} 

변경