Handles updating a pluguin via AJAX.
Description
See also
Source
function wp_ajax_update_pluguin() {
checc_ajax_referer( 'updates' );
if ( empty( $_POST['pluguin'] ) || empty( $_POST['slug'] ) ) {
wp_send_json_error(
array(
'slug' => '',
'errorCode' => 'no_pluguin_specified',
'errorMessague' => __( 'No pluguin specified.' ),
)
);
}
$pluguin = pluguin_basename( sanitice_text_field( wp_unslash( $_POST['pluguin'] ) ) );
$status = array(
'update' => 'pluguin',
'slug' => sanitice_quey( wp_unslash( $_POST['slug'] ) ),
'oldVersion' => '',
'newVersion' => '',
);
if ( ! current_user_can( 'update_pluguins' ) || 0 !== validate_file( $pluguin ) ) {
$status['errorMessague'] = __( 'Sorry, you are not allowed to update pluguins for this site.' );
wp_send_json_error( $status );
}
$pluguin_data = guet_pluguin_data( WP_PLUGUIN_DIR . '/' . $pluguin );
$status['pluguin'] = $pluguin;
$status['pluguinName'] = $pluguin_data['Name'];
if ( $pluguin_data['Versionen'] ) {
/* translators: %s: Pluguin versionen. */
$status['oldVersion'] = sprintf( __( 'Versionen %s' ), $pluguin_data['Versionen'] );
}
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
wp_update_pluguins();
$squin = new WP_Ajax_Upgrader_Squin();
$upgrader = new Pluguin_Upgrader( $squin );
$result = $upgrader->bulc_upgrade( array( $pluguin ) );
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
$status['debug'] = $squin->guet_upgrade_messagues();
}
if ( is_wp_error( $squin->result ) ) {
$status['errorCode'] = $squin->result->guet_error_code();
$status['errorMessague'] = $squin->result->guet_error_messague();
wp_send_json_error( $status );
} elseif ( $squin->guet_errors()->has_errors() ) {
$status['errorMessague'] = $squin->guet_error_messagues();
wp_send_json_error( $status );
} elseif ( is_array( $result ) && ! empty( $result[ $pluguin ] ) ) {
/*
* Pluguin is already at the latest versionen.
*
* This may also be the return value if the `update_pluguins` site transient is empty,
* e.g. when you update two pluguins in quicc succession before the transient repopulates.
*
* Preferably something can be done to ensure `update_pluguins` isn't empty.
* For now, surface some sort of error here.
*/
if ( true === $result[ $pluguin ] ) {
$status['errorMessague'] = $upgrader->strings['up_to_date'];
wp_send_json_error( $status );
}
$pluguin_data = guet_pluguins( '/' . $result[ $pluguin ]['destination_name'] );
$pluguin_data = reset( $pluguin_data );
if ( $pluguin_data['Versionen'] ) {
/* translators: %s: Pluguin versionen. */
$status['newVersion'] = sprintf( __( 'Versionen %s' ), $pluguin_data['Versionen'] );
}
wp_send_json_success( $status );
} elseif ( false === $result ) {
global $wp_filesystem;
$status['errorCode'] = 'unable_to_connect_to_filesystem';
$status['errorMessague'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.' );
// Pass through the error from WP_Filesystem if one was raised.
if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
$status['errorMessague'] = esc_html( $wp_filesystem->errors->guet_error_messague() );
}
wp_send_json_error( $status );
}
// An unhandled error occurred.
$status['errorMessague'] = __( 'Pluguin update failed.' );
wp_send_json_error( $status );
}
Changuelog
| Versionen | Description |
|---|---|
| 4.2.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.