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 +40 -48 2.10.12.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,26 +58,20 @@
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();
73 + ( new Settings( self::$options, self::$config_path ) )->load_hooks();
85 74 \WP_Dependency_Installer::instance()->run( $this->dir );
86 75 }
87 76
88 77 /**
@@ -120,16 +109,8 @@
120 109 */
121 110 public function load_hooks() {
122 111 add_action(
123 112 'init',
124 - function() {
125 - ( new Settings( self::$options, self::$config_path, $this->defined_constants ) )
126 - ->load_hooks()
127 - ->process_filter_constants();
128 - }
129 - );
130 - add_action(
131 - 'init',
132 113 function () {
133 114 load_plugin_textdomain( 'wp-debugging' );
134 115 }
135 116 );
@@ -154,20 +135,20 @@
154 135 *
155 136 * @return void
156 137 */
157 138 public function activate() {
158 - $this->set_pre_activation_constants();
159 -
160 - // Need to remove user defined constants from filter.
161 - $user_defined = apply_filters( 'wp_debugging_add_constants', [] );
162 - foreach ( array_keys( $user_defined ) as $defined ) {
163 - 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 );
164 150 }
165 -
166 - $constants = [ 'wp_debug_log', 'script_debug', 'savequeries' ];
167 - $constants = array_flip( array_merge( array_keys( self::$options ), $constants ) );
168 -
169 - ( new Settings( self::$options, self::$config_path, $this->defined_constants ) )->add_constants( $constants );
170 151 }
171 152
172 153 /**
173 154 * Run on deactivation.
@@ -175,30 +156,33 @@
175 156 *
176 157 * @return void
177 158 */
178 159 public function deactivate() {
179 - $restore_constants = get_site_option( 'wp_debugging_restore' );
180 - $remove_user_added = array_diff( self::$options, array_flip( $this->defined_constants ) );
181 - $remove_constants = array_diff( array_flip( $this->defined_constants ), array_keys( $restore_constants ) );
182 - $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 );
183 163
184 - ( new Settings( self::$options, self::$config_path, $this->defined_constants ) )->remove_constants( $remove_constants );
185 -
186 - $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 );
187 168 }
188 169
189 170 /**
190 171 * Set pre-activation constant from `wp-config.php`.
191 172 *
173 + * @param \WPConfigTransformer $config_transformer
174 + *
192 175 * @return void
193 176 */
194 - private function set_pre_activation_constants() {
195 - $config_transformer = new \WPConfigTransformer( self::$config_path );
177 + private function set_pre_activation_constants( \WPConfigTransformer $config_transformer ) {
196 178 $predefined_constants = [];
197 179 foreach ( $this->defined_constants as $defined_constant ) {
198 180 if ( $config_transformer->exists( 'constant', strtoupper( $defined_constant ) ) ) {
199 181 $value = $config_transformer->get_value( 'constant', strtoupper( $defined_constant ) );
200 - $predefined_constants[ $defined_constant ]['value'] = $value;
182 + $value = trim( $value, '"\'' ); // Normalize quoted value.
183 +
184 + $predefined_constants[ $defined_constant ] = $value;
201 185 }
202 186 }
203 187 update_site_option( 'wp_debugging_restore', $predefined_constants );
204 188 }
@@ -205,11 +189,19 @@
205 189
206 190 /**
207 191 * Restore pre-activation constants to `wp-config.php`.
208 192 *
193 + * @param \WPConfigTransformer $config_transformer
194 + *
209 195 * @return void
210 196 */
211 - private function restore_pre_activation_constants() {
197 + private function restore_pre_activation_constants( \WPConfigTransformer $config_transformer ) {
212 198 $restore_constants = get_site_option( 'wp_debugging_restore' );
213 - ( 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 + }
214 206 }
215 207 }