Skip to content

Commit 0821866

Browse files
authored
Merge pull request #69 from wp-cli/ignore_ssl_trigger_error
Ignore SSL trigger error in wp_update_themes/plugins().
2 parents 42a2bbb + a24f408 commit 0821866

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/Plugin_Command.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,14 @@ protected function install_from_repo( $slug, $assoc_args ) {
501501
if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'version' ) != 'dev' ) {
502502
WP_CLI::get_http_cache_manager()->whitelist_package( $api->download_link, $this->item_type, $api->slug, $api->version );
503503
}
504+
505+
// Ignore failures on accessing SSL "https://api.wordpress.org/plugins/update-check/1.1/" in `wp_update_plugins()` which seem to occur intermittently.
506+
set_error_handler( array( __CLASS__, 'error_handler' ), E_USER_WARNING | E_USER_NOTICE );
507+
504508
$result = $this->get_upgrader( $assoc_args )->install( $api->download_link );
505509

510+
restore_error_handler();
511+
506512
return $result;
507513
}
508514

src/Theme_Command.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,14 @@ protected function install_from_repo( $slug, $assoc_args ) {
411411
if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'version' ) != 'dev' ) {
412412
WP_CLI::get_http_cache_manager()->whitelist_package( $api->download_link, $this->item_type, $api->slug, $api->version );
413413
}
414+
415+
// Ignore failures on accessing SSL "https://api.wordpress.org/themes/update-check/1.1/" in `wp_update_themes()` which seem to occur intermittently.
416+
set_error_handler( array( __CLASS__, 'error_handler' ), E_USER_WARNING | E_USER_NOTICE );
417+
414418
$result = $this->get_upgrader( $assoc_args )->install( $api->download_link );
415419

420+
restore_error_handler();
421+
416422
return $result;
417423
}
418424

src/WP_CLI/CommandWithUpgrade.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,5 +626,23 @@ protected function get_formatter( &$assoc_args ) {
626626
return new \WP_CLI\Formatter( $assoc_args, $this->obj_fields, $this->item_type );
627627
}
628628

629+
/**
630+
* Error handler to ignore failures on accessing SSL "https://api.wordpress.org/themes/update-check/1.1/" in `wp_update_themes()`
631+
* and "https://api.wordpress.org/plugins/update-check/1.1/" in `wp_update_plugins()` which seem to occur intermittently.
632+
*/
633+
public static function error_handler( $errno, $errstr, $errfile, $errline, $errcontext = null ) {
634+
// If ignoring E_USER_WARNING | E_USER_NOTICE, default.
635+
if ( ! ( error_reporting() & $errno ) ) {
636+
return false;
637+
}
638+
// If not in "wp-includes/update.php", default.
639+
$update_php = 'wp-includes/update.php';
640+
if ( 0 !== substr_compare( $errfile, $update_php, -strlen( $update_php ) ) ) {
641+
return false;
642+
}
643+
// Else assume it's in `wp_update_themes()` or `wp_update_plugins()` and just ignore it.
644+
return true;
645+
}
646+
629647
}
630648

0 commit comments

Comments
 (0)