Opened 14 years ago
Closed 11 years ago
#15847 closed enhancement (wontfix)
Add filter in wp_insert_attachment for $data
Reported by: | pampfelimetten | Owned by: | rhundesign |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.0.3 |
Component: | Posts, Post Types | Keywords: | |
Focuses: | Cc: |
Description
Pretty self-explanatory, patch attached.
Attachments (1)
Change History (11)
#2
@
14 years ago
What is the filter going to be used for?
Without the context of why you want the filter it is hard to know if this is the right filter to add!
#3
follow-up:
↓ 4
@
14 years ago
@scribu: I basically looked at wp_insert_post, where it uses the same order:
$data = compact( array(...); $data = apply_filters('wp_insert_post_data', $data, $postarr); $data = stripslashes_deep( $data );
@westi: On the one hand, there's a similar filter in wp_insert_post, but not in wp_insert_attachment. That's odd, I can't see a reason for that.
Particularly, I want to check the post_name field of the attachment before it get's entered in the db. The reason is, I want to avoid numeric-only post_names, as it interferes with my non-standard permalinks (%post_id% only). I've been looking into all the functions, and there are no hooks at all to do that, so I figured it would be easiest to just copy the behaviour of wp_insert_post and modifiy the data there before it gets handed to the sanitize functions.
#4
in reply to:
↑ 3
@
14 years ago
- Milestone changed from Awaiting Review to Future Release
Replying to pampfelimetten:
@scribu: I basically looked at wp_insert_post, where it uses the same order:
$data = compact( array(...); $data = apply_filters('wp_insert_post_data', $data, $postarr); $data = stripslashes_deep( $data );@westi: On the one hand, there's a similar filter in wp_insert_post, but not in wp_insert_attachment. That's odd, I can't see a reason for that.
Particularly, I want to check the post_name field of the attachment before it get's entered in the db. The reason is, I want to avoid numeric-only post_names, as it interferes with my non-standard permalinks (%post_id% only). I've been looking into all the functions, and there are no hooks at all to do that, so I figured it would be easiest to just copy the behaviour of wp_insert_post and modifiy the data there before it gets handed to the sanitize functions.
Ok.
So a filter here would work for you.
But maybe a more generic filter on all post_names would be better and easier for you to use?
#5
follow-up:
↓ 6
@
14 years ago
@westi: Well, as my main goal is to modify the generated slug, a filter in the function wp_unique_post_slug (wp-includes/post.php) would probably be the best solution, but I'm not sure where the right place to put it would be.
#6
in reply to:
↑ 5
;
follow-up:
↓ 7
@
14 years ago
Replying to pampfelimetten:
@westi: Well, as my main goal is to modify the generated slug, a filter in the function wp_unique_post_slug (wp-includes/post.php) would probably be the best solution, but I'm not sure where the right place to put it would be.
3.1 has 3 filters for this :-)
#7
in reply to:
↑ 6
@
14 years ago
Replying to westi:
3.1 has 3 filters for this :-)
Oh great =)
In that case, my personal reason for the ticket is resolved.
In general, I still think that the filter has some validity, as there's no reason for the difference between wp_insert_post and wp_insert_attachment. So it's up to you core devs to decide if you want to close it or include it.
Thanks for the fast feedback!
#8
@
14 years ago
Just in case anybody wants to do the same as me, this is the code I now use with the 3.1 version:
function cba_wp_unique_post_slug_is_bad_attachment_slug ($false, $slug) { if(is_numeric($slug)) return true; else return false; }; add_filter( 'wp_unique_post_slug_is_bad_attachment_slug', 'cba_wp_unique_post_slug_is_bad_attachment_slug', '10', 2);
Why did you place the filter exactly before stripslashes_deep()?