WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 2 years ago

#18624 closed defect (bug) (fixed)

wpmu_update_blogs_date() should not be called on private_to_published

Reported by: mdawaffe Owned by: nacin
Milestone: 3.3 Priority: normal
Severity: normal Version: 3.2.1
Component: Multisite Keywords: has-patch
Focuses: Cc:

Description

http://core.trac.wordpress.org/browser/trunk/wp-includes/ms-default-filters.php?rev=16213#L39

add_action( 'private_to_published', 'wpmu_update_blogs_date' );
...
add_action( 'publish_post', 'wpmu_update_blogs_date' );

Those two add_action() calls are redundant. Whenever private_to_published is called, publish_post is also called.

Am I missing something?

Trivial patch attached.

Attachments (3)

18624.diff (648 bytes) - added by mdawaffe 3 years ago.
18624.2.diff (1.9 KB) - added by ryan 2 years ago.
Get fancy
18624.3.diff (1.9 KB) - added by ryan 2 years ago.

Download all attachments as: .zip

Change History (10)

mdawaffe3 years ago

comment:1 follow-up: nacin3 years ago

  • Keywords dev-feedback removed
  • Milestone changed from Awaiting Review to 3.3

Technically, private_to_published will fire for all posts, while publish_post will only fire on posts.

The latter is most certainly proper behavior. private_to_published has been considered an obsolete hook for many versions, well before custom post types. I'm pretty sure well before we actually had post types, when it was still post_status = static. So it's probably just an odd MU vestige.

Testing and committing. Thanks.

comment:2 nacin3 years ago

No way the hook on publish_phone would be needed either.

comment:3 nacin3 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In [18657]:

Update blog last_updated time only on publish_post. Both private_to_published and publish_phone are overly broad and otherwise redundant. props mdawaffe, fixes #18624.

comment:4 in reply to: ↑ 1 mdawaffe3 years ago

Replying to nacin:

Technically, private_to_published will fire for all posts, while publish_post will only fire on posts.

Ah. Good point. Then both hooks do something a little different.

Each time a post row of type post is saved in the publish state (even if it already was published), publish_post is called.

Each time a post row of any type transitions away from non-published to published, private_to_published is called.

So, technically, this change may break things. It's possible wpmu_update_blogs_date should be called when publishing custom post types.

comment:5 nacin3 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

So, technically, this change may break things. It's possible wpmu_update_blogs_date should be called when publishing custom post types.

Maybe, maybe not. The current functionality applies only to posts. I imagine that was the intention, and generally that's what a last updated date would signify. The only exception is that it also applies to any other post type but only when it goes from private to publish. (Well, I'm wrong about that -- more in a moment.) That is a side effect from how that hook has evolved over time.

Interesting, I thought that private_to_published was solely a private to publish hook, but I misread the code. Unfortunately there's no corresponding hook for that kind of change.

I'd probably support a post_changed_to_{$new_status} hook, or something to that effect, that way we could do post_changed_to_publish. Currently you'd have to hook into transition_post_status and do checks on new_status and old_status. It's actually the most common use case I've used one of those three hooks for.

Sidenote: I like how I was able to say "all posts" versus "[only] posts" and you understood I meant post types. Man, that's confusing. :-)

Re-opening, since this does break compat, as it *has* been applied to all post types until now.

ryan2 years ago

Get fancy

comment:6 ryan2 years ago

Patch adds a handler that updates the blog date when a post is published or when a published post is changed (saved or unpublished). Skips post types that cannot be queried publicly (should probably change this to !public since pages are publicly_queryable = false).

ryan2 years ago

comment:7 ryan2 years ago

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

In [19129]:

Update the blog date whenever a pubic post type is published or changed after being published. fixes #18624

Note: See TracTickets for help on using tickets.