This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Add post date control and preview #202
Merged
Merged
Changes from 8 commits
Commits
Show all changes
85 commits
Select commit
Hold shift + click to select a range
996c2ca
Post Date - Initial text input
johnregan3 adaf8cd
Post Date - Add basic custom control
johnregan3 59f5419
Post Date - Simplify, cleanup
johnregan3 7bedfab
Post Date - Iniital Tests
johnregan3 a73a67b
Post Date - Code cleanup
johnregan3 ddeed3b
Post Date - WIP
johnregan3 128d4bc
Post Date - New Control
johnregan3 c76f7a4
Merge branch 'develop' into feature/issue-56-post-date-control
johnregan3 a1f6ca0
Post Date - CSS, Code cleanup
johnregan3 d274099
Post Date - Change comment type
johnregan3 f8c68ee
Post Date - JS Date Handlers
johnregan3 37b3a87
Post Date - Code cleanup
johnregan3 a67829a
Post Date - Documentation
johnregan3 a7226a5
Post Date - Feature working
johnregan3 4798cdf
Post Date - Remove Date formatter
johnregan3 3c7acd9
Post Date - 'Published on' text
johnregan3 ca92ac4
Post Date - Code cleanup
johnregan3 0081baf
Post Date - Modify eslint for consistent-this
johnregan3 092d3bc
Post Date - correct syntax for eslint
johnregan3 0ac0e77
Post Date - Input validation
johnregan3 c59b673
Post Date - Documentation
johnregan3 e2ad701
Post Date - Code cleanup
johnregan3 4b56523
Post Date - Code cleanup
johnregan3 6fd3084
Post Date - Hidden update Post Status
johnregan3 4a5c6c5
Post Date - Update Post Status
johnregan3 e6a9048
Post Date - JSDocs
johnregan3 ef76128
Post Date - JSDoc update
johnregan3 1ca7394
Post Date - Refactor and new file
johnregan3 097f211
Post Date - Saving post_date_gmt & post_status
johnregan3 4e58a2d
Rename customize-post-date to customize-post-date-control
westonruter 467ebb8
Remove 'Post' from Status and Date control labels
westonruter 62adabe
Include timezone and/or GMT offset in date control description
westonruter 517cb2d
Add missing phpdoc and translator comment
westonruter 4845ec2
Refactor how date fields are bound with the post_date setting property.
westonruter c79172e
Remove obsolete CSS rule
westonruter e032ebb
Allow post type registration to override date control label
westonruter dd10ae7
Prevent selective refresh requests from dropping queriedPostId
westonruter 60a6f6a
Eliminate post_date_gmt and post_modified_gmt from setting value
westonruter 4caf74d
Hide date control in edit post screen preview; add todo for sync
westonruter f382ef9
Fix eslint issues across plugin
westonruter faf80fa
Prevent low-fidelity live preview of post title from running at refresh
westonruter 1dcaa23
Add getCurrentTime function
westonruter a0b0382
Use getDate (of month) instead of uncorrect getDay (of week)
westonruter 7b2e6cb
Prevent erroneously showing post navigation link when status is trash
westonruter 75bec41
Add dedicated post_status control, sync publish/future status with po…
westonruter ce5d417
Ensure JS sets post_author to integer
westonruter aab10bf
Prevent infinite partial fallbackRefresh when a setting is invalid
westonruter c70bd59
Turn off fallback_refresh for author partials
westonruter 0df59d2
Let auto-draft posts be inserted with empty dates
westonruter 43baeca
Allow draft posts to have empty dates which translate to current date…
westonruter 0262640
Add button to reset post_date to current time
westonruter 3b0d8ae
Merge branch 'develop' of https://github.com/xwp/wp-customize-posts i…
westonruter 0efcaea
Force archives to refresh when dates change so posts can bre reordered
westonruter 5680d0d
Filter the_posts to re-order after previewed changes have been applied
westonruter 0ec6824
Do full refreshes on archive views when a post field is modified that…
westonruter 28bc885
Add tests for Customize_Posts_Plugin and WP_Customize_Post_Date_Control
westonruter 410f9cb
Add test for render_post_date
westonruter 29077d4
Add tests for WP_Customize_Post_Setting
westonruter 899ce61
Add tests and stubs for stubs
westonruter 7f2e87c
Implement incomplete tests for WP_Customize_Posts
westonruter 86e448c
Implement tests for WP_Customize_Posts_Preview
westonruter 8dec6c8
Move month choices to main component class
westonruter 641b7eb
Ensure that empty dates are not leaked when a setting is invalid
westonruter 9b1fcdd
Attempt to fix Test_WP_Customize_Posts::test_enqueue_scripts double v…
westonruter 7975f86
Force all post field partials to refresh even if an unrelated field w…
westonruter 1b37d71
Leave partial placements in a loading state after they get refreshed …
westonruter 76afa9f
Move deferred partial into its own file; clean up dependencies
westonruter d86532e
Move settingValidities collection into separate JS file
westonruter 57bad17
Add scheduled countdown when status is future and time is after now
westonruter fb90a0a
Add grunt build to npm postinstall script
westonruter 191b923
Use small for date control description; fix call to format_gmt_offset
westonruter 70a7fd4
Re-use tz_string var
westonruter d95eaac
Update wp-plugin-dev-lib 449182d...ce4fce1: Use __FILE__ instead of _…
westonruter a385a60
Skip grunt build if not PHP>5.2
westonruter ebf331e
Only run grunt build if PHP>=5.3
westonruter 18364e2
Improvement: Refine UI for post date control reset button 💯
04efe42
Fix: Wierd redirect by adding buttons type
ad6751d
Merge pull request #208 from ahmadawais/feature/issue-56-post-date-co…
westonruter 276f8fb
Use link instead of button to re-use styles
westonruter 41b8d0b
Show local timezone abbr as details summary on same line as title
westonruter 2bac360
Update wp-plugin-dev-lib 449182d...4aba13a: Merge pull request #194 f…
westonruter b293245
Fix display of GMT offset
westonruter a7315e1
Fix reset post time by passing in post_date_gmt as empty as well
westonruter ce956fd
Fix race condition when saving publish post at current time
westonruter b7bcbe1
Improve logic for updating selected status option
westonruter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.customize-control-post_date { | ||
background: #f00; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
/** | ||
* Customize Post Date Control Class | ||
* | ||
* @package WordPress | ||
* @subpackage Customize | ||
*/ | ||
|
||
|
||
/** | ||
* Class WP_Customize_Post_Date_Control | ||
*/ | ||
class WP_Customize_Post_Date_Control extends WP_Customize_Dynamic_Control { | ||
|
||
/** | ||
* Type of control, used by JS. | ||
* | ||
* @access public | ||
* @var string | ||
*/ | ||
public $type = 'post_date'; | ||
|
||
/** | ||
* Get the data to export to the client via JSON. | ||
* | ||
* @return array Array of parameters passed to the JavaScript. | ||
*/ | ||
public function json() { | ||
$exported = parent::json(); | ||
$exported['month_choices'] = $this->get_month_choices(); | ||
$exported['date_inputs'] = array( | ||
'month', | ||
'date', | ||
'year', | ||
'hour', | ||
'min', | ||
); | ||
return $exported; | ||
} | ||
|
||
/** | ||
* Render the Underscore template for this control. | ||
* | ||
* @access protected | ||
* @codeCoverageIgnore | ||
*/ | ||
protected function content_template() { | ||
$data = $this->json(); | ||
?> | ||
<# | ||
_.defaults( data, <?php echo wp_json_encode( $data ) ?> ); | ||
data.input_id = 'input-' + String( Math.random() ); | ||
#> | ||
<span class="customize-control-title"><label for="{{ data.input_id }}">{{ data.label }}</label></span> | ||
<# if ( data.description ) { #> | ||
<span class="description customize-control-description">{{ data.description }}</span> | ||
<# } #> | ||
|
||
<# _.each( data.date_inputs, function( type ) { #> | ||
<# if ( 'month' === type ) { #> | ||
<select class="date-input {{ type }}"> | ||
<# _.each( data.month_choices, function( choice ) { #> | ||
<# | ||
if ( _.isObject( choice ) && ! _.isUndefined( choice.text ) && ! _.isUndefined( choice.value ) ) { | ||
text = choice.text; | ||
value = choice.value; | ||
} | ||
#> | ||
<option value="{{ value }}">{{ text }}</option> | ||
<# } ); #> | ||
</select> | ||
<# } else { #> | ||
<input | ||
type="text" | ||
class="date-input {{ type }}" | ||
value="" | ||
/> | ||
<# } #> | ||
<# }); #> | ||
<input | ||
id="{{ data.input_id }}" | ||
type="text" | ||
<# _.each( data.input_attrs, function( value, key ) { #> | ||
{{{ key }}}="{{ value }}" | ||
<# } ) #> | ||
<# if ( data.setting_property ) { #> | ||
data-customize-setting-property-link="{{ data.setting_property }}" | ||
<# } #> | ||
/> | ||
<?php | ||
} | ||
|
||
/** | ||
* Generate options for the month Select. | ||
* | ||
* Based on touch_time(). | ||
* | ||
* @see touch_time() | ||
* | ||
* @return array | ||
*/ | ||
public function get_month_choices() { | ||
global $wp_locale; | ||
$months = array(); | ||
for ( $i = 1; $i < 13; $i = $i + 1 ) { | ||
$month_number = zeroise( $i, 2 ); | ||
$month_text = $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ); | ||
|
||
/* translators: 1: month number (01, 02, etc.), 2: month abbreviation */ | ||
$months[ $i ]['text'] = sprintf( __( '%1$s-%2$s', 'customize-posts' ), $month_number, $month_text ); | ||
$months[ $i ]['value'] = $month_number; | ||
} | ||
return $months; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
tests/php/test-class-wp-customize-post-date-control.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
/** | ||
* Tests for Test_WP_Customize_Post_Date_Control. | ||
* | ||
* @package WordPress | ||
* @subpackage Customize | ||
*/ | ||
|
||
/** | ||
* Class Test_WP_Customize_Post_Date_Control | ||
*/ | ||
class Test_WP_Customize_Post_Date_Control extends WP_UnitTestCase { | ||
|
||
/** | ||
* Customize Manager instance. | ||
* | ||
* @var WP_Customize_Manager | ||
*/ | ||
public $wp_customize; | ||
|
||
/** | ||
* Component. | ||
* | ||
* @var WP_Customize_Posts | ||
*/ | ||
public $posts; | ||
|
||
/** | ||
* Setup. | ||
* | ||
* @inheritdoc | ||
*/ | ||
public function setUp() { | ||
parent::setUp(); | ||
require_once( ABSPATH . WPINC . '/class-wp-customize-manager.php' ); | ||
$GLOBALS['wp_customize'] = new WP_Customize_Manager(); | ||
$this->wp_customize = $GLOBALS['wp_customize']; | ||
wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); | ||
$this->posts = new WP_Customize_Posts( $this->wp_customize ); | ||
} | ||
|
||
/** | ||
* Teardown. | ||
* | ||
* @inheritdoc | ||
*/ | ||
function tearDown() { | ||
$this->wp_customize = null; | ||
$this->posts = null; | ||
unset( $GLOBALS['wp_customize'] ); | ||
unset( $GLOBALS['wp_scripts'] ); | ||
unset( $_REQUEST['nonce'] ); | ||
unset( $_REQUEST['customize_preview_post_nonce'] ); | ||
unset( $_REQUEST['wp_customize'] ); | ||
unset( $_GET['previewed_post'] ); | ||
parent::tearDown(); | ||
} | ||
|
||
/** | ||
* Do Customizer boot actions. | ||
*/ | ||
function do_customize_boot_actions() { | ||
// Remove actions that call add_theme_support( 'title-tag' ). | ||
remove_action( 'after_setup_theme', 'twentyfifteen_setup' ); | ||
remove_action( 'after_setup_theme', 'twentysixteen_setup' ); | ||
|
||
$_SERVER['REQUEST_METHOD'] = 'POST'; | ||
$_POST['customized'] = ''; | ||
do_action( 'setup_theme' ); | ||
$_REQUEST['nonce'] = wp_create_nonce( 'preview-customize_' . $this->wp_customize->theme()->get_stylesheet() ); | ||
$_REQUEST['customize_preview_post_nonce'] = wp_create_nonce( 'customize_preview_post' ); | ||
do_action( 'after_setup_theme' ); | ||
do_action( 'customize_register', $this->wp_customize ); | ||
$this->wp_customize->customize_preview_init(); | ||
do_action( 'wp', $GLOBALS['wp'] ); | ||
$_REQUEST['wp_customize'] = 'on'; | ||
$_GET['previewed_post'] = 123; | ||
} | ||
|
||
/** | ||
* Creates the dynamic control. | ||
* | ||
* @param int $setting_id The setting ID. | ||
*/ | ||
public function control( $setting_id ) { | ||
$args = array( | ||
'label' => 'Heading Text', | ||
'section' => $setting_id, | ||
'settings' => $setting_id, | ||
'priority' => 1, | ||
'field_type' => 'post_date', | ||
'setting_property' => 'post_date', | ||
'input_attrs' => array( 'data-test' => 'value-test' ), | ||
); | ||
return new WP_Customize_Post_Date_Control( $this->wp_customize, 'dynamic_control_id', $args ); | ||
} | ||
|
||
/** | ||
* Filter to register a setting, section, & control. | ||
*/ | ||
public function customize_register() { | ||
$setting_id = 'post[post][123]'; | ||
|
||
$this->wp_customize->add_setting( $setting_id ); | ||
|
||
$setting = new WP_Customize_Post_Section( $this->wp_customize, $setting_id, array( | ||
'panel' => 'posts[post]', | ||
'post_setting' => $this->wp_customize->get_setting( $setting_id ), | ||
'priority' => 1, | ||
) ); | ||
$this->wp_customize->add_section( $setting ); | ||
|
||
$control = $this->control( $setting_id ); | ||
$this->wp_customize->add_control( $control ); | ||
} | ||
|
||
/** | ||
* Test export data to JS. | ||
* | ||
* @see WP_Customize_Dynamic_Control::json() | ||
*/ | ||
public function test_json() { | ||
add_action( 'customize_register', array( $this, 'customize_register' ), 15 ); | ||
$this->do_customize_boot_actions(); | ||
|
||
$control = $this->control( 'post[post][123]' ); | ||
$json = $control->json(); | ||
|
||
$this->assertArrayHasKey( 'input_attrs', $json ); | ||
$this->assertArrayHasKey( 'field_type', $json ); | ||
$this->assertArrayHasKey( 'setting_property', $json ); | ||
$this->assertEquals( array( 'data-test' => 'value-test' ), $json['input_attrs'] ); | ||
$this->assertEquals( 'post_date', $json['field_type'] ); | ||
$this->assertEquals( 'post_date', $json['setting_property'] ); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@johnregan3 Can we use
number
as input type withmax
andmin
attributes?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PatelUtkarsh I would love to do that. I think it would help greatly with validation. @westonruter How closely do we want to match the existing interface? It uses simple text inputs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In number input that arrows(up and down) make it smaller(input needs more space) so maybe that's why the core is not using it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PatelUtkarsh You know, I'm not really sure. I think they would just rather leave it alone since it's been used for so long. However, I think it's time for an update of that whole metabox. in addition to the UI changes, the JS for the date function could be greatly improved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't like the existing interface 😄