Created
March 3, 2021 11:00
-
-
Save ipokkel/0e36cbe801d26dd62e8cf21109074896 to your computer and use it in GitHub Desktop.
This recipe gives administrators access to all membership levels' privileges on front-end single post of any post type (post, attachment, page, custom post types). Returns true for pmpro_hasMembershipLevel() if user has administrative capabilities. This will also return true when checking if an administrator has access using the filter 'pmpro_ha…
This file contains 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 | |
/** | |
* This recipe gives administrators access to all membership levels' privileges | |
* on front-end single post of any post type (post, attachment, page, custom post types). | |
* | |
* Returns true for pmpro_hasMembershipLevel() if user has administrative capabilities. | |
* This will also return true when checking if an administrator has access using the | |
* filter 'pmpro_has_membership_access_filter'. | |
* | |
* keywords: admin, admins, administrator, administrators, hasaccess, $hasaccess | |
* | |
* 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_admin_has_membership_level( $has_level, $user_id, $level ) { | |
// Check if user has an administrator capability | |
if ( ! is_admin() && is_singular() && user_can( $user_id, 'manage_options' ) ) { | |
$has_level = true; // return true for pmpro_hasMembershipLevel(). | |
} | |
return $has_level; | |
} | |
add_filter( 'pmpro_has_membership_level', 'my_pmpro_admin_has_membership_level', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
updated version in snippet library https://github.com/strangerstudios/pmpro-snippets-library/blob/dev/restricting-content/allow-access-for-admins.php