From c76c9738b751056c01bc46fadb11b195c65985fe Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Fri, 28 Feb 2014 20:54:05 +0000 Subject: [PATCH] Allow rewrite endpoints to specify a query variable name. Fixes #20905. git-svn-id: https://develop.svn.wordpress.org/trunk@27327 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/rewrite.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/rewrite.php b/src/wp-includes/rewrite.php index 2b48cdf83c..fc455b2edf 100644 --- a/src/wp-includes/rewrite.php +++ b/src/wp-includes/rewrite.php @@ -250,10 +250,11 @@ define( 'EP_ALL', EP_PERMALINK | EP_ATTACHMENT | EP_ROOT | EP_COMMENTS | EP_SEAR * * @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. */ -function add_rewrite_endpoint( $name, $places ) { +function add_rewrite_endpoint( $name, $places, $query_var = null ) { global $wp_rewrite; - $wp_rewrite->add_endpoint( $name, $places ); + $wp_rewrite->add_endpoint( $name, $places, $query_var ); } /** @@ -1265,7 +1266,7 @@ class WP_Rewrite { //match everything after the endpoint name, but allow for nothing to appear there $epmatch = $endpoint[1] . '(/(.*))?/?$'; //this will be appended on to the rest of the query for each dir - $epquery = '&' . $endpoint[1] . '='; + $epquery = '&' . $endpoint[2] . '='; $ep_query_append[$epmatch] = array ( $endpoint[0], $epquery ); } } @@ -1822,16 +1823,21 @@ class WP_Rewrite { * * @see add_rewrite_endpoint() * @since 2.1.0 + * @since 3.9.0 $query_var parameter added. * @access public * @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. Defaults to $name. */ - function add_endpoint($name, $places) { + function add_endpoint( $name, $places, $query_var = null ) { global $wp; - $this->endpoints[] = array ( $places, $name ); - $wp->add_query_var($name); + if ( null === $query_var ) { + $query_var = $name; + } + $this->endpoints[] = array( $places, $name, $query_var ); + $wp->add_query_var( $query_var ); } /**