开发者

Wordpress Shortcode setcookie Issue

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