WordPress.org

Make WordPress Core

Ticket #15178: 15178.patch

File 15178.patch, 3.8 KB (added by johnbillion, 20 months ago)
  • wp-includes/rewrite.php

     
    200200define('EP_ALL', 8191); 
    201201 
    202202/** 
    203  * Add an endpoint, like /trackback/. 
     203 * Add an endpoint, like /foo/bar/ 
    204204 * 
    205  * The endpoints are added to the end of the request. So a request matching 
    206  * "/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). 
    207207 * 
     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 * 
    208214 * Be sure to flush the rewrite rules (wp_rewrite->flush_rules()) when your plugin gets 
    209215 * activated (register_activation_hook()) and deactivated (register_deactivation_hook()) 
    210216 * 
     
    212218 * @see WP_Rewrite::add_endpoint() Parameters and more description. 
    213219 * @uses $wp_rewrite 
    214220 * 
    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 
    217224 */ 
    218 function add_rewrite_endpoint($name, $places) { 
     225function add_rewrite_endpoint($name, $places, $allow_empty = false) { 
    219226        global $wp_rewrite; 
    220         $wp_rewrite->add_endpoint($name, $places); 
     227        $wp_rewrite->add_endpoint($name, $places, $allow_empty); 
    221228} 
    222229 
    223230/** 
     
    12041211                if ( $endpoints ) { 
    12051212                        $ep_query_append = array (); 
    12061213                        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 
    12071223                                //match everything after the endpoint name, but allow for nothing to appear there 
    12081224                                $epmatch = $endpoint[1] . '(/(.*))?/?$'; 
    12091225                                //this will be appended on to the rest of the query for each dir 
    12101226                                $epquery = '&' . $endpoint[1] . '='; 
    12111227                                $ep_query_append[$epmatch] = array ( $endpoint[0], $epquery ); 
     1228 
    12121229                        } 
    12131230                } 
    12141231 
     
    13261343                        if ( $endpoints ) { 
    13271344                                foreach ( (array) $ep_query_append as $regex => $ep) { 
    13281345                                        //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                                        } 
    13311352                                } 
    13321353                        } 
    13331354 
     
    18151836         * @since 2.1.0 
    18161837         * @access public 
    18171838         * 
    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 
    18201842         */ 
    1821         function add_endpoint($name, $places) { 
     1843        function add_endpoint($name, $places, $allow_empty = false) { 
    18221844                global $wp; 
    1823                 $this->endpoints[] = array ( $places, $name ); 
     1845                $this->endpoints[] = array ( $places, $name, $allow_empty ); 
    18241846                $wp->add_query_var($name); 
    18251847        } 
    18261848