Ticket #19840: 19840.diff
File 19840.diff, 5.0 KB (added by , 13 years ago) |
---|
-
wp-admin/includes/media.php
386 386 return "<a href='" . esc_url( get_upload_iframe_src($type) ) . "' id='{$id}-add_{$type}' class='thickbox add_$type' title='" . esc_attr( $title ) . "'><img src='" . esc_url( admin_url( $icon ) ) . "' alt='$title' onclick='return false;' /></a>"; 387 387 } 388 388 389 function get_upload_iframe_src( $type = null ) {389 function get_upload_iframe_src( $type = null, $tab = null ) { 390 390 global $post_ID; 391 391 392 392 $uploading_iframe_ID = (int) $post_ID; … … 395 395 if ( $type && 'media' != $type ) 396 396 $upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src); 397 397 398 if ( $tab ) 399 $upload_iframe_src = add_query_arg('tab', $tab, $upload_iframe_src); 400 398 401 $upload_iframe_src = apply_filters($type . '_upload_iframe_src', $upload_iframe_src); 399 402 400 403 return add_query_arg('TB_iframe', true, $upload_iframe_src); -
wp-admin/js/custom-background.dev.js
10 10 jQuery('#clearcolor').hide(); 11 11 } 12 12 13 function send_to_editor( attachment_id ) { 14 jQuery.post(ajaxurl, { action: 'set-background-image', attachment_id: attachment_id }, function(){ 15 tb_remove(); 16 window.location.reload(); 17 }); 18 } 19 13 20 jQuery(document).ready(function() { 14 21 jQuery('#pickcolor').click(function() { 15 22 jQuery('#colorPickerDiv').show(); -
wp-admin/custom-background.php
69 69 add_action("load-$page", array(&$this, 'admin_load')); 70 70 add_action("load-$page", array(&$this, 'take_action'), 49); 71 71 add_action("load-$page", array(&$this, 'handle_upload'), 49); 72 add_action('attachment_fields_to_edit', array(&$this, 'attachment_fields_to_edit'), 10, 2); 73 add_action('image_send_to_editor', array(&$this, 'image_send_to_editor'), 10, 2); 74 add_action('media_upload_tabs', array(&$this, 'filter_upload_tabs')); 72 75 73 76 if ( $this->admin_header_callback ) 74 77 add_action("admin_head-$page", $this->admin_header_callback, 51); … … 96 99 '<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>' 97 100 ); 98 101 102 add_thickbox(); 103 wp_enqueue_script('media-upload'); 99 104 wp_enqueue_script('custom-background'); 100 105 wp_enqueue_style('farbtastic'); 101 106 } … … 246 251 <input type="hidden" name="action" value="save" /> 247 252 <?php wp_nonce_field('custom-background-upload', '_wpnonce-custom-background-upload') ?> 248 253 <?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?> 249 </form> 254 <?php 255 $image_library_url = get_upload_iframe_src('image', 'library'); 256 $image_library_url = remove_query_arg('TB_iframe', $image_library_url); 257 $image_library_url = add_query_arg( array( 'context' => 'custom-background', 'TB_iframe' => 1 ), $image_library_url ); 258 ?> 259 </form> 260 <span class="howto"><?php _e('or'); ?></span> <a class="thickbox" href="<?php echo $image_library_url; ?>"><?php _e( 'Choose from image library' ); ?></a> 250 261 </td> 251 262 </tr> 252 263 </tbody> … … 366 377 $this->updated = true; 367 378 } 368 379 380 function attachment_fields_to_edit( $form_fields, $post ) { 381 if ( !isset( $_REQUEST['context'] ) ) return $form_fields; 382 if ( $_REQUEST['context'] != 'custom-background' ) return $form_fields; 383 384 $button = get_submit_button( __( 'Use as background image' ), 'button', "send[{$post->ID}]", false ); 385 $form_fields['buttons'] = array( 'tr' => '<tr class="submit"><td></td><td>'.$button.'</td></tr>' ); 386 $form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-background' ); 387 388 return $form_fields; 389 } 390 391 function image_send_to_editor( $html, $id ) { 392 if ( !isset( $_REQUEST['attachments'][$id]['context'] ) ) return $html; 393 if ( $_REQUEST['attachments'][$id]['context'] != 'custom-background' ) return $html; 394 395 return $id; 396 } 397 398 function filter_upload_tabs ( $tabs ){ 399 if ( !isset( $_REQUEST['context'] ) ) return $tabs; 400 if ( $_REQUEST['context'] != 'custom-background' ) return $tabs; 401 402 return array( 'library' => __('Media Library') ); 403 } 369 404 } 405 406 function wp_set_background_image() { 407 if ( ! current_user_can('edit_theme_options') ) exit; 408 if ( ! isset( $_POST['attachment_id'] ) ) exit; 409 $attachment_id = intval($_POST['attachment_id']); 410 update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_option('stylesheet' ) ); 411 $url = wp_get_attachment_image_src($attachment_id); 412 $thumbnail = wp_get_attachment_image_src($attachment_id, 'thumbnail'); 413 set_theme_mod('background_image', esc_url($url[0])); 414 set_theme_mod('background_image_thumb', esc_url($thumbnail[0])); 415 exit; 416 } 417 add_action('wp_ajax_set-background-image', 'wp_set_background_image'); 418 No newline at end of file