admin管理员组文章数量:1392003
I want to email the new page password to somebody every month. I see no reason why this cannot be adapted.
First I guess I need to change this:
add_filter( 'cron_schedules', function( $schedules )
{
// Our custom cron interval:
$schedules['every_2nd_day'] = array(
'interval' => 2 * DAY_IN_SECONDS,
'display' => 'Once every second day'
);
to
add_filter( 'cron_schedules', function( $schedules )
{
// Our custom cron interval:
$schedules['every_month'] = array(
'interval' => 1 * MONTH_IN_SECONDS,
'display' => 'Once every Month'
);
And change the code again later where 'every_2nd_day' is referenced. Then how do I a) set up an automated email, and b) package the code as a plugin and install it?
Is that all I need do. I assume this script is still secure, and valid for current Wordpress?
I want to email the new page password to somebody every month. I see no reason why this cannot be adapted.
First I guess I need to change this:
add_filter( 'cron_schedules', function( $schedules )
{
// Our custom cron interval:
$schedules['every_2nd_day'] = array(
'interval' => 2 * DAY_IN_SECONDS,
'display' => 'Once every second day'
);
to
add_filter( 'cron_schedules', function( $schedules )
{
// Our custom cron interval:
$schedules['every_month'] = array(
'interval' => 1 * MONTH_IN_SECONDS,
'display' => 'Once every Month'
);
And change the code again later where 'every_2nd_day' is referenced. Then how do I a) set up an automated email, and b) package the code as a plugin and install it?
Is that all I need do. I assume this script is still secure, and valid for current Wordpress?
Share Improve this question edited Feb 14, 2020 at 9:29 Robert Frost asked Feb 14, 2020 at 9:14 Robert FrostRobert Frost 1435 bronze badges1 Answer
Reset to default 2First of all, you should wrap your cron into a method:
function cronjob_once_every_month() {
// Our custom cron interval:
$schedules['every_month'] = array(
'interval' => 1 * MONTH_IN_SECONDS,
'display' => 'Once every Month'
);
}
a) set up an automated email
Then you should schedule an action:
if ( ! wp_next_scheduled( 'cronjob_once_every_month' ) ) {
wp_schedule_event( time(), 'email_password_every_month', 'cronjob_once_every_month' );
}
Finally, you should hook into an action to fire the cron:
add_action( 'cronjob_once_every_month', 'email_password_every_month' );
function email_password_every_month() {
wp_mail( $to, $subject, $message, $headers, $attachments );
}
Tip: you should setup SMTP because wp_mail() does not guarantee the email was received by the user.
b) package the code as a plugin and install it?
Please, read the official documentation.
本文标签: pluginsHow do I email a new page password to somebody every month
版权声明:本文标题:plugins - How do I email a new page password to somebody every month? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744748131a2623011.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论