Make WordPress Core

Ticket #26825: 26825.diff

File 26825.diff, 1.7 KB (added by wonderboymusic, 11 years ago)
  • src/wp-admin/includes/media.php

     
    27472747
    27482748        if ( preg_match( '#^(audio|video)#', $post->post_mime_type ) ):
    27492749
     2750                if ( empty( $meta ) && file_exists( $file ) ): ?>
     2751                <div class="misc-pub-section">
     2752                        <a class="button" id="media-read-metadata" href="<?php echo admin_url( 'post.php?action=generate-metadata&post=' . $post->ID ) ?>"><?php _e( 'Read Metadata From File' ) ?></a>
     2753                </div>
     2754                <?php else:
    27502755                /**
    27512756                 * Filter the audio and video metadata fields to be shown in the publish meta box.
    27522757                 *
     
    28222827                        endif;
    28232828                endforeach;
    28242829
     2830                endif;
    28252831        endif;
    28262832
    28272833        if ( $media_dims ) : ?>
  • src/wp-admin/post.php

     
    311311        exit();
    312312        break;
    313313
     314case 'generate-metadata':
     315        if ( ! current_user_can( 'edit_post', $post_id ) ) {
     316                wp_die( __( 'You are not allowed to edit this item.' ) );
     317        }
     318
     319        $post = get_post( $post_id );
     320        if ( 'attachment' !== $post->post_type ) {
     321                wp_die( __( 'You can only generate metadata for an attachment.' ) );
     322        }
     323
     324        $file = get_attached_file( $post_id );
     325        if ( empty( $file ) ) {
     326                wp_die( __( 'This file does not exist.' ) );
     327        }
     328
     329        wp_update_attachment_metadata( $post_id, wp_generate_attachment_metadata( $post_id, $file ) );
     330
     331        wp_redirect( add_query_arg( 'action', 'edit', remove_query_arg( 'action' ) ) );
     332        exit();
     333        break;
     334
    314335default:
    315336        wp_redirect( admin_url('edit.php') );
    316337        exit();