WordPress doesn’t have a “Duration Since Signup” value so you’ll need to calculate it by finding the difference between the user registration date and the current date. I suggest getting the user above the conditional:
function set_mail_html_content_type() {
return 'text/html';
}
add_action( 'user_help_signup', 10 ,2 );
function user_help_signup( $ID, //DURATION SINCE SIGN UP ) {
$curr_user = get_user_by( 'id', $post->post_author );
$reg_date = new DateTime( $curr_user->user_registered );
$curr_date = new DateTime();
$days_reg = intval( $curr_date->diff( $reg_date )->format( "%a" ) );
if ( $days_reg > 3 || count_user_posts( $post->post_author ) > 1 ) {
return;
}
$to = $curr_user->user_email;
$subject="Need help ?";
$headers = array('Content-Type: text/html');
$message="<h3>Hi {display_name}! </h3> <p>
You signed up 3 days ago on mysite.com and we wanted to know if we could help you to get started ";
wp_mail( $to, $subject, $message, 'Content-Type: text/html' );
}
We know that $curr_user->user_registered
holds the date that the user registered and DateTime()
will get the current date so we can use the built-in DateTime method diff()
to get the difference and put it in as day format as %r%a
. There’s a good StackOverflow Answer on getting the day difference between two dates.