Media: Rename several attachment related parameters from `$post_id` to `$attachment_id` for clarity, and improve related

documentation.

See #41017

Built from https://develop.svn.wordpress.org/trunk@41288


git-svn-id: http://core.svn.wordpress.org/trunk@41128 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
John Blackbourn 2017-08-22 11:12:44 +00:00
parent c080c0a2ea
commit 9891448a42
6 changed files with 42 additions and 40 deletions

View File

@ -231,14 +231,13 @@ function wp_image_editor($post_id, $msg = false) {
/** /**
* Streams image in WP_Image_Editor to browser. * Streams image in WP_Image_Editor to browser.
* Provided for backcompat reasons
* *
* @param WP_Image_Editor $image * @param WP_Image_Editor $image The image editor instance.
* @param string $mime_type * @param string $mime_type The mime type of the image.
* @param int $post_id * @param int $attachment_id The image's attachment post ID.
* @return bool * @return bool True on success, false on failure.
*/ */
function wp_stream_image( $image, $mime_type, $post_id ) { function wp_stream_image( $image, $mime_type, $attachment_id ) {
if ( $image instanceof WP_Image_Editor ) { if ( $image instanceof WP_Image_Editor ) {
/** /**
@ -246,10 +245,10 @@ function wp_stream_image( $image, $mime_type, $post_id ) {
* *
* @since 3.5.0 * @since 3.5.0
* *
* @param WP_Image_Editor $image WP_Image_Editor instance. * @param WP_Image_Editor $image The image editor instance.
* @param int $post_id Post ID. * @param int $attachment_id The attachment post ID.
*/ */
$image = apply_filters( 'image_editor_save_pre', $image, $post_id ); $image = apply_filters( 'image_editor_save_pre', $image, $attachment_id );
if ( is_wp_error( $image->stream( $mime_type ) ) ) if ( is_wp_error( $image->stream( $mime_type ) ) )
return false; return false;
@ -264,10 +263,10 @@ function wp_stream_image( $image, $mime_type, $post_id ) {
* @since 2.9.0 * @since 2.9.0
* @deprecated 3.5.0 Use image_editor_save_pre instead. * @deprecated 3.5.0 Use image_editor_save_pre instead.
* *
* @param resource $image Image resource to be streamed. * @param resource $image Image resource to be streamed.
* @param int $post_id Post ID. * @param int $attachment_id The attachment post ID.
*/ */
$image = apply_filters( 'image_save_pre', $image, $post_id ); $image = apply_filters( 'image_save_pre', $image, $attachment_id );
switch ( $mime_type ) { switch ( $mime_type ) {
case 'image/jpeg': case 'image/jpeg':

View File

@ -429,8 +429,8 @@ class WP_Image_Editor_GD extends WP_Image_Editor {
* *
* @since 3.5.0 * @since 3.5.0
* *
* @param string $mime_type * @param string $mime_type The mime type of the image.
* @return bool * @return bool True on success, false on failure.
*/ */
public function stream( $mime_type = null ) { public function stream( $mime_type = null ) {
list( $filename, $extension, $mime_type ) = $this->get_output_format( null, $mime_type ); list( $filename, $extension, $mime_type ) = $this->get_output_format( null, $mime_type );

View File

@ -652,8 +652,8 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor {
* *
* @since 3.5.0 * @since 3.5.0
* *
* @param string $mime_type * @param string $mime_type The mime type of the image.
* @return true|WP_Error * @return bool|WP_Error True on success, WP_Error object on failure.
*/ */
public function stream( $mime_type = null ) { public function stream( $mime_type = null ) {
list( $filename, $extension, $mime_type ) = $this->get_output_format( null, $mime_type ); list( $filename, $extension, $mime_type ) = $this->get_output_format( null, $mime_type );

View File

@ -164,8 +164,8 @@ abstract class WP_Image_Editor {
* @since 3.5.0 * @since 3.5.0
* @abstract * @abstract
* *
* @param string $mime_type * @param string $mime_type The mime type of the image.
* @return bool|WP_Error * @return bool|WP_Error True on success, WP_Error object or false on failure.
*/ */
abstract public function stream( $mime_type = null ); abstract public function stream( $mime_type = null );

View File

@ -4963,14 +4963,15 @@ function wp_delete_attachment( $post_id, $force_delete = false ) {
* *
* @since 2.1.0 * @since 2.1.0
* *
* @param int $post_id Attachment ID. Default 0. * @param int $attachment_id Attachment post ID. Defaults to global $post.
* @param bool $unfiltered Optional. If true, filters are not run. Default false. * @param bool $unfiltered Optional. If true, filters are not run. Default false.
* @return mixed Attachment meta field. False on failure. * @return mixed Attachment meta field. False on failure.
*/ */
function wp_get_attachment_metadata( $post_id = 0, $unfiltered = false ) { function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) {
$post_id = (int) $post_id; $attachment_id = (int) $attachment_id;
if ( !$post = get_post( $post_id ) ) if ( ! $post = get_post( $attachment_id ) ) {
return false; return false;
}
$data = get_post_meta( $post->ID, '_wp_attachment_metadata', true ); $data = get_post_meta( $post->ID, '_wp_attachment_metadata', true );
@ -4982,9 +4983,9 @@ function wp_get_attachment_metadata( $post_id = 0, $unfiltered = false ) {
* *
* @since 2.1.0 * @since 2.1.0
* *
* @param array|bool $data Array of meta data for the given attachment, or false * @param array|bool $data Array of meta data for the given attachment, or false
* if the object does not exist. * if the object does not exist.
* @param int $post_id Attachment ID. * @param int $attachment_id Attachment post ID.
*/ */
return apply_filters( 'wp_get_attachment_metadata', $data, $post->ID ); return apply_filters( 'wp_get_attachment_metadata', $data, $post->ID );
} }
@ -4994,22 +4995,23 @@ function wp_get_attachment_metadata( $post_id = 0, $unfiltered = false ) {
* *
* @since 2.1.0 * @since 2.1.0
* *
* @param int $post_id Attachment ID. * @param int $attachment_id Attachment post ID.
* @param array $data Attachment data. * @param array $data Attachment meta data.
* @return int|bool False if $post is invalid. * @return int|bool False if $post is invalid.
*/ */
function wp_update_attachment_metadata( $post_id, $data ) { function wp_update_attachment_metadata( $attachment_id, $data ) {
$post_id = (int) $post_id; $attachment_id = (int) $attachment_id;
if ( !$post = get_post( $post_id ) ) if ( ! $post = get_post( $attachment_id ) ) {
return false; return false;
}
/** /**
* Filters the updated attachment meta data. * Filters the updated attachment meta data.
* *
* @since 2.1.0 * @since 2.1.0
* *
* @param array $data Array of updated attachment meta data. * @param array $data Array of updated attachment meta data.
* @param int $post_id Attachment ID. * @param int $attachment_id Attachment post ID.
*/ */
if ( $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ) ) if ( $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ) )
return update_post_meta( $post->ID, '_wp_attachment_metadata', $data ); return update_post_meta( $post->ID, '_wp_attachment_metadata', $data );
@ -5024,13 +5026,14 @@ function wp_update_attachment_metadata( $post_id, $data ) {
* *
* @global string $pagenow * @global string $pagenow
* *
* @param int $post_id Optional. Attachment ID. Default 0. * @param int $attachment_id Optional. Attachment post ID. Defaults to global $post.
* @return string|false Attachment URL, otherwise false. * @return string|false Attachment URL, otherwise false.
*/ */
function wp_get_attachment_url( $post_id = 0 ) { function wp_get_attachment_url( $attachment_id = 0 ) {
$post_id = (int) $post_id; $attachment_id = (int) $attachment_id;
if ( !$post = get_post( $post_id ) ) if ( ! $post = get_post( $attachment_id ) ) {
return false; return false;
}
if ( 'attachment' != $post->post_type ) if ( 'attachment' != $post->post_type )
return false; return false;
@ -5072,8 +5075,8 @@ function wp_get_attachment_url( $post_id = 0 ) {
* *
* @since 2.1.0 * @since 2.1.0
* *
* @param string $url URL for the given attachment. * @param string $url URL for the given attachment.
* @param int $post_id Attachment ID. * @param int $attachment_id Attachment post ID.
*/ */
$url = apply_filters( 'wp_get_attachment_url', $url, $post->ID ); $url = apply_filters( 'wp_get_attachment_url', $url, $post->ID );

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.9-alpha-41287'; $wp_version = '4.9-alpha-41288';
/** /**
* 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.