BP_XProfile_Field_Type_Member_Types::edit_field_options_html( array $args = array() )
Output the edit field options HTML for this field type.
Description
BuddyPress considers a field’s "options" to be, for example, the items in a selectbox. These are stored separately in the database, and their templating is handled separately.
This templating is separate from BP_XProfile_Field_Type::edit_field_html() because it’s also used in the wp-admin screens when creating new fields, and for backwards compatibility.
Must be used inside the bp_profile_fields() template loop.
Parameters
- $args
-
(Optional) The arguments passed to bp_the_profile_field_options().
Default value: array()
Source
File: bp-xprofile/classes/class-bp-xprofile-field-type-member-types.php
public function edit_field_options_html( array $args = array() ) { global $field; $post_type_selected = $this->get_selected_post_type( $field->id ); $post_selected = BP_XProfile_ProfileData::get_value_byid( $this->field_obj->id, $args['user_id'] ); $html = ''; if ( ! empty( $_POST[ 'field_' . $this->field_obj->id ] ) ) { $new_post_selected = (int) $_POST[ 'field_' . $this->field_obj->id ]; $post_selected = ( $post_selected != $new_post_selected ) ? $new_post_selected : $post_selected; } // Add Profile Type selected if users have previously added profile type in his/her account. if ( '' === $post_selected ) { $member_type = bp_get_member_type( (int) $args['user_id'] ); if ( '' !== $member_type ) { $post_selected = bp_member_type_post_by_type( $member_type ); } } // Get posts of custom post type selected. $posts = new \WP_Query( array( 'posts_per_page' => - 1, 'post_type' => bp_get_member_type_post_type(), 'orderby' => 'title', 'order' => 'ASC' ) ); if ( $posts ) { $html .= '<option value="">' . /* translators: no option picked in select box */ esc_html__( '----', 'buddyboss' ) . '</option>'; foreach ( $posts->posts as $post ) { $enabled = get_post_meta( $post->ID, '_bp_member_type_enable_profile_field', true ); if ( '' === $enabled || '1' === $enabled ) { $html .= sprintf( '<option value="%s" %s>%s</option>', $post->ID, ( $post_selected == $post->ID ) ? ' selected="selected"' : '', $post->post_title ); } } } echo apply_filters( 'bp_get_the_profile_field_member_type_post_type', $html, $args['type'], $post_type_selected, $this->field_obj->id ); }
Changelog
Version | Description |
---|---|
BuddyBoss 1.1.3 | 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.