bp_dtheme_activity_template_loader

Load the activity loop template when activity is requested via AJAX,.

Description

(string) bp_dtheme_activity_template_loader(); 

Returns (string)

JSON object containing 'contents' (output of the template loop for the Activity component) and 'feed_url' (URL to the relevant RSS feed).


Usage

  1. if ( !function_exists( 'bp_dtheme_activity_template_loader' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-themes/bp-default/_inc/ajax.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_dtheme_activity_template_loader(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/bp-themes/bp-default/_inc/ajax.php  
  1. function bp_dtheme_activity_template_loader() { 
  2. // Bail if not a POST action 
  3. if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) ) 
  4. return; 
  5.  
  6. $scope = ''; 
  7. if ( ! empty( $_POST['scope'] ) ) 
  8. $scope = $_POST['scope']; 
  9.  
  10. // We need to calculate and return the feed URL for each scope 
  11. switch ( $scope ) { 
  12. case 'friends': 
  13. $feed_url = bp_loggedin_user_domain() . bp_get_activity_slug() . '/friends/feed/'; 
  14. break; 
  15. case 'groups': 
  16. $feed_url = bp_loggedin_user_domain() . bp_get_activity_slug() . '/groups/feed/'; 
  17. break; 
  18. case 'favorites': 
  19. $feed_url = bp_loggedin_user_domain() . bp_get_activity_slug() . '/favorites/feed/'; 
  20. break; 
  21. case 'mentions': 
  22. $feed_url = bp_loggedin_user_domain() . bp_get_activity_slug() . '/mentions/feed/'; 
  23.  
  24. if ( isset( $_POST['_wpnonce_activity_filter'] ) && wp_verify_nonce( wp_unslash( $_POST['_wpnonce_activity_filter'] ), 'activity_filter' ) ) { 
  25. break; 
  26. default: 
  27. $feed_url = home_url( bp_get_activity_root_slug() . '/feed/' ); 
  28. break; 
  29.  
  30. // Buffer the loop in the template to a var for JS to spit out. 
  31. ob_start(); 
  32. locate_template( array( 'activity/activity-loop.php' ), true ); 
  33. $result['contents'] = ob_get_contents(); 
  34. $result['feed_url'] = apply_filters( 'bp_dtheme_activity_feed_url', $feed_url, $scope ); 
  35. ob_end_clean(); 
  36.  
  37. exit( json_encode( $result ) );