我有这个功能,每当作者创建一个新帖子时,我都会向所有订阅作者的用户发送电子邮件,效果很好。我正在尝试ajaxify函数,并每隔几秒钟检查一次帖子是否已更新,或者用户是否已发布新帖子。如果是这样,请通过“实时”通知弹出窗口更新该作者的所有订阅者(它不是真正实时的,但似乎是通过setInterval函数实时完成的)。无论如何,任何帮助都将不胜感激!
以下是当前函数:
add_action(\'publish_listings\', \'vba_update\', 10, 1);
add_action(\'draft_listings\', \'vba_update\', 10, 1);
function vba_update($post_id){
$args = array(
\'include\' => tb_get_followers($user_id)
);
$user_query = new WP_User_Query($args);
if ( !empty($user_query->results) ) :
$post_title = get_the_title( $post_id );
$post_url = get_permalink( $post_id );
$subject = \'A post has been updated\';
$message = "A post has been updated on your website:\\n\\n";
$message .= "<a href=\'". $post_url. "\'>" .$post_title. "</a>\\n\\n";
/** Send an individual message to each user */
foreach ( $user_query->results as $user ) :
wp_mail($user->data->user_email, $subject, $message);
endforeach;
endif;
}