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. git-svn-id: https://develop.svn.wordpress.org/trunk@44714 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
ca96ccc55c
commit
99450a446d
@ -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' ) );
|
||||
|
@ -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 ) {
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -83,4 +83,22 @@ class Tests_Targeted_Link_Rel extends WP_UnitTestCase {
|
||||
$expected = '<p>Links: <a href="/" target="_blank">Do not change me</a></p>';
|
||||
$this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure default content filters are added.
|
||||
*
|
||||
* @ticket 45292.
|
||||
*/
|
||||
public function test_wp_targeted_link_rel_filters_run() {
|
||||
$content = '<p>Links: <a href="/" target="_blank">No rel</a></p>';
|
||||
$expected = '<p>Links: <a href="/" target="_blank" rel="noopener noreferrer">No rel</a></p>';
|
||||
|
||||
$post = $this->factory()->post->create_and_get(
|
||||
array(
|
||||
'post_content' => $content,
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals( $expected, $post->post_content );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user