Make WordPress Core

Opened 15 years ago

Closed 6 months ago

Last modified 6 months ago

#11207 closed defect (bug) (fixed)

WordPress may display incorrect message when post is saved/published/etc

Reported by: sirzooro's profile sirzooro Owned by: desrosj's profile desrosj
Milestone: 6.6 Priority: normal
Severity: normal Version: 2.9
Component: Posts, Post Types Keywords: has-patch good-first-bug
Focuses: administration Cc:

Description

When post is saved, WP calls wp_insert_post_data filter. Plugin can use it to change post status. But even post status has been changed via plugin, WP still displays message basing on action originally executed by user. Need to change this and take into account final post status too.

Attachments (3)

11207.diff (437 bytes) - added by blepoxp 15 years ago.
This fixes it for the reported solution.
11207.2.diff (716 bytes) - added by kawauso 13 years ago.
11207.3.diff (947 bytes) - added by azouamauriac 2 years ago.

Download all attachments as: .zip

Change History (38)

#1 @sirzooro
15 years ago

Note: I have found this while testing WyPiekacz plugin on WP 2.9. This plugin checks if post submitted for review or published satisfies set of rules, and changes its status to Draft if not. In 2.8 I was able to change displayed message by overwriting $_GET['message'] in admin_notice hook, but this does not work in 2.9 because of changes in wp-admin/edit-form-advanced.php.

#2 @azaozz
15 years ago

  • Keywords reporter-feedback added; needs-patch removed

Have you tried using the filter redirect_post_location?

#3 @ryan
15 years ago

  • Milestone changed from 2.9 to 3.0

#4 @sirzooro
15 years ago

No - this is a new filter added in WP 2.9. I can use it, but this does not fix this problem in general.

#5 @Denis-de-Bernardy
15 years ago

  • Keywords needs-patch added; reporter-feedback removed

#6 @hakre
15 years ago

A potential fix might be to generalize the message displayed sothat it will fit for all cases. How does that sound?

#7 @hakre
15 years ago

Realted: #11515 (and this ticket's content is an intersting use-case to that one)

#8 @sirzooro
15 years ago

I think it should be sufficient to extend statuses list in wp-admin/post.php to include all possible post statuses.

BTW, it may be funny when someone will use wp_insert_post_data filter to trash/untrash post :)

#9 @bsamrajni
15 years ago

  • Owner set to bsamrajni
  • Status changed from new to accepted

#10 @blepoxp
15 years ago

  • Keywords reporter-feedback added; needs-patch removed

The Short: I just tested this on r14235 and it seems to be working well.

The long version (Steps I took to reproduce):

1) Installed said theme
2) Created rule for minimum 1000 words per post
3) Unchecked box to let admin bypass rules
4) Created new post with less than 1000 words
5) Hit publish

Results were that I got the following plugin messages:
1) Post is too short (minimum is 1000 chars, your post has 416).
2) Post Status has been changed to Draft.

And the following WordPress generated message: "Post draft updated. Preview post"

When including more than a 1000 words, I got the default "Publish Posted" message from WordPress. If I then take the number of words below 1000, we go back to the plugin and wordpress messages mentioned above. Everything seems to be working.

#11 @sirzooro
15 years ago

  • Keywords needs-patch added; reporter-feedback removed

@blepoxp: current verwsion of WyPiekacz plugin uses redirect_post_location filter to override target url, so WP displays expected message. Please edit plugin file and disable this filter (comment out line 68) and try again.

#12 @blepoxp
15 years ago

Ok. I see now. BTW, this ticket is referenced in inline documentation for wp_insert_post: http://core.trac.wordpress.org/ticket/9084 It's closed as 'fixed'. Not the same issue or not a real fix?

@blepoxp
15 years ago

This fixes it for the reported solution.

#13 @blepoxp
15 years ago

  • Keywords has-patch needs-testing added; needs-patch removed

I think the bug only happened when a filter has changed the status from publish to draft. If this is the case, my patch should fix the problem. In a little bit of a rush to change locations right now so I can test more thoroughly later tonight for unintended consequences... i think this should do it though.

#14 @blepoxp
15 years ago

  • Keywords needs-testing removed

I did a little more testing, I think this is the best solution. The code was always taking the final post status into account correctly. The problem was that it also assumed that if $_POST[ 'publish' ] was set, the status would not be draft.

