First post here and I’m not really a coder but have some understanding - I need to do the following in a directory theme that has a custom membership package as part of the theme. Its Atlas theme. The developer understandably does not support theme customizations, so hope someone can help.

The theme has membership packages for users that enable users to post listings. When the user membership expires, the listings posts do not expire or change status. There is no link between packages and post status. The user does lose the ability to edit or publish posts when the membership expires but the post will still be visible.

What I would like to do is this

  1. Change post status to draft when the user membership expires

Looking at the theme files there is a cronjob that runs to check when the membership is due to expire

/*
Expiring Memberships
*/
add_action(“tdp_cron_expire_memberships”, “tdp_cron_expire_memberships”);
function tdp_cron_expire_memberships()
{
global $wpdb;

    //make sure we only run once a day
    $today = date("Y-m-d");
    //look for memberships that expired before today
    $sqlQuery = "SELECT mu.user_id, mu.membership_id, mu.startdate, mu.enddate FROM $wpdb->tdp_memberships_users mu WHERE mu.status = 'active' AND mu.enddate IS NOT NULL AND mu.enddate <> '' AND mu.enddate <> '0000-00-00 00:00:00' AND DATE(mu.enddate) <= '" . $today . "' ORDER BY mu.enddate";
    $expired = $wpdb->get_results($sqlQuery);
    foreach($expired as $e)
    {                       
        //remove their membership
        tdp_changeMembershipLevel(false, $e->user_id);
        $send_email = apply_filters("tdp_send_expiration_email", true, $e->user_id);
        if($send_email)
        {
            //send an email
            $tdpemail = new TDpEmail();
            $euser = get_userdata($e->user_id);     
            $tdpemail->sendMembershipExpiredEmail($euser);
            printf(__("Membership expired email sent to %s. ", "tdp"), $euser->user_email);             
        }
    }
}
/*
    Expiration Warning Emails
*/
add_action("tdp_cron_expiration_warnings", "tdp_cron_expiration_warnings");
function tdp_cron_expiration_warnings()
{   
    global $wpdb;
    //make sure we only run once a day
    $today = date("Y-m-d 00:00:00");
    $tdp_email_days_before_expiration = apply_filters("tdp_email_days_before_expiration", 7);
    //look for memberships that are going to expire within one week (but we haven't emailed them within a week)
    $sqlQuery = "SELECT mu.user_id, mu.membership_id, mu.startdate, mu.enddate FROM $wpdb->tdp_memberships_users mu LEFT JOIN $wpdb->usermeta um ON um.user_id = mu.user_id AND um.meta_key = 'tdp_expiration_notice' WHERE mu.status = 'active' AND mu.enddate IS NOT NULL AND mu.enddate <> '' AND mu.enddate <> '0000-00-00 00:00:00' AND DATE_SUB(mu.enddate, INTERVAL " . $tdp_email_days_before_expiration . " Day) <= '" . $today . "' AND (um.meta_value IS NULL OR DATE_ADD(um.meta_value, INTERVAL " . $tdp_email_days_before_expiration . " Day) <= '" . $today . "') ORDER BY mu.enddate";
    $expiring_soon = $wpdb->get_results($sqlQuery);
    foreach($expiring_soon as $e)
    {               
        $send_email = apply_filters("tdp_send_expiration_warning_email", true, $e->user_id);
        if($send_email)
        {
            //send an email
            $tdpemail = new TDpEmail();
            $euser = get_userdata($e->user_id);     
            $tdpemail->sendMembershipExpiringEmail($euser);
            printf(__("Membership expiring email sent to %s. ", "tdp"), $euser->user_email);
        }
        //update user meta so we don't email them again
        update_user_meta($euser->ID, "tdp_expiration_notice", $today);
    }
}

From the themes forums, these function will check a users membership id

//Find membership level of the author of this post -JKB
function author_membership_level($this_post_id) {
global $wpdb;
global $post_author_membership;

$post_author_info = "SELECT mu.membership_id, mu.status
FROM $wpdb->tdp_memberships_users mu 
LEFT JOIN $wpdb->posts po ON mu.user_id = po.post_author 
WHERE mu.status = 'active' AND po.ID = " . $this_post_id;
$post_author_membership = $wpdb->get_results($post_author_info);

Can anyone suggest what I would need to create do to check membership expiry date and then set all posts assigned to a membership to draft status when it expires

Is it possible to just add an extra part to cron?

I did come across this for gravity forms, sorry I am not sure how to combine the 2 parts of the code and its a slightly different scenario

Many Thanks in Advance

Change post status based on user role

Read more here: How to set post status to draft when theme membership expires


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , , ,

Wordpress related questions and answers: