~ubuntu-branches/debian/jessie/wordpress/jessie

« back to all changes in this revision

Viewing changes to wp-includes/rewrite.php

  • Committer: Package Import Robot
  • Author(s): Craig Small
  • Date: 2014-04-17 20:56:19 UTC
  • mfrom: (1.2.35)
  • Revision ID: package-import@ubuntu.com-20140417205619-nurbet6eho4yvwfv
Tags: 3.9+dfsg-1
* New upstream release
* 3.9 seems to handle different locations for plugins so the
  plugin directory handling patches have been cut back.

Show diffs side-by-side

added added

removed removed

Lines of Context:
250
250
 *
251
251
 * @param string $name Name of the endpoint.
252
252
 * @param int $places Endpoint mask describing the places the endpoint should be added.
 
253
 * @param string $query_var Name of the corresponding query variable. Defaults to $name.
253
254
 */
254
 
function add_rewrite_endpoint( $name, $places ) {
 
255
function add_rewrite_endpoint( $name, $places, $query_var = null ) {
255
256
        global $wp_rewrite;
256
 
        $wp_rewrite->add_endpoint( $name, $places );
 
257
        $wp_rewrite->add_endpoint( $name, $places, $query_var );
257
258
}
258
259
 
259
260
/**
288
289
function url_to_postid($url) {
289
290
        global $wp_rewrite;
290
291
 
291
 
        $url = apply_filters('url_to_postid', $url);
 
292
        /**
 
293
         * Filter the URL to derive the post ID from.
 
294
         *
 
295
         * @since 2.2.0
 
296
         *
 
297
         * @param string $url The URL to derive the post ID from.
 
298
         */
 
299
        $url = apply_filters( 'url_to_postid', $url );
292
300
 
293
301
        // First, check to see if there is a 'p=N' or 'page_id=N' to match against
294
302
        if ( preg_match('#[?&](p|page_id|attachment_id)=(\d+)#', $url, $values) )       {
354
362
                if ( !empty($url) && ($url != $request) && (strpos($match, $url) === 0) )
355
363
                        $request_match = $url . '/' . $request;
356
364
 
357
 
                if ( preg_match("!^$match!", $request_match, $matches) ) {
 
365
                if ( preg_match("#^$match#", $request_match, $matches) ) {
358
366
 
359
367
                        if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) {
360
368
                                // this is a verbose page match, lets check to be sure about it
1265
1273
                                //match everything after the endpoint name, but allow for nothing to appear there
1266
1274
                                $epmatch = $endpoint[1] . '(/(.*))?/?$';
1267
1275
                                //this will be appended on to the rest of the query for each dir
1268
 
                                $epquery = '&' . $endpoint[1] . '=';
 
1276
                                $epquery = '&' . $endpoint[2] . '=';
1269
1277
                                $ep_query_append[$epmatch] = array ( $endpoint[0], $epquery );
1270
1278
                        }
1271
1279
                }
1558
1566
                }
1559
1567
                $registration_pages['.*wp-register.php$'] = $this->index . '?register=true'; // Deprecated
1560
1568
 
1561
 
                // Post
 
1569
                // Post rewrite rules.
1562
1570
                $post_rewrite = $this->generate_rewrite_rules( $this->permalink_structure, EP_PERMALINK );
1563
 
                $post_rewrite = apply_filters('post_rewrite_rules', $post_rewrite);
1564
 
 
1565
 
                // Date
 
1571
 
 
1572
                /**
 
1573
                 * Filter rewrite rules used for "post" archives.
 
1574
                 *
 
1575
                 * @since 1.5.0
 
1576
                 *
 
1577
                 * @param array $post_rewrite The rewrite rules for posts.
 
1578
                 */
 
1579
                $post_rewrite = apply_filters( 'post_rewrite_rules', $post_rewrite );
 
1580
 
 
1581
                // Date rewrite rules.
1566
1582
                $date_rewrite = $this->generate_rewrite_rules($this->get_date_permastruct(), EP_DATE);
1567
 
                $date_rewrite = apply_filters('date_rewrite_rules', $date_rewrite);
1568
 
 
1569
 
                // Root
 
1583
 
 
1584
                /**
 
1585
                 * Filter rewrite rules used for date archives.
 
1586
                 *
 
1587
                 * Likely date archives would include /yyyy/, /yyyy/mm/, and /yyyy/mm/dd/.
 
1588
                 *
 
1589
                 * @since 1.5.0
 
1590
                 *
 
1591
                 * @param array $date_rewrite The rewrite rules for date archives.
 
1592
                 */
 
1593
                $date_rewrite = apply_filters( 'date_rewrite_rules', $date_rewrite );
 
1594
 
 
1595
                // Root-level rewrite rules.
1570
1596
                $root_rewrite = $this->generate_rewrite_rules($this->root . '/', EP_ROOT);
1571
 
                $root_rewrite = apply_filters('root_rewrite_rules', $root_rewrite);
1572
 
 
1573
 
                // Comments
 
1597
 
 
1598
                /**
 
1599
                 * Filter rewrite rules used for root-level archives.
 
1600
                 *
 
1601
                 * Likely root-level archives would include pagination rules for the homepage
 
1602
                 * as well as site-wide post feeds (e.g. /feed/, and /feed/atom/).
 
1603
                 *
 
1604
                 * @since 1.5.0
 
1605
                 *
 
1606
                 * @param array $root_rewrite The root-level rewrite rules.
 
1607
                 */
 
1608
                $root_rewrite = apply_filters( 'root_rewrite_rules', $root_rewrite );
 
1609
 
 
1610
                // Comments rewrite rules.
1574
1611
                $comments_rewrite = $this->generate_rewrite_rules($this->root . $this->comments_base, EP_COMMENTS, false, true, true, false);
1575
 
                $comments_rewrite = apply_filters('comments_rewrite_rules', $comments_rewrite);
1576
 
 
1577
 
                // Search
 
1612
 
 
1613
                /**
 
1614
                 * Filter rewrite rules used for comment feed archives.
 
1615
                 *
 
1616
                 * Likely comments feed archives include /comments/feed/, and /comments/feed/atom/.
 
1617
                 *
 
1618
                 * @since 1.5.0
 
1619
                 *
 
1620
                 * @param array $comments_rewrite The rewrite rules for the site-wide comments feeds.
 
1621
                 */
 
1622
                $comments_rewrite = apply_filters( 'comments_rewrite_rules', $comments_rewrite );
 
1623
 
 
1624
                // Search rewrite rules.
1578
1625
                $search_structure = $this->get_search_permastruct();
1579
1626
                $search_rewrite = $this->generate_rewrite_rules($search_structure, EP_SEARCH);
1580
 
                $search_rewrite = apply_filters('search_rewrite_rules', $search_rewrite);
1581
 
 
1582
 
                // Authors
 
1627
 
 
1628
                /**
 
1629
                 * Filter rewrite rules used for search archives.
 
1630
                 *
 
1631
                 * Likely search-related archives include /search/search+query/ as well as
 
1632
                 * pagination and feed paths for a search.
 
1633
                 *
 
1634
                 * @since 1.5.0
 
1635
                 *
 
1636
                 * @param array $search_rewrite The rewrite rules for search queries.
 
1637
                 */
 
1638
                $search_rewrite = apply_filters( 'search_rewrite_rules', $search_rewrite );
 
1639
 
 
1640
                // Author rewrite rules.
1583
1641
                $author_rewrite = $this->generate_rewrite_rules($this->get_author_permastruct(), EP_AUTHORS);
1584
 
                $author_rewrite = apply_filters('author_rewrite_rules', $author_rewrite);
1585
 
 
1586
 
                // Pages
 
1642
 
 
1643
                /**
 
1644
                 * Filter rewrite rules used for author archives.
 
1645
                 *
 
1646
                 * Likely author archives would include /author/author-name/, as well as
 
1647
                 * pagination and feed paths for author archives.
 
1648
                 *
 
1649
                 * @since 1.5.0
 
1650
                 *
 
1651
                 * @param array $author_rewrite The rewrite rules for author archives.
 
1652
                 */
 
1653
                $author_rewrite = apply_filters( 'author_rewrite_rules', $author_rewrite );
 
1654
 
 
1655
                // Pages rewrite rules.
1587
1656
                $page_rewrite = $this->page_rewrite_rules();
1588
 
                $page_rewrite = apply_filters('page_rewrite_rules', $page_rewrite);
1589
 
 
1590
 
                // Extra permastructs
 
1657
 
 
1658
                /**
 
1659
                 * Filter rewrite rules used for "page" post type archives.
 
1660
                 *
 
1661
                 * @since 1.5.0
 
1662
                 *
 
1663
                 * @param array $page_rewrite The rewrite rules for the "page" post type.
 
1664
                 */
 
1665
                $page_rewrite = apply_filters( 'page_rewrite_rules', $page_rewrite );
 
1666
 
 
1667
                // Extra permastructs.
1591
1668
                foreach ( $this->extra_permastructs as $permastructname => $struct ) {
1592
1669
                        if ( is_array( $struct ) ) {
1593
1670
                                if ( count( $struct ) == 2 )
1598
1675
                                $rules = $this->generate_rewrite_rules( $struct );
1599
1676
                        }
1600
1677
 
1601
 
                        $rules = apply_filters($permastructname . '_rewrite_rules', $rules);
1602
 
                        if ( 'post_tag' == $permastructname )
1603
 
                                $rules = apply_filters('tag_rewrite_rules', $rules);
 
1678
                        /**
 
1679
                         * Filter rewrite rules used for individual permastructs.
 
1680
                         *
 
1681
                         * The dynamic portion of the hook name, $permastructname, refers
 
1682
                         * to the name of the registered permastruct, e.g. 'post_tag' (tags),
 
1683
                         * 'category' (categories), etc.
 
1684
                         *
 
1685
                         * @since 3.1.0
 
1686
                         *
 
1687
                         * @param array $rules The rewrite rules generated for the current permastruct.
 
1688
                         */
 
1689
                        $rules = apply_filters( $permastructname . '_rewrite_rules', $rules );
 
1690
                        if ( 'post_tag' == $permastructname ) {
 
1691
 
 
1692
                                /**
 
1693
                                 * Filter rewrite rules used specifically for Tags.
 
1694
                                 *
 
1695
                                 * @since 2.3.0
 
1696
                                 * @deprecated 3.1.0 Use 'post_tag_rewrite_rules' instead
 
1697
                                 *
 
1698
                                 * @param array $rules The rewrite rules generated for tags.
 
1699
                                 */
 
1700
                                $rules = apply_filters( 'tag_rewrite_rules', $rules );
 
1701
                        }
1604
1702
 
1605
1703
                        $this->extra_rules_top = array_merge($this->extra_rules_top, $rules);
1606
1704
                }
1611
1709
                else
1612
1710
                        $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite,  $author_rewrite, $date_rewrite, $post_rewrite, $page_rewrite, $this->extra_rules);