I tested it by placing the following code in twentyten's functions.php and changing the status. It works correctly for all possible stati:

function change_status( $data ) {
	$data['post_status'] = 'publish';
	return $data;
}
add_filter( 'wp_insert_post_data', 'change_status' );

#15 @nacin
15 years ago

  • Milestone changed from 3.0 to 3.1

#16 @scribu
14 years ago

  • Milestone changed from Awaiting Triage to 3.1

#17 @scribu
14 years ago

  • Keywords needs-refresh added

I can't figure out which post.php this patch refers to.

Please read: http://codex.wordpress.org/Reporting_Bugs#Patch_Writing_Guidelines

Also, it probably needs a refresh.

#18 @nacin
14 years ago

  • Milestone changed from 3.1 to Future Release

@kawauso
13 years ago

#19 @kawauso
13 years ago

  • Keywords needs-refresh removed

#20 @valeriosza
11 years ago

  • Keywords needs-refresh added

#21 @helen
11 years ago

  • Keywords needs-refresh removed

Patch applies fine.

#22 @nacin
11 years ago

  • Component changed from Administration to Posts, Post Types
  • Focuses administration added

#23 @chriscct7
9 years ago

  • Keywords needs-refresh added

#24 @desrosj
2 years ago

  • Keywords good-first-bug changes-requested added
  • Milestone set to Future Release

I found this ticket going through a list of ones missing a milestone. A lot has changed since this was created, so I've done some testing to figure out the current state of this bug.

With the block editor, this problem does not exist. When the response to a save request is received, the editor displays the correct message and adjusts the interface to reflect the post status as filtered and set.

With the Classic Editor, this issue still persists.

11207.2.diff would fix a scenario where the post status is switched from publish (or any other status) to draft, but not the other way around because $_POST['publish'] would not be set.

Since this only affects the Classic Editor, I'm going to mark this low priority. If someone is willing to write a patch, it's reasonable to include.

#25 follow-up: @desrosj
2 years ago

  • Owner bsamrajni deleted
  • Status changed from accepted to assigned

Resetting ownership since it has been 12 years since this one was claimed. May help other contributors feel empowered to grab this one to patch.

@azouamauriac
2 years ago

#26 @azouamauriac
2 years ago

  • Keywords needs-testing added; needs-refresh changes-requested removed

#27 in reply to: ↑ 25 @harryngwa
12 months ago

Hello, I'm a new contributor trying to get my feet wet. Can I work on this?

Replying to desrosj:

Resetting ownership since it has been 12 years since this one was claimed. May help other contributors feel empowered to grab this one to patch.

This ticket was mentioned in PR #6812 on WordPress/wordpress-develop by @freibergergarcia.


6 months ago
#28

Display the correct message when a post_status is changed by a filter, for example, wp_insert_post_data

Trac ticket: https://core.trac.wordpress.org/ticket/11207

#29 @freibergergarcia
6 months ago

I picked this to work on as part of Contributor Day - WCEU 2024. The issue was manually tested, a filter was applied, and it worked as expected.

https://github.com/WordPress/wordpress-develop/pull/6812

What are the next steps @desrosj?

#30 @desrosj
6 months ago

  • Owner set to desrosj
  • Status changed from assigned to reviewing

#31 @desrosj
6 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 58406:

Posts/Post Types: Display the correct message when post status is filtered on save.

This prevents the display of an inaccurate message when the wp_insert_post_data filter is used to change the status of a post while saving. This bug was only present when using the Classic Editor.

The previous code incorrectly assumed that a filter would never change a post’s status to draft, resulting in a “Post published.” message instead of “Post draft updated.”.

Props freibergergarcia, sirzooro, hakre, blepoxp, scribu, kawauso.
Fixes #11207.

#32 @desrosj
6 months ago

  • Keywords needs-testing removed
  • Milestone changed from Future Release to 6.6

@desrosj commented on PR #6812:


6 months ago
#33

Merged in https://core.trac.wordpress.org/changeset/58406. Thanks @freibergergarcia!

#34 @azouamauriac
6 months ago

@desrosj out of curiosity, any reason not listing me in props?

#35 @desrosj
6 months ago

Hi @azouamauriac,

It was unintentional 100% and a mistake. My apologies! Thanks for raising your hand so I can correct that. I've gone and added your props for the commit manually and is now showing on your profile, and you'll be included in the 6.6 credits as well!

Note: See TracTickets for help on using tickets.