bp_xprofile_repeater_field_get_children( array $children, boolean $for_editing, BP_XProfile_Field $field )

Return children of repeated field sets.

Description

Parameters

$children

(Required)

$for_editing

(Required)

$field

(Required)

Source

File: bp-xprofile/bp-xprofile-repeaters.php

608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
function bp_xprofile_repeater_field_get_children ( $children, $for_editing, $field ) {
    global $wpdb;
    $bp = buddypress();
     
    if ( ! bp_xprofile_get_meta( $field->id, 'field', '_is_repeater_clone', true ) ) {
        return $children;
    }
     
    //If the current field is a clone,
    //we'll query template field for children/field-options
    $template_field_id = bp_xprofile_get_meta( $field->id, 'field', '_cloned_from', true );
    if ( empty( $template_field_id ) ) {
        return $children;
    }
     
    $template_field = xprofile_get_field( $template_field_id );
    if ( $template_field == null ) {
        return $children;
    }
     
    if ( ! ( $template_children = wp_cache_get( $template_field_id, 'field_children_options' ) ) ) {
        // This is done here so we don't have problems with sql injection.
        if ( empty( $for_editing ) && ( 'asc' === $template_field->order_by ) ) {
            $sort_sql = 'ORDER BY name ASC';
        } elseif ( empty( $for_editing ) && ( 'desc' === $template_field->order_by ) ) {
            $sort_sql = 'ORDER BY name DESC';
        } else {
            $sort_sql = 'ORDER BY option_order ASC';
        }
 
        $parent_id = $template_field_id;
 
        $bp  = buddypress();
        $sql = $wpdb->prepare( "SELECT * FROM {$bp->profile->table_name_fields} WHERE parent_id = %d AND group_id = %d {$sort_sql}", $parent_id, $template_field->group_id );
 
        $template_children = $wpdb->get_results( $sql );
         
        wp_cache_set( $template_field_id, $template_children, 'field_children_options' );
    }
     
    if ( !empty( $template_children ) ) {
         
        //Since some children will be shared in all clones of a kind,
        //there are duplicate radiobutton/checkbox ids and hence associated labels behave incorreclty.
        //we'll need to manipuate children ids
        $temp = array();
        $clone_number = (int) bp_xprofile_get_meta( $field->id, 'field', '_clone_number', true );
        foreach ( $template_children as $child ) {
            $child->id .= '_' . $clone_number;
            $temp[] = $child;
        }
         
        $children = $temp;
    }
     
    return $children;
}

Changelog

Changelog
Version Description
BuddyBoss 1.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.