Make WordPress Core

Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#3458 closed enhancement (fixed)

Filter cat_ID when a new category is created

Reported by: donncha's profile donncha Owned by: markjaquith's profile markjaquith
Milestone: 2.1 Priority: normal
Severity: normal Version: 2.1
Component: Administration Keywords:
Focuses: Cc:

Description

This patch adds a filter to wp_insert_category() to modify the cat_ID just before returning it.

Attachments (1)

patch.diff (298 bytes) - added by donncha 17 years ago.

Download all attachments as: .zip

Change History (9)

@donncha
17 years ago

#1 @markjaquith
17 years ago

  • Owner changed from anonymous to markjaquith
  • Status changed from new to assigned

Is the assumption that if someone wanted to change the cat_ID, they'd make the appropriate UPDATE query? Why should the cat_ID matter (such that you'd want to change it)?

#2 @Viper007Bond
17 years ago

  • Version set to 2.1

Yeah, I see no reason why one would need to change the ID either. It's all used internally and you can encounter major problems if you change them.

#3 @donncha
17 years ago

This filter is used in WPMU to modify the cat_ID so it matches a cat_ID in a global categories table. On a regular wordpress install it could be used to sync the cat_ID in the categories table with a tag ID elsewhere.

#4 @markjaquith
17 years ago

Fancy. :-) In it goes.

#5 @markjaquith
17 years ago

Actually, slight issue. Look at the lines above it. Don't you think it would be better if the cat_ID filter were called on line 135, before all those other actions are called on the OLD id?

#6 @donncha
17 years ago

I thought about that and reasoned that those actions should happen on the unmodified cat_ID because that's what's in the db, but that makes no sense. It's probably better to have the new filter work it's magic before the actions so feel free to bump it up higher in the code!

#7 @markjaquith
17 years ago

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

(In [4638]) cat_id_filter from Donncha. fixes #3458

#8 @markjaquith
17 years ago

I gave it a second param... the $update flag, which will be TRUE or FALSE (TRUE representing a pre-existing category). If $update is false, you don't need to bother checking for post2cat entries to update.

I gave some inline notes as well, as this is a pretty powerful hook that could really mess things up if not fully understood.

Note: See TracTickets for help on using tickets.