Changeset 7350
- Timestamp:
- 08/15/2025 05:18:54 PM (7 months ago)
- Location:
- trunk/src/includes
- Files:
-
- 6 edited
-
forums/capabilities.php (modified) (2 diffs)
-
forums/functions.php (modified) (4 diffs)
-
replies/capabilities.php (modified) (2 diffs)
-
replies/functions.php (modified) (9 diffs)
-
topics/capabilities.php (modified) (2 diffs)
-
topics/functions.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/forums/capabilities.php
r7346 r7350 62 62 63 63 // User cannot spectate 64 if ( ! user_can( $user_id, 'spectate' ) ) {64 if ( ! user_can( $user_id, 'spectate' ) && ! bbp_is_anonymous() ) { 65 65 $caps = array( 'do_not_allow' ); 66 66 … … 82 82 // Post is public 83 83 if ( bbp_get_public_status_id() === $_post->post_status ) { 84 $caps = array( 'spectate' ); 84 85 // Anonymous users do not have caps, but can 'exist' 86 if ( bbp_is_anonymous() ) { 87 $caps = array( 'exist' ); 88 89 // Registered users need the 'spectate' cap 90 } else { 91 $caps = array( 'spectate' ); 92 } 85 93 86 94 // User is author so allow read -
trunk/src/includes/forums/functions.php
r7348 r7350 187 187 /** Forum Parent **********************************************************/ 188 188 189 // Forum parent was passed (the norm)190 if ( ! empty( $_POST['bbp_forum_parent_id'] ) ) {189 // Forum parent is expected for theme-side submissions 190 if ( ! empty( $_POST['bbp_forum_parent_id'] ) && is_numeric( $_POST['bbp_forum_parent_id'] ) ) { 191 191 $forum_parent_id = bbp_get_forum_id( $_POST['bbp_forum_parent_id'] ); 192 192 } … … 195 195 $forum_parent_id = apply_filters( 'bbp_new_forum_pre_parent_id', $forum_parent_id ); 196 196 197 // No forum parent was passed (should never happen)197 // Forum parent was not passed (required for theme-side BuddyPress support) 198 198 if ( empty( $forum_parent_id ) ) { 199 199 bbp_add_error( 'bbp_new_forum_missing_parent', __( '<strong>Error</strong>: Your forum must have a parent.', 'bbpress' ) ); 200 200 201 // Forum exists201 // Forum parent exists 202 202 } elseif ( ! empty( $forum_parent_id ) ) { 203 203 204 // Forum is a category 205 if ( bbp_is_forum_category( $forum_parent_id ) ) { 206 bbp_add_error( 'bbp_new_forum_forum_category', __( '<strong>Error</strong>: This forum is a category. No forums can be created in this forum.', 'bbpress' ) ); 207 } 208 209 // Forum is closed and user cannot access 210 if ( bbp_is_forum_closed( $forum_parent_id ) && ! current_user_can( 'edit_forum', $forum_parent_id ) ) { 211 bbp_add_error( 'bbp_new_forum_forum_closed', __( '<strong>Error</strong>: This forum has been closed to new forums.', 'bbpress' ) ); 212 } 213 214 // Forum is private and user cannot access 215 if ( bbp_is_forum_private( $forum_parent_id ) && ! current_user_can( 'read_forum', $forum_parent_id ) ) { 216 bbp_add_error( 'bbp_new_forum_forum_private', __( '<strong>Error</strong>: This forum is private and you do not have the capability to read or create new forums in it.', 'bbpress' ) ); 217 } 218 219 // Forum is hidden and user cannot access 220 if ( bbp_is_forum_hidden( $forum_parent_id ) && ! current_user_can( 'read_forum', $forum_parent_id ) ) { 221 bbp_add_error( 'bbp_new_forum_forum_hidden', __( '<strong>Error</strong>: This forum is hidden and you do not have the capability to read or create new forums in it.', 'bbpress' ) ); 204 // Forum parent not editable by user 205 if ( ! current_user_can( 'edit_forum', $forum_parent_id ) ) { 206 207 // Forum parent is closed 208 if ( bbp_is_forum_closed( $forum_parent_id ) ) { 209 bbp_add_error( 'bbp_new_forum_forum_closed', __( '<strong>Error</strong>: This forum is closed to new forums.', 'bbpress' ) ); 210 } 211 } 212 213 // Forum parent not readable by user 214 if ( ! current_user_can( 'read_forum', $forum_parent_id ) ) { 215 bbp_add_error( 'bbp_new_forum_forum_read', __( '<strong>Error</strong>: You do not have the capability to create new forums in this forum.', 'bbpress' ) ); 222 216 } 223 217 } … … 429 423 430 424 // Forum parent id was passed 431 if ( ! empty( $_POST['bbp_forum_parent_id'] ) ) {425 if ( ! empty( $_POST['bbp_forum_parent_id'] ) && is_numeric( $_POST['bbp_forum_parent_id'] ) ) { 432 426 $forum_parent_id = bbp_get_forum_id( $_POST['bbp_forum_parent_id'] ); 433 427 } … … 436 430 $current_parent_forum_id = bbp_get_forum_parent_id( $forum_id ); 437 431 438 // Forum exists432 // Forum parent exists 439 433 if ( ! empty( $forum_parent_id ) && ( $forum_parent_id !== $current_parent_forum_id ) ) { 440 434 441 // Forum is closed and user cannot access 442 if ( bbp_is_forum_closed( $forum_parent_id ) && ! current_user_can( 'edit_forum', $forum_parent_id ) ) { 443 bbp_add_error( 'bbp_edit_forum_forum_closed', __( '<strong>Error</strong>: This forum has been closed to new forums.', 'bbpress' ) ); 444 } 445 446 // Forum is private and user cannot access 447 if ( bbp_is_forum_private( $forum_parent_id ) && ! current_user_can( 'read_forum', $forum_parent_id ) ) { 448 bbp_add_error( 'bbp_edit_forum_forum_private', __( '<strong>Error</strong>: This forum is private and you do not have the capability to read or create new forums in it.', 'bbpress' ) ); 449 } 450 451 // Forum is hidden and user cannot access 452 if ( bbp_is_forum_hidden( $forum_parent_id ) && ! current_user_can( 'read_forum', $forum_parent_id ) ) { 453 bbp_add_error( 'bbp_edit_forum_forum_hidden', __( '<strong>Error</strong>: This forum is hidden and you do not have the capability to read or create new forums in it.', 'bbpress' ) ); 435 // Forum parent not editable by user 436 if ( ! current_user_can( 'edit_forum', $forum_parent_id ) ) { 437 438 // Forum is closed 439 if ( bbp_is_forum_closed( $forum_parent_id ) ) { 440 bbp_add_error( 'bbp_edit_forum_forum_closed', __( '<strong>Error</strong>: This forum is closed to new forums.', 'bbpress' ) ); 441 } 442 } 443 444 // Forum parent not readable by user 445 if ( ! current_user_can( 'read_forum', $forum_parent_id ) ) { 446 bbp_add_error( 'bbp_edit_forum_forum_read', __( '<strong>Error</strong>: You do not have the capability to create new forums in this forum.', 'bbpress' ) ); 454 447 } 455 448 } -
trunk/src/includes/replies/capabilities.php
r6975 r7350 52 52 53 53 // User cannot spectate 54 if ( ! user_can( $user_id, 'spectate' ) ) {54 if ( ! user_can( $user_id, 'spectate' ) && ! bbp_is_anonymous() ) { 55 55 $caps = array( 'do_not_allow' ); 56 56 … … 72 72 // Post is public 73 73 if ( bbp_get_public_status_id() === $_post->post_status ) { 74 $caps = array( 'spectate' ); 74 75 // Anonymous users do not have caps, but can 'exist' 76 if ( bbp_is_anonymous() ) { 77 $caps = array( 'exist' ); 78 79 // Registered users need the 'spectate' cap 80 } else { 81 $caps = array( 'spectate' ); 82 } 75 83 76 84 // User is author so allow read -
trunk/src/includes/replies/functions.php
r7326 r7350 180 180 $posted_topic_id = intval( $_POST['bbp_topic_id'] ); 181 181 182 // Topic id is 0 183 if ( 0 === $posted_topic_id ) { 184 bbp_add_error( 'bbp_reply_topic_id', __( '<strong>Error</strong>: Topic ID is missing.', 'bbpress' ) ); 185 182 186 // Topic id is a negative number 183 if ( 0 > $posted_topic_id ) {187 } elseif ( 0 > $posted_topic_id ) { 184 188 bbp_add_error( 'bbp_reply_topic_id', __( '<strong>Error</strong>: Topic ID cannot be a negative number.', 'bbpress' ) ); 185 189 … … 194 198 } 195 199 200 // User cannot read parent topic ID 201 if ( ! current_user_can( 'read_topic', $topic_id ) ) { 202 bbp_add_error( 'bbp_new_reply_topic_public', __( '<strong>Error</strong>: You do not have the capability to read or create new replies in this topic.', 'bbpress' ) ); 203 } 204 196 205 /** Forum ID **************************************************************/ 197 206 … … 217 226 $posted_forum_id = intval( $_POST['bbp_forum_id'] ); 218 227 219 // Forum id is empty228 // Forum id is 0 220 229 if ( 0 === $posted_forum_id ) { 221 bbp_add_error( 'bbp_ topic_forum_id', __( '<strong>Error</strong>: Forum ID is missing.', 'bbpress' ) );230 bbp_add_error( 'bbp_reply_forum_id', __( '<strong>Error</strong>: Forum ID is missing.', 'bbpress' ) ); 222 231 223 232 // Forum id is a negative number 224 233 } elseif ( 0 > $posted_forum_id ) { 225 bbp_add_error( 'bbp_ topic_forum_id', __( '<strong>Error</strong>: Forum ID cannot be a negative number.', 'bbpress' ) );234 bbp_add_error( 'bbp_reply_forum_id', __( '<strong>Error</strong>: Forum ID cannot be a negative number.', 'bbpress' ) ); 226 235 227 236 // Forum does not exist 228 237 } elseif ( ! bbp_get_forum( $posted_forum_id ) ) { 229 bbp_add_error( 'bbp_ topic_forum_id', __( '<strong>Error</strong>: Forum does not exist.', 'bbpress' ) );238 bbp_add_error( 'bbp_reply_forum_id', __( '<strong>Error</strong>: Forum does not exist.', 'bbpress' ) ); 230 239 231 240 // Use the POST'ed forum id … … 246 255 } else { 247 256 248 // Forum is closed and user cannot access 249 if ( bbp_is_forum_closed( $forum_id ) && ! current_user_can( 'edit_forum', $forum_id ) ) { 250 bbp_add_error( 'bbp_new_reply_forum_closed', __( '<strong>Error</strong>: This forum has been closed to new replies.', 'bbpress' ) ); 257 // Forum not editable by user 258 if ( ! current_user_can( 'edit_forum', $forum_id ) ) { 259 260 // Forum is closed 261 if ( bbp_is_forum_closed( $forum_id ) ) { 262 bbp_add_error( 'bbp_new_reply_forum_closed', __( '<strong>Error</strong>: This forum is closed to new replies.', 'bbpress' ) ); 263 } 251 264 } 252 265 253 // Forum is private and user cannot access 254 if ( bbp_is_forum_private( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) { 255 bbp_add_error( 'bbp_new_reply_forum_private', __( '<strong>Error</strong>: This forum is private and you do not have the capability to read or create new replies in it.', 'bbpress' ) ); 256 257 // Forum is hidden and user cannot access 258 } elseif ( bbp_is_forum_hidden( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) { 259 bbp_add_error( 'bbp_new_reply_forum_hidden', __( '<strong>Error</strong>: This forum is hidden and you do not have the capability to read or create new replies in it.', 'bbpress' ) ); 266 // Forum not readable by user 267 if ( ! current_user_can( 'read_forum', $forum_id ) ) { 268 bbp_add_error( 'bbp_new_reply_forum_read', __( '<strong>Error</strong>: You do not have the capability to read or create new replies in this forum.', 'bbpress' ) ); 260 269 } 261 270 } … … 269 278 remove_filter( 'bbp_new_reply_pre_content', 'bbp_encode_bad', 10 ); 270 279 remove_filter( 'bbp_new_reply_pre_content', 'bbp_filter_kses', 30 ); 280 } 281 282 /** Reply To **************************************************************/ 283 284 // Handle Reply To of the reply; $_REQUEST for non-JS submissions 285 if ( isset( $_REQUEST['bbp_reply_to'] ) && is_numeric( $_REQUEST['bbp_reply_to'] ) ) { 286 $reply_to = bbp_validate_reply_to( $_REQUEST['bbp_reply_to'] ); 287 } 288 289 // Check the Reply To ID 290 if ( ! empty( $reply_to ) ) { 291 292 // User cannot read parent reply ID 293 if ( ! current_user_can( 'read_reply', $reply_to ) ) { 294 bbp_add_error( 'bbp_new_reply_reply_to', __( '<strong>Error</strong>: You do not have the capability to read or create new replies to this reply.', 'bbpress' ) ); 295 } 271 296 } 272 297 … … 333 358 if ( bbp_is_topic_pending( $topic_id ) || ! bbp_check_for_moderation( $anonymous_data, $reply_author, $reply_title, $reply_content ) ) { 334 359 $reply_status = bbp_get_pending_status_id(); 335 }336 337 /** Reply To **************************************************************/338 339 // Handle Reply To of the reply; $_REQUEST for non-JS submissions340 if ( isset( $_REQUEST['bbp_reply_to'] ) ) {341 $reply_to = bbp_validate_reply_to( $_REQUEST['bbp_reply_to'] );342 360 } 343 361 … … 575 593 $topic_id = bbp_get_reply_topic_id( $reply_id ); 576 594 595 // User cannot read parent topic ID 596 if ( ! current_user_can( 'read_topic', $topic_id ) ) { 597 bbp_add_error( 'bbp_edit_reply_topic_read', __( '<strong>Error</strong>: You do not have the capability to read or create new replies in this topic.', 'bbpress' ) ); 598 } 599 577 600 /** Topic Forum ***********************************************************/ 578 601 … … 589 612 } else { 590 613 591 // Forum is closed and user cannot access 592 if ( bbp_is_forum_closed( $forum_id ) && ! current_user_can( 'edit_forum', $forum_id ) ) { 593 bbp_add_error( 'bbp_edit_reply_forum_closed', __( '<strong>Error</strong>: This forum has been closed to new replies.', 'bbpress' ) ); 614 // Forum not editable by user 615 if ( ! current_user_can( 'edit_forum', $forum_id ) ) { 616 617 // Forum is closed 618 if ( bbp_is_forum_closed( $forum_id ) ) { 619 bbp_add_error( 'bbp_edit_reply_forum_closed', __( '<strong>Error</strong>: This forum is closed to new replies.', 'bbpress' ) ); 620 } 594 621 } 595 622 596 // Forum is private and user cannot access 597 if ( bbp_is_forum_private( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) { 598 bbp_add_error( 'bbp_edit_reply_forum_private', __( '<strong>Error</strong>: This forum is private and you do not have the capability to read or create new replies in it.', 'bbpress' ) ); 599 600 // Forum is hidden and user cannot access 601 } elseif ( bbp_is_forum_hidden( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) { 602 bbp_add_error( 'bbp_edit_reply_forum_hidden', __( '<strong>Error</strong>: This forum is hidden and you do not have the capability to read or create new replies in it.', 'bbpress' ) ); 623 // Forum not readable by user 624 if ( ! current_user_can( 'read_forum', $forum_id ) ) { 625 bbp_add_error( 'bbp_edit_reply_forum_read', __( '<strong>Error</strong>: You do not have the capability to read or create new replies in this forum.', 'bbpress' ) ); 603 626 } 627 } 628 } 629 630 /** Reply To **************************************************************/ 631 632 $reply_to = bbp_get_reply_to( $reply_id ); 633 634 // Maybe sanitize Reply To, using $_REQUEST for non-JS submissions 635 if ( isset( $_REQUEST['bbp_reply_to'] ) && is_numeric( $_REQUEST['bbp_reply_to'] ) ) { 636 $reply_to = intval( $_REQUEST['bbp_reply_to'] ); 637 } 638 639 // Validate Reply To 640 $reply_to = bbp_validate_reply_to( $reply_to, $reply_id ); 641 642 // Check the Reply To ID 643 if ( ! empty( $reply_to ) ) { 644 645 // User cannot read parent reply ID 646 if ( ! current_user_can( 'read_reply', $reply_to ) ) { 647 bbp_add_error( 'bbp_edit_reply_reply_to', __( '<strong>Error</strong>: You do not have the capability to read or create new replies to this reply.', 'bbpress' ) ); 604 648 } 605 649 } … … 662 706 bbp_add_error( 'bbp_edit_reply_status', __( '<strong>Error</strong>: You do not have permission to do that.', 'bbpress' ) ); 663 707 } 664 }665 666 /** Reply To **************************************************************/667 668 // Handle Reply To of the reply; $_REQUEST for non-JS submissions669 if ( isset( $_REQUEST['bbp_reply_to'] ) && current_user_can( 'moderate', $reply_id ) ) {670 $reply_to = bbp_validate_reply_to( $_REQUEST['bbp_reply_to'], $reply_id );671 } elseif ( bbp_thread_replies() ) {672 $reply_to = bbp_get_reply_to( $reply_id );673 708 } 674 709 -
trunk/src/includes/topics/capabilities.php
r6975 r7350 72 72 73 73 // User cannot spectate 74 if ( ! user_can( $user_id, 'spectate' ) ) {74 if ( ! user_can( $user_id, 'spectate' ) && ! bbp_is_anonymous() ) { 75 75 $caps = array( 'do_not_allow' ); 76 76 … … 92 92 // Post is public 93 93 if ( bbp_get_public_status_id() === $_post->post_status ) { 94 $caps = array( 'spectate' ); 94 95 // Anonymous users do not have caps, but can 'exist' 96 if ( bbp_is_anonymous() ) { 97 $caps = array( 'exist' ); 98 99 // Registered users need the 'spectate' cap 100 } else { 101 $caps = array( 'spectate' ); 102 } 95 103 96 104 // User is author so allow read -
trunk/src/includes/topics/functions.php
r7318 r7350 197 197 $posted_forum_id = intval( $_POST['bbp_forum_id'] ); 198 198 199 // Forum id is empty199 // Forum id is 0 200 200 if ( 0 === $posted_forum_id ) { 201 201 bbp_add_error( 'bbp_topic_forum_id', __( '<strong>Error</strong>: Forum ID is missing.', 'bbpress' ) ); … … 226 226 } else { 227 227 228 // Forum is closed and user cannot access 229 if ( bbp_is_forum_closed( $forum_id ) && ! current_user_can( 'edit_forum', $forum_id ) ) { 230 bbp_add_error( 'bbp_new_topic_forum_closed', __( '<strong>Error</strong>: This forum has been closed to new topics.', 'bbpress' ) ); 228 // Forum not editable by user 229 if ( ! current_user_can( 'edit_forum', $forum_id ) ) { 230 231 // Forum is closed 232 if ( bbp_is_forum_closed( $forum_id ) ) { 233 bbp_add_error( 'bbp_new_topic_forum_closed', __( '<strong>Error</strong>: This forum is closed to new topics.', 'bbpress' ) ); 234 } 231 235 } 232 236 233 // Forum is private and user cannot access 234 if ( bbp_is_forum_private( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) { 235 bbp_add_error( 'bbp_new_topic_forum_private', __( '<strong>Error</strong>: This forum is private and you do not have the capability to read or create new topics in it.', 'bbpress' ) ); 236 237 // Forum is hidden and user cannot access 238 } elseif ( bbp_is_forum_hidden( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) { 239 bbp_add_error( 'bbp_new_topic_forum_hidden', __( '<strong>Error</strong>: This forum is hidden and you do not have the capability to read or create new topics in it.', 'bbpress' ) ); 237 // Forum not readable by user 238 if ( ! current_user_can( 'read_forum', $forum_id ) ) { 239 bbp_add_error( 'bbp_new_topic_forum_read', __( '<strong>Error</strong>: You do not have the capability to read or create new topics in this forum.', 'bbpress' ) ); 240 240 } 241 241 } … … 500 500 // Forum id was passed 501 501 } elseif ( is_numeric( $_POST['bbp_forum_id'] ) ) { 502 $forum_id = (int) $_POST['bbp_forum_id']; 502 503 // Get the forum id 504 $posted_forum_id = intval( $_POST['bbp_forum_id'] ); 505 506 // Forum id is 0 507 if ( 0 === $posted_forum_id ) { 508 bbp_add_error( 'bbp_topic_forum_id', __( '<strong>Error</strong>: Forum ID is missing.', 'bbpress' ) ); 509 510 // Forum id is a negative number 511 } elseif ( 0 > $posted_forum_id ) { 512 bbp_add_error( 'bbp_topic_forum_id', __( '<strong>Error</strong>: Forum ID cannot be a negative number.', 'bbpress' ) ); 513 514 // Forum does not exist 515 } elseif ( ! bbp_get_forum( $posted_forum_id ) ) { 516 bbp_add_error( 'bbp_topic_forum_id', __( '<strong>Error</strong>: Forum does not exist.', 'bbpress' ) ); 517 518 // Use the POST'ed forum id 519 } else { 520 $forum_id = $posted_forum_id; 521 } 503 522 } 504 523 … … 506 525 $current_forum_id = bbp_get_topic_forum_id( $topic_id ); 507 526 527 // Forum change 528 if ( $forum_id !== $current_forum_id ) { 529 530 // User cannot edit current forum 531 if ( ! current_user_can( 'edit_forum', $current_forum_id ) ) { 532 bbp_add_error( 'bbp_edit_topic_forum_move_old', __( '<strong>Error</strong>: You do not have the capability to move topics out of this forum.', 'bbpress' ) ); 533 534 // User cannot read new forum 535 } elseif ( ! current_user_can( 'read_forum', $forum_id ) ) { 536 bbp_add_error( 'bbp_edit_topic_forum_move_new', __( '<strong>Error</strong>: You do not have the capability to move topics into this forum.', 'bbpress' ) ); 537 } 538 } 539 508 540 // Forum exists 509 if ( ! empty( $forum_id ) && ( $forum_id !== $current_forum_id )) {541 if ( ! empty( $forum_id ) ) { 510 542 511 543 // Forum is a category … … 516 548 } else { 517 549 518 // Forum is closed and user cannot access 519 if ( bbp_is_forum_closed( $forum_id ) && ! current_user_can( 'edit_forum', $forum_id ) ) { 520 bbp_add_error( 'bbp_edit_topic_forum_closed', __( '<strong>Error</strong>: This forum has been closed to new topics.', 'bbpress' ) ); 550 // Forum not editable by user 551 if ( ! current_user_can( 'edit_forum', $forum_id ) ) { 552 553 // Forum is closed 554 if ( bbp_is_forum_closed( $forum_id ) ) { 555 bbp_add_error( 'bbp_edit_topic_forum_closed', __( '<strong>Error</strong>: This forum is closed to new topics.', 'bbpress' ) ); 556 } 521 557 } 522 558 523 // Forum is private and user cannot access 524 if ( bbp_is_forum_private( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) { 525 bbp_add_error( 'bbp_edit_topic_forum_private', __( '<strong>Error</strong>: This forum is private and you do not have the capability to read or create new topics in it.', 'bbpress' ) ); 526 527 // Forum is hidden and user cannot access 528 } elseif ( bbp_is_forum_hidden( $forum_id ) && ! current_user_can( 'read_forum', $forum_id ) ) { 529 bbp_add_error( 'bbp_edit_topic_forum_hidden', __( '<strong>Error</strong>: This forum is hidden and you do not have the capability to read or create new topics in it.', 'bbpress' ) ); 559 // Forum not readable by user 560 if ( ! current_user_can( 'read_forum', $forum_id ) ) { 561 bbp_add_error( 'bbp_edit_topic_forum_read', __( '<strong>Error</strong>: You do not have the capability to read or create new topics in this forum.', 'bbpress' ) ); 530 562 } 531 563 }
Note: See TracChangeset
for help on using the changeset viewer.