Controlling JSON encoded flags in ACF Custom Database Tables version 1.0.x
The ACF Custom Database Tables plugin uses JSON encoding to prepare complex values for storing in the database. This differs to WordPress' core approach as WordPress relies on serialization instead. By default, the plugin opts to not escape slashes when encoding but there may be times where additional flags need to be used. e.g;
The following example demonstrates how to short-circuit the plugin's encoding algorithm in order to define custom args for the
wp_json_encode() function. It uses the
acfcdt/filter_value_before_encode filter found in
This example is JSON only
Note that this example is using JSON encoding which is what the plugin expects when attempting to decode data for return from the database.
Whilst it would be possible to use this same filter for an alternate encoding method (such as serialization) it would also then be necessary to correctly decode values using the
acfcdt/filter_value_before_decode filter found in
\ACFCustomDatabaseTables\Intercept\ACFInterceptBase::maybe_decode() as the plugin will, by default, attempt to decode JSON strings.
Version 1.1 and above
In future versions of the plugin, this filter will continue to work but there are additional filters that will be more appropriate for controlling the args passed to the wp_json_encode() function.
Where to place this code?
This should work fine in your theme's
functions.php file. That said, anything related to database configuration would be better suited in a plugin as it is the type of configuration that is unlikely to change. Personally, I prefer to put my ACF Custom Database Tables config in an MU plugin to prevent anyone from deactivating it but a standard plugin will be sufficient if that is preferable.