Changeset 31645 for trunk/src/wp-includes/post.php
- Timestamp:
- 03/06/2015 08:25:09 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post.php
r31614 r31645 5072 5072 5073 5073 /** 5074 * Verfify the attachment as being of a specific type 5075 * 5076 * @param string $type Type: image, audio, or video. 5077 * @param int|WP_Post $post_id Optional. Default 0. 5078 * @return bool 5079 */ 5080 function wp_attachment_is( $type, $post_id = 0 ) { 5081 if ( ! $post = get_post( $post_id ) ) { 5082 return false; 5083 } 5084 5085 if ( ! $file = get_attached_file( $post->ID ) ) { 5086 return false; 5087 } 5088 5089 if ( 0 === strpos( $post->post_mime_type, $type . '/' ) ) { 5090 return true; 5091 } 5092 5093 $check = wp_check_filetype( $file ); 5094 if ( empty( $check['ext'] ) || 'import' !== $post->post_mime_type ) { 5095 return false; 5096 } 5097 $ext = $check['ext']; 5098 5099 switch ( $type ) { 5100 case 'image': 5101 $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' ); 5102 return in_array( $ext, $image_exts ); 5103 5104 case 'audio': 5105 return in_array( $ext, wp_get_audio_extensions() ); 5106 5107 case 'video': 5108 return in_array( $ext, wp_get_video_extensions() ); 5109 } 5110 5111 return false; 5112 } 5113 5114 /** 5074 5115 * Check if the attachment is an image. 5075 5116 * 5076 5117 * @since 2.1.0 5077 5118 * 5078 * @param int $post_idOptional. Attachment ID. Default 0.5119 * @param int|WP_Post $post Optional. Attachment ID. Default 0. 5079 5120 * @return bool Whether the attachment is an image. 5080 5121 */ 5081 function wp_attachment_is_image( $post_id = 0 ) { 5082 $post_id = (int) $post_id; 5083 if ( !$post = get_post( $post_id ) ) 5084 return false; 5085 5086 if ( !$file = get_attached_file( $post->ID ) ) 5087 return false; 5088 5089 $ext = preg_match('/\.([^.]+)$/', $file, $matches) ? strtolower($matches[1]) : false; 5090 5091 $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' ); 5092 5093 if ( 'image/' == substr($post->post_mime_type, 0, 6) || $ext && 'import' == $post->post_mime_type && in_array($ext, $image_exts) ) 5094 return true; 5095 return false; 5122 function wp_attachment_is_image( $post = 0 ) { 5123 return wp_attachment_is( 'image', $post ); 5096 5124 } 5097 5125
Note: See TracChangeset
for help on using the changeset viewer.