Make WordPress Core

Ticket #36292: just-callback.php

File just-callback.php, 575 bytes (added by rmccue, 9 years ago)

Example of a callback on the 'wp' action if a rule matches

Line 
1<?php
2
3class WP_Rewrite_CallMeMaybeRule implements WP_Rewrite_RuleInterface {
4        protected $callback;
5
6        public function __construct( $callback ) {
7                $this->callback = $callback;
8                add_action( 'wp', array( $this, 'maybe_run_callback' ) );
9        }
10
11        public function maybe_run_callback( WP $wp ) {
12                if ( $wp->matched_rule_object === $this ) {
13                        call_user_func( $this->callback, $wp );
14                }
15        }
16
17        public function should_parse_query() {
18                return false;
19        }
20
21        public function get_query_vars( $matches ) {
22                return null;
23        }
24
25        public function get_verbose_page_match() {
26                return false;
27        }
28}