admin管理员组文章数量:1332865
I've a button, where the user create a post after click it. I want to notify him just after 10 min. I don't know the best way to do this with PHP. I know how to send the email, what I don't know is how to schedule this email for a specific time after the action. Has someone an idea?
I've a button, where the user create a post after click it. I want to notify him just after 10 min. I don't know the best way to do this with PHP. I know how to send the email, what I don't know is how to schedule this email for a specific time after the action. Has someone an idea?
Share Improve this question asked Jul 3, 2020 at 23:36 Gabriel BorgesGabriel Borges 235 bronze badges1 Answer
Reset to default 0There's wp_schedule_single_event:
$in_ten_minutes = time() + 10 * 60;
$post_id = get_the_ID();
wp_schedule_single_event( $in_ten_minutes, 'notify_post_event', array( $post_id ) );
or similar - I've no idea if it's just the post ID you need, or whether get_the_ID() is the right way to find it when you're handling this action. Depending on where the button is and how you want to handle the button press (AJAX? POST back to the page?) this may need to go in an AJAX handler somewhere, and have the post ID and any other values passed in.
And you'll need a handler function too, e.g.
function notify_post_event_handler( $post_id ) {
$the_post = get_post( $post_id );
$author_email = get_the_author_meta( 'user_email', $the_post-post_author );
wp_mail( $author_email,
'Here is your ten minute reminder',
'Post: ' . get_post_permalink( $post_id ) );
}
add_action( 'notify_post_event', 'notify_post_event_handler', 10, 1 );
and this will be triggered after ten minutes by the wp_cron processing, so you'll need to make sure you have something set up to regularly trigger wp_cron jobs if you don't have enough constant volume of visitors to trigger it automatically after ten minutes.
本文标签: phpNotify the user by email after the creation of a post
版权声明:本文标题:php - Notify the user by e-mail after the creation of a post 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742293514a2448263.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论