diff --git a/wp-admin/includes/class-wp-upgrader-skins.php b/wp-admin/includes/class-wp-upgrader-skins.php index b48944f673..5dd2ce228a 100644 --- a/wp-admin/includes/class-wp-upgrader-skins.php +++ b/wp-admin/includes/class-wp-upgrader-skins.php @@ -526,4 +526,80 @@ class Theme_Upgrader_Skin extends WP_Upgrader_Skin { if ( ! empty($update_actions) ) $this->feedback(implode(' | ', (array)$update_actions)); } +} + +/** + * Upgrader Skin for Background WordPress Upgrades + * + * This skin is designed to be used when no output is intended, all output + * is captured and stored for the caller to process and log/email/discard. + * + * @package WordPress + * @subpackage Upgrader + * @since 3.7.0 + */ +class Background_Upgrader_Skin extends WP_Upgrader_Skin { + var $messages = array(); + + function request_filesystem_credentials( $error = false ) { + // TODO: fix up request_filesystem_credentials(), or split it, to allow us to request a no-output version + // This will output a credentials form in event of failure, We don't want that, so just hide with a buffer + ob_start(); + set_current_screen( 'tools' ); // Only here to avoid PHP Notices from screen_icon() which is used within that HTML + $result = parent::request_filesystem_credentials( $error ); + ob_end_clean(); + return $result; + } + + function feedback( $data ) { + if ( is_wp_error( $data ) ) + $string = $data->get_error_message(); + else if ( is_array( $data ) ) + return; + else + $string = $data; + + if ( ! empty( $this->upgrader->strings[ $string ] ) ) + $string = $this->upgrader->strings[ $string ]; + + if ( strpos( $string, '%' ) !== false ) { + $args = func_get_args(); + $args = array_splice( $args, 1 ); + if ( ! empty( $args ) ) + $string = vsprintf( $string, $args ); + } + + $string = trim( $string ); + + // Only allow basic HTML in the messages, as it'll be used in emails/logs rather than direct browser output. + $string = wp_kses( $string, array( + 'a' => array( + 'href' => true + ), + 'br' => true, + 'em' => true, + 'strong' => true, + ) ); + + if ( empty( $string ) ) + return; + + $this->messages[] = $string; + } + + function header() { + ob_start(); + } + + function footer() { + $output = ob_get_contents(); + if ( ! empty( $output ) ) + $this->feedback( $output ); + ob_end_clean(); + } + + function bulk_header() {} + function bulk_footer() {} + function before() {} + function after() {} } \ No newline at end of file