From 0613540ea20409ecb492b0ae9f6c2e0040b785ec Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Tue, 22 Aug 2017 11:11:23 +0000 Subject: [PATCH] Media: Rename several attachment related parameters from `$post_id` to `$attachment_id` for clarity, and improve related documentation. See #41017 git-svn-id: https://develop.svn.wordpress.org/trunk@41288 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/image-edit.php | 23 +++++----- src/wp-includes/class-wp-image-editor-gd.php | 4 +- .../class-wp-image-editor-imagick.php | 4 +- src/wp-includes/class-wp-image-editor.php | 4 +- src/wp-includes/post.php | 45 ++++++++++--------- 5 files changed, 41 insertions(+), 39 deletions(-) diff --git a/src/wp-admin/includes/image-edit.php b/src/wp-admin/includes/image-edit.php index d9cf6048f2..efa98659ee 100644 --- a/src/wp-admin/includes/image-edit.php +++ b/src/wp-admin/includes/image-edit.php @@ -231,14 +231,13 @@ function wp_image_editor($post_id, $msg = false) { /** * Streams image in WP_Image_Editor to browser. - * Provided for backcompat reasons * - * @param WP_Image_Editor $image - * @param string $mime_type - * @param int $post_id - * @return bool + * @param WP_Image_Editor $image The image editor instance. + * @param string $mime_type The mime type of the image. + * @param int $attachment_id The image's attachment post ID. + * @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 ) { /** @@ -246,10 +245,10 @@ function wp_stream_image( $image, $mime_type, $post_id ) { * * @since 3.5.0 * - * @param WP_Image_Editor $image WP_Image_Editor instance. - * @param int $post_id Post ID. + * @param WP_Image_Editor $image The image editor instance. + * @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 ) ) ) return false; @@ -264,10 +263,10 @@ function wp_stream_image( $image, $mime_type, $post_id ) { * @since 2.9.0 * @deprecated 3.5.0 Use image_editor_save_pre instead. * - * @param resource $image Image resource to be streamed. - * @param int $post_id Post ID. + * @param resource $image Image resource to be streamed. + * @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 ) { case 'image/jpeg': diff --git a/src/wp-includes/class-wp-image-editor-gd.php b/src/wp-includes/class-wp-image-editor-gd.php index b39b4ebf77..c5050b21d3 100644 --- a/src/wp-includes/class-wp-image-editor-gd.php +++ b/src/wp-includes/class-wp-image-editor-gd.php @@ -429,8 +429,8 @@ class WP_Image_Editor_GD extends WP_Image_Editor { * * @since 3.5.0 * - * @param string $mime_type - * @return bool + * @param string $mime_type The mime type of the image. + * @return bool True on success, false on failure. */ public function stream( $mime_type = null ) { list( $filename, $extension, $mime_type ) = $this->get_output_format( null, $mime_type ); diff --git a/src/wp-includes/class-wp-image-editor-imagick.php b/src/wp-includes/class-wp-image-editor-imagick.php index 2dbbf9e243..9f6a0f3b52 100644 --- a/src/wp-includes/class-wp-image-editor-imagick.php +++ b/src/wp-includes/class-wp-image-editor-imagick.php @@ -652,8 +652,8 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor { * * @since 3.5.0 * - * @param string $mime_type - * @return true|WP_Error + * @param string $mime_type The mime type of the image. + * @return bool|WP_Error True on success, WP_Error object on failure. */ public function stream( $mime_type = null ) { list( $filename, $extension, $mime_type ) = $this->get_output_format( null, $mime_type ); diff --git a/src/wp-includes/class-wp-image-editor.php b/src/wp-includes/class-wp-image-editor.php index d7646ccaca..85a4916117 100644 --- a/src/wp-includes/class-wp-image-editor.php +++ b/src/wp-includes/class-wp-image-editor.php @@ -164,8 +164,8 @@ abstract class WP_Image_Editor { * @since 3.5.0 * @abstract * - * @param string $mime_type - * @return bool|WP_Error + * @param string $mime_type The mime type of the image. + * @return bool|WP_Error True on success, WP_Error object or false on failure. */ abstract public function stream( $mime_type = null ); diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 56c2ea5c75..904d11d68d 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -4963,14 +4963,15 @@ function wp_delete_attachment( $post_id, $force_delete = false ) { * * @since 2.1.0 * - * @param int $post_id Attachment ID. Default 0. - * @param bool $unfiltered Optional. If true, filters are not run. Default false. + * @param int $attachment_id Attachment post ID. Defaults to global $post. + * @param bool $unfiltered Optional. If true, filters are not run. Default false. * @return mixed Attachment meta field. False on failure. */ -function wp_get_attachment_metadata( $post_id = 0, $unfiltered = false ) { - $post_id = (int) $post_id; - if ( !$post = get_post( $post_id ) ) +function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) { + $attachment_id = (int) $attachment_id; + if ( ! $post = get_post( $attachment_id ) ) { return false; + } $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 * - * @param array|bool $data Array of meta data for the given attachment, or false - * if the object does not exist. - * @param int $post_id Attachment ID. + * @param array|bool $data Array of meta data for the given attachment, or false + * if the object does not exist. + * @param int $attachment_id Attachment 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 * - * @param int $post_id Attachment ID. - * @param array $data Attachment data. + * @param int $attachment_id Attachment post ID. + * @param array $data Attachment meta data. * @return int|bool False if $post is invalid. */ -function wp_update_attachment_metadata( $post_id, $data ) { - $post_id = (int) $post_id; - if ( !$post = get_post( $post_id ) ) +function wp_update_attachment_metadata( $attachment_id, $data ) { + $attachment_id = (int) $attachment_id; + if ( ! $post = get_post( $attachment_id ) ) { return false; + } /** * Filters the updated attachment meta data. * * @since 2.1.0 * - * @param array $data Array of updated attachment meta data. - * @param int $post_id Attachment ID. + * @param array $data Array of updated attachment meta data. + * @param int $attachment_id Attachment post ID. */ if ( $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ) ) 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 * - * @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. */ -function wp_get_attachment_url( $post_id = 0 ) { - $post_id = (int) $post_id; - if ( !$post = get_post( $post_id ) ) +function wp_get_attachment_url( $attachment_id = 0 ) { + $attachment_id = (int) $attachment_id; + if ( ! $post = get_post( $attachment_id ) ) { return false; + } if ( 'attachment' != $post->post_type ) return false; @@ -5072,8 +5075,8 @@ function wp_get_attachment_url( $post_id = 0 ) { * * @since 2.1.0 * - * @param string $url URL for the given attachment. - * @param int $post_id Attachment ID. + * @param string $url URL for the given attachment. + * @param int $attachment_id Attachment post ID. */ $url = apply_filters( 'wp_get_attachment_url', $url, $post->ID );