-
Notifications
You must be signed in to change notification settings - Fork 38
Show notification when a post a restored from trash #347
Conversation
Ready for review. |
php/class-wp-customize-posts.php
Outdated
@@ -846,6 +846,7 @@ public function enqueue_scripts() { | |||
__( 'Customize Object Selector', 'customize-posts' ) | |||
) | |||
), | |||
'trashPostNotification' => __( 'This has been untrashed. If you publish changes now, this post will be published. Move back to trash to avoid this.' , 'customize-posts' ), |
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.
It may not actually be published. If the post was a draft
then it will be restored as a draft
, right?
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.
Correct, how about changing it to this?
"This has been untrashed. If you publish changes now, its status will change to the selected status. Move back to trash to avoid this."
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.
Yes, that's good.
@@ -32,6 +34,10 @@ | |||
panel.deferred.embedded.done(function() { | |||
panel.setupPanelActions(); | |||
}); | |||
|
|||
api.bind( 'saved', function() { |
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.
This will trigger even when updating a changeset draft via Customize Snapshots. Is that intended? If you want it to only run when the changeset is published as a whole, then I think you need to make sure that the changeset status is publish
, like:
api.bind( 'saved', function( data ) {
if ( 'publish' === data.changeset_status ) {
panel.removeTrashNotifications();
}
} );
Humm. But actually this code is also being used for purging the trashed items as well:
wp-customize-posts/js/customize-posts.js
Lines 1110 to 1116 in 32c6d1a
// Purge trashed posts and update client settings with saved values from server. | |
api.bind( 'saved', function( data ) { | |
if ( data.saved_post_setting_values ) { | |
component.updateSettingsQuietly( data.saved_post_setting_values ); | |
} | |
component.purgeTrash(); | |
} ); |
So maybe that other location in Customize Posts needs to be updated as well.
Or maybe this is all intended, to purge the trashed items upon saving an explicit draft as well as upon publishing, and if so you can ignore this comment 😄
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.
It was intended because if snapshot saves it as draft or any other status, it would eventually get published when they publish the snapshot, so the user should know this right?
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 think the way you have it is a better experience. If I hit Move to Trash, and then hit Save Draft, I pretty clearly don't want the trashed item around anymore and I'm unlikely to be wanting to undo it. So removing the trashed post sections upon explicit Save makes sense to me.
js/customize-posts-panel.js
Outdated
} ); | ||
|
||
statusControl.setting.bind( function() { | ||
statusControl.notifications.remove( panel.trashNotificationCode ); |
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.
So this will remove the notification whenever a user makes a change to the setting? Probably should call statusControl.setting.unbind()
to remove this function handler after it runs once, right?
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.
Yes, good point
message: api.Posts.data.l10n.trashPostNotification | ||
} ); | ||
|
||
statusControl = api.control( postData.section.id + '[post_status]' ); |
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.
It's unlikely, but this should probably check to see if statusControl
exists (like you're doing in removeTrashNotifications
below), and if not then short circuit.
js/customize-posts-panel.js
Outdated
statusControl = api.control( postData.section.id + '[post_status]' ); | ||
statusControl.deferred.embedded.done( function() { | ||
statusControl.notifications.add( panel.trashNotificationCode, notification ); | ||
} ); |
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.
Just curious why the statusControl.deferred.embedded
is needed here. The statusControl.notifications
collection should exist from the moment that a control is initialized, so I don't think that you have to wait for embedding?
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 wasn't sure, but right embedded is not required here.
…tification has been removed.
Fixes #217