/** * Add an activity comment * * @since 1.2.0 * * @param array $args See docs for $defaults for details * * @global object $bp BuddyPress global settings * @uses nxt_parse_args() * @uses bp_activity_add() * @uses apply_filters() To call the 'bp_activity_comment_action' hook * @uses apply_filters() To call the 'bp_activity_comment_content' hook * @uses bp_activity_new_comment_notification() * @uses nxt_cache_delete() * @uses do_action() To call the 'bp_activity_comment_posted' hook * * @return int $comment_id The comment id */ function bp_activity_new_comment($args = '') { global $bp; $defaults = array('id' => false, 'content' => false, 'user_id' => $bp->loggedin_user->id, 'activity_id' => false, 'parent_id' => false); $params = nxt_parse_args($args, $defaults); extract($params, EXTR_SKIP); if (empty($content) || empty($user_id) || empty($activity_id)) { return false; } if (empty($parent_id)) { $parent_id = $activity_id; } // Check to see if the parent activity is hidden, and if so, hide this comment publically. $activity = new BP_Activity_Activity($activity_id); $is_hidden = (int) $activity->hide_sitewide ? 1 : 0; // Insert the activity comment $comment_id = bp_activity_add(array('id' => $id, 'action' => apply_filters('bp_activity_comment_action', sprintf(__('%s posted a new activity comment', 'buddypress'), bp_core_get_userlink($user_id))), 'content' => apply_filters('bp_activity_comment_content', $content), 'component' => $bp->activity->id, 'type' => 'activity_comment', 'user_id' => $user_id, 'item_id' => $activity_id, 'secondary_item_id' => $parent_id, 'hide_sitewide' => $is_hidden)); // Send an email notification if settings allow bp_activity_new_comment_notification($comment_id, $user_id, $params); // Clear the comment cache for this activity nxt_cache_delete('bp_activity_comments_' . $parent_id); do_action('bp_activity_comment_posted', $comment_id, $params); return $comment_id; }
/** * Helper method to map action arguments to function parameters. * * @since 1.9.0 * * @param int $comment_id ID of the comment being notified about. * @param array $params Parameters to use with notification. */ function bp_activity_new_comment_notification_helper($comment_id, $params) { bp_activity_new_comment_notification($comment_id, $params['user_id'], $params); }
function bp_activity_new_comment( $args = '' ) { global $bp; $defaults = array( 'id' => false, 'content' => false, 'user_id' => $bp->loggedin_user->id, 'activity_id' => false, // ID of the root activity item 'parent_id' => false // ID of a parent comment (optional) ); $params = wp_parse_args( $args, $defaults ); extract( $params, EXTR_SKIP ); if ( empty($content) || empty($user_id) || empty($activity_id) ) return false; if ( empty($parent_id) ) $parent_id = $activity_id; /* Check to see if the parent activity is hidden, and if so, hide this comment publically. */ $activity = new BP_Activity_Activity( $activity_id ); $is_hidden = ( (int)$activity->hide_sitewide ) ? 1 : 0; /* Insert the activity comment */ $comment_id = bp_activity_add( array( 'id' => $id, 'action' => apply_filters( 'bp_activity_comment_action', sprintf( __( '%s posted a new activity comment:', 'buddypress' ), bp_core_get_userlink( $user_id ) ) ), 'content' => apply_filters( 'bp_activity_comment_content', $content ), 'component' => $bp->activity->id, 'type' => 'activity_comment', 'user_id' => $user_id, 'item_id' => $activity_id, 'secondary_item_id' => $parent_id, 'hide_sitewide' => $is_hidden ) ); /* Send an email notification if settings allow */ require_once( BP_PLUGIN_DIR . '/bp-activity/bp-activity-notifications.php' ); bp_activity_new_comment_notification( $comment_id, $user_id, $params ); /* Clear the comment cache for this activity */ wp_cache_delete( 'bp_activity_comments_' . $parent_id ); do_action( 'bp_activity_comment_posted', $comment_id, $params ); return $comment_id; }