[wp-trac] [WordPress Trac] #29710: Add hooks to wpdb's insert(), update(), delete() and similar methods

WordPress Trac noreply at wordpress.org
Tue Jul 28 01:48:55 UTC 2015


#29710: Add hooks to wpdb's insert(), update(), delete() and similar methods
-------------------------+------------------------------
 Reporter:  borekb       |       Owner:
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  Database     |     Version:  2.5
 Severity:  normal       |  Resolution:
 Keywords:  2nd-opinion  |     Focuses:
-------------------------+------------------------------

Comment (by dd32):

 Replying to [comment:17 borekb]:
 > That would still allow only one plugin / drop-in to hook into the query
 if I understand it correctly. We tried to take your idea a bit further and
 replace inheritance with composition by creating a proxy class and
 replacing `$wpdb` with that. It worked but there were still some issues
 with that approach:

 I would do exactly that, I don't realistically think these hooks this low
 are useful to most people (And won't really work with DB dropins - some of
 them may need to use their own method), any changes to items should be
 hookable higher up - and if they're not, tickets should be opened to add
 hooks to those locations.

 [attachment:wpdb-injector.php] is a example of a magic-based class that
 can wrap `$wpdb` no matter what dropin is in use, transparently acting as
 a proxy, any future methods or args added just work, and well.. it works
 (I just did it as a mu-plugin, but it'll just as happily work in a regular
 plugin).
 Other plugins could come along and register the exact same type of class
 (with a different classname..) and both plugins would happily co-exist,
 one plugin proxying the other plugin which proxies the DB connection.
 This only intercepts direct function calls to `$wpdb`, it doesn't catch
 internal `$wpdb` calls (ie. update() calling prepare() / query()

--
Ticket URL: <https://core.trac.wordpress.org/ticket/29710#comment:21>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list