Created
May 14, 2025 12:17
-
-
Save kjvdven/a8a3cbf2c3f68dff50df55752dce4e54 to your computer and use it in GitHub Desktop.
Fix issue with MailPoet and ACF breaking the post template selection in the location rules.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter("acf/location/rule_values/post_template", function ($choices) { | |
// Remove MailPoet or any values that are not strings | |
foreach ($choices as $key => $value) { | |
// Remove keys/groups like 'mailpoet_email' containing WP_Block_Template objects | |
if ( | |
is_array($value) && | |
!empty($value) && | |
isset($value["newsletter"]) && | |
is_object($value["newsletter"]) && | |
get_class($value["newsletter"]) === "WP_Block_Template" | |
) { | |
unset($choices[$key]); | |
continue; | |
} | |
// If it's not an array, but not a string, remove as well | |
if (!is_string($value) && !is_array($value)) { | |
unset($choices[$key]); | |
} | |
// If it's an array (subchoices like pages), check them: | |
if (is_array($value)) { | |
foreach ($value as $subkey => $subval) { | |
if (!is_string($subval)) { | |
unset($choices[$key][$subkey]); | |
} | |
} | |
// If group ends up empty, remove group | |
if (empty($choices[$key])) { | |
unset($choices[$key]); | |
} | |
} | |
} | |
return $choices; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fixes: