Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/01/2015 04:18:13 AM (10 years ago)
Author:
tw2113
Message:

First pass of documentation cleanup for the XProfile Component.

See #6406.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/bp-xprofile-activity.php

    r10140 r10163  
    1414
    1515/**
    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.
    2121 */
    2222function xprofile_register_activity_actions() {
    2323
    24     // Register the activity stream actions for this component
     24    // Register the activity stream actions for this component.
    2525    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.
    2827        'profile',
    2928        'new_avatar',
     
    5655 * @since 2.0.0
    5756 *
    58  * @param string $action Static activity action.
     57 * @param string $action   Static activity action.
    5958 * @param object $activity Activity object.
     59 *
    6060 * @return string
    6161 */
     
    6464    $action   = sprintf( __( '%s changed their profile picture', 'buddypress' ), $userlink );
    6565
    66     // Legacy filter - pass $user_id instead of $activity
     66    // Legacy filter - pass $user_id instead of $activity.
    6767    if ( has_filter( 'bp_xprofile_new_avatar_action' ) ) {
    6868        $action = apply_filters( 'bp_xprofile_new_avatar_action', $action, $activity->user_id );
     
    8585 * @since 2.0.0
    8686 *
    87  * @param string $action Static activity action.
     87 * @param string $action   Static activity action.
    8888 * @param object $activity Activity object.
     89 *
    8990 * @return string
    9091 */
     
    111112/**
    112113 * 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
    121123 */
    122124function xprofile_record_activity( $args = '' ) {
    123125
    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.
    130132    $r = bp_parse_args( $args, array(
    131133        'user_id'           => bp_loggedin_user_id(),
     
    146148/**
    147149 * 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 *
    154154 * @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
    156160 */
    157161function xprofile_delete_activity( $args = '' ) {
    158162
    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.
    165169    $r = bp_parse_args( $args, array(
    166170        'component' => buddypress()->profile->id
    167171    ), 'xprofile_delete_activity' );
    168172
    169     // Delete the activity item
     173    // Delete the activity item.
    170174    bp_activity_delete_by_item_id( $r );
    171175}
    172176
    173177/**
    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.
    181186 */
    182187function xprofile_register_activity_action( $key, $value ) {
    183188
    184     // Bail if activity component is not active
     189    // Bail if activity component is not active.
    185190    if ( ! bp_is_active( 'activity' ) ) {
    186191        return false;
     
    203208 *
    204209 * @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 *
    208212 * @uses bp_activity_add() Adds an entry to the activity component tables for a
    209213 *                         specific activity
    210214 *
    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
    212218 */
    213219function bp_xprofile_new_avatar_activity( $user_id = 0 ) {
    214220
    215     // Bail if activity component is not active
     221    // Bail if activity component is not active.
    216222    if ( ! bp_is_active( 'activity' ) ) {
    217223        return false;
     
    231237    $user_id = apply_filters( 'bp_xprofile_new_avatar_user_id', $user_id );
    232238
    233     // Add the activity
     239    // Add the activity.
    234240    bp_activity_add( array(
    235241        'user_id'   => $user_id,
     
    245251 * @since 2.0.0
    246252 *
    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 *
    255259 * @return bool True on success, false on failure.
    256260 */
    257261function bp_xprofile_updated_profile_activity( $user_id, $field_ids = array(), $errors = false, $old_values = array(), $new_values = array() ) {
    258262
    259     // If there were errors, don't post
     263    // If there were errors, don't post.
    260264    if ( ! empty( $errors ) ) {
    261265        return false;
    262266    }
    263267
    264     // Bail if activity component is not active
     268    // Bail if activity component is not active.
    265269    if ( ! bp_is_active( 'activity' ) ) {
    266270        return false;
     
    268272
    269273    // 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.
    271275    $public_changes = false;
    272276    foreach ( $new_values as $field_id => $new_value ) {
    273277        $old_value = isset( $old_values[ $field_id ] ) ? $old_values[ $field_id ] : '';
    274278
    275         // Don't register changes to private fields
     279        // Don't register changes to private fields.
    276280        if ( empty( $new_value['visibility'] ) || ( 'public' !== $new_value['visibility'] ) ) {
    277281            continue;
    278282        }
    279283
    280         // Don't register if there have been no changes
     284        // Don't register if there have been no changes.
    281285        if ( $new_value === $old_value ) {
    282286            continue;
    283287        }
    284288
    285         // Looks like we have public changes - no need to keep checking
     289        // Looks like we have public changes - no need to keep checking.
    286290        $public_changes = true;
    287291        break;
    288292    }
    289293
    290     // Bail if no public changes
     294    // Bail if no public changes.
    291295    if ( empty( $public_changes ) ) {
    292296        return false;
    293297    }
    294298
    295     // Throttle to one activity of this type per 2 hours
     299    // Throttle to one activity of this type per 2 hours.
    296300    $existing = bp_activity_get( array(
    297301        'max'    => 1,
     
    303307    ) );
    304308
    305     // Default throttle time is 2 hours. Filter to change (in seconds)
     309    // Default throttle time is 2 hours. Filter to change (in seconds).
    306310    if ( ! empty( $existing['activities'] ) ) {
    307311
     
    317321        $now             = strtotime( bp_core_current_time() );
    318322
    319         // Bail if throttled
     323        // Bail if throttled.
    320324        if ( ( $now - $then ) < $throttle_period ) {
    321325            return false;
     
    323327    }
    324328
    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.
    326330    $profile_link = trailingslashit( bp_core_get_user_domain( $user_id ) . bp_get_profile_slug() );
    327331
Note: See TracChangeset for help on using the changeset viewer.