我的目标是使用Heartbeat API检查博客主页加载后是否发布了新帖子。如果发布了新帖子,我会在屏幕顶部显示一个链接“16篇新帖子”,单击该链接后,会将新帖子插入DOM。
My problem:
如何检查博客主页加载后是否发布了新帖子?My PHP so far:
function new_post_check( $response, $data, $screen_id ) {
// Do some processing here.
// Respond.
return $response;
}
add_filter( \'heartbeat_received\', \'new_post_check\', 10, 3 );
add_filter( \'heartbeat_nopriv_received\', \'new_post_check\', 10, 3 );
My script so far:
$( document ).on( \'heartbeat-tick.poll\', function( event, data ) {
// Print data to the console.
console.log( data );
});