| 1 | <?php
|
|---|
| 2 |
|
|---|
| 3 | class WP_Rewrite_CallbackRule implements WP_Rewrite_RuleInterface {
|
|---|
| 4 | protected $callback;
|
|---|
| 5 | public function __construct( $callback ) {
|
|---|
| 6 | $this->callback = $callback;
|
|---|
| 7 | }
|
|---|
| 8 |
|
|---|
| 9 | public function should_parse_query() {
|
|---|
| 10 | return true;
|
|---|
| 11 | }
|
|---|
| 12 |
|
|---|
| 13 | public function get_query_vars( $matches ) {
|
|---|
| 14 | return call_user_func( $this->callback, $matches );
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | public function get_verbose_page_match() {
|
|---|
| 18 | return false;
|
|---|
| 19 | }
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | add_rewrite_rule( '/foo/', new WP_Rewrite_CallbackRule( function ( $matches ) {
|
|---|
| 23 | return [ 'args' ];
|
|---|
| 24 | }));
|
|---|