| @@ -57,9 +57,9 @@ | ||
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * Maps topic capabilities |
| 60 | 60 | * |
| 61 | - * @since 2.2.0 bbPress (r4242) | |
| 61 | + * @since 2.2.0 bbPress (r4244) | |
| 62 | 62 | * |
| 63 | 63 | * @param array $caps Capabilities for meta capability. |
| 64 | 64 | * @param string $cap Capability name. |
| 65 | 65 | * @param int $user_id User id. |
| @@ -281,9 +281,10 @@ | ||
| 281 | 281 | |
| 282 | 282 | /** |
| 283 | 283 | * Maps topic tag capabilities |
| 284 | 284 | * |
| 285 | - * @since 2.2.0 bbPress (r4242) | |
| 285 | + * @since 2.2.0 bbPress (r4244) | |
| 286 | + * @since 2.6.19 bbPress (r7741) Keep term IDs separate from post moderation. | |
| 286 | 287 | * |
| 287 | 288 | * @param array $caps Capabilities for meta capability |
| 288 | 289 | * @param string $cap Capability name |
| 289 | 290 | * @param int $user_id User id |
| @@ -300,11 +301,10 @@ | ||
| 300 | 301 | |
| 301 | 302 | case 'assign_topic_tags' : |
| 302 | 303 | |
| 303 | 304 | // Get post |
| 304 | - $post_id = ! empty( $args[0] ) | |
| 305 | - ? get_post( $args[0] )->ID | |
| 306 | - : 0; | |
| 305 | + $_post = ! empty( $args[0] ) ? get_post( $args[0] ) : null; | |
| 306 | + $post_id = ! empty( $_post ) ? $_post->ID : 0; | |
| 307 | 307 | |
| 308 | 308 | // Add 'do_not_allow' cap if user is spam or deleted |
| 309 | 309 | if ( bbp_is_user_inactive( $user_id ) ) { |
| 310 | 310 | $caps = array( 'do_not_allow' ); |
| @@ -372,10 +372,10 @@ | ||
| 372 | 372 | |
| 373 | 373 | case 'edit_topic_tag' : |
| 374 | 374 | |
| 375 | 375 | // Get the term |
| 376 | - $_tag = get_term( $args[0], bbp_get_topic_tag_tax_id() ); | |
| 377 | - if ( ! empty( $_tag ) ) { | |
| 376 | + $_tag = ! empty( $args[0] ) ? get_term( $args[0], bbp_get_topic_tag_tax_id() ) : false; | |
| 377 | + if ( $_tag instanceof WP_Term ) { | |
| 378 | 378 | |
| 379 | 379 | // Add 'do_not_allow' cap if user is spam or deleted |
| 380 | 380 | if ( bbp_is_user_inactive( $user_id ) ) { |
| 381 | 381 | $caps = array( 'do_not_allow' ); |
| @@ -380,9 +380,9 @@ | ||
| 380 | 380 | if ( bbp_is_user_inactive( $user_id ) ) { |
| 381 | 381 | $caps = array( 'do_not_allow' ); |
| 382 | 382 | |
| 383 | 383 | // Moderators can always edit topic tags |
| 384 | - } elseif ( user_can( $user_id, 'moderate', $_tag->term_id ) ) { | |
| 384 | + } elseif ( user_can( $user_id, 'moderate' ) ) { | |
| 385 | 385 | $caps = array( 'spectate' ); |
| 386 | 386 | |
| 387 | 387 | // Fallback to edit_terms. |
| 388 | 388 | } else { |
| @@ -388,8 +388,10 @@ | ||
| 388 | 388 | } else { |
| 389 | 389 | $taxonomy = get_taxonomy( bbp_get_topic_tag_tax_id() ); |
| 390 | 390 | $caps = array( $taxonomy->cap->edit_terms ); |
| 391 | 391 | } |
| 392 | + } else { | |
| 393 | + $caps = array( 'do_not_allow' ); | |
| 392 | 394 | } |
| 393 | 395 | |
| 394 | 396 | break; |
| 395 | 397 | |
| @@ -406,10 +408,10 @@ | ||
| 406 | 408 | |
| 407 | 409 | case 'delete_topic_tag' : |
| 408 | 410 | |
| 409 | 411 | // Get the term |
| 410 | - $_tag = get_term( $args[0], bbp_get_topic_tag_tax_id() ); | |
| 411 | - if ( ! empty( $_tag ) ) { | |
| 412 | + $_tag = ! empty( $args[0] ) ? get_term( $args[0], bbp_get_topic_tag_tax_id() ) : false; | |
| 413 | + if ( $_tag instanceof WP_Term ) { | |
| 412 | 414 | |
| 413 | 415 | // Add 'do_not_allow' cap if user is spam or deleted |
| 414 | 416 | if ( bbp_is_user_inactive( $user_id ) ) { |
| 415 | 417 | $caps = array( 'do_not_allow' ); |
| @@ -414,16 +416,18 @@ | ||
| 414 | 416 | if ( bbp_is_user_inactive( $user_id ) ) { |
| 415 | 417 | $caps = array( 'do_not_allow' ); |
| 416 | 418 | |
| 417 | 419 | // Moderators can always delete topic tags |
| 418 | - } elseif ( user_can( $user_id, 'moderate', $_tag->term_id ) ) { | |
| 420 | + } elseif ( user_can( $user_id, 'moderate' ) ) { | |
| 419 | 421 | $caps = array( 'spectate' ); |
| 420 | 422 | |
| 421 | 423 | // Fallback to delete_terms. |
| 422 | 424 | } else { |
| 423 | - $taxonomy = get_taxonomy( $_tag->post_type ); | |
| 425 | + $taxonomy = get_taxonomy( bbp_get_topic_tag_tax_id() ); | |
| 424 | 426 | $caps = array( $taxonomy->cap->delete_terms ); |
| 425 | 427 | } |
| 428 | + } else { | |
| 429 | + $caps = array( 'do_not_allow' ); | |
| 426 | 430 | } |
| 427 | 431 | |
| 428 | 432 | break; |
| 429 | 433 | |