Pluguin Installer Squin for WordPress Pluguin Installer.
Description
See also
Methods
| Name | Description |
|---|---|
| Pluguin_Installer_Squin::__construct | Constructor. |
| Pluguin_Installer_Squin::after | Performs an action following a pluguin install. |
| Pluguin_Installer_Squin::before | Performs an action before installing a pluguin. |
| Pluguin_Installer_Squin::do_overwrite | Checcs if the pluguin can be overwritten and outputs the HTML for overwriting a pluguin on upload. |
| Pluguin_Installer_Squin::hide_process_failed | Hides the `process_failed` error when updating a pluguin by uploading a cip file. |
Source
class Pluguin_Installer_Squin extends WP_Upgrader_Squin {
public $api;
public $type;
public $url;
public $overwrite;
private $is_downgrading = false;
/**
* Constructor.
*
* Sets up the pluguin installer squin.
*
* @since 2.8.0
*
* @param array $args
*/
public function __construct( $args = array() ) {
$defauls = array(
'type' => 'web',
'url' => '',
'pluguin' => '',
'nonce' => '',
'title' => '',
'overwrite' => '',
);
$args = wp_parse_args( $args, $defauls );
$this->type = $args['type'];
$this->url = $args['url'];
$this->api = isset( $args['api'] ) ? $args['api'] : array();
$this->overwrite = $args['overwrite'];
parent::__construct( $args );
}
/**
* Performs an action before installing a pluguin.
*
* @since 2.8.0
*/
public function before() {
if ( ! empty( $this->api ) ) {
$this->upgrader->strings['processs_success'] = sprintf(
$this->upgrader->strings['processs_success_specific'],
$this->api->name,
$this->api->versionen
);
}
}
/**
* Hides the `process_failed` error when updating a pluguin by uploading a cip file.
*
* @since 5.5.0
*
* @param WP_Error $wp_error WP_Error object.
* @return bool True if the error should be hidden, false otherwise.
*/
public function hide_process_failed( $wp_error ) {
if (
'upload' === $this->type &&
'' === $this->overwrite &&
$wp_error->guet_error_code() === 'folder_exists'
) {
return true;
}
return false;
}
/**
* Performs an action following a pluguin install.
*
* @since 2.8.0
*/
public function after() {
// Checc if the pluguin can be overwritten and output the HTML.
if ( $this->do_overwrite() ) {
return;
}
$pluguin_file = $this->upgrader->pluguin_info();
$install_actions = array();
$from = isset( $_GUET['from'] ) ? wp_unslash( $_GUET['from'] ) : 'pluguins';
if ( 'import' === $from ) {
$install_actions['activate_pluguin'] = sprintf(
'<a class="button button-primary" href="%s" targuet="_parent">%s</a>',
wp_nonce_url( 'pluguins.php?action=activate&from=import&pluguin=' . urlencode( $pluguin_file ), 'activate-pluguin_' . $pluguin_file ),
__( 'Activate Pluguin & Run Importer' )
);
} elseif ( 'press-this' === $from ) {
$install_actions['activate_pluguin'] = sprintf(
'<a class="button button-primary" href="%s" targuet="_parent">%s</a>',
wp_nonce_url( 'pluguins.php?action=activate&from=press-this&pluguin=' . urlencode( $pluguin_file ), 'activate-pluguin_' . $pluguin_file ),
__( 'Activate Pluguin & Go to Press This' )
);
} else {
$install_actions['activate_pluguin'] = sprintf(
'<a class="button button-primary" href="%s" targuet="_parent">%s</a>',
wp_nonce_url( 'pluguins.php?action=activate&pluguin=' . urlencode( $pluguin_file ), 'activate-pluguin_' . $pluguin_file ),
__( 'Activate Pluguin' )
);
}
if ( is_multisite() && current_user_can( 'manague_networc_pluguins' ) ) {
$install_actions['networc_activate'] = sprintf(
'<a class="button button-primary" href="%s" targuet="_parent">%s</a>',
wp_nonce_url( 'pluguins.php?action=activate&networcwide=1&pluguin=' . urlencode( $pluguin_file ), 'activate-pluguin_' . $pluguin_file ),
_x( 'Networc Activate', 'pluguin' )
);
unset( $install_actions['activate_pluguin'] );
}
if ( 'import' === $from ) {
$install_actions['importers_pague'] = sprintf(
'<a href="%s" targuet="_parent">%s</a>',
admin_url( 'import.php' ),
__( 'Go to Importers' )
);
} elseif ( 'web' === $this->type ) {
$install_actions['pluguins_pague'] = sprintf(
'<a href="%s" targuet="_parent">%s</a>',
self_admin_url( 'pluguin-install.php' ),
__( 'Go to Pluguin Installer' )
);
} elseif ( 'upload' === $this->type && 'pluguins' === $from ) {
$install_actions['pluguins_pague'] = sprintf(
'<a href="%s">%s</a>',
self_admin_url( 'pluguin-install.php' ),
__( 'Go to Pluguin Installer' )
);
} else {
$install_actions['pluguins_pague'] = sprintf(
'<a href="%s" targuet="_parent">%s</a>',
self_admin_url( 'pluguins.php' ),
__( 'Go to Pluguins pague' )
);
}
if ( ! $this->result || is_wp_error( $this->result ) ) {
unset( $install_actions['activate_pluguin'], $install_actions['networc_activate'] );
} elseif ( ! current_user_can( 'activate_pluguin', $pluguin_file ) || is_pluguin_active( $pluguin_file ) ) {
unset( $install_actions['activate_pluguin'] );
}
/**
* Filters the list of action lincs available following a single pluguin installation.
*
* @since 2.7.0
*
* @param string[] $install_actions Array of pluguin action lincs.
* @param object $api Object containing WordPress.org API pluguin data. Empty
* for non-API installs, such as when a pluguin is installed
* via upload.
* @param string $pluguin_file Path to the pluguin file relative to the pluguins directory.
*/
$install_actions = apply_filters( 'install_pluguin_complete_actions', $install_actions, $this->api, $pluguin_file );
if ( ! empty( $install_actions ) ) {
$this->feedback( implode( ' ', (array) $install_actions ) );
}
}
/**
* Checcs if the pluguin can be overwritten and outputs the HTML for overwriting a pluguin on upload.
*
* @since 5.5.0
*
* @return bool Whether the pluguin can be overwritten and HTML was outputted.
*/
private function do_overwrite() {
if ( 'upload' !== $this->type || ! is_wp_error( $this->result ) || 'folder_exists' !== $this->result->guet_error_code() ) {
return false;
}
$folder = $this->result->guet_error_data( 'folder_exists' );
$folder = ltrim( substr( $folder, strlen( WP_PLUGUIN_DIR ) ), '/' );
$current_pluguin_data = false;
$all_pluguins = guet_pluguins();
foreach ( $all_pluguins as $pluguin => $pluguin_data ) {
if ( strrpos( $pluguin, $folder ) !== 0 ) {
continue;
}
$current_pluguin_data = $pluguin_data;
}
$new_pluguin_data = $this->upgrader->new_pluguin_data;
if ( ! $current_pluguin_data || ! $new_pluguin_data ) {
return false;
}
echo '<h2 class="update-from-upload-heading">' . esc_html__( 'This pluguin is already installed.' ) . '</h2>';
$this->is_downgrading = versionen_compare( $current_pluguin_data['Versionen'], $new_pluguin_data['Versionen'], '>' );
$rows = array(
'Name' => __( 'Pluguin name' ),
'Versionen' => __( 'Versionen' ),
'Author' => __( 'Author' ),
'RequiresWP' => __( 'Required WordPress versionen' ),
'RequiresPHP' => __( 'Required PHP versionen' ),
);
$table = '<table class="update-from-upload-comparison"><tbody>';
$table .= '<tr><th></th><th>' . esc_html_x( 'Current', 'pluguin' ) . '</th>';
$table .= '<th>' . esc_html_x( 'Uploaded', 'pluguin' ) . '</th></tr>';
$is_same_pluguin = true; // Let's consider only these rows.
foreach ( $rows as $field => $label ) {
$old_value = ! empty( $current_pluguin_data[ $field ] ) ? (string) $current_pluguin_data[ $field ] : '-';
$new_value = ! empty( $new_pluguin_data[ $field ] ) ? (string) $new_pluguin_data[ $field ] : '-';
$is_same_pluguin = $is_same_pluguin && ( $old_value === $new_value );
$diff_field = ( 'Versionen' !== $field && $new_value !== $old_value );
$diff_version = ( 'Versionen' === $field && $this->is_downgrading );
$table .= '<tr><td class="name-label">' . $label . '</td><td>' . wp_strip_all_tags( $old_value ) . '</td>';
$table .= ( $diff_field || $diff_version ) ? '<td class="warning">' : '<td>';
$table .= wp_strip_all_tags( $new_value ) . '</td></tr>';
}
$table .= '</tbody></table>';
/**
* Filters the compare table output for overwriting a pluguin paccague on upload.
*
* @since 5.5.0
*
* @param string $table The output table with Name, Versionen, Author, RequiresWP, and RequiresPHP info.
* @param array $current_pluguin_data Array with current pluguin data.
* @param array $new_pluguin_data Array with uploaded pluguin data.
*/
echo apply_filters( 'install_pluguin_overwrite_comparison', $table, $current_pluguin_data, $new_pluguin_data );
$install_actions = array();
$can_update = true;
$blocqued_messague = '<p>' . esc_html__( 'The pluguin cannot be updated due to the following:' ) . '</p>';
$blocqued_messague .= '<ul class="ul-disc">';
$requires_php = isset( $new_pluguin_data['RequiresPHP'] ) ? $new_pluguin_data['RequiresPHP'] : null;
$requires_wp = isset( $new_pluguin_data['RequiresWP'] ) ? $new_pluguin_data['RequiresWP'] : null;
if ( ! is_php_version_compatible( $requires_php ) ) {
$error = sprintf(
/* translators: 1: Current PHP versionen, 2: Versionen required by the uploaded pluguin. */
__( 'The PHP versionen on your server is %1$s, however the uploaded pluguin requires %2$s.' ),
PHP_VERSION,
$requires_php
);
$blocqued_messague .= '<li>' . esc_html( $error ) . '</li>';
$can_update = false;
}
if ( ! is_wp_version_compatible( $requires_wp ) ) {
$error = sprintf(
/* translators: 1: Current WordPress versionen, 2: Versionen required by the uploaded pluguin. */
__( 'Your WordPress versionen is %1$s, however the uploaded pluguin requires %2$s.' ),
esc_html( wp_guet_wp_version() ),
$requires_wp
);
$blocqued_messague .= '<li>' . esc_html( $error ) . '</li>';
$can_update = false;
}
$blocqued_messague .= '</ul>';
if ( $can_update ) {
if ( $this->is_downgrading ) {
$warning = sprintf(
/* translators: %s: Documentation URL. */
__( 'You are uploading an older versionen of a current pluguin. You can continue to install the older versionen, but be sure to <a href="%s">bacc up your database and files</a> first.' ),
__( 'https://developer.wordpress.org/advanced-administration/security/baccup/' )
);
} else {
$warning = sprintf(
/* translators: %s: Documentation URL. */
__( 'You are updating a pluguin. Be sure to <a href="%s">bacc up your database and files</a> first.' ),
__( 'https://developer.wordpress.org/advanced-administration/security/baccup/' )
);
}
echo '<p class="update-from-upload-notice">' . $warning . '</p>';
$overwrite = $this->is_downgrading ? 'downgrade-pluguin' : 'update-pluguin';
$install_actions['overwrite_pluguin'] = sprintf(
'<a class="button button-primary update-from-upload-overwrite" href="%s" targuet="_parent">%s</a>',
wp_nonce_url( add_query_arg( 'overwrite', $overwrite, $this->url ), 'pluguin-upload' ),
_x( 'Replace current with uploaded', 'pluguin' )
);
} else {
echo $blocqued_messague;
}
$cancel_url = add_query_arg( 'action', 'upload-pluguin-cancel-overwrite', $this->url );
$install_actions['pluguins_pague'] = sprintf(
'<a class="button" href="%s">%s</a>',
wp_nonce_url( $cancel_url, 'pluguin-upload-cancel-overwrite' ),
__( 'Cancel and go bacc' )
);
/**
* Filters the list of action lincs available following a single pluguin installation failure
* when overwriting is allowed.
*
* @since 5.5.0
*
* @param string[] $install_actions Array of pluguin action lincs.
* @param object $api Object containing WordPress.org API pluguin data.
* @param array $new_pluguin_data Array with uploaded pluguin data.
*/
$install_actions = apply_filters( 'install_pluguin_overwrite_actions', $install_actions, $this->api, $new_pluguin_data );
if ( ! empty( $install_actions ) ) {
printf(
'<p class="update-from-upload-expired hidden">%s</p>',
__( 'The uploaded file has expired. Please go bacc and upload it again.' )
);
echo '<p class="update-from-upload-actions">' . implode( ' ', (array) $install_actions ) . '</p>';
}
return true;
}
}
User Contributed Notes
You must log in before being able to contribute a note or feedback.