Changeset 7998
- Timestamp:
- 02/27/2014 07:51:28 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-xprofile/bp-xprofile-activity.php
r7228 r7998 133 133 } 134 134 add_action( 'xprofile_avatar_uploaded', 'bp_xprofile_new_avatar_activity' ); 135 136 /** 137 * Add an activity item when a user has updated his profile. 138 * 139 * @since BuddyPress (2.0.0) 140 * 141 * @param int $user_id ID of the user who has updated his profile. 142 * @param array $field_ids IDs of the fields submitted. 143 * @param bool $errors True if validation or saving errors occurred, otherwise 144 * false. 145 * @param array $old_values Pre-save xprofile field values and visibility 146 * levels. 147 * @param array $new_values Post-save xprofile field values and visibility 148 * levels. 149 * @return bool True on success, false on failure. 150 */ 151 function bp_xprofile_updated_profile_activity( $user_id, $field_ids, $errors, $old_values = array(), $new_values = array() ) { 152 // If there were errors, don't post 153 if ( ! empty( $errors ) ) { 154 return false; 155 } 156 157 // Don't post if there have been no changes, or if the changes are 158 // related solely to non-public fields 159 $public_changes = false; 160 foreach ( $new_values as $field_id => $new_value ) { 161 $old_value = isset( $old_values[ $field_id ] ) ? $old_values[ $field_id ] : ''; 162 $old_value_value = isset( $old_value['value'] ) ? $old_value['value'] : ''; 163 $old_value_visibility = isset( $old_value['visibility'] ) ? $old_value['visibility'] : ''; 164 165 // Don't register changes to private fields 166 if ( 'public' !== $new_value['visibility'] ) { 167 continue; 168 } 169 170 // Don't register if there have been no changes 171 if ( $new_value === $old_value ) { 172 continue; 173 } 174 175 // Looks like we have public changes - no need to keep checking 176 $public_changes = true; 177 break; 178 } 179 180 if ( ! $public_changes ) { 181 return false; 182 } 183 184 // Throttle to one activity of this type per 2 hours 185 $existing = bp_activity_get( array( 186 'max' => 1, 187 'filter' => array( 188 'user_id' => $user_id, 189 'object' => buddypress()->profile->id, 190 'action' => 'updated_profile', 191 ), 192 ) ); 193 194 if ( empty( $existing['activities'] ) ) { 195 $throttle = false; 196 } else { 197 // Default throttle time is 2 hours. Filter to change (in seconds) 198 $throttle_period = apply_filters( 'bp_xprofile_updated_profile_activity_throttle_time', 60 * 60 * 2 ); 199 $then = strtotime( $existing['activities'][0]->date_recorded ); 200 $now = strtotime( bp_core_current_time() ); 201 202 $throttle = ( $now - $then ) < $throttle_period; 203 } 204 205 if ( $throttle ) { 206 return false; 207 } 208 209 // If we've reached this point, assemble and post the activity item 210 211 // Note for translators: The natural phrasing in English, "Joe updated 212 // his profile", requires that we know Joe's gender, which we don't. If 213 // your language doesn't have this restriction, feel free to use a more 214 // natural translation. 215 $profile_link = trailingslashit( bp_core_get_user_domain( $user_id ) . buddypress()->profile->slug ); 216 $action = sprintf( __( '%1$s’s profile was updated', 'buddypress' ), '<a href="' . $profile_link . '">' . bp_core_get_user_displayname( $user_id ) . '</a>' ); 217 218 $retval = xprofile_record_activity( array( 219 'user_id' => $user_id, 220 'action' => $action, 221 'primary_link' => $profile_link, 222 'component' => buddypress()->profile->id, 223 'type' => 'updated_profile', 224 ) ); 225 226 return (bool) $retval; 227 } 228 add_action( 'xprofile_updated_profile', 'bp_xprofile_updated_profile_activity', 10, 5 ); 229 230 /** 231 * Add filters for xprofile activity types to Show dropdowns. 232 * 233 * @since BuddyPress (2.0.0) 234 */ 235 function xprofile_activity_filter_options() { 236 ?> 237 238 <option value="updated_profile"><?php _e( 'Profile Updates', 'buddypress' ) ?></option> 239 240 <?php 241 } 242 add_action( 'bp_activity_filter_options', 'xprofile_activity_filter_options' ); -
trunk/bp-xprofile/bp-xprofile-screens.php
r7960 r7998 103 103 104 104 // Now we've checked for required fields, lets save the values. 105 $old_values = $new_values = array(); 105 106 foreach ( (array) $posted_field_ids as $field_id ) { 106 107 … … 121 122 $visibility_level = !empty( $_POST['field_' . $field_id . '_visibility'] ) ? $_POST['field_' . $field_id . '_visibility'] : 'public'; 122 123 xprofile_set_field_visibility_level( $field_id, bp_displayed_user_id(), $visibility_level ); 123 } 124 125 do_action( 'xprofile_updated_profile', bp_displayed_user_id(), $posted_field_ids, $errors ); 124 125 // Save the old and new values. They will be 126 // passed to the filter and used to determine 127 // whether an activity item should be posted 128 $old_values[ $field_id ] = array( 129 'value' => xprofile_get_field_data( $field_id, bp_displayed_user_id() ), 130 'visibility' => xprofile_get_field_visibility_level( $field_id, bp_displayed_user_id() ), 131 ); 132 $new_values[ $field_id ] = array( 133 'value' => $value, 134 'visibility' => $visibility_level, 135 ); 136 } 137 138 do_action( 'xprofile_updated_profile', bp_displayed_user_id(), $posted_field_ids, $errors, $old_values, $new_values ); 126 139 127 140 // Set the feedback messages
Note: See TracChangeset
for help on using the changeset viewer.