Support » Developing with WordPress » Overriding Method

  • Hi all,

    According to this page,

    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)
  • Could anybody help please?

    Mark Jaquith


    WordPress Lead Dev

    This requires WP 2.1

    You provide db.php and place it in wp-content (NOT plugins)

    db.php has something like this:

    class my_wpdb extends wpdb {
    function method_you_want_to_replace($foo) {
    $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+)

    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,



    mysql_query("SET NAMES utf8", $this->dbh);

    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


    WordPress Lead Dev

    See the discussion here:

    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.

    I really appreciate it, markjaquith.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Overriding Method’ is closed to new replies.