@@ -58,18 +58,26 @@ public function __construct() {
5858 $ this ->version = '1.3.5 ' ;
5959 $ this ->options = get_option ( 'wp_php_console ' );
6060
61+ if ( ! class_exists ( 'PhpConsole\Connector ' ) ) {
62+ return ;
63+ }
64+
65+ // By default PHP Console uses PhpConsole\Storage\Session for postponed responses,
66+ // so all temporary data will be stored in $_SESSION.
67+ // But there is some problem with frameworks like WordPress that override PHP session handler.
68+ $ php_console = new PhpConsole \Connector ;
69+ $ php_console ->setPostponeStorage ( new PhpConsole \Storage \File ( '/tmp/pc.data ' ) );
70+
6171 // Perform PHP Console initialisation required asap for other code to be able to output to the JavaScript console
62- $ connector = PhpConsole \Connector ::getInstance ();
72+ $ connector = $ php_console ::getInstance ();
6373
6474 // Apply 'register' option to PHP Console
6575 if ( ! empty ( $ this ->options ['register ' ] ) ) {
66-
6776 if ( ! class_exists ( 'PC ' , false ) ) {
68- // only if PC not registered yet
77+ // Only if PC not registered yet
6978 PhpConsole \Helper::register ( );
7079 }
7180 // PC::debug( 'PC::debug() is available');
72-
7381 }
7482
7583 // Apply 'stack' option to PHP Console
@@ -82,8 +90,6 @@ public function __construct() {
8290 $ connector ->setSourcesBasePath ( $ _SERVER ['DOCUMENT_ROOT ' ] );
8391 }
8492
85- // Initialise WordPress actions
86-
8793 // Translation
8894 add_action ( 'plugins_loaded ' , array ( $ this , 'set_locale ' ) );
8995 // Admin menu
@@ -387,10 +393,6 @@ public function settings_info() {
387393 */
388394 public function init () {
389395
390- if ( ! class_exists ( 'PhpConsole\Connector ' ) ) {
391- return ;
392- }
393-
394396 $ options = $ this ->options ;
395397
396398 $ password = isset ( $ options ['password ' ] ) ? $ options ['password ' ] : '' ;
@@ -406,16 +408,8 @@ public function init() {
406408 $ _POST [ PhpConsole \Connector::POST_VAR_NAME ] = stripslashes_deep ( $ _POST [ PhpConsole \Connector::POST_VAR_NAME ] );
407409 }
408410
409- /**
410- * By default PHP Console uses PhpConsole\Storage\Session for postponed responses,
411- * so all temporary data will be stored in $_SESSION.
412- * But there is some problem with frameworks like WordPress that override PHP session handler.
413- */
414- $ connector = new PhpConsole \Connector ;
415- $ connector ->setPostponeStorage ( new PhpConsole \Storage \File ( '/tmp/pc.data ' ) );
416-
417- $ connector_instance = $ connector ::getInstance ();
418- $ connector_instance ->setPassword ( $ password );
411+ $ connector = PhpConsole \Connector::getInstance ();
412+ $ connector ->setPassword ( $ password );
419413
420414 $ handler = PhpConsole \Handler::getInstance ();
421415 if ( PhpConsole \Handler::getInstance ()->isStarted () != true ) {
@@ -424,15 +418,15 @@ public function init() {
424418
425419 $ enableSslOnlyMode = isset ( $ options ['ssl ' ] ) ? ( ! empty ( $ options ['ssl ' ] ) ? $ options ['ssl ' ] : '' ) : '' ;
426420 if ( $ enableSslOnlyMode == true ) {
427- $ connector_instance ->enableSslOnlyMode ();
421+ $ connector ->enableSslOnlyMode ();
428422 }
429423
430424 $ allowedIpMasks = isset ( $ options ['ip ' ] ) ? ( ! empty ( $ options ['ip ' ] ) ? explode ( ', ' , $ options ['ip ' ] ) : '' ) : '' ;
431425 if ( is_array ( $ allowedIpMasks ) && ! empty ( $ allowedIpMasks ) ) {
432- $ connector_instance ->setAllowedIpMasks ( (array ) $ allowedIpMasks );
426+ $ connector ->setAllowedIpMasks ( (array ) $ allowedIpMasks );
433427 }
434428
435- $ evalProvider = $ connector_instance ->getEvalDispatcher ()->getEvalProvider ();
429+ $ evalProvider = $ connector ->getEvalDispatcher ()->getEvalProvider ();
436430
437431 $ evalProvider ->addSharedVar ( 'uri ' , $ _SERVER ['REQUEST_URI ' ] );
438432 $ evalProvider ->addSharedVarReference ( 'post ' , $ _POST );
@@ -442,7 +436,7 @@ public function init() {
442436 $ evalProvider ->addSharedVarReference ( 'dirs ' , $ openBaseDirs );
443437 $ evalProvider ->setOpenBaseDirs ( $ openBaseDirs );
444438
445- $ connector_instance ->startEvalRequestsListener ();
439+ $ connector ->startEvalRequestsListener ();
446440
447441 }
448442
0 commit comments