Advertisement
Guest User

Untitled

a guest
Nov 3rd, 2015
159
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function check_group_name_for_duplicates( $group ) {
  2.  
  3.         // Check we are at the right step.
  4.         if ( bp_get_groups_current_create_step() !== 'group-details' ) {
  5.                 return;
  6.         }
  7.  
  8.         // Bail if the group name isn't set.
  9.         if ( empty( $group->name ) ) {
  10.                 return;
  11.         }
  12.  
  13.         global $wpdb;
  14.         $table_name = buddypress()->groups->table_name;
  15.  
  16.         // Check if the group name already exists.
  17.         $retval = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$table_name} WHERE name = %s", strtolower( $group->name ) ) );
  18.  
  19.         // If group name exists, display an error message.
  20.         if ( $retval !== NULL ) {
  21.                 bp_core_add_message( __( 'Please add your error message here.', 'text-domain' ), 'error' );
  22.                 bp_core_redirect( trailingslashit( bp_get_groups_directory_permalink() . 'create/step/group-details' ) );
  23.         }
  24. }
  25. add_action( 'groups_group_before_save', 'check_group_name_for_duplicates' );
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement