BP_XProfile_Field::get_member_types()
Gets the member types to which this field should be available.
Description Description
Will not return inactive member types, even if associated metadata is found.
‘null’ is a special pseudo-type, which represents users that do not have a member type.
Return Return
(array) Array of member type names.
Source Source
File: bp-xprofile/classes/class-bp-xprofile-field.php
public function get_member_types() {
if ( ! is_null( $this->member_types ) ) {
return $this->member_types;
}
$raw_types = bp_xprofile_get_meta( $this->id, 'field', 'member_type', false );
// If `$raw_types` is not an array, it probably means this is a new field (id=0).
if ( ! is_array( $raw_types ) ) {
$raw_types = array();
}
// If '_none' is found in the array, it overrides all types.
$types = array();
if ( ! in_array( '_none', $raw_types ) ) {
$registered_types = bp_get_member_types();
// Eliminate invalid member types saved in the database.
foreach ( $raw_types as $raw_type ) {
// 'null' is a special case - it represents users without a type.
if ( 'null' === $raw_type || isset( $registered_types[ $raw_type ] ) ) {
$types[] = $raw_type;
}
}
// If no member types have been saved, intepret as *all* member types.
if ( empty( $types ) ) {
$types = array_values( $registered_types );
// + the "null" type, ie users without a type.
$types[] = 'null';
}
}
/**
* Filters the member types to which an XProfile object should be applied.
*
* @since 2.4.0
*
* @param array $types Member types.
* @param BP_XProfile_Field $field Field object.
*/
$this->member_types = apply_filters( 'bp_xprofile_field_member_types', $types, $this );
return $this->member_types;
}
Changelog Changelog
| Version | Description |
|---|---|
| 2.4.0 | Introduced. |