WordPress.org

Make WordPress Core

Ticket #16092: 16092.diff

File 16092.diff, 5.2 KB (added by duck_, 2 years ago)
  • wp-includes/rewrite.php

     
    5252 * 
    5353 * @param string $name Name for permalink structure. 
    5454 * @param string $struct Permalink structure. 
    55  * @param bool $with_front Prepend front base to permalink structure. 
     55 * @param array $args Optional configuration for building the rules from the permalink structure, 
     56 *     see {@link WP_Rewrite::add_permastruct()} for full details. 
    5657 */ 
    57 function add_permastruct( $name, $struct, $with_front = true, $ep_mask = EP_NONE ) { 
     58function add_permastruct( $name, $struct, $args = array() ) { 
    5859        global $wp_rewrite; 
    59         return $wp_rewrite->add_permastruct( $name, $struct, $with_front, $ep_mask ); 
     60 
     61        // backwards compatibility for the old parameters: $with_front and $ep_mask 
     62        if ( ! is_array( $args ) ) 
     63                $args = array( 'with_front' => $args ); 
     64        if ( func_num_args() == 4 ) 
     65                $args['ep_mask'] = func_get_arg( 3 ); 
     66 
     67        return $wp_rewrite->add_permastruct( $name, $struct, $args ); 
    6068} 
    6169 
    6270/** 
     
    9931001                        return false; 
    9941002 
    9951003                if ( isset($this->extra_permastructs[$name]) ) 
    996                         return $this->extra_permastructs[$name][0]; 
     1004                        return $this->extra_permastructs[$name]['struct']; 
    9971005 
    9981006                return false; 
    9991007        } 
     
    15181526                $page_rewrite = apply_filters('page_rewrite_rules', $page_rewrite); 
    15191527 
    15201528                // Extra permastructs 
    1521                 foreach ( $this->extra_permastructs as $permastructname => $permastruct ) { 
    1522                         if ( is_array($permastruct) ) 
    1523                                 $rules = $this->generate_rewrite_rules($permastruct[0], $permastruct[1]); 
    1524                         else 
    1525                                 $rules = $this->generate_rewrite_rules($permastruct, EP_NONE); 
     1529                foreach ( $this->extra_permastructs as $permastructname => $struct ) { 
     1530                        if ( is_array( $struct ) ) { 
     1531                                if ( count( $struct ) == 2 ) 
     1532                                        $rules = $this->generate_rewrite_rules( $struct[0], $struct[1] ); 
     1533                                else 
     1534                                        $rules = $this->generate_rewrite_rules( $struct['struct'], $struct['ep_mask'], $struct['paged'], $struct['feed'], $struct['forcomments'], $struct['walk_dirs'], $struct['endpoints'] ); 
     1535                        } else { 
     1536                                $rules = $this->generate_rewrite_rules( $struct ); 
     1537                        } 
    15261538 
    15271539                        $rules = apply_filters($permastructname . '_rewrite_rules', $rules); 
    15281540                        if ( 'post_tag' == $permastructname ) 
     
    18171829        } 
    18181830 
    18191831        /** 
    1820          * Add permalink structure. 
     1832         * Add a new permalink structure. 
    18211833         * 
    1822          * These are added along with the extra rewrite rules that are merged to the 
    1823          * top. 
     1834         * A permalink structure (permastruct) is an abstract definition of a set of rewrite rules; it 
     1835         * is an easy way of expressing a set of regular expressions that rewrite to a set of query strings. 
     1836         * The new permastruct is added to the {@link WP_Rewrite::$extra_permastructs} array. When the 
     1837         * rewrite rules are built by {@link WP_Rewrite::rewrite_rules()} all of these extra permastructs 
     1838         * are passed to {@link WP_Rewrite::generate_rewrite_rules()} which transforms them into the 
     1839         * regular expressions that many love to hate. 
    18241840         * 
     1841         * The $args parameter gives you control over how {@link WP_Rewrite::generate_rewrite_rules()} 
     1842         * works on the new permastruct. 
     1843         * 
    18251844         * @since 2.5.0 
    18261845         * @access public 
    18271846         * 
    18281847         * @param string $name Name for permalink structure. 
    1829          * @param string $struct Permalink structure. 
    1830          * @param bool $with_front Prepend front base to permalink structure. 
     1848         * @param string $struct Permalink structure (e.g. category/%category%) 
     1849         * @param array $args Optional configuration for building the rules from the permalink structure: 
     1850         *     - with_front (bool) - Should the structure be prepended with WP_Rewrite::$front? Default is true. 
     1851         *     - ep_mask (int) - Endpoint mask defining what endpoints are added to the structure. Default is EP_NONE. 
     1852         *     - paged (bool) - Should archive pagination rules be added for the structure? Default is true. 
     1853         *     - feed (bool) - Should feed rewrite rules be added for the structure? Default is true. 
     1854         *     - forcomments (bool) - Should the feed rules be a query for a comments feed? Default is false. 
     1855         *     - walk_dirs (bool) - Should the 'directories' making up the structure be walked over and rewrite 
     1856         *                          rules built for each in turn? Default is true. 
     1857         *     - endpoints (bool) - Should endpoints be applied to the generated rewrite rules? Default is true. 
    18311858         */ 
    1832         function add_permastruct($name, $struct, $with_front = true, $ep_mask = EP_NONE) { 
    1833                 if ( $with_front ) 
     1859        function add_permastruct( $name, $struct, $args = array() ) { 
     1860                // backwards compatibility for the old parameters: $with_front and $ep_mask 
     1861                if ( ! is_array( $args ) ) 
     1862                        $args = array( 'with_front' => $args ); 
     1863                if ( func_num_args() == 4 ) 
     1864                        $args['ep_mask'] = func_get_arg( 3 ); 
     1865 
     1866                $defaults = array( 
     1867                        'with_front' => true, 
     1868                        'ep_mask' => EP_NONE, 
     1869                        'paged' => true, 
     1870                        'feed' => true, 
     1871                        'forcomments' => false, 
     1872                        'walk_dirs' => true, 
     1873                        'endpoints' => true, // really necessary? 
     1874                ); 
     1875                $args = wp_parse_args( $args, $defaults ); 
     1876                $args['struct'] = $struct; 
     1877 
     1878                if ( $args['with_front'] ) 
    18341879                        $struct = $this->front . $struct; 
    18351880                else 
    18361881                        $struct = $this->root . $struct; 
    1837                 $this->extra_permastructs[$name] = array($struct, $ep_mask); 
     1882                $this->extra_permastructs[ $name ] = $args; 
    18381883        } 
    18391884 
    18401885        /**