简体   繁体   中英

How To Disable The WordPress Theme Editor

I know how to disable the plugin/theme editor in a specific WordPress site.

My Question: Is it possible to disable the the editor from a theme's functions.php file?

The idea is to have this turned off by default whenever my theme is active; however, once a few warnings are accepted, the editor can be re-enabled via the theme options page. (something that WordPress should be doing but, for whatever reason, does not.)

Beyond that, the particular theme in question is pretty advanced. Meaning that even someone who knows what they are doing could mess it up without realizing it.

Nick, you can try with action to call a function in your functions.php to disable editor but wordpress did not provide any way to disable editor for theme only. If you use DISALLOW_FILE_EDIT than your plugin editor will also be disabled.

I feel you should try the below approach to disable editor from functions.php of your theme.

    function disable_mytheme_action() {
      define('DISALLOW_FILE_EDIT', TRUE);
    }
    add_action('init','disable_mytheme_action');

you can also define some options and check in above function and control the disable file edit accordingly.

A friend ended up answering this one for me, so for the googlers:

in functions.php :

if (in_array($GLOBALS['pagenow'], array('theme-editor.php'))) {
    if (get_option('theme_editor') != TRUE) {
        wp_die('<p>'.__('In order to edit this theme, you must first re-enable the theme editor via the <a href="'.theme::options_uri().'">Theme Options</a> page').'</p>');
    }
}

Just make sure you allow people to re-enable the theme editor via your Theme Options page. As silly as it sounds, some people actually really like it, and want it.

I ended up adding a very visible warning around re-enable button like so: JSFiddle

open your wp-config.php file add code

define( 'DISALLOW_FILE_EDIT', true );

OR try this extension

https://wordpress.org/plugins/disable-theme-and-plugin-editor/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM