bp_blogs_format_activity_action_new_blog_comment

Format 'new_blog_comment' activity actions.

Description

(string) bp_blogs_format_activity_action_new_blog_comment( (string) $action, (object) $activity ); 

Returns (string)

Constructed activity action.

Parameters (2)

0. $action (string)
Static activity action.
1. $activity (object)
Activity data object.

Usage

  1. if ( !function_exists( 'bp_blogs_format_activity_action_new_blog_comment' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-blogs/bp-blogs-activity.php'; 
  3.  
  4. // Static activity action. 
  5. $action = ''; 
  6.  
  7. // Activity data object. 
  8. $activity = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bp_blogs_format_activity_action_new_blog_comment($action, $activity); 
  12.  

Defined (1)

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

/bp-blogs/bp-blogs-activity.php  
  1. function bp_blogs_format_activity_action_new_blog_comment( $action, $activity ) { 
  2. /** 
  3. * When the comment is published we are faking an activity object 
  4. * to which we add 4 properties : 
  5. * - the post url 
  6. * - the post title 
  7. * - the blog url 
  8. * - the blog name 
  9. * This is done to build the 'post link' part of the activity 
  10. * action string. 
  11. * NB: in this case the activity has not yet been created. 
  12. */ 
  13.  
  14. $blog_url = false; 
  15.  
  16. // Try to get the blog url from the activity object 
  17. if ( isset( $activity->blog_url ) ) { 
  18. $blog_url = $activity->blog_url; 
  19. } else { 
  20. $blog_url = bp_blogs_get_blogmeta( $activity->item_id, 'url' ); 
  21.  
  22. $blog_name = false; 
  23.  
  24. // Try to get the blog name from the activity object 
  25. if ( isset( $activity->blog_name ) ) { 
  26. $blog_name = $activity->blog_name; 
  27. } else { 
  28. $blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' ); 
  29.  
  30. if ( empty( $blog_url ) || empty( $blog_name ) ) { 
  31. $blog_url = get_home_url( $activity->item_id ); 
  32. $blog_name = get_blog_option( $activity->item_id, 'blogname' ); 
  33.  
  34. bp_blogs_update_blogmeta( $activity->item_id, 'url', $blog_url ); 
  35. bp_blogs_update_blogmeta( $activity->item_id, 'name', $blog_name ); 
  36.  
  37. $post_url = false; 
  38.  
  39. // Try to get the post url from the activity object 
  40. if ( isset( $activity->post_url ) ) { 
  41. $post_url = $activity->post_url; 
  42.  
  43. /** 
  44. * The post_url property is not set, we need to build the url 
  45. * thanks to the post id which is also saved as the secondary 
  46. * item id property of the activity object. 
  47. */ 
  48. } elseif ( ! empty( $activity->id ) ) { 
  49. $post_url = bp_activity_get_meta( $activity->id, 'post_url' ); 
  50.  
  51. $post_title = false; 
  52.  
  53. // Should be the case when the comment has just been published 
  54. if ( isset( $activity->post_title ) ) { 
  55. $post_title = $activity->post_title; 
  56.  
  57. // If activity already exists try to get the post title from activity meta 
  58. } elseif ( ! empty( $activity->id ) ) { 
  59. $post_title = bp_activity_get_meta( $activity->id, 'post_title' ); 
  60.  
  61. // Should only be empty at the time of post creation. 
  62. if ( empty( $post_url ) || empty( $post_title ) ) { 
  63. switch_to_blog( $activity->item_id ); 
  64.  
  65. $comment = get_comment( $activity->secondary_item_id ); 
  66.  
  67. if ( ! empty( $comment->comment_post_ID ) ) { 
  68. $post_url = add_query_arg( 'p', $comment->comment_post_ID, trailingslashit( $blog_url ) ); 
  69. bp_activity_update_meta( $activity->id, 'post_url', $post_url ); 
  70.  
  71. $post = get_post( $comment->comment_post_ID ); 
  72.  
  73. if ( is_a( $post, 'WP_Post' ) ) { 
  74. $post_title = $post->post_title; 
  75. bp_activity_update_meta( $activity->id, 'post_title', $post_title ); 
  76.  
  77.  
  78. $post_link = '<a href="' . esc_url( $post_url ) . '">' . $post_title . '</a>'; 
  79. $user_link = bp_core_get_userlink( $activity->user_id ); 
  80.  
  81. if ( is_multisite() ) { 
  82. $action = sprintf( __( '%1$s commented on the post, %2$s, on the site %3$s', buddypress ), $user_link, $post_link, '<a href="' . esc_url( $blog_url ) . '">' . esc_html( $blog_name ) . '</a>' ); 
  83. } else { 
  84. $action = sprintf( __( '%1$s commented on the post, %2$s', buddypress ), $user_link, $post_link ); 
  85.  
  86. // Legacy filter - requires the comment object. 
  87. if ( has_filter( 'bp_blogs_activity_new_comment_action' ) ) { 
  88. switch_to_blog( $activity->item_id ); 
  89. $comment = get_comment( $activity->secondary_item_id ); 
  90.  
  91. if ( ! empty( $comment ) && ! is_wp_error( $comment ) ) { 
  92. $action = apply_filters( 'bp_blogs_activity_new_comment_action', $action, $comment, $post_url . '#' . $activity->secondary_item_id ); 
  93.  
  94. /** 
  95. * Filters the new blog comment action for the new blog. 
  96. * @since 2.0.0 
  97. * @param string $action Constructed activity action. 
  98. * @param object $activity Activity data object. 
  99. */