Changeset 6056
- Timestamp:
- 06/05/2016 06:27:54 PM (9 years ago)
- Location:
- trunk/src
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bbpress.php
r5951 r6056 227 227 // Post type identifiers 228 228 $this->forum_post_type = apply_filters( 'bbp_forum_post_type', 'forum' ); 229 $this->forum_mod_tax_id = apply_filters( 'bbp_forum_mod_tax_id', 'forum-mod' );230 229 $this->topic_post_type = apply_filters( 'bbp_topic_post_type', 'topic' ); 231 230 $this->topic_tag_tax_id = apply_filters( 'bbp_topic_tag_tax_id', 'topic-tag' ); … … 663 662 * 664 663 * @since 2.0.0 bbPress (r2464) Added bbp_get_topic_tag_tax_id() taxonomy 665 * @since 2.6.0 bbPress (r5834) Added bbp_get_forum_mod_tax_id() taxonomy666 664 * 667 665 * @uses register_taxonomy() To register the taxonomy … … 673 671 * @uses current_user_can() To check if the current user can edit/delete tags 674 672 * @uses bbp_get_forum_post_type() To get the forum post type 675 * @uses bbp_get_forum_mod_tax_labels() To get the forum moderator taxonomy label676 * @uses bbp_get_forum_mod_caps() To check the forum moderator capabilities677 * @uses bbp_allow_forum_mods() To check if forum moderators are allowed678 673 * @uses current_user_can() To check if the current user can edit/delete forums 679 674 */ … … 697 692 ) 698 693 ) ); 699 700 // Register the forum-mod taxonomy.701 register_taxonomy(702 bbp_get_forum_mod_tax_id(),703 bbp_get_forum_post_type(),704 apply_filters( 'bbp_register_forum_moderator_taxonomy', array(705 'labels' => bbp_get_forum_mod_tax_labels(),706 'capabilities' => bbp_get_forum_mod_caps(),707 'update_count_callback' => '_update_post_term_count',708 'query_var' => false,709 'show_tagcloud' => true,710 'hierarchical' => false,711 'show_in_menu' => true,712 'show_in_nav_menus' => false,713 'public' => false,714 'show_ui' => bbp_allow_forum_mods() && current_user_can( 'bbp_forum_mods_admin' ),715 )716 ) );717 694 } 718 695 -
trunk/src/includes/admin/forums.php
r6047 r6056 73 73 74 74 // Metabox actions 75 add_action( 'add_meta_boxes', array( $this, 'attributes_metabox' ) ); 76 add_action( 'save_post', array( $this, 'attributes_metabox_save' ) ); 75 add_action( 'add_meta_boxes', array( $this, 'attributes_metabox' ) ); 76 add_action( 'add_meta_boxes', array( $this, 'moderators_metabox' ) ); 77 add_action( 'save_post', array( $this, 'save_meta_boxes' ) ); 77 78 78 79 // Check if there are any bbp_toggle_forum_* requests on admin_init, also have a message displayed 79 80 add_action( 'load-edit.php', array( $this, 'toggle_forum' ) ); 80 81 add_action( 'admin_notices', array( $this, 'toggle_forum_notice' ) ); 81 82 // Forum moderators AJAX; run at -1 to preempt built-in tag search83 add_action( 'wp_ajax_ajax-tag-search', array( $this, 'ajax_tag_search' ), -1 );84 82 85 83 // Contextual Help … … 258 256 } 259 257 260 add_meta_box ( 258 // Meta data 259 add_meta_box( 261 260 'bbp_forum_attributes', 262 261 __( 'Forum Attributes', 'bbpress' ), … … 271 270 272 271 /** 273 * Return user nicename suggestions instead of tag suggestions 274 * 275 * @since 2.6.0 bbPress (r5834) 276 * 277 * @uses bbp_get_forum_mod_tax_id() To get the forum moderator taxonomy id 278 * @uses sanitize_key() To sanitize the taxonomy id 279 * @uses get_taxonomy() To get the forum moderator taxonomy 280 * @uses current_user_can() To check if the current user add/edit forum moderators 281 * @uses get_users() To get an array of users 282 * @uses user_nicename() To get the users nice name 283 * 284 * @return Return early if not a request for forum moderators tax 285 */ 286 public function ajax_tag_search() { 287 288 // Only do AJAX if this is a forum moderators tax search. 289 if ( ! isset( $_GET['tax'] ) || ( bbp_get_forum_mod_tax_id() !== $_GET['tax'] ) ) { 272 * Add the forum moderators metabox 273 * 274 * @since 2.6.0 bbPress 275 * 276 * @uses bbp_get_forum_post_type() To get the forum post type 277 * @uses add_meta_box() To add the metabox 278 * @uses do_action() Calls 'bbp_forum_attributes_metabox' 279 */ 280 public function moderators_metabox() { 281 282 if ( $this->bail() ) { 290 283 return; 291 284 } 292 285 293 $taxonomy = sanitize_key( $_GET['tax'] ); 294 $tax = get_taxonomy( $taxonomy ); 295 if ( empty( $tax ) ) { 296 wp_die( 0 ); 297 } 298 299 // Check permissions. 300 if ( ! current_user_can( $tax->cap->assign_terms ) ) { 301 wp_die( -1 ); 302 } 303 304 $s = stripslashes( $_GET['q'] ); 305 306 // Replace tag delimiter with a comma if needed. 307 $comma = _x( ',', 'tag delimiter', 'bbpress' ); 308 if ( ',' !== $comma ) { 309 $s = str_replace( $comma, ',', $s ); 310 } 311 312 if ( false !== strpos( $s, ',' ) ) { 313 $s = explode( ',', $s ); 314 $s = $s[ count( $s ) - 1 ]; 315 } 316 317 // Search on at least 2 characters. 318 $s = trim( $s ); 319 if ( strlen( $s ) < 2 ) { 320 wp_die(); // Require 2 chars for matching. 321 } 322 323 // Get users. 324 $results = array(); 325 $users = get_users( array( 326 'blog_id' => 0, // All users. 327 'fields' => array( 'user_nicename' ), 328 'search' => '*' . $s . '*', 329 'search_columns' => array( 'user_nicename' ), 330 'orderby' => 'user_nicename', 331 ) ); 332 333 // Format the users into a nice array. 334 if ( ! empty( $users ) ) { 335 foreach ( array_values( $users ) as $details ) { 336 $results[] = $details->user_nicename; 337 } 338 } 339 340 // Echo results for AJAX. 341 echo join( $results, "\n" ); 342 wp_die(); 286 // Bail if feature not active or user cannot assign moderators 287 if ( ! bbp_allow_forum_mods() || ! current_user_can( 'assign_moderators' ) ) { 288 return; 289 } 290 291 // Moderators 292 add_meta_box( 293 'bbp_moderator_assignment_metabox', 294 __( 'Forum Moderators', 'bbpress' ), 295 'bbp_moderator_assignment_metabox', 296 $this->post_type, 297 'side', 298 'high' 299 ); 300 301 do_action( 'bbp_forum_moderators_metabox' ); 343 302 } 344 303 … … 365 324 * @return int Forum id 366 325 */ 367 public function attributes_metabox_save( $forum_id ) {326 public function save_meta_boxes( $forum_id ) { 368 327 369 328 if ( $this->bail() ) { … … 392 351 393 352 // Bail if current user cannot edit this forum 394 if ( ! current_user_can( 'edit_forum', $forum_id ) ) {353 if ( ! current_user_can( 'edit_forum', $forum_id ) ) { 395 354 return $forum_id; 396 355 } 397 356 398 357 // Parent ID 399 $parent_id = ( ! empty( $_POST['parent_id'] ) && is_numeric( $_POST['parent_id'] ) ) ? (int) $_POST['parent_id'] : 0; 358 $parent_id = ( ! empty( $_POST['parent_id'] ) && is_numeric( $_POST['parent_id'] ) ) 359 ? (int) $_POST['parent_id'] 360 : 0; 400 361 401 362 // Update the forum meta bidness 402 363 bbp_update_forum( array( 403 364 'forum_id' => $forum_id, 404 'post_parent' => (int)$parent_id365 'post_parent' => $parent_id 405 366 ) ); 406 367 … … 438 399 display: inline-block; 439 400 width: 60px; 401 } 402 403 #bbp_moderators { 404 width: 100%; 440 405 } 441 406 … … 519 484 520 485 // Only proceed if GET is a forum toggle action 521 if ( bbp_is_get_request() && ! empty( $_GET[' action'] ) && in_array( $_GET['action'], array( 'bbp_toggle_forum_close' ) ) && ! empty( $_GET['forum_id']) ) {486 if ( bbp_is_get_request() && ! empty( $_GET['forum_id'] ) && ! empty( $_GET['action'] ) && in_array( $_GET['action'], array( 'bbp_toggle_forum_close' ) ) ) { 522 487 $action = $_GET['action']; // What action is taking place? 523 488 $forum_id = (int) $_GET['forum_id']; // What's the forum id? … … 532 497 533 498 // What is the user doing here? 534 if ( ! current_user_can( 'keep_gate', $forum->ID ) ) {499 if ( ! current_user_can( 'keep_gate', $forum->ID ) ) { 535 500 wp_die( __( 'You do not have the permission to do that!', 'bbpress' ) ); 536 501 } … … 654 619 'bbp_forum_topic_count' => __( 'Topics', 'bbpress' ), 655 620 'bbp_forum_reply_count' => __( 'Replies', 'bbpress' ), 621 'bbp_forum_mods' => __( 'Moderators', 'bbpress' ), 656 622 'author' => __( 'Creator', 'bbpress' ), 657 'bbp_forum_mods' => __( 'Moderators', 'bbpress' ),658 623 'bbp_forum_created' => __( 'Created' , 'bbpress' ), 659 624 'bbp_forum_freshness' => __( 'Last Post', 'bbpress' ) … … 701 666 702 667 case 'bbp_forum_mods' : 703 bbp_ forum_mod_list( $forum_id, array(668 bbp_moderator_list( $forum_id, array( 704 669 'before' => '', 705 670 'after' => '', -
trunk/src/includes/admin/metaboxes.php
r6032 r6056 646 646 do_action( 'bbp_author_metabox', $post_id ); 647 647 } 648 649 /** 650 * Moderator assignment metabox 651 * 652 * @since 2.6.0 bbPress (r2828) 653 * 654 * @uses get_the_ID() To get the global post ID 655 * @uses get_post_meta() To get the author user information 656 */ 657 function bbp_moderator_assignment_metabox() { 658 659 // Post ID 660 $object_id = get_the_ID(); 661 $user_ids = bbp_get_moderator_ids( $object_id ); 662 $user_nicenames = bbp_get_user_nicenames_from_ids( $user_ids ); 663 $moderators = ! empty( $user_nicenames ) 664 ? implode( ', ', array_map( 'esc_attr', $user_nicenames ) ) 665 : ''; ?> 666 667 <p> 668 <label class="screen-reader-text" for="bbp_moderators"><?php esc_html_e( 'Moderators', 'bbpress' ); ?></label> 669 <input type="text" id="bbp_moderators" name="bbp_moderators" value="<?php echo esc_attr( $moderators ); ?>" /> 670 </p> 671 672 <?php 673 674 do_action( 'bbp_moderator_assignment_metabox', $object_id ); 675 } -
trunk/src/includes/admin/replies.php
r6045 r6056 73 73 74 74 // Reply metabox actions 75 add_action( 'add_meta_boxes', array( $this, 'attributes_metabox' ) ); 76 add_action( 'save_post', array( $this, 'attributes_metabox_save' ) ); 75 add_action( 'add_meta_boxes', array( $this, 'attributes_metabox' ) ); 76 add_action( 'add_meta_boxes', array( $this, 'author_metabox' ) ); 77 add_action( 'save_post', array( $this, 'save_meta_boxes' ) ); 77 78 78 79 // Check if there are any bbp_toggle_reply_* requests on admin_init, also have a message displayed 79 80 add_action( 'load-edit.php', array( $this, 'toggle_reply' ) ); 80 81 add_action( 'admin_notices', array( $this, 'toggle_reply_notice' ) ); 81 82 // Anonymous metabox actions83 add_action( 'add_meta_boxes', array( $this, 'author_metabox' ) );84 82 85 83 // Add ability to filter topics and replies per forum … … 264 262 } 265 263 266 add_meta_box 264 add_meta_box( 267 265 'bbp_reply_attributes', 268 266 __( 'Reply Attributes', 'bbpress' ), … … 288 286 * @return int Parent id 289 287 */ 290 public function attributes_metabox_save( $reply_id ) {288 public function save_meta_boxes( $reply_id ) { 291 289 292 290 if ( $this->bail() ) { -
trunk/src/includes/admin/topics.php
r6047 r6056 73 73 74 74 // Topic metabox actions 75 add_action( 'add_meta_boxes', array( $this, 'attributes_metabox' ) ); 76 add_action( 'save_post', array( $this, 'attributes_metabox_save' ) ); 75 add_action( 'add_meta_boxes', array( $this, 'attributes_metabox' ) ); 76 add_action( 'add_meta_boxes', array( $this, 'author_metabox' ) ); 77 add_action( 'add_meta_boxes', array( $this, 'replies_metabox' ) ); 78 add_action( 'save_post', array( $this, 'save_meta_boxes' ) ); 77 79 78 80 // Check if there are any bbp_toggle_topic_* requests on admin_init, also have a message displayed 79 81 add_action( 'load-edit.php', array( $this, 'toggle_topic' ) ); 80 82 add_action( 'admin_notices', array( $this, 'toggle_topic_notice' ) ); 81 82 // Metabox actions83 add_action( 'add_meta_boxes', array( $this, 'author_metabox' ) );84 add_action( 'add_meta_boxes', array( $this, 'replies_metabox' ) );85 83 86 84 // Add ability to filter topics and replies per forum … … 266 264 } 267 265 268 add_meta_box 266 add_meta_box( 269 267 'bbp_topic_attributes', 270 268 __( 'Topic Attributes', 'bbpress' ), … … 290 288 * @return int Parent id 291 289 */ 292 public function attributes_metabox_save( $topic_id ) {290 public function save_meta_boxes( $topic_id ) { 293 291 294 292 if ( $this->bail() ) { … … 326 324 // Formally update the topic 327 325 bbp_update_topic( $topic_id, $forum_id, $anonymous_data, $author_id, $is_edit ); 328 329 // Stickies330 if ( ! empty( $_POST['bbp_stick_topic'] ) && in_array( $_POST['bbp_stick_topic'], array( 'stick', 'super', 'unstick' ) ) ) {331 332 // What's the haps?333 switch ( $_POST['bbp_stick_topic'] ) {334 335 // Sticky in this forum336 case 'stick' :337 bbp_stick_topic( $topic_id );338 break;339 340 // Super sticky in all forums341 case 'super' :342 bbp_stick_topic( $topic_id, true );343 break;344 345 // Normal346 case 'unstick' :347 default :348 bbp_unstick_topic( $topic_id );349 break;350 }351 }352 326 353 327 // Allow other fun things to happen -
trunk/src/includes/admin/users.php
r6052 r6056 57 57 add_filter( 'manage_users_custom_column', array( $this, 'user_role_row' ), 10, 3 ); 58 58 59 // Only list bbPress roles under Forum Role, remove from WordPress' > 4.4 Site Role list.60 if ( bbp_get_major_wp_version() >= 4.4 ) {61 add_filter( 'get_role_list', array( $this, 'user_role_list_filter' ), 10, 2 );62 }63 64 59 // Process bulk role change 65 60 add_action( 'load-users.php', array( $this, 'user_role_bulk_change' ) ); … … 134 129 public static function user_role_bulk_dropdown() { 135 130 136 // Bail if current user cannot promote users 131 // Bail if current user cannot promote users 137 132 if ( ! current_user_can( 'promote_users' ) ) { 138 133 return; … … 189 184 check_admin_referer( 'bbp-bulk-users', 'bbp-bulk-users-nonce' ); 190 185 191 // Bail if current user cannot promote users 186 // Bail if current user cannot promote users 192 187 if ( ! current_user_can( 'promote_users' ) ) { 193 188 return; … … 207 202 208 203 // Set up user and role data 209 $user_role = bbp_get_user_role( $user_id ); 204 $user_role = bbp_get_user_role( $user_id ); 210 205 $new_role = sanitize_text_field( $_REQUEST['bbp-new-role'] ); 211 206 … … 268 263 return $retval; 269 264 } 270 271 /**272 * Filter the list of roles included in the WordPress site role list273 *274 * This ensures bbPress' roles are only displayed under the Forum Role list275 * in the WordPRess USers list table276 *277 * @since 2.6.0 bbPress (r6051)278 *279 * @return array $roles280 */281 public static function user_role_list_filter( $roles, $user ) {282 283 // Get the users role284 $user_role = bbp_get_user_role( $user->ID );285 286 if ( ! empty( $user_role ) ) {287 unset( $roles[ $user_role ] );288 }289 return $roles;290 }291 265 } 292 266 new BBP_Users_Admin(); -
trunk/src/includes/common/functions.php
r6055 r6056 847 847 * @param string $moderation List of moderation keys. One per new line. 848 848 */ 849 $moderation = apply_filters( 850 'bbp_moderation_keys', 851 trim( get_option( 'moderation_keys' ) 852 ) ); 849 $moderation = apply_filters( 'bbp_moderation_keys', trim( get_option( 'moderation_keys' ) ) ); 853 850 854 851 // Bail if blacklist is empty … … 1690 1687 * @since 2.0.0 bbPress (r3325) 1691 1688 * 1692 * @param int $ 1689 * @param int $parent_id Parent id 1693 1690 * @param string $post_type Post type. Defaults to 'post' 1694 1691 * @uses wp_cache_get() To check if there is a cache of the children -
trunk/src/includes/core/abstraction.php
r6051 r6056 129 129 return apply_filters( 'bbp_pretty_urls', $retval ); 130 130 } 131 132 /**133 * Parse the WordPress core version number134 *135 * @since 2.6.0 bbPress (r6051)136 *137 * @global string $wp_version138 *139 * @return string $wp_version140 */141 function bbp_get_major_wp_version() {142 global $wp_version;143 144 return (float) $wp_version;145 } -
trunk/src/includes/core/actions.php
r6054 r6056 341 341 342 342 // Clean bbPress post caches when WordPress's is cleaned 343 add_action( 'clean_post_cache', 'bbp_clean_post_cache' , 10, 2);343 add_action( 'clean_post_cache', 'bbp_clean_post_cache' ); 344 344 345 345 /** -
trunk/src/includes/core/cache.php
r6054 r6056 131 131 * 132 132 * @since 2.1.0 bbPress (r4040) 133 * @since 2.6.0 bbPress (r6053) Introduced the `$post_id` parameter.134 133 * 135 * @param int $post_id The post id.136 * @param WP_Post $post The WP_Post object.137 *138 * @uses get_post() To get the post object.139 * @uses bbp_get_forum_post_type() To get the forum post type.140 * @uses bbp_get_topic_post_type() To get the topic post type.141 * @uses bbp_get_reply_post_type() To get the reply post type.142 * @uses wp_cache_delete() To delete the cache item.143 * @uses clean_object_term_cache() To clean the term cache.144 * @uses bbp_clean_post_cache() Recursion.145 134 * @uses do_action() Calls 'bbp_clean_post_cache' on $id 146 * 147 * @return void 135 * @param object|int $_post The post object or ID to remove from the cache 148 136 */ 149 function bbp_clean_post_cache( $ post_id = null, $post = null) {137 function bbp_clean_post_cache( $_post = '' ) { 150 138 151 // Get the post object. 152 if ( null !== $post ) { 153 $post = get_post( $post ); 154 } else { 155 $post = get_post( $post_id ); 156 } 157 158 // Bail if no post. 159 if ( empty( $post ) ) { 139 // Bail if no post 140 $_post = get_post( $_post ); 141 if ( empty( $_post ) ) { 160 142 return; 161 143 } 162 144 163 // Child query types to clean .145 // Child query types to clean 164 146 $post_types = array( 165 147 bbp_get_forum_post_type(), 166 148 bbp_get_topic_post_type(), 167 bbp_get_reply_post_type() ,149 bbp_get_reply_post_type() 168 150 ); 169 151 170 // Bail if not a bbPress post type .171 if ( ! in_array( $ post->post_type, $post_types, true ) ) {152 // Bail if not a bbPress post type 153 if ( ! in_array( $_post->post_type, $post_types, true ) ) { 172 154 return; 173 155 } 174 156 175 // Be sure we haven't recached the post data. 176 wp_cache_delete( $post->ID, 'posts' ); 177 wp_cache_delete( $post->ID, 'post_meta' ); 157 wp_cache_delete( $_post->ID, 'posts' ); 158 wp_cache_delete( $_post->ID, 'post_meta' ); 178 159 179 // Clean the term cache for the given post. 180 clean_object_term_cache( $post->ID, $post->post_type ); 160 clean_object_term_cache( $_post->ID, $_post->post_type ); 181 161 182 // Loop through query types and clean caches. 162 do_action( 'bbp_clean_post_cache', $_post->ID, $_post ); 163 164 // Loop through query types and clean caches 183 165 foreach ( $post_types as $post_type ) { 184 wp_cache_delete( 'bbp_parent_all_' . $ post->ID . '_type_' . $post_type . '_child_ids', 'bbpress_posts' );166 wp_cache_delete( 'bbp_parent_all_' . $_post->ID . '_type_' . $post_type . '_child_ids', 'bbpress_posts' ); 185 167 } 186 168 187 /** 188 * Fires immediately after the given post's cache is cleaned. 189 * 190 * @since 2.1.0 191 * 192 * @param int $post_id Post ID. 193 * @param WP_Post $post Post object. 194 */ 195 do_action( 'bbp_clean_post_cache', $post->ID, $post ); 196 197 // Invalidate parent caches. 198 if ( ! empty( $post->post_parent ) ) { 199 bbp_clean_post_cache( $post->post_parent ); 169 // Invalidate parent caches 170 if ( ! empty( $_post->post_parent ) ) { 171 bbp_clean_post_cache( $_post->post_parent ); 200 172 } 201 173 } -
trunk/src/includes/core/capabilities.php
r5951 r6056 47 47 'throttle' => true, 48 48 'view_trash' => true, 49 'assign_moderators' => true, 49 50 50 51 // Forum caps … … 92 93 'throttle' => true, 93 94 'view_trash' => true, 95 'assign_moderators' => true, 94 96 95 97 // Forum caps -
trunk/src/includes/core/filters.php
r6014 r6056 253 253 add_filter( 'bbp_map_meta_caps', 'bbp_map_primary_meta_caps', 10, 4 ); // Primary caps 254 254 add_filter( 'bbp_map_meta_caps', 'bbp_map_forum_meta_caps', 10, 4 ); // Forums 255 add_filter( 'bbp_map_meta_caps', 'bbp_map_forum_mod_meta_caps', 10, 4 ); // Forum mods256 255 add_filter( 'bbp_map_meta_caps', 'bbp_map_topic_meta_caps', 10, 4 ); // Topics 257 256 add_filter( 'bbp_map_meta_caps', 'bbp_map_topic_tag_meta_caps', 10, 4 ); // Topic tags -
trunk/src/includes/forums/capabilities.php
r5951 r6056 184 184 $caps = array( 'keep_gate' ); 185 185 break; 186 187 // Forum moderator admin area.188 case 'bbp_forum_mods_admin' :189 $caps = array( 'keep_gate' );190 break;191 186 } 192 187 … … 195 190 196 191 /** 197 * Return forum moderator capabilities 198 * 199 * @since 2.6.0 bbPress (r5834) 200 * 201 * @uses apply_filters() Calls 'bbp_get_forum_mod_caps' with the capabilities 202 * 203 * @return array Forum mod capabilities. 204 */ 205 function bbp_get_forum_mod_caps() { 206 return apply_filters( 'bbp_get_forum_mod_caps', array( 207 'manage_terms' => 'keep_gate', 208 'edit_terms' => 'keep_gate', 209 'delete_terms' => 'keep_gate', 210 'assign_terms' => 'keep_gate', 211 ) ); 212 } 213 214 /** 215 * Maps forum moderator capabilities 216 * 217 * @since 2.6.0 bbPress (r5834) 218 * 219 * @param array $caps Capabilities for meta capability. 220 * @param string $cap Capability name. 221 * @param int $user_id User id. 222 * @param mixed $args Arguments. 223 * @uses apply_filters() Filter capabilities map results. 224 * 225 * @return array Actual capabilities for meta capability. 226 */ 227 function bbp_map_forum_mod_meta_caps( $caps, $cap, $user_id, $args ) { 228 229 // What capability is being checked? 230 switch ( $cap ) { 231 case 'manage_forum_mods' : 232 case 'edit_forum_mods' : 233 case 'delete_forum_mods' : 234 case 'assign_forum_mods' : 235 case 'bbp_forum_mods_admin' : 236 237 // Key Masters can always edit. 238 if ( user_can( $user_id, 'keep_gate' ) ) { 239 $caps = array( 'keep_gate' ); 240 } 241 } 242 243 return apply_filters( 'bbp_map_forum_mod_meta_caps', $caps, $cap, $user_id, $args ); 244 } 245 246 /** 247 * Get moderators of a forum 248 * 249 * @since 2.6.0 bbPress (r5834) 250 * 251 * @param int $forum_id Forum id. 252 * @uses bbp_get_forum_id() To get the forum id 253 * @uses bbp_is_forum() To make sure it is a forum 254 * @uses bbp_get_forum_mod_tax_id() To get the forum moderator taxonomy 255 * @uses bbp_get_forum_mods() To get the forum's moderator terms 256 * @uses bbp_get_term_taxonomy_user_id() To convert terms to user ids 257 * 258 * @return boolean|array Return false on error or empty, or array of user ids 259 */ 260 function bbp_get_forum_moderator_ids( $forum_id = 0 ) { 261 262 // Bail if no forum ID. 263 $forum_id = bbp_get_forum_id( $forum_id ); 264 if ( empty( $forum_id ) ) { 265 return false; 266 } 267 268 // Bail if forum does not exist. 269 if ( ! bbp_is_forum( $forum_id ) ) { 270 return false; 271 } 272 273 // Get forum taxonomy terms. 274 $terms = bbp_get_forum_mods( $forum_id ); 275 276 // Bail if no terms found. 277 if ( empty( $terms ) ) { 278 return false; 279 } 280 281 // Setup default values 282 $term_ids = wp_parse_id_list( $terms ); 283 $taxonomy = bbp_get_forum_mod_tax_id(); 284 $moderator_ids = array(); 285 286 // Convert term ids to user ids. 287 foreach ( $term_ids as $term_id ) { 288 $moderator_ids[] = bbp_get_term_taxonomy_user_id( $term_id, $taxonomy ); 289 } 290 291 // Remove empties 292 $retval = wp_parse_id_list( array_filter( $moderator_ids ) ); 293 294 // Filter & return 295 return apply_filters( 'bbp_get_forum_moderator_ids', $retval, $forum_id ); 296 } 297 298 /** 299 * Get forums of a moderator 192 * Get array of forum IDs that a user can moderate 300 193 * 301 194 * @since 2.6.0 bbPress (r5834) … … 303 196 * @param int $user_id User id. 304 197 * @uses get_userdata() To get the user object 305 * @uses bbp_get_forum_mod_tax_id() To get the forum moderator taxonomy306 * @uses bbp_get_user_taxonomy_term_id() To get the user taxonomy term id307 198 * @uses get_term_by() To get the term id 308 199 * @uses get_objects_in_term() Get the forums the user moderates … … 314 205 function bbp_get_moderator_forum_ids( $user_id = 0 ) { 315 206 207 // Default return value 208 $retval = $forums = array(); 209 316 210 // Bail if no user ID. 317 211 $user_id = bbp_get_user_id( $user_id ); 318 if ( empty( $user_id ) ) { 319 return false; 320 } 321 322 // Bail if user does not exist. 323 $user = get_userdata( $user_id ); 324 if ( empty( $user ) ) { 325 return false; 326 } 327 328 // Convert user id to term id. 329 $taxonomy = bbp_get_forum_mod_tax_id(); 330 $term_id = bbp_get_user_taxonomy_term_id( $user_id, $taxonomy ); 331 332 // Get moderator forums. 333 $forums = get_objects_in_term( $term_id, $taxonomy ); 334 335 // Forums found. 336 if ( empty( $forums ) || is_wp_error( $forums ) ) { 337 return false; 338 } 339 340 // Make sure the ids returned are forums. 341 $forum_ids = array(); 342 foreach ( $forums as $forum_id ) { 343 if ( bbp_is_forum( $forum_id ) ) { 344 $forum_ids[] = $forum_id; 212 if ( ! empty( $user_id ) ) { 213 214 // Bail if user does not exist. 215 $user = get_userdata( $user_id ); 216 if ( ! empty( $user ) ) { 217 218 // Get the forums this user can moderate 219 $forums = get_posts( array( 220 'post_type' => bbp_get_forum_post_type(), 221 'meta_key' => '_bbp_moderator_id', 222 'meta_type' => 'NUMERIC', 223 'meta_value' => $user_id, 224 'numberposts' => -1 225 ) ); 226 227 // Pluck IDs 228 if ( ! empty( $forums ) ) { 229 $retval = wp_list_pluck( $forums, 'ID' ); 230 } 345 231 } 346 232 } 347 233 348 // Remove empties349 $retval = wp_parse_id_list( array_filter( $forum_ids ) );350 351 234 // Filter & return 352 return apply_filters( 'bbp_get_moderator_forum_ids', $retval, $user_id);235 return (array) apply_filters( 'bbp_get_moderator_forum_ids', $retval, $user_id, $forums ); 353 236 } 354 237 … … 363 246 * @uses bbp_get_forum_id() 364 247 * @uses bbp_get_moderator_forum_ids() 365 * @uses apply_filters() Calls 'bbp_is_user_forum_mod ' with the forums248 * @uses apply_filters() Calls 'bbp_is_user_forum_moderator' with the forums 366 249 * 367 250 * @return bool Return true if user is moderator of forum 368 251 */ 369 function bbp_is_user_forum_mod ( $user_id = 0, $forum_id = 0 ) {252 function bbp_is_user_forum_moderator( $user_id = 0, $forum_id = 0 ) { 370 253 371 254 // Assume user cannot moderate the forum. … … 384 267 } 385 268 386 return (bool) apply_filters( 'bbp_is_user_forum_mod ', $retval, $user_id, $forum_id, $forum_ids );387 } 269 return (bool) apply_filters( 'bbp_is_user_forum_moderator', $retval, $user_id, $forum_id, $forum_ids ); 270 } -
trunk/src/includes/forums/functions.php
r6036 r6056 138 138 $forum_parent_id = $forum_author = 0; 139 139 $forum_title = $forum_content = ''; 140 $terms = array( bbp_get_forum_mod_tax_id() => array() );141 140 142 141 /** Forum Author **********************************************************/ … … 247 246 if ( ! bbp_check_for_moderation( $anonymous_data, $forum_author, $forum_title, $forum_content ) ) { 248 247 $post_status = bbp_get_pending_status_id(); 249 }250 251 /** Forum Mods ************************************************************/252 253 if ( bbp_allow_forum_mods() && ! empty( $_POST['bbp_forum_mods'] ) ) {254 255 // Escape tag input256 $terms = sanitize_text_field( $_POST['bbp_forum_mods'] );257 258 // Explode by comma259 if ( strstr( $terms, ',' ) ) {260 $terms = explode( ',', $terms );261 }262 263 // Add forum_mod ID as main key264 $terms = array( bbp_get_forum_mod_tax_id() => $terms );265 248 } 266 249 … … 285 268 'post_status' => $post_status, 286 269 'post_type' => bbp_get_forum_post_type(), 287 'tax_input' => $terms,288 270 'comment_status' => 'closed' 289 271 ) ); … … 522 504 } 523 505 524 /** Forum Mods ************************************************************/525 526 // Either replace terms527 if ( bbp_allow_forum_mods() && current_user_can( 'assign_forum_mods' ) && ! empty( $_POST['bbp_forum_mods'] ) ) {528 529 // Escape tag input530 $terms = sanitize_text_field( $_POST['bbp_forum_mods'] );531 532 // Explode by comma533 if ( strstr( $terms, ',' ) ) {534 $terms = explode( ',', $terms );535 }536 537 // Add forum mod ID as main key538 $terms = array( bbp_get_forum_mod_tax_id() => $terms );539 540 // ...or remove them.541 } elseif ( isset( $_POST['bbp_forum_mods'] ) ) {542 $terms = array( bbp_get_forum_mod_tax_id() => array() );543 544 // Existing terms545 } else {546 $terms = array( bbp_get_forum_mod_tax_id() => explode( ',', bbp_get_forum_mod_names( $forum_id, ',' ) ) );547 }548 549 506 /** Additional Actions (Before Save) **************************************/ 550 507 … … 745 702 do_action( 'bbp_update_forum_visibility', $forum_id, $old_visibility, $new_visibility ); 746 703 } 704 705 /** Forum Moderators ******************************************************/ 706 707 // Either replace terms 708 if ( bbp_allow_forum_mods() ) { 709 if ( current_user_can( 'assign_moderators' ) && ! empty( $_POST['bbp_moderators'] ) ) { 710 711 // Escape tag input 712 $users = sanitize_text_field( $_POST['bbp_moderators'] ); 713 714 // Explode by comma 715 $users = strstr( $users, ',' ) 716 ? explode( ',', $users ) 717 : (array) $users; 718 719 $user_ids = bbp_get_user_ids_from_nicenames( $users ); 720 721 // Update forum moderators 722 if ( ! empty( $user_ids ) ) { 723 724 // Remove all moderators 725 bbp_remove_moderator( $forum_id, null ); 726 727 // Add moderators 728 foreach ( $user_ids as $user_id ) { 729 bbp_add_moderator( $forum_id, $user_id ); 730 } 731 } 732 733 // ...or remove them. 734 } elseif ( isset( $_POST['bbp_moderators'] ) ) { 735 bbp_remove_moderator( $forum_id, null ); 736 } 737 } 747 738 } 748 739 … … 1987 1978 } 1988 1979 1989 /** Forum Mods ****************************************************************/1990 1991 /**1992 * Get forum mods for a specific forum ID1993 *1994 * @since 2.6.0 bbPress (r5836)1995 *1996 * @param int $forum_id1997 *1998 * @return string1999 */2000 function bbp_get_forum_mods( $forum_id = 0 ) {2001 $forum_id = bbp_get_forum_id( $forum_id );2002 $terms = (array) get_the_terms( $forum_id, bbp_get_forum_mod_tax_id() );2003 $forum_mods = array_filter( $terms );2004 2005 return apply_filters( 'bbp_get_forum_mods', $forum_mods, $forum_id );2006 }2007 2008 /**2009 * Get forum mods for a specific forum ID2010 *2011 * @since 2.2.0 bbPress (r4165)2012 *2013 * @param int $forum_id2014 * @param string $sep2015 *2016 * @return string2017 */2018 function bbp_get_forum_mod_names( $forum_id = 0, $sep = ', ' ) {2019 $forum_mods = bbp_get_forum_mods( $forum_id );2020 $pluck = wp_list_pluck( $forum_mods, 'name' );2021 $terms = ! empty( $pluck ) ? implode( $sep, $pluck ) : '';2022 2023 return apply_filters( 'bbp_get_forum_mod_names', $terms, $forum_id, $sep );2024 }2025 2026 1980 /** Helpers *******************************************************************/ 2027 1981 -
trunk/src/includes/forums/template.php
r6026 r6056 465 465 466 466 /** 467 * Output value of forum mods field468 *469 * @since 2.6.0 bbPress (r5837)470 *471 * @uses bbp_get_form_forum_mods() To get the value of forum mods field472 */473 function bbp_form_forum_mods() {474 echo bbp_get_form_forum_mods();475 }476 /**477 * Return value of forum mods field478 *479 * @since 2.6.0 bbPress (r5837)480 *481 * @uses bbp_is_forum_edit() To check if it's the forum edit page482 * @uses apply_filters() Calls 'bbp_get_form_forum_mods' with the mods483 *484 * @return string Value of forum mods field485 */486 function bbp_get_form_forum_mods() {487 488 // Get _POST data489 if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_forum_mods'] ) ) {490 $forum_mods = wp_unslash( $_POST['bbp_forum_mods'] );491 492 // Get edit data493 } elseif ( bbp_is_single_forum() || bbp_is_forum_edit() ) {494 495 // Get the forum ID496 $forum_id = bbp_get_forum_id( get_the_ID() );497 498 // Forum exists499 if ( ! empty( $forum_id ) ) {500 $forum_mods = bbp_get_forum_mod_names( $forum_id );501 }502 503 // No data504 } else {505 $forum_mods = '';506 }507 508 return apply_filters( 'bbp_get_form_forum_mods', $forum_mods );509 }510 511 /**512 467 * Output the forums last active ID 513 468 * … … 2225 2180 } 2226 2181 2227 /** Moderators ****************************************************************/2228 2229 /**2230 * Output the unique id of the forum moderators taxonomy2231 *2232 * @since 2.6.0 bbPress (r5834)2233 *2234 * @uses bbp_get_forum_mod_tax_id() To get the forum modorator taxonomy ID2235 */2236 function bbp_forum_mod_tax_id() {2237 echo bbp_get_forum_mod_tax_id();2238 }2239 /**2240 * Return the unique id of the forum moderators taxonomy2241 *2242 * @since 2.6.0 bbPress (r5834)2243 *2244 * @uses apply_filters() Calls 'bbp_get_forum_mod_tax_id' with the forum2245 * moderator taxonomy id2246 * @return string The unique forum moderators taxonomy2247 */2248 function bbp_get_forum_mod_tax_id() {2249 return apply_filters( 'bbp_get_forum_mod_tax_id', bbpress()->forum_mod_tax_id );2250 }2251 2252 /**2253 * Return array of labels used by the forum-mod taxonomy2254 *2255 * @since 2.6.0 bbPress (r5834)2256 *2257 * @uses apply_filters() Calls 'bbp_get_forum_mod_tax_id' with the forum2258 * moderator taxonomy labels2259 * @return array2260 */2261 function bbp_get_forum_mod_tax_labels() {2262 return apply_filters( 'bbp_get_forum_mod_tax_labels', array(2263 'name' => __( 'Forum Moderators', 'bbpress' ),2264 'singular_name' => __( 'Forum Moderator', 'bbpress' ),2265 'search_items' => __( 'Search Moderators', 'bbpress' ),2266 'popular_items' => __( 'Popular Moderators', 'bbpress' ),2267 'all_items' => __( 'All Moderators', 'bbpress' ),2268 'edit_item' => __( 'Edit Moderator', 'bbpress' ),2269 'update_item' => __( 'Update Moderator', 'bbpress' ),2270 'add_new_item' => __( 'Add New Moderator', 'bbpress' ),2271 'new_item_name' => __( 'New Moderator Name', 'bbpress' ),2272 'view_item' => __( 'View Forum Moderator', 'bbpress' ),2273 'separate_items_with_commas' => __( 'Separate moderator names with commas', 'bbpress' ),2274 ) );2275 }2276 2277 /**2278 * Output a the moderators of a forum2279 *2280 * @since 2.6.0 bbPress (r5834)2281 *2282 * @param int $forum_id Optional. Topic id2283 * @param array $args See {@link bbp_get_forum_mod_list()}2284 * @uses bbp_get_topic_tag_list() To get the forum mod list2285 */2286 function bbp_forum_mod_list( $forum_id = 0, $args = array() ) {2287 echo bbp_get_forum_mod_list( $forum_id, $args );2288 }2289 /**2290 * Return the moderators of a forum2291 *2292 * @since 2.6.0 bbPress (r5834)2293 *2294 * @param int $forum_id Optional. Forum id2295 * @param array $args This function supports these arguments:2296 * - before: Before the tag list2297 * - sep: Tag separator2298 * - after: After the tag list2299 * @uses bbp_get_forum_id() To get the forum id2300 * @uses get_the_term_list() To get the moderator list2301 *2302 * @return string Moderator list of the forum2303 */2304 function bbp_get_forum_mod_list( $forum_id = 0, $args = array() ) {2305 2306 // Bail if forum-mods are off2307 if ( ! bbp_allow_forum_mods() ) {2308 return '';2309 }2310 2311 // Parse arguments against default values2312 $r = bbp_parse_args( $args, array(2313 'before' => '<div class="bbp-forum-mods"><p>' . esc_html__( 'Moderators:', 'bbpress' ) . ' ',2314 'sep' => ', ',2315 'after' => '</p></div>',2316 'none' => ''2317 ), 'get_forum_mod_list' );2318 2319 // Bail if forum ID is invalid2320 $forum_id = bbp_get_forum_id( $forum_id );2321 if ( empty( $forum_id ) ) {2322 return '';2323 }2324 2325 // Get forum moderators2326 $moderators = bbp_get_forum_mods( $forum_id );2327 if ( ! empty( $moderators ) ) {2328 2329 // In admin, use nicenames2330 if ( is_admin() ) {2331 2332 // @todo link to filtering forums by moderator2333 $users = wp_list_pluck( $moderators, 'name' );2334 2335 // In theme, use display names & profile links2336 } else {2337 $users = array();2338 $term_ids = wp_list_pluck( $moderators, 'term_id' );2339 foreach ( $term_ids as $term_id ) {2340 $user_id = bbp_get_term_taxonomy_user_id( $term_id );2341 $users[] = bbp_get_user_profile_link( $user_id );2342 }2343 }2344 2345 $retval = $r['before'] . implode( $r['sep'], $users ) . $r['after'];2346 2347 // No forum moderators2348 } else {2349 $retval = $r['none'];2350 }2351 2352 return $retval;2353 }2354 2355 2182 /** Forms *********************************************************************/ 2356 2183 … … 2427 2254 2428 2255 return apply_filters( 'bbp_get_form_forum_content', $forum_content ); 2256 } 2257 2258 /** 2259 * Output value of forum moderators field 2260 * 2261 * @since 2.6.0 bbPress (r5837) 2262 * 2263 * @uses bbp_get_form_forum_moderators() To get the value of forum moderators field 2264 */ 2265 function bbp_form_forum_moderators() { 2266 echo bbp_get_form_forum_moderators(); 2267 } 2268 /** 2269 * Return value of forum moderators field 2270 * 2271 * @since 2.6.0 bbPress (r5837) 2272 * 2273 * @uses bbp_is_forum_edit() To check if it's the forum edit page 2274 * @uses apply_filters() Calls 'bbp_get_form_forum_mods' with the mods 2275 * 2276 * @return string Value of forum mods field 2277 */ 2278 function bbp_get_form_forum_moderators() { 2279 2280 // Default return value 2281 $forum_mods = ''; 2282 2283 // Get _POST data 2284 if ( bbp_is_forum_form_post_request() && isset( $_POST['bbp_moderators'] ) ) { 2285 $forum_mods = wp_unslash( $_POST['bbp_moderators'] ); 2286 2287 // Get edit data 2288 } elseif ( bbp_is_single_forum() || bbp_is_forum_edit() ) { 2289 2290 // Get the forum ID 2291 $forum_id = bbp_get_forum_id( get_the_ID() ); 2292 2293 // Forum exists 2294 if ( ! empty( $forum_id ) ) { 2295 2296 // Get moderator IDs 2297 $user_ids = bbp_get_moderator_ids( $forum_id ); 2298 if ( ! empty( $user_ids ) ) { 2299 $user_nicenames = bbp_get_user_nicenames_from_ids( $user_ids ); 2300 2301 // Comma separate user nicenames 2302 if ( ! empty( $user_nicenames ) ) { 2303 $forum_mods = implode( ', ', wp_list_pluck( $user_nicenames, 'user_nicename' ) ); 2304 } 2305 } 2306 } 2307 } 2308 2309 return apply_filters( 'bbp_get_form_forum_moderators', $forum_mods ); 2429 2310 } 2430 2311 … … 2648 2529 $r = bbp_parse_args( $args, array( 2649 2530 'select_id' => 'bbp_forum_type', 2531 'select_class' => 'bbp_dropdown', 2650 2532 'tab' => false, 2651 2533 'forum_id' => $forum_id, … … 2681 2563 ob_start(); ?> 2682 2564 2683 <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select" <?php echo $tab; ?>>2565 <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select" class="<?php echo esc_attr( $r['select_class'] ); ?>"<?php echo $tab; ?>> 2684 2566 2685 2567 <?php foreach ( bbp_get_forum_types( $r['forum_id'] ) as $key => $label ) : ?> … … 2740 2622 $r = bbp_parse_args( $args, array( 2741 2623 'select_id' => 'bbp_forum_status', 2624 'select_class' => 'bbp_dropdown', 2742 2625 'tab' => false, 2743 2626 'forum_id' => $forum_id, … … 2773 2656 ob_start(); ?> 2774 2657 2775 <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select" <?php echo $tab; ?>>2658 <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select" class="<?php echo esc_attr( $r['select_class'] ); ?>"<?php echo $tab; ?>> 2776 2659 2777 2660 <?php foreach ( bbp_get_forum_statuses( $r['forum_id'] ) as $key => $label ) : ?> … … 2832 2715 $r = bbp_parse_args( $args, array( 2833 2716 'select_id' => 'bbp_forum_visibility', 2717 'select_class' => 'bbp_dropdown', 2834 2718 'tab' => false, 2835 2719 'forum_id' => $forum_id, … … 2865 2749 ob_start(); ?> 2866 2750 2867 <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select" <?php echo $tab; ?>>2751 <select name="<?php echo esc_attr( $r['select_id'] ) ?>" id="<?php echo esc_attr( $r['select_id'] ) ?>_select" class="<?php echo esc_attr( $r['select_class'] ); ?>"<?php echo $tab; ?>> 2868 2752 2869 2753 <?php foreach ( bbp_get_forum_visibilities( $r['forum_id'] ) as $key => $label ) : ?> -
trunk/src/includes/replies/capabilities.php
r5951 r6056 41 41 * @uses get_post_type_object() To get the post type object 42 42 * @uses bbp_get_public_status_id() To get the public status id 43 * @uses bbp_is_user_forum_mod () To check if the user is a forum moderator43 * @uses bbp_is_user_forum_moderator() To check if the user is a forum moderator 44 44 * @uses bbp_get_reply_forum_id() To get the repliy forum id 45 45 * @uses apply_filters() Filter mapped results … … 135 135 136 136 // User is a per-forum moderator, make sure they can spectate. 137 } elseif ( bbp_allow_forum_mods() && bbp_is_user_forum_mod ( $user_id, bbp_get_reply_forum_id( $_post->ID ) ) ) {137 } elseif ( bbp_allow_forum_mods() && bbp_is_user_forum_moderator( $user_id, bbp_get_reply_forum_id( $_post->ID ) ) ) { 138 138 $caps = array( 'spectate' ); 139 139 -
trunk/src/includes/topics/capabilities.php
r5951 r6056 59 59 * @uses get_post_type_object() To get the post type object 60 60 * @uses bbp_get_public_status_id() To get the public status id 61 * @uses bbp_is_user_forum_mod () To check if the user is a forum moderator61 * @uses bbp_is_user_forum_moderator() To check if the user is a forum moderator 62 62 * @uses bbp_get_topic_forum_id() To get the opic forum id 63 63 * @uses apply_filters() Filter capability map results … … 156 156 157 157 // If user is a per-forum moderator, make sure they can spectate. 158 if ( bbp_is_user_forum_mod ( $user_id, bbp_get_topic_forum_id( $_post->ID ) ) ) {158 if ( bbp_is_user_forum_moderator( $user_id, bbp_get_topic_forum_id( $_post->ID ) ) ) { 159 159 $caps = array( 'spectate' ); 160 160 -
trunk/src/includes/topics/functions.php
r6037 r6056 393 393 do_action( 'bbp_new_topic', $topic_id, $forum_id, $anonymous_data, $topic_author ); 394 394 395 /** Stickies **********************************************************/396 397 // Sticky check after 'bbp_new_topic' action so forum ID meta is set398 if ( ! empty( $_POST['bbp_stick_topic'] ) && in_array( $_POST['bbp_stick_topic'], array( 'stick', 'super', 'unstick' ) ) ) {399 400 // What's the caps?401 if ( current_user_can( 'moderate', $topic_id ) ) {402 403 // What's the haps?404 switch ( $_POST['bbp_stick_topic'] ) {405 406 // Sticky in this forum407 case 'stick' :408 bbp_stick_topic( $topic_id );409 break;410 411 // Super sticky in all forums412 case 'super' :413 bbp_stick_topic( $topic_id, true );414 break;415 416 // We can avoid this as it is a new topic417 case 'unstick' :418 default :419 break;420 }421 }422 }423 424 395 /** Additional Actions (After Save) ***********************************/ 425 396 … … 761 732 } 762 733 763 /** Stickies **********************************************************/764 765 // Get the topic types766 $topic_types = bbp_get_topic_types( $topic_id );767 768 // Maybe sticky769 if ( ! empty( $_POST['bbp_stick_topic'] ) && in_array( $_POST['bbp_stick_topic'], array_keys( $topic_types ) ) ) {770 771 // What's the caps?772 if ( current_user_can( 'moderate', $topic_id ) ) {773 774 // What's the haps?775 switch ( $_POST['bbp_stick_topic'] ) {776 777 // Sticky in forum778 case 'stick' :779 bbp_stick_topic( $topic_id );780 break;781 782 // Sticky in all forums783 case 'super' :784 bbp_stick_topic( $topic_id, true );785 break;786 787 // Normal788 case 'unstick' :789 default :790 bbp_unstick_topic( $topic_id );791 break;792 }793 }794 }795 796 734 /** Additional Actions (After Save) ***********************************/ 797 735 … … 879 817 if ( empty( $forum_id ) ) { 880 818 $forum_id = bbp_get_topic_forum_id( $topic_id ); 819 } 820 821 // Get the topic types 822 $topic_types = bbp_get_topic_types( $topic_id ); 823 824 // Sticky check after 'bbp_new_topic' action so forum ID meta is set 825 if ( ! empty( $_POST['bbp_stick_topic'] ) && in_array( $_POST['bbp_stick_topic'], array_keys( $topic_types ) ) ) { 826 827 // What's the caps? 828 if ( current_user_can( 'moderate', $topic_id ) ) { 829 830 // What's the haps? 831 switch ( $_POST['bbp_stick_topic'] ) { 832 833 // Sticky in this forum 834 case 'stick' : 835 bbp_stick_topic( $topic_id ); 836 break; 837 838 // Super sticky in all forums 839 case 'super' : 840 bbp_stick_topic( $topic_id, true ); 841 break; 842 843 // We can avoid this as it is a new topic 844 case 'unstick' : 845 default : 846 break; 847 } 848 } 881 849 } 882 850 -
trunk/src/includes/users/capabilities.php
r5951 r6056 26 26 * @uses bbp_get_reply_post_type() To get the reply post type 27 27 * @uses bbp_get_reply_forum_id() To get the reply forum id 28 * @uses bbp_is_user_forum_mod () To check if the user is a forum moderator28 * @uses bbp_is_user_forum_moderator() To check if the user is a forum moderator 29 29 * @uses apply_filters() Filter mapped results 30 30 * … … 110 110 111 111 // If user is a per-forum moderator, make sure they can spectate. 112 if ( bbp_is_user_forum_mod ( $user_id, $forum_id ) ) {112 if ( bbp_is_user_forum_moderator( $user_id, $forum_id ) ) { 113 113 $caps = array( 'spectate' ); 114 114 } … … 798 798 return (bool) apply_filters( 'bbp_show_user_profile', $retval, $user_id ); 799 799 } 800 801 /** Moderators ****************************************************************/ 802 803 /** 804 * Add a moderator to an object 805 * 806 * @since 2.6.0 bbPRess 807 * 808 * @param int $object_id Traditionally a forum ID, but could be useful 809 * @param int $user_id 810 * 811 * @return @mixed 812 */ 813 function bbp_add_moderator( $object_id = 0, $user_id = 0 ) { 814 return add_post_meta( $object_id, '_bbp_moderator_id', $user_id ); 815 } 816 817 /** 818 * Remove a moderator user ID from an object 819 * 820 * @since 2.6.0 bbPress 821 * 822 * @param int $object_id 823 * @param int $user_id 824 * 825 * @return mixed 826 */ 827 function bbp_remove_moderator( $object_id = 0, $user_id = 0 ) { 828 return delete_post_meta( $object_id, '_bbp_moderator_id', $user_id ); 829 } 830 831 /** 832 * Get user IDs of moderators for an object 833 * 834 * @since 2.6.0 bbPress 835 * 836 * @param int $object_id 837 * 838 * @return mixed 839 */ 840 function bbp_get_moderator_ids( $object_id = 0 ) { 841 return get_post_meta( $object_id, '_bbp_moderator_id', false ); 842 } 843 844 /** 845 * Get moderators for a specific object ID. Will return global moderators when 846 * object ID is empty. 847 * 848 * @since 2.6.0 bbPress 849 * 850 * @param int $object_id 851 * 852 * @return array 853 */ 854 function bbp_get_moderators( $object_id = 0 ) { 855 856 // Get global moderators 857 if ( empty( $object_id ) ) { 858 $users = get_users( array( 859 'role__in' => bbp_get_moderator_role(), 860 ) ); 861 862 // Get object moderators 863 } else { 864 $users = get_users( array( 865 'include' => bbp_get_moderator_ids( $object_id ), 866 ) ); 867 } 868 869 return apply_filters( 'bbp_get_moderators', $users, $object_id ); 870 } -
trunk/src/includes/users/functions.php
r5951 r6056 1721 1721 } 1722 1722 1723 /** 1724 * Get user IDs from nicenames 1725 * 1726 * This function is primarily used when saving object moderators 1727 * 1728 * @since 2.6.0 bbPress 1729 * 1730 * @param mixed $user_nicenames 1731 * @return array 1732 */ 1733 function bbp_get_user_ids_from_nicenames( $user_nicenames = array() ) { 1734 1735 // Default value 1736 $user_ids = array(); 1737 1738 // Only query if nicenames 1739 if ( ! empty( $user_nicenames ) ) { 1740 1741 // Maybe explode by comma 1742 $user_nicenames = ( is_string( $user_nicenames ) && strstr( $user_nicenames, ',' ) ) 1743 ? explode( ',', $user_nicenames ) 1744 : (array) $user_nicenames; 1745 1746 // Do the query 1747 $users = implode( "', '", array_map( 'trim', $user_nicenames ) ); 1748 $bbp_db = bbp_db(); 1749 $query = "SELECT ID FROM `{$bbp_db->users}` WHERE user_nicename IN ('{$users}')"; 1750 $user_ids = $bbp_db->get_col( $query ); 1751 } 1752 1753 return apply_filters( 'bbp_get_user_ids_from_nicenames', $user_ids, $user_nicenames ); 1754 } 1755 1756 /** 1757 * Get user nicenames from IDs 1758 * 1759 * This function is primarily used when saving object moderators 1760 * 1761 * @since 2.6.0 bbPress 1762 * 1763 * @param mixed $user_ids 1764 * @return array 1765 */ 1766 function bbp_get_user_nicenames_from_ids( $user_ids = array() ) { 1767 1768 // Default value 1769 $user_nicenames = array(); 1770 1771 // Only query if nicenames 1772 if ( ! empty( $user_ids ) ) { 1773 1774 // Get user objects 1775 $users = get_users( array( 1776 'include' => $user_ids 1777 ) ); 1778 1779 // Pluck or empty 1780 if ( ! empty( $users ) ) { 1781 $user_nicenames = wp_list_pluck( $users, 'user_nicename' ); 1782 } 1783 } 1784 1785 return apply_filters( 'bbp_get_user_nicenames_from_ids', $user_nicenames, $user_ids ); 1786 } 1787 1723 1788 /** Post Counts ***************************************************************/ 1724 1789 … … 1912 1977 $user_id = bbp_get_reply_author_id( $reply_id ); 1913 1978 return bbp_bump_user_reply_count( $user_id, -1 ); 1914 }1915 1916 /** User Nicename Taxonomies **************************************************/1917 1918 /**1919 * Return the term id for a given user id and taxonomy1920 *1921 * @since 2.6.0 bbPress (r5834)1922 *1923 * @param int $user_id User id.1924 * @param string $taxonomy Taxonomy.1925 * @uses get_userdata() To get the user data1926 * @uses taxonomy_exists() To make sure the taxonomy exists1927 * @uses get_term_by() To get the term by name1928 *1929 * @return boolean|int Return false early, or if not found, or int term id1930 */1931 function bbp_get_user_taxonomy_term_id( $user_id = 0, $taxonomy = '' ) {1932 1933 // Bail if no user ID.1934 if ( empty( $user_id ) ) {1935 return false;1936 }1937 1938 // Bail if user does not exist.1939 $user = get_userdata( $user_id );1940 if ( empty( $user ) ) {1941 return false;1942 }1943 1944 // Bail if no taxonomy.1945 if ( empty( $taxonomy ) || ! taxonomy_exists( $taxonomy ) ) {1946 return false;1947 }1948 1949 // Get the term id.1950 $term = get_term_by( 'name', $user->user_nicename, $taxonomy );1951 if ( ! empty( $term ) ) {1952 return $term->term_id;1953 }1954 1955 return false;1956 }1957 1958 /**1959 * Return the user id for a given term id and taxonomy1960 *1961 * @since 2.6.0 bbPress (r5834)1962 *1963 * @param int $term_id Term id.1964 * @param string $taxonomy Taxonomy.1965 * @uses taxonomy_exists() To make sure the taxonomy exists1966 * @uses get_term() To get the term by term id1967 * @uses get_user_by() To get the user by nicename1968 *1969 * @return boolean|int Return false early, or if not found, or int user id1970 */1971 function bbp_get_term_taxonomy_user_id( $term_id = 0, $taxonomy = '' ) {1972 1973 // Bail if no user ID.1974 if ( empty( $term_id ) ) {1975 return false;1976 }1977 1978 // Bail if no taxonomy.1979 if ( empty( $taxonomy ) || ! taxonomy_exists( $taxonomy ) ) {1980 return false;1981 }1982 1983 // Bail if no term exists.1984 $term = get_term( $term_id, $taxonomy );1985 if ( empty( $term ) ) {1986 return false;1987 }1988 1989 // Get the user by nicename.1990 $nicename = $term->name;1991 $user = get_user_by( 'slug', $nicename );1992 if ( ! empty( $user ) ) {1993 return $user->ID;1994 }1995 1996 return false;1997 }1998 1999 function bbp_filter_forum_mod_term_link( $termlink = '', $term = '', $taxonomy = '' ) {2000 2001 // Bail if taxonomy is not forum mod2002 if ( bbp_get_forum_mod_tax_id() !== $taxonomy ) {2003 return $termlink;2004 }2005 2006 // Bail if forum mods is not allowed2007 if ( ! bbp_allow_forum_mods() ) {2008 return $termlink;2009 }2010 2011 // Get user ID from taxonomy term2012 $user_id = bbp_get_term_taxonomy_user_id( $term->term_id, bbp_get_forum_mod_tax_id() );2013 2014 if ( is_admin() ) {2015 2016 // Get the moderator's display name2017 $display_name = get_userdata( $user_id )->display_name;2018 $user_link = get_edit_user_link( $user_id );2019 2020 // Link or name only2021 if ( ! empty( $user_link ) ) {2022 $retval = '<a href="' . esc_url( $user_link ) . '">' . esc_html( $display_name ) . '</a>';2023 2024 // Can't edit2025 } else {2026 $retval = $display_name;2027 }2028 2029 // Theme side term link2030 } else {2031 $retval = bbp_get_user_profile_link( $user_id );2032 }2033 2034 return $retval;2035 1979 } 2036 1980 -
trunk/src/includes/users/template.php
r6032 r6056 2110 2110 return (bool) apply_filters( 'bbp_current_user_can_access_anonymous_user_form', (bool) $retval ); 2111 2111 } 2112 2113 /** Moderators ****************************************************************/ 2114 2115 /** 2116 * Output the moderators of a forum 2117 * 2118 * @since 2.6.0 bbPress 2119 * 2120 * @param int $forum_id Optional. Topic id 2121 * @param array $args See {@link bbp_get_moderator_list()} 2122 * @uses bbp_get_moderator_list() To get the moderator list 2123 */ 2124 function bbp_moderator_list( $forum_id = 0, $args = array() ) { 2125 echo bbp_get_moderator_list( $forum_id, $args ); 2126 } 2127 2128 /** 2129 * Return the moderators for an object 2130 * 2131 * @since 2.6.0 bbPress 2132 * 2133 * @param int $object_id Optional. Object id 2134 * @param array $args This function supports these arguments: 2135 * - before: Before the tag list 2136 * - sep: Tag separator 2137 * - after: After the tag list 2138 * 2139 * @return string Moderator list of the object 2140 */ 2141 function bbp_get_moderator_list( $object_id = 0, $args = array() ) { 2142 2143 // Parse arguments against default values 2144 $r = bbp_parse_args( $args, array( 2145 'before' => '<div class="bbp-moderators"><p>' . esc_html__( 'Moderators:', 'bbpress' ) . ' ', 2146 'sep' => ', ', 2147 'after' => '</p></div>', 2148 'none' => '' 2149 ), 'get_moderator_list' ); 2150 2151 // Get forum moderators 2152 $user_ids = bbp_get_moderator_ids( $object_id ); 2153 if ( ! empty( $user_ids ) ) { 2154 2155 // In admin, use nicenames 2156 if ( is_admin() ) { 2157 $users = bbp_get_user_nicenames_from_ids( $user_ids ); 2158 2159 // In theme, use display names & profile links 2160 } else { 2161 foreach ( $user_ids as $user_id ) { 2162 $users[] = bbp_get_user_profile_link( $user_id ); 2163 } 2164 } 2165 2166 $retval = $r['before'] . implode( $r['sep'], $users ) . $r['after']; 2167 2168 // No forum moderators 2169 } else { 2170 $retval = $r['none']; 2171 } 2172 2173 return apply_filters( 'bbp_get_moderator_list', $retval ); 2174 } -
trunk/src/templates/default/bbpress/form-forum.php
r5868 r6056 91 91 <?php endif; ?> 92 92 93 <?php if ( bbp_allow_forum_mods() && current_user_can( 'assign_ forum_mods' ) ) : ?>93 <?php if ( bbp_allow_forum_mods() && current_user_can( 'assign_moderators' ) ) : ?> 94 94 95 95 <?php do_action( 'bbp_theme_before_forum_form_mods' ); ?> 96 96 97 97 <p> 98 <label for="bbp_ forum_mods"><?php esc_html_e( 'Forum Moderators:', 'bbpress' ); ?></label><br />99 <input type="text" value="<?php bbp_form_forum_mod s(); ?>" size="40" name="bbp_forum_mods" id="bbp_forum_mods" />98 <label for="bbp_moderators"><?php esc_html_e( 'Forum Moderators:', 'bbpress' ); ?></label><br /> 99 <input type="text" value="<?php bbp_form_forum_moderators(); ?>" size="40" name="bbp_moderators" id="bbp_moderators" /> 100 100 </p> 101 101
Note: See TracChangeset
for help on using the changeset viewer.