Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sbrajesh/48cce7bac52fff2b39d1f3cc395a21f0 to your computer and use it in GitHub Desktop.
Save sbrajesh/48cce7bac52fff2b39d1f3cc395a21f0 to your computer and use it in GitHub Desktop.
Limits the number of characters allowed in BuddyPress Group description
// For Group creation.
add_action( 'groups_action_sort_creation_steps', function () {
$allowed_length = 225; // how may characters are allowed?
$step = wp_unslash( bp_action_variable( 1 ) );
if ( empty( $_POST['save'] ) ) {
return;
}
if ( 'group-details' !== $step || empty( $_POST['group-desc'] ) ) {
return;
}
if ( mb_strlen( $_POST['group-desc'] ) > $allowed_length ) {
bp_core_add_message( sprintf( 'Group description must be less than %d characters.', $allowed_length ), 'error' );
bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create/step/' . $step ) );
}
} );
// Group->Manage->Details update screen.
add_action( 'bp_screens', function () {
$allowed_length = 225; // how may characters are allowed?
if ( 'edit-details' !== bp_get_group_current_admin_tab() || ! bp_is_item_admin() ) {
return false;
}
if ( empty( $_POST['group-desc'] ) ) {
return;
}
if ( mb_strlen( $_POST['group-desc'] ) > $allowed_length ) {
bp_core_add_message( sprintf( 'Group description must be less than %d characters.', $allowed_length ), 'error' );
bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/edit-details/' );
}
}, 8 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment