Skip to content

Commit 5cbc329

Browse files
committed
Suppress warnings to avoid headers already sent notices
1 parent 83949eb commit 5cbc329

26 files changed

+1021
-628
lines changed

.circleci/apache_ci.conf

Lines changed: 0 additions & 29 deletions
This file was deleted.

.circleci/config.yml

Lines changed: 0 additions & 45 deletions
This file was deleted.

ChangeLog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Changelog
22

3-
### 1.5.4 (28 May 2019)
3+
### 1.5.4 (30 May 2019)
44
* Fix: Temporarily suppress PHP warnings while connecting with PHP Console to avoid headers already sent warnings, then restore all errors reporting
5+
* Misc: Improved PHP and WordPress compatibility loader
56

67
### 1.5.3 (22 May 2019)
78
* Fix: Try to get rid of PHP errors related to "Unable to set PHP Console server cookie" and "Cannot modify header information - headers already sent"

LICENSE.txt

Lines changed: 617 additions & 282 deletions
Large diffs are not rendered by default.

codeception.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

composer.json

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "unfulvio/wp-php-console",
33
"description": "A WordPress implementation of PHP Console.",
44
"type": "wordpress-plugin",
5-
"version": "1.5.3",
5+
"version": "1.5.4",
66
"keywords": ["wordpress", "debug", "debugging", "development", "php-console", "console", "terminal", "command-line", "cli" ],
77
"homepage": "https://github.com/unfulvio/wp-php-console",
88
"license": "GPLv2.0+",
@@ -15,24 +15,9 @@
1515
}
1616
],
1717
"require": {
18-
"php": ">=5.6.0",
19-
"composer/installers": "^1.0",
20-
"nekojira/wp-requirements": "^1.4",
21-
"php-console/php-console": "3.1.7",
22-
"xrstf/composer-php52": "1.*"
18+
"php-console/php-console": "3.1.7"
2319
},
2420
"require-dev": {
2521
"lucatume/wp-browser": "2.2.7"
26-
},
27-
"scripts": {
28-
"post-install-cmd": [
29-
"xrstf\\Composer52\\Generator::onPostInstallCmd"
30-
],
31-
"post-update-cmd": [
32-
"xrstf\\Composer52\\Generator::onPostInstallCmd"
33-
],
34-
"post-autoload-dump": [
35-
"xrstf\\Composer52\\Generator::onPostInstallCmd"
36-
]
3722
}
3823
}

includes/Functions.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* WP PHP Console
4+
*
5+
* This source file is subject to the GNU General Public License v3.0
6+
* that is bundled with this package in the file license.txt.
7+
* It is also available through the world-wide-web at this URL:
8+
* http://www.gnu.org/licenses/gpl-3.0.html
9+
*
10+
* @author Fulvio Notarstefano <[email protected]>
11+
* @copyright Copyright (c) 2014-2019 Fulvio Notarstefano
12+
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
13+
*/
14+
15+
defined( 'ABSPATH' ) or exit;
16+
17+
18+
/**
19+
* Gets the WP PHP Console instance.
20+
*
21+
* @since 1.5.4
22+
*
23+
* @return WP_PHP_Console\Plugin
24+
*/
25+
function wp_php_console() {
26+
27+
return new \WP_PHP_Console\Plugin();
28+
}

includes/class-wp-php-console.php renamed to includes/Plugin.php

Lines changed: 82 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
<?php
2+
/**
3+
* WP PHP Console
4+
*
5+
* This source file is subject to the GNU General Public License v3.0
6+
* that is bundled with this package in the file license.txt.
7+
* It is also available through the world-wide-web at this URL:
8+
* http://www.gnu.org/licenses/gpl-3.0.html
9+
*
10+
* @author Fulvio Notarstefano <[email protected]>
11+
* @copyright Copyright (c) 2014-2019 Fulvio Notarstefano
12+
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
13+
*/
214

315
namespace WP_PHP_Console;
416

@@ -22,7 +34,7 @@ class Plugin {
2234

2335

2436
/** @var array settings options */
25-
protected $options = [];
37+
private $options = [];
2638

2739
/** @var PhpConsole\Connector instance */
2840
public $connector;
@@ -35,24 +47,38 @@ class Plugin {
3547
*/
3648
public function __construct() {
3749

38-
// handle translations
39-
add_action( 'plugins_loaded', [ $this, 'set_locale' ] );
50+
$this->set_debug_mode();
51+
$this->set_options();
52+
$this->set_admin();
53+
$this->set_hooks();
54+
}
4055

41-
// set options
42-
$this->options = $this->get_options();
4356

44-
// load admin
45-
$this->set_admin();
57+
/**
58+
* Sets constants and elevates PHP error reporting.
59+
*
60+
* @since 1.5.4
61+
*/
62+
private function set_debug_mode() {
4663

47-
// bail out if PHP Console can't be found
48-
if ( ! class_exists( 'PhpConsole\Connector' ) ) {
49-
return;
64+
@error_reporting( E_ALL );
65+
66+
foreach ( [ 'WP_DEBUG', 'WP_DEBUG_LOG', 'WP_DEBUG_DISPLAY', ] as $wp_debug_constant ) {
67+
if ( ! defined( $wp_debug_constant ) ) {
68+
define ( $wp_debug_constant, true );
69+
}
5070
}
71+
}
5172

52-
// connect to PHP Console
53-
add_action( 'init', [ $this, 'connect' ], -1000 );
54-
// delay further PHP Console initialisation to have more context during Remote PHP execution
55-
add_action( 'wp_loaded', [ $this, 'init' ], -1000 );
73+
74+
/**
75+
* Sets the plugin options.
76+
*
77+
* @since 1.5.4
78+
*/
79+
private function set_options() {
80+
81+
$this->options = $this->get_options();
5682
}
5783

5884

@@ -88,14 +114,32 @@ private function set_admin() {
88114
], $actions );
89115
} );
90116

