[buddypress-trac] [BuddyPress Trac] #9043: Birthday Email Situation Trigger

buddypress-trac noreply at wordpress.org
Fri Dec 22 17:47:57 UTC 2023


#9043: Birthday Email Situation Trigger
-----------------------------+-------------------------------------
 Reporter:  gbordormor22     |       Owner:  (none)
     Type:  feature request  |      Status:  new
 Priority:  high             |   Milestone:  Awaiting Contributions
Component:  Core             |     Version:  12.0.0
 Severity:  normal           |  Resolution:
 Keywords:                   |
-----------------------------+-------------------------------------

Comment (by gbordormor22):

 Someone provided me this Code:

 {{{#!php
 <?php
 // Add this code to your theme's functions.php file or use a custom code
 plugin

 function wbcom_send_birthday_reminders() {
     // Get all BuddyPress members
     $bp_members = new BP_User_Query(array('per_page' => -1));

     if (!empty($bp_members->results)) {
         foreach ($bp_members->results as $member) {
             // Get the user's birthday from xProfile field
             $birthday = bp_get_profile_field_data(array('field' =>
 'Birthday', 'user_id' => $member->ID));

             // Check if it's the user's birthday
             if ($birthday && date('md', strtotime($birthday)) ==
 date('md')) {
                 // It's the user's birthday, send a reminder email
                 $to = $member->user_email;
                 $subject = 'Happy Birthday!';
                 $message = 'Dear ' . $member->display_name . ',\n\nHappy
 Birthday!';

                 // Send email
                 wp_mail($to, $subject, $message);
             }
         }
     }
 }

 // Schedule the birthday reminder to be sent daily
 add_action('init', function () {
     if (!wp_next_scheduled('wbcom_send_birthday_reminders')) {
         wp_schedule_event(time(), 'daily',
 'wbcom_send_birthday_reminders');
     }
 });

 // Hook the function to the scheduled event
 add_action('wbcom_send_birthday_reminders',
 'wbcom_send_birthday_reminders');
 }}}



 I don't know if this can be a starting point for what I'm asking for?

-- 
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/9043#comment:5>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list