add_rewrite_endpoint

Add an endpoint, like /trackback/.

Description

add_rewrite_endpoint( (string) $name, (int) $places, (bool) $query_var = true ); 

Adding an endpoint creates extra rewrite rules for each of the matching places specified by the provided bitmask. For example:

will add a new rewrite rule ending with json(/(.*))?/?$ for every permastruct that describes a permalink (post) or page. This is rewritten to json=$match where $match is the part of the URL matched by the endpoint regex (e.g. foo in "[permalink]/json/foo/").

A new query var with the same name as the endpoint will also be created.

When specifying $places ensure that you are using the EP_* constants (or a combination of them using the bitwise OR operator) as their values are not guaranteed to remain static (especially EP_ALL).

Be sure to flush the rewrite rules - see flush_rewrite_rules() - when your plugin gets activated and deactivated.

Parameters (3)

0. $name (string)
Name of the endpoint.
1. $places (int)
Endpoint mask describing the places the endpoint should be added.
2. $query_var — Optional. (bool) => true
Name of the corresponding query variable. Pass false to skip registering a query_var for this endpoint. Defaults to the value of $name..

Usage

  1. if ( !function_exists( 'add_rewrite_endpoint' ) ) { 
  2. require_once ABSPATH . WPINC . '/rewrite.php'; 
  3.  
  4. // Name of the endpoint. 
  5. $name = ''; 
  6.  
  7. // Endpoint mask describing the places the endpoint should be added. 
  8. $places = -1; 
  9.  
  10. // Name of the corresponding query variable. Pass `false` to skip registering a query_var 
  11. // for this endpoint. Defaults to the value of `$name`. 
  12. $query_var = true; 
  13.  
  14. // NOTICE! Understand what this does before running. 
  15. $result = add_rewrite_endpoint($name, $places, $query_var); 
  16.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/rewrite.php  
  1. function add_rewrite_endpoint( $name, $places, $query_var = true ) { 
  2. global $wp_rewrite; 
  3. $wp_rewrite->add_endpoint( $name, $places, $query_var );