plugins - Add to array, redirect and display

I want add text to array and display after redirect and unset array.class test{public function one(){$this->save(2, &

I want add text to array and display after redirect and unset array.

class test{

    public function one(){

        $this->save(2, 'some');

        $url = get_site_url(null, '/redirect_to_two');
        wp_safe_redirect( $url );

    }

    public function two(){

        $this->display();

    }
}

I want add text to array and display after redirect and unset array.

class test{

    public function one(){

        $this->save(2, 'some');

        $url = get_site_url(null, '/redirect_to_two');
        wp_safe_redirect( $url );

    }

    public function two(){

        $this->display();

    }
}
Share Improve this question edited Jul 21, 2019 at 23:37 Jaron asked Mar 28, 2019 at 19:50 JaronJaron 458 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

If you need to pass some data over the redirect, you can do that by adding parameters to the redirect url with add_query_arg(). But other more elegant solutions might exist also.

Single parameter,

wp_redirect( add_query_arg( 'notice', 'success', get_site_url(null, '/redirect_to_two') ) );
exit;

or multiple parameters

wp_redirect( add_query_arg( array( 'notice' => 'success', 'foo' => 'bar' ), get_site_url(null, '/redirect_to_two') ) );
exit;

Then use $_GET to grab the parameter(s),

if ( ! empty( $_GET['notice'] ) && 'success' == $_GET['notice'] ) {
    // Do whatever.
}

If I'm not mistaken, I don't think you need to worry about unsetting arrays as data doesn't normally persist in WordPress. Once you do a redirect all the data in your $variables are gone.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745307069a4621775.html

相关推荐

  • plugins - Add to array, redirect and display

    I want add text to array and display after redirect and unset array.class test{public function one(){$this->save(2, &

    13小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信