mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 01:27:36 +01:00
Code Modernization: Rename parameters that use reserved keywords in wp-admin/includes/class-custom-image-header.php
.
While using reserved PHP keywords as parameter name labels is allowed, in the context of function calls using named parameters in PHP 8.0+, this will easily lead to confusion. To avoid that, it is recommended not to use reserved keywords as function parameter names. This commit renames the `$object` variable in `Custom_Image_Header` class methods to `$attachment` for clarity and consistency, as the variable type is actually an array, and updates the documentation accordingly. Props jrf, aristath, poena, justinahinon, SergeyBiryukov. See #55327. Built from https://develop.svn.wordpress.org/trunk@52946 git-svn-id: http://core.svn.wordpress.org/trunk@52535 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
5c2f80f60f
commit
d6589948ca
@ -975,8 +975,8 @@ endif;
|
|||||||
$file = $file['file'];
|
$file = $file['file'];
|
||||||
$filename = wp_basename( $file );
|
$filename = wp_basename( $file );
|
||||||
|
|
||||||
// Construct the object array.
|
// Construct the array with attachment object data.
|
||||||
$object = array(
|
$attachment = array(
|
||||||
'post_title' => $filename,
|
'post_title' => $filename,
|
||||||
'post_content' => $url,
|
'post_content' => $url,
|
||||||
'post_mime_type' => $type,
|
'post_mime_type' => $type,
|
||||||
@ -985,7 +985,7 @@ endif;
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Save the data.
|
// Save the data.
|
||||||
$attachment_id = wp_insert_attachment( $object, $file );
|
$attachment_id = wp_insert_attachment( $attachment, $file );
|
||||||
|
|
||||||
return compact( 'attachment_id', 'file', 'filename', 'url', 'type' );
|
return compact( 'attachment_id', 'file', 'filename', 'url', 'type' );
|
||||||
}
|
}
|
||||||
@ -1061,14 +1061,14 @@ endif;
|
|||||||
/** This filter is documented in wp-admin/includes/class-custom-image-header.php */
|
/** 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.
|
$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
|
||||||
|
|
||||||
$object = $this->create_attachment_object( $cropped, $attachment_id );
|
$attachment = $this->create_attachment_object( $cropped, $attachment_id );
|
||||||
|
|
||||||
if ( ! empty( $_POST['create-new-attachment'] ) ) {
|
if ( ! empty( $_POST['create-new-attachment'] ) ) {
|
||||||
unset( $object['ID'] );
|
unset( $attachment['ID'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the attachment.
|
// Update the attachment.
|
||||||
$attachment_id = $this->insert_attachment( $object, $cropped );
|
$attachment_id = $this->insert_attachment( $attachment, $cropped );
|
||||||
|
|
||||||
$url = wp_get_attachment_url( $attachment_id );
|
$url = wp_get_attachment_url( $attachment_id );
|
||||||
$this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) );
|
$this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) );
|
||||||
@ -1300,7 +1300,7 @@ endif;
|
|||||||
*
|
*
|
||||||
* @param string $cropped Cropped image URL.
|
* @param string $cropped Cropped image URL.
|
||||||
* @param int $parent_attachment_id Attachment ID of parent image.
|
* @param int $parent_attachment_id Attachment ID of parent image.
|
||||||
* @return array Attachment object.
|
* @return array An array with attachment object data.
|
||||||
*/
|
*/
|
||||||
final public function create_attachment_object( $cropped, $parent_attachment_id ) {
|
final public function create_attachment_object( $cropped, $parent_attachment_id ) {
|
||||||
$parent = get_post( $parent_attachment_id );
|
$parent = get_post( $parent_attachment_id );
|
||||||
@ -1310,7 +1310,7 @@ endif;
|
|||||||
$size = wp_getimagesize( $cropped );
|
$size = wp_getimagesize( $cropped );
|
||||||
$image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
|
$image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
|
||||||
|
|
||||||
$object = array(
|
$attachment = array(
|
||||||
'ID' => $parent_attachment_id,
|
'ID' => $parent_attachment_id,
|
||||||
'post_title' => wp_basename( $cropped ),
|
'post_title' => wp_basename( $cropped ),
|
||||||
'post_mime_type' => $image_type,
|
'post_mime_type' => $image_type,
|
||||||
@ -1319,7 +1319,7 @@ endif;
|
|||||||
'post_parent' => $parent_attachment_id,
|
'post_parent' => $parent_attachment_id,
|
||||||
);
|
);
|
||||||
|
|
||||||
return $object;
|
return $attachment;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1327,15 +1327,15 @@ endif;
|
|||||||
*
|
*
|
||||||
* @since 3.9.0
|
* @since 3.9.0
|
||||||
*
|
*
|
||||||
* @param array $object Attachment object.
|
* @param array $attachment An array with attachment object data.
|
||||||
* @param string $cropped File path to cropped image.
|
* @param string $cropped File path to cropped image.
|
||||||
* @return int Attachment ID.
|
* @return int Attachment ID.
|
||||||
*/
|
*/
|
||||||
final public function insert_attachment( $object, $cropped ) {
|
final public function insert_attachment( $attachment, $cropped ) {
|
||||||
$parent_id = isset( $object['post_parent'] ) ? $object['post_parent'] : null;
|
$parent_id = isset( $attachment['post_parent'] ) ? $attachment['post_parent'] : null;
|
||||||
unset( $object['post_parent'] );
|
unset( $attachment['post_parent'] );
|
||||||
|
|
||||||
$attachment_id = wp_insert_attachment( $object, $cropped );
|
$attachment_id = wp_insert_attachment( $attachment, $cropped );
|
||||||
$metadata = wp_generate_attachment_metadata( $attachment_id, $cropped );
|
$metadata = wp_generate_attachment_metadata( $attachment_id, $cropped );
|
||||||
|
|
||||||
// If this is a crop, save the original attachment ID as metadata.
|
// If this is a crop, save the original attachment ID as metadata.
|
||||||
@ -1404,25 +1404,25 @@ endif;
|
|||||||
/** This filter is documented in wp-admin/includes/class-custom-image-header.php */
|
/** 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.
|
$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
|
||||||
|
|
||||||
$object = $this->create_attachment_object( $cropped, $attachment_id );
|
$attachment = $this->create_attachment_object( $cropped, $attachment_id );
|
||||||
|
|
||||||
$previous = $this->get_previous_crop( $object );
|
$previous = $this->get_previous_crop( $attachment );
|
||||||
|
|
||||||
if ( $previous ) {
|
if ( $previous ) {
|
||||||
$object['ID'] = $previous;
|
$attachment['ID'] = $previous;
|
||||||
} else {
|
} else {
|
||||||
unset( $object['ID'] );
|
unset( $attachment['ID'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
$new_attachment_id = $this->insert_attachment( $object, $cropped );
|
$new_attachment_id = $this->insert_attachment( $attachment, $cropped );
|
||||||
|
|
||||||
$object['attachment_id'] = $new_attachment_id;
|
$attachment['attachment_id'] = $new_attachment_id;
|
||||||
$object['url'] = wp_get_attachment_url( $new_attachment_id );
|
$attachment['url'] = wp_get_attachment_url( $new_attachment_id );
|
||||||
|
|
||||||
$object['width'] = $dimensions['dst_width'];
|
$attachment['width'] = $dimensions['dst_width'];
|
||||||
$object['height'] = $dimensions['dst_height'];
|
$attachment['height'] = $dimensions['dst_height'];
|
||||||
|
|
||||||
wp_send_json_success( $object );
|
wp_send_json_success( $attachment );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1577,10 +1577,10 @@ endif;
|
|||||||
*
|
*
|
||||||
* @since 4.9.0
|
* @since 4.9.0
|
||||||
*
|
*
|
||||||
* @param array $object A crop attachment object.
|
* @param array $attachment An array with a cropped attachment object data.
|
||||||
* @return int|false An attachment ID if one exists. False if none.
|
* @return int|false An attachment ID if one exists. False if none.
|
||||||
*/
|
*/
|
||||||
public function get_previous_crop( $object ) {
|
public function get_previous_crop( $attachment ) {
|
||||||
$header_images = $this->get_uploaded_header_images();
|
$header_images = $this->get_uploaded_header_images();
|
||||||
|
|
||||||
// Bail early if there are no header images.
|
// Bail early if there are no header images.
|
||||||
@ -1591,7 +1591,7 @@ endif;
|
|||||||
$previous = false;
|
$previous = false;
|
||||||
|
|
||||||
foreach ( $header_images as $image ) {
|
foreach ( $header_images as $image ) {
|
||||||
if ( $image['attachment_parent'] === $object['post_parent'] ) {
|
if ( $image['attachment_parent'] === $attachment['post_parent'] ) {
|
||||||
$previous = $image['attachment_id'];
|
$previous = $image['attachment_id'];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.0-alpha-52945';
|
$wp_version = '6.0-alpha-52946';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user