Skip to:
Content

bbPress.org

Changeset 3430


Ignore:
Timestamp:
08/20/2011 10:15:21 PM (15 years ago)
Author:
johnjamesjacoby
Message:

Remove hierarchical check against private/hidden forum types. Fixes issue where a user needed to be able to view private forums in order to view hidden forums. See #1576.

Location:
branches/plugin/bbp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-core-hooks.php

    r3427 r3430  
    124124add_action( 'pre_get_posts',     'bbp_pre_get_posts',                2 );
    125125add_action( 'pre_get_posts',     'bbp_pre_get_posts_exclude_forums', 4 );
    126 add_action( 'template_redirect', 'bbp_forum_visibility_check',      -1 );
     126
     127// Restrict forum access
     128add_action( 'template_redirect', 'bbp_forum_enforce_hidden',        -1 );
     129add_action( 'template_redirect', 'bbp_forum_enforce_private',       -1 );
    127130
    128131// Profile Edit
  • branches/plugin/bbp-includes/bbp-forum-functions.php

    r3349 r3430  
    945945
    946946/**
     947 * Check if it's a hidden forum or a topic or reply of a hidden forum and if
     948 * the user can't view it, then sets a 404
     949 *
     950 * @since bbPress (r2996)
     951 *
     952 * @uses current_user_can() To check if the current user can read private forums
     953 * @uses is_singular() To check if it's a singular page
     954 * @uses bbp_get_forum_post_type() To get the forum post type
     955 * @uses bbp_get_topic_post_type() To get the topic post type
     956 * @uses bbp_get_reply_post_type() TO get the reply post type
     957 * @uses bbp_get_topic_forum_id() To get the topic forum id
     958 * @uses bbp_get_reply_forum_id() To get the reply forum id
     959 * @uses bbp_is_forum_hidden() To check if the forum is hidden or not
     960 * @uses bbp_set_404() To set a 404 status
     961 */
     962function bbp_forum_enforce_hidden() {
     963
     964    // Bail if not viewing a single item or if user has caps
     965    if ( !is_singular() || is_super_admin() || current_user_can( 'read_hidden_forums' ) )
     966        return;
     967
     968    global $wp_query;
     969
     970    // Define local variable
     971    $forum_id = 0; 
     972
     973    // Check post type
     974    switch ( $wp_query->get( 'post_type' ) ) {
     975
     976        // Forum
     977        case bbp_get_forum_post_type() :
     978            $forum_id = bbp_get_forum_id( $wp_query->post->ID );
     979            break;
     980
     981        // Topic
     982        case bbp_get_topic_post_type() :
     983            $forum_id = bbp_get_topic_forum_id( $wp_query->post->ID );
     984            break;
     985
     986        // Reply
     987        case bbp_get_reply_post_type() :
     988            $forum_id = bbp_get_reply_forum_id( $wp_query->post->ID );
     989            break;
     990
     991    }
     992
     993    // If forum is explicitly hidden and user not capable, set 404
     994    if ( !empty( $forum_id ) && bbp_is_forum_hidden( $forum_id ) && !current_user_can( 'read_hidden_forums' ) )
     995        bbp_set_404();
     996}
     997
     998/**
    947999 * Check if it's a private forum or a topic or reply of a private forum and if
    9481000 * the user can't view it, then sets a 404
     
    9601012 * @uses bbp_set_404() To set a 404 status
    9611013 */
    962 function bbp_forum_visibility_check() {
     1014function bbp_forum_enforce_private() {
     1015
     1016    // Bail if not viewing a single item or if user has caps
     1017    if ( !is_singular() || is_super_admin() || current_user_can( 'read_private_forums' ) )
     1018        return;
     1019
    9631020    global $wp_query;
    9641021
    965     // Bail if not viewing a single item or if user has caps
    966     if ( !is_singular() || is_super_admin() || ( current_user_can( 'read_private_forums' ) && current_user_can( 'read_hidden_forums' ) ) )
    967         return;
    968 
     1022    // Define local variable
     1023    $forum_id = 0;
     1024   
    9691025    // Check post type
    9701026    switch ( $wp_query->get( 'post_type' ) ) {
     
    9881044
    9891045    // If forum is explicitly hidden and user not capable, set 404
    990     if ( !empty( $forum_id ) && bbp_is_forum_hidden( $forum_id ) && !current_user_can( 'read_hidden_forums' ) )
     1046    if ( !empty( $forum_id ) && bbp_is_forum_private( $forum_id ) && !current_user_can( 'read_hidden_forums' ) )
    9911047        bbp_set_404();
    9921048}
Note: See TracChangeset for help on using the changeset viewer.