Problem Description
Recently, users reported a compatibility issue when the WPSlug plugin is enabled alongside Advanced Custom Fields Pro (ACF Pro):
- ACF field keys are corrupted:
field_abc_123is converted tofield-abc-123(underscores replaced with hyphens), preventing ACF custom fields from saving and retrieving data correctly. This is the most critical issue. - ACF field group
post_nameis interfered with: WPSlug attempts to convert the slugs of ACF’s internal post types into pinyin. - ACF field group
post_excerptis converted to pinyin: Excerpts generated by ACF’s internalsanitize_title()calls are intercepted and processed by WPSlug.
Root Cause Analysis
WPSlug intercepts slug generation via several WordPress hooks: sanitize_title (priority 9), wp_insert_post_data (priority 10), wp_unique_post_slug (priority 10), and transition_post_status (priority 10).
ACF Pro registers five internal post types: acf-field-group, acf-field, acf-post-type, acf-taxonomy, and acf-ui-options-page. When ACF saves field data, it passes through wp_insert_post → sanitize_title. WPSlug’s filters on this chain convert underscores in ACF field keys to hyphens.
Although ACF itself implements a fix in wp_unique_post_slug (priority 999) — returning $original_slug — that value has already been corrupted by the earlier sanitize_title filter, rendering the fix ineffective.
Additionally, WPSlug’s isPostTypeEnabled() method defaults to allowing all post types when its enable list is empty (i.e., empty = all), and does not explicitly exclude ACF’s internal post types.
Fix Strategy
1. Exclude ACF Internal Post Types
Add an exclusion list in WPSlug_Core, and insert early guard clauses in the following methods: processPostData, processUniquePostSlug, and handlePostStatusTransition:
private static $excluded_post_types = array(
'acf-field-group',
'acf-field',
'acf-post-type',
'acf-taxonomy',
'acf-ui-options-page',
);
2. Call Stack Detection for sanitize_title Protection
The processSanitizeTitle filter cannot directly access post_type. Instead, implement an isAcfInternalRequest() method that inspects the call stack for ACF-related classes or functions, such as:
- The
ACF_Internal_Post_Typeclass - The
ACF_Field_Groupclass - Functions like
acf_update_field,acf_import_field_group, etc.
3. Defense-in-Depth
Also exclude ACF’s internal post types in WPSlug_Settings::isPostTypeEnabled(), providing redundant protection.
Test Verification
| Test Case | Before Fix | After Fix |
|---|---|---|
ACF field key field_abc_123 |
field-abc-123 |
field_abc_123 |
ACF field group post_name |
Converted to pinyin | Remains group_xxx key |
ACF field group post_excerpt |
Converted to pinyin | Preserved unchanged |
acf_get_field() lookup |
Fails to find field |
Succeeds |
| Chinese slug for regular posts | Correctly converted to pinyin | Correctly converted to pinyin |
| Chinese slug for pages | Correctly converted to pinyin | Correctly converted to pinyin |
| Custom post types | Correctly converted to pinyin | Correctly converted to pinyin |
| Custom taxonomies | Correctly converted to pinyin | Correctly converted to pinyin |
| Draft → Published transition | Works normally | Works normally |
| Saving posts containing ACF fields | Field values lost | Field values preserved correctly |
Update Instructions
The fix has been pushed to the feicode repository. Users employing the WenPai updater will automatically receive this update.
If you encounter compatibility issues with other plugins while using WPSlug, please report them in this thread.