diff --git bp-activity/bp-activity-classes.php bp-activity/bp-activity-classes.php
index eca743a..0084a8a 100644
|
|
class BP_Activity_Activity { |
442 | 442 | if ( $activities && $display_comments ) |
443 | 443 | $activities = BP_Activity_Activity::append_comments( $activities, $spam ); |
444 | 444 | |
| 445 | // Generate action string |
| 446 | $activities = BP_Activity_Activity::generate_action_strings( $activities ); |
| 447 | |
445 | 448 | // If $max is set, only return up to the max results |
446 | 449 | if ( !empty( $max ) ) { |
447 | 450 | if ( (int) $total_activities > (int) $max ) |
… |
… |
class BP_Activity_Activity { |
569 | 572 | } |
570 | 573 | |
571 | 574 | /** |
| 575 | * Generate action strings for the activities located in BP_Activity_Activity::get(). |
| 576 | * |
| 577 | * @since BuddyPress (2.0.0) |
| 578 | * |
| 579 | * @param array $activities Array of activities. |
| 580 | * @return array |
| 581 | */ |
| 582 | protected static function generate_action_strings( $activities ) { |
| 583 | foreach ( $activities as $key => $activity ) { |
| 584 | // Load action_data, the cached strings that will be |
| 585 | // used by the callback to generate the action strings |
| 586 | $activity->action_data = bp_activity_get_meta( $activity->id, 'action_data' ); |
| 587 | |
| 588 | $generated_action = bp_activity_generate_action_string( $activity ); |
| 589 | if ( false !== $generated_action ) { |
| 590 | $activity->action = $generated_action; |
| 591 | } |
| 592 | |
| 593 | $activities[ $key ] = $activity; |
| 594 | } |
| 595 | |
| 596 | return $activities; |
| 597 | } |
| 598 | |
| 599 | /** |
572 | 600 | * Get the SQL for the 'meta_query' param in BP_Activity_Activity::get(). |
573 | 601 | * |
574 | 602 | * We use WP_Meta_Query to do the heavy lifting of parsing the |
diff --git bp-activity/bp-activity-functions.php bp-activity/bp-activity-functions.php
index 8599d50..4be8c76 100644
|
|
function bp_activity_get_userid_from_mentionname( $mentionname ) { |
266 | 266 | * @param string $component_id The unique string ID of the component. |
267 | 267 | * @param string $key The action key. |
268 | 268 | * @param string $value The action value. |
| 269 | * @param callable $format_callback Callback for formatting the action string. |
269 | 270 | * @return bool False if any param is empty, otherwise true. |
270 | 271 | */ |
271 | | function bp_activity_set_action( $component_id, $key, $value ) { |
| 272 | function bp_activity_set_action( $component_id, $key, $value, $format_callback = false ) { |
272 | 273 | global $bp; |
273 | 274 | |
274 | 275 | // Return false if any of the above values are not set |
275 | | if ( empty( $component_id ) || empty( $key ) || empty( $value ) ) |
| 276 | if ( empty( $component_id ) || empty( $key ) || empty( $value ) ) { |
276 | 277 | return false; |
| 278 | } |
277 | 279 | |
278 | 280 | // Set activity action |
279 | 281 | if ( !isset( $bp->activity->actions ) || !is_object( $bp->activity->actions ) ) { |
280 | 282 | $bp->activity->actions = new stdClass; |
281 | 283 | } |
282 | 284 | |
| 285 | // Verify callback |
| 286 | if ( ! is_callable( $format_callback ) ) { |
| 287 | $format_callback = ''; |
| 288 | } |
| 289 | |
283 | 290 | if ( !isset( $bp->activity->actions->{$component_id} ) || !is_object( $bp->activity->actions->{$component_id} ) ) { |
284 | 291 | $bp->activity->actions->{$component_id} = new stdClass; |
285 | 292 | } |
286 | 293 | |
287 | 294 | $bp->activity->actions->{$component_id}->{$key} = apply_filters( 'bp_activity_set_action', array( |
288 | | 'key' => $key, |
289 | | 'value' => $value |
| 295 | 'key' => $key, |
| 296 | 'value' => $value, |
| 297 | 'format_callback' => $format_callback, |
290 | 298 | ), $component_id, $key, $value ); |
291 | 299 | |
292 | 300 | return true; |
… |
… |
add_action( 'bp_make_ham_user', 'bp_activity_ham_all_user_data' ); |
860 | 868 | function bp_activity_register_activity_actions() { |
861 | 869 | global $bp; |
862 | 870 | |
863 | | bp_activity_set_action( $bp->activity->id, 'activity_update', __( 'Posted a status update', 'buddypress' ) ); |
| 871 | bp_activity_set_action( |
| 872 | $bp->activity->id, |
| 873 | 'activity_update', |
| 874 | __( 'Posted a status update', 'buddypress' ), |
| 875 | 'bp_activity_format_activity_action_activity_update' |
| 876 | ); |
| 877 | |
864 | 878 | bp_activity_set_action( $bp->activity->id, 'activity_comment', __( 'Replied to a status update', 'buddypress' ) ); |
865 | 879 | |
866 | 880 | do_action( 'bp_activity_register_activity_actions' ); |
… |
… |
function bp_activity_register_activity_actions() { |
870 | 884 | } |
871 | 885 | add_action( 'bp_register_activity_actions', 'bp_activity_register_activity_actions' ); |
872 | 886 | |
| 887 | /** |
| 888 | * Generate an activity action string for an activity item. |
| 889 | * |
| 890 | * @param object $activity Activity data object. |
| 891 | * @return string|bool Returns false if no callback is found, otherwise returns |
| 892 | * the formatted action string. |
| 893 | */ |
| 894 | function bp_activity_generate_action_string( $activity ) { |
| 895 | // Check for valid input |
| 896 | if ( empty( $activity->component ) || empty( $activity->type ) || empty( $activity->action_data ) ) { |
| 897 | return false; |
| 898 | } |
| 899 | |
| 900 | // Check for registered format callback |
| 901 | if ( empty( buddypress()->activity->actions->{$activity->component}->{$activity->type}['format_callback'] ) ) { |
| 902 | return false; |
| 903 | } |
| 904 | |
| 905 | return call_user_func( buddypress()->activity->actions->{$activity->component}->{$activity->type}['format_callback'], $activity ); |
| 906 | } |
| 907 | |
| 908 | /** |
| 909 | * Format 'activity_update' activity actions. |
| 910 | * |
| 911 | * @since BuddyPress (2.0.0) |
| 912 | * |
| 913 | * @param object $activity Activity data object. |
| 914 | * @return string |
| 915 | */ |
| 916 | function bp_activity_format_activity_action_activity_update( $activity ) { |
| 917 | $user_link = isset( $activity->action_data['user_link'] ) ? $activity->action_data['user_link'] : ''; |
| 918 | return sprintf( __( '%s posted an update', 'buddypress' ), $user_link ); |
| 919 | } |
| 920 | |
873 | 921 | /****************************************************************************** |
874 | 922 | * Business functions are where all the magic happens in BuddyPress. They will |
875 | 923 | * handle the actual saving or manipulation of information. Usually they will |
… |
… |
function bp_activity_add( $args = '' ) { |
1062 | 1110 | 'id' => false, // Pass an existing activity ID to update an existing entry. |
1063 | 1111 | |
1064 | 1112 | 'action' => '', // The activity action - e.g. "Jon Doe posted an update" |
| 1113 | 'action_data' => array(), |
1065 | 1114 | 'content' => '', // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!" |
1066 | 1115 | |
1067 | 1116 | 'component' => false, // The name/ID of the component e.g. groups, profile, mycomponent |
… |
… |
function bp_activity_add( $args = '' ) { |
1090 | 1139 | $activity->user_id = $user_id; |
1091 | 1140 | $activity->component = $component; |
1092 | 1141 | $activity->type = $type; |
1093 | | $activity->action = $action; |
1094 | 1142 | $activity->content = $content; |
1095 | 1143 | $activity->primary_link = $primary_link; |
1096 | 1144 | $activity->item_id = $item_id; |
… |
… |
function bp_activity_add( $args = '' ) { |
1098 | 1146 | $activity->date_recorded = $recorded_time; |
1099 | 1147 | $activity->hide_sitewide = $hide_sitewide; |
1100 | 1148 | $activity->is_spam = $is_spam; |
| 1149 | $activity->action = isset( $action ) ? $action : bp_activity_generate_action_string( $activity ); |
1101 | 1150 | |
1102 | 1151 | if ( !$activity->save() ) |
1103 | 1152 | return false; |
1104 | 1153 | |
| 1154 | bp_activity_update_meta( $activity->id, 'action_data', $action_data ); |
| 1155 | |
1105 | 1156 | // If this is an activity comment, rebuild the tree |
1106 | 1157 | if ( 'activity_comment' == $activity->type ) |
1107 | 1158 | BP_Activity_Activity::rebuild_activity_comment_tree( $activity->item_id ); |
… |
… |
function bp_activity_post_update( $args = '' ) { |
1153 | 1204 | |
1154 | 1205 | // Record this on the user's profile |
1155 | 1206 | $from_user_link = bp_core_get_userlink( $user_id ); |
1156 | | $activity_action = sprintf( __( '%s posted an update', 'buddypress' ), $from_user_link ); |
1157 | 1207 | $activity_content = $content; |
1158 | 1208 | $primary_link = bp_core_get_userlink( $user_id, false, true ); |
1159 | 1209 | |
1160 | 1210 | // Now write the values |
1161 | 1211 | $activity_id = bp_activity_add( array( |
1162 | 1212 | 'user_id' => $user_id, |
1163 | | 'action' => apply_filters( 'bp_activity_new_update_action', $activity_action ), |
1164 | 1213 | 'content' => apply_filters( 'bp_activity_new_update_content', $activity_content ), |
1165 | 1214 | 'primary_link' => apply_filters( 'bp_activity_new_update_primary_link', $primary_link ), |
1166 | 1215 | 'component' => $bp->activity->id, |
1167 | | 'type' => 'activity_update' |
| 1216 | 'type' => 'activity_update', |
| 1217 | 'action_data' => array( |
| 1218 | 'user_link' => $from_user_link, |
| 1219 | ), |
1168 | 1220 | ) ); |
1169 | 1221 | |
1170 | 1222 | $activity_content = apply_filters( 'bp_activity_latest_update_content', $content, $activity_content ); |
diff --git bp-groups/bp-groups-activity.php bp-groups/bp-groups-activity.php
index 324064c..aefb5f1 100644
|
|
function groups_register_activity_actions() { |
24 | 24 | } |
25 | 25 | |
26 | 26 | bp_activity_set_action( $bp->groups->id, 'created_group', __( 'Created a group', 'buddypress' ) ); |
27 | | bp_activity_set_action( $bp->groups->id, 'joined_group', __( 'Joined a group', 'buddypress' ) ); |
| 27 | bp_activity_set_action( |
| 28 | $bp->groups->id, |
| 29 | 'joined_group', |
| 30 | __( 'Joined a group', 'buddypress' ), |
| 31 | 'bp_groups_format_activity_action_joined_group' |
| 32 | ); |
28 | 33 | |
29 | 34 | // These actions are for the legacy forums |
30 | 35 | // Since the bbPress plugin also shares the same 'forums' identifier, we also |
… |
… |
function groups_register_activity_actions() { |
39 | 44 | add_action( 'bp_register_activity_actions', 'groups_register_activity_actions' ); |
40 | 45 | |
41 | 46 | /** |
| 47 | * Format 'joined_group' activity actions. |
| 48 | * |
| 49 | * @since BuddyPress (2.0.0) |
| 50 | * |
| 51 | * @param object $activity Activity data object. |
| 52 | * @return string |
| 53 | */ |
| 54 | function bp_groups_format_activity_action_joined_group( $activity ) { |
| 55 | $user_link = isset( $activity->action_data['user_link'] ) ? $activity->action_data['user_link'] : ''; |
| 56 | $group_link = isset( $activity->action_data['group_link'] ) ? $activity->action_data['group_link'] : ''; |
| 57 | return sprintf( __( '%1$s joined the group %2$s', 'buddypress' ), $user_link, $group_link ); |
| 58 | } |
| 59 | |
| 60 | /** |
42 | 61 | * Record an activity item related to the Groups component. |
43 | 62 | * |
44 | 63 | * A wrapper for {@link bp_activity_add()} that provides some Groups-specific |
diff --git bp-groups/bp-groups-functions.php bp-groups/bp-groups-functions.php
index 251ae96..3234c24 100644
|
|
function groups_join_group( $group_id, $user_id = 0 ) { |
329 | 329 | |
330 | 330 | // Record this in activity streams |
331 | 331 | groups_record_activity( array( |
332 | | 'action' => apply_filters( 'groups_activity_joined_group', sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( $user_id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( bp_get_group_name( $group ) ) . '</a>' ) ), |
333 | 332 | 'type' => 'joined_group', |
334 | 333 | 'item_id' => $group_id, |
335 | | 'user_id' => $user_id |
| 334 | 'user_id' => $user_id, |
| 335 | 'action_data' => array( |
| 336 | 'user_link' => bp_core_get_userlink( $user_id ), |
| 337 | 'group_link' => '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( bp_get_group_name( $group ) ) . '</a>', |
| 338 | ), |
336 | 339 | ) ); |
337 | 340 | |
338 | 341 | // Modify group meta |