Group Mods

  • Profile picture of @mercime
  • Profile picture of r-a-y
  • Profile picture of Hugo

Support: Creating & Extending

Existing and new plugins/components and themes.

BP 1.2 : problem with bp_profile_group_has_fields() (6 posts)

Started 2 years, 4 months ago by: Grosbouff

  • Profile picture of Grosbouff grosbouff said 2 years, 4 months ago:

    I used this code with BP 1.1.3 to retrieve the fields into my plugin admin options (bp-real-names).

    I’m now trying to update it for BP 1.2; the problem is that the function bp_profile_group_has_fields() returns me false; I don’t understand why.
    Any idea ?
    Thanks !

    if ( bp_has_profile() ) {

    while ( bp_profile_groups() ) : bp_the_profile_group();
    global $group;

    $one_group = array();
    $one_group['id'] = $group->id;
    $one_group['name'] = $group->name;

    $groups[ $group->id ] = $one_group;

    print_r(“test”); //prints
    if ( bp_profile_group_has_fields() ) {
    print_r(“test2″); //do not print
    while ( bp_profile_fields() ) : bp_the_profile_field();

    if ( bp_field_has_data() ) {
    global $field;

    $one_field = array();
    $one_field['id'] = $field->id;
    $one_field['name'] = $field->name;

    $fields[] = $one_field;
    }
    endwhile;
    }

    endwhile;
    }

  • Profile picture of Grosbouff grosbouff said 2 years, 4 months ago:

    Seems this has something to do with function has_fields() :

    function has_fields() {
    $has_data = false;

    for ( $i = 0; $i < count( $this->group->fields ); $i++ ) {
    $field = &$this->group->fields[$i];
    if ( $field->data->value != null ) {
    $has_data = true;
    }
    }

    if ( $has_data )
    return true;

    return false;
    }

    print_r($field) returns

    teststdClass Object ( [id] => 1 [name] => Name [type] => textbox [group_id] => 1 ) stdClass Object ( [id] => 2 [name] => Name [type] => textbox [group_id] => 1 ) stdClass Object ( [id] => 3 [name] => First Name [type] => textbox [group_id] => 1 ) stdClass Object ( [id] => 4 [name] => Both Names [type] => textbox [group_id] => 1 )

    print_r($field->data) returns FALSE…

  • Profile picture of Grosbouff grosbouff said 2 years, 4 months ago:

    Ok, I founded out :

    if ( bp_has_profile() ) {

    while ( bp_profile_groups() ) : bp_the_profile_group();
    global $group;

    $one_group = array();
    $one_group['id'] = $group->id;
    $one_group['name'] = $group->name;

    $groups[ $group->id ] = $one_group;

    //if ( bp_profile_group_has_fields() ) {

    while ( bp_profile_fields() ) : bp_the_profile_field();

    //if ( bp_field_has_data() ) {
    global $field;

    $one_field = array();
    $one_field['id'] = $field->id;
    $one_field['name'] = $field->name;

    $fields[] = $one_field;
    //}
    endwhile;
    //}

    endwhile;
    }

    Hope that it’s ok to comment those lines…

  • Profile picture of Andy Peatling Andy Peatling said 2 years, 4 months ago:

    Can you post this in a ticket please?

  • Profile picture of nig3d nig3d said 2 years ago:

    this hasn’t be fixed yet. Has the ticket been created?
    Moreover what was bp_fields_has_data supposed to do originally? Because if it should check if the field exists, it seems straightforward to fix.

  • Profile picture of John James Jacoby John James Jacoby said 2 years ago:

    @grosbouff For the purpose of your plugin, bp_profile_group_has_fields gets in the way. The purpose of bp_profile_group_has_fields in the default theme, is that it will skip over any group of fields that have no values filled in when inside the profile loop.

    I think what you want to use is bp_field_has_data().

    I also don’t think that this is a bug. All of those functions are doing exactly what is expected.

    Can you explain in more detail what you need these functions to do?