• Resolved melchi2

    (@melchi2)


    Hello, Can you tell me if the following script is correct because I tried it but it does not work, thank you very much

    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_45','birth_date_45-31',
                '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' );
    }
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Aswin Giri

    (@aswingiri)

    Hello @melchi2

    Can you please mention what part of the code is not working?

    Thread Starter melchi2

    (@melchi2)

    good evening Aswin, it’s sending mail that doesn’t work after I don’t know if the following syntax is good:

    key’ => ‘birth_date_45′,’birth_date_45-31’,

    I have two keys one for hosts and one for women. I don’t know if the blocking of sending mail comes from there. Thank you in advance for your assistance

    Plugin Support andrewshu

    (@andrewshu)

    Hello @melchi2

    Sorry for the late answer. You could try to change this raw to this:

    key’ => array(‘birth_date_45′,’birth_date_45-31’),

    Thank you.

    Thread Starter melchi2

    (@melchi2)

    function um_080822_email_notifications( $notifications ){
    
    	$notifications['um_greet_todays_birthdays'] = array(
    		'key'           	=> 'um_greet_todays_birthdays',
    		'title'         	=> __( 'Joyeux anniversaire!','um-groups' ),
    		'subject'       	=> 'Joyeux anniversaire de {site_name}',
    		'body'          	=> 'Bonjour {display_name},<br /><br />'.
    		                   'Nous te souhaitons un joyeux anniversaire!',
    		'description'   	=> __('Whether to send the user an email when someone\'s todays birthday.','um-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_45_31',
                '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' );
    }

    I tried with the script but unfortunately it doesn’t work. In the database the date of birth is in this form birth_date_45_31 1984/11/22. I don’t understand what is blocking

    Plugin Support andrewshu

    (@andrewshu)

    Hello @melchi2

    First of all, you have a mistake here (there is no Y):

    $date = date("/m/d");

    Thank you.

    Plugin Support andrewshu

    (@andrewshu)

    Hi @melchi2

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread if any other questions come up and we’d be happy to help. ??

    Regards

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘celebration birthday’ is closed to new replies.