| @@ -36,9 +36,9 @@ | ||
| 36 | 36 | |
| 37 | 37 | public $slug; |
| 38 | 38 | public $version; |
| 39 | 39 | |
| 40 | - private $plugin_config = null; | |
| 40 | + private $plugin_config = array(); | |
| 41 | 41 | |
| 42 | 42 | protected function __construct( $file, $slug, $version = '1.0.0' ) { |
| 43 | 43 | $this->file = $file; |
| 44 | 44 | $this->slug = $slug; |
| @@ -45,11 +45,12 @@ | ||
| 45 | 45 | $this->version = $version; |
| 46 | 46 | |
| 47 | 47 | require plugin_dir_path( $this->file ) . 'includes/admin-settings/core/bootstrap.php'; |
| 48 | 48 | |
| 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' ); | |
| 49 | + // Load the config file | |
| 50 | + $this->plugin_config = self::get_plugin_config(); | |
| 51 | + // Load the plugin's settings from the DB | |
| 52 | + $this->plugin_settings = get_option( $this->plugin_config['settings-key'] ); | |
| 52 | 53 | |
| 53 | 54 | // Register all the needed hooks |
| 54 | 55 | $this->register_hooks(); |
| 55 | 56 | } |
| @@ -54,23 +55,8 @@ | ||
| 54 | 55 | $this->register_hooks(); |
| 55 | 56 | } |
| 56 | 57 | |
| 57 | 58 | /** |
| 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 | 59 | * Register our actions and filters |
| 74 | 60 | */ |
| 75 | 61 | function register_hooks() { |
| 76 | 62 | |
| @@ -104,24 +90,8 @@ | ||
| 104 | 90 | /** |
| 105 | 91 | * Render the settings page for this plugin. |
| 106 | 92 | */ |
| 107 | 93 | 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 | 94 | include_once plugin_dir_path( $this->file ) . 'includes/admin-settings/views/admin.php'; |
| 125 | 95 | } |
| 126 | 96 | |
| 127 | 97 | /** |
| @@ -152,13 +122,11 @@ | ||
| 152 | 122 | $screen = get_current_screen(); |
| 153 | 123 | if ( $screen->id == $this->plugin_screen_hook_suffix ) { |
| 154 | 124 | $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
| 155 | 125 | |
| 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 ); | |
| 126 | + wp_enqueue_script( $this->slug . '-settings-page-script', | |
| 127 | + plugins_url( 'js/settings-page' . $suffix . '.js', $this->file ), | |
| 128 | + array( 'jquery' ), $this->version ); | |
| 161 | 129 | |
| 162 | 130 | wp_add_inline_script( $this->slug . '-settings-page-script', |
| 163 | 131 | PixCustomify_Customizer::getlocalizeToWindowScript( 'customify', |
| 164 | 132 | array( |
| @@ -219,20 +187,14 @@ | ||
| 219 | 187 | |
| 220 | 188 | private function get_nonce() { |
| 221 | 189 | $nonce = null; |
| 222 | 190 | |
| 223 | - // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This helper reads the nonce value that permission_nonce_callback() verifies. | |
| 224 | 191 | 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'] ) ); | |
| 192 | + $nonce = wp_unslash( $_REQUEST['customify_settings_nonce'] ); | |
| 193 | + } elseif ( isset( $_POST['customify_settings_nonce'] ) ) { | |
| 194 | + $nonce = wp_unslash( $_POST['customify_settings_nonce'] ); | |
| 227 | 195 | } |
| 228 | 196 | |
| 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 | 197 | return $nonce; |
| 236 | 198 | } |
| 237 | 199 | |
| 238 | 200 | static public function get_plugin_config() { |
| @@ -237,10 +199,9 @@ | ||
| 237 | 199 | |
| 238 | 200 | static public function get_plugin_config() { |
| 239 | 201 | |
| 240 | 202 | $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'] ) ) ) { | |
| 203 | + if ( isset( $_GET['debug'] ) && $_GET['debug'] === 'true' ) { | |
| 243 | 204 | $debug = true; |
| 244 | 205 | } |
| 245 | 206 | |
| 246 | 207 | return array( |
| @@ -342,12 +303,12 @@ | ||
| 342 | 303 | |
| 343 | 304 | 'typography_group' => array( |
| 344 | 305 | 'type' => 'group', |
| 345 | 306 | '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' ), | |
| 307 | + 'typography_standard_fonts' => array( | |
| 308 | + 'name' => 'typography_standard_fonts', | |
| 309 | + 'label' => esc_html__( 'Use Standard fonts', 'customify' ), | |
| 310 | + 'desc' => esc_html__( 'Would you like to use system fonts?', 'customify' ), | |
| 350 | 311 | 'default' => true, |
| 351 | 312 | 'type' => 'switch', |
| 352 | 313 | ), |
| 353 | 314 | 'typography_google_fonts' => array( |
| @@ -352,9 +313,9 @@ | ||
| 352 | 313 | ), |
| 353 | 314 | 'typography_google_fonts' => array( |
| 354 | 315 | 'name' => 'typography_google_fonts', |
| 355 | 316 | 'label' => esc_html__( 'Use Google fonts:', 'customify' ), |
| 356 | - 'desc' => esc_html__( 'Would you like to have Google fonts available in the font controls?', 'customify' ), | |
| 317 | + 'desc' => esc_html__( 'Would you like to use Google fonts?', 'customify' ), | |
| 357 | 318 | 'default' => true, |
| 358 | 319 | 'type' => 'switch', |
| 359 | 320 | 'show_group' => 'typography_google_fonts_group', |
| 360 | 321 | 'display_option' => true, |
| @@ -362,11 +323,11 @@ | ||
| 362 | 323 | 'typography_google_fonts_group' => array( |
| 363 | 324 | 'type' => 'group', |
| 364 | 325 | 'options' => array( |
| 365 | 326 | 'typography_group_google_fonts' => array( |
| 366 | - 'name' => 'typography_group_google_fonts', | |
| 327 | + 'name' => 'typography_standard_fonts', | |
| 367 | 328 | 'label' => esc_html__( 'Group Google fonts:', 'customify' ), |
| 368 | - 'desc' => esc_html__( 'You can chose to see the Google fonts in groups', 'customify' ), | |
| 329 | + 'desc' => esc_html__( 'You can chose to see the google fonts in groups', 'customify' ), | |
| 369 | 330 | 'default' => true, |
| 370 | 331 | 'type' => 'switch', |
| 371 | 332 | ), |
| 372 | 333 | ), |
| @@ -372,10 +333,10 @@ | ||
| 372 | 333 | ), |
| 373 | 334 | ), |
| 374 | 335 | 'typography_cloud_fonts' => array( |
| 375 | 336 | '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' ), | |
| 337 | + 'label' => esc_html__( 'Use Cloud fonts', 'customify' ), | |
| 338 | + 'desc' => esc_html__( 'Would you to use Cloud fonts?', 'customify' ), | |
| 378 | 339 | 'default' => true, |
| 379 | 340 | 'type' => 'switch', |
| 380 | 341 | 'display_option' => true, |
| 381 | 342 | ), |
| @@ -431,12 +392,11 @@ | ||
| 431 | 392 | * |
| 432 | 393 | * @return bool|null |
| 433 | 394 | */ |
| 434 | 395 | public function get_config_option( $option, $default = null ) { |
| 435 | - $config = $this->get_lazy_plugin_config(); | |
| 436 | 396 | |
| 437 | - if ( isset( $config[ $option ] ) ) { | |
| 438 | - return $config[ $option ]; | |
| 397 | + if ( isset( $this->plugin_config[ $option ] ) ) { | |
| 398 | + return $this->plugin_config[ $option ]; | |
| 439 | 399 | } elseif ( $default !== null ) { |
| 440 | 400 | return $default; |
| 441 | 401 | } |
| 442 | 402 | |