dartmoon/wordpress-disable-editor

禁用特定模板、页面、帖子等编辑器。

v1.1.4 2023-08-18 10:01 UTC

This package is auto-updated.

Last update: 2024-09-18 12:44:18 UTC


README

此插件允许您禁用某些CPTs、模板或特定页面的编辑器。

安装

如果您使用Roots Bedrock或基于Composer的WordPress安装

composer require dartmoon/wordpress-disable-editor

如果您使用常规WordPress安装

  1. 下载并安装一个MU插件加载器,让您可以使用位于文件夹中的MU插件。例如,您可以使用Bedrock Autoloader

  2. 下载此插件的最新版本并将其提取到您的WordPress安装的mu-plugins文件夹中。

使用方法

禁用Gutenberg

add_filter('drtn/disable_gutenberg', function ($can_edit, $post_id, $post_type) {
    /**
     * Post types for which to enable Gutenberg
     */
    if ($post_type == 'post') {
        return true;
    }

    /**
     * Templates for which we need to disable Gutemberg
     */
    $excludedTemplates = [
        // 
    ];

    /**
     * Specific Post IDs for which we need to disable Gutenberg
     */
    $excludedIds = [
        //
    ];

    // Retrieve the template of the current post id
    $template = basename(get_page_template());
    return !(in_array($post_id, $excludedIds) || in_array($template, $excludedTemplates));
}, 10, 3);

禁用经典编辑器

add_filter('drtn/disable_editor', function ($can_edit, $post_id, $post_type) {
    /**
     * Post types for which to enable the classic editor
     */
    if ($post_type == 'post') {
        return true;
    }

    /**
     * Templates for which we need to disable the classic editor
     */
    $excludedTemplates = [
        // 
    ];

    /**
     * Specific Post IDs for which we need to disable the classic editor
     */
    $excludedIds = [
        //
    ];

    // Retrieve the template of the current post id
    $template = basename(get_page_template());
    return !(in_array($post_id, $excludedIds) || in_array($template, $excludedTemplates));
}, 10, 3);

许可证

本项目采用MIT许可证 - 请参阅LICENSE.md文件以获取详细信息