Skip to content

Commit

Permalink
Prevent Kses from corrupting JSON in term_description
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Apr 26, 2018
1 parent 1799976 commit 5f067bc
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions includes/utils/class-amp-validation-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -2136,9 +2136,16 @@ public static function handle_validation_error_update( $redirect_to, $action, $t
}

if ( $term_group ) {
$has_pre_term_description_filter = has_filter( 'pre_term_description', 'wp_filter_kses' );
if ( false !== $has_pre_term_description_filter ) {
remove_filter( 'pre_term_description', 'wp_filter_kses', $has_pre_term_description_filter );
}
foreach ( $term_ids as $term_id ) {
wp_update_term( $term_id, self::TAXONOMY_SLUG, compact( 'term_group' ) );
}
if ( false !== $has_pre_term_description_filter ) {
add_filter( 'pre_term_description', 'wp_filter_kses', $has_pre_term_description_filter );
}
$redirect_to = add_query_arg(
array(
'amp_actioned' => $action,
Expand Down Expand Up @@ -2213,7 +2220,14 @@ public static function store_validation_errors( $validation_errors, $url ) {
// Not using WP_Term_Query since more likely individual terms are cached and wp_insert_term() will itself look at this cache anyway.
$term = get_term_by( 'slug', $term_slug, self::TAXONOMY_SLUG );
if ( ! ( $term instanceof WP_Term ) ) {
$has_pre_term_description_filter = has_filter( 'pre_term_description', 'wp_filter_kses' );
if ( false !== $has_pre_term_description_filter ) {
remove_filter( 'pre_term_description', 'wp_filter_kses', $has_pre_term_description_filter );
}
$r = wp_insert_term( $term_slug, self::TAXONOMY_SLUG, wp_slash( compact( 'description' ) ) );
if ( false !== $has_pre_term_description_filter ) {
add_filter( 'pre_term_description', 'wp_filter_kses', $has_pre_term_description_filter );
}
if ( is_wp_error( $r ) ) {
continue;
}
Expand Down

0 comments on commit 5f067bc

Please sign in to comment.