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