Home / Archive / MemberPress: Display Corporate Account Logo for Sub-Users
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Display Corporate Account Logo for Sub-Users

This code snippet allows the custom logo to be displayed as the parent corporate account’s logo for the sub-account users in MemberPress.

The logo image needs to be collected using a MemberPress “File Upload ”custom field added to the parent corporate account registration or account forms. The custom field can be created at Dashbaorad > MemberPress > Settings > Fields tab.

The sample code below uses a custom field named “Logo” with the mepr_logo slug, to collect the logo image. The code must be adjusted to use the correct field slug. Thus, if the custom field used to collect the logo image has a different name, the mepr_logo field slug must be replaced with the slug of that field on this line:

Code Preview
php
<?php
add_shortcode('mepr-sub-logo', function() {
    global $wpdb;
    $logo_slug = 'mepr_logo'; // Custom field logo slug
    // Get current user
    $user = MeprUtils::get_currentuserinfo();
    $caid = get_user_meta($user->ID, 'mpca_corporate_account_id');
    if (empty($caid)) {
        return; // Return if no corporate account ID is found
    }
    
    // Get parent user (corporate account holder)
    $query = $wpdb->prepare("SELECT user_id FROM {$wpdb->prefix}mepr_corporate_accounts WHERE id = %d", (int) $caid[0]);
    $parent_id = $wpdb->get_var($query);
    if (empty($parent_id)) {
        return; // Return if parent user is not found
    }
    
    $parent = new MeprUser($parent_id);
    // Get the custom logo from parent user's meta
    $logo = get_user_meta($parent->ID, $logo_slug, true);
    if (empty($logo)) {
        return; // Return if no logo is found
    }
    // Return the logo image with sanitized URL
    return '<img src="' . sanitize_url($logo) . '" />';
});

Comments

Add a Comment