BuddyDev

Search

[Resolved] No text limit on buddypress group description

  • Participant
    Level: Initiated
    Posts: 3
    Buddypress guy on #50212

    Hello buddydev

    When a user makes a group or modifies the description
    they can type an unlimited number of characters.

    This BP core file

    The bp_create_excerpt () (in bp-core-template.php, line 365)
    sets the length of the description to 225 characters

    This only limits the group excerpt description length on the
    Groups directory page. Not the actual content amount .

    I copy and pasted 200 thousand characters into the group
    description edit box. All 200 thousand were saved and pushed
    into the database.

    Tryed these codes in theme functions and bp-custom
    They only work on the excerpt.

    —————

    function bbg_custom_group_description_excerpt( $excerpt, $group ) {
    $excerpt = bp_create_excerpt( $group->description, 270 );
    return $excerpt;
    }
    add_filter( ‘bp_get_group_description_excerpt’, ‘bbg_custom_group_description_excerpt’, 70, 2 );

    —————

    and this below

    —————

    add_action( ‘groups_group_details_edited’, ‘yzc_group_limit_description’ );
    add_action( ‘groups_created_group’, ‘yzc_group_limit_description’ );

    function yzc_group_limit_description( $group_id ) {

    if ( isset( $_POST[‘group-desc’] ) && ! empty( $_POST[‘group-desc’] ) ) {
    $limit_length = 270;
    if ( strlen( $_POST[‘group-desc’] ) > $limit_length ) {
    bp_core_add_message( sprintf( __( ‘Sorry, You cannot add more than %d character in group description.’, $limit_length ),

    ‘buddypress’ ), ‘error’ );
    }
    }

    }

    ———————

    Do you have some code that would work?
    that would be extra great !

    Thank you

    Buddypress guy

  • Keymaster
    (BuddyDev Team)
    Posts: 24766
    Brajesh Singh on #50216

    Hi,
    Welcome to BuddyDev support forums.
    The first snippet limits display and not store and the second snippet you have shared has limited scope.

    What is your goal with it.Do you want to limit(truncate) description before saving or do you want to show error if a user posts more than ‘n’ characters?

    Please let me know and we will assist.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 3
    Buddypress guy on #50230

    Hello Brajesh
    Thank you for the response.

    For me first and second snippit limits display — but they -do- allow store

    If a user types or pastes any number of characters they are all saved.
    I pasted 100 thousand characters. After save, All of the text in the group
    description edit box was still there.

    I looked at the wordpress buddypress backend ,- / Groups list edit.
    All of the text was there It filled up 3 pages.

    Limit (truncate) description before saving would be awesome.
    something that would stop an exceeded number of characters from
    being typed or pasted beyond a set limit. Then, there is no way too
    many characters could be saved.

    The group name edit is already doing that at 100 characters, I guess
    there is a core file somewhere doing that.

    Thank you Brajesh

    BPress-guy

  • Participant
    Level: Initiated
    Posts: 3
    Buddypress guy on #50268

    Hi Brajesh

    Here is some buddydev code I found on the web that is working on
    buddypress profile edit

    I’ve been trying to tweek it so it will work on group description edit
    — with out any luck.

    Maybe you would know how do it easy ? That way you wouldn’t
    have to write anything new.

    —————————————

    function buddydev_limit_xpfield_length( $validated, $values, $field ) {
    $allowed_len = 0;

    if ( $field instanceof BP_XProfile_Field_Type_Textarea ) {
    $allowed_len = 600;
    } elseif ( $field instanceof BP_XProfile_Field_Type_Textbox ) {
    $allowed_len = 300;
    }

    if ( $allowed_len ) {
    $validated = strlen( $values ) < $allowed_len;
    }

    return $validated;
    }

    add_filter( ‘bp_xprofile_field_type_is_valid’, ‘buddydev_limit_xpfield_length’, 10, 3 );

    —————————————

    Thank you

    BPress-guy

  • Keymaster
    (BuddyDev Team)
    Posts: 24766
    Brajesh Singh on #50291

    Hi,
    Thank you for the reply.
    I have looked at it and there is no direct way but we can hack around it.

    I will put some code in next 24 hours to assist you with it.

    Regards
    Brajesh

  • Keymaster
    (BuddyDev Team)
    Posts: 24766
    Brajesh Singh on #50328

    Hi,
    Hope you are doing well.
    Thank you for your patience.

    Please use the code from this gist and update the allowed length as you need.

    https://gist.github.com/sbrajesh/48cce7bac52fff2b39d1f3cc395a21f0

    Hope that helps.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 3
    Buddypress guy on #50354

    Hi Brajesh

    HEY ! This code works Great ! You even put the error message on it.
    It looks like fair amount of work. Thank you !

    I have some useful BP code that will replace the users profile name
    with the username. Profile names can be duplicated.—If 100 users call
    themselves ” John Doe ” a members search will find 100 John Doe.
    / Activity stream – which one made this post ?
    This code will solve that.

    —– How do I post it on code snips page ? ? ?

    Thank you
    BPress-guy

  • Keymaster
    (BuddyDev Team)
    Posts: 24766
    Brajesh Singh on #50368

    Hi,
    Thank you.
    I am glad it worked.

    Thank you for your kind intention of sharing with the community. Our snippets section needs maintinence and that’s why we have disabled new snippet creation for now.

    Please use this support forum to share the code(or even better link to a gist on github.com from here on this forum)

    Regards
    Brajesh

You must be logged in to reply to this topic.

This topic is: resolved