From 7f5969a4661fcb1038f73b7438fa2358675fd937 Mon Sep 17 00:00:00 2001 From: imath Date: Tue, 13 Feb 2024 22:43:26 +0100 Subject: [PATCH] Fix bbPress pagination Use BP action variables to set the `WP_Query` `paged` query var expected by bbPress with the page number to display. --- inc/forums/functions.php | 36 ++++++++++++++++++++++++++++++++++++ inc/loader.php | 10 ++++++++++ 2 files changed, 46 insertions(+) create mode 100644 inc/forums/functions.php diff --git a/inc/forums/functions.php b/inc/forums/functions.php new file mode 100644 index 0000000..7105e70 --- /dev/null +++ b/inc/forums/functions.php @@ -0,0 +1,36 @@ +get( 'paged' ) ) { + return; + } + + if ( ( bp_is_user() && bp_is_current_component( 'forums' ) ) || ( bp_is_group() && bp_is_current_action( 'forum' ) ) ) { + $action_variables = (array) bp_action_variables(); + $is_paged = array_search( bbp_get_paged_slug(), $action_variables, true ); + + if ( false !== $is_paged ) { + $query->set( 'paged', (int) bp_action_variable( $is_paged + 1 ) ); + } + } +} +add_action( 'bp_members_parse_query', 'bp_classic_setup_forums_pagination' ); +add_action( 'bp_groups_parse_query', 'bp_classic_setup_forums_pagination' ); diff --git a/inc/loader.php b/inc/loader.php index d4c5a6a..d2d865d 100644 --- a/inc/loader.php +++ b/inc/loader.php @@ -91,3 +91,13 @@ function bp_classic_template_pack_includes() { } } add_action( 'bp_after_setup_theme', 'bp_classic_template_pack_includes', 1 ); + +/** + * Specific compatibility functions for bbPress. + * + * @since 1.4.0 + */ +function bp_classic_forums_includes() { + require trailingslashit( plugin_dir_path( __FILE__ ) ) . 'forums/functions.php'; +} +add_action( 'bbp_buddypress_loaded', 'bp_classic_forums_includes' );