Can you rerun the subscription pings

Is there an easy way to rerun the subscription pings? We weren't able to get them working properly before launch so there are a number of accounts that didn't go through that process. It would be nice to be able to rerun them.

  • Cagle Webmaster

    I would presume I could just loop through the subscribers (though I'm not sure how to get the query just right for that) and fire the pings if I knew which code to run to do that. So I guess the secondary question for your dev team is what is the best way to get a list of subscribers and how do I fire off the ping. Knowing that I could handle the rest.

  • Jude

    Hi again @Cagle Webmaster,

    Hope you're doing great.

    Here is a function that does this with some commetnts

    // Function to get a list of users based on date joined / subscription type / level etc and refire pings
    
    	function refire_pings()
    	{
    		global $wpdb;
    	   		$query = "SELECT  ID , sub_id, level_id, user_email, user_login ,display_name
    				                           FROM  wp_m_membership_relationships
    	                  			INNER JOIN  wp_users ON wp_m_membership_relationships.user_id = wp_users.ID
    	                  			WHERE  startdate
    	                  			BETWEEN  '2015-01-30 23:59:59'
    	                   			AND  '2015-02-01 23:59:59'"
    
    	  		$new_users = $wpdb->get_results($query);
    
    	  		// Loop through the each user and fire respective ping
    	    	foreach ($new_users as $user) {
    	    		// Get the level for each user (perform conditionals here if needed)
    	    		$level = Membership_Plugin::factory()->get_level( $user->level_id );
    
    				// Get the Joining ping (can be any other ping type)
    				$joiningping_id = $level->get_meta( 'joining_ping' );
    					// Fire the pings
    					if ( !empty( $joiningping_id ) ) {
    						$ping = new M_Ping( $joiningping_id );
    						$ping->send_ping( false, $user->level_id, $user->ID);
    					}
    	    	}
    	   	return ;
    	}

    You can find some SQL variants here

    Cheers
    Jude