WordPress.org

Make WordPress Core

Ticket #35235: 35235.diff

File 35235.diff, 2.3 KB (added by swissspidy, 5 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 035bbc3..e6f768f 100644
    class WP_Rewrite { 
    17451745        }
    17461746
    17471747        /**
     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        /**
    17481760         * Removes rewrite rules and then recreate rewrite rules.
    17491761         *
    17501762         * Calls WP_Rewrite::wp_rewrite_rules() after removing the 'rewrite_rules' option.
  • src/wp-includes/rewrite.php

    diff --git src/wp-includes/rewrite.php src/wp-includes/rewrite.php
    index 7f3b2ed..73137f8 100644
    function add_permastruct( $name, $struct, $args = array() ) { 
    198198}
    199199
    200200/**
     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 */
     210function remove_permastruct( $name ) {
     211        global $wp_rewrite;
     212
     213        $wp_rewrite->remove_permastruct( $name );
     214}
     215
     216/**
    201217 * Add a new feed type like /atom1/.
    202218 *
    203219 * @since 2.1.0
  • new file tests/phpunit/tests/rewrite/permastructs.php

    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 */
     6class 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}