Opened 6 months ago

Closed 3 months ago

#4654 closed defect (bug) (fixed)

incorrect usage of $wpdb->prepare()

Reported by: anointed Owned by:
Priority: normal Milestone: 1.7
Component: All Components Version:
Severity: normal Keywords:
Cc: cklosowski@…

Description

Keeping an eye out on my log files for warnings about prepare. I will continue appending new ones as they show up in my log files

1st one:

argument 2 for wpdb::prepare(), called in /wp-content/plugins/buddypress/bp-messages/bp-messages-classes.php on line 558

Change History (29)

#2-friends-classes

 Missing argument 2 for wpdb::prepare(), called in /wp-content/plugins/buddypress/bp-friends/bp-friends-classes.php on line 94
Last edited 6 months ago by anointed (previous) (diff)

#3 activity-classes

 Missing argument 2 for wpdb::prepare(), called in /wp-content/plugins/buddypress/bp-activity/bp-activity-classes.php on line 219

#4 activity-classes

 Missing argument 2 for wpdb::prepare(), called in /wp-content/plugins/buddypress/bp-activity/bp-activity-classes.php on line 231

#5 activity-classes line 236, 239

 Missing argument 2 for wpdb::prepare(), called in /wp-content/plugins/buddypress/bp-activity/bp-activity-classes.php on line 236
 mod_fcgid: stderr: PHP Warning:  Missing argument 2 for wpdb::prepare(), called in /buddypress/bp-activity/bp-activity-classes.php on line 239
Last edited 6 months ago by anointed (previous) (diff)

#6 activity-classes

 Missing argument 2 for wpdb::prepare(), called in /wp-content/plugins/buddypress/bp-activity/bp-activity-classes.php on line 250

#7 friends-classes

 Missing argument 2 for wpdb::prepare(), called in /wp-content/plugins/buddypress/bp-friends/bp-friends-classes.php on line 90

#8 #9 #10 bp-blogs-classes Line 116, 117, 296

mod_fcgid: stderr: PHP Warning:  Missing argument 2 for wpdb::prepare(), called in /wp-content/plugins/buddypress/bp-blogs/bp-blogs-classes.php on line 116
mod_fcgid: stderr: PHP Warning:  Missing argument 2 for wpdb::prepare(), called in /wp-content/plugins/buddypress/bp-blogs/bp-blogs-classes.php on line 117
 mod_fcgid: stderr: PHP Warning:  Missing argument 2 for wpdb::prepare(), called in /wp-content/plugins/buddypress/bp-blogs/bp-blogs-classes.php on line 296

bp-xprofile line 139, 173, 333

 mod_fcgid: stderr: PHP Warning:  Missing argument 2 for wpdb::prepare(), called in /buddypress/bp-xprofile/bp-xprofile-classes.php on line 139
Missing argument 2 for wpdb::prepare(), called in /buddypress/bp-xprofile/bp-xprofile-classes.php on line 173 
Missing argument 2 for wpdb::prepare(), called in /buddypress/bp-xprofile/bp-xprofile-classes.php on line 333
Last edited 6 months ago by anointed (previous) (diff)
  • Component changed from Core to All Components
  • Milestone changed from Awaiting Review to 1.7

JJJ's committed r6492, r6493, r6494, r6495, r6497 against some of these.

(In [6498]) Remove more unneeded prepare() calls in bp-activity-classes.php. See #4654

(In [6499]) Remove more unneeded prepare() calls on the BuddyPress admin screen. See #4654

(In [6500]) Remove unneeded prepare() calls from the group directory screen. See #4654

Here are 3 that popped up for me on a fresh WordPress 3.5 beta 2 install and svn checkout of BuddyPress on 2012-11-12 ~12:00PM:
---
Warning: Missing argument 2 for wpdb::prepare(), called in \wordpress\wp-content\plugins\buddypress\bp-core\bp-core-functions.php on line 176 and defined in \wordpress\wp-includes\wp-db.php on line 990

Warning: Missing argument 2 for wpdb::prepare(), called in \wordpress\wp-content\plugins\buddypress\bp-core\bp-core-options.php on line 296 and defined in \wordpress\wp-includes\wp-db.php on line 990

