Skip to:
Content

BuddyPress.org

Changeset 13166


Ignore:
Timestamp:
12/10/2021 04:14:11 PM (3 years ago)
Author:
dcavins
Message:

Introduce bp_get_membership_requests_required().

Introduce a new function to determine if membership
requests are enabled and add the toggle to the admin
form at BuddyPress Settings > Options.

See #8582.

Location:
trunk/src
Files:
3 edited

Legend:

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

    r13137 r13166  
    193193    <label for="bp-enable-members-invitations"><?php _e( 'Allow registered members to invite people to join this network', 'buddypress' ); ?></label>
    194194    <?php if ( ! bp_get_signup_allowed() ) : ?>
    195         <p class="description"><?php _e( 'Public registration is currently disabled. However, invitees will still be able to register if network invitations are enabled.', 'buddypress' ); ?></p>
     195        <?php if ( is_multisite() ) : ?>
     196            <p class="description"><?php esc_html_e( 'With a WP multisite setup, to require membership requests for new signups, choose one of the following two options from the Network Settings > Registration Settings pane:' ); ?><p>
     197                <ul>
     198                    <li><p class="description"><?php esc_html_e( 'To allow the submission of membership requests but not allow site creation requests, select "Registration is disabled".' ) ?></p></li>
     199                    <li><p class="description"><?php esc_html_e( 'To allow the submission of membership requests and to allow new sites to be created by your users, choose "Logged in users may register new sites".' ) ?></p></li>
     200                </ul>
     201            <p class="description"><?php esc_html_e( 'The other two options, "User accounts may be registered" and "Both sites and user accounts can be registered," are open in nature and membership requests will not be enabled if one of those options is selected.' ); ?><p>
     202        <?php else : ?>
     203        <p class="description"><?php esc_html_e( 'Public registration is currently disabled. However, invitees will still be able to register if network invitations are enabled.', 'buddypress' ); ?></p>
     204        <?php endif; ?>
    196205    <?php endif; ?>
    197206    <?php
     
    202211     */
    203212    do_action( 'bp_admin_settings_after_members_invitations' );
     213}
     214
     215/**
     216 * Allow new users to request membership to the network.
     217 *
     218 * @since 10.0.0
     219 */
     220function bp_admin_setting_callback_membership_requests() {
     221?>
     222    <input id="bp-enable-membership-requests" name="bp-enable-membership-requests" type="checkbox" value="1" <?php checked( bp_get_membership_requests_required( 'raw' ) ); ?> <?php disabled( bp_get_signup_allowed() ); ?> />
     223    <label for="bp-enable-membership-requests"><?php esc_html_e( 'Allow visitors to request site membership. If enabled, an administrator must approve each new site membership request.', 'buddypress' ); ?></label>
     224    <?php if ( bp_get_signup_allowed() ) : ?>
     225        <p class="description"><?php esc_html_e( 'Public registration is currently enabled. If you wish to require approval for new memberships, disable public registration and enable the membership requests feature.', 'buddypress' ); ?></p>
     226    <?php endif; ?>
     227    <?php
     228    /**
     229     * Fires after the output of the membership requests settings section.
     230     *
     231     * @since 10.0.0
     232     */
     233    do_action( 'bp_admin_settings_after_membership_requests' );
    204234}
    205235
  • trunk/src/bp-core/classes/class-bp-admin.php

    r13164 r13166  
    488488            add_settings_field( 'bp-enable-members-invitations', __( 'Invitations', 'buddypress' ), 'bp_admin_setting_callback_members_invitations', 'buddypress', 'bp_members' );
    489489            register_setting( 'buddypress', 'bp-enable-members-invitations', 'intval' );
     490        }
     491
     492        // Membership requests.
     493        if ( bp_is_active( 'members', 'membership_requests' ) ) {
     494            add_settings_field( 'bp-enable-membership-requests', __( 'Membership Requests', 'buddypress' ), 'bp_admin_setting_callback_membership_requests', 'buddypress', 'bp_members' );
     495            register_setting( 'buddypress', 'bp-enable-membership-requests', 'intval' );
    490496        }
    491497
  • trunk/src/bp-members/bp-members-template.php

    r13140 r13166  
    29232923
    29242924/**
     2925 * Are membership requests required for joining this site?
     2926 *
     2927 * @since 10.0.0
     2928 *
     2929 * @param bool $context "raw" to fetch value from database,
     2930 *                      "site" to take "anyone can register" setting into account.
     2931 * @return bool
     2932 */
     2933function bp_get_membership_requests_required( $context = 'site' ) {
     2934    if ( 'raw' === $context ) {
     2935        $retval = bp_is_active( 'members', 'membership_requests' ) && (bool) bp_get_option( 'bp-enable-membership-requests' );
     2936    } else {
     2937        $retval = bp_is_active( 'members', 'membership_requests' ) && ! bp_get_signup_allowed() && (bool) bp_get_option( 'bp-enable-membership-requests' );
     2938    }
     2939
     2940    /**
     2941     * Filters whether or not prospective members may submit network membership requests.
     2942     *
     2943     * @since 10.0.0
     2944     *
     2945     * @param bool $retval Whether or not membership requests are required.
     2946     * @param bool $retval Whether this is the value stored in the database ('raw')
     2947     *                     or whether the site's "anyone can register" setting is
     2948     *                     being considered ('site' or anything else).
     2949     */
     2950    return apply_filters( 'bp_get_membership_requests_required', $retval, $context );
     2951}
     2952
     2953/**
    29252954 * Should the system create and allow access
    29262955 * to the Register and Activate pages?
     
    29312960 */
    29322961function bp_allow_access_to_registration_pages() {
    2933     $retval = bp_get_signup_allowed() || bp_get_members_invitations_allowed();
     2962    $retval = bp_get_signup_allowed() || bp_get_members_invitations_allowed() || bp_get_membership_requests_required();
    29342963
    29352964    /**
Note: See TracChangeset for help on using the changeset viewer.