How does this plugin pull patreon data?

Hey all! I’m new to this plug in but have a couple years of wordpress under my belt. For awhile, I have had to manually edit users every time a pledge changed.

This plug in looks like it can automate a lot of work for me but I don’t quite understand…

  1. How does my website pull the patreon data? Does it automatically try to match the email address from their user login between the two systems? How do they link or what is the process the users have to go through to link the accounts?

  2. I have a special PHP code that checks on donors level. How would it be phrased with this plug in? For example, my current code looks like this… How would I modify for this plug in?

Thank you!

$user_id = get_current_user_id();
$current_level = intVal(get_user_meta($user_id, ‘learndash_plus_level’, true ));
$levels = learndash_plus_get_levels();
$currentlevelname = $levels[$current_level][‘name’];

// echo “Welcome. You are a $currentlevelname”;
if (strpos($currentlevelname,‘Patreon’) == false){
// if Patreon is in the name of the membership then…

It does not automatically sync the email addresses between the two systems, the user (patron) will have to give you permission to access his Patreon data through the API. The plugin makes this possible.

I’m sure @codebard will be able to address your second point.

1 Like

1 - Plugin login/registration works with the below logic currently:

  • The plugin first checks if the user is logged into wordpress.
  • If yes, then it links that Patreon account to that WP account and logs it in.
  • If the WP account didnt have an email saved (unlikely) and Patreon account has its mail verified - we dont save it currently - we may start doing it in next versions but its unlikely that an already created WP account would be without an email
  • If the user is not logged in, the plugin gets user’s id from Patreon return and checks for a linked WP account
  • If linked wp accounts are found, the user is logged into the account which is the linked (latest linked )
  • If no linked wp accounts are found, a new user is created with patreon_XXXX nickname where XXXX is user’s patreon id
  • If the user has his/her email verified at Patreon, email is imported if not, no
  • User is logged in

2 - Patreon_Wordpress::getUserPatronage(); would get you the $ level of the patron. In cents. This is how we check user patronage level. Currently we dont get the precise patronage/reward level at Patreon.

  	$user_patronage = Patreon_Wordpress::getUserPatronage();

  	$declined = Patreon_Wordpress::checkDeclinedPatronage($user);
  	
  	if($user_patronage == false 
  		|| $user_patronage < ($patreon_level*100)
  		|| $declined
  	) {

Above code should cover all check cases.

You can compare the $ amount of the pledge level you are getting with your code with the $ amount that function gets and match them.