WordPress.org

Make WordPress Core

Ticket #28517: 28517.diff

File 28517.diff, 3.5 KB (added by swissspidy, 4 years ago)
  • src/wp-includes/class-wp-rewrite.php

    diff --git src/wp-includes/class-wp-rewrite.php src/wp-includes/class-wp-rewrite.php
    index 17c58b90a8..6937380750 100644
    class WP_Rewrite { 
    17981798         * @staticvar bool $do_hard_later
    17991799         *
    18001800         * @param bool $hard Whether to update .htaccess (hard flush) or just update rewrite_rules option (soft flush). Default is true (hard).
     1801         * @return bool True on a hard flush attempt, false on a soft flush attempt.
    18011802         */
    18021803        public function flush_rules( $hard = true ) {
    18031804                static $do_hard_later = null;
    class WP_Rewrite { 
    18221823                 *
    18231824                 * A "hard" flush updates .htaccess (Apache) or web.config (IIS).
    18241825                 *
    1825                  * @since 3.7.0
     1826                 * @since 4.8.0
    18261827                 *
    1827                  * @param bool $hard Whether to flush rewrite rules "hard". Default true.
     1828                 * @param bool $hard Whether to flush rewrite rules "hard".
    18281829                 */
    1829                 if ( ! $hard || ! apply_filters( 'flush_rewrite_rules_hard', true ) ) {
    1830                         return;
     1830                $hard = apply_filters( 'flush_rewrite_rules_hard', $hard );
     1831
     1832                if ( ! $hard ) {
     1833                        return false;
    18311834                }
    1832                 if ( function_exists( 'save_mod_rewrite_rules' ) )
     1835
     1836                if ( function_exists( 'save_mod_rewrite_rules' ) ) {
    18331837                        save_mod_rewrite_rules();
    1834                 if ( function_exists( 'iis7_save_url_rewrite_rules' ) )
     1838                }
     1839
     1840                if ( function_exists( 'iis7_save_url_rewrite_rules' ) ) {
    18351841                        iis7_save_url_rewrite_rules();
     1842                }
     1843
     1844                return true;
    18361845        }
    18371846
    18381847        /**
  • src/wp-includes/rewrite.php

    diff --git src/wp-includes/rewrite.php src/wp-includes/rewrite.php
    index 705e5f2bc8..fdba218a62 100644
    function add_feed( $feedname, $function ) { 
    267267 *
    268268 * @param bool $hard Whether to update .htaccess (hard flush) or just update
    269269 *                       rewrite_rules transient (soft flush). Default is true (hard).
     270 * @return bool True on a hard flush attempt, false on a soft flush attempt.
    270271 */
    271272function flush_rewrite_rules( $hard = true ) {
    272273        global $wp_rewrite;
    273         $wp_rewrite->flush_rules( $hard );
     274        return $wp_rewrite->flush_rules( $hard );
    274275}
    275276
    276277/**
  • tests/phpunit/tests/rewrite.php

    diff --git tests/phpunit/tests/rewrite.php tests/phpunit/tests/rewrite.php
    index dfa9749821..d37cb0e226 100644
    class Tests_Rewrite extends WP_UnitTestCase { 
    399399                $this->assertInternalType( 'array', $rewrite_rules );
    400400                $this->assertNotEmpty( $rewrite_rules );
    401401        }
     402
     403        /**
     404         * @ticket 28517
     405         */
     406        function test_flush_rules_hard_true_no_filters() {
     407                $this->assertTrue( flush_rewrite_rules( true ) );
     408        }
     409
     410        /**
     411         * @ticket 28517
     412         */
     413        function test_flush_rules_hard_false_no_filters() {
     414                $this->assertFalse( flush_rewrite_rules( false ) );
     415        }
     416
     417        /**
     418         * @ticket 28517
     419         */
     420        function test_flush_rules_hard_true_with_filters_true() {
     421                add_filter( 'flush_rewrite_rules_hard', '__return_true' );
     422                $this->assertTrue( flush_rewrite_rules( true ) );
     423        }
     424
     425        /**
     426         * @ticket 28517
     427         */
     428        function test_flush_rules_hard_true_with_filters_false() {
     429                add_filter( 'flush_rewrite_rules_hard', '__return_false' );
     430                $this->assertFalse( flush_rewrite_rules( true ) );
     431        }
     432
     433        /**
     434         * @ticket 28517
     435         */
     436        function test_flush_rules_hard_false_with_filters_true() {
     437                add_filter( 'flush_rewrite_rules_hard', '__return_true' );
     438                $this->assertTrue( flush_rewrite_rules( false ) );
     439        }
     440
     441        /**
     442         * @ticket 28517
     443         */
     444        function test_flush_rules_hard_false_with_filters_false() {
     445                add_filter( 'flush_rewrite_rules_hard', '__return_false' );
     446                $this->assertFalse( flush_rewrite_rules( false ) );
     447        }
    402448}