When you create a new post, the initial post status is not new
, but rather auto-draft
. Try this:
add_action("draft_to_publish", "doSomething", 10,1);
function doSomething($post){
global $post;
$_SESSION['yeni'] = 'test';
}
echo $_SESSION['yeni'];
Also note that you may want to make sure your session is properly initialized. To verify the callback works at least, enable WP_DEBUG
and WP_DEBUG_LOG
and do something like
add_action("draft_to_publish", "doSomething", 10,1);
function doSomething($post){
error_log( 'Inside the new post transition');
}
Then publish a post and look at wp-content/debug.log