Allow rewrite endpoints to be registered without also registering query vars.
Passing `false` to `add_rewrite_endpoint()` will now allow you to take advantage of the rewrite API without thereby modifying the way that WP sets up the main query from the request URI. This new functionality allows developers to work around certain edge-case bugs, such as when a proper endpoint request (such as `/test/1/`) would short- circuit `is_home()` calculation when a static front page is set. Props mordauk, boonebgorges. Fixes #25143. Built from https://develop.svn.wordpress.org/trunk@32293 git-svn-id: http://core.svn.wordpress.org/trunk@32264 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
2699d8d989
commit
317150ccbd
|
@ -243,14 +243,17 @@ define( 'EP_ALL', EP_PERMALINK | EP_ATTACHMENT | EP_ROOT | EP_COMMENTS | EP_SEAR
|
|||
* activated and deactivated.
|
||||
*
|
||||
* @since 2.1.0
|
||||
* @since 4.3.0 Added support for skipping query var registration by passing `false` to `$query_var`.
|
||||
*
|
||||
* @see WP_Rewrite::add_endpoint()
|
||||
* @global object $wp_rewrite
|
||||
*
|
||||
* @param string $name Name of the endpoint.
|
||||
* @param int $places Endpoint mask describing the places the endpoint should be added.
|
||||
* @param string $query_var Name of the corresponding query variable. Defaults to $name.
|
||||
* @param string $name Name of the endpoint.
|
||||
* @param int $places Endpoint mask describing the places the endpoint should be added.
|
||||
* @param string|bool $query_var Name of the corresponding query variable. Pass `false` to skip registering a query_var
|
||||
* for this endpoint. Defaults to the value of `$name`.
|
||||
*/
|
||||
function add_rewrite_endpoint( $name, $places, $query_var = null ) {
|
||||
function add_rewrite_endpoint( $name, $places, $query_var = true ) {
|
||||
global $wp_rewrite;
|
||||
$wp_rewrite->add_endpoint( $name, $places, $query_var );
|
||||
}
|
||||
|
@ -1959,22 +1962,29 @@ class WP_Rewrite {
|
|||
*
|
||||
* @since 2.1.0
|
||||
* @since 3.9.0 $query_var parameter added.
|
||||
* @since 4.3.0 Added support for skipping query var registration by passing `false` to `$query_var`.
|
||||
* @access public
|
||||
*
|
||||
* @see add_rewrite_endpoint() for full documentation.
|
||||
* @uses WP::add_query_var()
|
||||
*
|
||||
* @param string $name Name of the endpoint.
|
||||
* @param int $places Endpoint mask describing the places the endpoint should be added.
|
||||
* @param string $query_var Name of the corresponding query variable. Default is value of $name.
|
||||
* @param string $name Name of the endpoint.
|
||||
* @param int $places Endpoint mask describing the places the endpoint should be added.
|
||||
* @param string|bool $query_var Name of the corresponding query variable. Pass `false` to skip registering
|
||||
* a query_var for this endpoint. Defaults to the value of `$name`.
|
||||
*/
|
||||
public function add_endpoint( $name, $places, $query_var = null ) {
|
||||
public function add_endpoint( $name, $places, $query_var = true ) {
|
||||
global $wp;
|
||||
if ( null === $query_var ) {
|
||||
|
||||
// For backward compatibility, if `null` has explicitly been passed as `$query_var`, assume `true`.
|
||||
if ( true === $query_var || null === func_get_arg( 2 ) ) {
|
||||
$query_var = $name;
|
||||
}
|
||||
$this->endpoints[] = array( $places, $name, $query_var );
|
||||
$wp->add_query_var( $query_var );
|
||||
|
||||
if ( $query_var ) {
|
||||
$wp->add_query_var( $query_var );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.3-alpha-32292';
|
||||
$wp_version = '4.3-alpha-32293';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue