Skip to:
Content

BuddyPress.org

Changeset 8126


Ignore:
Timestamp:
03/13/2014 07:05:27 PM (11 years ago)
Author:
boonebgorges
Message:

Use WP Plugin API rather than call_user_func() to apply format_callback to activity actions

This allows plugin authors to modify or override default formatting callbacks
using the standard remove_filter() and add_filter() API functions.

Hat-tip to nacin for the idea

See #3856

Location:
trunk
Files:
5 edited

Legend:

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

    r8125 r8126  
    913913    }
    914914
    915     return call_user_func( buddypress()->activity->actions->{$activity->component}->{$activity->type}['format_callback'], $activity );
     915    // We apply the format_callback as a filter
     916    add_filter( 'bp_activity_generate_action_string', buddypress()->activity->actions->{$activity->component}->{$activity->type}['format_callback'], 10, 2 );
     917
     918    // Generate the action string (run through the filter defined above)
     919    $action = apply_filters( 'bp_activity_generate_action_string', $activity->action, $activity );
     920
     921    // Remove the filter for future activity items
     922    remove_filter( 'bp_activity_generate_action_string', buddypress()->activity->actions->{$activity->component}->{$activity->type}['format_callback'], 10, 2 );
     923
     924    return $action;
    916925}
    917926
     
    921930 * @since BuddyPress (2.0.0)
    922931 *
     932 * @param string $action Static activity action.
    923933 * @param object $activity Activity data object.
    924934 * @return string
    925935 */
    926 function bp_activity_format_activity_action_activity_update( $activity ) {
     936function bp_activity_format_activity_action_activity_update( $action, $activity ) {
    927937    $action = sprintf( __( '%s posted an update', 'buddypress' ), bp_core_get_userlink( $activity->user_id ) );
    928938    return apply_filters( 'bp_activity_new_update_action', $action, $activity );
     
    934944 * @since BuddyPress (2.0.0)
    935945 *
     946 * @param string $action Static activity action.
    936947 * @param object $activity Activity data object.
    937948 * @return string
    938949 */
    939 function bp_activity_format_activity_action_activity_comment( $activity ) {
     950function bp_activity_format_activity_action_activity_comment( $action, $activity ) {
    940951    $action = sprintf( __( '%s posted a new activity comment', 'buddypress' ), bp_core_get_userlink( $activity->user_id ) );
    941952    return apply_filters( 'bp_activity_comment_action', $action, $activity );
  • trunk/bp-blogs/bp-blogs-activity.php

    r8125 r8126  
    6060 * @since BuddyPress (2.0.0)
    6161 *
     62 * @param string $action Static activity action.
    6263 * @param obj $activity Activity data object.
    6364 */
    64 function bp_blogs_format_activity_action_new_blog( $activity ) {
     65function bp_blogs_format_activity_action_new_blog( $action, $activity ) {
    6566    $blog_url  = bp_blogs_get_blogmeta( $activity->item_id, 'url' );
    6667    $blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' );
     
    8889 * @since BuddyPress (2.0.0)
    8990 *
     91 * @param string $action Static activity action.
    9092 * @param obj $activity Activity data object.
    9193 */
    92 function bp_blogs_format_activity_action_new_blog_post( $activity ) {
     94function bp_blogs_format_activity_action_new_blog_post( $action, $activity ) {
    9395    $blog_url  = bp_blogs_get_blogmeta( $activity->item_id, 'url' );
    9496    $blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' );
     
    148150 * @since BuddyPress (2.0.0)
    149151 *
     152 * @param string $action Static activity action.
    150153 * @param obj $activity Activity data object.
    151154 */
    152 function bp_blogs_format_activity_action_new_blog_comment( $activity ) {
     155function bp_blogs_format_activity_action_new_blog_comment( $action, $activity ) {
    153156    $blog_url  = bp_blogs_get_blogmeta( $activity->item_id, 'url' );
    154157    $blog_name = bp_blogs_get_blogmeta( $activity->item_id, 'name' );
  • trunk/bp-friends/bp-friends-activity.php

    r8125 r8126  
    122122 * @return string $action Formatted activity action.
    123123 */
    124 function bp_friends_format_activity_action_friendship_accepted( $activity ) {
     124function bp_friends_format_activity_action_friendship_accepted( $action, $activity ) {
    125125    $initiator_link = bp_core_get_userlink( $activity->user_id );
    126126    $friend_link    = bp_core_get_userlink( $activity->secondary_item_id );
     
    144144 * @since BuddyPress (2.0.0)
    145145 *
     146 * @param string $action Static activity action.
    146147 * @param object $activity Activity data.
    147148 * @return string $action Formatted activity action.
    148149 */
    149 function bp_friends_format_activity_action_friendship_created( $activity ) {
     150function bp_friends_format_activity_action_friendship_created( $action, $activity ) {
    150151    $initiator_link = bp_core_get_userlink( $activity->user_id );
    151152    $friend_link    = bp_core_get_userlink( $activity->secondary_item_id );
  • trunk/bp-groups/bp-groups-activity.php

    r8125 r8126  
    5555 * @since BuddyPress (2.0.0)
    5656 *
     57 * @param string $action Static activity action.
    5758 * @param object $activity Activity data object.
    5859 * @return string
    5960 */
    60 function bp_groups_format_activity_action_created_group( $activity ) {
     61function bp_groups_format_activity_action_created_group( $action, $activity ) {
    6162    $user_link = bp_core_get_userlink( $activity->user_id );
    6263
     
    7778 * @since BuddyPress (2.0.0)
    7879 *
     80 * @param string $action Static activity action.
    7981 * @param object $activity Activity data object.
    8082 * @return string
    8183 */
    82 function bp_groups_format_activity_action_joined_group( $activity ) {
     84function bp_groups_format_activity_action_joined_group( $action, $activity ) {
    8385    $user_link = bp_core_get_userlink( $activity->user_id );
    8486
  • trunk/bp-xprofile/bp-xprofile-activity.php

    r8125 r8126  
    4848 * @since BuddyPress (2.0.0)
    4949 *
     50 * @param string $action Static activity action.
    5051 * @param object $activity Activity object.
    5152 * @return string
    5253 */
    53 function bp_xprofile_format_activity_action_new_avatar( $activity ) {
     54function bp_xprofile_format_activity_action_new_avatar( $action, $activity ) {
    5455    $userlink = bp_core_get_userlink( $activity->user_id );
    5556    $action   = sprintf( __( '%s changed their profile picture', 'buddypress' ), $userlink );
     
    6869 * @since BuddyPress (2.0.0)
    6970 *
     71 * @param string $action Static activity action.
    7072 * @param object $activity Activity object.
    7173 * @return string
    7274 */
    73 function bp_xprofile_format_activity_action_new_member( $activity ) {
     75function bp_xprofile_format_activity_action_new_member( $action, $activity ) {
    7476    $userlink = bp_core_get_userlink( $activity->user_id );
    7577    $action   = sprintf( __( '%s became a registered member', 'buddypress' ), $userlink );
     
    8890 * @since BuddyPress (2.0.0)
    8991 *
     92 * @param string $action Static activity action.
    9093 * @param object $activity Activity object.
    9194 * @return string
    9295 */
    93 function bp_xprofile_format_activity_action_updated_profile( $activity ) {
     96function bp_xprofile_format_activity_action_updated_profile( $action, $activity ) {
    9497    // Note for translators: The natural phrasing in English, "Joe updated
    9598    // his profile", requires that we know Joe's gender, which we don't. If
Note: See TracChangeset for help on using the changeset viewer.