91-
// init settings
92-
require_once __DIR__ . '/class-wp-php-console-settings.php';
93-
94117
new Settings( $this->options );
95118
}
96119
}
97120

98121

122+
/**
123+
* Sets plugin hooks.
124+
*
125+
* @since 1.5.4
126+
*/
127+
private function set_hooks() {
128+
129+
// bail out if PHP Console can't be found
130+
if ( ! class_exists( 'PhpConsole\Connector' ) ) {
131+
return;
132+
}
133+
134+
// handle translations
135+
add_action( 'plugins_loaded', [ $this, 'set_locale' ] );
136+
// connect to PHP Console
137+
add_action( 'init', [ $this, 'connect' ], -1000 );
138+
// delay further PHP Console initialisation to have more context during Remote PHP execution
139+
add_action( 'wp_loaded', [ $this, 'init' ], -1000 );
140+
}
141+
142+
99143
/**
100144
* Connects to PHP Console.
101145
*
@@ -110,21 +154,27 @@ public function connect() {
110154
// workaround for avoiding headers already sent warnings
111155
@error_reporting( E_ALL & ~E_WARNING );
112156

113-
if ( empty( @session_id() ) ) {
157+
if ( ! @session_id() ) {
114158
@session_start();
115159
}
116160

161+
$connected = true;
162+
117163
if ( ! $this->connector instanceof PhpConsole\Connector ) {
118164
try {
119165
$this->connector = PhpConsole\Connector::getInstance();
120-
} catch ( \Exception $e ) {}
166+
} catch ( \Exception $e ) {
167+
$connected = false;
168+
}
121169
}
122170

123171
// restore error reporting
124172
@error_reporting( E_ALL );
125173

126174
// apply PHP Console options
127-
$this->apply_options();
175+
if ( $connected ) {
176+
$this->apply_options();
177+
}
128178
}
129179

130180

@@ -215,9 +265,20 @@ public function init() {
215265
// get PHP Console instance if wasn't set yet
216266
if ( ! $this->connector instanceof PhpConsole\Connector ) {
217267

268+
// workaround for avoiding headers already sent warnings
269+
@error_reporting( E_ALL & ~E_WARNING );
270+
218271
try {
219272
$this->connector = PhpConsole\Connector::getInstance();
273+
$connected = true;
220274
} catch ( \Exception $e ) {
275+
$connected = false;
276+
}
277+
278+
// restore error reporting
279+
@error_reporting( E_ALL );
280+
281+
if ( ! $connected ) {
221282
return;
222283
}
223284
}
@@ -321,7 +382,7 @@ public function password_notice() {
321382
?>
322383
<div class="update-nag">
323384
<p><?php printf(
324-
/* translators: Placeholders: %1$s - WP Php Console name, %2$s - opening HTML <a> link tag; %3$s closing HTML </a> link tag */
385+
/* translators: Placeholders: %1$s - WP PHP Console name, %2$s - opening HTML <a> link tag; %3$s closing HTML </a> link tag */
325386
__( '%1$s: Please remember to %2$sset a password%3$s if you want to enable the terminal.', 'wp-php-console' ),
326387
'<strong>' . self::NAME . '</strong>',
327388
'<a href="' . esc_url( admin_url( 'options-general.php?page=wp-php-console' ) ) .'">',

includes/class-wp-php-console-settings.php renamed to includes/Settings.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
<?php
2+
/**
3+
* WP PHP Console
4+
*
5+
* This source file is subject to the GNU General Public License v3.0
6+
* that is bundled with this package in the file license.txt.
7+
* It is also available through the world-wide-web at this URL:
8+
* http://www.gnu.org/licenses/gpl-3.0.html
9+
*
10+
* @author Fulvio Notarstefano <[email protected]>
11+
* @copyright Copyright (c) 2014-2019 Fulvio Notarstefano
12+
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
13+
*/
214

315
namespace WP_PHP_Console;
416

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "wp-php-console",
33
"title": "WP PHP Console",
44
"description": "An implementation of PHP Console as a WordPress plugin. Use Chrome Dev Tools to debug your WordPress installation!",
5-
"version": "1.5.3",
5+
"version": "1.5.4",
66
"homepage": "https://wordpress.org/plugins/wp-php-console/",
77
"repository": {
88
"type": "git",

0 commit comments

Comments
 (0)