Skip to:
Content

BuddyPress.org

Changeset 11220


Ignore:
Timestamp:
11/03/2016 08:33:35 AM (3 years ago)
Author:
djpaul
Message:

Core: grant the 'bp_xprofile_change_field_visibility' cap to logged-out users.

Fixes problem introduced in v2.7 where profile field visibilty options were not appearing on the registration form.
WordPress does not well handle capabilty checks for anonymous users, and it's likely we'll iterate on this technique in the future as we begin to fully adopt user capabilities.

Fixes #7298

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/bp-xprofile-caps.php

    r11203 r11220  
    2626    switch ( $cap ) {
    2727        case 'bp_xprofile_change_field_visibility' :
    28             $caps = array( 'exist' ); // Must allow for logged-out users during registration.
     28            $caps = array( 'exist' );
    2929
    3030            // You may pass args manually: $field_id, $profile_user_id.
     
    7272}
    7373add_filter( 'bp_map_meta_caps', 'bp_xprofile_map_meta_caps', 10, 4 );
     74
     75/**
     76 * Grant the 'bp_xprofile_change_field_visibility' cap to logged-out users.
     77 *
     78 * @since 2.7.1
     79 *
     80 * @param bool   $user_can
     81 * @param int    $user_id
     82 * @param string $capability
     83 * @return bool
     84 */
     85function bp_xprofile_grant_bp_xprofile_change_field_visibility_for_logged_out_users( $user_can, $user_id, $capability ) {
     86    if ( 'bp_xprofile_change_field_visibility' === $capability && 0 === $user_id ) {
     87        $user_can = true;
     88    }
     89
     90    return $user_can;
     91}
     92add_filter( 'bp_user_can', 'bp_xprofile_grant_bp_xprofile_change_field_visibility_for_logged_out_users', 10, 3 );
Note: See TracChangeset for help on using the changeset viewer.