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 +40 -63 2.10.02.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,20 +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 - 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 49 }
74 50
75 51 /**
76 52 * Load hooks for settings.
@@ -127,9 +103,9 @@
127 103 ? wp_unslash( $_POST['wp-debugging'] )
128 104 : [];
129 105 // phpcs:enable
130 106
131 - $options = $this->sanitize( $options );
107 + $options = self::sanitize( $options );
132 108 $this->update_constants( self::$options, $options );
133 109 $filtered_options = array_filter(
134 110 self::$options,
135 111 function ( $e ) {
@@ -169,26 +145,26 @@
169 145 * @param array $add Constants to add to wp-config.php.
170 146 * @return array $added Array of added constants.
171 147 */
172 148 public function add_constants( $add ) {
173 - $added = [];
174 - try {
175 - $config_transformer = new \WPConfigTransformer( self::$config_path );
176 - foreach ( $add as $constant => $config ) {
177 - $value = 'wp_debug_display' === $constant ? 'false' : 'true';
178 - $value = isset( $config['value'] ) ? $config['value'] : $value;
179 - $raw = isset( $config['raw'] ) ? $config['raw'] : true;
180 - self::$config_args = array_merge( self::$config_args, [ 'raw' => $raw ] );
181 - $config_transformer->update( 'constant', strtoupper( $constant ), $value, self::$config_args );
182 - $added[ $constant ] = $value;
183 - }
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 + }
184 165
185 - return $added;
186 - } catch ( \Exception $e ) {
187 - $messsage = 'Caught Exception: \Fragen\WP_Debugging\Settings::add_constants() - ' . $e->getMessage();
188 - // error_log( $messsage );
189 - wp_die( esc_html( $messsage ) );
190 - }
166 + return $added;
191 167 }
192 168
193 169 /**
194 170 * Process user defined constants added via filter.
@@ -195,8 +171,11 @@
195 171 *
196 172 * @return void
197 173 */
198 174 public function process_filter_constants() {
175 + if ( ! \file_exists( self::$config_path ) || ! trim( \file_get_contents( self::$config_path ) ) ) {
176 + return;
177 + }
199 178 /**
200 179 * Filter to add user define constants.
201 180 *
202 181 * @since 2.5.0
@@ -235,18 +214,15 @@
235 214 * @param array $remove Constants to remove from wp-config.php.
236 215 * @return void
237 216 */
238 217 public function remove_constants( $remove ) {
239 - try {
240 - $config_transformer = new \WPConfigTransformer( self::$config_path );
241 - foreach ( array_keys( $remove ) as $constant ) {
242 - $config_transformer->remove( 'constant', strtoupper( $constant ) );
243 - }
244 - } catch ( \Exception $e ) {
245 - $messsage = 'Caught Exception: \Fragen\WP_Debugging\Settings::remove_constants() - ' . $e->getMessage();
246 - // error_log( $messsage );
247 - wp_die( esc_html( $messsage ) );
218 + if ( ! \file_exists( self::$config_path ) || ! trim( \file_get_contents( self::$config_path ) ) ) {
219 + return;
248 220 }
221 + $config_transformer = new \WPConfigTransformer( self::$config_path );
222 + foreach ( array_keys( $remove ) as $constant ) {
223 + $config_transformer->remove( 'constant', strtoupper( $constant ) );
224 + }
249 225 }
250 226
251 227 /**
252 228 * Redirect back to settings page on save.
@@ -340,20 +316,21 @@
340 316 'title' => esc_html__( 'Set WP_DEBUG_DISPLAY to false, default is true.', 'wp-debugging' ),
341 317 ]
342 318 );
343 319
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 - );
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 + }
356 333 }
357 334
358 335 /**
359 336 * Print settings section information.