开发者

Wordpress Shortcode setcookie Issue

开发者 https://www.devze.com 2023-03-04 18:12 出处:网络
No errors or warnings are generated when running the code below. I just ran into a problem on wordpress when trying to create cookies inside of shortcode events.

No errors or warnings are generated when running the code below.

I just ran into a problem on wordpress when trying to create cookies inside of shortcode events.

In the code below, the test1 cookie is created just fine, however the test2 cookie is not created.

The verbiage 'Code Ran' does display however.

if ( ! function_exists('cookieset')) :
function cookieset( $atts, $content = null ) {
    extract( shortcode_atts( array(
   开发者_开发知识库     'name'     => 'cookieloc',
        'redirect' => '/',
        'expires'  => '365',
    ), $atts ) );
    setcookie("test2", 1, time()+3600, "/", ".domainname.com", false, true);
    return "Code Ran";
}
endif;

if ( ! function_exists('cookieloc_action') ) :

function cookieloc_action() {
    echo add_shortcode('cookieloc', 'cookieset');
    setcookie("test1", 1, time()+3600, "/", ".domainname.com", false, true);  
}
endif;


It appears the Word Press does not buffer the entire page content, but progressively sends the content, thus I cannot send headers in an add_shortcode(...) function

Sadly, the order of execution is not provided in the API sections on wordpress... http://codex.wordpress.org/Shortcode_API

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号