Skip to:
Content

BuddyPress.org

Ticket #8582: 8582.2.add-links.diff

File 8582.2.add-links.diff, 2.7 KB (added by dcavins, 3 years ago)

Add Request Membership links to WP Toolbar, meta widget, wp-login form.

  • src/bp-members/bp-members-filters.php

    diff --git src/bp-members/bp-members-filters.php src/bp-members/bp-members-filters.php
    index c536e639d..c1608cb44 100644
    function bp_members_membership_requests_filter_signup_table_unsent_message( $mes 
    474474add_filter( 'bp_members_signup_date_sent_unsent_message', 'bp_members_membership_requests_filter_signup_table_unsent_message', 10, 2 );
    475475add_filter( 'bp_members_ms_signup_date_sent_unsent_message', 'bp_members_membership_requests_filter_signup_table_unsent_message', 10, 2 );
    476476
     477/**
     478 * Filter the "Register" link from `wp_register()` as used in
     479 * `sidebar.php` and the WP Core meta widget.
     480 *
     481 * @since 10.0.0
     482 *
     483 * @param string $link The HTML code for the link to the Registration or Admin page.
     484 */
     485function bp_members_membership_requests_filter_sidebar_register_link( $link ) {
     486        // $link should be an empty string when public registration is disabled.
     487        if ( ! is_user_logged_in() && bp_get_membership_requests_required() && empty( $link ) ) {
     488                // @TODO: How can we know what before and after tags should be?
     489                $link = '<li><a href="' . esc_url( wp_registration_url() ) . '">' . __( 'Request Membership' ) . '</a><li>';
     490        }
     491        return $link;
     492}
     493add_filter( 'register', 'bp_members_membership_requests_filter_sidebar_register_link' );
     494
     495/**
     496 * Add a Request Membership link to the WP Toolbar.
     497 * Priority 21 should place it just after the "Log In" link.
     498 *
     499 * @since 10.0.0
     500 *
     501 * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference
     502 */
     503function bp_members_membership_requests_add_toolbar_link( $wp_admin_bar ) {
     504        if ( is_user_logged_in() || ! bp_get_membership_requests_required() ) {
     505                return;
     506        }
     507
     508        $args = array(
     509                'id'    => 'bp-request-membership',
     510                'title' => __( 'Request Membership' ),
     511                'href'  => wp_registration_url(),
     512                'meta'  => array(
     513                        'class' => 'buddypress-request-membership',
     514                        'title' => __( 'Request Membership' )
     515                ),
     516        );
     517        $wp_admin_bar->add_node( $args );
     518}
     519add_action( 'admin_bar_menu', 'bp_members_membership_requests_add_toolbar_link', 21 );
     520
     521/**
     522 * Add a Request Membership link to the WP Login form.
     523 * This is not the ideal place, but WP Core doesn't offer a filer
     524 * in the #nav paragraph where the "Register" link would appear.
     525 *
     526 * @since 10.0.0
     527 *
     528 * @param string $link HTML link to the home URL of the current site.
     529 */
     530function bp_members_membership_requests_add_link_wp_login( $link ) {
     531        if ( bp_get_membership_requests_required() ) {
     532                return $link . '&ensp;|&ensp;' . '<a href="' . esc_url( wp_registration_url() ) . '">' . __( 'Request Membership' ) . '</a>';
     533        }
     534}
     535add_action( 'login_site_html_link', 'bp_members_membership_requests_add_link_wp_login' );