| @@ -39,22 +39,8 @@ | ||
| 39 | 39 | */ |
| 40 | 40 | protected $defined_constants; |
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | - * Holds config args for WPConfigTransformer. | |
| 44 | - * | |
| 45 | - * @var array | |
| 46 | - */ | |
| 47 | - protected static $config_args; | |
| 48 | - | |
| 49 | - /** | |
| 50 | - * Holds nonce. | |
| 51 | - * | |
| 52 | - * @var $nonce | |
| 53 | - */ | |
| 54 | - protected static $nonce; | |
| 55 | - | |
| 56 | - /** | |
| 57 | 43 | * Constructor. |
| 58 | 44 | * |
| 59 | 45 | * @param array $options Plugin options. |
| 60 | 46 | * @param string $config_path Path to config file. |
| @@ -64,22 +50,8 @@ | ||
| 64 | 50 | public function __construct( $options, $config_path, $defined_constants ) { |
| 65 | 51 | self::$options = $options; |
| 66 | 52 | self::$config_path = $config_path; |
| 67 | 53 | $this->defined_constants = $defined_constants; |
| 68 | - self::$config_args = [ 'normalize' => true ]; | |
| 69 | - static::$nonce = wp_create_nonce( 'wp-debugging' ); | |
| 70 | - | |
| 71 | - if ( false === strpos( file_get_contents( self::$config_path ), "/* That's all, stop editing!" ) ) { | |
| 72 | - if ( 1 === preg_match( '@\$table_prefix = (.*);@', file_get_contents( self::$config_path ), $matches ) ) { | |
| 73 | - self::$config_args = array_merge( | |
| 74 | - self::$config_args, | |
| 75 | - [ | |
| 76 | - 'anchor' => "$matches[0]", | |
| 77 | - 'placement' => 'after', | |
| 78 | - ] | |
| 79 | - ); | |
| 80 | - } | |
| 81 | - } | |
| 82 | 54 | } |
| 83 | 55 | |
| 84 | 56 | /** |
| 85 | 57 | * Load hooks for settings. |
| @@ -122,24 +94,23 @@ | ||
| 122 | 94 | |
| 123 | 95 | /** |
| 124 | 96 | * Update settings on save. |
| 125 | 97 | * |
| 98 | + * phpcs:disable WordPress.Security.NonceVerification.Missing | |
| 99 | + * | |
| 126 | 100 | * @return void |
| 127 | 101 | */ |
| 128 | 102 | public function update_settings() { |
| 129 | - // Exit if improper privileges. | |
| 130 | - if ( ! current_user_can( 'manage_options' ) || ! wp_verify_nonce( static::$nonce, 'wp-debugging' ) ) { | |
| 131 | - return; | |
| 132 | - } | |
| 133 | - | |
| 134 | 103 | if ( isset( $_POST['option_page'] ) && |
| 135 | 104 | 'wp_debugging' === $_POST['option_page'] |
| 136 | 105 | ) { |
| 137 | 106 | $options = isset( $_POST['wp-debugging'] ) |
| 138 | - ? array_map( 'sanitize_text_field', wp_unslash( $_POST['wp-debugging'] ) ) | |
| 107 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 108 | + ? wp_unslash( $_POST['wp-debugging'] ) | |
| 139 | 109 | : []; |
| 110 | + // phpcs:enable | |
| 140 | 111 | |
| 141 | - $options = $this->sanitize( $options ); | |
| 112 | + $options = self::sanitize( $options ); | |
| 142 | 113 | $this->update_constants( self::$options, $options ); |
| 143 | 114 | $filtered_options = array_filter( |
| 144 | 115 | self::$options, |
| 145 | 116 | function ( $e ) { |
| @@ -183,13 +154,16 @@ | ||
| 183 | 154 | $added = []; |
| 184 | 155 | try { |
| 185 | 156 | $config_transformer = new \WPConfigTransformer( self::$config_path ); |
| 186 | 157 | foreach ( $add as $constant => $config ) { |
| 187 | - $value = 'wp_debug_display' === $constant ? 'false' : 'true'; | |
| 188 | - $value = isset( $config['value'] ) ? $config['value'] : $value; | |
| 189 | - $raw = isset( $config['raw'] ) ? $config['raw'] : true; | |
| 190 | - self::$config_args = array_merge( self::$config_args, [ 'raw' => $raw ] ); | |
| 191 | - $config_transformer->update( 'constant', strtoupper( $constant ), $value, self::$config_args ); | |
| 158 | + $value = 'wp_debug_display' === $constant ? 'false' : 'true'; | |
| 159 | + $value = isset( $config['value'] ) ? $config['value'] : $value; | |
| 160 | + $raw = isset( $config['raw'] ) ? $config['raw'] : true; | |
| 161 | + $config_args = [ | |
| 162 | + 'raw' => $raw, | |
| 163 | + 'normalize' => true, | |
| 164 | + ]; | |
| 165 | + $config_transformer->update( 'constant', strtoupper( $constant ), $value, $config_args ); | |
| 192 | 166 | $added[ $constant ] = $value; |
| 193 | 167 | } |
| 194 | 168 | |
| 195 | 169 | return $added; |
| @@ -260,21 +234,20 @@ | ||
| 260 | 234 | |
| 261 | 235 | /** |
| 262 | 236 | * Redirect back to settings page on save. |
| 263 | 237 | * |
| 238 | + * phpcs:disable WordPress.Security.NonceVerification.Missing | |
| 239 | + * | |
| 264 | 240 | * @return void |
| 265 | 241 | */ |
| 266 | 242 | private function redirect_on_save() { |
| 267 | 243 | $update = false; |
| 268 | - if ( ! wp_verify_nonce( static::$nonce, 'wp-debugging' ) ) { | |
| 269 | - return; | |
| 270 | - } | |
| 271 | - | |
| 272 | 244 | if ( ( isset( $_POST['action'] ) && 'update' === $_POST['action'] ) && |
| 273 | 245 | ( isset( $_POST['option_page'] ) && 'wp_debugging' === $_POST['option_page'] ) |
| 274 | 246 | ) { |
| 275 | 247 | $update = true; |
| 276 | 248 | } |
| 249 | + // phpcs:enable | |
| 277 | 250 | |
| 278 | 251 | $redirect_url = is_multisite() ? network_admin_url( 'settings.php' ) : admin_url( 'tools.php' ); |
| 279 | 252 | |
| 280 | 253 | if ( $update ) { |
| @@ -292,21 +265,22 @@ | ||
| 292 | 265 | |
| 293 | 266 | /** |
| 294 | 267 | * Add notice when settings are saved. |
| 295 | 268 | * |
| 269 | + * phpcs:disable WordPress.PHP.StrictComparisons.LooseComparison | |
| 270 | + * phpcs:disable WordPress.Security.NonceVerification.Recommended | |
| 271 | + * | |
| 296 | 272 | * @return void |
| 297 | 273 | */ |
| 298 | 274 | private function saved_settings_notice() { |
| 299 | - if ( ! wp_verify_nonce( static::$nonce, 'wp-debugging' ) ) { | |
| 300 | - return; | |
| 301 | - } | |
| 302 | - if ( ( isset( $_GET['updated'] ) && '1' === $_GET['updated'] ) || | |
| 303 | - ( isset( $_GET['settings-updated'] ) && '1' === $_GET['settings-updated'] ) | |
| 275 | + if ( ( isset( $_GET['updated'] ) && true == $_GET['updated'] ) || | |
| 276 | + ( isset( $_GET['settings-updated'] ) && true == $_GET['settings-updated'] ) | |
| 304 | 277 | ) { |
| 305 | 278 | echo '<div class="updated"><p>'; |
| 306 | 279 | esc_html_e( 'Saved.', 'wp-debugging' ); |
| 307 | 280 | echo '</p></div>'; |
| 308 | 281 | } |
| 282 | + // phpcs:enable | |
| 309 | 283 | } |
| 310 | 284 | |
| 311 | 285 | /** |
| 312 | 286 | * Register settings. |
| @@ -350,20 +324,21 @@ | ||
| 350 | 324 | 'title' => esc_html__( 'Set WP_DEBUG_DISPLAY to false, default is true.', 'wp-debugging' ), |
| 351 | 325 | ] |
| 352 | 326 | ); |
| 353 | 327 | |
| 354 | - add_settings_field( | |
| 355 | - 'wp_disable_fatal_error_handler', | |
| 356 | - null, | |
| 357 | - [ $this, 'checkbox_setting' ], | |
| 358 | - 'wp_debugging', | |
| 359 | - 'wp_debugging', | |
| 360 | - [ | |
| 361 | - 'id' => 'wp_disable_fatal_error_handler', | |
| 362 | - 'title' => esc_html__( 'Set WP_DISABLE_FATAL_ERROR_HANDLER to true.', 'wp-debugging' ), | |
| 363 | - 'class' => version_compare( get_bloginfo( 'version' ), '5.2', '>=' ) ? '' : 'hidden', | |
| 364 | - ] | |
| 365 | - ); | |
| 328 | + if ( version_compare( get_bloginfo( 'version' ), '5.2-beta', '>=' ) ) { | |
| 329 | + add_settings_field( | |
| 330 | + 'wp_disable_fatal_error_handler', | |
| 331 | + null, | |
| 332 | + [ $this, 'checkbox_setting' ], | |
| 333 | + 'wp_debugging', | |
| 334 | + 'wp_debugging', | |
| 335 | + [ | |
| 336 | + 'id' => 'wp_disable_fatal_error_handler', | |
| 337 | + 'title' => esc_html__( 'Set WP_DISABLE_FATAL_ERROR_HANDLER to true.', 'wp-debugging' ), | |
| 338 | + ] | |
| 339 | + ); | |
| 340 | + } | |
| 366 | 341 | } |
| 367 | 342 | |
| 368 | 343 | /** |
| 369 | 344 | * Print settings section information. |
| @@ -422,9 +397,9 @@ | ||
| 422 | 397 | <div class="updated fade"> |
| 423 | 398 | <p><?php echo wp_kses_post( __( '<strong>Please note:</strong> Your <code>wp-config.php</code> file must be writable by the filesystem. Any errors will result in a PHP Exception being thrown. Debug constants per <a href="https://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a>.', 'wp-debugging' ) ); ?></p> |
| 424 | 399 | </div> |
| 425 | 400 | <div> |
| 426 | - <form method="post" action="<?php echo esc_attr( $action ); ?>"> | |
| 401 | + <form method="post" action="<?php esc_attr_e( $action ); ?>"> | |
| 427 | 402 | <?php settings_fields( 'wp_debugging' ); ?> |
| 428 | 403 | <?php do_settings_sections( 'wp_debugging' ); ?> |
| 429 | 404 | <?php submit_button(); ?> |
| 430 | 405 | </form> |
| @@ -459,10 +434,10 @@ | ||
| 459 | 434 | public function checkbox_setting( $args ) { |
| 460 | 435 | $checked = isset( self::$options[ $args['id'] ] ) ? self::$options[ $args['id'] ] : null; |
| 461 | 436 | ?> |
| 462 | 437 | <style> .form-table th { display:none; } </style> |
| 463 | - <label for="<?php echo esc_attr( $args['id'] ); ?>"> | |
| 464 | - <input type="checkbox" name="wp-debugging[<?php echo esc_attr( $args['id'] ); ?>]" value="1" <?php checked( '1', $checked ); ?> > | |
| 438 | + <label for="<?php esc_attr_e( $args['id'] ); ?>"> | |
| 439 | + <input type="checkbox" name="wp-debugging[<?php esc_attr_e( $args['id'] ); ?>]" value="1" <?php checked( '1', $checked ); ?> > | |
| 465 | 440 | <?php esc_html_e( $args['title'] ); ?> |
| 466 | 441 | </label> |
| 467 | 442 | <?php |
| 468 | 443 | } |