WordPress.org

Ready to get started?Download WordPress

Forums

Category Icons
Missing Argument 2 for wpdb::prepare (32 posts)

  1. tadesse
    Member
    Posted 1 year ago #

    Hallo,
    almost all wpdb::prepare statements should be improved to the WP 3.5 compatible version.
    See here: http://make.wordpress.org/core/2012/12/12/php-warning-missing-argument-2-for-wpdb-prepare/

    http://wordpress.org/plugins/category-icons/

  2. pvogel2
    Member
    Posted 1 year ago #

    Hi,

    I have installed Category Icons Light Plugin. After upgrade to wp 3.6 I got the same error message.

    ("Warning: Missing argument 2 for wpdb::prepare(), called in ...\wordpress\wp-content\plugins\category-icons-lite\caticons-lite.class.php on line 306 and defined in ...\wordpress\wp-includes\wp-db.php on line 992")

    By the way, the 'Visit plugin link' for the Light versions on the Plugins page in wp admin seems to be broken, it links to 'http://www.category-icons.com/' which responds with a 403, forbidden.

    Cheers Peter

  3. criana
    Member
    Posted 1 year ago #

    I am having the exact same problem on a site that was updated to 3.6 today. Any possible solutions?

  4. playingsmart
    Member
    Posted 1 year ago #

    Glad to see I'm not the only one! I found a "solution" in another thread, but when I substituted the bits of code nothing changed. Surely there's a way around this? (Or another plugin that does this...?)

  5. pvogel2
    Member
    Posted 1 year ago #

    In the file
    plugins/category-icons-lite/caticons-lite.class.php I patched the code as follows:

    ...
    			WHERE meta_key = %s";
    			//WHERE meta_key = '".esc_sql($this->meta_key).'\'';
    			$k = $this->meta_key;
    			$results = wp_cache_get( 'categoryiconslite_results');
    			if ( false === $results ) { // put in cache the result
    				$results = $wpdb->get_results( $wpdb->prepare($query, $k) );

    and the plugin started to work again.
    (In the Query string changed the last line containing 'WHERE meta_key...' and added the variable $k which is given to the $wpdb->prepare function.
    Hopefully this helps.

  6. tadesse
    Member
    Posted 1 year ago #

    Hello,
    well I did change the code as well for our WordPress page.
    But this should be done by the plugin author.
    Here are my code changes in: /wp-content/plugins/category-icons/category_icons.php

    Index: category_icons.php
    ===================================================================
    --- category_icons.php	(revision 420)
    +++ category_icons.php	(revision 427)
    @@ -290,7 +290,7 @@
     				FROM $wpdb->term_relationships
     				right join $wpdb->term_taxonomy on $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id
     				left join $wpdb->posts on $wpdb->term_relationships.object_id = $wpdb->posts.ID
    -				where post_type = 'page' and $wpdb->term_taxonomy.taxonomy = 'category' and ID=";
    +				where post_type = 'page' and $wpdb->term_taxonomy.taxonomy = 'category' and ID = '' ";
     	$nb_max_icons_page = (int) get_option('igcaticons_max_icons');
     	$cats = array();
     	if ($type != 'cat' && $type != 'page') {
    @@ -1044,7 +1044,8 @@
      */
     function ig_caticons_install() {
     	global $wpdb, $table_prefix;
    -	$wpdb->query($wpdb->prepare("CREATE TABLE IF NOT EXISTS <code>$wpdb->ig_caticons</code> (<code>cat_id</code> INT NOT NULL ,<code>priority</code> INT NOT NULL ,<code>icon</code> TEXT NOT NULL ,<code>small_icon</code> TEXT NOT NULL , PRIMARY KEY ( <code>cat_id</code> ))"));
    +//	$wpdb->query($wpdb->prepare("CREATE TABLE IF NOT EXISTS <code>$wpdb->ig_caticons</code> (<code>cat_id</code> INT NOT NULL ,<code>priority</code> INT NOT NULL ,<code>icon</code> TEXT NOT NULL ,<code>small_icon</code> TEXT NOT NULL , PRIMARY KEY ( <code>cat_id</code> ))"));
    +	$wpdb->query($wpdb->prepare("CREATE TABLE IF NOT EXISTS %s (<code>cat_id</code> INT NOT NULL ,<code>priority</code> INT NOT NULL ,<code>icon</code> TEXT NOT NULL ,<code>small_icon</code> TEXT NOT NULL , PRIMARY KEY ( <code>cat_id</code> ))", $wpdb->ig_caticons ) ) ;
     	add_option('igcaticons_path', '');
     	add_option('igcaticons_url', '');
     	add_option('igcaticons_filetypes', 'jpg gif jpeg png');
    @@ -1357,7 +1358,8 @@
     	foreach($cats as $cat)
     		$instr .= $wpdb->escape($cat).',';
     	$instr = preg_replace('/,$/','', $instr); // Remove trailing comma
    -	if ($row = $wpdb->get_row($wpdb->prepare("SELECT cat_id, priority, icon, small_icon FROM $wpdb->ig_caticons WHERE cat_id IN($instr) ORDER BY priority DESC LIMIT 1")))
    +//	if ($row = $wpdb->get_row($wpdb->prepare("SELECT cat_id, priority, icon, small_icon FROM $wpdb->ig_caticons WHERE cat_id IN($instr) ORDER BY priority DESC LIMIT 1")))
    +if ($row = $wpdb->get_row($wpdb->prepare("SELECT cat_id, priority, icon, small_icon FROM %s WHERE cat_id IN(%s) ORDER BY priority DESC LIMIT 1", $wpdb->ig_caticons, $instr )))
     		return array($row->cat_id, $row->priority, $row->icon, $row->small_icon);
     	else
     		return false;

    I changed the wrong translation tags _e( to: __( as well.

  7. pvogel2
    Member
    Posted 1 year ago #

    Hi, of course.
    My comment was ment just as a workaround until the fix is availabe. Especially as criana and playingsmarta asked for help.

  8. baco99
    Member
    Posted 12 months ago #

    Hello tadesse please can you help me, unfortunately I can't understand where to put your patch inside category_icons.php.

    I have tried but i got syntax errors. I have tried to put in place of original "function ig_caticons_install()".

  9. tadesse
    Member
    Posted 12 months ago #

    Hello,
    the above code is a diff patch.
    Here is the new updated code of function ig_caticons_install

    function ig_caticons_install() {
    	global $wpdb, $table_prefix;
    	$wpdb->query($wpdb->prepare( "CREATE TABLE IF NOT EXISTS $wpdb->ig_caticons (cat_id INT NOT NULL ,priority INT NOT NULL ,icon TEXT NOT NULL ,small_icon TEXT NOT NULL , PRIMARY KEY ( cat_id ))", $table ) ) ;
    	add_option('igcaticons_path', '');
    	add_option('igcaticons_url', '');
    	add_option('igcaticons_filetypes', 'jpg gif jpeg png');
    	add_option('igcaticons_max_icons','3');
    	add_option('igcaticons_before_name','true');
    	add_option('igcaticons_fit_width','-1');
    	add_option('igcaticons_fit_height','-1');
    	add_option('igcaticons_use_small','true');
    	add_option('igcaticons_templatecode_patch','0');
    	add_option('igcaticons_templatecode_sidebar','1');
    	add_option('igcaticons_rssfeeds','1');
    	add_option('igcaticons_useseo_plugin', '0');
    	add_option('igcaticons_max_width','-1');
    	add_option('igcaticons_max_height','-1');
    	add_option('igcaticons_iconcatpage','0');
    }
  10. baco99
    Member
    Posted 12 months ago #

    Hello, thanks for your reply. Now I don't see anymore the warning message in the header but now I see it where there were the icons :\

  11. brembs
    Member
    Posted 11 months ago #

    @tadesse: This patch did not work for me, unfortunately.

  12. baco99
    Member
    Posted 11 months ago #

    Same here:(

    I have tried to delete and reinstall it, change "function ig_caticons_install()" following tadesse istructions, but then I see the error where there were the icons.

  13. tadesse
    Member
    Posted 11 months ago #

    Hello,
    in Function bm_caticons_adminicons from Line 916 you must change the queries to:

    if ( $wpdb->get_var( $wpdb->prepare( "SELECT cat_id FROM $wpdb->ig_caticons WHERE cat_id = '%d' ", $cat_ID ) ) ) {
    				$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->ig_caticons SET priority = '%d', icon = '%s', small_icon='$s' WHERE cat_id = '%d' ", $priority, $icon, $small_icon, $cat_ID ) ) ;
    			} else {
    				$wpdb->query($wpdb->prepare("INSERT INTO $wpdb->ig_caticons (cat_id, priority, icon, small_icon) VALUES ('$cat_ID', '$priority', '$icon', '$small_icon')"));
  14. brembs
    Member
    Posted 11 months ago #

    Inserting this code at that place had no effect on the error message whatsoever, I'm sorry. But thanks for trying to help us all out!

  15. meysamsalehi
    Member
    Posted 11 months ago #

    hi my friends , can you help me?
    i have a problem with "category icon" plugin .
    when activated plugin got error that Included :

    ( ! ) Warning: Missing argument 2 for wpdb::prepare(), called in C:\wamp\www\wordpress\wp-content\plugins\category-icons\category_icons.php on line 1047 and defined in C:\wamp\www\wordpress\wp-includes\wp-db.php on line 992
    Call Stack
    # Time Memory Function Location
    1 0.0013 215136 {main}( ) ..\edit.php:0
    2 0.0020 258128 require_once( 'C:\wamp\www\wordpress\wp-admin\admin.php' ) ..\edit.php:10
    3 0.0024 269368 require_once( 'C:\wamp\www\wordpress\wp-load.php' ) ..\admin.php:30
    4 0.0027 276744 require_once( 'C:\wamp\www\wordpress\wp-config.php' ) ..\wp-load.php:29
    5 0.0036 334640 require_once( 'C:\wamp\www\wordpress\wp-settings.php' ) ..\wp-config.php:90
    6 0.3088 12311984 do_action( ) ..\wp-settings.php:308
    7 0.3223 12402600 call_user_func_array ( ) ..\plugin.php:406
    8 0.3223 12402616 ig_caticons_install( ) ..\plugin.php:406
    9 0.3223 12402992 wpdb->prepare( ) ..\category_icons.php:1047

    so , What me Do?

  16. baco99
    Member
    Posted 11 months ago #

    Hello tadesse, thanks for the help but unfortunately I got the same error:

    http://img841.imageshack.us/img841/2937/sri9.jpg

    ps i have edited ig_caticons_install and bm_caticons_adminicons

  17. davs63
    Member
    Posted 9 months ago #

    Tnaks a lot Tadesse for your code

    ( you miss a "}" at the end of your change on bm_caticons_adminicons function ? )

  18. davs63
    Member
    Posted 9 months ago #

    arf :( u have another error in admin page of this plugin :

    Warning: Missing argument 2 for wpdb::prepare(), called in /homepages/2/d142305709/htdocs/als/wp-content/plugins/category-icons/category_icons.php on line 1337

  19. tadesse
    Member
    Posted 9 months ago #

    Hello Davs63,
    well, yes } is missing ..
    this whole modified function copied here:

    /**
     * Display the icons panel in Icons tab
     * @author Brahim MACHKOURI
     */
    // I took some of the code from categories.php of WordPress 2.5 and modified it a little
    function bm_caticons_adminicons() {
    	global $wpdb;
    	$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
    	if ( isset($_GET['deleteit']) && isset($_GET['delete']) )
    		$action = 'bulk-delete';
    	switch($action) {
    		case 'update-category-icon':
    			$cat_ID = (int) $_GET['cat_ID'];
    			$priority = $_REQUEST['ig_priority'];
    			$icon = $_REQUEST['ig_icon'];
    			$small_icon = $_REQUEST['ig_small_icon'];
    			if ( $wpdb->get_var( $wpdb->prepare( "SELECT cat_id FROM $wpdb->ig_caticons WHERE cat_id = '%d' ", $cat_ID ) ) ) {
    				$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->ig_caticons SET priority = '%d', icon = '%s', small_icon='$s' WHERE cat_id = '%d' ", $priority, $icon, $small_icon, $cat_ID ) ) ;
    			} else {
    				$wpdb->query($wpdb->prepare("INSERT INTO $wpdb->ig_caticons (cat_id, priority, icon, small_icon) VALUES ('$cat_ID', '$priority', '$icon', '$small_icon')"));
    			}
    		break;
    		case 'delete':
    			$cat_ID = (int) $_GET['cat_ID'];
    			if (!is_admin() || !current_user_can( 'manage_categories' ))
    				wp_die(__('Are you trying to cheat ?','category_icons'));
    			$cat_name = get_catname($cat_ID);
    			$request = "DELETE FROM $wpdb->ig_caticons WHERE cat_id='$cat_ID'";
    			if (false === $wpdb->query($wpdb->prepare($request) ))
    				wp_die(__('Error in Category Icons','category_icons').' : '.$request);
    		break;
    		case 'bulk-delete':
    			if (!is_admin() || !current_user_can( 'manage_categories' ))
    				wp_die( __('You are not allowed to delete category icons.','category_icons') );
    			foreach ( (array) $_GET['delete'] as $cat_ID ) {
    				$cat_name = get_catname($cat_ID);
    				$wpdb->query($wpdb->prepare("DELETE FROM $wpdb->ig_caticons WHERE cat_id='$cat_ID'"));
    			}
    		break;
    	}
    	switch ($action) {
    	case 'edit':
    		$cat_ID = (int) $_GET['cat_ID'];
    		$category = get_category_to_edit($cat_ID);
    		list($priority, $icon, $small_icon) = bm_caticons_get_icons($cat_ID);
    		?>
    		<div class="wrap">
    		<h2><?php _e('Select Category Icons','category_icons') ?></h2>
    		<form method="post" name="caticons-form1" action="">
    		  <?php wp_nonce_field('caticons-nonce'); ?>
    			<input type="hidden" name="ig_module" value="caticons" />
    			<input type="hidden" name="ig_tab" value="icons" />
    			<input type="hidden" name="action" value="update-category-icon" />
                <table  border="0" class="form-table">
                    <tr>
                        <th scope="row" style="vertical-align:text-top;"><?php _e('Category ID','category_icons'); ?></th>
                        <td colspan="2" ><?php echo $cat_ID;?></td>
                    </tr>
                    <tr>
                        <th scope="row" style="vertical-align:text-top;"><?php _e('Name','category_icons'); ?></th>
                        <td colspan="2"><?php echo $category->name;?></td>
                    </tr>
                    <tr>
                        <th scope="row" class="num" style="vertical-align:text-top;"><?php _e('Priority','category_icons'); ?></th>
                        <td colspan="2">
                            <input type="text" name="ig_priority" size="5" value="<?php echo $priority; ?>" />
                        </td>
                    </tr>
                    <tr>
                        <th scope="row" style="vertical-align:text-top;"><?php _e('Icon','category_icons'); ?></th>
                        <td valign="top"><label><?php _e('Select a file : ','category_icons');?></label>
                            <select name="ig_icon" onchange="icon_preview.src=('<?php echo ig_caticons_url();?>/'+this.options[this.selectedIndex].value);">
                                <option value="">--- <?php _e('No Icon','category_icons'); ?> ---</option>
                                <?php bm_caticons_get_icons_paths($icon);	?>
                            </select><br />
                            <label><?php _e('Or enter an URL : ','category_icons');?><input type="text" name="bm_icon_url"/></label>
                        </td>
                        <td valign="top"><img id="icon_preview" src="<?php echo ig_caticons_url()."/$icon";?>" alt="icon" /></td>
                    </tr>
                    <tr>
                        <th scope="row" style="vertical-align:text-top;"><?php _e('Small Icon','category_icons'); ?></th>
                        <td valign="top"><label><?php _e('Select a file : ','category_icons');?></label>
                            <select name="ig_small_icon" onchange="small_icon_preview.src=('<?php echo ig_caticons_url();?>/'+this.options[this.selectedIndex].value);">
                                <option value="">--- <?php _e('No Icon','category_icons'); ?> ---</option>
                                <?php bm_caticons_get_icons_paths($small_icon); ?>
                            </select><br />
                            <label><?php _e('Or enter an URL : ','category_icons');?><input type="text" name="bm_smallicon_url"/></label>
                        </td>
                        <td valign="top"><img id="small_icon_preview" src="<?php echo ig_caticons_url()."/$small_icon";?>" alt="small icon" /></td>
                    </tr>
                </table>
    			<div class="submit"><input type="submit" name="info_update" value="<?php _e('Select Icons','category_icons');?> ยป" /></div>
            </form>
    		</div>
    		<?php
    	break;
    	default:
    	?>
    	<div class="wrap">
            <form id="posts-filter" action="" method="get" name="caticons-form2">
            <?php wp_nonce_field('caticons-nonce'); ?>
                <input type="hidden" name="ig_module" value="caticons" />
                <input type="hidden" name="page" value="category_icons.php" />
                <input type="hidden" name="action" value="delete" />
                <input type="hidden" name="ig_tab" value="icons" />
    
    		<div class="tablenav">
    			<div class="alignleft">
    				<input type="submit" value="<?php _e('Delete icons and priority','category_icons'); ?>" name="deleteit" class="button-secondary delete" />
    			</div>
    			<br class="clear" />
    		</div>
    		<br class="clear" />
    		<table class="widefat" id="caticons_table">
    			<thead>
    			<tr>
       				<th scope="col" id="cb" class="check-column"><input type="checkbox" /></th>
    				<th scope="col"><?php _e('ID','category_icons') ?></th>
                    <th scope="col" ><?php _e('Name','category_icons') ?></th>
                    <th scope="col" style="text-align:center"><?php _e('Description','category_icons') ?></th>
                    <th scope="col" class="num" style="text-align:center"><?php _e('Posts','category_icons') ?></th>
                    <th scope="col" style="text-align:center"><?php _e('Priority','category_icons') ?></th>
    				<th scope="col" style="text-align:center"><?php _e('Icon','category_icons') ?></th>
    				<th scope="col" style="text-align:center"><?php _e('Small Icon','category_icons') ?></th>
    			</tr>
    			</thead>
    			<tbody id="the-list" class="list:cat">
    		<?php
    		bm_caticons_rows();
    		?>
    			</tbody>
    		</table>
    		</form>
            <div class="tablenav">
            <br class="clear" />
            </div>
            <br class="clear" />
            </div>
    	<?php
    	}// end switch
    }

    and install aswell:

    /**
     * Install the plugin
     * @author Ivan Georgiev
     */
    function ig_caticons_install() {
    	global $wpdb, $table_prefix;
    	$wpdb->query($wpdb->prepare( "CREATE TABLE IF NOT EXISTS <code>$wpdb->ig_caticons</code> (<code>cat_id</code> INT NOT NULL ,<code>priority</code> INT NOT NULL ,<code>icon</code> TEXT NOT NULL ,<code>small_icon</code> TEXT NOT NULL , PRIMARY KEY ( <code>cat_id</code> ))", $table ) ) ;
    	add_option('igcaticons_path', '');
    	add_option('igcaticons_url', '');
    	add_option('igcaticons_filetypes', 'jpg gif jpeg png');
    	add_option('igcaticons_max_icons','3');
    	add_option('igcaticons_before_name','true');
    	add_option('igcaticons_fit_width','-1');
    	add_option('igcaticons_fit_height','-1');
    	add_option('igcaticons_use_small','true');
    	add_option('igcaticons_templatecode_patch','0');
    	add_option('igcaticons_templatecode_sidebar','1');
    	add_option('igcaticons_rssfeeds','1');
    	add_option('igcaticons_useseo_plugin', '0');
    	add_option('igcaticons_max_width','-1');
    	add_option('igcaticons_max_height','-1');
    	add_option('igcaticons_iconcatpage','0');
    }

    I hope this helps ..

  20. brembs
    Member
    Posted 9 months ago #

    Thanks, tadesse, for these updates. However, they've had zero effect on the error message I'm receiving, it's still there, unfortunately.

  21. tadesse
    Member
    Posted 9 months ago #

    Hello,
    id did run the script with debug enabled and improved some php notices
    On our server I get no error messages anymore.
    find the full code of the modified category_icons.php here:
    http://pastebin.com/GSSjg3kE
    It is old code by the way.

    > "hey've had zero effect on the error message I'm receiving"

    What exactly do you mean?

  22. brembs
    Member
    Posted 9 months ago #

    "What exactly do you mean?"

    I mean if I take the original code from the original author and replace it with your code, I still get the same error message, as if I hadn't changed anything.

  23. adamwalter
    Member
    Posted 9 months ago #

    Thank you tadesse! This cleared up the error for me. Where on Earth is the developer in all this?

  24. tadesse
    Member
    Posted 9 months ago #

    Well,
    glad I could be of some help (after some time :-)

  25. brembs
    Member
    Posted 9 months ago #

    Pasting the whole code from the pastebin now also worked for me, finally! many thanks tadesse!!

  26. dsmcac
    Member
    Posted 8 months ago #

    Hi tadesse. any chance you can put the complete code back up, seems pastebin has emptied itself.

  27. tadesse
    Member
    Posted 7 months ago #

    Hello,
    yes, ok : http://pastebin.com/XevRdaZg
    I hope it helps ...

  28. dsmcac
    Member
    Posted 7 months ago #

    Great! works perfectly. Thanks

  29. rwilki
    Member
    Posted 7 months ago #

    Hi Tadesse! Thank you so much for your help on this. Worked like a charm. Is this plugin supported by the developer any longer? Such a great and functional plugin I hope it is.

    Thanks again!

  30. Echtzeit
    Member
    Posted 7 months ago #

    Yes, thank you so much Tadesse! But I still get an error, maybe you can help me?

    Warning: Missing argument 2 for wpdb::prepare(), called in /public_html/wp-content/plugins/category-icons/category_icons.php on line 919 and defined in /public_html/wp-includes/wp-db.php on line 992

    I've copy+pasted your exact lines.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic