Last active
September 14, 2024 02:54
-
-
Save doiftrue/6d8f975ed8af5ac325b6d9a1c52abf1c to your computer and use it in GitHub Desktop.
[wp-kama embed] https://wp-kama.com/2600 Disable WP Customizer. Original code see here: https://wordpress.org/plugins/customizer-disabler/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Plugin name: Disable Customizer | |
* Description: Completely turn off customizer on your site. | |
* | |
* Plugin URI: https://gist.github.com/doiftrue/6d8f975ed8af5ac325b6d9a1c52abf1c | |
* Author URI: https://wp-kama.com | |
* Author: Timur Kamaev | |
* Note: This is a fork of https://wordpress.org/plugins/customizer-disabler/ (v2.2.7) | |
* Source Author: Johannes Siipola | |
* Source Author URI: https://siipo.la | |
* | |
* Version: 2.3.0 | |
*/ | |
defined( 'ABSPATH' ) || exit; | |
Disable_WP_Customizer::init(); | |
class Disable_WP_Customizer { | |
public static function init(): void { | |
add_filter( 'map_meta_cap', [ __CLASS__, 'map_meta_cap__remove_customize_capability' ], 10, 2 ); | |
add_action( 'admin_init', [ __CLASS__, 'on_admin_init' ], 10 ); | |
} | |
public static function on_admin_init(): void { | |
remove_action( 'plugins_loaded', '_wp_customize_include', 10 ); | |
remove_action( 'admin_enqueue_scripts', '_wp_customize_loader_settings', 11 ); | |
add_action( 'load-customize.php', [ __CLASS__, 'on_load_customizer', ] ); | |
} | |
public static function map_meta_cap__remove_customize_capability( $caps, $cap ) { | |
return ( $cap === 'customize' ) ? [ 'do_not_allow' ] : $caps; | |
} | |
public static function on_load_customizer(): void { | |
/** @noinspection ForgottenDebugOutputInspection */ | |
wp_die( 'The Customizer is currently disabled.' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment