Make WordPress Core

Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#15023 closed enhancement (wontfix)

wpdb Filters

Reported by: sc0ttkclark's profile sc0ttkclark Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.1
Component: Plugins Keywords:
Focuses: Cc:

Description

Plugins wishing to hook into wpdb would benefit from having a few additional filters added. Right now, the only filter running is on query, which absolutely requires use of complex regex or a mysql parser to figure out what's going on.

Furthermore, I believe adding filters to the following functions would be useful for adding additional database support apart from MySQL without much code rewriting.

Existing Filter:

  • wpdb::query 'query' (normal apply_filters) [Filter the query and rewrite if necessary]

New / Updated Filters:

(note, new filters use _exec at the end to differentiate from format original filter uses for 'query')

  • wpdb::query 'query' (use apply_filters_ref_array and pass through &$this) [Filter the query and rewrite if necessary]
  • wpdb::query 'query_exec' (use apply_filters_ref_array and pass through &$this) [Same as 'query' except it allows for a plugin to intercept the function and perform it's operations through other DB functions vs forcing mysql_query]
  • wpdb::_insert_replace_helper 'insert_replace_exec' (use apply_filters_ref_array and pass through &$this) [Allows for a plugin to intercept the function and perform it's operations through other DB functions vs forcing mysql_query] {This function is used by wpdb::insert and wpdb::replace}
  • wpdb::update 'update_exec' (use apply_filters_ref_array and pass through &$this) [Allows for a plugin to intercept the function and perform it's operations through other DB functions vs forcing mysql_query]

Attachments (1)

wp-db-filters.patch (1.9 KB) - added by sc0ttkclark 16 years ago.
Initial Patch including the new / updated filters

Download all attachments as: .zip

Change History (7)

@sc0ttkclark
16 years ago

Initial Patch including the new / updated filters

#1 follow-up: @nacin
16 years ago

Wouldn't it be more effective to extend wpdb if you need such deep integration at the database level?

#2 @sc0ttkclark
16 years ago

Yes, that would also be possible. But perhaps some of the adjustments here have merit, if not intercepting then perhaps filtering the values in wpdb::_insert_replace_helper and wpdb::update?

#3 @sc0ttkclark
16 years ago

Also, the adjustment to the wpdb::query 'query' filter would also pass &$this, which would be beneficial too.

#4 in reply to: ↑ 1 @scribu
16 years ago

Replying to nacin:

Wouldn't it be more effective to extend wpdb if you need such deep integration at the database level?

I agree. Regular plugins shouldn't be messing with this. Don't really see the point of the existing filter either.

#5 @sc0ttkclark
16 years ago

  • Resolution set to wontfix
  • Status changed from new to closed

Gotcha, this was just going forward using the understanding that filtering was useful in this. If the recommendation is to extend wpdb then this ticket can be closed.

#6 @nacin
16 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.