Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save AngeliMae/fc35b41d8433fd606d8dcc7cc8537b5e to your computer and use it in GitHub Desktop.

Select an option

Save AngeliMae/fc35b41d8433fd606d8dcc7cc8537b5e to your computer and use it in GitHub Desktop.
Send birthday greetings to accounts with today’s birthdays
function um_080822_email_notifications( $notifications ){
$notifications['um_greet_todays_birthdays'] = array(
'key' => 'um_greet_todays_birthdays',
'title' => __( 'Happy Birthday!','um-groups' ),
'subject' => 'Happy Birthday from {site_name}',
'body' => 'Hi {display_name},<br /><br />'.
'"We wish you a happy birthday!',
'description' => __('Whether to send the user an email when someone\'s todays birthday.','ultimate-member'),
'recipient' => 'member',
'default_active' => true
);
return $notifications;
}
add_filter( 'um_email_notifications', 'um_080822_email_notifications', 10, 1 );
function um_080822_cron_task_birthday_greet_notification(){
$date = date("/m/d");
$query_args['meta_query'][ ] = array(
'relation' => 'AND',
array(
'key' => 'birth_date',
'value' => $date,
'compare' => 'RLIKE'
),
array(
'key' => 'um_birthday_greeted_' . md5( $date ),
'compare' => 'NOT EXISTS'
)
);
$users = new WP_User_Query( $query_args );
// Get the results
$celebrants = $wp_user_query->get_results();
// Check for results
if ( !empty( $celebrants ) ) {
foreach( $celebrants as $c ){
$recipient_email = $c->user_email;
$display_name = um_user("display_name");
UM()->mail()->send( $recipient_email, 'um_greet_todays_birthdays', array(
'plain_text' => 1,
'tags' => array(
'{display_name}',
),
'tags_replace' => array(
$display_name,
)
) );
update_user_meta( $c->ID, 'um_birthday_greeted_' . md5( $date ), true );
}
}
}
add_action("um_do2_birthday_greet_notification","um_080822_cron_task_birthday_greet_notification");
if ( ! wp_next_scheduled ( 'um_do2_birthday_greet_notification') ) {
wp_schedule_event( time(), 'hourly', 'um_do2_birthday_greet_notification' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment