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
This commit is contained in:
Peter Wilson 2019-01-29 21:29:50 +00:00
parent 2ce767141a
commit d9a1f99d9c
4 changed files with 66 additions and 16 deletions

View File

@ -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' ) );

View File

@ -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 ) {

View File

@ -3095,6 +3095,52 @@ function wp_targeted_link_rel_callback( $matches ) {
return "<a $link_html>";
}
/**
* 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.
*

View File

@ -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.