Skip to:
Content
Pages
Categories
Search
Top
Bottom

Filtering Activity Feed


  • groston
    Participant

    @groston

    I would like to prevent certain types of activities from appearing in the global feed. I have found a number of articles that discuss this, but many are quite old (prior versions) and (to a novice), many seem to be incomplete.

    Based on my reading, it seems that the clean way to do this is to add some code to the file functions.php in themes/child-theme. Based on my reading, and just for testing purposes, I added the following code:

    function ec_filter_activity( $activity_object ) {
      $activity_object['action'] = array( 'activity_comment' , 'activity_update');
      $activity_object['per_page'] = 8;
      return $activity_object;
    }
    add_action( 'bp_after_has_activities_parse_args', 'ec_filter_activity');

    However, when I reloaded the page with the activity feed, the following appeared in debug.log:

    PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘ec_filter_activity’ not found or invalid function name in /var/www/html/wp-includes/class-wp-hook.php on line 286

    Can you please help me figure out what I am doing wrong. I suspect that if I can get past this error, I can make the filtering work…

    Thanks

Viewing 7 replies - 1 through 7 (of 7 total)

  • Varun Dubey
    Participant

    @vapvarun


    groston
    Participant

    @groston

    Varun – thanks for pointing out this plugin. Sadly, it fails to provide the single most wanted capability – only showing certain types of activities. Honestly, I do not understand the purpose of this plugin…


    groston
    Participant

    @groston

    please help!


    r-a-y
    Keymaster

    @r-a-y

    You should use add_filter() and not add_action().

    Apart from that the code looks correct to me… you might want to move your code out from your theme and into a plugin.


    groston
    Participant

    @groston

    r-a-y,

    This is blather to try to trick the ‘Duplicate reply detected’ nonsense.

    Thanks for the reply – seem like the right approach, but… Following is my code:

    function ec_filter_activity( $activity_object ) {
      $activity_object['action'] = array( 'item1', 'item2');
      return $activity_object;
    }
    add_filter( 'bp_after_has_activities_parse_args', 'ec_filter_activity');

    When I load the activity feed, I get this warning (in the debug.log file):

    PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'ec_filter_activity' not found or invalid function name in /var/www/html/wp-includes/class-wp-hook.php on line 286

    I do not understand why this error is appearing – can you offer some guidance?

    p.s. The site is the MVP for the company. If there is decent adoption, the next release will be a custom app, so moving the code into a plugin is not really needed.


    groston
    Participant

    @groston

    I stumbled across the solution to my own problem and am sharing in case others run into a similar problem.

    Noting that a) our WP/BP site has been customized and b) that I am not the author of the site: Our site has both of the following folders:
    …/wp-content/themes/social-portfolio
    …/wp-content/themes/social-portfolio-child

    and both folder have a functions.php file. My original posting, with the described problem, occurred when the quoted code was in functions.php in the social-portfolio-child folder. When I moved the code to the functions.php in the social-portfolio folder, it worked exactly as expected.


    Prashant Singh
    Participant

    @prashantvatsh

    You have placed the code in parent theme’s functions.php which is not correct, because in future you will have an update of the theme and when you will update these changes will be lost. So you should always paste any new code in child theme’s functions.php. In case it is not working there and you are not able to get it why? then install this https://wordpress.org/plugins/code-snippets/ plugin and try adding code under snippets and see if it is working fine. Also before placing code with this plugin just remove it from your functions.php otherwise if the same code will be there on both places then it will generate a fatal error.

    When I moved the code to the functions.php in the social-portfolio folder, it worked exactly as expected.

    Thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
Skip to toolbar