bp_get_form_field_attributes( string $name = '', array $attributes = array() )

Get the attributes for a form field.

Description

Primarily to add better support for touchscreen devices, but plugin devs can use the ‘bp_get_form_field_extra_attributes’ filter for further manipulation.

Parameters

$name

(string) (Optional) The field name to get attributes for.

Default value: ''

$attributes

(array) (Optional) Array of existing attributes to add.

Default value: array()

Return

(string)

Source

File: bp-core/bp-core-template.php

	function bp_get_form_field_attributes( $name = '', $attributes = array() ) {
		$retval = '';

		if ( empty( $attributes ) ) {
			$attributes = array();
		}

		$name = strtolower( $name );

		switch ( $name ) {
			case 'username' :
			case 'blogname' :
				$attributes['autocomplete']   = 'off';
				$attributes['autocapitalize'] = 'none';
				break;

			case 'email' :
				if ( wp_is_mobile() ) {
					$attributes['autocapitalize'] = 'none';
				}
				break;

			case 'password' :
				$attributes['spellcheck']   = 'false';
				$attributes['autocomplete'] = 'off';

				if ( wp_is_mobile() ) {
					$attributes['autocorrect']    = 'false';
					$attributes['autocapitalize'] = 'none';
				}
				break;
		}

		/**
		 * Filter the attributes for a field before rendering output.
		 *
		 * @since BuddyPress 2.2.0
		 *
		 * @param array  $attributes The field attributes.
		 * @param string $name       The field name.
		 */
		$attributes = (array) apply_filters( 'bp_get_form_field_attributes', $attributes, $name );

		foreach( $attributes as $attr => $value ) {
			// Numeric keyed array.
			if (is_numeric( $attr ) ) {
				$retval .= sprintf( ' %s', esc_attr( $value ) );

			// Associative keyed array.
			} else {
				$retval .= sprintf( ' %s="%s"', sanitize_key( $attr ), esc_attr( $value ) );
			}
		}

		return $retval;
	}

Changelog

Changelog
Version Description
BuddyPress 2.2.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.