WordPress.org

Make WordPress Core

Ticket #3964: endpoints.txt

File endpoints.txt, 5.5 KB (added by jhodgdon, 7 years ago)

Sample code and printout of the rewrite rules generated

Line 
1// Here is my plugin's init function, where it adds the endpoint:
2
3$langSwitchPermalink = "langswitch_lang";
4
5function langswitch_init () {
6   global $langSwitchPermalink;
7   global $wp_rewrite;
8
9   // this doesn't seem to work in global namespace
10   add_rewrite_endpoint( $langSwitchPermalink,
11                         EP_PERMALINK +
12                         EP_DATE +
13                         EP_YEAR +
14                         EP_MONTH +
15                         EP_DAY +
16                         EP_ROOT +
17                         EP_COMMENTS +
18                         EP_SEARCH +
19                         EP_CATEGORIES +
20                         EP_AUTHORS +
21                         EP_PAGES );
22   $wp_rewrite->flush_rules();
23}
24
25// The actual permalink sections are added with filters, e.g.:
26
27add_filter( 'the_permalink', 'langswitch_add_language_url' );
28add_filter( 'post_link', 'langswitch_add_language_url' );
29
30// Definition of that function (somewhat simplified -- the real version
31// does a lot more checking
32
33$langswitch_lang = "es";
34
35function langswitch_add_language_url( $urlstr )
36{
37  global $langSwitchPermalink, $langswitch_lang;
38
39  return langswitch_trailingslashit( $urlstr ) . $langSwitchPermalink . "/" .
40      $langswitch_lang;
41}
42 
43function langswitch_trailingslashit( $uri ){
44  if( $uri{ strlen($uri) - 1 } != '/' ) {
45    return $uri . '/';
46  } else {
47    return $uri;
48  }
49}
50
51
52/////////////////////////////////
53Here is a printout of the rewrite rules being generated, with the
54permalink set to /%category%/%postname%/ and a couple of pages present in the database.
55
56Current blog URL is  http://poplarware.com/WPTest/
57I also have a hack installed on that page that prints
58out which rule matched whenever you visit a link; the rewrite
59rules are also printed out at the top of every post. Here they
60are currently:
61
62robots.txt$
63wp-atom.php$
64wp-rdf.php$
65wp-rss.php$
66wp-rss2.php$
67wp-feed.php$
68wp-commentsrss2.php$
69(another-page/about)/trackback/?$
70(another-page/about)/feed/(feed|rdf|rss|rss2|atom)/?$
71(another-page/about)/(feed|rdf|rss|rss2|atom)/?$
72(another-page/about)/page/?([0-9]{1,})/?$
73(another-page/about)/langswitch_lang(/(.*))?/?$
74(another-page/about)(/[0-9]+)?/?$
75another-page/about/attachment/([^/]+)/?$
76another-page/about/attachment/([^/]+)/trackback/?$
77another-page/about/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$
78another-page/about/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$
79(another-page)/trackback/?$
80(another-page)/feed/(feed|rdf|rss|rss2|atom)/?$
81(another-page)/(feed|rdf|rss|rss2|atom)/?$
82(another-page)/page/?([0-9]{1,})/?$
83(another-page)/langswitch_lang(/(.*))?/?$
84(another-page)(/[0-9]+)?/?$
85another-page/attachment/([^/]+)/?$
86another-page/attachment/([^/]+)/trackback/?$
87another-page/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$
88another-page/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$
89(test-static-post-page)/trackback/?$
90(test-static-post-page)/feed/(feed|rdf|rss|rss2|atom)/?$
91(test-static-post-page)/(feed|rdf|rss|rss2|atom)/?$
92(test-static-post-page)/page/?([0-9]{1,})/?$
93(test-static-post-page)/langswitch_lang(/(.*))?/?$
94(test-static-post-page)(/[0-9]+)?/?$
95test-static-post-page/attachment/([^/]+)/?$
96test-static-post-page/attachment/([^/]+)/trackback/?$
97test-static-post-page/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$
98test-static-post-page/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$
99feed/(feed|rdf|rss|rss2|atom)/?$
100(feed|rdf|rss|rss2|atom)/?$
101page/?([0-9]{1,})/?$
102comments/feed/(feed|rdf|rss|rss2|atom)/?$
103comments/(feed|rdf|rss|rss2|atom)/?$
104comments/page/?([0-9]{1,})/?$
105search/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$
106search/(.+)/(feed|rdf|rss|rss2|atom)/?$
107search/(.+)/page/?([0-9]{1,})/?$
108search/(.+)/langswitch_lang(/(.*))?/?$
109search/(.+)/?$
110category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$
111category/(.+?)/(feed|rdf|rss|rss2|atom)/?$
112category/(.+?)/page/?([0-9]{1,})/?$
113category/(.+?)/langswitch_lang(/(.*))?/?$
114category/(.+?)/?$
115author/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$
116author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$
117author/([^/]+)/page/?([0-9]{1,})/?$
118author/([^/]+)/langswitch_lang(/(.*))?/?$
119author/([^/]+)/?$
120([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$
121([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$
122([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$
123([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/langswitch_lang(/(.*))?/?$
124([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$
125([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$
126([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$
127([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$
128([0-9]{4})/([0-9]{1,2})/langswitch_lang(/(.*))?/?$
129([0-9]{4})/([0-9]{1,2})/?$
130([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$
131([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$
132([0-9]{4})/page/?([0-9]{1,})/?$
133([0-9]{4})/langswitch_lang(/(.*))?/?$
134([0-9]{4})/?$
135(.+?)/([^/]+)/trackback/?$
136(.+?)/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$
137(.+?)/([^/]+)/(feed|rdf|rss|rss2|atom)/?$
138(.+?)/([^/]+)/page/?([0-9]{1,})/?$
139(.+?)/([^/]+)/langswitch_lang(/(.*))?/?$
140(.+?)/([^/]+)(/[0-9]+)?/?$
141.+?/[^/]+/([^/]+)/?$
142.+?/[^/]+/([^/]+)/trackback/?$
143.+?/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$
144.+?/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$
145.+?/[^/]+/attachment/([^/]+)/?$
146.+?/[^/]+/attachment/([^/]+)/trackback/?$
147.+?/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$
148.+?/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$
149(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$
150(.+?)/(feed|rdf|rss|rss2|atom)/?$
151(.+?)/page/?([0-9]{1,})/?$
152(.+?)/langswitch_lang(/(.*))?/?$
153(.+?)/?$
154
155
156