maxworkingwell

check_user_valid_cron_hook

Oct 29th, 2021 (edited)
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.08 KB | None | 0 0
  1. add_action( 'check_user_valid_cron_hook', 'check_user_valid_func' );
  2.  
  3. if ( ! wp_next_scheduled( 'check_user_valid_cron_hook' ) ) {
  4.     wp_schedule_event( time(), 'daily', 'check_user_valid_cron_hook' );
  5. }
  6.  
  7.   function check_user_valid_func() {
  8.  
  9.      // The Query
  10.     $user_query = new WP_User_Query( array( 'role' => 'Purchaser', 'fields' => 'all' ) );
  11.     $today = date("U");
  12.  
  13.      // User Loop
  14.     if ( ! empty( $user_query->get_results() ) ) {
  15.         foreach ( $user_query->get_results() as $user ) {
  16.  
  17.             $validuntil = types_render_usermeta( "date-of-home-purchase", array( "user_id" => "$user->ID", "output" => "raw" ) );
  18.             $user_id = $user->ID;
  19.  
  20.             if($validuntil < $today) {
  21.                  
  22.                 $user = get_userdata( $user_id );
  23.                     $user->user_email;
  24.  
  25.                     $message = '
  26. <html>
  27. <head>
  28. <title>Email title</title>
  29. </head>
  30. <body>
  31. <p>Some text</p>
  32. </body>
  33. </html>
  34. ';
  35.                     wp_mail( $user, 'Your subject', $message, $headers, $attachments );
  36.  
  37.             }
  38.         }
  39.     }
  40. }
Add Comment
Please, Sign In to add comment