Make WordPress Core

Ticket #29211: 29211.3.diff

File 29211.3.diff, 24.9 KB (added by markoheijnen, 10 years ago)
  • src/wp-admin/css/customize-controls.css

     
    762762.customize-control-upload .current,
    763763.customize-control-image .current,
    764764.customize-control-background .current,
     765.customize-control-cropimage .current,
    765766.customize-control-header .current {
    766767        margin-bottom: 8px;
    767768}
     
    797798.customize-control-background .remove-button,
    798799.customize-control-background .default-button,
    799800.customize-control-background .upload-button,
     801.customize-control-cropimage .remove-button,
     802.customize-control-cropimage .default-button,
     803.customize-control-cropimage .upload-button,
    800804.customize-control-header button.new,
    801805.customize-control-header button.remove {
    802806        white-space: normal;
     
    808812.customize-control-upload .current .container,
    809813.customize-control-image .current .container,
    810814.customize-control-background .current .container,
     815.customize-control-cropimage .current .container,
    811816.customize-control-header .current .container {
    812817        overflow: hidden;
    813818        -webkit-border-radius: 2px;
     
    819824.customize-control-media .current .container,
    820825.customize-control-upload .current .container,
    821826.customize-control-background .current .container,
     827.customize-control-cropimage .current .container,
    822828.customize-control-image .current .container {
    823829        min-height: 40px;
    824830}
     
    827833.customize-control-upload .placeholder,
    828834.customize-control-image .placeholder,
    829835.customize-control-background .placeholder,
     836.customize-control-cropimage .placeholder,
    830837.customize-control-header .placeholder {
    831838        width: 100%;
    832839        position: relative;
     
    838845.customize-control-upload .inner,
    839846.customize-control-image .inner,
    840847.customize-control-background .inner,
     848.customize-control-cropimage .inner,
    841849.customize-control-header .inner {
    842850        display: none;
    843851        position: absolute;
     
    851859.customize-control-media .inner,
    852860.customize-control-upload .inner,
    853861.customize-control-background .inner,
     862.customize-control-cropimage .inner,
    854863.customize-control-image .inner {
    855864        display: block;
    856865        min-height: 40px;
     
    860869.customize-control-upload .inner,
    861870.customize-control-image .inner,
    862871.customize-control-background .inner,
     872.customize-control-cropimage .inner,
    863873.customize-control-header .inner,
    864874.customize-control-header .inner .dashicons {
    865875        line-height: 20px;
     
    963973.customize-control-upload .actions,
    964974.customize-control-image .actions,
    965975.customize-control-background .actions,
     976.customize-control-cropimage .actions,
    966977.customize-control-header .actions {
    967978        margin-bottom: 32px;
    968979}
     
    981992.customize-control-upload img,
    982993.customize-control-image img,
    983994.customize-control-background img,
     995.customize-control-cropimage img,
    984996.customize-control-header img {
    985997        width: 100%;
    986998        -webkit-border-radius: 2px;
     
    9951007.customize-control-image .default-button,
    9961008.customize-control-background .remove-button,
    9971009.customize-control-background .default-button,
     1010.customize-control-cropimage .remove-button,
     1011.customize-control-cropimage .default-button,
    9981012.customize-control-header .remove {
    9991013        float: left;
    10001014        margin-right: 3px;
     
    10041018.customize-control-upload .upload-button,
    10051019.customize-control-image .upload-button,
    10061020.customize-control-background .upload-button,
     1021.customize-control-cropimage .upload-button,
    10071022.customize-control-header .new {
    10081023        float: right;
    10091024}
  • src/wp-admin/js/customize-controls.js

     
    18401840         * @augments wp.customize.Control
    18411841         * @augments wp.customize.Class
    18421842         */
    1843         api.HeaderControl = api.Control.extend({
     1843        api.CropControl = api.UploadControl.extend({
     1844                /**
     1845                 * When the control's DOM structure is ready,
     1846                 * set up internal event bindings.
     1847                 */
    18441848                ready: function() {
    1845                         this.btnRemove = $('#customize-control-header_image .actions .remove');
    1846                         this.btnNew    = $('#customize-control-header_image .actions .new');
     1849                        var control = this;
    18471850
    1848                         _.bindAll(this, 'openMedia', 'removeImage');
     1851                        api.UploadControl.prototype.ready.apply( this, arguments );
     1852                },
    18491853
    1850                         this.btnNew.on( 'click', this.openMedia );
    1851                         this.btnRemove.on( 'click', this.removeImage );
     1854                /**
     1855                 * Open the media modal.
     1856                 */
     1857                openFrame: function( event ) {
     1858                        if ( api.utils.isKeydownButNotEnterEvent( event ) ) {
     1859                                return;
     1860                        }
    18521861
    1853                         api.HeaderTool.currentHeader = this.getInitialHeaderImage();
     1862                        if ( this.frame ) {
     1863                                this.frame.setState('library');
     1864                        }
    18541865
    1855                         new api.HeaderTool.CurrentView({
    1856                                 model: api.HeaderTool.currentHeader,
    1857                                 el: '#customize-control-header_image .current .container'
    1858                         });
     1866                        api.UploadControl.prototype.openFrame.call( this, event );
     1867                },
    18591868
    1860                         new api.HeaderTool.ChoiceListView({
    1861                                 collection: api.HeaderTool.UploadsList = new api.HeaderTool.ChoiceList(),
    1862                                 el: '#customize-control-header_image .choices .uploaded .list'
    1863                         });
     1869                /**
     1870                 * Create a media modal select frame, and store it so the instance can be reused when needed.
     1871                 */
     1872                initFrame: function() {
     1873                        var l10n = _wpMediaViewsL10n;
    18641874
    1865                         new api.HeaderTool.ChoiceListView({
    1866                                 collection: api.HeaderTool.DefaultsList = new api.HeaderTool.DefaultsList(),
    1867                                 el: '#customize-control-header_image .choices .default .list'
     1875                        this.frame = wp.media({
     1876                                button: {
     1877                                        text: l10n.selectAndCrop,
     1878                                        close: false
     1879                                },
     1880                                states: [
     1881                                        new wp.media.controller.Library({
     1882                                                title:     this.params.button_labels.frame_title,
     1883                                                library:   wp.media.query({ type: 'image' }),
     1884                                                multiple:  false,
     1885                                                date:      false,
     1886                                                priority:  20,
     1887                                                suggestedWidth: this.params.width,
     1888                                                suggestedHeight: this.params.height
     1889                                        }),
     1890                                        new wp.media.controller.Cropper({
     1891                                                imgSelectOptions: this.calculateImageSelectOptions,
     1892                                                control: this
     1893                                        })
     1894                                ]
    18681895                        });
    18691896
    1870                         api.HeaderTool.combinedList = api.HeaderTool.CombinedList = new api.HeaderTool.CombinedList([
    1871                                 api.HeaderTool.UploadsList,
    1872                                 api.HeaderTool.DefaultsList
    1873                         ]);
     1897                        this.frame.on('select', this.select, this);
     1898                        this.frame.on('cropped', this.onCropped, this);
     1899                        this.frame.on('skippedcrop', this.onSkippedCrop, this);
    18741900                },
    18751901
    18761902                /**
    1877                  * Returns a new instance of api.HeaderTool.ImageModel based on the currently
    1878                  * saved header image (if any).
     1903                 * After an image is selected in the media modal,
     1904                 * switch to the cropper state.
     1905                 */
     1906                select: function() {
     1907                        this.frame.setState('cropper');
     1908                },
     1909
     1910                /**
     1911                 * After the image has been cropped, apply the cropped image data to the setting.
    18791912                 *
    1880                  * @since 4.2.0
    1881                  *
    1882                  * @returns {Object} Options
     1913                 * @param {object} croppedImage Cropped attachment data.
    18831914                 */
    1884                 getInitialHeaderImage: function() {
    1885                         if ( ! api.get().header_image || ! api.get().header_image_data || _.contains( [ 'remove-header', 'random-default-image', 'random-uploaded-image' ], api.get().header_image ) ) {
    1886                                 return new api.HeaderTool.ImageModel();
    1887                         }
    1888 
    1889                         // Get the matching uploaded image object.
    1890                         var currentHeaderObject = _.find( _wpCustomizeHeader.uploads, function( imageObj ) {
    1891                                 return ( imageObj.attachment_id === api.get().header_image_data.attachment_id );
    1892                         } );
    1893                         // Fall back to raw current header image.
    1894                         if ( ! currentHeaderObject ) {
    1895                                 currentHeaderObject = {
    1896                                         url: api.get().header_image,
    1897                                         thumbnail_url: api.get().header_image,
    1898                                         attachment_id: api.get().header_image_data.attachment_id
    1899                                 };
    1900                         }
    1901 
    1902                         return new api.HeaderTool.ImageModel({
    1903                                 header: currentHeaderObject,
    1904                                 choice: currentHeaderObject.url.split( '/' ).pop()
    1905                         });
     1915                onCropped: function(croppedImage) {
     1916                        var url = croppedImage.post_content,
     1917                                attachmentId = croppedImage.attachment_id,
     1918                                w = croppedImage.width,
     1919                                h = croppedImage.height;
     1920                        this.setImageFromURL(url, attachmentId, w, h);
    19061921                },
    19071922
    19081923                /**
     
    19151930                 * @returns {Object} Options
    19161931                 */
    19171932                calculateImageSelectOptions: function(attachment, controller) {
    1918                         var xInit = parseInt(_wpCustomizeHeader.data.width, 10),
    1919                                 yInit = parseInt(_wpCustomizeHeader.data.height, 10),
    1920                                 flexWidth = !! parseInt(_wpCustomizeHeader.data['flex-width'], 10),
    1921                                 flexHeight = !! parseInt(_wpCustomizeHeader.data['flex-height'], 10),
     1933                        var control = controller.get('control');
     1934                        var xInit = parseInt(control.params.width, 10),
     1935                                yInit = parseInt(control.params.height, 10),
     1936                                flexWidth = !! parseInt(control.params.flex_width, 10),
     1937                                flexHeight = !! parseInt(control.params.flex_height, 10),
    19221938                                ratio, xImg, yImg, realHeight, realWidth,
    19231939                                imgSelectOptions;
    19241940
     
    19251941                        realWidth = attachment.get('width');
    19261942                        realHeight = attachment.get('height');
    19271943
    1928                         this.headerImage = new api.HeaderTool.ImageModel();
    1929                         this.headerImage.set({
     1944                        this.image = new api.CropTool.ImageModel();
     1945                        this.image.set({
    19301946                                themeWidth: xInit,
    19311947                                themeHeight: yInit,
    19321948                                themeFlexWidth: flexWidth,
     
    19351951                                imageHeight: realHeight
    19361952                        });
    19371953
    1938                         controller.set( 'canSkipCrop', ! this.headerImage.shouldBeCropped() );
     1954                        controller.set( 'canSkipCrop', ! this.image.shouldBeCropped() );
    19391955
    19401956                        ratio = xInit / yInit;
    19411957                        xImg = realWidth;
     
    19761992                },
    19771993
    19781994                /**
    1979                  * Sets up and opens the Media Manager in order to select an image.
    1980                  * Depending on both the size of the image and the properties of the
    1981                  * current theme, a cropping step after selection may be required or
    1982                  * skippable.
    1983                  *
    1984                  * @param {event} event
    1985                  */
    1986                 openMedia: function(event) {
    1987                         var l10n = _wpMediaViewsL10n;
    1988 
    1989                         event.preventDefault();
    1990 
    1991                         this.frame = wp.media({
    1992                                 button: {
    1993                                         text: l10n.selectAndCrop,
    1994                                         close: false
    1995                                 },
    1996                                 states: [
    1997                                         new wp.media.controller.Library({
    1998                                                 title:     l10n.chooseImage,
    1999                                                 library:   wp.media.query({ type: 'image' }),
    2000                                                 multiple:  false,
    2001                                                 date:      false,
    2002                                                 priority:  20,
    2003                                                 suggestedWidth: _wpCustomizeHeader.data.width,
    2004                                                 suggestedHeight: _wpCustomizeHeader.data.height
    2005                                         }),
    2006                                         new wp.media.controller.Cropper({
    2007                                                 imgSelectOptions: this.calculateImageSelectOptions
    2008                                         })
    2009                                 ]
    2010                         });
    2011 
    2012                         this.frame.on('select', this.onSelect, this);
    2013                         this.frame.on('cropped', this.onCropped, this);
    2014                         this.frame.on('skippedcrop', this.onSkippedCrop, this);
    2015 
    2016                         this.frame.open();
    2017                 },
    2018 
    2019                 /**
    2020                  * After an image is selected in the media modal,
    2021                  * switch to the cropper state.
    2022                  */
    2023                 onSelect: function() {
    2024                         this.frame.setState('cropper');
    2025                 },
    2026 
    2027                 /**
    2028                  * After the image has been cropped, apply the cropped image data to the setting.
    2029                  *
    2030                  * @param {object} croppedImage Cropped attachment data.
    2031                  */
    2032                 onCropped: function(croppedImage) {
    2033                         var url = croppedImage.post_content,
    2034                                 attachmentId = croppedImage.attachment_id,
    2035                                 w = croppedImage.width,
    2036                                 h = croppedImage.height;
    2037                         this.setImageFromURL(url, attachmentId, w, h);
    2038                 },
    2039 
    2040                 /**
    20411995                 * If cropping was skipped, apply the image data directly to the setting.
    20421996                 *
    20431997                 * @param {object} selection
     
    20882042                        choice.importImage();
    20892043                },
    20902044
    2091                 /**
    2092                  * Triggers the necessary events to deselect an image which was set as
    2093                  * the currently selected one.
    2094                  */
    2095                 removeImage: function() {
    2096                         api.HeaderTool.currentHeader.trigger('hide');
    2097                         api.HeaderTool.CombinedList.trigger('control:removeImage');
    2098                 }
     2045        });
    20992046
     2047        /**
     2048         * @class
     2049         * @augments wp.customize.Control
     2050         * @augments wp.customize.Class
     2051         */
     2052        api.HeaderControl = api.CropControl.extend({
     2053
    21002054        });
    21012055
    21022056        /**
     
    26992653                media:      api.MediaControl,
    27002654                upload:     api.UploadControl,
    27012655                image:      api.ImageControl,
     2656                cropimage:  api.CropControl,
    27022657                header:     api.HeaderControl,
    27032658                background: api.BackgroundControl,
    27042659                theme:      api.ThemeControl
  • src/wp-includes/class-wp-customize-control.php

     
    997997}
    998998
    999999/**
    1000  * Customize Header Image Control class.
     1000 * Customize Cropped Image Control class.
    10011001 *
    1002  * @since 3.4.0
     1002 * @since 4.3.0
    10031003 *
    10041004 * @see WP_Customize_Image_Control
    10051005 */
    1006 class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
    1007         public $type = 'header';
    1008         public $uploaded_headers;
    1009         public $default_headers;
     1006class WP_Customize_Cropped_Image_Control extends WP_Customize_Image_Control {
     1007        public $type = 'cropimage';
    10101008
     1009        protected $width  = 150;
     1010        protected $height = 150;
     1011        protected $flex_width  = false;
     1012        protected $flex_height = false;
     1013        protected $localized_name;
     1014        protected $current_title = '';
     1015
    10111016        /**
     1017         * Constructor.
     1018         *
     1019         * @since 4.3.0
     1020         * @uses WP_Customize_Image_Control::__construct()
     1021         *
    10121022         * @param WP_Customize_Manager $manager
    10131023         */
    1014         public function __construct( $manager ) {
    1015                 parent::__construct( $manager, 'header_image', array(
    1016                         'label'    => __( 'Header Image' ),
    1017                         'settings' => array(
    1018                                 'default' => 'header_image',
    1019                                 'data'    => 'header_image_data',
    1020                         ),
    1021                         'section'  => 'header_image',
    1022                         'removed'  => 'remove-header',
    1023                         'get_url'  => 'get_header_image',
    1024                 ) );
    1025 
     1024        public function __construct( $manager, $id, $args ) {
     1025                parent::__construct( $manager, $id, $args );
    10261026        }
    10271027
    10281028        /**
     
    10291029         * @access public
    10301030         */
    10311031        public function enqueue() {
    1032                 wp_enqueue_media();
    10331032                wp_enqueue_script( 'customize-views' );
    10341033
    1035                 $this->prepare_control();
     1034                parent::enqueue();
     1035        }
    10361036
    1037                 wp_localize_script( 'customize-views', '_wpCustomizeHeader', array(
    1038                         'data' => array(
    1039                                 'width' => absint( get_theme_support( 'custom-header', 'width' ) ),
    1040                                 'height' => absint( get_theme_support( 'custom-header', 'height' ) ),
    1041                                 'flex-width' => absint( get_theme_support( 'custom-header', 'flex-width' ) ),
    1042                                 'flex-height' => absint( get_theme_support( 'custom-header', 'flex-height' ) ),
    1043                                 'currentImgSrc' => $this->get_current_image_src(),
     1037        /**
     1038         * Refresh the parameters passed to the JavaScript via JSON.
     1039         *
     1040         * @since 4.3.0
     1041         * @access public
     1042         * @uses WP_Customize_Image_Control::to_json()
     1043         *
     1044         * @see WP_Customize_Control::to_json()
     1045         */
     1046        public function to_json() {
     1047                parent::to_json();
     1048
     1049                $this->json['width']       = absint( $this->width );
     1050                $this->json['height']      = absint( $this->height );
     1051                $this->json['flex_width']  = absint( $this->flex_width );
     1052                $this->json['flex_height'] = absint( $this->flex_height );
     1053        }
     1054
     1055}
     1056
     1057/**
     1058 * Customize Header Image Control class.
     1059 *
     1060 * @since 3.4.0
     1061 *
     1062 * @see WP_Customize_Cropped_Image_Control
     1063 */
     1064class WP_Customize_Header_Image_Control extends WP_Customize_Cropped_Image_Control {
     1065        public $type = 'header';
     1066
     1067        /**
     1068         * @param WP_Customize_Manager $manager
     1069         */
     1070        public function __construct( $manager ) {
     1071                parent::__construct( $manager, 'header_image', array(
     1072                        'label'         => __( 'Header Image' ),
     1073                        'current_title' => __( 'Current header' ),
     1074                        'settings' => array(
     1075                                'default' => 'header_image',
     1076                                'data'    => 'header_image_data',
    10441077                        ),
    1045                         'nonces' => array(
    1046                                 'add' => wp_create_nonce( 'header-add' ),
    1047                                 'remove' => wp_create_nonce( 'header-remove' ),
    1048                         ),
    1049                         'uploads' => $this->uploaded_headers,
    1050                         'defaults' => $this->default_headers
     1078                        'section'       => 'header_image',
     1079                        'removed'       => 'remove-header',
    10511080                ) );
    10521081
    1053                 parent::enqueue();
     1082                $this->width  = get_theme_support( 'custom-header', 'width' );
     1083                $this->height = get_theme_support( 'custom-header', 'height' );
     1084                $this->flex_width  = get_theme_support( 'custom-header', 'flex-width' );
     1085                $this->flex_height = get_theme_support( 'custom-header', 'flex-height' );
     1086                $this->localized_name = '_wpCustomizeHeader';
    10541087        }
    10551088
    10561089        /**
     
    10591092         */
    10601093        public function prepare_control() {
    10611094                global $custom_image_header;
     1095
    10621096                if ( empty( $custom_image_header ) ) {
    10631097                        return;
    10641098                }
     
    10651099
    10661100                // Process default headers and uploaded headers.
    10671101                $custom_image_header->process_default_headers();
    1068                 $this->default_headers = $custom_image_header->get_default_header_images();
    1069                 $this->uploaded_headers = $custom_image_header->get_uploaded_header_images();
     1102                $this->default_images = $custom_image_header->get_default_header_images();
     1103                $this->uploaded_images = $custom_image_header->get_uploaded_header_images();
    10701104        }
    10711105
    10721106        /**
     
    11001134
    11011135                        <# } #>
    11021136                </script>
    1103 
    1104                 <script type="text/template" id="tmpl-header-current">
    1105                         <# if (data.choice) { #>
    1106                                 <# if (data.random) { #>
    1107 
    1108                         <div class="placeholder">
    1109                                 <div class="inner">
    1110                                         <span><span class="dashicons dashicons-randomize dice"></span>
    1111                                         <# if ( data.type === 'uploaded' ) { #>
    1112                                                 <?php _e( 'Randomizing uploaded headers' ); ?>
    1113                                         <# } else if ( data.type === 'default' ) { #>
    1114                                                 <?php _e( 'Randomizing suggested headers' ); ?>
    1115                                         <# } #>
    1116                                         </span>
    1117                                 </div>
    1118                         </div>
    1119 
    1120                                 <# } else { #>
    1121 
    1122                         <img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}" tabindex="0"/>
    1123 
    1124                                 <# } #>
    1125                         <# } else { #>
    1126 
    1127                         <div class="placeholder">
    1128                                 <div class="inner">
    1129                                         <span>
    1130                                                 <?php _e( 'No image set' ); ?>
    1131                                         </span>
    1132                                 </div>
    1133                         </div>
    1134 
    1135                         <# } #>
    1136                 </script>
    11371137                <?php
    11381138        }
    11391139
    11401140        /**
    1141          * @return string|void
    1142          */
    1143         public function get_current_image_src() {
    1144                 $src = $this->value();
    1145                 if ( isset( $this->get_url ) ) {
    1146                         $src = call_user_func( $this->get_url, $src );
    1147                         return $src;
    1148                 }
    1149         }
    1150 
    1151         /**
    11521141         * @access public
    11531142         */
    11541143        public function render_content() {
    11551144                $this->print_header_image_template();
    1156                 $visibility = $this->get_current_image_src() ? '' : ' style="display:none" ';
    1157                 $width = absint( get_theme_support( 'custom-header', 'width' ) );
    1158                 $height = absint( get_theme_support( 'custom-header', 'height' ) );
    1159                 ?>
    11601145
    1161 
    1162                 <div class="customize-control-content">
    1163                         <p class="customizer-section-intro">
    1164                                 <?php
    1165                                 if ( $width && $height ) {
    1166                                         printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a header size of <strong>%s &times; %s</strong> pixels.' ), $width, $height );
    1167                                 } elseif ( $width ) {
    1168                                         printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a header width of <strong>%s</strong> pixels.' ), $width );
    1169                                 } else {
    1170                                         printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a header height of <strong>%s</strong> pixels.' ), $height );
    1171                                 }
    1172                                 ?>
    1173                         </p>
    1174                         <div class="current">
    1175                                 <span class="customize-control-title">
    1176                                         <?php _e( 'Current header' ); ?>
    1177                                 </span>
    1178                                 <div class="container">
    1179                                 </div>
    1180                         </div>
    1181                         <div class="actions">
    1182                                 <?php /* translators: Hide as in hide header image via the Customizer */ ?>
    1183                                 <button type="button"<?php echo $visibility ?> class="button remove"><?php _ex( 'Hide image', 'custom header' ); ?></button>
    1184                                 <?php /* translators: New as in add new header image via the Customizer */ ?>
    1185                                 <button type="button" class="button new"><?php _ex( 'Add new image', 'header image' ); ?></button>
    1186                                 <div style="clear:both"></div>
    1187                         </div>
    1188                         <div class="choices">
    1189                                 <span class="customize-control-title header-previously-uploaded">
    1190                                         <?php _ex( 'Previously uploaded', 'custom headers' ); ?>
    1191                                 </span>
    1192                                 <div class="uploaded">
    1193                                         <div class="list">
    1194                                         </div>
    1195                                 </div>
    1196                                 <span class="customize-control-title header-default">
    1197                                         <?php _ex( 'Suggested', 'custom headers' ); ?>
    1198                                 </span>
    1199                                 <div class="default">
    1200                                         <div class="list">
    1201                                         </div>
    1202                                 </div>
    1203                         </div>
    1204                 </div>
    1205                 <?php
     1146                parent::render_content();
    12061147        }
    12071148}
    12081149
  • src/wp-includes/class-wp-customize-manager.php

     
    12781278                $this->register_control_type( 'WP_Customize_Upload_Control' );
    12791279                $this->register_control_type( 'WP_Customize_Image_Control' );
    12801280                $this->register_control_type( 'WP_Customize_Background_Image_Control' );
     1281                $this->register_control_type( 'WP_Customize_Cropped_Image_Control' );
    12811282                $this->register_control_type( 'WP_Customize_Theme_Control' );
    12821283
    12831284                /* Themes */
  • src/wp-includes/class-wp-customize-nav-menus.php

     
    403403                        'description' => $description,
    404404                ) );
    405405
    406                 // @todo if ( ! $menus ) : make a "default" menu
    407                 if ( $menus ) {
    408                         $choices = array( '0' => __( '&mdash; Select &mdash;' ) );
    409                         foreach ( $menus as $menu ) {
    410                                 $choices[ $menu->term_id ] = wp_html_excerpt( $menu->name, 40, '&hellip;' );
    411                         }
     406                $choices = array( '0' => __( '&mdash; Select &mdash;' ) );
     407                foreach ( $menus as $menu ) {
     408                        $choices[ $menu->term_id ] = wp_html_excerpt( $menu->name, 40, '&hellip;' );
     409                }
    412410
    413                         foreach ( $locations as $location => $description ) {
    414                                 $setting_id = "nav_menu_locations[{$location}]";
     411                foreach ( $locations as $location => $description ) {
     412                        $setting_id = "nav_menu_locations[{$location}]";
    415413
    416                                 $setting = $this->manager->get_setting( $setting_id );
    417                                 if ( $setting ) {
    418                                         $setting->transport = 'postMessage';
    419                                         remove_filter( "customize_sanitize_{$setting_id}", 'absint' );
    420                                         add_filter( "customize_sanitize_{$setting_id}", array( $this, 'intval_base10' ) );
    421                                 } else {
    422                                         $this->manager->add_setting( $setting_id, array(
    423                                                 'sanitize_callback' => array( $this, 'intval_base10' ),
    424                                                 'theme_supports'    => 'menus',
    425                                                 'type'              => 'theme_mod',
    426                                                 'transport'         => 'postMessage',
    427                                         ) );
    428                                 }
     414                        $setting = $this->manager->get_setting( $setting_id );
     415                        if ( $setting ) {
     416                                $setting->transport = 'postMessage';
     417                                remove_filter( "customize_sanitize_{$setting_id}", 'absint' );
     418                                add_filter( "customize_sanitize_{$setting_id}", array( $this, 'intval_base10' ) );
     419                        } else {
     420                                $this->manager->add_setting( $setting_id, array(
     421                                        'sanitize_callback' => array( $this, 'intval_base10' ),
     422                                        'theme_supports'    => 'menus',
     423                                        'type'              => 'theme_mod',
     424                                        'transport'         => 'postMessage',
     425                                ) );
     426                        }
    429427
    430                                 $this->manager->add_control( new WP_Customize_Nav_Menu_Location_Control( $this->manager, $setting_id, array(
    431                                         'label'       => $description,
    432                                         'location_id' => $location,
    433                                         'section'     => 'menu_locations',
    434                                         'choices'     => $choices,
    435                                 ) ) );
    436                         }
     428                        $this->manager->add_control( new WP_Customize_Nav_Menu_Location_Control( $this->manager, $setting_id, array(
     429                                'label'       => $description,
     430                                'location_id' => $location,
     431                                'section'     => 'menu_locations',
     432                                'choices'     => $choices,
     433                        ) ) );
    437434                }
    438435
    439436                // Register each menu as a Customizer section, and add each menu item to each menu.
  • src/wp-includes/js/customize-models.js

     
    11/* globals _wpCustomizeHeader, _ */
    22(function( $, wp ) {
    33        var api = wp.customize;
    4         api.HeaderTool = {};
     4        api.CropTool = api.HeaderTool = {};
    55
    66
    77        /**
    8          * wp.customize.HeaderTool.ImageModel
     8         * wp.customize.CropTool.ImageModel
    99         *
    1010         * A header image. This is where saves via the Customizer API are
    1111         * abstracted away, plus our own AJAX calls to add images to and remove
     
    1616         * @constructor
    1717         * @augments Backbone.Model
    1818         */
    19         api.HeaderTool.ImageModel = Backbone.Model.extend({
     19        api.CropTool.ImageModel = Backbone.Model.extend({
    2020                defaults: function() {
    2121                        return {
    2222                                header: {
     
    129129         * @augments Backbone.Collection
    130130         */
    131131        api.HeaderTool.ChoiceList = Backbone.Collection.extend({
    132                 model: api.HeaderTool.ImageModel,
     132                model: api.CropTool.ImageModel,
    133133
    134134                // Ordered from most recently used to least
    135135                comparator: function(model) {
  • src/wp-includes/js/customize-views.js

     
    1616         * @augments wp.Backbone.View
    1717         */
    1818        api.HeaderTool.CurrentView = wp.Backbone.View.extend({
    19                 template: wp.template('header-current'),
     19                template: wp.template('cropped-current'),
    2020
    2121                initialize: function() {
    2222                        this.listenTo(this.model, 'change', this.render);
     
    8686         * Represents a choosable header image, be it user-uploaded,
    8787         * theme-suggested or a special Randomize choice.
    8888         *
    89          * Takes a wp.customize.HeaderTool.ImageModel.
     89         * Takes a wp.customize.CropTool.ImageModel.
    9090         *
    9191         * Manually changes model wp.customize.HeaderTool.currentHeader via the
    9292         * `select` method.