admin管理员组文章数量:1201362
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
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?
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 asked Oct 3, 2012 at 15:54 KyleKyle 2702 gold badges4 silver badges14 bronze badges 3 |1 Answer
Reset to default 1Add a nonce to your redirect url.
See the examples in the codex for wp_nonce_url()
. Use wp_verify_nonce()
to check for the nonce and run your function to load the modal.
You might also want to check if is_user_logged_in()
in this case.
本文标签: hooksFiring a function AFTER redirect
版权声明:本文标题:hooks - Firing a function AFTER redirect 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738556585a2098408.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
add_query_arg( 'key', 'value' );
- then hook intowp_query()
with your fn, and switch withget_arg( 'key' )
if you want to trigger or abort. – kaiser Commented Oct 3, 2012 at 15:56template_redirect
or whatever fits). – kaiser Commented Oct 4, 2012 at 6:33