Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Created September 23, 2025 12:06
Show Gist options
  • Save andrewlimaza/913fe17bf6210e65d9d7688559fd24fe to your computer and use it in GitHub Desktop.
Save andrewlimaza/913fe17bf6210e65d9d7688559fd24fe to your computer and use it in GitHub Desktop.
Add support for "View As" which allows admins access to Addon Packages when set to "true"
<?php
/**
* Give access to admins to Addon Packages when "View As" is enabled.
*
* Add this code to your site by following this guide - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmproap_support_admin_view_as( $levels, $user_id, $post_id ){
if ( current_user_can( 'manage_options' ) ) {
$view_as = get_user_meta( $user_id, 'pmpro_admin_membership_access', true );
if ( $view_as === 'yes' ) {
$all_levels = pmpro_getAllLevels( true );
$levels = wp_list_pluck( $all_levels, 'id' );
}
}
return $levels;
}
add_filter( 'pmproap_all_access_levels', 'my_pmproap_support_admin_view_as', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment