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

Commit 6cbefa3

Browse files
authored
Merge pull request #305 from xwp/develop
Release 0.8.2
2 parents f5f8c75 + 615b78d commit 6cbefa3

11 files changed

+104
-22
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "xwp/wp-customize-posts",
33
"description": "Manage posts and postmeta via the Customizer.",
4-
"version": "0.8.1",
4+
"version": "0.8.2",
55
"type": "wordpress-plugin",
66
"keywords": [ "customizer", "customize", "posts", "postmeta", "preview", "featured-image", "page-template" ],
77
"homepage": "https://github.com/xwp/wp-customize-posts/",

customize-posts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Customize Posts
44
* Description: Manage posts and postmeta via the Customizer. Works best in conjunction with the <a href="https://wordpress.org/plugins/customize-setting-validation/">Customize Setting Validation</a> plugin.
55
* Plugin URI: https://github.com/xwp/wp-customize-posts/
6-
* Version: 0.8.1
6+
* Version: 0.8.2
77
* Author: XWP
88
* Author URI: https://make.xwp.co/
99
* License: GPLv2+

js/customize-post-date-control.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@
183183
return;
184184
}
185185

186-
remainingTime = ( new Date( control.setting.get().post_date ) ).valueOf();
187-
remainingTime -= ( new Date( api.Posts.getCurrentTime() ) ).valueOf();
186+
remainingTime = api.Posts.parsePostDate( control.setting.get().post_date ).valueOf();
187+
remainingTime -= api.Posts.parsePostDate( api.Posts.getCurrentTime() ).valueOf();
188188
remainingTime = Math.ceil( remainingTime / 1000 );
189189
if ( remainingTime > 0 ) {
190190
control.scheduledCountdownContainer.text( control.scheduledCountdownTemplate( { remainingTime: remainingTime } ) );

js/customize-post-status-control.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,17 @@
110110
*/
111111
updateChoices: function updateChoices() {
112112
var control = this, data = control.setting.get(), isFuture, postTimestamp, currentTimestamp;
113-
postTimestamp = ( new Date( data.post_date ) ).valueOf();
114-
currentTimestamp = ( new Date( api.Posts.getCurrentTime() ) ).valueOf();
113+
postTimestamp = api.Posts.parsePostDate( data.post_date );
114+
currentTimestamp = api.Posts.parsePostDate( api.Posts.getCurrentTime() );
115115
isFuture = postTimestamp > currentTimestamp;
116116

117117
/*
118118
* Account for race condition when saving a post with an empty date
119119
* when server time and client time aren't exactly aligned. If the
120120
* status is publish, and yet the post date is less than 15 seconds
121121
* into the future, consider it as not future.
122+
*
123+
* See also https://github.com/xwp/wp-customize-posts/issues/303
122124
*/
123125
if ( isFuture && 'publish' === data.post_status && postTimestamp - currentTimestamp < 15 * 1000 ) {
124126
isFuture = false;

js/customize-posts.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@
308308
request = wp.ajax.post( 'customize-posts-fetch-settings', {
309309
'customize-posts-nonce': api.settings.nonce['customize-posts'],
310310
'wp_customize': 'on',
311+
'customized': api.previewer.query().customized,
311312
'post_ids': newPostIds
312313
} );
313314

@@ -533,13 +534,26 @@
533534
component.getCurrentTime = function getCurrentTime() {
534535
var currentDate, currentTimestamp, timestampDifferential;
535536
currentTimestamp = ( new Date() ).valueOf();
536-
currentDate = new Date( component.data.initialServerDate.replace( ' ', 'T' ) );
537+
currentDate = component.parsePostDate( component.data.initialServerDate );
537538
timestampDifferential = currentTimestamp - component.data.initialClientTimestamp;
538539
timestampDifferential += component.data.initialClientTimestamp - component.data.initialServerTimestamp;
539540
currentDate.setTime( currentDate.getTime() + timestampDifferential );
540541
return component.formatDate( currentDate );
541542
};
542543

544+
/**
545+
* Parse post date string in YYYY-MM-DD HH:MM:SS format (local timezone).
546+
*
547+
* @param {string} postDate Post date string.
548+
* @returns {Date} Parsed date.
549+
*/
550+
component.parsePostDate = function parsePostDate( postDate ) {
551+
var dateParts = _.map( postDate.split( /\D/ ), function( datePart ) {
552+
return parseInt( datePart, 10 );
553+
} );
554+
return new Date( dateParts[0], dateParts[1] - 1, dateParts[2], dateParts[3], dateParts[4], dateParts[5] ); // eslint-disable-line no-magic-numbers
555+
};
556+
543557
/**
544558
* Focus on the control requested from the preview.
545559
*

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"type": "git",
77
"url": "https://github.com/xwp/wp-customize-posts.git"
88
},
9-
"version": "0.8.1",
9+
"version": "0.8.2",
1010
"license": "GPL-2.0+",
1111
"private": true,
1212
"devDependencies": {

php/class-wp-customize-posts-preview.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,9 +860,18 @@ public function _inject_meta_sql_customized_derived_tables( $matches ) {
860860
/**
861861
* Filter the postmeta rows that are being previewed.
862862
*
863-
* @param array $postmeta_rows Postmeta rows, associative arrays with keys for post_id, meta_key, and meta_value.
863+
* @param array $postmeta_rows Postmeta rows, associative arrays with keys for post_id, meta_key, and meta_value.
864+
* @param WP_Customize_Postmeta_Setting $setting Post meta setting.
864865
*/
865-
$postmeta_rows = apply_filters( 'customize_previewed_postmeta_rows', $postmeta_rows );
866+
$postmeta_rows = apply_filters( 'customize_previewed_postmeta_rows', $postmeta_rows, $setting );
867+
868+
/**
869+
* Filter the postmeta rows that are being previewed for a specific key.
870+
*
871+
* @param array $postmeta_rows Postmeta rows, associative arrays with keys for post_id, meta_key, and meta_value.
872+
* @param WP_Customize_Postmeta_Setting $setting Post meta setting.
873+
*/
874+
$postmeta_rows = apply_filters( "customize_previewed_postmeta_rows_{$setting->meta_key}", $postmeta_rows, $setting );
866875

867876
$previewed_meta_keys = wp_list_pluck( $postmeta_rows, 'meta_key' );
868877

php/class-wp-customize-posts.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,25 +1322,32 @@ public function ajax_fetch_settings() {
13221322
wp_send_json_error( 'bad_post_ids' );
13231323
}
13241324

1325+
$this->manager->add_dynamic_settings( array_keys( $this->manager->unsanitized_post_values() ) );
1326+
13251327
$setting_params = array();
13261328
$settings = $this->get_settings( $post_ids );
13271329
foreach ( $settings as $setting ) {
13281330
if ( $setting->check_capabilities() ) {
1331+
$setting->preview();
13291332
$setting_params[ $setting->id ] = $this->get_setting_params( $setting );
13301333
}
13311334
}
13321335

13331336
// Return with a failure if any of the requested posts.
13341337
foreach ( $post_ids as $post_id ) {
1335-
$post = get_post( $post_id );
1336-
if ( empty( $post ) ) {
1337-
status_header( 404 );
1338-
wp_send_json_error( 'requested_post_absent' );
1338+
if ( $post_id < 0 ) {
1339+
$post_type = 'nav_menu_item';
1340+
} else {
1341+
$post_type = get_post_type( $post_id );
1342+
if ( empty( $post_type ) ) {
1343+
status_header( 404 );
1344+
wp_send_json_error( 'requested_post_absent' );
1345+
}
13391346
}
1340-
if ( 'nav_menu_item' === $post->post_type ) {
1341-
$setting_id = sprintf( 'nav_menu_item[%d]', $post->ID );
1347+
if ( 'nav_menu_item' === $post_type ) {
1348+
$setting_id = sprintf( 'nav_menu_item[%d]', $post_id );
13421349
} else {
1343-
$setting_id = WP_Customize_Post_Setting::get_post_setting_id( $post );
1350+
$setting_id = WP_Customize_Post_Setting::get_post_setting_id( get_post( $post_id ) );
13441351
}
13451352
if ( ! isset( $setting_params[ $setting_id ] ) ) {
13461353
status_header( 404 );

readme.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Edit posts and postmeta in the Customizer. Stop editing your posts/postmeta blin
88
**Tags:** [customizer](https://wordpress.org/plugins/tags/customizer), [customize](https://wordpress.org/plugins/tags/customize), [posts](https://wordpress.org/plugins/tags/posts), [postmeta](https://wordpress.org/plugins/tags/postmeta), [editor](https://wordpress.org/plugins/tags/editor), [preview](https://wordpress.org/plugins/tags/preview), [featured-image](https://wordpress.org/plugins/tags/featured-image), [page-template](https://wordpress.org/plugins/tags/page-template)
99
**Requires at least:** 4.5
1010
**Tested up to:** 4.7-alpha
11-
**Stable tag:** 0.8.1
11+
**Stable tag:** 0.8.2
1212
**License:** [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html)
1313

1414
[![Build Status](https://travis-ci.org/xwp/wp-customize-posts.svg?branch=master)](https://travis-ci.org/xwp/wp-customize-posts) [![Coverage Status](https://coveralls.io/repos/xwp/wp-customize-posts/badge.svg?branch=master)](https://coveralls.io/github/xwp/wp-customize-posts) [![Built with Grunt](https://cdn.gruntjs.com/builtwith.svg)](http://gruntjs.com) [![devDependency Status](https://david-dm.org/xwp/wp-customize-posts/dev-status.svg)](https://david-dm.org/xwp/wp-customize-posts#info=devDependencies)
@@ -90,6 +90,15 @@ The following are listed in reverse chronological order. The first, more recent
9090

9191
## Changelog ##
9292

93+
### [0.8.2] - 2016-10-03 ###
94+
* Fixed browser incompatible way of parsing local datetime strings. This is a follow-up on <a href="https://github.com/xwp/wp-customize-posts/pull/293" class="issue-link js-issue-link" data-url="https://github.com/xwp/wp-customize-posts/issues/293" data-id="178983334" data-error-text="Failed to load issue title" data-permission-text="Issue title is private">#293</a>, which was not fully fixed in 0.8.1. PR <a href="https://github.com/xwp/wp-customize-posts/pull/304" class="issue-link js-issue-link" data-url="https://github.com/xwp/wp-customize-posts/issues/304" data-id="180808420" data-error-text="Failed to load issue title" data-permission-text="Issue title is private">#304</a>.
95+
* Improved fetching of post/postmeta settings so that the <code>customized</code> state is included in the request, and allow for placeholder <code>nav_menu_item</code> settings to be fetched. PR <a href="https://github.com/xwp/wp-customize-posts/pull/299" class="issue-link js-issue-link" data-url="https://github.com/xwp/wp-customize-posts/issues/299" data-id="180154206" data-error-text="Failed to load issue title" data-permission-text="Issue title is private">#299</a>.
96+
* Added <code>$setting</code> context to <code>customize_previewed_postmeta_rows</code> filter and add new <code>customize_previewed_postmeta_rows_{$setting-&gt;post_meta}</code> filter. PR <a href="https://github.com/xwp/wp-customize-posts/pull/299" class="issue-link js-issue-link" data-url="https://github.com/xwp/wp-customize-posts/issues/299" data-id="180154206" data-error-text="Failed to load issue title" data-permission-text="Issue title is private">#299</a>.
97+
98+
Props Weston Ruter (<a href="https://github.com/westonruter" class="user-mention">@westonruter</a>), Utkarsh Patel (<a href="https://github.com/PatelUtkarsh" class="user-mention">@PatelUtkarsh</a>).
99+
100+
See <a href="https://github.com/xwp/wp-customize-posts/milestone/10?closed=1">issues and PRs in milestone</a> and <a href="https://github.com/xwp/wp-customize-posts/compare/0.8.1...0.8.2">full release commit log</a>.
101+
93102
### [0.8.1] - 2016-09-23 ###
94103
Fixed compatibility with Safari in the <code>wp.customize.Posts.getCurrentTime()</code> method. See <a href="https://github.com/xwp/wp-customize-posts/pull/293" class="issue-link js-issue-link" data-url="https://github.com/xwp/wp-customize-posts/issues/293" data-id="178983334" data-error-text="Failed to load issue title" data-permission-text="Issue title is private">#293</a>. Props Piotr Delawski (<a href="https://github.com/delawski" class="user-mention">@delawski</a>).
95104

readme.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: xwp, westonruter, valendesigns
33
Tags: customizer, customize, posts, postmeta, editor, preview, featured-image, page-template
44
Requires at least: 4.5
55
Tested up to: 4.7-alpha
6-
Stable tag: 0.8.1
6+
Stable tag: 0.8.2
77
License: GPLv2 or later
88
License URI: http://www.gnu.org/licenses/gpl-2.0.html
99

@@ -67,6 +67,16 @@ The following are listed in reverse chronological order. The first, more recent
6767

6868
== Changelog ==
6969

70+
= [0.8.2] - 2016-10-03 =
71+
72+
* Fixed browser incompatible way of parsing local datetime strings. This is a follow-up on <a href="https://github.com/xwp/wp-customize-posts/pull/293" class="issue-link js-issue-link" data-url="https://github.com/xwp/wp-customize-posts/issues/293" data-id="178983334" data-error-text="Failed to load issue title" data-permission-text="Issue title is private">#293</a>, which was not fully fixed in 0.8.1. PR <a href="https://github.com/xwp/wp-customize-posts/pull/304" class="issue-link js-issue-link" data-url="https://github.com/xwp/wp-customize-posts/issues/304" data-id="180808420" data-error-text="Failed to load issue title" data-permission-text="Issue title is private">#304</a>.
73+
* Improved fetching of post/postmeta settings so that the <code>customized</code> state is included in the request, and allow for placeholder <code>nav_menu_item</code> settings to be fetched. PR <a href="https://github.com/xwp/wp-customize-posts/pull/299" class="issue-link js-issue-link" data-url="https://github.com/xwp/wp-customize-posts/issues/299" data-id="180154206" data-error-text="Failed to load issue title" data-permission-text="Issue title is private">#299</a>.
74+
* Added <code>$setting</code> context to <code>customize_previewed_postmeta_rows</code> filter and add new <code>customize_previewed_postmeta_rows_{$setting-&gt;post_meta}</code> filter. PR <a href="https://github.com/xwp/wp-customize-posts/pull/299" class="issue-link js-issue-link" data-url="https://github.com/xwp/wp-customize-posts/issues/299" data-id="180154206" data-error-text="Failed to load issue title" data-permission-text="Issue title is private">#299</a>.
75+
76+
Props Weston Ruter (<a href="https://github.com/westonruter" class="user-mention">@westonruter</a>), Utkarsh Patel (<a href="https://github.com/PatelUtkarsh" class="user-mention">@PatelUtkarsh</a>).
77+
78+
See <a href="https://github.com/xwp/wp-customize-posts/milestone/10?closed=1">issues and PRs in milestone</a> and <a href="https://github.com/xwp/wp-customize-posts/compare/0.8.1...0.8.2">full release commit log</a>.
79+
7080
= [0.8.1] - 2016-09-23 =
7181

7282
Fixed compatibility with Safari in the <code>wp.customize.Posts.getCurrentTime()</code> method. See <a href="https://github.com/xwp/wp-customize-posts/pull/293" class="issue-link js-issue-link" data-url="https://github.com/xwp/wp-customize-posts/issues/293" data-id="178983334" data-error-text="Failed to load issue title" data-permission-text="Issue title is private">#293</a>. Props Piotr Delawski (<a href="https://github.com/delawski" class="user-mention">@delawski</a>).

0 commit comments

Comments
 (0)