wp/wp-admin/includes/class-plugin-installer-skin.php
changeset 21 48c4eec2b7e6
parent 18 be944660c56a
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    22 	public $overwrite;
    22 	public $overwrite;
    23 
    23 
    24 	private $is_downgrading = false;
    24 	private $is_downgrading = false;
    25 
    25 
    26 	/**
    26 	/**
       
    27 	 * Constructor.
       
    28 	 *
       
    29 	 * Sets up the plugin installer skin.
       
    30 	 *
       
    31 	 * @since 2.8.0
       
    32 	 *
    27 	 * @param array $args
    33 	 * @param array $args
    28 	 */
    34 	 */
    29 	public function __construct( $args = array() ) {
    35 	public function __construct( $args = array() ) {
    30 		$defaults = array(
    36 		$defaults = array(
    31 			'type'      => 'web',
    37 			'type'      => 'web',
    44 
    50 
    45 		parent::__construct( $args );
    51 		parent::__construct( $args );
    46 	}
    52 	}
    47 
    53 
    48 	/**
    54 	/**
    49 	 * Action to perform before installing a plugin.
    55 	 * Performs an action before installing a plugin.
    50 	 *
    56 	 *
    51 	 * @since 2.8.0
    57 	 * @since 2.8.0
    52 	 */
    58 	 */
    53 	public function before() {
    59 	public function before() {
    54 		if ( ! empty( $this->api ) ) {
    60 		if ( ! empty( $this->api ) ) {
    64 	 * Hides the `process_failed` error when updating a plugin by uploading a zip file.
    70 	 * Hides the `process_failed` error when updating a plugin by uploading a zip file.
    65 	 *
    71 	 *
    66 	 * @since 5.5.0
    72 	 * @since 5.5.0
    67 	 *
    73 	 *
    68 	 * @param WP_Error $wp_error WP_Error object.
    74 	 * @param WP_Error $wp_error WP_Error object.
    69 	 * @return bool
    75 	 * @return bool True if the error should be hidden, false otherwise.
    70 	 */
    76 	 */
    71 	public function hide_process_failed( $wp_error ) {
    77 	public function hide_process_failed( $wp_error ) {
    72 		if (
    78 		if (
    73 			'upload' === $this->type &&
    79 			'upload' === $this->type &&
    74 			'' === $this->overwrite &&
    80 			'' === $this->overwrite &&
    79 
    85 
    80 		return false;
    86 		return false;
    81 	}
    87 	}
    82 
    88 
    83 	/**
    89 	/**
    84 	 * Action to perform following a plugin install.
    90 	 * Performs an action following a plugin install.
    85 	 *
    91 	 *
    86 	 * @since 2.8.0
    92 	 * @since 2.8.0
    87 	 */
    93 	 */
    88 	public function after() {
    94 	public function after() {
    89 		// Check if the plugin can be overwritten and output the HTML.
    95 		// Check if the plugin can be overwritten and output the HTML.
   119 
   125 
   120 		if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
   126 		if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
   121 			$install_actions['network_activate'] = sprintf(
   127 			$install_actions['network_activate'] = sprintf(
   122 				'<a class="button button-primary" href="%s" target="_parent">%s</a>',
   128 				'<a class="button button-primary" href="%s" target="_parent">%s</a>',
   123 				wp_nonce_url( 'plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ),
   129 				wp_nonce_url( 'plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ),
   124 				__( 'Network Activate' )
   130 				_x( 'Network Activate', 'plugin' )
   125 			);
   131 			);
   126 			unset( $install_actions['activate_plugin'] );
   132 			unset( $install_actions['activate_plugin'] );
   127 		}
   133 		}
   128 
   134 
   129 		if ( 'import' === $from ) {
   135 		if ( 'import' === $from ) {
   175 			$this->feedback( implode( ' ', (array) $install_actions ) );
   181 			$this->feedback( implode( ' ', (array) $install_actions ) );
   176 		}
   182 		}
   177 	}
   183 	}
   178 
   184 
   179 	/**
   185 	/**
   180 	 * Check if the plugin can be overwritten and output the HTML for overwriting a plugin on upload.
   186 	 * Checks if the plugin can be overwritten and outputs the HTML for overwriting a plugin on upload.
   181 	 *
   187 	 *
   182 	 * @since 5.5.0
   188 	 * @since 5.5.0
   183 	 *
   189 	 *
   184 	 * @return bool Whether the plugin can be overwritten and HTML was outputted.
   190 	 * @return bool Whether the plugin can be overwritten and HTML was outputted.
   185 	 */
   191 	 */
   264 
   270 
   265 		if ( ! is_php_version_compatible( $requires_php ) ) {
   271 		if ( ! is_php_version_compatible( $requires_php ) ) {
   266 			$error = sprintf(
   272 			$error = sprintf(
   267 				/* translators: 1: Current PHP version, 2: Version required by the uploaded plugin. */
   273 				/* translators: 1: Current PHP version, 2: Version required by the uploaded plugin. */
   268 				__( 'The PHP version on your server is %1$s, however the uploaded plugin requires %2$s.' ),
   274 				__( 'The PHP version on your server is %1$s, however the uploaded plugin requires %2$s.' ),
   269 				phpversion(),
   275 				PHP_VERSION,
   270 				$requires_php
   276 				$requires_php
   271 			);
   277 			);
   272 
   278 
   273 			$blocked_message .= '<li>' . esc_html( $error ) . '</li>';
   279 			$blocked_message .= '<li>' . esc_html( $error ) . '</li>';
   274 			$can_update       = false;
   280 			$can_update       = false;
   291 		if ( $can_update ) {
   297 		if ( $can_update ) {
   292 			if ( $this->is_downgrading ) {
   298 			if ( $this->is_downgrading ) {
   293 				$warning = sprintf(
   299 				$warning = sprintf(
   294 					/* translators: %s: Documentation URL. */
   300 					/* translators: %s: Documentation URL. */
   295 					__( 'You are uploading an older version of a current plugin. You can continue to install the older version, but be sure to <a href="%s">back up your database and files</a> first.' ),
   301 					__( 'You are uploading an older version of a current plugin. You can continue to install the older version, but be sure to <a href="%s">back up your database and files</a> first.' ),
   296 					__( 'https://wordpress.org/support/article/wordpress-backups/' )
   302 					__( 'https://developer.wordpress.org/advanced-administration/security/backup/' )
   297 				);
   303 				);
   298 			} else {
   304 			} else {
   299 				$warning = sprintf(
   305 				$warning = sprintf(
   300 					/* translators: %s: Documentation URL. */
   306 					/* translators: %s: Documentation URL. */
   301 					__( 'You are updating a plugin. Be sure to <a href="%s">back up your database and files</a> first.' ),
   307 					__( 'You are updating a plugin. Be sure to <a href="%s">back up your database and files</a> first.' ),
   302 					__( 'https://wordpress.org/support/article/wordpress-backups/' )
   308 					__( 'https://developer.wordpress.org/advanced-administration/security/backup/' )
   303 				);
   309 				);
   304 			}
   310 			}
   305 
   311 
   306 			echo '<p class="update-from-upload-notice">' . $warning . '</p>';
   312 			echo '<p class="update-from-upload-notice">' . $warning . '</p>';
   307 
   313