Skip to:
Content

bbPress.org

Ticket #3650: 3650.diff

File 3650.diff, 19.4 KB (added by johnjamesjacoby, 8 months ago)
  • src/includes/forums/capabilities.php

     
    8181
    8282                                        // Post is public
    8383                                        if ( bbp_get_public_status_id() === $_post->post_status ) {
    84                                                 $caps = array( 'spectate' );
    8584
     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                                                }
     93
    8694                                        // User is author so allow read
    8795                                        } elseif ( (int) $user_id === (int) $_post->post_author ) {
    8896                                                $caps = array( 'spectate' );
  • src/includes/forums/functions.php

     
    186186
    187187        /** Forum Parent **********************************************************/
    188188
    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'] ) ) {
    191191                $forum_parent_id = bbp_get_forum_id( $_POST['bbp_forum_parent_id'] );
    192192        }
    193193
    194194        // Filter and sanitize
    195195        $forum_parent_id = apply_filters( 'bbp_new_forum_pre_parent_id', $forum_parent_id );
    196196
    197         // No forum parent was passed (should never happen)
     197        // Forum parent was not passed (required for theme-side BuddyPress support)
    198198        if ( empty( $forum_parent_id ) ) {
    199199                bbp_add_error( 'bbp_new_forum_missing_parent', __( '<strong>Error</strong>: Your forum must have a parent.', 'bbpress' ) );
    200200
    201         // Forum exists
     201        // Forum parent exists
    202202        } elseif ( ! empty( $forum_parent_id ) ) {
    203203
    204                 // Forum is a category
     204                // Forum parent is a category
    205205                if ( bbp_is_forum_category( $forum_parent_id ) ) {
    206206                        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' ) );
    207207                }
    208208
    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                 }
     209                // Forum parent not editable by user
     210                if ( ! current_user_can( 'edit_forum', $forum_parent_id ) ) {
    213211
    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' ) );
     212                        // Forum parent is closed
     213                        if ( bbp_is_forum_closed( $forum_parent_id ) ) {
     214                                bbp_add_error( 'bbp_new_forum_forum_closed', __( '<strong>Error</strong>: This forum is closed to new forums.', 'bbpress' ) );
     215                        }
    217216                }
    218217
    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' ) );
     218                // Forum parent not readable by user
     219                if ( ! current_user_can( 'read_forum', $forum_parent_id ) ) {
     220                        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' ) );
    222221                }
    223222        }
    224223
     
    428427        /** Forum Parent ***********************************************************/
    429428
    430429        // Forum parent id was passed
    431         if ( ! empty( $_POST['bbp_forum_parent_id'] ) ) {
     430        if ( ! empty( $_POST['bbp_forum_parent_id'] ) && is_numeric( $_POST['bbp_forum_parent_id'] ) ) {
    432431                $forum_parent_id = bbp_get_forum_id( $_POST['bbp_forum_parent_id'] );
    433432        }
    434433
    435434        // Current forum this forum is in
    436435        $current_parent_forum_id = bbp_get_forum_parent_id( $forum_id );
    437436
    438         // Forum exists
     437        // Forum parent exists
    439438        if ( ! empty( $forum_parent_id ) && ( $forum_parent_id !== $current_parent_forum_id ) ) {
    440439
    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                 }
     440                // Forum parent not editable by user
     441                if ( ! current_user_can( 'edit_forum', $forum_parent_id ) ) {
    445442
    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' ) );
     443                        // Forum is closed
     444                        if ( bbp_is_forum_closed( $forum_parent_id ) ) {
     445                                bbp_add_error( 'bbp_edit_forum_forum_closed', __( '<strong>Error</strong>: This forum is closed to new forums.', 'bbpress' ) );
     446                        }
    449447                }
    450448
    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' ) );
     449                // Forum parent not readable by user
     450                if ( ! current_user_can( 'read_forum', $forum_parent_id ) ) {
     451                        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' ) );
    454452                }
    455453        }
    456454
  • src/includes/replies/functions.php

     
    179179                // Get the topic id
    180180                $posted_topic_id = intval( $_POST['bbp_topic_id'] );
    181181
     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
    182186                // Topic id is a negative number
    183                 if ( 0 > $posted_topic_id ) {
     187                } elseif ( 0 > $posted_topic_id ) {
    184188                        bbp_add_error( 'bbp_reply_topic_id', __( '<strong>Error</strong>: Topic ID cannot be a negative number.', 'bbpress' ) );
    185189
    186190                // Topic does not exist
     
    193197                }
    194198        }
    195199
     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
    196205        /** Forum ID **************************************************************/
    197206
    198207        // Try to use the forum id of the topic
     
    216225                        // Get the forum id
    217226                        $posted_forum_id = intval( $_POST['bbp_forum_id'] );
    218227
    219                         // Forum id is empty
     228                        // Forum id is 0
    220229                        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' ) );
    222231
    223232                        // Forum id is a negative number
    224233                        } 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' ) );
    226235
    227236                        // Forum does not exist
    228237                        } 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' ) );
    230239
    231240                        // Use the POST'ed forum id
    232241                        } else {
     
    245254                // Forum is not a category
    246255                } else {
    247256
    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                                }
    251264                        }
    252265
    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' ) );
    260269                        }
    261270                }
    262271        }
     
    270279                remove_filter( 'bbp_new_reply_pre_content', 'bbp_filter_kses', 30 );
    271280        }
    272281
     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                }
     296        }
     297
    273298        /** Reply Title ***********************************************************/
    274299
    275300        if ( ! empty( $_POST['bbp_reply_title'] ) ) {
     
    334359                $reply_status = bbp_get_pending_status_id();
    335360        }
    336361
    337         /** Reply To **************************************************************/
    338 
    339         // Handle Reply To of the reply; $_REQUEST for non-JS submissions
    340         if ( isset( $_REQUEST['bbp_reply_to'] ) ) {
    341                 $reply_to = bbp_validate_reply_to( $_REQUEST['bbp_reply_to'] );
    342         }
    343 
    344362        /** Topic Closed **********************************************************/
    345363
    346364        // If topic is closed, moderators can still reply
     
    574592
    575593        $topic_id = bbp_get_reply_topic_id( $reply_id );
    576594
     595        // User cannot read parent topic ID
     596        if ( ! current_user_can( 'read_topic', $topic_id ) ) {
     597                bbp_add_error( 'bbp_edit_reply_topic', __( '<strong>Error</strong>: You do not have the capability to read or create new replies in this topic.', 'bbpress' ) );
     598        }
     599
    577600        /** Topic Forum ***********************************************************/
    578601
    579602        $forum_id = bbp_get_topic_forum_id( $topic_id );
     
    588611                // Forum is not a category
    589612                } else {
    590613
    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                                }
    594621                        }
    595622
    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 topics in this forum.', 'bbpress' ) );
    603626                        }
    604627                }
    605628        }
    606629
     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' ) );
     648                }
     649        }
     650
    607651        /** Reply Title ***********************************************************/
    608652
    609653        if ( ! empty( $_POST['bbp_reply_title'] ) ) {
     
    663707                }
    664708        }
    665709
    666         /** Reply To **************************************************************/
    667 
    668         // Handle Reply To of the reply; $_REQUEST for non-JS submissions
    669         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         }
    674 
    675710        /** Topic Tags ************************************************************/
    676711
    677712        // Either replace terms
  • src/includes/topics/functions.php

     
    196196                        // Get the forum id
    197197                        $posted_forum_id = intval( $_POST['bbp_forum_id'] );
    198198
    199                         // Forum id is empty
     199                        // Forum id is 0
    200200                        if ( 0 === $posted_forum_id ) {
    201201                                bbp_add_error( 'bbp_topic_forum_id', __( '<strong>Error</strong>: Forum ID is missing.', 'bbpress' ) );
    202202
     
    225225                // Forum is not a category
    226226                } else {
    227227
    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                                }
    231235                        }
    232236
    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' ) );
    240240                        }
    241241                }
    242242        }
     
    499499
    500500        // Forum id was passed
    501501        } 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                }
    503522        }
    504523
    505524        // Current forum this topic is in
    506525        $current_forum_id = bbp_get_topic_forum_id( $topic_id );
    507526
     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
    508540        // Forum exists
    509         if ( ! empty( $forum_id ) && ( $forum_id !== $current_forum_id ) ) {
     541        if ( ! empty( $forum_id ) ) {
    510542
    511543                // Forum is a category
    512544                if ( bbp_is_forum_category( $forum_id ) ) {
     
    515547                // Forum is not a category
    516548                } else {
    517549
    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                                }
    521557                        }
    522558
    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' ) );
    530562                        }
    531563                }
    532564        }