WordPress.org

Ready to get started?Download WordPress

Forums

Get Notified of User's One Year Anniversary After Registration - Possible? (3 posts)

  1. Freelancealot
    Member
    Posted 2 years ago #

    Hi,

    I've tried to find a plugin but haven't been 100% successful.

    Members List will let me see a list of users via the registration date. So the information is in the database to be used.

    Is there anyway of getting notified as the WP Admin when a user reaches the 365th day after they registered -- ie, their one-year anniversary as a member of the site?

    So put simply, something along the lines of:

    <?php
    
    function user_anniversary {
    if user = subscriber (& registration date +365 days = today) 
    
    action "notify Admin (via email preferably)" 
    
    }

    As you may guess, I'm not a natural php coder!! ;)

    I'm pretty sure I'm not the only one having requested this, but can't seem to find anything.

    Any pointers gratefully received.

    Cheers,

    Tracy

  2. TCBarrett
    Member
    Posted 2 years ago #

    Here's a quick, untested, snippet that will hopefully inspire you.

    <?php
    global $current_user;
    get_currentuserinfo();
    
    $registered = $current_user->user_registered;
    $now        = date('Y-m-d H:i:s');
    $diff       = strtotime($now) - strtotime($registered);
    $days       = $diff / (60 * 60 *24);
    $daysround  = round($days);
    
    if( $daysround == 365 ) echo "Happy anniversary";
    ?>

    Don't forget leap years...

  3. Freelancealot
    Member
    Posted 2 years ago #

    Hi tcbarrett,

    Thanks for this -- looks promising.

    Somehow I need to add an instruction to email Admin in place of the:

    echo "Happy anniversary"

    I found this useful snippet (at http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/) that looks well on the way to getting what I want along with the above code (slighly hacked for this purpose):

    if (!wp_next_scheduled('my_task_hook')) {
       wp_schedule_event( time(), 'daily', 'my_task_hook' );
    }
    
    add_action( 'my_task_hook', 'my_task_function' );
    
    function my_task_function() {
      wp_mail('blogadmin@mysite.com', 'Automatic email', 'User-name has been a member for one year.');
    }

    Basically, a scheduled event happening daily, that will call the function to check if any user has been a member for 365 days.

    I just don't know how to marry the two snippets of code above. As I say, I'm not a programmer so I'm relying heavily on you experts out there.

    Cheers,

    Tracy

Topic Closed

This topic has been closed to new replies.

About this Topic