Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.
This repository was 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

Description

@mohdsayed

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'.

Activity

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.[/+] on Aug 15, 2016

westonruter commented on Aug 15, 2016

@westonruter
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 commented on Aug 15, 2016

@mohdsayed
ContributorAuthor

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 commented on Aug 15, 2016

@westonruter
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 commented on Aug 15, 2016

@mohdsayed
ContributorAuthor
added this to the milestone on Aug 15, 2016

mohdsayed commented on Aug 15, 2016

@mohdsayed
ContributorAuthor

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

westonruter commented on Aug 15, 2016

@westonruter
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 commented on Aug 15, 2016

@westonruter
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 commented on Aug 16, 2016

@westonruter
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.

modified the milestones: 0.8.0, , 0.9.0 on Sep 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions