From d9a1f99d9ce352a0e151169c3612b00c4c146ddf Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Tue, 29 Jan 2019 21:29:50 +0000 Subject: [PATCH] Customize: Remove `wp_targeted_link_rel` pre-save filter from change-sets. The pre-save filters added to links in [43732] could invalidate JSON data when saving Customizer change-sets. This removes the filters when saving and publishing change-sets. Props peterwilsoncc, nikeo for testing. See #45292. Built from https://develop.svn.wordpress.org/trunk@44714 git-svn-id: http://core.svn.wordpress.org/trunk@44545 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-customize-manager.php | 20 +++++++++- wp-includes/default-filters.php | 14 +------ wp-includes/formatting.php | 46 ++++++++++++++++++++++ wp-includes/version.php | 2 +- 4 files changed, 66 insertions(+), 16 deletions(-) diff --git a/wp-includes/class-wp-customize-manager.php b/wp-includes/class-wp-customize-manager.php index 7aa50f7862..81be17b79d 100644 --- a/wp-includes/class-wp-customize-manager.php +++ b/wp-includes/class-wp-customize-manager.php @@ -2885,10 +2885,20 @@ final class WP_Customize_Manager { $this->store_changeset_revision = $allow_revision; add_filter( 'wp_save_post_revision_post_has_changed', array( $this, '_filter_revision_post_has_changed' ), 5, 3 ); - // Update the changeset post. The publish_customize_changeset action will cause the settings in the changeset to be saved via WP_Customize_Setting::save(). + /* + * Update the changeset post. The publish_customize_changeset action + * will cause the settings in the changeset to be saved via + * WP_Customize_Setting::save(). + */ + + // Prevent content filters from corrupting JSON in post_content. $has_kses = ( false !== has_filter( 'content_save_pre', 'wp_filter_post_kses' ) ); if ( $has_kses ) { - kses_remove_filters(); // Prevent KSES from corrupting JSON in post_content. + kses_remove_filters(); + } + $has_targeted_link_rel_filters = ( false !== has_filter( 'content_save_pre', 'wp_targeted_link_rel' ) ); + if ( $has_targeted_link_rel_filters ) { + wp_remove_targeted_link_rel_filters(); } // Note that updating a post with publish status will trigger WP_Customize_Manager::publish_changeset_values(). @@ -2918,9 +2928,15 @@ final class WP_Customize_Manager { $this->_changeset_post_id = $r; // Update cached post ID for the loaded changeset. } } + + // Restore removed content filters. if ( $has_kses ) { kses_init_filters(); } + if ( $has_targeted_link_rel_filters ) { + wp_init_targeted_link_rel_filters(); + } + $this->_changeset_data = null; // Reset so WP_Customize_Manager::changeset_data() will re-populate with updated contents. remove_filter( 'wp_save_post_revision_post_has_changed', array( $this, '_filter_revision_post_has_changed' ) ); diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 66d64485d6..1319826212 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -128,19 +128,7 @@ foreach ( array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pr } // Add proper rel values for links with target. -foreach ( array( - 'title_save_pre', - 'content_save_pre', - 'excerpt_save_pre', - 'content_filtered_save_pre', - 'pre_comment_content', - 'pre_term_description', - 'pre_link_description', - 'pre_link_notes', - 'pre_user_description', -) as $filter ) { - add_filter( $filter, 'wp_targeted_link_rel' ); -}; +add_action( 'init', 'wp_init_targeted_link_rel_filters' ); // Format strings for display. foreach ( array( 'comment_author', 'term_name', 'link_name', 'link_description', 'link_notes', 'bloginfo', 'wp_title', 'widget_title' ) as $filter ) { diff --git a/wp-includes/formatting.php b/wp-includes/formatting.php index 878b148d14..f9a985e864 100644 --- a/wp-includes/formatting.php +++ b/wp-includes/formatting.php @@ -3095,6 +3095,52 @@ function wp_targeted_link_rel_callback( $matches ) { return ""; } +/** + * Adds all filters modifying the rel attribute of targeted links. + * + * @since 5.1.0 + */ +function wp_init_targeted_link_rel_filters() { + $filters = array( + 'title_save_pre', + 'content_save_pre', + 'excerpt_save_pre', + 'content_filtered_save_pre', + 'pre_comment_content', + 'pre_term_description', + 'pre_link_description', + 'pre_link_notes', + 'pre_user_description', + ); + + foreach ( $filters as $filter ) { + add_filter( $filter, 'wp_targeted_link_rel' ); + }; +} + +/** + * Removes all filters modifying the rel attribute of targeted links. + * + * @since 5.1.0 + */ +function wp_remove_targeted_link_rel_filters() { + $filters = array( + 'title_save_pre', + 'content_save_pre', + 'excerpt_save_pre', + 'content_filtered_save_pre', + 'pre_comment_content', + 'pre_term_description', + 'pre_link_description', + 'pre_link_notes', + 'pre_user_description', + ); + + foreach ( $filters as $filter ) { + remove_filter( $filter, 'wp_targeted_link_rel' ); + }; +} + /** * Convert one smiley code to the icon graphic file equivalent. * diff --git a/wp-includes/version.php b/wp-includes/version.php index 6a0eb499eb..6583625da5 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.1-beta2-44713'; +$wp_version = '5.1-beta2-44714'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.