Ticket #459: 459.1.diff
File 459.1.diff, 8.0 KB (added by , 12 years ago) |
---|
-
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 global $wpdb; 274 275 // Only do AJAX if this is a forum moderators tax search 276 if ( isset( $_GET['tax'] ) && $_GET['tax'] == bbp_get_forum_mod_tax_id() ) { 277 $taxonomy = sanitize_key( $_GET['tax'] ); 278 $tax = get_taxonomy( $taxonomy ); 279 if ( ! $tax ) 280 wp_die( 0 ); 281 282 // Check permissions 283 if ( ! current_user_can( $tax->cap->assign_terms ) ) 284 wp_die( -1 ); 285 286 $s = stripslashes( $_GET['q'] ); 287 288 // Replace tag delimiter with a comma if needed 289 $comma = _x( ',', 'tag delimiter', 'bbpress' ); 290 if ( ',' !== $comma ) 291 $s = str_replace( $comma, ',', $s ); 292 if ( false !== strpos( $s, ',' ) ) { 293 $s = explode( ',', $s ); 294 $s = $s[count( $s ) - 1]; 295 } 296 297 // Search on at least 2 characters 298 $s = trim( $s ); 299 if ( strlen( $s ) < 2 ) 300 wp_die(); // require 2 chars for matching 301 302 $results = $wpdb->get_col( $wpdb->prepare( "SELECT user_nicename FROM $wpdb->users WHERE user_nicename LIKE (%s)", '%' . like_escape( $s ) . '%' ) ); 303 304 // Echo results for AJAX 305 echo join( $results, "\n" ); 306 wp_die(); 307 } 308 309 return; 310 } 311 312 /** 265 313 * Pass the forum attributes for processing 266 314 * 267 315 * @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
1920 1920 return apply_filters( 'bbp_get_single_forum_description', $retstr, $args ); 1921 1921 } 1922 1922 1923 /** Moderators ****************************************************************/ 1924 1925 /** 1926 * Output the unique id of the forum moderators taxonomy 1927 * 1928 * @uses bbp_get_forum_post_type() To get the forum post type 1929 */ 1930 function bbp_forum_mod_tax_id() { 1931 echo bbp_get_forum_mod_tax_id(); 1932 } 1933 /** 1934 * Return the unique id of the forum moderators taxonomy 1935 * 1936 * @uses apply_filters() Calls 'bbp_get_forum_mod_tax_id' with the forum moderator tax id 1937 * @return string The unique forum moderators taxonomy 1938 */ 1939 function bbp_get_forum_mod_tax_id() { 1940 return apply_filters( 'bbp_get_forum_mod_tax_id', bbpress()->forum_mod_tax_id ); 1941 } 1942 1923 1943 /** Forms *********************************************************************/ 1924 1944 1925 1945 /** -
bbpress.php
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 /**