-1

I'm trying to set a limit on the numbers of letters user can add to their xprofile fields in their BuddyPress profiles.

For example, in BIO field, max limit will be 300 letters.

Please give me complete code if you can, because I have read lots of article about it but couldn't manage to find a code that works.

Thank you, Shay.

closed as off-topic by Howdy_McGee May 10 '17 at 5:12

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • Check out my answer at wordpress.stackexchange.com/a/262572/66711 - you can use a similar approach, just count the characters in $values instead of querying for identical values. – user66711 Apr 6 '17 at 14:19
  • Alternatively if you have a custom field type you can try defining BP_XProfile_Field_Type::$validation_regex with a regex like /^.{0,300}$/. – user66711 Apr 6 '17 at 14:25
2

Try this code, if it will helps:

function filtered_profile_data( $args ) {

$data = bp_get_member_profile_data( $args );

$defaults = array(
    'field' => false, // Field name
    'user_id' => $user_id
);

$r = wp_parse_args( $args, $defaults );
extract( $r, EXTR_SKIP );

switch($field) {
    case 'Field Name': // for specific field character limit
    $max_len = 10;
    break;
    default:
    $max_len = 5;
    break;
}

echo substr( $data, 0, $max_len);

}
  • Hi! thank you for replying! but i couldn't figure out where should I change the code to my field details and how.. and does it applies on BP xProfile fields plugin? – Shay S Apr 9 '17 at 9:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.