Skip to:
Content

BuddyPress.org

Ticket #5807: 5807.03.patch

File 5807.03.patch, 12.7 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 90aa677..3c3647a 100644
    class BP_Activity_Activity { 
    421421                        $excluded_types[] = 'last_activity';
    422422                }
    423423
    424                 // Exclude 'new_member' items if xprofile component is not active
    425                 if ( ! bp_is_active( 'xprofile' ) ) {
    426                         $excluded_types[] = 'new_member';
    427                 }
    428 
    429424                // Build the excluded type sql part
    430425                if ( ! empty( $excluded_types ) ) {
    431426                        $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..336e94f 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_migrate_new_member_activity_component();
     412        }
     413}
     414
     415/**
     416 * Updates the component field for new_members type.
     417 *
     418 * @since BuddyPress (2.2.0)
     419 *
     420 * @global $wpdb
     421 * @uses   buddypress()
     422 *
     423 */
     424function bp_migrate_new_member_activity_component() {
     425        global $wpdb;
     426        $bp = buddypress();
     427
     428        // Update the component for the new_member type
     429        $wpdb->update(
     430                // Activity table
     431                $bp->members->table_name_last_activity,
     432                array(
     433                        'component' => $bp->members->id,
     434                ),
     435                array(
     436                        'component' => $bp->profile->id,
     437                        'type'      => 'new_member',
     438                ),
     439                // Data sanitization format
     440                array(
     441                        '%s',
     442                ),
     443                // WHERE sanitization format
     444                array(
     445                        '%s',
     446                        '%s'
     447                )
     448        );
    408449}
    409450
    410451/**
  • src/bp-core/deprecated/2.2.php

    diff --git src/bp-core/deprecated/2.2.php src/bp-core/deprecated/2.2.php
    index 838e324..fdf0d5c 100644
    function bp_blogs_format_clear_blog_cache( $recorded_blog_obj ) { 
    7777        _deprecated_function( __FUNCTION__, '2.2', 'bp_blogs_clear_blog_object_cache()' );
    7878        bp_blogs_clear_blog_object_cache( false, $recorded_blog_obj->user_id );
    7979}
     80
     81/**
     82 * Format 'new_member' activity actions.
     83 *
     84 * @since BuddyPress (2.0.0)
     85 * @deprecated BuddyPress (2.2.0)
     86 *
     87 * @param string $action Static activity action.
     88 * @param object $activity Activity object.
     89 * @return string
     90 */
     91function bp_xprofile_format_activity_action_new_member( $action, $activity ) {
     92        _deprecated_function( __FUNCTION__, '2.2', 'bp_members_format_activity_action_new_member()' );
     93
     94        $action = apply_filters( 'bp_xprofile_format_activity_action_new_member', $action, $activity );
     95        return bp_members_format_activity_action_new_member( $action, $activity );
     96}
  • 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..5bf1518 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' );
  • src/bp-members/bp-members-functions.php

    diff --git src/bp-members/bp-members-functions.php src/bp-members/bp-members-functions.php
    index 0d7f141..80ee17d 100644
    function bp_members_migrate_signups() { 
    18471847}
    18481848
    18491849/**
    1850  * Create a "became a registered user" activity item when a user activates his account.
    1851  *
    1852  * @param array $user Array of userdata passed to bp_core_activated_user hook.
    1853  */
    1854 function bp_core_new_user_activity( $user ) {
    1855         if ( empty( $user ) || ! bp_is_active( 'activity' ) || ! bp_is_active( 'xprofile' ) ) {
    1856                 return false;
    1857         }
    1858 
    1859         if ( is_array( $user ) ) {
    1860                 $user_id = $user['user_id'];
    1861         } else {
    1862                 $user_id = $user;
    1863         }
    1864 
    1865         if ( empty( $user_id ) ) {
    1866                 return false;
    1867         }
    1868 
    1869         bp_activity_add( array(
    1870                 'user_id'   => $user_id,
    1871                 'component' => 'xprofile',
    1872                 'type'      => 'new_member'
    1873         ) );
    1874 }
    1875 add_action( 'bp_core_activated_user', 'bp_core_new_user_activity' );
    1876 
    1877 /**
    18781850 * Map a user's WP display name to the XProfile fullname field, if necessary.
    18791851 *
    18801852 * 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 53daef4..4856c25 100644
    class BP_Members_Component extends BP_Component { 
    5959                        'cache',
    6060                );
    6161
     62                if ( bp_is_active( 'activity' ) ) {
     63                        $includes[] = 'activity';
     64                }
     65
    6266                // Include these only if in admin
    6367                if ( is_admin() ) {
    6468                        $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..90ce67c 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_migrate_new_member_activity_component
     30         */
     31        public function test_bp_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_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() {