Skip to content

Commit f36abbc

Browse files
committed
Maybe we nailed #13 at last
1 parent c83a296 commit f36abbc

File tree

2 files changed

+39
-51
lines changed

2 files changed

+39
-51
lines changed

includes/class-wp-php-console-settings.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function settings_info() {
154154

155155
?>
156156
<p><?php
157-
/* translators: %s refers to 'PHP Console' Chrome extension, will print download link for the Chrome extension */
157+
/* translators: Placeholder: %s refers to the PHP Console library, pointing to its GitHub repository */
158158
printf( _x( 'This plugin allows you to use %s within your WordPress installation for testing, debugging and development purposes.', 'PHP Console, the PHP Library', 'wp-php-console' ),
159159
'<a href="https://github.com/barbushin/php-console" target="_blank">PHP Console</a>'
160160
); ?><br>
@@ -164,14 +164,14 @@ public function settings_info() {
164164
<?php
165165

166166
$instructions = array(
167-
/* translators: Install PHP Console extension for Google Chrome download link */
167+
/* translators: Placeholder: %s represents the Google Chrome PHP Console extension download link */
168168
sprintf( _x( 'Make sure you have downloaded and installed %s.', 'PHP Console, the Chrome Extension', 'wp-php-console' ),
169169
'<a target="_blank" href="https://chrome.google.com/webstore/detail/php-console/nfhmhhlpfleoednkpnnnkolmclajemef">PHP Console extension for Google Chrome</a>'
170170
),
171171
esc_html__( 'Set a password for the eval terminal in the options below and hit "Save Changes".', 'wp-php-console' ),
172172
esc_html__( 'Reload any page of your installation and click on the key icon in your Chrome browser address bar, enter your password and access the terminal.', 'wp-php-console' ),
173173
esc_html__( 'From the eval terminal you can execute any PHP or WordPress specific function, including functions from your plugins and active theme.', 'wp-php-console' ),
174-
/* translators: %1$s - PHP code snippet example, %2$s - Chrome javascript console shortcut */
174+
/* translators: Placeholders: %1$s - PHP code snippet example, %2$s - Chrome javascript console shortcut */
175175
sprintf( __( 'In your PHP code, you can call PHP Console debug statements like %1$s to display PHP variables in the browser\'s JavaScript-console (e.g. %2$s) and optionally filter selected tags through the browser\'s Remote PHP Eval Terminal screen\'s "Ignore Debug options".', 'wp-php-console' ),
176176
'<code>debug(&#36;var, &#36;tag)</code>',
177177
'<code>CTRL+SHIFT+J</code>'
@@ -235,7 +235,7 @@ public function ip_field() {
235235
<p class="description"><?php esc_html_e( 'You may specify any of the following, to give access to specific IPs to the eval terminal:', 'wp-php-console' ); ?><br>
236236
<ol>
237237
<li><small><?php
238-
/* translators: Placeholders: %1$s - a single IP address, %2$s link to Varying Vagrant Vagrants repo */
238+
/* translators: Placeholders: %1$s - a single IP address, %2$s link to Varying Vagrant Vagrants project repository */
239239
printf( __( 'An IP address (for example %1$s, %2$s default IP address).', 'wp-php-console' ),
240240
'<code>192.168.50.4</code>',
241241
'<a href="https://github.com/Varying-Vagrant-Vagrants/VVV">Varying Vagrant Vagrants</a>'
@@ -266,7 +266,7 @@ public function register_field() {
266266
<p class="description"><?php
267267
esc_html_e( 'Tick to register PC class in the global namespace.', 'wp-php-console' );
268268
echo '<br>';
269-
/* translators: Placeholders: PHP code snippets examples */
269+
/* translators: Placeholders: %1$s, %2$s and %3$s are PHP code snippets examples */
270270
printf( __( 'Allows to write %1$s or %2$s instructions in PHP to inspect %3$s in the JavaScript console.', 'wp-php-console' ),
271271
'<code>PC::debug(&#36;var, &#36;tag)</code>',
272272
'<code>PC::magic_tag(&#36;var)</code>',
@@ -306,7 +306,7 @@ public function short_field() {
306306
<p class="description"><?php
307307
esc_html_e( 'Tick to shorten the length of PHP Console error sources and traces paths in browser JavaScript console for better readability.', 'wp-php-console' );
308308
echo '<br>';
309-
/* translators: %1$s - long server path, %2$s shortened server path */
309+
/* translators: Placeholders: %1$s - long server path, %2$s - shortened server path */
310310
printf( __( 'Paths like %1$s will be displayed as %2$s', 'wp-php-console' ),
311311
'<code>/server/path/to/document/root/WP/wp-admin/admin.php:31</code>',
312312
'<code>/WP/wp-admin/admin.php:31</code>'

includes/class-wp-php-console.php

Lines changed: 33 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -63,43 +63,25 @@ class Plugin {
6363
*/
6464
public function __construct() {
6565

66-
// Translations.
66+
// Handle translations.
6767
add_action( 'plugins_loaded', array( $this, 'set_locale' ) );
6868

6969
// Set options.
7070
$this->options = $this->get_options();
7171

7272
// Load admin.
73-
if ( ! defined( 'DOING_AJAX' ) && is_admin() ) {
74-
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 );
81-
} );
82-
83-
require_once __DIR__ . '/class-wp-php-console-settings.php';
84-
new Settings( $this->options );
85-
}
73+
$this->set_admin();
8674

8775
// Bail out if PHP Console can't be found.
8876
if ( ! class_exists( 'PhpConsole\Connector' ) ) {
8977
return;
9078
}
9179

9280
// Connect to PHP Console.
93-
add_action( 'init', function() {
94-
95-
$this->connect();
96-
97-
// Apply PHP Console options.
98-
$this->apply_options();
99-
100-
}, -100 );
81+
add_action( 'init', array( $this, 'connect' ), -100 );
10182

102-
// Delay further PHP Console initialisation to have more context during Remote PHP execution.
83+
// Delay further PHP Console initialisation
84+
// to have more context during Remote PHP execution.
10385
add_action( 'wp_loaded', array( $this, 'init' ), -100 );
10486

10587
}
@@ -122,40 +104,46 @@ public function set_locale() {
122104

123105

124106
/**
125-
* Connect to PHP Console.
107+
* Load admin.
126108
*
127-
* @since 1.4.0
109+
* @since 1.5.0
128110
*/
129-
private function connect() {
111+
private function set_admin() {
130112

131-
// By default PHP Console uses PhpConsole\Storage\Session for postponed responses,
132-
// so all temporary data will be stored in $_SESSION.
133-
// But there is some problem with frameworks like WordPress that override PHP session handler.
134-
// PHP Console has alternative storage drivers for this - we will write to a temporary file:
113+
if ( ! defined( 'DOING_AJAX' ) && is_admin() ) {
135114

136-
$phpcdir = __DIR__ . '/tmp';
137-
$make_dir = wp_mkdir_p( $phpcdir );
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 );
121+
} );
138122

139-
if ( true === $make_dir ) {
123+
// Init settings.
124+
require_once __DIR__ . '/class-wp-php-console-settings.php';
125+
new Settings( $this->options );
126+
}
140127

141-
try {
142-
$storage = new PhpConsole\Storage\File( $phpcdir . '/' . md5( __FILE__ ) . '_pc.data' );
143-
PhpConsole\Connector::setPostponeStorage( $storage );
144-
} catch( \Exception $e ) {
145-
// PHP Console will complain about this: "Path <...> is under DOCUMENT_ROOT. It's insecure!"
146-
// but there's nothing we can do at the moment as there doesn't seem to be another solution in WP
147-
// nevertheless PHP Console tool is not meant to be used in production so this shouldn't be a concern
148-
// $this->print_notice_exception( $e );
149-
}
128+
}
129+
130+
131+
/**
132+
* Connect to PHP Console.
133+
*
134+
* @since 1.4.0
135+
*/
136+
public function connect() {
150137

151-
}
138+
session_start();
152139

153-
// Perform PHP Console initialisation required asap
154-
// for other code to be able to output to the JavaScript console.
155140
if ( ! $this->connector instanceof PhpConsole\Connector ) {
156141
$this->connector = PhpConsole\Connector::getInstance();
157142
}
158143

144+
// Apply PHP Console options.
145+
$this->apply_options();
146+
159147
}
160148

161149

0 commit comments

Comments
 (0)