Skip to content

Commit

Permalink
Merge pull request #186 from dparker1005/3.1-no-access-message
Browse files Browse the repository at this point in the history
Updating the "no access" message for 3.1
  • Loading branch information
andrewlimaza committed Jul 17, 2024
2 parents 58914b7 + 4762225 commit 87a6214
Showing 1 changed file with 42 additions and 5 deletions.
47 changes: 42 additions & 5 deletions pmpro-approvals.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ public static function init() {
add_action( 'pmpro_save_membership_level', array( 'PMPro_Approvals', 'pmpro_save_membership_level' ) );

//Add code for filtering checkouts, confirmation, and content filters
add_filter( 'pmpro_non_member_text_filter', array( 'PMPro_Approvals', 'pmpro_non_member_text_filter' ) );
add_filter( 'pmpro_no_access_message_header', array( 'PMPro_Approvals', 'pmpro_no_access_message_header' ) ); // PMPro v3.1+.
add_filter( 'pmpro_no_access_message_body', array( 'PMPro_Approvals', 'pmpro_non_member_text_filter' ) ); // PMPro v3.1+.
add_filter( 'pmpro_non_member_text_filter', array( 'PMPro_Approvals', 'pmpro_non_member_text_filter' ) ); // Pre-PMPro 3.1
add_action( 'pmpro_account_bullets_top', array( 'PMPro_Approvals', 'pmpro_account_bullets_top' ) );
add_filter( 'pmpro_confirmation_message', array( 'PMPro_Approvals', 'pmpro_confirmation_message' ), 10, 2 );
add_action( 'pmpro_before_change_membership_level', array( 'PMPro_Approvals', 'pmpro_before_change_membership_level' ), 10, 4 );
Expand Down Expand Up @@ -1260,12 +1262,47 @@ public static function pmpro_after_change_membership_level( $level_id, $user_id
$email->sendAdminPending( $user_id, null, $level_id );
}

/**
* Filter the header message for the no access message.
*
* @since TBD
*
* @param string $header The header message for the no access message.
* @return string The filtered header message for the no access message.
*/
public static function pmpro_no_access_message_header( $header ) {
global $current_user;

// We are running PMPro v3.1+, so make sure that deprecated filters don't run later.
remove_filter( 'pmpro_non_member_text_filter', array( 'PMPro_Approvals', 'pmpro_non_member_text_filter' ), 10 );

// If a user does not have a membership level, return default text.
if ( ! pmpro_hasMembershipLevel() ) {
return $header;
}

// Loop through all user levels and check if any are pending approval or denied.
$user_levels = pmpro_getMembershipLevelsForUser( $current_user->ID );
foreach ( $user_levels as $user_level ) {
if ( ! self::requiresApproval( $user_level->id ) ) {
continue;
}

if ( self::isPending( $current_user->ID, $user_level->id ) ) {
return __( 'Membership Pending Approval', 'pmpro-approvals' );
} elseif ( self::isDenied( $current_user->ID, $user_level->id ) ) {
return __( 'Membership Denied', 'pmpro-approvals' );
}
}

return $header;
}

/**
* Show a different message for users that have their membership awaiting approval.
*/
public static function pmpro_non_member_text_filter( $text ) {

global $current_user, $has_access;
global $current_user;

//if a user does not have a membership level, return default text.
if ( ! pmpro_hasMembershipLevel() ) {
Expand All @@ -1279,9 +1316,9 @@ public static function pmpro_non_member_text_filter( $text ) {
}

if ( self::isPending( $current_user->ID, $user_level->id ) ) {
return esc_html__( 'Your membership requires approval before you are able to view this content.', 'pmpro-approvals' );
return '<p>' . esc_html__( 'Your membership requires approval before you are able to view this content.', 'pmpro-approvals' ) . '</p>';
} elseif ( self::isDenied( $current_user->ID, $user_level->id ) ) {
return esc_html__( 'Your membership application has been denied. Contact the site owners if you believe this is an error.', 'pmpro-approvals' );
return '<p>' . esc_html__( 'Your membership application has been denied. Contact the site owners if you believe this is an error.', 'pmpro-approvals' ) . '</p>';
}
}
}
Expand Down

0 comments on commit 87a6214

Please sign in to comment.