Wordpress wp-members customization - login failure message

How to Change the Message Displayed to Users When They Logon to WP-MEMBERS pages

The default link shown to users when they fail to logon is just URL/wp-profile which is just plain stupid. You can change it to a custom logon page.

You will be editing these files:
dialogs.php, class-wp-members.php and api-forms.php
full paths:
./wp-content/plugins/wp-members/includes/api/api-forms.php
./wp-content/plugins/wp-members/includes/class-wp-members.php
./wp-content/plugins/wp-members/includes/legacy/dialogs.php

Step1: Add a handler in api-forms.php

If you have a php file called login.php then it will show this link in the failure message. Add this near the bottom of the file.
...append this function to the end of api-forms.php...

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
function my_login_failed_msg( $str )
{
    // The generated html for the login failed message

    // is passed to this filter as $str and includes the

    // formatting tags. You can change it or append to it.

    $str = str_replace("/my-profile/", "/login.php", $str);

    return $str;
}

Step 2: Add this to class_wp_members.php

... add this line to a function called load_hooks() inside class_wp_members.php, add it near the end of the function right before the final IF statement.
add_filter( 'wpmem_login_failed', 'my_login_failed_msg' );
...

Step 3: Customize the wpmem_inc_loginfailed() failure handler

Find this in dialogs.php then add something to heading_before. By default this array element only has h2 in it. you can add an H1 element to spruce it up.
..here.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
        $defaults = array(
                'div_before'     => '<div align="center" id="wpmem_msg">',
                'div_after'      => '</div>',
                'heading_before' => '<h1>Smardii Partners</h1><h2>',
                'heading'        => $wpmem->get_text( 'login_failed_heading' ),
                'heading_after'  => '</h2>',
                'p_before'       => '<p>',
                'message'        => $wpmem->get_text( 'login_failed' ), // @todo $wpmem->error
                'p_after'        => '</p>',
                'link'           => '<a href="' . esc_url( $_SERVER['REQUEST_URI'] ) . '">' . $wpmem->get_text( 'login_failed_link' ) . '</a>',
        );
...


References:  https://rocketgeek.com/plugins/wp-members/docs/filter-hooks/wpmem_login_failed/
https://www.php.net/manual/en/function.str-replace.php

Comments

Popular posts from this blog

Microsoft Visio 2010 Premium Product Keys

Mercedes Benz Diesel CDI EGR Emulator Circuit Diagrams

Fix: The Diagnostic Service Host service failed to start due to the following error. [ solved, no kidding ]