Skip to main content

Unlocking multilingual content access management with WPML

Vasyl MartyniukOther GoodiesAbout 4 min

WordPress, a powerhouse in content management, opens the doors to a global audience with its built-in multilingual support. However, while WordPress provides the framework for multilingual setups, it offers limited functionality for translating content seamlessly. That is why several custom solutions are available to enhance WordPress CMS with user-friendly interface.

For example, WPMLopen in new window (WordPress Multilingual Plugin), a robust solution designed to enhance the translation experience for WordPress users. In this article, we'll explore the seamless integration of WPMLopen in new window and Advanced Access Manager (AAM) plugin to streamline access management for multilingual content.

Understanding WPML

WPML facilitates content translation by creating separate post records in the database for each language translation. For instance, translating an article titled "Introduction to Quantum Physics" into German, French, and Spanish would result in four independent post records in the database. WPML manages these translations through internal relationships stored in the wp_icl_translations table, ensuring coherence across language variants.

WMPL Post Translations

AAM seamlessly integrates with WPML, but it's essential to grasp how WPML stores translations in the database to align access control strategies effectively. Since AAM and WordPress core treat translated posts as independent entities, managing access to multilingual content requires careful planning; and there are few tactics you can apply to overcome these difficulties, so let's delve into a few scenarios.

Set access for each translated post

While time-consuming, assigning access controls to individual translated posts offers precise control over content accessibility. Let's say you want to restrict the mentioned above post "Introduction to Quantum Physics" and all its translated versions. In this case you would do the following steps:

  1. Enable "Render Access Manager Metabox" setting, so you can define your access controls directly from the post edit screen.
  2. Go to the "Posts" page and select the "All languages" option at the top of the post list table. This will show you all the posts with their translated versions.

WPML All Languages Option

  1. Open each post one-by-one and scroll to the bottom of the edit page. There should be the "Access Manager" metabox that allows you to define access controls. Make sure you switch to the desired assignee (e.g. role or visitors) and then define your access controls.

AAM Access Manager Metabox

This scenario might not be feasible on a larger scale, especially when managing access controls for numerous posts, ranging from dozens to even hundreds. In such situations, we suggest considering an alternative strategy by categorizing posts into groups based on categories, tags, or terms within custom taxonomies.

Group translated posts with terms

WPML not only translates posts, pages, and custom post types but also categories, tags, and terms of custom taxonomies. Similar to posts, a new record is stored in the database for each translated term. Additionally, the list of terms adjusts dynamically based on the currently selected language from the admin toolbar. For instance, if you choose the French version of a post titled "Introduction à la physique quantique", the categories and tags list will be tailored accordingly.

WPML Categories Adjustment

This default behavior of WPML is managed through the "Taxonomies Translation" settings found on the "WPML -> Settings" page. Here, you can specify which taxonomies should undergo translation and which should not. This level of flexibility provided by the WPML team enables us to leverage options like excluding certain taxonomies from translation, grouping posts with terms, and defining access controls to posts on the term level (a premium feature available with our premium add-on).

Assuming you're utilizing standard post categories and tags to organize your content, we recommend creating a custom taxonomy, such as "Access Rules," which can be attached to the "Posts" post type. This taxonomy can be hierarchical or not, depending on the complexity of your required access rules.

To clarify further, ensure that you select the "Not translatable" option for this taxonomy on the "WPML -> Settings" page under "Taxonomies Translation."

WPML Exclude Taxonomies From Transaction

Here are the steps:

  1. Create a custom taxonomy either programmatically using register_taxonomyopen in new window or via a plugin allowing custom taxonomy definition (e.g., CPTopen in new window). In our case, we register the hierarchical taxonomy "Access Rules".

  2. Create a new "Access Rule" to group posts together. Let's name it "Users Only" and restrict access to all posts for anonymous visitors.

AAM Restricted Categories Controls

  1. Open each post individually and assign the "Users Only" category to the post.

Now, any post assigned to the "Users Only" category will automatically inherit access controls from it.

Manage access to the entire language

If you find the need to restrict access to all content in a particular language, AAM provides various methods to accomplish this with our premium add-on. One straightforward approach is to utilize the "URL Access" feature and set up specific access rules. For instance, if your website is configured to prefix all URLs with language codes like /de/, /fr/, you can use wildcard rules to block access to URLs starting with the desired language code. The following two rules deny access to all URLs starting with /de/:

WPML Wildcard Rule

This means URLs such as https://example.xyz/de or https://example.xyz/de/einfuehrung-in-die-quantenphysik will be denied access.

Furthermore, you can hide unwanted language options from the WPML language selector for any role, user, or visitor using AAM access policies. WPML provides a programmatic hook called icl_ls_languagesopen in new window that AAM can utilize for language filtering. The following policy achieves this:

{
    "Statement": [
        {
            "Effect": "override",
            "Resource": "Hook:icl_ls_languages",
            "Response": "&:filter($key !in [de,fr])"
        }
    ]
}

Attach this policy to the desired assignee, and unwanted languages will be removed. In the provided policy, German (de) and French (fr) languages are removed. For further information on the Hook resource, you can refer to our Access Policies Hook article.

Conclusion

The seamless integration of WPML and AAM empowers WordPress users to navigate the complexities of multilingual content management effortlessly. By understanding the intricacies of WPML's translation mechanisms and harnessing the versatile access management capabilities of AAM, users can unlock the full potential of their multilingual websites. Whether assigning access controls to individual posts, grouping content with terms or implementing language-based access restrictions, WPML and AAM offer a comprehensive solution for managing multilingual content with ease.