/** * Initialize PHP Console. * * @since 1.0.0 */ public function init() { // Get PHP Console extension password. $password = $this->options['password']; if (!$password) { // Display admin notice and abort if no password has been set. add_action('admin_notices', array($this, 'password_notice')); return; } // Selectively remove slashes added by WordPress as expected by PhpConsole. if (array_key_exists(PhpConsole\Connector::POST_VAR_NAME, $_POST)) { $_POST[PhpConsole\Connector::POST_VAR_NAME] = stripslashes_deep($_POST[PhpConsole\Connector::POST_VAR_NAME]); } // Get PHP Console instance if wasn't set yet. if (!$this->connector instanceof PhpConsole\Connector) { $this->connector = PhpConsole\Connector::getInstance(); } // Set PHP Console password. try { $this->connector->setPassword($password); } catch (\Exception $e) { $this->print_notice_exception($e); } // Get PHP Console handler instance. $handler = PhpConsole\Handler::getInstance(); if (true !== PhpConsole\Handler::getInstance()->isStarted()) { try { $handler->start(); } catch (\Exception $e) { $this->print_notice_exception($e); } } // Enable SSL-only mode. if (true === $this->options['ssl']) { $this->connector->enableSslOnlyMode(); } // Restrict IP addresses. $allowedIpMasks = !empty($this->options['ip']) ? explode(',', $this->options['ip']) : ''; if (is_array($allowedIpMasks) && count($allowedIpMasks) > 0) { $this->connector->setAllowedIpMasks($allowedIpMasks); } $evalProvider = $this->connector->getEvalDispatcher()->getEvalProvider(); try { $evalProvider->addSharedVar('uri', $_SERVER['REQUEST_URI']); } catch (\Exception $e) { $this->print_notice_exception($e); } try { $evalProvider->addSharedVarReference('post', $_POST); } catch (\Exception $e) { $this->print_notice_exception($e); } $openBaseDirs = array(ABSPATH, get_template_directory()); try { $evalProvider->addSharedVarReference('dirs', $openBaseDirs); } catch (\Exception $e) { $this->print_notice_exception($e); } $evalProvider->setOpenBaseDirs($openBaseDirs); try { $this->connector->startEvalRequestsListener(); } catch (\Exception $e) { $this->print_notice_exception($e); } }