Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save JarrydLong/1f242ad3dbe30fee22f630e6b36f2efe to your computer and use it in GitHub Desktop.

Select an option

Save JarrydLong/1f242ad3dbe30fee22f630e6b36f2efe to your computer and use it in GitHub Desktop.
Custom no access message that includes membership level names
<?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