Astra_Admin_Ajax::required_plugin_activate()
Required Plugin Activate
Description
Source
File: admin/includes/class-astra-admin-ajax.php
public function required_plugin_activate() {
$response_data = array( 'message' => $this->get_error_msg( 'permission' ) );
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( $response_data );
}
if ( empty( $_POST ) ) {
$response_data = array( 'message' => $this->get_error_msg( 'invalid' ) );
wp_send_json_error( $response_data );
}
/**
* Nonce verification.
*/
if ( ! check_ajax_referer( 'astra_plugin_manager_nonce', 'security', false ) ) {
$response_data = array( 'message' => $this->get_error_msg( 'nonce' ) );
wp_send_json_error( $response_data );
}
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
if ( ! current_user_can( 'install_plugins' ) || ! isset( $_POST['init'] ) || ! sanitize_text_field( wp_unslash( $_POST['init'] ) ) ) {
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
wp_send_json_error(
array(
'success' => false,
'message' => __( 'No plugin specified', 'astra' ),
)
);
}
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
$plugin_init = ( isset( $_POST['init'] ) ) ? sanitize_text_field( wp_unslash( $_POST['init'] ) ) : '';
/** @psalm-suppress PossiblyInvalidArgument */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
$activate = activate_plugin( $plugin_init, '', false, true );
if ( is_wp_error( $activate ) ) {
/** @psalm-suppress PossiblyNullReference */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
wp_send_json_error(
array(
'success' => false,
'message' => $activate->get_error_message(),
)
);
/** @psalm-suppress PossiblyNullReference */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort
}
wp_send_json_success(
array(
'success' => true,
'message' => __( 'Plugin Successfully Activated', 'astra' ),
)
);
}
Expand full source code Collapse full source code View on Trac
Changelog
| Version | Description |
|---|---|
| 1.2.4 | Introduced. |