forked from lukecav/code-snippets-wp-speed-up
-
Notifications
You must be signed in to change notification settings - Fork 0
/
customizer-remove-all.code-snippets.xml
142 lines (142 loc) · 5 KB
/
customizer-remove-all.code-snippets.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?xml version="1.0" encoding="UTF-8"?>
<!-- This is a code snippets export file generated by the Code Snippets WordPress plugin. -->
<!-- https://wordpress.org/plugins/code-snippets -->
<!-- To import these snippets a WordPress site follow these steps: -->
<!-- 1. Log in to that site as an administrator. -->
<!-- 2. Install the Code Snippets plugin using the directions provided at the above link. -->
<!-- 3. Go to 'Tools: Import' in the WordPress admin panel. -->
<!-- 4. Click on the "Code Snippets" importer in the list -->
<!-- 5. Upload this file using the form provided on that page. -->
<!-- 6. Code Snippets will then import all of the snippets and associated information contained in this file into your site. -->
<!-- 7. You will then have to visit the 'Snippets: All Snippets' admin menu and activate desired snippets. -->
<!-- generator="Code Snippets/2.8.6" created="2017-08-28 18:54" -->
<snippets>
<snippet scope="1">
<name>Customizer remove all</name>
<desc></desc>
<tags>remove, customizer, wordpress</tags>
<code>// Exit if accessed directly
if ( __FILE__ == $_SERVER['SCRIPT_FILENAME'] ) { exit; }
if (!class_exists('Customizer_Remove_All')) :
class Customizer_Remove_All {
/**
* @var Customizer_Remove_All
*/
private static $instance;
/**
* Main Instance
*
* Allows only one instance of Customizer_Remove_All in memory.
*
* @static
* @staticvar array $instance
* @return Big mama, Customizer_Remove_All
*/
public static function instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Customizer_Remove_All ) ) {
// Start your engines!
self::$instance = new Customizer_Remove_All;
// Load the structures to trigger initially
add_action( 'plugins_loaded', array( self::$instance, 'load_languages' ) );
add_action( 'init', array( self::$instance, 'init' ), 10 ); // was priority 5
add_action( 'admin_init', array( self::$instance, 'admin_init' ), 10 ); // was priority 5
}
return self::$instance;
}
/**
* Run all plugin stuff on init.
*
* @return void
*/
public function init() {
// Remove customize capability
add_filter( 'map_meta_cap', array( self::$instance, 'filter_to_remove_customize_capability'), 10, 4 );
}
/**
* Run all of our plugin stuff on admin init.
*
* @return void
*/
public function admin_init() {
// Drop some customizer actions
remove_action( 'plugins_loaded', '_wp_customize_include', 10);
remove_action( 'admin_enqueue_scripts', '_wp_customize_loader_settings', 11);
// Manually overrid Customizer behaviors
add_action( 'load-customize.php', array( self::$instance, 'override_load_customizer_action') );
}
/**
* Load our language files
*
* @access public
* @return void
*/
public function load_languages() {
// Set textdomain string
$textdomain = 'wp-crap';
// The 'plugin_locale' filter is also used by default in load_plugin_textdomain()
$locale = apply_filters( 'plugin_locale', get_locale(), $textdomain );
// Set filter for WordPress languages directory
$wp_languages_dir = apply_filters( 'crap_wp_languages_dir', WP_LANG_DIR . '/wp-crap/' . $textdomain . '-' . $locale . '.mo' );
// Translations: First, look in WordPress' "languages" folder
load_textdomain( $textdomain, $wp_languages_dir );
// Translations: Next, look in plugin's "languages" folder (default)
$plugin_dir = basename( dirname( __FILE__ ) );
$languages_dir = apply_filters( 'crap_languages_dir', $plugin_dir . '/languages' );
load_plugin_textdomain( $textdomain, FALSE, $languages_dir );
}
/**
* Remove customize capability
*
* This needs to be in public so the admin bar link for 'customize' is hidden.
*/
public function filter_to_remove_customize_capability( $caps = array(), $cap = '', $user_id = 0, $args = array() ) {
if ($cap == 'customize') {
return array('nope'); // thanks @ScreenfeedFr, http://bit.ly/1KbIdPg
}
return $caps;
}
/**
* Manually overriding specific Customizer behaviors
*/
public function override_load_customizer_action() {
// If accessed directly
wp_die( __( 'The Customizer is currently disabled.', 'wp-crap' ) );
}
} // End Class
endif;
/**
* The main function. Use like a global variable, except no need to declare the global.
*
* @return object The one true Customizer_Remove_All Instance
*/
function Customizer_Remove_All() {
return Customizer_Remove_All::instance();
}
// GO!
Customizer_Remove_All();</code>
</snippet>
</snippets>