Skip to:
Content

bbPress.org


Ignore:
Timestamp:
07/24/2025 12:29:32 AM (4 months ago)
Author:
johnjamesjacoby
Message:

Forums: prevent PHP warnings on singular bbPress pages when post ID's are not set.

This change adds checks for empty $wp_query->post->ID before using it inside of bbp_forum_enforce_private() and bbp_forum_enforce_hidden().

In branches/2.6, for 2.6.15.

Fixes #3644.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.6/src/includes/forums/functions.php

    r7320 r7342  
    24702470    $forum_id = 0;
    24712471    $wp_query = bbp_get_wp_query();
     2472    $post_id  = ! empty( $wp_query->post->ID )
     2473        ? $wp_query->post->ID
     2474        : 0;
    24722475
    24732476    // Check post type
     
    24762479        // Forum
    24772480        case bbp_get_forum_post_type() :
    2478             $forum_id = bbp_get_forum_id( $wp_query->post->ID );
     2481            $forum_id = bbp_get_forum_id( $post_id );
    24792482            break;
    24802483
    24812484        // Topic
    24822485        case bbp_get_topic_post_type() :
    2483             $forum_id = bbp_get_topic_forum_id( $wp_query->post->ID );
     2486            $forum_id = bbp_get_topic_forum_id( $post_id );
    24842487            break;
    24852488
    24862489        // Reply
    24872490        case bbp_get_reply_post_type() :
    2488             $forum_id = bbp_get_reply_forum_id( $wp_query->post->ID );
     2491            $forum_id = bbp_get_reply_forum_id( $post_id );
    24892492            break;
    24902493    }
     
    25122515    $forum_id = 0;
    25132516    $wp_query = bbp_get_wp_query();
     2517    $post_id  = ! empty( $wp_query->post->ID )
     2518        ? $wp_query->post->ID
     2519        : 0;
    25142520
    25152521    // Check post type
     
    25182524        // Forum
    25192525        case bbp_get_forum_post_type() :
    2520             $forum_id = bbp_get_forum_id( $wp_query->post->ID );
     2526            $forum_id = bbp_get_forum_id( $post_id );
    25212527            break;
    25222528
    25232529        // Topic
    25242530        case bbp_get_topic_post_type() :
    2525             $forum_id = bbp_get_topic_forum_id( $wp_query->post->ID );
     2531            $forum_id = bbp_get_topic_forum_id( $post_id );
    25262532            break;
    25272533
    25282534        // Reply
    25292535        case bbp_get_reply_post_type() :
    2530             $forum_id = bbp_get_reply_forum_id( $wp_query->post->ID );
     2536            $forum_id = bbp_get_reply_forum_id( $post_id );
    25312537            break;
    2532 
    25332538    }
    25342539
Note: See TracChangeset for help on using the changeset viewer.