PluginProbe
WP Debugging / 2.4.3
WP Debugging v2.4.3
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/Bootstrap.php +41 -54 2.11.202.4.3 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 Bootstrap
19 14 */
20 15 class Bootstrap {
@@ -63,32 +58,21 @@
63 58 $this->file = $file;
64 59 $this->dir = dirname( $file );
65 60 self::$options = get_site_option( 'wp_debugging', [ 'wp_debug' => '1' ] );
66 61 self::$config_path = $this->get_config_path();
67 - @ini_set( 'display_errors', 1 ); // phpcs:ignore WordPress.PHP.IniSet.display_errors_Blacklisted
62 + @ini_set( 'display_errors', 1 );
68 63 }
69 64
70 65 /**
71 - * Test for writable wp-config.php, exit with notice if not available.
66 + * Let's get going.
72 67 *
73 - * @return bool|void
68 + * @return void
74 69 */
75 - public function init() {
76 - if ( ! is_writable( self::$config_path ) ) {
77 - echo '<div class="error notice is-dismissible"><p>';
78 - echo wp_kses_post( __( 'The <strong>WP Debugging</strong> plugin must have a <code>wp-config.php</code> file that is writable by the filesystem.', 'wp-debugging' ) );
79 - echo '</p></div>';
80 -
81 - return false;
82 - }
83 -
70 + public function run() {
71 + require_once $this->dir . '/vendor/autoload.php';
84 72 $this->load_hooks();
85 - add_action(
86 - 'plugins_loaded',
87 - function() {
88 - \WP_Dependency_Installer::instance()->run( $this->dir );
89 - }
90 - );
73 + ( new Settings( self::$options, self::$config_path ) )->load_hooks();
74 + \WP_Dependency_Installer::instance()->run( $this->dir );
91 75 }
92 76
93 77 /**
94 78 * Get the `wp-config.php` file path.
@@ -124,16 +108,8 @@
124 108 * @return void
125 109 */
126 110 public function load_hooks() {
127 111 add_action(
128 - 'plugins_loaded',
129 - function() {
130 - ( new Settings( self::$options, self::$config_path, $this->defined_constants ) )
131 - ->load_hooks()
132 - ->process_filter_constants();
133 - }
134 - );
135 - add_action(
136 112 'init',
137 113 function () {
138 114 load_plugin_textdomain( 'wp-debugging' );
139 115 }
@@ -159,20 +135,20 @@
159 135 *
160 136 * @return void
161 137 */
162 138 public function activate() {
163 - $this->set_pre_activation_constants();
164 -
165 - // Need to remove user defined constants from filter.
166 - $user_defined = apply_filters( 'wp_debugging_add_constants', [] );
167 - foreach ( array_keys( $user_defined ) as $defined ) {
168 - unset( self::$options[ $defined ] );
139 + $config_transformer = new \WPConfigTransformer( self::$config_path );
140 + $constants = [ 'wp_debug_log', 'script_debug', 'savequeries' ];
141 + $constants = array_merge( array_keys( self::$options ), $constants );
142 + $config_args = [
143 + 'raw' => true,
144 + 'normalize' => true,
145 + ];
146 + $this->set_pre_activation_constants( $config_transformer );
147 + foreach ( $constants as $constant ) {
148 + $value = 'wp_debug_display' === $constant ? 'false' : 'true';
149 + $config_transformer->update( 'constant', strtoupper( $constant ), $value, $config_args );
169 150 }
170 -
171 - $constants = [ 'wp_debug_log', 'script_debug', 'savequeries' ];
172 - $constants = array_flip( array_merge( array_keys( self::$options ), $constants ) );
173 -
174 - ( new Settings( self::$options, self::$config_path, $this->defined_constants ) )->add_constants( $constants );
175 151 }
176 152
177 153 /**
178 154 * Run on deactivation.
@@ -180,30 +156,33 @@
180 156 *
181 157 * @return void
182 158 */
183 159 public function deactivate() {
184 - $restore_constants = get_site_option( 'wp_debugging_restore' );
185 - $remove_user_added = array_diff( self::$options, array_flip( $this->defined_constants ) );
186 - $remove_constants = array_diff( array_flip( $this->defined_constants ), array_keys( $restore_constants ) );
187 - $remove_constants = array_merge( $remove_constants, $remove_user_added );
160 + $restore_constants = get_site_option( 'wp_debugging_restore' );
161 + $remove_constants = array_diff( $this->defined_constants, array_keys( $restore_constants ) );
162 + $config_transformer = new \WPConfigTransformer( self::$config_path );
188 163
189 - ( new Settings( self::$options, self::$config_path, $this->defined_constants ) )->remove_constants( $remove_constants );
190 -
191 - $this->restore_pre_activation_constants();
164 + foreach ( $remove_constants as $constant ) {
165 + $config_transformer->remove( 'constant', strtoupper( $constant ) );
166 + }
167 + $this->restore_pre_activation_constants( $config_transformer );
192 168 }
193 169
194 170 /**
195 171 * Set pre-activation constant from `wp-config.php`.
196 172 *
173 + * @param \WPConfigTransformer $config_transformer
174 + *
197 175 * @return void
198 176 */
199 - private function set_pre_activation_constants() {
200 - $config_transformer = new \WPConfigTransformer( self::$config_path );
177 + private function set_pre_activation_constants( \WPConfigTransformer $config_transformer ) {
201 178 $predefined_constants = [];
202 179 foreach ( $this->defined_constants as $defined_constant ) {
203 180 if ( $config_transformer->exists( 'constant', strtoupper( $defined_constant ) ) ) {
204 181 $value = $config_transformer->get_value( 'constant', strtoupper( $defined_constant ) );
205 - $predefined_constants[ $defined_constant ]['value'] = $value;
182 + $value = trim( $value, '"\'' ); // Normalize quoted value.
183 +
184 + $predefined_constants[ $defined_constant ] = $value;
206 185 }
207 186 }
208 187 update_site_option( 'wp_debugging_restore', $predefined_constants );
209 188 }
@@ -210,11 +189,19 @@
210 189
211 190 /**
212 191 * Restore pre-activation constants to `wp-config.php`.
213 192 *
193 + * @param \WPConfigTransformer $config_transformer
194 + *
214 195 * @return void
215 196 */
216 - private function restore_pre_activation_constants() {
197 + private function restore_pre_activation_constants( \WPConfigTransformer $config_transformer ) {
217 198 $restore_constants = get_site_option( 'wp_debugging_restore' );
218 - ( new Settings( self::$options, self::$config_path, $this->defined_constants ) )->add_constants( $restore_constants );
199 + $config_args = [
200 + 'raw' => true,
201 + 'normalize' => true,
202 + ];
203 + foreach ( $restore_constants as $constant => $value ) {
204 + $config_transformer->update( 'constant', strtoupper( $constant ), $value, $config_args );
205 + }
219 206 }
220 207 }