bp_xprofile_updated_profile_activity( int $user_id, array $field_ids = array(), bool $errors = false, array $old_values = array(), array $new_values = array() )
Add an activity item when a user has updated his profile.
Description
Parameters
- $user_id
-
(Required) ID of the user who has updated his profile.
- $field_ids
-
(Optional) IDs of the fields submitted.
Default value: array()
- $errors
-
(Optional) True if validation or saving errors occurred, otherwise false.
Default value: false
- $old_values
-
(Optional) Pre-save xprofile field values and visibility levels.
Default value: array()
- $new_values
-
(Optional) Post-save xprofile field values and visibility levels.
Default value: array()
Return
(bool) True on success, false on failure.
Source
File: bp-xprofile/bp-xprofile-activity.php
function bp_xprofile_updated_profile_activity( $user_id, $field_ids = array(), $errors = false, $old_values = array(), $new_values = array() ) { // If there were errors, don't post. if ( ! empty( $errors ) ) { return false; } // Bail if activity component is not active. if ( ! bp_is_active( 'activity' ) ) { return false; } // Don't post if there have been no changes, or if the changes are // related solely to non-public fields. $public_changes = false; foreach ( $new_values as $field_id => $new_value ) { $old_value = isset( $old_values[ $field_id ] ) ? $old_values[ $field_id ] : ''; // Don't register changes to private fields. if ( empty( $new_value['visibility'] ) || ( 'public' !== $new_value['visibility'] ) ) { continue; } // Don't register if there have been no changes. if ( $new_value === $old_value ) { continue; } // Looks like we have public changes - no need to keep checking. $public_changes = true; break; } // Bail if no public changes. if ( empty( $public_changes ) ) { return false; } // Throttle to one activity of this type per 2 hours. $existing = bp_activity_get( array( 'max' => 1, 'filter' => array( 'user_id' => $user_id, 'object' => buddypress()->profile->id, 'action' => 'updated_profile', ), ) ); // Default throttle time is 2 hours. Filter to change (in seconds). if ( ! empty( $existing['activities'] ) ) { /** * Filters the throttle time, in seconds, used to prevent excessive activity posting. * * @since BuddyPress 2.0.0 * * @param int $value Throttle time, in seconds. */ $throttle_period = apply_filters( 'bp_xprofile_updated_profile_activity_throttle_time', HOUR_IN_SECONDS * 2 ); $then = strtotime( $existing['activities'][0]->date_recorded ); $now = bp_core_current_time( true, 'timestamp' ); // Bail if throttled. if ( ( $now - $then ) < $throttle_period ) { return false; } } // If we've reached this point, assemble and post the activity item. $profile_link = trailingslashit( bp_core_get_user_domain( $user_id ) . bp_get_profile_slug() ); return (bool) xprofile_record_activity( array( 'user_id' => $user_id, 'primary_link' => $profile_link, 'component' => buddypress()->profile->id, 'type' => 'updated_profile', ) ); }
Changelog
Version | Description |
---|---|
BuddyPress 2.0.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.