Forked from dwanjuki/my_pmpro_no_access_message_body.php
Last active
September 24, 2025 08:54
-
-
Save JarrydLong/1f242ad3dbe30fee22f630e6b36f2efe to your computer and use it in GitHub Desktop.
Custom no access message that includes membership level names
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Custom "no access" message | |
| * | |
| * You can add this recipe to your site by creating a custom plugin | |
| * or using the Code Snippets plugin available for free in the WordPress repository. | |
| * Read this companion article for step-by-step directions on either method. | |
| * https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
| */ | |
| function my_pmpro_custom_no_access_message_body( $body, $required_level_ids ) { | |
| $body = ""; | |
| foreach( $required_level_ids as $level ) { | |
| if( $level === 1 ) { | |
| $body = "This content is for Level 1 members only."; | |
| } | |
| if( $level === 2 ) { | |
| $body = "This content is for Level 2 members only."; | |
| } | |
| } | |
| $body .= '<p><a class="' . pmpro_get_element_class( 'pmpro_btn' ) . '" href="/levels">View Levels</a></p>'; | |
| return $body; | |
| } | |
| add_filter( 'pmpro_no_access_message_body', 'my_pmpro_custom_no_access_message_body', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment