{"id":1306,"date":"2013-10-06T12:55:15","date_gmt":"2013-10-06T19:55:15","guid":{"rendered":"http:\/\/zsprawl.com\/iOS\/?p=1306"},"modified":"2013-10-06T13:06:18","modified_gmt":"2013-10-06T20:06:18","slug":"wordpress-sql-injections-fixing-your-themes","status":"publish","type":"post","link":"http:\/\/zsprawl.com\/iOS\/2013\/10\/wordpress-sql-injections-fixing-your-themes\/","title":{"rendered":"WordPress SQL Injections &#038; Fixing Your Themes"},"content":{"rendered":"<p>With the update to WordPress 3.5, which happened quite a while ago, a number of popular themes (and some unpopular ones) started displaying the php warnings.<\/p>\n<blockquote><p>Missing argument 2 for wpdb::prepare(), called in \/wp\/wp-content\/themes\/piano-black\/sidebar.php on line 75 and defined<\/p><\/blockquote>\n<p>In my case, the <a href=\"http:\/\/www.mono-lab.net\/\" target=\"_blank\">theme makers<\/a> don&#8217;t speak English, so I&#8217;m stuck fixing this baby myself. Piano-black is the name of the theme that I&#8217;m using on my <a href=\"http:\/\/zsprawl.com\/wp\/\" target=\"_blank\">old video game blog<\/a>, which doesn&#8217;t get updated much, since I no longer correspond for IGN, sadly.<br \/>\n<!--more--><br \/>\nAny good programmer knows, you need to prepare your queries to avoid nasty little SQL injections. The easiest way to fall victim is to plug a variable right into a SQL statement. A clever and nefarious hacker can very easy put something unintended in that variable, and exploit your code to access the underlining database. This wouldn&#8217;t be good.<\/p>\n<p>As shown in the above error, the problem has to do with the incorrect usage of the wpdb::prepare() function. Take this following example:<\/p>\n<p>[code]$wpdb->prepare(&#8220;SELECT * FROM list WHERE ID = %d&#8221;, $id)[\/code]<\/p>\n<p>Notice how the %d is a reference to the $id variable. This is important so that the prepare function actually parses your variable before putting it into the SQL statement. Here is the WRONG way of using wpdb::prepare():<\/p>\n<p>[code]$wpdb->prepare(&#8220;SELECT * FROM list WHERE ID = $id&#8221;)[\/code]<\/p>\n<p>Since the function is always expecting TWO parameters at a minimum, it is now throwing errors to warn developers of a potential security risk. The downside is that it is also showing potential hackers exactly where your code can be exploited. It&#8217;s a double-edged sword that must be fixed as soon as possible. However, if you need to buy yourself time, add the following code to your wp-config.php file:<\/p>\n<p>[code]@ini_set(&#8216;display_errors&#8217;, 0);[\/code]<\/p>\n<p>Please understand, this only hides the errors until you can fix them. It does NOT fix the errors. If you leave them, and find yourself hacked, don&#8217;t blame me!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With the update to WordPress 3.5, which happened quite a while ago, a number of popular themes (and some unpopular ones) started displaying the php warnings. Missing argument 2 for wpdb::prepare(), called in \/wp\/wp-content\/themes\/piano-black\/sidebar.php on line 75 and defined In my case, the theme makers don&#8217;t speak English, so I&#8217;m stuck fixing this baby myself. <a href=\"http:\/\/zsprawl.com\/iOS\/2013\/10\/wordpress-sql-injections-fixing-your-themes\/#more-'\" class=\"more-link\"><br \/>more \u00bb<\/a><\/p>\n","protected":false},"author":318,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,89],"tags":[90,128],"class_list":["post-1306","post","type-post","status-publish","format-standard","hentry","category-blog","category-wordpress","tag-php","tag-wordpress"],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/posts\/1306"}],"collection":[{"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/users\/318"}],"replies":[{"embeddable":true,"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/comments?post=1306"}],"version-history":[{"count":6,"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/posts\/1306\/revisions"}],"predecessor-version":[{"id":1346,"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/posts\/1306\/revisions\/1346"}],"wp:attachment":[{"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/media?parent=1306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/categories?post=1306"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zsprawl.com\/iOS\/wp-json\/wp\/v2\/tags?post=1306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}