diff --git a/assets/js/admin.js b/assets/js/admin.js index e95c91b..20cae4e 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -11,6 +11,7 @@ var patreon_wordpress_nonce_patron_content_manager_addon_notice_shown = jQuery( this ).parent().attr( 'patreon_wordpress_nonce_patron_content_manager_addon_notice_shown' ); var patreon_wordpress_nonce_rate_plugin_notice = jQuery( this ).parent().attr( 'patreon_wordpress_nonce_rate_plugin_notice' ); var patreon_wordpress_nonce_plugin_critical_issues = jQuery( this ).parent().attr( 'patreon_wordpress_nonce_plugin_critical_issues' ); + var patreon_wordpress_nonce_patreon_api_version_update = jQuery(this).parent().attr( 'patreon_wordpress_nonce_patreon_api_version_update' ); jQuery.ajax({ url: ajaxurl, type:"POST", @@ -23,6 +24,7 @@ patreon_wordpress_nonce_patron_pro_addon_notice_shown: patreon_wordpress_nonce_patron_pro_addon_notice_shown, patreon_wordpress_nonce_patron_content_manager_addon_notice_shown: patreon_wordpress_nonce_patron_content_manager_addon_notice_shown, patreon_wordpress_nonce_plugin_critical_issues: patreon_wordpress_nonce_plugin_critical_issues, + patreon_wordpress_nonce_patreon_api_version_update: patreon_wordpress_nonce_patreon_api_version_update, } }); }); @@ -372,12 +374,17 @@ data: { action: 'patreon_wordpress_disconnect_patreon_account', patreon_disconnect_user_id: jQuery( this ).attr( 'patreon_disconnect_user_id' ), + patreon_wordpress_nonce_disconnect_user_account_from_patreon: jQuery(this).attr( 'patreon_wordpress_nonce_disconnect_user_account_from_patreon' ), }, beforeSend: function(e) { jQuery( '#patreon_wordpress_user_profile_account_connection_wrapper' ).html( 'A moment...' ); }, success: function( response ) { - jQuery( '#patreon_wordpress_user_profile_account_connection_wrapper' ).html( response ); + var message = response; + if (response == 0 ) { + message = 'This form seems to have expired - please refresh the form and Disconnect again'; + } + jQuery('#patreon_wordpress_user_profile_account_connection_wrapper').html(message ); }, }); diff --git a/classes/patreon_api_v2.php b/classes/patreon_api_v2.php index 2c59912..40edfec 100644 --- a/classes/patreon_api_v2.php +++ b/classes/patreon_api_v2.php @@ -19,7 +19,7 @@ public function fetch_user() { // We construct the old return from the new returns by combining /me and pledge details - $api_return = $this->__get_json( "identity?include=memberships.currently_entitled_tiers,memberships.campaign&fields[user]=email,first_name,full_name,image_url,last_name,thumb_url,url,vanity,is_email_verified&fields[member]=currently_entitled_amount_cents,lifetime_support_cents,campaign_lifetime_support_cents,last_charge_status,patron_status,last_charge_date,pledge_relationship_start,pledge_cadence" ); + $api_return = $this->__get_json( "identity?include=memberships.currently_entitled_tiers,memberships.campaign&fields[user]=email,first_name,full_name,image_url,last_name,thumb_url,url,vanity,is_email_verified&fields[member]=currently_entitled_amount_cents,lifetime_support_cents,campaign_lifetime_support_cents,last_charge_status,patron_status,last_charge_date,pledge_relationship_start,pledge_cadence" ); $creator_id = get_option( 'patreon-creator-id', false ); $campaign_id = get_option( 'patreon-campaign-id', false ); @@ -31,7 +31,7 @@ public function fetch_user() { foreach ($api_return['included'] as $key => $value) { - if ( $api_return['included'][$key]['type'] == 'member' AND $api_return['included'][$key]['relationships']['campaign']['data']['id'] == $campaign_id ) { + if ( $api_return['included'][$key]['type'] == 'member' AND ( isset( $api_return['included'][$key]['relationships']['campaign'] ) AND $campaign_id AND $api_return['included'][$key]['relationships']['campaign']['data']['id'] == $campaign_id ) ) { // The below procedure will take take the matching membership out of the array, put it to the top and reindex numberic keys. This will allow backwards compatibility to be kept $membership = $api_return['included'][$key]; @@ -43,7 +43,7 @@ public function fetch_user() { $api_return['included'][0]['type'] = 'pledge'; $api_return['included'][0]['attributes']['amount_cents'] = $api_return['included'][0]['attributes']['currently_entitled_amount_cents']; $api_return['included'][0]['attributes']['created_at'] = $api_return['included'][0]['attributes']['pledge_relationship_start']; - $api_return['included'][0]['attributes']['lifetime_support_cents'] = $api_return['included'][0]['attributes']['campaign_lifetime_support_cents']; + $api_return['included'][0]['attributes']['lifetime_support_cents'] = $api_return['included'][0]['attributes']['campaign_lifetime_support_cents']; if ( $api_return['included'][0]['attributes']['last_charge_status'] != 'Paid' ) { $api_return['included'][0]['attributes']['declined_since'] = $api_return['included'][0]['attributes']['last_charge_date']; @@ -165,7 +165,7 @@ public function add_post_webhook( $params = array() ) { if ( is_wp_error( $check_url ) ) { return; - } + } $postfields = array( 'data' => array ( diff --git a/classes/patreon_login.php b/classes/patreon_login.php index 048369b..3cbdbb8 100644 --- a/classes/patreon_login.php +++ b/classes/patreon_login.php @@ -502,6 +502,10 @@ public static function get_update_user_patreon_avatar( $patreon_image_url, $user public static function disconnect_account_from_patreon() { // Disconnects an account from Patreon. + + if ( !isset($_REQUEST['patreon_wordpress_nonce_disconnect_user_account_from_patreon']) OR !wp_verify_nonce( sanitize_key( $_REQUEST['patreon_wordpress_nonce_disconnect_user_account_from_patreon'] ), 'patreon_wordpress_nonce_disconnect_user_account_from_patreon' ) ) { + return; + } $user = wp_get_current_user(); diff --git a/classes/patreon_user_profiles.php b/classes/patreon_user_profiles.php index 64741e2..b91fe4b 100644 --- a/classes/patreon_user_profiles.php +++ b/classes/patreon_user_profiles.php @@ -124,7 +124,7 @@ function patreon_user_profile_fields( $user ) {
Your site's connection to Patreon must be upgraded to ensure that Patreon features will work! Please click here to start the setup wizard to reconnect your site again
+