Skip to:
Content
Pages
Categories
Search
Top
Bottom

Error: Missing argument 2 for wpdb::prepare

  • Avatar of Shmoo
    Shmoo
    Participant

    @macpresss

    I’m getting a strange error while the code seem to be working fine.

    ” Missing argument 2 for wpdb::prepare() “

    I’ve got Debug mode turned on in the config.php file and when I switch this mode off the error is gone but and everything is just working fine but I would like to know how bad this is.

    The errors shows up when I was testing this.

    
    <?php if ( bp_has_profile( array ( 'exclude_fields' => 15, 'exclude_groups' => 2 ) ) ) : ?>
    
Viewing 7 replies - 1 through 7 (of 7 total)
  • Avatar of Henry
    Henry
    Participant

    @henrywright-1

    http://make.wordpress.org/core/2012/12/12/php-warning-missing-argument-2-for-wpdb-prepare/

    Take a look at this post which will give you some background as to why WP throws that warning at you.

    Avatar of Shmoo
    Shmoo
    Participant

    @macpresss

    Okay if I understand correct this Query isn’t safe and the $ID is just thrown (unprepared) in the query.

    Can I do something to make it more safe or is this something that the BuddyPress Plugin Developers would have to upgrade, since the error is caused by the BP plugin.

    - I’ve turned off all PHP warnings like the first paragraph says so.

    Avatar of Henry
    Henry
    Participant

    @henrywright-1

    - I’ve turned off all PHP warnings like the first paragraph says so.

    But are you a developer or a user?

    With reference to any BP core changes being necessary – does the warning appear when using BP ‘out-of-the-box’ or are you introducing some code that is causing it? If it is resulting from some custom code, paste it here… and i’ll try taking a look

    Avatar of Paul Gibbs
    Paul Gibbs
    Keymaster

    @djpaul

    You should have gotten a filename or line number along with the error message. I’m interested if it’s in a core BP file, or in another plugin, like Henry says.

    Avatar of Shmoo
    Shmoo
    Participant

    @macpresss

    It’s my theme and I code WordPress themes for like 5 years now but I don’t see myself as a Developer it’s more a hobby :)

    I’m solid at HTML-CSS and can read PHP when I see it happen but I can’t write PHP it out of the box.

    This error shows up when I try to hide a complete xProfile-group-ID or just an unique xProfile-field-ID from the loop.

    This is what I did.
    Inside: my-theme/buddypress/members/single/profile/profile-loop.php
    I found the start of the loop

    
    <?php if ( bp_has_profile() ) : ?>
    ....
    

    My first thought was, maybe there are default options here to control the output of which ID’s will be visible so I started the search how the bp_has_profile() was build and looked into plugins/buddypress/bp-xprofile/bp-xprofile-template.php and found this at line 150:

    
    ....
    
    $defaults = array(
    	'user_id'             => bp_displayed_user_id(),
    	'profile_group_id'    => false,
    	'hide_empty_groups'   => true,
    	'hide_empty_fields'   => $hide_empty_fields_default,
    	'fetch_fields'        => true,
    	'fetch_field_data'    => true,
    	'fetch_visibility_level' => $fetch_visibility_level_default,
    	'exclude_groups'      => false, // Comma-separated list of profile field group IDs to exclude
    	'exclude_fields'      => false  // Comma-separated list of profile field IDs to exclude
    );
    

    This looks very familiar to bbPress so my first thoughts was lets try to add one of those Array’s to the loop and overwrite the default value.
    Just like this.

    
    <?php if ( bp_has_profile( array ( 'exclude_groups' => 1 ) ) ) : ?>
    ...
    

    This works perfect, it hides all xProfile-fields from the first Base primary Tab (back-end). Just like I wanted it because I didn’t want all the fields to show up front-end, I’ve got a few xProfile-fields that I use for user-customization of the profile-page. Each user can add color-codes to change the default menu-color and add background-images to their profile-page to make each profile a little more unique.
    Those field-ID’s are just urls or color-codes and don’t have to be visable to the public, thats why I try to hide them front-end.

    buddypress member pofile tab

    Avatar of Henry
    Henry
    Participant

    @henrywright-1

    @macpresss

    Take a look at this page to see the parameters accepted:

    http://codex.buddypress.org/developer/loops-reference/the-profile-fields-loop-bp_has_profile/

    Perhaps try using profile_group_id:

    By default all groups and all fields will be displayed. If you provide the ID of a profile field group, then only the fields in this group will be displayed

    So it would be:

    if ( bp_has_profile( 'profile_group_id=2' ) ) :

    Where 2 is the ID(s) of the group you’d like to include. I think it should take a comma separated list but I haven’t tested.

    Avatar of Shmoo
    Shmoo
    Participant

    @macpresss

    Yes that works much better, no error to show up this time.

    Thanks.

Viewing 7 replies - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.