Overriding Method (6 posts)

  1. goxu
    Posted 8 years ago #

    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?

  2. goxu
    Posted 8 years ago #

    Could anybody help please?

  3. Mark Jaquith
    WordPress Lead Dev
    Posted 8 years ago #

    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+)

  4. goxu
    Posted 8 years ago #

    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.

  5. Mark Jaquith
    WordPress Lead Dev
    Posted 8 years ago #

    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.

  6. goxu
    Posted 8 years ago #

    I really appreciate it, markjaquith.

Topic Closed

This topic has been closed to new replies.

About this Topic