Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
03/13/2014 07:05:27 PM (13 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

File:
1 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 );
Note: See TracChangeset for help on using the changeset viewer.