@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | use PhpConsole; |
| 12 | 12 | |
| 13 | -defined( 'ABSPATH' ) or exit; |
|
| 13 | +defined('ABSPATH') or exit; |
|
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * WP PHP Console main class. |
@@ -64,43 +64,43 @@ discard block |
||
| 64 | 64 | public function __construct() { |
| 65 | 65 | |
| 66 | 66 | // Translations. |
| 67 | - add_action( 'plugins_loaded', array( $this, 'set_locale' ) ); |
|
| 67 | + add_action('plugins_loaded', array($this, 'set_locale')); |
|
| 68 | 68 | |
| 69 | 69 | // Set options. |
| 70 | 70 | $this->options = $this->get_options(); |
| 71 | 71 | |
| 72 | 72 | // Load admin. |
| 73 | - if ( ! defined( 'DOING_AJAX' ) && is_admin() ) { |
|
| 73 | + if ( ! defined('DOING_AJAX') && is_admin()) { |
|
| 74 | 74 | |
| 75 | 75 | // Add a settings link to the plugins admin screen. |
| 76 | - $plugin_name = str_replace( 'includes/class-', '', plugin_basename( __FILE__ ) ); |
|
| 77 | - add_filter( "plugin_action_links_{$plugin_name}", function( $actions ) { |
|
| 78 | - return array_merge( array( |
|
| 79 | - '<a href="' . esc_url( admin_url( 'options-general.php?page=wp-php-console' ) ) . '">' . __( 'Settings', 'wp-php-console' ) . '</a>', |
|
| 80 | - ), $actions ); |
|
| 76 | + $plugin_name = str_replace('includes/class-', '', plugin_basename(__FILE__)); |
|
| 77 | + add_filter("plugin_action_links_{$plugin_name}", function($actions) { |
|
| 78 | + return array_merge(array( |
|
| 79 | + '<a href="'.esc_url(admin_url('options-general.php?page=wp-php-console')).'">'.__('Settings', 'wp-php-console').'</a>', |
|
| 80 | + ), $actions); |
|
| 81 | 81 | } ); |
| 82 | 82 | |
| 83 | - require_once __DIR__ . '/class-wp-php-console-settings.php'; |
|
| 84 | - new Settings( $this->options ); |
|
| 83 | + require_once __DIR__.'/class-wp-php-console-settings.php'; |
|
| 84 | + new Settings($this->options); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | // Bail out if PHP Console can't be found. |
| 88 | - if ( ! class_exists( 'PhpConsole\Connector' ) ) { |
|
| 88 | + if ( ! class_exists('PhpConsole\Connector')) { |
|
| 89 | 89 | return; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | // Connect to PHP Console. |
| 93 | - add_action( 'init', function() { |
|
| 93 | + add_action('init', function() { |
|
| 94 | 94 | |
| 95 | 95 | $this->connect(); |
| 96 | 96 | |
| 97 | 97 | // Apply PHP Console options. |
| 98 | 98 | $this->apply_options(); |
| 99 | 99 | |
| 100 | - }, -100 ); |
|
| 100 | + }, -100); |
|
| 101 | 101 | |
| 102 | 102 | // Delay further PHP Console initialisation to have more context during Remote PHP execution. |
| 103 | - add_action( 'wp_loaded', array( $this, 'init' ), -100 ); |
|
| 103 | + add_action('wp_loaded', array($this, 'init'), -100); |
|
| 104 | 104 | |
| 105 | 105 | } |
| 106 | 106 | |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | load_plugin_textdomain( |
| 116 | 116 | 'wp-php-console', |
| 117 | 117 | false, |
| 118 | - dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' |
|
| 118 | + dirname(dirname(plugin_basename(__FILE__))).'/languages/' |
|
| 119 | 119 | ); |
| 120 | 120 | |
| 121 | 121 | } |
@@ -133,15 +133,15 @@ discard block |
||
| 133 | 133 | // But there is some problem with frameworks like WordPress that override PHP session handler. |
| 134 | 134 | // PHP Console has alternative storage drivers for this - we will write to a temporary file: |
| 135 | 135 | |
| 136 | - $phpcdir = __DIR__ . '/tmp'; |
|
| 137 | - $make_dir = wp_mkdir_p( $phpcdir ); |
|
| 136 | + $phpcdir = __DIR__.'/tmp'; |
|
| 137 | + $make_dir = wp_mkdir_p($phpcdir); |
|
| 138 | 138 | |
| 139 | - if ( true === $make_dir ) { |
|
| 139 | + if (true === $make_dir) { |
|
| 140 | 140 | |
| 141 | 141 | try { |
| 142 | - $storage = new PhpConsole\Storage\File( $phpcdir . '/' . md5( __FILE__ ) . '_pc.data' ); |
|
| 143 | - PhpConsole\Connector::setPostponeStorage( $storage ); |
|
| 144 | - } catch( \Exception $e ) { |
|
| 142 | + $storage = new PhpConsole\Storage\File($phpcdir.'/'.md5(__FILE__).'_pc.data'); |
|
| 143 | + PhpConsole\Connector::setPostponeStorage($storage); |
|
| 144 | + } catch (\Exception $e) { |
|
| 145 | 145 | // PHP Console will complain about this: "Path <...> is under DOCUMENT_ROOT. It's insecure!" |
| 146 | 146 | // but there's nothing we can do at the moment as there doesn't seem to be another solution in WP |
| 147 | 147 | // nevertheless PHP Console tool is not meant to be used in production so this shouldn't be a concern |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | |
| 153 | 153 | // Perform PHP Console initialisation required asap |
| 154 | 154 | // for other code to be able to output to the JavaScript console. |
| 155 | - if ( ! $this->connector instanceof PhpConsole\Connector ) { |
|
| 155 | + if ( ! $this->connector instanceof PhpConsole\Connector) { |
|
| 156 | 156 | $this->connector = PhpConsole\Connector::getInstance(); |
| 157 | 157 | } |
| 158 | 158 | |
@@ -167,16 +167,16 @@ discard block |
||
| 167 | 167 | */ |
| 168 | 168 | protected function get_options() { |
| 169 | 169 | |
| 170 | - $options = get_option( 'wp_php_console', array() ); |
|
| 170 | + $options = get_option('wp_php_console', array()); |
|
| 171 | 171 | |
| 172 | - return wp_parse_args( $options, array( |
|
| 172 | + return wp_parse_args($options, array( |
|
| 173 | 173 | 'ip' => '', |
| 174 | 174 | 'password' => '', |
| 175 | 175 | 'register' => false, |
| 176 | 176 | 'short' => false, |
| 177 | 177 | 'ssl' => false, |
| 178 | 178 | 'stack' => false, |
| 179 | - ) ); |
|
| 179 | + )); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | |
@@ -188,31 +188,31 @@ discard block |
||
| 188 | 188 | private function apply_options() { |
| 189 | 189 | |
| 190 | 190 | // Bail out if not connected yet to PHP Console. |
| 191 | - if ( ! $this->connector instanceof PhpConsole\Connector ) { |
|
| 191 | + if ( ! $this->connector instanceof PhpConsole\Connector) { |
|
| 192 | 192 | return; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | // Apply 'register' option to PHP Console... |
| 196 | - if ( true === $this->options['register'] && ! class_exists( 'PC', false ) ) { |
|
| 196 | + if (true === $this->options['register'] && ! class_exists('PC', false)) { |
|
| 197 | 197 | // ...only if PC not registered yet. |
| 198 | 198 | try { |
| 199 | 199 | PhpConsole\Helper::register(); |
| 200 | - } catch( \Exception $e ) { |
|
| 201 | - $this->print_notice_exception( $e ); |
|
| 200 | + } catch (\Exception $e) { |
|
| 201 | + $this->print_notice_exception($e); |
|
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | // Apply 'stack' option to PHP Console. |
| 206 | - if ( true === $this->options['stack'] ) { |
|
| 206 | + if (true === $this->options['stack']) { |
|
| 207 | 207 | $this->connector->getDebugDispatcher()->detectTraceAndSource = true; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | // Apply 'short' option to PHP Console. |
| 211 | - if ( true === $this->options['short'] ) { |
|
| 211 | + if (true === $this->options['short']) { |
|
| 212 | 212 | try { |
| 213 | - $this->connector->setSourcesBasePath( $_SERVER['DOCUMENT_ROOT'] ); |
|
| 214 | - } catch ( \Exception $e ) { |
|
| 215 | - $this->print_notice_exception( $e ); |
|
| 213 | + $this->connector->setSourcesBasePath($_SERVER['DOCUMENT_ROOT']); |
|
| 214 | + } catch (\Exception $e) { |
|
| 215 | + $this->print_notice_exception($e); |
|
| 216 | 216 | } |
| 217 | 217 | } |
| 218 | 218 | |
@@ -229,80 +229,80 @@ discard block |
||
| 229 | 229 | // Get PHP Console extension password. |
| 230 | 230 | $password = $this->options['password']; |
| 231 | 231 | |
| 232 | - if ( ! $password ) { |
|
| 232 | + if ( ! $password) { |
|
| 233 | 233 | // Display admin notice and abort if no password has been set. |
| 234 | - add_action( 'admin_notices', array( $this, 'password_notice' ) ); |
|
| 234 | + add_action('admin_notices', array($this, 'password_notice')); |
|
| 235 | 235 | return; |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | // Selectively remove slashes added by WordPress as expected by PhpConsole. |
| 239 | - if ( array_key_exists( PhpConsole\Connector::POST_VAR_NAME, $_POST ) ) { |
|
| 240 | - $_POST[ PhpConsole\Connector::POST_VAR_NAME ] = stripslashes_deep( $_POST[ PhpConsole\Connector::POST_VAR_NAME ] ); |
|
| 239 | + if (array_key_exists(PhpConsole\Connector::POST_VAR_NAME, $_POST)) { |
|
| 240 | + $_POST[PhpConsole\Connector::POST_VAR_NAME] = stripslashes_deep($_POST[PhpConsole\Connector::POST_VAR_NAME]); |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | // Get PHP Console instance if wasn't set yet. |
| 244 | - if ( ! $this->connector instanceof PhpConsole\Connector ) { |
|
| 244 | + if ( ! $this->connector instanceof PhpConsole\Connector) { |
|
| 245 | 245 | $this->connector = PhpConsole\Connector::getInstance(); |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | // Set PHP Console password. |
| 249 | 249 | try { |
| 250 | - $this->connector->setPassword( $password ); |
|
| 251 | - } catch ( \Exception $e ) { |
|
| 252 | - $this->print_notice_exception( $e ); |
|
| 250 | + $this->connector->setPassword($password); |
|
| 251 | + } catch (\Exception $e) { |
|
| 252 | + $this->print_notice_exception($e); |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | // Get PHP Console handler instance. |
| 256 | 256 | $handler = PhpConsole\Handler::getInstance(); |
| 257 | 257 | |
| 258 | - if ( true !== PhpConsole\Handler::getInstance()->isStarted() ) { |
|
| 258 | + if (true !== PhpConsole\Handler::getInstance()->isStarted()) { |
|
| 259 | 259 | try { |
| 260 | 260 | $handler->start(); |
| 261 | - } catch( \Exception $e ) { |
|
| 262 | - $this->print_notice_exception( $e ); |
|
| 261 | + } catch (\Exception $e) { |
|
| 262 | + $this->print_notice_exception($e); |
|
| 263 | 263 | } |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | // Enable SSL-only mode. |
| 267 | - if ( true === $this->options['ssl'] ) { |
|
| 267 | + if (true === $this->options['ssl']) { |
|
| 268 | 268 | $this->connector->enableSslOnlyMode(); |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | // Restrict IP addresses. |
| 272 | - $allowedIpMasks = ! empty( $this->options['ip'] ) ? explode( ',', $this->options['ip'] ) : ''; |
|
| 272 | + $allowedIpMasks = ! empty($this->options['ip']) ? explode(',', $this->options['ip']) : ''; |
|
| 273 | 273 | |
| 274 | - if ( is_array( $allowedIpMasks ) && count( $allowedIpMasks ) > 0 ) { |
|
| 275 | - $this->connector->setAllowedIpMasks( $allowedIpMasks ); |
|
| 274 | + if (is_array($allowedIpMasks) && count($allowedIpMasks) > 0) { |
|
| 275 | + $this->connector->setAllowedIpMasks($allowedIpMasks); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | $evalProvider = $this->connector->getEvalDispatcher()->getEvalProvider(); |
| 279 | 279 | |
| 280 | 280 | try { |
| 281 | - $evalProvider->addSharedVar( 'uri', $_SERVER['REQUEST_URI'] ); |
|
| 282 | - } catch ( \Exception $e ) { |
|
| 283 | - $this->print_notice_exception( $e ); |
|
| 281 | + $evalProvider->addSharedVar('uri', $_SERVER['REQUEST_URI']); |
|
| 282 | + } catch (\Exception $e) { |
|
| 283 | + $this->print_notice_exception($e); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | try { |
| 287 | - $evalProvider->addSharedVarReference( 'post', $_POST ); |
|
| 288 | - } catch ( \Exception $e ) { |
|
| 289 | - $this->print_notice_exception( $e ); |
|
| 287 | + $evalProvider->addSharedVarReference('post', $_POST); |
|
| 288 | + } catch (\Exception $e) { |
|
| 289 | + $this->print_notice_exception($e); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - $openBaseDirs = array( ABSPATH, get_template_directory() ); |
|
| 292 | + $openBaseDirs = array(ABSPATH, get_template_directory()); |
|
| 293 | 293 | |
| 294 | 294 | try { |
| 295 | - $evalProvider->addSharedVarReference( 'dirs', $openBaseDirs ); |
|
| 296 | - } catch ( \Exception $e ) { |
|
| 297 | - $this->print_notice_exception( $e ); |
|
| 295 | + $evalProvider->addSharedVarReference('dirs', $openBaseDirs); |
|
| 296 | + } catch (\Exception $e) { |
|
| 297 | + $this->print_notice_exception($e); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - $evalProvider->setOpenBaseDirs( $openBaseDirs ); |
|
| 300 | + $evalProvider->setOpenBaseDirs($openBaseDirs); |
|
| 301 | 301 | |
| 302 | 302 | try { |
| 303 | 303 | $this->connector->startEvalRequestsListener(); |
| 304 | - } catch ( \Exception $e ) { |
|
| 305 | - $this->print_notice_exception( $e ); |
|
| 304 | + } catch (\Exception $e) { |
|
| 305 | + $this->print_notice_exception($e); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | } |
@@ -314,13 +314,13 @@ discard block |
||
| 314 | 314 | * @since 1.4.0 |
| 315 | 315 | * @param \Exception $e Exception object |
| 316 | 316 | */ |
| 317 | - public function print_notice_exception( \Exception $e ) { |
|
| 317 | + public function print_notice_exception(\Exception $e) { |
|
| 318 | 318 | |
| 319 | - add_action( 'admin_notices', function() use ( $e ) { |
|
| 319 | + add_action('admin_notices', function() use ($e) { |
|
| 320 | 320 | |
| 321 | 321 | ?> |
| 322 | 322 | <div class="error"> |
| 323 | - <p><?php printf( '%1$s: %2$s', self::NAME, $e->getMessage() ); ?></p> |
|
| 323 | + <p><?php printf('%1$s: %2$s', self::NAME, $e->getMessage()); ?></p> |
|
| 324 | 324 | </div> |
| 325 | 325 | <?php |
| 326 | 326 | |
@@ -341,9 +341,9 @@ discard block |
||
| 341 | 341 | <div class="update-nag"> |
| 342 | 342 | <p><?php |
| 343 | 343 | /* translators: Placeholders: %1$s - WP Php Console name, %2$s - opening HTML <a> link tag; %3$s closing HTML </a> link tag */ |
| 344 | - printf( __( '%1$s: Please remember to %2$sset a password%3$s if you want to enable the terminal.', 'wp-php-console' ), |
|
| 345 | - '<strong>' . self::NAME . '</strong>', |
|
| 346 | - '<a href="' . esc_url( admin_url( 'options-general.php?page=wp-php-console' ) ) .'">', |
|
| 344 | + printf(__('%1$s: Please remember to %2$sset a password%3$s if you want to enable the terminal.', 'wp-php-console'), |
|
| 345 | + '<strong>'.self::NAME.'</strong>', |
|
| 346 | + '<a href="'.esc_url(admin_url('options-general.php?page=wp-php-console')).'">', |
|
| 347 | 347 | '</a>' |
| 348 | 348 | ); ?> |
| 349 | 349 | </p> |