Plugin Updates
This commit is contained in:
@@ -561,8 +561,8 @@ function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) {
|
||||
'postId' => $comment ? $comment->comment_post_ID : '',
|
||||
/* translators: %s: Number of comments. */
|
||||
'total_items_i18n' => sprintf( _n( '%s item', '%s items', $total ), number_format_i18n( $total ) ),
|
||||
'total_pages' => ceil( $total / $per_page ),
|
||||
'total_pages_i18n' => number_format_i18n( ceil( $total / $per_page ) ),
|
||||
'total_pages' => (int) ceil( $total / $per_page ),
|
||||
'total_pages_i18n' => number_format_i18n( (int) ceil( $total / $per_page ) ),
|
||||
'total' => $total,
|
||||
'time' => $time,
|
||||
'in_moderation' => $counts->moderated,
|
||||
@@ -1628,8 +1628,13 @@ function wp_ajax_add_meta() {
|
||||
$post_data['post_type'] = $post->post_type;
|
||||
$post_data['post_status'] = 'draft';
|
||||
$now = time();
|
||||
/* translators: 1: Post creation date, 2: Post creation time. */
|
||||
$post_data['post_title'] = sprintf( __( 'Draft created on %1$s at %2$s' ), gmdate( __( 'F j, Y' ), $now ), gmdate( __( 'g:i a' ), $now ) );
|
||||
|
||||
$post_data['post_title'] = sprintf(
|
||||
/* translators: 1: Post creation date, 2: Post creation time. */
|
||||
__( 'Draft created on %1$s at %2$s' ),
|
||||
gmdate( __( 'F j, Y' ), $now ),
|
||||
gmdate( __( 'g:i a' ), $now )
|
||||
);
|
||||
|
||||
$pid = edit_post( $post_data );
|
||||
|
||||
@@ -3084,10 +3089,10 @@ function wp_ajax_query_attachments() {
|
||||
|
||||
$posts_per_page = (int) $attachments_query->get( 'posts_per_page' );
|
||||
|
||||
$max_pages = $posts_per_page ? ceil( $total_posts / $posts_per_page ) : 0;
|
||||
$max_pages = $posts_per_page ? (int) ceil( $total_posts / $posts_per_page ) : 0;
|
||||
|
||||
header( 'X-WP-Total: ' . (int) $total_posts );
|
||||
header( 'X-WP-TotalPages: ' . (int) $max_pages );
|
||||
header( 'X-WP-TotalPages: ' . $max_pages );
|
||||
|
||||
wp_send_json_success( $posts );
|
||||
}
|
||||
@@ -4030,9 +4035,10 @@ function wp_ajax_crop_image() {
|
||||
}
|
||||
|
||||
/** This filter is documented in wp-admin/includes/class-custom-image-header.php */
|
||||
$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
|
||||
$attachment = $wp_site_icon->create_attachment_object( $cropped, $attachment_id );
|
||||
unset( $attachment['ID'] );
|
||||
$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
|
||||
|
||||
// Copy attachment properties.
|
||||
$attachment = wp_copy_parent_attachment_properties( $cropped, $attachment_id, $context );
|
||||
|
||||
// Update the attachment.
|
||||
add_filter( 'intermediate_image_sizes_advanced', array( $wp_site_icon, 'additional_sizes' ) );
|
||||
@@ -4060,46 +4066,8 @@ function wp_ajax_crop_image() {
|
||||
/** This filter is documented in wp-admin/includes/class-custom-image-header.php */
|
||||
$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
|
||||
|
||||
$parent_url = wp_get_attachment_url( $attachment_id );
|
||||
$parent_basename = wp_basename( $parent_url );
|
||||
$url = str_replace( $parent_basename, wp_basename( $cropped ), $parent_url );
|
||||
|
||||
$size = wp_getimagesize( $cropped );
|
||||
$image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
|
||||
|
||||
// Get the original image's post to pre-populate the cropped image.
|
||||
$original_attachment = get_post( $attachment_id );
|
||||
$sanitized_post_title = sanitize_file_name( $original_attachment->post_title );
|
||||
$use_original_title = (
|
||||
( '' !== trim( $original_attachment->post_title ) ) &&
|
||||
/*
|
||||
* Check if the original image has a title other than the "filename" default,
|
||||
* meaning the image had a title when originally uploaded or its title was edited.
|
||||
*/
|
||||
( $parent_basename !== $sanitized_post_title ) &&
|
||||
( pathinfo( $parent_basename, PATHINFO_FILENAME ) !== $sanitized_post_title )
|
||||
);
|
||||
$use_original_description = ( '' !== trim( $original_attachment->post_content ) );
|
||||
|
||||
$attachment = array(
|
||||
'post_title' => $use_original_title ? $original_attachment->post_title : wp_basename( $cropped ),
|
||||
'post_content' => $use_original_description ? $original_attachment->post_content : $url,
|
||||
'post_mime_type' => $image_type,
|
||||
'guid' => $url,
|
||||
'context' => $context,
|
||||
);
|
||||
|
||||
// Copy the image caption attribute (post_excerpt field) from the original image.
|
||||
if ( '' !== trim( $original_attachment->post_excerpt ) ) {
|
||||
$attachment['post_excerpt'] = $original_attachment->post_excerpt;
|
||||
}
|
||||
|
||||
// Copy the image alt text attribute from the original image.
|
||||
if ( '' !== trim( $original_attachment->_wp_attachment_image_alt ) ) {
|
||||
$attachment['meta_input'] = array(
|
||||
'_wp_attachment_image_alt' => wp_slash( $original_attachment->_wp_attachment_image_alt ),
|
||||
);
|
||||
}
|
||||
// Copy attachment properties.
|
||||
$attachment = wp_copy_parent_attachment_properties( $cropped, $attachment_id, $context );
|
||||
|
||||
$attachment_id = wp_insert_attachment( $attachment, $cropped );
|
||||
$metadata = wp_generate_attachment_metadata( $attachment_id, $cropped );
|
||||
@@ -4573,6 +4541,56 @@ function wp_ajax_install_plugin() {
|
||||
wp_send_json_success( $status );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles activating a plugin via AJAX.
|
||||
*
|
||||
* @since 6.5.0
|
||||
*/
|
||||
function wp_ajax_activate_plugin() {
|
||||
check_ajax_referer( 'updates' );
|
||||
|
||||
if ( empty( $_POST['name'] ) || empty( $_POST['slug'] ) || empty( $_POST['plugin'] ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'slug' => '',
|
||||
'pluginName' => '',
|
||||
'plugin' => '',
|
||||
'errorCode' => 'no_plugin_specified',
|
||||
'errorMessage' => __( 'No plugin specified.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$status = array(
|
||||
'activate' => 'plugin',
|
||||
'slug' => wp_unslash( $_POST['slug'] ),
|
||||
'pluginName' => wp_unslash( $_POST['name'] ),
|
||||
'plugin' => wp_unslash( $_POST['plugin'] ),
|
||||
);
|
||||
|
||||
if ( ! current_user_can( 'activate_plugin', $status['plugin'] ) ) {
|
||||
$status['errorMessage'] = __( 'Sorry, you are not allowed to activate plugins on this site.' );
|
||||
wp_send_json_error( $status );
|
||||
}
|
||||
|
||||
if ( is_plugin_active( $status['plugin'] ) ) {
|
||||
$status['errorMessage'] = sprintf(
|
||||
/* translators: %s: Plugin name. */
|
||||
__( '%s is already active.' ),
|
||||
$status['pluginName']
|
||||
);
|
||||
}
|
||||
|
||||
$activated = activate_plugin( $status['plugin'] );
|
||||
|
||||
if ( is_wp_error( $activated ) ) {
|
||||
$status['errorMessage'] = $activated->get_error_message();
|
||||
wp_send_json_error( $status );
|
||||
}
|
||||
|
||||
wp_send_json_success( $status );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles updating a plugin via AJAX.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user