Changeset 19743
- Timestamp:
- 01/24/2012 06:27:18 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/rewrite.php
r19737 r19743 53 53 * @param string $name Name for permalink structure. 54 54 * @param string $struct Permalink structure. 55 * @param bool $with_front Prepend front base to permalink structure. 56 */ 57 function add_permastruct( $name, $struct, $with_front = true, $ep_mask = EP_NONE ) { 55 * @param array $args Optional configuration for building the rules from the permalink structure, 56 * see {@link WP_Rewrite::add_permastruct()} for full details. 57 */ 58 function add_permastruct( $name, $struct, $args = array() ) { 58 59 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 ); 60 68 } 61 69 … … 994 1002 995 1003 if ( isset($this->extra_permastructs[$name]) ) 996 return $this->extra_permastructs[$name][ 0];1004 return $this->extra_permastructs[$name]['struct']; 997 1005 998 1006 return false; … … 1519 1527 1520 1528 // 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 } 1526 1538 1527 1539 $rules = apply_filters($permastructname . '_rewrite_rules', $rules); … … 1818 1830 1819 1831 /** 1820 * Add permalink structure. 1821 * 1822 * These are added along with the extra rewrite rules that are merged to the 1823 * top. 1832 * Add a new permalink structure. 1833 * 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. 1840 * 1841 * The $args parameter gives you control over how {@link WP_Rewrite::generate_rewrite_rules()} 1842 * works on the new permastruct. 1824 1843 * 1825 1844 * @since 2.5.0 … … 1827 1846 * 1828 1847 * @param string $name Name for permalink structure. 1829 * @param string $struct Permalink structure. 1830 * @param bool $with_front Prepend front base to permalink structure. 1831 */ 1832 function add_permastruct($name, $struct, $with_front = true, $ep_mask = EP_NONE) { 1833 if ( $with_front ) 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. 1858 */ 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, 1874 ); 1875 $args = wp_parse_args( $args, $defaults ); 1876 1877 if ( $args['with_front'] ) 1834 1878 $struct = $this->front . $struct; 1835 1879 else 1836 1880 $struct = $this->root . $struct; 1837 $this->extra_permastructs[$name] = array($struct, $ep_mask); 1881 $args['struct'] = $struct; 1882 1883 $this->extra_permastructs[ $name ] = $args; 1838 1884 } 1839 1885
Note: See TracChangeset
for help on using the changeset viewer.