author | Anthony Ly <anthonyly.com@gmail.com> |
Mon, 19 Nov 2012 18:26:13 +0100 | |
changeset 194 | 32102edaa81b |
parent 136 | bde1974c263b |
child 204 | 09a1c134465b |
permissions | -rw-r--r-- |
136 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress Link Template Functions |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Template |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
10 |
* Display the permalink for the current post. |
|
11 |
* |
|
12 |
* @since 1.2.0 |
|
13 |
* @uses apply_filters() Calls 'the_permalink' filter on the permalink string. |
|
14 |
*/ |
|
15 |
function the_permalink() { |
|
16 |
echo apply_filters('the_permalink', get_permalink()); |
|
17 |
} |
|
18 |
||
19 |
/** |
|
20 |
* Retrieve trailing slash string, if blog set for adding trailing slashes. |
|
21 |
* |
|
22 |
* Conditionally adds a trailing slash if the permalink structure has a trailing |
|
23 |
* slash, strips the trailing slash if not. The string is passed through the |
|
24 |
* 'user_trailingslashit' filter. Will remove trailing slash from string, if |
|
25 |
* blog is not set to have them. |
|
26 |
* |
|
27 |
* @since 2.2.0 |
|
28 |
* @uses $wp_rewrite |
|
29 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
30 |
* @param string $string URL with or without a trailing slash. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
31 |
* @param string $type_of_url The type of URL being considered (e.g. single, category, etc) for use in the filter. |
136 | 32 |
* @return string |
33 |
*/ |
|
34 |
function user_trailingslashit($string, $type_of_url = '') { |
|
35 |
global $wp_rewrite; |
|
36 |
if ( $wp_rewrite->use_trailing_slashes ) |
|
37 |
$string = trailingslashit($string); |
|
38 |
else |
|
39 |
$string = untrailingslashit($string); |
|
40 |
||
41 |
// Note that $type_of_url can be one of following: |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
42 |
// single, single_trackback, single_feed, single_paged, feed, category, page, year, month, day, paged, post_type_archive |
136 | 43 |
$string = apply_filters('user_trailingslashit', $string, $type_of_url); |
44 |
return $string; |
|
45 |
} |
|
46 |
||
47 |
/** |
|
48 |
* Display permalink anchor for current post. |
|
49 |
* |
|
50 |
* The permalink mode title will use the post title for the 'a' element 'id' |
|
51 |
* attribute. The id mode uses 'post-' with the post ID for the 'id' attribute. |
|
52 |
* |
|
53 |
* @since 0.71 |
|
54 |
* |
|
55 |
* @param string $mode Permalink mode can be either 'title', 'id', or default, which is 'id'. |
|
56 |
*/ |
|
57 |
function permalink_anchor($mode = 'id') { |
|
58 |
global $post; |
|
59 |
switch ( strtolower($mode) ) { |
|
60 |
case 'title': |
|
61 |
$title = sanitize_title($post->post_title) . '-' . $post->ID; |
|
62 |
echo '<a id="'.$title.'"></a>'; |
|
63 |
break; |
|
64 |
case 'id': |
|
65 |
default: |
|
66 |
echo '<a id="post-' . $post->ID . '"></a>'; |
|
67 |
break; |
|
68 |
} |
|
69 |
} |
|
70 |
||
71 |
/** |
|
72 |
* Retrieve full permalink for current post or post ID. |
|
73 |
* |
|
74 |
* @since 1.0.0 |
|
75 |
* |
|
76 |
* @param int $id Optional. Post ID. |
|
77 |
* @param bool $leavename Optional, defaults to false. Whether to keep post name or page name. |
|
78 |
* @return string |
|
79 |
*/ |
|
80 |
function get_permalink($id = 0, $leavename = false) { |
|
81 |
$rewritecode = array( |
|
82 |
'%year%', |
|
83 |
'%monthnum%', |
|
84 |
'%day%', |
|
85 |
'%hour%', |
|
86 |
'%minute%', |
|
87 |
'%second%', |
|
88 |
$leavename? '' : '%postname%', |
|
89 |
'%post_id%', |
|
90 |
'%category%', |
|
91 |
'%author%', |
|
92 |
$leavename? '' : '%pagename%', |
|
93 |
); |
|
94 |
||
95 |
if ( is_object($id) && isset($id->filter) && 'sample' == $id->filter ) { |
|
96 |
$post = $id; |
|
97 |
$sample = true; |
|
98 |
} else { |
|
99 |
$post = &get_post($id); |
|
100 |
$sample = false; |
|
101 |
} |
|
102 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
103 |
if ( empty($post->ID) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
104 |
return false; |
136 | 105 |
|
106 |
if ( $post->post_type == 'page' ) |
|
107 |
return get_page_link($post->ID, $leavename, $sample); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
108 |
elseif ( $post->post_type == 'attachment' ) |
136 | 109 |
return get_attachment_link($post->ID); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
110 |
elseif ( in_array($post->post_type, get_post_types( array('_builtin' => false) ) ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
111 |
return get_post_permalink($post->ID, $leavename, $sample); |
136 | 112 |
|
113 |
$permalink = get_option('permalink_structure'); |
|
114 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
115 |
$permalink = apply_filters('pre_post_link', $permalink, $post, $leavename); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
116 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
117 |
if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending', 'auto-draft')) ) { |
136 | 118 |
$unixtime = strtotime($post->post_date); |
119 |
||
120 |
$category = ''; |
|
121 |
if ( strpos($permalink, '%category%') !== false ) { |
|
122 |
$cats = get_the_category($post->ID); |
|
123 |
if ( $cats ) { |
|
124 |
usort($cats, '_usort_terms_by_ID'); // order by ID |
|
125 |
$category = $cats[0]->slug; |
|
126 |
if ( $parent = $cats[0]->parent ) |
|
127 |
$category = get_category_parents($parent, false, '/', true) . $category; |
|
128 |
} |
|
129 |
// show default category in permalinks, without |
|
130 |
// having to assign it explicitly |
|
131 |
if ( empty($category) ) { |
|
132 |
$default_category = get_category( get_option( 'default_category' ) ); |
|
133 |
$category = is_wp_error( $default_category ) ? '' : $default_category->slug; |
|
134 |
} |
|
135 |
} |
|
136 |
||
137 |
$author = ''; |
|
138 |
if ( strpos($permalink, '%author%') !== false ) { |
|
139 |
$authordata = get_userdata($post->post_author); |
|
140 |
$author = $authordata->user_nicename; |
|
141 |
} |
|
142 |
||
143 |
$date = explode(" ",date('Y m d H i s', $unixtime)); |
|
144 |
$rewritereplace = |
|
145 |
array( |
|
146 |
$date[0], |
|
147 |
$date[1], |
|
148 |
$date[2], |
|
149 |
$date[3], |
|
150 |
$date[4], |
|
151 |
$date[5], |
|
152 |
$post->post_name, |
|
153 |
$post->ID, |
|
154 |
$category, |
|
155 |
$author, |
|
156 |
$post->post_name, |
|
157 |
); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
158 |
$permalink = home_url( str_replace($rewritecode, $rewritereplace, $permalink) ); |
136 | 159 |
$permalink = user_trailingslashit($permalink, 'single'); |
160 |
} else { // if they're not using the fancy permalink option |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
161 |
$permalink = home_url('?p=' . $post->ID); |
136 | 162 |
} |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
163 |
return apply_filters('post_link', $permalink, $post, $leavename); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
164 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
165 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
166 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
167 |
* Retrieve the permalink for a post with a custom post type. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
168 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
169 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
170 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
171 |
* @param int $id Optional. Post ID. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
172 |
* @param bool $leavename Optional, defaults to false. Whether to keep post name. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
173 |
* @param bool $sample Optional, defaults to false. Is it a sample permalink. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
174 |
* @return string |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
175 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
176 |
function get_post_permalink( $id = 0, $leavename = false, $sample = false ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
177 |
global $wp_rewrite; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
178 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
179 |
$post = &get_post($id); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
180 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
181 |
if ( is_wp_error( $post ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
182 |
return $post; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
183 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
184 |
$post_link = $wp_rewrite->get_extra_permastruct($post->post_type); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
185 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
186 |
$slug = $post->post_name; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
187 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
188 |
$draft_or_pending = isset($post->post_status) && in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
189 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
190 |
$post_type = get_post_type_object($post->post_type); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
191 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
192 |
if ( !empty($post_link) && ( !$draft_or_pending || $sample ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
193 |
if ( ! $leavename ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
194 |
if ( $post_type->hierarchical ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
195 |
$slug = get_page_uri($id); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
196 |
$post_link = str_replace("%$post->post_type%", $slug, $post_link); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
197 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
198 |
$post_link = home_url( user_trailingslashit($post_link) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
199 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
200 |
if ( $post_type->query_var && ( isset($post->post_status) && !$draft_or_pending ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
201 |
$post_link = add_query_arg($post_type->query_var, $slug, ''); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
202 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
203 |
$post_link = add_query_arg(array('post_type' => $post->post_type, 'p' => $post->ID), ''); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
204 |
$post_link = home_url($post_link); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
205 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
206 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
207 |
return apply_filters('post_type_link', $post_link, $post, $leavename, $sample); |
136 | 208 |
} |
209 |
||
210 |
/** |
|
211 |
* Retrieve permalink from post ID. |
|
212 |
* |
|
213 |
* @since 1.0.0 |
|
214 |
* |
|
215 |
* @param int $post_id Optional. Post ID. |
|
216 |
* @param mixed $deprecated Not used. |
|
217 |
* @return string |
|
218 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
219 |
function post_permalink( $post_id = 0, $deprecated = '' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
220 |
if ( !empty( $deprecated ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
221 |
_deprecated_argument( __FUNCTION__, '1.3' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
222 |
|
136 | 223 |
return get_permalink($post_id); |
224 |
} |
|
225 |
||
226 |
/** |
|
227 |
* Retrieve the permalink for current page or page ID. |
|
228 |
* |
|
229 |
* Respects page_on_front. Use this one. |
|
230 |
* |
|
231 |
* @since 1.5.0 |
|
232 |
* |
|
233 |
* @param int $id Optional. Post ID. |
|
234 |
* @param bool $leavename Optional, defaults to false. Whether to keep page name. |
|
235 |
* @param bool $sample Optional, defaults to false. Is it a sample permalink. |
|
236 |
* @return string |
|
237 |
*/ |
|
238 |
function get_page_link( $id = false, $leavename = false, $sample = false ) { |
|
239 |
global $post; |
|
240 |
||
241 |
$id = (int) $id; |
|
242 |
if ( !$id ) |
|
243 |
$id = (int) $post->ID; |
|
244 |
||
245 |
if ( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
246 |
$link = home_url('/'); |
136 | 247 |
else |
248 |
$link = _get_page_link( $id , $leavename, $sample ); |
|
249 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
250 |
return apply_filters('page_link', $link, $id, $sample); |
136 | 251 |
} |
252 |
||
253 |
/** |
|
254 |
* Retrieve the page permalink. |
|
255 |
* |
|
256 |
* Ignores page_on_front. Internal use only. |
|
257 |
* |
|
258 |
* @since 2.1.0 |
|
259 |
* @access private |
|
260 |
* |
|
261 |
* @param int $id Optional. Post ID. |
|
262 |
* @param bool $leavename Optional. Leave name. |
|
263 |
* @param bool $sample Optional. Sample permalink. |
|
264 |
* @return string |
|
265 |
*/ |
|
266 |
function _get_page_link( $id = false, $leavename = false, $sample = false ) { |
|
267 |
global $post, $wp_rewrite; |
|
268 |
||
269 |
if ( !$id ) |
|
270 |
$id = (int) $post->ID; |
|
271 |
else |
|
272 |
$post = &get_post($id); |
|
273 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
274 |
$draft_or_pending = in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
275 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
276 |
$link = $wp_rewrite->get_page_permastruct(); |
136 | 277 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
278 |
if ( !empty($link) && ( ( isset($post->post_status) && !$draft_or_pending ) || $sample ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
279 |
if ( ! $leavename ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
280 |
$link = str_replace('%pagename%', get_page_uri($id), $link); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
281 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
282 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
283 |
$link = home_url($link); |
136 | 284 |
$link = user_trailingslashit($link, 'page'); |
285 |
} else { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
286 |
$link = home_url("?page_id=$id"); |
136 | 287 |
} |
288 |
||
289 |
return apply_filters( '_get_page_link', $link, $id ); |
|
290 |
} |
|
291 |
||
292 |
/** |
|
293 |
* Retrieve permalink for attachment. |
|
294 |
* |
|
295 |
* This can be used in the WordPress Loop or outside of it. |
|
296 |
* |
|
297 |
* @since 2.0.0 |
|
298 |
* |
|
299 |
* @param int $id Optional. Post ID. |
|
300 |
* @return string |
|
301 |
*/ |
|
302 |
function get_attachment_link($id = false) { |
|
303 |
global $post, $wp_rewrite; |
|
304 |
||
305 |
$link = false; |
|
306 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
307 |
if ( ! $id) |
136 | 308 |
$id = (int) $post->ID; |
309 |
||
310 |
$object = get_post($id); |
|
311 |
if ( $wp_rewrite->using_permalinks() && ($object->post_parent > 0) && ($object->post_parent != $id) ) { |
|
312 |
$parent = get_post($object->post_parent); |
|
313 |
if ( 'page' == $parent->post_type ) |
|
314 |
$parentlink = _get_page_link( $object->post_parent ); // Ignores page_on_front |
|
315 |
else |
|
316 |
$parentlink = get_permalink( $object->post_parent ); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
317 |
|
136 | 318 |
if ( is_numeric($object->post_name) || false !== strpos(get_option('permalink_structure'), '%category%') ) |
319 |
$name = 'attachment/' . $object->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker |
|
320 |
else |
|
321 |
$name = $object->post_name; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
322 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
323 |
if ( strpos($parentlink, '?') === false ) |
136 | 324 |
$link = user_trailingslashit( trailingslashit($parentlink) . $name ); |
325 |
} |
|
326 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
327 |
if ( ! $link ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
328 |
$link = home_url( "/?attachment_id=$id" ); |
136 | 329 |
|
330 |
return apply_filters('attachment_link', $link, $id); |
|
331 |
} |
|
332 |
||
333 |
/** |
|
334 |
* Retrieve the permalink for the year archives. |
|
335 |
* |
|
336 |
* @since 1.5.0 |
|
337 |
* |
|
338 |
* @param int|bool $year False for current year or year for permalink. |
|
339 |
* @return string |
|
340 |
*/ |
|
341 |
function get_year_link($year) { |
|
342 |
global $wp_rewrite; |
|
343 |
if ( !$year ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
344 |
$year = gmdate('Y', current_time('timestamp')); |
136 | 345 |
$yearlink = $wp_rewrite->get_year_permastruct(); |
346 |
if ( !empty($yearlink) ) { |
|
347 |
$yearlink = str_replace('%year%', $year, $yearlink); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
348 |
return apply_filters('year_link', home_url( user_trailingslashit($yearlink, 'year') ), $year); |
136 | 349 |
} else { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
350 |
return apply_filters('year_link', home_url('?m=' . $year), $year); |
136 | 351 |
} |
352 |
} |
|
353 |
||
354 |
/** |
|
355 |
* Retrieve the permalink for the month archives with year. |
|
356 |
* |
|
357 |
* @since 1.0.0 |
|
358 |
* |
|
359 |
* @param bool|int $year False for current year. Integer of year. |
|
360 |
* @param bool|int $month False for current month. Integer of month. |
|
361 |
* @return string |
|
362 |
*/ |
|
363 |
function get_month_link($year, $month) { |
|
364 |
global $wp_rewrite; |
|
365 |
if ( !$year ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
366 |
$year = gmdate('Y', current_time('timestamp')); |
136 | 367 |
if ( !$month ) |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
368 |
$month = gmdate('m', current_time('timestamp')); |
136 | 369 |
$monthlink = $wp_rewrite->get_month_permastruct(); |
370 |
if ( !empty($monthlink) ) { |
|
371 |
$monthlink = str_replace('%year%', $year, $monthlink); |
|
372 |
$monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
373 |
return apply_filters('month_link', home_url( user_trailingslashit($monthlink, 'month') ), $year, $month); |
136 | 374 |
} else { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
375 |
return apply_filters('month_link', home_url( '?m=' . $year . zeroise($month, 2) ), $year, $month); |
136 | 376 |
} |
377 |
} |
|
378 |
||
379 |
/** |
|
380 |
* Retrieve the permalink for the day archives with year and month. |
|
381 |
* |
|
382 |
* @since 1.0.0 |
|
383 |
* |
|
384 |
* @param bool|int $year False for current year. Integer of year. |
|
385 |
* @param bool|int $month False for current month. Integer of month. |
|
386 |
* @param bool|int $day False for current day. Integer of day. |
|
387 |
* @return string |
|
388 |
*/ |
|
389 |
function get_day_link($year, $month, $day) { |
|
390 |
global $wp_rewrite; |
|
391 |
if ( !$year ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
392 |
$year = gmdate('Y', current_time('timestamp')); |
136 | 393 |
if ( !$month ) |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
394 |
$month = gmdate('m', current_time('timestamp')); |
136 | 395 |
if ( !$day ) |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
396 |
$day = gmdate('j', current_time('timestamp')); |
136 | 397 |
|
398 |
$daylink = $wp_rewrite->get_day_permastruct(); |
|
399 |
if ( !empty($daylink) ) { |
|
400 |
$daylink = str_replace('%year%', $year, $daylink); |
|
401 |
$daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink); |
|
402 |
$daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
403 |
return apply_filters('day_link', home_url( user_trailingslashit($daylink, 'day') ), $year, $month, $day); |
136 | 404 |
} else { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
405 |
return apply_filters('day_link', home_url( '?m=' . $year . zeroise($month, 2) . zeroise($day, 2) ), $year, $month, $day); |
136 | 406 |
} |
407 |
} |
|
408 |
||
409 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
410 |
* Display the permalink for the feed type. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
411 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
412 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
413 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
414 |
* @param string $anchor The link's anchor text. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
415 |
* @param string $feed Optional, defaults to default feed. Feed type. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
416 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
417 |
function the_feed_link( $anchor, $feed = '' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
418 |
$link = '<a href="' . esc_url( get_feed_link( $feed ) ) . '">' . $anchor . '</a>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
419 |
echo apply_filters( 'the_feed_link', $link, $feed ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
420 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
421 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
422 |
/** |
136 | 423 |
* Retrieve the permalink for the feed type. |
424 |
* |
|
425 |
* @since 1.5.0 |
|
426 |
* |
|
427 |
* @param string $feed Optional, defaults to default feed. Feed type. |
|
428 |
* @return string |
|
429 |
*/ |
|
430 |
function get_feed_link($feed = '') { |
|
431 |
global $wp_rewrite; |
|
432 |
||
433 |
$permalink = $wp_rewrite->get_feed_permastruct(); |
|
434 |
if ( '' != $permalink ) { |
|
435 |
if ( false !== strpos($feed, 'comments_') ) { |
|
436 |
$feed = str_replace('comments_', '', $feed); |
|
437 |
$permalink = $wp_rewrite->get_comment_feed_permastruct(); |
|
438 |
} |
|
439 |
||
440 |
if ( get_default_feed() == $feed ) |
|
441 |
$feed = ''; |
|
442 |
||
443 |
$permalink = str_replace('%feed%', $feed, $permalink); |
|
444 |
$permalink = preg_replace('#/+#', '/', "/$permalink"); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
445 |
$output = home_url( user_trailingslashit($permalink, 'feed') ); |
136 | 446 |
} else { |
447 |
if ( empty($feed) ) |
|
448 |
$feed = get_default_feed(); |
|
449 |
||
450 |
if ( false !== strpos($feed, 'comments_') ) |
|
451 |
$feed = str_replace('comments_', 'comments-', $feed); |
|
452 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
453 |
$output = home_url("?feed={$feed}"); |
136 | 454 |
} |
455 |
||
456 |
return apply_filters('feed_link', $output, $feed); |
|
457 |
} |
|
458 |
||
459 |
/** |
|
460 |
* Retrieve the permalink for the post comments feed. |
|
461 |
* |
|
462 |
* @since 2.2.0 |
|
463 |
* |
|
464 |
* @param int $post_id Optional. Post ID. |
|
465 |
* @param string $feed Optional. Feed type. |
|
466 |
* @return string |
|
467 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
468 |
function get_post_comments_feed_link($post_id = 0, $feed = '') { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
469 |
$post_id = absint( $post_id ); |
136 | 470 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
471 |
if ( ! $post_id ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
472 |
$post_id = get_the_ID(); |
136 | 473 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
474 |
if ( empty( $feed ) ) |
136 | 475 |
$feed = get_default_feed(); |
476 |
||
477 |
if ( '' != get_option('permalink_structure') ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
478 |
if ( 'page' == get_option('show_on_front') && $post_id == get_option('page_on_front') ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
479 |
$url = _get_page_link( $post_id ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
480 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
481 |
$url = get_permalink($post_id); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
482 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
483 |
$url = trailingslashit($url) . 'feed'; |
136 | 484 |
if ( $feed != get_default_feed() ) |
485 |
$url .= "/$feed"; |
|
486 |
$url = user_trailingslashit($url, 'single_feed'); |
|
487 |
} else { |
|
488 |
$type = get_post_field('post_type', $post_id); |
|
489 |
if ( 'page' == $type ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
490 |
$url = home_url("?feed=$feed&page_id=$post_id"); |
136 | 491 |
else |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
492 |
$url = home_url("?feed=$feed&p=$post_id"); |
136 | 493 |
} |
494 |
||
495 |
return apply_filters('post_comments_feed_link', $url); |
|
496 |
} |
|
497 |
||
498 |
/** |
|
499 |
* Display the comment feed link for a post. |
|
500 |
* |
|
501 |
* Prints out the comment feed link for a post. Link text is placed in the |
|
502 |
* anchor. If no link text is specified, default text is used. If no post ID is |
|
503 |
* specified, the current post is used. |
|
504 |
* |
|
505 |
* @package WordPress |
|
506 |
* @subpackage Feed |
|
507 |
* @since 2.5.0 |
|
508 |
* |
|
509 |
* @param string $link_text Descriptive text. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
510 |
* @param int $post_id Optional post ID. Default to current post. |
136 | 511 |
* @param string $feed Optional. Feed format. |
512 |
* @return string Link to the comment feed for the current post. |
|
513 |
*/ |
|
514 |
function post_comments_feed_link( $link_text = '', $post_id = '', $feed = '' ) { |
|
515 |
$url = get_post_comments_feed_link($post_id, $feed); |
|
516 |
if ( empty($link_text) ) |
|
517 |
$link_text = __('Comments Feed'); |
|
518 |
||
519 |
echo apply_filters( 'post_comments_feed_link_html', "<a href='$url'>$link_text</a>", $post_id, $feed ); |
|
520 |
} |
|
521 |
||
522 |
/** |
|
523 |
* Retrieve the feed link for a given author. |
|
524 |
* |
|
525 |
* Returns a link to the feed for all posts by a given author. A specific feed |
|
526 |
* can be requested or left blank to get the default feed. |
|
527 |
* |
|
528 |
* @package WordPress |
|
529 |
* @subpackage Feed |
|
530 |
* @since 2.5.0 |
|
531 |
* |
|
532 |
* @param int $author_id ID of an author. |
|
533 |
* @param string $feed Optional. Feed type. |
|
534 |
* @return string Link to the feed for the author specified by $author_id. |
|
535 |
*/ |
|
536 |
function get_author_feed_link( $author_id, $feed = '' ) { |
|
537 |
$author_id = (int) $author_id; |
|
538 |
$permalink_structure = get_option('permalink_structure'); |
|
539 |
||
540 |
if ( empty($feed) ) |
|
541 |
$feed = get_default_feed(); |
|
542 |
||
543 |
if ( '' == $permalink_structure ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
544 |
$link = home_url("?feed=$feed&author=" . $author_id); |
136 | 545 |
} else { |
546 |
$link = get_author_posts_url($author_id); |
|
547 |
if ( $feed == get_default_feed() ) |
|
548 |
$feed_link = 'feed'; |
|
549 |
else |
|
550 |
$feed_link = "feed/$feed"; |
|
551 |
||
552 |
$link = trailingslashit($link) . user_trailingslashit($feed_link, 'feed'); |
|
553 |
} |
|
554 |
||
555 |
$link = apply_filters('author_feed_link', $link, $feed); |
|
556 |
||
557 |
return $link; |
|
558 |
} |
|
559 |
||
560 |
/** |
|
561 |
* Retrieve the feed link for a category. |
|
562 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
563 |
* Returns a link to the feed for all posts in a given category. A specific feed |
136 | 564 |
* can be requested or left blank to get the default feed. |
565 |
* |
|
566 |
* @package WordPress |
|
567 |
* @subpackage Feed |
|
568 |
* @since 2.5.0 |
|
569 |
* |
|
570 |
* @param int $cat_id ID of a category. |
|
571 |
* @param string $feed Optional. Feed type. |
|
572 |
* @return string Link to the feed for the category specified by $cat_id. |
|
573 |
*/ |
|
574 |
function get_category_feed_link($cat_id, $feed = '') { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
575 |
return get_term_feed_link($cat_id, 'category', $feed); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
576 |
} |
136 | 577 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
578 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
579 |
* Retrieve the feed link for a term. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
580 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
581 |
* Returns a link to the feed for all posts in a given term. A specific feed |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
582 |
* can be requested or left blank to get the default feed. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
583 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
584 |
* @since 3.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
585 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
586 |
* @param int $term_id ID of a category. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
587 |
* @param string $taxonomy Optional. Taxonomy of $term_id |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
588 |
* @param string $feed Optional. Feed type. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
589 |
* @return string Link to the feed for the term specified by $term_id and $taxonomy. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
590 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
591 |
function get_term_feed_link( $term_id, $taxonomy = 'category', $feed = '' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
592 |
$term_id = ( int ) $term_id; |
136 | 593 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
594 |
$term = get_term( $term_id, $taxonomy ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
595 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
596 |
if ( empty( $term ) || is_wp_error( $term ) ) |
136 | 597 |
return false; |
598 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
599 |
if ( empty( $feed ) ) |
136 | 600 |
$feed = get_default_feed(); |
601 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
602 |
$permalink_structure = get_option( 'permalink_structure' ); |
136 | 603 |
|
604 |
if ( '' == $permalink_structure ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
605 |
if ( 'category' == $taxonomy ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
606 |
$link = home_url("?feed=$feed&cat=$term_id"); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
607 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
608 |
elseif ( 'post_tag' == $taxonomy ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
609 |
$link = home_url("?feed=$feed&tag=$term->slug"); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
610 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
611 |
$t = get_taxonomy( $taxonomy ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
612 |
$link = home_url("?feed=$feed&$t->query_var=$term->slug"); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
613 |
} |
136 | 614 |
} else { |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
615 |
$link = get_term_link( $term_id, $term->taxonomy ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
616 |
if ( $feed == get_default_feed() ) |
136 | 617 |
$feed_link = 'feed'; |
618 |
else |
|
619 |
$feed_link = "feed/$feed"; |
|
620 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
621 |
$link = trailingslashit( $link ) . user_trailingslashit( $feed_link, 'feed' ); |
136 | 622 |
} |
623 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
624 |
if ( 'category' == $taxonomy ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
625 |
$link = apply_filters( 'category_feed_link', $link, $feed ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
626 |
elseif ( 'post_tag' == $taxonomy ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
627 |
$link = apply_filters( 'category_feed_link', $link, $feed ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
628 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
629 |
$link = apply_filters( 'taxonomy_feed_link', $link, $feed, $taxonomy ); |
136 | 630 |
|
631 |
return $link; |
|
632 |
} |
|
633 |
||
634 |
/** |
|
635 |
* Retrieve permalink for feed of tag. |
|
636 |
* |
|
637 |
* @since 2.3.0 |
|
638 |
* |
|
639 |
* @param int $tag_id Tag ID. |
|
640 |
* @param string $feed Optional. Feed type. |
|
641 |
* @return string |
|
642 |
*/ |
|
643 |
function get_tag_feed_link($tag_id, $feed = '') { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
644 |
return get_term_feed_link($tag_id, 'post_tag', $feed); |
136 | 645 |
} |
646 |
||
647 |
/** |
|
648 |
* Retrieve edit tag link. |
|
649 |
* |
|
650 |
* @since 2.7.0 |
|
651 |
* |
|
652 |
* @param int $tag_id Tag ID |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
653 |
* @param string $taxonomy Taxonomy |
136 | 654 |
* @return string |
655 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
656 |
function get_edit_tag_link( $tag_id, $taxonomy = 'post_tag' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
657 |
return apply_filters( 'get_edit_tag_link', get_edit_term_link( $tag_id, $taxonomy ) ); |
136 | 658 |
} |
659 |
||
660 |
/** |
|
661 |
* Display or retrieve edit tag link with formatting. |
|
662 |
* |
|
663 |
* @since 2.7.0 |
|
664 |
* |
|
665 |
* @param string $link Optional. Anchor text. |
|
666 |
* @param string $before Optional. Display before edit link. |
|
667 |
* @param string $after Optional. Display after edit link. |
|
668 |
* @param int|object $tag Tag object or ID |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
669 |
* @return string HTML content. |
136 | 670 |
*/ |
671 |
function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
672 |
$link = edit_term_link( $link, '', '', false, $tag ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
673 |
echo $before . apply_filters( 'edit_tag_link', $link ) . $after; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
674 |
} |
136 | 675 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
676 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
677 |
* Retrieve edit term url. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
678 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
679 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
680 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
681 |
* @param int $term_id Term ID |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
682 |
* @param string $taxonomy Taxonomy |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
683 |
* @param string $object_type The object type |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
684 |
* @return string |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
685 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
686 |
function get_edit_term_link( $term_id, $taxonomy, $object_type = '' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
687 |
$tax = get_taxonomy( $taxonomy ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
688 |
if ( !current_user_can( $tax->cap->edit_terms ) ) |
136 | 689 |
return; |
690 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
691 |
$term = get_term( $term_id, $taxonomy ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
692 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
693 |
$args = array( |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
694 |
'action' => 'edit', |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
695 |
'taxonomy' => $taxonomy, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
696 |
'tag_ID' => $term->term_id, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
697 |
); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
698 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
699 |
if ( $object_type ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
700 |
$args['post_type'] = $object_type; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
701 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
702 |
$location = add_query_arg( $args, admin_url( 'edit-tags.php' ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
703 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
704 |
return apply_filters( 'get_edit_term_link', $location, $term_id, $taxonomy, $object_type ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
705 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
706 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
707 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
708 |
* Display or retrieve edit term link with formatting. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
709 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
710 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
711 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
712 |
* @param string $link Optional. Anchor text. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
713 |
* @param string $before Optional. Display before edit link. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
714 |
* @param string $after Optional. Display after edit link. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
715 |
* @param object $term Term object |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
716 |
* @return string HTML content. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
717 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
718 |
function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
719 |
if ( is_null( $term ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
720 |
$term = get_queried_object(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
721 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
722 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
723 |
$tax = get_taxonomy( $term->taxonomy ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
724 |
if ( !current_user_can($tax->cap->edit_terms) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
725 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
726 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
727 |
if ( empty( $link ) ) |
136 | 728 |
$link = __('Edit This'); |
729 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
730 |
$link = '<a href="' . get_edit_term_link( $term->term_id, $term->taxonomy ) . '" title="' . $link . '">' . $link . '</a>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
731 |
$link = $before . apply_filters( 'edit_term_link', $link, $term->term_id ) . $after; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
732 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
733 |
if ( $echo ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
734 |
echo $link; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
735 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
736 |
return $link; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
737 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
738 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
739 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
740 |
* Retrieve permalink for search. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
741 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
742 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
743 |
* @param string $query Optional. The query string to use. If empty the current query is used. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
744 |
* @return string |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
745 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
746 |
function get_search_link( $query = '' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
747 |
global $wp_rewrite; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
748 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
749 |
if ( empty($query) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
750 |
$search = get_search_query( false ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
751 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
752 |
$search = stripslashes($query); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
753 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
754 |
$permastruct = $wp_rewrite->get_search_permastruct(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
755 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
756 |
if ( empty( $permastruct ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
757 |
$link = home_url('?s=' . urlencode($search) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
758 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
759 |
$search = urlencode($search); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
760 |
$search = str_replace('%2F', '/', $search); // %2F(/) is not valid within a URL, send it unencoded. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
761 |
$link = str_replace( '%search%', $search, $permastruct ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
762 |
$link = home_url( user_trailingslashit( $link, 'search' ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
763 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
764 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
765 |
return apply_filters( 'search_link', $link, $search ); |
136 | 766 |
} |
767 |
||
768 |
/** |
|
769 |
* Retrieve the permalink for the feed of the search results. |
|
770 |
* |
|
771 |
* @since 2.5.0 |
|
772 |
* |
|
773 |
* @param string $search_query Optional. Search query. |
|
774 |
* @param string $feed Optional. Feed type. |
|
775 |
* @return string |
|
776 |
*/ |
|
777 |
function get_search_feed_link($search_query = '', $feed = '') { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
778 |
global $wp_rewrite; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
779 |
$link = get_search_link($search_query); |
136 | 780 |
|
781 |
if ( empty($feed) ) |
|
782 |
$feed = get_default_feed(); |
|
783 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
784 |
$permastruct = $wp_rewrite->get_search_permastruct(); |
136 | 785 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
786 |
if ( empty($permastruct) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
787 |
$link = add_query_arg('feed', $feed, $link); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
788 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
789 |
$link = trailingslashit($link); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
790 |
$link .= "feed/$feed/"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
791 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
792 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
793 |
$link = apply_filters('search_feed_link', $link, $feed, 'posts'); |
136 | 794 |
|
795 |
return $link; |
|
796 |
} |
|
797 |
||
798 |
/** |
|
799 |
* Retrieve the permalink for the comments feed of the search results. |
|
800 |
* |
|
801 |
* @since 2.5.0 |
|
802 |
* |
|
803 |
* @param string $search_query Optional. Search query. |
|
804 |
* @param string $feed Optional. Feed type. |
|
805 |
* @return string |
|
806 |
*/ |
|
807 |
function get_search_comments_feed_link($search_query = '', $feed = '') { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
808 |
global $wp_rewrite; |
136 | 809 |
|
810 |
if ( empty($feed) ) |
|
811 |
$feed = get_default_feed(); |
|
812 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
813 |
$link = get_search_feed_link($search_query, $feed); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
814 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
815 |
$permastruct = $wp_rewrite->get_search_permastruct(); |
136 | 816 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
817 |
if ( empty($permastruct) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
818 |
$link = add_query_arg('feed', 'comments-' . $feed, $link); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
819 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
820 |
$link = add_query_arg('withcomments', 1, $link); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
821 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
822 |
$link = apply_filters('search_feed_link', $link, $feed, 'comments'); |
136 | 823 |
|
824 |
return $link; |
|
825 |
} |
|
826 |
||
827 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
828 |
* Retrieve the permalink for a post type archive. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
829 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
830 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
831 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
832 |
* @param string $post_type Post type |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
833 |
* @return string |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
834 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
835 |
function get_post_type_archive_link( $post_type ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
836 |
global $wp_rewrite; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
837 |
if ( ! $post_type_obj = get_post_type_object( $post_type ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
838 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
839 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
840 |
if ( ! $post_type_obj->has_archive ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
841 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
842 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
843 |
if ( get_option( 'permalink_structure' ) && is_array( $post_type_obj->rewrite ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
844 |
$struct = ( true === $post_type_obj->has_archive ) ? $post_type_obj->rewrite['slug'] : $post_type_obj->has_archive; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
845 |
if ( $post_type_obj->rewrite['with_front'] ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
846 |
$struct = $wp_rewrite->front . $struct; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
847 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
848 |
$struct = $wp_rewrite->root . $struct; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
849 |
$link = home_url( user_trailingslashit( $struct, 'post_type_archive' ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
850 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
851 |
$link = home_url( '?post_type=' . $post_type ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
852 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
853 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
854 |
return apply_filters( 'post_type_archive_link', $link, $post_type ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
855 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
856 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
857 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
858 |
* Retrieve the permalink for a post type archive feed. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
859 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
860 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
861 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
862 |
* @param string $post_type Post type |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
863 |
* @param string $feed Optional. Feed type |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
864 |
* @return string |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
865 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
866 |
function get_post_type_archive_feed_link( $post_type, $feed = '' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
867 |
$default_feed = get_default_feed(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
868 |
if ( empty( $feed ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
869 |
$feed = $default_feed; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
870 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
871 |
if ( ! $link = get_post_type_archive_link( $post_type ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
872 |
return false; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
873 |
$post_type_obj = get_post_type_object( $post_type ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
874 |
if ( $post_type_obj->rewrite['feeds'] && get_option( 'permalink_structure' ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
875 |
$link = trailingslashit($link); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
876 |
$link .= 'feed/'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
877 |
if ( $feed != $default_feed ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
878 |
$link .= "$feed/"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
879 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
880 |
$link = add_query_arg( 'feed', $feed, $link ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
881 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
882 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
883 |
return apply_filters( 'post_type_archive_feed_link', $link, $feed ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
884 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
885 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
886 |
/** |
136 | 887 |
* Retrieve edit posts link for post. |
888 |
* |
|
889 |
* Can be used within the WordPress loop or outside of it. Can be used with |
|
890 |
* pages, posts, attachments, and revisions. |
|
891 |
* |
|
892 |
* @since 2.3.0 |
|
893 |
* |
|
894 |
* @param int $id Optional. Post ID. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
895 |
* @param string $context Optional, defaults to display. How to write the '&', defaults to '&'. |
136 | 896 |
* @return string |
897 |
*/ |
|
898 |
function get_edit_post_link( $id = 0, $context = 'display' ) { |
|
899 |
if ( !$post = &get_post( $id ) ) |
|
900 |
return; |
|
901 |
||
902 |
if ( 'display' == $context ) |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
903 |
$action = '&action=edit'; |
136 | 904 |
else |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
905 |
$action = '&action=edit'; |
136 | 906 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
907 |
$post_type_object = get_post_type_object( $post->post_type ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
908 |
if ( !$post_type_object ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
909 |
return; |
136 | 910 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
911 |
if ( !current_user_can( $post_type_object->cap->edit_post, $post->ID ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
912 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
913 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
914 |
return apply_filters( 'get_edit_post_link', admin_url( sprintf($post_type_object->_edit_link . $action, $post->ID) ), $post->ID, $context ); |
136 | 915 |
} |
916 |
||
917 |
/** |
|
918 |
* Display edit post link for post. |
|
919 |
* |
|
920 |
* @since 1.0.0 |
|
921 |
* |
|
922 |
* @param string $link Optional. Anchor text. |
|
923 |
* @param string $before Optional. Display before edit link. |
|
924 |
* @param string $after Optional. Display after edit link. |
|
925 |
* @param int $id Optional. Post ID. |
|
926 |
*/ |
|
927 |
function edit_post_link( $link = null, $before = '', $after = '', $id = 0 ) { |
|
928 |
if ( !$post = &get_post( $id ) ) |
|
929 |
return; |
|
930 |
||
931 |
if ( !$url = get_edit_post_link( $post->ID ) ) |
|
932 |
return; |
|
933 |
||
934 |
if ( null === $link ) |
|
935 |
$link = __('Edit This'); |
|
936 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
937 |
$post_type_obj = get_post_type_object( $post->post_type ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
938 |
$link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr( $post_type_obj->labels->edit_item ) . '">' . $link . '</a>'; |
136 | 939 |
echo $before . apply_filters( 'edit_post_link', $link, $post->ID ) . $after; |
940 |
} |
|
941 |
||
942 |
/** |
|
943 |
* Retrieve delete posts link for post. |
|
944 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
945 |
* Can be used within the WordPress loop or outside of it, with any post type. |
136 | 946 |
* |
947 |
* @since 2.9.0 |
|
948 |
* |
|
949 |
* @param int $id Optional. Post ID. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
950 |
* @param string $deprecated Not used. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
951 |
* @param bool $force_delete Whether to bypass trash and force deletion. Default is false. |
136 | 952 |
* @return string |
953 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
954 |
function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
955 |
if ( ! empty( $deprecated ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
956 |
_deprecated_argument( __FUNCTION__, '3.0' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
957 |
|
136 | 958 |
if ( !$post = &get_post( $id ) ) |
959 |
return; |
|
960 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
961 |
$post_type_object = get_post_type_object( $post->post_type ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
962 |
if ( !$post_type_object ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
963 |
return; |
136 | 964 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
965 |
if ( !current_user_can( $post_type_object->cap->delete_post, $post->ID ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
966 |
return; |
136 | 967 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
968 |
$action = ( $force_delete || !EMPTY_TRASH_DAYS ) ? 'delete' : 'trash'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
969 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
970 |
$delete_link = add_query_arg( 'action', $action, admin_url( sprintf( $post_type_object->_edit_link, $post->ID ) ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
971 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
972 |
return apply_filters( 'get_delete_post_link', wp_nonce_url( $delete_link, "$action-{$post->post_type}_{$post->ID}" ), $post->ID, $force_delete ); |
136 | 973 |
} |
974 |
||
975 |
/** |
|
976 |
* Retrieve edit comment link. |
|
977 |
* |
|
978 |
* @since 2.3.0 |
|
979 |
* |
|
980 |
* @param int $comment_id Optional. Comment ID. |
|
981 |
* @return string |
|
982 |
*/ |
|
983 |
function get_edit_comment_link( $comment_id = 0 ) { |
|
984 |
$comment = &get_comment( $comment_id ); |
|
985 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
986 |
if ( !current_user_can( 'edit_comment', $comment->comment_ID ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
987 |
return; |
136 | 988 |
|
989 |
$location = admin_url('comment.php?action=editcomment&c=') . $comment->comment_ID; |
|
990 |
return apply_filters( 'get_edit_comment_link', $location ); |
|
991 |
} |
|
992 |
||
993 |
/** |
|
994 |
* Display or retrieve edit comment link with formatting. |
|
995 |
* |
|
996 |
* @since 1.0.0 |
|
997 |
* |
|
998 |
* @param string $link Optional. Anchor text. |
|
999 |
* @param string $before Optional. Display before edit link. |
|
1000 |
* @param string $after Optional. Display after edit link. |
|
1001 |
* @return string|null HTML content, if $echo is set to false. |
|
1002 |
*/ |
|
1003 |
function edit_comment_link( $link = null, $before = '', $after = '' ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1004 |
global $comment; |
136 | 1005 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1006 |
if ( !current_user_can( 'edit_comment', $comment->comment_ID ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1007 |
return; |
136 | 1008 |
|
1009 |
if ( null === $link ) |
|
1010 |
$link = __('Edit This'); |
|
1011 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1012 |
$link = '<a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . esc_attr__( 'Edit comment' ) . '">' . $link . '</a>'; |
136 | 1013 |
echo $before . apply_filters( 'edit_comment_link', $link, $comment->comment_ID ) . $after; |
1014 |
} |
|
1015 |
||
1016 |
/** |
|
1017 |
* Display edit bookmark (literally a URL external to blog) link. |
|
1018 |
* |
|
1019 |
* @since 2.7.0 |
|
1020 |
* |
|
1021 |
* @param int $link Optional. Bookmark ID. |
|
1022 |
* @return string |
|
1023 |
*/ |
|
1024 |
function get_edit_bookmark_link( $link = 0 ) { |
|
1025 |
$link = get_bookmark( $link ); |
|
1026 |
||
1027 |
if ( !current_user_can('manage_links') ) |
|
1028 |
return; |
|
1029 |
||
1030 |
$location = admin_url('link.php?action=edit&link_id=') . $link->link_id; |
|
1031 |
return apply_filters( 'get_edit_bookmark_link', $location, $link->link_id ); |
|
1032 |
} |
|
1033 |
||
1034 |
/** |
|
1035 |
* Display edit bookmark (literally a URL external to blog) link anchor content. |
|
1036 |
* |
|
1037 |
* @since 2.7.0 |
|
1038 |
* |
|
1039 |
* @param string $link Optional. Anchor text. |
|
1040 |
* @param string $before Optional. Display before edit link. |
|
1041 |
* @param string $after Optional. Display after edit link. |
|
1042 |
* @param int $bookmark Optional. Bookmark ID. |
|
1043 |
*/ |
|
1044 |
function edit_bookmark_link( $link = '', $before = '', $after = '', $bookmark = null ) { |
|
1045 |
$bookmark = get_bookmark($bookmark); |
|
1046 |
||
1047 |
if ( !current_user_can('manage_links') ) |
|
1048 |
return; |
|
1049 |
||
1050 |
if ( empty($link) ) |
|
1051 |
$link = __('Edit This'); |
|
1052 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1053 |
$link = '<a href="' . get_edit_bookmark_link( $bookmark ) . '" title="' . esc_attr__( 'Edit Link' ) . '">' . $link . '</a>'; |
136 | 1054 |
echo $before . apply_filters( 'edit_bookmark_link', $link, $bookmark->link_id ) . $after; |
1055 |
} |
|
1056 |
||
1057 |
// Navigation links |
|
1058 |
||
1059 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1060 |
* Retrieve previous post that is adjacent to current post. |
136 | 1061 |
* |
1062 |
* @since 1.5.0 |
|
1063 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1064 |
* @param bool $in_same_cat Optional. Whether post should be in a same category. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1065 |
* @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1066 |
* @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. |
136 | 1067 |
*/ |
1068 |
function get_previous_post($in_same_cat = false, $excluded_categories = '') { |
|
1069 |
return get_adjacent_post($in_same_cat, $excluded_categories); |
|
1070 |
} |
|
1071 |
||
1072 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1073 |
* Retrieve next post that is adjacent to current post. |
136 | 1074 |
* |
1075 |
* @since 1.5.0 |
|
1076 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1077 |
* @param bool $in_same_cat Optional. Whether post should be in a same category. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1078 |
* @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1079 |
* @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. |
136 | 1080 |
*/ |
1081 |
function get_next_post($in_same_cat = false, $excluded_categories = '') { |
|
1082 |
return get_adjacent_post($in_same_cat, $excluded_categories, false); |
|
1083 |
} |
|
1084 |
||
1085 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1086 |
* Retrieve adjacent post. |
136 | 1087 |
* |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1088 |
* Can either be next or previous post. |
136 | 1089 |
* |
1090 |
* @since 2.5.0 |
|
1091 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1092 |
* @param bool $in_same_cat Optional. Whether post should be in a same category. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1093 |
* @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
136 | 1094 |
* @param bool $previous Optional. Whether to retrieve previous post. |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1095 |
* @return mixed Post object if successful. Null if global $post is not set. Empty string if no corresponding post exists. |
136 | 1096 |
*/ |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1097 |
function get_adjacent_post( $in_same_cat = false, $excluded_categories = '', $previous = true ) { |
136 | 1098 |
global $post, $wpdb; |
1099 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1100 |
if ( empty( $post ) ) |
136 | 1101 |
return null; |
1102 |
||
1103 |
$current_post_date = $post->post_date; |
|
1104 |
||
1105 |
$join = ''; |
|
1106 |
$posts_in_ex_cats_sql = ''; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1107 |
if ( $in_same_cat || ! empty( $excluded_categories ) ) { |
136 | 1108 |
$join = " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id"; |
1109 |
||
1110 |
if ( $in_same_cat ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1111 |
$cat_array = wp_get_object_terms($post->ID, 'category', array('fields' => 'ids')); |
136 | 1112 |
$join .= " AND tt.taxonomy = 'category' AND tt.term_id IN (" . implode(',', $cat_array) . ")"; |
1113 |
} |
|
1114 |
||
1115 |
$posts_in_ex_cats_sql = "AND tt.taxonomy = 'category'"; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1116 |
if ( ! empty( $excluded_categories ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1117 |
if ( ! is_array( $excluded_categories ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1118 |
// back-compat, $excluded_categories used to be IDs separated by " and " |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1119 |
if ( strpos( $excluded_categories, ' and ' ) !== false ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1120 |
_deprecated_argument( __FUNCTION__, '3.3', sprintf( __( 'Use commas instead of %s to separate excluded categories.' ), "'and'" ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1121 |
$excluded_categories = explode( ' and ', $excluded_categories ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1122 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1123 |
$excluded_categories = explode( ',', $excluded_categories ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1124 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1125 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1126 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1127 |
$excluded_categories = array_map( 'intval', $excluded_categories ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1128 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1129 |
if ( ! empty( $cat_array ) ) { |
136 | 1130 |
$excluded_categories = array_diff($excluded_categories, $cat_array); |
1131 |
$posts_in_ex_cats_sql = ''; |
|
1132 |
} |
|
1133 |
||
1134 |
if ( !empty($excluded_categories) ) { |
|
1135 |
$posts_in_ex_cats_sql = " AND tt.taxonomy = 'category' AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')'; |
|
1136 |
} |
|
1137 |
} |
|
1138 |
} |
|
1139 |
||
1140 |
$adjacent = $previous ? 'previous' : 'next'; |
|
1141 |
$op = $previous ? '<' : '>'; |
|
1142 |
$order = $previous ? 'DESC' : 'ASC'; |
|
1143 |
||
1144 |
$join = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_cat, $excluded_categories ); |
|
1145 |
$where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare("WHERE p.post_date $op %s AND p.post_type = %s AND p.post_status = 'publish' $posts_in_ex_cats_sql", $current_post_date, $post->post_type), $in_same_cat, $excluded_categories ); |
|
1146 |
$sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1" ); |
|
1147 |
||
1148 |
$query = "SELECT p.* FROM $wpdb->posts AS p $join $where $sort"; |
|
1149 |
$query_key = 'adjacent_post_' . md5($query); |
|
1150 |
$result = wp_cache_get($query_key, 'counts'); |
|
1151 |
if ( false !== $result ) |
|
1152 |
return $result; |
|
1153 |
||
1154 |
$result = $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p $join $where $sort"); |
|
1155 |
if ( null === $result ) |
|
1156 |
$result = ''; |
|
1157 |
||
1158 |
wp_cache_set($query_key, $result, 'counts'); |
|
1159 |
return $result; |
|
1160 |
} |
|
1161 |
||
1162 |
/** |
|
1163 |
* Get adjacent post relational link. |
|
1164 |
* |
|
1165 |
* Can either be next or previous post relational link. |
|
1166 |
* |
|
1167 |
* @since 2.8.0 |
|
1168 |
* |
|
1169 |
* @param string $title Optional. Link title format. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1170 |
* @param bool $in_same_cat Optional. Whether link should be in a same category. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1171 |
* @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1172 |
* @param bool $previous Optional, default is true. Whether to display link to previous or next post. |
136 | 1173 |
* @return string |
1174 |
*/ |
|
1175 |
function get_adjacent_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '', $previous = true) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1176 |
if ( $previous && is_attachment() && is_object( $GLOBALS['post'] ) ) |
136 | 1177 |
$post = & get_post($GLOBALS['post']->post_parent); |
1178 |
else |
|
1179 |
$post = get_adjacent_post($in_same_cat,$excluded_categories,$previous); |
|
1180 |
||
1181 |
if ( empty($post) ) |
|
1182 |
return; |
|
1183 |
||
1184 |
if ( empty($post->post_title) ) |
|
1185 |
$post->post_title = $previous ? __('Previous Post') : __('Next Post'); |
|
1186 |
||
1187 |
$date = mysql2date(get_option('date_format'), $post->post_date); |
|
1188 |
||
1189 |
$title = str_replace('%title', $post->post_title, $title); |
|
1190 |
$title = str_replace('%date', $date, $title); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1191 |
$title = apply_filters('the_title', $title, $post->ID); |
136 | 1192 |
|
1193 |
$link = $previous ? "<link rel='prev' title='" : "<link rel='next' title='"; |
|
1194 |
$link .= esc_attr( $title ); |
|
1195 |
$link .= "' href='" . get_permalink($post) . "' />\n"; |
|
1196 |
||
1197 |
$adjacent = $previous ? 'previous' : 'next'; |
|
1198 |
return apply_filters( "{$adjacent}_post_rel_link", $link ); |
|
1199 |
} |
|
1200 |
||
1201 |
/** |
|
1202 |
* Display relational links for the posts adjacent to the current post. |
|
1203 |
* |
|
1204 |
* @since 2.8.0 |
|
1205 |
* |
|
1206 |
* @param string $title Optional. Link title format. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1207 |
* @param bool $in_same_cat Optional. Whether link should be in a same category. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1208 |
* @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
136 | 1209 |
*/ |
1210 |
function adjacent_posts_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { |
|
1211 |
echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true); |
|
1212 |
echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false); |
|
1213 |
} |
|
1214 |
||
1215 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1216 |
* Display relational links for the posts adjacent to the current post for single post pages. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1217 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1218 |
* This is meant to be attached to actions like 'wp_head'. Do not call this directly in plugins or theme templates. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1219 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1220 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1221 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1222 |
function adjacent_posts_rel_link_wp_head() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1223 |
if ( !is_singular() || is_attachment() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1224 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1225 |
adjacent_posts_rel_link(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1226 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1227 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1228 |
/** |
136 | 1229 |
* Display relational link for the next post adjacent to the current post. |
1230 |
* |
|
1231 |
* @since 2.8.0 |
|
1232 |
* |
|
1233 |
* @param string $title Optional. Link title format. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1234 |
* @param bool $in_same_cat Optional. Whether link should be in a same category. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1235 |
* @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
136 | 1236 |
*/ |
1237 |
function next_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { |
|
1238 |
echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', false); |
|
1239 |
} |
|
1240 |
||
1241 |
/** |
|
1242 |
* Display relational link for the previous post adjacent to the current post. |
|
1243 |
* |
|
1244 |
* @since 2.8.0 |
|
1245 |
* |
|
1246 |
* @param string $title Optional. Link title format. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1247 |
* @param bool $in_same_cat Optional. Whether link should be in a same category. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1248 |
* @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
136 | 1249 |
*/ |
1250 |
function prev_post_rel_link($title = '%title', $in_same_cat = false, $excluded_categories = '') { |
|
1251 |
echo get_adjacent_post_rel_link($title, $in_same_cat, $excluded_categories = '', true); |
|
1252 |
} |
|
1253 |
||
1254 |
/** |
|
1255 |
* Retrieve boundary post. |
|
1256 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1257 |
* Boundary being either the first or last post by publish date within the constraints specified |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1258 |
* by $in_same_cat or $excluded_categories. |
136 | 1259 |
* |
1260 |
* @since 2.8.0 |
|
1261 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1262 |
* @param bool $in_same_cat Optional. Whether returned post should be in a same category. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1263 |
* @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1264 |
* @param bool $start Optional. Whether to retrieve first or last post. |
136 | 1265 |
* @return object |
1266 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1267 |
function get_boundary_post( $in_same_cat = false, $excluded_categories = '', $start = true ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1268 |
global $post; |
136 | 1269 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1270 |
if ( empty($post) || ! is_single() || is_attachment() ) |
136 | 1271 |
return null; |
1272 |
||
1273 |
$cat_array = array(); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1274 |
if( ! is_array( $excluded_categories ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1275 |
$excluded_categories = explode( ',', $excluded_categories ); |
136 | 1276 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1277 |
if ( $in_same_cat || ! empty( $excluded_categories ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1278 |
if ( $in_same_cat ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1279 |
$cat_array = wp_get_object_terms( $post->ID, 'category', array( 'fields' => 'ids' ) ); |
136 | 1280 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1281 |
if ( ! empty( $excluded_categories ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1282 |
$excluded_categories = array_map( 'intval', $excluded_categories ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1283 |
$excluded_categories = array_diff( $excluded_categories, $cat_array ); |
136 | 1284 |
|
1285 |
$inverse_cats = array(); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1286 |
foreach ( $excluded_categories as $excluded_category ) |
136 | 1287 |
$inverse_cats[] = $excluded_category * -1; |
1288 |
$excluded_categories = $inverse_cats; |
|
1289 |
} |
|
1290 |
} |
|
1291 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1292 |
$categories = implode( ',', array_merge( $cat_array, $excluded_categories ) ); |
136 | 1293 |
|
1294 |
$order = $start ? 'ASC' : 'DESC'; |
|
1295 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1296 |
return get_posts( array('numberposts' => 1, 'category' => $categories, 'order' => $order, 'update_post_term_cache' => false, 'update_post_meta_cache' => false) ); |
136 | 1297 |
} |
1298 |
||
1299 |
/** |
|
1300 |
* Display previous post link that is adjacent to the current post. |
|
1301 |
* |
|
1302 |
* @since 1.5.0 |
|
1303 |
* |
|
1304 |
* @param string $format Optional. Link anchor format. |
|
1305 |
* @param string $link Optional. Link permalink format. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1306 |
* @param bool $in_same_cat Optional. Whether link should be in a same category. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1307 |
* @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
136 | 1308 |
*/ |
1309 |
function previous_post_link($format='« %link', $link='%title', $in_same_cat = false, $excluded_categories = '') { |
|
1310 |
adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, true); |
|
1311 |
} |
|
1312 |
||
1313 |
/** |
|
1314 |
* Display next post link that is adjacent to the current post. |
|
1315 |
* |
|
1316 |
* @since 1.5.0 |
|
1317 |
* |
|
1318 |
* @param string $format Optional. Link anchor format. |
|
1319 |
* @param string $link Optional. Link permalink format. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1320 |
* @param bool $in_same_cat Optional. Whether link should be in a same category. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1321 |
* @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
136 | 1322 |
*/ |
1323 |
function next_post_link($format='%link »', $link='%title', $in_same_cat = false, $excluded_categories = '') { |
|
1324 |
adjacent_post_link($format, $link, $in_same_cat, $excluded_categories, false); |
|
1325 |
} |
|
1326 |
||
1327 |
/** |
|
1328 |
* Display adjacent post link. |
|
1329 |
* |
|
1330 |
* Can be either next post link or previous. |
|
1331 |
* |
|
1332 |
* @since 2.5.0 |
|
1333 |
* |
|
1334 |
* @param string $format Link anchor format. |
|
1335 |
* @param string $link Link permalink format. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1336 |
* @param bool $in_same_cat Optional. Whether link should be in a same category. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1337 |
* @param array|string $excluded_categories Optional. Array or comma-separated list of excluded category IDs. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1338 |
* @param bool $previous Optional, default is true. Whether to display link to previous or next post. |
136 | 1339 |
*/ |
1340 |
function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) { |
|
1341 |
if ( $previous && is_attachment() ) |
|
1342 |
$post = & get_post($GLOBALS['post']->post_parent); |
|
1343 |
else |
|
1344 |
$post = get_adjacent_post($in_same_cat, $excluded_categories, $previous); |
|
1345 |
||
1346 |
if ( !$post ) |
|
1347 |
return; |
|
1348 |
||
1349 |
$title = $post->post_title; |
|
1350 |
||
1351 |
if ( empty($post->post_title) ) |
|
1352 |
$title = $previous ? __('Previous Post') : __('Next Post'); |
|
1353 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1354 |
$title = apply_filters('the_title', $title, $post->ID); |
136 | 1355 |
$date = mysql2date(get_option('date_format'), $post->post_date); |
1356 |
$rel = $previous ? 'prev' : 'next'; |
|
1357 |
||
1358 |
$string = '<a href="'.get_permalink($post).'" rel="'.$rel.'">'; |
|
1359 |
$link = str_replace('%title', $title, $link); |
|
1360 |
$link = str_replace('%date', $date, $link); |
|
1361 |
$link = $string . $link . '</a>'; |
|
1362 |
||
1363 |
$format = str_replace('%link', $link, $format); |
|
1364 |
||
1365 |
$adjacent = $previous ? 'previous' : 'next'; |
|
1366 |
echo apply_filters( "{$adjacent}_post_link", $format, $link ); |
|
1367 |
} |
|
1368 |
||
1369 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1370 |
* Retrieve links for page numbers. |
136 | 1371 |
* |
1372 |
* @since 1.5.0 |
|
1373 |
* |
|
1374 |
* @param int $pagenum Optional. Page ID. |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1375 |
* @param bool $escape Optional. Whether to escape the URL for display, with esc_url(). Defaults to true. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1376 |
* Otherwise, prepares the URL with esc_url_raw(). |
136 | 1377 |
* @return string |
1378 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1379 |
function get_pagenum_link($pagenum = 1, $escape = true ) { |
136 | 1380 |
global $wp_rewrite; |
1381 |
||
1382 |
$pagenum = (int) $pagenum; |
|
1383 |
||
1384 |
$request = remove_query_arg( 'paged' ); |
|
1385 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1386 |
$home_root = parse_url(home_url()); |
136 | 1387 |
$home_root = ( isset($home_root['path']) ) ? $home_root['path'] : ''; |
1388 |
$home_root = preg_quote( trailingslashit( $home_root ), '|' ); |
|
1389 |
||
1390 |
$request = preg_replace('|^'. $home_root . '|', '', $request); |
|
1391 |
$request = preg_replace('|^/+|', '', $request); |
|
1392 |
||
1393 |
if ( !$wp_rewrite->using_permalinks() || is_admin() ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1394 |
$base = trailingslashit( get_bloginfo( 'url' ) ); |
136 | 1395 |
|
1396 |
if ( $pagenum > 1 ) { |
|
1397 |
$result = add_query_arg( 'paged', $pagenum, $base . $request ); |
|
1398 |
} else { |
|
1399 |
$result = $base . $request; |
|
1400 |
} |
|
1401 |
} else { |
|
1402 |
$qs_regex = '|\?.*?$|'; |
|
1403 |
preg_match( $qs_regex, $request, $qs_match ); |
|
1404 |
||
1405 |
if ( !empty( $qs_match[0] ) ) { |
|
1406 |
$query_string = $qs_match[0]; |
|
1407 |
$request = preg_replace( $qs_regex, '', $request ); |
|
1408 |
} else { |
|
1409 |
$query_string = ''; |
|
1410 |
} |
|
1411 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1412 |
$request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request); |
136 | 1413 |
$request = preg_replace( '|^index\.php|', '', $request); |
1414 |
$request = ltrim($request, '/'); |
|
1415 |
||
1416 |
$base = trailingslashit( get_bloginfo( 'url' ) ); |
|
1417 |
||
1418 |
if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' != $request ) ) |
|
1419 |
$base .= 'index.php/'; |
|
1420 |
||
1421 |
if ( $pagenum > 1 ) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1422 |
$request = ( ( !empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . "/" . $pagenum, 'paged' ); |
136 | 1423 |
} |
1424 |
||
1425 |
$result = $base . $request . $query_string; |
|
1426 |
} |
|
1427 |
||
1428 |
$result = apply_filters('get_pagenum_link', $result); |
|
1429 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1430 |
if ( $escape ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1431 |
return esc_url( $result ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1432 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1433 |
return esc_url_raw( $result ); |
136 | 1434 |
} |
1435 |
||
1436 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1437 |
* Retrieve next posts page link. |
136 | 1438 |
* |
1439 |
* Backported from 2.1.3 to 2.0.10. |
|
1440 |
* |
|
1441 |
* @since 2.0.10 |
|
1442 |
* |
|
1443 |
* @param int $max_page Optional. Max pages. |
|
1444 |
* @return string |
|
1445 |
*/ |
|
1446 |
function get_next_posts_page_link($max_page = 0) { |
|
1447 |
global $paged; |
|
1448 |
||
1449 |
if ( !is_single() ) { |
|
1450 |
if ( !$paged ) |
|
1451 |
$paged = 1; |
|
1452 |
$nextpage = intval($paged) + 1; |
|
1453 |
if ( !$max_page || $max_page >= $nextpage ) |
|
1454 |
return get_pagenum_link($nextpage); |
|
1455 |
} |
|
1456 |
} |
|
1457 |
||
1458 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1459 |
* Display or return the next posts page link. |
136 | 1460 |
* |
1461 |
* @since 0.71 |
|
1462 |
* |
|
1463 |
* @param int $max_page Optional. Max pages. |
|
1464 |
* @param boolean $echo Optional. Echo or return; |
|
1465 |
*/ |
|
1466 |
function next_posts( $max_page = 0, $echo = true ) { |
|
1467 |
$output = esc_url( get_next_posts_page_link( $max_page ) ); |
|
1468 |
||
1469 |
if ( $echo ) |
|
1470 |
echo $output; |
|
1471 |
else |
|
1472 |
return $output; |
|
1473 |
} |
|
1474 |
||
1475 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1476 |
* Return the next posts page link. |
136 | 1477 |
* |
1478 |
* @since 2.7.0 |
|
1479 |
* |
|
1480 |
* @param string $label Content for link text. |
|
1481 |
* @param int $max_page Optional. Max pages. |
|
1482 |
* @return string|null |
|
1483 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1484 |
function get_next_posts_link( $label = null, $max_page = 0 ) { |
136 | 1485 |
global $paged, $wp_query; |
1486 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1487 |
if ( !$max_page ) |
136 | 1488 |
$max_page = $wp_query->max_num_pages; |
1489 |
||
1490 |
if ( !$paged ) |
|
1491 |
$paged = 1; |
|
1492 |
||
1493 |
$nextpage = intval($paged) + 1; |
|
1494 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1495 |
if ( null === $label ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1496 |
$label = __( 'Next Page »' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1497 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1498 |
if ( !is_single() && ( $nextpage <= $max_page ) ) { |
136 | 1499 |
$attr = apply_filters( 'next_posts_link_attributes', '' ); |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1500 |
return '<a href="' . next_posts( $max_page, false ) . "\" $attr>" . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', $label) . '</a>'; |
136 | 1501 |
} |
1502 |
} |
|
1503 |
||
1504 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1505 |
* Display the next posts page link. |
136 | 1506 |
* |
1507 |
* @since 0.71 |
|
1508 |
* @uses get_next_posts_link() |
|
1509 |
* |
|
1510 |
* @param string $label Content for link text. |
|
1511 |
* @param int $max_page Optional. Max pages. |
|
1512 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1513 |
function next_posts_link( $label = null, $max_page = 0 ) { |
136 | 1514 |
echo get_next_posts_link( $label, $max_page ); |
1515 |
} |
|
1516 |
||
1517 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1518 |
* Retrieve previous posts page link. |
136 | 1519 |
* |
1520 |
* Will only return string, if not on a single page or post. |
|
1521 |
* |
|
1522 |
* Backported to 2.0.10 from 2.1.3. |
|
1523 |
* |
|
1524 |
* @since 2.0.10 |
|
1525 |
* |
|
1526 |
* @return string|null |
|
1527 |
*/ |
|
1528 |
function get_previous_posts_page_link() { |
|
1529 |
global $paged; |
|
1530 |
||
1531 |
if ( !is_single() ) { |
|
1532 |
$nextpage = intval($paged) - 1; |
|
1533 |
if ( $nextpage < 1 ) |
|
1534 |
$nextpage = 1; |
|
1535 |
return get_pagenum_link($nextpage); |
|
1536 |
} |
|
1537 |
} |
|
1538 |
||
1539 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1540 |
* Display or return the previous posts page link. |
136 | 1541 |
* |
1542 |
* @since 0.71 |
|
1543 |
* |
|
1544 |
* @param boolean $echo Optional. Echo or return; |
|
1545 |
*/ |
|
1546 |
function previous_posts( $echo = true ) { |
|
1547 |
$output = esc_url( get_previous_posts_page_link() ); |
|
1548 |
||
1549 |
if ( $echo ) |
|
1550 |
echo $output; |
|
1551 |
else |
|
1552 |
return $output; |
|
1553 |
} |
|
1554 |
||
1555 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1556 |
* Return the previous posts page link. |
136 | 1557 |
* |
1558 |
* @since 2.7.0 |
|
1559 |
* |
|
1560 |
* @param string $label Optional. Previous page link text. |
|
1561 |
* @return string|null |
|
1562 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1563 |
function get_previous_posts_link( $label = null ) { |
136 | 1564 |
global $paged; |
1565 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1566 |
if ( null === $label ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1567 |
$label = __( '« Previous Page' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1568 |
|
136 | 1569 |
if ( !is_single() && $paged > 1 ) { |
1570 |
$attr = apply_filters( 'previous_posts_link_attributes', '' ); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1571 |
return '<a href="' . previous_posts( false ) . "\" $attr>". preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) .'</a>'; |
136 | 1572 |
} |
1573 |
} |
|
1574 |
||
1575 |
/** |
|
1576 |
* Display the previous posts page link. |
|
1577 |
* |
|
1578 |
* @since 0.71 |
|
1579 |
* @uses get_previous_posts_link() |
|
1580 |
* |
|
1581 |
* @param string $label Optional. Previous page link text. |
|
1582 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1583 |
function previous_posts_link( $label = null ) { |
136 | 1584 |
echo get_previous_posts_link( $label ); |
1585 |
} |
|
1586 |
||
1587 |
/** |
|
1588 |
* Return post pages link navigation for previous and next pages. |
|
1589 |
* |
|
1590 |
* @since 2.8 |
|
1591 |
* |
|
1592 |
* @param string|array $args Optional args. |
|
1593 |
* @return string The posts link navigation. |
|
1594 |
*/ |
|
1595 |
function get_posts_nav_link( $args = array() ) { |
|
1596 |
global $wp_query; |
|
1597 |
||
1598 |
$return = ''; |
|
1599 |
||
1600 |
if ( !is_singular() ) { |
|
1601 |
$defaults = array( |
|
1602 |
'sep' => ' — ', |
|
1603 |
'prelabel' => __('« Previous Page'), |
|
1604 |
'nxtlabel' => __('Next Page »'), |
|
1605 |
); |
|
1606 |
$args = wp_parse_args( $args, $defaults ); |
|
1607 |
||
1608 |
$max_num_pages = $wp_query->max_num_pages; |
|
1609 |
$paged = get_query_var('paged'); |
|
1610 |
||
1611 |
//only have sep if there's both prev and next results |
|
1612 |
if ($paged < 2 || $paged >= $max_num_pages) { |
|
1613 |
$args['sep'] = ''; |
|
1614 |
} |
|
1615 |
||
1616 |
if ( $max_num_pages > 1 ) { |
|
1617 |
$return = get_previous_posts_link($args['prelabel']); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1618 |
$return .= preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', $args['sep']); |
136 | 1619 |
$return .= get_next_posts_link($args['nxtlabel']); |
1620 |
} |
|
1621 |
} |
|
1622 |
return $return; |
|
1623 |
||
1624 |
} |
|
1625 |
||
1626 |
/** |
|
1627 |
* Display post pages link navigation for previous and next pages. |
|
1628 |
* |
|
1629 |
* @since 0.71 |
|
1630 |
* |
|
1631 |
* @param string $sep Optional. Separator for posts navigation links. |
|
1632 |
* @param string $prelabel Optional. Label for previous pages. |
|
1633 |
* @param string $nxtlabel Optional Label for next pages. |
|
1634 |
*/ |
|
1635 |
function posts_nav_link( $sep = '', $prelabel = '', $nxtlabel = '' ) { |
|
1636 |
$args = array_filter( compact('sep', 'prelabel', 'nxtlabel') ); |
|
1637 |
echo get_posts_nav_link($args); |
|
1638 |
} |
|
1639 |
||
1640 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1641 |
* Retrieve comments page number link. |
136 | 1642 |
* |
1643 |
* @since 2.7.0 |
|
1644 |
* |
|
1645 |
* @param int $pagenum Optional. Page number. |
|
1646 |
* @return string |
|
1647 |
*/ |
|
1648 |
function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) { |
|
1649 |
global $post, $wp_rewrite; |
|
1650 |
||
1651 |
$pagenum = (int) $pagenum; |
|
1652 |
||
1653 |
$result = get_permalink( $post->ID ); |
|
1654 |
||
1655 |
if ( 'newest' == get_option('default_comments_page') ) { |
|
1656 |
if ( $pagenum != $max_page ) { |
|
1657 |
if ( $wp_rewrite->using_permalinks() ) |
|
1658 |
$result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged'); |
|
1659 |
else |
|
1660 |
$result = add_query_arg( 'cpage', $pagenum, $result ); |
|
1661 |
} |
|
1662 |
} elseif ( $pagenum > 1 ) { |
|
1663 |
if ( $wp_rewrite->using_permalinks() ) |
|
1664 |
$result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged'); |
|
1665 |
else |
|
1666 |
$result = add_query_arg( 'cpage', $pagenum, $result ); |
|
1667 |
} |
|
1668 |
||
1669 |
$result .= '#comments'; |
|
1670 |
||
1671 |
$result = apply_filters('get_comments_pagenum_link', $result); |
|
1672 |
||
1673 |
return $result; |
|
1674 |
} |
|
1675 |
||
1676 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1677 |
* Return the link to next comments page. |
136 | 1678 |
* |
1679 |
* @since 2.7.1 |
|
1680 |
* |
|
1681 |
* @param string $label Optional. Label for link text. |
|
1682 |
* @param int $max_page Optional. Max page. |
|
1683 |
* @return string|null |
|
1684 |
*/ |
|
1685 |
function get_next_comments_link( $label = '', $max_page = 0 ) { |
|
1686 |
global $wp_query; |
|
1687 |
||
1688 |
if ( !is_singular() || !get_option('page_comments') ) |
|
1689 |
return; |
|
1690 |
||
1691 |
$page = get_query_var('cpage'); |
|
1692 |
||
1693 |
$nextpage = intval($page) + 1; |
|
1694 |
||
1695 |
if ( empty($max_page) ) |
|
1696 |
$max_page = $wp_query->max_num_comment_pages; |
|
1697 |
||
1698 |
if ( empty($max_page) ) |
|
1699 |
$max_page = get_comment_pages_count(); |
|
1700 |
||
1701 |
if ( $nextpage > $max_page ) |
|
1702 |
return; |
|
1703 |
||
1704 |
if ( empty($label) ) |
|
1705 |
$label = __('Newer Comments »'); |
|
1706 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1707 |
return '<a href="' . esc_url( get_comments_pagenum_link( $nextpage, $max_page ) ) . '" ' . apply_filters( 'next_comments_link_attributes', '' ) . '>'. preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', $label) .'</a>'; |
136 | 1708 |
} |
1709 |
||
1710 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1711 |
* Display the link to next comments page. |
136 | 1712 |
* |
1713 |
* @since 2.7.0 |
|
1714 |
* |
|
1715 |
* @param string $label Optional. Label for link text. |
|
1716 |
* @param int $max_page Optional. Max page. |
|
1717 |
*/ |
|
1718 |
function next_comments_link( $label = '', $max_page = 0 ) { |
|
1719 |
echo get_next_comments_link( $label, $max_page ); |
|
1720 |
} |
|
1721 |
||
1722 |
/** |
|
1723 |
* Return the previous comments page link. |
|
1724 |
* |
|
1725 |
* @since 2.7.1 |
|
1726 |
* |
|
1727 |
* @param string $label Optional. Label for comments link text. |
|
1728 |
* @return string|null |
|
1729 |
*/ |
|
1730 |
function get_previous_comments_link( $label = '' ) { |
|
1731 |
if ( !is_singular() || !get_option('page_comments') ) |
|
1732 |
return; |
|
1733 |
||
1734 |
$page = get_query_var('cpage'); |
|
1735 |
||
1736 |
if ( intval($page) <= 1 ) |
|
1737 |
return; |
|
1738 |
||
1739 |
$prevpage = intval($page) - 1; |
|
1740 |
||
1741 |
if ( empty($label) ) |
|
1742 |
$label = __('« Older Comments'); |
|
1743 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1744 |
return '<a href="' . esc_url( get_comments_pagenum_link( $prevpage ) ) . '" ' . apply_filters( 'previous_comments_link_attributes', '' ) . '>' . preg_replace('/&([^#])(?![a-z]{1,8};)/i', '&$1', $label) .'</a>'; |
136 | 1745 |
} |
1746 |
||
1747 |
/** |
|
1748 |
* Display the previous comments page link. |
|
1749 |
* |
|
1750 |
* @since 2.7.0 |
|
1751 |
* |
|
1752 |
* @param string $label Optional. Label for comments link text. |
|
1753 |
*/ |
|
1754 |
function previous_comments_link( $label = '' ) { |
|
1755 |
echo get_previous_comments_link( $label ); |
|
1756 |
} |
|
1757 |
||
1758 |
/** |
|
1759 |
* Create pagination links for the comments on the current post. |
|
1760 |
* |
|
1761 |
* @see paginate_links() |
|
1762 |
* @since 2.7.0 |
|
1763 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1764 |
* @param string|array $args Optional args. See paginate_links(). |
136 | 1765 |
* @return string Markup for pagination links. |
1766 |
*/ |
|
1767 |
function paginate_comments_links($args = array()) { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1768 |
global $wp_rewrite; |
136 | 1769 |
|
1770 |
if ( !is_singular() || !get_option('page_comments') ) |
|
1771 |
return; |
|
1772 |
||
1773 |
$page = get_query_var('cpage'); |
|
1774 |
if ( !$page ) |
|
1775 |
$page = 1; |
|
1776 |
$max_page = get_comment_pages_count(); |
|
1777 |
$defaults = array( |
|
1778 |
'base' => add_query_arg( 'cpage', '%#%' ), |
|
1779 |
'format' => '', |
|
1780 |
'total' => $max_page, |
|
1781 |
'current' => $page, |
|
1782 |
'echo' => true, |
|
1783 |
'add_fragment' => '#comments' |
|
1784 |
); |
|
1785 |
if ( $wp_rewrite->using_permalinks() ) |
|
1786 |
$defaults['base'] = user_trailingslashit(trailingslashit(get_permalink()) . 'comment-page-%#%', 'commentpaged'); |
|
1787 |
||
1788 |
$args = wp_parse_args( $args, $defaults ); |
|
1789 |
$page_links = paginate_links( $args ); |
|
1790 |
||
1791 |
if ( $args['echo'] ) |
|
1792 |
echo $page_links; |
|
1793 |
else |
|
1794 |
return $page_links; |
|
1795 |
} |
|
1796 |
||
1797 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1798 |
* Retrieve the Press This bookmarklet link. |
136 | 1799 |
* |
1800 |
* Use this in 'a' element 'href' attribute. |
|
1801 |
* |
|
1802 |
* @since 2.6.0 |
|
1803 |
* |
|
1804 |
* @return string |
|
1805 |
*/ |
|
1806 |
function get_shortcut_link() { |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1807 |
// In case of breaking changes, version this. #WP20071 |
136 | 1808 |
$link = "javascript: |
1809 |
var d=document, |
|
1810 |
w=window, |
|
1811 |
e=w.getSelection, |
|
1812 |
k=d.getSelection, |
|
1813 |
x=d.selection, |
|
1814 |
s=(e?e():(k)?k():(x?x.createRange().text:0)), |
|
1815 |
f='" . admin_url('press-this.php') . "', |
|
1816 |
l=d.location, |
|
1817 |
e=encodeURIComponent, |
|
1818 |
u=f+'?u='+e(l.href)+'&t='+e(d.title)+'&s='+e(s)+'&v=4'; |
|
1819 |
a=function(){if(!w.open(u,'t','toolbar=0,resizable=1,scrollbars=1,status=1,width=720,height=570'))l.href=u;}; |
|
1820 |
if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0); else a(); |
|
1821 |
void(0)"; |
|
1822 |
||
1823 |
$link = str_replace(array("\r", "\n", "\t"), '', $link); |
|
1824 |
||
1825 |
return apply_filters('shortcut_link', $link); |
|
1826 |
} |
|
1827 |
||
1828 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1829 |
* Retrieve the home url for the current site. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1830 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1831 |
* Returns the 'home' option with the appropriate protocol, 'https' if |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1832 |
* is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1833 |
* overridden. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1834 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1835 |
* @package WordPress |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1836 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1837 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1838 |
* @uses get_home_url() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1839 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1840 |
* @param string $path (optional) Path relative to the home url. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1841 |
* @param string $scheme (optional) Scheme to give the home url context. Currently 'http', 'https', or 'relative'. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1842 |
* @return string Home url link with optional path appended. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1843 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1844 |
function home_url( $path = '', $scheme = null ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1845 |
return get_home_url(null, $path, $scheme); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1846 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1847 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1848 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1849 |
* Retrieve the home url for a given site. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1850 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1851 |
* Returns the 'home' option with the appropriate protocol, 'https' if |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1852 |
* is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1853 |
* overridden. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1854 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1855 |
* @package WordPress |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1856 |
* @since 3.0.0 |
136 | 1857 |
* |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1858 |
* @param int $blog_id (optional) Blog ID. Defaults to current blog. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1859 |
* @param string $path (optional) Path relative to the home url. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1860 |
* @param string $scheme (optional) Scheme to give the home url context. Currently 'http', 'https', or 'relative'. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1861 |
* @return string Home url link with optional path appended. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1862 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1863 |
function get_home_url( $blog_id = null, $path = '', $scheme = null ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1864 |
$orig_scheme = $scheme; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1865 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1866 |
if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1867 |
$scheme = is_ssl() && !is_admin() ? 'https' : 'http'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1868 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1869 |
if ( empty( $blog_id ) || !is_multisite() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1870 |
$url = get_option( 'home' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1871 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1872 |
$url = get_blog_option( $blog_id, 'home' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1873 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1874 |
if ( 'relative' == $scheme ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1875 |
$url = preg_replace( '#^.+://[^/]*#', '', $url ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1876 |
elseif ( 'http' != $scheme ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1877 |
$url = str_replace( 'http://', "$scheme://", $url ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1878 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1879 |
if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1880 |
$url .= '/' . ltrim( $path, '/' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1881 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1882 |
return apply_filters( 'home_url', $url, $path, $orig_scheme, $blog_id ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1883 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1884 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1885 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1886 |
* Retrieve the site url for the current site. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1887 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1888 |
* Returns the 'site_url' option with the appropriate protocol, 'https' if |
136 | 1889 |
* is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is |
1890 |
* overridden. |
|
1891 |
* |
|
1892 |
* @package WordPress |
|
1893 |
* @since 2.6.0 |
|
1894 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1895 |
* @uses get_site_url() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1896 |
* |
136 | 1897 |
* @param string $path Optional. Path relative to the site url. |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1898 |
* @param string $scheme Optional. Scheme to give the site url context. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'. |
136 | 1899 |
* @return string Site url link with optional path appended. |
1900 |
*/ |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1901 |
function site_url( $path = '', $scheme = null ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1902 |
return get_site_url(null, $path, $scheme); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1903 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1904 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1905 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1906 |
* Retrieve the site url for a given site. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1907 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1908 |
* Returns the 'site_url' option with the appropriate protocol, 'https' if |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1909 |
* is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1910 |
* overridden. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1911 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1912 |
* @package WordPress |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1913 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1914 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1915 |
* @param int $blog_id (optional) Blog ID. Defaults to current blog. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1916 |
* @param string $path Optional. Path relative to the site url. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1917 |
* @param string $scheme Optional. Scheme to give the site url context. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1918 |
* @return string Site url link with optional path appended. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1919 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1920 |
function get_site_url( $blog_id = null, $path = '', $scheme = null ) { |
136 | 1921 |
// should the list of allowed schemes be maintained elsewhere? |
1922 |
$orig_scheme = $scheme; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1923 |
if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) { |
136 | 1924 |
if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) ) |
1925 |
$scheme = 'https'; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1926 |
elseif ( ( 'login' == $scheme ) && force_ssl_admin() ) |
136 | 1927 |
$scheme = 'https'; |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1928 |
elseif ( ( 'admin' == $scheme ) && force_ssl_admin() ) |
136 | 1929 |
$scheme = 'https'; |
1930 |
else |
|
1931 |
$scheme = ( is_ssl() ? 'https' : 'http' ); |
|
1932 |
} |
|
1933 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1934 |
if ( empty( $blog_id ) || !is_multisite() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1935 |
$url = get_option( 'siteurl' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1936 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1937 |
$url = get_blog_option( $blog_id, 'siteurl' ); |
136 | 1938 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1939 |
if ( 'relative' == $scheme ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1940 |
$url = preg_replace( '#^.+://[^/]*#', '', $url ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1941 |
elseif ( 'http' != $scheme ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1942 |
$url = str_replace( 'http://', "{$scheme}://", $url ); |
136 | 1943 |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1944 |
if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1945 |
$url .= '/' . ltrim( $path, '/' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1946 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1947 |
return apply_filters( 'site_url', $url, $path, $orig_scheme, $blog_id ); |
136 | 1948 |
} |
1949 |
||
1950 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1951 |
* Retrieve the url to the admin area for the current site. |
136 | 1952 |
* |
1953 |
* @package WordPress |
|
1954 |
* @since 2.6.0 |
|
1955 |
* |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1956 |
* @param string $path Optional path relative to the admin url. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1957 |
* @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1958 |
* @return string Admin url link with optional path appended. |
136 | 1959 |
*/ |
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1960 |
function admin_url( $path = '', $scheme = 'admin' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1961 |
return get_admin_url(null, $path, $scheme); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1962 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1963 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1964 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1965 |
* Retrieve the url to the admin area for a given site. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1966 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1967 |
* @package WordPress |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1968 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1969 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1970 |
* @param int $blog_id (optional) Blog ID. Defaults to current blog. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1971 |
* @param string $path Optional path relative to the admin url. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1972 |
* @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1973 |
* @return string Admin url link with optional path appended. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1974 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1975 |
function get_admin_url( $blog_id = null, $path = '', $scheme = 'admin' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1976 |
$url = get_site_url($blog_id, 'wp-admin/', $scheme); |
136 | 1977 |
|
1978 |
if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
|
1979 |
$url .= ltrim($path, '/'); |
|
1980 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
1981 |
return apply_filters('admin_url', $url, $path, $blog_id); |
136 | 1982 |
} |
1983 |
||
1984 |
/** |
|
1985 |
* Retrieve the url to the includes directory. |
|
1986 |
* |
|
1987 |
* @package WordPress |
|
1988 |
* @since 2.6.0 |
|
1989 |
* |
|
1990 |
* @param string $path Optional. Path relative to the includes url. |
|
1991 |
* @return string Includes url link with optional path appended. |
|
1992 |
*/ |
|
1993 |
function includes_url($path = '') { |
|
1994 |
$url = site_url() . '/' . WPINC . '/'; |
|
1995 |
||
1996 |
if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
|
1997 |
$url .= ltrim($path, '/'); |
|
1998 |
||
1999 |
return apply_filters('includes_url', $url, $path); |
|
2000 |
} |
|
2001 |
||
2002 |
/** |
|
2003 |
* Retrieve the url to the content directory. |
|
2004 |
* |
|
2005 |
* @package WordPress |
|
2006 |
* @since 2.6.0 |
|
2007 |
* |
|
2008 |
* @param string $path Optional. Path relative to the content url. |
|
2009 |
* @return string Content url link with optional path appended. |
|
2010 |
*/ |
|
2011 |
function content_url($path = '') { |
|
2012 |
$url = WP_CONTENT_URL; |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2013 |
if ( 0 === strpos($url, 'http') && is_ssl() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2014 |
$url = str_replace( 'http://', 'https://', $url ); |
136 | 2015 |
|
2016 |
if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
|
2017 |
$url .= '/' . ltrim($path, '/'); |
|
2018 |
||
2019 |
return apply_filters('content_url', $url, $path); |
|
2020 |
} |
|
2021 |
||
2022 |
/** |
|
2023 |
* Retrieve the url to the plugins directory or to a specific file within that directory. |
|
2024 |
* You can hardcode the plugin slug in $path or pass __FILE__ as a second argument to get the correct folder name. |
|
2025 |
* |
|
2026 |
* @package WordPress |
|
2027 |
* @since 2.6.0 |
|
2028 |
* |
|
2029 |
* @param string $path Optional. Path relative to the plugins url. |
|
2030 |
* @param string $plugin Optional. The plugin file that you want to be relative to - i.e. pass in __FILE__ |
|
2031 |
* @return string Plugins url link with optional path appended. |
|
2032 |
*/ |
|
2033 |
function plugins_url($path = '', $plugin = '') { |
|
2034 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2035 |
$mu_plugin_dir = WPMU_PLUGIN_DIR; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2036 |
foreach ( array('path', 'plugin', 'mu_plugin_dir') as $var ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2037 |
$$var = str_replace('\\' ,'/', $$var); // sanitize for Win32 installs |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2038 |
$$var = preg_replace('|/+|', '/', $$var); |
136 | 2039 |
} |
2040 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2041 |
if ( !empty($plugin) && 0 === strpos($plugin, $mu_plugin_dir) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2042 |
$url = WPMU_PLUGIN_URL; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2043 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2044 |
$url = WP_PLUGIN_URL; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2045 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2046 |
if ( 0 === strpos($url, 'http') && is_ssl() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2047 |
$url = str_replace( 'http://', 'https://', $url ); |
136 | 2048 |
|
2049 |
if ( !empty($plugin) && is_string($plugin) ) { |
|
2050 |
$folder = dirname(plugin_basename($plugin)); |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2051 |
if ( '.' != $folder ) |
136 | 2052 |
$url .= '/' . ltrim($folder, '/'); |
2053 |
} |
|
2054 |
||
2055 |
if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
|
2056 |
$url .= '/' . ltrim($path, '/'); |
|
2057 |
||
2058 |
return apply_filters('plugins_url', $url, $path, $plugin); |
|
2059 |
} |
|
2060 |
||
2061 |
/** |
|
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2062 |
* Retrieve the site url for the current network. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2063 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2064 |
* Returns the site url with the appropriate protocol, 'https' if |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2065 |
* is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2066 |
* overridden. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2067 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2068 |
* @package WordPress |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2069 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2070 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2071 |
* @param string $path Optional. Path relative to the site url. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2072 |
* @param string $scheme Optional. Scheme to give the site url context. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2073 |
* @return string Site url link with optional path appended. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2074 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2075 |
function network_site_url( $path = '', $scheme = null ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2076 |
global $current_site; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2077 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2078 |
if ( !is_multisite() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2079 |
return site_url($path, $scheme); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2080 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2081 |
$orig_scheme = $scheme; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2082 |
if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2083 |
if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2084 |
$scheme = 'https'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2085 |
elseif ( ('login' == $scheme) && ( force_ssl_admin() ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2086 |
$scheme = 'https'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2087 |
elseif ( ('admin' == $scheme) && force_ssl_admin() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2088 |
$scheme = 'https'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2089 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2090 |
$scheme = ( is_ssl() ? 'https' : 'http' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2091 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2092 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2093 |
if ( 'relative' == $scheme ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2094 |
$url = $current_site->path; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2095 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2096 |
$url = $scheme . '://' . $current_site->domain . $current_site->path; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2097 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2098 |
if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2099 |
$url .= ltrim($path, '/'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2100 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2101 |
return apply_filters('network_site_url', $url, $path, $orig_scheme); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2102 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2103 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2104 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2105 |
* Retrieve the home url for the current network. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2106 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2107 |
* Returns the home url with the appropriate protocol, 'https' if |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2108 |
* is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2109 |
* overridden. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2110 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2111 |
* @package WordPress |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2112 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2113 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2114 |
* @param string $path (optional) Path relative to the home url. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2115 |
* @param string $scheme (optional) Scheme to give the home url context. Currently 'http', 'https', or 'relative'. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2116 |
* @return string Home url link with optional path appended. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2117 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2118 |
function network_home_url( $path = '', $scheme = null ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2119 |
global $current_site; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2120 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2121 |
if ( !is_multisite() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2122 |
return home_url($path, $scheme); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2123 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2124 |
$orig_scheme = $scheme; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2125 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2126 |
if ( !in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2127 |
$scheme = is_ssl() && !is_admin() ? 'https' : 'http'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2128 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2129 |
if ( 'relative' == $scheme ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2130 |
$url = $current_site->path; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2131 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2132 |
$url = $scheme . '://' . $current_site->domain . $current_site->path; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2133 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2134 |
if ( !empty( $path ) && is_string( $path ) && strpos( $path, '..' ) === false ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2135 |
$url .= ltrim( $path, '/' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2136 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2137 |
return apply_filters( 'network_home_url', $url, $path, $orig_scheme); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2138 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2139 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2140 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2141 |
* Retrieve the url to the admin area for the network. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2142 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2143 |
* @package WordPress |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2144 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2145 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2146 |
* @param string $path Optional path relative to the admin url. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2147 |
* @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2148 |
* @return string Admin url link with optional path appended. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2149 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2150 |
function network_admin_url( $path = '', $scheme = 'admin' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2151 |
if ( ! is_multisite() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2152 |
return admin_url( $path, $scheme ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2153 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2154 |
$url = network_site_url('wp-admin/network/', $scheme); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2155 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2156 |
if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2157 |
$url .= ltrim($path, '/'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2158 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2159 |
return apply_filters('network_admin_url', $url, $path); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2160 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2161 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2162 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2163 |
* Retrieve the url to the admin area for the current user. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2164 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2165 |
* @package WordPress |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2166 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2167 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2168 |
* @param string $path Optional path relative to the admin url. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2169 |
* @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2170 |
* @return string Admin url link with optional path appended. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2171 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2172 |
function user_admin_url( $path = '', $scheme = 'admin' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2173 |
$url = network_site_url('wp-admin/user/', $scheme); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2174 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2175 |
if ( !empty($path) && is_string($path) && strpos($path, '..') === false ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2176 |
$url .= ltrim($path, '/'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2177 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2178 |
return apply_filters('user_admin_url', $url, $path); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2179 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2180 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2181 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2182 |
* Retrieve the url to the admin area for either the current blog or the network depending on context. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2183 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2184 |
* @package WordPress |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2185 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2186 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2187 |
* @param string $path Optional path relative to the admin url. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2188 |
* @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2189 |
* @return string Admin url link with optional path appended. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2190 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2191 |
function self_admin_url($path = '', $scheme = 'admin') { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2192 |
if ( is_network_admin() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2193 |
return network_admin_url($path, $scheme); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2194 |
elseif ( is_user_admin() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2195 |
return user_admin_url($path, $scheme); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2196 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2197 |
return admin_url($path, $scheme); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2198 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2199 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2200 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2201 |
* Set the scheme for a URL |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2202 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2203 |
* @since 3.4.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2204 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2205 |
* @param string $url Absolute url that includes a scheme |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2206 |
* @param string $scheme Optional. Scheme to give $url. Currently 'http', 'https', 'login', 'login_post', 'admin', or 'relative'. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2207 |
* @return string $url URL with chosen scheme. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2208 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2209 |
function set_url_scheme( $url, $scheme = null ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2210 |
$orig_scheme = $scheme; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2211 |
if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ) ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2212 |
if ( ( 'login_post' == $scheme || 'rpc' == $scheme ) && ( force_ssl_login() || force_ssl_admin() ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2213 |
$scheme = 'https'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2214 |
elseif ( ( 'login' == $scheme ) && force_ssl_admin() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2215 |
$scheme = 'https'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2216 |
elseif ( ( 'admin' == $scheme ) && force_ssl_admin() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2217 |
$scheme = 'https'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2218 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2219 |
$scheme = ( is_ssl() ? 'https' : 'http' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2220 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2221 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2222 |
if ( 'relative' == $scheme ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2223 |
$url = preg_replace( '#^.+://[^/]*#', '', $url ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2224 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2225 |
$url = preg_replace( '#^.+://#', $scheme . '://', $url ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2226 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2227 |
return apply_filters( 'set_url_scheme', $url, $scheme, $orig_scheme ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2228 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2229 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2230 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2231 |
* Get the URL to the user's dashboard. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2232 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2233 |
* If a user does not belong to any site, the global user dashboard is used. If the user belongs to the current site, |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2234 |
* the dashboard for the current site is returned. If the user cannot edit the current site, the dashboard to the user's |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2235 |
* primary blog is returned. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2236 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2237 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2238 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2239 |
* @param int $user_id User ID |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2240 |
* @param string $path Optional path relative to the dashboard. Use only paths known to both blog and user admins. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2241 |
* @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2242 |
* @return string Dashboard url link with optional path appended. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2243 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2244 |
function get_dashboard_url( $user_id, $path = '', $scheme = 'admin' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2245 |
$user_id = (int) $user_id; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2246 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2247 |
$blogs = get_blogs_of_user( $user_id ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2248 |
if ( ! is_super_admin() && empty($blogs) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2249 |
$url = user_admin_url( $path, $scheme ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2250 |
} elseif ( ! is_multisite() ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2251 |
$url = admin_url( $path, $scheme ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2252 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2253 |
$current_blog = get_current_blog_id(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2254 |
if ( $current_blog && ( is_super_admin( $user_id ) || in_array( $current_blog, array_keys( $blogs ) ) ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2255 |
$url = admin_url( $path, $scheme ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2256 |
} else { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2257 |
$active = get_active_blog_for_user( $user_id ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2258 |
if ( $active ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2259 |
$url = get_admin_url( $active->blog_id, $path, $scheme ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2260 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2261 |
$url = user_admin_url( $path, $scheme ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2262 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2263 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2264 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2265 |
return apply_filters( 'user_dashboard_url', $url, $user_id, $path, $scheme); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2266 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2267 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2268 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2269 |
* Get the URL to the user's profile editor. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2270 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2271 |
* @since 3.1.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2272 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2273 |
* @param int $user User ID |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2274 |
* @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2275 |
* @return string Dashboard url link with optional path appended. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2276 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2277 |
function get_edit_profile_url( $user, $scheme = 'admin' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2278 |
$user = (int) $user; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2279 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2280 |
if ( is_user_admin() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2281 |
$url = user_admin_url( 'profile.php', $scheme ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2282 |
elseif ( is_network_admin() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2283 |
$url = network_admin_url( 'profile.php', $scheme ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2284 |
else |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2285 |
$url = get_dashboard_url( $user, 'profile.php', $scheme ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2286 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2287 |
return apply_filters( 'edit_profile_url', $url, $user, $scheme); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2288 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2289 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2290 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2291 |
* Output rel=canonical for singular queries. |
136 | 2292 |
* |
2293 |
* @package WordPress |
|
2294 |
* @since 2.9.0 |
|
2295 |
*/ |
|
2296 |
function rel_canonical() { |
|
2297 |
if ( !is_singular() ) |
|
2298 |
return; |
|
2299 |
||
2300 |
global $wp_the_query; |
|
2301 |
if ( !$id = $wp_the_query->get_queried_object_id() ) |
|
2302 |
return; |
|
2303 |
||
2304 |
$link = get_permalink( $id ); |
|
2305 |
echo "<link rel='canonical' href='$link' />\n"; |
|
2306 |
} |
|
2307 |
||
194
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2308 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2309 |
* Return a shortlink for a post, page, attachment, or blog. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2310 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2311 |
* This function exists to provide a shortlink tag that all themes and plugins can target. A plugin must hook in to |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2312 |
* provide the actual shortlinks. Default shortlink support is limited to providing ?p= style links for posts. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2313 |
* Plugins can short-circuit this function via the pre_get_shortlink filter or filter the output |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2314 |
* via the get_shortlink filter. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2315 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2316 |
* @since 3.0.0. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2317 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2318 |
* @param int $id A post or blog id. Default is 0, which means the current post or blog. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2319 |
* @param string $context Whether the id is a 'blog' id, 'post' id, or 'media' id. If 'post', the post_type of the post is consulted. If 'query', the current query is consulted to determine the id and context. Default is 'post'. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2320 |
* @param bool $allow_slugs Whether to allow post slugs in the shortlink. It is up to the plugin how and whether to honor this. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2321 |
* @return string A shortlink or an empty string if no shortlink exists for the requested resource or if shortlinks are not enabled. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2322 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2323 |
function wp_get_shortlink($id = 0, $context = 'post', $allow_slugs = true) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2324 |
// Allow plugins to short-circuit this function. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2325 |
$shortlink = apply_filters('pre_get_shortlink', false, $id, $context, $allow_slugs); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2326 |
if ( false !== $shortlink ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2327 |
return $shortlink; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2328 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2329 |
global $wp_query; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2330 |
$post_id = 0; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2331 |
if ( 'query' == $context && is_single() ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2332 |
$post_id = $wp_query->get_queried_object_id(); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2333 |
} elseif ( 'post' == $context ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2334 |
$post = get_post($id); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2335 |
$post_id = $post->ID; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2336 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2337 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2338 |
$shortlink = ''; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2339 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2340 |
// Return p= link for posts. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2341 |
if ( !empty($post_id) && '' != get_option('permalink_structure') ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2342 |
$post = get_post($post_id); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2343 |
if ( isset($post->post_type) && 'post' == $post->post_type ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2344 |
$shortlink = home_url('?p=' . $post->ID); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2345 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2346 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2347 |
return apply_filters('get_shortlink', $shortlink, $id, $context, $allow_slugs); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2348 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2349 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2350 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2351 |
* Inject rel=shortlink into head if a shortlink is defined for the current page. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2352 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2353 |
* Attached to the wp_head action. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2354 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2355 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2356 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2357 |
* @uses wp_get_shortlink() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2358 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2359 |
function wp_shortlink_wp_head() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2360 |
$shortlink = wp_get_shortlink( 0, 'query' ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2361 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2362 |
if ( empty( $shortlink ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2363 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2364 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2365 |
echo "<link rel='shortlink' href='" . esc_url( $shortlink ) . "' />\n"; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2366 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2367 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2368 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2369 |
* Send a Link: rel=shortlink header if a shortlink is defined for the current page. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2370 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2371 |
* Attached to the wp action. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2372 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2373 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2374 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2375 |
* @uses wp_get_shortlink() |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2376 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2377 |
function wp_shortlink_header() { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2378 |
if ( headers_sent() ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2379 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2380 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2381 |
$shortlink = wp_get_shortlink(0, 'query'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2382 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2383 |
if ( empty($shortlink) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2384 |
return; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2385 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2386 |
header('Link: <' . $shortlink . '>; rel=shortlink', false); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2387 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2388 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2389 |
/** |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2390 |
* Display the Short Link for a Post |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2391 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2392 |
* Must be called from inside "The Loop" |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2393 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2394 |
* Call like the_shortlink(__('Shortlinkage FTW')) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2395 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2396 |
* @since 3.0.0 |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2397 |
* |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2398 |
* @param string $text Optional The link text or HTML to be displayed. Defaults to 'This is the short link.' |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2399 |
* @param string $title Optional The tooltip for the link. Must be sanitized. Defaults to the sanitized post title. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2400 |
* @param string $before Optional HTML to display before the link. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2401 |
* @param string $after Optional HTML to display after the link. |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2402 |
*/ |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2403 |
function the_shortlink( $text = '', $title = '', $before = '', $after = '' ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2404 |
global $post; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2405 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2406 |
if ( empty( $text ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2407 |
$text = __('This is the short link.'); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2408 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2409 |
if ( empty( $title ) ) |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2410 |
$title = the_title_attribute( array( 'echo' => false ) ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2411 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2412 |
$shortlink = wp_get_shortlink( $post->ID ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2413 |
|
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2414 |
if ( !empty( $shortlink ) ) { |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2415 |
$link = '<a rel="shortlink" href="' . esc_url( $shortlink ) . '" title="' . $title . '">' . $text . '</a>'; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2416 |
$link = apply_filters( 'the_shortlink', $link, $shortlink, $text, $title ); |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2417 |
echo $before, $link, $after; |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2418 |
} |
32102edaa81b
MAJ wordpress et ajout de plugin
Anthony Ly <anthonyly.com@gmail.com>
parents:
136
diff
changeset
|
2419 |
} |