Skip to content

Instantly share code, notes, and snippets.

@gagimilicevic
Created May 19, 2020 21:00
Show Gist options
  • Save gagimilicevic/d0193b46ed00ac65e9f69019f8429c2a to your computer and use it in GitHub Desktop.
Save gagimilicevic/d0193b46ed00ac65e9f69019f8429c2a to your computer and use it in GitHub Desktop.
BuddyPress prevent duplicate Group Names
/**
* Create Shoebox - Check if Shoebox name already exists if does do not create duplicated shoebox.
*/
function dwply_check_group_name( $group_new ) {
if ( 'group-details' == bp_get_groups_current_create_step() ) {
$args = array(
'per_page' => null,
'populate_extras' => false,
'update_meta_cache' => false
);
$groups = groups_get_groups( $args );
foreach ( $groups['groups'] as $group ) {
if( $group->name == $group_new->name ) {
$group_new->name = '';
dwply_group_name_error_message();
break;
}
}
}
}
add_action( 'groups_group_before_save', 'dwply_check_group_name' );
/**
* Create Shoebox - Duplicated Shoebox error message.
*/
function dwply_group_name_error_message() {
global $l10n;
$mo = new MO();
$mo->add_entry(array(
'singular' => 'That group name is already in use. Please try again.',
'translations' => array(
__('That name is already being used. Please use a different name.', 'Buddypress')
)
));
if (isset($l10n['buddypress'])) $mo->merge_with($l10n['buddypress']);
$l10n['buddypress'] = & $mo;
unset($mo);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment