Filter uncanny-automator

automator_create_posts_should_wpslash

Filters whether WordPress should automatically add slashes to post content when creating posts via the Automator integration.

add_filter( 'automator_create_posts_should_wpslash', $callback, 10, 1 );

Description

Filters whether WordPress's `wp_slash` function should be applied to post content when creating posts via the Automator. Developers can return `true` to enforce `wp_slash` for enhanced security, or `false` to skip it. This hook provides control over content sanitization during post creation.


Usage

add_filter( 'automator_create_posts_should_wpslash', 'your_function_name', 10, 1 );

Parameters

$action_data (mixed)
This parameter is an initial value for the filter, typically `false`, and can be used to control whether WordPress slashes are applied to the post content.

Return Value

The filtered value.


Examples

/**
 * Example of how to use the automator_create_posts_should_wpslash filter.
 * This example conditionally enables wp_slash for post content if a specific
 * meta key in $action_data is set to 'yes'.
 */
add_filter(
	'automator_create_posts_should_wpslash',
	function ( $should_slash, $action_data ) {
		// Check if the $action_data array and its 'meta' key exist
		if ( isset( $action_data['meta'] ) && is_array( $action_data['meta'] ) ) {
			// Define a specific meta key to check for enabling wp_slash
			$enable_slash_meta_key = 'ANOTHER_PLUGIN_ENABLE_WP_SLASH';

			// Check if the meta key exists and its value is 'yes'
			if ( isset( $action_data['meta'][ $enable_slash_meta_key ] ) && 'yes' === $action_data['meta'][ $enable_slash_meta_key ] ) {
				// If the condition is met, return true to enable wp_slash
				return true;
			}
		}

		// If the condition is not met, return the original value (usually false)
		return $should_slash;
	},
	10,
	2
);

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/integrations/wp/actions/wp-createpost.php:413

'true' === $action_data['meta']['WPCPOSTCONTENTCUSTOMJSCHECKBOX']
		) {
			$custom_js = Automator()->parse->text( $action_data['meta']['WPCPOSTCONTENTCUSTOMJS'], $recipe_id, $user_id, $args );

			$post_content .= '<!-- wp:html --><script>' . $custom_js . '</script><!-- /wp:html -->';
		}

		$should_wp_slash = apply_filters( 'automator_create_posts_should_wpslash', false, $action_data );

		if ( true === $should_wp_slash ) {
			$content = wp_slash( $content );
		}

		$post_content = $post_content . $content;

Scroll to Top