Last active
February 3, 2017 17:08
-
-
Save dabernathy89/e969e07f03c44f2515540b9fdcde5adc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SimpleEndpoint { | |
public function hooks() { | |
add_action( 'init', array( $this, 'add_endpoint' ) ); | |
add_action( 'template_redirect', array( $this, 'handle_request' ) ); | |
} | |
public function add_endpoint() { | |
add_rewrite_tag( '%foobar%', '([^&]+)' ); | |
add_rewrite_rule( '^(foobar)/?$', 'index.php?$matches[1]=1', 'top' ); | |
} | |
public function handle_request() { | |
if ( get_query_var('foobar') === '1' ) { | |
wp_send_json( 'foo' => 'bar' ); | |
} | |
} | |
} | |
$simple_endpoint = new SimpleEndpoint; | |
$simple_endpoint->hooks(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment