Ticket #459: 459.2.diff
File 459.2.diff, 8.1 KB (added by , 12 years ago) |
---|
-
bbpress.php
5 5 * 6 6 * bbPress is forum software with a twist from the creators of WordPress. 7 7 * 8 * $Id $8 * $Id: bbpress.php 4479 2012-11-23 14:58:53Z bumpbot $ 9 9 * 10 10 * @package bbPress 11 11 * @subpackage Main … … 208 208 $this->forum_post_type = apply_filters( 'bbp_forum_post_type', 'forum' ); 209 209 $this->topic_post_type = apply_filters( 'bbp_topic_post_type', 'topic' ); 210 210 $this->reply_post_type = apply_filters( 'bbp_reply_post_type', 'reply' ); 211 $this->forum_mod_tax_id = apply_filters( 'bbp_forum_mod_tax_id', 'forum-mod' ); 211 212 $this->topic_tag_tax_id = apply_filters( 'bbp_topic_tag_tax_id', 'topic-tag' ); 212 213 213 214 // Status identifiers … … 725 726 } 726 727 727 728 /** 728 * Register the topic tag taxonomy729 * Register the topic tag and forum moderator taxonomies 729 730 * 730 731 * @since bbPress (r2464) 731 732 * @uses register_taxonomy() To register the taxonomy … … 771 772 'show_ui' => bbp_allow_topic_tags() && current_user_can( 'bbp_topic_tags_admin' ) 772 773 ) 773 774 ) ); 775 776 // Define local variable(s) 777 $forum_mod = array(); 778 779 // Forum moderator labels 780 $forum_mod['labels'] = array( 781 'name' => __( 'Forum Moderators', 'bbpress' ), 782 'singular_name' => __( 'Forum Moderator', 'bbpress' ), 783 'search_items' => __( 'Search Moderators', 'bbpress' ), 784 'popular_items' => __( 'Popular Moderators', 'bbpress' ), 785 'all_items' => __( 'All Moderators', 'bbpress' ), 786 'edit_item' => __( 'Edit Moderator', 'bbpress' ), 787 'update_item' => __( 'Update Moderator', 'bbpress' ), 788 'add_new_item' => __( 'Add New Moderator', 'bbpress' ), 789 'new_item_name' => __( 'New Moderator Name', 'bbpress' ), 790 'view_item' => __( 'View Forum Moderator', 'bbpress' ), 791 'separate_items_with_commas' => __( 'Separate moderator names with commas', 'bbpress' ) 792 ); 793 794 // Register the forum moderator taxonomy 795 register_taxonomy( 796 bbp_get_forum_mod_tax_id(), 797 bbp_get_forum_post_type(), 798 apply_filters( 'bbp_register_forum_mod_taxonomy', array( 799 'labels' => $forum_mod['labels'], 800 'capabilities' => bbp_get_forum_moderator_caps(), 801 'update_count_callback' => '_update_post_term_count', 802 'query_var' => true, 803 'show_tagcloud' => true, 804 'hierarchical' => false, 805 'public' => false, 806 'show_ui' => current_user_can( 'bbp_forum_moderators_admin' ) 807 ) 808 ) ); 774 809 } 775 810 776 811 /** -
includes/admin/forums.php
58 58 private function setup_actions() { 59 59 60 60 // Add some general styling to the admin area 61 add_action( 'bbp_admin_head', array( $this, 'admin_head') );61 add_action( 'bbp_admin_head', array( $this, 'admin_head' ) ); 62 62 63 63 // Messages 64 add_filter( 'post_updated_messages', array( $this, 'updated_messages') );64 add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) ); 65 65 66 66 // Metabox actions 67 add_action( 'add_meta_boxes', array( $this, 'attributes_metabox') );68 add_action( 'save_post', array( $this, 'attributes_metabox_save') );67 add_action( 'add_meta_boxes', array( $this, 'attributes_metabox' ) ); 68 add_action( 'save_post', array( $this, 'attributes_metabox_save' ) ); 69 69 70 // Forum moderators AJAX; run at -1 to preempt built-in tag search 71 add_action( 'wp_ajax_ajax-tag-search', array( $this, 'ajax_tag_search' ), -1 ); 72 70 73 // Column headers. 71 74 add_filter( 'manage_' . $this->post_type . '_posts_columns', array( $this, 'column_headers' ) ); 72 75 … … 262 265 } 263 266 264 267 /** 268 * Return user nicename suggestions instead of tag suggestions 269 * 270 * @return Return early if not a request for forum moderators tax 271 */ 272 public function ajax_tag_search() { 273 274 // Only do AJAX if this is a forum moderators tax search 275 if ( ! isset( $_GET['tax'] ) || ( bbp_get_forum_mod_tax_id() != $_GET['tax'] ) ) 276 return; 277 278 $taxonomy = sanitize_key( $_GET['tax'] ); 279 $tax = get_taxonomy( $taxonomy ); 280 if ( empty( $tax ) ) 281 wp_die( 0 ); 282 283 // Check permissions 284 if ( ! current_user_can( $tax->cap->assign_terms ) ) 285 wp_die( -1 ); 286 287 $s = stripslashes( $_GET['q'] ); 288 289 // Replace tag delimiter with a comma if needed 290 $comma = _x( ',', 'tag delimiter', 'bbpress' ); 291 if ( ',' !== $comma ) { 292 $s = str_replace( $comma, ',', $s ); 293 } 294 295 if ( false !== strpos( $s, ',' ) ) { 296 $s = explode( ',', $s ); 297 $s = $s[count( $s ) - 1]; 298 } 299 300 // Search on at least 2 characters 301 $s = trim( $s ); 302 if ( strlen( $s ) < 2 ) 303 wp_die(); // require 2 chars for matching 304 305 // Get users 306 $results = array(); 307 $users = get_users( array( 308 'blog_id' => 0, // All users 309 'fields' => array( 'user_nicename' ), 310 'search' => '*' . $s . '*', 311 'search_columns' => array( 'user_nicename' ), 312 'orderby' => 'user_nicename' 313 ) ); 314 315 // Format the users into a nice array 316 if ( ! empty( $users ) ) { 317 foreach( array_values( $users ) as $details ) { 318 $results[] = $details->user_nicename; 319 } 320 } 321 322 // Echo results for AJAX 323 echo join( $results, "\n" ); 324 wp_die(); 325 } 326 327 /** 265 328 * Pass the forum attributes for processing 266 329 * 267 330 * @since bbPress (r2746) -
includes/forums/capabilities.php
176 176 /** Admin *************************************************************/ 177 177 178 178 case 'bbp_forums_admin' : 179 case 'bbp_forum_moderators_admin' : 179 180 $caps = array( 'manage_options' ); 180 181 break; 181 182 } 182 183 183 184 return apply_filters( 'bbp_map_forum_meta_caps', $caps, $cap, $user_id, $args ); 184 185 } 186 187 /** 188 * Return forum moderator capabilities 189 * 190 * @uses apply_filters() Calls 'bbp_get_forum_mod_caps' with the capabilities 191 * @return array Forum mod capabilities 192 */ 193 function bbp_get_forum_moderator_caps() { 194 return apply_filters( 'bbp_get_forum_moderator_caps', array( 195 'manage_terms' => 'keep_gate', 196 'edit_terms' => 'keep_gate', 197 'delete_terms' => 'keep_gate', 198 'assign_terms' => 'keep_gate' 199 ) ); 200 } 201 202 /** 203 * Maps forum moderator capabilities 204 * 205 * @param array $caps Capabilities for meta capability 206 * @param string $cap Capability name 207 * @param int $user_id User id 208 * @param mixed $args Arguments 209 * @uses apply_filters() Filter capabilities map results 210 * @return array Actual capabilities for meta capability 211 */ 212 function bbp_map_forum_moderator_meta_caps( $caps, $cap, $user_id, $args ) { 213 214 // What capability is being checked? 215 switch( $cap ) { 216 case 'manage_forum_mods' : 217 case 'edit_forum_mods' : 218 case 'delete_forum_mods' : 219 case 'assign_forum_mods' : 220 case 'bbp_forum_mods_admin' : 221 222 // Key Masters can always edit 223 if ( user_can( $user_id, 'keep_gate' ) ) { 224 $caps = array( 'keep_gate' ); 225 } 226 } 227 228 return apply_filters( 'bbp_map_forum_mod_meta_caps', $caps, $cap, $user_id, $args ); 229 } -
includes/forums/template-tags.php
1919 1919 return apply_filters( 'bbp_get_single_forum_description', $retstr, $args ); 1920 1920 } 1921 1921 1922 /** Moderators ****************************************************************/ 1923 1924 /** 1925 * Output the unique id of the forum moderators taxonomy 1926 * 1927 * @uses bbp_get_forum_post_type() To get the forum post type 1928 */ 1929 function bbp_forum_mod_tax_id() { 1930 echo bbp_get_forum_mod_tax_id(); 1931 } 1932 /** 1933 * Return the unique id of the forum moderators taxonomy 1934 * 1935 * @uses apply_filters() Calls 'bbp_get_forum_mod_tax_id' with the forum moderator tax id 1936 * @return string The unique forum moderators taxonomy 1937 */ 1938 function bbp_get_forum_mod_tax_id() { 1939 return apply_filters( 'bbp_get_forum_mod_tax_id', bbpress()->forum_mod_tax_id ); 1940 } 1941 1922 1942 /** Forms *********************************************************************/ 1923 1943 1924 1944 /**