category = _x( 'Multi Fields', 'xprofile field type category', 'buddypress' ); $this->name = _x( 'Radio Buttons', 'xprofile field type', 'buddypress' ); $this->supports_options = true; $this->set_format( '/^.+$/', 'replace' ); /** * Fires inside __construct() method for BP_XProfile_Field_Type_Radiobutton class. * * @since 2.0.0 * * @param BP_XProfile_Field_Type_Radiobutton $this Current instance of * the field type radio button. */ do_action( 'bp_xprofile_field_type_radiobutton', $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/input.radio.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(); } ?>

$user_id ) ); if ( ! bp_get_the_profile_field_is_required() ) : $clear = 'clear'; if ( is_admin() && ! wp_doing_ajax() ) { $clear = 'bp.clear'; } $js_clear = sprintf( 'javascript:%1$s( \'%2$s\' );', $clear, esc_js( bp_get_the_profile_field_input_name() ) ); ?> field_obj->id, $args['user_id'] ); $options = $this->field_obj->get_children(); $html = ''; for ( $k = 0, $count = count( $options ); $k < $count; ++$k ) { // Check for updated posted values, but errors preventing them from // being saved first time. if ( isset( $_POST['field_' . $this->field_obj->id] ) && $option_value != $_POST['field_' . $this->field_obj->id] ) { if ( ! empty( $_POST['field_' . $this->field_obj->id] ) ) { $option_value = 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 ); $selected = ''; if ( $option_value === $allowed_options || ( empty( $option_value ) && ! empty( $options[$k]->is_default_option ) ) ) { $selected = ' checked="checked"'; } $new_html = sprintf( '', $selected, esc_attr( bp_get_the_profile_field_input_name() ), esc_attr( "option_{$options[$k]->id}" ), esc_attr( stripslashes( $options[$k]->name ) ), esc_html( stripslashes( $options[$k]->name ) ) ); /** * Filters the HTML output for an individual field options radio button. * * @since 1.1.0 * * @param string $new_html Label and radio input field. * @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_radio', $new_html, $options[$k], $this->field_obj->id, $selected, $k ); } printf( '
%2$s
', esc_attr( 'field_' . $this->field_obj->id ), $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() ) { bp_the_profile_field_options(); if ( bp_get_the_profile_field_is_required() ) { return; } ?>