<!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>[38906] trunk: Customize: Allow page stubs to be created via `dropdown-pages` controls in the Static Front Page section.</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/38906">38906</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/38906","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>westonruter</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-10-25 06:30:27 +0000 (Tue, 25 Oct 2016)</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'>Customize: Allow page stubs to be created via `dropdown-pages` controls in the Static Front Page section.
This ability was previously added to nav menus via the available page items panel. The "Add New Page" button only appears when the `allow_addition` control param is supplied as `true`. Code is adapted from the Customize Posts feature plugin.
Props celloexpressions, westonruter.
See <a href="https://core.trac.wordpress.org/ticket/38013">#38013</a>, <a href="https://core.trac.wordpress.org/ticket/34923">#34923</a>.
Fixes <a href="https://core.trac.wordpress.org/ticket/38164">#38164</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadmincsscustomizecontrolscss">trunk/src/wp-admin/css/customize-controls.css</a></li>
<li><a href="#trunksrcwpadmincsscustomizenavmenuscss">trunk/src/wp-admin/css/customize-nav-menus.css</a></li>
<li><a href="#trunksrcwpadminjscustomizecontrolsjs">trunk/src/wp-admin/js/customize-controls.js</a></li>
<li><a href="#trunksrcwpadminjscustomizenavmenusjs">trunk/src/wp-admin/js/customize-nav-menus.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>
<li><a href="#trunksrcwpincludesclasswpcustomizenavmenusphp">trunk/src/wp-includes/class-wp-customize-nav-menus.php</a></li>
<li><a href="#trunktestsphpunittestscustomizecontrolphp">trunk/tests/phpunit/tests/customize/control.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 2016-10-25 06:01:03 UTC (rev 38905)
+++ trunk/src/wp-admin/css/customize-controls.css 2016-10-25 06:30:27 UTC (rev 38906)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -565,8 +565,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"> .customize-control select {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- min-width: 50%;
- max-width: 100%;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ width: 100%;
+ max-width: 300px;
</ins><span class="cx" style="display: block; padding: 0 10px"> height: 28px;
</span><span class="cx" style="display: block; padding: 0 10px"> line-height: 28px;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -587,6 +587,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> display: block;
</span><span class="cx" style="display: block; padding: 0 10px"> font-style: italic;
</span><span class="cx" style="display: block; padding: 0 10px"> line-height: 18px;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ margin-top: 0;
</ins><span class="cx" style="display: block; padding: 0 10px"> margin-bottom: 5px;
</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">@@ -674,6 +675,54 @@
</span><span class="cx" style="display: block; padding: 0 10px"> float: left;
</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">+#available-menu-items .accordion-section-content .new-content-item,
+.customize-control-dropdown-pages .new-content-item {
+ width: -webkit-calc(100% - 30px);
+ width: calc(100% - 30px);
+ padding: 8px 15px;
+ position: absolute;
+ bottom: 0;
+ z-index: 10;
+ background: #eee;
+ display: -webkit-box;
+ display: -moz-box;
+ display: -ms-flexbox;
+ display: -webkit-flex;
+ display: flex;
+}
+
+.customize-control-dropdown-pages .new-content-item {
+ width: 100%;
+ max-width: 300px;
+ padding: 5px 0 5px 1px;
+ position: relative;
+}
+
+#available-menu-items .new-content-item .create-item-input,
+.customize-control-dropdown-pages .new-content-item .create-item-input {
+ -webkit-box-flex: 10;
+ -webkit-flex-grow: 10;
+ -moz-box-flex: 10;
+ -ms-flex-positive: 10;
+ -ms-flex: 10;
+ flex-grow: 10;
+}
+
+#available-menu-items .new-content-item .add-content,
+.customize-control-dropdown-pages .new-content-item .add-content {
+ margin: 2px 0 2px 6px;
+ -webkit-box-flex: 10;
+ -webkit-flex-grow: 10;
+ -moz-box-flex: 10;
+ -ms-flex-positive: 10;
+ -ms-flex: 10;
+ flex-grow: 1;
+}
+
+.customize-control-dropdown-pages .new-content-item .create-item-input.invalid {
+ border: 1px solid #f00;
+}
+
</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="trunksrcwpadmincsscustomizenavmenuscss"></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-nav-menus.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/css/customize-nav-menus.css 2016-10-25 06:01:03 UTC (rev 38905)
+++ trunk/src/wp-admin/css/customize-nav-menus.css 2016-10-25 06:30:27 UTC (rev 38906)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -572,41 +572,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> padding: 0 15px 15px 15px;
</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">-#available-menu-items .accordion-section-content .new-content-item {
- width: -webkit-calc(100% - 30px);
- width: calc(100% - 30px);
- padding: 8px 15px;
- position: absolute;
- bottom: 0;
- z-index: 10;
- background: #eee;
- display: -webkit-box;
- display: -moz-box;
- display: -ms-flexbox;
- display: -webkit-flex;
- display: flex;
-}
-
-#available-menu-items .new-content-item .create-item-input {
- -webkit-box-flex: 10;
- -webkit-flex-grow: 10;
- -moz-box-flex: 10;
- -ms-flex-positive: 10;
- -ms-flex: 10;
- flex-grow: 10;
- margin-left: 5px;
- padding: 4.5px;
-}
-#available-menu-items .new-content-item .add-content {
- padding-left: 6px;
- -webkit-box-flex: 10;
- -webkit-flex-grow: 10;
- -moz-box-flex: 10;
- -ms-flex-positive: 10;
- -ms-flex: 10;
- flex-grow: 1;
-}
-
</del><span class="cx" style="display: block; padding: 0 10px"> #available-menu-items .menu-item-tpl {
</span><span class="cx" style="display: block; padding: 0 10px"> margin: 0;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</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 2016-10-25 06:01:03 UTC (rev 38905)
+++ trunk/src/wp-admin/js/customize-controls.js 2016-10-25 06:30:27 UTC (rev 38906)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2516,9 +2516,28 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Triggered when the control's markup has been injected into the DOM.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @abstract
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @returns {void}
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</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">+ ready: function() {
+ var control = this, newItem;
+ if ( 'dropdown-pages' === control.params.type && control.params.allow_addition ) {
+ newItem = control.container.find( '.new-content-item' );
+ newItem.hide(); // Hide in JS to preserve flex display when showing.
+ control.container.on( 'click', '.add-new-toggle', function( e ) {
+ $( e.currentTarget ).slideUp( 180 );
+ newItem.slideDown( 180 );
+ newItem.find( '.create-item-input' ).focus();
+ });
+ control.container.on( 'click', '.add-content', function() {
+ control.addNewPage();
+ });
+ control.container.on( 'keyup', '.create-item-input', function( e ) {
+ if ( 13 === e.which ) { // Enter
+ control.addNewPage();
+ }
+ });
+ }
+ },
</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"> * Get the element inside of a control's container that contains the validation error message.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2736,6 +2755,73 @@
</span><span class="cx" style="display: block; padding: 0 10px"> control.container.html( template( control.params ) );
</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">+ },
+
+ /**
+ * Add a new page to a dropdown-pages control reusing menus code for this.
+ *
+ * @since 4.7.0
+ * @access private
+ * @returns {void}
+ */
+ addNewPage: function () {
+ var control = this, promise, toggle, container, input, title, select;
+
+ if ( 'dropdown-pages' !== control.params.type || ! control.params.allow_addition || ! api.Menus ) {
+ return;
+ }
+
+ toggle = control.container.find( '.add-new-toggle' );
+ container = control.container.find( '.new-content-item' );
+ input = control.container.find( '.create-item-input' );
+ title = input.val();
+ select = control.container.find( 'select' );
+
+ if ( ! title ) {
+ input.addClass( 'invalid' );
+ return;
+ }
+
+ input.removeClass( 'invalid' );
+ input.attr( 'disabled', 'disabled' );
+
+ // The menus functions add the page, publish when appropriate, and also add the new page to the dropdown-pages controls.
+ promise = api.Menus.insertAutoDraftPost( {
+ post_title: title,
+ post_type: 'page'
+ } );
+ promise.done( function( data ) {
+ var availableItem, $content, itemTemplate;
+
+ // Prepare the new page as an available menu item.
+ // See api.Menus.submitNew().
+ availableItem = new api.Menus.AvailableItemModel( {
+ 'id': 'post-' + data.post_id, // Used for available menu item Backbone models.
+ 'title': title,
+ 'type': 'page',
+ 'type_label': api.Menus.data.l10n.page_label,
+ 'object': 'post_type',
+ 'object_id': data.post_id,
+ 'url': data.url
+ } );
+
+ // Add the new item to the list of available menu items.
+ api.Menus.availableMenuItemsPanel.collection.add( availableItem );
+ $content = $( '#available-menu-items-post_type-page' ).find( '.available-menu-items-list' );
+ itemTemplate = wp.template( 'available-menu-item' );
+ $content.prepend( itemTemplate( availableItem.attributes ) );
+
+ // Focus the select control.
+ select.focus();
+ control.setting.set( String( data.post_id ) ); // Triggers a preview refresh and updates the setting.
+
+ // Reset the create page form.
+ container.slideUp( 180 );
+ toggle.slideDown( 180 );
+ } )
+ .always( function() {
+ input.val( '' ).removeAttr( 'disabled' );
+ } );
</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></pre></div>
<a id="trunksrcwpadminjscustomizenavmenusjs"></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-nav-menus.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/js/customize-nav-menus.js 2016-10-25 06:01:03 UTC (rev 38905)
+++ trunk/src/wp-admin/js/customize-nav-menus.js 2016-10-25 06:30:27 UTC (rev 38906)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -101,7 +101,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> request.done( function( response ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( response.post_id ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- deferred.resolve( response );
</del><span class="cx" style="display: block; padding: 0 10px"> api.Menus.insertedAutoDrafts.push( response.post_id );
</span><span class="cx" style="display: block; padding: 0 10px"> api( 'nav_menus_created_posts' ).set( _.clone( api.Menus.insertedAutoDrafts ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -121,6 +120,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><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ deferred.resolve( response );
</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></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 2016-10-25 06:01:03 UTC (rev 38905)
+++ trunk/src/wp-includes/class-wp-customize-control.php 2016-10-25 06:30:27 UTC (rev 38906)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -115,6 +115,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public $input_attrs = array();
</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">+ * Show UI for adding new content, currently only used for the dropdown-pages control.
+ *
+ * @since 4.7.0
+ * @access public
+ * @var array
+ */
+ public $allow_addition = false;
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * @deprecated It is better to just call the json() method
</span><span class="cx" style="display: block; padding: 0 10px"> * @access public
</span><span class="cx" style="display: block; padding: 0 10px"> * @var array
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -296,6 +305,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->json['label'] = $this->label;
</span><span class="cx" style="display: block; padding: 0 10px"> $this->json['description'] = $this->description;
</span><span class="cx" style="display: block; padding: 0 10px"> $this->json['instanceNumber'] = $this->instance_number;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ if ( 'dropdown-pages' === $this->type ) {
+ $this->json['allow_addition'] = $this->allow_addition;
+ }
</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">@@ -554,10 +567,34 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Hackily add in the data link parameter.
</span><span class="cx" style="display: block; padding: 0 10px"> $dropdown = str_replace( '<select', '<select ' . $this->get_link(), $dropdown );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ // Even more hacikly add auto-draft page stubs.
+ // @todo Eventually this should be removed in favor of the pages being injected into the underlying get_pages() call. See <https://github.com/xwp/wp-customize-posts/pull/250>.
+ $nav_menus_created_posts_setting = $this->manager->get_setting( 'nav_menus_created_posts' );
+ if ( $nav_menus_created_posts_setting && current_user_can( 'publish_pages' ) ) {
+ $auto_draft_page_options = '';
+ foreach ( $nav_menus_created_posts_setting->value() as $auto_draft_page_id ) {
+ $post = get_post( $auto_draft_page_id );
+ if ( $post && 'page' === $post->post_type ) {
+ $auto_draft_page_options .= sprintf( '<option value="%1$s">%2$s</option>', esc_attr( $post->ID ), esc_html( $post->post_title ) );
+ }
+ }
+ if ( $auto_draft_page_options ) {
+ $dropdown = str_replace( '</select>', $auto_draft_page_options . '</select>', $dropdown );
+ }
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> echo $dropdown;
</span><span class="cx" style="display: block; padding: 0 10px"> ?>
</span><span class="cx" style="display: block; padding: 0 10px"> </label>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- <?php
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <?php if ( $this->allow_addition && current_user_can( 'publish_pages' ) && current_user_can( 'edit_theme_options' ) ) : // Currently tied to menus functionality. ?>
+ <button type="button" class="button add-new-toggle"><?php echo get_post_type_object( 'page' )->labels->add_new_item; ?></button>
+ <div class="new-content-item">
+ <label for="create-input-<?php echo $this->id; ?>"><span class="screen-reader-text"><?php _e( 'New page title' ); ?></span></label>
+ <input type="text" id="create-input-<?php echo $this->id; ?>" class="create-item-input" placeholder="<?php esc_attr_e( 'New page title…' ); ?>">
+ <button type="button" class="button add-content"><?php _e( 'Add' ); ?></button>
+ </div>
+ <?php endif;
</ins><span class="cx" style="display: block; padding: 0 10px"> break;
</span><span class="cx" style="display: block; padding: 0 10px"> default:
</span><span class="cx" style="display: block; padding: 0 10px"> ?>
</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 2016-10-25 06:01:03 UTC (rev 38905)
+++ trunk/src/wp-includes/class-wp-customize-manager.php 2016-10-25 06:30:27 UTC (rev 38906)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3356,6 +3356,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'label' => __( 'Front page' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'section' => 'static_front_page',
</span><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'dropdown-pages',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'allow_addition' => true,
</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"> $this->add_setting( 'page_for_posts', array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3367,6 +3368,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'label' => __( 'Posts page' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'section' => 'static_front_page',
</span><span class="cx" style="display: block; padding: 0 10px"> 'type' => 'dropdown-pages',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'allow_addition' => true,
</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"> /* Custom CSS */
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpcustomizenavmenusphp"></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-nav-menus.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-customize-nav-menus.php 2016-10-25 06:01:03 UTC (rev 38905)
+++ trunk/src/wp-includes/class-wp-customize-nav-menus.php 2016-10-25 06:30:27 UTC (rev 38906)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -370,6 +370,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'untitled' => _x( '(no label)', 'missing menu item navigation label' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'unnamed' => _x( '(unnamed)', 'Missing menu name.' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'custom_label' => __( 'Custom Link' ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'page_label' => get_post_type_object( 'page' )->labels->singular_name,
</ins><span class="cx" style="display: block; padding: 0 10px"> /* translators: %s: menu location */
</span><span class="cx" style="display: block; padding: 0 10px"> 'menuLocation' => _x( '(Currently set to: %s)', 'menu' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'menuNameLabel' => __( 'Menu Name' ),
</span></span></pre></div>
<a id="trunktestsphpunittestscustomizecontrolphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/customize/control.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/customize/control.php 2016-10-25 06:01:03 UTC (rev 38905)
+++ trunk/tests/phpunit/tests/customize/control.php 2016-10-25 06:30:27 UTC (rev 38906)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -26,6 +26,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function setUp() {
</span><span class="cx" style="display: block; padding: 0 10px"> parent::setUp();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_set_current_user( $this->factory()->user->create( array( 'role' => 'administrator' ) ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> require_once( ABSPATH . WPINC . '/class-wp-customize-manager.php' );
</span><span class="cx" style="display: block; padding: 0 10px"> // @codingStandardsIgnoreStart
</span><span class="cx" style="display: block; padding: 0 10px"> $GLOBALS['wp_customize'] = new WP_Customize_Manager();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -39,7 +40,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @see WP_Customize_Control::check_capabilities()
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function test_check_capabilities() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
</del><span class="cx" style="display: block; padding: 0 10px"> do_action( 'customize_register', $this->wp_customize );
</span><span class="cx" style="display: block; padding: 0 10px"> $control = new WP_Customize_Control( $this->wp_customize, 'blogname', array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'settings' => array( 'blogname' ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -78,6 +78,67 @@
</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">+ * @ticket 38164
+ */
+ function test_dropdown_pages() {
+ do_action( 'customize_register', $this->wp_customize );
+
+ $this->assertInstanceOf( 'WP_Customize_Nav_Menus', $this->wp_customize->nav_menus );
+ $nav_menus_created_posts_setting = $this->wp_customize->get_setting( 'nav_menus_created_posts' );
+ $this->assertInstanceOf( 'WP_Customize_Filter_Setting', $nav_menus_created_posts_setting );
+ $page_on_front_control = $this->wp_customize->get_control( 'page_on_front' );
+
+ // Ensure the add-new-toggle is absent if allow_addition param is not set.
+ $page_on_front_control->allow_addition = false;
+ ob_start();
+ $page_on_front_control->maybe_render();
+ $content = ob_get_clean();
+ $this->assertNotContains( 'add-new-toggle', $content );
+
+ // Ensure the add-new-toggle is absent if allow_addition param is set.
+ $page_on_front_control->allow_addition = true;
+ ob_start();
+ $page_on_front_control->maybe_render();
+ $content = ob_get_clean();
+ $this->assertContains( 'add-new-toggle', $content );
+
+ // Ensure that dropdown-pages delect is rendered even if there are no pages published (yet).
+ foreach ( get_pages() as $page ) {
+ wp_delete_post( $page->ID );
+ }
+ $page_on_front_control->allow_addition = true;
+ ob_start();
+ $page_on_front_control->maybe_render();
+ $content = ob_get_clean();
+ $this->assertContains( '<option value="0">', $content, 'Dropdown-pages renders select even without any pages published.' );
+
+ // Ensure that auto-draft pages are included if they are among the nav_menus_created_posts.
+ $auto_draft_page_id = $this->factory()->post->create( array(
+ 'post_type' => 'page',
+ 'post_status' => 'auto-draft',
+ 'post_title' => 'Auto Draft Page',
+ ) );
+ $this->factory()->post->create( array(
+ 'post_type' => 'page',
+ 'post_status' => 'auto-draft',
+ 'post_title' => 'Orphan Auto Draft Page',
+ ) );
+ $auto_draft_post_id = $this->factory()->post->create( array(
+ 'post_type' => 'post',
+ 'post_status' => 'auto-draft',
+ 'post_title' => 'Auto Draft Post',
+ ) );
+ $this->wp_customize->set_post_value( $nav_menus_created_posts_setting->id, array( $auto_draft_page_id, $auto_draft_post_id ) );
+ $nav_menus_created_posts_setting->preview();
+ ob_start();
+ $page_on_front_control->maybe_render();
+ $content = ob_get_clean();
+ $this->assertContains( sprintf( '<option value="%d">Auto Draft Page</option>', $auto_draft_page_id ), $content );
+ $this->assertNotContains( 'Auto Draft Post', $content );
+ $this->assertNotContains( 'Orphan Auto Draft Page', $content );
+ }
+
+ /**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Tear down.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function tearDown() {
</span></span></pre>
</div>
</div>
</body>
</html>