@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | use PhpConsole; |
6 | 6 | |
7 | -defined( 'ABSPATH' ) or exit; |
|
7 | +defined('ABSPATH') or exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * WP PHP Console main class. |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | public function __construct() { |
37 | 37 | |
38 | 38 | // handle translations |
39 | - add_action( 'plugins_loaded', [ $this, 'set_locale' ] ); |
|
39 | + add_action('plugins_loaded', [$this, 'set_locale']); |
|
40 | 40 | |
41 | 41 | // set options |
42 | 42 | $this->options = $this->get_options(); |
@@ -45,14 +45,14 @@ discard block |
||
45 | 45 | $this->set_admin(); |
46 | 46 | |
47 | 47 | // bail out if PHP Console can't be found |
48 | - if ( ! class_exists( 'PhpConsole\Connector' ) ) { |
|
48 | + if ( ! class_exists('PhpConsole\Connector')) { |
|
49 | 49 | return; |
50 | 50 | } |
51 | 51 | |
52 | 52 | // connect to PHP Console |
53 | - add_action( 'init', [ $this, 'connect' ], -1000 ); |
|
53 | + add_action('init', [$this, 'connect'], -1000); |
|
54 | 54 | // delay further PHP Console initialisation to have more context during Remote PHP execution |
55 | - add_action( 'wp_loaded', [ $this, 'init' ], -1000 ); |
|
55 | + add_action('wp_loaded', [$this, 'init'], -1000); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | load_plugin_textdomain( |
67 | 67 | 'wp-php-console', |
68 | 68 | false, |
69 | - dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' |
|
69 | + dirname(dirname(plugin_basename(__FILE__))).'/languages/' |
|
70 | 70 | ); |
71 | 71 | } |
72 | 72 | |
@@ -78,20 +78,20 @@ discard block |
||
78 | 78 | */ |
79 | 79 | private function set_admin() { |
80 | 80 | |
81 | - if ( ! defined( 'DOING_AJAX' ) && is_admin() ) { |
|
81 | + if ( ! defined('DOING_AJAX') && is_admin()) { |
|
82 | 82 | |
83 | 83 | // add a settings link to the plugins admin screen |
84 | - $plugin_name = str_replace( 'includes/class-', '', plugin_basename( __FILE__ ) ); |
|
85 | - add_filter( "plugin_action_links_{$plugin_name}", static function( $actions ) { |
|
86 | - return array_merge( [ |
|
87 | - '<a href="' . esc_url( admin_url( 'options-general.php?page=wp-php-console' ) ) . '">' . __( 'Settings', 'wp-php-console' ) . '</a>', |
|
88 | - ], $actions ); |
|
84 | + $plugin_name = str_replace('includes/class-', '', plugin_basename(__FILE__)); |
|
85 | + add_filter("plugin_action_links_{$plugin_name}", static function($actions) { |
|
86 | + return array_merge([ |
|
87 | + '<a href="'.esc_url(admin_url('options-general.php?page=wp-php-console')).'">'.__('Settings', 'wp-php-console').'</a>', |
|
88 | + ], $actions); |
|
89 | 89 | } ); |
90 | 90 | |
91 | 91 | // init settings |
92 | - require_once __DIR__ . '/class-wp-php-console-settings.php'; |
|
92 | + require_once __DIR__.'/class-wp-php-console-settings.php'; |
|
93 | 93 | |
94 | - new Settings( $this->options ); |
|
94 | + new Settings($this->options); |
|
95 | 95 | } |
96 | 96 | } |
97 | 97 | |
@@ -108,22 +108,22 @@ discard block |
||
108 | 108 | public function connect() { |
109 | 109 | |
110 | 110 | // workaround for avoiding headers already sent warnings |
111 | - @error_reporting( E_ALL & ~E_WARNING ); |
|
111 | + @error_reporting(E_ALL & ~E_WARNING); |
|
112 | 112 | |
113 | - if ( empty( @session_id() ) ) { |
|
113 | + if (empty(@session_id())) { |
|
114 | 114 | @session_start(); |
115 | 115 | } |
116 | 116 | |
117 | - if ( ! $this->connector instanceof PhpConsole\Connector ) { |
|
117 | + if ( ! $this->connector instanceof PhpConsole\Connector) { |
|
118 | 118 | try { |
119 | 119 | $this->connector = PhpConsole\Connector::getInstance(); |
120 | - } catch ( \Exception $e ) { |
|
120 | + } catch (\Exception $e) { |
|
121 | 121 | return; |
122 | 122 | } |
123 | 123 | } |
124 | 124 | |
125 | 125 | // restore error reporting |
126 | - @error_reporting( E_ALL ); |
|
126 | + @error_reporting(E_ALL); |
|
127 | 127 | |
128 | 128 | // apply PHP Console options |
129 | 129 | $this->apply_options(); |
@@ -139,16 +139,16 @@ discard block |
||
139 | 139 | */ |
140 | 140 | protected function get_options() { |
141 | 141 | |
142 | - $options = get_option( 'wp_php_console', [] ); |
|
142 | + $options = get_option('wp_php_console', []); |
|
143 | 143 | |
144 | - return wp_parse_args( $options, [ |
|
144 | + return wp_parse_args($options, [ |
|
145 | 145 | 'ip' => '', |
146 | 146 | 'password' => '', |
147 | 147 | 'register' => false, |
148 | 148 | 'short' => false, |
149 | 149 | 'ssl' => false, |
150 | 150 | 'stack' => false, |
151 | - ] ); |
|
151 | + ]); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | |
@@ -160,31 +160,31 @@ discard block |
||
160 | 160 | private function apply_options() { |
161 | 161 | |
162 | 162 | // bail out if not connected yet to PHP Console |
163 | - if ( ! $this->connector instanceof PhpConsole\Connector ) { |
|
163 | + if ( ! $this->connector instanceof PhpConsole\Connector) { |
|
164 | 164 | return; |
165 | 165 | } |
166 | 166 | |
167 | 167 | // apply 'register' option to PHP Console... |
168 | - if ( true === $this->options['register'] && ! class_exists( 'PC', false ) ) { |
|
168 | + if (true === $this->options['register'] && ! class_exists('PC', false)) { |
|
169 | 169 | // ...only if PC not registered yet |
170 | 170 | try { |
171 | 171 | PhpConsole\Helper::register(); |
172 | - } catch( \Exception $e ) { |
|
173 | - $this->print_notice_exception( $e ); |
|
172 | + } catch (\Exception $e) { |
|
173 | + $this->print_notice_exception($e); |
|
174 | 174 | } |
175 | 175 | } |
176 | 176 | |
177 | 177 | // apply 'stack' option to PHP Console |
178 | - if ( true === $this->options['stack'] ) { |
|
178 | + if (true === $this->options['stack']) { |
|
179 | 179 | $this->connector->getDebugDispatcher()->detectTraceAndSource = true; |
180 | 180 | } |
181 | 181 | |
182 | 182 | // apply 'short' option to PHP Console |
183 | - if ( true === $this->options['short'] ) { |
|
183 | + if (true === $this->options['short']) { |
|
184 | 184 | try { |
185 | - $this->connector->setSourcesBasePath( $_SERVER['DOCUMENT_ROOT'] ); |
|
186 | - } catch ( \Exception $e ) { |
|
187 | - $this->print_notice_exception( $e ); |
|
185 | + $this->connector->setSourcesBasePath($_SERVER['DOCUMENT_ROOT']); |
|
186 | + } catch (\Exception $e) { |
|
187 | + $this->print_notice_exception($e); |
|
188 | 188 | } |
189 | 189 | } |
190 | 190 | } |
@@ -200,89 +200,89 @@ discard block |
||
200 | 200 | public function init() { |
201 | 201 | |
202 | 202 | // get PHP Console extension password |
203 | - $password = trim( $this->options['password'] ); |
|
203 | + $password = trim($this->options['password']); |
|
204 | 204 | |
205 | - if ( empty( $password ) ) { |
|
205 | + if (empty($password)) { |
|
206 | 206 | |
207 | 207 | // display admin notice and abort if no password has been set |
208 | - add_action( 'admin_notices', [ $this, 'password_notice' ] ); |
|
208 | + add_action('admin_notices', [$this, 'password_notice']); |
|
209 | 209 | return; |
210 | 210 | } |
211 | 211 | |
212 | 212 | // selectively remove slashes added by WordPress as expected by PHP Console |
213 | - if ( array_key_exists( PhpConsole\Connector::POST_VAR_NAME, $_POST ) ) { |
|
214 | - $_POST[ PhpConsole\Connector::POST_VAR_NAME ] = stripslashes_deep( $_POST[ PhpConsole\Connector::POST_VAR_NAME ] ); |
|
213 | + if (array_key_exists(PhpConsole\Connector::POST_VAR_NAME, $_POST)) { |
|
214 | + $_POST[PhpConsole\Connector::POST_VAR_NAME] = stripslashes_deep($_POST[PhpConsole\Connector::POST_VAR_NAME]); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | // get PHP Console instance if wasn't set yet |
218 | - if ( ! $this->connector instanceof PhpConsole\Connector ) { |
|
218 | + if ( ! $this->connector instanceof PhpConsole\Connector) { |
|
219 | 219 | |
220 | 220 | try { |
221 | 221 | $this->connector = PhpConsole\Connector::getInstance(); |
222 | - } catch ( \Exception $e ) { |
|
222 | + } catch (\Exception $e) { |
|
223 | 223 | return; |
224 | 224 | } |
225 | 225 | } |
226 | 226 | |
227 | 227 | // set PHP Console password |
228 | 228 | try { |
229 | - $this->connector->setPassword( $password ); |
|
230 | - } catch ( \Exception $e ) { |
|
231 | - $this->print_notice_exception( $e ); |
|
229 | + $this->connector->setPassword($password); |
|
230 | + } catch (\Exception $e) { |
|
231 | + $this->print_notice_exception($e); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | // get PHP Console handler instance |
235 | 235 | $handler = PhpConsole\Handler::getInstance(); |
236 | 236 | |
237 | - if ( true !== PhpConsole\Handler::getInstance()->isStarted() ) { |
|
237 | + if (true !== PhpConsole\Handler::getInstance()->isStarted()) { |
|
238 | 238 | try { |
239 | 239 | $handler->start(); |
240 | - } catch( \Exception $e ) { |
|
241 | - $this->print_notice_exception( $e ); |
|
240 | + } catch (\Exception $e) { |
|
241 | + $this->print_notice_exception($e); |
|
242 | 242 | return; |
243 | 243 | } |
244 | 244 | } |
245 | 245 | |
246 | 246 | // enable SSL-only mode |
247 | - if ( true === $this->options['ssl'] ) { |
|
247 | + if (true === $this->options['ssl']) { |
|
248 | 248 | $this->connector->enableSslOnlyMode(); |
249 | 249 | } |
250 | 250 | |
251 | 251 | // restrict IP addresses |
252 | - $allowedIpMasks = ! empty( $this->options['ip'] ) ? explode( ',', $this->options['ip'] ) : ''; |
|
252 | + $allowedIpMasks = ! empty($this->options['ip']) ? explode(',', $this->options['ip']) : ''; |
|
253 | 253 | |
254 | - if ( is_array( $allowedIpMasks ) && count( $allowedIpMasks ) > 0 ) { |
|
255 | - $this->connector->setAllowedIpMasks( $allowedIpMasks ); |
|
254 | + if (is_array($allowedIpMasks) && count($allowedIpMasks) > 0) { |
|
255 | + $this->connector->setAllowedIpMasks($allowedIpMasks); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | $evalProvider = $this->connector->getEvalDispatcher()->getEvalProvider(); |
259 | 259 | |
260 | 260 | try { |
261 | - $evalProvider->addSharedVar( 'uri', $_SERVER['REQUEST_URI'] ); |
|
262 | - } catch ( \Exception $e ) { |
|
263 | - $this->print_notice_exception( $e ); |
|
261 | + $evalProvider->addSharedVar('uri', $_SERVER['REQUEST_URI']); |
|
262 | + } catch (\Exception $e) { |
|
263 | + $this->print_notice_exception($e); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | try { |
267 | - $evalProvider->addSharedVarReference( 'post', $_POST ); |
|
268 | - } catch ( \Exception $e ) { |
|
269 | - $this->print_notice_exception( $e ); |
|
267 | + $evalProvider->addSharedVarReference('post', $_POST); |
|
268 | + } catch (\Exception $e) { |
|
269 | + $this->print_notice_exception($e); |
|
270 | 270 | } |
271 | 271 | |
272 | - $openBaseDirs = [ ABSPATH, get_template_directory() ]; |
|
272 | + $openBaseDirs = [ABSPATH, get_template_directory()]; |
|
273 | 273 | |
274 | 274 | try { |
275 | - $evalProvider->addSharedVarReference( 'dirs', $openBaseDirs ); |
|
276 | - } catch ( \Exception $e ) { |
|
277 | - $this->print_notice_exception( $e ); |
|
275 | + $evalProvider->addSharedVarReference('dirs', $openBaseDirs); |
|
276 | + } catch (\Exception $e) { |
|
277 | + $this->print_notice_exception($e); |
|
278 | 278 | } |
279 | 279 | |
280 | - $evalProvider->setOpenBaseDirs( $openBaseDirs ); |
|
280 | + $evalProvider->setOpenBaseDirs($openBaseDirs); |
|
281 | 281 | |
282 | 282 | try { |
283 | 283 | $this->connector->startEvalRequestsListener(); |
284 | - } catch ( \Exception $e ) { |
|
285 | - $this->print_notice_exception( $e ); |
|
284 | + } catch (\Exception $e) { |
|
285 | + $this->print_notice_exception($e); |
|
286 | 286 | } |
287 | 287 | } |
288 | 288 | |
@@ -294,13 +294,13 @@ discard block |
||
294 | 294 | * |
295 | 295 | * @param \Exception $e Exception object |
296 | 296 | */ |
297 | - public function print_notice_exception( \Exception $e ) { |
|
297 | + public function print_notice_exception(\Exception $e) { |
|
298 | 298 | |
299 | - add_action( 'admin_notices', static function() use ( $e ) { |
|
299 | + add_action('admin_notices', static function() use ($e) { |
|
300 | 300 | |
301 | 301 | ?> |
302 | 302 | <div class="error"> |
303 | - <p><?php printf( '%1$s: %2$s', self::NAME, $e->getMessage() ); ?></p> |
|
303 | + <p><?php printf('%1$s: %2$s', self::NAME, $e->getMessage()); ?></p> |
|
304 | 304 | </div> |
305 | 305 | <?php |
306 | 306 | |
@@ -324,9 +324,9 @@ discard block |
||
324 | 324 | <div class="update-nag"> |
325 | 325 | <p><?php printf( |
326 | 326 | /* translators: Placeholders: %1$s - WP Php Console name, %2$s - opening HTML <a> link tag; %3$s closing HTML </a> link tag */ |
327 | - __( '%1$s: Please remember to %2$sset a password%3$s if you want to enable the terminal.', 'wp-php-console' ), |
|
328 | - '<strong>' . self::NAME . '</strong>', |
|
329 | - '<a href="' . esc_url( admin_url( 'options-general.php?page=wp-php-console' ) ) .'">', |
|
327 | + __('%1$s: Please remember to %2$sset a password%3$s if you want to enable the terminal.', 'wp-php-console'), |
|
328 | + '<strong>'.self::NAME.'</strong>', |
|
329 | + '<a href="'.esc_url(admin_url('options-general.php?page=wp-php-console')).'">', |
|
330 | 330 | '</a>' |
331 | 331 | ); ?></p> |
332 | 332 | </div> |