Warning: Missing argument 2 for wpdb::prepare(), called in \wordpress\wp-content\plugins\buddypress\bp-core\admin\bp-core-functions.php on line 220 and defined in \wordpress\wp-includes\wp-db.php on line 990
---

Others from front-end:
---
Warning: Missing argument 2 for wpdb::prepare(), called in \wordpress\wp-content\plugins\buddypress\bp-groups\bp-groups-classes.php on line 674 and defined in \wordpress\wp-includes\wp-db.php on line 990

Warning: Missing argument 2 for wpdb::prepare(), called in \wordpress\wp-content\plugins\buddypress\bp-core\bp-core-classes.php on line 355 and defined in \wordpress\wp-includes\wp-db.php on line 990

Warning: Missing argument 2 for wpdb::prepare(), called in \wordpress\wp-content\plugins\buddypress\bp-xprofile\bp-xprofile-filters.php on line 237 and defined in \wordpress\wp-includes\wp-db.php on line 990

Warning: Missing argument 2 for wpdb::prepare(), called in \wordpress\wp-content\plugins\buddypress\bp-activity\bp-activity-classes.php on line 219 and defined in \wordpress\wp-includes\wp-db.php on line 990

Warning: Missing argument 2 for wpdb::prepare(), called in \wordpress\wp-content\plugins\buddypress\bp-activity\bp-activity-classes.php on line 231 and defined in \wordpress\wp-includes\wp-db.php on line 990

Warning: Missing argument 2 for wpdb::prepare(), called in \wordpress\wp-content\plugins\buddypress\bp-activity\bp-activity-classes.php on line 236 and defined in \wordpress\wp-includes\wp-db.php on line 990

Warning: Missing argument 2 for wpdb::prepare(), called in \wordpress\wp-content\plugins\buddypress\bp-friends\bp-friends-classes.php on line 88 and defined in \wordpress\wp-includes\wp-db.php on line 990

Warning: Missing argument 2 for wpdb::prepare(), called in \wordpress\wp-content\plugins\buddypress\bp-friends\bp-friends-classes.php on line 90 and defined in \wordpress\wp-includes\wp-db.php on line 990

Warning: Missing argument 2 for wpdb::prepare(), called in \wordpress\wp-content\plugins\buddypress\bp-friends\bp-friends-classes.php on line 94 and defined in \wordpress\wp-includes\wp-db.php on line 990

Warning: Missing argument 2 for wpdb::prepare(), called in \wordpress\wp-content\plugins\buddypress\bp-xprofile\bp-xprofile-classes.php on line 139 and defined in \wordpress\wp-includes\wp-db.php on line 990

Warning: Missing argument 2 for wpdb::prepare(), called in \wordpress\wp-content\plugins\buddypress\bp-xprofile\bp-xprofile-classes.php on line 333 and defined in \wordpress\wp-includes\wp-db.php on line 990

Warning: Missing argument 2 for wpdb::prepare(), called in \wordpress\wp-content\plugins\buddypress\bp-xprofile\bp-xprofile-classes.php on line 173 and defined in \wordpress\wp-includes\wp-db.php on line 990

Warning: Missing argument 2 for wpdb::prepare(), called in \wordpress\wp-content\plugins\buddypress\bp-xprofile\bp-xprofile-classes.php on line 136 and defined in \wordpress\wp-includes\wp-db.php on line 990

Warning: Missing argument 2 for wpdb::prepare(), called in \wordpress\wp-content\plugins\buddypress\bp-xprofile\bp-xprofile-classes.php on line 141 and defined in \wordpress\wp-includes\wp-db.php on line 990

Warning: Missing argument 2 for wpdb::prepare(), called in \wordpress\wp-content\plugins\buddypress\bp-xprofile\bp-xprofile-classes.php on line 167 and defined in \wordpress\wp-includes\wp-db.php on line 990
---

These 4 popped up in admin groups page:
---
Warning: Missing argument 2 for wpdb::prepare(), called in \wordpress\wp-content\plugins\buddypress\bp-groups\bp-groups-classes.php on line 761 and defined in \wordpress\wp-includes\wp-db.php on line 990

