Skip to:
Content

BuddyPress.org

Ticket #8408: 8408.patch

File 8408.patch, 11.5 KB (added by imath, 10 months ago)
  • src/bp-core/bp-core-update.php

    diff --git src/bp-core/bp-core-update.php src/bp-core/bp-core-update.php
    index eda45ead0..eedf3a1f3 100644
    function bp_version_updater() { 
    273273                if ( $raw_db_version < 12385 ) {
    274274                        bp_update_to_5_0();
    275275                }
     276
     277                // Version 8.0.0.
     278                if ( $raw_db_version < 12836 ) {
     279                        bp_update_to_8_0();
     280                }
    276281        }
    277282
    278283        /* All done! *************************************************************/
    function bp_update_to_5_0() { 
    589594        }
    590595}
    591596
     597/**
     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
    592626/**
    593627 * Updates the component field for new_members type.
    594628 *
  • new file src/bp-core/deprecated/8.0.php

    diff --git src/bp-core/deprecated/8.0.php src/bp-core/deprecated/8.0.php
    new file mode 100644
    index 000000000..acee31af0
    - +  
     1<?php
     2
     3/**
     4 * Deprecated functions.
     5 *
     6 * @deprecated 8.0.0
     7 */
     8
     9// Exit if accessed directly.
     10defined( 'ABSPATH' ) || exit;
     11
     12/**
     13 * Format 'new_avatar' activity actions.
     14 *
     15 * @since 2.0.0
     16 * @deprecated 8.0.0
     17 *
     18 * @param string $action   Static activity action.
     19 * @param object $activity Activity object.
     20 * @return string
     21 */
     22function bp_xprofile_format_activity_action_new_avatar( $action, $activity ) {
     23        _deprecated_function( __FUNCTION__, '8.0.0', 'bp_members_format_activity_action_new_avatar()' );
     24        return bp_members_format_activity_action_new_avatar( $action, $activity );
     25}
     26
     27/**
     28 * Adds an activity stream item when a user has uploaded a new avatar.
     29 *
     30 * @since 1.0.0
     31 * @since 2.3.4 Add new parameter to get the user id the avatar was set for.
     32 * @deprecated 8.0.0
     33 *
     34 * @param int $user_id The user id the avatar was set for.
     35 * @return bool
     36 */
     37function bp_xprofile_new_avatar_activity( $user_id = 0 ) {
     38        _deprecated_function( __FUNCTION__, '8.0.0', 'bp_members_new_avatar_activity()' );
     39        return bp_members_new_avatar_activity( $user_id );
     40}
  • src/bp-members/bp-members-activity.php

    diff --git src/bp-members/bp-members-activity.php src/bp-members/bp-members-activity.php
    index 30775dd6d..8907d0a7e 100644
    function bp_members_register_activity_actions() { 
    2727                array( 'activity' )
    2828        );
    2929
     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' )
     38        );
     39
    3040        /**
    3141         * Fires after the default 'new member' activity types are registered.
    3242         *
    function bp_members_format_activity_action_new_member( $action, $activity ) { 
    6777        return apply_filters( 'bp_members_format_activity_action_new_member', $action, $activity );
    6878}
    6979
     80/**
     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
    70114/**
    71115 * Create a "became a registered user" activity item when a user activates his account.
    72116 *
    function bp_core_new_user_activity( $user ) { 
    97141        ) );
    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' );
  • src/bp-xprofile/bp-xprofile-activity.php

    diff --git src/bp-xprofile/bp-xprofile-activity.php src/bp-xprofile/bp-xprofile-activity.php
    index 1adfae605..1e007dde4 100644
    defined( 'ABSPATH' ) || exit; 
    2121 */
    2222function xprofile_register_activity_actions() {
    2323
    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         );
    33 
    3424        bp_activity_set_action(
    3525                buddypress()->profile->id,
    3626                'updated_profile',
    function xprofile_register_activity_actions() { 
    4939}
    5040add_action( 'bp_register_activity_actions', 'xprofile_register_activity_actions' );
    5141
    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 }
    82 
    8342/**
    8443 * Format 'updated_profile' activity actions.
    8544 *
    function xprofile_register_activity_action( $key, $value ) { 
    199158        return apply_filters( 'xprofile_register_activity_action', bp_activity_set_action( buddypress()->profile->id, $key, $value ), $key, $value );
    200159}
    201160
    202 /**
    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 
    242161/**
    243162 * Add an activity item when a user has updated his profile.
    244163 *
  • src/class-buddypress.php

    diff --git src/class-buddypress.php src/class-buddypress.php
    index aad6f163b..6d93bc2e4 100644
    class BuddyPress { 
    304304                /** Versions **********************************************************/
    305305
    306306                $this->version    = '8.0.0-alpha';
    307                 $this->db_version = 12385;
     307                $this->db_version = 12836;
    308308
    309309                /** Loading ***********************************************************/
    310310
  • tests/phpunit/testcases/members/activity.php

    diff --git tests/phpunit/testcases/members/activity.php tests/phpunit/testcases/members/activity.php
    index a4a48e395..07ec30406 100644
    class BP_Tests_Members_Activity extends BP_UnitTestCase { 
    2525                $this->assertSame( $expected, $a_obj->action );
    2626        }
    2727
     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 ) );
     41
     42                $a_obj = new BP_Activity_Activity( $a );
     43
     44                $this->assertSame( $expected, $a_obj->action );
     45        }
     46
    2847        /**
    2948         * @group bp_migrate_new_member_activity_component
    3049         */
  • tests/phpunit/testcases/xprofile/activity.php

    diff --git tests/phpunit/testcases/xprofile/activity.php tests/phpunit/testcases/xprofile/activity.php
    index 7a1b42db2..ee0e5e9cb 100644
    class BP_Tests_XProfile_Activity extends BP_UnitTestCase { 
    294294                $this->assertTrue( bp_xprofile_updated_profile_activity( $d['u'], array( $d['f'] ), false, $old_values, $new_values ) );
    295295        }
    296296
    297         /**
    298          * @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 
    316297        /**
    317298         * @group activity_action
    318299         * @group bp_xprofile_format_activity_action_updated_profile