1613
1711
 
1614
 
                do_action_ref_array('generate_rewrite_rules', array(&$this));
1615
 
                $this->rules = apply_filters('rewrite_rules_array', $this->rules);
 
1712
                /**
 
1713
                 * Fires after the rewrite rules are generated.
 
1714
                 *
 
1715
                 * @since 1.5.0
 
1716
                 *
 
1717
                 * @param WP_Rewrite $this Current WP_Rewrite instance, passed by reference.
 
1718
                 */
 
1719
                do_action_ref_array( 'generate_rewrite_rules', array( &$this ) );
 
1720
 
 
1721
                /**
 
1722
                 * Filter the full set of generated rewrite rules.
 
1723
                 *
 
1724
                 * @since 1.5.0
 
1725
                 *
 
1726
                 * @param array $this->rules The compiled array of rewrite rules.
 
1727
                 */
 
1728
                $this->rules = apply_filters( 'rewrite_rules_array', $this->rules );
1616
1729
 
1617
1730
                return $this->rules;
1618
1731
        }
1720
1833
 
1721
1834
                $rules .= "</IfModule>\n";
1722
1835
 
1723
 
                $rules = apply_filters('mod_rewrite_rules', $rules);
1724
 
                $rules = apply_filters('rewrite_rules', $rules);  // Deprecated
 
