Conditions - Restrict Content for Members only

Hello!
I am hoping you can help me out, as I have dedicated much time to this problem.
I want to use conditions to restrict content for memberships or user-roles.
I have a multisite, and I tried to restrict content by user-roles, but the user-roles that are tied to the memberships are not updating on the subsites, so I need to restrict content by memberships.

I am using Paid Memberships Pro and have gone back and forth with them, with an hour DM back and forth with the co-founder, and no one was able to help me at all.

The table I need to pull from is the “wpqg_pmpro_memberships_users” and the field I need to use is “membership_id”.

I have tried the following variations through using the condtions>string based on past topics here:

{{dc:paid-memberships-pro: wpqg_pmpro_memberships_users field=“membership_id”}} IS 4
{{dc:user: wpqg_pmpro_memberships_users field=“membership_id”}} IS 4
{{dc:wpqg_pmpro_memberships_users field=“membership_id”}} IS 4
{{dc:pmpro: wpqg_pmpro_memberships_users field=“membership_id”}} IS 4
{{dc:pmpro: pmpro_memberships_users field=“membership_id”}} IS 4
{{dc:user: pmpro_memberships_users field=“membership_id”}} IS 4
{{dc:paid-memberships-pro: pmpro_memberships_users field=“membership_id”}} IS 4
{{dc:user: membership_id"}} IS 4
4 IN (above variations)

I am hoping you can help guide me on this, otherwise, I don’t know how I can possibly restrict the content for paid members if the theme doesn’t let me restrict by memberships and the plugin won’t update roles. (I have even tried using different 3rd party plugins that update roles, didn’t work)

Please note I took all the basic steps - looked for plugin conflicts, disabled all plugins, cleared my site, cdn, and browser cache, and used different browsers.

Thanks for any solution. I will take any guidance on either updating roles or using conditions on memberships if you have any.

Hello @lgiguere,

Thanks for writing in!

All of those conditions is incorrect. You can simply use the User Role instead.

kindly let us know how it goes.

As I stated in my question - the user roles are not updating on the sites, or I wouldn’t be looking for guidance.

To use the user role, they would have to update when a membership changes.

The only thing that updates on the subsites is the membership. I can restrict by memberships easily in posts with a shortcode. But when I am using certain elements - like header menus, I either need the user roles to update automatically when a membership is changed (which I’ve been trying to do with the help of the plugin’s customer service, to no avail), or I need to be able to use the membership fields as condition to restrict, and I was hoping for assistance from you on how I would find that recipe, please. If possible, a push in the right direction is be greatly appreciated. Thanks.

I just found a snippet on the internet that worked for me to update user roles on all the subsites, so now I can use the user roles for conditions.

I will share the miracle snippet just in case anyone else here has the same issue that I do. Thanks again for your time.

add_action( 'set_user_role', 'sync_user_roles_wpse_91745', 10, 2 );

function sync_user_roles_wpse_91745( $user_id, $role )
{
    // is_multisite() used just as precaution, this code is meant to Multisite only
    if( !is_multisite() || !is_main_site() )
        return;

    // Initial data
    $blogs = get_blogs_of_user( $user_id );
    $original_blog_id = get_current_blog_id();

    // Remove main site from affected sites
    unset( $blogs[ $original_blog_id ] );

    // Iterate through blogs of user
    foreach ( $blogs as $blog ) 
    {
        // Work with another site
        switch_to_blog( $blog->userblog_id );

        // Grab all user info and update role as in main site
        $site_user = get_user_by( 'id', $user_id );
        $site_user->set_role( $role );
    }

    // Back to original main site
    switch_to_blog( $original_blog_id );    
}

Hello @lgiguere,

I based my response on what I have seen in the user profile. This was I found out which lead me to suggest to use the User Roles.

Well anyway, you have resolved the issue already. We really appreciate for letting us know and for sharing it here in our Support Forum so that it may help help other users as well.

Cheers.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.