]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/includes/class-wp-ajax-upgrader-skin.php
WordPress 4.6.3
[autoinstalls/wordpress.git] / wp-admin / includes / class-wp-ajax-upgrader-skin.php
1 <?php
2 /**
3  * Upgrader API: WP_Ajax_Upgrader_Skin class
4  *
5  * @package WordPress
6  * @subpackage Upgrader
7  * @since 4.6.0
8  */
9
10 /**
11  * Upgrader Skin for Ajax WordPress upgrades.
12  *
13  * This skin is designed to be used for Ajax updates.
14  *
15  * @since 4.6.0
16  *
17  * @see Automatic_Upgrader_Skin
18  */
19 class WP_Ajax_Upgrader_Skin extends Automatic_Upgrader_Skin {
20
21         /**
22          * Holds the WP_Error object.
23          *
24          * @since 4.6.0
25          * @access protected
26          * @var null|WP_Error
27          */
28         protected $errors = null;
29
30         /**
31          * Constructor.
32          *
33          * @since 4.6.0
34          * @access public
35          *
36          * @param array $args Options for the upgrader, see WP_Upgrader_Skin::__construct().
37          */
38         public function __construct( $args = array() ) {
39                 parent::__construct( $args );
40
41                 $this->errors = new WP_Error();
42         }
43
44         /**
45          * Retrieves the list of errors.
46          *
47          * @since 4.6.0
48          * @access public
49          *
50          * @return WP_Error Errors during an upgrade.
51          */
52         public function get_errors() {
53                 return $this->errors;
54         }
55
56         /**
57          * Retrieves a string for error messages.
58          *
59          * @since 4.6.0
60          * @access public
61          *
62          * @return string Error messages during an upgrade.
63          */
64         public function get_error_messages() {
65                 $messages = array();
66
67                 foreach ( $this->errors->get_error_codes() as $error_code ) {
68                         if ( $this->errors->get_error_data( $error_code ) && is_string( $this->errors->get_error_data( $error_code ) ) ) {
69                                 $messages[] = $this->errors->get_error_message( $error_code ) . ' ' . esc_html( strip_tags( $this->errors->get_error_data( $error_code ) ) );
70                         } else {
71                                 $messages[] = $this->errors->get_error_message( $error_code );
72                         }
73                 }
74
75                 return implode( ', ', $messages );
76         }
77
78         /**
79          * Stores a log entry for an error.
80          *
81          * @since 4.6.0
82          * @access public
83          *
84          * @param string|WP_Error $errors Errors.
85          */
86         public function error( $errors ) {
87                 if ( is_string( $errors ) ) {
88                         $string = $errors;
89                         if ( ! empty( $this->upgrader->strings[ $string ] ) ) {
90                                 $string = $this->upgrader->strings[ $string ];
91                         }
92
93                         if ( false !== strpos( $string, '%' ) ) {
94                                 $args = func_get_args();
95                                 $args = array_splice( $args, 1 );
96                                 if ( ! empty( $args ) ) {
97                                         $string = vsprintf( $string, $args );
98                                 }
99                         }
100
101                         // Count existing errors to generate an unique error code.
102                         $errors_count = count( $errors->get_error_codes() );
103                         $this->errors->add( 'unknown_upgrade_error_' . $errors_count + 1 , $string );
104                 } elseif ( is_wp_error( $errors ) ) {
105                         foreach ( $errors->get_error_codes() as $error_code ) {
106                                 $this->errors->add( $error_code, $errors->get_error_message( $error_code ), $errors->get_error_data( $error_code ) );
107                         }
108                 }
109
110                 $args = func_get_args();
111                 call_user_func_array( array( $this, 'parent::error' ), $args );
112         }
113
114         /**
115          * Stores a log entry.
116          *
117          * @since 4.6.0
118          * @access public
119          *
120          * @param string|array|WP_Error $data Log entry data.
121          */
122         public function feedback( $data ) {
123                 if ( is_wp_error( $data ) ) {
124                         foreach ( $data->get_error_codes() as $error_code ) {
125                                 $this->errors->add( $error_code, $data->get_error_message( $error_code ), $data->get_error_data( $error_code ) );
126                         }
127                 }
128
129                 $args = func_get_args();
130                 call_user_func_array( array( $this, 'parent::feedback' ), $args );
131         }
132 }