Skip to:
Content

bbPress.org

Opened 4 years ago

Last modified 5 months ago

#3355 new defect (bug)

Forum Pagination links are broken

Reported by: sirlouen's profile SirLouen Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: General Keywords: needs-patch
Cc:

Description

I posted this issue in buddypress trac some weeks ago:

I've found that forum pagination links are broken:
Check this user for example:
https://buddypress.org/members/modemlooper/forums/
In the bottom pagination links:
https://i.imgur.com/4D6qDpX.png

But they commented that it could be an issue on bbpress
https://buddypress.trac.wordpress.org/ticket/8237#comment:3

Change History (23)

#1 @SirLouen
4 years ago

  • Keywords needs-patch added

#2 @jgasba
7 months ago

Bumping this issue as I noticed the same thing and I'm retracing that breadcrumb. BuddyPress + bbpress combo produces broken pagination links on members profiles.

Anything new on this 4 years old issue?

#3 @jgasba
7 months ago

@johnjamesjacoby marked this issue as resolved

Version 0, edited 7 months ago by jgasba (next)

#4 @jgasba
7 months ago

From what I managed to gather not knowing the bbpress code until now, I think the bug comes from
bbp_get_replies_pagination_base() in /includes/replies/template.php (for replies, equivalent for topics being bbp_get_topics_pagination_base) https://bbpress.trac.wordpress.org/browser/trunk/src/includes/replies/template.php#L2308


// User's replies
if ( bbp_is_single_user_replies() )
    $base = bbp_get_user_replies_created_url( bbp_get_displayed_user_id() );
    // returns exampledomain/membres/username/forums/responses/
// Root profile page
} elseif ( bbp_is_single_user() ) {
    $base = bbp_get_user_profile_url( bbp_get_displayed_user_id() );
    // returns exampledomain/membres/username/
}

When using BuddyPress the function used in an other user profile is bbp_is_single_user for the pagination links so the pagination link url does not include /forum/responses/

The solution might be in one of those functions. I guess.

#5 @Robin W
7 months ago

I'm not quite clear what you are saying - only because I don't have need of buddypress, so don't know what it us looking for :-)

from the 2 functions above, which function needs to return what different answer?

#6 @jgasba
7 months ago

On a WordPress install using BuddyPress+bbPress if you navigate to a user profile page and look at his forum history, the pagination links are :

exampledomain/membres/username/page/2/

when they should be, for replies tab as an example:

exampledomain/membres/username/forums/replies/page/2/

For a reason I'm not too sure to understand, when both plugins are enabled bbPress does not recognize the replies tab of a user profile as bbp_is_single_user_replies == true. This returns false and then the query does not return the proper output.

11 years ago it was resolved apparently on bbPress end but the template.php code has changed since and the issue is back again. See this issue from back then https://bbpress.trac.wordpress.org/ticket/2190

On the logged in user profile, on /forums/replies bbp_is_single_user() and bbp_is_single_user_replies return true but on another user profile bbp_is_single_user() returns true when bbp_is_single_user_replies returns false.

I can't figure out why. I have notified buddypress too as the bug is affecting even their own website. I think it possibly affects a lot of website using both plugins together.

#7 @Robin W
7 months ago

thanks for prompt further info - I'm not a bbpress author, but try to help out. I'll take a further look at this shortly :-)

#8 @Robin W
6 months ago

@jgasba - ok, I've just looked at this and I am not seeing the issue, mine resolves as

exampledomain/members-2/admin/forums/replies/page/2/

as it should.

this is on a twentyten theme, with 6.4.2 and php 8.2 buddypress 11.4.0 and bbpress 2.6.9

Initial thoughts are :

  1. language different?
  2. Have you tried it with a default theme and just bbpress and buddypress to eliminate theme other plugins?
  3. have I done something wrong?

#9 @julianoe
6 months ago

@robin-w your answer triggered me because I thought I tested this thoroughly.

SO, I just did a new test, wiped completely and started from scratch on fresh DB and new install.
I'm on twentytwentyone theme, 6.4.2, php 8.2 buddypress 11.4.0 and bbpress 2.6.9.
I created some dummy forums, topics and 18 answers so that it switches to proposing me several pages on /membres/default/forums/replies/

At first, it worked well (good!). With the default config.
Then I adjusted the config to mimic how I used BuddyPress on the other big project I had to patch this issue:

  • in /wp-admin/admin.php?page=bp-components I unticked everything but the Private Messages
  • in /wp-admin/admin.php?page=bp-settings I unticked everything and used Heritage. Note that the issue is also present with Nouveau.

I'm on a French version of WordPress but do you think it could change anything? I tried switching languages and refreshing the permalinks settings between steps but it did not solve.

Important: It works well when I'm on my own profile and connected, but when viewing the page from a disconnected account, I confirm there is the bug.

#10 @Robin W
6 months ago

when you say disconnected account -

  1. do you mean a user who has been deleted? or what does disconnected mean?
  2. is this the only time you see it?

#11 @Robin W
6 months ago

Ignore that - I've finally woke up to the issue :-)

and yes I can replicate.

#12 @Robin W
6 months ago

