Home / Archive / MemberPress: Shortcode To Display Content for Parent Accounts and Exclude Subaccounts
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Shortcode To Display Content for Parent Accounts and Exclude Subaccounts

The code snippet registers a new shortcode: [mepr_exclude_sub_accounts]...[/mepr_exclude_sub_accounts].

The content added to this shortcode will be hidden if a user is a sub-account. Here's an example of how to use this shortcode:

[mepr_exclude_sub_accounts]
Content that should be hidden for sub accounts.
[/mepr_exclude_sub_accounts]

Code Preview
php
<?php
function mepr_exclude_sub_accounts( $atts, $content = "" ) {
  $user = MeprUtils::get_currentuserinfo();
  if ($user === false) {
    return;
  }
  $ca_uuid = get_user_meta( $user->ID, 'mpca_corporate_account_id', true );
  // If $ca_uuid has a value, in other words, not empty, then it's a sub account.
  if ( ! empty ($ca_uuid ) ) {
    return;
  }
  // Display content to the rest of users.
  return do_shortcode( $content );
}
add_shortcode( 'mepr_exclude_sub_accounts', 'mepr_exclude_sub_accounts' );

Comments

Add a Comment