Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

capital_P_dangit ;) #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion classes/patreon_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private function __get_json( $suffix, $v2 = false ) {

$headers = array(
'Authorization' => 'Bearer ' . $this->access_token,
'User-Agent' => 'Patreon-Wordpress, version ' . PATREON_WORDPRESS_VERSION . PATREON_WORDPRESS_BETA_STRING . ', platform ' . php_uname('s') . '-' . php_uname( 'r' ),
'User-Agent' => 'Patreon-WordPress, version ' . PATREON_WORDPRESS_VERSION . PATREON_WORDPRESS_BETA_STRING . ', platform ' . php_uname('s') . '-' . php_uname( 'r' ),
);

$api_request = array(
Expand Down
46 changes: 23 additions & 23 deletions classes/patreon_frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ public static function getLabelOverUniversalButton( $patreon_level, $args = fals

$label = PATREON_TEXT_OVER_BUTTON_1;
$user_logged_into_patreon = self::isUserLoggedInPatreon();
$is_patron = Patreon_Wordpress::isPatron( wp_get_current_user() );
$is_patron = Patreon_WordPress::isPatron( wp_get_current_user() );
$messages = self::processPatreonMessages();
$user = wp_get_current_user();
$declined = Patreon_Wordpress::checkDeclinedPatronage( $user );
$user_patronage = Patreon_Wordpress::getUserPatronage();
$declined = Patreon_WordPress::checkDeclinedPatronage( $user );
$user_patronage = Patreon_WordPress::getUserPatronage();

// Get creator full name:
$creator_full_name = get_option( 'patreon-creator-full-name', false );
Expand All @@ -200,10 +200,10 @@ public static function getLabelOverUniversalButton( $patreon_level, $args = fals
if ( !isset( $args['lock'] ) ) {

if ( isset( $args['post_id'] ) ) {
$lock_or_not = Patreon_Wordpress::lock_or_not( $args['post_id'] );
$lock_or_not = Patreon_WordPress::lock_or_not( $args['post_id'] );
}
else {
$lock_or_not = Patreon_Wordpress::lock_or_not();
$lock_or_not = Patreon_WordPress::lock_or_not();
}
}

Expand Down Expand Up @@ -374,11 +374,11 @@ public static function getLabelUnderUniversalButton( $patreon_level, $state = f

$label = '';
$user_logged_into_patreon = self::isUserLoggedInPatreon();
$is_patron = Patreon_Wordpress::isPatron( wp_get_current_user() );
$is_patron = Patreon_WordPress::isPatron( wp_get_current_user() );
$messages = self::processPatreonMessages();
$user = wp_get_current_user();
$declined = Patreon_Wordpress::checkDeclinedPatronage( $user );
$user_patronage = Patreon_Wordpress::getUserPatronage();
$declined = Patreon_WordPress::checkDeclinedPatronage( $user );
$user_patronage = Patreon_WordPress::getUserPatronage();

// Get creator full name:
$creator_full_name = get_option( 'patreon-creator-full-name', false );
Expand All @@ -391,10 +391,10 @@ public static function getLabelUnderUniversalButton( $patreon_level, $state = f
if ( !isset( $args['lock'] ) ) {

if ( isset( $args['post_id'] ) ) {
$lock_or_not = Patreon_Wordpress::lock_or_not( $args['post_id'] );
$lock_or_not = Patreon_WordPress::lock_or_not( $args['post_id'] );
}
else {
$lock_or_not = Patreon_Wordpress::lock_or_not();
$lock_or_not = Patreon_WordPress::lock_or_not();
}
}

Expand Down Expand Up @@ -668,7 +668,7 @@ public static function patreonMakeUniversalButtonLabel() {

$label = apply_filters( 'ptrn/universal_button_label', PATREON_TEXT_UNLOCK_WITH_PATREON );
$user_logged_into_patreon = self::isUserLoggedInPatreon();
$is_patron = Patreon_Wordpress::isPatron();
$is_patron = Patreon_WordPress::isPatron();

// Change this after getting info about which value confirms user's payment is declined. The only different button label is for that condition.

Expand All @@ -692,7 +692,7 @@ public static function isUserLoggedInPatreon() {
if ( $user ) {

// REVISIT - whats below may be a concern - it connects to API to check for valid user for every generation of button. If we could cache it it would be better
$user_response = Patreon_Wordpress::getPatreonUser( $user );
$user_response = Patreon_WordPress::getPatreonUser( $user );

if ( $user_response ) {
// This is a user logged into Patreon.
Expand Down Expand Up @@ -772,7 +772,7 @@ public static function patreonMakeLoginButton( $client_id = false ) {

if ( $user ) {

$user_response = Patreon_Wordpress::getPatreonUser( $user );
$user_response = Patreon_WordPress::getPatreonUser( $user );
// ^ REVISIT - whats above may be a concern - it connects to API to check for valid user for every generation of button. If we could cache it it would be better

if ( $user_response ) {
Expand Down Expand Up @@ -857,10 +857,10 @@ public static function lock_this_post( $post = false ) {
}

$user = wp_get_current_user();
$user_pledge_relationship_start = Patreon_Wordpress::get_user_pledge_relationship_start();
$user_patronage = Patreon_Wordpress::getUserPatronage();
$user_lifetime_patronage = Patreon_Wordpress::get_user_lifetime_patronage();
$declined = Patreon_Wordpress::checkDeclinedPatronage($user);
$user_pledge_relationship_start = Patreon_WordPress::get_user_pledge_relationship_start();
$user_patronage = Patreon_WordPress::getUserPatronage();
$user_lifetime_patronage = Patreon_WordPress::get_user_lifetime_patronage();
$declined = Patreon_WordPress::checkDeclinedPatronage($user);

// Check if post was set for active patrons only
$patreon_active_patrons_only = get_post_meta( $post->ID, 'patreon-active-patrons-only', true );
Expand Down Expand Up @@ -957,7 +957,7 @@ public static function protectContentFromUsers( $content, $post_id = false ) {

// Now send the post id to locking decision function

$lock_or_not = Patreon_Wordpress::lock_or_not($post_id);
$lock_or_not = Patreon_WordPress::lock_or_not($post_id);

// An array with args should be returned
$hide_content = false;
Expand Down Expand Up @@ -1024,11 +1024,11 @@ public static function MakeValidPatronFooter( $patreon_level, $user_patronage, $

$label = PATREON_VALID_PATRON_POST_FOOTER_TEXT;
$user_logged_into_patreon = self::isUserLoggedInPatreon();
$is_patron = Patreon_Wordpress::isPatron( wp_get_current_user() );
$is_patron = Patreon_WordPress::isPatron( wp_get_current_user() );
$messages = self::processPatreonMessages();
$user = wp_get_current_user();
$declined = Patreon_Wordpress::checkDeclinedPatronage( $user );
$user_patronage = Patreon_Wordpress::getUserPatronage();
$declined = Patreon_WordPress::checkDeclinedPatronage( $user );
$user_patronage = Patreon_WordPress::getUserPatronage();

// Get creator full name:
$creator_full_name = get_option( 'patreon-creator-full-name', false );
Expand All @@ -1041,10 +1041,10 @@ public static function MakeValidPatronFooter( $patreon_level, $user_patronage, $
if ( !isset( $args['lock'] ) ) {

if ( isset( $args['post_id'] ) ) {
$lock_or_not = Patreon_Wordpress::lock_or_not( $args['post_id'] );
$lock_or_not = Patreon_WordPress::lock_or_not( $args['post_id'] );
}
else {
$lock_or_not = Patreon_Wordpress::lock_or_not();
$lock_or_not = Patreon_WordPress::lock_or_not();
}
}

Expand Down
6 changes: 3 additions & 3 deletions classes/patreon_login.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public static function createOrLogInUserFromPatreon($user_response, $tokens, $re

} else {

/* log user into existing wordpress account with matching username */
/* log user into existing WordPress account with matching username */
wp_set_current_user( $user->ID, $user->user_login );
wp_set_auth_cookie( $user->ID );
do_action( 'wp_login', $user->user_login, $user );
Expand Down Expand Up @@ -248,7 +248,7 @@ public static function createOrLogInUserFromPatreon($user_response, $tokens, $re

if ( $user == false ) {

/* create wordpress user with provided username */
/* create WordPress user with provided username */

$random_password = wp_generate_password( 64, false );
$user_email = '';
Expand Down Expand Up @@ -327,7 +327,7 @@ public static function createOrLogInUserFromPatreon($user_response, $tokens, $re

} else {

/* wordpress account creation failed */
/* WordPress account creation failed */

$redirect = add_query_arg( 'patreon_message', 'patreon_could_not_create_wp_account', $redirect );
wp_redirect( $redirect );
Expand Down
2 changes: 1 addition & 1 deletion classes/patreon_oauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private function __update_token( $params ) {
$api_endpoint = "https://api.patreon.com/oauth2/token";

$headers = array(
'User-Agent' => 'Patreon-Wordpress, version ' . PATREON_WORDPRESS_VERSION . PATREON_WORDPRESS_BETA_STRING . ', platform ' . php_uname('s') . '-' . php_uname( 'r' ),
'User-Agent' => 'Patreon-WordPress, version ' . PATREON_WORDPRESS_VERSION . PATREON_WORDPRESS_BETA_STRING . ', platform ' . php_uname('s') . '-' . php_uname( 'r' ),
);

$api_request = array(
Expand Down
10 changes: 5 additions & 5 deletions classes/patreon_options.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function patreon_plugin_setup_page(){
<div class="wrap">

<div id="icon-options-general" class="icon32"></div>
<h1>Patreon Wordpress Settings</h1>
<h1>Patreon WordPress Settings</h1>

<div id="poststuff">

Expand Down Expand Up @@ -141,7 +141,7 @@ function patreon_plugin_setup_page(){
<div class="handlediv" title="Click to toggle"><br /></div>
<!-- Toggle -->

<h2 class="handle"><span>Patreon Wordpress Options</span></h2>
<h2 class="handle"><span>Patreon WordPress Options</span></h2>

<div class="inside">

Expand Down Expand Up @@ -243,13 +243,13 @@ function patreon_plugin_setup_page(){
<div class="handlediv" title="Click to toggle"><br></div>
<!-- Toggle -->

<h2 class="hndle">About Patreon Wordpress</h2>
<h2 class="hndle">About Patreon WordPress</h2>

<div class="inside">
<p>Patreon Wordpress developed by Patreon</p>
<p>Patreon WordPress developed by Patreon</p>

<p><strong>SUPPORT &amp; TECHNICAL HELP</strong> <br>
We actively support this plugin on our <a href="https://www.patreondevelopers.com/c/patreon-wordpress-plugin-support" target="_blank">Patreon Wordpress Support Forum</a>.</p>
We actively support this plugin on our <a href="https://www.patreondevelopers.com/c/patreon-wordpress-plugin-support" target="_blank">Patreon WordPress Support Forum</a>.</p>
<p><strong>DOCUMENTATION</strong> <br>Technical documentation and code examples available @ <a href="https://patreon.com/apps/wordpress" target="_blank">https://patreon.com/apps/wordpress</a></p>
</div>
<!-- .inside -->
Expand Down
8 changes: 4 additions & 4 deletions classes/patreon_protect.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@ public static function servePatronOnlyImage( $image=false ) {

// We are here, then we have a nonzero pledge level. Protect the image.

$user_patronage = Patreon_Wordpress::getUserPatronage();
$user_patronage = Patreon_WordPress::getUserPatronage();

$user = wp_get_current_user();

$declined = Patreon_Wordpress::checkDeclinedPatronage( $user );
$declined = Patreon_WordPress::checkDeclinedPatronage( $user );

if ($user_patronage == false
|| $user_patronage < ( $patreon_level * 100 )
Expand Down Expand Up @@ -833,9 +833,9 @@ public static function checkPatronPledgeForImage( $attachment_id, $user = false
return 0;
}

$declined_patron = Patreon_Wordpress::checkDeclinedPatronage($user);
$declined_patron = Patreon_WordPress::checkDeclinedPatronage($user);

$patron_pledge = Patreon_Wordpress::getUserPatronage();
$patron_pledge = Patreon_WordPress::getUserPatronage();

$patreon_level = get_post_meta( $attachment_id, 'patreon_level', true );

Expand Down
26 changes: 16 additions & 10 deletions classes/patreon_wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
die;
}

class Patreon_Wordpress {
class Patreon_WordPress {

private static $Patreon_Routing;
private static $Patreon_Frontend;
Expand Down Expand Up @@ -61,7 +61,7 @@ function __construct() {
add_action( 'init', array( $this, 'checkPatreonCreatorName' ) );
add_action( 'init', 'Patreon_Login::checkTokenExpiration' );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueueAdminScripts' ) );
add_action( 'upgrader_process_complete', 'Patreon_Wordpress::AfterUpdateActions', 10, 2 );
add_action( 'upgrader_process_complete', 'Patreon_WordPress::AfterUpdateActions', 10, 2 );
add_action( 'admin_notices', array( $this, 'AdminMessages' ) );
add_action( 'init', array( $this, 'transitionalImageOptionCheck' ) );
add_action( 'admin_init', array( $this, 'add_privacy_policy_section' ), 20 ) ;
Expand Down Expand Up @@ -164,7 +164,7 @@ static function updatePatreonUser() {
// Set the update time
update_user_meta( $user->ID, 'patreon_user_details_last_updated', time() );

/* all the details you want to update on wordpress user account */
/* all the details you want to update on WordPress user account */
update_user_meta( $user->ID, 'patreon_user', $user_response['data']['attributes']['vanity'] );
update_user_meta( $user->ID, 'patreon_created', $user_response['data']['attributes']['created'] );
update_user_meta( $user->ID, 'user_firstname', $user_response['data']['attributes']['first_name'] );
Expand Down Expand Up @@ -994,11 +994,11 @@ public static function lock_or_not( $post_id = false ) {
}

$user = wp_get_current_user();
$user_pledge_relationship_start = Patreon_Wordpress::get_user_pledge_relationship_start( $user );
$user_patronage = Patreon_Wordpress::getUserPatronage( $user );
$is_patron = Patreon_Wordpress::isPatron( $user );
$user_lifetime_patronage = Patreon_Wordpress::get_user_lifetime_patronage( $user );
$declined = Patreon_Wordpress::checkDeclinedPatronage( $user );
$user_pledge_relationship_start = Patreon_WordPress::get_user_pledge_relationship_start( $user );
$user_patronage = Patreon_WordPress::getUserPatronage( $user );
$is_patron = Patreon_WordPress::isPatron( $user );
$user_lifetime_patronage = Patreon_WordPress::get_user_lifetime_patronage( $user );
$declined = Patreon_WordPress::checkDeclinedPatronage( $user );
$active_patron_at_post_date = false;

// Just bail out if this is not the main query for content and no post id was given
Expand Down Expand Up @@ -1288,7 +1288,7 @@ public static function populate_patreon_level_select_from_ajax() {

$post = get_post( $_REQUEST['pw_post_id'] );

echo Patreon_Wordpress::make_tiers_select( $post );
echo Patreon_WordPress::make_tiers_select( $post );
exit;

}
Expand Down Expand Up @@ -1427,4 +1427,10 @@ public static function update_creator_tiers_from_api() {

}

}
}


/**
* Backwards compatibility
**/
class_alias('Patreon_WordPress','Patreon_Wordpress');
9 changes: 5 additions & 4 deletions patreon.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/*
Plugin Name: Patreon Wordpress
Plugin Name: Patreon WordPress
Plugin URI: https://www.patreon.com/apps/wordpress
Description: Patron-only content, directly on your website.
Version: 1.2.6
Expand Down Expand Up @@ -45,7 +45,7 @@
define( "PATREON_TEXT_UNDER_BUTTON_2", 'Already a Patreon member? <a href="%%flow_link%%" rel="nofollow">Refresh</a> to access this post.' );
define( "PATREON_TEXT_UNDER_BUTTON_3", 'Already updated? <a href="%%flow_link%%" rel="nofollow">Refresh</a> to access this post.' );
define( "PATREON_CANT_LOGIN_STRICT_OAUTH", 'Sorry, couldn\'t log you in with Patreon because you have to be logged in to '.get_bloginfo('NAME').' first' );
define( "PATREON_LOGIN_WITH_WORDPRESS_NOW", 'You can now login with your wordpress username/password.' );
define( "PATREON_LOGIN_WITH_WORDPRESS_NOW", 'You can now login with your WordPress username/password.' );
define( "PATREON_CANT_LOGIN_NONCES_DONT_MATCH", 'Sorry. Aborted Patreon login for security because security cookies dont match.' );
define( "PATREON_CANT_LOGIN_DUE_TO_API_ERROR", 'Sorry. Login aborted due to an API error.' );
define( "PATREON_CANT_LOGIN_DUE_TO_API_ERROR_CHECK_CREDENTIALS", 'Sorry. Login aborted due to an API error. Please check API credentials.' );
Expand Down Expand Up @@ -84,9 +84,10 @@
define( "PATREON_COULDNT_ACQUIRE_USER_DETAILS", 'Sorry. Could not acquire your info from Patreon. Please try again later.' );
define( "PATREON_TEXT_EVERYONE", 'Everyone' );
define( "PATREON_TEXT_ANY_PATRON", 'Any patron' );
define( 'PATREON_TEXT_YOU_HAVE_NO_REWARDS_IN_THIS_CAMPAIGN', '' );

include 'classes/patreon_wordpress.php';

register_activation_hook( __FILE__, array( 'Patreon_Wordpress', 'activate' ) );
register_activation_hook( __FILE__, array( 'Patreon_WordPress', 'activate' ) );

$Patreon_Wordpress = new Patreon_Wordpress;
$Patreon_WordPress = new Patreon_WordPress;