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

git-svn-id: http://core.svn.wordpress.org/trunk@22505 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Daryl Koopersmith 2012-11-09 11:59:05 +00:00
parent 156e782313
commit 9af37358a9
2 changed files with 47 additions and 9 deletions

View File

@ -172,7 +172,7 @@ class Custom_Image_Header {
if ( ( 1 == $step || 3 == $step ) ) {
add_thickbox();
wp_enqueue_script( 'media-upload' );
wp_enqueue_media();
wp_enqueue_script( 'custom-header' );
if ( current_theme_supports( 'custom-header', 'header-text' ) )
wp_enqueue_script( 'wp-color-picker' );
@ -534,13 +534,18 @@ class Custom_Image_Header {
<?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?>
</p>
<?php
$image_library_url = get_upload_iframe_src( 'image', null, 'library' );
$image_library_url = remove_query_arg( 'TB_iframe', $image_library_url );
$image_library_url = add_query_arg( array( 'context' => 'custom-header', 'TB_iframe' => 1 ), $image_library_url );
$modal_update_href = esc_url( add_query_arg( array(
'page' => 'custom-header',
'step' => 2,
'_wpnonce-custom-header-upload' => wp_create_nonce('custom-header-upload'),
), admin_url('themes.php') ) );
?>
<p>
<label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br />
<a id="choose-from-library-link" class="button thickbox" href="<?php echo esc_url( $image_library_url ); ?>"><?php _e( 'Choose Image' ); ?></a>
<a id="choose-from-library-link" class="button"
data-update-link="<?php echo esc_attr( $modal_update_href ); ?>"
data-choose="<?php esc_attr_e( 'Choose a Custom Header' ); ?>"
data-update="<?php esc_attr_e( 'Set as header' ); ?>"><?php _e( 'Choose Image' ); ?></a>
</p>
</form>
</td>
@ -746,7 +751,7 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
<p class="submit">
<?php submit_button( __( 'Crop and Publish' ), 'primary', 'submit', false ); ?>
<?php
if ( isset( $oitar ) && 1 == $oitar && ( current_theme_supports( 'custom-header', 'flex-height' ) || current_theme_supports( 'custom-header', 'flex-width' ) ) )
if ( isset( $oitar ) && 1 == $oitar && ( current_theme_supports( 'custom-header', 'flex-height' ) || current_theme_supports( 'custom-header', 'flex-width' ) ) )
submit_button( __( 'Skip Cropping, Publish Image as Is' ), 'secondary', 'skip-cropping', false );
?>
</p>
@ -800,7 +805,7 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
if ( ! empty( $_POST['skip-cropping'] ) && ! ( current_theme_supports( 'custom-header', 'flex-height' ) || current_theme_supports( 'custom-header', 'flex-width' ) ) )
wp_die( __( 'Cheatin&#8217; uh?' ) );
if ( $_POST['oitar'] > 1 ) {
$_POST['x1'] = $_POST['x1'] * $_POST['oitar'];
$_POST['y1'] = $_POST['y1'] * $_POST['oitar'];

View File

@ -1,7 +1,9 @@
(function($) {
// Fetch available headers and apply jQuery.masonry
// once the images have loaded.
var frame;
$( function() {
// Fetch available headers and apply jQuery.masonry
// once the images have loaded.
var $headers = $('.available-headers');
$headers.imagesLoaded( function() {
@ -9,5 +11,36 @@
itemSelector: '.default-header'
});
});
// Build the choose from library frame.
$('#choose-from-library-link').click( function( event ) {
var $el = $(this);
event.preventDefault();
frame = wp.media({
title: $el.data('choose'),
library: {
type: 'image'
}
});
frame.toolbar.on( 'activate:select', function() {
frame.toolbar.view().add({
select: {
style: 'primary',
text: $el.data('update'),
click: function() {
var attachment = frame.state().get('selection').first(),
link = $el.data('updateLink');
window.location = link + '&file=' + attachment.id;
}
}
});
});
frame.state('library');
});
});
}(jQuery));