/* Plugin Name: Forums Moderators Plugin URI: http://www.adityanaik.com/projects/plugins/bb-forum-moderators/ Description: Give forum specific moderator priviledges Author: Aditya Naik Version: 1.0 Author URI: http://www.adityanaik.com/ Install Instructions: - If you don't have a /my-plugins/ directory in your bbpress installaltion, create it on the same level as config.php. - Menu can be access from Admin > User > Forum Moderators Version History: 1.0 : Initial Release Please note that the plugin will disable all priviledges for moderators and will need to be given specific priviledges to each forum from the admin menu. */ function forum_moderators_add_admin_page() { global $bb_submenu; $bb_submenu['users.php'][] = array(__('Forum Moderators'), 'use_keys', 'forum_moderators_admin_page'); } function forum_moderators_admin_page() { $bb_user_search = new BB_Forum_Moderators_Search($_REQUEST['usersearch'], $_REQUEST['userspage']); $bb_user_search->display(); } function forum_moderators_process_post() { if ($_POST['mod_user_id']) { foreach($_POST['mod_user_id'] as $mod) { $user_obj = new BB_User( $mod); $user_obj->set_role('moderator'); bb_update_usermeta( $mod, 'forum_moderator', $_POST['mod_forums'][$mod] ); //print_r($_POST['mod_forums'][$mod]); } } } add_action( 'bb_admin-header.php','forum_moderators_process_post'); add_action( 'bb_admin_menu_generator', 'forum_moderators_add_admin_page' ); add_filter('bb_user_has_cap','forum_moderators_process_capacities',10,2); function forum_moderators_process_capacities($allcaps, $caps){ global $bb_current_user, $forum,$topic_id; if (!$bb_current_user || in_array('keymaster',$bb_current_user->roles) || in_array('administrator',$bb_current_user->roles)) return $allcaps; if (empty($forum)) { $topic = get_topic($topic_id); $forum = get_forum($topic->forum_id); } $forum_moderator = ((!empty($bb_current_user->data->forum_moderator)) ? $bb_current_user->data->forum_moderator : array()); $filtering_caps = array( 'manage_topics' , 'edit_closed' , 'edit_deleted' , 'browse_deleted' , 'edit_others_tags' , 'edit_others_topics' , 'manage_posts' , 'ignore_edit_lock' , 'edit_others_posts' ); if (!empty($forum) && !array_key_exists($forum->forum_id,$forum_moderator ) && array_intersect($filtering_caps,$caps)) { foreach($filtering_caps as $filtering_cap) { unset($allcaps[$filtering_cap]); } } return $allcaps; } class BB_Forum_Moderators_Search { var $results; var $search_term; var $page; var $raw_page; var $users_per_page = 50; var $first_user; var $last_user; var $query_limit; var $query_from_where; var $total_users_for_query = 0; var $search_errors; function BB_Forum_Moderators_Search ($search_term = '', $page = '') { // constructor $this->search_term = $search_term; $this->raw_page = ( '' == $page ) ? false : (int) $page; $this->page = (int) ( '' == $page ) ? 1 : $page; $this->prepare_query(); $this->query(); $this->prepare_vars_for_template_usage(); $this->do_paging(); } function prepare_query() { global $bbdb; $this->first_user = ($this->page - 1) * $this->users_per_page; $this->query_limit = 'LIMIT ' . $this->first_user . ',' . $this->users_per_page; if ( $this->search_term ) { $searches = array(); $search_sql = 'AND ('; foreach ( array('user_login', 'user_nicename', 'user_email', 'user_url', 'display_name') as $col ) $searches[] = $col . " LIKE '%$this->search_term%'"; $search_sql .= implode(' OR ', $searches); $search_sql .= ')'; } $this->query_from_where = "FROM $bbdb->users WHERE 1=1 $search_sql"; } function query() { global $bbdb; $this->results = $bbdb->get_col('SELECT ID ' . $this->query_from_where . $this->query_limit); $keymasters = get_ids_by_role( 'keymaster'); $administrators = get_ids_by_role( 'administrator'); $this->results = array_diff($this->results, $keymasters , $administrators ); if ( $this->results ) $this->total_users_for_query = $bbdb->get_var('SELECT COUNT(ID) ' . $this->query_from_where); // no limit else $this->search_errors = new WP_Error('no_matching_users_found', __('No matching users were found!')); } function prepare_vars_for_template_usage() { $this->search_term = stripslashes($this->search_term); // done with DB, from now on we want slashes gone } function do_paging() { global $bb_current_submenu; if ( $this->total_users_for_query > $this->users_per_page ) { // have to page the results $pagenow = bb_get_admin_tab_link($bb_current_submenu); $this->paging_text = paginate_links( array( 'total' => ceil($this->total_users_for_query / $this->users_per_page), 'current' => $this->page, 'prev_text' => '« Previous Page', 'next_text' => 'Next Page »', 'base' => $pagenow . ( false === strpos($pagenow, '?') ? '?%_%' : '&%_%' ), 'format' => 'userspage=%#%', 'add_args' => array( 'usersearch' => urlencode($this->search_term) ) ) ); } } function get_results() { return (array) $this->results; } function page_links() { echo $this->paging_text; } function results_are_paged() { if ( $this->paging_text ) return true; return false; } function is_search() { if ( $this->search_term ) return true; return false; } function display( $show_search = true, $show_email = false ) { global $bb_roles; $r = ''; // Make the user objects foreach ( $this->get_results() as $user_id ) { $tmp_user = new BB_User($user_id); $roles = $tmp_user->roles; $role = array_shift($roles); $roleclasses[$role][$tmp_user->data->user_login] = $tmp_user; } if ( isset($this->title) ) $title = $this->title; elseif ( $this->is_search() ) $title = sprintf(__('Users Matching "%s" by Role'), wp_specialchars( $this->search_term )); else $title = __('User List by Role'); $r .= "
|
|
FOCUS Forums is an exciting new way to stay connected. FOCUS Forums is a place where FOCUS Associates and staff can stay informed of news, events, prayer requests and more. Registered users can post topics for discussion, network with other associates and keep connected within this online community. Sign up now!
|
|
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
Last post by Hiicollictt22 |
1 post(s) 5 months ago |
|
|
|
FOCUS East
FOCUS East Forum |
1 discussion(s) |
|
Prayer FOCUS East Prayer |
0 discussion(s) |
|
News FOCUS East News |
0 discussion(s) |
|
Events FOCUS East Events |
0 discussion(s) |
|
FOCUS North
FOCUS North Forum |
1 discussion(s) |
|
Prayer FOCUS North Prayer |
0 discussion(s) |
|
News FOCUS North News |
0 discussion(s) |
|
Events FOCUS North Events |
1 discussion(s) |
|
FOCUS West
FOCUS West Forum |
1 discussion(s) |
|
Prayer FOCUS West Prayer |
0 discussion(s) |
|
News FOCUS West News |
0 discussion(s) |
|
Events FOCUS West Events |
0 discussion(s) |
|
FOCUS Northwest
FOCUS Northwest Forum |
1 discussion(s) |
|
Prayer FOCUS Northwest Prayer |
0 discussion(s) |
|
News FOCUS Northwest News |
0 discussion(s) |
|
Events FOCUS Northwest Events |
0 discussion(s) |
|
FOCUS Central
FOCUS Central Forum |
1 discussion(s) |
|
Prayer FOCUS Central Prayer |
0 discussion(s) |
|
News FOCUS Central News |
0 discussion(s) |
|
Events FOCUS Central Events |
700 discussion(s) |
|
Stats
|
| Hot Tags |