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

WordPress Trac noreply at wordpress.org
Sat Jul 25 23:31:59 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 SergeyBiryukov):

 Replying to [comment:12 borekb]:
 > (To be fair to db.php, it's not really its problem; there should be only
 one DB driver so it's probably OK to allow just one plugin to occupy it.
 The problem is the lack of other extensibility points in this area, so
 things that are ''not'' DB drivers like various debug plugins or our
 VersionPress often resort to it just because there's no other easy way.
 See also the IRC discussion linked in [comment:2 comment 2].)

 This works for me in a plugin without using the `db.php` drop-in:
 {{{
 class wpdb_after_query extends wpdb {

         function query( $query ) {
                 $return_val = parent::query( $query );

                 if ( false !== $return_val ) {
                         /**
                          * Fires after the query is executed.
                          *
                          * @param string $query Database query.
                          * @param wpdb   $wpdb  wpdb instance.
                          */
                         do_action( 'after_query', $query, $this );
                 }

                 return $return_val;
         }

 }

 function wp29710_replace_wpdb() {
         global $wpdb;

         $wpdb = new wpdb_after_query( DB_USER, DB_PASSWORD, DB_NAME,
 DB_HOST );

         wp_set_wpdb_vars();
 }
 add_action( 'plugins_loaded', 'wp29710_replace_wpdb' );
 }}}

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


More information about the wp-trac mailing list