Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/28/2023 04:15:24 PM (3 years ago)
Author:
dcavins
Message:

Introduce basic community visibility feature.

Site admins now have the option to restrict access to the
community portion of a BuddyPress site. If the site admin
chooses "members only," then, when a non-logged-in
user attempts to visit a BuddyPress screen, she will
be shown an access error message and a log-in form.

Props imath, sbrajesh, jjj, shawfactor.

Fixes #8734.

File:
1 edited

Legend:

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

    r13532 r13533  
    49724972    return $navigations;
    49734973}
     4974
     4975/**
     4976 * Get the community visibility value calculated from the
     4977 * saved visibility setting.
     4978 *
     4979 * @since 12.0.0
     4980 *
     4981 * @param string $component Whether we want the visibility for a single component
     4982 *                          or for all components.
     4983 *
     4984 * @return arrary|string $retval The calculated visbility settings for the site.
     4985 */
     4986function bp_get_community_visibility( $component = 'global' ) {
     4987    $retval = ( 'all' === $component ) ? array( 'global' => 'anyone' ) : 'anyone';
     4988    if ( 'rewrites' !== bp_core_get_query_parser() ) {
     4989        return $retval;
     4990    }
     4991
     4992    $saved_value = (array) bp_get_option( '_bp_community_visibility', array() );
     4993
     4994    // If the global value has not been set, we assume that the site is open.
     4995    if ( ! isset( $saved_value['global'] ) ) {
     4996        $saved_value['global'] = 'anyone';
     4997    }
     4998
     4999    if ( 'all' === $component ) {
     5000        // Build the component list.
     5001        $retval = array(
     5002            'global' => $saved_value['global']
     5003        );
     5004        $directory_pages = bp_core_get_directory_pages();
     5005        foreach ( $directory_pages as $component_id => $component_page ) {
     5006            if ( in_array( $component_id, array( 'register', 'activate' ), true ) ) {
     5007                continue;
     5008            }
     5009            $retval[ $component_id ] = isset( $saved_value[ $component_id ] ) ? $saved_value[ $component_id ] : $saved_value['global'];
     5010        }
     5011    } else {
     5012        // We are checking a particular component.
     5013        // Fall back to the global value if not set.
     5014        $retval = isset( $saved_value[ $component ] ) ? $saved_value[ $component ] : $saved_value['global'];
     5015    }
     5016
     5017    /**
     5018     * Filter the community visibility value calculated from the
     5019     * saved visibility setting.
     5020     *
     5021     * @since 12.0.0
     5022     *
     5023     * @param arrary|string $retval    The calculated visbility settings for the site.
     5024     * @param string        $component The component value to get the visibility for.
     5025     */
     5026    return apply_filters( 'bp_get_community_visibility', $retval, $component );
     5027}
Note: See TracChangeset for help on using the changeset viewer.