WP Manifestindependent plugin directory
manifest / i18n / acfpolylangtranslatablefields

ACF Polylang translatable fields WP Registry grade A-. Low-severity findings · 1 findingWP RegistryLow-severity findings · 1 findingOpen the reportA-

Adds translatable fields to ACF for non-translated contents using Polylang

★ 2stars
18composer installs
1.1.1latest · 1 year ago

Install

Download source zip No release zip yet

This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.

Install straight from GitHub with WP-CLI:

wp plugin install https://github.com/pierrelebedel/acfpolylangtranslatablefields/archive/refs/heads/main.zip

On Packagist as pleb/acf-polylang-translatable-fields:

composer require pleb/acf-polylang-translatable-fields
No built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.

ACF Polylang Translatable Field

This plugin adds some translatable fields to ACF for non-translated contents using Polylang

The problem

When using Polylang, each translatable post is duplicated, and that the one that matches to the users's language is displayed. The custom fields have to be filled for each post translation.

And when using qTanslate-XT, the post is not duplicate, but that's the field whitch get all translated values internally.

Sometimes, we want some duplicable post types, and some non-duplicable post types with translatable fields.

The solution

This plugin add some fields types to the ACF choices, and when the post form is submitted, that's the field himself whitch got all translated values. Internally, the values are saved with a qTranslate-like HTML comment format :

<!--:en_US-->English content<!--:--><!--:fr_FR-->Contenu en Français<!--:-->

When filling in the fields, a tab will be displayed for each Polylang configured languages :

content editing languages tabs

Installation

  • Download and unzip the package file to your wp-content/plugins/ directory

  • Or install with Composer : composer require pleb/acf-polylang-translatable-fields

Usage

Register fields

You have to choose your field type from the Polylang translatable group inside the ACF field type select box.

Each field type presents an additionational option, witch let you decide the empty translated value field behavior. You can choose between returning the empty value (like there is saved), and returning the default site language value instead.

Get values in your templates

The ACF get_field() function returns to you the translated value in your current context Polylang language.

// pll_current_language('locale') => fr_FR
$translation = get_field('acf_field_name', $post_id);
echo $translation; // "Contenu en Français"

This function can take a boolean third parameter to allow you to get non-formatted values. In this case, you will receive an associative array of your field translations :

$translations = get_field('acf_field_name', $post_id, false);
print_r($translations);
// array(
//   'en_EN' => "English content",
//   'fr_FR' => "Contenu en Français"
// );

Update values

You can update a translated field from outside of the box by sending your values inside an associative array within ACF update_field function :

update_field('acf_field_name', array(
    'fr_FR' => "Nouveau contenu en Français"
), $post_id);

The posted values will be merged with the others languages values.

Note your can also send your values with the 2 chars language slug instead of the 5 chars language locale :

update_field('acf_field_name', array(
    'en' => "New english content",
    'fr' => "Nouveau contenu en Français"
), $post_id);

If you send non-array value to the update_field function, it is only the current context Polylang language (or the default site language if not applicable) that will be updated :

// pll_current_language('locale') => es_ES
update_field('acf_field_name', "Contenido en español", $post_id);
// do the same
update_field('acf_field_name', array(
    'es_ES' => "Contenido en español"
), $post_id);

Releases

2 releases.

Tag
Published
1.1.1 latest
Nov 12, 2024 1 year ago
Nov 12, 2024 1 year ago

These releases are tags only. The author does not attach a packaged zip, so there are no download counts to report.

A- grade

Security

ACF Polylang translatable fields 1.1.1 · audited by WP Registry

Low-severity findings only.

1 low
Audited release
1.1.1
Findings
1
Worst severity
low
Content hash
43c826695f212ba4feac65ab…

Findings

  • low Unescaped echo of field key and language metadata in admin tabs

    missing_escaping

    AcfPolylangFieldTrait::renderLanguageField echoes $field['key'], $lang->locale, $lang->flag, and $lang->name into href/id/HTML without esc_attr/esc_html. Reachable only to users who can render ACF fields in admin. Limited blast unless field keys or Polylang language objects are attacker-influenced.

    classes/AcfPolylangFieldTrait.php:56-68

    Recommendation

    Escape with esc_attr() for attributes and esc_html()/wp_kses_post() for flag/name output.

WP Registry hashes the installable build and reports on that exact bytes-for-bytes copy. Embargoed findings are withheld until they are disclosed, so a clean verdict means nothing public is outstanding. WP Manifest does not audit code itself.