[wp-trac] [WordPress Trac] #35236: remove_rewrite_tag()

WordPress Trac noreply at wordpress.org
Tue Jan 5 12:05:00 UTC 2016


#35236: remove_rewrite_tag()
--------------------------------------+------------------
 Reporter:  swissspidy                |       Owner:
     Type:  defect (bug)              |      Status:  new
 Priority:  normal                    |   Milestone:  4.5
Component:  Rewrite Rules             |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+------------------

Comment (by swissspidy):

 Replying to [comment:2 boonebgorges]:
 > In your tests, you're using `array_pop()` to test the presence of a
 value in `$wp_rewrite` properties. This is dangerous: `array_pop()`
 modifies the original array, which might break later tests. Can you use
 `assertContains()` and `assertNotContains()` instead? If it's important to
 check that it's the last item in the array, maybe you could use `end()`?

 Ah, thanks for pointing this out! For `WP_Rewrite::$rewritereplace` it is
 indeed important.

 For example, when you register custom post types, `'(.+)'` gets added to
 `WP_Rewrite::$rewritereplace` multiple times. We only want to remove this
 once from the array, not all occurrences.

 The positions of tags, regexes and query strings inside the arrays need to
 be in sync because we remove them that way.

 Rewrite tags are unique because you can't add one twice (it gets updated
 instead).

 I now switched to using `end()` and `assertContains()` where needed and
 added some more tests.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/35236#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list