WordPress.org

Make WordPress Core

Changeset 36217


Ignore:
Timestamp:
01/07/2016 09:38:06 AM (4 years ago)
Author:
swissspidy
Message:

Rewrite: Add a remove_rewrite_tag() helper function.

It can be used to properly remove registered rewrite tags. Adds unit tests.

Fixes #35236.

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-rewrite.php

    r36181 r36217  
    839839            $this->rewritereplace[] = $regex;
    840840            $this->queryreplace[] = $query;
     841        }
     842    }
     843
     844
     845    /**
     846     * Removes an existing rewrite tag.
     847     *
     848     * @since 4.5.0
     849     * @access public
     850     *
     851     * @see WP_Rewrite::$rewritecode
     852     * @see WP_Rewrite::$rewritereplace
     853     * @see WP_Rewrite::$queryreplace
     854     *
     855     * @param string $tag Name of the rewrite tag to remove.
     856     */
     857    public function remove_rewrite_tag( $tag ) {
     858        $position = array_search( $tag, $this->rewritecode );
     859        if ( false !== $position && null !== $position ) {
     860            unset( $this->rewritecode[ $position ] );
     861            unset( $this->rewritereplace[ $position ] );
     862            unset( $this->queryreplace[ $position ] );
    841863        }
    842864    }
  • trunk/src/wp-includes/rewrite.php

    r36181 r36217  
    171171
    172172    $wp_rewrite->add_rewrite_tag( $tag, $regex, $query );
     173}
     174
     175/**
     176 * Removes an existing rewrite tag (like %postname%).
     177 *
     178 * @since 4.5.0
     179 *
     180 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
     181 *
     182 * @param string $tag Name of the rewrite tag.
     183 */
     184function remove_rewrite_tag( $tag ) {
     185    global $wp_rewrite;
     186    $wp_rewrite->remove_rewrite_tag( $tag );
    173187}
    174188
Note: See TracChangeset for help on using the changeset viewer.