From 786c6a7c39adfd197a4b05ba5abf74fa8d64fc46 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Mon, 12 Aug 2019 07:42:09 -0600 Subject: [PATCH] build docs --- .../developers/data/data-core-editor.md | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/docs/designers-developers/developers/data/data-core-editor.md b/docs/designers-developers/developers/data/data-core-editor.md index e3456d65168dbd..18ca22f602fff8 100644 --- a/docs/designers-developers/developers/data/data-core-editor.md +++ b/docs/designers-developers/developers/data/data-core-editor.md @@ -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. @@ -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.