Make WordPress Core

Changeset 22505


Ignore:
Timestamp:
11/09/2012 11:59:05 AM (14 years ago)
Author:
koopersmith
Message:

Integrate media with the custom header page. fixes #21820, see #21390.

Location:
trunk/wp-admin
Files:
2 edited

Legend:

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

    r22470 r22505  
    173173                if ( ( 1 == $step || 3 == $step ) ) {
    174174                        add_thickbox();
    175                         wp_enqueue_script( 'media-upload' );
     175                        wp_enqueue_media();
    176176                        wp_enqueue_script( 'custom-header' );
    177177                        if ( current_theme_supports( 'custom-header', 'header-text' ) )
     
    535535        </p>
    536536        <?php
    537                 $image_library_url = get_upload_iframe_src( 'image', null, 'library' );
    538                 $image_library_url = remove_query_arg( 'TB_iframe', $image_library_url );
    539                 $image_library_url = add_query_arg( array( 'context' => 'custom-header', 'TB_iframe' => 1 ), $image_library_url );
     537                $modal_update_href = esc_url( add_query_arg( array(
     538                        'page' => 'custom-header',
     539                        'step' => 2,
     540                        '_wpnonce-custom-header-upload' => wp_create_nonce('custom-header-upload'),
     541                ), admin_url('themes.php') ) );
    540542        ?>
    541543        <p>
    542544                <label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br />
    543                 <a id="choose-from-library-link" class="button thickbox" href="<?php echo esc_url( $image_library_url ); ?>"><?php _e( 'Choose Image' ); ?></a>
     545                <a id="choose-from-library-link" class="button"
     546                        data-update-link="<?php echo esc_attr( $modal_update_href ); ?>"
     547                        data-choose="<?php esc_attr_e( 'Choose a Custom Header' ); ?>"
     548                        data-update="<?php esc_attr_e( 'Set as header' ); ?>"><?php _e( 'Choose Image' ); ?></a>
    544549        </p>
    545550        </form>
     
    747752        <?php submit_button( __( 'Crop and Publish' ), 'primary', 'submit', false ); ?>
    748753        <?php
    749         if ( isset( $oitar ) && 1 == $oitar && ( current_theme_supports( 'custom-header', 'flex-height' ) || current_theme_supports( 'custom-header', 'flex-width' ) ) ) 
     754        if ( isset( $oitar ) && 1 == $oitar && ( current_theme_supports( 'custom-header', 'flex-height' ) || current_theme_supports( 'custom-header', 'flex-width' ) ) )
    750755                submit_button( __( 'Skip Cropping, Publish Image as Is' ), 'secondary', 'skip-cropping', false );
    751756        ?>
     
    801806                if ( ! empty( $_POST['skip-cropping'] ) && ! ( current_theme_supports( 'custom-header', 'flex-height' ) || current_theme_supports( 'custom-header', 'flex-width' ) ) )
    802807                        wp_die( __( 'Cheatin&#8217; uh?' ) );
    803                        
     808
    804809                if ( $_POST['oitar'] > 1 ) {
    805810                        $_POST['x1'] = $_POST['x1'] * $_POST['oitar'];
  • trunk/wp-admin/js/custom-header.js

    r22504 r22505  
    11(function($) {
    2         // Fetch available headers and apply jQuery.masonry
    3         // once the images have loaded.
     2        var frame;
     3
    44        $( function() {
     5                // Fetch available headers and apply jQuery.masonry
     6                // once the images have loaded.
    57                var $headers = $('.available-headers');
    68
     
    1012                        });
    1113                });
     14
     15                // Build the choose from library frame.
     16                $('#choose-from-library-link').click( function( event ) {
     17                        var $el = $(this);
     18                        event.preventDefault();
     19
     20                        frame = wp.media({
     21                                title:     $el.data('choose'),
     22                                library:   {
     23                                        type: 'image'
     24                                }
     25                        });
     26
     27                        frame.toolbar.on( 'activate:select', function() {
     28                                frame.toolbar.view().add({
     29                                        select: {
     30                                                style: 'primary',
     31                                                text:  $el.data('update'),
     32
     33                                                click: function() {
     34                                                        var attachment = frame.state().get('selection').first(),
     35                                                                link = $el.data('updateLink');
     36
     37                                                        window.location = link + '&file=' + attachment.id;
     38                                                }
     39                                        }
     40                                });
     41                        });
     42
     43                        frame.state('library');
     44                });
    1245        });
    1346}(jQuery));
Note: See TracChangeset for help on using the changeset viewer.