wp/wp-admin/includes/class-wp-upgrader-skin.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    23 	 * Holds the result of an upgrade.
    23 	 * Holds the result of an upgrade.
    24 	 *
    24 	 *
    25 	 * @since 2.8.0
    25 	 * @since 2.8.0
    26 	 * @var string|bool|WP_Error
    26 	 * @var string|bool|WP_Error
    27 	 */
    27 	 */
    28 	public $result = false;
    28 	public $result  = false;
    29 	public $options = array();
    29 	public $options = array();
    30 
    30 
    31 	/**
    31 	/**
    32 	 *
       
    33 	 * @param array $args
    32 	 * @param array $args
    34 	 */
    33 	 */
    35 	public function __construct($args = array()) {
    34 	public function __construct( $args = array() ) {
    36 		$defaults = array( 'url' => '', 'nonce' => '', 'title' => '', 'context' => false );
    35 		$defaults      = array(
    37 		$this->options = wp_parse_args($args, $defaults);
    36 			'url'     => '',
    38 	}
    37 			'nonce'   => '',
    39 
    38 			'title'   => '',
    40 	/**
    39 			'context' => false,
    41 	 *
    40 		);
       
    41 		$this->options = wp_parse_args( $args, $defaults );
       
    42 	}
       
    43 
       
    44 	/**
    42 	 * @param WP_Upgrader $upgrader
    45 	 * @param WP_Upgrader $upgrader
    43 	 */
    46 	 */
    44 	public function set_upgrader(&$upgrader) {
    47 	public function set_upgrader( &$upgrader ) {
    45 		if ( is_object($upgrader) )
    48 		if ( is_object( $upgrader ) ) {
    46 			$this->upgrader =& $upgrader;
    49 			$this->upgrader =& $upgrader;
       
    50 		}
    47 		$this->add_strings();
    51 		$this->add_strings();
    48 	}
    52 	}
    49 
    53 
    50 	/**
    54 	/**
    51 	 */
    55 	 */
    82 	public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
    86 	public function request_filesystem_credentials( $error = false, $context = '', $allow_relaxed_file_ownership = false ) {
    83 		$url = $this->options['url'];
    87 		$url = $this->options['url'];
    84 		if ( ! $context ) {
    88 		if ( ! $context ) {
    85 			$context = $this->options['context'];
    89 			$context = $this->options['context'];
    86 		}
    90 		}
    87 		if ( !empty($this->options['nonce']) ) {
    91 		if ( ! empty( $this->options['nonce'] ) ) {
    88 			$url = wp_nonce_url($url, $this->options['nonce']);
    92 			$url = wp_nonce_url( $url, $this->options['nonce'] );
    89 		}
    93 		}
    90 
    94 
    91 		$extra_fields = array();
    95 		$extra_fields = array();
    92 
    96 
    93 		return request_filesystem_credentials( $url, '', $error, $context, $extra_fields, $allow_relaxed_file_ownership );
    97 		return request_filesystem_credentials( $url, '', $error, $context, $extra_fields, $allow_relaxed_file_ownership );
   113 		$this->done_footer = true;
   117 		$this->done_footer = true;
   114 		echo '</div>';
   118 		echo '</div>';
   115 	}
   119 	}
   116 
   120 
   117 	/**
   121 	/**
   118 	 *
       
   119 	 * @param string|WP_Error $errors
   122 	 * @param string|WP_Error $errors
   120 	 */
   123 	 */
   121 	public function error($errors) {
   124 	public function error( $errors ) {
   122 		if ( ! $this->done_header )
   125 		if ( ! $this->done_header ) {
   123 			$this->header();
   126 			$this->header();
   124 		if ( is_string($errors) ) {
   127 		}
   125 			$this->feedback($errors);
   128 		if ( is_string( $errors ) ) {
   126 		} elseif ( is_wp_error($errors) && $errors->get_error_code() ) {
   129 			$this->feedback( $errors );
       
   130 		} elseif ( is_wp_error( $errors ) && $errors->has_errors() ) {
   127 			foreach ( $errors->get_error_messages() as $message ) {
   131 			foreach ( $errors->get_error_messages() as $message ) {
   128 				if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) )
   132 				if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) ) {
   129 					$this->feedback($message . ' ' . esc_html( strip_tags( $errors->get_error_data() ) ) );
   133 					$this->feedback( $message . ' ' . esc_html( strip_tags( $errors->get_error_data() ) ) );
   130 				else
   134 				} else {
   131 					$this->feedback($message);
   135 					$this->feedback( $message );
       
   136 				}
   132 			}
   137 			}
   133 		}
   138 		}
   134 	}
   139 	}
   135 
   140 
   136 	/**
   141 	/**
   137 	 *
       
   138 	 * @param string $string
   142 	 * @param string $string
   139 	 */
   143 	 */
   140 	public function feedback($string) {
   144 	public function feedback( $string ) {
   141 		if ( isset( $this->upgrader->strings[$string] ) )
   145 		if ( isset( $this->upgrader->strings[ $string ] ) ) {
   142 			$string = $this->upgrader->strings[$string];
   146 			$string = $this->upgrader->strings[ $string ];
   143 
   147 		}
   144 		if ( strpos($string, '%') !== false ) {
   148 
       
   149 		if ( strpos( $string, '%' ) !== false ) {
   145 			$args = func_get_args();
   150 			$args = func_get_args();
   146 			$args = array_splice($args, 1);
   151 			$args = array_splice( $args, 1 );
   147 			if ( $args ) {
   152 			if ( $args ) {
   148 				$args = array_map( 'strip_tags', $args );
   153 				$args   = array_map( 'strip_tags', $args );
   149 				$args = array_map( 'esc_html', $args );
   154 				$args   = array_map( 'esc_html', $args );
   150 				$string = vsprintf($string, $args);
   155 				$string = vsprintf( $string, $args );
   151 			}
   156 			}
   152 		}
   157 		}
   153 		if ( empty($string) )
   158 		if ( empty( $string ) ) {
   154 			return;
   159 			return;
   155 		show_message($string);
   160 		}
       
   161 		show_message( $string );
   156 	}
   162 	}
   157 
   163 
   158 	/**
   164 	/**
   159 	 */
   165 	 */
   160 	public function before() {}
   166 	public function before() {}
   183 					}
   189 					}
   184 				</script>';
   190 				</script>';
   185 		} else {
   191 		} else {
   186 			echo '<script type="text/javascript">
   192 			echo '<script type="text/javascript">
   187 					(function( wp ) {
   193 					(function( wp ) {
   188 						if ( wp && wp.updates.decrementCount ) {
   194 						if ( wp && wp.updates && wp.updates.decrementCount ) {
   189 							wp.updates.decrementCount( "' . $type . '" );
   195 							wp.updates.decrementCount( "' . $type . '" );
   190 						}
   196 						}
   191 					})( window.wp );
   197 					})( window.wp );
   192 				</script>';
   198 				</script>';
   193 		}
   199 		}