Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlimaza committed Oct 6, 2022
2 parents 729876e + f706bd6 commit 1234fd8
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 226 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/label-sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Sync labels
on:
# You can run this with every type of event, but it's better to run it only when you actually need it.
workflow_dispatch:

jobs:
labels:
runs-on: ubuntu-latest

steps:
- uses: strangerstudios/label-sync@v2
with:
# If you want to use a source repo, you can put is name here (only the owner/repo format is accepted)
source-repo: strangerstudios/paid-memberships-pro

# If you want to delete any additional label, set this to true
delete-other-labels: true

#If you want the action just to show you the preview of the changes, without actually editing the labels, set this to tru
dry-run: false

# You can change the token used to change the labels, this is the default one
token: ${{ secrets.GITHUB_TOKEN }}
64 changes: 35 additions & 29 deletions adminpages/approvals.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,23 @@
//Approve, deny or reset member back to pending
if ( ! empty( $_REQUEST['approve'] ) ) {
check_admin_referer( 'pmpro_approvals', 'pmpro_approvals_nonce' );
if ( ! PMPro_Approvals::isApproved( intval( $_REQUEST['approve'] ) ) ) {
if ( ! PMPro_Approvals::isApproved( intval( $_REQUEST['approve'] ), $l ) ) {
PMPro_Approvals::approveMember( intval( $_REQUEST['approve'] ), $l );
$l = false;
$status = 'pending';
}
} elseif ( ! empty( $_REQUEST['deny'] ) ) {
check_admin_referer( 'pmpro_approvals', 'pmpro_approvals_nonce' );
if ( ! PMPro_Approvals::isDenied( intval( $_REQUEST['deny'] ) ) ) {
if ( ! PMPro_Approvals::isDenied( intval( $_REQUEST['deny'] ), $l ) ) {
PMPro_Approvals::denyMember( intval( $_REQUEST['deny'] ), $l );
$l = false;
$status = 'pending';
}
} elseif ( ! empty( $_REQUEST['unapprove'] ) ) {
check_admin_referer( 'pmpro_approvals', 'pmpro_approvals_nonce' );
PMPro_Approvals::resetMember( intval( $_REQUEST['unapprove'] ), $l );
$l = false;
$status = 'pending';
}

require_once PMPRO_DIR . '/adminpages/admin_header.php';
Expand Down Expand Up @@ -137,16 +143,17 @@
$limit = 15;
}

$theusers = PMPro_Approvals::getApprovals( $l, $s, $status, $sortby, $sortorder, $pn, $limit );
$approval_users = PMPro_Approvals::getApprovals( $l, $s, $status, $sortby, $sortorder, $pn, $limit );
$totalrows = $wpdb->get_var( 'SELECT FOUND_ROWS() as found_rows' );

if ( $theusers ) {
if ( $approval_users ) {
?>
<p class="clear">
<?php
if ( $l == 1 ) {
?>
<?php echo $totalrows; ?> <?php _e( 'applications awaiting review', 'pmpro-approvals' ); ?>.<?php } ?>
<?php
if ( $status === 'pending' ) {
?>
<?php echo $totalrows; ?> <?php _e( 'applications awaiting review', 'pmpro-approvals' ); ?>.
<?php } ?>
</p>
<?php
}
Expand All @@ -158,7 +165,7 @@
<th><?php _e( 'Username', 'pmpro-approvals' ); ?></th>
<th><?php _e( 'Name', 'pmpro-approvals' ); ?></th>
<th><?php _e( 'Email', 'pmpro-approvals' ); ?></th>
<?php do_action( 'pmpro_approvals_list_extra_cols_header', $theusers ); ?>
<?php do_action( 'pmpro_approvals_list_extra_cols_header', $approval_users ); ?>
<th><?php _e( 'Membership', 'pmpro-approvals' ); ?></th>
<th><?php _e( 'Approval Status', 'pmpro-approvals' ); ?></th>
<th><a href="<?php echo admin_url( 'admin.php?page=pmpro-approvals&s=' . esc_attr( $s ) . '&limit=' . $limit . '&pn=' . $pn . '&sortby=user_registered' ); ?>
Expand All @@ -171,28 +178,27 @@
<tbody id="users" class="list:user user-list">
<?php
$count = 0;
foreach ( $theusers as $auser ) {
foreach ( $approval_users as $approval_user ) {
//get meta
$theuser = get_userdata( $auser->ID );
$theuser->membership_level = pmpro_getMembershipLevelForUser( $theuser->ID );
$user_data = get_userdata( $approval_user->ID );
?>
<tr
<?php
if ( $count++ % 2 == 0 ) {
?>
class="alternate"<?php } ?>>
<td><?php echo $theuser->ID; ?></td>
<td><?php echo $user_data->ID; ?></td>
<td class="username column-username">
<?php echo get_avatar( $theuser->ID, 32 ); ?>
<?php echo get_avatar( $user_data->ID, 32 ); ?>
<?php if ( current_user_can( 'edit_users' ) ) { ?>
<strong><a href="user-edit.php?user_id=<?php echo $theuser->ID; ?>"><?php echo $theuser->user_login; ?></a></strong>
<strong><a href="user-edit.php?user_id=<?php echo $user_data->ID; ?>"><?php echo $user_data->user_login; ?></a></strong>
<?php } else { ?>
<strong><a href="admin.php?page=pmpro-approvals&user_id=<?php echo $theuser->ID; ?>"><?php echo $theuser->user_login; ?></a></strong>
<strong><a href="admin.php?page=pmpro-approvals&user_id=<?php echo $user_data->ID; ?>"><?php echo $user_data->user_login; ?></a></strong>
<?php } ?>
<br />
<?php
// Set up the hover actions for this user
$actions = apply_filters( 'pmpro_approvals_user_row_actions', array(), $theuser );
$actions = apply_filters( 'pmpro_approvals_user_row_actions', array(), $user_data, $approval_user );
$action_count = count( $actions );
$i = 0;
if ( $action_count ) {
Expand All @@ -207,46 +213,46 @@ class="alternate"<?php } ?>>
}
?>
</td>
<td><?php echo trim( $theuser->first_name . ' ' . $theuser->last_name ); ?></td>
<td><a href="mailto:<?php echo $theuser->user_email; ?>"><?php echo $theuser->user_email; ?></a></td>
<?php do_action( 'pmpro_approvals_list_extra_cols_body', $theuser ); ?>
<td><?php echo trim( $user_data->first_name . ' ' . $user_data->last_name ); ?></td>
<td><a href="mailto:<?php echo $user_data->user_email; ?>"><?php echo $user_data->user_email; ?></a></td>
<?php do_action( 'pmpro_approvals_list_extra_cols_body', $user_data ); ?>
<td>
<?php
echo $auser->membership;
echo $approval_user->membership;
?>
</td>
<td>
<?php
$pmpro_approvals_nonce = wp_create_nonce( 'pmpro_approvals' );

if ( PMPro_Approvals::isApproved( $theuser->ID ) || PMPro_Approvals::isDenied( $theuser->ID ) ) {
if ( PMPro_Approvals::isApproved( $user_data->ID, $approval_user->membership_id) || PMPro_Approvals::isDenied( $user_data->ID, $approval_user->membership_id ) ) {

if ( ! PMPro_Approvals::getEmailConfirmation( $theuser->ID ) ) {
if ( ! PMPro_Approvals::getEmailConfirmation( $user_data->ID ) ) {
_e( 'Email Confirmation Required.', 'pmpro-approvals' );
} else {

echo PMPro_Approvals::getUserApprovalStatus( $theuser->ID, $theuser->membership_level->id, false );
echo PMPro_Approvals::getUserApprovalStatus( $user_data->ID, $approval_user->membership_id, false );

//link to unapprove
?>
[<a href="javascript:askfirst('Are you sure you want to reset approval for <?php echo $theuser->user_login; ?>?', '?page=pmpro-approvals&s=<?php echo esc_attr( $s ); ?>&l=<?php echo $l; ?>&limit=<?php echo intval( $limit ); ?>&status=<?php echo $status; ?>&sortby=<?php echo $sortby; ?>&sortorder=<?php echo $sortorder; ?>&pn=<?php echo intval( $pn ); ?>&unapprove=<?php echo $theuser->ID; ?>&pmpro_approvals_nonce=<?php echo urlencode( $pmpro_approvals_nonce ); ?>');">X</a>]
[<a href="javascript:askfirst('Are you sure you want to reset approval for <?php echo $user_data->user_login; ?>?', '?page=pmpro-approvals&s=<?php echo esc_attr( $s ); ?>&l=<?php echo $approval_user->membership_id; ?>&limit=<?php echo intval( $limit ); ?>&status=<?php echo $status; ?>&sortby=<?php echo $sortby; ?>&sortorder=<?php echo $sortorder; ?>&pn=<?php echo intval( $pn ); ?>&unapprove=<?php echo $user_data->ID; ?>&pmpro_approvals_nonce=<?php echo urlencode( $pmpro_approvals_nonce ); ?>');">X</a>]
<?php
}
} else {
?>

<a href="?page=pmpro-approvals&s=<?php echo esc_attr( $s ); ?>&l=<?php echo $l; ?>&limit=<?php echo intval( $limit ); ?>&status=<?php echo $status; ?>&sortby=<?php echo $sortby; ?>&sortorder=<?php echo $sortorder; ?>&pn=<?php echo intval( $pn ); ?>&approve=<?php echo $theuser->ID; ?>&pmpro_approvals_nonce=<?php echo urlencode( $pmpro_approvals_nonce ); ?>"><?php _e('Approve', 'pmpro-approvals') ?></a> |
<a href="?page=pmpro-approvals&s=<?php echo esc_attr( $s ); ?>&l=<?php echo $l; ?>&limit=<?php echo intval( $limit ); ?>&status=<?php echo $status; ?>&sortby=<?php echo $sortby; ?>&sortorder=<?php echo $sortorder; ?>&pn=<?php echo intval( $pn ); ?>&deny=<?php echo $theuser->ID; ?>&pmpro_approvals_nonce=<?php echo urlencode( $pmpro_approvals_nonce ); ?>"><?php _e('Deny', 'pmpro-approvals') ?></a>
<a href="?page=pmpro-approvals&s=<?php echo esc_attr( $s ); ?>&l=<?php echo $approval_user->membership_id; ?>&limit=<?php echo intval( $limit ); ?>&status=<?php echo $status; ?>&sortby=<?php echo $sortby; ?>&sortorder=<?php echo $sortorder; ?>&pn=<?php echo intval( $pn ); ?>&approve=<?php echo $user_data->ID; ?>&pmpro_approvals_nonce=<?php echo urlencode( $pmpro_approvals_nonce ); ?>"><?php _e('Approve', 'pmpro-approvals') ?></a> |
<a href="?page=pmpro-approvals&s=<?php echo esc_attr( $s ); ?>&l=<?php echo $approval_user->membership_id; ?>&limit=<?php echo intval( $limit ); ?>&status=<?php echo $status; ?>&sortby=<?php echo $sortby; ?>&sortorder=<?php echo $sortorder; ?>&pn=<?php echo intval( $pn ); ?>&deny=<?php echo $user_data->ID; ?>&pmpro_approvals_nonce=<?php echo urlencode( $pmpro_approvals_nonce ); ?>"><?php _e('Deny', 'pmpro-approvals') ?></a>
<?php
}
?>
</td>
<td><?php echo date_i18n( get_option( 'date_format' ), strtotime( $theuser->user_registered ) ); ?></td>
<td><?php echo date_i18n( get_option( 'date_format' ), strtotime( $user_data->user_registered ) ); ?></td>
</tr>
<?php
}

if ( ! $theusers ) {
if ( ! $approval_users ) {
?>
<tr>
<td colspan="9"><p><?php _e( 'No pending members found.', 'pmpro-approvals' ); ?></p></td>
Expand Down
20 changes: 13 additions & 7 deletions adminpages/userinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
if ( isset( $_REQUEST['l'] ) ) {
$l = intval( $_REQUEST['l'] );
} else {
$l = false;
// Default to a random level that the user has. Hopefully we never actually do this.
$levels = pmpro_getMembershipLevelsForUser( $current_user->ID );
if ( ! empty( $levels ) ) {
$l = $levels[0]->id;
} else {
$l = 0;
}
}

if ( ! empty( $_REQUEST['approve'] ) ) {
Expand Down Expand Up @@ -59,7 +65,7 @@
<td>
<?php
//Changed this to show Membership Level Name now, so approvers don't need to go back and forth to see what level the user is applying for.
$level_details = pmpro_getMembershipLevelForUser( $user->ID );
$level_details = pmpro_getSpecificMembershipLevelForUser( $user->ID, $l );

echo esc_html( $level_details->name );

Expand All @@ -71,20 +77,20 @@
<td>
<?php
//show status here
if ( PMPro_Approvals::isApproved( $user->ID ) || PMPro_Approvals::isDenied( $user->ID ) ) {
if ( PMPro_Approvals::isApproved( $user->ID, $l ) || PMPro_Approvals::isDenied( $user->ID, $l ) ) {
if ( ! PMPro_Approvals::getEmailConfirmation( $user->ID ) ) {
_e( 'Email Confirmation Required.', 'pmpro-approvals' );
} else {
echo PMPro_Approvals::getUserApprovalStatus( $user->ID, null, false );
echo PMPro_Approvals::getUserApprovalStatus( $user->ID, $l, false );
?>
[<a href="javascript:askfirst('Are you sure you want to reset approval for <?php echo esc_attr( $user->user_login ); ?>?', '?page=pmpro-approvals&user_id=<?php echo $user->ID; ?>&unapprove=<?php echo $user->ID; ?>');">X</a>]
[<a href="javascript:askfirst('Are you sure you want to reset approval for <?php echo esc_attr( $user->user_login ); ?>?', '?page=pmpro-approvals&user_id=<?php echo $user->ID; ?>&unapprove=<?php echo $user->ID; ?>&l=<?php echo $l ?>');">X</a>]
<?php
} // end of email confirmation check.
} else {
?>

<a href="?page=pmpro-approvals&user_id=<?php echo $user->ID; ?>&approve=<?php echo $user->ID; ?>">Approve</a> |
<a href="?page=pmpro-approvals&user_id=<?php echo $user->ID; ?>&deny=<?php echo $user->ID; ?>">Deny</a>
<a href="?page=pmpro-approvals&user_id=<?php echo $user->ID; ?>&approve=<?php echo $user->ID; ?>&l=<?php echo $l ?>"><?php esc_html_e( 'Approve', 'pmpro-approvals' ); ?></a> |
<a href="?page=pmpro-approvals&user_id=<?php echo $user->ID; ?>&deny=<?php echo $user->ID; ?>&l=<?php echo $l ?>"><?php esc_html_e( 'Deny', 'pmpro-approvals' ); ?></a>
<?php
}
?>
Expand Down
52 changes: 39 additions & 13 deletions classes/class.approvalemails.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,22 @@ public static function get_instance() {
* Send user's an email that their account has been approved.
*
* @param $member. The member's ID or object.
* @param int $level_id
*/
public function sendMemberApproved( $member ) {
public function sendMemberApproved( $member, $level_id = null ) {

if ( empty( $member ) ) {
return;
} elseif ( is_int( $member ) ) {
$member = get_user_by( 'ID', $member );
}

$level = pmpro_getMembershipLevelForUser( $member->ID );
if ( empty( $level_id ) ) {
$level = pmpro_getMembershipLevelForUser( $member->ID );
} else {
$level = pmpro_getSpecificMembershipLevelForUser( $member->ID, $level_id );
}


$this->email = $member->user_email;
$this->subject = sprintf( __( 'Your membership at %s has been approved.', 'pmpro-approvals' ), get_bloginfo( 'name' ) );
Expand Down Expand Up @@ -58,16 +64,21 @@ public function sendMemberApproved( $member ) {
* Send user's an email that their account has been denied.
*
* @param $member. The member's ID or object.
* @param int $level_id
*/
public function sendMemberDenied( $member ) {
public function sendMemberDenied( $member, $level_id = null ) {

if ( empty( $member ) ) {
return;
} elseif ( is_int( $member ) ) {
$member = get_user_by( 'ID', $member );
}

$level = pmpro_getMembershipLevelForUser( $member->ID );
if ( empty( $level_id ) ) {
$level = pmpro_getMembershipLevelForUser( $member->ID );
} else {
$level = pmpro_getSpecificMembershipLevelForUser( $member->ID, $level_id );
}

$this->email = $member->user_email;
$this->subject = sprintf( __( 'Your membership at %s has been denied.', 'pmpro-approvals' ), get_bloginfo( 'name' ) );
Expand Down Expand Up @@ -98,8 +109,9 @@ public function sendMemberDenied( $member ) {
*
* @param $member The member object/ID/email.
* @param $admin The admin object/ID. Default $current_user object.
* @param int $level_id
*/
public function sendAdminPending( $member = null, $admin = null ) {
public function sendAdminPending( $member = null, $admin = null, $level_id = null ) {

if ( empty( $admin ) ) {
$admin = get_user_by( 'email', get_option( 'admin_email' ) );
Expand Down Expand Up @@ -130,13 +142,17 @@ public function sendAdminPending( $member = null, $admin = null ) {
$member = get_user_by( 'email', $member );
}

$level = pmpro_getMembershipLevelForUser( $member->ID );
if ( empty( $level_id ) ) {
$level = pmpro_getMembershipLevelForUser( $member->ID );
} else {
$level = pmpro_getSpecificMembershipLevelForUser( $member->ID, $level_id );
}

$this->data['member_name'] = $member->display_name;
$this->data['member_email'] = $member->user_email;
$this->data['membership_id'] = $level->id;
$this->data['membership_level_name'] = $level->name;
$this->data['view_profile'] = admin_url( 'admin.php?page=pmpro-approvals&user_id=' . $member->ID );
$this->data['view_profile'] = admin_url( 'admin.php?page=pmpro-approvals&user_id=' . $member->ID . '&l=' . $level->id );
$this->data['approve_link'] = $this->data['view_profile'] . '&approve=' . $member->ID;
$this->data['deny_link'] = $this->data['view_profile'] . '&deny=' . $member->ID;
}
Expand All @@ -151,8 +167,9 @@ public function sendAdminPending( $member = null, $admin = null ) {
*
* @param $member The member object/ID/email.
* @param $admin The admin object/ID. Default $current_user object.
* @param int $level_id
*/
public function sendAdminApproval( $member = null, $admin = null ) {
public function sendAdminApproval( $member = null, $admin = null, $level_id = null ) {

if ( empty( $admin ) ) {
$admin = get_user_by( 'email', get_option( 'admin_email' ) );
Expand Down Expand Up @@ -184,13 +201,17 @@ public function sendAdminApproval( $member = null, $admin = null ) {
$member = get_user_by( 'email', $member );
}

$level = pmpro_getMembershipLevelForUser( $member->ID );
if ( empty( $level_id ) ) {
$level = pmpro_getMembershipLevelForUser( $member->ID );
} else {
$level = pmpro_getSpecificMembershipLevelForUser( $member->ID, $level_id );
}

$this->data['membership_id'] = $level->id;
$this->data['membership_level_name'] = $level->name;
$this->data['member_email'] = $member->user_email;
$this->data['member_name'] = $member->display_name;
$this->data['view_profile'] = admin_url( 'admin.php?page=pmpro-approvals&user_id=' . $member->ID );
$this->data['view_profile'] = admin_url( 'admin.php?page=pmpro-approvals&user_id=' . $member->ID . '&l=' . $level->id );
}

$this->data = apply_filters( 'pmpro_approvals_admin_approved_email_data', $this->data, $member, $admin );
Expand All @@ -203,8 +224,9 @@ public function sendAdminApproval( $member = null, $admin = null ) {
*
* @param $member The member object/ID/email.
* @param $admin The admin object/ID. Default $current_user object.
* @param int $level_id
*/
public function sendAdminDenied( $member = null, $admin = null ) {
public function sendAdminDenied( $member = null, $admin = null, $level_id = null ) {

if ( empty( $admin ) ) {
$admin = get_user_by( 'email', get_option( 'admin_email' ) );
Expand Down Expand Up @@ -236,13 +258,17 @@ public function sendAdminDenied( $member = null, $admin = null ) {
$member = get_user_by( 'email', $member );
}

$level = pmpro_getMembershipLevelForUser( $member->ID );
if ( empty( $level_id ) ) {
$level = pmpro_getMembershipLevelForUser( $member->ID );
} else {
$level = pmpro_getSpecificMembershipLevelForUser( $member->ID, $level_id );
}

$this->data['membership_id'] = $level->id;
$this->data['membership_level_name'] = $level->name;
$this->data['member_email'] = $member->user_email;
$this->data['member_name'] = $member->display_name;
$this->data['view_profile'] = admin_url( 'admin.php?page=pmpro-approvals&user_id=' . $member->ID );
$this->data['view_profile'] = admin_url( 'admin.php?page=pmpro-approvals&user_id=' . $member->ID . '&l=' . $level->id );
}

$this->data = apply_filters( 'pmpro_approvals_admin_denied_email_data', $this->data, $member, $admin );
Expand Down
Loading

0 comments on commit 1234fd8

Please sign in to comment.