Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/12/2015 05:45:14 AM (11 years ago)
Author:
tw2113
Message:

Further documentation cleanup for Activity Component.

See #6396.

File:
1 edited

Legend:

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

    r10217 r10253  
    99 */
    1010
    11 // Exit if accessed directly
     11// Exit if accessed directly.
    1212defined( 'ABSPATH' ) || exit;
    1313
    … …  
    8686 * @param string $content The content of the activity, usually found in
    8787 *                        $activity->content.
    88  *
    8988 * @return array|bool Associative array with user ID as key and username as
    9089 *                    value. Boolean false if no mentions found.
    … …  
    9594        preg_match_all( $pattern, $content, $usernames );
    9695
    97         // Make sure there's only one instance of each username
     96        // Make sure there's only one instance of each username.
    9897        $usernames = array_unique( $usernames[1] );
    9998
    100         // Bail if no usernames
     99        // Bail if no usernames.
    101100        if ( empty( $usernames ) ) {
    102101                return false;
    … …  
    105104        $mentioned_users = array();
    106105
    107         // We've found some mentions! Check to see if users exist
     106        // We've found some mentions! Check to see if users exist.
    108107        foreach( (array) array_values( $usernames ) as $username ) {
    109108                $user_id = bp_activity_get_userid_from_mentionname( $username );
    110109
    111                 // user ID exists, so let's add it to our array
     110                // The user ID exists, so let's add it to our array.
    112111                if ( ! empty( $user_id ) ) {
    113112                        $mentioned_users[ $user_id ] = $username;
    … …  
    151150 * @param int    $activity_id The unique id for the activity item.
    152151 * @param string $action      Can be 'delete' or 'add'. Defaults to 'add'.
    153  *
    154152 * @return bool
    155153 */
    156154function bp_activity_adjust_mention_count( $activity_id = 0, $action = 'add' ) {
    157155
    158         // Bail if no activity ID passed
     156        // Bail if no activity ID passed.
    159157        if ( empty( $activity_id ) ) {
    160158                return false;
    161159        }
    162160
    163         // Get activity object
     161        // Get activity object.
    164162        $activity  = new BP_Activity_Activity( (int) $activity_id );
    165163
    166         // Try to find mentions
     164        // Try to find mentions.
    167165        $usernames = bp_activity_find_mentions( strip_tags( $activity->content ) );
    168166
    169         // Still empty? Stop now
     167        // Still empty? Stop now.
    170168        if ( empty( $usernames ) ) {
    171169                return false;
    172170        }
    173171
    174         // Increment mention count foreach mentioned user
     172        // Increment mention count foreach mentioned user.
    175173        foreach( (array) array_keys( $usernames ) as $user_id ) {
    176174                bp_activity_update_mention_count_for_user( $user_id, $activity_id, $action );
    … …  
    192190 * @param int    $activity_id The unique ID for the activity item.
    193191 * @param string $action      'delete' or 'add'. Default: 'add'.
    194  *
    195192 * @return bool
    196193 */
    … …  
    201198        }
    202199
    203         // Adjust the mention list and count for the member
     200        // Adjust the mention list and count for the member.
    204201        $new_mention_count = (int) bp_get_user_meta( $user_id, 'bp_new_mention_count', true );
    205202        $new_mentions      =       bp_get_user_meta( $user_id, 'bp_new_mentions',      true );
    206203
    207         // Make sure new mentions is an array
     204        // Make sure new mentions is an array.
    208205        if ( empty( $new_mentions ) ) {
    209206                $new_mentions = array();
    … …  
    229226        }
    230227
    231         // Get an updated mention count
     228        // Get an updated mention count.
    232229        $new_mention_count = count( $new_mentions );
    233230
    234         // Resave the user_meta
     231        // Resave the user_meta.
    235232        bp_update_user_meta( $user_id, 'bp_new_mention_count', $new_mention_count );
    236233        bp_update_user_meta( $user_id, 'bp_new_mentions',      $new_mentions );
    … …  
    245242 *
    246243 * @param int|string $user_id ID of the user to get @-mention name for.
    247  *
    248  * @return string User name appropriate for @-mentions.
     244 * @return string $mentionname User name appropriate for @-mentions.
    249245 */
    250246function bp_activity_get_user_mentionname( $user_id ) {
    … …  
    270266 *
    271267 * @param string $mentionname Username of user in @-mentions.
    272  *
    273268 * @return int|bool ID of the user, if one is found. Otherwise false.
    274269 */
    … …  
    276271        $user_id = false;
    277272
    278         // In username compatibility mode, hyphens are ambiguous between
    279         // actual hyphens and converted spaces.
    280         //
    281         // @todo There is the potential for username clashes between 'foo bar'
    282         // and 'foo-bar' in compatibility mode. Come up with a system for
    283         // unique mentionnames.
     273        /*
     274         * In username compatibility mode, hyphens are ambiguous between
     275         * actual hyphens and converted spaces.
     276         *
     277         * @todo There is the potential for username clashes between 'foo bar'
     278         * and 'foo-bar' in compatibility mode. Come up with a system for
     279         * unique mentionnames.
     280         */
    284281        if ( bp_is_username_compatibility_mode() ) {
    285                 // First, try the raw username
     282                // First, try the raw username.
    286283                $userdata = get_user_by( 'login', $mentionname );
    287284
    … …  
    297294
    298295        // When username compatibility mode is disabled, the mentionname is
    299         // the same as the nicename
     296        // the same as the nicename.
    300297        } else {
    301298                $user_id = bp_core_get_userid_from_nicename( $mentionname );
    … …  
    332329 *                                        Values: 'activity', 'member', 'member_groups', 'group'.
    333330 * @param  int           $position        Optional. The position of the action when listed in dropdowns.
    334  *
    335331 * @return bool False if any param is empty, otherwise true.
    336332 */
    … …  
    338334        $bp = buddypress();
    339335
    340         // Return false if any of the above values are not set
     336        // Return false if any of the above values are not set.
    341337        if ( empty( $component_id ) || empty( $type ) || empty( $description ) ) {
    342338                return false;
    343339        }
    344340
    345         // Set activity action
     341        // Set activity action.
    346342        if ( ! isset( $bp->activity->actions ) || ! is_object( $bp->activity->actions ) ) {
    347343                $bp->activity->actions = new stdClass;
    348344        }
    349345
    350         // Verify callback
     346        // Verify callback.
    351347        if ( ! is_callable( $format_callback ) ) {
    352348                $format_callback = '';
    … …  
    393389 * @param array  $args {
    394390 *     An associative array of tracking parameters. All items are optional.
    395  *
    396391 *     @type string   $bp_activity_admin_filter String to use in the Dashboard > Activity dropdown.
    397392 *     @type string   $bp_activity_front_filter String to use in frontend dropdown.
    … …  
    415410 *                                              the post type does not natively support comments, otherwise false.
    416411 * }
    417  *
    418412 * @return bool
    419413 */
    … …  
    445439 *
    446440 * @param  string $post_type Name of the post type.
    447  *
    448441 * @return object The tracking arguments of the post type.
    449442 */
    … …  
    515508 */
    516509function bp_activity_get_post_types_tracking_args() {
    517         // Fetch all public post types
     510        // Fetch all public post types.
    518511        $post_types = get_post_types( array( 'public' => true ), 'names' );
    519512
    … …  
    595588 * @param string $component_id The unique string ID of the component.
    596589 * @param string $key          The action key.
    597  *
    598590 * @return string|bool Action value if found, otherwise false.
    599591 */
    600592function bp_activity_get_action( $component_id, $key ) {
    601593
    602         // Return false if any of the above values are not set
     594        // Return false if any of the above values are not set.
    603595        if ( empty( $component_id ) || empty( $key ) ) {
    604596                return false;
    … …  
    643635        }
    644636
    645         // This was a mis-named activity type from before BP 1.6
     637        // This was a mis-named activity type from before BP 1.6.
    646638        unset( $actions['friends_register_activity_action'] );
    647639
    … …  
    667659 *
    668660 * @param int $user_id ID of the user whose favorites are being queried.
    669  *
    670661 * @return array IDs of the user's favorite activity items.
    671662 */
    672663function bp_activity_get_user_favorites( $user_id = 0 ) {
    673664
    674         // Fallback to logged in user if no user_id is passed
     665        // Fallback to logged in user if no user_id is passed.
    675666        if ( empty( $user_id ) ) {
    676667                $user_id = bp_displayed_user_id();
    677668        }
    678669
    679         // Get favorites for user
     670        // Get favorites for user.
    680671        $favs = bp_get_user_meta( $user_id, 'bp_favorite_activities', true );
    681672
    … …  
    705696 * @param int $activity_id ID of the activity item being favorited.
    706697 * @param int $user_id     ID of the user favoriting the activity item.
    707  *
    708698 * @return bool True on success, false on failure.
    709699 */
    710700function bp_activity_add_user_favorite( $activity_id, $user_id = 0 ) {
    711701
    712         // Favorite activity stream items are for logged in users only
     702        // Favorite activity stream items are for logged in users only.
    713703        if ( ! is_user_logged_in() ) {
    714704                return false;
    715705        }
    716706
    717         // Fallback to logged in user if no user_id is passed
     707        // Fallback to logged in user if no user_id is passed.
    718708        if ( empty( $user_id ) ) {
    719709                $user_id = bp_loggedin_user_id();
    … …  
    725715        }
    726716
    727         // Bail if the user has already favorited this activity item
     717        // Bail if the user has already favorited this activity item.
    728718        if ( in_array( $activity_id, $my_favs ) ) {
    729719                return false;
    730720        }
    731721
    732         // Add to user's favorites
     722        // Add to user's favorites.
    733723        $my_favs[] = $activity_id;
    734724
    735         // Update the total number of users who have favorited this activity
     725        // Update the total number of users who have favorited this activity.
    736726        $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' );
    737727        $fav_count = !empty( $fav_count ) ? (int) $fav_count + 1 : 1;
    738728
    739         // Update user meta
     729        // Update user meta.
    740730        bp_update_user_meta( $user_id, 'bp_favorite_activities', $my_favs );
    741731
    742         // Update activity meta counts
     732        // Update activity meta counts.
    743733        if ( bp_activity_update_meta( $activity_id, 'favorite_count', $fav_count ) ) {
    744734
    … …  
    753743                do_action( 'bp_activity_add_user_favorite', $activity_id, $user_id );
    754744
    755                 // Success
     745                // Success.
    756746                return true;
    757747
    758         // Saving meta was unsuccessful for an unknown reason
     748        // Saving meta was unsuccessful for an unknown reason.
    759749        } else {
    760750
    … …  
    787777 * @param int $activity_id ID of the activity item being unfavorited.
    788778 * @param int $user_id     ID of the user unfavoriting the activity item.
    789  *
    790779 * @return bool True on success, false on failure.
    791780 */
    792781function bp_activity_remove_user_favorite( $activity_id, $user_id = 0 ) {
    793782
    794         // Favorite activity stream items are for logged in users only
     783        // Favorite activity stream items are for logged in users only.
    795784        if ( ! is_user_logged_in() ) {
    796785                return false;
    797786        }
    798787
    799         // Fallback to logged in user if no user_id is passed
     788        // Fallback to logged in user if no user_id is passed.
    800789        if ( empty( $user_id ) ) {
    801790                $user_id = bp_loggedin_user_id();
    … …  
    805794        $my_favs = array_flip( (array) $my_favs );
    806795
    807         // Bail if the user has not previously favorited the item
     796        // Bail if the user has not previously favorited the item.
    808797        if ( ! isset( $my_favs[ $activity_id ] ) ) {
    809798                return false;
    810799        }
    811800
    812         // Remove the fav from the user's favs
     801        // Remove the fav from the user's favs.
    813802        unset( $my_favs[$activity_id] );
    814803        $my_favs = array_unique( array_flip( $my_favs ) );
    815804
    816         // Update the total number of users who have favorited this activity
     805        // Update the total number of users who have favorited this activity.
    817806        $fav_count = bp_activity_get_meta( $activity_id, 'favorite_count' );
    818807        if ( ! empty( $fav_count ) ) {
    819808
    820                 // Deduct from total favorites
     809                // Deduct from total favorites.
    821810                if ( bp_activity_update_meta( $activity_id, 'favorite_count', (int) $fav_count - 1 ) ) {
    822811
    823                         // Update users favorites
     812                        // Update users favorites.
    824813                        if ( bp_update_user_meta( $user_id, 'bp_favorite_activities', $my_favs ) ) {
    825814
    … …  
    834823                                do_action( 'bp_activity_remove_user_favorite', $activity_id, $user_id );
    835824
    836                                 // Success
     825                                // Success.
    837826                                return true;
    838827
    839                         // Error updating
     828                        // Error updating.
    840829                        } else {
    841830                                return false;
    842831                        }
    843832
    844                 // Error updating favorite count
     833                // Error updating favorite count.
    845834                } else {
    846835                        return false;
    847836                }
    848837
    849         // Error getting favorite count
     838        // Error getting favorite count.
    850839        } else {
    851840                return false;
    … …  
    862851 *
    863852 * @param string $content The content to filter by.
    864  *
    865853 * @return int|null The ID of the located activity item. Null if none is found.
    866854 */
    … …  
    907895 *
    908896 * @param int $user_id ID of the user whose favorite count is being requested.
    909  *
    910897 * @return int Total favorite count for the user.
    911898 */
    912899function bp_activity_total_favorites_for_user( $user_id = 0 ) {
    913900
    914         // Fallback on displayed user, and then logged in user
     901        // Fallback on displayed user, and then logged in user.
    915902        if ( empty( $user_id ) ) {
    916903                $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
    … …  
    937924 * @param bool   $delete_all  Optional. If true, delete matching metadata entries
    938925 *                            for all objects, ignoring the specified object_id. Otherwise,
    939  *                                only delete matching metadata entries for the specified
    940  *                                activity item. Default: false.
    941  *
     926 *                            only delete matching metadata entries for the specified
     927 *                            activity item. Default: false.
    942928 * @return bool True on success, false on failure.
    943929 */
    944930function bp_activity_delete_meta( $activity_id, $meta_key = '', $meta_value = '', $delete_all = false ) {
    945931
    946         // Legacy - if no meta_key is passed, delete all for the item
     932        // Legacy - if no meta_key is passed, delete all for the item.
    947933        if ( empty( $meta_key ) ) {
    948934                $all_meta = bp_activity_get_meta( $activity_id );
    949935                $keys     = ! empty( $all_meta ) ? array_keys( $all_meta ) : array();
    950936
    951                 // With no meta_key, ignore $delete_all
     937                // With no meta_key, ignore $delete_all.
    952938                $delete_all = false;
    953939        } else {
    … …  
    978964 *                            activity item will be fetched.
    979965 * @param bool   $single      Optional. If true, return only the first value of the
    980  *                                specified meta_key. This parameter has no effect if meta_key is not
    981  *                                specified. Default: true.
    982  *
     966 *                            specified meta_key. This parameter has no effect if meta_key is not
     967 *                            specified. Default: true.
    983968 * @return mixed The meta value(s) being requested.
    984969 */
    … …  
    1011996 * @param mixed  $prev_value  Optional. If specified, only update existing metadata entries
    1012997 *                            with the specified value. Otherwise, update all entries.
    1013  *
    1014998 * @return bool|int Returns false on failure. On successful update of existing
    1015999 *                  metadata, returns true. On successful creation of new metadata,
    … …  
    10351019 *                            given key. If true, and the object already has a value for
    10361020 *                            the key, no change will be made. Default: false.
    1037  *
    10381021 * @return int|bool The meta ID on successful update, false on failure.
    10391022 */
    … …  
    10601043 *
    10611044 * @param int $user_id ID of the user whose activity is being deleted.
    1062  *
    10631045 * @return bool
    10641046 */
    10651047function bp_activity_remove_all_user_data( $user_id = 0 ) {
    10661048
    1067         // Do not delete user data unless a logged in user says so
     1049        // Do not delete user data unless a logged in user says so.
    10681050        if ( empty( $user_id ) || ! is_user_logged_in() ) {
    10691051                return false;
    10701052        }
    10711053
    1072         // Clear the user's activity from the sitewide stream and clear their activity tables
     1054        // Clear the user's activity from the sitewide stream and clear their activity tables.
    10731055        bp_activity_delete( array( 'user_id' => $user_id ) );
    10741056
    1075         // Remove any usermeta
     1057        // Remove any usermeta.
    10761058        bp_delete_user_meta( $user_id, 'bp_latest_update'       );
    10771059        bp_delete_user_meta( $user_id, 'bp_favorite_activities' );
    … …  
    11001082 *
    11011083 * @param int $user_id ID of the user whose activity is being spammed.
    1102  *
    11031084 * @return bool
    11041085 */
    … …  
    11061087        global $wpdb;
    11071088
    1108         // Do not delete user data unless a logged in user says so
     1089        // Do not delete user data unless a logged in user says so.
    11091090        if ( empty( $user_id ) || ! is_user_logged_in() ) {
    11101091                return false;
    … …  
    11201101        $bp = buddypress();
    11211102
    1122         // Mark each as spam
     1103        // Mark each as spam.
    11231104        foreach ( (array) $activities['activities'] as $activity ) {
    11241105
    1125                 // Create an activity object
     1106                // Create an activity object.
    11261107                $activity_obj = new BP_Activity_Activity;
    11271108                foreach ( $activity as $k => $v ) {
    … …  
    11291110                }
    11301111
    1131                 // Mark as spam
     1112                // Mark as spam.
    11321113                bp_activity_mark_as_spam( $activity_obj );
    11331114
    … …  
    11431124                }
    11441125
    1145                 // Tidy up
     1126                // Tidy up.
    11461127                unset( $activity_obj );
    11471128        }
    11481129
    1149         // Mark all of this user's activities as spam
     1130        // Mark all of this user's activities as spam.
    11501131        $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET is_spam = 1 WHERE user_id = %d", $user_id ) );
    11511132
    … …  
    11701151 *
    11711152 * @param int $user_id ID of the user whose activity is being hammed.
    1172  *
    11731153 * @return bool
    11741154 */
    … …  
    11761156        global $wpdb;
    11771157
    1178         // Do not delete user data unless a logged in user says so
     1158        // Do not delete user data unless a logged in user says so.
    11791159        if ( empty( $user_id ) || ! is_user_logged_in() ) {
    11801160                return false;
    … …  
    11911171        $bp = buddypress();
    11921172
    1193         // Mark each as not spam
     1173        // Mark each as not spam.
    11941174        foreach ( (array) $activities['activities'] as $activity ) {
    11951175
    1196                 // Create an activity object
     1176                // Create an activity object.
    11971177                $activity_obj = new BP_Activity_Activity;
    11981178                foreach ( $activity as $k => $v ) {
    … …  
    12001180                }
    12011181
    1202                 // Mark as not spam
     1182                // Mark as not spam.
    12031183                bp_activity_mark_as_ham( $activity_obj );
    12041184
    … …  
    12141194                }
    12151195
    1216                 // Tidy up
     1196                // Tidy up.
    12171197                unset( $activity_obj );
    12181198        }
    12191199
    1220         // Mark all of this user's activities as not spam
     1200        // Mark all of this user's activities as not spam.
    12211201        $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET is_spam = 0 WHERE user_id = %d", $user_id ) );
    12221202
    … …  
    12761256 *
    12771257 * @param object $activity Activity data object.
    1278  *
    12791258 * @return string|bool Returns false if no callback is found, otherwise returns
    12801259 *                     the formatted action string.
    … …  
    12821261function bp_activity_generate_action_string( $activity ) {
    12831262
    1284         // Check for valid input
     1263        // Check for valid input.
    12851264        if ( empty( $activity->component ) || empty( $activity->type ) ) {
    12861265                return false;
    12871266        }
    12881267
    1289         // Check for registered format callback
     1268        // Check for registered format callback.
    12901269        $actions = bp_activity_get_actions();
    12911270        if ( empty( $actions->{$activity->component}->{$activity->type}['format_callback'] ) ) {
    … …  
    12931272        }
    12941273
    1295         // We apply the format_callback as a filter
     1274        // We apply the format_callback as a filter.
    12961275        add_filter( 'bp_activity_generate_action_string', $actions->{$activity->component}->{$activity->type}['format_callback'], 10, 2 );
    12971276
    … …  
    13061285        $action = apply_filters( 'bp_activity_generate_action_string', $activity->action, $activity );
    13071286
    1308         // Remove the filter for future activity items
     1287        // Remove the filter for future activity items.
    13091288        remove_filter( 'bp_activity_generate_action_string', $actions->{$activity->component}->{$activity->type}['format_callback'], 10, 2 );
    13101289
    … …  
    13191298 * @param string $action   Static activity action.
    13201299 * @param object $activity Activity data object.
    1321  *
    1322  * @return string
     1300 * @return string $action
    13231301 */
    13241302function bp_activity_format_activity_action_activity_update( $action, $activity ) {
    … …  
    13431321 * @param string $action   Static activity action.
    13441322 * @param object $activity Activity data object.
    1345  *
    1346  * @return string
     1323 * @return string $action
    13471324 */
    13481325function bp_activity_format_activity_action_activity_comment( $action, $activity ) {
    … …  
    13671344 * @param string $action   Static activity action.
    13681345 * @param object $activity Activity data object.
    1369  *
    1370  * @return string
     1346 * @return string $action
    13711347 */
    13721348function bp_activity_format_activity_action_custom_post_type_post( $action, $activity ) {
    … …  
    14181394}
    14191395
    1420 /******************************************************************************
     1396/*
    14211397 * Business functions are where all the magic happens in BuddyPress. They will
    14221398 * handle the actual saving or manipulation of information. Usually they will
    … …  
    14281404 * Retrieve an activity or activities.
    14291405 *
    1430  * bp_activity_get() shares all arguments with BP_Activity_Activity::get(). The
    1431  * following is a list of bp_activity_get() parameters that have different
     1406 * The bp_activity_get() function shares all arguments with BP_Activity_Activity::get().
     1407 * The following is a list of bp_activity_get() parameters that have different
    14321408 * default values from BP_Activity_Activity::get() (value in parentheses is
    14331409 * the default for the bp_activity_get()).
    … …  
    14461422 *
    14471423 * @param array|string $args See BP_Activity_Activity::get() for description.
    1448  *
    14491424 * @return array $activity See BP_Activity_Activity::get() for description.
    14501425 */
    … …  
    14641439                'filter_query'      => false,
    14651440                'show_hidden'       => false,        // Show activity items that are hidden site-wide?
    1466                 'exclude'           => false,        // Comma-separated list of activity IDs to exclude
    1467                 'in'                => false,        // Comma-separated list or array of activity IDs to which you want to limit the query
     1441                'exclude'           => false,        // Comma-separated list of activity IDs to exclude.
     1442                'in'                => false,        // Comma-separated list or array of activity IDs to which you
     1443                                                     // want to limit the query.
    14681444                'spam'              => 'ham_only',   // 'ham_only' (default), 'spam_only' or 'all'.
    14691445                'update_meta_cache' => true,
    … …  
    14741450                 * Pass filters as an array -- all filter items can be multiple values comma separated:
    14751451                 * array(
    1476                  *      'user_id'      => false, // user_id to filter on
    1477                  *      'object'       => false, // object to filter on e.g. groups, profile, status, friends
    1478                  *      'action'       => false, // action to filter on e.g. activity_update, profile_updated
    1479                  *      'primary_id'   => false, // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
    1480                  *      'secondary_id' => false, // secondary object ID to filter on e.g. a post_id
     1452                 *     'user_id'      => false, // User ID to filter on.
     1453                 *     'object'       => false, // Object to filter on e.g. groups, profile, status, friends.
     1454                 *     'action'       => false, // Action to filter on e.g. activity_update, profile_updated.
     1455                 *     'primary_id'   => false, // Object ID to filter on e.g. a group_id or forum_id or blog_id etc.
     1456                 *     'secondary_id' => false, // Secondary object ID to filter on e.g. a post_id.
    14811457                 * );
    14821458                 */
    … …  
    15581534 *     except for the following:
    15591535 *     @type string|int|array Single activity ID, comma-separated list of IDs,
    1560  *           or array of IDs.
     1536 *                            or array of IDs.
    15611537 * }
    15621538 * @return array $activity See BP_Activity_Activity::get() for description.
    … …  
    15661542        $r = bp_parse_args( $args, array(
    15671543                'activity_ids'      => false,      // A single activity_id or array of IDs.
    1568                 'display_comments'  => false,      // true or false to display threaded comments for these specific activity items
    1569                 'max'               => false,      // Maximum number of results to return
    1570                 'page'              => 1,          // page 1 without a per_page will result in no pagination.
    1571                 'per_page'          => false,      // results per page
    1572                 'show_hidden'       => true,       // When fetching specific items, show all
    1573                 'sort'              => 'DESC',     // sort ASC or DESC
    1574                 'spam'              => 'ham_only', // Retrieve items marked as spam
     1544                'display_comments'  => false,      // True or false to display threaded comments for these specific activity items.
     1545                'max'               => false,      // Maximum number of results to return.
     1546                'page'              => 1,          // Page 1 without a per_page will result in no pagination.
     1547                'per_page'          => false,      // Results per page.
     1548                'show_hidden'       => true,       // When fetching specific items, show all.
     1549                'sort'              => 'DESC',     // Sort ASC or DESC
     1550                'spam'              => 'ham_only', // Retrieve items marked as spam.
    15751551                'update_meta_cache' => true,
    15761552        ) );
    … …  
    16501626                'action'            => '',                     // The activity action - e.g. "Jon Doe posted an update"
    16511627                'content'           => '',                     // Optional: The content of the activity item e.g. "BuddyPress is awesome guys!"
    1652                 'component'         => false,                  // The name/ID of the component e.g. groups, profile, mycomponent
    1653                 'type'              => false,                  // The activity type e.g. activity_update, profile_updated
    1654                 'primary_link'      => '',                     // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink)
     1628                'component'         => false,                  // The name/ID of the component e.g. groups, profile, mycomponent.
     1629                'type'              => false,                  // The activity type e.g. activity_update, profile_updated.
     1630                'primary_link'      => '',                     // Optional: The primary URL for this item in RSS feeds (defaults to activity permalink).
    16551631                'user_id'           => bp_loggedin_user_id(),  // Optional: The user to record the activity for, can be false if this activity is not for a user.
    1656                 'item_id'           => false,                  // Optional: The ID of the specific item being recorded, e.g. a blog_id
    1657                 'secondary_item_id' => false,                  // Optional: A second ID used to further filter e.g. a comment_id
    1658                 'recorded_time'     => bp_core_current_time(), // The GMT time that this activity was recorded
     1632                'item_id'           => false,                  // Optional: The ID of the specific item being recorded, e.g. a blog_id.
     1633                'secondary_item_id' => false,                  // Optional: A second ID used to further filter e.g. a comment_id.
     1634                'recorded_time'     => bp_core_current_time(), // The GMT time that this activity was recorded.
    16591635                'hide_sitewide'     => false,                  // Should this be hidden on the sitewide activity stream?
    16601636                'is_spam'           => false,                  // Is this activity item to be marked as spam?
    16611637        ), 'activity_add' );
    16621638
    1663         // Make sure we are backwards compatible
     1639        // Make sure we are backwards compatible.
    16641640        if ( empty( $r['component'] ) && !empty( $r['component_name'] ) ) {
    16651641                $r['component'] = $r['component_name'];
    … …  
    16701646        }
    16711647
    1672         // Setup activity to be added
     1648        // Setup activity to be added.
    16731649        $activity                    = new BP_Activity_Activity( $r['id'] );
    16741650        $activity->user_id           = $r['user_id'];
    … …  
    16901666        }
    16911667
    1692         // If this is an activity comment, rebuild the tree
     1668        // If this is an activity comment, rebuild the tree.
    16931669        if ( 'activity_comment' === $activity->type ) {
    1694                 // Also clear the comment cache for the parent activity ID
     1670                // Also clear the comment cache for the parent activity ID.
    16951671                wp_cache_delete( $activity->item_id, 'bp_activity_comments' );
    16961672
    … …  
    17491725        }
    17501726
    1751         // Record this on the user's profile
     1727        // Record this on the user's profile.
    17521728        $activity_content = $r['content'];
    17531729        $primary_link     = bp_core_get_userlink( $r['user_id'], false, true );
    … …  
    17711747        $add_primary_link = apply_filters( 'bp_activity_new_update_primary_link', $primary_link );
    17721748
    1773         // Now write the values
     1749        // Now write the values.
    17741750        $activity_id = bp_activity_add( array(
    17751751                'user_id'      => $r['user_id'],
    … …  
    18151791 * @since 2.2.0
    18161792 *
    1817  * @param  int      $post_id ID of the new post.
    1818  * @param  WP_Post  $post    Post object.
    1819  * @param  int      $user_id ID of the post author.
    1820  *
     1793 * @param int     $post_id ID of the new post.
     1794 * @param WP_Post $post    Post object.
     1795 * @param int     $user_id ID of the post author.
    18211796 * @return int|bool The ID of the activity on success. False on error.
    18221797 */
    … …  
    19531928 * @since 2.2.0
    19541929 *
    1955  * @param  WP_Post $post Post item.
    1956  *
    1957  * @return bool    True on success, false on failure.
     1930 * @param WP_Post $post Post item.
     1931 * @return bool True on success, false on failure.
    19581932 */
    19591933function bp_activity_post_type_update( $post = null ) {
    … …  
    20241998 * @param  int     $post_id ID of the post being unpublished.
    20251999 * @param  WP_Post $post    Post object.
    2026  *
    2027  * @return bool    True on success, false on failure.
     2000 * @return bool True on success, false on failure.
    20282001 */
    20292002function bp_activity_post_type_unpublish( $post_id = 0, $post = null ) {
    … …  
    20332006        }
    20342007
    2035         // Get the post type tracking args
     2008        // Get the post type tracking args.
    20362009        $activity_post_object = bp_activity_get_post_type_tracking_args( $post->post_type );
    20372010
    … …  
    21062079                'content'     => false,
    21072080                'user_id'     => bp_loggedin_user_id(),
    2108                 'activity_id' => false, // ID of the root activity item
    2109                 'parent_id'   => false  // ID of a parent comment (optional)
     2081                'activity_id' => false, // ID of the root activity item.
     2082                'parent_id'   => false  // ID of a parent comment (optional).
    21102083        ) );
    21112084
    2112         // Bail if missing necessary data
     2085        // Bail if missing necessary data.
    21132086        if ( empty( $r['content'] ) || empty( $r['user_id'] ) || empty( $r['activity_id'] ) ) {
    21142087                $errors->add( 'missing_data', $feedback );
    … …  
    21182091        }
    21192092
    2120         // Maybe set current activity ID as the parent
     2093        // Maybe set current activity ID as the parent.
    21212094        if ( empty( $r['parent_id'] ) ) {
    21222095                $r['parent_id'] = $r['activity_id'];
    … …  
    21252098        $activity_id = $r['activity_id'];
    21262099
    2127         // Get the parent activity
     2100        // Get the parent activity.
    21282101        $activity  = new BP_Activity_Activity( $activity_id );
    21292102
    2130         // Bail if the parent activity does not exist
     2103        // Bail if the parent activity does not exist.
    21312104        if ( empty( $activity->date_recorded ) ) {
    21322105                $errors->add( 'missing_activity', __( 'Sorry, the item you are replying to no longer exists.', 'buddypress' ) );
    … …  
    21482121        $comment_content = apply_filters( 'bp_activity_comment_content', $r['content'] );
    21492122
    2150         // Insert the activity comment
     2123        // Insert the activity comment.
    21512124        $comment_id = bp_activity_add( array(
    21522125                'id'                => $r['id'],
    … …  
    21602133        ) );
    21612134
    2162         // Comment caches are stored only with the top-level item
     2135        // Comment caches are stored only with the top-level item.
    21632136        wp_cache_delete( $activity_id, 'bp_activity_comments' );
    21642137
    2165         // Walk the tree to clear caches for all parent items
     2138        // Walk the tree to clear caches for all parent items.
    21662139        $clear_id = $r['parent_id'];
    21672140        while ( $clear_id != $activity_id ) {
    … …  
    22022175 *
    22032176 * @param array|string $args See BP_Activity_Activity::get() for description.
    2204  *
    22052177 * @return int $activity_id The ID of the activity item found.
    22062178 */
    … …  
    22682240 *                           the same as BP_Activity_Activity::get().
    22692241 *                           See that method for a description.
    2270  *
    22712242 * @return bool True on success, false on failure.
    22722243 */
    22732244function bp_activity_delete( $args = '' ) {
    22742245
    2275         // Pass one or more the of following variables to delete by those variables
     2246        // Pass one or more the of following variables to delete by those variables.
    22762247        $args = bp_parse_args( $args, array(
    22772248                'id'                => false,
    … …  
    22972268        do_action( 'bp_before_activity_delete', $args );
    22982269
    2299         // Adjust the new mention count of any mentioned member
     2270        // Adjust the new mention count of any mentioned member.
    23002271        bp_activity_adjust_mention_count( $args['id'], 'delete' );
    23012272
    … …  
    23052276        }
    23062277
    2307         // Check if the user's latest update has been deleted
     2278        // Check if the user's latest update has been deleted.
    23082279        $user_id = empty( $args['user_id'] )
    23092280                ? bp_loggedin_user_id()
    … …  
    23532324         * @param array|string $args See BP_Activity_Activity::get for a
    23542325         *                           description of accepted arguments.
    2355          *
    23562326         * @return bool True on success, false on failure.
    23572327         */
    … …  
    23772347         *
    23782348         * @param int $activity_id ID of the activity item to be deleted.
    2379          *
    23802349         * @return bool True on success, false on failure.
    23812350         */
    … …  
    23982367         * @param string $component The activity component.
    23992368         * @param string $type      The activity type.
    2400          *
    24012369         * @return bool True on success, false on failure.
    24022370         */
    … …  
    24222390         * @param int    $user_id   The user id.
    24232391         * @param string $component The activity component.
    2424          *
    24252392         * @return bool True on success, false on failure.
    24262393         */
    … …  
    24502417 *                         oldest ancestor.
    24512418 * @param int $comment_id  The ID of the comment to be deleted.
    2452  *
    24532419 * @return bool True on success, false on failure.
    24542420 */
    … …  
    24742440        bp_activity_delete_children( $activity_id, $comment_id );
    24752441
    2476         // Delete the actual comment
     2442        // Delete the actual comment.
    24772443        if ( ! bp_activity_delete( array( 'id' => $comment_id, 'type' => 'activity_comment' ) ) ) {
    24782444                return false;
    24792445        }
    24802446
    2481         // Purge comment cache for the root activity update
     2447        // Purge comment cache for the root activity update.
    24822448        wp_cache_delete( $activity_id, 'bp_activity_comments' );
    24832449
    2484         // Recalculate the comment tree
     2450        // Recalculate the comment tree.
    24852451        BP_Activity_Activity::rebuild_activity_comment_tree( $activity_id );
    24862452
    … …  
    25132479        function bp_activity_delete_children( $activity_id, $comment_id ) {
    25142480
    2515                 // Get activity children to delete
     2481                // Get activity children to delete.
    25162482                $children = BP_Activity_Activity::get_child_comments( $comment_id );
    25172483
    … …  
    25232489                }
    25242490
    2525                 // Delete the comment itself
     2491                // Delete the comment itself.
    25262492                bp_activity_delete( array(
    25272493                        'secondary_item_id' => $comment_id,
    … …  
    25472513 * @param int         $activity_id  The unique id of the activity object.
    25482514 * @param object|bool $activity_obj Optional. The activity object.
    2549  *
    25502515 * @return string $link Permalink for the activity item.
    25512516 */
    … …  
    26002565 *
    26012566 * @param int $user_id The ID of the user whose activity is being hidden.
    2602  *
    26032567 * @return bool True on success, false on failure.
    26042568 */
    … …  
    26292593 * @param array|bool  $args    Optional. The args passed to the activity
    26302594 *                             creation function (eg bp_blogs_record_activity()).
    2631  *
    26322595 * @return string $content The content with images stripped and replaced with a
    26332596 *                         single thumb.
    … …  
    26372600        preg_match_all( '/<img[^>]*>/Ui', $content, $matches );
    26382601
    2639         // Remove <img> tags. Also remove caption shortcodes and caption text if present
     2602        // Remove <img> tags. Also remove caption shortcodes and caption text if present.
    26402603        $content = preg_replace('|(\[caption(.*?)\])?<img[^>]*>([^\[\[]*\[\/caption\])?|', '', $content );
    26412604
    26422605        if ( !empty( $matches ) && !empty( $matches[0] ) ) {
    26432606
    2644                 // Get the SRC value
     2607                // Get the SRC value.
    26452608                preg_match( '/<img.*?(src\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i',    $matches[0][0], $src    );
    26462609
    2647                 // Get the width and height
     2610                // Get the width and height.
    26482611                preg_match( '/<img.*?(height\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i', $matches[0][0], $height );
    26492612                preg_match( '/<img.*?(width\=[\'|"]{0,1}.*?[\'|"]{0,1})[\s|>]{1}/i',  $matches[0][0], $width  );
    … …  
    27022665 * @param array  $activity The data passed to bp_activity_add() or the values
    27032666 *                         from an Activity obj.
    2704  *
    2705  * @return string
     2667 * @return string $summary
    27062668 */
    27072669function bp_activity_create_summary( $content, $activity ) {
    … …  
    28862848        $activity->is_spam = 1;
    28872849
    2888         // Clear the activity stream first page cache
     2850        // Clear the activity stream first page cache.
    28892851        wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
    28902852
    2891         // Clear the activity comment cache for this activity item
     2853        // Clear the activity comment cache for this activity item.
    28922854        wp_cache_delete( $activity->id, 'bp_activity_comments' );
    28932855
    2894         // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity
     2856        // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity.
    28952857        if ( 'by_a_person' == $source && !empty( $bp->activity->akismet ) ) {
    28962858                remove_action( 'bp_activity_before_save', array( $bp->activity->akismet, 'check_activity' ), 4, 1 );
    28972859
    2898                 // Build data package for Akismet
     2860                // Build data package for Akismet.
    28992861                $activity_data = BP_Akismet::build_akismet_data_package( $activity );
    29002862
    2901                 // Tell Akismet this is spam
     2863                // Tell Akismet this is spam.
    29022864                $activity_data = $bp->activity->akismet->send_akismet_request( $activity_data, 'submit', 'spam' );
    29032865
    2904                 // Update meta
     2866                // Update meta.
    29052867                add_action( 'bp_activity_after_save', array( $bp->activity->akismet, 'update_activity_spam_meta' ), 1, 1 );
    29062868        }
    … …  
    29332895        $activity->is_spam = 0;
    29342896
    2935         // Clear the activity stream first page cache
     2897        // Clear the activity stream first page cache.
    29362898        wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
    29372899
    2938         // Clear the activity comment cache for this activity item
     2900        // Clear the activity comment cache for this activity item.
    29392901        wp_cache_delete( $activity->id, 'bp_activity_comments' );
    29402902
    2941         // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity
     2903        // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity.
    29422904        if ( 'by_a_person' == $source && !empty( $bp->activity->akismet ) ) {
    29432905                remove_action( 'bp_activity_before_save', array( $bp->activity->akismet, 'check_activity' ), 4, 1 );
    29442906
    2945                 // Build data package for Akismet
     2907                // Build data package for Akismet.
    29462908                $activity_data = BP_Akismet::build_akismet_data_package( $activity );
    29472909
    2948                 // Tell Akismet this is spam
     2910                // Tell Akismet this is spam.
    29492911                $activity_data = $bp->activity->akismet->send_akismet_request( $activity_data, 'submit', 'ham' );
    29502912
    2951                 // Update meta
     2913                // Update meta.
    29522914                add_action( 'bp_activity_after_save', array( $bp->activity->akismet, 'update_activity_ham_meta' ), 1, 1 );
    29532915        }
    … …  
    30723034 * @param int    $id       The ID of the activity item.
    30733035 * @param string $cachekey The cache key generated in BP_Embed::parse_oembed().
    3074  *
    30753036 * @return mixed The cached embeds for this activity item.
    30763037 */
    … …  
    30933054 * @param string $cachekey The cache key generated in BP_Embed::parse_oembed().
    30943055 * @param int    $id       The ID of the activity item.
    3095  *
    3096  * @return bool True on success, false on failure.
    30973056 */
    30983057function bp_embed_activity_save_cache( $cache, $cachekey, $id ) {
Note: See TracChangeset for help on using the changeset viewer.