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..fe6b99a 100644
|
|
function add_rewrite_tag( $tag, $regex, $query = '' ) { |
178 | 178 | * @since 3.0.0 |
179 | 179 | * |
180 | 180 | * @see WP_Rewrite::add_permastruct() |
181 | | * @global WP_Rewrite $wp_rewrite |
| 181 | * @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
182 | 182 | * |
183 | 183 | * @param string $name Name for permalink structure. |
184 | 184 | * @param string $struct Permalink structure. |
… |
… |
function add_permastruct( $name, $struct, $args = array() ) { |
198 | 198 | } |
199 | 199 | |
200 | 200 | /** |
| 201 | * Remove permalink structure. |
| 202 | * |
| 203 | * Can only be used to remove permastructs that were added using add_permastruct(). |
| 204 | * Built-in permastructs cannot be removed. |
| 205 | * |
| 206 | * @since 4.5.0 |
| 207 | * |
| 208 | * @see WP_Rewrite::remove_permastruct() |
| 209 | * @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
| 210 | * |
| 211 | * @param string $name Name for permalink structure. |
| 212 | */ |
| 213 | function remove_permastruct( $name ) { |
| 214 | global $wp_rewrite; |
| 215 | |
| 216 | $wp_rewrite->remove_permastruct( $name ); |
| 217 | } |
| 218 | |
| 219 | /** |
201 | 220 | * Add a new feed type like /atom1/. |
202 | 221 | * |
203 | 222 | * @since 2.1.0 |
diff --git tests/phpunit/tests/rewrite/permastructs.php tests/phpunit/tests/rewrite/permastructs.php
new file mode 100644
index 0000000..3413398
-
|
+
|
|
| 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->assertEqualSets( array( |
| 19 | 'with_front' => true, |
| 20 | 'ep_mask' => EP_NONE, |
| 21 | 'paged' => true, |
| 22 | 'feed' => true, |
| 23 | 'walk_dirs' => true, |
| 24 | 'endpoints' => true, |
| 25 | 'forcomments' => false, |
| 26 | 'struct' => '/bar/%foo%', |
| 27 | ), $wp_rewrite->extra_permastructs['foo'] ); |
| 28 | } |
| 29 | |
| 30 | public function test_remove_permastruct( ) { |
| 31 | global $wp_rewrite; |
| 32 | |
| 33 | add_permastruct( 'foo', 'bar/%foo%' ); |
| 34 | $this->assertInternalType( 'array', $wp_rewrite->extra_permastructs['foo'] ); |
| 35 | $this->assertSame( '/bar/%foo%', $wp_rewrite->extra_permastructs['foo']['struct'] ); |
| 36 | |
| 37 | remove_permastruct( 'foo' ); |
| 38 | $this->assertFalse( isset( $wp_rewrite->extra_permastructs['foo'] ) ); |
| 39 | } |
| 40 | } |