Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ipokkel/0e36cbe801d26dd62e8cf21109074896 to your computer and use it in GitHub Desktop.
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…
<?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