rebase on oct-10-2023

This commit is contained in:
Rachit Bhargava
2023-10-10 17:23:21 -04:00
parent d37566ffb6
commit d096058d7d
4789 changed files with 254611 additions and 307223 deletions

View File

@@ -202,8 +202,10 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
wp_after_insert_post( $attachment, false, null );
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
// Set a custom header with the attachment_id.
// Used by the browser/client to resume creating image sub-sizes after a PHP fatal error.
/*
* Set a custom header with the attachment_id.
* Used by the browser/client to resume creating image sub-sizes after a PHP fatal error.
*/
header( 'X-WP-Upload-Attachment-ID: ' . $attachment_id );
}
@@ -211,8 +213,10 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
require_once ABSPATH . 'wp-admin/includes/media.php';
require_once ABSPATH . 'wp-admin/includes/image.php';
// Post-process the upload (create image sub-sizes, make PDF thumbnails, etc.) and insert attachment meta.
// At this point the server may run out of resources and post-processing of uploaded images may fail.
/*
* Post-process the upload (create image sub-sizes, make PDF thumbnails, etc.) and insert attachment meta.
* At this point the server may run out of resources and post-processing of uploaded images may fail.
*/
wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) );
$response = $this->prepare_item_for_response( $attachment, $request );
@@ -562,8 +566,10 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
$image_ext = pathinfo( $image_file, PATHINFO_EXTENSION );
$image_name = wp_basename( $image_file, ".{$image_ext}" );
// Do not append multiple `-edited` to the file name.
// The user may be editing a previously edited image.
/*
* Do not append multiple `-edited` to the file name.
* The user may be editing a previously edited image.
*/
if ( preg_match( '/-edited(-\d+)?$/', $image_name ) ) {
// Remove any `-1`, `-2`, etc. `wp_unique_filename()` will add the proper number.
$image_name = preg_replace( '/-edited(-\d+)?$/', '-edited', $image_name );
@@ -625,8 +631,10 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
}
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
// Set a custom header with the attachment_id.
// Used by the browser/client to resume creating image sub-sizes after a PHP fatal error.
/*
* Set a custom header with the attachment_id.
* Used by the browser/client to resume creating image sub-sizes after a PHP fatal error.
*/
header( 'X-WP-Upload-Attachment-ID: ' . $new_attachment_id );
}
@@ -968,8 +976,8 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
*
* @since 4.7.0
*
* @param array $data Supplied file data.
* @param array $headers HTTP headers from the request.
* @param string $data Supplied file data.
* @param array $headers HTTP headers from the request.
* @return array|WP_Error Data from wp_handle_sideload().
*/
protected function upload_from_data( $data, $headers ) {
@@ -1111,7 +1119,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
foreach ( $disposition_header as $value ) {
$value = trim( $value );
if ( strpos( $value, ';' ) === false ) {
if ( ! str_contains( $value, ';' ) ) {
continue;
}
@@ -1121,7 +1129,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
$attributes = array();
foreach ( $attr_parts as $part ) {
if ( strpos( $part, '=' ) === false ) {
if ( ! str_contains( $part, '=' ) ) {
continue;
}
@@ -1137,7 +1145,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
$filename = trim( $attributes['filename'] );
// Unquote quoted filename, but after trimming.
if ( substr( $filename, 0, 1 ) === '"' && substr( $filename, -1, 1 ) === '"' ) {
if ( str_starts_with( $filename, '"' ) && str_ends_with( $filename, '"' ) ) {
$filename = substr( $filename, 1, -1 );
}
}