Skip to content

Commit

Permalink
Updates to 1.11.35
Browse files Browse the repository at this point in the history
  • Loading branch information
MemberPress committed Sep 26, 2024
1 parent fa2c5af commit d8ac83d
Show file tree
Hide file tree
Showing 510 changed files with 74,504 additions and 67,829 deletions.
1,417 changes: 728 additions & 689 deletions app/controllers/MeprAccountCtrl.php

Large diffs are not rendered by default.

48 changes: 27 additions & 21 deletions app/controllers/MeprAccountLoginCtrl.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
<?php
if(!defined('ABSPATH')) {die('You are not allowed to call this page directly.');}

class MeprAccountLoginCtrl extends MeprBaseCtrl {
public function load_hooks() {
add_filter('submenu_file', array($this, 'highlight_menu_item'));
}
if (!defined('ABSPATH')) {
die('You are not allowed to call this page directly.');
}

public function highlight_menu_item($submenu_file) {
global $current_screen;
class MeprAccountLoginCtrl extends MeprBaseCtrl
{
public function load_hooks()
{
add_filter('submenu_file', [$this, 'highlight_menu_item']);
}

// Remove the "Account Login" menu item on all pages
remove_submenu_page('memberpress', 'memberpress-account-login');
public function highlight_menu_item($submenu_file)
{
global $current_screen;

// Set the highlighted menu item to "Settings"
if ($current_screen instanceof WP_Screen && $current_screen->id == 'memberpress_page_memberpress-account-login') {
$submenu_file = 'memberpress-options';
}
// Remove the "Account Login" menu item on all pages
remove_submenu_page('memberpress', 'memberpress-account-login');

return $submenu_file;
}
// Set the highlighted menu item to "Settings"
if ($current_screen instanceof WP_Screen && $current_screen->id == 'memberpress_page_memberpress-account-login') {
$submenu_file = 'memberpress-options';
}

public static function route() {
$account_email = get_option('mepr_authenticator_account_email');
$secret = get_option('mepr_authenticator_secret_token');
$site_uuid = get_option('mepr_authenticator_site_uuid');
return $submenu_file;
}

MeprView::render('/admin/account-login/ui', get_defined_vars());
}
public static function route()
{
$account_email = get_option('mepr_authenticator_account_email');
$secret = get_option('mepr_authenticator_secret_token');
$site_uuid = get_option('mepr_authenticator_site_uuid');

MeprView::render('/admin/account-login/ui', get_defined_vars());
}
} //End class
191 changes: 102 additions & 89 deletions app/controllers/MeprActiveInactiveHooksCtrl.php
Original file line number Diff line number Diff line change
@@ -1,99 +1,112 @@
<?php
if(!defined('ABSPATH')) {die('You are not allowed to call this page directly.');}
/*
** Added in MP 1.7.3
** USED FOR OUR AUTORESPONDER ADD-ONS - So we can have the active/inactive logic all in one place
*/
class MeprActiveInactiveHooksCtrl extends MeprBaseCtrl {
public function load_hooks() {
add_action('mepr-txn-store', array($this, 'handle_txn_store'), 99, 2);
add_action('mepr-txn-expired', array($this, 'handle_txn_expired'), 11, 2);
add_action( 'delete_user', array( $this, 'handle_delete_user' ) );
}

public function handle_txn_store($txn, $old_txn) {
// Already been here?
if($old_txn->status == $txn->status) { return; }

// Allow third party plugins to stop the running of the method
if(MeprHooks::apply_filters('mepr-active-inactive-hooks-skip', false, $txn)){
return;
}

// Bail if no id's
if(!isset($txn->id) || $txn->id <= 0 || !isset($txn->user_id) || $txn->user_id <= 0) { return; }

// Ignore "pending" txns
if(!isset($txn->status) || empty($txn->status) || $txn->status == MeprTransaction::$pending_str) { return; }

$active_status = array(MeprTransaction::$complete_str, MeprTransaction::$confirmed_str);
$now = time();
$expires = 0; // Lifetime

if ( ! empty( $txn->expires_at ) && $txn->expires_at != MeprUtils::db_lifetime() ) {
$expires = strtotime($txn->expires_at);
}

if(in_array($txn->status, $active_status)) {
if($expires === 0 || $expires >= $now) {
MeprHooks::do_action('mepr-account-is-active', $txn);
}
else {
MeprHooks::do_action('mepr-account-is-inactive', $txn);
}
}
else {
MeprHooks::do_action('mepr-account-is-inactive', $txn);
}
}

public function handle_txn_expired($txn, $sub_status = false) {
global $wpdb;

// Part of an Enabled subscription, so let's bail
if($sub_status == MeprSubscription::$active_str) {
return;
if (!defined('ABSPATH')) {
die('You are not allowed to call this page directly.');
}
/*
** Added in MP 1.7.3
** USED FOR OUR AUTORESPONDER ADD-ONS - So we can have the active/inactive logic all in one place
*/
class MeprActiveInactiveHooksCtrl extends MeprBaseCtrl
{
public function load_hooks()
{
add_action('mepr-txn-store', [$this, 'handle_txn_store'], 99, 2);
add_action('mepr-txn-expired', [$this, 'handle_txn_expired'], 11, 2);
add_action('delete_user', [$this, 'handle_delete_user']);
}

// Allow third party plugins to stop the running of the method
if(MeprHooks::apply_filters('mepr-active-inactive-hooks-skip', false, $txn)){
return;
public function handle_txn_store($txn, $old_txn)
{
// Already been here?
if ($old_txn->status == $txn->status) {
return;
}

// Allow third party plugins to stop the running of the method
if (MeprHooks::apply_filters('mepr-active-inactive-hooks-skip', false, $txn)) {
return;
}

// Bail if no id's
if (!isset($txn->id) || $txn->id <= 0 || !isset($txn->user_id) || $txn->user_id <= 0) {
return;
}

// Ignore "pending" txns
if (!isset($txn->status) || empty($txn->status) || $txn->status == MeprTransaction::$pending_str) {
return;
}

$active_status = [MeprTransaction::$complete_str, MeprTransaction::$confirmed_str];
$now = time();
$expires = 0; // Lifetime

if (! empty($txn->expires_at) && $txn->expires_at != MeprUtils::db_lifetime()) {
$expires = strtotime($txn->expires_at);
}

if (in_array($txn->status, $active_status)) {
if ($expires === 0 || $expires >= $now) {
MeprHooks::do_action('mepr-account-is-active', $txn);
} else {
MeprHooks::do_action('mepr-account-is-inactive', $txn);
}
} else {
MeprHooks::do_action('mepr-account-is-inactive', $txn);
}
}

// Bail if no id's
if(!isset($txn->id) || $txn->id <= 0 || !isset($txn->user_id) || $txn->user_id <= 0) { return; }

// Go directly to the database and maybe flush caches beforehand
if(MeprHooks::apply_filters('mepr-autoresponder-flush-caches', true)) {
wp_cache_flush();
$wpdb->flush();
}

$query = $wpdb->prepare(
"SELECT count(*) FROM {$wpdb->prefix}mepr_transactions WHERE user_id = %d AND product_id = %d AND status IN (%s, %s) AND (expires_at >= %s OR expires_at = %s)",
$txn->user_id,
$txn->product_id,
MeprTransaction::$complete_str,
MeprTransaction::$confirmed_str,
MeprUtils::db_now(),
MeprUtils::db_lifetime()
);

$active_on_membership = $wpdb->get_var($query);

if($active_on_membership) {
MeprHooks::do_action('mepr-account-is-active', $txn);
}
else {
MeprHooks::do_action('mepr-account-is-inactive', $txn);
public function handle_txn_expired($txn, $sub_status = false)
{
global $wpdb;

// Part of an Enabled subscription, so let's bail
if ($sub_status == MeprSubscription::$active_str) {
return;
}

// Allow third party plugins to stop the running of the method
if (MeprHooks::apply_filters('mepr-active-inactive-hooks-skip', false, $txn)) {
return;
}

// Bail if no id's
if (!isset($txn->id) || $txn->id <= 0 || !isset($txn->user_id) || $txn->user_id <= 0) {
return;
}

// Go directly to the database and maybe flush caches beforehand
if (MeprHooks::apply_filters('mepr-autoresponder-flush-caches', true)) {
wp_cache_flush();
$wpdb->flush();
}

$query = $wpdb->prepare(
"SELECT count(*) FROM {$wpdb->prefix}mepr_transactions WHERE user_id = %d AND product_id = %d AND status IN (%s, %s) AND (expires_at >= %s OR expires_at = %s)",
$txn->user_id,
$txn->product_id,
MeprTransaction::$complete_str,
MeprTransaction::$confirmed_str,
MeprUtils::db_now(),
MeprUtils::db_lifetime()
);

$active_on_membership = $wpdb->get_var($query);

if ($active_on_membership) {
MeprHooks::do_action('mepr-account-is-active', $txn);
} else {
MeprHooks::do_action('mepr-account-is-inactive', $txn);
}
}
}

public function handle_delete_user($user_id) {
$user = new MeprUser( $user_id );
$transactions = (array) $user->active_product_subscriptions( 'transactions', true, true );
foreach ($transactions as $transaction) {
do_action('mepr-account-is-inactive', $transaction);
public function handle_delete_user($user_id)
{
$user = new MeprUser($user_id);
$transactions = (array) $user->active_product_subscriptions('transactions', true, true);
foreach ($transactions as $transaction) {
do_action('mepr-account-is-inactive', $transaction);
}
}
}
} // End Class
Loading

0 comments on commit d8ac83d

Please sign in to comment.