Make WordPress Core

Ticket #18450: rewrite.diff

File rewrite.diff, 1.8 KB (added by joostdevalk, 13 years ago)

Patch that hooks on shutdown and blocks frontend flushes

  • wp-includes/rewrite.php

     
    19271927        }
    19281928
    19291929        /**
     1930         * Schedules a flush of the rewrite rules.     
     1931         *
     1932         * @since 2.0.1
     1933         * @access public
     1934         * @param bool $hard Whether to update .htaccess (hard flush) or just update rewrite_rules option (soft flush). Default is true (hard).
     1935         */
     1936        function flush_rules( $hard = true ) {
     1937                if ( !did_action( 'admin_init' ) ) {
     1938                        _doing_it_wrong( __( 'Never flush rules before admin_init, and NEVER on a front-end page load! Do it on plugin activation instead.' ) );
     1939                        return false;
     1940                }
     1941                if ( $hard )
     1942                        add_filter( 'shutdown_filter_rewrite_rules_hard', '__return_true' );
     1943                add_action( 'shutdown', '_wp_shutdown_flush_rules' );
     1944        }
     1945       
     1946        /**
    19301947         * Remove rewrite rules and then recreate rewrite rules.
    19311948         *
    19321949         * Calls {@link WP_Rewrite::wp_rewrite_rules()} after removing the
    19331950         * 'rewrite_rules' option. If the function named 'save_mod_rewrite_rules'
    19341951         * exists, it will be called.
    19351952         *
    1936          * @since 2.0.1
    1937          * @access public
    1938          * @param bool $hard Whether to update .htaccess (hard flush) or just update rewrite_rules option (soft flush). Default is true (hard).
     1953         * @since 3.4
     1954         * @access private
    19391955         */
    1940         function flush_rules($hard = true) {
     1956        function _wp_shutdown_flush_rules() {
     1957                if ( !did_action( 'shutdown' ) ) {
     1958                        _doing_it_wrong( __( 'Do not call this function directly, use flush_rules instead.' ) );
     1959                        return false;
     1960                }
    19411961                delete_option('rewrite_rules');
    19421962                $this->wp_rewrite_rules();
     1963               
     1964                $hard = apply_filters( 'shutdown_filter_rewrite_rules_hard', false );
     1965               
    19431966                if ( $hard && function_exists('save_mod_rewrite_rules') )
    19441967                        save_mod_rewrite_rules();
    19451968                if ( $hard && function_exists('iis7_save_url_rewrite_rules') )