Show Sidebar Log in
Commons In A Box Logo
  • Home
  • About
    • Project Team
    • Logos and Graphics
  • Showcase
    • CBOX Classic Showcase
    • CBOX OpenLab Showcase
  • Demo
  • Get Started
  • Documentation
    • Technical Guide
    • CBOX Classic Guide
    • CBOX OpenLab Guide
  • Support Forums
    • CBOX Classic
    • CBOX OpenLab
    • Developers Forum
  • News

Group Admins

  • Profile picture of Scott Voth

CBOX Classic Support

Public Group active 4 months ago

This group provides support for Commons In A Box Classic, our original software for community-building. Register for an account or log in to commonsinabox.org, then join the group and post your question here.

How to filter the names of new groups during group creation?

Tagged: buddypress, groups

  • This topic has 2 replies, 2 voices, and was last updated 11 years, 9 months ago by Mike Stumpf.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • July 22, 2013 at 3:33 pm #3197
    Mike Stumpf
    Participant

    Hello,

    I am trying to make a simple function to filter out “bad” group names and names that are already taken, similar to the filtering done when creating a group blog, but I cannot make sense of the BuddyPress-specific pieces of the code.

    I have the files I probably need narrowed down to:

    …/wp-content/themes/cbox-theme/groups/create.php (for inserting the function call)
    &
    …/wp-content/themes/cbox-theme/groups/groups-loop.php (for using the methods for retrieving groups, like on the Group Directory page)

    I am stuck on finding where exactly in the code the group is being created and making sense of calls like: ” do_action( ‘bp_after_group_details_creation_step’ );” in create.php.

    Currently, when groups are created with the same name, the second group has a “-” and a string of number appended to it.  I cannot find where this is happening in the code either.

     

    Can anybody help me with this?

     

    Here is what I have of the function so far:

    // Validate new group name
    function group_name_check($groupNameToCheck)
    {
    while (bp_groups() ) : bp_the_group();
    if(bp_get_group_name() = $groupNameToCheck)
    {
    $error = "something here"
    }
    endif;
    return $error;
    endwhile;
    }

    • This topic was modified 11 years, 9 months ago by Mike Stumpf.
    July 23, 2013 at 9:45 pm #3207
    Ray
    Keymaster

    Hi Mike,

    I just took a look at this and it appears that BuddyPress doesn’t allow plugin devs to filter the group slug.

    It just checks for any existing group slug or forbidden slug and if that happens, a random number is appended to prevent duplicate slugs.

    A filter needs to be added to groups_check_slug() to do what you want to do.

    I can think of a workaround, but it would be very messy and involve hooking into a bunch of actions.  Probably best to wait for a filter.

    July 24, 2013 at 9:43 am #3212
    Mike Stumpf
    Participant

    Thank you, this was exactly what I needed.  My solution, if anyone is interested, is that I changed the groups_check_slug($slug) function in:

    …/wp-content/plugins/buddypress/bp-groups/bp-groups-functions.php

     

    function groups_check_slug( $slug ) {

    global $bp;

     

    if ( 'wp' == substr( $slug, 0, 2 ) )

    $slug = substr( $slug, 2, strlen( $slug ) - 2 );

     

    if ( in_array( $slug, (array) $bp->groups->forbidden_names )) {

    bp_core_add_message( __( 'Sorry, that group name is reserved.  Please try again.', 'buddypress' ), 'error' );

     

    bp_core_redirect( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/' );

     

    }

    if ( BP_Groups_Group::check_slug( $slug ) ) {

    do {

    bp_core_add_message( __( 'Sorry, that group name is already taken. Please try again.', 'buddypress' ), 'error' );

     

    bp_core_redirect( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/create/step/' . bp_get_groups_current_create_step() . '/' );

     

    }

    while ( BP_Groups_Group::check_slug( $slug ) );

    }

     

    return $slug;

    }

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Log In
Group logo of CBOX Classic Support
  • Home
  • Forum
  • Announcements
  • Docs
  • Members 287
  • Send Invites

Groups

Newest | Active | Popular | Alphabetical
  • Group logo of CBOX Classic Support
    CBOX Classic Support
    287 members
  • Group logo of CBOX Pioneers
    CBOX Pioneers
    71 members
  • Group logo of CBOX Developers
    CBOX Developers
    40 members
  • Group logo of CBOX OpenLab Support
    CBOX OpenLab Support
    22 members
  • Group logo of CBOX-OL Testing Partners
    CBOX-OL Testing Partners
    12 members

CBOX has its roots in the CUNY Academic Commons, which in turn was made possible through funding from The City University of New York itself.

CUNY Logo

CUNY Academic Commons Logo

City Tech logo

The Commons In A Box was made possible through the generous support of the Alfred P. Sloan Foundation.

Alfred P. Sloan Foundation Logo

NEH Logo

The CUNY Graduate Center has directly contributed to the CUNY Academic Commons, housing the project since its inception, and has contributed to CBOX through its GC Digital Initiatives.

CUNY Graduate Center Logo

CUNY Graduate Center Digital Initiatives Logo

Powered by Commons In A Box
css.php
Skip to toolbar
  • About WordPress
    • WordPress.org
    • Documentation
    • Learn WordPress
    • Support
    • Feedback
  • Log In
  • Register