Problem Description
We recently received user feedback reporting the following compatibility issues when the WPSlug plugin is enabled alongside Advanced Custom Fields Pro (ACF Pro):
- ACF Field Keys Are Altered:
field_abc_123is converted tofield-abc-123(underscores replaced with hyphens), causing ACF custom fields to fail saving and retrieval. 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 internal calls tosanitize_title()are intercepted and processed by WPSlug.
Root Cause Analysis
WPSlug intercepts slug generation via several 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. At this point, 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 fix is ineffective because $original_slug has already been corrupted by the earlier sanitize_title filter.
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 processPostData, processUniquePostSlug, and handlePostStatusTransition methods:
private static $excluded_post_types = array(
'acf-field-group',
'acf-field',
'acf-post-type',
'acf-taxonomy',
'acf-ui-options-page',
);
2. Call-Stack Detection to Protect sanitize_title
Since the processSanitizeTitle filter cannot directly access post_type, implement an isAcfInternalRequest() helper that inspects the call stack for ACF-related classes or functions:
ACF_Internal_Post_TypeclassACF_Field_Groupclass- Functions such as
acf_update_field,acf_import_field_group, etc.
3. Defense-in-Depth
Also exclude ACF’s internal post types in WPSlug_Settings::isPostTypeEnabled(), providing a second layer of 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 | Preserved as 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 correctly | Works correctly |
| Saving posts containing ACF fields | Field values lost | Field values preserved |
Update Delivery
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, please report them in this thread.