Skip to content

Commit

Permalink
Merge pull request #112 from strangerstudios/dev
Browse files Browse the repository at this point in the history
Update master to V1.3.4
  • Loading branch information
andrewlimaza authored Nov 13, 2019
2 parents e9a5171 + e5248a6 commit ae18fcd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 13 deletions.
52 changes: 42 additions & 10 deletions pmpro-approvals.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Paid Memberships Pro - Approvals Add On
Plugin URI: https://www.paidmembershipspro.com/add-ons/approval-process-membership/
Description: Grants administrators the ability to approve/deny memberships after signup.
Version: 1.3.3
Version: 1.3.4
Author: Stranger Studios
Author URI: https://www.paidmembershipspro.com
Text Domain: pmpro-approvals
Expand Down Expand Up @@ -477,7 +477,7 @@ public static function pmpro_has_membership_level( $haslevel, $user_id, $levels
// Ignore if on the edit user screen. This will allow admins/users to update custom fields.
$current_screen = get_current_screen();

if ( $current_screen->base == 'user-edit' || $current_screen->base == 'profile' ) {
if ( !empty( $current_screen ) && ( $current_screen->base == 'user-edit' || $current_screen->base == 'profile' ) ) {
return $haslevel;
}

Expand Down Expand Up @@ -879,6 +879,9 @@ public static function approveMember( $user_id, $level_id = null ) {
'approver' => $current_user->user_login,
)
);

//delete the approval count cache
delete_transient( 'pmpro_approvals_approval_count' );

//update statuses/etc
$msg = 1;
Expand Down Expand Up @@ -928,6 +931,9 @@ public static function denyMember( $user_id, $level_id ) {
)
);

//delete the approval count cache
delete_transient( 'pmpro_approvals_approval_count' );

//update statuses/etc
$msg = 1;
$msgt = __( 'Member was denied.', 'pmpro-approvals' );
Expand Down Expand Up @@ -975,6 +981,9 @@ public static function resetMember( $user_id, $level_id ) {
'approver' => '',
)
);

//delete the approval count cache
delete_transient( 'pmpro_approvals_approval_count' );

$msg = 1;
$msgt = __( 'Approval reset.', 'pmpro-approvals' );
Expand Down Expand Up @@ -1021,6 +1030,9 @@ public static function pmpro_before_change_membership_level( $level_id, $user_id
'approver' => '',
)
);

//delete the approval count cache
delete_transient( 'pmpro_approvals_approval_count' );
}

/**
Expand All @@ -1031,7 +1043,7 @@ public static function pmpro_after_change_membership_level( $level_id, $user_id
//check if level requires approval, if not stop executing this function and don't send email.
if ( ! self::requiresApproval( $level_id ) ) {
return;
}
}

//send email to admin that a new member requires approval.
$email = new PMPro_Approvals_Email();
Expand Down Expand Up @@ -1400,18 +1412,38 @@ public static function getApprovalCount( $approval_status = null ) {

global $wpdb, $menu, $submenu;

// Default to pending status.
if ( empty( $approval_status ) ) {
$approval_status = 'pending';
}

//get all users with 'pending' status.
$sqlQuery = $wpdb->prepare( "SELECT COUNT(u.ID) as count FROM $wpdb->users u LEFT JOIN $wpdb->pmpro_memberships_users mu ON u.ID = mu.user_id LEFT JOIN $wpdb->pmpro_membership_levels m ON mu.membership_id = m.id LEFT JOIN $wpdb->usermeta um ON um.user_id = u.ID AND um.meta_key LIKE CONCAT('pmpro_approval_', mu.membership_id) WHERE mu.status = 'active' AND mu.membership_id > 0 AND um.meta_value LIKE '%s'", '%' . $approval_status . '%' );

$results = $wpdb->get_results( $sqlQuery );
$number_of_users = (int) $results[0]->count;

return $number_of_users;
// Check for a cached value in the transient.
$number_of_users = get_transient( 'pmpro_approvals_approval_count' );

// Store results in an array to support different statuses.
if ( ! isset( $number_of_users ) ) {
$number_of_users = array();
}

// If we don't have this value yet, get it.
if ( ! isset( $number_of_users[$approval_status] ) ) {
//get all users with 'pending' status.
$sqlQuery = $wpdb->prepare( "SELECT COUNT(mu.user_id) as count
FROM $wpdb->pmpro_memberships_users mu
LEFT JOIN $wpdb->usermeta um
ON um.user_id = mu.user_id
AND um.meta_key LIKE CONCAT('pmpro_approval_', mu.membership_id)
WHERE mu.status = 'active'
AND mu.membership_id > 0
AND um.meta_value LIKE '%s'", '%' . $approval_status . '%' );

$results = $wpdb->get_results( $sqlQuery );
$number_of_users[$approval_status] = (int) $results[0]->count;

set_transient( 'pmpro_approvals_approval_count', $number_of_users, 3600*24 );
}

return $number_of_users[$approval_status];
}

/**
Expand Down
9 changes: 6 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
=== Paid Memberships Pro - Approvals ===
Contributors: strangerstudios, andrewza
Tags: paid memberships pro, pmpro, approval, approvals, workflow
Requires at least: 4.0
Tested up to: 5.2.4
Stable tag: 1.3.3
Requires at least: 4.7
Tested up to: 5.3
Stable tag: 1.3.4

Grants administrators the ability to approve/deny memberships after signup.

Expand Down Expand Up @@ -37,6 +37,9 @@ View full documentation at: https://www.paidmembershipspro.com/add-ons/approval-

== Changelog ==

= 1.3.4 - 2019-11-13 =
* ENHANCEMENT: Improved query for Approval Count inside dashboard for speed improvements to reduce load times while in WordPress dashboard.

= 1.3.3 - 2019-10-31 =
* BUG FIX: Fixed issues with PMPro Member Directory integration if your DB prefix was not wp_. (Thanks, Ciprian Tepes)
* ENHANCEMENT: Added pmpro_approvals_level_requires_approval to filter the result of the PMPro_Approvals::requiresApproval() method.
Expand Down

0 comments on commit ae18fcd

Please sign in to comment.