Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#15023 closed enhancement (wontfix)

wpdb Filters

Reported by: sc0ttkclark Owned by:
Priority: normal Milestone:
Component: Plugins Version: 3.1
Severity: normal Keywords:
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 3 years ago.
Initial Patch including the new / updated filters

Download all attachments as: .zip

Change History (7)

Initial Patch including the new / updated filters

comment:1 follow-up: ↓ 4   nacin3 years ago

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

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?

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

comment:4 in reply to: ↑ 1   scribu3 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.

  • 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.

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