Skip to:
Content

BuddyPress.org

Changeset 9273


Ignore:
Timestamp:
12/24/2014 04:35:52 AM (12 years ago)
Author:
imath
Message:

Move the 'new_member' activity type into the Members component

Since BuddyPress 1.1, the 'new_member' type was attached to the xProfile component. In version 2.2, we are moving it into the Members one. Once the user will have upgraded to this version, every existing 'new_member' activity items will have their component updated to the 'members' one and each time a new member will register, the 'new_member' activity will be attached to the members component.

Props boonebgorges, DJPaul

Fixes #5807

Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/bp-activity-classes.php

    r9263 r9273  
    434434                if ( empty( $r['filter']['object'] ) ) {
    435435                        $excluded_types[] = 'last_activity';
    436                 }
    437 
    438                 // Exclude 'new_member' items if xprofile component is not active
    439                 if ( ! bp_is_active( 'xprofile' ) ) {
    440                         $excluded_types[] = 'new_member';
    441436                }
    442437
  • trunk/src/bp-core/bp-core-update.php

    r9182 r9273  
    399399 *
    400400 * - Add messages meta table
     401 * - Update the component field of the 'new members' activity type
    401402 *
    402403 * @since BuddyPress (2.2.0)
     
    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' => 'xprofile',
     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
  • trunk/src/bp-core/deprecated/2.2.php

    r9251 r9273  
    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}
  • trunk/src/bp-members/bp-members-functions.php

    r9270 r9273  
    21262126
    21272127/**
    2128  * Create a "became a registered user" activity item when a user activates his account.
    2129  *
    2130  * @param array $user Array of userdata passed to bp_core_activated_user hook.
    2131  */
    2132 function bp_core_new_user_activity( $user ) {
    2133         if ( empty( $user ) || ! bp_is_active( 'activity' ) || ! bp_is_active( 'xprofile' ) ) {
    2134                 return false;
    2135         }
    2136 
    2137         if ( is_array( $user ) ) {
    2138                 $user_id = $user['user_id'];
    2139         } else {
    2140                 $user_id = $user;
    2141         }
    2142 
    2143         if ( empty( $user_id ) ) {
    2144                 return false;
    2145         }
    2146 
    2147         bp_activity_add( array(
    2148                 'user_id'   => $user_id,
    2149                 'component' => 'xprofile',
    2150                 'type'      => 'new_member'
    2151         ) );
    2152 }
    2153 add_action( 'bp_core_activated_user', 'bp_core_new_user_activity' );
    2154 
    2155 /**
    21562128 * Map a user's WP display name to the XProfile fullname field, if necessary.
    21572129 *
  • trunk/src/bp-members/bp-members-loader.php

    r9210 r9273  
    5959                        'cache',
    6060                );
     61
     62                if ( bp_is_active( 'activity' ) ) {
     63                        $includes[] = 'activity';
     64                }
    6165
    6266                // Include these only if in admin
  • trunk/src/bp-xprofile/bp-xprofile-activity.php

    r8814 r9273  
    3434        );
    3535
    36         // Get the profile component ID
    37         $profile_id = buddypress()->profile->id;
    38 
    3936        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 
    48         bp_activity_set_action(
    49                 $profile_id,
     37                buddypress()->profile->id,
    5038                'updated_profile',
    5139                __( 'Updated Profile', 'buddypress' ),
     
    7866
    7967        return apply_filters( 'bp_xprofile_format_activity_action_new_avatar', $action, $activity );
    80 }
    81 
    82 /**
    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 );
    10168}
    10269
  • trunk/tests/phpunit/testcases/xprofile/activity.php

    r9139 r9273  
    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         */
Note: See TracChangeset for help on using the changeset viewer.