diff --git src/wp-includes/class-wp-rewrite.php src/wp-includes/class-wp-rewrite.php
index 17c58b90a8..6937380750 100644
|
|
class WP_Rewrite { |
1798 | 1798 | * @staticvar bool $do_hard_later |
1799 | 1799 | * |
1800 | 1800 | * @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. |
1801 | 1802 | */ |
1802 | 1803 | public function flush_rules( $hard = true ) { |
1803 | 1804 | static $do_hard_later = null; |
… |
… |
class WP_Rewrite { |
1822 | 1823 | * |
1823 | 1824 | * A "hard" flush updates .htaccess (Apache) or web.config (IIS). |
1824 | 1825 | * |
1825 | | * @since 3.7.0 |
| 1826 | * @since 4.8.0 |
1826 | 1827 | * |
1827 | | * @param bool $hard Whether to flush rewrite rules "hard". Default true. |
| 1828 | * @param bool $hard Whether to flush rewrite rules "hard". |
1828 | 1829 | */ |
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; |
1831 | 1834 | } |
1832 | | if ( function_exists( 'save_mod_rewrite_rules' ) ) |
| 1835 | |
| 1836 | if ( function_exists( 'save_mod_rewrite_rules' ) ) { |
1833 | 1837 | save_mod_rewrite_rules(); |
1834 | | if ( function_exists( 'iis7_save_url_rewrite_rules' ) ) |
| 1838 | } |
| 1839 | |
| 1840 | if ( function_exists( 'iis7_save_url_rewrite_rules' ) ) { |
1835 | 1841 | iis7_save_url_rewrite_rules(); |
| 1842 | } |
| 1843 | |
| 1844 | return true; |
1836 | 1845 | } |
1837 | 1846 | |
1838 | 1847 | /** |
diff --git src/wp-includes/rewrite.php src/wp-includes/rewrite.php
index 705e5f2bc8..fdba218a62 100644
|
|
function add_feed( $feedname, $function ) { |
267 | 267 | * |
268 | 268 | * @param bool $hard Whether to update .htaccess (hard flush) or just update |
269 | 269 | * rewrite_rules transient (soft flush). Default is true (hard). |
| 270 | * @return bool True on a hard flush attempt, false on a soft flush attempt. |
270 | 271 | */ |
271 | 272 | function flush_rewrite_rules( $hard = true ) { |
272 | 273 | global $wp_rewrite; |
273 | | $wp_rewrite->flush_rules( $hard ); |
| 274 | return $wp_rewrite->flush_rules( $hard ); |
274 | 275 | } |
275 | 276 | |
276 | 277 | /** |
diff --git tests/phpunit/tests/rewrite.php tests/phpunit/tests/rewrite.php
index dfa9749821..d37cb0e226 100644
|
|
class Tests_Rewrite extends WP_UnitTestCase { |
399 | 399 | $this->assertInternalType( 'array', $rewrite_rules ); |
400 | 400 | $this->assertNotEmpty( $rewrite_rules ); |
401 | 401 | } |
| 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 | } |
402 | 448 | } |