WP_Rewrite::add_endpoint() WordPress Method
The WP_Rewrite::add_endpoint() method allows you to add an endpoint to a WordPress URL. An endpoint is a new URL structure that can be added to a WordPress site. This method takes two parameters: the name of the endpoint and the callback function. The callback function is used to process the request when the endpoint is accessed.
WP_Rewrite::add_endpoint( string $name, int $places, string|bool $query_var = true ) #
Adds an endpoint, like /trackback/.
Description
See also
- add_rewrite_endpoint(): for full documentation.
Parameters
- $name
(string)(Required)Name of the endpoint.
- $places
(int)(Required)Endpoint mask describing the places the endpoint should be added. Accepts a mask of:
EP_ALLEP_NONEEP_ALL_ARCHIVESEP_ATTACHMENTEP_AUTHORSEP_CATEGORIESEP_COMMENTSEP_DATEEP_DAYEP_MONTHEP_PAGESEP_PERMALINKEP_ROOTEP_SEARCHEP_TAGSEP_YEAR
- $query_var
(string|bool)(Optional) Name of the corresponding query variable. Pass
falseto skip registering a query_var for this endpoint. Defaults to the value of$name.Default value: true
Source
File: wp-includes/class-wp-rewrite.php
public function add_endpoint( $name, $places, $query_var = true ) {
global $wp;
// For backward compatibility, if null has explicitly been passed as `$query_var`, assume `true`.
if ( true === $query_var || null === $query_var ) {
$query_var = $name;
}
$this->endpoints[] = array( $places, $name, $query_var );
if ( $query_var ) {
$wp->add_query_var( $query_var );
}
}
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
| Version | Description |
|---|---|
| 4.3.0 | Added support for skipping query var registration by passing false to $query_var. |
| 3.9.0 | $query_var parameter added. |
| 2.1.0 | Introduced. |