Skip to content

Commit

Permalink
build docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Silverstein committed Aug 12, 2019
1 parent 0d335bb commit 786c6a7
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions docs/designers-developers/developers/data/data-core-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,41 @@ _Related_

Returns an action object used to signal that post saving is locked.

_Usage_

const { subscribe } = wp.data;

const initialPostStatus = wp.data.select( 'core/editor' ).getEditedPostAttribute( 'status' );

// Only allow publishing posts that are set to a future date.
if ( 'publish' !== initialPostStatus ) {

// Track locking.
let locked = false;

// Watch for the publish event.
let unssubscribe = subscribe( () => {
const currentPostStatus = wp.data.select( 'core/editor' ).getEditedPostAttribute( 'status' );
if ( 'publish' !== currentPostStatus ) {

// Compare the post date to the current date, lock the post if the date isn't in the future.
const postDate = new Date( wp.data.select( 'core/editor' ).getEditedPostAttribute( 'date' ) );
const currentDate = new Date();
if ( postDate.getTime() <= currentDate.getTime() ) {
if ( ! locked ) {
locked = true;
wp.data.dispatch( 'core/editor' ).lockPostSaving( 'futurelock' );
}
} else {
if ( locked ) {
locked = false;
wp.data.dispatch( 'core/editor' ).unlockPostSaving( 'futurelock' );
}
}
}
} );
}

_Parameters_

- _lockName_ `string`: The lock name.
Expand Down Expand Up @@ -1336,6 +1371,11 @@ _Returns_

Returns an action object used to signal that post saving is unlocked.

_Usage_

// Unlock post saving with the lock key `mylock`:
wp.data.dispatch( 'core/editor' ).unlockPostSaving( 'mylock' );

_Parameters_

- _lockName_ `string`: The lock name.
Expand Down

0 comments on commit 786c6a7

Please sign in to comment.