Make WordPress Core

Changeset 44714


Ignore:
Timestamp:
01/29/2019 09:28:57 PM (6 years ago)
Author:
peterwilsoncc
Message:

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.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r44580 r44714  
    28862886        add_filter( 'wp_save_post_revision_post_has_changed', array( $this, '_filter_revision_post_has_changed' ), 5, 3 );
    28872887
    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.
    28892895        $has_kses = ( false !== has_filter( 'content_save_pre', 'wp_filter_post_kses' ) );
    28902896        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();
    28922902        }
    28932903
     
    29192929            }
    29202930        }
     2931
     2932        // Restore removed content filters.
    29212933        if ( $has_kses ) {
    29222934            kses_init_filters();
    29232935        }
     2936        if ( $has_targeted_link_rel_filters ) {
     2937            wp_init_targeted_link_rel_filters();
     2938        }
     2939
    29242940        $this->_changeset_data = null; // Reset so WP_Customize_Manager::changeset_data() will re-populate with updated contents.
    29252941
  • trunk/src/wp-includes/default-filters.php

    r44157 r44714  
    129129
    130130// 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 };
     131add_action( 'init', 'wp_init_targeted_link_rel_filters' );
    144132
    145133// Format strings for display.
  • trunk/src/wp-includes/formatting.php

    r44691 r44714  
    30973097
    30983098/**
     3099 * Adds all filters modifying the rel attribute of targeted links.
     3100 *
     3101 * @since 5.1.0
     3102 */
     3103function 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 */
     3126function 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
     3144/**
    30993145 * Convert one smiley code to the icon graphic file equivalent.
    31003146 *
  • trunk/tests/phpunit/tests/formatting/WPTargetedLinkRel.php

    r44691 r44714  
    8484        $this->assertEquals( $expected, wp_targeted_link_rel( $content ) );
    8585    }
     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    }
    86104}
Note: See TracChangeset for help on using the changeset viewer.