15th Dec2012
Author: Gyro

WordPress 3.5 – PHP Warning: Missing argument 2 for wpdb::prepare()

I just updated a work in progress to WordPress 3.5, and ended up with broken permalinks (to fix that: reset to default permalinks, then set the custom permalinks again), and my favorite plugin "Network Shared Posts" gave a super-long error message on each page, something along the lines of
PHP Warning: Missing argument 2 for wpdb::prepare()…blablabla…

So, after doing some research I found out that the root of all evil are the WordPress developers! Or to be more precise, they decided to make their functions more strict, resulting in a lot of plugins now showing the error "PHP Warning: Missing argument 2 for wpdb::prepare()", after someone updates to WordPress 3.5 and before the author has the chance to update, or in some cases totally rewrite their plugin. Read this article for more on this.

Here is my work-around to literally hide all "PHP Warning: Missing argument 2 for wpdb::prepare()" error messages:


So, since I can't wait for the plugin author to update the plugin so that it complies with WP requirements, I had to come up with a way to fix this annoying "PHP Warning: Missing argument 2 for wpdb::prepare()" warning in WordPress 3.5 stuffstuff :)

Simply modify each line that produces the error message like this:

Add a @ infront of wpdb->prepare !

So, instead of changing for example this line:

$wpdb->get_var($wpdb->prepare("SELECT term_id FROM $TermsTable WHERE slug = ‘$category' "));

to this:
$wpdb->get_var($wpdb->prepare("SELECT term_id FROM %s WHERE slug = %s ", $TermsTable, $category));

I simply did this:
$wpdb->get_var(@$wpdb->prepare("SELECT term_id FROM $TermsTable WHERE slug = ‘$category' "));

Either way, you would end up with one less "PHP Warning: Missing argument 2 for wpdb::prepare()" error message showing up, just work your way through the file that was mentioned in the error message, and you'll end up with everything being as before updating to WordPress 3.5 :)

1322

Keep Me Going
Your Name / Website:
Did you like my post? Buy me a Bitcoffee! 14JX52Li7zTKbyQv2omw4tvu6Bi1KzfHNW



Leave a Reply

Your email address will not be published. Required fields are marked *

What is 12 + 13 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)