PluginProbe
WP Debugging / 2.9.2
WP Debugging v2.9.2
2.12.6 2.12.5 trunk 2.10.0 2.10.1 2.10.2 2.11.0 2.11.1 2.11.10 2.11.11 2.11.12 2.11.13 2.11.14 2.11.15 2.11.16 2.11.17 2.11.18 2.11.19 2.11.2 2.11.20 2.11.21 2.11.22 2.11.23 2.11.24 2.11.3 All 59 releases
← All changes | src/Settings.php +47 -62 trunk2.9.2 View file →
@@ -39,15 +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 43 * Constructor.
51 44 *
52 45 * @param array $options Plugin options.
53 46 * @param string $config_path Path to config file.
@@ -57,21 +50,8 @@
57 50 public function __construct( $options, $config_path, $defined_constants ) {
58 51 self::$options = $options;
59 52 self::$config_path = $config_path;
60 53 $this->defined_constants = $defined_constants;
61 - self::$config_args = [ 'normalize' => true ];
62 -
63 - if ( false === strpos( file_get_contents( self::$config_path ), "/* That's all, stop editing!" ) ) {
64 - if ( 1 === preg_match( '@\$table_prefix(.*;)@', file_get_contents( self::$config_path ), $matches ) ) {
65 - self::$config_args = array_merge(
66 - self::$config_args,
67 - [
68 - 'anchor' => "$matches[0]",
69 - 'placement' => 'after',
70 - ]
71 - );
72 - }
73 - }
74 54 }
75 55
76 56 /**
77 57 * Load hooks for settings.
@@ -114,30 +94,27 @@
114 94
115 95 /**
116 96 * Update settings on save.
117 97 *
98 + * phpcs:disable WordPress.Security.NonceVerification.Missing
99 + *
118 100 * @return void
119 101 */
120 102 public function update_settings() {
121 - // Exit if improper privileges.
122 - if ( ! current_user_can( 'manage_options' )
123 - || ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['_wpnonce'] ) ), 'wp_debugging-options' ) )
124 - ) {
125 - return;
126 - }
127 -
128 103 if ( isset( $_POST['option_page'] ) &&
129 104 'wp_debugging' === $_POST['option_page']
130 105 ) {
131 106 $options = isset( $_POST['wp-debugging'] )
132 - ? array_map( 'sanitize_text_field', wp_unslash( $_POST['wp-debugging'] ) )
107 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
108 + ? wp_unslash( $_POST['wp-debugging'] )
133 109 : [];
110 + // phpcs:enable
134 111
135 - $options = $this->sanitize( $options );
112 + $options = self::sanitize( $options );
136 113 $this->update_constants( self::$options, $options );
137 114 $filtered_options = array_filter(
138 115 self::$options,
139 - static function ( $e ) {
116 + function ( $e ) {
140 117 return '1' !== $e;
141 118 }
142 119 );
143 120 $options = array_merge( $filtered_options, $options );
@@ -148,15 +125,15 @@
148 125
149 126 /**
150 127 * Update constants in wp-config.php.
151 128 *
152 - * @param array $old Current value of self::$options.
153 - * @param mixed $updated New value of $options.
129 + * @param array $old Current value of self::$options.
130 + * @param mixed $new New value of $options.
154 131 * @return void
155 132 */
156 - private function update_constants( $old, $updated ) {
157 - $remove = array_diff_assoc( $old, $updated );
158 - $add = array_diff_assoc( $updated, $old );
133 + private function update_constants( $old, $new ) {
134 + $remove = array_diff_assoc( $old, $new );
135 + $add = array_diff_assoc( $new, $old );
159 136
160 137 if ( ! empty( $add ) ) {
161 138 $this->add_constants( $add );
162 139 }
@@ -177,13 +154,16 @@
177 154 $added = [];
178 155 try {
179 156 $config_transformer = new \WPConfigTransformer( self::$config_path );
180 157 foreach ( $add as $constant => $config ) {
181 - $value = 'wp_debug_display' === $constant ? 'false' : 'true';
182 - $value = isset( $config['value'] ) ? $config['value'] : $value;
183 - $raw = isset( $config['raw'] ) ? $config['raw'] : true;
184 - self::$config_args = array_merge( self::$config_args, [ 'raw' => $raw ] );
185 - $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 );
186 166 $added[ $constant ] = $value;
187 167 }
188 168
189 169 return $added;
@@ -188,8 +168,9 @@
188 168
189 169 return $added;
190 170 } catch ( \Exception $e ) {
191 171 $messsage = 'Caught Exception: \Fragen\WP_Debugging\Settings::add_constants() - ' . $e->getMessage();
172 + // error_log( $messsage );
192 173 wp_die( esc_html( $messsage ) );
193 174 }
194 175 }
195 176
@@ -245,8 +226,9 @@
245 226 $config_transformer->remove( 'constant', strtoupper( $constant ) );
246 227 }
247 228 } catch ( \Exception $e ) {
248 229 $messsage = 'Caught Exception: \Fragen\WP_Debugging\Settings::remove_constants() - ' . $e->getMessage();
230 + // error_log( $messsage );
249 231 wp_die( esc_html( $messsage ) );
250 232 }
251 233 }
252 234
@@ -252,14 +234,14 @@
252 234
253 235 /**
254 236 * Redirect back to settings page on save.
255 237 *
238 + * phpcs:disable WordPress.Security.NonceVerification.Missing
239 + *
256 240 * @return void
257 241 */
258 242 private function redirect_on_save() {
259 243 $update = false;
260 -
261 - // phpcs:disable WordPress.Security.NonceVerification.Missing
262 244 if ( ( isset( $_POST['action'] ) && 'update' === $_POST['action'] ) &&
263 245 ( isset( $_POST['option_page'] ) && 'wp_debugging' === $_POST['option_page'] )
264 246 ) {
265 247 $update = true;
@@ -283,14 +265,16 @@
283 265
284 266 /**
285 267 * Add notice when settings are saved.
286 268 *
269 + * phpcs:disable WordPress.PHP.StrictComparisons.LooseComparison
270 + * phpcs:disable WordPress.Security.NonceVerification.Recommended
271 + *
287 272 * @return void
288 273 */
289 274 private function saved_settings_notice() {
290 - // phpcs:disable WordPress.Security.NonceVerification.Recommended
291 - if ( ( isset( $_GET['updated'] ) && '1' === $_GET['updated'] ) ||
292 - ( 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'] )
293 277 ) {
294 278 echo '<div class="updated"><p>';
295 279 esc_html_e( 'Saved.', 'wp-debugging' );
296 280 echo '</p></div>';
@@ -340,20 +324,21 @@
340 324 'title' => esc_html__( 'Set WP_DEBUG_DISPLAY to false, default is true.', 'wp-debugging' ),
341 325 ]
342 326 );
343 327
344 - add_settings_field(
345 - 'wp_disable_fatal_error_handler',
346 - null,
347 - [ $this, 'checkbox_setting' ],
348 - 'wp_debugging',
349 - 'wp_debugging',
350 - [
351 - 'id' => 'wp_disable_fatal_error_handler',
352 - 'title' => esc_html__( 'Set WP_DISABLE_FATAL_ERROR_HANDLER to true.', 'wp-debugging' ),
353 - 'class' => version_compare( get_bloginfo( 'version' ), '5.2', '>=' ) ? '' : 'hidden',
354 - ]
355 - );
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 + }
356 341 }
357 342
358 343 /**
359 344 * Print settings section information.
@@ -409,12 +394,12 @@
409 394 $action = is_multisite() ? 'edit.php?action=wp-debugging' : 'options.php'; ?>
410 395 <div class="wrap">
411 396 <h1><?php esc_html_e( 'WP Debugging', 'wp-debugging' ); ?></h1>
412 397 <div class="updated fade">
413 - <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 as documented in <a href="https://wordpress.org/documentation/article/debugging-in-wordpress/">Debugging in WordPress</a>.', 'wp-debugging' ) ); ?></p>
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>
414 399 </div>
415 400 <div>
416 - <form method="post" action="<?php echo esc_attr( $action ); ?>">
401 + <form method="post" action="<?php esc_attr_e( $action ); ?>">
417 402 <?php settings_fields( 'wp_debugging' ); ?>
418 403 <?php do_settings_sections( 'wp_debugging' ); ?>
419 404 <?php submit_button(); ?>
420 405 </form>
@@ -449,11 +434,11 @@
449 434 public function checkbox_setting( $args ) {
450 435 $checked = isset( self::$options[ $args['id'] ] ) ? self::$options[ $args['id'] ] : null;
451 436 ?>
452 437 <style> .form-table th { display:none; } </style>
453 - <label for="<?php echo esc_attr( $args['id'] ); ?>">
454 - <input type="checkbox" name="wp-debugging[<?php echo esc_attr( $args['id'] ); ?>]" value="1" <?php checked( '1', $checked ); ?> >
455 - <?php echo esc_html( $args['title'] ); ?>
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 ); ?> >
440 + <?php esc_html_e( $args['title'] ); ?>
456 441 </label>
457 442 <?php
458 443 }
459 444