Opened 12 years ago
Closed 11 years ago
#2351 closed enhancement (fixed)
Forum post_status switch from wpdb->update to wp_update_post
Reported by: | nofearinc | Owned by: | johnjamesjacoby |
---|---|---|---|
Milestone: | 2.4 | Priority: | normal |
Severity: | normal | Version: | 2.1 |
Component: | Tools - Code Improvements | Keywords: | has-patch |
Cc: |
Description
Forum post_status
update has been applied with $wpdb->user which is not the best practice as some conditionals are being ignored that normally happen in wp_update_post
. Additionally, wp_update_post is used in several other areas of the website.
The transient switch is also turned off now as it is called by wp_insert_post
which is triggered at the end of wp_update_post
.
Attachments (3)
Change History (13)
#2
@
11 years ago
Can you explain what conditionals are being skipped, and what the bug is?
IIRC, the $wpdb->update() approach is used by design to avoid the additional overhead and potential for filter recursion caused by running through wp_update_post(), wp_insert_post(), et all.
#3
@
11 years ago
Two things:
First off, I know update()
is faster - it's called from wp_update_post()
as well. However, there are lots of filters and actions on the way of wp_update_post, such as:
- filter wp_insert_post_empty_content
- function sanitize_title has filters
- filter wp_insert_post_parent
- function wp_unique_post_slug has various filters
- filter wp_insert_post_data
- action pre_post_update
- clean_post_cache - function that takes care of caching + various actions
I'm also not sure that save_post and wp_insert_post are fired in wpdb->update (I believe they're skipped).
I'm personally using some of these in WP plugins to take care of additional meta data, dynamic template attachment 'on the fly', tracking (for stats) in other tables and translating Cyrillic symbols to Latin.
Second, there are other wp_update_post()
calls in the plugin and if you disagree with the first point, then probably they should also be translated to update() calls for consistency.
@
11 years ago
Relpaces all $wpdb->update() usages, for testing actions/filters, and transition_post_status() changes
#4
@
11 years ago
- Milestone changed from Awaiting Review to 2.4
In the patch attached, I'm worried that wp_transition_post_status() is going to get called too late. It uses wp_update_post(), but I'm still not convinced it's the correct approach without doing extensive testing.
#5
follow-up:
↓ 6
@
11 years ago
I'm worried that wp_transition_post_status() is going to get called too late
Do you think that this would be a problem? In the original code it's called after the update, I'm not sure how late would it be when migrating to wp_update_post
- can you think of a problematic use case as I've been using this for a few days now with no issues so far?
#6
in reply to:
↑ 5
@
11 years ago
Replying to nofearinc:
Do you think that this would be a problem? In the original code it's called after the update, I'm not sure how late would it be when migrating to
wp_update_post
- can you think of a problematic use case as I've been using this for a few days now with no issues so far?
It might be, yes. We specifically pass the old visibility value into those functions, and use it when we manually call wp_transition_post_status(). I think this is because we're already likely calling wp_update_post() farther up the stack, and are relying on the original post_status being passed in.
Migrate from wpdb->update to wp_update_post