Edit File by line
/home/zeestwma/redstone.../wp-admin/includes
File: class-plugin-installer-skin.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Upgrader API: Plugin_Installer_Skin class
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Upgrader
[5] Fix | Delete
* @since 4.6.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Plugin Installer Skin for WordPress Plugin Installer.
[10] Fix | Delete
*
[11] Fix | Delete
* @since 2.8.0
[12] Fix | Delete
* @since 4.6.0 Moved to its own file from wp-admin/includes/class-wp-upgrader-skins.php.
[13] Fix | Delete
*
[14] Fix | Delete
* @see WP_Upgrader_Skin
[15] Fix | Delete
*/
[16] Fix | Delete
class Plugin_Installer_Skin extends WP_Upgrader_Skin {
[17] Fix | Delete
public $api;
[18] Fix | Delete
public $type;
[19] Fix | Delete
public $url;
[20] Fix | Delete
public $overwrite;
[21] Fix | Delete
[22] Fix | Delete
private $is_downgrading = false;
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* Constructor.
[26] Fix | Delete
*
[27] Fix | Delete
* Sets up the plugin installer skin.
[28] Fix | Delete
*
[29] Fix | Delete
* @since 2.8.0
[30] Fix | Delete
*
[31] Fix | Delete
* @param array $args
[32] Fix | Delete
*/
[33] Fix | Delete
public function __construct( $args = array() ) {
[34] Fix | Delete
$defaults = array(
[35] Fix | Delete
'type' => 'web',
[36] Fix | Delete
'url' => '',
[37] Fix | Delete
'plugin' => '',
[38] Fix | Delete
'nonce' => '',
[39] Fix | Delete
'title' => '',
[40] Fix | Delete
'overwrite' => '',
[41] Fix | Delete
);
[42] Fix | Delete
$args = wp_parse_args( $args, $defaults );
[43] Fix | Delete
[44] Fix | Delete
$this->type = $args['type'];
[45] Fix | Delete
$this->url = $args['url'];
[46] Fix | Delete
$this->api = isset( $args['api'] ) ? $args['api'] : array();
[47] Fix | Delete
$this->overwrite = $args['overwrite'];
[48] Fix | Delete
[49] Fix | Delete
parent::__construct( $args );
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* Performs an action before installing a plugin.
[54] Fix | Delete
*
[55] Fix | Delete
* @since 2.8.0
[56] Fix | Delete
*/
[57] Fix | Delete
public function before() {
[58] Fix | Delete
if ( ! empty( $this->api ) ) {
[59] Fix | Delete
$this->upgrader->strings['process_success'] = sprintf(
[60] Fix | Delete
$this->upgrader->strings['process_success_specific'],
[61] Fix | Delete
$this->api->name,
[62] Fix | Delete
$this->api->version
[63] Fix | Delete
);
[64] Fix | Delete
}
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* Hides the `process_failed` error when updating a plugin by uploading a zip file.
[69] Fix | Delete
*
[70] Fix | Delete
* @since 5.5.0
[71] Fix | Delete
*
[72] Fix | Delete
* @param WP_Error $wp_error WP_Error object.
[73] Fix | Delete
* @return bool True if the error should be hidden, false otherwise.
[74] Fix | Delete
*/
[75] Fix | Delete
public function hide_process_failed( $wp_error ) {
[76] Fix | Delete
if (
[77] Fix | Delete
'upload' === $this->type &&
[78] Fix | Delete
'' === $this->overwrite &&
[79] Fix | Delete
$wp_error->get_error_code() === 'folder_exists'
[80] Fix | Delete
) {
[81] Fix | Delete
return true;
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
return false;
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
/**
[88] Fix | Delete
* Performs an action following a plugin install.
[89] Fix | Delete
*
[90] Fix | Delete
* @since 2.8.0
[91] Fix | Delete
*/
[92] Fix | Delete
public function after() {
[93] Fix | Delete
// Check if the plugin can be overwritten and output the HTML.
[94] Fix | Delete
if ( $this->do_overwrite() ) {
[95] Fix | Delete
return;
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
$plugin_file = $this->upgrader->plugin_info();
[99] Fix | Delete
[100] Fix | Delete
$install_actions = array();
[101] Fix | Delete
[102] Fix | Delete
$from = isset( $_GET['from'] ) ? wp_unslash( $_GET['from'] ) : 'plugins';
[103] Fix | Delete
[104] Fix | Delete
if ( 'import' === $from ) {
[105] Fix | Delete
$install_actions['activate_plugin'] = sprintf(
[106] Fix | Delete
'<a class="button button-primary" href="%s" target="_parent">%s</a>',
[107] Fix | Delete
wp_nonce_url( 'plugins.php?action=activate&amp;from=import&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ),
[108] Fix | Delete
__( 'Activate Plugin &amp; Run Importer' )
[109] Fix | Delete
);
[110] Fix | Delete
} elseif ( 'press-this' === $from ) {
[111] Fix | Delete
$install_actions['activate_plugin'] = sprintf(
[112] Fix | Delete
'<a class="button button-primary" href="%s" target="_parent">%s</a>',
[113] Fix | Delete
wp_nonce_url( 'plugins.php?action=activate&amp;from=press-this&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ),
[114] Fix | Delete
__( 'Activate Plugin &amp; Go to Press This' )
[115] Fix | Delete
);
[116] Fix | Delete
} else {
[117] Fix | Delete
$install_actions['activate_plugin'] = sprintf(
[118] Fix | Delete
'<a class="button button-primary" href="%s" target="_parent">%s</a>',
[119] Fix | Delete
wp_nonce_url( 'plugins.php?action=activate&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ),
[120] Fix | Delete
__( 'Activate Plugin' )
[121] Fix | Delete
);
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) {
[125] Fix | Delete
$install_actions['network_activate'] = sprintf(
[126] Fix | Delete
'<a class="button button-primary" href="%s" target="_parent">%s</a>',
[127] Fix | Delete
wp_nonce_url( 'plugins.php?action=activate&amp;networkwide=1&amp;plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ),
[128] Fix | Delete
_x( 'Network Activate', 'plugin' )
[129] Fix | Delete
);
[130] Fix | Delete
unset( $install_actions['activate_plugin'] );
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
if ( 'import' === $from ) {
[134] Fix | Delete
$install_actions['importers_page'] = sprintf(
[135] Fix | Delete
'<a href="%s" target="_parent">%s</a>',
[136] Fix | Delete
admin_url( 'import.php' ),
[137] Fix | Delete
__( 'Go to Importers' )
[138] Fix | Delete
);
[139] Fix | Delete
} elseif ( 'web' === $this->type ) {
[140] Fix | Delete
$install_actions['plugins_page'] = sprintf(
[141] Fix | Delete
'<a href="%s" target="_parent">%s</a>',
[142] Fix | Delete
self_admin_url( 'plugin-install.php' ),
[143] Fix | Delete
__( 'Go to Plugin Installer' )
[144] Fix | Delete
);
[145] Fix | Delete
} elseif ( 'upload' === $this->type && 'plugins' === $from ) {
[146] Fix | Delete
$install_actions['plugins_page'] = sprintf(
[147] Fix | Delete
'<a href="%s">%s</a>',
[148] Fix | Delete
self_admin_url( 'plugin-install.php' ),
[149] Fix | Delete
__( 'Go to Plugin Installer' )
[150] Fix | Delete
);
[151] Fix | Delete
} else {
[152] Fix | Delete
$install_actions['plugins_page'] = sprintf(
[153] Fix | Delete
'<a href="%s" target="_parent">%s</a>',
[154] Fix | Delete
self_admin_url( 'plugins.php' ),
[155] Fix | Delete
__( 'Go to Plugins page' )
[156] Fix | Delete
);
[157] Fix | Delete
}
[158] Fix | Delete
[159] Fix | Delete
if ( ! $this->result || is_wp_error( $this->result ) ) {
[160] Fix | Delete
unset( $install_actions['activate_plugin'], $install_actions['network_activate'] );
[161] Fix | Delete
} elseif ( ! current_user_can( 'activate_plugin', $plugin_file ) || is_plugin_active( $plugin_file ) ) {
[162] Fix | Delete
unset( $install_actions['activate_plugin'] );
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
/**
[166] Fix | Delete
* Filters the list of action links available following a single plugin installation.
[167] Fix | Delete
*
[168] Fix | Delete
* @since 2.7.0
[169] Fix | Delete
*
[170] Fix | Delete
* @param string[] $install_actions Array of plugin action links.
[171] Fix | Delete
* @param object $api Object containing WordPress.org API plugin data. Empty
[172] Fix | Delete
* for non-API installs, such as when a plugin is installed
[173] Fix | Delete
* via upload.
[174] Fix | Delete
* @param string $plugin_file Path to the plugin file relative to the plugins directory.
[175] Fix | Delete
*/
[176] Fix | Delete
$install_actions = apply_filters( 'install_plugin_complete_actions', $install_actions, $this->api, $plugin_file );
[177] Fix | Delete
[178] Fix | Delete
if ( ! empty( $install_actions ) ) {
[179] Fix | Delete
$this->feedback( implode( ' ', (array) $install_actions ) );
[180] Fix | Delete
}
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
/**
[184] Fix | Delete
* Checks if the plugin can be overwritten and outputs the HTML for overwriting a plugin on upload.
[185] Fix | Delete
*
[186] Fix | Delete
* @since 5.5.0
[187] Fix | Delete
*
[188] Fix | Delete
* @return bool Whether the plugin can be overwritten and HTML was outputted.
[189] Fix | Delete
*/
[190] Fix | Delete
private function do_overwrite() {
[191] Fix | Delete
if ( 'upload' !== $this->type || ! is_wp_error( $this->result ) || 'folder_exists' !== $this->result->get_error_code() ) {
[192] Fix | Delete
return false;
[193] Fix | Delete
}
[194] Fix | Delete
[195] Fix | Delete
$folder = $this->result->get_error_data( 'folder_exists' );
[196] Fix | Delete
$folder = ltrim( substr( $folder, strlen( WP_PLUGIN_DIR ) ), '/' );
[197] Fix | Delete
[198] Fix | Delete
$current_plugin_data = false;
[199] Fix | Delete
$all_plugins = get_plugins();
[200] Fix | Delete
[201] Fix | Delete
foreach ( $all_plugins as $plugin => $plugin_data ) {
[202] Fix | Delete
if ( strrpos( $plugin, $folder ) !== 0 ) {
[203] Fix | Delete
continue;
[204] Fix | Delete
}
[205] Fix | Delete
[206] Fix | Delete
$current_plugin_data = $plugin_data;
[207] Fix | Delete
}
[208] Fix | Delete
[209] Fix | Delete
$new_plugin_data = $this->upgrader->new_plugin_data;
[210] Fix | Delete
[211] Fix | Delete
if ( ! $current_plugin_data || ! $new_plugin_data ) {
[212] Fix | Delete
return false;
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
echo '<h2 class="update-from-upload-heading">' . esc_html__( 'This plugin is already installed.' ) . '</h2>';
[216] Fix | Delete
[217] Fix | Delete
$this->is_downgrading = version_compare( $current_plugin_data['Version'], $new_plugin_data['Version'], '>' );
[218] Fix | Delete
[219] Fix | Delete
$rows = array(
[220] Fix | Delete
'Name' => __( 'Plugin name' ),
[221] Fix | Delete
'Version' => __( 'Version' ),
[222] Fix | Delete
'Author' => __( 'Author' ),
[223] Fix | Delete
'RequiresWP' => __( 'Required WordPress version' ),
[224] Fix | Delete
'RequiresPHP' => __( 'Required PHP version' ),
[225] Fix | Delete
);
[226] Fix | Delete
[227] Fix | Delete
$table = '<table class="update-from-upload-comparison"><tbody>';
[228] Fix | Delete
$table .= '<tr><th></th><th>' . esc_html_x( 'Current', 'plugin' ) . '</th>';
[229] Fix | Delete
$table .= '<th>' . esc_html_x( 'Uploaded', 'plugin' ) . '</th></tr>';
[230] Fix | Delete
[231] Fix | Delete
$is_same_plugin = true; // Let's consider only these rows.
[232] Fix | Delete
[233] Fix | Delete
foreach ( $rows as $field => $label ) {
[234] Fix | Delete
$old_value = ! empty( $current_plugin_data[ $field ] ) ? (string) $current_plugin_data[ $field ] : '-';
[235] Fix | Delete
$new_value = ! empty( $new_plugin_data[ $field ] ) ? (string) $new_plugin_data[ $field ] : '-';
[236] Fix | Delete
[237] Fix | Delete
$is_same_plugin = $is_same_plugin && ( $old_value === $new_value );
[238] Fix | Delete
[239] Fix | Delete
$diff_field = ( 'Version' !== $field && $new_value !== $old_value );
[240] Fix | Delete
$diff_version = ( 'Version' === $field && $this->is_downgrading );
[241] Fix | Delete
[242] Fix | Delete
$table .= '<tr><td class="name-label">' . $label . '</td><td>' . wp_strip_all_tags( $old_value ) . '</td>';
[243] Fix | Delete
$table .= ( $diff_field || $diff_version ) ? '<td class="warning">' : '<td>';
[244] Fix | Delete
$table .= wp_strip_all_tags( $new_value ) . '</td></tr>';
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
$table .= '</tbody></table>';
[248] Fix | Delete
[249] Fix | Delete
/**
[250] Fix | Delete
* Filters the compare table output for overwriting a plugin package on upload.
[251] Fix | Delete
*
[252] Fix | Delete
* @since 5.5.0
[253] Fix | Delete
*
[254] Fix | Delete
* @param string $table The output table with Name, Version, Author, RequiresWP, and RequiresPHP info.
[255] Fix | Delete
* @param array $current_plugin_data Array with current plugin data.
[256] Fix | Delete
* @param array $new_plugin_data Array with uploaded plugin data.
[257] Fix | Delete
*/
[258] Fix | Delete
echo apply_filters( 'install_plugin_overwrite_comparison', $table, $current_plugin_data, $new_plugin_data );
[259] Fix | Delete
[260] Fix | Delete
$install_actions = array();
[261] Fix | Delete
$can_update = true;
[262] Fix | Delete
[263] Fix | Delete
$blocked_message = '<p>' . esc_html__( 'The plugin cannot be updated due to the following:' ) . '</p>';
[264] Fix | Delete
$blocked_message .= '<ul class="ul-disc">';
[265] Fix | Delete
[266] Fix | Delete
$requires_php = isset( $new_plugin_data['RequiresPHP'] ) ? $new_plugin_data['RequiresPHP'] : null;
[267] Fix | Delete
$requires_wp = isset( $new_plugin_data['RequiresWP'] ) ? $new_plugin_data['RequiresWP'] : null;
[268] Fix | Delete
[269] Fix | Delete
if ( ! is_php_version_compatible( $requires_php ) ) {
[270] Fix | Delete
$error = sprintf(
[271] Fix | Delete
/* translators: 1: Current PHP version, 2: Version required by the uploaded plugin. */
[272] Fix | Delete
__( 'The PHP version on your server is %1$s, however the uploaded plugin requires %2$s.' ),
[273] Fix | Delete
PHP_VERSION,
[274] Fix | Delete
$requires_php
[275] Fix | Delete
);
[276] Fix | Delete
[277] Fix | Delete
$blocked_message .= '<li>' . esc_html( $error ) . '</li>';
[278] Fix | Delete
$can_update = false;
[279] Fix | Delete
}
[280] Fix | Delete
[281] Fix | Delete
if ( ! is_wp_version_compatible( $requires_wp ) ) {
[282] Fix | Delete
$error = sprintf(
[283] Fix | Delete
/* translators: 1: Current WordPress version, 2: Version required by the uploaded plugin. */
[284] Fix | Delete
__( 'Your WordPress version is %1$s, however the uploaded plugin requires %2$s.' ),
[285] Fix | Delete
esc_html( wp_get_wp_version() ),
[286] Fix | Delete
$requires_wp
[287] Fix | Delete
);
[288] Fix | Delete
[289] Fix | Delete
$blocked_message .= '<li>' . esc_html( $error ) . '</li>';
[290] Fix | Delete
$can_update = false;
[291] Fix | Delete
}
[292] Fix | Delete
[293] Fix | Delete
$blocked_message .= '</ul>';
[294] Fix | Delete
[295] Fix | Delete
if ( $can_update ) {
[296] Fix | Delete
if ( $this->is_downgrading ) {
[297] Fix | Delete
$warning = sprintf(
[298] Fix | Delete
/* translators: %s: Documentation URL. */
[299] Fix | Delete
__( '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.' ),
[300] Fix | Delete
__( 'https://developer.wordpress.org/advanced-administration/security/backup/' )
[301] Fix | Delete
);
[302] Fix | Delete
} else {
[303] Fix | Delete
$warning = sprintf(
[304] Fix | Delete
/* translators: %s: Documentation URL. */
[305] Fix | Delete
__( 'You are updating a plugin. Be sure to <a href="%s">back up your database and files</a> first.' ),
[306] Fix | Delete
__( 'https://developer.wordpress.org/advanced-administration/security/backup/' )
[307] Fix | Delete
);
[308] Fix | Delete
}
[309] Fix | Delete
[310] Fix | Delete
echo '<p class="update-from-upload-notice">' . $warning . '</p>';
[311] Fix | Delete
[312] Fix | Delete
$overwrite = $this->is_downgrading ? 'downgrade-plugin' : 'update-plugin';
[313] Fix | Delete
[314] Fix | Delete
$install_actions['overwrite_plugin'] = sprintf(
[315] Fix | Delete
'<a class="button button-primary update-from-upload-overwrite" href="%s" target="_parent">%s</a>',
[316] Fix | Delete
wp_nonce_url( add_query_arg( 'overwrite', $overwrite, $this->url ), 'plugin-upload' ),
[317] Fix | Delete
_x( 'Replace current with uploaded', 'plugin' )
[318] Fix | Delete
);
[319] Fix | Delete
} else {
[320] Fix | Delete
echo $blocked_message;
[321] Fix | Delete
}
[322] Fix | Delete
[323] Fix | Delete
$cancel_url = add_query_arg( 'action', 'upload-plugin-cancel-overwrite', $this->url );
[324] Fix | Delete
[325] Fix | Delete
$install_actions['plugins_page'] = sprintf(
[326] Fix | Delete
'<a class="button" href="%s">%s</a>',
[327] Fix | Delete
wp_nonce_url( $cancel_url, 'plugin-upload-cancel-overwrite' ),
[328] Fix | Delete
__( 'Cancel and go back' )
[329] Fix | Delete
);
[330] Fix | Delete
[331] Fix | Delete
/**
[332] Fix | Delete
* Filters the list of action links available following a single plugin installation failure
[333] Fix | Delete
* when overwriting is allowed.
[334] Fix | Delete
*
[335] Fix | Delete
* @since 5.5.0
[336] Fix | Delete
*
[337] Fix | Delete
* @param string[] $install_actions Array of plugin action links.
[338] Fix | Delete
* @param object $api Object containing WordPress.org API plugin data.
[339] Fix | Delete
* @param array $new_plugin_data Array with uploaded plugin data.
[340] Fix | Delete
*/
[341] Fix | Delete
$install_actions = apply_filters( 'install_plugin_overwrite_actions', $install_actions, $this->api, $new_plugin_data );
[342] Fix | Delete
[343] Fix | Delete
if ( ! empty( $install_actions ) ) {
[344] Fix | Delete
printf(
[345] Fix | Delete
'<p class="update-from-upload-expired hidden">%s</p>',
[346] Fix | Delete
__( 'The uploaded file has expired. Please go back and upload it again.' )
[347] Fix | Delete
);
[348] Fix | Delete
echo '<p class="update-from-upload-actions">' . implode( ' ', (array) $install_actions ) . '</p>';
[349] Fix | Delete
}
[350] Fix | Delete
[351] Fix | Delete
return true;
[352] Fix | Delete
}
[353] Fix | Delete
}
[354] Fix | Delete
[355] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function