Let all loggedin users to access members page, no matter from

when they register
parent 124a77f7
# SexHackMe Wordpress Plugin # SexHackMe Wordpress Plugin
This plugin is developed for the website https://www.sexhack.me This plugin is developed for the website https://www.sexhack.me
\ No newline at end of file
The plugin is in a very early developement stage therefore
continuosly evolving and possibly still very bugged, so
please contact me if you like to use it at franco@nexlab.it
plugin dependencies aren't really fully managed (yet),
this is a list of the actual dependencies:
* WooCommerce (core dependency)
* Paid Members Subscriptions (core dependency)
* Unlock Protocol (only if enabled in the general options)
It is also assumed you are using storefront as a theme in couple with
WooCommerce, but should work with other themes too.
This is NOT a proper TODO list.
It's just a quick dirty list of things i want to
remember to do, mostly little refinery.
---------------------------------------
* Look at exporters/importers of user data: https://rudrastyh.com/wordpress/personal-data-exporters-and-erasers.html
* reduce duplication of code, database queries.
-------------------------------------
SOON OR LATER this plugin will be re-written to make some order and re-group
action, filters and so on with a better organizations of classes, hooks etc,
and then the initialization will be re-done from scratch removing the "sub plugin selection"
while we will remove dependencies from woocommerce, pms and the rest.
...@@ -29,17 +29,44 @@ if(!class_exists('SexhackAddUnlockLogin')) { ...@@ -29,17 +29,44 @@ if(!class_exists('SexhackAddUnlockLogin')) {
add_filter("login_form_bottom", array($this, "add_to_login"), 10, 2); add_filter("login_form_bottom", array($this, "add_to_login"), 10, 2);
add_action("woocommerce_after_order_notes", array($this, "add_to_checkout")); add_action("woocommerce_after_order_notes", array($this, "add_to_checkout"));
add_filter("pms_register_shortcode_content", array($this, "add_to_register"), 10, 2); add_filter("pms_register_shortcode_content", array($this, "add_to_register"), 10, 2);
add_filter("unlock_authenticate_user", array($this, "fix_unlock_user"), 11, 1);
sexhack_log('SexhackAddUnlockLogin() Instanced'); sexhack_log('SexhackAddUnlockLogin() Instanced');
} }
public function get_proto(){ public function get_proto(){
if(is_ssl()) { return get_proto();
return 'https://';
} else {
return 'http://';
}
} }
public function fix_unlock_user($user)
{
global $sexhack_pms;
if(is_object($user) && is_valid_eth_address($user->user_login))
{
if(!($sexhack_pms->is_member($user->ID)) && !($sexhack_pms->is_premium($user->ID)))
{
$subscription_plan = $sexhack_pms->get_default_plan();
if($subscription_plan)
{
$data = array(
'user_id' => $user->ID,
'subscription_plan_id' => $subscription_plan->id,
'start_date' => date( 'Y-m-d H:i:s' ),
'expiration_date' => $subscription_plan->get_expiration_date(),
'status' => 'active',
);
$member_subscription = new \PMS_Member_Subscription();
$inserted = $member_subscription->insert( $data );
}
}
}
return $user;
}
public function unlock_get_login_url($redirect_url=false) { public function unlock_get_login_url($redirect_url=false) {
$UNLOCK_BASE_URL = 'https://app.unlock-protocol.com/checkout'; $UNLOCK_BASE_URL = 'https://app.unlock-protocol.com/checkout';
$rurl=apply_filters( 'unlock_protocol_get_redirect_uri', wp_login_url()); $rurl=apply_filters( 'unlock_protocol_get_redirect_uri', wp_login_url());
......
...@@ -28,6 +28,8 @@ if(!class_exists('WoocommerceEmailCheckout')) { ...@@ -28,6 +28,8 @@ if(!class_exists('WoocommerceEmailCheckout')) {
{ {
sexhack_log('WoocommerceEmailCheckout() Instanced'); sexhack_log('WoocommerceEmailCheckout() Instanced');
add_filter( 'woocommerce_checkout_fields' , array($this,'simplify_checkout_virtual') ); add_filter( 'woocommerce_checkout_fields' , array($this,'simplify_checkout_virtual') );
add_filter( 'woocommerce_login_redirect', array($this, 'fix_woocommerce_user'), 99, 2);
} }
public function simplify_checkout_virtual( $fields ) { public function simplify_checkout_virtual( $fields ) {
...@@ -54,7 +56,38 @@ if(!class_exists('WoocommerceEmailCheckout')) { ...@@ -54,7 +56,38 @@ if(!class_exists('WoocommerceEmailCheckout')) {
} }
return $fields; return $fields;
} }
public function fix_woocommerce_user($redirect, $user)
{
global $sexhack_pms;
if(is_object($user) && is_checkout())
{
if(!($sexhack_pms->is_member($user->ID)) && !($sexhack_pms->is_premium($user->ID)))
{
$subscription_plan = $sexhack_pms->get_default_plan();
if($subscription_plan)
{
$data = array(
'user_id' => $user->ID,
'subscription_plan_id' => $subscription_plan->id,
'start_date' => date( 'Y-m-d H:i:s' ),
'expiration_date' => $subscription_plan->get_expiration_date(),
'status' => 'active',
);
$member_subscription = new \PMS_Member_Subscription();
$inserted = $member_subscription->insert( $data );
}
}
}
return $redirect;
}
} }
} }
......
...@@ -78,4 +78,32 @@ function do_dump_rewrite() { ...@@ -78,4 +78,32 @@ function do_dump_rewrite() {
add_action( 'parse_request', 'wp_SexHackMe\sarca' ); add_action( 'parse_request', 'wp_SexHackMe\sarca' );
} }
function get_proto(){
if(is_ssl()) {
return 'https://';
} else {
return 'http://';
}
}
function user_has_premium_access($uid='')
{
global $sexhack_pms;
return $sexhack_pms->is_premium($uid) AND is_user_logged_in();
}
function user_has_member_access($uid='')
{
global $sexhack_pms;
if($uid) return $sexhack_pms->is_member($uid) OR $sexhack_pms->is_premium($uid);
return is_user_logged_in();
}
?> ?>
...@@ -27,32 +27,84 @@ class SexHackPMSHelper ...@@ -27,32 +27,84 @@ class SexHackPMSHelper
public function __construct() public function __construct()
{ {
$this->plans = $this->get_pms_plantype(); $this->plans = false;
} }
public function get_pms_plantype() private function set_pms_plans()
{ {
$plans = array( $plans = array(
'member' => array(), 'member' => array(),
'premium'=> array() 'premium'=> array(),
); 'byid' => array()
);
$splans=pms_get_subscription_plans(true); $splans=pms_get_subscription_plans(true);
foreach($splans as $splan) foreach($splans as $splan)
{ {
if(intval($splan->price)==0) $plans['member'][] = $splan->id; if(intval($splan->price)==0) $plans['member'][] = $splan->id;
else $plans['premium'][] = $splan->id; else $plans['premium'][] = $splan->id;
}
$plans['byid'][$splan->id] = $splan;
}
$this->plans = $plans;
return $plans; return $plans;
} }
public function refresh_plans()
{
$this->plans = set_pms_plans();
return $this->plans;
}
// XXX Here we just return the first "member" (free) plan
// if any in our array.
//
// I should probably make it configurable with an option?
// And should not be limited to the free ones?
public function get_default_plan()
{
if(!$this->plans) $this->set_pms_plans();
if(count($this->plans['member']) > 0)
{
return $this->plans['byid'][$this->plans['member'][0]];
}
return false;
}
public function get_member_plans()
{
if(!$this->plans) $this->set_pms_plans();
return $this->plans['member'];
}
public function get_premium_plans()
{
if(!$this->plans) $this->set_pms_plans();
return $this->plans['premium'];
}
public function get_plans($pid=false)
{
if(!$this->plans) $this->set_pms_plans();
if($pid)
{
if(array_key_exists($pid, $this->plans['byid'])) return $this->plans['byid'][$pid];
return false;
}
return $this->plans['byid'];
}
public function is_member($uid='') public function is_member($uid='')
{ {
return pms_is_member( $uid, $this->plans['member'] ); return pms_is_member( $uid, $this->get_member_plans() );
} }
public function is_premium($uid='') public function is_premium($uid='')
{ {
return pms_is_member( $uid, $this->plans['premium'] ); return pms_is_member( $uid, $this->get_premium_plans() );
} }
} }
......
...@@ -100,7 +100,7 @@ get_header(); ?> ...@@ -100,7 +100,7 @@ get_header(); ?>
} }
else else
{ {
if($sexhack_pms->is_premium()) { if(wp_SexHackMe\user_has_premium_access()) {
if($hls_premium) $tab = 'subscribers'; if($hls_premium) $tab = 'subscribers';
elseif($vr_premium) $tab = 'vrsub'; elseif($vr_premium) $tab = 'vrsub';
elseif($hls_members) $tab = 'members'; elseif($hls_members) $tab = 'members';
...@@ -108,7 +108,7 @@ get_header(); ?> ...@@ -108,7 +108,7 @@ get_header(); ?>
elseif($vr_public || $vr_preview) $tab = 'vrpub'; elseif($vr_public || $vr_preview) $tab = 'vrpub';
else $tab = 'public'; else $tab = 'public';
} }
elseif($sexhack_pms->is_member()) // free membership elseif(wp_SexHackMe\user_has_member_access()) // free membership
{ {
if($hls_members) $tab = 'members'; if($hls_members) $tab = 'members';
elseif($vr_members) $tab = 'vrmem'; elseif($vr_members) $tab = 'vrmem';
...@@ -138,7 +138,7 @@ get_header(); ?> ...@@ -138,7 +138,7 @@ get_header(); ?>
case "members": case "members":
case "vrmem": case "vrmem":
if($sexhack_pms->is_premium() || $sexhack_pms->is_member()) if(wp_SexHackMe\user_has_member_access())
{ {
if($hls_members) echo do_shortcode( "[sexhls url=\"".$hls_members."\" posters=\"".$thumb."\"]" ); if($hls_members) echo do_shortcode( "[sexhls url=\"".$hls_members."\" posters=\"".$thumb."\"]" );
else if($vr_members) echo do_shortcode( "[sexvideo url=\"".$vr_members."\" posters=\"".$thumb."\"]" ); else if($vr_members) echo do_shortcode( "[sexvideo url=\"".$vr_members."\" posters=\"".$thumb."\"]" );
...@@ -155,7 +155,7 @@ get_header(); ?> ...@@ -155,7 +155,7 @@ get_header(); ?>
case "subscribers": case "subscribers":
case "vrsub": case "vrsub":
if($sexhack_pms->is_premium()) if(wp_SexHackMe\user_has_premium_access())
{ {
if($hls_premium) echo do_shortcode( "[sexhls url=\"".$hls_premium."\" posters=\"".$thumb."\"]" ); if($hls_premium) echo do_shortcode( "[sexhls url=\"".$hls_premium."\" posters=\"".$thumb."\"]" );
else if($vr_premium) echo do_shortcode( "[sexvideo url=\"".$vr_premium."\" posters=\"".$thumb."\"]" ); else if($vr_premium) echo do_shortcode( "[sexvideo url=\"".$vr_premium."\" posters=\"".$thumb."\"]" );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment