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 +46 -62 trunk2.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,37 +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,WordPress.PHP.NoSilencedErrors.Discouraged,WordPress.PHP.IniSet.display_errors_Disallowed
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 - register_activation_hook( $this->file, [ $this, 'activate' ] );
77 - register_deactivation_hook( $this->file, [ $this, 'deactivate' ] );
78 -
79 - // Load settings hooks and exit if not on WP Debugging settings page.
80 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended
81 - if ( ! isset( $_REQUEST['page'] ) || 'wp-debugging' !== sanitize_key( wp_unslash( $_REQUEST['page'] ) ) ) {
82 - ( new Settings( self::$options, self::$config_path, $this->defined_constants ) )
83 - ->load_hooks();
84 - return;
85 - }
86 -
87 - if ( ! is_writable( self::$config_path ) ) {
88 - echo '<div class="error notice is-dismissible"><p>';
89 - 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' ) );
90 - echo '</p></div>';
91 -
92 - return false;
93 - }
94 -
70 + public function run() {
71 + require_once $this->dir . '/vendor/autoload.php';
95 72 $this->load_hooks();
73 + ( new Settings( self::$options, self::$config_path ) )->load_hooks();
74 + \WP_Dependency_Installer::instance()->run( $this->dir );
96 75 }
97 76
98 77 /**
99 78 * Get the `wp-config.php` file path.
@@ -107,9 +86,8 @@
107 86 public function get_config_path() {
108 87 $config_path = ABSPATH . 'wp-config.php';
109 88
110 89 if ( ! file_exists( $config_path ) ) {
111 - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
112 90 if ( @file_exists( dirname( ABSPATH ) . '/wp-config.php' ) && ! @file_exists( dirname( ABSPATH ) . '/wp-settings.php' ) ) {
113 91 $config_path = dirname( ABSPATH ) . '/wp-config.php';
114 92 }
115 93 }
@@ -130,13 +108,11 @@
130 108 * @return void
131 109 */
132 110 public function load_hooks() {
133 111 add_action(
134 - 'plugins_loaded',
112 + 'init',
135 113 function () {
136 - ( new Settings( self::$options, self::$config_path, $this->defined_constants ) )
137 - ->load_hooks()
138 - ->process_filter_constants();
114 + load_plugin_textdomain( 'wp-debugging' );
139 115 }
140 116 );
141 117 add_filter(
142 118 'wp_dependency_timeout',
@@ -147,14 +123,11 @@
147 123 },
148 124 10,
149 125 2
150 126 );
151 - add_action(
152 - 'plugins_loaded',
153 - function () {
154 - \WP_Dependency_Installer::instance()->run( $this->dir );
155 - }
156 - );
127 +
128 + register_activation_hook( $this->file, [ $this, 'activate' ] );
129 + register_deactivation_hook( $this->file, [ $this, 'deactivate' ] );
157 130 }
158 131
159 132 /**
160 133 * Run on activation.
@@ -162,20 +135,20 @@
162 135 *
163 136 * @return void
164 137 */
165 138 public function activate() {
166 - $this->set_pre_activation_constants();
167 -
168 - // Need to remove user defined constants from filter.
169 - $user_defined = apply_filters( 'wp_debugging_add_constants', [] );
170 - foreach ( array_keys( $user_defined ) as $defined ) {
171 - 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 );
172 150 }
173 -
174 - $constants = [ 'wp_debug_log', 'script_debug', 'savequeries' ];
175 - $constants = array_flip( array_merge( array_keys( self::$options ), $constants ) );
176 -
177 - ( new Settings( self::$options, self::$config_path, $this->defined_constants ) )->add_constants( $constants );
178 151 }
179 152
180 153 /**
181 154 * Run on deactivation.
@@ -183,30 +156,33 @@
183 156 *
184 157 * @return void
185 158 */
186 159 public function deactivate() {
187 - $restore_constants = get_site_option( 'wp_debugging_restore' );
188 - $remove_user_added = array_diff( self::$options, array_flip( $this->defined_constants ) );
189 - $remove_constants = array_diff( array_flip( $this->defined_constants ), array_keys( (array) $restore_constants ) );
190 - $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 );
191 163
192 - ( new Settings( self::$options, self::$config_path, $this->defined_constants ) )->remove_constants( $remove_constants );
193 -
194 - $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 );
195 168 }
196 169
197 170 /**
198 171 * Set pre-activation constant from `wp-config.php`.
199 172 *
173 + * @param \WPConfigTransformer $config_transformer
174 + *
200 175 * @return void
201 176 */
202 - private function set_pre_activation_constants() {
203 - $config_transformer = new \WPConfigTransformer( self::$config_path );
177 + private function set_pre_activation_constants( \WPConfigTransformer $config_transformer ) {
204 178 $predefined_constants = [];
205 179 foreach ( $this->defined_constants as $defined_constant ) {
206 180 if ( $config_transformer->exists( 'constant', strtoupper( $defined_constant ) ) ) {
207 181 $value = $config_transformer->get_value( 'constant', strtoupper( $defined_constant ) );
208 - $predefined_constants[ $defined_constant ]['value'] = $value;
182 + $value = trim( $value, '"\'' ); // Normalize quoted value.
183 +
184 + $predefined_constants[ $defined_constant ] = $value;
209 185 }
210 186 }
211 187 update_site_option( 'wp_debugging_restore', $predefined_constants );
212 188 }
@@ -213,11 +189,19 @@
213 189
214 190 /**
215 191 * Restore pre-activation constants to `wp-config.php`.
216 192 *
193 + * @param \WPConfigTransformer $config_transformer
194 + *
217 195 * @return void
218 196 */
219 - private function restore_pre_activation_constants() {
197 + private function restore_pre_activation_constants( \WPConfigTransformer $config_transformer ) {
220 198 $restore_constants = get_site_option( 'wp_debugging_restore' );
221 - ( 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 + }
222 206 }
223 207 }