Skip to:
Content
Pages
Categories
Search
Top
Bottom

BP 1.2 : problem with bp_profile_group_has_fields()


  • grosbouff
    Participant

    @grosbouff

    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;

    }

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

  • grosbouff
    Participant

    @grosbouff

    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…


    grosbouff
    Participant

    @grosbouff

    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…

    Can you post this in a ticket please?


    nig3d
    Participant

    @nig3d

    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.


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    @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?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘BP 1.2 : problem with bp_profile_group_has_fields()’ is closed to new replies.
Skip to toolbar