WordPress.org

Make WordPress Core

Ticket #23367: 23367.4.diff

File 23367.4.diff, 1.6 KB (added by morganestes, 7 years ago)

Canonical URL filtered with PHP

  • src/wp-admin/admin.php

    diff --git src/wp-admin/admin.php src/wp-admin/admin.php
    index 22813cc..ca98667 100644
    if ( isset($_GET['import']) && !defined('WP_LOAD_IMPORTERS') ) 
    3030
    3131require_once(dirname(dirname(__FILE__)) . '/wp-load.php');
    3232
     33/**
     34 * Remove specific query string parameters from a URL.
     35 *
     36 * @since 4.2.0
     37 *
     38 * @return string The filtered URL with parameters stripped.
     39 */
     40function wp_admin_filtered_url() {
     41        $removable_url_params = array(
     42                'message', 'updated', 'settings-updated',
     43                'saved', 'activated', 'activate',
     44                'deactivate', 'locked', 'skipped',
     45                'deleted', 'trashed', 'untrashed',
     46        );
     47
     48        /**
     49         * Filter the list of URL parameters to remove.
     50         *
     51         * @since 4.2.0
     52         *
     53         * @param array $removable_url_params An array of parameters to remove from the URL.
     54         */
     55        $removable_url_params = apply_filters( 'removable_url_params', $removable_url_params );
     56
     57        // Ensure we're using an absolute URL.
     58        return get_site_url() . remove_query_arg( $removable_url_params );
     59}
     60
     61/**
     62 * Prints the filtered canonical link in the admin header and change the current URL to match.
     63 *
     64 * @since 4.2.0
     65 */
     66function wp_admin_canonical_url_head() {
     67        ?>
     68        <link id="wp-admin-canonical" rel="canonical" href="<?php echo esc_url( wp_admin_filtered_url() ); ?>" />
     69        <script>if ( jQuery.isFunction( history.replaceState ) ) {
     70                        history.replaceState( null, null, document.getElementById( 'wp-admin-canonical' ).href );
     71                }</script>
     72<?php
     73}
     74
     75add_action( 'admin_head', 'wp_admin_canonical_url_head', 20 );
     76
    3377nocache_headers();
    3478
    3579if ( get_option('db_upgraded') ) {