bp_xprofile_admin_form_field_types( string $select_field_type )
Print <option>
elements containing the xprofile field types.
Description
Parameters
- $select_field_type
-
(string) (Required) The name of the field type that should be selected. Will defaults to "textbox" if NULL is passed.
Source
File: bp-xprofile/bp-xprofile-admin.php
function bp_xprofile_admin_form_field_types( $select_field_type ) { $categories = array(); if ( is_null( $select_field_type ) ) { $select_field_type = 'textbox'; } // Sort each field type into its category. foreach ( bp_xprofile_get_field_types() as $field_name => $field_class ) { $field_type_obj = new $field_class; $the_category = $field_type_obj->category; // Fallback to a catch-all if category not set. if ( ! $the_category ) { $the_category = __( 'Other', 'buddyboss' ); } if ( isset( $categories[$the_category] ) ) { $categories[$the_category][] = array( $field_name, $field_type_obj ); } else { $categories[$the_category] = array( array( $field_name, $field_type_obj ) ); } } // Sort the categories alphabetically. ksort()'s SORT_NATURAL is only in PHP >= 5.4 :((. uksort( $categories, 'strnatcmp' ); // Disable Gender field if that is already added previously. global $wpdb; $disabled_gender = false; $exists_gender = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}bp_xprofile_fields a WHERE parent_id = 0 AND type = 'gender' "); if ( $exists_gender > 0 ) { $disabled_gender = true; } $disabled_social_networks = false; $exists_social_networks = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}bp_xprofile_fields a WHERE parent_id = 0 AND type = 'socialnetworks' "); if ( $exists_social_networks > 0 ) { $disabled_social_networks = true; } // Loop through each category and output form <options>. foreach ( $categories as $category => $fields ) { printf( '<optgroup label="%1$s">', esc_attr( $category ) ); // Already i18n'd in each profile type class. // Sort these fields types alphabetically. uasort( $fields, function( $a, $b ) { return strnatcmp( $a[1]->name, $b[1]->name ); } ); foreach ( $fields as $field_type_obj ) { $field_name = $field_type_obj[0]; $field_type_obj = $field_type_obj[1]; if ( 'gender' === $field_name && true === $disabled_gender ) { printf( '<option value="%1$s" %2$s>%3$s</option>', esc_attr( $field_name ), selected( $select_field_type, $field_name, false ), esc_html( $field_type_obj->name ) ); } elseif ( 'socialnetworks' === $field_name && true === $disabled_social_networks) { printf( '<option value="%1$s" %2$s>%3$s</option>', esc_attr( $field_name ), selected( $select_field_type, $field_name, false ), esc_html( $field_type_obj->name ) ); } else { printf( '<option value="%1$s" %2$s>%3$s</option>', esc_attr( $field_name ), selected( $select_field_type, $field_name, false ), esc_html( $field_type_obj->name ) ); } } printf( '</optgroup>' ); } }
Changelog
Version | Description |
---|---|
BuddyPress 2.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.