可以在wordpress后端的某些页面模板上禁用内容编辑器吗?

Cla*_*ire 3 wordpress

我正在使用wordpress的高级自定义字段插件,这意味着我的一些页面中已经存在已停用的内容编辑器,因此我想在某些页面上禁用它们.我发现下面的一些网站的代码,但是这在后台创建了一个错误Undefined index: post,并Undefined index: post_ID

add_action( 'admin_init', 'hide_editor' );

function hide_editor() {
    // Get the Post ID.
    $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
    if( !isset( $post_id ) ) return;

    // Get the name of the Page Template file.
    $template_file = get_post_meta($post_id, '_wp_page_template', true);

    if($template_file == 'contact.php'){ // edit the template name
        remove_post_type_support('page', 'editor');
    }
}
Run Code Online (Sandbox Code Playgroud)

Nas*_*qan 7

使用PHP函数isset()来修复此错误:

add_action( 'admin_init', 'hide_editor' );

function hide_editor() {

        // Get the Post ID.
        if ( isset ( $_GET['post'] ) )
        $post_id = $_GET['post'];
        else if ( isset ( $_POST['post_ID'] ) )
        $post_id = $_POST['post_ID'];

    if( !isset ( $post_id ) || empty ( $post_id ) )
        return;

    // Get the name of the Page Template file.
    $template_file = get_post_meta($post_id, '_wp_page_template', true);

    if($template_file == 'contact.php'){ // edit the template name
        remove_post_type_support('page', 'editor');
    }

}
Run Code Online (Sandbox Code Playgroud)