Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
fec7f9b
Introduce WP_Customize_Postmeta_Setting
westonruter Mar 2, 2016
10b269a
Update wp-plugin-dev-lib 12991a3...05bc18b: Merge pull request xwp/wp…
westonruter Apr 10, 2016
bc6b45b
Move test-customize-posts.php into php dir
westonruter Apr 10, 2016
da06d92
Fix test for WP_Customize_Posts::__construct
westonruter Apr 10, 2016
2f7a2ac
Rename test-class-wp-customize-posts.php
westonruter Apr 10, 2016
080e0dc
Add test for WP_Customize_Posts::sanitize_post_id()
westonruter Apr 10, 2016
d8e171f
Instantiate test WP_Customize_Manager after user logged-in
westonruter Apr 10, 2016
24002c7
Check if get_current_screen() returns object before accessing property
westonruter Apr 10, 2016
88ff1df
Ensure builtin post meta get registered and add plugin hook to regist…
westonruter Apr 10, 2016
e9085a9
Fix PHP 5.2 compat and phpcs issues
westonruter Apr 11, 2016
cc64c0d
Add select type for dynamic control
westonruter Apr 12, 2016
95fa80a
Add post_author control with full refresh
valendesigns Apr 12, 2016
1a33e94
Add page template controller
westonruter Apr 12, 2016
2eec305
Remove erroneous sanitize_callback default
westonruter Apr 12, 2016
6d4a5f5
Remove obsolete WP_Customize_Page_Template_Postmeta_Setting
westonruter Apr 12, 2016
a477814
Add default template name label
westonruter Apr 12, 2016
bf375db
Export page template choices as array of objects
westonruter Apr 12, 2016
dd29a84
Link page template control to setting
westonruter Apr 12, 2016
dc92c65
Account for default being among choices
westonruter Apr 12, 2016
815314b
Introduce WP_Customize_Postmeta_Controller
westonruter Apr 12, 2016
06cb8ee
Merge feature/postmeta
valendesigns Apr 12, 2016
aa40849
Remove sanitize_value_callback and requirement for sanitize_meta() fi…
westonruter Apr 13, 2016
84cc064
Apply customize_sanitize filters in postmeta sanitize method
westonruter Apr 13, 2016
fae1e94
Add partial placement
valendesigns Apr 13, 2016
6637a25
Update dev-lib
valendesigns Apr 13, 2016
9311fbc
Let postmeta control ID match the setting ID
westonruter Apr 13, 2016
0d2595d
Fix check for choices length
westonruter Apr 13, 2016
a80d9ec
Fix linking root-level settings in dynamic controls
westonruter Apr 13, 2016
4e45cfc
Add default value for settings
westonruter Apr 13, 2016
e44ac20
Define postmeta settings and pass to controls
westonruter Apr 13, 2016
7763779
Add handlePostMetaSettings stub and get postmeta settings for infinit…
westonruter Apr 13, 2016
39a78b7
Consolidate handling of post and postmeta setting message passing
westonruter Apr 13, 2016
d27ec28
Improve function names
westonruter Apr 13, 2016
cd4bcaf
Remove unnecessary esc_html
westonruter Apr 13, 2016
898abe6
Merge branch 'feature/post_author' of https://github.com/xwp/wp-custo…
westonruter Apr 13, 2016
837fb49
Use elseif and check for WP_Customize_Post_Field_Partial instance
westonruter Apr 13, 2016
34ae101
Use this consistently
westonruter Apr 13, 2016
8709312
Revert esc_html
valendesigns Apr 13, 2016
cd28a73
Merge develop & fix conflicts
valendesigns Apr 13, 2016
5f94f4b
Remove thumbnail from being hard-coded in posts
westonruter Apr 13, 2016
b9787de
Merge branch 'feature/postmeta' of https://github.com/xwp/wp-customiz…
westonruter Apr 13, 2016
a0b6645
Ensure page template control is not displayed if no page templates
westonruter Apr 14, 2016
dd4f7f7
Improve docblock for WP_Customize_Page_Template_Controller
westonruter Apr 14, 2016
bfa277d
Introduce WP_Customize_Page_Template_Controller::get_page_template_ch…
westonruter Apr 14, 2016
3703072
Fix 404 pages
valendesigns Apr 14, 2016
2cb9415
Add missing public tag
westonruter Apr 14, 2016
03b0250
Test that customize-page-template is registered
westonruter Apr 14, 2016
65daf80
Use setting default when empty string returned form get_post_meta
westonruter Apr 14, 2016
70cf628
Refactor postmeta controller to handle syncing of setting from custom…
westonruter Apr 14, 2016
02693ec
Improve docblock for WP_Customize_Postmeta_Setting
valendesigns Apr 14, 2016
c92f6e4
Reduce args passed to auth_post_meta_callback; add access tags
westonruter Apr 14, 2016
e97495d
Finish test coverage for WP_Customize_Postmeta_Setting constructor
westonruter Apr 14, 2016
9425b58
Add incomplete tests & fix dockblocks
valendesigns Apr 15, 2016
7dbf83c
Fix docblock & remove whitespace
valendesigns Apr 15, 2016
9cc9fe8
Fix array_key_exists order of the parameters
mehigh Apr 16, 2016
abd1e0f
Remove skip for incomplete test; add coverage
westonruter Apr 16, 2016
562c068
Remove debug code and increase tests for WP_Customize_Posts_Preview
westonruter Apr 16, 2016
09077f7
Flesh out most of tests for Test_WP_Customize_Posts_Preview and impro…
westonruter Apr 17, 2016
ea2e0b8
Finish tests for WP_Customize_Posts_Preview
westonruter Apr 17, 2016
87bd48b
Flesh out tests for post field partial and post setting
westonruter Apr 17, 2016
e63fee4
Flesh out tests for postmeta controller and page template controller
westonruter Apr 17, 2016
f17aecb
Prevent invoking page preview logic when not in page preview
westonruter Apr 17, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev-lib
48 changes: 46 additions & 2 deletions js/customize-dynamic-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,50 @@
control.propertyElements = [];
},

