Last active
August 29, 2015 14:24
-
-
Save ntwb/f70f8f089d44db31879b to your computer and use it in GitHub Desktop.
WPORG - Custom Forum Moderator Role see https://wordpress.slack.com/archives/meta-i18n/p1436133108000049 See also: https://gist.github.com/ocean90/e266ab5b675df4e4e463
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: WPORG - Custom Forum Moderator Role | |
Plugin URI: https://wordpress.slack.com/archives/meta-i18n/p1436133108000049 | |
Description: WPORG - Custom Forum Moderator Role | |
Version: 0.0.1 | |
Author: Stephen Edgar aka @netweb | |
Author URI: https://netweb.com.au | |
*/ | |
function wporg_add_new_roles( $bbp_roles ) { | |
/* Add a role called wporg_forum_moderator */ | |
$bbp_roles['wporg_forum_moderator'] = array( | |
'name' => 'WordPress Support Forum Moderator', | |
'capabilities' => wporg_custom_capabilities( 'wporg_forum_moderator' ) | |
); | |
return $bbp_roles; | |
} | |
add_filter( 'bbp_get_dynamic_roles', 'wporg_add_new_roles', 1 ); | |
function wporg_add_role_caps_filter( $caps, $role ) { | |
/* Only filter for roles we are interested in! */ | |
if( $role == 'wporg_forum_moderator' ) | |
$caps = wporg_custom_capabilities( $role ); | |
return $caps; | |
} | |
add_filter( 'bbp_get_caps_for_role', 'wporg_add_role_caps_filter', 10, 2 ); | |
function wporg_custom_capabilities( $role ) { | |
switch ( $role ) { | |
/* Capabilities for 'wporg_forum_moderator' role */ | |
case 'wporg_forum_moderator': | |
return array( | |
// Primary caps | |
'spectate' => true, | |
'participate' => true, | |
'moderate' => false, | |
'throttle' => false, | |
'view_trash' => false, | |
// Forum caps | |
'publish_forums' => true, | |
'edit_forums' => true, | |
'edit_others_forums' => true, | |
'delete_forums' => true, | |
'delete_others_forums' => true, | |
'read_private_forums' => true, | |
'read_hidden_forums' => false, | |
// Topic caps | |
'publish_topics' => true, | |
'edit_topics' => true, | |
'edit_others_topics' => false, | |
'delete_topics' => false, | |
'delete_others_topics' => false, | |
'read_private_topics' => true, | |
// Reply caps | |
'publish_replies' => true, | |
'edit_replies' => true, | |
'edit_others_replies' => false, | |
'delete_replies' => false, | |
'delete_others_replies' => false, | |
'read_private_replies' => true, | |
// Topic tag caps | |
'manage_topic_tags' => false, | |
'edit_topic_tags' => false, | |
'delete_topic_tags' => false, | |
'assign_topic_tags' => true, | |
); | |
break; | |
default : | |
return $role; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment