Skip to:
Content

BuddyPress.org

Changeset 8125


Ignore:
Timestamp:
03/13/2014 06:34:06 PM (6 years ago)
Author:
boonebgorges
Message:

Generate activity actions dynamically, instead of using static values stored in the database

Activity actions - like 'Joe became a registered member' - have always been
stored as static strings in the activity table. This has been a perennial thorn
in the side of BP site administrators. For one thing, static strings cannot be
translated for multilingual audiences (without unreasonable workarounds).
For another, information in these static strings becomes out of date as users
change their display names, groups change their names, and so on.

This changeset makes it possible for activity types to be registered with a
new $format_callback function, passed to bp_activity_set_action(), which BP
will use to generate the action dynamically when building the activity loop.
This makes the activity stream fully localizable, continually up-to-date, and
generally the bomb dot com.

Existing plugins that do not register format_callback functions will continue
to have their actions pulled directly from the database. Likewise, since a copy
of the static string is saved in the activity table, static strings can be
served if the given component is disabled at any point (and thus the callback
is no longer available).

The original argument for caching the action strings was that generating them
inline was too resource intensive; it often requires pulling up display names,
user permalinks, group links, blog post names, and so forth. To address this
problem, each component can now prefetch required data at the beginning of an
activity loop by hooking to bp_activity_prefetch_object_data, and loading any
relevant data into the cache. The Activity, Friends, Groups, and Blogs
component now do this natively. It's likely that this prefetching will have
other performance benefits, as plugin authors will now be able to access user
data etc inline without performance penalties.

The case of the Blogs component is a special one; it's not practical to
prefetch data from multiple blogs at the beginning of a loop, due to the
resources required by switch_to_blog(). For this reason, the format_callback
functions in the blog component cache some relevant data (like the post name)
in blogmeta, where it's readily accessible within the loop.

Fixes #3856

Location:
trunk
Files:
3 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-classes.php

    r8075 r8125  
    161161            $this->mptt_right        = $row->mptt_right;
    162162            $this->is_spam           = $row->is_spam;
     163        }
     164
     165        // Generate dynamic 'action' when possible
     166        $action = bp_activity_generate_action_string( $this );
     167        if ( false !== $action ) {
     168            $this->action = $action;
     169
     170        // If no callback is available, use the literal string from
     171        // the database row
     172        } else if ( ! empty( $row->action ) ) {
     173            $this->action = $row->action;
     174
     175        // Provide a fallback to avoid PHP notices
     176        } else {
     177            $this->action = '';
    163178        }
    164179    }
     
    443458            $activities = BP_Activity_Activity::append_comments( $activities, $spam );
    444459
     460        // Pre-fetch data associated with activity users and other objects
     461        BP_Activity_Activity::prefetch_object_data( $activities );
     462
     463        // Generate action strings
     464        $activities = BP_Activity_Activity::generate_action_strings( $activities );
     465
    445466        // If $max is set, only return up to the max results
    446467        if ( !empty( $max ) ) {
     
    540561                }
    541562            }
     563        }
     564
     565        return $activities;
     566    }
     567
     568    /**
     569     * Pre-fetch data for objects associated with activity items.
     570     *
     571     * Activity items are associated with users, and often with other
     572     * BuddyPress data objects. Here, we pre-fetch data about these
     573     * associated objects, so that inline lookups - done primarily when
     574     * building action strings - do not result in excess database queries.
     575     *
     576     * The only object data required for activity component activity types
     577     * (activity_update and activity_comment) is related to users, and that
     578     * info is fetched separately in BP_Activity_Activity::get_activity_data().
     579     * So this method contains nothing but a filter that allows other
     580     * components, such as bp-friends and bp-groups, to hook in and prime
     581     * their own caches at the beginning of an activity loop.
     582     *
     583     * @since BuddyPress (2.0.0)
     584     *
     585     * @param array $activities Array of activities.
     586     */
     587    protected static function prefetch_object_data( $activities ) {
     588        return apply_filters( 'bp_activity_prefetch_object_data', $activities );
     589    }
     590
     591    /**
     592     * Generate action strings for the activities located in BP_Activity_Activity::get().
     593     *
     594     * If no string can be dynamically generated for a given item
     595     * (typically because the activity type has not been properly
     596     * registered), the static 'action' value pulled from the database will
     597     * be left in place.
     598     *
     599     * @since BuddyPress (2.0.0)
     600     *
     601     * @param array $activities Array of activities.
     602     * @return array
     603     */
     604    protected static function generate_action_strings( $activities ) {
     605        foreach ( $activities as $key => $activity ) {
     606            $generated_action = bp_activity_generate_action_string( $activity );
     607            if ( false !== $generated_action ) {
     608                $activity->action = $generated_action;
     609            }
     610
     611            $activities[ $key ] = $activity;
    542612        }
    543613
  • trunk/bp-activity/bp-activity-functions.php

    r8076 r8125  
    257257
    258258/**
    259  * Set the current action for a given activity stream location.
    260  *
    261  * @since BuddyPress (1.1)
    262  *
    263  * @global object $bp BuddyPress global settings
    264  * @uses apply_filters() To call the 'bp_activity_set_action' hook
     259 * Register an activity 'type' and its action description/callback.
     260 *
     261 * Activity actions are strings used to describe items in the activity stream,
     262 * such as 'Joe became a registered member' or 'Bill and Susie are now
     263 * friends'. Each activity type (such as 'new_member' or 'friendship_created')
     264 * used by a component should be registered using this function.
     265 *
     266 * While it's possible to post items to the activity stream whose types are
     267 * not registered using bp_activity_set_action(), it is not recommended;
     268 * unregistered types will not be displayed properly in the activity admin
     269 * panel, and dynamic action generation (which is essential for multilingual
     270 * sites, etc) will not work.
     271 *
     272 * @since BuddyPress (1.1.0)
    265273 *
    266274 * @param string $component_id The unique string ID of the component.
    267  * @param string $key The action key.
    268  * @param string $value The action value.
     275 * @param string $type The action type.
     276 * @param string $description The action description.
     277 * @param callable $format_callback Callback for formatting the action string.
    269278 * @return bool False if any param is empty, otherwise true.
    270279 */
    271 function bp_activity_set_action( $component_id, $key, $value ) {
    272     global $bp;
     280function bp_activity_set_action( $component_id, $type, $description, $format_callback = false ) {
     281    $bp = buddypress();
    273282
    274283    // Return false if any of the above values are not set
    275     if ( empty( $component_id ) || empty( $key ) || empty( $value ) )
    276         return false;
     284    if ( empty( $component_id ) || empty( $type ) || empty( $description ) ) {
     285        return false;
     286    }
    277287
    278288    // Set activity action
    279     if ( !isset( $bp->activity->actions ) || !is_object( $bp->activity->actions ) ) {
     289    if ( ! isset( $bp->activity->actions ) || ! is_object( $bp->activity->actions ) ) {
    280290        $bp->activity->actions = new stdClass;
    281291    }
    282292
    283     if ( !isset( $bp->activity->actions->{$component_id} ) || !is_object( $bp->activity->actions->{$component_id} ) ) {
     293    // Verify callback
     294    if ( ! is_callable( $format_callback ) ) {
     295        $format_callback = '';
     296    }
     297
     298    if ( ! isset( $bp->activity->actions->{$component_id} ) || ! is_object( $bp->activity->actions->{$component_id} ) ) {
    284299        $bp->activity->actions->{$component_id} = new stdClass;
    285300    }
    286301
    287     $bp->activity->actions->{$component_id}->{$key} = apply_filters( 'bp_activity_set_action', array(
    288         'key'   => $key,
    289         'value' => $value
    290     ), $component_id, $key, $value );
     302    $bp->activity->actions->{$component_id}->{$type} = apply_filters( 'bp_activity_set_action', array(
     303        'key'             => $type,
     304        'value'           => $description,
     305        'format_callback' => $format_callback,
     306    ), $component_id, $type, $description, $format_callback );
    291307
    292308    return true;
     
    858874    global $bp;
    859875
    860     bp_activity_set_action( $bp->activity->id, 'activity_update', __( 'Posted a status update', 'buddypress' ) );
    861     bp_activity_set_action( $bp->activity->id, 'activity_comment', __( 'Replied to a status update', 'buddypress' ) );
     876    bp_activity_set_action(
     877        $bp->activity->id,
     878        'activity_update',
     879        __( 'Posted a status update', 'buddypress' ),
     880        'bp_activity_format_activity_action_activity_update'
     881    );
     882
     883    bp_activity_set_action(
     884        $bp->activity->id,
     885        'activity_comment',
     886        __( 'Replied to a status update', 'buddypress' ),
     887        'bp_activity_format_activity_action_activity_comment'
     888    );
    862889
    863890    do_action( 'bp_activity_register_activity_actions' );
     
    867894}
    868895add_action( 'bp_register_activity_actions', 'bp_activity_register_activity_actions' );
     896
     897/**
     898 * Generate an activity action string for an activity item.
     899 *
     900 * @param object $activity Activity data object.
     901 * @return string|bool Returns false if no callback is found, otherwise returns
     902 *         the formatted action string.
     903 */
     904function bp_activity_generate_action_string( $activity ) {
     905    // Check for valid input
     906    if ( empty( $activity->component ) || empty( $activity->type ) ) {
     907        return false;
     908    }
     909
     910    // Check for registered format callback
     911    if ( empty( buddypress()->activity->actions->{$activity->component}->{$activity->type}['format_callback'] ) ) {
     912        return false;
     913    }
     914
     915    return call_user_func( buddypress()->activity->actions->{$activity->component}->{$activity->type}['format_callback'], $activity );
     916}
     917
     918/**
     919 * Format 'activity_update' activity actions.
     920 *
     921 * @since BuddyPress (2.0.0)
     922 *
     923 * @param object $activity Activity data object.
     924 * @return string
     925 */
     926function bp_activity_format_activity_action_activity_update( $activity ) {
     927    $action = sprintf( __( '%s posted an update', 'buddypress' ), bp_core_get_userlink( $activity->user_id ) );
     928    return apply_filters( 'bp_activity_new_update_action', $action, $activity );
     929}
     930
     931/**
     932 * Format 'activity_comment' activity actions.
     933 *
     934 * @since BuddyPress (2.0.0)
     935 *
     936 * @param object $activity Activity data object.
     937 * @return string
     938 */
     939function bp_activity_format_activity_action_activity_comment( $activity ) {
     940    $action = sprintf( __( '%s posted a new activity comment', 'buddypress' ), bp_core_get_userlink( $activity->user_id ) );
     941    return apply_filters( 'bp_activity_comment_action', $action, $activity );
     942}
    869943
    870944/******************************************************************************
     
    10321106 *           false to create a new item. Default: false.
    10331107 *     @type string $action Optional. The activity action/description, typically
    1034  *           something like "Joe posted an update".
     1108 *           something like "Joe posted an update". Values passed to this param
     1109 *           will be stored in the database and used as a fallback for when the
     1110 *           activity item's format_callback cannot be found (eg, when the
     1111 *           component is disabled). As long as you have registered a
     1112 *           format_callback for your $type, it is unnecessary to include this
     1113 *           argument - BP will generate it automatically.
     1114 *           See {@link bp_activity_set_action()}.
    10351115 *     @type string $content Optional. The content of the activity item.
    10361116 *     @type string $component The unique name of the component associated with
     
    10881168    $activity->component         = $component;
    10891169    $activity->type              = $type;
    1090     $activity->action            = $action;
    10911170    $activity->content           = $content;
    10921171    $activity->primary_link      = $primary_link;
     
    10961175    $activity->hide_sitewide     = $hide_sitewide;
    10971176    $activity->is_spam           = $is_spam;
     1177    $activity->action            = ! empty( $action ) ? $action : bp_activity_generate_action_string( $activity );
    10981178
    10991179    if ( !$activity->save() )
     
    11511231    // Record this on the user's profile
    11521232    $from_user_link   = bp_core_get_userlink( $user_id );
    1153     $activity_action  = sprintf( __( '%s posted an update', 'buddypress' ), $from_user_link );
    11541233    $activity_content = $content;
    11551234    $primary_link     = bp_core_get_userlink( $user_id, false, true );
     
    11581237    $activity_id = bp_activity_add( array(
    11591238        'user_id'      => $user_id,
    1160         'action'       => apply_filters( 'bp_activity_new_update_action', $activity_action ),
    11611239        'content'      => apply_filters( 'bp_activity_new_update_content', $activity_content ),
    11621240        'primary_link' => apply_filters( 'bp_activity_new_update_primary_link', $primary_link ),
    11631241        'component'    => $bp->activity->id,
    1164         'type'         => 'activity_update'
     1242        'type'         => 'activity_update',
    11651243    ) );
    11661244
     
    12311309    $comment_id = bp_activity_add( array(
    12321310        'id'                => $id,
    1233         'action'            => apply_filters( 'bp_activity_comment_action', sprintf( __( '%s posted a new activity comment', 'buddypress' ), bp_core_get_userlink( $user_id ) ) ),
    12341311        'content'           => apply_filters( 'bp_activity_comment_content', $content ),
    12351312        'component'         => buddypress()->activity->id,
  • trunk/bp-blogs/bp-blogs-activity.php

    r7555 r8125  
    2929
    3030    if ( is_multisite() ) {
    31         bp_activity_set_action( $bp->blogs->id, 'new_blog', __( 'New site created',        'buddypress' ) );
    32     }
    33 
    34     bp_activity_set_action( $bp->blogs->id, 'new_blog_post',    __( 'New post published',      'buddypress' ) );
    35     bp_activity_set_action( $bp->blogs->id, 'new_blog_comment', __( 'New post comment posted', 'buddypress' ) );
     31        bp_activity_set_action(
     32            $bp->blogs->id,
     33            'new_blog',
     34            __( 'New site created', 'buddypress' ),
     35            'bp_blogs_format_activity_action_new_blog'
     36        );
     37    }
     38
     39    bp_activity_set_action(
     40        $bp->blogs->id,
     41        'new_blog_post',
     42        __( 'New post published', 'buddypress' ),
     43        'bp_blogs_format_activity_action_new_blog_post'
     44    );
     45
     46    bp_activity_set_action(
     47        $bp->blogs->id,
     48        'new_blog_comment',
     49        __( 'New post comment posted', 'buddypress' ),
     50        'bp_blogs_format_activity_action_new_blog_comment'
     51    );
    3652
    3753    do_action( 'bp_blogs_register_activity_actions' );
    3854}
    3955add_action( 'bp_register_activity_actions', 'bp_blogs_register_activity_actions' );
     56
     57/**
     58 * Format 'new_blog' activity actions.
     59 *
     60 * @since BuddyPress (2.0.0)
     61 *
     62 * @param obj $activity Activity data object.
     63 */
     64function bp_blogs_format_activity_action_new_blog( $activity ) {
     65    $blog_url  = bp_blogs_get_blogmeta( $activity->item_id, 'url' );
     66    $blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' );
     67
     68    $action = sprintf( __( '%s created the site %s', 'buddypress' ), bp_core_get_userlink( $activity->user_id ), '<a href="' . esc_url( $blog_url ) . '">' . esc_html( $blog_name ) . '</a>' );
     69
     70    // Legacy filter - requires the BP_Blogs_Blog object
     71    if ( has_filter( 'bp_blogs_activity_created_blog_action' ) ) {
     72        $user_blog = BP_Blogs_Blog::get_user_blog( $activity->user_id, $activity->item_id );
     73        if ( $user_blog ) {
     74            $recorded_blog = new BP_Blogs_Blog( $user_blog );
     75        }
     76
     77        if ( isset( $recorded_blog ) ) {
     78            $action = apply_filters( 'bp_blogs_activity_created_blog_action', $action, $recorded_blog, $blog_name, bp_blogs_get_blogmeta( $activity->item_id, 'description' ) );
     79        }
     80    }
     81
     82    return apply_filters( 'bp_blogs_format_activity_action_new_blog', $action, $activity );
     83}
     84
     85/**
     86 * Format 'new_blog_post' activity actions.
     87 *
     88 * @since BuddyPress (2.0.0)
     89 *
     90 * @param obj $activity Activity data object.
     91 */
     92function bp_blogs_format_activity_action_new_blog_post( $activity ) {
     93    $blog_url  = bp_blogs_get_blogmeta( $activity->item_id, 'url' );
     94    $blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' );
     95
     96    if ( empty( $blog_url ) || empty( $blog_name ) ) {
     97        $blog_url  = get_home_url( $activity->item_id );
     98        $blog_name = get_blog_option( $activity->item_id, 'blogname' );
     99
     100        bp_blogs_update_blogmeta( $activity->item_id, 'url', $blog_url );
     101        bp_blogs_update_blogmeta( $activity->item_id, 'name', $blog_name );
     102    }
     103
     104    $post_url = add_query_arg( 'p', $activity->secondary_item_id, trailingslashit( $blog_url ) );
     105
     106    $post_title = bp_activity_get_meta( $activity->id, 'post_title' );
     107
     108    // Should only be empty at the time of post creation
     109    if ( empty( $post_title ) ) {
     110        switch_to_blog( $activity->item_id );
     111
     112        $post = get_post( $activity->secondary_item_id );
     113        if ( is_a( $post, 'WP_Post' ) ) {
     114            $post_title = $post->post_title;
     115            bp_activity_update_meta( $activity->id, 'post_title', $post_title );
     116        }
     117
     118        restore_current_blog();
     119    }
     120
     121    $post_link  = '<a href="' . $post_url . '">' . $post_title . '</a>';
     122
     123    $user_link = bp_core_get_userlink( $activity->user_id );
     124
     125    if ( is_multisite() ) {
     126        $action  = sprintf( __( '%1$s wrote a new post, %2$s, on the site %3$s', 'buddypress' ), $user_link, $post_link, '<a href="' . esc_url( $blog_url ) . '">' . esc_html( $blog_name ) . '</a>' );
     127    } else {
     128        $action  = sprintf( __( '%1$s wrote a new post, %2$s', 'buddypress' ), $user_link, $post_link );
     129    }
     130
     131    // Legacy filter - requires the post object
     132    if ( has_filter( 'bp_blogs_activity_new_post_action' ) ) {
     133        switch_to_blog( $activity->item_id );
     134        $post = get_post( $activity->secondary_item_id );
     135        restore_current_blog();
     136
     137        if ( ! empty( $post ) && ! is_wp_error( $post ) ) {
     138            $action = apply_filters( 'bp_blogs_activity_new_post_action', $action, $post, $post_url );
     139        }
     140    }
     141
     142    return apply_filters( 'bp_blogs_format_activity_action_new_blog_post', $action, $activity );
     143}
     144
     145/**
     146 * Format 'new_blog_comment' activity actions.
     147 *
     148 * @since BuddyPress (2.0.0)
     149 *
     150 * @param obj $activity Activity data object.
     151 */
     152function bp_blogs_format_activity_action_new_blog_comment( $activity ) {
     153    $blog_url  = bp_blogs_get_blogmeta( $activity->item_id, 'url' );
     154    $blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' );
     155
     156    if ( empty( $blog_url ) || empty( $blog_name ) ) {
     157        $blog_url  = get_home_url( $activity->item_id );
     158        $blog_name = get_blog_option( $activity->item_id, 'blogname' );
     159
     160        bp_blogs_update_blogmeta( $activity->item_id, 'url', $blog_url );
     161        bp_blogs_update_blogmeta( $activity->item_id, 'name', $blog_name );
     162    }
     163
     164    $post_url   = bp_activity_get_meta( $activity->id, 'post_url' );
     165    $post_title = bp_activity_get_meta( $activity->id, 'post_title' );
     166
     167    // Should only be empty at the time of post creation
     168    if ( empty( $post_url ) || empty( $post_title ) ) {
     169        switch_to_blog( $activity->item_id );
     170
     171        $comment = get_comment( $activity->secondary_item_id );
     172
     173        if ( ! empty( $comment->comment_post_ID ) ) {
     174            $post_url = add_query_arg( 'p', $comment->comment_post_ID, trailingslashit( $blog_url ) );
     175            bp_activity_update_meta( $activity->id, 'post_url', $post_url );
     176
     177            $post = get_post( $comment->comment_post_ID );
     178
     179            if ( is_a( $post, 'WP_Post' ) ) {
     180                $post_title = $post->post_title;
     181                bp_activity_update_meta( $activity->id, 'post_title', $post_title );
     182            }
     183        }
     184
     185        restore_current_blog();
     186    }
     187
     188    $post_link = '<a href="' . $post_url . '">' . $post_title . '</a>';
     189    $user_link = bp_core_get_userlink( $activity->user_id );
     190
     191    if ( is_multisite() ) {
     192        $action  = sprintf( __( '%1$s commented on the post, %2$s, on the site %3$s', 'buddypress' ), $user_link, $post_link, '<a href="' . esc_url( $blog_url ) . '">' . esc_html( $blog_name ) . '</a>' );
     193    } else {
     194        $action  = sprintf( __( '%1$s commented on the post, %2$s', 'buddypress' ), $user_link, $post_link );
     195    }
     196
     197    // Legacy filter - requires the comment object
     198    if ( has_filter( 'bp_blogs_activity_new_comment_action' ) ) {
     199        switch_to_blog( $activity->item_id );
     200        $comment = get_comment( $activity->secondary_item_id );
     201        restore_current_blog();
     202
     203        if ( ! empty( $comment ) && ! is_wp_error( $comment ) ) {
     204            $action = apply_filters( 'bp_blogs_activity_new_comment_action', $action, $comment, $post_url . '#' . $activity->secondary_item_id );
     205        }
     206    }
     207
     208    return apply_filters( 'bp_blogs_format_activity_action_new_blog_comment', $action, $activity );
     209}
     210
     211/**
     212 * Fetch data related to blogs at the beginning of an activity loop.
     213 *
     214 * This reduces database overhead during the activity loop.
     215 *
     216 * @since BuddyPress (2.0.0)
     217 *
     218 * @param array $activities Array of activity items.
     219 * @return array
     220 */
     221function bp_blogs_prefetch_activity_object_data( $activities ) {
     222    if ( empty( $activities ) ) {
     223        return $activities;
     224    }
     225
     226    $blog_ids = array();
     227
     228    foreach ( $activities as $activity ) {
     229        if ( buddypress()->blogs->id !== $activity->component ) {
     230            continue;
     231        }
     232
     233        $blog_ids[] = $activity->item_id;
     234    }
     235
     236    if ( ! empty( $blog_ids ) ) {
     237        bp_blogs_update_meta_cache( $blog_ids );
     238    }
     239}
     240add_filter( 'bp_activity_prefetch_object_data', 'bp_blogs_prefetch_activity_object_data' );
    40241
    41242/**
  • trunk/bp-blogs/bp-blogs-classes.php

    r8042 r8125  
    504504        return false;
    505505    }
     506
     507    /**
     508     * Get ID of user-blog link.
     509     *
     510     * @param int $user_id ID of user.
     511     * @param int $blog_id ID of blog.
     512     * @return int|bool ID of user-blog link, or false if not found.
     513     */
     514    public static function get_user_blog( $user_id, $blog_id ) {
     515        global $bp, $wpdb;
     516
     517        $user_blog = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$bp->blogs->table_name} WHERE user_id = %d AND blog_id = %d", $user_id, $blog_id ) );
     518
     519        if ( empty( $user_blog ) ) {
     520            $user_blog = false;
     521        } else {
     522            $user_blog = intval( $user_blog );
     523        }
     524
     525        return $user_blog;
     526    }
    506527}
  • trunk/bp-blogs/bp-blogs-functions.php

    r8111 r8125  
    183183        return false;
    184184
     185    $url         = get_home_url( $blog_id );
    185186    $name        = get_blog_option( $blog_id, 'blogname' );
    186187    $description = get_blog_option( $blog_id, 'blogdescription' );
     
    195196    $is_recorded            = !empty( $recorded_blog_id ) ? true : false;
    196197
     198    bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'url', $url );
    197199    bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'name', $name );
    198200    bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'description', $description );
     
    208210        bp_blogs_record_activity( array(
    209211            'user_id'      => $recorded_blog->user_id,
    210             'action'       => apply_filters( 'bp_blogs_activity_created_blog_action', sprintf( __( '%s created the site %s', 'buddypress'), bp_core_get_userlink( $recorded_blog->user_id ), '<a href="' . get_home_url( $recorded_blog->blog_id ) . '">' . esc_attr( $name ) . '</a>' ), $recorded_blog, $name, $description ),
    211             'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', get_home_url( $recorded_blog->blog_id ), $recorded_blog->blog_id ),
     212            'primary_link' => apply_filters( 'bp_blogs_activity_created_blog_primary_link', $url, $recorded_blog->blog_id ),
    212213            'type'         => 'new_blog',
    213214            'item_id'      => $recorded_blog->blog_id
     
    358359            bp_blogs_record_activity( array(
    359360                'user_id'           => (int) $post->post_author,
    360                 'action'            => apply_filters( 'bp_blogs_activity_new_post_action',       $activity_action,  $post, $post_permalink ),
    361361                'content'           => apply_filters( 'bp_blogs_activity_new_post_content',      $activity_content, $post, $post_permalink ),
    362362                'primary_link'      => apply_filters( 'bp_blogs_activity_new_post_primary_link', $post_permalink,   $post_id               ),
     
    453453        bp_blogs_record_activity( array(
    454454            'user_id'           => $user_id,
    455             'action'            => apply_filters_ref_array( 'bp_blogs_activity_new_comment_action',       array( $activity_action,  &$recorded_comment, $comment_link ) ),
    456455            'content'           => apply_filters_ref_array( 'bp_blogs_activity_new_comment_content',      array( $activity_content, &$recorded_comment, $comment_link ) ),
    457456            'primary_link'      => apply_filters_ref_array( 'bp_blogs_activity_new_comment_primary_link', array( $comment_link,     &$recorded_comment                ) ),
  • trunk/bp-friends/bp-friends-activity.php

    r7629 r8125  
    9393
    9494    // These two added in BP 1.6
    95     bp_activity_set_action( $bp->friends->id, 'friendship_accepted', __( 'Friendships accepted', 'buddypress' ) );
    96     bp_activity_set_action( $bp->friends->id, 'friendship_created',  __( 'New friendships',      'buddypress' ) );
     95    bp_activity_set_action(
     96        $bp->friends->id,
     97        'friendship_accepted',
     98        __( 'Friendships accepted', 'buddypress' ),
     99        'bp_friends_format_activity_action_friendship_accepted'
     100    );
     101
     102    bp_activity_set_action(
     103        $bp->friends->id,
     104        'friendship_created',
     105        __( 'New friendships', 'buddypress' ),
     106        'bp_friends_format_activity_action_friendship_created'
     107    );
    97108
    98109    // < BP 1.6 backpat
     
    102113}
    103114add_action( 'bp_register_activity_actions', 'friends_register_activity_actions' );
     115
     116/**
     117 * Format 'friendship_accepted' activity actions.
     118 *
     119 * @since BuddyPress (2.0.0)
     120 *
     121 * @param object $activity Activity data.
     122 * @return string $action Formatted activity action.
     123 */
     124function bp_friends_format_activity_action_friendship_accepted( $activity ) {
     125    $initiator_link = bp_core_get_userlink( $activity->user_id );
     126    $friend_link    = bp_core_get_userlink( $activity->secondary_item_id );
     127
     128    $action = sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $initiator_link, $friend_link );
     129
     130    // Backward compatibility for legacy filter
     131    // The old filter has the $friendship object passed to it. We want to
     132    // avoid having to build this object if it's not necessary
     133    if ( has_filter( 'friends_activity_friendship_accepted_action' ) ) {
     134        $friendship = new BP_Friends_Friendship( $activity->item_id );
     135        $action     = apply_filters( 'friends_activity_friendsip_accepted_action', $action, $friendship );
     136    }
     137
     138    return apply_filters( 'bp_friends_format_activity_action_friendship_accepted', $action, $activity );
     139}
     140
     141/**
     142 * Format 'friendship_created' activity actions.
     143 *
     144 * @since BuddyPress (2.0.0)
     145 *
     146 * @param object $activity Activity data.
     147 * @return string $action Formatted activity action.
     148 */
     149function bp_friends_format_activity_action_friendship_created( $activity ) {
     150    $initiator_link = bp_core_get_userlink( $activity->user_id );
     151    $friend_link    = bp_core_get_userlink( $activity->secondary_item_id );
     152
     153    $action = sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $initiator_link, $friend_link );
     154
     155    // Backward compatibility for legacy filter
     156    // The old filter has the $friendship object passed to it. We want to
     157    // avoid having to build this object if it's not necessary
     158    if ( has_filter( 'friends_activity_friendship_accepted_action' ) ) {
     159        $friendship = new BP_Friends_Friendship( $activity->item_id );
     160        $action     = apply_filters( 'friends_activity_friendsip_accepted_action', $action, $friendship );
     161    }
     162
     163    return apply_filters( 'bp_friends_format_activity_action_friendship_created', $action, $activity );
     164}
     165
     166/**
     167 * Fetch data related to friended users at the beginning of an activity loop.
     168 *
     169 * This reduces database overhead during the activity loop.
     170 *
     171 * @since BuddyPress (2.0.0)
     172 *
     173 * @param array $activities Array of activity items.
     174 * @return array
     175 */
     176function bp_friends_prefetch_activity_object_data( $activities ) {
     177    if ( empty( $activities ) ) {
     178        return $activities;
     179    }
     180
     181    $friend_ids = array();
     182
     183    foreach ( $activities as $activity ) {
     184        if ( buddypress()->friends->id !== $activity->component ) {
     185            continue;
     186        }
     187
     188        $friend_ids[] = $activity->secondary_item_id;
     189    }
     190
     191    if ( ! empty( $friend_ids ) ) {
     192        // Fire a user query to prime user caches
     193        new BP_User_Query( array(
     194            'user_ids'          => $friend_ids,
     195            'populate_extras'   => false,
     196            'update_meta_cache' => false,
     197        ) );
     198    }
     199}
     200add_filter( 'bp_activity_prefetch_object_data', 'bp_friends_prefetch_activity_object_data' );
    104201
    105202/**
     
    129226        'user_id'           => $initiator_user_id,
    130227        'type'              => 'friendship_created',
    131         'action'            => apply_filters( 'friends_activity_friendship_accepted_action', sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $initiator_link, $friend_link ), $friendship ),
    132228        'item_id'           => $friendship_id,
    133229        'secondary_item_id' => $friend_user_id
     
    138234        'user_id'           => $friend_user_id,
    139235        'type'              => 'friendship_created',
    140         'action'            => apply_filters( 'friends_activity_friendship_accepted_action', sprintf( __( '%1$s and %2$s are now friends', 'buddypress' ), $friend_link, $initiator_link ), $friendship ),
    141236        'item_id'           => $friendship_id,
    142237        'secondary_item_id' => $initiator_user_id,
  • trunk/bp-groups/bp-groups-actions.php

    r8094 r8125  
    161161            // Once we compelete all steps, record the group creation in the activity stream.
    162162            groups_record_activity( array(
    163                 'action' => apply_filters( 'groups_activity_created_group_action', sprintf( __( '%1$s created the group %2$s', 'buddypress'), bp_core_get_userlink( bp_loggedin_user_id() ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' ) ),
    164163                'type' => 'created_group',
    165164                'item_id' => $bp->groups->new_group_id
  • trunk/bp-groups/bp-groups-activity.php

    r7624 r8125  
    2424    }
    2525
    26     bp_activity_set_action( $bp->groups->id, 'created_group',   __( 'Created a group',       'buddypress' ) );
    27     bp_activity_set_action( $bp->groups->id, 'joined_group',    __( 'Joined a group',        'buddypress' ) );
     26    bp_activity_set_action(
     27        $bp->groups->id,
     28        'created_group',
     29        __( 'Created a group', 'buddypress' ),
     30        'bp_groups_format_activity_action_created_group'
     31    );
     32
     33    bp_activity_set_action(
     34        $bp->groups->id,
     35        'joined_group',
     36        __( 'Joined a group', 'buddypress' ),
     37        'bp_groups_format_activity_action_joined_group'
     38    );
    2839
    2940    // These actions are for the legacy forums
     
    3849}
    3950add_action( 'bp_register_activity_actions', 'groups_register_activity_actions' );
     51
     52/**
     53 * Format 'created_group' activity actions.
     54 *
     55 * @since BuddyPress (2.0.0)
     56 *
     57 * @param object $activity Activity data object.
     58 * @return string
     59 */
     60function bp_groups_format_activity_action_created_group( $activity ) {
     61    $user_link = bp_core_get_userlink( $activity->user_id );
     62
     63    $group = groups_get_group( array(
     64        'group_id'        => $activity->item_id,
     65        'populate_extras' => false,
     66    ) );
     67    $group_link = '<a href="' . esc_url( bp_get_group_permalink( $group ) ) . '">' . esc_html( $group->name ) . '</a>';
     68
     69    $action = sprintf( __( '%1$s created the group %2$s', 'buddypress'), $user_link, $group_link );
     70
     71    return apply_filters( 'groups_activity_created_group_action', $action, $activity );
     72}
     73
     74/**
     75 * Format 'joined_group' activity actions.
     76 *
     77 * @since BuddyPress (2.0.0)
     78 *
     79 * @param object $activity Activity data object.
     80 * @return string
     81 */
     82function bp_groups_format_activity_action_joined_group( $activity ) {
     83    $user_link = bp_core_get_userlink( $activity->user_id );
     84
     85    $group = groups_get_group( array(
     86        'group_id'        => $activity->item_id,
     87        'populate_extras' => false,
     88    ) );
     89    $group_link = '<a href="' . esc_url( bp_get_group_permalink( $group ) ) . '">' . esc_html( $group->name ) . '</a>';
     90
     91    $action = sprintf( __( '%1$s joined the group %2$s', 'buddypress' ), $user_link, $group_link );
     92
     93    // Legacy filters (do not follow parameter patterns of other activity
     94    // action filters, and requires apply_filters_ref_array())
     95    if ( has_filter( 'groups_activity_membership_accepted_action' ) ) {
     96        $action = apply_filters_ref_array( 'groups_activity_membership_accepted_action', array( $action, $user_link, &$group ) );
     97    }
     98
     99    // Another legacy filter
     100    if ( has_filter( 'groups_activity_accepted_invite_action' ) ) {
     101        $action = apply_filters_ref_array( 'groups_activity_accepted_invite_action', array( $action, $activity->user_id, &$group ) );
     102    }
     103
     104    return apply_filters( 'bp_groups_format_activity_action_joined_group', $action, $activity );
     105}
     106
     107/**
     108 * Fetch data related to groups at the beginning of an activity loop.
     109 *
     110 * This reduces database overhead during the activity loop.
     111 *
     112 * @since BuddyPress (2.0.0)
     113 *
     114 * @param array $activities Array of activity items.
     115 * @return array
     116 */
     117function bp_groups_prefetch_activity_object_data( $activities ) {
     118    $group_ids = array();
     119
     120    if ( empty( $activities ) ) {
     121        return $activities;
     122    }
     123
     124    foreach ( $activities as $activity ) {
     125        if ( buddypress()->groups->id !== $activity->component ) {
     126            continue;
     127        }
     128
     129        $group_ids[] = $activity->item_id;
     130    }
     131
     132    if ( ! empty( $group_ids ) ) {
     133
     134        // TEMPORARY - Once the 'populate_extras' issue is solved
     135        // in the groups component, we can do this with groups_get_groups()
     136        // rather than manually
     137        $uncached_ids = array();
     138        foreach ( $group_ids as $group_id ) {
     139            if ( false === wp_cache_get( $group_id, 'bp_groups' ) ) {
     140                $uncached_ids[] = $group_id;
     141            }
     142        }
     143
     144        global $wpdb, $bp;
     145        $uncached_ids_sql = implode( ',', wp_parse_id_list( $uncached_ids ) );
     146        $groups = $wpdb->get_results( "SELECT * FROM {$bp->groups->table_name} WHERE id IN ({$uncached_ids_sql})" );
     147        foreach ( $groups as $group ) {
     148            wp_cache_set( $group->id, $group, 'bp_groups' );
     149        }
     150    }
     151}
     152add_filter( 'bp_activity_prefetch_object_data', 'bp_groups_prefetch_activity_object_data' );
    40153
    41154/**
  • trunk/bp-groups/bp-groups-functions.php

    r8057 r8125  
    330330    // Record this in activity streams
    331331    groups_record_activity( array(
    332         'action'  => apply_filters( 'groups_activity_joined_group', sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( $user_id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( bp_get_group_name( $group ) ) . '</a>' ) ),
    333332        'type'    => 'joined_group',
    334333        'item_id' => $group_id,
    335         'user_id' => $user_id
     334        'user_id' => $user_id,
    336335    ) );
    337336
  • trunk/bp-groups/bp-groups-screens.php

    r8094 r8125  
    5050
    5151            groups_record_activity( array(
    52                 'action'  => apply_filters_ref_array( 'groups_activity_accepted_invite_action', array( sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( bp_loggedin_user_id() ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>' ), bp_loggedin_user_id(), &$group ) ),
    5352                'type'    => 'joined_group',
    5453                'item_id' => $group->id
  • trunk/bp-members/bp-members-functions.php

    r8124 r8125  
    16451645    bp_activity_add( array(
    16461646        'user_id'   => $user_id,
    1647         'action'    => apply_filters( 'bp_core_activity_registered_member_action', sprintf( __( '%s became a registered member', 'buddypress' ), $userlink ), $user_id ),
    16481647        'component' => 'xprofile',
    16491648        'type'      => 'new_member'
  • trunk/bp-xprofile/bp-xprofile-activity.php

    r7998 r8125  
    1818
    1919    // Register the activity stream actions for this component
    20     bp_activity_set_action( $bp->profile->id, 'new_avatar',      __( 'Member changed profile picture', 'buddypress' ) );
    21     bp_activity_set_action( $bp->profile->id, 'new_member',      __( 'New member registered', 'buddypress' ) );
    22     bp_activity_set_action( $bp->profile->id, 'updated_profile', __( 'Updated Profile', 'buddypress' ) );
     20    bp_activity_set_action(
     21        $bp->profile->id,
     22        'new_avatar',
     23        __( 'Member changed profile picture', 'buddypress' ),
     24        'bp_xprofile_format_activity_action_new_avatar'
     25    );
     26
     27    bp_activity_set_action(
     28        $bp->profile->id,
     29        'new_member',
     30        __( 'New member registered', 'buddypress' ),
     31        'bp_xprofile_format_activity_action_new_member'
     32    );
     33
     34    bp_activity_set_action(
     35        $bp->profile->id,
     36        'updated_profile',
     37        __( 'Updated Profile', 'buddypress' ),
     38        'bp_xprofile_format_activity_action_updated_profile'
     39    );
    2340
    2441    do_action( 'xprofile_register_activity_actions' );
    2542}
    2643add_action( 'bp_register_activity_actions', 'xprofile_register_activity_actions' );
     44
     45/**
     46 * Format 'new_avatar' activity actions.
     47 *
     48 * @since BuddyPress (2.0.0)
     49 *
     50 * @param object $activity Activity object.
     51 * @return string
     52 */
     53function bp_xprofile_format_activity_action_new_avatar( $activity ) {
     54    $userlink = bp_core_get_userlink( $activity->user_id );
     55    $action   = sprintf( __( '%s changed their profile picture', 'buddypress' ), $userlink );
     56
     57    // Legacy filter - pass $user_id instead of $activity
     58    if ( has_filter( 'bp_xprofile_new_avatar_action' ) ) {
     59        $action = apply_filters( 'bp_xprofile_new_avatar_action', $action, $activity->user_id );
     60    }
     61
     62    return apply_filters( 'bp_xprofile_format_activity_action_new_avatar', $action, $activity );
     63}
     64
     65/**
     66 * Format 'new_member' activity actions.
     67 *
     68 * @since BuddyPress (2.0.0)
     69 *
     70 * @param object $activity Activity object.
     71 * @return string
     72 */
     73function bp_xprofile_format_activity_action_new_member( $activity ) {
     74    $userlink = bp_core_get_userlink( $activity->user_id );
     75    $action   = sprintf( __( '%s became a registered member', 'buddypress' ), $userlink );
     76
     77    // Legacy filter - pass $user_id instead of $activity
     78    if ( has_filter( 'bp_core_activity_registered_member_action' ) ) {
     79        $action = apply_filters( 'bp_core_activity_registered_member_action', $action, $activity->user_id );
     80    }
     81
     82    return apply_filters( 'bp_xprofile_format_activity_action_new_member', $action, $activity );
     83}
     84
     85/**
     86 * Format 'updated_profile' activity actions.
     87 *
     88 * @since BuddyPress (2.0.0)
     89 *
     90 * @param object $activity Activity object.
     91 * @return string
     92 */
     93function bp_xprofile_format_activity_action_updated_profile( $activity ) {
     94    // Note for translators: The natural phrasing in English, "Joe updated
     95    // his profile", requires that we know Joe's gender, which we don't. If
     96    // your language doesn't have this restriction, feel free to use a more
     97    // natural translation.
     98    $profile_link = trailingslashit( bp_core_get_user_domain( $activity->user_id ) . buddypress()->profile->slug );
     99    $action       = sprintf( __( '%1$s&#8217;s profile was updated', 'buddypress' ), '<a href="' . $profile_link . '">' . bp_core_get_user_displayname( $activity->user_id ) . '</a>' );
     100
     101    return apply_filters( 'bp_xprofile_format_activity_action_updated_profile', $action, $activity );
     102}
    27103
    28104/**
     
    127203    bp_activity_add( array(
    128204        'user_id' => $user_id,
    129         'action' => apply_filters( 'bp_xprofile_new_avatar_action', sprintf( __( '%s changed their profile picture', 'buddypress' ), $userlink ), $user_id ),
    130205        'component' => 'profile',
    131206        'type' => 'new_avatar'
     
    208283
    209284    // 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.
    215285    $profile_link = trailingslashit( bp_core_get_user_domain( $user_id ) . buddypress()->profile->slug );
    216     $action = sprintf( __( '%1$s&#8217;s profile was updated', 'buddypress' ), '<a href="' . $profile_link . '">' . bp_core_get_user_displayname( $user_id ) . '</a>' );
    217286
    218287    $retval = xprofile_record_activity( array(
    219288        'user_id'      => $user_id,
    220         'action'       => $action,
    221289        'primary_link' => $profile_link,
    222290        'component'    => buddypress()->profile->id,
  • trunk/tests/includes/factory.php

    r8119 r8125  
    2121
    2222        $this->default_generation_definitions = array(
    23             'action'       => new WP_UnitTest_Generator_Sequence( 'Activity action %s' ),
    2423            'component'    => buddypress()->activity->id,
    2524            'content'      => new WP_UnitTest_Generator_Sequence( 'Activity content %s' ),
  • trunk/tests/testcases/activity/class.BP_Activity_Activity.php

    r8012 r8125  
    440440        $this->assertSame( date( 'Y-m-d H:i:s', $now - 100 ), BP_Activity_Activity::get_last_updated() );
    441441    }
     442
     443    /**
     444     * @group activity_action
     445     */
     446    public function test_instantiated_action_with_dynamic_callback() {
     447        bp_activity_set_action(
     448            'foo',
     449            'bar',
     450            'Foo Bar',
     451            array( $this, 'action_cb' )
     452        );
     453
     454        // Create the activity item with a manual activity string
     455        $a = $this->factory->activity->create( array(
     456            'component' => 'foo',
     457            'type' => 'bar',
     458            'action' => 'baz',
     459        ) );
     460
     461        $a_obj = new BP_Activity_Activity( $a );
     462
     463        $this->assertSame( 'Woo Hoo!', $a_obj->action );
     464    }
     465
     466    /**
     467     * @group activity_action
     468     */
     469    public function test_instantiated_action_without_dynamic_callback_but_with_stored_action() {
     470        // No callback is registered - this mimics a legacy plugin
     471
     472        // Create the activity item with a manual activity string
     473        $a = $this->factory->activity->create( array(
     474            'component' => 'foo',
     475            'type' => 'bar1',
     476            'action' => 'baz',
     477        ) );
     478
     479        $a_obj = new BP_Activity_Activity( $a );
     480
     481        $this->assertSame( 'baz', $a_obj->action );
     482    }
     483
     484    /**
     485     * @group activity_action
     486     */
     487    public function test_instantiated_action_without_dynamic_callback_but_with_no_stored_action() {
     488        // No callback is registered - this mimics a legacy plugin
     489
     490        // Create the activity item with a manual activity string
     491        $a = $this->factory->activity->create( array(
     492            'component' => 'foo',
     493            'type' => 'bar2',
     494        ) );
     495
     496        $a_obj = new BP_Activity_Activity( $a );
     497
     498        $this->assertSame( '', $a_obj->action );
     499    }
     500
     501    public function action_cb( $activity ) {
     502        return 'Woo Hoo!';
     503    }
    442504}
  • trunk/tests/testcases/activity/functions.php

    r8076 r8125  
    539539
    540540        remove_filter( 'bp_is_username_compatibility_mode', '__return_true' );
     541    }
     542
     543    /**
     544     * @group activity_action
     545     * @group bp_activity_format_activity_action_activity_update
     546     */
     547    public function test_bp_activity_format_activity_action_activity_update() {
     548        $u = $this->create_user();
     549        $a = $this->factory->activity->create( array(
     550            'component' => buddypress()->activity->id,
     551            'type' => 'activity_update',
     552            'user_id' => $u,
     553        ) );
     554
     555        $a_obj = new BP_Activity_Activity( $a );
     556
     557        $expected = sprintf( '%s posted an update', bp_core_get_userlink( $u ) );
     558
     559        $this->assertSame( $expected, $a_obj->action );
     560    }
     561
     562    /**
     563     * @group activity_action
     564     * @group bp_activity_format_activity_action_activity_comment
     565     */
     566    public function test_bp_activity_format_activity_action_activity_comment() {
     567        $u = $this->create_user();
     568        $a = $this->factory->activity->create( array(
     569            'component' => buddypress()->activity->id,
     570            'type' => 'activity_comment',
     571            'user_id' => $u,
     572        ) );
     573
     574        $a_obj = new BP_Activity_Activity( $a );
     575
     576        $expected = sprintf( '%s posted a new activity comment', bp_core_get_userlink( $u ) );
     577
     578        $this->assertSame( $expected, $a_obj->action );
    541579    }
    542580
  • trunk/tests/testcases/xprofile/activity.php

    r8016 r8125  
    271271    }
    272272
     273    /**
     274     * @group activity_action
     275     * @group bp_xprofile_format_activity_action_new_avatar
     276     */
     277    public function test_bp_xprofile_format_activity_action_new_avatar() {
     278        $u = $this->create_user();
     279        $a = $this->factory->activity->create( array(
     280            'component' => buddypress()->profile->id,
     281            'type' => 'new_avatar',
     282            'user_id' => $u,
     283        ) );
     284
     285        $expected = sprintf( __( '%s changed their profile picture', 'buddypress' ), bp_core_get_userlink( $u ) );
     286
     287        $a_obj = new BP_Activity_Activity( $a );
     288
     289        $this->assertSame( $expected, $a_obj->action );
     290    }
     291
     292    /**
     293     * @group activity_action
     294     * @group bp_xprofile_format_activity_action_new_member
     295     */
     296    public function test_bp_xprofile_format_activity_action_new_member_xprofile_on() {
     297        $active = bp_is_active( 'xprofile' );
     298        buddypress()->active_components['xprofile'] = '1';
     299
     300        $u = $this->create_user();
     301        $a = $this->factory->activity->create( array(
     302            'component' => buddypress()->profile->id,
     303            'type' => 'new_member',
     304            'user_id' => $u,
     305        ) );
     306
     307        $expected = sprintf( __( '%s became a registered member', 'buddypress' ), bp_core_get_userlink( $u ) );
     308
     309        $a_obj = new BP_Activity_Activity( $a );
     310
     311        $this->assertSame( $expected, $a_obj->action );
     312
     313        if ( ! $active ) {
     314            unset( buddypress()->active_components['xprofile'] );
     315        }
     316    }
     317
     318    /**
     319     * @group activity_action
     320     * @group bp_xprofile_format_activity_action_new_member
     321     */
     322    public function test_bp_xprofile_format_activity_action_new_member_xprofile_off() {
     323        $active = bp_is_active( 'xprofile' );
     324        unset( buddypress()->active_components['xprofile'] );
     325
     326        $u = $this->create_user();
     327        $a = $this->factory->activity->create( array(
     328            'component' => buddypress()->profile->id,
     329            'type' => 'new_member',
     330            'user_id' => $u,
     331        ) );
     332
     333        $expected = sprintf( __( '%s became a registered member', 'buddypress' ), bp_core_get_userlink( $u ) );
     334
     335        $a_obj = new BP_Activity_Activity( $a );
     336
     337        $this->assertSame( $expected, $a_obj->action );
     338
     339        if ( $active ) {
     340            buddypress()->active_components['xprofile'] = '1';
     341        }
     342    }
     343
     344    /**
     345     * @group activity_action
     346     * @group bp_xprofile_format_activity_action_updated_profile
     347     */
     348    public function test_bp_xprofile_format_activity_action_updated_profile() {
     349        $u = $this->create_user();
     350        $a = $this->factory->activity->create( array(
     351            'component' => buddypress()->profile->id,
     352            'type' => 'updated_profile',
     353            'user_id' => $u,
     354        ) );
     355
     356        $expected = sprintf( __( '%s&#8217;s profile was updated', 'buddypress' ), '<a href="' . bp_core_get_user_domain( $u ) . buddypress()->profile->slug . '/">' . bp_core_get_user_displayname( $u ) . '</a>' );
     357
     358        $a_obj = new BP_Activity_Activity( $a );
     359
     360        $this->assertSame( $expected, $a_obj->action );
     361    }
    273362
    274363    protected function setup_updated_profile_data() {
Note: See TracChangeset for help on using the changeset viewer.