1836
                /**
 
1837
                 *
 
1838
                 * Filter the list of rewrite rules formatted for output to an .htaccess file.
 
1839
                 *
 
1840
                 * @since 1.5.0
 
1841
                 *
 
1842
                 * @param string $rules mod_rewrite Rewrite rules formatted for .htaccess.
 
1843
                 */
 
1844
                $rules = apply_filters( 'mod_rewrite_rules', $rules );
 
1845
 
 
1846
                /**
 
1847
                 * Filter the list of rewrite rules formatted for output to an .htaccess file.
 
1848
                 *
 
1849
                 * @since 1.5.0
 
1850
                 * @deprecated 1.5.0 Use the mod_rewrite_rules filter instead.
 
1851
                 *
 
1852
                 * @param string $rules mod_rewrite Rewrite rules formatted for .htaccess.
 
1853
                 */
 
1854
                $rules = apply_filters( 'rewrite_rules', $rules );  // Deprecated
1725
1855
 
1726
1856
                return $rules;
1727
1857
        }
1767
1897
</configuration>';
1768
1898
                }
1769
1899
 
1770
 
                $rules = apply_filters('iis7_url_rewrite_rules', $rules);
 
1900
                /**
 
1901
                 * Filter the list of rewrite rules formatted for output to a web.config.
 
1902
                 *
 
1903
                 * @since 2.8.0
 
1904
                 *
 
1905
                 * @param string $rules Rewrite rules formatted for IIS web.config.
 
1906
                 */
 
