Make WordPress Core

Changeset 30931 for branches/4.1


Ignore:
Timestamp:
12/16/2014 09:28:28 PM (12 years ago)
Author:
nacin
Message:

Customizer: Add _wp_attachment_is_custom_background meta to uploaded background images.

Merges [30885] to the 4.1 branch.

props ocean90.
fixes #30707.

Location:
branches/4.1
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/4.1

  • branches/4.1/src/wp-admin/css/customize-controls.css

    r30911 r30931  
    582582.customize-control-upload .current,
    583583.customize-control-image .current,
     584.customize-control-background .current,
    584585.customize-control-header .current {
    585586        margin-bottom: 8px;
     
    611612.customize-control-image .default-button,
    612613.customize-control-image .upload-button,
     614.customize-control-background .remove-button,
     615.customize-control-background .default-button,
     616.customize-control-background .upload-button,
    613617.customize-control-header button.new,
    614618.customize-control-header button.remove {
     
    620624.customize-control-upload .current .container,
    621625.customize-control-image .current .container,
     626.customize-control-background .current .container,
    622627.customize-control-header .current .container {
    623628        overflow: hidden;
     
    629634
    630635.customize-control-upload .current .container,
     636.customize-control-background .current .container,
    631637.customize-control-image .current .container {
    632638        min-height: 40px;
     
    635641.customize-control-upload .placeholder,
    636642.customize-control-image .placeholder,
     643.customize-control-background .placeholder,
    637644.customize-control-header .placeholder {
    638645        width: 100%;
     
    644651.customize-control-upload .inner,
    645652.customize-control-image .inner,
     653.customize-control-background .inner,
    646654.customize-control-header .inner {
    647655        display: none;
     
    655663
    656664.customize-control-upload .inner,
     665.customize-control-background .inner,
    657666.customize-control-image .inner {
    658667        display: block;
     
    662671.customize-control-upload .inner,
    663672.customize-control-image .inner,
     673.customize-control-background .inner,
    664674.customize-control-header .inner,
    665675.customize-control-header .inner .dashicons {
     
    778788.customize-control-upload .actions,
    779789.customize-control-image .actions,
     790.customize-control-background .actions,
    780791.customize-control-header .actions {
    781792        margin-bottom: 32px;
     
    794805.customize-control-upload img,
    795806.customize-control-image img,
     807.customize-control-background img,
    796808.customize-control-header img {
    797809        width: 100%;
     
    804816.customize-control-image .remove-button,
    805817.customize-control-image .default-button,
     818.customize-control-background .remove-button,
     819.customize-control-background .default-button,
    806820.customize-control-header .remove {
    807821        float: left;
     
    811825.customize-control-upload .upload-button,
    812826.customize-control-image .upload-button,
     827.customize-control-background .upload-button,
    813828.customize-control-header .new {
    814829        float: right;
  • branches/4.1/src/wp-admin/custom-background.php

    r30657 r30931  
    6161
    6262                add_action( 'admin_menu', array( $this, 'init' ) );
     63
     64                add_action( 'wp_ajax_custom-background-add', array( $this, 'ajax_background_add' ) );
     65
     66                // Unused since 3.5.0.
    6367                add_action( 'wp_ajax_set-background-image', array( $this, 'wp_set_background_image' ) );
    6468        }
     
    465469
    466470        /**
    467          * Unused since 3.5.0.
     471         * AJAX handler for adding custom background context to an attachment.
     472         *
     473         * Triggered when the user adds a new background image from the
     474         * Media Manager.
     475         *
     476         * @since 4.1.0
     477         */
     478        public function ajax_background_add() {
     479                check_ajax_referer( 'background-add', 'nonce' );
     480
     481                if ( ! current_user_can( 'edit_theme_options' ) ) {
     482                        wp_send_json_error();
     483                }
     484
     485                $attachment_id = absint( $_POST['attachment_id'] );
     486                if ( $attachment_id < 1 ) {
     487                        wp_send_json_error();
     488                }
     489
     490                update_post_meta( $attachment_id, '_wp_attachment_is_custom_background', get_stylesheet() );
     491
     492                wp_send_json_success();
     493        }
     494
     495        /**
    468496         *
    469497         * @since 3.4.0
     498         * @deprecated 3.5.0
    470499         */
    471500        public function attachment_fields_to_edit( $form_fields ) {
     
    474503
    475504        /**
    476          * Unused since 3.5.0.
    477505         *
    478506         * @since 3.4.0
     507         * @deprecated 3.5.0
    479508         */
    480509        public function filter_upload_tabs( $tabs ) {
     
    482511        }
    483512
     513        /**
     514         *
     515         * @since 3.4.0
     516         * @deprecated 3.5.0
     517         */
    484518        public function wp_set_background_image() {
    485519                if ( ! current_user_can('edit_theme_options') || ! isset( $_POST['attachment_id'] ) ) exit;
  • branches/4.1/src/wp-admin/js/customize-controls.js

    r30916 r30931  
    1 /* globals _wpCustomizeHeader, _wpMediaViewsL10n */
     1/* globals _wpCustomizeHeader, _wpCustomizeBackground, _wpMediaViewsL10n */
    22(function( exports, $ ){
    33        var Container, focus, api = wp.customize;
     
    11451145
    11461146        /**
     1147         * A control for uploading background images.
     1148         *
     1149         * @class
     1150         * @augments wp.customize.UploadControl
     1151         * @augments wp.customize.Control
     1152         * @augments wp.customize.Class
     1153         */
     1154        api.BackgroundControl = api.UploadControl.extend({
     1155
     1156                /**
     1157                 * When the control's DOM structure is ready,
     1158                 * set up internal event bindings.
     1159                 */
     1160                ready: function() {
     1161                        api.UploadControl.prototype.ready.apply( this, arguments );
     1162                },
     1163
     1164                /**
     1165                 * Callback handler for when an attachment is selected in the media modal.
     1166                 * Does an additional AJAX request for setting the background context.
     1167                 */
     1168                select: function() {
     1169                        api.UploadControl.prototype.select.apply( this, arguments );
     1170
     1171                        wp.ajax.post( 'custom-background-add', {
     1172                                nonce: _wpCustomizeBackground.nonces.add,
     1173                                wp_customize: 'on',
     1174                                theme: api.settings.theme.stylesheet,
     1175                                attachment_id: this.params.attachment.id
     1176                        } );
     1177                }
     1178        });
     1179
     1180        /**
    11471181         * @class
    11481182         * @augments wp.customize.Control
     
    18231857                upload: api.UploadControl,
    18241858                image:  api.ImageControl,
    1825                 header: api.HeaderControl
     1859                header: api.HeaderControl,
     1860                background: api.BackgroundControl
    18261861        };
    18271862        api.panelConstructor = {};
  • branches/4.1/src/wp-includes/class-wp-customize-control.php

    r30911 r30931  
    880880 */
    881881class WP_Customize_Background_Image_Control extends WP_Customize_Image_Control {
     882        public $type = 'background';
    882883
    883884        /**
     
    893894                        'label'    => __( 'Background Image' ),
    894895                        'section'  => 'background_image',
     896                ) );
     897        }
     898
     899        /**
     900         * Enqueue control related scripts/styles.
     901         *
     902         * @since 4.1.0
     903         */
     904        public function enqueue() {
     905                parent::enqueue();
     906
     907                wp_localize_script( 'customize-controls', '_wpCustomizeBackground', array(
     908                        'nonces' => array(
     909                                'add' => wp_create_nonce( 'background-add' ),
     910                        ),
    895911                ) );
    896912        }
     
    913929                        ),
    914930                        'section'  => 'header_image',
    915                         'context'  => 'custom-header',
    916931                        'removed'  => 'remove-header',
    917932                        'get_url'  => 'get_header_image',
  • branches/4.1/src/wp-includes/class-wp-customize-manager.php

    r30695 r30931  
    975975                $this->register_control_type( 'WP_Customize_Upload_Control' );
    976976                $this->register_control_type( 'WP_Customize_Image_Control' );
     977                $this->register_control_type( 'WP_Customize_Background_Image_Control' );
    977978
    978979                /* Site Title & Tagline */
Note: See TracChangeset for help on using the changeset viewer.