Skip to content

Allow Pending Members to see non-member content#475

Open
kimwhite wants to merge 1 commit into
strangerstudios:devfrom
kimwhite:pending-apprval-view
Open

Allow Pending Members to see non-member content#475
kimwhite wants to merge 1 commit into
strangerstudios:devfrom
kimwhite:pending-apprval-view

Conversation

@kimwhite

Copy link
Copy Markdown
Contributor

This is used to modify the behavior described here: strangerstudios/pmpro-approvals#192

This recipe allow the pending member to view non-member content block or shortcode content.

The final version keeps the original behavior but adds a few safeguards and makes the membership-level check more flexible.

Changes from the Original

Added an admin check earlier in the function

The original snippet skipped admin requests after several other checks.
The final version exits immediately on admin requests, avoiding unnecessary processing.

Made the PMPro page check safer

The original code used is_page( $pmpro_pages ).
The final version only runs the page check after WordPress has finished loading the current page (did_action( 'wp' )) and uses array_values( $pmpro_pages ) to ensure only page IDs are checked.
This prevents issues if the filter runs before the queried page is available.

Added a check to confirm the Approvals Add On is active

The final version verifies that the PMPro_Approvals class exists before attempting to use it.
This prevents fatal errors if the Add On is deactivated.

Improved detection of "non-member content" checks

The original snippet only handled cases where $levels was an array containing a single value of 0.
The final version also supports checks where $levels is passed directly as 0 or '0'.
This makes the snippet compatible with more ways developers may call pmpro_hasMembershipLevel().

Simplified the approval check

The original version created an instance of the Approvals class before checking the member status.
The final version calls PMPro_Approvals::isPending() directly, which is cleaner and easier to read.
Result

The functionality remains the same: users with a single pending approval level will see content intended for non-members.

The final version is more defensive, handles additional edge cases, and is less likely to cause issues when used alongside custom code or future PMPro updates.

This is used to modify the behavior described here: strangerstudios/pmpro-approvals#192

This recipe allow the pending member to view non-member content block or shortcode content.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant