WordPress.org

Make WordPress Core

Ticket #19840: 19840.diff

File 19840.diff, 5.0 KB (added by greuben, 2 years ago)
  • wp-admin/includes/media.php

     
    386386        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>"; 
    387387} 
    388388 
    389 function get_upload_iframe_src( $type = null ) { 
     389function get_upload_iframe_src( $type = null, $tab = null ) { 
    390390        global $post_ID; 
    391391 
    392392        $uploading_iframe_ID = (int) $post_ID; 
     
    395395        if ( $type && 'media' != $type ) 
    396396                $upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src); 
    397397 
     398        if ( $tab ) 
     399                $upload_iframe_src = add_query_arg('tab', $tab, $upload_iframe_src); 
     400 
    398401        $upload_iframe_src = apply_filters($type . '_upload_iframe_src', $upload_iframe_src); 
    399402 
    400403        return add_query_arg('TB_iframe', true, $upload_iframe_src); 
  • wp-admin/js/custom-background.dev.js

     
    1010                jQuery('#clearcolor').hide(); 
    1111} 
    1212 
     13function 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 
    1320jQuery(document).ready(function() { 
    1421        jQuery('#pickcolor').click(function() { 
    1522                jQuery('#colorPickerDiv').show(); 
  • wp-admin/custom-background.php

     
    6969                add_action("load-$page", array(&$this, 'admin_load')); 
    7070                add_action("load-$page", array(&$this, 'take_action'), 49); 
    7171                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')); 
    7275 
    7376                if ( $this->admin_header_callback ) 
    7477                        add_action("admin_head-$page", $this->admin_header_callback, 51); 
     
    9699                        '<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>' 
    97100                ); 
    98101 
     102                add_thickbox(); 
     103                wp_enqueue_script('media-upload'); 
    99104                wp_enqueue_script('custom-background'); 
    100105                wp_enqueue_style('farbtastic'); 
    101106        } 
     
    246251<input type="hidden" name="action" value="save" /> 
    247252<?php wp_nonce_field('custom-background-upload', '_wpnonce-custom-background-upload') ?> 
    248253<?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> 
    250261</td> 
    251262</tr> 
    252263</tbody> 
     
    366377                $this->updated = true; 
    367378        } 
    368379 
     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        } 
    369404} 
     405 
     406function 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} 
     417add_action('wp_ajax_set-background-image', 'wp_set_background_image'); 
     418 No newline at end of file