WordPress.org

Make WordPress Core

Changeset 25228


Ignore:
Timestamp:
09/04/13 07:16:16 (4 years ago)
Author:
dd32
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-upgrader-skins.php

    r25227 r25228  
    528528    } 
    529529} 
     530 
     531/** 
     532 * Upgrader Skin for Background WordPress Upgrades 
     533 * 
     534 * This skin is designed to be used when no output is intended, all output  
     535 * is captured and stored for the caller to process and log/email/discard. 
     536 * 
     537 * @package WordPress 
     538 * @subpackage Upgrader 
     539 * @since 3.7.0 
     540 */ 
     541class Background_Upgrader_Skin extends WP_Upgrader_Skin { 
     542    var $messages = array(); 
     543 
     544    function request_filesystem_credentials( $error = false ) { 
     545        // TODO: fix up request_filesystem_credentials(), or split it, to allow us to request a no-output version 
     546        // This will output a credentials form in event of failure, We don't want that, so just hide with a buffer 
     547        ob_start(); 
     548        set_current_screen( 'tools' ); // Only here to avoid PHP Notices from screen_icon() which is used within that HTML 
     549        $result = parent::request_filesystem_credentials( $error ); 
     550        ob_end_clean(); 
     551        return $result; 
     552    } 
     553 
     554    function feedback( $data ) { 
     555        if ( is_wp_error( $data ) ) 
     556            $string = $data->get_error_message(); 
     557        else if ( is_array( $data ) ) 
     558            return; 
     559        else 
     560            $string = $data; 
     561 
     562        if ( ! empty( $this->upgrader->strings[ $string ] ) ) 
     563            $string = $this->upgrader->strings[ $string ]; 
     564 
     565        if ( strpos( $string, '%' ) !== false ) { 
     566            $args = func_get_args(); 
     567            $args = array_splice( $args, 1 ); 
     568            if ( ! empty( $args ) ) 
     569                $string = vsprintf( $string, $args ); 
     570        } 
     571 
     572        $string = trim( $string ); 
     573 
     574        // Only allow basic HTML in the messages, as it'll be used in emails/logs rather than direct browser output. 
     575        $string = wp_kses( $string, array( 
     576            'a' => array( 
     577                'href' => true 
     578            ), 
     579            'br' => true, 
     580            'em' => true, 
     581            'strong' => true, 
     582        ) ); 
     583 
     584        if ( empty( $string ) ) 
     585            return; 
     586 
     587        $this->messages[] = $string; 
     588    } 
     589 
     590    function header() { 
     591        ob_start(); 
     592    } 
     593 
     594    function footer() { 
     595        $output = ob_get_contents(); 
     596        if ( ! empty( $output ) ) 
     597            $this->feedback( $output ); 
     598        ob_end_clean(); 
     599    } 
     600 
     601    function bulk_header() {} 
     602    function bulk_footer() {} 
     603    function before() {} 
     604    function after() {} 
     605} 
Note: See TracChangeset for help on using the changeset viewer.