最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - How do I email a new page password to somebody every month?

programmeradmin1浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 2

First 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.

发布评论

评论列表(0)

  1. 暂无评论