• Resolved toondg

    (@toondg)


    Hi,

    We are using members to manage access to certain pages on our website. The website is in two languages using WPML. In the default language, everything is working great, but in the secondary language, all pages are accessible to everyone.

    Did I miss a setting? Or is Members not compatible with multilingual websites?

    Regards,

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Omar ElHawary

    (@omarelhawary)

    Hi @toondg,

    Thanks for reaching out Members Support Team!

    I tried to replicate the issue from my end and everything works fine from my end. Just make sure to use WordPress Editor as in this screenshot.

    Regards,

    Thread Starter toondg

    (@toondg)

    Thank you for your reply.

    Our site is entirely translated with the advanced translation editor.
    Does your plugin contain any filter hooks, that I could use to override the permissions of a page?

    Thread Starter toondg

    (@toondg)

    And an extra question.
    If page content is blocked, the page still loads with a HTML status 200, instead of 401. Is there a way to change this?

    Plugin Support Omar ElHawary

    (@omarelhawary)

    Hi @toondg,

    Regarding first point, you should check with WPML how to duplicate or apply post meta on the translated post/page.

    Regarding second point, that’s a normal status. We don’t change page status as we only protect page/post content so the status is still 200.

    Regards,

    Thread Starter toondg

    (@toondg)

    Ok. For the moment I fixed the first point using this code:

    /**
    * Get the _members_access_role meta key for translated pages, to make Members plugin access controll work
    */
    function sync_members_access_role_meta_field($meta_value, $object_id, $meta_key, $single) {
    // Check if the meta key is '_members_access_role'
    if ($meta_key === '_members_access_role') {
    // Use a static variable to prevent infinite loop
    static $is_running = false;

    if ($is_running) {
    return $meta_value;
    }

    $is_running = true;

    // Get the current language
    $current_language = apply_filters('wpml_current_language', null);

    // Get the default language
    $default_language = apply_filters('wpml_default_language', null);

    // If the current language is not the default language
    if ($current_language !== $default_language) {
    // Get the original post ID
    $original_post_id = apply_filters('wpml_object_id', $object_id, get_post_type($object_id), true, $default_language);

    // Get all values of the custom meta field from the original post
    $meta_values = get_post_meta($original_post_id, $meta_key, false);

    // Reset the static variable
    $is_running = false;

    // Return all meta values if not requesting a single value
    if (!$single) {
    return $meta_values;
    }

    // Return the first meta value if requesting a single value
    if (!empty($meta_values)) {
    return $meta_values[0];
    }

    return '';
    }

    // Reset the static variable
    $is_running = false;
    }

    return $meta_value;
    }

    add_filter('get_post_metadata', 'sync_members_access_role_meta_field', 10, 4);
    • This reply was modified 3 months ago by toondg.
Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.