Ограничить редактор Гутенберга для пользовательских типов записей WordPress - PullRequest
0 голосов
/ 17 октября 2018

Мне нужно создать свой собственный тип поста, и я хочу ограничить редактор Гутенберга для моего типа поста (только) и использовать редактор WordPress в этом типе поста.Как можно ограничить этот плагин для моего cpt?

спасибо

Ответы [ 3 ]

0 голосов
/ 17 октября 2018

Вы можете сделать это с помощью плагина или пользовательского кода.

  1. Плагин Отключить Гутенберг

  2. Код, добавьте егок functions.php

function mh_disable_gutenberg($is_enabled, $post_type) {

  if ($post_type === 'news') return false; // change news to your post type

  return $is_enabled;

}
add_filter('gutenberg_can_edit_post_type', 'mh_disable_gutenberg', 10, 2);
0 голосов
/ 15 января 2019

Для тех, кто находит этот вопрос после выхода WordPress 5.0, вы можете отключить Редактор блоков (fka Gutenberg) для определенных типов записей, используя фильтр use_block_editor_for_post_type , например, так:

add_filter('use_block_editor_for_post_type', function( $useBlockEditor, $postType ){

    if( $postType == 'your-custom-post-type-slug' )
        return false;
    return $useBlockEditor;

}, 10, 2);
0 голосов
/ 17 октября 2018

Вы можете использовать фильтр, чтобы отключить Gutenberg для всех типов сообщений, за исключением вашего пользовательского имени типа сообщения.

/**
 * Disabling the Gutenberg editor all post types except post.
 *
 * @param bool   $can_edit  Whether to use the Gutenberg editor.
 * @param string $post_type Name of WordPress post type.
 * @return bool  $can_edit
 */
function gutenberg_can_edit_post_type_83744857( $can_edit, $post_type ) {
    $gutenberg_supported_types = array( 'post' ); //Change this to you custom post type
    if ( ! in_array( $post_type, $gutenberg_supported_types, true ) ) {
        $can_edit = false;
    }
    return $can_edit;
}
add_filter( 'gutenberg_can_edit_post_type', 'gutenberg_can_edit_post_type_83744857', 10, 2 );
...