Making WordPress.org

Changeset 12347


Ignore:
Timestamp:
12/20/2022 02:36:14 AM (22 months ago)
Author:
dd32
Message:

Support Forums: Plugin/Theme/Review "forums": Make bbp_get_forum_id() work in the plugin/theme/review "forums".

These forums are not forums, but rather, are views of a forum. As a result of this, bbPress doesn't return a forum object even through it's seen as a single forum.

This caused the Block Editor to be enabled for these views due to a misconfiguration of the Blocks integration, where in the event it couldn't find a forum for the current page, defaulted to being enabled.

This code aims to remove similar faults in the future, by allowing bbp_get_forum_id() to return the true forum_id for these forums, while at the same time being a view.

This should not be removed without verifying that [12348] works as expected.

See #6608.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-directory-compat.php

    r11580 r12347  
    6363            // Tell WordPress not to 404 (before bbPress overrides it) so that Canonical can do it's job.
    6464            add_filter( 'pre_handle_404', array( $this, 'abort_wp_handle_404' ) );
     65
     66            // Let plugins know which forum we're in.
     67            add_filter( 'bbp_get_forum_id', array( $this, 'bbp_get_forum_id' ) );
     68
    6569        }
    6670    }
     
    727731    }
    728732
     733    /**
     734     * These compat routes are views, but showing a singular forum.
     735     * This makes other plugins understand that the compat view is a forum.
     736     *
     737     * @param int $forum_id The detected forum id.
     738     * @return int The actual forum id.
     739     */
     740    public function bbp_get_forum_id( $forum_id ) {
     741        if ( ! $forum_id && bbp_is_single_view() ) {
     742            if ( $this->compat() === bbp_get_view_id() ) {
     743                $forum_id = $this->forum_id();
     744            } elseif ( 'reviews' == bbp_get_view_id() ) {
     745                $forum_id = Plugin::REVIEWS_FORUM_ID;
     746            }
     747        }
     748
     749        return $forum_id;
     750    }
    729751
    730752    /**
Note: See TracChangeset for help on using the changeset viewer.