質問

We have the following code that is used to hide our core theme so that it can't be enabled directly and you can only enable the child themes from the WordPress Dashboard.

function hide_core_theme($themes) {
    unset($themes['nacore']);
    return $themes;
}
add_action('wp_prepare_themes_for_js', 'hide_core_theme');

However if you put this code inside the functions.php file of either the Parent or Child theme it will only hide the core theme when one of them is enabled... e.g. if someone was to turn on another theme the core theme would appear again.

Another option is to add this code inside a custom plugin... but it means having it enabled and a user could always disable this plugin to get around it... plus we're not too keen on having a plugin to turn off a theme as it feels pretty detached.

Is it possible to add some hooks that are outside of a Theme or Plugin? And therefore are called regardless of what themes or plugins are enabled?

役に立ちましたか?

解決

You want a "Must Use Plugin". Any PHP files placed in wp-content/mu-plugins will be run automatically, and can only be 'deactivated' by removing the file.

ライセンス: CC-BY-SA帰属
所属していません wordpress.stackexchange
scroll top