Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Trashed post shows published and changes status to publish if loaded again and you hit publish. #217

Closed
mohdsayed opened this issue Aug 15, 2016 · 8 comments
Milestone

Comments

@mohdsayed
Copy link
Contributor

mohdsayed commented Aug 15, 2016

Step-1: Trash one post and hit Save & Publish button.
Step-2: Reload the page and search for the trashed post in dropdown and open it. Or put the section id in autofocus ( ...?autofocus[section]=sectionId )
Step-3 Hit publish/save button again ( or go to another section make changes and hit publish )

The trashed post becomes published because the status selected in post section after loading is 'publish' and not 'trash'.

@mohdsayed mohdsayed changed the title Trashed post shows published and changed status to publish if loaded again and you hit publish. Trashed post shows published and changes status to publish if loaded again and you hit publish. Aug 15, 2016
@westonruter
Copy link
Contributor

@sayedwp this is actually by design. When you un-trash a post it is designed to re-store the previous status and slug that were used when it was trashed previously. This follows the behavior from wp_untrash_post() here: https://developer.wordpress.org/reference/functions/wp_untrash_post/

You can see this behavior was specifically implemented in Customize Posts here:

// Amend trashed post setting values with the pre-trashed state.
if ( $setting instanceof WP_Customize_Post_Setting && 'trash' === $setting_params['value']['post_status'] ) {
$setting_params['dirty'] = true;
// Resurrect the old status.
$former_status = get_post_meta( $setting->post_id, '_wp_trash_meta_status', true );
if ( ! $former_status ) {
$former_status = 'draft';
}
$setting_params['value']['post_status'] = $former_status;
// Resurrect the old slug.
$former_slug = get_post_meta( $setting->post_id, '_wp_desired_post_slug', true );
if ( ! $former_slug ) {
$former_slug = preg_replace( '#__trashed$#', '', $setting_params['value']['post_name'] );
}
$setting_params['value']['post_name'] = $former_slug;
}

This being said, is there a bug here?

@mohdsayed
Copy link
Contributor Author

I see a problem with this behaviour, it can make a trashed post go publish, which was not intended by user, I will create a video explaining this later today.

@westonruter
Copy link
Contributor

If they don't want it to be published, then they shouldn't be opening it from trash. If they want it to stay in the trash, then they should click “Move to trash” or change the status back to trash. Perhaps a notification added to the status control to alert the user that the status has been restored would be in order, and notifying them that if they publish now the post will be restored.

@mohdsayed
Copy link
Contributor Author

@westonruter westonruter added this to the 0.7.1 milestone Aug 15, 2016
@mohdsayed
Copy link
Contributor Author

Exactly, at least adding a notification would be great, so they have some way of knowing that they are making that post published.

@westonruter
Copy link
Contributor

@sayedwp thanks for that helpful video. Yeah, a notification is needed here at the very least. Something like this:

screen shot 2016-08-15 at 12 42 26 am

Example code that ads this notification:

code = 'untrashed';
postStatusControlId = 'post[post][6189][post_status]';
notification = new wp.customize.Notification( code, { 
    type: 'info', 
    message: 'This has been untrashed. If you publish changes now, this post will be published. Move back to trash to avoid this.' 
} );
wp.customize.control( postStatusControlId ).notifications.add( code, notification );

@westonruter
Copy link
Contributor

Something else that would help here is a listing of all of the dirty changes in the current Customizer state: xwp/wp-customize-snapshots#61

@westonruter
Copy link
Contributor

Note that the notification should be added when the post is restored from trash, and the notification should be removed once the saved event happens or if the post_status switches back to trash.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants