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
-
(Optional) The field name to get attributes for.
Default value: ''
- $attributes
-
(Optional) Array of existing attributes to add.
Default value: array()
Return
(string)
Source
File: bp-core/bp-core-template.php
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 | 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
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.