PHP Warning: Missing argument 2 for wpdb::prepare() WPML Plugin

Suddenly I am getting an error on a specific backend page on my wordpress project:

Warning: Missing argument 2 for wpdb::prepare(), called in .../wp-content/plugins/wpml-media/inc/wpml_media.class.php on line 463 and defined in .../wp-includes/wp-db.php on line 992

Which would be:

wpml_media.class.php

// get language of their parents
if(!empty($missing_langs)){     
    $results = $wpdb->get_results($wpdb->prepare("
        SELECT p.ID, t.language_code 
        FROM {$wpdb->posts} p JOIN {$wpdb->prefix}icl_translations t ON p.ID = t.element_id AND t.element_type = CONCAT('post_', p.post_type)
        WHERE p.ID IN(".join(',', $missing_langs).")
    "));
    foreach($results as $row){
        $parent_langs[$row->ID] = $row->language_code;
    }
}

and wp-db.php

function prepare( $query, $args ) {
    if ( is_null( $query ) )
        return;

    $args = func_get_args();
    array_shift( $args );
    // If args were passed as an array (as in vsprintf), move them up
    if ( isset( $args[0] ) && is_array($args[0]) )
        $args = $args[0];
    $query = str_replace( "'%s'", '%s', $query ); // in case someone mistakenly already singlequoted it
    $query = str_replace( '"%s"', '%s', $query ); // doublequote unquoting
    $query = preg_replace( '|(?<!%)%f|' , '%F', $query ); // Force floats to be locale unaware
    $query = preg_replace( '|(?<!%)%s|', "'%s'", $query ); // quote the strings, avoiding escaped strings like %%s
    array_walk( $args, array( $this, 'escape_by_ref' ) );
    return @vsprintf( $query, $args );
}

I have no clue whats happening here, any ideas? Unfortunately the author's support has expired.

Thanks

Answers


$wpdb->prepare needs at least two params http://codex.wordpress.org/Class_Reference/wpdb#Protect_Queries_Against_SQL_Injection_Attacks

try something like that:

$wpdb->prepare("
        SELECT p.ID, t.language_code 
        FROM {$wpdb->posts} p JOIN {$wpdb->prefix}icl_translations t ON p.ID = t.element_id AND t.element_type = CONCAT('post_', p.post_type)
        WHERE p.ID IN(%s)", join(',', $missing_langs))

There's some more info on this problem here. Basically, don't panic because it's just a warning so nothing is going to actually break.

If you're looking to modify the wpml-media plugin to get rid of this error, the developer info in the above link should help. If you just want the warning to go away, then I quote:

First, if you’re a user and you want to get rid of these errors, you should turn off the displaying of errors in PHP. There are many ways to do this, such as in php.ini, .htaccess, etc. For this, you can just put this in wp-config.php. (Note that hiding errors on production sites is good practice anyway.)

@ini_set('display_errors', 0);

Need Your Help

Detecting changes in SQL Server 2000 table data

sql-server hash sql-server-2000 checksum

I have a periodic check of a certain query (which by the way includes multiple tables) to add informational messages to the user if something has changed since the last check (once a day).

Most efficient language to implement tensor factorization for Web Application

python c++ mysql django large-data

I have implemented Tensor Factorization Algorithm in Matlab. But, actually, I need to use it in Web Application.