• Hi all,

    According to this page,

    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

    (@goxu)

    Could anybody help please?

    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

    (@goxu)

    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.

    See the discussion here:

    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

    (@goxu)

    I really appreciate it, markjaquith.

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