Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bbPress pagination #44

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' );