Skip to:
Content

BuddyPress.org

Ticket #5807: 5807.02.patch

File 5807.02.patch, 12.6 KB (added by imath, 7 years ago)
  • src/bp-activity/bp-activity-classes.php

    diff --git src/bp-activity/bp-activity-classes.php src/bp-activity/bp-activity-classes.php
    index 9b9131a..e393f61 100644
    class BP_Activity_Activity { 
    418418                        $excluded_types[] = 'last_activity';
    419419                }
    420420
    421                 // Exclude 'new_member' items if xprofile component is not active
    422                 if ( ! bp_is_active( 'xprofile' ) ) {
    423                         $excluded_types[] = 'new_member';
    424                 }
    425 
    426421                // Build the excluded type sql part
    427422                if ( ! empty( $excluded_types ) ) {
    428423                        $not_in = "'" . implode( "', '", esc_sql( $excluded_types ) ) . "'";
  • src/bp-core/bp-core-update.php

    diff --git src/bp-core/bp-core-update.php src/bp-core/bp-core-update.php
    index 1adb022..8c6099b 100644
    function bp_update_to_2_0_1() { 
    398398 * 2.2.0 update routine.
    399399 *
    400400 * - Add messages meta table
     401 * - Update the component field of the 'new members' activity type
    401402 *
    402403 * @since BuddyPress (2.2.0)
    403404 */
    function bp_update_to_2_2() { 
    405406        if ( bp_is_active( 'messages' ) ) {
    406407                bp_core_install_private_messaging();
    407408        }
     409
     410        if ( bp_is_active( 'activity' ) ) {
     411                bp_members_migrate_new_member_activity_component();
     412        }
    408413}
    409414
    410415/**
  • src/bp-core/deprecated/2.2.php

    diff --git src/bp-core/deprecated/2.2.php src/bp-core/deprecated/2.2.php
    index acfd25e..084b372 100644
    function bp_blogs_update_post( $post ) { 
    6363        _deprecated_function( __FUNCTION__, '2.2', 'bp_activity_post_type_update()' );
    6464        bp_activity_post_type_update( $post );
    6565}
     66
     67/**
     68 * Format 'new_member' activity actions.
     69 *
     70 * @since BuddyPress (2.0.0)
     71 * @deprecated BuddyPress (2.2.0)
     72 *
     73 * @param string $action Static activity action.
     74 * @param object $activity Activity object.
     75 * @return string
     76 */
     77function bp_xprofile_format_activity_action_new_member( $action, $activity ) {
     78        _deprecated_function( __FUNCTION__, '2.2', 'bp_members_format_activity_action_new_member()' );
     79
     80        $action = apply_filters( 'bp_xprofile_format_activity_action_new_member', $action, $activity );
     81        return bp_members_format_activity_action_new_member( $action, $activity );
     82}
  • src/bp-members/bp-members-activity.php

    diff --git src/bp-members/bp-members-activity.php src/bp-members/bp-members-activity.php
    index e69de29..b500860 100644
     
     1<?php
     2
     3/**
     4 * BuddyPress Member Activity
     5 *
     6 * @package BuddyPress
     7 * @subpackage MembersActivity
     8 */
     9
     10// Exit if accessed directly
     11if ( ! defined( 'ABSPATH' ) ) exit;
     12
     13/**
     14 * Register the 'new member' activity type
     15 *
     16 * @since  BuddyPress (2.2.0)
     17 *
     18 * @uses bp_activity_set_action()
     19 * @uses buddypress()
     20 */
     21function bp_members_register_activity_actions() {
     22
     23        bp_activity_set_action(
     24                buddypress()->members->id,
     25                'new_member',
     26                __( 'New member registered', 'buddypress' ),
     27                'bp_members_format_activity_action_new_member',
     28                __( 'New Members', 'buddypress' ),
     29                array( 'activity' )
     30        );
     31
     32        do_action( 'bp_members_register_activity_actions' );
     33}
     34add_action( 'bp_register_activity_actions', 'bp_members_register_activity_actions' );
     35
     36/**
     37 * Format 'new_member' activity actions.
     38 *
     39 * @since BuddyPress (2.2.0)
     40 *
     41 * @param string $action Static activity action.
     42 * @param object $activity Activity object.
     43 * @return string
     44 */
     45function bp_members_format_activity_action_new_member( $action, $activity ) {
     46        $userlink = bp_core_get_userlink( $activity->user_id );
     47        $action   = sprintf( __( '%s became a registered member', 'buddypress' ), $userlink );
     48
     49        // Legacy filter - pass $user_id instead of $activity
     50        if ( has_filter( 'bp_core_activity_registered_member_action' ) ) {
     51                $action = apply_filters( 'bp_core_activity_registered_member_action', $action, $activity->user_id );
     52        }
     53
     54        return apply_filters( 'bp_members_format_activity_action_new_member', $action, $activity );
     55}
     56
     57/**
     58 * Create a "became a registered user" activity item when a user activates his account.
     59 *
     60 * @param array $user Array of userdata passed to bp_core_activated_user hook.
     61 */
     62function bp_core_new_user_activity( $user ) {
     63        if ( empty( $user ) ) {
     64                return false;
     65        }
     66
     67        if ( is_array( $user ) ) {
     68                $user_id = $user['user_id'];
     69        } else {
     70                $user_id = $user;
     71        }
     72
     73        if ( empty( $user_id ) ) {
     74                return false;
     75        }
     76
     77        bp_activity_add( array(
     78                'user_id'   => $user_id,
     79                'component' => buddypress()->members->id,
     80                'type'      => 'new_member'
     81        ) );
     82}
     83add_action( 'bp_core_activated_user', 'bp_core_new_user_activity' );
     84
     85/**
     86 * Updates the component field for new_members type.
     87 *
     88 * @since BuddyPress (2.2.0)
     89 *
     90 * @global $wpdb
     91 * @uses   buddypress()
     92 *
     93 */
     94function bp_members_migrate_new_member_activity_component() {
     95        global $wpdb;
     96        $bp = buddypress();
     97
     98        // Update the component for the new_member type
     99        $wpdb->update(
     100                // Activity table
     101                $bp->members->table_name_last_activity,
     102                array(
     103                        'component' => $bp->members->id,
     104                ),
     105                array(
     106                        'component' => $bp->profile->id,
     107                        'type'      => 'new_member',
     108                ),
     109                // Data sanitization format
     110                array(
     111                        '%s',
     112                ),
     113                // WHERE sanitization format
     114                array(
     115                        '%s',
     116                        '%s'
     117                )
     118        );
     119}
  • src/bp-members/bp-members-functions.php

    diff --git src/bp-members/bp-members-functions.php src/bp-members/bp-members-functions.php
    index a1e3cad..f4124e5 100644
    function bp_members_migrate_signups() { 
    18451845}
    18461846
    18471847/**
    1848  * Create a "became a registered user" activity item when a user activates his account.
    1849  *
    1850  * @param array $user Array of userdata passed to bp_core_activated_user hook.
    1851  */
    1852 function bp_core_new_user_activity( $user ) {
    1853         if ( empty( $user ) || ! bp_is_active( 'activity' ) || ! bp_is_active( 'xprofile' ) ) {
    1854                 return false;
    1855         }
    1856 
    1857         if ( is_array( $user ) ) {
    1858                 $user_id = $user['user_id'];
    1859         } else {
    1860                 $user_id = $user;
    1861         }
    1862 
    1863         if ( empty( $user_id ) ) {
    1864                 return false;
    1865         }
    1866 
    1867         bp_activity_add( array(
    1868                 'user_id'   => $user_id,
    1869                 'component' => 'xprofile',
    1870                 'type'      => 'new_member'
    1871         ) );
    1872 }
    1873 add_action( 'bp_core_activated_user', 'bp_core_new_user_activity' );
    1874 
    1875 /**
    18761848 * Map a user's WP display name to the XProfile fullname field, if necessary.
    18771849 *
    18781850 * This only happens when a user is registered in wp-admin by an administrator;
  • src/bp-members/bp-members-loader.php

    diff --git src/bp-members/bp-members-loader.php src/bp-members/bp-members-loader.php
    index 1ab4a64..ea79560 100644
    class BP_Members_Component extends BP_Component { 
    4848                        'functions'
    4949                );
    5050
     51                if ( bp_is_active( 'activity' ) ) {
     52                        $includes[] = 'activity';
     53                }
     54
    5155                // Include these only if in admin
    5256                if ( is_admin() ) {
    5357                        $includes[] = 'admin';
  • src/bp-xprofile/bp-xprofile-activity.php

    diff --git src/bp-xprofile/bp-xprofile-activity.php src/bp-xprofile/bp-xprofile-activity.php
    index 82c147a..d53b536 100644
    function xprofile_register_activity_actions() { 
    3333                __( 'Updated Profile Photos', 'buddypress' )
    3434        );
    3535
    36         // Get the profile component ID
    37         $profile_id = buddypress()->profile->id;
    38 
    39         bp_activity_set_action(
    40                 $profile_id,
    41                 'new_member',
    42                 __( 'New member registered', 'buddypress' ),
    43                 'bp_xprofile_format_activity_action_new_member',
    44                 __( 'New Members', 'buddypress' ),
    45                 array( 'activity' )
    46         );
    47 
    4836        bp_activity_set_action(
    49                 $profile_id,
     37                buddypress()->profile->id,
    5038                'updated_profile',
    5139                __( 'Updated Profile', 'buddypress' ),
    5240                'bp_xprofile_format_activity_action_updated_profile',
    function bp_xprofile_format_activity_action_new_avatar( $action, $activity ) { 
    8068}
    8169
    8270/**
    83  * Format 'new_member' activity actions.
    84  *
    85  * @since BuddyPress (2.0.0)
    86  *
    87  * @param string $action Static activity action.
    88  * @param object $activity Activity object.
    89  * @return string
    90  */
    91 function bp_xprofile_format_activity_action_new_member( $action, $activity ) {
    92         $userlink = bp_core_get_userlink( $activity->user_id );
    93         $action   = sprintf( __( '%s became a registered member', 'buddypress' ), $userlink );
    94 
    95         // Legacy filter - pass $user_id instead of $activity
    96         if ( has_filter( 'bp_core_activity_registered_member_action' ) ) {
    97                 $action = apply_filters( 'bp_core_activity_registered_member_action', $action, $activity->user_id );
    98         }
    99 
    100         return apply_filters( 'bp_xprofile_format_activity_action_new_member', $action, $activity );
    101 }
    102 
    103 /**
    10471 * Format 'updated_profile' activity actions.
    10572 *
    10673 * @since BuddyPress (2.0.0)
  • tests/phpunit/testcases/members/activity.php

    diff --git tests/phpunit/testcases/members/activity.php tests/phpunit/testcases/members/activity.php
    index e69de29..f8719f4 100644
     
     1<?php
     2
     3/**
     4 * @group members
     5 * @group activity
     6 */
     7class BP_Tests_Members_Activity extends BP_UnitTestCase {
     8
     9        /**
     10         * @group activity_action
     11         * @group bp_core_format_activity_action_new_member
     12         */
     13        public function test_bp_members_format_activity_action_new_member() {
     14                $u = $this->factory->user->create();
     15                $a = $this->factory->activity->create( array(
     16                        'component' => buddypress()->members->id,
     17                        'type' => 'new_member',
     18                        'user_id' => $u,
     19                ) );
     20
     21                $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 bp_core_migrate_new_member_activity_component
     30         */
     31        public function test_bp_members_migrate_new_member_activity_component() {
     32                global $wpdb;
     33                $bp = buddypress();
     34
     35                $u1 = $this->factory->user->create();
     36                $u2 = $this->factory->user->create();
     37                $u3 = $this->factory->user->create();
     38
     39                $au1 = $this->factory->activity->create( array(
     40                        'component' => 'xprofile',
     41                        'type' => 'new_member',
     42                        'user_id' => $u1,
     43                ) );
     44
     45                $au2 = $this->factory->activity->create( array(
     46                        'component' => 'xprofile',
     47                        'type' => 'new_member',
     48                        'user_id' => $u2,
     49                ) );
     50
     51                $au3 = $this->factory->activity->create( array(
     52                        'component' => 'xprofile',
     53                        'type' => 'new_member',
     54                        'user_id' => $u3,
     55                ) );
     56
     57                bp_members_migrate_new_member_activity_component();
     58
     59                $expected = array(
     60                        $u1 => $au1,
     61                        $u2 => $au2,
     62                        $u3 => $au3,
     63                );
     64
     65                $in = "'" . implode( "', '", array_keys( $expected ) ) . "'";
     66                $found = $wpdb->get_results(
     67                        $wpdb->prepare(
     68                                "SELECT user_id, id FROM {$bp->members->table_name_last_activity} WHERE component = %s AND type = %s AND user_id IN ({$in}) ORDER BY user_id ASC",
     69                                $bp->members->id,
     70                                'new_member'
     71                ), OBJECT_K );
     72
     73                $found = array_map( 'intval', wp_list_pluck( $found, 'id' ) );
     74
     75                $this->assertSame( $expected, $found );
     76        }
     77}
  • tests/phpunit/testcases/xprofile/activity.php

    diff --git tests/phpunit/testcases/xprofile/activity.php tests/phpunit/testcases/xprofile/activity.php
    index 0368270..05d29e6 100644
    class BP_Tests_XProfile_Activity extends BP_UnitTestCase { 
    293293
    294294        /**
    295295         * @group activity_action
    296          * @group bp_xprofile_format_activity_action_new_member
    297          */
    298         public function test_bp_xprofile_format_activity_action_new_member_xprofile_on() {
    299                 $active = bp_is_active( 'xprofile' );
    300                 buddypress()->active_components['xprofile'] = '1';
    301 
    302                 $u = $this->factory->user->create();
    303                 $a = $this->factory->activity->create( array(
    304                         'component' => buddypress()->profile->id,
    305                         'type' => 'new_member',
    306                         'user_id' => $u,
    307                 ) );
    308 
    309                 $expected = sprintf( __( '%s became a registered member', '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                 if ( ! $active ) {
    316                         unset( buddypress()->active_components['xprofile'] );
    317                 }
    318         }
    319 
    320         /**
    321          * @group activity_action
    322          * @group bp_xprofile_format_activity_action_new_member
    323          */
    324         public function test_bp_xprofile_format_activity_action_new_member_xprofile_off() {
    325                 $active = bp_is_active( 'xprofile' );
    326                 unset( buddypress()->active_components['xprofile'] );
    327 
    328                 $u = $this->factory->user->create();
    329                 $a = $this->factory->activity->create( array(
    330                         'component' => buddypress()->profile->id,
    331                         'type' => 'new_member',
    332                         'user_id' => $u,
    333                 ) );
    334 
    335                 $expected = sprintf( __( '%s became a registered member', 'buddypress' ), bp_core_get_userlink( $u ) );
    336 
    337                 $a_obj = new BP_Activity_Activity( $a );
    338 
    339                 $this->assertSame( $expected, $a_obj->action );
    340 
    341                 if ( $active ) {
    342                         buddypress()->active_components['xprofile'] = '1';
    343                 }
    344         }
    345 
    346         /**
    347          * @group activity_action
    348296         * @group bp_xprofile_format_activity_action_updated_profile
    349297         */
    350298        public function test_bp_xprofile_format_activity_action_updated_profile() {