Automattic / Automattic/babble

Clashing keys when using the `bbl_translated_meta_fields` filter

Open
#257 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
PHP
Stars
250
Forks
44
PR merge metrics
No merged PRs in 30d

Description

There is an API for specifying what meta keys can be translated, and what UI the translation requires. So you can take a plugin with a whole bunch of meta fields and say: "this meta key is translated using an RTE, this one using a text field, and this one with a text area" (unspecified keys don’t need translation so the values remain the same across all translations (e.g. for a map reference, or a colour)).

The API allows you to filter an array for a post, with each index on the array being a meta key.

Here’s the filter: https://github.com/Automattic/babble/blob/49a5140dbb8caf56e932c41f66674b6e9aebbb85/class-jobs.php#L1227

Here’s the example plugin: https://github.com/Automattic/babble/blob/master/translation-fields.php

I am not sure we have considered that you could have two post types which use the same meta key for completely different purposes, and I’m wondering if we should switch to dynamic filter names, which include the post type name in the filter; e.g.

``` php
$fields = (array) apply_filters( 'bbl_translated_meta_fields-' . $post->post_type, array(), $post );
```

This way a developer has to pick the filter name corresponding to the required post type, rather than expecting them to check the second `WP_Post` parameter, which they probably won’t… and then when there’s a meta key clash :boom: disaster.

Contributor guide

Open the contributing guide

Research direction

Start with class-jobs.php around line 1227 and compare the bbl_translated_meta_fields filter with the example in translation-fields.php. Trace how the post type and meta-key mappings are used, then determine the agreed API change and verify that different post types cannot clash when configuring translation fields.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api, backend
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.