{"id":27255,"date":"2009-12-23T11:00:58","date_gmt":"2009-12-23T16:00:58","guid":{"rendered":"http:\/\/wpmu.org\/?p=27255"},"modified":"2018-08-21T16:36:29","modified_gmt":"2018-08-21T16:36:29","slug":"how-to-restrict-buddypress-group-creation-based-on-user-roles-and-capabilities","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/how-to-restrict-buddypress-group-creation-based-on-user-roles-and-capabilities\/","title":{"rendered":"How To Restrict BuddyPress Group Creation Based on User Roles and Capabilities"},"content":{"rendered":"<p>Is your BuddyPress group creation getting out of hand? Would you rather your users submit group requests to you for moderation and create them yourself?<\/p>\n<p>After doing a little bit of hunting on the BuddyPress forums, I stumbled across this custom plugin created by <a href=\"http:\/\/buddypress.org\/developers\/simonwheatley\/\" rel=\"noopener\" target=\"_blank\">Simon Wheatley<\/a>.<\/p>\n<p>Here&#8217;s how you can use it to restrict BuddyPress group creation to <strong>admin only<\/strong>:<\/p>\n<h3 style=\"padding-bottom: 15px;\">Step 1: Download the <a href=\"http:\/\/trac.buddypress.org\/attachment\/ticket\/1150\/restrict-group-creation.php\" rel=\"noopener\" target=\"_blank\">Restrict Group Creation<\/a> plugin.<\/h3>\n<h3 style=\"padding-bottom: 15px;\">Step 2: FTP that file to your Plugins directory and activate. This will change it so that no users can create groups.<\/h3>\n<h3 style=\"padding-bottom: 15px;\">Step. 3: Add this code to each function to permit the admin to create groups:<\/h3>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">if ( current_user_can( &#039;manage_options&#039; ) )\r\nreturn true;<\/pre>\n<p>So what&#8217; you&#8217;ll have then for the first function will look something like this:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">function rgc_validate_creation( $allowed, $group_details ) {\r\n\/\/ At this point one could check the capabilities of the user, the details of the\r\n\/\/ group to be created, etc.\r\nif ( current_user_can( &#039;manage_options&#039; ) )\r\nreturn true;\r\nbp_core_add_message( &#039;Sorry, you are not allowed to create groups.&#039;, &#039;error&#039; );\r\nreturn false;\r\n}\r\nadd_filter( &#039;bp_allow_create_group&#039;, &#039;rgc_validate_creation&#039;, null, 2 );<\/pre>\n<p>You&#8217;ll want to modify the other functions in that plugin to match &#8211; or you can <a href=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2009\/12\/restrict-group-creation.zip\" target=\"_blank\">download my modified version here<\/a>. :)<\/p>\n<p>You can also modify it so that other roles can create groups as well, based on their <a href=\"http:\/\/codex.wordpress.org\/Roles_and_Capabilities\" rel=\"noopener\" target=\"_blank\">roles and capabilities<\/a>. For example, if I wanted to make it so that only Admins and Editors are allowed to create groups, I might use:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">if ( current_user_can( &#039;delete_others_posts&#039; ) )\r\nreturn true;<\/pre>\n<p>This offers you a great deal of flexibility in customizing group creation by checking the user&#8217;s capabilities. I hope this is helpful to those wanting to further customize their BuddyPress communities.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Is your BuddyPress group creation getting out of hand? Would you rather your users submit group requests to you for moderation and create them yourself? After doing a little bit of hunting on the BuddyPress forums, I stumbled across this custom plugin created by Simon Wheatley. Here&#8217;s how you can use it to restrict BuddyPress [&hellip;]<\/p>\n","protected":false},"author":4099,"featured_media":169606,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[263],"tags":[9892],"tutorials_categories":[],"class_list":["post-27255","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-buddypress-2"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/27255","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/4099"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=27255"}],"version-history":[{"count":3,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/27255\/revisions"}],"predecessor-version":[{"id":173904,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/27255\/revisions\/173904"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/169606"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=27255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=27255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=27255"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=27255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}