WordPress.org

Make WordPress Core

Changeset 21009


Ignore:
Timestamp:
06/06/12 16:48:53 (23 months ago)
Author:
ryan
Message:

Check context before adding media upload filters. Props SergeyBiryukov. fixes #20819

Location:
trunk/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/custom-background.php

    r20966 r21009  
    7373        add_action("load-$page", array(&$this, 'take_action'), 49); 
    7474        add_action("load-$page", array(&$this, 'handle_upload'), 49); 
    75         add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 10, 2 ); 
    76         add_filter( 'media_upload_tabs', array( $this, 'filter_upload_tabs' ) ); 
     75 
     76        if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-background' ) { 
     77            add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 10, 2 ); 
     78            add_filter( 'media_upload_tabs', array( $this, 'filter_upload_tabs' ) ); 
     79            add_filter( 'media_upload_mime_type_links', '__return_empty_array' ); 
     80        } 
    7781 
    7882        if ( $this->admin_header_callback ) 
     
    389393    } 
    390394 
     395    /** 
     396     * Replace default attachment actions with "Set as background" link. 
     397     * 
     398     * @since 3.4.0 
     399     */ 
    391400    function attachment_fields_to_edit( $form_fields, $post ) { 
    392         if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-background' ) { 
    393             $form_fields = array( 'image-size' => $form_fields['image-size'] ); 
    394             $form_fields['buttons'] = array( 'tr' => '<tr class="submit"><td></td><td><a data-attachment-id="' . $post->ID . '" class="wp-set-background">' . __( 'Set as background' ) . '</a></td></tr>' ); 
    395             $form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-background' ); 
    396         } 
     401        $form_fields = array( 'image-size' => $form_fields['image-size'] ); 
     402        $form_fields['buttons'] = array( 'tr' => '<tr class="submit"><td></td><td><a data-attachment-id="' . $post->ID . '" class="wp-set-background">' . __( 'Set as background' ) . '</a></td></tr>' ); 
     403        $form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-background' ); 
    397404 
    398405        return $form_fields; 
    399406    } 
    400407 
    401     function filter_upload_tabs ( $tabs ){ 
    402         if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-background' ) 
    403             return array( 'library' => __('Media Library') ); 
    404  
    405         return $tabs; 
     408    /** 
     409     * Leave only "Media Library" tab in the uploader window. 
     410     * 
     411     * @since 3.4.0 
     412     */ 
     413    function filter_upload_tabs() { 
     414        return array( 'library' => __('Media Library') ); 
    406415    } 
    407416 
  • trunk/wp-admin/custom-header.php

    r20982 r21009  
    9595            add_action("admin_head-$page", $this->admin_header_callback, 51); 
    9696 
    97         add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 10, 2 ); 
    98         add_filter( 'media_upload_tabs', array( $this, 'filter_upload_tabs' ) ); 
    99         add_filter( 'media_upload_mime_type_links', '__return_empty_array' ); 
     97        if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-header' ) { 
     98            add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 10, 2 ); 
     99            add_filter( 'media_upload_tabs', array( $this, 'filter_upload_tabs' ) ); 
     100            add_filter( 'media_upload_mime_type_links', '__return_empty_array' ); 
     101        } 
    100102    } 
    101103 
     
    973975     */ 
    974976    function attachment_fields_to_edit( $form_fields, $post ) { 
    975         if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-header' ) { 
    976             $form_fields = array(); 
    977             $href = esc_url(add_query_arg(array( 
    978                 'page' => 'custom-header', 
    979                 'step' => 2, 
    980                 '_wpnonce-custom-header-upload' => wp_create_nonce('custom-header-upload'), 
    981                 'file' => $post->ID 
    982             ), admin_url('themes.php'))); 
    983  
    984             $form_fields['buttons'] = array( 'tr' => '<tr class="submit"><td></td><td><a data-location="' . $href . '" class="wp-set-header">' . __( 'Set as header' ) . '</a></td></tr>' ); 
    985             $form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-header' ); 
    986         } 
     977        $form_fields = array(); 
     978        $href = esc_url(add_query_arg(array( 
     979            'page' => 'custom-header', 
     980            'step' => 2, 
     981            '_wpnonce-custom-header-upload' => wp_create_nonce('custom-header-upload'), 
     982            'file' => $post->ID 
     983        ), admin_url('themes.php'))); 
     984 
     985        $form_fields['buttons'] = array( 'tr' => '<tr class="submit"><td></td><td><a data-location="' . $href . '" class="wp-set-header">' . __( 'Set as header' ) . '</a></td></tr>' ); 
     986        $form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-header' ); 
    987987 
    988988        return $form_fields; 
     
    994994     * @since 3.4.0 
    995995     */ 
    996     function filter_upload_tabs( $tabs ) { 
    997         if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-header' ) 
    998             return array( 'library' => __('Media Library') ); 
    999  
    1000         return $tabs; 
     996    function filter_upload_tabs() { 
     997        return array( 'library' => __('Media Library') ); 
    1001998    } 
    1002999 
Note: See TracChangeset for help on using the changeset viewer.