Skip to:
Content

bbPress.org


Ignore:
Timestamp:
07/24/2025 12:27:11 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 trunk, for 2.7.

Fixes #3644.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/forums/functions.php

    r7321 r7341  
    24632463    $forum_id = 0;
    24642464    $wp_query = bbp_get_wp_query();
     2465    $post_id  = ! empty( $wp_query->post->ID )
     2466        ? $wp_query->post->ID
     2467        : 0;
    24652468
    24662469    // Check post type
     
    24692472        // Forum
    24702473        case bbp_get_forum_post_type() :
    2471             $forum_id = bbp_get_forum_id( $wp_query->post->ID );
     2474            $forum_id = bbp_get_forum_id( $post_id );
    24722475            break;
    24732476
    24742477        // Topic
    24752478        case bbp_get_topic_post_type() :
    2476             $forum_id = bbp_get_topic_forum_id( $wp_query->post->ID );
     2479            $forum_id = bbp_get_topic_forum_id( $post_id );
    24772480            break;
    24782481
    24792482        // Reply
    24802483        case bbp_get_reply_post_type() :
    2481             $forum_id = bbp_get_reply_forum_id( $wp_query->post->ID );
     2484            $forum_id = bbp_get_reply_forum_id( $post_id );
    24822485            break;
    24832486    }
     
    25052508    $forum_id = 0;
    25062509    $wp_query = bbp_get_wp_query();
     2510    $post_id  = ! empty( $wp_query->post->ID )
     2511        ? $wp_query->post->ID
     2512        : 0;
    25072513
    25082514    // Check post type
     
    25112517        // Forum
    25122518        case bbp_get_forum_post_type() :
    2513             $forum_id = bbp_get_forum_id( $wp_query->post->ID );
     2519            $forum_id = bbp_get_forum_id( $post_id );
    25142520            break;
    25152521
    25162522        // Topic
    25172523        case bbp_get_topic_post_type() :
    2518             $forum_id = bbp_get_topic_forum_id( $wp_query->post->ID );
     2524            $forum_id = bbp_get_topic_forum_id( $post_id );
    25192525            break;
    25202526
    25212527        // Reply
    25222528        case bbp_get_reply_post_type() :
    2523             $forum_id = bbp_get_reply_forum_id( $wp_query->post->ID );
     2529            $forum_id = bbp_get_reply_forum_id( $post_id );
    25242530            break;
    2525 
    25262531    }
    25272532
Note: See TracChangeset for help on using the changeset viewer.