Changeset 57545 for trunk/src/wp-admin/includes/ajax-actions.php
- Timestamp:
- 02/06/2024 11:44:09 PM (10 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/ajax-actions.php
r57136 r57545 4580 4580 4581 4581 /** 4582 * Handles activating a plugin via AJAX. 4583 * 4584 * @since 6.5.0 4585 */ 4586 function wp_ajax_activate_plugin() { 4587 check_ajax_referer( 'updates' ); 4588 4589 if ( empty( $_POST['name'] ) || empty( $_POST['slug'] ) || empty( $_POST['plugin'] ) ) { 4590 wp_send_json_error( 4591 array( 4592 'slug' => '', 4593 'pluginName' => '', 4594 'plugin' => '', 4595 'errorCode' => 'no_plugin_specified', 4596 'errorMessage' => __( 'No plugin specified.' ), 4597 ) 4598 ); 4599 } 4600 4601 $status = array( 4602 'activate' => 'plugin', 4603 'slug' => wp_unslash( $_POST['slug'] ), 4604 'pluginName' => wp_unslash( $_POST['name'] ), 4605 'plugin' => wp_unslash( $_POST['plugin'] ), 4606 ); 4607 4608 if ( ! current_user_can( 'activate_plugin', $status['plugin'] ) ) { 4609 $status['errorMessage'] = __( 'Sorry, you are not allowed to activate plugins on this site.' ); 4610 wp_send_json_error( $status ); 4611 } 4612 4613 if ( is_plugin_active( $status['plugin'] ) ) { 4614 $status['errorMessage'] = sprintf( 4615 /* translators: %s: Plugin name. */ 4616 __( '%s is already active.' ), 4617 $status['pluginName'] 4618 ); 4619 } 4620 4621 $activated = activate_plugin( $status['plugin'] ); 4622 4623 if ( is_wp_error( $activated ) ) { 4624 $status['errorMessage'] = $activated->get_error_message(); 4625 wp_send_json_error( $status ); 4626 } 4627 4628 wp_send_json_success( $status ); 4629 } 4630 4631 /** 4582 4632 * Handles updating a plugin via AJAX. 4583 4633 *
Note: See TracChangeset
for help on using the changeset viewer.