--- a/wp/wp-admin/includes/ajax-actions.php Wed Sep 21 18:19:35 2022 +0200
+++ b/wp/wp-admin/includes/ajax-actions.php Tue Sep 27 16:37:53 2022 +0200
@@ -158,6 +158,7 @@
'name__like' => $s,
'fields' => 'names',
'hide_empty' => false,
+ 'number' => isset( $_GET['number'] ) ? (int) $_GET['number'] : 0,
)
);
@@ -1071,16 +1072,21 @@
}
if ( ! $tag || is_wp_error( $tag ) ) {
- $message = __( 'An error has occurred. Please reload the page and try again.' );
+ $message = __( 'An error has occurred. Please reload the page and try again.' );
+ $error_code = 'error';
if ( is_wp_error( $tag ) && $tag->get_error_message() ) {
$message = $tag->get_error_message();
}
+ if ( is_wp_error( $tag ) && $tag->get_error_code() ) {
+ $error_code = $tag->get_error_code();
+ }
+
$x->add(
array(
'what' => 'taxonomy',
- 'data' => new WP_Error( 'error', $message ),
+ 'data' => new WP_Error( $error_code, $message ),
)
);
$x->send();
@@ -1102,10 +1108,24 @@
$wp_list_table->single_row( $tag );
$parents = ob_get_clean();
+ require ABSPATH . 'wp-admin/includes/edit-tag-messages.php';
+
+ $message = '';
+ if ( isset( $messages[ $tax->name ][1] ) ) {
+ $message = $messages[ $tax->name ][1];
+ } elseif ( isset( $messages['_item'][1] ) ) {
+ $message = $messages['_item'][1];
+ }
+
$x->add(
array(
'what' => 'taxonomy',
- 'supplemental' => compact( 'parents', 'noparents' ),
+ 'data' => $message,
+ 'supplemental' => array(
+ 'parents' => $parents,
+ 'noparents' => $noparents,
+ 'notice' => $message,
+ ),
)
);
@@ -1271,7 +1291,7 @@
if ( empty( $post->post_status ) ) {
wp_die( 1 );
} elseif ( in_array( $post->post_status, array( 'draft', 'pending', 'trash' ), true ) ) {
- wp_die( __( 'Error: You can’t reply to a comment on a draft post.' ) );
+ wp_die( __( 'You cannot reply to a comment on a draft post.' ) );
}
$user = wp_get_current_user();
@@ -1301,7 +1321,7 @@
}
if ( '' === $comment_content ) {
- wp_die( __( 'Error: Please type your comment text.' ) );
+ wp_die( __( 'Please type your comment text.' ) );
}
$comment_parent = 0;
@@ -1403,7 +1423,7 @@
}
if ( '' === $_POST['content'] ) {
- wp_die( __( 'Error: Please type your comment text.' ) );
+ wp_die( __( 'Please type your comment text.' ) );
}
if ( isset( $_POST['status'] ) ) {
@@ -3003,7 +3023,7 @@
$total_posts = $count_query->found_posts;
}
- $posts_per_page = (int) $attachments_query->query['posts_per_page'];
+ $posts_per_page = (int) $attachments_query->get( 'posts_per_page' );
$max_pages = $posts_per_page ? ceil( $total_posts / $posts_per_page ) : 0;
@@ -3558,6 +3578,19 @@
$update_php = network_admin_url( 'update.php?action=install-theme' );
+ $installed_themes = search_theme_directories();
+
+ if ( false === $installed_themes ) {
+ $installed_themes = array();
+ }
+
+ foreach ( $installed_themes as $theme_slug => $theme_data ) {
+ // Ignore child themes.
+ if ( str_contains( $theme_slug, '/' ) ) {
+ unset( $installed_themes[ $theme_slug ] );
+ }
+ }
+
foreach ( $api->themes as &$theme ) {
$theme->install_url = add_query_arg(
array(
@@ -3589,12 +3622,19 @@
}
}
+ $is_theme_installed = array_key_exists( $theme->slug, $installed_themes );
+
+ // We only care about installed themes.
+ $theme->block_theme = $is_theme_installed && wp_get_theme( $theme->slug )->is_block_theme();
+
if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
+ $customize_url = $theme->block_theme ? admin_url( 'site-editor.php' ) : wp_customize_url( $theme->slug );
+
$theme->customize_url = add_query_arg(
array(
'return' => urlencode( network_admin_url( 'theme-install.php', 'relative' ) ),
),
- wp_customize_url( $theme->slug )
+ $customize_url
);
}
@@ -3910,13 +3950,13 @@
}
/** 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.
- $object = $wp_site_icon->create_attachment_object( $cropped, $attachment_id );
- unset( $object['ID'] );
+ $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'] );
// Update the attachment.
add_filter( 'intermediate_image_sizes_advanced', array( $wp_site_icon, 'additional_sizes' ) );
- $attachment_id = $wp_site_icon->insert_attachment( $object, $cropped );
+ $attachment_id = $wp_site_icon->insert_attachment( $attachment, $cropped );
remove_filter( 'intermediate_image_sizes_advanced', array( $wp_site_icon, 'additional_sizes' ) );
// Additional sizes in wp_prepare_attachment_for_js().
@@ -3940,21 +3980,48 @@
/** 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 );
- $url = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url );
+ $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';
- $object = array(
- 'post_title' => wp_basename( $cropped ),
- 'post_content' => $url,
+ // 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,
);
- $attachment_id = wp_insert_attachment( $object, $cropped );
+ // 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 ),
+ );
+ }
+
+ $attachment_id = wp_insert_attachment( $attachment, $cropped );
$metadata = wp_generate_attachment_metadata( $attachment_id, $cropped );
/**
@@ -4129,6 +4196,9 @@
}
}
+ $theme = wp_get_theme( $slug );
+ $status['blockTheme'] = $theme->is_block_theme();
+
if ( ! is_multisite() && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
$status['customizeUrl'] = add_query_arg(
array(