@@ -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,7 +64,7 @@ discard block |
||
| 64 | 64 | public function __construct() { |
| 65 | 65 | |
| 66 | 66 | // Handle 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(); |
@@ -73,16 +73,16 @@ discard block |
||
| 73 | 73 | $this->set_admin(); |
| 74 | 74 | |
| 75 | 75 | // Bail out if PHP Console can't be found. |
| 76 | - if ( ! class_exists( 'PhpConsole\Connector' ) ) { |
|
| 76 | + if ( ! class_exists('PhpConsole\Connector')) { |
|
| 77 | 77 | return; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // Connect to PHP Console. |
| 81 | - add_action( 'init', array( $this, 'connect' ), -100 ); |
|
| 81 | + add_action('init', array($this, 'connect'), -100); |
|
| 82 | 82 | |
| 83 | 83 | // Delay further PHP Console initialisation |
| 84 | 84 | // to have more context during Remote PHP execution. |
| 85 | - add_action( 'wp_loaded', array( $this, 'init' ), -100 ); |
|
| 85 | + add_action('wp_loaded', array($this, 'init'), -100); |
|
| 86 | 86 | |
| 87 | 87 | } |
| 88 | 88 | |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | load_plugin_textdomain( |
| 98 | 98 | 'wp-php-console', |
| 99 | 99 | false, |
| 100 | - dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' |
|
| 100 | + dirname(dirname(plugin_basename(__FILE__))).'/languages/' |
|
| 101 | 101 | ); |
| 102 | 102 | |
| 103 | 103 | } |
@@ -110,19 +110,19 @@ discard block |
||
| 110 | 110 | */ |
| 111 | 111 | private function set_admin() { |
| 112 | 112 | |
| 113 | - if ( ! defined( 'DOING_AJAX' ) && is_admin() ) { |
|
| 113 | + if ( ! defined('DOING_AJAX') && is_admin()) { |
|
| 114 | 114 | |
| 115 | 115 | // Add a settings link to the plugins admin screen. |
| 116 | - $plugin_name = str_replace( 'includes/class-', '', plugin_basename( __FILE__ ) ); |
|
| 117 | - add_filter( "plugin_action_links_{$plugin_name}", function( $actions ) { |
|
| 118 | - return array_merge( array( |
|
| 119 | - '<a href="' . esc_url( admin_url( 'options-general.php?page=wp-php-console' ) ) . '">' . __( 'Settings', 'wp-php-console' ) . '</a>', |
|
| 120 | - ), $actions ); |
|
| 116 | + $plugin_name = str_replace('includes/class-', '', plugin_basename(__FILE__)); |
|
| 117 | + add_filter("plugin_action_links_{$plugin_name}", function($actions) { |
|
| 118 | + return array_merge(array( |
|
| 119 | + '<a href="'.esc_url(admin_url('options-general.php?page=wp-php-console')).'">'.__('Settings', 'wp-php-console').'</a>', |
|
| 120 | + ), $actions); |
|
| 121 | 121 | } ); |
| 122 | 122 | |
| 123 | 123 | // Init settings. |
| 124 | - require_once __DIR__ . '/class-wp-php-console-settings.php'; |
|
| 125 | - new Settings( $this->options ); |
|
| 124 | + require_once __DIR__.'/class-wp-php-console-settings.php'; |
|
| 125 | + new Settings($this->options); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | } |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | |
| 138 | 138 | session_start(); |
| 139 | 139 | |
| 140 | - if ( ! $this->connector instanceof PhpConsole\Connector ) { |
|
| 140 | + if ( ! $this->connector instanceof PhpConsole\Connector) { |
|
| 141 | 141 | $this->connector = PhpConsole\Connector::getInstance(); |
| 142 | 142 | } |
| 143 | 143 | |
@@ -155,16 +155,16 @@ discard block |
||
| 155 | 155 | */ |
| 156 | 156 | protected function get_options() { |
| 157 | 157 | |
| 158 | - $options = get_option( 'wp_php_console', array() ); |
|
| 158 | + $options = get_option('wp_php_console', array()); |
|
| 159 | 159 | |
| 160 | - return wp_parse_args( $options, array( |
|
| 160 | + return wp_parse_args($options, array( |
|
| 161 | 161 | 'ip' => '', |
| 162 | 162 | 'password' => '', |
| 163 | 163 | 'register' => false, |
| 164 | 164 | 'short' => false, |
| 165 | 165 | 'ssl' => false, |
| 166 | 166 | 'stack' => false, |
| 167 | - ) ); |
|
| 167 | + )); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | |
@@ -176,31 +176,31 @@ discard block |
||
| 176 | 176 | private function apply_options() { |
| 177 | 177 | |
| 178 | 178 | // Bail out if not connected yet to PHP Console. |
| 179 | - if ( ! $this->connector instanceof PhpConsole\Connector ) { |
|
| 179 | + if ( ! $this->connector instanceof PhpConsole\Connector) { |
|
| 180 | 180 | return; |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | // Apply 'register' option to PHP Console... |
| 184 | - if ( true === $this->options['register'] && ! class_exists( 'PC', false ) ) { |
|
| 184 | + if (true === $this->options['register'] && ! class_exists('PC', false)) { |
|
| 185 | 185 | // ...only if PC not registered yet. |
| 186 | 186 | try { |
| 187 | 187 | PhpConsole\Helper::register(); |
| 188 | - } catch( \Exception $e ) { |
|
| 189 | - $this->print_notice_exception( $e ); |
|
| 188 | + } catch (\Exception $e) { |
|
| 189 | + $this->print_notice_exception($e); |
|
| 190 | 190 | } |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | // Apply 'stack' option to PHP Console. |
| 194 | - if ( true === $this->options['stack'] ) { |
|
| 194 | + if (true === $this->options['stack']) { |
|
| 195 | 195 | $this->connector->getDebugDispatcher()->detectTraceAndSource = true; |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | // Apply 'short' option to PHP Console. |
| 199 | - if ( true === $this->options['short'] ) { |
|
| 199 | + if (true === $this->options['short']) { |
|
| 200 | 200 | try { |
| 201 | - $this->connector->setSourcesBasePath( $_SERVER['DOCUMENT_ROOT'] ); |
|
| 202 | - } catch ( \Exception $e ) { |
|
| 203 | - $this->print_notice_exception( $e ); |
|
| 201 | + $this->connector->setSourcesBasePath($_SERVER['DOCUMENT_ROOT']); |
|
| 202 | + } catch (\Exception $e) { |
|
| 203 | + $this->print_notice_exception($e); |
|
| 204 | 204 | } |
| 205 | 205 | } |
| 206 | 206 | |
@@ -217,80 +217,80 @@ discard block |
||
| 217 | 217 | // Get PHP Console extension password. |
| 218 | 218 | $password = $this->options['password']; |
| 219 | 219 | |
| 220 | - if ( ! $password ) { |
|
| 220 | + if ( ! $password) { |
|
| 221 | 221 | // Display admin notice and abort if no password has been set. |
| 222 | - add_action( 'admin_notices', array( $this, 'password_notice' ) ); |
|
| 222 | + add_action('admin_notices', array($this, 'password_notice')); |
|
| 223 | 223 | return; |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | // Selectively remove slashes added by WordPress as expected by PhpConsole. |
| 227 | - if ( array_key_exists( PhpConsole\Connector::POST_VAR_NAME, $_POST ) ) { |
|
| 228 | - $_POST[ PhpConsole\Connector::POST_VAR_NAME ] = stripslashes_deep( $_POST[ PhpConsole\Connector::POST_VAR_NAME ] ); |
|
| 227 | + if (array_key_exists(PhpConsole\Connector::POST_VAR_NAME, $_POST)) { |
|
| 228 | + $_POST[PhpConsole\Connector::POST_VAR_NAME] = stripslashes_deep($_POST[PhpConsole\Connector::POST_VAR_NAME]); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | // Get PHP Console instance if wasn't set yet. |
| 232 | - if ( ! $this->connector instanceof PhpConsole\Connector ) { |
|
| 232 | + if ( ! $this->connector instanceof PhpConsole\Connector) { |
|
| 233 | 233 | $this->connector = PhpConsole\Connector::getInstance(); |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | // Set PHP Console password. |
| 237 | 237 | try { |
| 238 | - $this->connector->setPassword( $password ); |
|
| 239 | - } catch ( \Exception $e ) { |
|
| 240 | - $this->print_notice_exception( $e ); |
|
| 238 | + $this->connector->setPassword($password); |
|
| 239 | + } catch (\Exception $e) { |
|
| 240 | + $this->print_notice_exception($e); |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | // Get PHP Console handler instance. |
| 244 | 244 | $handler = PhpConsole\Handler::getInstance(); |
| 245 | 245 | |
| 246 | - if ( true !== PhpConsole\Handler::getInstance()->isStarted() ) { |
|
| 246 | + if (true !== PhpConsole\Handler::getInstance()->isStarted()) { |
|
| 247 | 247 | try { |
| 248 | 248 | $handler->start(); |
| 249 | - } catch( \Exception $e ) { |
|
| 250 | - $this->print_notice_exception( $e ); |
|
| 249 | + } catch (\Exception $e) { |
|
| 250 | + $this->print_notice_exception($e); |
|
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | // Enable SSL-only mode. |
| 255 | - if ( true === $this->options['ssl'] ) { |
|
| 255 | + if (true === $this->options['ssl']) { |
|
| 256 | 256 | $this->connector->enableSslOnlyMode(); |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | // Restrict IP addresses. |
| 260 | - $allowedIpMasks = ! empty( $this->options['ip'] ) ? explode( ',', $this->options['ip'] ) : ''; |
|
| 260 | + $allowedIpMasks = ! empty($this->options['ip']) ? explode(',', $this->options['ip']) : ''; |
|
| 261 | 261 | |
| 262 | - if ( is_array( $allowedIpMasks ) && count( $allowedIpMasks ) > 0 ) { |
|
| 263 | - $this->connector->setAllowedIpMasks( $allowedIpMasks ); |
|
| 262 | + if (is_array($allowedIpMasks) && count($allowedIpMasks) > 0) { |
|
| 263 | + $this->connector->setAllowedIpMasks($allowedIpMasks); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | $evalProvider = $this->connector->getEvalDispatcher()->getEvalProvider(); |
| 267 | 267 | |
| 268 | 268 | try { |
| 269 | - $evalProvider->addSharedVar( 'uri', $_SERVER['REQUEST_URI'] ); |
|
| 270 | - } catch ( \Exception $e ) { |
|
| 271 | - $this->print_notice_exception( $e ); |
|
| 269 | + $evalProvider->addSharedVar('uri', $_SERVER['REQUEST_URI']); |
|
| 270 | + } catch (\Exception $e) { |
|
| 271 | + $this->print_notice_exception($e); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | try { |
| 275 | - $evalProvider->addSharedVarReference( 'post', $_POST ); |
|
| 276 | - } catch ( \Exception $e ) { |
|
| 277 | - $this->print_notice_exception( $e ); |
|
| 275 | + $evalProvider->addSharedVarReference('post', $_POST); |
|
| 276 | + } catch (\Exception $e) { |
|
| 277 | + $this->print_notice_exception($e); |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | - $openBaseDirs = array( ABSPATH, get_template_directory() ); |
|
| 280 | + $openBaseDirs = array(ABSPATH, get_template_directory()); |
|
| 281 | 281 | |
| 282 | 282 | try { |
| 283 | - $evalProvider->addSharedVarReference( 'dirs', $openBaseDirs ); |
|
| 284 | - } catch ( \Exception $e ) { |
|
| 285 | - $this->print_notice_exception( $e ); |
|
| 283 | + $evalProvider->addSharedVarReference('dirs', $openBaseDirs); |
|
| 284 | + } catch (\Exception $e) { |
|
| 285 | + $this->print_notice_exception($e); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | - $evalProvider->setOpenBaseDirs( $openBaseDirs ); |
|
| 288 | + $evalProvider->setOpenBaseDirs($openBaseDirs); |
|
| 289 | 289 | |
| 290 | 290 | try { |
| 291 | 291 | $this->connector->startEvalRequestsListener(); |
| 292 | - } catch ( \Exception $e ) { |
|
| 293 | - $this->print_notice_exception( $e ); |
|
| 292 | + } catch (\Exception $e) { |
|
| 293 | + $this->print_notice_exception($e); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | } |
@@ -302,13 +302,13 @@ discard block |
||
| 302 | 302 | * @since 1.4.0 |
| 303 | 303 | * @param \Exception $e Exception object |
| 304 | 304 | */ |
| 305 | - public function print_notice_exception( \Exception $e ) { |
|
| 305 | + public function print_notice_exception(\Exception $e) { |
|
| 306 | 306 | |
| 307 | - add_action( 'admin_notices', function() use ( $e ) { |
|
| 307 | + add_action('admin_notices', function() use ($e) { |
|
| 308 | 308 | |
| 309 | 309 | ?> |
| 310 | 310 | <div class="error"> |
| 311 | - <p><?php printf( '%1$s: %2$s', self::NAME, $e->getMessage() ); ?></p> |
|
| 311 | + <p><?php printf('%1$s: %2$s', self::NAME, $e->getMessage()); ?></p> |
|
| 312 | 312 | </div> |
| 313 | 313 | <?php |
| 314 | 314 | |
@@ -329,9 +329,9 @@ discard block |
||
| 329 | 329 | <div class="update-nag"> |
| 330 | 330 | <p><?php |
| 331 | 331 | /* translators: Placeholders: %1$s - WP Php Console name, %2$s - opening HTML <a> link tag; %3$s closing HTML </a> link tag */ |
| 332 | - printf( __( '%1$s: Please remember to %2$sset a password%3$s if you want to enable the terminal.', 'wp-php-console' ), |
|
| 333 | - '<strong>' . self::NAME . '</strong>', |
|
| 334 | - '<a href="' . esc_url( admin_url( 'options-general.php?page=wp-php-console' ) ) .'">', |
|
| 332 | + printf(__('%1$s: Please remember to %2$sset a password%3$s if you want to enable the terminal.', 'wp-php-console'), |
|
| 333 | + '<strong>'.self::NAME.'</strong>', |
|
| 334 | + '<a href="'.esc_url(admin_url('options-general.php?page=wp-php-console')).'">', |
|
| 335 | 335 | '</a>' |
| 336 | 336 | ); ?> |
| 337 | 337 | </p> |