3 * Upgrader API: Automatic_Upgrader_Skin class
11 * Upgrader Skin for Automatic WordPress Upgrades
13 * This skin is designed to be used when no output is intended, all output
14 * is captured and stored for the caller to process and log/email/discard.
17 * @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php.
19 * @see Bulk_Upgrader_Skin
21 class Automatic_Upgrader_Skin extends WP_Upgrader_Skin {
22 protected $messages = array();
25 * Determines whether the upgrader needs FTP/SSH details in order to connect
29 * @since 4.6.0 The `$context` parameter default changed from `false` to an empty string.
31 * @see request_filesystem_credentials()
33 * @param bool $error Optional. Whether the current request has failed to connect.
35 * @param string $context Optional. Full path to the directory that is tested
36 * for being writable. Default empty.
37 * @param bool $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable. Default false.
38 * @return bool True on success, false on failure.
40 public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
42 $this->options['context'] = $context;
44 // TODO: fix up request_filesystem_credentials(), or split it, to allow us to request a no-output version
45 // This will output a credentials form in event of failure, We don't want that, so just hide with a buffer
47 $result = parent::request_filesystem_credentials( $error, $context, $allow_relaxed_file_ownership );
57 public function get_upgrade_messages() {
58 return $this->messages;
62 * @param string|array|WP_Error $data
64 public function feedback( $data ) {
65 if ( is_wp_error( $data ) ) {
66 $string = $data->get_error_message();
67 } elseif ( is_array( $data ) ) {
72 if ( ! empty( $this->upgrader->strings[ $string ] ) )
73 $string = $this->upgrader->strings[ $string ];
75 if ( strpos( $string, '%' ) !== false ) {
76 $args = func_get_args();
77 $args = array_splice( $args, 1 );
78 if ( ! empty( $args ) )
79 $string = vsprintf( $string, $args );
82 $string = trim( $string );
84 // Only allow basic HTML in the messages, as it'll be used in emails/logs rather than direct browser output.
85 $string = wp_kses( $string, array(
94 if ( empty( $string ) )
97 $this->messages[] = $string;
103 public function header() {
110 public function footer() {
111 $output = ob_get_clean();
112 if ( ! empty( $output ) )
113 $this->feedback( $output );