@@ 4847-4867 (lines=21) @@ | ||
4844 | * @param bool $unfiltered Optional. If true, filters are not run. Default false. |
|
4845 | * @return mixed Attachment meta field. False on failure. |
|
4846 | */ |
|
4847 | function wp_get_attachment_metadata( $post_id = 0, $unfiltered = false ) { |
|
4848 | $post_id = (int) $post_id; |
|
4849 | if ( !$post = get_post( $post_id ) ) |
|
4850 | return false; |
|
4851 | ||
4852 | $data = get_post_meta( $post->ID, '_wp_attachment_metadata', true ); |
|
4853 | ||
4854 | if ( $unfiltered ) |
|
4855 | return $data; |
|
4856 | ||
4857 | /** |
|
4858 | * Filters the attachment meta data. |
|
4859 | * |
|
4860 | * @since 2.1.0 |
|
4861 | * |
|
4862 | * @param array|bool $data Array of meta data for the given attachment, or false |
|
4863 | * if the object does not exist. |
|
4864 | * @param int $post_id Attachment ID. |
|
4865 | */ |
|
4866 | return apply_filters( 'wp_get_attachment_metadata', $data, $post->ID ); |
|
4867 | } |
|
4868 | ||
4869 | /** |
|
4870 | * Update metadata for an attachment. |
|
@@ 4878-4895 (lines=18) @@ | ||
4875 | * @param array $data Attachment data. |
|
4876 | * @return int|bool False if $post is invalid. |
|
4877 | */ |
|
4878 | function wp_update_attachment_metadata( $post_id, $data ) { |
|
4879 | $post_id = (int) $post_id; |
|
4880 | if ( !$post = get_post( $post_id ) ) |
|
4881 | return false; |
|
4882 | ||
4883 | /** |
|
4884 | * Filters the updated attachment meta data. |
|
4885 | * |
|
4886 | * @since 2.1.0 |
|
4887 | * |
|
4888 | * @param array $data Array of updated attachment meta data. |
|
4889 | * @param int $post_id Attachment ID. |
|
4890 | */ |
|
4891 | if ( $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ) ) |
|
4892 | return update_post_meta( $post->ID, '_wp_attachment_metadata', $data ); |
|
4893 | else |
|
4894 | return delete_post_meta( $post->ID, '_wp_attachment_metadata' ); |
|
4895 | } |
|
4896 | ||
4897 | /** |
|
4898 | * Retrieve the URL for an attachment. |
|
@@ 4971-4992 (lines=22) @@ | ||
4968 | * @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`. |
|
4969 | * @return string|false False on failure. Attachment caption on success. |
|
4970 | */ |
|
4971 | function wp_get_attachment_caption( $post_id = 0 ) { |
|
4972 | $post_id = (int) $post_id; |
|
4973 | if ( ! $post = get_post( $post_id ) ) { |
|
4974 | return false; |
|
4975 | } |
|
4976 | ||
4977 | if ( 'attachment' !== $post->post_type ) { |
|
4978 | return false; |
|
4979 | } |
|
4980 | ||
4981 | $caption = $post->post_excerpt; |
|
4982 | ||
4983 | /** |
|
4984 | * Filters the attachment caption. |
|
4985 | * |
|
4986 | * @since 4.6.0 |
|
4987 | * |
|
4988 | * @param string $caption Caption for the given attachment. |
|
4989 | * @param int $post_id Attachment ID. |
|
4990 | */ |
|
4991 | return apply_filters( 'wp_get_attachment_caption', $caption, $post->ID ); |
|
4992 | } |
|
4993 | ||
4994 | /** |
|
4995 | * Retrieve thumbnail for an attachment. |