1907
                $rules = apply_filters( 'iis7_url_rewrite_rules', $rules );
1771
1908
 
1772
1909
                return $rules;
1773
1910
        }
1818
1955
        /**
1819
1956
         * Add an endpoint, like /trackback/.
1820
1957
         *
1821
 
         * See {@link add_rewrite_endpoint()} for full documentation.
1822
 
         *
1823
 
         * @see add_rewrite_endpoint()
1824
1958
         * @since 2.1.0
 
1959
         * @since 3.9.0 $query_var parameter added.
1825
1960
         * @access public
 
1961
         *
 
1962
         * @see add_rewrite_endpoint() for full documentation.
1826
1963
         * @uses WP::add_query_var()
1827
1964
         *
1828
 
         * @param string $name Name of the endpoint.
1829
 
         * @param int $places Endpoint mask describing the places the endpoint should be added.
 
1965
         * @param string $name      Name of the endpoint.
 
1966
         * @param int    $places    Endpoint mask describing the places the endpoint should be added.
 
1967
         * @param string $query_var Name of the corresponding query variable. Default is value of $name.
1830
1968
         */
1831
 
        function add_endpoint($name, $places) {
 
1969
        function add_endpoint( $name, $places, $query_var = null ) {
1832
1970
                global $wp;
1833
 
                $this->endpoints[] = array ( $places, $name );
1834
 
                $wp->add_query_var($name);
 
1971
                if ( null === $query_var ) {
 
1972
                        $query_var = $name;
 
1973
                }
 
1974
                $this->endpoints[] = array( $places, $name, $query_var );
 
1975
                $wp->add_query_var( $query_var );
1835
1976
        }
1836
1977
 
1837
1978
        /**
1910
2051
                 * A "hard" flush updates .htaccess (Apache) or web.config (IIS).
1911
2052
                 *
1912
2053
                 * @since 3.7.0
1913
 
                 * @param bool $hard Defaults to true.
 
2054
                 *
 
2055
                 * @param bool $hard Whether to flush rewrite rules "hard". Default true.
1914
2056
                 */
1915
 
                if ( ! $hard || ! apply_filters( 'flush_rewrite_rules_hard', true ) )
 
2057
                if ( ! $hard || ! apply_filters( 'flush_rewrite_rules_hard', true ) ) {
1916
2058
                        return;
 
2059
                }
1917
2060
                if ( function_exists( 'save_mod_rewrite_rules' ) )
1918
2061
                        save_mod_rewrite_rules();
1919
2062
                if ( function_exists( 'iis7_save_url_rewrite_rules' ) )
1972
2115
                        $old_permalink_structure = $this->permalink_structure;
1973
2116
                        update_option('permalink_structure', $permalink_structure);
1974
2117
                        $this->init();
1975
 
                        do_action('permalink_structure_changed', $old_permalink_structure, $permalink_structure);
 
2118
 
 
2119
                        /**
 
2120
                         * Fires after the permalink structure is updated.
 
2121
                         *
 
2122
                         * @since 2.8.0
 
2123
                         *
 
2124
                         * @param string $old_permalink_structure The previous permalink structure.
 
2125
                         * @param string $permalink_structure     The new permalink structure.
 
2126
                         */
 
2127
                        do_action( 'permalink_structure_changed', $old_permalink_structure, $permalink_structure );
1976
2128
                }
1977
2129
        }
1978
2130