Core Auto Updates: Add a initial skin to allow capturing the output from the upgrader without displaying it (such as we need during cron calls).
This has been copied almost verbatim from the automatic-updater plugin with a few style tweaks and additional upgrade-possible check. See #22704 Built from https://develop.svn.wordpress.org/trunk@25228 git-svn-id: http://core.svn.wordpress.org/trunk@25198 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
bc02809fe3
commit
4231f4668a
|
@ -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() {}
|
||||
}
|
Loading…
Reference in New Issue