Support » Plugin: Category Icons » Missing Argument 2 for wpdb::prepare

Viewing 2 replies - 1 through 2 (of 2 total)
  • I’m having the same problem. Were you ever able to figure out a solution to this?



    I spent weeks wrestling with this problem myself, and finally solved it just a couple of days ago.

    I extracted the solution from here:
    That article is written for theme/plugin authors, and it’s full of information about why the warning happens when it didn’t used to, but the important point is this:
    To solve the warning about a missing 2nd argument… add a 2nd argument.

    NOTE: This involves editing at least one of the actual plugin files, which is not something I would normally consider doing [because any changes would be lost in a subsequent upgrade], but this plugin unfortunately seems to have been abandoned, so I decided I wasn’t going to worry about losing my changes.

    So, onward. The warning message tells you which line of the file has the problem — in this case, Line 1047. Open the problematic file category_icons.php in a real text editor (NOT a word processor) — I recommend Notepad++, because it helpfully displays the file with line numbers, but you could use Notepad in a pinch.

    Line 1047 is this:
    $wpdb->query($wpdb->prepare("CREATE TABLE IF NOT EXISTS$wpdb->ig_caticons(cat_idINT NOT NULL ,priorityINT NOT NULL ,iconTEXT NOT NULL ,small_iconTEXT NOT NULL , PRIMARY KEY (cat_id))"));

    * You don’t need to understand what all this means, but it helps if you understand how parentheses are nested and how quotes and commas are used to structure an expression. *

    Everything between the double quotes — one near the beginning, just before CREATE, and the other the 3rd character from the end, before the last two parentheses — is the first argument. Back when this plugin was developed, only one argument was necessary. But WordPress has advanced significantly, and this prepare function now requires two arguments (again, see that authors’ reference, above).

    What we need to do is insert something as a placeholder for the 2nd argument, to satisfy the function that it’s got two arguments, so that the warning will not be triggered.

    Go to the end of Line 1047 and insert a comma, a space, and two single quote marks between the double quotes and the second-to-last parenthesis.

    The very end of Line 1047 should go from this:

    To this:
    ))", ''));

    That’s all there is to it. The two single quotes create an empty (Null) 2nd argument for the function, and it’s perfectly happy with that.

    Before you close your file, go to Line 1338 and make exactly the same change — this is another instance of prepare, and if you skip it you’ll get exactly the same warning message, but with the new line number.

    Now save your file and upload it back to your server, and you’ll be good to go.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Missing Argument 2 for wpdb::prepare’ is closed to new replies.