Skip to:
Content

BuddyPress.org

Changeset 11629


Ignore:
Timestamp:
07/07/2017 06:37:55 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 (2.8-branch)

Location:
branches/2.8
Files:
3 edited

Legend:

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

    r11385 r11629  
    20642064                }
    20652065
    2066                 // Save the visibility level.
    2067                 $visibility_level = ! empty( $user['meta']['field_' . $field_id . '_visibility'] ) ? $user['meta']['field_' . $field_id . '_visibility'] : 'public';
     2066                /*
     2067                 * Save the visibility level.
     2068                 *
     2069                 * Use the field's default visibility if not present, and 'public' if a
     2070                 * default visibility is not defined.
     2071                 */
     2072                $key = "field_{$field_id}_visibility";
     2073                if ( isset( $user['meta'][ $key ] ) ) {
     2074                    $visibility_level = $user['meta'][ $key ];
     2075                } else {
     2076                    $vfield           = xprofile_get_field( $field_id );
     2077                    $visibility_level = isset( $vfield->default_visibility ) ? $vfield->default_visibility : 'public';
     2078                }
    20682079                xprofile_set_field_visibility_level( $field_id, $user_id, $visibility_level );
    20692080            }
  • branches/2.8/src/bp-members/classes/class-bp-signup.php

    r11240 r11629  
    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                }
  • branches/2.8/tests/phpunit/testcases/members/class-bp-signup.php

    r9819 r11629  
    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.