Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Possible Duplicate:
Stackoverflow type of badge plugin giving warnings in Wordpress 3.5

I'm getting an error on my site that says:

Warning: Missing argument 2 for wpdb::prepare(), called in /home/blahblahblah/public_html/wp-content/mu-plugins/domain-mapping.php on line 489 and defined in /home/blahblahblah/public_html/wp-includes/wp-db.php on line 990

It's my understanding this is because now in WP 3.5 wpdb::prepare() requires you to use an array. Here is the offending code on line 489 of domain-mapping.php:

$olddomain = $this->db->get_var( $this->db->prepare( "SELECT option_value FROM {$this->db->options} WHERE option_name='siteurl' LIMIT 1 /* domain mapping */" ) );

How can I change this to be an array so it stops causing errors?

In this thread several other people had similar but different problems. There are fixes posted but I'm having trouble translating it into a solution for me.

If it helps to provide context here is the code for the whole function:

    function swap_mapped_url($url, $path, $plugin = false) {
    global $current_blog, $current_site, $mapped_id;

    // To reduce the number of database queries, save the results the first time we encounter each blog ID.
    static $swapped_url = array();

    if ( !isset( $swapped_url[ $this->db->blogid ] ) ) {
        $s = $this->db->suppress_errors();
        $newdomain = $this->db->get_var( $this->db->prepare( "SELECT domain FROM {$this->dmt} WHERE domain = %s AND blog_id = %d LIMIT 1 /* domain mapping */", preg_replace( "/^www\./", "", $_SERVER[ 'HTTP_HOST' ] ), $this->db->blogid ) );
        //$olddomain = str_replace($path, '', $url);
        $olddomain = $this->db->get_var( $this->db->prepare( "SELECT option_value FROM {$this->db->options} WHERE option_name='siteurl' LIMIT 1 /* domain mapping */" ) );

        if ( empty( $domain ) ) {
            $domain = $this->db->get_var( $this->db->prepare( "SELECT domain FROM {$this->dmt} WHERE blog_id = %d /* domain mapping */", $this->db->blogid ) );
        }

        $this->db->suppress_errors( $s );
        $protocol = ( 'on' == strtolower( $_SERVER['HTTPS' ] ) ) ? 'https://' : 'http://';
        if ( $domain ) {

            $innerurl = trailingslashit( $protocol . $domain . $current_site->path );
            $newurl = str_replace($olddomain, $innerurl, $url);
            $swapped_url[ $this->db->blogid ] = array($olddomain, $innerurl);
            $url = $newurl;
        } else {
            $swapped_url[ $this->db->blogid ] = false;
        }
    } elseif ( $swapped_url[ $this->db->blogid ] !== FALSE) {
        $olddomain = $swapped_url[ $this->db->blogid ][0];
        $url = str_replace($olddomain, $swapped_url[ $this->db->blogid ][1], $url);
    }

    return $url;


}
share|improve this question

marked as duplicate by toscho Jan 3 '13 at 3:15

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

add comment

1 Answer 1

prepare has always required two arguments, it just didn't throw an error when used incorrectly until 3.5.

Basically, the use of prepare in this case is not doing anything. Since you're not passing potentially unsafe data to the query, you can remove it entirely to get rid of the error and just pass your query directly to get_var.

$olddomain = $this->db->get_var( "SELECT option_value FROM {$this->db->options} WHERE option_name='siteurl' LIMIT 1" );

See the entry in wpdb Protect Queries Against SQL Injection Attacks for correct use of prepare.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.