I've kicked this around a bit, and this code gets you round the problem

add_filter ('bbp_is_single_user_replies' , 'bbpr_check_buddypress_user') ;
add_filter ('bbp_is_single_user_topics' , 'bbpr_check_buddypress_user') ;

function bbpr_check_buddypress_user ($retval= false) {
        if (function_exists ('buddypress')) {
        //check if we are on a buddpress single user page (and logged out), as this produces a pagination error in buddypress
        //see https://bbpress.trac.wordpress.org/ticket/3355
        if (!is_user_logged_in() && bp_is_user())$retval = true ;
        }       
return $retval ;
}


<?php

for others coming accross this who might not be as code savvy...

Put this in your child theme's function file -

ie wp-content/themes/%your-theme-name%/functions.php

where %your-theme-name% is the name of your theme
or use https://wordpress.org/plugins/code-snippets/

Last edited 6 months ago by Robin W (previous) (diff)

#13 @Robin W
6 months ago

I've also added it to automatically run in my bbp-style-pack plugin

https://wordpress.org/plugins/bbp-style-pack/

#14 @hardel
6 months ago

Robin, this issue also effects engagements and favorites. I'd also assume subscriptions as well, but have not tested this.

#15 @julianoe
6 months ago

Just to be as complete as possible about this and for future reference, here is how I personnaly patched it in my project:
I thought I had shared it here but can't find where I have done that

<?php
/**
 * Fix the pagination links on Buddypress forum Replies pages
 */
add_filter('bbp_get_replies_pagination_base', 'fix_replies_pagination_links', 10, 2);
function fix_replies_pagination_links( $base, $topic_id ) {
    if ( bp_is_user() ) {
        $base = bbp_get_user_replies_created_url( bbp_get_displayed_user_id() );
        $base = trailingslashit( $base ) . user_trailingslashit( bbp_get_paged_slug() . '/%#%/' );    
    }
  
    return $base;
}

/**
 * Fix the pagination links on Buddypress forum Topics pages
 */
add_filter('bbp_get_topics_pagination_base', 'fix_topics_pagination_links', 10, 2);
function fix_topics_pagination_links( $base, $topic_id ) {
    if ( bp_is_user() ) {
        $base = bbp_get_user_topics_created_url( bbp_get_displayed_user_id() );
        $base = trailingslashit( $base ) . user_trailingslashit( bbp_get_paged_slug() . '/%#%/' );    
    }
  
    return $base;
}

(shit I commented with other account, nvm)

Last edited 6 months ago by julianoe (previous) (diff)

#16 follow-up: @imath
6 months ago

@robin-w If you are using BuddyPress 12.0.0 you can have it fixed this way:

https://gist.github.com/imath/24fdfa1b8625477e93c0daa0d90b2a44

#17 @Robin W
6 months ago

thanks for that info :-)

#18 in reply to: ↑ 16 @hardel
5 months ago

@imath - Where do we upload the php file that you created (bp-custom.php)? Is it suppose to be placed in one of the Buddypress folders? Or is the code suppose to be placed in the child theme's functions.php? TIA

#19 @lmstearn
5 months ago

@hardel Think it has to go in /wp-content/plugins folder. Tried it at this site, not working- would it work for you?

#20 @imath
5 months ago

Yes that’s where it needs to be. Please note this will only work with BuddyPress 12.0 & the BP Classic back compatibility Add-on (as bbPress is not ready yet for 12.0)

#21 @hardel
5 months ago

Does that mean we won't need this file when bbPress is updated to be compatible with Buddypress 12? As in, the bug will be fixed?

#22 @hardel
5 months ago

I uploaded it to that folder, but unfortunately it does not work. I am running the latest buddypress and bbpress versions.

#23 @ahillmortons
5 months ago

Hi,

Can I clarify what needs adding where to resolve this please?

I'm using a multi-site, so have bp-custom.php in my wp-content folder, is this correct?

The content is like this:

<?php
// your php custom code goes below this line.

define( 'BP_ENABLE_MULTIBLOG', true );


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

/**
 * bbPress should include such an action into its `src/includes/extend/buddypress/members.php` file.
 */
function fix_bbpress_member_pagination( &$query ) {
        if ( bp_is_user() && bp_is_current_component( 'forums' ) ) {
                $action_variables = (array) bp_action_variables();

                if ( function_exists( 'bbp_get_paged_slug' ) && bbp_get_paged_slug() === bp_action_variable( 0 ) ) {
                        $query->set( 'paged', (int) bp_action_variable( 1 ) );
                }
        }

}
add_action( 'bp_members_parse_query', 'fix_bbpress_member_pagination' );

Does that look correct? Is there something else I need to add anywhere?

I've added the above but the pagination is still wrong and goes to a 404.

I'm using:
WordPress 6.4.2
bbPress 2.6.9
BuddyPress 12.1.1
BuddyPress Multi Network 1.0.3
bbp style pack 5.8.0
Profile Builder 3.10.7
Profile Builder Elite 3.9.9

I'm using an FSE theme with compatability turned on in bbp style pack.

Many Thanks,

Andy

Note: See TracTickets for help on using tickets.