diff --git src/bp-xprofile/bp-xprofile-admin.php src/bp-xprofile/bp-xprofile-admin.php
index 5d93acb..a94499a 100644
|
|
|
function xprofile_admin_field( $admin_field, $admin_group, $class = '' ) { |
| 508 | 508 | |
| 509 | 509 | <?php if ( empty( $field->can_delete ) ) : ?><?php esc_html_e( '(Primary)', 'buddypress' ); endif; ?> |
| 510 | 510 | <?php if ( bp_get_the_profile_field_is_required() ) : ?><?php esc_html_e( '(Required)', 'buddypress' ); endif; ?> |
| 511 | | <?php if ( bp_xprofile_get_meta( $field->id, 'field', 'signup_position' ) ) : ?><?php esc_html_e( '(Sign-up)', 'buddypress' ); endif; ?> |
| 512 | 511 | |
| 513 | 512 | <?php |
| | 513 | // Check for Signup position and member type metas |
| | 514 | $field_metas = bp_xprofile_get_meta( $field->id, 'field' ); |
| | 515 | |
| | 516 | if ( $field_metas ) { |
| | 517 | foreach ( $field_metas as $meta_key => $meta_value ) { |
| | 518 | if ( 'signup_position' === $meta_key ) { |
| | 519 | esc_html_e( '(Sign-up)', 'buddypress' ); |
| | 520 | } |
| | 521 | |
| | 522 | if ( 'member-type' === $meta_key ) { |
| | 523 | $label = reset( $meta_value ); |
| | 524 | $labels = array(); |
| | 525 | |
| | 526 | if ( 'none' !== $label ) { |
| | 527 | $member_types = bp_get_member_types( array(), 'objects' ); |
| | 528 | |
| | 529 | foreach ( $meta_value as $member_type ) { |
| | 530 | if ( ! isset( $member_types[ $member_type ] ) ) { |
| | 531 | continue; |
| | 532 | } |
| | 533 | |
| | 534 | $labels[] = $member_types[ $member_type ]->labels['singular_name']; |
| | 535 | } |
| | 536 | |
| | 537 | $label = join( ', ', $labels ); |
| | 538 | } |
| | 539 | |
| | 540 | printf( esc_html__( '(Member types: %s)', 'buddypress' ), $label ); |
| | 541 | } |
| | 542 | } |
| | 543 | } |
| 514 | 544 | |
| 515 | 545 | /** |
| 516 | 546 | * Fires at end of legend above the name field in base xprofile group. |
diff --git src/bp-xprofile/classes/class-bp-xprofile-group.php src/bp-xprofile/classes/class-bp-xprofile-group.php
index 9056da9..27146a4 100644
|
|
|
class BP_XProfile_Group { |
| 334 | 334 | // Fetch the fields |
| 335 | 335 | $fields = $wpdb->get_results( "SELECT id, name, description, type, group_id, is_required FROM {$bp->profile->table_name_fields} WHERE group_id IN ( {$group_ids_in} ) AND parent_id = 0 {$exclude_fields_sql} ORDER BY field_order" ); |
| 336 | 336 | |
| 337 | | // Remove fields based on member-type restrictions, if necessary. |
| 338 | | if ( $r['user_id'] ) { |
| 339 | | $user_member_types = bp_get_member_type( $r['user_id'], false ); |
| 340 | | if ( empty( $user_member_types ) ) { |
| | 337 | // If some member types are set, remove fields based on member-type restrictions, if necessary. |
| | 338 | if ( bp_get_member_types() ) { |
| | 339 | |
| | 340 | if ( $r['user_id'] ) { |
| | 341 | $user_member_types = bp_get_member_type( $r['user_id'], false ); |
| | 342 | } else { |
| | 343 | $user_member_types = apply_filters( 'bp_xprofile_field_restrict_to_member_types', array() ); |
| | 344 | } |
| | 345 | |
| | 346 | // Users with no member type |
| | 347 | if ( false === $user_member_types ) { |
| 341 | 348 | $user_member_types = array( 'none' ); |
| 342 | 349 | } |
| 343 | 350 | |
| 344 | | foreach ( $fields as $k => $_field ) { |
| 345 | | $field_obj = new BP_XProfile_Field( $_field->id ); |
| 346 | | $field_member_types = $field_obj->get_member_types(); |
| 347 | | $matching_types = array_intersect( $user_member_types, $field_member_types ); |
| 348 | | if ( empty( $matching_types ) ) { |
| 349 | | unset( $fields[ $k ] ); |
| | 351 | if ( ! empty( $user_member_types ) ) { |
| | 352 | |
| | 353 | foreach ( $fields as $k => $_field ) { |
| | 354 | $field_obj = new BP_XProfile_Field( $_field->id ); |
| | 355 | $field_member_types = $field_obj->get_member_types(); |
| | 356 | $matching_types = array_intersect( $user_member_types, $field_member_types ); |
| | 357 | if ( empty( $matching_types ) ) { |
| | 358 | unset( $fields[ $k ] ); |
| | 359 | } |
| 350 | 360 | } |
| 351 | | } |
| 352 | 361 | |
| 353 | | // Reset indexes. |
| 354 | | $fields = array_values( $fields ); |
| | 362 | // Reset indexes. |
| | 363 | $fields = array_values( $fields ); |
| | 364 | } |
| 355 | 365 | } |
| 356 | 366 | |
| 357 | 367 | $field_ids = wp_list_pluck( $fields, 'id' ); |