Skip to:
Content

BuddyPress.org

Opened 7 years ago

Closed 7 years ago

#5687 closed defect (bug) (no action required)

Activity Load more button doesn't work for custom non-components scopes

Reported by: slaFFik Owned by:
Milestone: Priority: normal
Severity: major Version:
Component: Activity Keywords:
Cc: slava.abakumov@…

Description

In bp_legacy_theme_activity_template_loader() it is checked.
But in js and in POST params after clicking there is no scope:

action:activity_get_older_updates
cookie:bp-members-scope%3Dpersonal%26bp-members-filter%3Dactive%26bp-blogs-scope%3Drss%26bp-blogs-filter%3Dactive%26bp-activity-scope%3Dfavorites%26bp-activity-filter%3D-1%26bp-activity-oldestpage%3D1
page:2
exclude_just_posted:

So load more doesn't honour the tab selected on Activity Directory.

Favorites tab loading works because of page param and lines 514-519 in bp-activity-template.php (imo, haven't dived too far).

As a developer I would like to be able to "Load more" any custom tab/scope without creating an obsolete components etc to pass that 514-519 lines, as you give actions to add tabs easily.

Attachments (1)

5687.experimental.patch (732 bytes) - added by imath 7 years ago.

Download all attachments as: .zip

Change History (9)

#1 @imath
7 years ago

  • Keywords reporter-feedback added

Hi slaFFik,

Thanks for your feedback, i wonder how you manage to display activities for your scope in the Activity directory at first place..

But let's first start with your scope carrying trouble. Actually in the arguments you shared the scope is included in the cookie arg :
bp-activity-scope%3Dfavorites so to get it you'll need to parse the cookie like it is done at the top (line 476 to 480) of the function bp_legacy_theme_ajax_querystring() in /bp-template/bp-legacy/buddypress

Line 514-519 in bp-activity-template.php are there to set the scope for the user's profile tab as there's no ajax when clicking on LI elements of the subnav in this part.

But as i've said in intro, i'm a bit amazed by the fact you are displaying activities of your scope.. Because the filter template argument is only set for built in scopes :
see lines 578 to 635 of bp-activity-template.php so at the end whatever the scope you are using in your activity directory extra tab.. if it's not :

  • 'just-me',
  • 'friends'
  • 'groups'
  • 'favorites'
  • 'mentions'

then the scope won't be converted into the object argument of the filter template arg.

You can check this by var_dumping the $template_args var after line 671 of bp-activity-template.php

Here's a test i've made in a bp-custom.php file :

function slaffik_li() {
        // scope is js parsed to what is after "activity-" in the LI id. 
	?>
	<li id="activity-slaffik"><a href="#" title="testing">Slaffik</a></li>
	<?php
}
add_action( 'bp_activity_type_tabs', 'slaffik_li' );

I haven't gone further to edit the activity table to force some items to have a component field set to slaffik because even if the scope is carried into the bp_has_activities as i've said, it won't be converted into 'filter' => array( 'object' => 'slaffik' )

So i'd be very curious to see the code you are using :)

Last edited 7 years ago by imath (previous) (diff)

#2 @imath
7 years ago

The only way for my example to work (by editing some activities in the table to force them to have a 'slaffik' value into the component field) was to quickly build the 5687.experimental.patch.

It did load more the activities of the "slaffik" scope and heartbeat (#5688) did load the newest activities from that scope...

#3 @slaFFik
7 years ago

  • Cc slava.abakumov@… added
  • Keywords reporter-feedback removed

That patch if included in the core would be an awesome edition.

And now regarding the situation I have.
Using bp_activity_type_tabs action I add tabs (<li><a></a></li>). Javascript in BuddyPress works in that way, that if that <li> has and <id> attribute - its second part (after -) will be converted to scope, and the first one is treated as object. So in my case I add <li id="activity-whatever">... there. And js sends a POST on clicking the tab with the scope=whatever. After that I'm adding a filter to bp_ajax_querystring with a relatively low priority (in my case 99) and modify the bp_has_activities() arguments like I need. That's the whole magic :)

But as I found out, load more and heartbeat ignores that js (rather handy) behaviour.

BTW, I was able to fix load more issue in my plugin using this code:

$scope = isset($_POST['scope']) ? $_POST['scope'] : isset($_COOKIE['bp-activity-scope']) ? $_COOKIE['bp-activity-scope'] : '';
Last edited 7 years ago by slaFFik (previous) (diff)

#4 @slaFFik
7 years ago

As a good fix (as for me) there will be adding a bp-activity-scope cookie check before sending load-more and heartbeat requests with including of that cookie scope into the POST params.

#5 @imath
7 years ago

Thanks for your reply, ok i haven't completely understood your need at first. So you are using the custom scope to know when to override activity arguments. Thought you needed to actually pass an object argument to filter the activity stream to display activities having the component set to the scope..

Well actually the page argument and the scope is catched into bp_ajax_querystring, so you don't need to get the value of the cookie/post vars, it should already be in the scope attribute of the ajax_querystring.

This is what i've tested :

function slaffik_li() {
    // scope is js parsed to what is after "activity-" in the LI id. 
	?>
	<li id="activity-slaffik"><a href="#" title="testing">Slaffik</a></li>
	<?php
}
add_action( 'bp_activity_type_tabs', 'slaffik_li' );

function slaffik_qs( $qs, $object ) {
	if ( 'activity' != $object ) {
		return $qs;
	}

	$args = wp_parse_args( $qs, array() );

	// Dumping args
	var_dump( $args );

	return $qs;
}
add_filter( 'bp_ajax_querystring', 'slaffik_qs', 99, 2 );

And i get when on the slaffik scope :
array(1) { ["scope"]=> string(7) "slaffik" }

When hitting the load more button :
array(2) { ["scope"]=> string(7) "slaffik" ["page"]=> string(1) "2" }

So if you don't get it, there may be a plugin that is filtering the ajax querystring before 99 priority and that is resetting the scope before returning the query string..

I'll reply on #5688 but it's the same result scope is passed

#6 follow-up: @slaFFik
7 years ago

I'm getting scope on tab click, that's not a problem. But Load more and heartbeat don't send them at all, that's why I needed to check cookie.

#7 in reply to: ↑ 6 @imath
7 years ago

Replying to slaFFik:

I'm getting scope on tab click, that's not a problem. But Load more and heartbeat don't send them at all, that's why I needed to check cookie.

When hitting the load more button :
array(2) { ["scope"]=> string(7) "slaffik" ["page"]=> string(1) "2" }

I get the scope when using load more in my example ;)

#8 @slaFFik
7 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Yes, that weird plugin made a dirty hack :(

Thanks for investigation and sorry for the time you spent.
Really appreciate your openness.

Note: See TracTickets for help on using tickets.