Skip to:
Content

BuddyPress.org

Changeset 12851


Ignore:
Timestamp:
02/21/2021 08:10:55 PM (5 years ago)
Author:
imath
Message:

The new_avatar activity belongs to the Members component

The activity generated when members add/update their profile photo wasn't migrated to the Members component during the 6.0.0 milestone. This commit's goal is to repare this oversight.

See #8156
See #8407
Fixes #8408

Location:
trunk
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-update.php

    r12617 r12851  
    274274                        bp_update_to_5_0();
    275275                }
     276
     277                // Version 8.0.0.
     278                if ( $raw_db_version < 12850 ) {
     279                        bp_update_to_8_0();
     280                }
    276281        }
    277282
     
    591596
    592597/**
     598 * 8.0.0 update routine.
     599 *
     600 * - Edit the `new_avatar` activity type's component to `members`.
     601 *
     602 * @since 8.0.0
     603 */
     604function bp_update_to_8_0() {
     605        global $wpdb;
     606        $bp_prefix = bp_core_get_table_prefix();
     607
     608        // Update the `new_avatar` activity type's component to `members`.
     609        $wpdb->update(
     610                $bp_prefix . 'bp_activity',
     611                array(
     612                        'component' => 'members',
     613                ),
     614                array(
     615                        'type' => 'new_avatar',
     616                ),
     617                array(
     618                        '%s',
     619                ),
     620                array(
     621                        '%s',
     622                )
     623        );
     624}
     625
     626/**
    593627 * Updates the component field for new_members type.
    594628 *
  • trunk/src/bp-members/bp-members-activity.php

    r12591 r12851  
    2626                __( 'New Members', 'buddypress' ),
    2727                array( 'activity' )
     28        );
     29
     30        // Register the activity stream actions for this component.
     31        bp_activity_set_action(
     32                // Older avatar activity items use 'profile' for component. See r4273.
     33                buddypress()->members->id,
     34                'new_avatar',
     35                __( 'Member changed profile picture', 'buddypress' ),
     36                'bp_members_format_activity_action_new_avatar',
     37                __( 'Updated Profile Photos', 'buddypress' )
    2838        );
    2939
     
    6979
    7080/**
     81 * Format 'new_avatar' activity actions.
     82 *
     83 * @since 8.0.0
     84 *
     85 * @param string $action   Static activity action.
     86 * @param object $activity Activity object.
     87 * @return string
     88 */
     89function bp_members_format_activity_action_new_avatar( $action, $activity ) {
     90        $userlink = bp_core_get_userlink( $activity->user_id );
     91
     92        /* translators: %s: user link */
     93        $action = sprintf( esc_html__( '%s changed their profile picture', 'buddypress' ), $userlink );
     94
     95        // Legacy filter - pass $user_id instead of $activity.
     96        if ( has_filter( 'bp_xprofile_new_avatar_action' ) ) {
     97                $action = apply_filters( 'bp_xprofile_new_avatar_action', $action, $activity->user_id );
     98        }
     99
     100        /** This filter is documented in wp-includes/deprecated.php */
     101        $action = apply_filters_deprecated( 'bp_xprofile_format_activity_action_new_avatar', array( $action, $activity ), '8.0.0', 'bp_members_format_activity_action_new_avatar' );
     102
     103        /**
     104         * Filters the formatted 'new_avatar' activity stream action.
     105         *
     106         * @since 8.0.0
     107         *
     108         * @param string $action   Formatted action for activity stream.
     109         * @param object $activity Activity object.
     110         */
     111        return apply_filters( 'bp_members_format_activity_action_new_avatar', $action, $activity );
     112}
     113
     114/**
    71115 * Create a "became a registered user" activity item when a user activates his account.
    72116 *
     
    98142}
    99143add_action( 'bp_core_activated_user', 'bp_core_new_user_activity' );
     144
     145/**
     146 * Adds an activity stream item when a user has uploaded a new avatar.
     147 *
     148 * @since 8.0.0
     149 *
     150 * @param int $user_id The user id the avatar was set for.
     151 */
     152function bp_members_new_avatar_activity( $user_id = 0 ) {
     153
     154        // Bail if activity component is not active.
     155        if ( ! bp_is_active( 'activity' ) ) {
     156                return false;
     157        }
     158
     159        if ( empty( $user_id ) ) {
     160                $user_id = bp_displayed_user_id();
     161        }
     162
     163        /** This filter is documented in wp-includes/deprecated.php */
     164        $user_id = apply_filters_deprecated( 'bp_xprofile_new_avatar_user_id', array( $user_id ), '8.0.0', 'bp_members_new_avatar_user_id' );
     165
     166        /**
     167         * Filters the user ID when a user has uploaded a new avatar.
     168         *
     169         * @since 8.0.0
     170         *
     171         * @param int $user_id ID of the user the avatar was set for.
     172         */
     173        $user_id = apply_filters( 'bp_members_new_avatar_user_id', $user_id );
     174
     175        // Add the activity.
     176        bp_activity_add( array(
     177                'user_id'   => $user_id,
     178                'component' => buddypress()->members->id,
     179                'type'      => 'new_avatar'
     180        ) );
     181}
     182add_action( 'bp_members_avatar_uploaded', 'bp_members_new_avatar_activity' );
  • trunk/src/bp-xprofile/bp-xprofile-activity.php

    r12812 r12851  
    2121 */
    2222function xprofile_register_activity_actions() {
    23 
    24         // Register the activity stream actions for this component.
    25         bp_activity_set_action(
    26                 // Older avatar activity items use 'profile' for component. See r4273.
    27                 'profile',
    28                 'new_avatar',
    29                 __( 'Member changed profile picture', 'buddypress' ),
    30                 'bp_xprofile_format_activity_action_new_avatar',
    31                 __( 'Updated Profile Photos', 'buddypress' )
    32         );
    3323
    3424        bp_activity_set_action(
     
    4939}
    5040add_action( 'bp_register_activity_actions', 'xprofile_register_activity_actions' );
    51 
    52 /**
    53  * Format 'new_avatar' activity actions.
    54  *
    55  * @since 2.0.0
    56  *
    57  * @param string $action   Static activity action.
    58  * @param object $activity Activity object.
    59  * @return string
    60  */
    61 function bp_xprofile_format_activity_action_new_avatar( $action, $activity ) {
    62         $userlink = bp_core_get_userlink( $activity->user_id );
    63 
    64         /* translators: %s: user link */
    65         $action = sprintf( esc_html__( '%s changed their profile picture', 'buddypress' ), $userlink );
    66 
    67         // Legacy filter - pass $user_id instead of $activity.
    68         if ( has_filter( 'bp_xprofile_new_avatar_action' ) ) {
    69                 $action = apply_filters( 'bp_xprofile_new_avatar_action', $action, $activity->user_id );
    70         }
    71 
    72         /**
    73          * Filters the formatted 'new_avatar' activity stream action.
    74          *
    75          * @since 2.0.0
    76          *
    77          * @param string $action   Formatted action for activity stream.
    78          * @param object $activity Activity object.
    79          */
    80         return apply_filters( 'bp_xprofile_format_activity_action_new_avatar', $action, $activity );
    81 }
    8241
    8342/**
     
    201160
    202161/**
    203  * Adds an activity stream item when a user has uploaded a new avatar.
    204  *
    205  * @since 1.0.0
    206  * @since 2.3.4 Add new parameter to get the user id the avatar was set for.
    207  *
    208  *                         specific activity
    209  *
    210  * @param int $user_id The user id the avatar was set for.
    211  * @return bool
    212  */
    213 function bp_xprofile_new_avatar_activity( $user_id = 0 ) {
    214 
    215         // Bail if activity component is not active.
    216         if ( ! bp_is_active( 'activity' ) ) {
    217                 return false;
    218         }
    219 
    220         if ( empty( $user_id ) ) {
    221                 $user_id = bp_displayed_user_id();
    222         }
    223 
    224         /**
    225          * Filters the user ID when a user has uploaded a new avatar.
    226          *
    227          * @since 1.5.0
    228          *
    229          * @param int $user_id ID of the user the avatar was set for.
    230          */
    231         $user_id = apply_filters( 'bp_xprofile_new_avatar_user_id', $user_id );
    232 
    233         // Add the activity.
    234         bp_activity_add( array(
    235                 'user_id'   => $user_id,
    236                 'component' => 'profile',
    237                 'type'      => 'new_avatar'
    238         ) );
    239 }
    240 add_action( 'bp_members_avatar_uploaded', 'bp_xprofile_new_avatar_activity' );
    241 
    242 /**
    243162 * Add an activity item when a user has updated his profile.
    244163 *
  • trunk/src/class-buddypress.php

    r12821 r12851  
    305305
    306306                $this->version    = '8.0.0-alpha';
    307                 $this->db_version = 12385;
     307                $this->db_version = 12850;
    308308
    309309                /** Loading ***********************************************************/
  • trunk/tests/phpunit/testcases/members/activity.php

    r11737 r12851  
    2020
    2121                $expected = sprintf( __( '%s became a registered member', 'buddypress' ), bp_core_get_userlink( $u ) );
     22
     23                $a_obj = new BP_Activity_Activity( $a );
     24
     25                $this->assertSame( $expected, $a_obj->action );
     26        }
     27
     28        /**
     29         * @group activity_action
     30         * @group bp_members_format_activity_action_new_avatar
     31         */
     32        public function test_bp_members_format_activity_action_new_avatar() {
     33                $u = self::factory()->user->create();
     34                $a = self::factory()->activity->create( array(
     35                        'component' => 'members',
     36                        'type' => 'new_avatar',
     37                        'user_id' => $u,
     38                ) );
     39
     40                $expected = sprintf( __( '%s changed their profile picture', 'buddypress' ), bp_core_get_userlink( $u ) );
    2241
    2342                $a_obj = new BP_Activity_Activity( $a );
  • trunk/tests/phpunit/testcases/xprofile/activity.php

    r12599 r12851  
    297297        /**
    298298         * @group activity_action
    299          * @group bp_xprofile_format_activity_action_new_avatar
    300          */
    301         public function test_bp_xprofile_format_activity_action_new_avatar() {
    302                 $u = self::factory()->user->create();
    303                 $a = self::factory()->activity->create( array(
    304                         'component' => 'profile',
    305                         'type' => 'new_avatar',
    306                         'user_id' => $u,
    307                 ) );
    308 
    309                 $expected = sprintf( __( '%s changed their profile picture', 'buddypress' ), bp_core_get_userlink( $u ) );
    310 
    311                 $a_obj = new BP_Activity_Activity( $a );
    312 
    313                 $this->assertSame( $expected, $a_obj->action );
    314         }
    315 
    316         /**
    317          * @group activity_action
    318299         * @group bp_xprofile_format_activity_action_updated_profile
    319300         */
Note: See TracChangeset for help on using the changeset viewer.