Make WordPress Core

Opened 16 years ago

Closed 15 years ago

#9073 closed enhancement (wontfix)

wp_insert_post_data should allow to modify categories and tags too

Reported by: sirzooro's profile sirzooro Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.7
Component: General Keywords: has-patch needs-testing
Focuses: Cc:

Description

It will be good to pass categories and tags to wp_insert_post_data filter. I wrote plugin which checks how many tags and categories are used, and I had to access POST data directly to do this. With this change, my plugin could access this data in easier way. This change will also open way to write new kinds of plugins, which can change categories and tags just before post is saved.

Attachments (1)

post.php.diff (1.2 KB) - added by sirzooro 15 years ago.

Download all attachments as: .zip

Change History (15)

#1 @filosofo
16 years ago

If the post categories are set, they are passed to wp_insert_post_data. Do something like this to access them:

add_filter('wp_insert_post_data', 'my_filter_callback', 10, 2);
function my_filter_callback($data = null, $arguments = null) {

// if they're defined, the categories are $arguments['post_category'];
// tags would be $arguments['tags_input'];
 

return $data;
}

However, that will allow you to change only core post data, not the categories or tags themselves. To do that, use the "wp_insert_post" filter.

#2 @sirzooro
16 years ago

Thanks. This is exactly what I was looking for.

I leave this ticket open, so you can either implement this enhancement in the future, or you can close it.

#3 @filosofo
16 years ago

  • Milestone 2.8 deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Since you can accomplish what you want with existing filters, let's close it.

#4 follow-up: @sirzooro
16 years ago

  • Keywords needs-patch added
  • Milestone set to 2.9
  • Resolution wontfix deleted
  • Status changed from closed to reopened

I would like to extend my plugin (WyPiekacz) again. This time I want to add options to automatically enforce rules when post is published - namely remove extra links, tags and categories. I can do this for links using this filter, but cannot do this for tags and categories. Therefore I am reopening this ticket.

#5 @sirzooro
16 years ago

  • Summary changed from wp_insert_post_data should have access to categories and tags too to wp_insert_post_data should allow to modify categories and tags too

#6 in reply to: ↑ 4 @filosofo
16 years ago

Replying to sirzooro:

I would like to extend my plugin (WyPiekacz) again. This time I want to add options to automatically enforce rules when post is published - namely remove extra links, tags and categories. I can do this for links using this filter, but cannot do this for tags and categories. Therefore I am reopening this ticket.

Could you please provide a specific example of something that you are unable to do with the current filters?

#7 @sirzooro
16 years ago

I want to check how many tags post have, when post is saved. If there will be too many (e.g. 15, when limit is set to 10), I would like to extra ones (in this case remove last 5). I cannot do this with wp_insert_post_data filter - it allows to count tags, but does not allow to modify them. The same applies for categories and custom taxonomies too.

I know that it is possible to modify $_POST array directly (e.g. in init hook, or even earlier), but this approach is a bit tricky. So I would like to see easier method.

#8 @ryan
15 years ago

  • Milestone changed from 2.9 to Future Release

#9 @sirzooro
15 years ago

  • Keywords has-patch needs-testing added; needs-patch removed
  • Milestone changed from Future Release to 2.9

Attached patch adds three filters to wp_insert_post(): wp_insert_post_category, wp_insert_post_tags and wp_insert_post_tax. They can be used by plugins to modify categories, tags (passed in pre-WP2.8 way) and taxonomies.

@sirzooro
15 years ago

#10 @ryan
15 years ago

If there's no regression this should be milestoned for Future Release.

#11 @sirzooro
15 years ago

Future Release sounds like "maybe sometimes, maybe never". If now it is too late to include it in 2.9, move it to 3.0 :)

#12 @filosofo
15 years ago

It used to be that tickets with patches went to the next version, and "Future" was for those without patches.

I think that's a good policy, because it somewhat helps to limit ticket rot. If you're moving a ticket with patch to "Future", it's probably better just to close it as "wontfix" or the like.

#13 @ryan
15 years ago

  • Milestone changed from 2.9 to 3.0

#14 @scribu
15 years ago

  • Milestone 3.0 deleted
  • Resolution set to wontfix
  • Status changed from reopened to closed

-1 for several reasons:

  • filosofo's first comment
  • custom taxonomies are left out
  • there's a new filter for limiting the inserted terms: #10943
Note: See TracTickets for help on using tickets.