PluginProbe
WP Debugging / 2.7.2
WP Debugging v2.7.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 +55 -80 2.11.122.7.2 View file →
@@ -8,13 +8,8 @@
8 8 */
9 9
10 10 namespace Fragen\WP_Debugging;
11 11
12 -// Exit if called directly.
13 -if ( ! defined( 'WPINC' ) ) {
14 - die;
15 -}
16 -
17 12 /**
18 13 * Class Settings
19 14 */
20 15 class Settings {
@@ -39,15 +34,8 @@
39 34 */
40 35 protected $defined_constants;
41 36
42 37 /**
43 - * Holds config args for WPConfigTransformer.
44 - *
45 - * @var array
46 - */
47 - protected static $config_args;
48 -
49 - /**
50 38 * Constructor.
51 39 *
52 40 * @param array $options Plugin options.
53 41 * @param string $config_path Path to config file.
@@ -57,21 +45,8 @@
57 45 public function __construct( $options, $config_path, $defined_constants ) {
58 46 self::$options = $options;
59 47 self::$config_path = $config_path;
60 48 $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 49 }
75 50
76 51 /**
77 52 * Load hooks for settings.
@@ -114,26 +89,23 @@
114 89
115 90 /**
116 91 * Update settings on save.
117 92 *
93 + * phpcs:disable WordPress.Security.NonceVerification.Missing
94 + *
118 95 * @return void
119 96 */
120 97 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 98 if ( isset( $_POST['option_page'] ) &&
129 99 'wp_debugging' === $_POST['option_page']
130 100 ) {
131 101 $options = isset( $_POST['wp-debugging'] )
132 - ? array_map( 'sanitize_text_field', wp_unslash( $_POST['wp-debugging'] ) )
102 + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
103 + ? wp_unslash( $_POST['wp-debugging'] )
133 104 : [];
105 + // phpcs:enable
134 106
135 - $options = $this->sanitize( $options );
107 + $options = self::sanitize( $options );
136 108 $this->update_constants( self::$options, $options );
137 109 $filtered_options = array_filter(
138 110 self::$options,
139 111 function ( $e ) {
@@ -173,26 +145,26 @@
173 145 * @param array $add Constants to add to wp-config.php.
174 146 * @return array $added Array of added constants.
175 147 */
176 148 public function add_constants( $add ) {
177 - $added = [];
178 - try {
179 - $config_transformer = new \WPConfigTransformer( self::$config_path );
180 - 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 );
186 - $added[ $constant ] = $value;
187 - }
149 + if ( ! \file_exists( self::$config_path ) || ! trim( \file_get_contents( self::$config_path ) ) ) {
150 + return [];
151 + }
152 + $added = [];
153 + $config_transformer = new \WPConfigTransformer( self::$config_path );
154 + foreach ( $add as $constant => $config ) {
155 + $value = 'wp_debug_display' === $constant ? 'false' : 'true';
156 + $value = isset( $config['value'] ) ? $config['value'] : $value;
157 + $raw = isset( $config['raw'] ) ? $config['raw'] : true;
158 + $config_args = [
159 + 'raw' => $raw,
160 + 'normalize' => true,
161 + ];
162 + $config_transformer->update( 'constant', strtoupper( $constant ), $value, $config_args );
163 + $added[ $constant ] = $value;
164 + }
188 165
189 - return $added;
190 - } catch ( \Exception $e ) {
191 - $messsage = 'Caught Exception: \Fragen\WP_Debugging\Settings::add_constants() - ' . $e->getMessage();
192 - // error_log( $messsage );
193 - wp_die( esc_html( $messsage ) );
194 - }
166 + return $added;
195 167 }
196 168
197 169 /**
198 170 * Process user defined constants added via filter.
@@ -199,8 +171,11 @@
199 171 *
200 172 * @return void
201 173 */
202 174 public function process_filter_constants() {
175 + if ( ! \file_exists( self::$config_path ) || ! trim( \file_get_contents( self::$config_path ) ) ) {
176 + return;
177 + }
203 178 /**
204 179 * Filter to add user define constants.
205 180 *
206 181 * @since 2.5.0
@@ -239,29 +214,26 @@
239 214 * @param array $remove Constants to remove from wp-config.php.
240 215 * @return void
241 216 */
242 217 public function remove_constants( $remove ) {
243 - try {
244 - $config_transformer = new \WPConfigTransformer( self::$config_path );
245 - foreach ( array_keys( $remove ) as $constant ) {
246 - $config_transformer->remove( 'constant', strtoupper( $constant ) );
247 - }
248 - } catch ( \Exception $e ) {
249 - $messsage = 'Caught Exception: \Fragen\WP_Debugging\Settings::remove_constants() - ' . $e->getMessage();
250 - // error_log( $messsage );
251 - wp_die( esc_html( $messsage ) );
218 + if ( ! \file_exists( self::$config_path ) || ! trim( \file_get_contents( self::$config_path ) ) ) {
219 + return;
252 220 }
221 + $config_transformer = new \WPConfigTransformer( self::$config_path );
222 + foreach ( array_keys( $remove ) as $constant ) {
223 + $config_transformer->remove( 'constant', strtoupper( $constant ) );
224 + }
253 225 }
254 226
255 227 /**
256 228 * Redirect back to settings page on save.
257 229 *
230 + * phpcs:disable WordPress.Security.NonceVerification.Missing
231 + *
258 232 * @return void
259 233 */
260 234 private function redirect_on_save() {
261 235 $update = false;
262 -
263 - // phpcs:disable WordPress.Security.NonceVerification.Missing
264 236 if ( ( isset( $_POST['action'] ) && 'update' === $_POST['action'] ) &&
265 237 ( isset( $_POST['option_page'] ) && 'wp_debugging' === $_POST['option_page'] )
266 238 ) {
267 239 $update = true;
@@ -285,14 +257,16 @@
285 257
286 258 /**
287 259 * Add notice when settings are saved.
288 260 *
261 + * phpcs:disable WordPress.PHP.StrictComparisons.LooseComparison
262 + * phpcs:disable WordPress.Security.NonceVerification.Recommended
263 + *
289 264 * @return void
290 265 */
291 266 private function saved_settings_notice() {
292 - // phpcs:disable WordPress.Security.NonceVerification.Recommended
293 - if ( ( isset( $_GET['updated'] ) && '1' === $_GET['updated'] ) ||
294 - ( isset( $_GET['settings-updated'] ) && '1' === $_GET['settings-updated'] )
267 + if ( ( isset( $_GET['updated'] ) && true == $_GET['updated'] ) ||
268 + ( isset( $_GET['settings-updated'] ) && true == $_GET['settings-updated'] )
295 269 ) {
296 270 echo '<div class="updated"><p>';
297 271 esc_html_e( 'Saved.', 'wp-debugging' );
298 272 echo '</p></div>';
@@ -342,20 +316,21 @@
342 316 'title' => esc_html__( 'Set WP_DEBUG_DISPLAY to false, default is true.', 'wp-debugging' ),
343 317 ]
344 318 );
345 319
346 - add_settings_field(
347 - 'wp_disable_fatal_error_handler',
348 - null,
349 - [ $this, 'checkbox_setting' ],
350 - 'wp_debugging',
351 - 'wp_debugging',
352 - [
353 - 'id' => 'wp_disable_fatal_error_handler',
354 - 'title' => esc_html__( 'Set WP_DISABLE_FATAL_ERROR_HANDLER to true.', 'wp-debugging' ),
355 - 'class' => version_compare( get_bloginfo( 'version' ), '5.2', '>=' ) ? '' : 'hidden',
356 - ]
357 - );
320 + if ( version_compare( get_bloginfo( 'version' ), '5.2-beta', '>=' ) ) {
321 + add_settings_field(
322 + 'wp_disable_fatal_error_handler',
323 + null,
324 + [ $this, 'checkbox_setting' ],
325 + 'wp_debugging',
326 + 'wp_debugging',
327 + [
328 + 'id' => 'wp_disable_fatal_error_handler',
329 + 'title' => esc_html__( 'Set WP_DISABLE_FATAL_ERROR_HANDLER to true.', 'wp-debugging' ),
330 + ]
331 + );
332 + }
358 333 }
359 334
360 335 /**
361 336 * Print settings section information.
@@ -414,9 +389,9 @@
414 389 <div class="updated fade">
415 390 <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>
416 391 </div>
417 392 <div>
418 - <form method="post" action="<?php echo esc_attr( $action ); ?>">
393 + <form method="post" action="<?php esc_attr_e( $action ); ?>">
419 394 <?php settings_fields( 'wp_debugging' ); ?>
420 395 <?php do_settings_sections( 'wp_debugging' ); ?>
421 396 <?php submit_button(); ?>
422 397 </form>
@@ -451,10 +426,10 @@
451 426 public function checkbox_setting( $args ) {
452 427 $checked = isset( self::$options[ $args['id'] ] ) ? self::$options[ $args['id'] ] : null;
453 428 ?>
454 429 <style> .form-table th { display:none; } </style>
455 - <label for="<?php echo esc_attr( $args['id'] ); ?>">
456 - <input type="checkbox" name="wp-debugging[<?php echo esc_attr( $args['id'] ); ?>]" value="1" <?php checked( '1', $checked ); ?> >
430 + <label for="<?php esc_attr_e( $args['id'] ); ?>">
431 + <input type="checkbox" name="wp-debugging[<?php esc_attr_e( $args['id'] ); ?>]" value="1" <?php checked( '1', $checked ); ?> >
457 432 <?php esc_html_e( $args['title'] ); ?>
458 433 </label>
459 434 <?php
460 435 }