Filter
Since Legacy
uncanny-automator
automator_wpcpostcontent_should_wp_slash
Filters whether to automatically slash post content data before saving to the database.
add_filter( 'automator_wpcpostcontent_should_wp_slash', $callback, 10, 2 );
Description
Filters whether to apply `wp_slash()` to post content. Use this hook to conditionally prevent or enable `wp_slash()` for post content, typically for security or data integrity reasons. Defaults to false.
Usage
add_filter( 'automator_wpcpostcontent_should_wp_slash', 'your_function_name', 10, 2 );
Parameters
-
$should_slash(bool) - Whether to apply wp_slash(). Default false.
-
$data(array) - The field data array.
Return Value
The filtered value.
Examples
/**
* Example of using the 'automator_wpcpostcontent_should_wp_slash' filter.
*
* This filter allows you to conditionally bypass the wp_slash() function
* for 'WPCPOSTCONTENT' field types, potentially when you've already
* handled slashes or don't need them.
*
* @param bool $should_wp_slash The default value, usually false.
* @param array $data The array of data being processed.
*
* @return bool Whether or not wp_slash() should be applied.
*/
add_filter(
'automator_wpcpostcontent_should_wp_slash',
function( $should_wp_slash, $data ) {
// For example, if we know that this specific post content is safe
// and doesn't require database escaping for slashes, we might
// want to disable it to avoid unnecessary processing.
// This could be based on a specific flag in the $data array,
// or a user setting, or even the context of the automation.
// Let's imagine a scenario where if a specific key 'skip_db_slashes'
// exists and is set to true within the $data array, we bypass wp_slash().
if ( isset( $data['skip_db_slashes'] ) && true === $data['skip_db_slashes'] ) {
return false; // Do not apply wp_slash()
}
// In all other cases, we defer to the default behavior or other filters.
return $should_wp_slash;
},
10, // Priority
2 // Number of accepted arguments
);
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/api/services/field/class-field-sanitizer-legacy-hooks.php:120
src/core/lib/utilities/class-automator-utilities.php:586
public function handle_wpcpostcontent( $sanitized, $original, string $type, string $transport, Field $field ) {
// Build the data array in legacy format for filter compatibility.
$data = array( 'WPCPOSTCONTENT' => $sanitized );
/**
* Filters whether to sanitize WPCPOSTCONTENT with wp_kses_post().
*
* @since Legacy
*
* @param bool $should_sanitize Whether to apply wp_kses_post(). Default false.
* @param array $data The field data array.
*/
if ( apply_filters( 'automator_wpcpostcontent_should_sanitize', false, $data ) ) {
$sanitized = wp_kses_post( $sanitized );
}
/**
* Filters whether to apply wp_slash() to WPCPOSTCONTENT.
*
* @since Legacy
*
* @param bool $should_slash Whether to apply wp_slash(). Default false.
* @param array $data The field data array.
*/
if ( apply_filters( 'automator_wpcpostcontent_should_wp_slash', false, $data ) ) {
$sanitized = wp_slash( $sanitized );
}
return $sanitized;
}