diff --git a/src/wp-includes/class-wp-customize-manager.php b/src/wp-includes/class-wp-customize-manager.php
index 7aa50f7862..81be17b79d 100644
a
|
b
|
final class WP_Customize_Manager { |
2885 | 2885 | $this->store_changeset_revision = $allow_revision; |
2886 | 2886 | add_filter( 'wp_save_post_revision_post_has_changed', array( $this, '_filter_revision_post_has_changed' ), 5, 3 ); |
2887 | 2887 | |
2888 | | // Update the changeset post. The publish_customize_changeset action will cause the settings in the changeset to be saved via WP_Customize_Setting::save(). |
| 2888 | /* |
| 2889 | * Update the changeset post. The publish_customize_changeset action |
| 2890 | * will cause the settings in the changeset to be saved via |
| 2891 | * WP_Customize_Setting::save(). |
| 2892 | */ |
| 2893 | |
| 2894 | // Prevent content filters from corrupting JSON in post_content. |
2889 | 2895 | $has_kses = ( false !== has_filter( 'content_save_pre', 'wp_filter_post_kses' ) ); |
2890 | 2896 | if ( $has_kses ) { |
2891 | | kses_remove_filters(); // Prevent KSES from corrupting JSON in post_content. |
| 2897 | kses_remove_filters(); |
| 2898 | } |
| 2899 | $has_targeted_link_rel_filters = ( false !== has_filter( 'content_save_pre', 'wp_targeted_link_rel' ) ); |
| 2900 | if ( $has_targeted_link_rel_filters ) { |
| 2901 | wp_remove_targeted_link_rel_filters(); |
2892 | 2902 | } |
2893 | 2903 | |
2894 | 2904 | // Note that updating a post with publish status will trigger WP_Customize_Manager::publish_changeset_values(). |
… |
… |
final class WP_Customize_Manager { |
2918 | 2928 | $this->_changeset_post_id = $r; // Update cached post ID for the loaded changeset. |
2919 | 2929 | } |
2920 | 2930 | } |
| 2931 | |
| 2932 | // Restore removed content filters. |
2921 | 2933 | if ( $has_kses ) { |
2922 | 2934 | kses_init_filters(); |
2923 | 2935 | } |
| 2936 | if ( $has_targeted_link_rel_filters ) { |
| 2937 | wp_init_targeted_link_rel_filters(); |
| 2938 | } |
| 2939 | |
2924 | 2940 | $this->_changeset_data = null; // Reset so WP_Customize_Manager::changeset_data() will re-populate with updated contents. |
2925 | 2941 | |
2926 | 2942 | remove_filter( 'wp_save_post_revision_post_has_changed', array( $this, '_filter_revision_post_has_changed' ) ); |
diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php
index 66d64485d6..1319826212 100644
a
|
b
|
foreach ( array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pr |
128 | 128 | } |
129 | 129 | |
130 | 130 | // Add proper rel values for links with target. |
131 | | foreach ( array( |
132 | | 'title_save_pre', |
133 | | 'content_save_pre', |
134 | | 'excerpt_save_pre', |
135 | | 'content_filtered_save_pre', |
136 | | 'pre_comment_content', |
137 | | 'pre_term_description', |
138 | | 'pre_link_description', |
139 | | 'pre_link_notes', |
140 | | 'pre_user_description', |
141 | | ) as $filter ) { |
142 | | add_filter( $filter, 'wp_targeted_link_rel' ); |
143 | | }; |
| 131 | add_action( 'init', 'wp_init_targeted_link_rel_filters' ); |
144 | 132 | |
145 | 133 | // Format strings for display. |
146 | 134 | foreach ( array( 'comment_author', 'term_name', 'link_name', 'link_description', 'link_notes', 'bloginfo', 'wp_title', 'widget_title' ) as $filter ) { |
diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php
index dc4bf24648..4beb33cb8f 100644
a
|
b
|
function wp_targeted_link_rel_callback( $matches ) { |
3095 | 3095 | return "<a $link_html>"; |
3096 | 3096 | } |
3097 | 3097 | |
| 3098 | /** |
| 3099 | * Adds all filters modifying the rel attribute of targeted links. |
| 3100 | * |
| 3101 | * @since 5.1.0 |
| 3102 | */ |
| 3103 | function wp_init_targeted_link_rel_filters() { |
| 3104 | $filters = array( |
| 3105 | 'title_save_pre', |
| 3106 | 'content_save_pre', |
| 3107 | 'excerpt_save_pre', |
| 3108 | 'content_filtered_save_pre', |
| 3109 | 'pre_comment_content', |
| 3110 | 'pre_term_description', |
| 3111 | 'pre_link_description', |
| 3112 | 'pre_link_notes', |
| 3113 | 'pre_user_description', |
| 3114 | ); |
| 3115 | |
| 3116 | foreach ( $filters as $filter ) { |
| 3117 | add_filter( $filter, 'wp_targeted_link_rel' ); |
| 3118 | }; |
| 3119 | } |
| 3120 | |
| 3121 | /** |
| 3122 | * Removes all filters modifying the rel attribute of targeted links. |
| 3123 | * |
| 3124 | * @since 5.1.0 |
| 3125 | */ |
| 3126 | function wp_remove_targeted_link_rel_filters() { |
| 3127 | $filters = array( |
| 3128 | 'title_save_pre', |
| 3129 | 'content_save_pre', |
| 3130 | 'excerpt_save_pre', |
| 3131 | 'content_filtered_save_pre', |
| 3132 | 'pre_comment_content', |
| 3133 | 'pre_term_description', |
| 3134 | 'pre_link_description', |
| 3135 | 'pre_link_notes', |
| 3136 | 'pre_user_description', |
| 3137 | ); |
| 3138 | |
| 3139 | foreach ( $filters as $filter ) { |
| 3140 | remove_filter( $filter, 'wp_targeted_link_rel' ); |
| 3141 | }; |
| 3142 | } |
| 3143 | |
3098 | 3144 | /** |
3099 | 3145 | * Convert one smiley code to the icon graphic file equivalent. |
3100 | 3146 | * |
diff --git a/tests/phpunit/tests/formatting/WPTargetedLinkRel.php b/tests/phpunit/tests/formatting/WPTargetedLinkRel.php
index 5693f02973..08f8ac1021 100644
a
|
b
|
class Tests_Targeted_Link_Rel extends WP_UnitTestCase { |
83 | 83 | $expected = '<p>Links: <a href="/" target="_blank">Do not change me</a></p>'; |
84 | 84 | $this->assertEquals( $expected, wp_targeted_link_rel( $content ) ); |
85 | 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Ensure default content filters are added. |
| 89 | * |
| 90 | * @ticket 45292. |
| 91 | */ |
| 92 | public function test_wp_targeted_link_rel_filters_run() { |
| 93 | $content = '<p>Links: <a href="/" target="_blank">No rel</a></p>'; |
| 94 | $expected = '<p>Links: <a href="/" target="_blank" rel="noopener noreferrer">No rel</a></p>'; |
| 95 | |
| 96 | $post = $this->factory()->post->create_and_get( |
| 97 | array( |
| 98 | 'post_content' => $content, |
| 99 | ) |
| 100 | ); |
| 101 | |
| 102 | $this->assertEquals( $expected, $post->post_content ); |
| 103 | } |
86 | 104 | } |