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

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

Closed
sayedtaqui opened this Issue Aug 15, 2016 · 8 comments

Comments

Projects
None yet
2 participants
@sayedtaqui
Collaborator

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

@sayedtaqui sayedtaqui changed the title from Trashed post shows published and changed status to publish if loaded again and you hit publish. to Trashed post shows published and changes status to publish if loaded again and you hit publish. Aug 15, 2016

@westonruter

This comment has been minimized.

Show comment
Hide comment
@westonruter

westonruter Aug 15, 2016

Member

@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?

Member

westonruter commented Aug 15, 2016

@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?

@sayedtaqui

This comment has been minimized.

Show comment
Hide comment
@sayedtaqui

sayedtaqui Aug 15, 2016

Collaborator

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.

Collaborator

sayedtaqui commented Aug 15, 2016

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

This comment has been minimized.

Show comment
Hide comment
@westonruter

westonruter Aug 15, 2016

Member

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.

Member

westonruter commented Aug 15, 2016

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.

@sayedtaqui

This comment has been minimized.

Show comment
Hide comment
@sayedtaqui
Collaborator

sayedtaqui commented Aug 15, 2016

@westonruter westonruter added this to the 0.7.1 milestone Aug 15, 2016

@sayedtaqui

This comment has been minimized.

Show comment
Hide comment
@sayedtaqui

sayedtaqui Aug 15, 2016

Collaborator

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

Collaborator

sayedtaqui commented Aug 15, 2016

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

@westonruter

This comment has been minimized.

Show comment
Hide comment
@westonruter

westonruter Aug 15, 2016

Member

@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 );
Member

westonruter commented Aug 15, 2016

@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

This comment has been minimized.

Show comment
Hide comment
@westonruter

westonruter Aug 15, 2016

Member

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

Member

westonruter commented Aug 15, 2016

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

This comment has been minimized.

Show comment
Hide comment
@westonruter

westonruter Aug 16, 2016

Member

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.

Member

westonruter commented Aug 16, 2016

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 join this conversation on GitHub. Already have an account? Sign in to comment