Home / Archive / MemberPress: Shortcode To Display Manage Sub-Accounts Link
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Shortcode To Display Manage Sub-Accounts Link

The code snippet registers a new shortcode: [mepr-subaccount-link]. Adding this shortcode will display the manage sub-accounts link for the most recent active corporate subscription.

Code Preview
php
<?php
add_shortcode( 'mepr-subaccount-link', function() {
	global $wpdb;
	$user = MeprUtils::get_currentuserinfo();
	if ( ! $user ) {
	    return;
	}
	$subaccount_link = '';
	$caid = get_user_meta( $user->ID, 'mpca_corporate_account_id', true );
	if ( empty( $caid ) ) {
		$query = $wpdb->prepare( "SELECT uuid FROM {$wpdb->prefix}mepr_corporate_accounts
		WHERE user_id = %d AND status = 'enabled'
		ORDER BY id DESC", (int) $user->ID );
		$uuid  = $wpdb->get_var( $query );
		if ( isset( $uuid ) ) {
			$mepr_options = MeprOptions::fetch();
			$account_url = $mepr_options->account_page_url();
			$subaccount_link = '<a href="' . $account_url . '?action=manage_sub_accounts&ca=' . $uuid . '">Sub Account</a>';
		}
	}
	return $subaccount_link;
} );

Comments

Add a Comment