admin管理员组

文章数量:1023187

template:

<form action="<?php echo esc_url( admin_url('admin-post.php')); ?>" method="post">
    <input type="text" name="boo" id="boo" required>
    <input type="hidden" name="action" value="foo">
</form>

I have add the hook in theme functions.php and moo is registered:

add_action( 'admin_post_foo', 'moo' );
add_action( 'admin_post_nopriv_foo', 'moo' );
function moo() {
    wp_safe_redirect(
        esc_url(
            site_url( 'http://127.0.0.1:8000/?page_id=5' )
        )
    );
}

and still after post it hangs on admin_post.php

I don't have debug and I'm clueless of whether the hook is invoked so any idea of how to determine that as well?

template:

<form action="<?php echo esc_url( admin_url('admin-post.php')); ?>" method="post">
    <input type="text" name="boo" id="boo" required>
    <input type="hidden" name="action" value="foo">
</form>

I have add the hook in theme functions.php and moo is registered:

add_action( 'admin_post_foo', 'moo' );
add_action( 'admin_post_nopriv_foo', 'moo' );
function moo() {
    wp_safe_redirect(
        esc_url(
            site_url( 'http://127.0.0.1:8000/?page_id=5' )
        )
    );
}

and still after post it hangs on admin_post.php

I don't have debug and I'm clueless of whether the hook is invoked so any idea of how to determine that as well?

Share Improve this question asked Apr 25, 2019 at 12:27 Bat ManBat Man 1031 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Let's say your site's address is example. When you want to redirect to example/page/subpage you should use site_url('/page/subpage').

I assume the WordPress address is http://127.0.0.1:8000. You have in your code
site_url( 'http://127.0.0.1:8000/?page_id=5' ) and it will be converted to this address: http://127.0.0.1:8000http://127.0.0.1:8000/?page_id=5.

Try using this redirection:

wp_safe_redirect( site_url( '/?page_id=5' ) );

Second issue, if you'll take a look at code reference, you will find there:

wp_safe_redirect() does not exit automatically and should almost always be followed by exit.

template:

<form action="<?php echo esc_url( admin_url('admin-post.php')); ?>" method="post">
    <input type="text" name="boo" id="boo" required>
    <input type="hidden" name="action" value="foo">
</form>

I have add the hook in theme functions.php and moo is registered:

add_action( 'admin_post_foo', 'moo' );
add_action( 'admin_post_nopriv_foo', 'moo' );
function moo() {
    wp_safe_redirect(
        esc_url(
            site_url( 'http://127.0.0.1:8000/?page_id=5' )
        )
    );
}

and still after post it hangs on admin_post.php

I don't have debug and I'm clueless of whether the hook is invoked so any idea of how to determine that as well?

template:

<form action="<?php echo esc_url( admin_url('admin-post.php')); ?>" method="post">
    <input type="text" name="boo" id="boo" required>
    <input type="hidden" name="action" value="foo">
</form>

I have add the hook in theme functions.php and moo is registered:

add_action( 'admin_post_foo', 'moo' );
add_action( 'admin_post_nopriv_foo', 'moo' );
function moo() {
    wp_safe_redirect(
        esc_url(
            site_url( 'http://127.0.0.1:8000/?page_id=5' )
        )
    );
}

and still after post it hangs on admin_post.php

I don't have debug and I'm clueless of whether the hook is invoked so any idea of how to determine that as well?

Share Improve this question asked Apr 25, 2019 at 12:27 Bat ManBat Man 1031 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Let's say your site's address is example. When you want to redirect to example/page/subpage you should use site_url('/page/subpage').

I assume the WordPress address is http://127.0.0.1:8000. You have in your code
site_url( 'http://127.0.0.1:8000/?page_id=5' ) and it will be converted to this address: http://127.0.0.1:8000http://127.0.0.1:8000/?page_id=5.

Try using this redirection:

wp_safe_redirect( site_url( '/?page_id=5' ) );

Second issue, if you'll take a look at code reference, you will find there:

wp_safe_redirect() does not exit automatically and should almost always be followed by exit.

本文标签: functionsPostback redirect through addaction is not triggered