Changeset 10163 for trunk/src/bp-xprofile/bp-xprofile-activity.php
- Timestamp:
- 10/01/2015 04:18:13 AM (10 years ago)
- File:
-
- 1 edited
-
trunk/src/bp-xprofile/bp-xprofile-activity.php (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-xprofile/bp-xprofile-activity.php
r10140 r10163 14 14 15 15 /** 16 * Register the activity actions for the Extended Profile component 17 * 18 * @since 1.0.0 19 * 20 * @uses bp_activity_set_action() To setup the individual actions 16 * Register the activity actions for the Extended Profile component. 17 * 18 * @since 1.0.0 19 * 20 * @uses bp_activity_set_action() To setup the individual actions. 21 21 */ 22 22 function xprofile_register_activity_actions() { 23 23 24 // Register the activity stream actions for this component 24 // Register the activity stream actions for this component. 25 25 bp_activity_set_action( 26 // older avatar activity items use 'profile' for component 27 // see r4273 26 // Older avatar activity items use 'profile' for component. See r4273. 28 27 'profile', 29 28 'new_avatar', … … 56 55 * @since 2.0.0 57 56 * 58 * @param string $action Static activity action.57 * @param string $action Static activity action. 59 58 * @param object $activity Activity object. 59 * 60 60 * @return string 61 61 */ … … 64 64 $action = sprintf( __( '%s changed their profile picture', 'buddypress' ), $userlink ); 65 65 66 // Legacy filter - pass $user_id instead of $activity 66 // Legacy filter - pass $user_id instead of $activity. 67 67 if ( has_filter( 'bp_xprofile_new_avatar_action' ) ) { 68 68 $action = apply_filters( 'bp_xprofile_new_avatar_action', $action, $activity->user_id ); … … 85 85 * @since 2.0.0 86 86 * 87 * @param string $action Static activity action.87 * @param string $action Static activity action. 88 88 * @param object $activity Activity object. 89 * 89 90 * @return string 90 91 */ … … 111 112 /** 112 113 * Records activity for the logged in user within the profile component so that 113 * it will show in the users activity stream (if installed) 114 * 115 * @since 1.0.0 116 * 117 * @package BuddyPress 118 * @subpackage XProfileActivity 119 * @param string $args String containing all variables used after extract() call 120 * @uses bp_activity_add() Adds an entry to the activity component tables for a specific activity 114 * it will show in the users activity stream (if installed). 115 * 116 * @since 1.0.0 117 * 118 * @uses bp_activity_add() Adds an entry to the activity component tables for a specific activity. 119 * 120 * @param array|string $args String containing all variables used after bp_parse_args() call. 121 * 122 * @return array 121 123 */ 122 124 function xprofile_record_activity( $args = '' ) { 123 125 124 // Bail if activity component is not active 125 if ( ! bp_is_active( 'activity' ) ) { 126 return false; 127 } 128 129 // Parse the arguments 126 // Bail if activity component is not active. 127 if ( ! bp_is_active( 'activity' ) ) { 128 return false; 129 } 130 131 // Parse the arguments. 130 132 $r = bp_parse_args( $args, array( 131 133 'user_id' => bp_loggedin_user_id(), … … 146 148 /** 147 149 * Deletes activity for a user within the profile component so that it will be 148 * removed from the users activity stream and sitewide stream (if installed) 149 * 150 * @since 1.0.0 151 * 152 * @package BuddyPress XProfile 153 * @param string $args Containing all variables used after extract() call 150 * removed from the users activity stream and sitewide stream (if installed). 151 * 152 * @since 1.0.0 153 * 154 154 * @uses bp_activity_delete() Deletes an entry to the activity component tables 155 * for a specific activity 155 * for a specific activity. 156 * 157 * @param array|string $args Containing all variables used after bp_parse_args() call. 158 * 159 * @return bool 156 160 */ 157 161 function xprofile_delete_activity( $args = '' ) { 158 162 159 // Bail if activity component is not active 160 if ( ! bp_is_active( 'activity' ) ) { 161 return false; 162 } 163 164 // Parse the arguments 163 // Bail if activity component is not active. 164 if ( ! bp_is_active( 'activity' ) ) { 165 return false; 166 } 167 168 // Parse the arguments. 165 169 $r = bp_parse_args( $args, array( 166 170 'component' => buddypress()->profile->id 167 171 ), 'xprofile_delete_activity' ); 168 172 169 // Delete the activity item 173 // Delete the activity item. 170 174 bp_activity_delete_by_item_id( $r ); 171 175 } 172 176 173 177 /** 174 * Register an activity action for the Extended Profiles component 175 * 176 * @since 1.0.0 177 * 178 * @param string $key 179 * @param string $value 180 * @return bool True if success, false on failure 178 * Register an activity action for the Extended Profiles component. 179 * 180 * @since 1.0.0 181 * 182 * @param string $key Key. 183 * @param string $value Value. 184 * 185 * @return bool True if success, false on failure. 181 186 */ 182 187 function xprofile_register_activity_action( $key, $value ) { 183 188 184 // Bail if activity component is not active 189 // Bail if activity component is not active. 185 190 if ( ! bp_is_active( 'activity' ) ) { 186 191 return false; … … 203 208 * 204 209 * @since 1.0.0 205 * @since 2.3.4 Add new parameter to get the user id the avatar was set for 206 * 207 * @package BuddyPress XProfile 210 * @since 2.3.4 Add new parameter to get the user id the avatar was set for. 211 * 208 212 * @uses bp_activity_add() Adds an entry to the activity component tables for a 209 213 * specific activity 210 214 * 211 * @param int $user_id The user id the avatar was set for 215 * @param int $user_id The user id the avatar was set for. 216 * 217 * @return bool 212 218 */ 213 219 function bp_xprofile_new_avatar_activity( $user_id = 0 ) { 214 220 215 // Bail if activity component is not active 221 // Bail if activity component is not active. 216 222 if ( ! bp_is_active( 'activity' ) ) { 217 223 return false; … … 231 237 $user_id = apply_filters( 'bp_xprofile_new_avatar_user_id', $user_id ); 232 238 233 // Add the activity 239 // Add the activity. 234 240 bp_activity_add( array( 235 241 'user_id' => $user_id, … … 245 251 * @since 2.0.0 246 252 * 247 * @param int $user_id ID of the user who has updated his profile. 248 * @param array $field_ids IDs of the fields submitted. 249 * @param bool $errors True if validation or saving errors occurred, otherwise 250 * false. 251 * @param array $old_values Pre-save xprofile field values and visibility 252 * levels. 253 * @param array $new_values Post-save xprofile field values and visibility 254 * levels. 253 * @param int $user_id ID of the user who has updated his profile. 254 * @param array $field_ids IDs of the fields submitted. 255 * @param bool $errors True if validation or saving errors occurred, otherwise false. 256 * @param array $old_values Pre-save xprofile field values and visibility levels. 257 * @param array $new_values Post-save xprofile field values and visibility levels. 258 * 255 259 * @return bool True on success, false on failure. 256 260 */ 257 261 function bp_xprofile_updated_profile_activity( $user_id, $field_ids = array(), $errors = false, $old_values = array(), $new_values = array() ) { 258 262 259 // If there were errors, don't post 263 // If there were errors, don't post. 260 264 if ( ! empty( $errors ) ) { 261 265 return false; 262 266 } 263 267 264 // Bail if activity component is not active 268 // Bail if activity component is not active. 265 269 if ( ! bp_is_active( 'activity' ) ) { 266 270 return false; … … 268 272 269 273 // Don't post if there have been no changes, or if the changes are 270 // related solely to non-public fields 274 // related solely to non-public fields. 271 275 $public_changes = false; 272 276 foreach ( $new_values as $field_id => $new_value ) { 273 277 $old_value = isset( $old_values[ $field_id ] ) ? $old_values[ $field_id ] : ''; 274 278 275 // Don't register changes to private fields 279 // Don't register changes to private fields. 276 280 if ( empty( $new_value['visibility'] ) || ( 'public' !== $new_value['visibility'] ) ) { 277 281 continue; 278 282 } 279 283 280 // Don't register if there have been no changes 284 // Don't register if there have been no changes. 281 285 if ( $new_value === $old_value ) { 282 286 continue; 283 287 } 284 288 285 // Looks like we have public changes - no need to keep checking 289 // Looks like we have public changes - no need to keep checking. 286 290 $public_changes = true; 287 291 break; 288 292 } 289 293 290 // Bail if no public changes 294 // Bail if no public changes. 291 295 if ( empty( $public_changes ) ) { 292 296 return false; 293 297 } 294 298 295 // Throttle to one activity of this type per 2 hours 299 // Throttle to one activity of this type per 2 hours. 296 300 $existing = bp_activity_get( array( 297 301 'max' => 1, … … 303 307 ) ); 304 308 305 // Default throttle time is 2 hours. Filter to change (in seconds) 309 // Default throttle time is 2 hours. Filter to change (in seconds). 306 310 if ( ! empty( $existing['activities'] ) ) { 307 311 … … 317 321 $now = strtotime( bp_core_current_time() ); 318 322 319 // Bail if throttled 323 // Bail if throttled. 320 324 if ( ( $now - $then ) < $throttle_period ) { 321 325 return false; … … 323 327 } 324 328 325 // If we've reached this point, assemble and post the activity item 329 // If we've reached this point, assemble and post the activity item. 326 330 $profile_link = trailingslashit( bp_core_get_user_domain( $user_id ) . bp_get_profile_slug() ); 327 331
Note: See TracChangeset
for help on using the changeset viewer.