Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wp_filter_post_kses creates invalid JSON on save_post_array #311

Closed
dennisnissle opened this issue May 30, 2019 · 3 comments · Fixed by #312
Closed

wp_filter_post_kses creates invalid JSON on save_post_array #311

dennisnissle opened this issue May 30, 2019 · 3 comments · Fixed by #312

Comments

@dennisnissle
Copy link
Contributor

Hi,

I was facing a really nasty bug. My actions were added correctly but did all receive a "failed fetch action" error. This was due to my arguments not being able to run through json_decode and therefor not being attached to my hook (resulting in a PHP too few arguments error). This is an example of my arguments:

$args = array(
	'date_expires' => '<' . $today->getTimestamp(),
	'status'       => 'active',
	'limit'        => 1,
	'orderby'      => 'date_expires',
	'paginate'     => true,
);

This is the JSON being created within the post_content DB field (sanitized by WP)

{"args":{"date_expires":"&lt;1559174400&quot;,&quot;status&quot;:&quot;active&quot;,&quot;limit&quot;:50,&quot;orderby&quot;:&quot;date_expires&quot;,&quot;offset&quot;:0}}

As you can see, starting from the timestamp all the quotes are transformed into their HTML equivalent - this is due to wp_filter_post_kses sanitizing the post_content data.

WP prevents this from happening with their own JSON data (e.g. WP_Embed) by checking and removing the kses filters before inserting/updating the post. I've fixed the error by doing the same in ActionScheduler_wpPostStore method save_post_array:

$has_kses = false !== has_filter( 'content_save_pre', 'wp_filter_post_kses' );

if ( $has_kses ) {
	// Prevent KSES from corrupting JSON in post_content.
	kses_remove_filters();
}

$post_id = wp_insert_post($post_array);

if ( $has_kses ) {
	kses_init_filters();
}

I can provide you with a pull request too..

Cheers

@dennisnissle dennisnissle changed the title wp_filter_post_kses quotes JSON on save_post_array wp_filter_post_kses creates invalid JSON on save_post_array May 30, 2019
@rrennick
Copy link
Contributor

I can provide you with a pull request too..

Please do. Can you include a reference to where WP does it for WP_Embed?

@thenbrent
Copy link
Contributor

this is due to wp_filter_post_kses sanitizing the post_content data

This should also be fixed with custom tables, as we won't be using post_content anymore.

@dennisnissle
Copy link
Contributor Author

Added the pull request. See https://core.trac.wordpress.org/browser/trunk/src/wp-includes/class-wp-embed.php#L282 for further information on how this is handled within WP_Embed.

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants