Completed
Push — master ( f36abb...807b52 )
by Fulvio
02:16
created
includes/class-wp-php-console.php 1 patch
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,11 +137,11 @@  discard block
 block discarded – undo
137 137
 
138 138
 		// PhpConsole needs to hook in session, in WordPress we need to be in 'init'
139 139
 		// @link http://silvermapleweb.com/using-the-php-session-in-wordpress/
140
-		if ( ! session_id() ) {
140
+		if ( ! session_id()) {
141 141
 			session_start();
142 142
 		}
143 143
 
144
-		if ( ! $this->connector instanceof PhpConsole\Connector ) {
144
+		if ( ! $this->connector instanceof PhpConsole\Connector) {
145 145
 			$this->connector = PhpConsole\Connector::getInstance();
146 146
 		}
147 147
 
@@ -159,16 +159,16 @@  discard block
 block discarded – undo
159 159
 	 */
160 160
 	protected function get_options() {
161 161
 
162
-		$options = get_option( 'wp_php_console', array() );
162
+		$options = get_option('wp_php_console', array());
163 163
 
164
-		return wp_parse_args( $options, array(
164
+		return wp_parse_args($options, array(
165 165
 			'ip'       => '',
166 166
 			'password' => '',
167 167
 			'register' => false,
168 168
 			'short'    => false,
169 169
 			'ssl'      => false,
170 170
 			'stack'    => false,
171
-		) );
171
+		));
172 172
 	}
173 173
 
174 174
 
@@ -180,31 +180,31 @@  discard block
 block discarded – undo
180 180
 	private function apply_options() {
181 181
 
182 182
 		// Bail out if not connected yet to PHP Console.
183
-		if ( ! $this->connector instanceof PhpConsole\Connector ) {
183
+		if ( ! $this->connector instanceof PhpConsole\Connector) {
184 184
 			return;
185 185
 		}
186 186
 
187 187
 		// Apply 'register' option to PHP Console...
188
-		if ( true === $this->options['register'] && ! class_exists( 'PC', false ) ) {
188
+		if (true === $this->options['register'] && ! class_exists('PC', false)) {
189 189
 			// ...only if PC not registered yet.
190 190
 			try {
191 191
 				PhpConsole\Helper::register();
192
-			} catch( \Exception $e ) {
193
-				$this->print_notice_exception( $e );
192
+			} catch (\Exception $e) {
193
+				$this->print_notice_exception($e);
194 194
 			}
195 195
 		}
196 196
 
197 197
 		// Apply 'stack' option to PHP Console.
198
-		if ( true === $this->options['stack'] ) {
198
+		if (true === $this->options['stack']) {
199 199
 			$this->connector->getDebugDispatcher()->detectTraceAndSource = true;
200 200
 		}
201 201
 
202 202
 		// Apply 'short' option to PHP Console.
203
-		if ( true === $this->options['short'] ) {
203
+		if (true === $this->options['short']) {
204 204
 			try {
205
-				$this->connector->setSourcesBasePath( $_SERVER['DOCUMENT_ROOT'] );
206
-			} catch ( \Exception $e ) {
207
-				$this->print_notice_exception( $e );
205
+				$this->connector->setSourcesBasePath($_SERVER['DOCUMENT_ROOT']);
206
+			} catch (\Exception $e) {
207
+				$this->print_notice_exception($e);
208 208
 			}
209 209
 		}
210 210
 
@@ -221,80 +221,80 @@  discard block
 block discarded – undo
221 221
 		// Get PHP Console extension password.
222 222
 		$password = $this->options['password'];
223 223
 
224
-		if ( ! $password ) {
224
+		if ( ! $password) {
225 225
 			// Display admin notice and abort if no password has been set.
226
-			add_action( 'admin_notices', array( $this, 'password_notice' ) );
226
+			add_action('admin_notices', array($this, 'password_notice'));
227 227
 			return;
228 228
 		}
229 229
 
230 230
 		// Selectively remove slashes added by WordPress as expected by PhpConsole.
231
-		if ( array_key_exists( PhpConsole\Connector::POST_VAR_NAME, $_POST ) ) {
232
-			$_POST[ PhpConsole\Connector::POST_VAR_NAME ] = stripslashes_deep( $_POST[ PhpConsole\Connector::POST_VAR_NAME ] );
231
+		if (array_key_exists(PhpConsole\Connector::POST_VAR_NAME, $_POST)) {
232
+			$_POST[PhpConsole\Connector::POST_VAR_NAME] = stripslashes_deep($_POST[PhpConsole\Connector::POST_VAR_NAME]);
233 233
 		}
234 234
 
235 235
 		// Get PHP Console instance if wasn't set yet.
236
-		if ( ! $this->connector instanceof PhpConsole\Connector ) {
236
+		if ( ! $this->connector instanceof PhpConsole\Connector) {
237 237
 			$this->connector = PhpConsole\Connector::getInstance();
238 238
 		}
239 239
 
240 240
 		// Set PHP Console password.
241 241
 		try {
242
-			$this->connector->setPassword( $password );
243
-		} catch ( \Exception $e ) {
244
-			$this->print_notice_exception( $e );
242
+			$this->connector->setPassword($password);
243
+		} catch (\Exception $e) {
244
+			$this->print_notice_exception($e);
245 245
 		}
246 246
 
247 247
 		// Get PHP Console handler instance.
248 248
 		$handler = PhpConsole\Handler::getInstance();
249 249
 
250
-		if ( true !== PhpConsole\Handler::getInstance()->isStarted() ) {
250
+		if (true !== PhpConsole\Handler::getInstance()->isStarted()) {
251 251
 			try {
252 252
 				$handler->start();
253
-			} catch( \Exception $e ) {
254
-				$this->print_notice_exception( $e );
253
+			} catch (\Exception $e) {
254
+				$this->print_notice_exception($e);
255 255
 			}
256 256
 		}
257 257
 
258 258
 		// Enable SSL-only mode.
259
-		if ( true === $this->options['ssl'] ) {
259
+		if (true === $this->options['ssl']) {
260 260
 			$this->connector->enableSslOnlyMode();
261 261
 		}
262 262
 
263 263
 		// Restrict IP addresses.
264
-		$allowedIpMasks = ! empty( $this->options['ip'] ) ? explode( ',', $this->options['ip'] ) : '';
264
+		$allowedIpMasks = ! empty($this->options['ip']) ? explode(',', $this->options['ip']) : '';
265 265
 
266
-		if ( is_array( $allowedIpMasks ) && count( $allowedIpMasks ) > 0 ) {
267
-			$this->connector->setAllowedIpMasks( $allowedIpMasks );
266
+		if (is_array($allowedIpMasks) && count($allowedIpMasks) > 0) {
267
+			$this->connector->setAllowedIpMasks($allowedIpMasks);
268 268
 		}
269 269
 
270 270
 		$evalProvider = $this->connector->getEvalDispatcher()->getEvalProvider();
271 271
 
272 272
 		try {
273
-			$evalProvider->addSharedVar( 'uri', $_SERVER['REQUEST_URI'] );
274
-		} catch ( \Exception $e ) {
275
-			$this->print_notice_exception( $e );
273
+			$evalProvider->addSharedVar('uri', $_SERVER['REQUEST_URI']);
274
+		} catch (\Exception $e) {
275
+			$this->print_notice_exception($e);
276 276
 		}
277 277
 
278 278
 		try {
279
-			$evalProvider->addSharedVarReference( 'post', $_POST );
280
-		} catch ( \Exception $e ) {
281
-			$this->print_notice_exception( $e );
279
+			$evalProvider->addSharedVarReference('post', $_POST);
280
+		} catch (\Exception $e) {
281
+			$this->print_notice_exception($e);
282 282
 		}
283 283
 
284
-		$openBaseDirs = array( ABSPATH, get_template_directory() );
284
+		$openBaseDirs = array(ABSPATH, get_template_directory());
285 285
 
286 286
 		try {
287
-			$evalProvider->addSharedVarReference( 'dirs', $openBaseDirs );
288
-		} catch ( \Exception $e ) {
289
-			$this->print_notice_exception( $e );
287
+			$evalProvider->addSharedVarReference('dirs', $openBaseDirs);
288
+		} catch (\Exception $e) {
289
+			$this->print_notice_exception($e);
290 290
 		}
291 291
 
292
-		$evalProvider->setOpenBaseDirs( $openBaseDirs );
292
+		$evalProvider->setOpenBaseDirs($openBaseDirs);
293 293
 
294 294
 		try {
295 295
 			$this->connector->startEvalRequestsListener();
296
-		} catch ( \Exception $e ) {
297
-			$this->print_notice_exception( $e );
296
+		} catch (\Exception $e) {
297
+			$this->print_notice_exception($e);
298 298
 		}
299 299
 
300 300
 	}
@@ -306,13 +306,13 @@  discard block
 block discarded – undo
306 306
 	 * @since 1.4.0
307 307
 	 * @param \Exception $e Exception object
308 308
 	 */
309
-	public function print_notice_exception( \Exception $e ) {
309
+	public function print_notice_exception(\Exception $e) {
310 310
 
311
-		add_action( 'admin_notices', function() use ( $e ) {
311
+		add_action('admin_notices', function() use ($e) {
312 312
 
313 313
 			?>
314 314
 			<div class="error">
315
-				<p><?php printf( '%1$s: %2$s', self::NAME, $e->getMessage() ); ?></p>
315
+				<p><?php printf('%1$s: %2$s', self::NAME, $e->getMessage()); ?></p>
316 316
 			</div>
317 317
 			<?php
318 318
 
@@ -333,9 +333,9 @@  discard block
 block discarded – undo
333 333
 		<div class="update-nag">
334 334
 			<p><?php
335 335
 			/* translators: Placeholders: %1$s - WP Php Console name, %2$s - opening HTML <a> link tag; %3$s closing HTML </a> link tag */
336
-			printf( __( '%1$s: Please remember to %2$sset a password%3$s if you want to enable the terminal.', 'wp-php-console' ),
337
-				'<strong>' . self::NAME . '</strong>',
338
-				'<a href="' . esc_url( admin_url( 'options-general.php?page=wp-php-console' ) ) .'">',
336
+			printf(__('%1$s: Please remember to %2$sset a password%3$s if you want to enable the terminal.', 'wp-php-console'),
337
+				'<strong>'.self::NAME.'</strong>',
338
+				'<a href="'.esc_url(admin_url('options-general.php?page=wp-php-console')).'">',
339 339
 				'</a>'
340 340
 			); ?>
341 341
 			</p>
Please login to merge, or discard this patch.