Sharebar : Missing argument 2 for wpdb::prepare()

You can remove the " Missing argument 2 for wpdb::prepare() " caused by the Sharebar Plugin just by editing two lines in the plugin file.

Recent update of WordPress 3.5 has caused a lot of websites to show this warning “PHP Warning: Missing argument 2 for wpdb::prepare().”

Don’t worry if you got this error, its just a new warning introduced in WordPress version 3.5 for more security. You can ignore this warning just by turning off the displaying of errors in PHP. Just put the code below in your wp-config.php

@ini_set('display_errors', 0);

The above code will remove the warning only, but you have to look into it as you may be exposing your website to SQL injection vulnerability.

You may be thinking that the code worked fine so why it has broken after the update? It just that previously only 1 argument was passed in $wpdb->prepare(). Just as the example below.

$wpdb->prepare( "SELECT * FROM table WHERE id = $id" );

But after the update it require second argument too for security reasons. See the correct way of using $wpdb->prepare()

$wpdb->prepare( "SELECT * FROM table WHERE id = %d", $id );

How to Turn Off this warning for Sharebar Plugin ?

  1. Log into your dashboard and click on plugins.
  2. Scroll down and find Sharebar and click edit


  1. Now press CTRL +F ( Command F for Mac ) and find $wpdb->prepare

The Complete code will look like this.

$results = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".$wpdb->prefix."sharebar WHERE enabled=1 ORDER BY position, id ASC")); $str .= "\n";
  1. Replace the above code with the following:
$results = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".$wpdb->prefix."sharebar WHERE enabled=1 ORDER BY position, id ASC", null)); $str .= "\n";

If you see the difference is only of a comma and null has been added. Now again look for the same code with $wpdb->prepare and you will find it on line 124. Just add comma and word null as described in step 4.

  1. Click the Update File button and your are done.

No more “Missing argument 2 for wpdb::prepare()” for your Sharebar Plugin