Skip to:
Content

BuddyPress.org

Ticket #5807: 5807.move_new_member.patch

File 5807.move_new_member.patch, 12.6 KB (added by imath, 7 years 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 6b27154..2c5f276 100644
    function bp_version_updater() { 
    241241                if ( $raw_db_version < 8311 ) {
    242242                        bp_update_to_2_0_1();
    243243                }
     244
     245                // 2.1
     246                if ( $raw_db_version < 8320 ) {
     247                        bp_update_to_2_1();
     248                }
    244249        }
    245250
    246251        /** All done! *************************************************************/
    function bp_update_to_2_0_1() { 
    390395}
    391396
    392397/**
     398 * 2.1 database upgrade routine
     399 *
     400 * @since BuddyPress (2.1)
     401 *
     402 * @return void
     403 */
     404function bp_update_to_2_1() {
     405
     406        // Update the component field of the 'new members' activity type
     407        bp_core_migrate_new_member_activity_component();
     408}
     409
     410/**
    393411 * Redirect user to BP's What's New page on first page load after activation.
    394412 *
    395413 * @since BuddyPress (1.7.0)
  • src/bp-core/deprecated/2.1.php

    diff --git src/bp-core/deprecated/2.1.php src/bp-core/deprecated/2.1.php
    index 30f5f66..bf2a210 100644
    function bp_blogs_get_subdomain_base() { 
    623623        _deprecated_function( __FUNCTION__, '2.1', 'bp_signup_get_subdomain_base()' );
    624624        return bp_signup_get_subdomain_base();
    625625}
     626
     627/**
     628 * Format 'new_member' activity actions.
     629 *
     630 * @since BuddyPress (2.0.0)
     631 *
     632 * @param string $action Static activity action.
     633 * @param object $activity Activity object.
     634 * @return string
     635 *
     636 * @deprecated BuddyPress (2.1.0)
     637 */
     638function bp_xprofile_format_activity_action_new_member( $action, $activity ) {
     639        _deprecated_function( __FUNCTION__, '2.1', 'bp_xprofile_format_activity_action_new_member()' );
     640
     641        $action = apply_filters( 'bp_xprofile_format_activity_action_new_member', $action, $activity );
     642        return bp_core_format_activity_action_new_member( $action, $activity );
     643}
  • src/bp-loader.php

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

    diff --git src/bp-members/bp-members-functions.php src/bp-members/bp-members-functions.php
    index 145b52d..6237dc8 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' ) ) {
    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..b178dda 100644
    class BP_Members_Component extends BP_Component { 
    4040                // Always include these files
    4141                $includes = array(
    4242                        'actions',
     43                        'activity',
    4344                        'classes',
    4445                        'filters',
    4546                        'screens',
  • src/bp-xprofile/bp-xprofile-activity.php

    diff --git src/bp-xprofile/bp-xprofile-activity.php src/bp-xprofile/bp-xprofile-activity.php
    index 7949787..fb43422 100644
    function xprofile_register_activity_actions() { 
    2929
    3030        bp_activity_set_action(
    3131                $bp->profile->id,
    32                 'new_member',
    33                 __( 'New member registered', 'buddypress' ),
    34                 'bp_xprofile_format_activity_action_new_member',
    35                 __( 'New Members', 'buddypress' ),
    36                 array( 'activity' )
    37         );
    38 
    39         bp_activity_set_action(
    40                 $bp->profile->id,
    4132                'updated_profile',
    4233                __( 'Updated Profile', 'buddypress' ),
    4334                'bp_xprofile_format_activity_action_updated_profile',
    function bp_xprofile_format_activity_action_new_avatar( $action, $activity ) { 
    7162}
    7263
    7364/**
    74  * Format 'new_member' activity actions.
    75  *
    76  * @since BuddyPress (2.0.0)
    77  *
    78  * @param string $action Static activity action.
    79  * @param object $activity Activity object.
    80  * @return string
    81  */
    82 function bp_xprofile_format_activity_action_new_member( $action, $activity ) {
    83         $userlink = bp_core_get_userlink( $activity->user_id );
    84         $action   = sprintf( __( '%s became a registered member', 'buddypress' ), $userlink );
    85 
    86         // Legacy filter - pass $user_id instead of $activity
    87         if ( has_filter( 'bp_core_activity_registered_member_action' ) ) {
    88                 $action = apply_filters( 'bp_core_activity_registered_member_action', $action, $activity->user_id );
    89         }
    90 
    91         return apply_filters( 'bp_xprofile_format_activity_action_new_member', $action, $activity );
    92 }
    93 
    94 /**
    9565 * Format 'updated_profile' activity actions.
    9666 *
    9767 * @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..52f6f1b 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_core_format_activity_action_new_member() {
     14                $u = $this->create_user();
     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_core_migrate_new_member_activity_component() {
     32                global $wpdb;
     33                $bp = buddypress();
     34
     35                // We explicitly do not want new_member created, so use the
     36                // WP factory methods
     37                $u1 = $this->factory->user->create();
     38                $u2 = $this->factory->user->create();
     39                $u3 = $this->factory->user->create();
     40
     41                $au1 = $this->factory->activity->create( array(
     42                        'component' => 'xprofile',
     43                        'type' => 'new_member',
     44                        'user_id' => $u1,
     45                ) );
     46
     47                $au2 = $this->factory->activity->create( array(
     48                        'component' => 'xprofile',
     49                        'type' => 'new_member',
     50                        'user_id' => $u2,
     51                ) );
     52
     53                $au3 = $this->factory->activity->create( array(
     54                        'component' => 'xprofile',
     55                        'type' => 'new_member',
     56                        'user_id' => $u3,
     57                ) );
     58
     59                bp_core_migrate_new_member_activity_component();
     60
     61                $expected = array(
     62                        $u1 => $au1,
     63                        $u2 => $au1,
     64                        $u3 => $au2,
     65                );
     66
     67                $in = "'" . implode( "', '", array_keys( $expected ) ) . "'";
     68                $found = $wpdb->get_results(
     69                        $wpdb->prepare(
     70                                "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",
     71                                $bp->members->id,
     72                                'new_member'
     73                ), OBJECT_K );
     74
     75                $found = array_map( 'intval', wp_list_pluck( $found, 'id' ) );
     76
     77                $this->assertSame( $expected, $found );
     78        }
     79}
  • tests/phpunit/testcases/xprofile/activity.php

    diff --git tests/phpunit/testcases/xprofile/activity.php tests/phpunit/testcases/xprofile/activity.php
    index ccdc951..6d7b15d 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->create_user();
    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->create_user();
    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() {