<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[30309] trunk/src: Customizer: Add support for the media library in Background Image controls.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/30309">30309</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/30309","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>ocean90</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2014-11-11 23:51:48 +0000 (Tue, 11 Nov 2014)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Customizer: Add support for the media library in Background Image controls.
`WP_Customize_Upload_Control` (PHP) and `api.UploadControl` (JS) can now open the media modal.
props celloexpressions, and ericlewis for docs.
see <a href="https://core.trac.wordpress.org/ticket/21483">#21483</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadmincsscustomizecontrolscss">trunk/src/wp-admin/css/customize-controls.css</a></li>
<li><a href="#trunksrcwpadminjscustomizecontrolsjs">trunk/src/wp-admin/js/customize-controls.js</a></li>
<li><a href="#trunksrcwpincludesclasswpcustomizecontrolphp">trunk/src/wp-includes/class-wp-customize-control.php</a></li>
<li><a href="#trunksrcwpincludesclasswpcustomizemanagerphp">trunk/src/wp-includes/class-wp-customize-manager.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadmincsscustomizecontrolscss"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/css/customize-controls.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/css/customize-controls.css 2014-11-11 22:45:47 UTC (rev 30308)
+++ trunk/src/wp-admin/css/customize-controls.css 2014-11-11 23:51:48 UTC (rev 30309)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -10,6 +10,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> font-size: 14px;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+#customize-controls img {
+ max-width: 100%;
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px"> #customize-controls .submit {
</span><span class="cx" style="display: block; padding: 0 10px"> text-align: center;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -414,6 +418,40 @@
</span><span class="cx" style="display: block; padding: 0 10px"> margin-right: 5px;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+.customize-control .attachment-thumb.type-icon {
+ float: left;
+ margin-right: 12px;
+}
+
+.customize-control .attachment-title {
+ font-weight: bold;
+ margin: 0 0 12px 0;
+}
+
+.customize-control .remove-button {
+ margin-left: 8px;
+ vertical-align: middle;
+}
+
+.customize-control .thumbnail-audio .attachment-title,
+.customize-control .thumbnail.thumbnail-audio,
+.customize-control .thumbnail.thumbnail-video,
+.customize-control .thumbnail.thumbnail-image {
+ margin-bottom: 8px;
+}
+
+.customize-control .placeholder-text {
+ font-size: 18px;
+ font-weight: 300;
+ text-align: center;
+ color: #aaa;
+ cursor: default;
+}
+
+.customize-control .thumbnail-image img {
+ cursor: pointer;
+}
+
</ins><span class="cx" style="display: block; padding: 0 10px"> #customize-preview iframe {
</span><span class="cx" style="display: block; padding: 0 10px"> width: 100%;
</span><span class="cx" style="display: block; padding: 0 10px"> height: 100%;
</span></span></pre></div>
<a id="trunksrcwpadminjscustomizecontrolsjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/js/customize-controls.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/js/customize-controls.js 2014-11-11 22:45:47 UTC (rev 30308)
+++ trunk/src/wp-admin/js/customize-controls.js 2014-11-11 23:51:48 UTC (rev 30309)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5,7 +5,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // @todo Move private helper functions to wp.customize.utils so they can be unit tested
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @constructor
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @class
</ins><span class="cx" style="display: block; padding: 0 10px"> * @augments wp.customize.Value
</span><span class="cx" style="display: block; padding: 0 10px"> * @augments wp.customize.Class
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -127,7 +127,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Base class for Panel and Section
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @constructor
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @class
</ins><span class="cx" style="display: block; padding: 0 10px"> * @augments wp.customize.Class
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> Container = api.Class.extend({
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -316,7 +316,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @constructor
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @class
</ins><span class="cx" style="display: block; padding: 0 10px"> * @augments wp.customize.Class
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> api.Section = Container.extend({
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -471,7 +471,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @constructor
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @class
</ins><span class="cx" style="display: block; padding: 0 10px"> * @augments wp.customize.Class
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> api.Panel = Container.extend({
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -640,8 +640,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @constructor
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * A Customizer Control.
+ *
+ * A control provides a UI element that allows a user to modify a Customizer Setting.
+ *
+ * @see PHP class WP_Customize_Control.
+ *
+ * @class
</ins><span class="cx" style="display: block; padding: 0 10px"> * @augments wp.customize.Class
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *
+ * @param {string} id Unique identifier for the control instance.
+ * @param {object} options Options hash for the control instance.
+ * @param {object} options.params
+ * @param {object} options.params.type Type of control (e.g. text, radio, dropdown-pages, etc.)
+ * @param {string} options.params.content The HTML content for the control.
+ * @param {string} options.params.priority Order of priority to show the control within the section.
+ * @param {string} options.params.active
+ * @param {string} options.params.section
+ * @param {string} options.params.label
+ * @param {string} options.params.description
+ * @param {string} options.params.instanceNumber Order in which this instance was created in relation to other instances.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> api.Control = api.Class.extend({
</span><span class="cx" style="display: block; padding: 0 10px"> defaultActiveArguments: { duration: 'fast', completeCallback: $.noop },
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -652,7 +670,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> control.params = {};
</span><span class="cx" style="display: block; padding: 0 10px"> $.extend( control, options || {} );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> control.id = id;
</span><span class="cx" style="display: block; padding: 0 10px"> control.selector = '#customize-control-' + id.replace( /\]/g, '' ).replace( /\[/g, '-' );
</span><span class="cx" style="display: block; padding: 0 10px"> control.templateSelector = 'customize-control-' + control.params.type + '-content';
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -728,7 +745,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> },
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- *
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Embed the control into the page.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> embed: function () {
</span><span class="cx" style="display: block; padding: 0 10px"> var control = this,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -758,6 +775,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> },
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Triggered when the control's markup has been injected into the DOM.
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @abstract
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> ready: function() {},
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -865,17 +884,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> var template,
</span><span class="cx" style="display: block; padding: 0 10px"> control = this;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Replace the container element's content with the control.
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( 0 !== $( '#tmpl-' + control.templateSelector ).length ) {
</span><span class="cx" style="display: block; padding: 0 10px"> template = wp.template( control.templateSelector );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( template && control.container ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- control.container.append( template( control.params ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ control.container.html( template( control.params ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @constructor
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * A colorpicker control.
+ *
+ * @class
</ins><span class="cx" style="display: block; padding: 0 10px"> * @augments wp.customize.Control
</span><span class="cx" style="display: block; padding: 0 10px"> * @augments wp.customize.Class
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -901,192 +923,141 @@
</span><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @constructor
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * An upload control, which utilizes the media modal.
+ *
+ * @class
</ins><span class="cx" style="display: block; padding: 0 10px"> * @augments wp.customize.Control
</span><span class="cx" style="display: block; padding: 0 10px"> * @augments wp.customize.Class
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> api.UploadControl = api.Control.extend({
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- ready: function() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * When the control's DOM structure is ready,
+ * set up internal event bindings.
+ */
+ ready: function() {
</ins><span class="cx" style="display: block; padding: 0 10px"> var control = this;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Shortcut so that we don't have to use _.bind every time we add a callback.
+ _.bindAll( control, 'restoreDefault', 'removeFile', 'openFrame', 'select' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- this.params.removed = this.params.removed || '';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Bind events, with delegation to facilitate re-rendering.
+ control.container.on( 'click keydown', '.upload-button', control.openFrame );
+ control.container.on( 'click keydown', '.thumbnail-image img', control.openFrame );
+ control.container.on( 'click keydown', '.default-button', control.restoreDefault );
+ control.container.on( 'click keydown', '.remove-button', control.removeFile );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- this.success = $.proxy( this.success, this );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Re-render whenever the control's setting changes.
+ control.setting.bind( function () { control.renderContent(); } );
+ },
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- this.uploader = $.extend({
- container: this.container,
- browser: this.container.find('.upload'),
- dropzone: this.container.find('.upload-dropzone'),
- success: this.success,
- plupload: {},
- params: {}
- }, this.uploader || {} );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Open the media modal.
+ */
+ openFrame: function( event ) {
+ if ( event.type === 'keydown' && 13 !== event.which ) { // enter
+ return;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( control.params.extensions ) {
- control.uploader.plupload.filters = [{
- title: api.l10n.allowedFiles,
- extensions: control.params.extensions
- }];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ event.preventDefault();
+
+ if ( ! this.frame ) {
+ this.initFrame();
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( control.params.context )
- control.uploader.params['post_data[context]'] = this.params.context;
-
- if ( api.settings.theme.stylesheet )
- control.uploader.params['post_data[theme]'] = api.settings.theme.stylesheet;
-
- this.uploader = new wp.Uploader( this.uploader );
-
- this.remover = this.container.find('.remove');
- this.remover.on( 'click keydown', function( event ) {
- if ( isKeydownButNotEnterEvent( event ) ) {
- return;
- }
-
- control.setting.set( control.params.removed );
- event.preventDefault();
- });
-
- this.removerVisibility = $.proxy( this.removerVisibility, this );
- this.setting.bind( this.removerVisibility );
- this.removerVisibility( this.setting.get() );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ this.frame.open();
</ins><span class="cx" style="display: block; padding: 0 10px"> },
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- success: function( attachment ) {
- this.setting.set( attachment.get('url') );
- },
- removerVisibility: function( to ) {
- this.remover.toggle( to != this.params.removed );
- }
- });
</del><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- /**
- * @constructor
- * @augments wp.customize.UploadControl
- * @augments wp.customize.Control
- * @augments wp.customize.Class
- */
- api.ImageControl = api.UploadControl.extend({
- ready: function() {
- var control = this,
- panels;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Create a media modal select frame, and store it so the instance can be reused when needed.
+ */
+ initFrame: function() {
+ this.frame = wp.media({
+ // The title of the media modal.
+ title: this.params.button_labels.frame_title,
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- this.uploader = {
- init: function() {
- var fallback, button;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Restrict the library to specified mime type.
+ library: {
+ type: this.params.mime_type
+ },
+ button: {
+ // Change the submit button label.
+ text: this.params.button_labels.frame_button
+ },
+ multiple: false
+ });
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( this.supports.dragdrop )
- return;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // When a file is selected, run a callback.
+ this.frame.on( 'select', this.select );
+ },
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Maintain references while wrapping the fallback button.
- fallback = control.container.find( '.upload-fallback' );
- button = fallback.children().detach();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Callback handler for when an attachment is selected in the media modal.
+ * Gets the selected image information, and sets it within the control.
+ */
+ select: function() {
+ // Get the attachment from the modal frame.
+ var attachment = this.frame.state().get( 'selection' ).first().toJSON();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- this.browser.detach().empty().append( button );
- fallback.append( this.browser ).show();
- }
- };
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ this.params.attachment = attachment;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- api.UploadControl.prototype.ready.call( this );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Set the Customizer setting; the callback takes care of rendering.
+ this.setting( attachment.url );
+ },
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- this.thumbnail = this.container.find('.preview-thumbnail img');
- this.thumbnailSrc = $.proxy( this.thumbnailSrc, this );
- this.setting.bind( this.thumbnailSrc );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Reset the setting to the default value.
+ */
+ restoreDefault: function( event ) {
+ if ( event.type === 'keydown' && 13 !== event.which ) { // enter
+ return;
+ }
+ event.preventDefault();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- this.library = this.container.find('.library');
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ this.params.attachment = this.params.defaultAttachment;
+ this.setting( this.params.defaultAttachment.url );
+ },
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Generate tab objects
- this.tabs = {};
- panels = this.library.find('.library-content');
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Called when the "Remove" link is clicked. Empties the setting.
+ *
+ * @param {object} event jQuery Event object
+ */
+ removeFile: function( event ) {
+ if ( event.type === 'keydown' && 13 !== event.which ) { // enter
+ return;
+ }
+ event.preventDefault();
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- this.library.children('ul').children('li').each( function() {
- var link = $(this),
- id = link.data('customizeTab'),
- panel = panels.filter('[data-customize-tab="' + id + '"]');
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ this.params.attachment = {};
+ this.setting( '' );
+ this.renderContent(); // Not bound to setting change when emptying.
+ },
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- control.tabs[ id ] = {
- both: link.add( panel ),
- link: link,
- panel: panel
- };
- });
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // @deprecated
+ success: function() {},
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Bind tab switch events
- this.library.children('ul').on( 'click keydown', 'li', function( event ) {
- if ( isKeydownButNotEnterEvent( event ) ) {
- return;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // @deprecated
+ removerVisibility: function() {}
+ });
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- var id = $(this).data('customizeTab'),
- tab = control.tabs[ id ];
-
- event.preventDefault();
-
- if ( tab.link.hasClass('library-selected') )
- return;
-
- control.selected.both.removeClass('library-selected');
- control.selected = tab;
- control.selected.both.addClass('library-selected');
- });
-
- // Bind events to switch image urls.
- this.library.on( 'click keydown', 'a', function( event ) {
- if ( isKeydownButNotEnterEvent( event ) ) {
- return;
- }
-
- var value = $(this).data('customizeImageValue');
-
- if ( value ) {
- control.setting.set( value );
- event.preventDefault();
- }
- });
-
- if ( this.tabs.uploaded ) {
- this.tabs.uploaded.target = this.library.find('.uploaded-target');
- if ( ! this.tabs.uploaded.panel.find('.thumbnail').length )
- this.tabs.uploaded.both.addClass('hidden');
- }
-
- // Select a tab
- panels.each( function() {
- var tab = control.tabs[ $(this).data('customizeTab') ];
-
- // Select the first visible tab.
- if ( ! tab.link.hasClass('hidden') ) {
- control.selected = tab;
- tab.both.addClass('library-selected');
- return false;
- }
- });
-
- this.dropdownInit();
- },
- success: function( attachment ) {
- api.UploadControl.prototype.success.call( this, attachment );
-
- // Add the uploaded image to the uploaded tab.
- if ( this.tabs.uploaded && this.tabs.uploaded.target.length ) {
- this.tabs.uploaded.both.removeClass('hidden');
-
- // @todo: Do NOT store this on the attachment model. That is bad.
- attachment.element = $( '<a href="#" class="thumbnail"></a>' )
- .data( 'customizeImageValue', attachment.get('url') )
- .append( '<img src="' + attachment.get('url')+ '" />' )
- .appendTo( this.tabs.uploaded.target );
- }
- },
- thumbnailSrc: function( to ) {
- if ( /^(https?:)?\/\//.test( to ) )
- this.thumbnail.prop( 'src', to ).show();
- else
- this.thumbnail.hide();
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * A control for uploading images.
+ *
+ * This control no longer needs to do anything more
+ * than what the upload control does in JS.
+ *
+ * @class
+ * @augments wp.customize.UploadControl
+ * @augments wp.customize.Control
+ * @augments wp.customize.Class
+ */
+ api.ImageControl = api.UploadControl.extend({
+ // @deprecated
+ thumbnailSrc: function() {}
</ins><span class="cx" style="display: block; padding: 0 10px"> });
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @constructor
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @class
</ins><span class="cx" style="display: block; padding: 0 10px"> * @augments wp.customize.Control
</span><span class="cx" style="display: block; padding: 0 10px"> * @augments wp.customize.Class
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1233,9 +1204,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> this.frame.open();
</span><span class="cx" style="display: block; padding: 0 10px"> },
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * After an image is selected in the media modal,
+ * switch to the cropper state.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> onSelect: function() {
</span><span class="cx" style="display: block; padding: 0 10px"> this.frame.setState('cropper');
</span><span class="cx" style="display: block; padding: 0 10px"> },
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * After the image has been cropped, apply the cropped image data to the setting.
+ *
+ * @param {object} croppedImage Cropped attachment data.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> onCropped: function(croppedImage) {
</span><span class="cx" style="display: block; padding: 0 10px"> var url = croppedImage.post_content,
</span><span class="cx" style="display: block; padding: 0 10px"> attachmentId = croppedImage.attachment_id,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1243,6 +1224,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> h = croppedImage.height;
</span><span class="cx" style="display: block; padding: 0 10px"> this.setImageFromURL(url, attachmentId, w, h);
</span><span class="cx" style="display: block; padding: 0 10px"> },
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * If cropping was skipped, apply the image data directly to the setting.
+ *
+ * @param {object} selection
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> onSkippedCrop: function(selection) {
</span><span class="cx" style="display: block; padding: 0 10px"> var url = selection.get('url'),
</span><span class="cx" style="display: block; padding: 0 10px"> w = selection.get('width'),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1309,7 +1296,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> api.panel = new api.Values({ defaultConstructor: api.Panel });
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @constructor
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @class
</ins><span class="cx" style="display: block; padding: 0 10px"> * @augments wp.customize.Messenger
</span><span class="cx" style="display: block; padding: 0 10px"> * @augments wp.customize.Class
</span><span class="cx" style="display: block; padding: 0 10px"> * @mixes wp.customize.Events
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1523,7 +1510,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> };
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @constructor
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @class
</ins><span class="cx" style="display: block; padding: 0 10px"> * @augments wp.customize.Messenger
</span><span class="cx" style="display: block; padding: 0 10px"> * @augments wp.customize.Class
</span><span class="cx" style="display: block; padding: 0 10px"> * @mixes wp.customize.Events
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpcustomizecontrolphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-customize-control.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-customize-control.php 2014-11-11 22:45:47 UTC (rev 30308)
+++ trunk/src/wp-includes/class-wp-customize-control.php 2014-11-11 23:51:48 UTC (rev 30309)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -637,18 +637,42 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.4.0
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> class WP_Customize_Upload_Control extends WP_Customize_Control {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public $type = 'upload';
- public $removed = '';
- public $context;
- public $extensions = array();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public $type = 'upload';
+ public $mime_type = '';
+ public $button_labels = array();
+ public $removed = ''; // unused
+ public $context; // unused
+ public $extensions = array(); // unused
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Constructor.
+ *
+ * @since 4.1.0
+ * @uses WP_Customize_Control::__construct()
+ *
+ * @param WP_Customize_Manager $manager
+ */
+ public function __construct( $manager, $id, $args = array() ) {
+ parent::__construct( $manager, $id, $args );
+
+ $this->button_labels = array(
+ 'select' => __( 'Select File' ),
+ 'change' => __( 'Change File' ),
+ 'default' => __( 'Default' ),
+ 'remove' => __( 'Remove' ),
+ 'placeholder' => __( 'No file selected' ),
+ 'frame_title' => __( 'Select File' ),
+ 'frame_button' => __( 'Choose File' ),
+ );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Enqueue control related scripts/styles.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.4.0
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function enqueue() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_enqueue_script( 'wp-plupload' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_enqueue_media();
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -659,35 +683,122 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function to_json() {
</span><span class="cx" style="display: block; padding: 0 10px"> parent::to_json();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->json['mime_type'] = $this->mime_type;
+ $this->json['button_labels'] = $this->button_labels;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->json['removed'] = $this->removed;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_object( $this->setting ) ) {
+ if ( $this->setting->default ) {
+ // Fake an attachment model - needs all fields used by template.
+ $type = in_array( substr( $this->setting->default, -3 ), array( 'jpg', 'png', 'gif', 'bmp' ) ) ? 'image' : 'document';
+ $default_attachment = array(
+ 'id' => 1,
+ 'url' => $this->setting->default,
+ 'type' => $type,
+ 'sizes' => array(
+ 'full' => array( 'url' => $this->setting->default ),
+ ),
+ 'icon' => wp_mime_type_icon( $type ),
+ 'title' => basename( $this->setting->default ),
+ );
+ $this->json['defaultAttachment'] = $default_attachment;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $this->context )
- $this->json['context'] = $this->context;
-
- if ( $this->extensions )
- $this->json['extensions'] = implode( ',', $this->extensions );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Get the attachment model for the existing file.
+ if ( $this->value() ) {
+ $attachment_id = attachment_url_to_postid( $this->value() );
+ if ( $attachment_id ) {
+ $this->json['attachment'] = wp_prepare_attachment_for_js( $attachment_id);
+ }
+ } else if ( $this->setting->default ) {
+ // Set the default as the attachment.
+ $this->json['attachment'] = $default_attachment;
+ }
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Render the control's content.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Don't render any content for this control from PHP.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @see WP_Customize_Upload_Control::content_template()
</ins><span class="cx" style="display: block; padding: 0 10px"> * @since 3.4.0
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function render_content() {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function render_content() {}
+
+ /**
+ * Render a JS template for the content of the upload control.
+ *
+ * @since 4.1.0
+ */
+ public function content_template() {
</ins><span class="cx" style="display: block; padding: 0 10px"> ?>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <label>
- <?php if ( ! empty( $this->label ) ) : ?>
- <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
- <?php endif;
- if ( ! empty( $this->description ) ) : ?>
- <span class="description customize-control-description"><?php echo $this->description; ?></span>
- <?php endif; ?>
- <div>
- <a href="#" class="button-secondary upload"><?php _e( 'Upload' ); ?></a>
- <a href="#" class="remove"><?php _e( 'Remove' ); ?></a>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <label for="{{ data.settings.default }}-button">
+ <# if ( data.label ) { #>
+ <span class="customize-control-title">{{ data.label }}</span>
+ <# } #>
+ <# if ( data.description ) { #>
+ <span class="description customize-control-description">{{ data.description }}</span>
+ <# } #>
+ </label>
+
+ <# // Ensure that the default attachment is used if it exists.
+ if ( _.isEmpty( data.attachment ) && data.defaultAttachment ) {
+ data.attachment = data.defaultAttachment;
+ }
+
+ if ( data.attachment && data.attachment.id ) { #>
+ <div class="attachment-media-view {{ data.attachment.orientation }}">
+ <div class="thumbnail thumbnail-{{ data.attachment.type }}">
+ <# if ( 'image' === data.attachment.type && data.attachment.sizes && data.attachment.sizes.medium ) { #>
+ <img class="attachment-thumb" src="{{ data.attachment.sizes.medium.url }}" draggable="false" />
+ <# } else if ( 'image' === data.attachment.type && data.attachment.sizes && data.attachment.sizes.full ) { #>
+ <img class="attachment-thumb" src="{{ data.attachment.sizes.full.url }}" draggable="false" />
+ <# } else if ( -1 === jQuery.inArray( data.attachment.type, [ 'audio', 'video' ] ) ) { #>
+ <img class="attachment-thumb type-icon" src="{{ data.attachment.icon }}" class="icon" draggable="false" />
+ <p class="attachment-title">{{ data.attachment.title }}</p>
+ <# } #>
+
+ <# if ( 'audio' === data.attachment.type ) { #>
+ <div class="wp-media-wrapper">
+ <p class="attachment-title">{{ data.attachment.title }}</p>
+ <audio style="visibility: hidden" controls class="wp-audio-shortcode" width="100%" preload="none">
+ <source type="{{ data.attachment.mime }}" src="{{ data.attachment.url }}"/>
+ </audio>
+ </div>
+ <# } else if ( 'video' === data.attachment.type ) {
+ var w_rule = h_rule = '';
+ if ( data.attachment.width ) {
+ w_rule = 'width: ' + data.attachment.width + 'px;';
+ } else if ( wp.media.view.settings.contentWidth ) {
+ w_rule = 'width: ' + wp.media.view.settings.contentWidth + 'px;';
+ }
+ if ( data.attachment.height ) {
+ h_rule = 'height: ' + data.attachment.height + 'px;';
+ }
+ #>
+ <div style="{{ w_rule }}{{ h_rule }}" class="wp-media-wrapper wp-video">
+ <video controls="controls" class="wp-video-shortcode" preload="metadata"
+ <# if ( data.attachment.width ) { #>width="{{ data.attachment.width }}"<# } #>
+ <# if ( data.attachment.height ) { #>height="{{ data.attachment.height }}"<# } #>
+ <# if ( data.attachment.image && data.attachment.image.src !== data.attachment.icon ) { #>poster="{{ data.attachment.image.src }}"<# } #>>
+ <source type="{{ data.attachment.mime }}" src="{{ data.attachment.url }}"/>
+ </video>
+ </div>
+ <# } #>
+ </div>
</ins><span class="cx" style="display: block; padding: 0 10px"> </div>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- </label>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <a class="button upload-button" id="{{ data.settings.default }}-button" href="#"><?php echo $this->button_labels['change']; ?></a>
+ <# if ( data.defaultAttachment && data.defaultAttachment.id !== data.attachment.id ) { #>
+ <a class="default-button remove-button" href="#"><?php echo $this->button_labels['default']; ?></a>
+ <# } else { #>
+ <a class="remove-button" href="#"><?php echo $this->button_labels['remove']; ?></a>
+ <# } #>
+ <# } else { #>
+ <p class="placeholder-text"><?php echo $this->button_labels['placeholder']; ?></p>
+ <a class="button upload-button" id="{{ data.settings.default }}-button" href="#"><?php echo $this->button_labels['select']; ?></a>
+ <# if ( ! data.defaultAttachment ) { #>
+ <a class="default-button remove-button" href="#"><?php echo $this->button_labels['default']; ?></a>
+ <# } #>
+ <# } #>
</ins><span class="cx" style="display: block; padding: 0 10px"> <?php
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -701,12 +812,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> class WP_Customize_Image_Control extends WP_Customize_Upload_Control {
</span><span class="cx" style="display: block; padding: 0 10px"> public $type = 'image';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public $get_url;
- public $statuses;
- public $extensions = array( 'jpg', 'jpeg', 'gif', 'png' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public $mime_type = 'image';
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- protected $tabs = array();
-
</del><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Constructor.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -714,168 +821,53 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @uses WP_Customize_Upload_Control::__construct()
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param WP_Customize_Manager $manager
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $id
- * @param array $args
</del><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function __construct( $manager, $id, $args ) {
- $this->statuses = array( '' => __('No Image') );
-
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function __construct( $manager, $id, $args = array() ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> parent::__construct( $manager, $id, $args );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->add_tab( 'upload-new', __('Upload New'), array( $this, 'tab_upload_new' ) );
- $this->add_tab( 'uploaded', __('Uploaded'), array( $this, 'tab_uploaded' ) );
-
- // Early priority to occur before $this->manager->prepare_controls();
- add_action( 'customize_controls_init', array( $this, 'prepare_control' ), 5 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->button_labels = array(
+ 'select' => __( 'Select Image' ),
+ 'change' => __( 'Change Image' ),
+ 'remove' => __( 'Remove' ),
+ 'default' => __( 'Default' ),
+ 'placeholder' => __( 'No image selected' ),
+ 'frame_title' => __( 'Select Image' ),
+ 'frame_button' => __( 'Choose Image' ),
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Prepares the control.
- *
- * If no tabs exist, removes the control from the manager.
- *
</del><span class="cx" style="display: block; padding: 0 10px"> * @since 3.4.2
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @deprecated 4.1.0
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function prepare_control() {
- if ( ! $this->tabs )
- $this->manager->remove_control( $this->id );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function prepare_control() {}
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Refresh the parameters passed to the JavaScript via JSON.
- *
</del><span class="cx" style="display: block; padding: 0 10px"> * @since 3.4.0
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @uses WP_Customize_Upload_Control::to_json()
- */
- public function to_json() {
- parent::to_json();
- $this->json['statuses'] = $this->statuses;
- }
-
- /**
- * Render the control's content.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @deprecated 4.1.0
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @since 3.4.0
- */
- public function render_content() {
- $src = $this->value();
- if ( isset( $this->get_url ) )
- $src = call_user_func( $this->get_url, $src );
-
- ?>
- <div class="customize-image-picker">
- <?php if ( ! empty( $this->label ) ) : ?>
- <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
- <?php endif;
- if ( ! empty( $this->description ) ) : ?>
- <span class="description customize-control-description"><?php echo $this->description; ?></span>
- <?php endif; ?>
-
- <div class="customize-control-content">
- <div class="dropdown preview-thumbnail" tabindex="0">
- <div class="dropdown-content">
- <?php if ( empty( $src ) ): ?>
- <img style="display:none;" />
- <?php else: ?>
- <img src="<?php echo esc_url( set_url_scheme( $src ) ); ?>" />
- <?php endif; ?>
- <div class="dropdown-status"></div>
- </div>
- <div class="dropdown-arrow"></div>
- </div>
- </div>
-
- <div class="library">
- <ul>
- <?php foreach ( $this->tabs as $id => $tab ): ?>
- <li data-customize-tab='<?php echo esc_attr( $id ); ?>' tabindex='0'>
- <?php echo esc_html( $tab['label'] ); ?>
- </li>
- <?php endforeach; ?>
- </ul>
- <?php foreach ( $this->tabs as $id => $tab ): ?>
- <div class="library-content" data-customize-tab='<?php echo esc_attr( $id ); ?>'>
- <?php call_user_func( $tab['callback'] ); ?>
- </div>
- <?php endforeach; ?>
- </div>
-
- <div class="actions">
- <a href="#" class="remove"><?php _e( 'Remove Image' ); ?></a>
- </div>
- </div>
- <?php
- }
-
- /**
- * Add a tab to the control.
- *
- * @since 3.4.0
- *
</del><span class="cx" style="display: block; padding: 0 10px"> * @param string $id
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $label
</span><span class="cx" style="display: block; padding: 0 10px"> * @param mixed $callback
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function add_tab( $id, $label, $callback ) {
- $this->tabs[ $id ] = array(
- 'label' => $label,
- 'callback' => $callback,
- );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function add_tab( $id, $label, $callback ) {}
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Remove a tab from the control.
- *
</del><span class="cx" style="display: block; padding: 0 10px"> * @since 3.4.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @deprecated 4.1.0
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $id
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function remove_tab( $id ) {
- unset( $this->tabs[ $id ] );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function remove_tab( $id ) {}
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.4.0
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- */
- public function tab_upload_new() {
- if ( ! _device_can_upload() ) {
- echo '<p>' . sprintf( __('The web browser on your device cannot be used to upload files. You may be able to use the <a href="%s">native app for your device</a> instead.'), 'https://apps.wordpress.org/' ) . '</p>';
- } else {
- ?>
- <div class="upload-dropzone">
- <?php _e('Drop a file here or <a href="#" class="upload">select a file</a>.'); ?>
- </div>
- <div class="upload-fallback">
- <span class="button-secondary"><?php _e('Select File'); ?></span>
- </div>
- <?php
- }
- }
-
- /**
- * @since 3.4.0
- */
- public function tab_uploaded() {
- ?>
- <div class="uploaded-target"></div>
- <?php
- }
-
- /**
- * @since 3.4.0
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @deprecated 4.1.0
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $url
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $thumbnail_url
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- public function print_tab_image( $url, $thumbnail_url = null ) {
- $url = set_url_scheme( $url );
- $thumbnail_url = ( $thumbnail_url ) ? set_url_scheme( $thumbnail_url ) : $url;
- ?>
- <a href="#" class="thumbnail" data-customize-image-value="<?php echo esc_url( $url ); ?>">
- <img src="<?php echo esc_url( $thumbnail_url ); ?>" />
- </a>
- <?php
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function print_tab_image( $url, $thumbnail_url = null ) {}
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -899,42 +891,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> parent::__construct( $manager, 'background_image', array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'label' => __( 'Background Image' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'section' => 'background_image',
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'context' => 'custom-background',
- 'get_url' => 'get_background_image',
</del><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- if ( $this->setting->default )
- $this->add_tab( 'default', __('Default'), array( $this, 'tab_default_background' ) );
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
- /**
- * @since 3.4.0
- */
- public function tab_uploaded() {
- $backgrounds = get_posts( array(
- 'post_type' => 'attachment',
- 'meta_key' => '_wp_attachment_is_custom_background',
- 'meta_value' => $this->manager->get_stylesheet(),
- 'orderby' => 'none',
- 'nopaging' => true,
- ) );
-
- ?><div class="uploaded-target"></div><?php
-
- if ( empty( $backgrounds ) )
- return;
-
- foreach ( (array) $backgrounds as $background )
- $this->print_tab_image( esc_url_raw( $background->guid ) );
- }
-
- /**
- * @since 3.4.0
- * @uses WP_Customize_Image_Control::print_tab_image()
- */
- public function tab_default_background() {
- $this->print_tab_image( $this->setting->default );
- }
</del><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpcustomizemanagerphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-customize-manager.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-customize-manager.php 2014-11-11 22:45:47 UTC (rev 30308)
+++ trunk/src/wp-includes/class-wp-customize-manager.php 2014-11-11 23:51:48 UTC (rev 30309)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -965,6 +965,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /* Control Types (custom control classes) */
</span><span class="cx" style="display: block; padding: 0 10px"> $this->register_control_type( 'WP_Customize_Color_Control' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->register_control_type( 'WP_Customize_Upload_Control' );
+ $this->register_control_type( 'WP_Customize_Image_Control' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /* Site Title & Tagline */
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre>
</div>
</div>
</body>
</html>