Skip to:
Content

BuddyPress.org

Changeset 10982


Ignore:
Timestamp:
08/02/2016 05:44:09 AM (9 years ago)
Author:
r-a-y
Message:

Core: Adjust how our error message is registered on the WP login page.

WordPress 3.6 introduced the 'wp_login_errors' filter, which allows us to
properly register our no access error message on the WordPress login page
in a better manner.

This also addresses an issue with the Theme My Login plugin where a PHP
warning was being displayed.

Fixes #4990.

File:
1 edited

Legend:

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

    r10899 r10982  
    699699
    700700/**
    701  * Add an error message to wp-login.php.
    702  *
    703  * Hooks into the "bpnoaccess" action defined in bp_core_no_access().
     701 * Add a custom BuddyPress no access error message to wp-login.php.
    704702 *
    705703 * @since 1.5.0
    706  *
    707  * @global string $error Error message to pass to wp-login.php.
    708  */
    709 function bp_core_no_access_wp_login_error() {
    710     global $error;
     704 * @since 2.7.0 Hook moved to 'wp_login_errors' made available since WP 3.6.0.
     705 *
     706 * @param  WP_Error $errors Current error container.
     707 * @return WP_Error
     708 */
     709function bp_core_no_access_wp_login_error( $errors ) {
     710    if ( empty( $_GET['action'] ) || 'bpnoaccess' !== $_GET['action'] ) {
     711        return $errors;
     712    }
    711713
    712714    /**
     
    718720     * @param string $value URL to redirect user to after successful login.
    719721     */
    720     $error = apply_filters( 'bp_wp_login_error', __( 'You must log in to access the page you requested.', 'buddypress' ), $_REQUEST['redirect_to'] );
    721 
    722     // Shake shake shake!.
    723     add_action( 'login_head', 'wp_shake_js', 12 );
    724 }
    725 add_action( 'login_form_bpnoaccess', 'bp_core_no_access_wp_login_error' );
     722    $message = apply_filters( 'bp_wp_login_error', __( 'You must log in to access the page you requested.', 'buddypress' ), $_REQUEST['redirect_to'] );
     723
     724    $errors->add( 'bp_no_access', $message );
     725
     726    return $errors;
     727}
     728add_filter( 'wp_login_errors', 'bp_core_no_access_wp_login_error' );
     729
     730/**
     731 * Add our custom error code to WP login's shake error codes.
     732 *
     733 * @since 2.7.0
     734 *
     735 * @param  array $codes Array of WP error codes.
     736 * @return array
     737 */
     738function bp_core_login_filter_shake_codes( $codes ) {
     739    $codes[] = 'bp_no_access';
     740    return $codes;
     741}
     742add_filter( 'shake_error_codes', 'bp_core_login_filter_shake_codes' );
    726743
    727744/**
Note: See TracChangeset for help on using the changeset viewer.