Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Merge branch 'develop' into bugfix/post-navigation-link-selective-ref…
Browse files Browse the repository at this point in the history
…resh-persistence
  • Loading branch information
valendesigns committed Jun 15, 2016
2 parents a8a5298 + ddc1774 commit 4f2dacb
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 15 deletions.
64 changes: 57 additions & 7 deletions js/customize-post-section.js
Expand Up @@ -62,6 +62,9 @@
if ( ! args.params.title ) {
args.params.title = api.Posts.data.l10n.noTitle;
}
api( id, function( setting ) {
setting.findControls = section.findPostSettingControls;
} );

section.postFieldControls = {};

Expand Down Expand Up @@ -236,20 +239,58 @@
},

/**
* Prevent notifications for settings from being added to post field control notifications.
* Prevent notifications for settings from being added to post field control notifications
* unless the notification is specifically for this control's setting property.
*
* @this {wp.customize.Control}
* @param {string} code Notification code.
* @param {wp.customize.Notification} notification Notification object.
* @returns {wp.customize.Notification|null} Notification if not bypassed.
*/
addPostFieldControlNotification: function( code, notification ) {
if ( -1 !== code.indexOf( ':' ) ) {
return null;
} else {
addPostFieldControlNotification: function addPostFieldControlNotification( code, notification ) {
var isSettingNotification, isSettingPropertyNotification;
isSettingNotification = -1 !== code.indexOf( ':' ) || notification.data && notification.data.setting; // Note that sniffing for ':' is deprecated as of #36944.
isSettingPropertyNotification = notification.data && notification.data.setting_property === this.setting_property;
if ( isSettingPropertyNotification || ! isSettingNotification ) {
return api.Values.prototype.add.call( this, code, notification );
} else {
return null;
}
},

/**
* Find controls associated with this setting.
*
* Filter the list of controls down to just those that have setting properties
* that correspond to setting properties listed among the data in notifications,
* if there are any.
*
* @this {wp.customize.Setting}
* @returns {wp.customize.Control[]} Controls associated with setting.
*/
findPostSettingControls: function findPostSettingControls() {
var settingPropertyControls = [], controls, settingProperties = [];
controls = api.Setting.prototype.findControls.call( this );

this.notifications.each( function( notification ) {
if ( notification.data && notification.data.setting_property ) {
settingProperties.push( notification.data.setting_property );
}
} );

_.each( controls, function( control ) {
if ( -1 !== _.indexOf( settingProperties, control.params.setting_property ) ) {
settingPropertyControls.push( control );
}
} );

if ( settingPropertyControls.length > 0 ) {
controls = settingPropertyControls;
}

return controls;
},

/**
* Add post title control.
*
Expand Down Expand Up @@ -282,6 +323,7 @@

if ( control.notifications ) {
control.notifications.add = section.addPostFieldControlNotification;
control.notifications.setting_property = control.params.setting_property;
}
return control;
},
Expand Down Expand Up @@ -329,6 +371,7 @@

if ( control.notifications ) {
control.notifications.add = section.addPostFieldControlNotification;
control.notifications.setting_property = control.params.setting_property;
}
return control;
},
Expand Down Expand Up @@ -409,6 +452,7 @@

if ( control.notifications ) {
control.notifications.add = section.addPostFieldControlNotification;
control.notifications.setting_property = control.params.setting_property;
}
return control;
},
Expand Down Expand Up @@ -673,6 +717,7 @@

if ( control.notifications ) {
control.notifications.add = section.addPostFieldControlNotification;
control.notifications.setting_property = control.params.setting_property;
}
return control;
},
Expand Down Expand Up @@ -709,6 +754,7 @@

if ( control.notifications ) {
control.notifications.add = section.addPostFieldControlNotification;
control.notifications.setting_property = control.params.setting_property;
}
return control;
},
Expand Down Expand Up @@ -745,6 +791,7 @@

if ( control.notifications ) {
control.notifications.add = section.addPostFieldControlNotification;
control.notifications.setting_property = control.params.setting_property;
}
return control;
},
Expand Down Expand Up @@ -782,6 +829,7 @@

if ( control.notifications ) {
control.notifications.add = section.addPostFieldControlNotification;
control.notifications.setting_property = control.params.setting_property;
}
return control;
},
Expand Down Expand Up @@ -810,7 +858,9 @@
// Sync setting notifications into the section notifications
setting.notifications.bind( 'add', function( settingNotification ) {
var notification = new api.Notification( setting.id + ':' + settingNotification.code, settingNotification );
section.notifications.add( notification.code, notification );
if ( ! settingNotification.data || ! settingNotification.data.setting_property || ! api.control.has( section.id + '[' + settingNotification.data.setting_property + ']' ) ) {
section.notifications.add( notification.code, notification );
}
} );
setting.notifications.bind( 'remove', function( settingNotification ) {
section.notifications.remove( setting.id + ':' + settingNotification.code );
Expand Down Expand Up @@ -890,7 +940,7 @@
_.each( section.postFieldControls, function( postFieldControl ) {
if ( postFieldControl.notifications ) {
postFieldControl.notifications.each( function( notification ) {
if ( 'error' === notification.type ) {
if ( 'error' === notification.type && ( ! notification.data || ! notification.data.from_server ) ) {
postFieldControl.notifications.remove( notification.code );
}
} );
Expand Down
16 changes: 10 additions & 6 deletions php/class-customize-posts-plugin.php
Expand Up @@ -179,11 +179,15 @@ function show_core_version_dependency_failure() {
public function register_scripts( WP_Scripts $wp_scripts ) {
$suffix = ( SCRIPT_DEBUG ? '' : '.min' ) . '.js';

$handle = 'customize-controls-patched-36521';
$src = plugins_url( 'js/customize-controls-patched-36521' . $suffix, dirname( __FILE__ ) );
$deps = array( 'customize-controls' );
$in_footer = 1;
$wp_scripts->add( $handle, $src, $deps, $this->version, $in_footer );
require_once ABSPATH . WPINC . '/class-wp-customize-setting.php';
$is_gte_wp46_beta = method_exists( 'WP_Customize_Setting', 'validate' );
if ( ! $is_gte_wp46_beta ) {
$handle = 'customize-controls-patched-36521';
$src = plugins_url( 'js/customize-controls-patched-36521' . $suffix, dirname( __FILE__ ) );
$deps = array( 'customize-controls' );
$in_footer = 1;
$wp_scripts->add( $handle, $src, $deps, $this->version, $in_footer );
}

$handle = 'customize-posts-panel';
$src = plugins_url( 'js/customize-posts-panel' . $suffix, dirname( __FILE__ ) );
Expand Down Expand Up @@ -214,7 +218,7 @@ public function register_scripts( WP_Scripts $wp_scripts ) {
'customize-dynamic-control',
'underscore',
);
if ( version_compare( str_replace( array( '-src' ), '', $GLOBALS['wp_version'] ), '4.6-beta1', '<' ) ) {
if ( ! $is_gte_wp46_beta ) {
$deps[] = 'customize-controls-patched-36521';
}
$in_footer = 1;
Expand Down
4 changes: 2 additions & 2 deletions php/class-wp-customize-post-setting.php
Expand Up @@ -319,7 +319,7 @@ public function sanitize( $post_data ) {

/** This filter is documented in wp-includes/post.php */
if ( 'trash' !== $post_data['post_status'] && apply_filters( 'wp_insert_post_empty_content', $maybe_empty, $post_data ) ) {
return $has_setting_validation ? new WP_Error( 'empty_content', __( 'Content, title, and excerpt are empty.', 'customize-posts' ) ) : null;
return $has_setting_validation ? new WP_Error( 'empty_content', __( 'Content, title, and excerpt are empty.', 'customize-posts' ), array( 'setting_property' => 'post_content' ) ) : null;
}

if ( empty( $post_data['post_status'] ) ) {
Expand Down Expand Up @@ -371,7 +371,7 @@ public function sanitize( $post_data ) {
$aa = substr( $post_data['post_date'], 0, 4 );
$valid_date = wp_checkdate( $mm, $jj, $aa, $post_data['post_date'] );
if ( ! $valid_date ) {
return $has_setting_validation ? new WP_Error( 'invalid_date', __( 'Whoops, the provided date is invalid.', 'customize-posts' ) ) : null;
return $has_setting_validation ? new WP_Error( 'invalid_date', __( 'Whoops, the provided date is invalid.', 'customize-posts' ), array( 'setting_property' => 'post_date' ) ) : null;
}

if ( empty( $post_data['post_date_gmt'] ) || '0000-00-00 00:00:00' === $post_data['post_date_gmt'] ) {
Expand Down

0 comments on commit 4f2dacb

Please sign in to comment.