@@ 4969-4989 (lines=21) @@ | ||
4966 | * @param bool $unfiltered Optional. If true, filters are not run. Default false. |
|
4967 | * @return mixed Attachment meta field. False on failure. |
|
4968 | */ |
|
4969 | function wp_get_attachment_metadata( $post_id = 0, $unfiltered = false ) { |
|
4970 | $post_id = (int) $post_id; |
|
4971 | if ( !$post = get_post( $post_id ) ) |
|
4972 | return false; |
|
4973 | ||
4974 | $data = get_post_meta( $post->ID, '_wp_attachment_metadata', true ); |
|
4975 | ||
4976 | if ( $unfiltered ) |
|
4977 | return $data; |
|
4978 | ||
4979 | /** |
|
4980 | * Filters the attachment meta data. |
|
4981 | * |
|
4982 | * @since 2.1.0 |
|
4983 | * |
|
4984 | * @param array|bool $data Array of meta data for the given attachment, or false |
|
4985 | * if the object does not exist. |
|
4986 | * @param int $post_id Attachment ID. |
|
4987 | */ |
|
4988 | return apply_filters( 'wp_get_attachment_metadata', $data, $post->ID ); |
|
4989 | } |
|
4990 | ||
4991 | /** |
|
4992 | * Update metadata for an attachment. |
|
@@ 5000-5017 (lines=18) @@ | ||
4997 | * @param array $data Attachment data. |
|
4998 | * @return int|bool False if $post is invalid. |
|
4999 | */ |
|
5000 | function wp_update_attachment_metadata( $post_id, $data ) { |
|
5001 | $post_id = (int) $post_id; |
|
5002 | if ( !$post = get_post( $post_id ) ) |
|
5003 | return false; |
|
5004 | ||
5005 | /** |
|
5006 | * Filters the updated attachment meta data. |
|
5007 | * |
|
5008 | * @since 2.1.0 |
|
5009 | * |
|
5010 | * @param array $data Array of updated attachment meta data. |
|
5011 | * @param int $post_id Attachment ID. |
|
5012 | */ |
|
5013 | if ( $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ) ) |
|
5014 | return update_post_meta( $post->ID, '_wp_attachment_metadata', $data ); |
|
5015 | else |
|
5016 | return delete_post_meta( $post->ID, '_wp_attachment_metadata' ); |
|
5017 | } |
|
5018 | ||
5019 | /** |
|
5020 | * Retrieve the URL for an attachment. |
|
@@ 5093-5114 (lines=22) @@ | ||
5090 | * @param int $post_id Optional. Attachment ID. Default is the ID of the global `$post`. |
|
5091 | * @return string|false False on failure. Attachment caption on success. |
|
5092 | */ |
|
5093 | function wp_get_attachment_caption( $post_id = 0 ) { |
|
5094 | $post_id = (int) $post_id; |
|
5095 | if ( ! $post = get_post( $post_id ) ) { |
|
5096 | return false; |
|
5097 | } |
|
5098 | ||
5099 | if ( 'attachment' !== $post->post_type ) { |
|
5100 | return false; |
|
5101 | } |
|
5102 | ||
5103 | $caption = $post->post_excerpt; |
|
5104 | ||
5105 | /** |
|
5106 | * Filters the attachment caption. |
|
5107 | * |
|
5108 | * @since 4.6.0 |
|
5109 | * |
|
5110 | * @param string $caption Caption for the given attachment. |
|
5111 | * @param int $post_id Attachment ID. |
|
5112 | */ |
|
5113 | return apply_filters( 'wp_get_attachment_caption', $caption, $post->ID ); |
|
5114 | } |
|
5115 | ||
5116 | /** |
|
5117 | * Retrieve thumbnail for an attachment. |