-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add examples for the lockPostSaving and unlockPostSaving actions #16713
Conversation
So I did this:
|
@draganescu Thanks for testing. Hmmm, let me re-test that, it worked when I tested earlier. Did you see any errors in the browser console? |
Hi, no errors whatsoever, just didn't do what I expected :) Maybe I did something wrong ... |
@draganescu did you complete the publish process or only notice that the publish button was active? If you click it you sill see the next publish button should be disabled: To confirm here is the code snippet I am testing with 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' );
}
}
}
} );
} |
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.
Example works as described
@adamsilverstein yes, that was my issue, I expected that publish would become inactive immediately not after I clicked :) Thank you for the explanation! You should also build the docs and commit the changes I think for the tests to pass. |
Ah right, thanks for the reminder. Built in 786c6a7 |
* Add examples for the lockPostSaving and unlockPostSaving actions * build docs
* Add examples for the lockPostSaving and unlockPostSaving actions * build docs
Description
@example
code examples forlockPostSaving
andunlockPostSaving
.See #10649 (comment)
How has this been tested?
Test the example for
lockPostSaving
by pasting code into the browser console. The post will be unpublishable until the publish date is set to the future.Screenshots
Example code running:
Types of changes
Checklist: