Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating the "no access" message for 3.1 #186

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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