id = get_current_user_id(); } /** * Magic getter. * * Provides custom logic for getting protected properties. * * @since 15.0.0 * * @param string $key Property name. * @return mixed */ public function __get( $key ) { switch ( $key ) { case 'id': return get_current_user_id(); case 'userdata': return WP_User::get_data_by( 'id', get_current_user_id() ); case 'fullname': $current_user_id = get_current_user_id(); $disable_profile_sync = bp_disable_profile_sync(); /** * When profile sync is disabled, display_name may diverge from the xprofile * fullname field value, and the xprofile field should take precedence. */ $retval = ''; if ( $disable_profile_sync && bp_is_active( 'xprofile' ) ) { $retval = xprofile_get_field_data( bp_xprofile_fullname_field_name(), $current_user_id ); } /** * Common case: If BP profile and WP profiles are synced, * then we use the WP value. * This is also used if the xprofile field data is preferred, but empty or the component is disabled. */ if ( ! $disable_profile_sync || ! $retval ) { $retval = bp_core_get_user_displayname( $current_user_id ); } return $retval; case 'is_super_admin': case 'is_site_admin': return is_super_admin( get_current_user_id() ); case 'domain': return bp_members_get_user_url( get_current_user_id() ); default: return isset( $this->{$key} ) ? $this->{$key} : null; } } /** * Magic issetter. * * Used to maintain backward compatibility for properties that are now * accessible only via magic method. * * @since 15.0.0 * * @param string $key Property name. * @return bool */ public function __isset( $key ) { switch ( $key ) { case 'id': case 'userdata': case 'fullname': case 'is_super_admin': case 'is_site_admin': case 'domain': return true; default: return isset( $this->{$key} ); } } }