PluginProbe
Customify / 2.5.1
Customify v2.5.1
2.10.9 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.7.1 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.6.0 1.6.0.1 1.6.5 1.7.0 1.7.1 All 77 releases
← All changes | includes/class-customify-settings.php +30 -95 2.10.9 → 2.5.1 View file →
@@ -24,8 +24,10 @@
24 24 * @var string
25 25 */
26 26 protected $plugin_screen_hook_suffix = null;
27 27
28 + public $display_admin_menu = false;
29 +
28 30 public $plugin_settings;
29 31
30 32 /**
31 33 * The main plugin file.
@@ -36,9 +38,9 @@
36 38
37 39 public $slug;
38 40 public $version;
39 41
40 - private $plugin_config = null;
42 + private $plugin_config = array();
41 43
42 44 protected function __construct( $file, $slug, $version = '1.0.0' ) {
43 45 $this->file = $file;
44 46 $this->slug = $slug;
@@ -45,11 +47,12 @@
45 47 $this->version = $version;
46 48
47 49 require plugin_dir_path( $this->file ) . 'includes/admin-settings/core/bootstrap.php';
48 50
49 - // Load the plugin's settings from the DB.
50 - // We use the settings key directly to avoid loading the full config (which has translation calls) too early.
51 - $this->plugin_settings = get_option( 'pixcustomify_settings' );
51 + // Load the config file
52 + $this->plugin_config = self::get_plugin_config();
53 + // Load the plugin's settings from the DB
54 + $this->plugin_settings = get_option( $this->plugin_config['settings-key'] );
52 55
53 56 // Register all the needed hooks
54 57 $this->register_hooks();
55 58 }
@@ -54,23 +57,8 @@
54 57 $this->register_hooks();
55 58 }
56 59
57 60 /**
58 - * Get the plugin config, loading it on first access.
59 - *
60 - * This lazy-loads the config to avoid calling translation functions before the textdomain is loaded.
61 - *
62 - * @return array
63 - */
64 - private function get_lazy_plugin_config() {
65 - if ( null === $this->plugin_config ) {
66 - $this->plugin_config = self::get_plugin_config();
67 - }
68 -
69 - return $this->plugin_config;
70 - }
71 -
72 - /**
73 61 * Register our actions and filters
74 62 */
75 63 function register_hooks() {
76 64
@@ -104,24 +92,8 @@
104 92 /**
105 93 * Render the settings page for this plugin.
106 94 */
107 95 function display_plugin_admin_page() {
108 - // Check the nonce, in case the form was submitted.
109 - if ( isset( $_SERVER['REQUEST_METHOD'] ) && 'POST' === sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) ) {
110 - check_admin_referer( 'customify_settings_save', '_wpnonce-customify-settings' );
111 - }
112 -
113 - $config = Customify_Settings::get_plugin_config();
114 -
115 - // Invoke the processor.
116 - /**
117 - * @var PixCustomifyProcessorImpl $processor
118 - */
119 - $processor = pixcustomify::processor( $config );
120 - $status = $processor->status();
121 - $errors = $processor->errors();
122 -
123 - // Do the saving and display the form.
124 96 include_once plugin_dir_path( $this->file ) . 'includes/admin-settings/views/admin.php';
125 97 }
126 98
127 99 /**
@@ -134,10 +106,9 @@
134 106 }
135 107
136 108 $screen = get_current_screen();
137 109 if ( $screen->id === $this->plugin_screen_hook_suffix ) {
138 - $rtl_suffix = is_rtl() ? '-rtl' : '';
139 - wp_enqueue_style( $this->slug . '-admin-styles', plugins_url( 'css/admin' . $rtl_suffix . '.css', $this->file ), array(), $this->version );
110 + wp_enqueue_style( $this->slug . '-admin-styles', plugins_url( 'css/admin.css', $this->file ), array(), $this->version );
140 111 }
141 112 }
142 113
143 114 /**
@@ -150,29 +121,17 @@
150 121 }
151 122
152 123 $screen = get_current_screen();
153 124 if ( $screen->id == $this->plugin_screen_hook_suffix ) {
154 - $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
155 -
156 - wp_enqueue_script( $this->slug . '-settings-page-script',
157 - plugins_url( 'js/settings-page' . $suffix . '.js', $this->file ),
158 - array( 'jquery' ),
159 - $this->version,
160 - false );
161 -
162 - wp_add_inline_script( $this->slug . '-settings-page-script',
163 - PixCustomify_Customizer::getlocalizeToWindowScript( 'customify',
164 - array(
165 - 'config' => array(
166 - 'ajax_url' => admin_url( 'admin-ajax.php' ),
167 - 'wp_rest' => array(
168 - 'root' => esc_url_raw( rest_url() ),
169 - 'nonce' => wp_create_nonce( 'wp_rest' ),
170 - 'customify_settings_nonce' => wp_create_nonce( 'customify_settings_nonce' )
171 - ),
172 - )
173 - )
174 - ) );
125 + wp_enqueue_script( $this->slug . '-admin-script', plugins_url( 'js/admin.js', $this->file ), array( 'jquery' ), $this->version );
126 + wp_localize_script( $this->slug . '-admin-script', 'customify_settings', array(
127 + 'ajax_url' => admin_url( 'admin-ajax.php' ),
128 + 'wp_rest' => array(
129 + 'root' => esc_url_raw( rest_url() ),
130 + 'nonce' => wp_create_nonce( 'wp_rest' ),
131 + 'customify_settings_nonce' => wp_create_nonce( 'customify_settings_nonce' )
132 + ),
133 + ) );
175 134 }
176 135
177 136 wp_localize_script( $this->slug . '-customizer-scripts', 'WP_API_Settings', array(
178 137 'root' => esc_url_raw( rest_url() ),
@@ -207,10 +166,8 @@
207 166 }
208 167
209 168 remove_theme_mod( $key );
210 169
211 - PixCustomifyPlugin()->invalidate_all_caches();
212 -
213 170 wp_send_json_success('Deleted ' . $key . ' theme mod!');
214 171 }
215 172
216 173 public function permission_nonce_callback() {
@@ -219,20 +176,14 @@
219 176
220 177 private function get_nonce() {
221 178 $nonce = null;
222 179
223 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This helper reads the nonce value that permission_nonce_callback() verifies.
224 180 if ( isset( $_REQUEST['customify_settings_nonce'] ) ) {
225 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This helper reads the nonce value that permission_nonce_callback() verifies.
226 - $nonce = sanitize_text_field( wp_unslash( $_REQUEST['customify_settings_nonce'] ) );
181 + $nonce = wp_unslash( $_REQUEST['customify_settings_nonce'] );
182 + } elseif ( isset( $_POST['customify_settings_nonce'] ) ) {
183 + $nonce = wp_unslash( $_POST['customify_settings_nonce'] );
227 184 }
228 185
229 - // phpcs:ignore WordPress.Security.NonceVerification.Missing -- This helper reads the nonce value that permission_nonce_callback() verifies.
230 - if ( null === $nonce && isset( $_POST['customify_settings_nonce'] ) ) {
231 - // phpcs:ignore WordPress.Security.NonceVerification.Missing -- This helper reads the nonce value that permission_nonce_callback() verifies.
232 - $nonce = sanitize_text_field( wp_unslash( $_POST['customify_settings_nonce'] ) );
233 - }
234 -
235 186 return $nonce;
236 187 }
237 188
238 189 static public function get_plugin_config() {
@@ -237,10 +188,9 @@
237 188
238 189 static public function get_plugin_config() {
239 190
240 191 $debug = false;
241 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only debug flag for rendering the settings config.
242 - if ( isset( $_GET['debug'] ) && 'true' === sanitize_text_field( wp_unslash( $_GET['debug'] ) ) ) {
192 + if ( isset( $_GET['debug'] ) && $_GET['debug'] === 'true' ) {
243 193 $debug = true;
244 194 }
245 195
246 196 return array(
@@ -342,12 +292,12 @@
342 292
343 293 'typography_group' => array(
344 294 'type' => 'group',
345 295 'options' => array(
346 - 'typography_system_fonts' => array(
347 - 'name' => 'typography_system_fonts',
348 - 'label' => esc_html__( 'Use system fonts', 'customify' ),
349 - 'desc' => esc_html__( 'Would you like to have system fonts available in the font controls?', 'customify' ),
296 + 'typography_standard_fonts' => array(
297 + 'name' => 'typography_standard_fonts',
298 + 'label' => esc_html__( 'Use Standard fonts:', 'customify' ),
299 + 'desc' => esc_html__( 'Would you like them?', 'customify' ),
350 300 'default' => true,
351 301 'type' => 'switch',
352 302 ),
353 303 'typography_google_fonts' => array(
@@ -352,9 +302,9 @@
352 302 ),
353 303 'typography_google_fonts' => array(
354 304 'name' => 'typography_google_fonts',
355 305 'label' => esc_html__( 'Use Google fonts:', 'customify' ),
356 - 'desc' => esc_html__( 'Would you like to have Google fonts available in the font controls?', 'customify' ),
306 + 'desc' => esc_html__( 'Would you like them?', 'customify' ),
357 307 'default' => true,
358 308 'type' => 'switch',
359 309 'show_group' => 'typography_google_fonts_group',
360 310 'display_option' => true,
@@ -362,24 +312,16 @@
362 312 'typography_google_fonts_group' => array(
363 313 'type' => 'group',
364 314 'options' => array(
365 315 'typography_group_google_fonts' => array(
366 - 'name' => 'typography_group_google_fonts',
316 + 'name' => 'typography_standard_fonts',
367 317 'label' => esc_html__( 'Group Google fonts:', 'customify' ),
368 - 'desc' => esc_html__( 'You can chose to see the Google fonts in groups', 'customify' ),
318 + 'desc' => esc_html__( 'You can chose to see the google fonts in groups', 'customify' ),
369 319 'default' => true,
370 320 'type' => 'switch',
371 321 ),
372 322 ),
373 323 ),
374 - 'typography_cloud_fonts' => array(
375 - 'name' => 'typography_cloud_fonts',
376 - 'label' => esc_html__( 'Use cloud fonts', 'customify' ),
377 - 'desc' => esc_html__( 'Would you to have Cloud fonts available in the font controls?', 'customify' ),
378 - 'default' => true,
379 - 'type' => 'switch',
380 - 'display_option' => true,
381 - ),
382 324 ),
383 325 ),
384 326 ),
385 327 ),
@@ -394,11 +336,8 @@
394 336 ),
395 337 ),
396 338 ),
397 339 ),
398 - 'callbacks' => array(
399 - 'invalidate_caches' => 'pixcustomify_cache_invalidate_cache',
400 - ),
401 340 'processor' => array(
402 341 // callback signature: (array $input, customifyProcessor $processor)
403 342 'preupdate' => array(
404 343 // callbacks to run before update process
@@ -403,11 +342,8 @@
403 342 'preupdate' => array(
404 343 // callbacks to run before update process
405 344 // cleanup and validation has been performed on data
406 345 ),
407 - 'postupdate' => array(
408 - 'invalidate_caches'
409 - ),
410 346 ),
411 347 'cleanup' => array(
412 348 'switch' => array( 'switch_not_available' ),
413 349 ),
@@ -431,12 +367,11 @@
431 367 *
432 368 * @return bool|null
433 369 */
434 370 public function get_config_option( $option, $default = null ) {
435 - $config = $this->get_lazy_plugin_config();
436 371
437 - if ( isset( $config[ $option ] ) ) {
438 - return $config[ $option ];
372 + if ( isset( $this->plugin_config[ $option ] ) ) {
373 + return $this->plugin_config[ $option ];
439 374 } elseif ( $default !== null ) {
440 375 return $default;
441 376 }
442 377