Warning: Missing argument 2 for wpdb::prepare(), called in \wordpress\wp-content\plugins\buddypress\bp-groups\bp-groups-classes.php on line 762 and defined in \wordpress\wp-includes\wp-db.php on line 990

Warning: Missing argument 2 for wpdb::prepare(), called in \wordpress\wp-content\plugins\buddypress\bp-groups\bp-groups-classes.php on line 763 and defined in \wordpress\wp-includes\wp-db.php on line 990

Warning: Missing argument 2 for wpdb::prepare(), called in \wordpress\wp-content\plugins\buddypress\bp-groups\bp-groups-classes.php on line 764 and defined in \wordpress\wp-includes\wp-db.php on line 990
---

For visitors reading this, the workaround/fix for these is to remove the $wpdb->prepare(); function that only has 1 string argument, for example, on line 94 of \wordpress\wp-content\plugins\buddypress\bp-friends\bp-friends-classes.php:

$friends = $wpdb->get_results( $wpdb->prepare( "SELECT friend_user_id, initiator_user_id FROM {$bp->friends->table_name} $friend_sql $oc_sql ORDER BY date_created DESC" ) );

BECOMES:

$friends = $wpdb->get_results( "SELECT friend_user_id, initiator_user_id FROM {$bp->friends->table_name} $friend_sql $oc_sql ORDER BY date_created DESC" );

---
Thanks -- Marty McGee? (companyjuice)

(In [6518]) Fix more prepare() warnings. See #4654

(In [6521]) Fix more prepare() warnings in Activity. See #4654

Warning: Missing argument 2 for wpdb::prepare(), called in /home/nexialys/public_html/core/wp-content/plugins/buddypress/bp-core/bp-core-functions.php on line 176 and defined in /home/nexialys/public_html/core/wp-includes/wp-db.php on line 990

Warning: Missing argument 2 for wpdb::prepare(), called in /home/nexialys/public_html/core/wp-content/plugins/buddypress/bp-core/bp-core-options.php on line 296 and defined in /home/nexialys/public_html/core/wp-includes/wp-db.php on line 990

Warning: Missing argument 2 for wpdb::prepare(), called in /home/nexialys/public_html/core/wp-content/plugins/buddypress/bp-core/admin/bp-core-functions.php on line 217 and defined in /home/nexialys/public_html/core/wp-includes/wp-db.php on line 990

########

btw, just add $args = "" in the proper line 990 in wp-db.php would avoid all these alerts with no problem...

Last edited 6 months ago by nexia (previous) (diff)

(In [6533]) Fix a prepare() warning when filtering comments. See #4654

  • Cc cklosowski@… added

(In [6539]) Fix incorrect prepare() usages in Blogs component. See #4654. (trunk)

(In [6557]) Fix alot of WPDB->Prepare() warnings in the 1.6 branch. See #4654

(In [6573]) Fix wpdb::prepare() warnings in BP_Groups_Group::get_group_type_ids(). See #4654.

(In [6575]) Query variable and prepare() usage audit. See #4654. (1.6 branch)

  • Resolution set to fixed
  • Status changed from new to closed

Looks all fixed up to me. Closing as fixed.

  • Resolution fixed deleted
  • Status changed from closed to reopened
  1. Fresh install, with (current) trunk
  2. custom profile fields.
  3. add details to the profile field and change the visibility to, for example 'friends only'.
  4. log out and view profile.
  5. profit:

[07-Feb-2013 08:07:31] PHP Notice: wpdb::prepare was called <strong>incorrectly</strong>. wpdb::prepare() requires at least two arguments. Please see <a href="http://codex.wordpress.org/Debugging_in_WordPress">Debugging in WordPress</a> for more information. (This message was added in version 3.5.) in wp-includes/functions.php on line 2959

From a quick glance, I'm pretty sure it's the exclude_fields_sql http://buddypress.trac.wordpress.org/browser/trunk/bp-xprofile/bp-xprofile-classes.php#L167 but don't have time to look into it at the moment.

Last edited 3 months ago by chrisclayton (previous) (diff)
  • Resolution set to fixed
  • Status changed from reopened to closed

(In [6775]) Remove unneeded prepare() call in bp-xprofile-classes.php. Fixes #4654.

Note: See TracTickets for help on using tickets.