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/Bootstrap.php +22 -27 trunk2.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 Bootstrap
19 14 */
20 15 class Bootstrap {
@@ -63,9 +58,9 @@
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 ); // phpcs:ignore WordPress.PHP.IniSet.display_errors_Blacklisted
68 63 }
69 64
70 65 /**
71 66 * Test for writable wp-config.php, exit with notice if not available.
@@ -72,19 +67,8 @@
72 67 *
73 68 * @return bool|void
74 69 */
75 70 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 71 if ( ! is_writable( self::$config_path ) ) {
88 72 echo '<div class="error notice is-dismissible"><p>';
89 73 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 74 echo '</p></div>';
@@ -90,10 +74,14 @@
90 74 echo '</p></div>';
91 75
92 76 return false;
93 77 }
78 + if ( ! \file_exists( self::$config_path ) || ! trim( \file_get_contents( self::$config_path ) ) ) {
79 + return;
80 + }
94 81
95 82 $this->load_hooks();
83 + \WP_Dependency_Installer::instance()->run( $this->dir );
96 84 }
97 85
98 86 /**
99 87 * Get the `wp-config.php` file path.
@@ -107,9 +95,8 @@
107 95 public function get_config_path() {
108 96 $config_path = ABSPATH . 'wp-config.php';
109 97
110 98 if ( ! file_exists( $config_path ) ) {
111 - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
112 99 if ( @file_exists( dirname( ABSPATH ) . '/wp-config.php' ) && ! @file_exists( dirname( ABSPATH ) . '/wp-settings.php' ) ) {
113 100 $config_path = dirname( ABSPATH ) . '/wp-config.php';
114 101 }
115 102 }
@@ -130,15 +117,21 @@
130 117 * @return void
131 118 */
132 119 public function load_hooks() {
133 120 add_action(
134 - 'plugins_loaded',
135 - function () {
121 + 'init',
122 + function() {
136 123 ( new Settings( self::$options, self::$config_path, $this->defined_constants ) )
137 124 ->load_hooks()
138 125 ->process_filter_constants();
139 126 }
140 127 );
128 + add_action(
129 + 'init',
130 + function () {
131 + load_plugin_textdomain( 'wp-debugging' );
132 + }
133 + );
141 134 add_filter(
142 135 'wp_dependency_timeout',
143 136 function ( $timeout, $source ) {
144 137 $timeout = basename( $this->dir ) !== $source ? $timeout : 45;
@@ -147,14 +140,11 @@
147 140 },
148 141 10,
149 142 2
150 143 );
151 - add_action(
152 - 'plugins_loaded',
153 - function () {
154 - \WP_Dependency_Installer::instance()->run( $this->dir );
155 - }
156 - );
144 +
145 + register_activation_hook( $this->file, [ $this, 'activate' ] );
146 + register_deactivation_hook( $this->file, [ $this, 'deactivate' ] );
157 147 }
158 148
159 149 /**
160 150 * Run on activation.
@@ -185,9 +175,9 @@
185 175 */
186 176 public function deactivate() {
187 177 $restore_constants = get_site_option( 'wp_debugging_restore' );
188 178 $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 ) );
179 + $remove_constants = array_diff( array_flip( $this->defined_constants ), array_keys( $restore_constants ) );
190 180 $remove_constants = array_merge( $remove_constants, $remove_user_added );
191 181
192 182 ( new Settings( self::$options, self::$config_path, $this->defined_constants ) )->remove_constants( $remove_constants );
193 183
@@ -199,13 +189,18 @@
199 189 *
200 190 * @return void
201 191 */
202 192 private function set_pre_activation_constants() {
193 + if ( ! \file_exists( self::$config_path ) || ! trim( \file_get_contents( self::$config_path ) ) ) {
194 + return;
195 + }
203 196 $config_transformer = new \WPConfigTransformer( self::$config_path );
204 197 $predefined_constants = [];
205 198 foreach ( $this->defined_constants as $defined_constant ) {
206 199 if ( $config_transformer->exists( 'constant', strtoupper( $defined_constant ) ) ) {
207 200 $value = $config_transformer->get_value( 'constant', strtoupper( $defined_constant ) );
201 + $value = trim( $value, '"\'' ); // Normalize quoted value.
202 +
208 203 $predefined_constants[ $defined_constant ]['value'] = $value;
209 204 }
210 205 }
211 206 update_site_option( 'wp_debugging_restore', $predefined_constants );