创建新帖子时,初始帖子状态为new
, 而是auto-draft
. 尝试以下操作:
add_action("draft_to_publish", "doSomething", 10,1);
function doSomething($post){
global $post;
$_SESSION[\'yeni\'] = \'test\';
}
echo $_SESSION[\'yeni\'];
还请注意,您可能需要确保会话已正确初始化。要验证回调是否至少正常工作,请启用
WP_DEBUG
和
WP_DEBUG_LOG
然后做一些类似的事情
add_action("draft_to_publish", "doSomething", 10,1);
function doSomething($post){
error_log( \'Inside the new post transition\');
}
然后发布一篇帖子,看看
wp-content/debug.log