ID, 'media_author', true ); $form_fields['media_author'] = array( 'value' => $media_author ? $media_author : '', 'label' => __( 'Author' ) ); // get post mime type $type = get_post_mime_type( $post->ID ); // get the attachment path $attachment_path = get_attached_file( $post->ID ); // get image metadata $metadata = wp_read_image_metadata( $attachment_path ); if( 'image/jpeg' == $type ){ if( $metadata ) { $exif_data = array( 'aperture' => 'Aperture', 'camera' => 'Camera', 'created_timestamp' => 'Timestamp', 'focal_length' => 'Focal Lenght', 'iso' => 'ISO', 'shutter_speed' => 'Exposure Time', 'orientation' => 'Orientation' ); foreach ( $exif_data as $key => $value ) { $exif = $metadata[$key]; $form_fields[$key] = array( 'value' => $exif ? $exif : '', 'label' => __( $value ), 'input' => 'html', 'html' => "
" ); } } } return $form_fields; } add_filter( 'attachment_fields_to_edit', 'media_hacks_attachment_fields_to_edit', 10, 2 ); /** * Update attachment metadata * * @param int $post_ID Attachment ID. */ function media_hacks_edit_attachment( $attachment_id ){ if ( isset( $_REQUEST['attachments'][$attachment_id]['media_author'] ) ) { $media_author = $_REQUEST['attachments'][$attachment_id]['media_author']; update_post_meta( $attachment_id, 'media_author', $media_author ); } } add_action( 'edit_attachment', 'media_hacks_edit_attachment' ); /** * Filters the post content. * * @param string $content Content of the current post. */ function media_hacks_the_content( $content ){ global $post; if( is_attachment() && 'image/jpeg' == get_post_mime_type( $post->ID ) ) { $fields = wp_get_attachment_metadata( $post->ID ); $meta = $fields['image_meta']; if( ! empty( $meta['camera'] ) ){ $custom_content = " "; $content .= $custom_content; } } return $content; } add_filter( 'the_content', 'media_hacks_the_content' ); /** * Registers post type arguments. * * @param array $args Array of arguments for a post type * @param string $post_type Post type key */ function media_hacks_register_post_type_args( $args, $post_type ){ if( $post_type == 'attachment' ){ $args['has_archive'] = true; } return $args; } add_filter( 'register_post_type_args', 'media_hacks_register_post_type_args', 10, 2 ); /** * Set custom query vars for WP_Query * * @param WP_Query &$this The WP_Query instance (passed by reference). */ function media_hacks_pre_get_posts( $query ){ if ( !is_admin() && $query->is_main_query() ) { if( is_post_type_archive('attachment') ){ $query->set('post_mime_type', 'image/jpeg'); $query->set( 'post_status', 'inherit' ); } } } add_action( 'pre_get_posts', 'media_hacks_pre_get_posts' );