Title: Overriding Method
Last modified: August 18, 2016

---

# Overriding Method

 *  [goxu](https://wordpress.org/support/users/goxu/)
 * (@goxu)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/overriding-method/)
 * Hi all,
 * According to this page,
 * [http://codex.wordpress.org/Pluggable_Functions](http://codex.wordpress.org/Pluggable_Functions)
 * if I want to replace a function which is decleared in the wordpress oore files,
   I need to do this.
 * `if(!function_exists('wp-replacig-function')) {
    function wp-replacig-function(){}}
 * So, if the function is in a class, I mean if it is a method, how can I replace
   it? Actually I’d like to override the only wpdb method.
 * Do I need to redeclare the entire class?

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Thread Starter [goxu](https://wordpress.org/support/users/goxu/)
 * (@goxu)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/overriding-method/#post-504322)
 * Could anybody help please?
 *  [Mark Jaquith](https://wordpress.org/support/users/markjaquith/)
 * (@markjaquith)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/overriding-method/#post-504403)
 * This requires WP 2.1
 * You provide `db.php` and place it in `wp-content` (NOT plugins)
 * `db.php` has something like this:
 * `
    <?php class my_wpdb extends wpdb { function method_you_want_to_replace($foo){//
   yourcode } } $wpdb = new my_wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST); ?>
 * At least, that’s how it should work in theory… this is new for 2.1
 * Also note that if it’s query filtering that you’re looking for, there is a new`
   query` filter that gives you access to that (that’s in 2.1+ and 2.0.6+)
 *  Thread Starter [goxu](https://wordpress.org/support/users/goxu/)
 * (@goxu)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/overriding-method/#post-504419)
 * Thank you markjaquith for your responce.
 * What kind of change was made in v2.1 in order to make it work?
 * What I’d like to do is just changing this,
 * `$this->select($dbname);`
 * to,
 * `mysql_query("SET NAMES utf8", $this->dbh);
    $this->select($dbname);
 * in the wpdb funtion of the wp-db.php.
 * Could this be done differently for the older versions? Is it not possible to 
   do it with a single plugin?
 * Sorry if you meant to suggest the use of query filter for this since I’m not 
   familiar with it.
 *  [Mark Jaquith](https://wordpress.org/support/users/markjaquith/)
 * (@markjaquith)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/overriding-method/#post-504421)
 * See the discussion here:
 * [http://trac.wordpress.org/ticket/2721](http://trac.wordpress.org/ticket/2721)
 * Query filter doesn’t apply to you here… didn’t know what you wanted to do, so
   I just threw it out there.
 * I don’t think this can be easily done in WP 2.0.x, and I don’t think it can be
   done via a plugin, as you need to hook in before plugins are loaded.
 *  Thread Starter [goxu](https://wordpress.org/support/users/goxu/)
 * (@goxu)
 * [19 years, 4 months ago](https://wordpress.org/support/topic/overriding-method/#post-504423)
 * I really appreciate it, markjaquith.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Overriding Method’ is closed to new replies.

## Tags

 * [class](https://wordpress.org/support/topic-tag/class/)
 * [method](https://wordpress.org/support/topic-tag/method/)
 * [plugin-development](https://wordpress.org/support/topic-tag/plugin-development/)
 * [WPadvanced](https://wordpress.org/support/topic-tag/wpadvanced/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 5 replies
 * 2 participants
 * Last reply from: [goxu](https://wordpress.org/support/users/goxu/)
 * Last activity: [19 years, 4 months ago](https://wordpress.org/support/topic/overriding-method/#post-504423)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