_setUpSettingProperty: function() {
/**
* Add bidirectional data binding links between inputs and the setting(s).
*
* This is copied from wp.customize.Control.prototype.initialize(). It
* should be changed in Core to be applied once the control is embedded.
*
* @private
*/
_setUpSettingRootLinks: function() {
var control, nodes, radios;
control = this;
nodes = control.container.find( '[data-customize-setting-link]' );
radios = {};

nodes.each( function() {
var node = $( this ),
name;

if ( node.is( ':radio' ) ) {
name = node.prop( 'name' );
if ( radios[ name ] ) {
return;
}

radios[ name ] = true;
node = nodes.filter( '[name="' + name + '"]' );
}

api( node.data( 'customizeSettingLink' ), function( setting ) {
var element = new api.Element( node );
control.elements.push( element );
element.sync( setting );
element.set( setting() );
});
});

},

/**
* Add bidirectional data binding links between inputs and the setting properties.
*
* @private
*/
_setUpSettingPropertyLinks: function() {
var control = this, nodes, radios;
if ( ! control.params.setting_property || ! control.setting ) {
return;
Expand Down Expand Up @@ -82,7 +125,8 @@
ready: function() {
var control = this;

control._setUpSettingProperty();
control._setUpSettingRootLinks();
control._setUpSettingPropertyLinks();

api.Control.prototype.ready.call( control );

Expand Down
115 changes: 115 additions & 0 deletions js/customize-page-template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/* global module, EditPostPreviewCustomize, wp, _, _wpCustomizePageTemplateExports */
/* exported CustomizePageTemplate */

var CustomizePageTemplate = (function( api ) {
'use strict';

var component = {
data: {
l10n: {
controlLabel: ''
},
defaultPageTemplateChoices: {}
}
};

/**
* Init component.
*/
component.init = function() {
if ( 'undefined' !== typeof _wpCustomizePageTemplateExports ) {
_.extend( component.data, _wpCustomizePageTemplateExports );
}
component.extendSections();
};

/**
* Extend existing sections and future sections added with the page template control.
*/
component.extendSections = function() {
api.section.each( function( section ) {
component.addControl( section );
} );
api.section.bind( 'add', function( section ) {
component.addControl( section );
} );
};

/**
* Add the page template control to the given section.
*
* @param {wp.customize.Section} section
* @returns {wp.customize.Control|null} The control.
*/
component.addControl = function( section ) {
var supports, control, controlId, settingId, isActiveCallback;
if ( ! section.extended( api.Posts.PostSection ) ) {
return null;
}
supports = api.Posts.data.postTypes[ section.params.post_type ].supports;
if ( ! supports['page-attributes'] ) {
return null;
}

settingId = 'postmeta[' + section.params.post_type + '][' + String( section.params.post_id ) + '][_wp_page_template]';
controlId = settingId;

// If in page preview, send the updated page template to the post edit screen when it is changed.
if ( 'undefined' !== typeof EditPostPreviewCustomize ) {
api( settingId, function( setting ) {
setting.bind( function( pageTemplate ) {
var settings = {};
settings[ settingId ] = pageTemplate;
EditPostPreviewCustomize.sendSettingsToEditPostScreen( settings );
} );
} );
}

if ( api.control.has( controlId ) ) {
return api.control( controlId );
}

control = new api.controlConstructor.dynamic( controlId, {
params: {
section: section.id,
priority: 1,
label: component.data.l10n.controlLabel,
active: true,
settings: {
'default': settingId
},
field_type: 'select',
choices: component.data.defaultPageTemplateChoices,
input_attrs: {
'data-customize-setting-link': settingId
}
}
} );

/**
* Make sure that control only appears if there are page templates (other than 'default').
*
* @returns {boolean}
*/
isActiveCallback = function() {
var defaultSize = 1;
return _.size( control.params.choices ) > defaultSize;
};
control.active.set( isActiveCallback() );
control.active.validate = isActiveCallback;

// Register.
api.control.add( control.id, control );

// @todo Fetch the page templates related to control.params.post_id to override the default choices

return control;
};

if ( 'undefined' !== typeof module ) {
module.exports = component;
}

return component;

})( wp.customize );
9 changes: 8 additions & 1 deletion js/customize-post-field-partial.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @inheritdoc
*/
initialize: function( id, options ) {
var partial = this, args, matches, baseSelector, idPattern = /^post\[(.+?)]\[(-?\d+)]\[(.+?)]$/;
var partial = this, args, matches, baseSelector, idPattern = /^post\[(.+?)]\[(-?\d+)]\[(.+?)](?:\[(.+?)])?$/;

args = options || {};
args.params = args.params || {};
Expand All @@ -32,6 +32,7 @@
args.params.post_type = matches[1];
args.params.post_id = parseInt( matches[2], 10 );
args.params.field_id = matches[3];
args.params.placement = matches[4] || '';

if ( ! args.params.selector ) {
baseSelector = '.hentry.post-' + String( args.params.post_id ) + '.type-' + args.params.post_type;
Expand All @@ -41,6 +42,12 @@
args.params.selector = baseSelector + ' .entry-content';
} else if ( 'post_excerpt' === args.params.field_id ) {
args.params.selector = baseSelector + ' .entry-summary';
} else if ( 'post_author' === args.params.field_id ) {
if ( 'author-bio' === args.params.placement ) {
args.params.selector = baseSelector + ' .author-info';
} else if ( 'byline' === args.params.placement ) {
args.params.selector = baseSelector + ' .byline a.fn';
}
}
}
api.selectiveRefresh.Partial.prototype.initialize.call( partial, id, args );
Expand Down
42 changes: 42 additions & 0 deletions js/customize-post-section.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
if ( postTypeObj.supports.excerpt ) {
section.addExcerptControl();
}
if ( postTypeObj.supports.author ) {
section.addAuthorControl();
}
},

/**
Expand Down Expand Up @@ -336,6 +339,45 @@
return control;
},

/**
* Add post author control.
*
* @returns {wp.customize.Control}
*/
addAuthorControl: function() {
var section = this, control, setting = api( section.id );
control = new api.controlConstructor.dynamic( section.id + '[post_author]', {
params: {
section: section.id,
priority: 1,
label: api.Posts.data.l10n.fieldAuthorLabel,
active: true,
settings: {
'default': setting.id
},
field_type: 'select',
setting_property: 'post_author',
choices: api.Posts.data.authorChoices
}
} );

// Override preview trying to de-activate control not present in preview context.
control.active.validate = function() {
return true;
};

// Register.
section.postFieldControls.post_author = control;
api.control.add( control.id, control );

// Remove the setting from the settingValidationMessages since it is not specific to this field.
if ( control.settingValidationMessages ) {
control.settingValidationMessages.remove( setting.id );
control.settingValidationMessages.add( control.id, new api.Value( '' ) );
}
return control;
},

/**
* Set up setting validation.
*/
Expand Down
98 changes: 55 additions & 43 deletions js/customize-posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,56 +53,68 @@
*
* @param {object} data
*/
component.receiveCustomizedPosts = function( data ) {
_.each( data.postSettings, function( settingValue, settingId ) {
var section, sectionId, panelId, sectionType, postId, postType, idParts, Constructor, htmlParser;
idParts = settingId.replace( /]/g, '' ).split( '[' );
postType = idParts[1];
if ( ! component.data.postTypes[ postType ] ) {
if ( 'undefined' !== typeof console && console.error ) {
console.error( 'Unrecognized post type: ' + postType );
}
return;
}
postId = parseInt( idParts[2], 10 );
if ( ! postId ) {
if ( 'undefined' !== typeof console && console.error ) {
console.error( 'Bad post id: ' + idParts[2] );
}
return;
}
component.receivePreviewData = function( data ) {
_.each( data.settings, function( setting, id ) {

if ( ! api.has( settingId ) ) {
api.create( settingId, settingId, settingValue, {
transport: 'postMessage', // @todo Let this be postMessage
if ( ! api.has( id ) ) {
api.create( id, id, setting.value, {
transport: setting.transport,
previewer: api.previewer,
dirty: false
dirty: setting.dirty
} );
}

sectionType = 'post[' + postType + ']';
panelId = 'posts[' + postType + ']';
sectionId = settingId;
if ( 'post' === setting.type ) {
component.addPostSection( id );
}
} );
};

if ( api.section.has( sectionId ) ) {
return;
/**
* Handle adding post setting.
*
* @param {string} id
*/
component.addPostSection = function( id ) {
var section, sectionId, panelId, sectionType, postId, postType, idParts, Constructor, htmlParser;
idParts = id.replace( /]/g, '' ).split( '[' );
postType = idParts[1];
if ( ! component.data.postTypes[ postType ] ) {
if ( 'undefined' !== typeof console && console.error ) {
console.error( 'Unrecognized post type: ' + postType );
}
return;
}
postId = parseInt( idParts[2], 10 );
if ( ! postId ) {
if ( 'undefined' !== typeof console && console.error ) {
console.error( 'Bad post id: ' + idParts[2] );
}
return;
}

Constructor = api.sectionConstructor[ sectionType ] || api.sectionConstructor.post;

htmlParser = $( '<div>' ).html( component.data.l10n.sectionCustomizeActionTpl.replace( '%s', api.panel( panelId ).params.title ) );
section = new Constructor( sectionId, {
params: {
id: sectionId,
panel: panelId,
post_type: postType,
post_id: postId,
active: true,
customizeAction: htmlParser.text()
}
});
api.section.add( sectionId, section );
} );
sectionType = 'post[' + postType + ']';
panelId = 'posts[' + postType + ']';
sectionId = id;

if ( api.section.has( sectionId ) ) {
return;
}

Constructor = api.sectionConstructor[ sectionType ] || api.sectionConstructor.post;

htmlParser = $( '<div>' ).html( component.data.l10n.sectionCustomizeActionTpl.replace( '%s', api.panel( panelId ).params.title ) );
section = new Constructor( sectionId, {
params: {
id: sectionId,
panel: panelId,
post_type: postType,
post_id: postId,
active: true,
customizeAction: htmlParser.text()
}
});
api.section.add( sectionId, section );
};

api.bind( 'ready', function() {
Expand All @@ -111,7 +123,7 @@
component.postIdInput = $( '<input type="hidden" id="post_ID" name="post_ID">' );
$( 'body' ).append( component.postIdInput );

api.previewer.bind( 'customized-posts', component.receiveCustomizedPosts );
api.previewer.bind( 'customized-posts', component.receivePreviewData );

/**
* Focus on the section requested from the preview.
Expand Down
Loading