Skip to content

Commit a869515

Browse files
authored
Suppress PHP warnings when pre-fetching WordPress updates (#2458)
#2295 added pre-fetching of all the api.wp.org/update-check requests in Playground Web. Unfortunately, it also generates some noise in the output: ``` [04-Aug-2025 17:10:25 UTC] PHP Warning: wp_update_plugins(): An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/forums/">support forums</a>. (WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.) in /wordpress/wp-includes/functions.php on line 135 [04-Aug-2025 17:10:25 UTC] PHP Warning: wp_update_themes(): An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/forums/">support forums</a>. (WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.) in /wordpress/wp-includes/functions.php on line 135 [04-Aug-2025 17:10:25 UTC] PHP Warning: wp_version_check(): An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/forums/">support forums</a>. (WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.) in /wordpress/wp-includes/functions.php on line 135 ``` This PR suppresses those warnings without suppressing other errors. cc @draganescu ## Testing instructions 1. Go to http://127.0.0.1:5400/website-server/?php=8.0 2. Confirm the warnings mentioned above are not present in the browser devtools
1 parent 1cee011 commit a869515

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

packages/playground/remote/src/lib/wordpress-fetch-network-transport.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,25 @@ export class WordPressFetchNetworkTransport {
217217
delete_site_transient($php_transient_key);
218218
}
219219
220+
// Set up custom error handler to suppress specific WordPress.org connection warnings:
221+
// * wp_update_plugins(): An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/forums/">support forums</a>. (WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.) in /wordpress/wp-includes/functions.php on line 135
222+
// * wp_update_themes(): An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/forums/">support forums</a>. (WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.) in /wordpress/wp-includes/functions.php on line 135
223+
// * wp_version_check(): An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/forums/">support forums</a>. (WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.) in /wordpress/wp-includes/functions.php on line 135
224+
$previous_error_handler = set_error_handler(function($errno, $errstr, $errfile, $errline) {
225+
global $previous_error_handler;
226+
if (
227+
strpos($errstr, 'WordPress could not establish a secure connection to WordPress.org') !== false ||
228+
strpos($errstr, 'An unexpected error occurred. Something may be wrong with WordPress.org') !== false
229+
) {
230+
return true;
231+
}
232+
// For all other errors, use the previous error handler or default behavior
233+
if ($previous_error_handler) {
234+
return call_user_func($previous_error_handler, $errno, $errstr, $errfile, $errline);
235+
}
236+
return false; // Use default error handling
237+
});
238+
220239
if (!$existing_transients['update_plugins']) {
221240
wp_update_plugins();
222241
delete_site_transient('update_plugins');

0 commit comments

Comments
 (0)