Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using a function that redirects the user to a custom page, rather than wp-login in the event of errors. In my case I am using the Http Referer function to send the user back to the same page because I have the login form in a modal. How can I execute a function on the redirected page, so that the page automatically opens the modal?

This is the code for the redirect in the event of an error:

add_filter('login_redirect', '_catch_login_error', 10, 3);
function _catch_login_error($redir1, $redir2, $wperr_user) {
    $rurl = $_SERVER['HTTP_REFERER'];
    if(!is_wp_error($wperr_user) || !$wperr_user->get_error_code()) return $redir1;
        switch($wperr_user->get_error_code()) {
            case 'incorrect_password': 
            case 'empty_password': 
            case 'invalid_username': 
            default: wp_redirect($rurl); }
        return $redir1;
     }

This code courtesy of http://projectivemotion.com/2011/12/16/redirect-failed-login-attempt-wordpress/#comment-653

The function I want to execute after redirect is:

add_action('genesis_before_post', 'force_open_modal_1');
function force_open_modal_1() { ?>
    <script type="text/javascript">
    jQuery(document).ready(function($){
        $('#loginmodal').reveal();
    });
    </script>
<?php }

Is this possible?

share|improve this question
    
Try add_query_arg( 'key', 'value' ); - then hook into wp_query() with your fn, and switch with get_arg( 'key' ) if you want to trigger or abort. –  kaiser Oct 3 '12 at 15:56
    
Thanks for the reply, how do I go about hooking the _catch_login_error into a wp_query? I'm a little confused –  Kyle Oct 3 '12 at 17:18
    
Not "a" wp_query. Into the equally named hook (or maybe into template_redirect or whatever fits). –  kaiser Oct 4 '12 at 6:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.