Skip to content

Commit

Permalink
Fix bbPress pagination
Browse files Browse the repository at this point in the history
Use BP action variables to set the `WP_Query` `paged` query var expected by bbPress with the page number to display.
  • Loading branch information
imath committed Feb 13, 2024
1 parent 0f69166 commit 7f5969a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
36 changes: 36 additions & 0 deletions inc/forums/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* BP Classic Compatibility Functions for bbPress.
*
* @package bp-classic\inc\forums
* @since 1.4.0
*/

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* Adjusts the `WP_Query` paged var.
*
* @since 1.4.0
*
* @param WP_Query $query The WP Query pasded by reference.
*/
function bp_classic_setup_forums_pagination( &$query ) {
if ( $query->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' );
10 changes: 10 additions & 0 deletions inc/loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );

0 comments on commit 7f5969a

Please sign in to comment.