Ticket #19840: 19840.diff

File 19840.diff, 5.0 KB (added by greuben, 16 months ago)
Line 
1Index: wp-admin/includes/media.php
2===================================================================
3--- wp-admin/includes/media.php (revision 19896)
4+++ wp-admin/includes/media.php (working copy)
5@@ -386,7 +386,7 @@
6        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>";
7 }
8 
9-function get_upload_iframe_src( $type = null ) {
10+function get_upload_iframe_src( $type = null, $tab = null ) {
11        global $post_ID;
12 
13        $uploading_iframe_ID = (int) $post_ID;
14@@ -395,6 +395,9 @@
15        if ( $type && 'media' != $type )
16                $upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src);
17 
18+       if ( $tab )
19+               $upload_iframe_src = add_query_arg('tab', $tab, $upload_iframe_src);
20+
21        $upload_iframe_src = apply_filters($type . '_upload_iframe_src', $upload_iframe_src);
22 
23        return add_query_arg('TB_iframe', true, $upload_iframe_src);
24Index: wp-admin/js/custom-background.dev.js
25===================================================================
26--- wp-admin/js/custom-background.dev.js        (revision 19896)
27+++ wp-admin/js/custom-background.dev.js        (working copy)
28@@ -10,6 +10,13 @@
29                jQuery('#clearcolor').hide();
30 }
31 
32+function send_to_editor( attachment_id ) {
33+       jQuery.post(ajaxurl, { action: 'set-background-image', attachment_id: attachment_id }, function(){
34+               tb_remove();
35+               window.location.reload();
36+       });
37+}
38+
39 jQuery(document).ready(function() {
40        jQuery('#pickcolor').click(function() {
41                jQuery('#colorPickerDiv').show();
42Index: wp-admin/custom-background.php
43===================================================================
44--- wp-admin/custom-background.php      (revision 19896)
45+++ wp-admin/custom-background.php      (working copy)
46@@ -69,6 +69,9 @@
47                add_action("load-$page", array(&$this, 'admin_load'));
48                add_action("load-$page", array(&$this, 'take_action'), 49);
49                add_action("load-$page", array(&$this, 'handle_upload'), 49);
50+               add_action('attachment_fields_to_edit', array(&$this, 'attachment_fields_to_edit'), 10, 2);
51+               add_action('image_send_to_editor', array(&$this, 'image_send_to_editor'), 10, 2);
52+               add_action('media_upload_tabs', array(&$this, 'filter_upload_tabs'));
53 
54                if ( $this->admin_header_callback )
55                        add_action("admin_head-$page", $this->admin_header_callback, 51);
56@@ -96,6 +99,8 @@
57                        '<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
58                );
59 
60+               add_thickbox();
61+               wp_enqueue_script('media-upload');
62                wp_enqueue_script('custom-background');
63                wp_enqueue_style('farbtastic');
64        }
65@@ -246,7 +251,13 @@
66 <input type="hidden" name="action" value="save" />
67 <?php wp_nonce_field('custom-background-upload', '_wpnonce-custom-background-upload') ?>
68 <?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?>
69-</form>
70+<?php
71+       $image_library_url = get_upload_iframe_src('image', 'library');
72+       $image_library_url = remove_query_arg('TB_iframe', $image_library_url);
73+       $image_library_url = add_query_arg( array( 'context' => 'custom-background', 'TB_iframe' => 1 ), $image_library_url );
74+?>
75+       </form>
76+       <span class="howto"><?php _e('or'); ?></span> <a class="thickbox" href="<?php echo $image_library_url; ?>"><?php _e( 'Choose from image library' ); ?></a>
77 </td>
78 </tr>
79 </tbody>
80@@ -366,4 +377,41 @@
81                $this->updated = true;
82        }
83 
84+       function attachment_fields_to_edit( $form_fields, $post ) {
85+               if ( !isset( $_REQUEST['context'] ) ) return $form_fields;
86+               if ( $_REQUEST['context'] != 'custom-background' ) return $form_fields;
87+
88+               $button = get_submit_button( __( 'Use as background image' ), 'button', "send[{$post->ID}]", false );
89+               $form_fields['buttons'] = array( 'tr' => '<tr class="submit"><td></td><td>'.$button.'</td></tr>' );
90+               $form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-background' );
91+
92+               return $form_fields;
93+       }
94+
95+       function image_send_to_editor( $html, $id ) {
96+               if ( !isset( $_REQUEST['attachments'][$id]['context'] ) ) return $html;
97+               if ( $_REQUEST['attachments'][$id]['context'] != 'custom-background' ) return $html;
98+
99+               return $id;
100+       }
101+
102+       function filter_upload_tabs ( $tabs ){
103+               if ( !isset( $_REQUEST['context'] ) ) return $tabs;
104+               if ( $_REQUEST['context'] != 'custom-background' ) return $tabs;
105+
106+               return array( 'library' => __('Media Library') );
107+       }
108 }
109+
110+function wp_set_background_image() {
111+       if ( ! current_user_can('edit_theme_options') ) exit;
112+       if ( ! isset( $_POST['attachment_id'] ) ) exit;
113+       $attachment_id = intval($_POST['attachment_id']);
114+       update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_option('stylesheet' ) );
115+       $url = wp_get_attachment_image_src($attachment_id);
116+       $thumbnail = wp_get_attachment_image_src($attachment_id, 'thumbnail');
117+       set_theme_mod('background_image', esc_url($url[0]));
118+       set_theme_mod('background_image_thumb', esc_url($thumbnail[0]));
119+       exit;
120+}
121+add_action('wp_ajax_set-background-image', 'wp_set_background_image');
122\ No newline at end of file