category = _x( 'Multi Fields', 'xprofile field type category', 'buddypress' ); $this->name = _x( 'Drop Down Select Box', 'xprofile field type', 'buddypress' ); $this->supports_options = true; $this->set_format( '/^.+$/', 'replace' ); /** * Fires inside __construct() method for BP_XProfile_Field_Type_Selectbox class. * * @since 2.0.0 * * @param BP_XProfile_Field_Type_Selectbox $this Current instance of * the field type select box. */ do_action( 'bp_xprofile_field_type_selectbox', $this ); } /** * Output the edit field HTML for this field type. * * Must be used inside the {@link bp_profile_fields()} template loop. * * @since 2.0.0 * * @param array $raw_properties Optional key/value array of * {@link http://dev.w3.org/html5/markup/select.html permitted attributes} * that you want to add. */ public function edit_field_html( array $raw_properties = array() ) { // User_id is a special optional parameter that we pass to // {@link bp_the_profile_field_options()}. if ( isset( $raw_properties['user_id'] ) ) { $user_id = (int) $raw_properties['user_id']; unset( $raw_properties['user_id'] ); } else { $user_id = bp_displayed_user_id(); } ?>

field_obj->id, $args['user_id'] ) ); $options = $this->field_obj->get_children(); $html = ''; if ( empty( $original_option_values ) && !empty( $_POST['field_' . $this->field_obj->id] ) ) { $original_option_values = sanitize_text_field( $_POST['field_' . $this->field_obj->id] ); } $option_values = ( $original_option_values ) ? (array) $original_option_values : array(); for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) { $selected = ''; // Check for updated posted values, but errors preventing them from // being saved first time. foreach( $option_values as $i => $option_value ) { if ( isset( $_POST['field_' . $this->field_obj->id] ) && $_POST['field_' . $this->field_obj->id] != $option_value ) { if ( ! empty( $_POST['field_' . $this->field_obj->id] ) ) { $option_values[$i] = sanitize_text_field( $_POST['field_' . $this->field_obj->id] ); } } } // Run the allowed option name through the before_save filter, so // we'll be sure to get a match. $allowed_options = xprofile_sanitize_data_value_before_save( $options[$k]->name, false, false ); // First, check to see whether the user-entered value matches. if ( in_array( $allowed_options, $option_values ) ) { $selected = ' selected="selected"'; } // Then, if the user has not provided a value, check for defaults. if ( ! is_array( $original_option_values ) && empty( $option_values ) && $options[$k]->is_default_option ) { $selected = ' selected="selected"'; } /** * Filters the HTML output for options in a select input. * * @since 1.1.0 * * @param string $value Option tag for current value being rendered. * @param object $value Current option being rendered for. * @param int $id ID of the field object being rendered. * @param string $selected Current selected value. * @param string $k Current index in the foreach loop. */ $html .= apply_filters( 'bp_get_the_profile_field_options_select', '' . esc_html( stripslashes( $options[$k]->name ) ) . '', $options[$k], $this->field_obj->id, $selected, $k ); } echo $html; } /** * Output HTML for this field type on the wp-admin Profile Fields screen. * * Must be used inside the {@link bp_profile_fields()} template loop. * * @since 2.0.0 * * @param array $raw_properties Optional key/value array of permitted attributes that you want to add. */ public function admin_field_html( array $raw_properties = array() ) { ?>