Changeset 8125 for trunk/bp-groups/bp-groups-activity.php
- Timestamp:
- 03/13/2014 06:34:06 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-groups/bp-groups-activity.php
r7624 r8125 24 24 } 25 25 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' ) ); 26 bp_activity_set_action( 27 $bp->groups->id, 28 'created_group', 29 __( 'Created a group', 'buddypress' ), 30 'bp_groups_format_activity_action_created_group' 31 ); 32 33 bp_activity_set_action( 34 $bp->groups->id, 35 'joined_group', 36 __( 'Joined a group', 'buddypress' ), 37 'bp_groups_format_activity_action_joined_group' 38 ); 28 39 29 40 // These actions are for the legacy forums … … 38 49 } 39 50 add_action( 'bp_register_activity_actions', 'groups_register_activity_actions' ); 51 52 /** 53 * Format 'created_group' activity actions. 54 * 55 * @since BuddyPress (2.0.0) 56 * 57 * @param object $activity Activity data object. 58 * @return string 59 */ 60 function bp_groups_format_activity_action_created_group( $activity ) { 61 $user_link = bp_core_get_userlink( $activity->user_id ); 62 63 $group = groups_get_group( array( 64 'group_id' => $activity->item_id, 65 'populate_extras' => false, 66 ) ); 67 $group_link = '<a href="' . esc_url( bp_get_group_permalink( $group ) ) . '">' . esc_html( $group->name ) . '</a>'; 68 69 $action = sprintf( __( '%1$s created the group %2$s', 'buddypress'), $user_link, $group_link ); 70 71 return apply_filters( 'groups_activity_created_group_action', $action, $activity ); 72 } 73 74 /** 75 * Format 'joined_group' activity actions. 76 * 77 * @since BuddyPress (2.0.0) 78 * 79 * @param object $activity Activity data object. 80 * @return string 81 */ 82 function bp_groups_format_activity_action_joined_group( $activity ) { 83 $user_link = bp_core_get_userlink( $activity->user_id ); 84 85 $group = groups_get_group( array( 86 'group_id' => $activity->item_id, 87 'populate_extras' => false, 88 ) ); 89 $group_link = '<a href="' . esc_url( bp_get_group_permalink( $group ) ) . '">' . esc_html( $group->name ) . '</a>'; 90 91 $action = sprintf( __( '%1$s joined the group %2$s', 'buddypress' ), $user_link, $group_link ); 92 93 // Legacy filters (do not follow parameter patterns of other activity 94 // action filters, and requires apply_filters_ref_array()) 95 if ( has_filter( 'groups_activity_membership_accepted_action' ) ) { 96 $action = apply_filters_ref_array( 'groups_activity_membership_accepted_action', array( $action, $user_link, &$group ) ); 97 } 98 99 // Another legacy filter 100 if ( has_filter( 'groups_activity_accepted_invite_action' ) ) { 101 $action = apply_filters_ref_array( 'groups_activity_accepted_invite_action', array( $action, $activity->user_id, &$group ) ); 102 } 103 104 return apply_filters( 'bp_groups_format_activity_action_joined_group', $action, $activity ); 105 } 106 107 /** 108 * Fetch data related to groups at the beginning of an activity loop. 109 * 110 * This reduces database overhead during the activity loop. 111 * 112 * @since BuddyPress (2.0.0) 113 * 114 * @param array $activities Array of activity items. 115 * @return array 116 */ 117 function bp_groups_prefetch_activity_object_data( $activities ) { 118 $group_ids = array(); 119 120 if ( empty( $activities ) ) { 121 return $activities; 122 } 123 124 foreach ( $activities as $activity ) { 125 if ( buddypress()->groups->id !== $activity->component ) { 126 continue; 127 } 128 129 $group_ids[] = $activity->item_id; 130 } 131 132 if ( ! empty( $group_ids ) ) { 133 134 // TEMPORARY - Once the 'populate_extras' issue is solved 135 // in the groups component, we can do this with groups_get_groups() 136 // rather than manually 137 $uncached_ids = array(); 138 foreach ( $group_ids as $group_id ) { 139 if ( false === wp_cache_get( $group_id, 'bp_groups' ) ) { 140 $uncached_ids[] = $group_id; 141 } 142 } 143 144 global $wpdb, $bp; 145 $uncached_ids_sql = implode( ',', wp_parse_id_list( $uncached_ids ) ); 146 $groups = $wpdb->get_results( "SELECT * FROM {$bp->groups->table_name} WHERE id IN ({$uncached_ids_sql})" ); 147 foreach ( $groups as $group ) { 148 wp_cache_set( $group->id, $group, 'bp_groups' ); 149 } 150 } 151 } 152 add_filter( 'bp_activity_prefetch_object_data', 'bp_groups_prefetch_activity_object_data' ); 40 153 41 154 /**
Note: See TracChangeset
for help on using the changeset viewer.