最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - Add to array, redirect and display

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论