Skip to:
Content

BuddyPress.org

Ticket #4990: 4990.01.patch

File 4990.01.patch, 2.0 KB (added by r-a-y, 5 years ago)
  • src/bp-core/bp-core-catchuri.php

     
    698698/**
    699699 * Add an error message to wp-login.php.
    700700 *
    701  * Hooks into the "bpnoaccess" action defined in bp_core_no_access().
    702  *
    703701 * @since 1.5.0
     702 * @since 2.x.0 Hook moved to 'wp_login_errors' made available since WP 3.6.0.
    704703 *
    705  * @global string $error Error message to pass to wp-login.php.
     704 * @param  WP_Error $errors Current error container.
     705 * @return WP_Error
    706706 */
    707 function bp_core_no_access_wp_login_error() {
    708         global $error;
     707function bp_core_no_access_wp_login_error( $errors ) {
     708        if ( empty( $_GET['action'] ) || 'bpnoaccess' !== $_GET['action'] ) {
     709                return $errors;
     710        }
    709711
    710712        /**
    711713         * Filters the error message for wp-login.php when needing to log in before accessing.
     
    715717         * @param string $value Error message to display.
    716718         * @param string $value URL to redirect user to after successful login.
    717719         */
    718         $error = apply_filters( 'bp_wp_login_error', __( 'You must log in to access the page you requested.', 'buddypress' ), $_REQUEST['redirect_to'] );
     720        $message = apply_filters( 'bp_wp_login_error', __( 'You must log in to access the page you requested.', 'buddypress' ), $_REQUEST['redirect_to'] );
     721
     722        $errors->add( 'bp_no_access', $message );
     723
     724        return $errors;
     725}
     726add_filter( 'wp_login_errors', 'bp_core_no_access_wp_login_error' );
    719727
    720         // Shake shake shake!.
    721         add_action( 'login_head', 'wp_shake_js', 12 );
     728/**
     729 * Add our custom error code to WP login's shake error codes.
     730 *
     731 * @since 2.x.0
     732 *
     733 * @param  array $codes Array of WP error codes.
     734 * @return array
     735 */
     736function bp_core_login_filter_shake_codes( $codes ) {
     737        $codes[] = 'bp_no_access';
     738        return $codes;
    722739}
    723 add_action( 'login_form_bpnoaccess', 'bp_core_no_access_wp_login_error' );
     740add_filter( 'shake_error_codes', 'bp_core_login_filter_shake_codes' );
    724741
    725742/**
    726743 * Canonicalize BuddyPress URLs.