Ticket #15178: 15178.patch
| File 15178.patch, 3.8 KB (added by johnbillion, 20 months ago) |
|---|
-
wp-includes/rewrite.php
200 200 define('EP_ALL', 8191); 201 201 202 202 /** 203 * Add an endpoint, like / trackback/.203 * Add an endpoint, like /foo/bar/ 204 204 * 205 * The endpoint s are added to the end of the request. So a request matching206 * "/2008/10/14/my_post/myep/", the endpoint will be "/myep/".205 * The endpoint query variable ('foo' in this example) gets set to the value trailing the 206 * endpoint ('bar' in this example). 207 207 * 208 * If the $allow_empty parameter is true then the endpoint query variable will be set to 209 * string 'true' when accessing the endpoint without a trailing value (eg. /foo/). 210 * 211 * The endpoints are added to the end of the request. So for a request matching 212 * "/2008/10/14/my_post/foo/", the endpoint will be "/foo/". 213 * 208 214 * Be sure to flush the rewrite rules (wp_rewrite->flush_rules()) when your plugin gets 209 215 * activated (register_activation_hook()) and deactivated (register_deactivation_hook()) 210 216 * … … 212 218 * @see WP_Rewrite::add_endpoint() Parameters and more description. 213 219 * @uses $wp_rewrite 214 220 * 215 * @param unknown_type $name 216 * @param unknown_type $places 221 * @param string $name The endpoint name (which is also the query variable) 222 * @param int|array $places An endpoint mask or array of endpoint masks 223 * @param bool $allow_empty Whether to allow an endpoint with no trailing value 217 224 */ 218 function add_rewrite_endpoint($name, $places ) {225 function add_rewrite_endpoint($name, $places, $allow_empty = false) { 219 226 global $wp_rewrite; 220 $wp_rewrite->add_endpoint($name, $places );227 $wp_rewrite->add_endpoint($name, $places, $allow_empty); 221 228 } 222 229 223 230 /** … … 1204 1211 if ( $endpoints ) { 1205 1212 $ep_query_append = array (); 1206 1213 foreach ( (array) $this->endpoints as $endpoint) { 1214 1215 if ( isset( $endpoint[2] ) and $endpoint[2] ) { 1216 //allow endpoints with no trailing value 1217 $epmatch = $endpoint[1] . '/?$'; 1218 //this will be appended on to the rest of the query for each dir 1219 $epquery = '&' . $endpoint[1] . '=true'; 1220 $ep_query_append[$epmatch] = array ( $endpoint[0], $epquery, true ); 1221 } 1222 1207 1223 //match everything after the endpoint name, but allow for nothing to appear there 1208 1224 $epmatch = $endpoint[1] . '(/(.*))?/?$'; 1209 1225 //this will be appended on to the rest of the query for each dir 1210 1226 $epquery = '&' . $endpoint[1] . '='; 1211 1227 $ep_query_append[$epmatch] = array ( $endpoint[0], $epquery ); 1228 1212 1229 } 1213 1230 } 1214 1231 … … 1326 1343 if ( $endpoints ) { 1327 1344 foreach ( (array) $ep_query_append as $regex => $ep) { 1328 1345 //add the endpoints on if the mask fits 1329 if ( $ep[0] & $ep_mask || $ep[0] & $ep_mask_specific ) 1330 $rewrite[$match . $regex] = $index . '?' . $query . $ep[1] . $this->preg_index($num_toks + 2); 1346 if ( $ep[0] & $ep_mask || $ep[0] & $ep_mask_specific ) { 1347 if ( isset( $ep[2] ) and $ep[2] ) 1348 $rewrite[$match . $regex] = $index . '?' . $query . $ep[1]; 1349 else 1350 $rewrite[$match . $regex] = $index . '?' . $query . $ep[1] . $this->preg_index($num_toks + 2); 1351 } 1331 1352 } 1332 1353 } 1333 1354 … … 1815 1836 * @since 2.1.0 1816 1837 * @access public 1817 1838 * 1818 * @param string $name Name of endpoint. 1819 * @param array $places URL types that endpoint can be used. 1839 * @param string $name The endpoint name (which is also the query variable) 1840 * @param int|array $places An endpoint mask or array of endpoint masks 1841 * @param bool $allow_empty Whether to allow an endpoint with no trailing value 1820 1842 */ 1821 function add_endpoint($name, $places ) {1843 function add_endpoint($name, $places, $allow_empty = false) { 1822 1844 global $wp; 1823 $this->endpoints[] = array ( $places, $name );1845 $this->endpoints[] = array ( $places, $name, $allow_empty ); 1824 1846 $wp->add_query_var($name); 1825 1847 } 1826 1848