Skip to:
Content

BuddyPress.org

Changeset 11630


Ignore:
Timestamp:
07/07/2017 06:38:57 PM (7 years ago)
Author:
r-a-y
Message:

Activation: Ensure we use the XProfile field's default visibility level during activation.

Previously, if the visibility option for a XProfile field was removed from
the registration template, the visibility level for the user would always
fallback to 'public' instead of what the actual XProfile field's default
visibility level was.

Commit includes a unit test and rectifies the problem.

Props uscore713.

Fixes #7553 (trunk)

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-functions.php

    r11611 r11630  
    20732073                }
    20742074
    2075                 // Save the visibility level.
    2076                 $visibility_level = ! empty( $user['meta']['field_' . $field_id . '_visibility'] ) ? $user['meta']['field_' . $field_id . '_visibility'] : 'public';
     2075                /*
     2076                 * Save the visibility level.
     2077                 *
     2078                 * Use the field's default visibility if not present, and 'public' if a
     2079                 * default visibility is not defined.
     2080                 */
     2081                $key = "field_{$field_id}_visibility";
     2082                if ( isset( $user['meta'][ $key ] ) ) {
     2083                    $visibility_level = $user['meta'][ $key ];
     2084                } else {
     2085                    $vfield           = xprofile_get_field( $field_id );
     2086                    $visibility_level = isset( $vfield->default_visibility ) ? $vfield->default_visibility : 'public';
     2087                }
    20772088                xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level );
    20782089            }
  • trunk/src/bp-members/classes/class-bp-signup.php

    r11240 r11630  
    389389                    xprofile_set_field_data( $field_id, $user_id, $current_field );
    390390
    391                     // Save the visibility level.
    392                     $visibility_level = ! empty( $usermeta['field_' . $field_id . '_visibility'] ) ? $usermeta['field_' . $field_id . '_visibility'] : 'public';
     391                    /*
     392                     * Save the visibility level.
     393                     *
     394                     * Use the field's default visibility if not present, and 'public' if a
     395                     * default visibility is not defined.
     396                     */
     397                    $key = "field_{$field_id}_visibility";
     398                    if ( isset( $usermeta[ $key ] ) ) {
     399                        $visibility_level = $usermeta[ $key ];
     400                    } else {
     401                        $vfield           = xprofile_get_field( $field_id );
     402                        $visibility_level = isset( $vfield->default_visibility ) ? $vfield->default_visibility : 'public';
     403                    }
    393404                    xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level );
    394405                }
  • trunk/tests/phpunit/testcases/members/class-bp-signup.php

    r9819 r11630  
    6363
    6464    /**
     65     * @group add
     66     */
     67    public function test_add_no_visibility_level_set_should_use_default_visiblity_level() {
     68        // Update field_1's default visiblity to 'adminsonly'
     69        bp_xprofile_update_field_meta( 1, 'default_visibility', 'adminsonly' );
     70
     71        // Add new signup without a custom field visibility set for field_1.
     72        $signup = BP_Signup::add( array(
     73            'domain' => 'foo',
     74            'path' => 'bar',
     75            'title' => 'Foo bar',
     76            'user_login' => 'user1',
     77            'user_email' => 'user1@example.com',
     78            'registered' => bp_core_current_time(),
     79            'activation_key' => '12345',
     80            'meta' => array(
     81                'field_1' => 'Foo Bar',
     82                'meta1' => 'meta2',
     83                'password' => 'password',
     84
     85                /*
     86                 * Ensure we pass the field ID.
     87                 *
     88                 * See bp_core_activate_signup() and BP_Signup::add_backcompat().
     89                 */
     90                'profile_field_ids' => '1'
     91            ),
     92        ) );
     93
     94        // Activate the signup.
     95        $activate = BP_Signup::activate( (array) $signup );
     96
     97        // Assert that field 1's visibility for the signup is still 'adminsonly'
     98        $vis = xprofile_get_field_visibility_level( 1, $activate['activated'][0] );
     99        $this->assertSame( 'adminsonly', $vis );
     100    }
     101
     102    /**
    65103     * @group get
    66104     */
Note: See TracChangeset for help on using the changeset viewer.