diff --git src/wp-includes/class-wp-rewrite.php src/wp-includes/class-wp-rewrite.php
index 035bbc3..e6f768f 100644
|
|
class WP_Rewrite { |
1745 | 1745 | } |
1746 | 1746 | |
1747 | 1747 | /** |
| 1748 | * Removes a permalink structure. |
| 1749 | * |
| 1750 | * @since 4.5.0 |
| 1751 | * @access public |
| 1752 | * |
| 1753 | * @param string $name Name for permalink structure. |
| 1754 | */ |
| 1755 | public function remove_permastruct( $name ) { |
| 1756 | unset( $this->extra_permastructs[ $name ] ); |
| 1757 | } |
| 1758 | |
| 1759 | /** |
1748 | 1760 | * Removes rewrite rules and then recreate rewrite rules. |
1749 | 1761 | * |
1750 | 1762 | * Calls WP_Rewrite::wp_rewrite_rules() after removing the 'rewrite_rules' option. |
diff --git src/wp-includes/rewrite.php src/wp-includes/rewrite.php
index 7f3b2ed..73137f8 100644
|
|
function add_permastruct( $name, $struct, $args = array() ) { |
198 | 198 | } |
199 | 199 | |
200 | 200 | /** |
| 201 | * Remove permalink structure. |
| 202 | * |
| 203 | * @since 4.5.0 |
| 204 | * |
| 205 | * @see WP_Rewrite::remove_permastruct() |
| 206 | * @global WP_Rewrite $wp_rewrite |
| 207 | * |
| 208 | * @param string $name Name for permalink structure. |
| 209 | */ |
| 210 | function remove_permastruct( $name ) { |
| 211 | global $wp_rewrite; |
| 212 | |
| 213 | $wp_rewrite->remove_permastruct( $name ); |
| 214 | } |
| 215 | |
| 216 | /** |
201 | 217 | * Add a new feed type like /atom1/. |
202 | 218 | * |
203 | 219 | * @since 2.1.0 |
diff --git tests/phpunit/tests/rewrite/permastructs.php tests/phpunit/tests/rewrite/permastructs.php
new file mode 100644
index 0000000..8261dc9
-
|
+
|
|
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @group rewrite |
| 5 | */ |
| 6 | class Tests_Rewrite_Permastructs extends WP_UnitTestCase { |
| 7 | |
| 8 | public function setUp() { |
| 9 | parent::setUp(); |
| 10 | |
| 11 | $this->set_permalink_structure( '/%postname%/' ); |
| 12 | } |
| 13 | |
| 14 | public function test_add_permastruct( ) { |
| 15 | global $wp_rewrite; |
| 16 | |
| 17 | add_permastruct( 'foo', 'bar/%foo%' ); |
| 18 | $this->assertInternalType( 'array', $wp_rewrite->extra_permastructs['foo'] ); |
| 19 | $this->assertSame( '/bar/%foo%', $wp_rewrite->extra_permastructs['foo']['struct'] ); |
| 20 | } |
| 21 | |
| 22 | public function test_remove_permastruct( ) { |
| 23 | global $wp_rewrite; |
| 24 | |
| 25 | add_permastruct( 'foo', 'bar/%foo%' ); |
| 26 | $this->assertInternalType( 'array', $wp_rewrite->extra_permastructs['foo'] ); |
| 27 | $this->assertSame( '/bar/%foo%', $wp_rewrite->extra_permastructs['foo']['struct'] ); |
| 28 | |
| 29 | remove_permastruct( 'foo' ); |
| 30 | $this->assertFalse( isset( $wp_rewrite->extra_permastructs['foo'] ) ); |
| 31 | } |
| 32 | } |