
如何修复MAMP中Apache服务器未启动错误
wp_attachment_is ( $type, $post = null )
wp_attachment_is: 这是一个实用函数,用于确定一个文章的ID是否代表一个附件。它接受一个文章的ID作为参数,如果该文章是一个附件,则返回true,如果不是,则返回false: 这个函数根据WordPress中已知的附件类型列表检查指定的文章ID的文章类型,其中包括”附件”、”修订”和”导航菜单_项目”。如果在这个列表中找到了文章类型,那么这个函数就返回true。
验证一个附件是一个特定的类型。
function wp_attachment_is( $type, $post = null ) { $post = get_post( $post ); if ( ! $post ) { return false; } $file = get_attached_file( $post->ID ); if ( ! $file ) { return false; } if ( 0 === strpos( $post->post_mime_type, $type . '/' ) ) { return true; } $check = wp_check_filetype( $file ); if ( empty( $check['ext'] ) ) { return false; } $ext = $check['ext']; if ( 'import' !== $post->post_mime_type ) { return $type === $ext; } switch ( $type ) { case 'image': $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'webp' ); return in_array( $ext, $image_exts, true ); case 'audio': return in_array( $ext, wp_get_audio_extensions(), true ); case 'video': return in_array( $ext, wp_get_video_extensions(), true ); default: return $type === $ext; } }