adding html attributes to Xprofile fields – code check
-
I need to add some html attributes to some Xprofile fields such as max-length. I was trying to find a filter so I could use str_replace to add attributes, but I eventually found the filter
bp_xprofile_field_edit_html_elements
in bp-xprofile/classes/class-bp-xprofile-field-type.php.
I’ve now got this code which works, but I’m not great with PHP so just checking if this is the best way to achieve this:function hp_xprofile_add_attributes($r){ $field_name = bp_get_the_profile_field_name(); if( $field_name == 'Name' ) { $new_attribute['maxlength']= '20'; $attributes = array_merge($new_attribute, $r); } elseif( $field_name == 'Short Description') { $new_attribute['maxlength']= '160'; $attributes = array_merge($new_attribute, $r); } else { $attributes = $r; } return $attributes; } add_filter('bp_xprofile_field_edit_html_elements', 'hp_xprofile_add_attributes', 11);
Any help appreciated.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- You must be logged in to reply to this topic.