• Resolved lspoe2

    (@lspoe2)


    Hi,

    I offer Non-Renewing memberships. When expired, use gets another membership level as per below:

    /*
    	When users cancel (are changed to membership level 0) we give them another "cancelled" level. Can be used to downgrade someone to a free level when they cancel.
    */
    function pmpro_after_change_membership_level_default_level($level_id, $user_id)
    {
    	//if we see this global set, then another gist is planning to give the user their level back
    	global $pmpro_next_payment_timestamp;
    	if(!empty($pmpro_next_payment_timestamp))
    		return;
    	
    	if($level_id == 0) {
    		//cancelling, give them level 1 instead
    		pmpro_changeMembershipLevel(9, $user_id);
    	}
    }
    add_action("pmpro_after_change_membership_level", "pmpro_after_change_membership_level_default_level", 10, 2);

    Additionally, I’m using the below snippet to move the authors post to a closed down status. However the below snippet is not working when a user is downgraded via the system. It only works when I manually change the users level to level 9.

    I’m not sure what I’m doing wrong here.
    Maybe I should change $level_id == 9 to $level_id == 0 ?

    Or could it be that the wp cron job didn’t run properly as my site is still private and does not have many visitors?

    function pmpro_after_change_author_level_update_posts( $level_id, $user_id ) {
    	//get the user roles
    	$usermeta = get_userdata($user_id);
    	$user_roles = $usermeta->roles;
    	
    	//check if the user is an author and is cancelling
    	if ( $level_id == 9 ) { 
    		//get the user's posts
    		$args = array(
    			'post_type'       =>  'post',
    	    );
    		$user_posts = get_posts( $args );
    		foreach ( $user_posts as $user_post ) {
    			$post = array( 'ID' => $user_post->ID, 'post_status' => 'gd-closed' );
    			wp_update_post($post);
    		}
    	}
    }
    add_action( 'pmpro_after_change_membership_level', 'pmpro_after_change_author_level_update_posts', 10, 2);

    Thanks

    • This topic was modified 2 years, 6 months ago by lspoe2.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Change post status after change membership level’ is closed to new replies.