Skip to:
Content

BuddyPress.org

Changeset 13171


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

Membership Requests: Add links to signup form.

Add links to the signup form in the WP sidebar,
on the login form and in the WP toolbar.

Fixes #8582.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-membership-requests.php

    r13170 r13171  
    369369add_filter( 'bp_members_ms_signup_date_sent_unsent_message', 'bp_members_membership_requests_filter_signup_table_unsent_message', 10, 2 );
    370370
     371/**
     372 * Filter/add "Request Membership" links in the following locations:
     373 * - BP login widget,
     374 * - Sidebar register link,
     375 * - WP Toolbar,
     376 * - WP login form.
     377 *********************************************************************/
     378
     379/**
     380 * Add "Request Membership" link to Widget login form.
     381 *
     382 * @since 10.0.0
     383 *
     384 * @return string $retval the HTML for the request membership link.
     385 */
     386function bp_members_membership_requests_add_link_to_widget_login_form() {
     387    ?>
     388    <span class="bp-login-widget-request-membership-link"><a href="<?php echo esc_url( bp_get_signup_page() ); ?>"><?php esc_html_e( 'Request Membership', 'buddypress' ); ?></a></span>
     389    <?php
     390}
     391add_action( 'bp_login_widget_form', 'bp_members_membership_requests_add_link_to_widget_login_form' );
     392
     393/**
     394 * Filter the "Register" link from `wp_register()` as used in
     395 * `sidebar.php` and the WP Core meta widget.
     396 *
     397 * @since 10.0.0
     398 *
     399 * @param string $link The HTML code for the link to the Registration or Admin page.
     400 * @return string      An empty string or the HTML code for the link to the Membership request page.
     401 */
     402function bp_members_membership_requests_filter_sidebar_register_link( $link ) {
     403    // $link should be an empty string when public registration is disabled.
     404    if ( ! is_user_logged_in() && empty( $link ) ) {
     405        $link = '<a href="' . esc_url( wp_registration_url() ) . '">' . esc_html__( 'Request Membership', 'buddypress' ) . '</a>';
     406    }
     407
     408    return $link;
     409}
     410add_filter( 'register', 'bp_members_membership_requests_filter_sidebar_register_link' );
     411
     412/**
     413 * Add a "Request Membership" link to the WP Toolbar.
     414 * Priority 21 should place it just after the "Log In" link.
     415 *
     416 * @since 10.0.0
     417 *
     418 * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference
     419 */
     420function bp_members_membership_requests_add_toolbar_link( $wp_admin_bar ) {
     421    if ( is_user_logged_in() ) {
     422        return;
     423    }
     424
     425    $args = array(
     426        'id'    => 'bp-request-membership',
     427        'title' => __( 'Request Membership', 'buddypress' ),
     428        'href'  => wp_registration_url(),
     429        'meta'  => array(
     430            'class' => 'buddypress-request-membership',
     431            'title' => __( 'Request Membership', 'buddypress' ),
     432        ),
     433    );
     434
     435    $wp_admin_bar->add_node( $args );
     436}
     437add_action( 'admin_bar_menu', 'bp_members_membership_requests_add_toolbar_link', 21 );
     438
     439/**
     440 * Add a "Request Membership" link to the WP Login form.
     441 *
     442 * @since 10.0.0
     443 *
     444 * @param string $link HTML link to the home URL of the current site.
     445 * @return string      HTML link to the home URL of the current site and the one to request a membership.
     446 */
     447function bp_members_membership_requests_add_link_wp_login( $link ) {
     448    $link_separator = apply_filters( 'login_link_separator', ' | ' );
     449
     450    return $link . $link_separator . '<a href="' . esc_url( wp_registration_url() ) . '">' . esc_html__( 'Request Membership', 'buddypress' ) . '</a>';
     451}
     452add_action( 'login_site_html_link', 'bp_members_membership_requests_add_link_wp_login' );
Note: See TracChangeset for help on using the changeset viewer.