PluginProbe
Bogo / 2.9
Bogo v2.9
3.9.3 trunk 1.0 1.1 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5 2.6 2.6.1 2.7 2.8 2.8.1 2.9 3.0 3.0.1 All 52 releases
← All changes | includes/link-template.php +29 -70 trunk2.9 View file →
@@ -2,14 +2,13 @@
2 2
3 3 add_filter( 'post_link', 'bogo_post_link', 10, 3 );
4 4
5 5 function bogo_post_link( $permalink, $post, $leavename ) {
6 - if ( ! bogo_is_localizable_post_type( $post->post_type ) ) {
6 + if ( ! bogo_is_localizable_post_type( $post->post_type ) )
7 7 return $permalink;
8 - }
9 8
10 9 $locale = bogo_get_post_locale( $post->ID );
11 - $sample = ( isset( $post->filter ) && 'sample' === $post->filter );
10 + $sample = ( isset( $post->filter ) && 'sample' == $post->filter );
12 11 $permalink_structure = get_option( 'permalink_structure' );
13 12
14 13 $using_permalinks = $permalink_structure &&
15 14 ( $sample || ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ) );
@@ -14,35 +13,33 @@
14 13 $using_permalinks = $permalink_structure &&
15 14 ( $sample || ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ) );
16 15
17 16 $permalink = bogo_get_url_with_lang( $permalink, $locale,
18 - array( 'using_permalinks' => $using_permalinks )
19 - );
17 + array( 'using_permalinks' => $using_permalinks ) );
20 18
21 19 return $permalink;
22 20 }
23 21
24 -
25 22 add_filter( 'page_link', 'bogo_page_link', 10, 3 );
26 23
27 -function bogo_page_link( $permalink, $post_id, $sample ) {
24 +function bogo_page_link( $permalink, $id, $sample ) {
28 25 if ( ! bogo_is_localizable_post_type( 'page' ) ) {
29 26 return $permalink;
30 27 }
31 28
32 - $locale = bogo_get_post_locale( $post_id );
33 - $post = get_post( $post_id );
29 + $locale = bogo_get_post_locale( $id );
30 + $post = get_post( $id );
34 31
35 - if ( 'page' === get_option( 'show_on_front' ) ) {
32 + if ( 'page' == get_option( 'show_on_front' ) ) {
36 33 $front_page_id = get_option( 'page_on_front' );
37 34
38 - if ( $post_id == $front_page_id ) {
35 + if ( $id == $front_page_id ) {
39 36 return $permalink;
40 37 }
41 38
42 39 $translation = bogo_get_post_translation( $front_page_id, $locale );
43 40
44 - if ( $translation and $translation->ID === $post_id ) {
41 + if ( $translation && $translation->ID == $id ) {
45 42 $home = set_url_scheme( get_option( 'home' ) );
46 43 $home = trailingslashit( $home );
47 44 return bogo_url( $home, $locale );
48 45 }
@@ -53,21 +50,18 @@
53 50 $using_permalinks = $permalink_structure &&
54 51 ( $sample || ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ) );
55 52
56 53 $permalink = bogo_get_url_with_lang( $permalink, $locale,
57 - array( 'using_permalinks' => $using_permalinks )
58 - );
54 + array( 'using_permalinks' => $using_permalinks ) );
59 55
60 56 return $permalink;
61 57 }
62 58
63 -
64 59 add_filter( 'post_type_link', 'bogo_post_type_link', 10, 4 );
65 60
66 61 function bogo_post_type_link( $permalink, $post, $leavename, $sample ) {
67 - if ( ! bogo_is_localizable_post_type( $post->post_type ) ) {
62 + if ( ! bogo_is_localizable_post_type( $post->post_type ) )
68 63 return $permalink;
69 - }
70 64
71 65 $locale = bogo_get_post_locale( $post->ID );
72 66 $permalink_structure = get_option( 'permalink_structure' );
73 67
@@ -74,15 +68,13 @@
74 68 $using_permalinks = $permalink_structure &&
75 69 ( $sample || ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ) );
76 70
77 71 $permalink = bogo_get_url_with_lang( $permalink, $locale,
78 - array( 'using_permalinks' => $using_permalinks )
79 - );
72 + array( 'using_permalinks' => $using_permalinks ) );
80 73
81 74 return $permalink;
82 75 }
83 76
84 -
85 77 add_filter( 'year_link', 'bogo_year_link', 10, 2 );
86 78
87 79 function bogo_year_link( $link, $year ) {
88 80 return bogo_url( $link );
@@ -87,9 +79,8 @@
87 79 function bogo_year_link( $link, $year ) {
88 80 return bogo_url( $link );
89 81 }
90 82
91 -
92 83 add_filter( 'month_link', 'bogo_month_link', 10, 3 );
93 84
94 85 function bogo_month_link( $link, $year, $month ) {
95 86 return bogo_url( $link );
@@ -94,9 +85,8 @@
94 85 function bogo_month_link( $link, $year, $month ) {
95 86 return bogo_url( $link );
96 87 }
97 88
98 -
99 89 add_filter( 'day_link', 'bogo_day_link', 10, 4 );
100 90
101 91 function bogo_day_link( $link, $year, $month, $day ) {
102 92 return bogo_url( $link );
@@ -101,9 +91,8 @@
101 91 function bogo_day_link( $link, $year, $month, $day ) {
102 92 return bogo_url( $link );
103 93 }
104 94
105 -
106 95 add_filter( 'feed_link', 'bogo_feed_link', 10, 2 );
107 96
108 97 function bogo_feed_link( $link, $feed ) {
109 98 return bogo_url( $link );
@@ -108,9 +97,8 @@
108 97 function bogo_feed_link( $link, $feed ) {
109 98 return bogo_url( $link );
110 99 }
111 100
112 -
113 101 add_filter( 'author_feed_link', 'bogo_author_feed_link', 10, 2 );
114 102
115 103 function bogo_author_feed_link( $link, $feed ) {
116 104 return bogo_url( $link );
@@ -115,9 +103,8 @@
115 103 function bogo_author_feed_link( $link, $feed ) {
116 104 return bogo_url( $link );
117 105 }
118 106
119 -
120 107 add_filter( 'category_feed_link', 'bogo_category_feed_link', 10, 2 );
121 108
122 109 function bogo_category_feed_link( $link, $feed ) {
123 110 return bogo_url( $link );
@@ -122,9 +109,8 @@
122 109 function bogo_category_feed_link( $link, $feed ) {
123 110 return bogo_url( $link );
124 111 }
125 112
126 -
127 113 add_filter( 'taxonomy_feed_link', 'bogo_taxonomy_feed_link', 10, 3 );
128 114
129 115 function bogo_taxonomy_feed_link( $link, $feed, $taxonomy ) {
130 116 return bogo_url( $link );
@@ -129,9 +115,8 @@
129 115 function bogo_taxonomy_feed_link( $link, $feed, $taxonomy ) {
130 116 return bogo_url( $link );
131 117 }
132 118
133 -
134 119 add_filter( 'post_type_archive_link', 'bogo_post_type_archive_link', 10, 2 );
135 120
136 121 function bogo_post_type_archive_link( $link, $post_type ) {
137 122 return bogo_url( $link );
@@ -136,19 +121,14 @@
136 121 function bogo_post_type_archive_link( $link, $post_type ) {
137 122 return bogo_url( $link );
138 123 }
139 124
125 +add_filter( 'post_type_archive_feed_link', 'bogo_post_type_archive_feed_link', 10, 2 );
140 126
141 -add_filter( 'post_type_archive_feed_link',
142 - 'bogo_post_type_archive_feed_link',
143 - 10, 2
144 -);
145 -
146 127 function bogo_post_type_archive_feed_link( $link, $feed ) {
147 128 return bogo_url( $link );
148 129 }
149 130
150 -
151 131 add_filter( 'term_link', 'bogo_term_link', 10, 3 );
152 132
153 133 function bogo_term_link( $link, $term, $taxonomy ) {
154 134 return bogo_url( $link );
@@ -153,22 +133,19 @@
153 133 function bogo_term_link( $link, $term, $taxonomy ) {
154 134 return bogo_url( $link );
155 135 }
156 136
137 +add_filter( 'home_url', 'bogo_home_url' );
157 138
158 -add_filter( 'home_url', 'bogo_home_url', 10, 1 );
159 -
160 139 function bogo_home_url( $url ) {
161 - if ( is_admin() or ! did_action( 'template_redirect' ) ) {
140 + if ( is_admin() || ! did_action( 'template_redirect' ) )
162 141 return $url;
163 - }
164 142
165 143 return bogo_url( $url );
166 144 }
167 145
146 +add_action( 'wp_head', 'bogo_m17n_headers' );
168 147
169 -add_action( 'wp_head', 'bogo_m17n_headers', 10, 0 );
170 -
171 148 function bogo_m17n_headers() {
172 149 $languages = array();
173 150
174 151 if ( is_singular() ) {
@@ -173,9 +150,9 @@
173 150
174 151 if ( is_singular() ) {
175 152 $post_id = get_queried_object_id();
176 153
177 - if ( $post_id and $translations = bogo_get_post_translations( $post_id ) ) {
154 + if ( $post_id && $translations = bogo_get_post_translations( $post_id ) ) {
178 155 $locale = get_locale();
179 156 $translations[$locale] = get_post( $post_id );
180 157
181 158 foreach ( $translations as $lang => $translation ) {
@@ -180,20 +157,19 @@
180 157
181 158 foreach ( $translations as $lang => $translation ) {
182 159 $languages[] = array(
183 160 'hreflang' => bogo_language_tag( $lang ),
184 - 'href' => get_permalink( $translation ),
185 - );
161 + 'href' => get_permalink( $translation ) );
186 162 }
187 163 }
188 164 } else {
189 - $available_locales = bogo_available_locales();
165 + $available_locales = bogo_available_locales( array(
166 + 'exclude_enus_if_inactive' => true ) );
190 167
191 168 foreach ( $available_locales as $locale ) {
192 169 $languages[] = array(
193 170 'hreflang' => bogo_language_tag( $locale ),
194 - 'href' => bogo_url( null, $locale ),
195 - );
171 + 'href' => bogo_url( null, $locale ) );
196 172 }
197 173 }
198 174
199 175 $languages = apply_filters( 'bogo_rel_alternate_hreflang', $languages );
@@ -198,36 +174,20 @@
198 174
199 175 $languages = apply_filters( 'bogo_rel_alternate_hreflang', $languages );
200 176
201 177 foreach ( (array) $languages as $language ) {
202 - $hreflang = $language['hreflang'] ?? '';
203 - $href = $language['href'] ?? '';
178 + $hreflang = isset( $language['hreflang'] ) ? $language['hreflang'] : '';
179 + $href = isset( $language['href'] ) ? $language['href'] : '';
204 180
205 - if ( $hreflang and $href ) {
206 - $link = sprintf(
207 - '<link %s />',
208 - bogo_format_atts( array(
209 - 'rel' => 'alternate',
210 - 'href' => esc_url( $href ),
211 - 'hreflang' => $hreflang,
212 - ) )
213 - );
181 + if ( $hreflang && $href ) {
182 + $link = sprintf( '<link rel="alternate" hreflang="%1$s" href="%2$s" />',
183 + esc_attr( $hreflang ), esc_url( $href ) );
214 184
215 - echo wp_kses(
216 - $link,
217 - array(
218 - 'link' => array(
219 - 'rel' => true,
220 - 'href' => true,
221 - 'hreflang' => true,
222 - ),
223 - )
224 - ) . "\n";
185 + echo $link . "\n";
225 186 }
226 187 }
227 188 }
228 189
229 -
230 190 add_filter( 'get_previous_post_join', 'bogo_adjacent_post_join', 10, 3 );
231 191 add_filter( 'get_next_post_join', 'bogo_adjacent_post_join', 10, 3 );
232 192
233 193 function bogo_adjacent_post_join( $join, $in_same_term, $excluded_terms ) {
@@ -234,9 +194,9 @@
234 194 global $wpdb;
235 195
236 196 $post = get_post();
237 197
238 - if ( $post and bogo_is_localizable_post_type( get_post_type( $post ) ) ) {
198 + if ( $post && bogo_is_localizable_post_type( get_post_type( $post ) ) ) {
239 199 $join .= " LEFT JOIN $wpdb->postmeta AS postmeta_bogo ON (p.ID = postmeta_bogo.post_id AND postmeta_bogo.meta_key = '_locale')";
240 200 }
241 201
242 202 return $join;
@@ -241,9 +201,8 @@
241 201
242 202 return $join;
243 203 }
244 204
245 -
246 205 add_filter( 'get_previous_post_where', 'bogo_adjacent_post_where', 10, 3 );
247 206 add_filter( 'get_next_post_where', 'bogo_adjacent_post_where', 10, 3 );
248 207
249 208 function bogo_adjacent_post_where( $where, $in_same_term, $excluded_terms ) {
@@ -250,9 +209,9 @@
250 209 global $wpdb;
251 210
252 211 $post = get_post();
253 212
254 - if ( $post and bogo_is_localizable_post_type( get_post_type( $post ) ) ) {
213 + if ( $post && bogo_is_localizable_post_type( get_post_type( $post ) ) ) {
255 214 $locale = bogo_get_post_locale( $post->ID );
256 215
257 216 $where .= " AND (1=0";
258 217 $where .= $wpdb->prepare( " OR postmeta_bogo.meta_value LIKE %s", $locale );