author | ymh <ymh.work@gmail.com> |
Wed, 21 Sep 2022 18:19:35 +0200 | |
changeset 18 | be944660c56a |
parent 16 | a86126ab1dd4 |
child 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* WordPress Feed API |
|
4 |
* |
|
5 |
* Many of the functions used in here belong in The Loop, or The Loop for the |
|
6 |
* Feeds. |
|
7 |
* |
|
8 |
* @package WordPress |
|
9 |
* @subpackage Feed |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
10 |
* @since 2.1.0 |
0 | 11 |
*/ |
12 |
||
13 |
/** |
|
14 |
* RSS container for the bloginfo function. |
|
15 |
* |
|
16 |
* You can retrieve anything that you can using the get_bloginfo() function. |
|
17 |
* Everything will be stripped of tags and characters converted, when the values |
|
18 |
* are retrieved for use in the feeds. |
|
19 |
* |
|
20 |
* @since 1.5.1 |
|
16 | 21 |
* |
0 | 22 |
* @see get_bloginfo() For the list of possible values to display. |
23 |
* |
|
24 |
* @param string $show See get_bloginfo() for possible values. |
|
25 |
* @return string |
|
26 |
*/ |
|
9 | 27 |
function get_bloginfo_rss( $show = '' ) { |
28 |
$info = strip_tags( get_bloginfo( $show ) ); |
|
5 | 29 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
* Filters the bloginfo for use in RSS feeds. |
5 | 31 |
* |
32 |
* @since 2.2.0 |
|
33 |
* |
|
34 |
* @see convert_chars() |
|
35 |
* @see get_bloginfo() |
|
36 |
* |
|
37 |
* @param string $info Converted string value of the blog information. |
|
38 |
* @param string $show The type of blog information to retrieve. |
|
39 |
*/ |
|
40 |
return apply_filters( 'get_bloginfo_rss', convert_chars( $info ), $show ); |
|
0 | 41 |
} |
42 |
||
43 |
/** |
|
44 |
* Display RSS container for the bloginfo function. |
|
45 |
* |
|
46 |
* You can retrieve anything that you can using the get_bloginfo() function. |
|
47 |
* Everything will be stripped of tags and characters converted, when the values |
|
48 |
* are retrieved for use in the feeds. |
|
49 |
* |
|
50 |
* @since 0.71 |
|
16 | 51 |
* |
0 | 52 |
* @see get_bloginfo() For the list of possible values to display. |
53 |
* |
|
54 |
* @param string $show See get_bloginfo() for possible values. |
|
55 |
*/ |
|
9 | 56 |
function bloginfo_rss( $show = '' ) { |
5 | 57 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
58 |
* Filters the bloginfo for display in RSS feeds. |
5 | 59 |
* |
60 |
* @since 2.1.0 |
|
61 |
* |
|
62 |
* @see get_bloginfo() |
|
63 |
* |
|
64 |
* @param string $rss_container RSS container for the blog information. |
|
65 |
* @param string $show The type of blog information to retrieve. |
|
66 |
*/ |
|
67 |
echo apply_filters( 'bloginfo_rss', get_bloginfo_rss( $show ), $show ); |
|
0 | 68 |
} |
69 |
||
70 |
/** |
|
71 |
* Retrieve the default feed. |
|
72 |
* |
|
73 |
* The default feed is 'rss2', unless a plugin changes it through the |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
* {@see 'default_feed'} filter. |
0 | 75 |
* |
5 | 76 |
* @since 2.5.0 |
0 | 77 |
* |
78 |
* @return string Default feed, or for example 'rss2', 'atom', etc. |
|
79 |
*/ |
|
80 |
function get_default_feed() { |
|
5 | 81 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
82 |
* Filters the default feed type. |
5 | 83 |
* |
84 |
* @since 2.5.0 |
|
85 |
* |
|
86 |
* @param string $feed_type Type of default feed. Possible values include 'rss2', 'atom'. |
|
87 |
* Default 'rss2'. |
|
88 |
*/ |
|
89 |
$default_feed = apply_filters( 'default_feed', 'rss2' ); |
|
16 | 90 |
|
91 |
return ( 'rss' === $default_feed ) ? 'rss2' : $default_feed; |
|
0 | 92 |
} |
93 |
||
94 |
/** |
|
95 |
* Retrieve the blog title for the feed title. |
|
96 |
* |
|
97 |
* @since 2.2.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
98 |
* @since 4.4.0 The optional `$sep` parameter was deprecated and renamed to `$deprecated`. |
0 | 99 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
100 |
* @param string $deprecated Unused.. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
101 |
* @return string The document title. |
0 | 102 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
function get_wp_title_rss( $deprecated = '–' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
104 |
if ( '–' !== $deprecated ) { |
16 | 105 |
/* translators: %s: 'document_title_separator' filter name. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
106 |
_deprecated_argument( __FUNCTION__, '4.4.0', sprintf( __( 'Use the %s filter instead.' ), '<code>document_title_separator</code>' ) ); |
5 | 107 |
} |
108 |
||
109 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
110 |
* Filters the blog title for use as the feed title. |
5 | 111 |
* |
112 |
* @since 2.2.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
113 |
* @since 4.4.0 The `$sep` parameter was deprecated and renamed to `$deprecated`. |
5 | 114 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
115 |
* @param string $title The current blog title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
116 |
* @param string $deprecated Unused. |
5 | 117 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
118 |
return apply_filters( 'get_wp_title_rss', wp_get_document_title(), $deprecated ); |
0 | 119 |
} |
120 |
||
121 |
/** |
|
122 |
* Display the blog title for display of the feed title. |
|
123 |
* |
|
124 |
* @since 2.2.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
* @since 4.4.0 The optional `$sep` parameter was deprecated and renamed to `$deprecated`. |
0 | 126 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
127 |
* @param string $deprecated Unused. |
0 | 128 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
129 |
function wp_title_rss( $deprecated = '–' ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
130 |
if ( '–' !== $deprecated ) { |
16 | 131 |
/* translators: %s: 'document_title_separator' filter name. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
132 |
_deprecated_argument( __FUNCTION__, '4.4.0', sprintf( __( 'Use the %s filter instead.' ), '<code>document_title_separator</code>' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
133 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
|
5 | 135 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
* Filters the blog title for display of the feed title. |
5 | 137 |
* |
138 |
* @since 2.2.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
139 |
* @since 4.4.0 The `$sep` parameter was deprecated and renamed to `$deprecated`. |
5 | 140 |
* |
141 |
* @see get_wp_title_rss() |
|
142 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
143 |
* @param string $wp_title_rss The current blog title. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
144 |
* @param string $deprecated Unused. |
5 | 145 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
146 |
echo apply_filters( 'wp_title_rss', get_wp_title_rss(), $deprecated ); |
0 | 147 |
} |
148 |
||
149 |
/** |
|
150 |
* Retrieve the current post title for the feed. |
|
151 |
* |
|
152 |
* @since 2.0.0 |
|
153 |
* |
|
154 |
* @return string Current post title. |
|
155 |
*/ |
|
156 |
function get_the_title_rss() { |
|
157 |
$title = get_the_title(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
158 |
|
5 | 159 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
160 |
* Filters the post title for use in a feed. |
5 | 161 |
* |
162 |
* @since 1.2.0 |
|
163 |
* |
|
164 |
* @param string $title The current post title. |
|
165 |
*/ |
|
16 | 166 |
return apply_filters( 'the_title_rss', $title ); |
0 | 167 |
} |
168 |
||
169 |
/** |
|
170 |
* Display the post title in the feed. |
|
171 |
* |
|
172 |
* @since 0.71 |
|
173 |
*/ |
|
174 |
function the_title_rss() { |
|
175 |
echo get_the_title_rss(); |
|
176 |
} |
|
177 |
||
178 |
/** |
|
179 |
* Retrieve the post content for feeds. |
|
180 |
* |
|
181 |
* @since 2.9.0 |
|
16 | 182 |
* |
0 | 183 |
* @see get_the_content() |
184 |
* |
|
185 |
* @param string $feed_type The type of feed. rss2 | atom | rss | rdf |
|
186 |
* @return string The filtered content. |
|
187 |
*/ |
|
9 | 188 |
function get_the_content_feed( $feed_type = null ) { |
189 |
if ( ! $feed_type ) { |
|
0 | 190 |
$feed_type = get_default_feed(); |
9 | 191 |
} |
0 | 192 |
|
5 | 193 |
/** This filter is documented in wp-includes/post-template.php */ |
194 |
$content = apply_filters( 'the_content', get_the_content() ); |
|
9 | 195 |
$content = str_replace( ']]>', ']]>', $content ); |
16 | 196 |
|
5 | 197 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
198 |
* Filters the post content for use in feeds. |
5 | 199 |
* |
200 |
* @since 2.9.0 |
|
201 |
* |
|
202 |
* @param string $content The current post content. |
|
203 |
* @param string $feed_type Type of feed. Possible values include 'rss2', 'atom'. |
|
204 |
* Default 'rss2'. |
|
205 |
*/ |
|
206 |
return apply_filters( 'the_content_feed', $content, $feed_type ); |
|
0 | 207 |
} |
208 |
||
209 |
/** |
|
210 |
* Display the post content for feeds. |
|
211 |
* |
|
212 |
* @since 2.9.0 |
|
213 |
* |
|
214 |
* @param string $feed_type The type of feed. rss2 | atom | rss | rdf |
|
215 |
*/ |
|
9 | 216 |
function the_content_feed( $feed_type = null ) { |
217 |
echo get_the_content_feed( $feed_type ); |
|
0 | 218 |
} |
219 |
||
220 |
/** |
|
221 |
* Display the post excerpt for the feed. |
|
222 |
* |
|
223 |
* @since 0.71 |
|
224 |
*/ |
|
225 |
function the_excerpt_rss() { |
|
226 |
$output = get_the_excerpt(); |
|
5 | 227 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
228 |
* Filters the post excerpt for a feed. |
5 | 229 |
* |
230 |
* @since 1.2.0 |
|
231 |
* |
|
232 |
* @param string $output The current post excerpt. |
|
233 |
*/ |
|
234 |
echo apply_filters( 'the_excerpt_rss', $output ); |
|
0 | 235 |
} |
236 |
||
237 |
/** |
|
238 |
* Display the permalink to the post for use in feeds. |
|
239 |
* |
|
240 |
* @since 2.3.0 |
|
241 |
*/ |
|
242 |
function the_permalink_rss() { |
|
5 | 243 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
244 |
* Filters the permalink to the post for use in feeds. |
5 | 245 |
* |
246 |
* @since 2.3.0 |
|
247 |
* |
|
248 |
* @param string $post_permalink The current post permalink. |
|
249 |
*/ |
|
250 |
echo esc_url( apply_filters( 'the_permalink_rss', get_permalink() ) ); |
|
0 | 251 |
} |
252 |
||
253 |
/** |
|
254 |
* Outputs the link to the comments for the current post in an xml safe way |
|
255 |
* |
|
256 |
* @since 3.0.0 |
|
257 |
*/ |
|
258 |
function comments_link_feed() { |
|
5 | 259 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
260 |
* Filters the comments permalink for the current post. |
5 | 261 |
* |
262 |
* @since 3.6.0 |
|
263 |
* |
|
264 |
* @param string $comment_permalink The current comment permalink with |
|
265 |
* '#comments' appended. |
|
266 |
*/ |
|
0 | 267 |
echo esc_url( apply_filters( 'comments_link_feed', get_comments_link() ) ); |
268 |
} |
|
269 |
||
270 |
/** |
|
271 |
* Display the feed GUID for the current comment. |
|
272 |
* |
|
273 |
* @since 2.5.0 |
|
274 |
* |
|
16 | 275 |
* @param int|WP_Comment $comment_id Optional comment object or ID. Defaults to global comment object. |
0 | 276 |
*/ |
9 | 277 |
function comment_guid( $comment_id = null ) { |
278 |
echo esc_url( get_comment_guid( $comment_id ) ); |
|
0 | 279 |
} |
280 |
||
281 |
/** |
|
282 |
* Retrieve the feed GUID for the current comment. |
|
283 |
* |
|
284 |
* @since 2.5.0 |
|
285 |
* |
|
16 | 286 |
* @param int|WP_Comment $comment_id Optional comment object or ID. Defaults to global comment object. |
287 |
* @return string|false GUID for comment on success, false on failure. |
|
0 | 288 |
*/ |
9 | 289 |
function get_comment_guid( $comment_id = null ) { |
290 |
$comment = get_comment( $comment_id ); |
|
0 | 291 |
|
9 | 292 |
if ( ! is_object( $comment ) ) { |
0 | 293 |
return false; |
9 | 294 |
} |
0 | 295 |
|
9 | 296 |
return get_the_guid( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID; |
0 | 297 |
} |
298 |
||
299 |
/** |
|
300 |
* Display the link to the comments. |
|
301 |
* |
|
302 |
* @since 1.5.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
303 |
* @since 4.4.0 Introduced the `$comment` argument. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
304 |
* |
16 | 305 |
* @param int|WP_Comment $comment Optional. Comment object or ID. Defaults to global comment object. |
0 | 306 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
307 |
function comment_link( $comment = null ) { |
5 | 308 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
309 |
* Filters the current comment's permalink. |
5 | 310 |
* |
311 |
* @since 3.6.0 |
|
312 |
* |
|
313 |
* @see get_comment_link() |
|
314 |
* |
|
315 |
* @param string $comment_permalink The current comment permalink. |
|
316 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
317 |
echo esc_url( apply_filters( 'comment_link', get_comment_link( $comment ) ) ); |
0 | 318 |
} |
319 |
||
320 |
/** |
|
321 |
* Retrieve the current comment author for use in the feeds. |
|
322 |
* |
|
323 |
* @since 2.0.0 |
|
324 |
* |
|
325 |
* @return string Comment Author |
|
326 |
*/ |
|
327 |
function get_comment_author_rss() { |
|
5 | 328 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
329 |
* Filters the current comment author for use in a feed. |
5 | 330 |
* |
331 |
* @since 1.5.0 |
|
332 |
* |
|
333 |
* @see get_comment_author() |
|
334 |
* |
|
335 |
* @param string $comment_author The current comment author. |
|
336 |
*/ |
|
337 |
return apply_filters( 'comment_author_rss', get_comment_author() ); |
|
0 | 338 |
} |
339 |
||
340 |
/** |
|
341 |
* Display the current comment author in the feed. |
|
342 |
* |
|
343 |
* @since 1.0.0 |
|
344 |
*/ |
|
345 |
function comment_author_rss() { |
|
346 |
echo get_comment_author_rss(); |
|
347 |
} |
|
348 |
||
349 |
/** |
|
350 |
* Display the current comment content for use in the feeds. |
|
351 |
* |
|
352 |
* @since 1.0.0 |
|
353 |
*/ |
|
354 |
function comment_text_rss() { |
|
355 |
$comment_text = get_comment_text(); |
|
5 | 356 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
357 |
* Filters the current comment content for use in a feed. |
5 | 358 |
* |
359 |
* @since 1.5.0 |
|
360 |
* |
|
361 |
* @param string $comment_text The content of the current comment. |
|
362 |
*/ |
|
363 |
$comment_text = apply_filters( 'comment_text_rss', $comment_text ); |
|
0 | 364 |
echo $comment_text; |
365 |
} |
|
366 |
||
367 |
/** |
|
368 |
* Retrieve all of the post categories, formatted for use in feeds. |
|
369 |
* |
|
370 |
* All of the categories for the current post in the feed loop, will be |
|
371 |
* retrieved and have feed markup added, so that they can easily be added to the |
|
372 |
* RSS2, Atom, or RSS1 and RSS0.91 RDF feeds. |
|
373 |
* |
|
374 |
* @since 2.1.0 |
|
375 |
* |
|
376 |
* @param string $type Optional, default is the type returned by get_default_feed(). |
|
377 |
* @return string All of the post categories for displaying in the feed. |
|
378 |
*/ |
|
9 | 379 |
function get_the_category_rss( $type = null ) { |
380 |
if ( empty( $type ) ) { |
|
0 | 381 |
$type = get_default_feed(); |
9 | 382 |
} |
0 | 383 |
$categories = get_the_category(); |
9 | 384 |
$tags = get_the_tags(); |
385 |
$the_list = ''; |
|
386 |
$cat_names = array(); |
|
0 | 387 |
|
388 |
$filter = 'rss'; |
|
16 | 389 |
if ( 'atom' === $type ) { |
0 | 390 |
$filter = 'raw'; |
9 | 391 |
} |
0 | 392 |
|
9 | 393 |
if ( ! empty( $categories ) ) { |
394 |
foreach ( (array) $categories as $category ) { |
|
395 |
$cat_names[] = sanitize_term_field( 'name', $category->name, $category->term_id, 'category', $filter ); |
|
396 |
} |
|
0 | 397 |
} |
398 |
||
9 | 399 |
if ( ! empty( $tags ) ) { |
400 |
foreach ( (array) $tags as $tag ) { |
|
401 |
$cat_names[] = sanitize_term_field( 'name', $tag->name, $tag->term_id, 'post_tag', $filter ); |
|
402 |
} |
|
0 | 403 |
} |
404 |
||
9 | 405 |
$cat_names = array_unique( $cat_names ); |
0 | 406 |
|
407 |
foreach ( $cat_names as $cat_name ) { |
|
16 | 408 |
if ( 'rdf' === $type ) { |
0 | 409 |
$the_list .= "\t\t<dc:subject><![CDATA[$cat_name]]></dc:subject>\n"; |
16 | 410 |
} elseif ( 'atom' === $type ) { |
5 | 411 |
$the_list .= sprintf( '<category scheme="%1$s" term="%2$s" />', esc_attr( get_bloginfo_rss( 'url' ) ), esc_attr( $cat_name ) ); |
9 | 412 |
} else { |
16 | 413 |
$the_list .= "\t\t<category><![CDATA[" . html_entity_decode( $cat_name, ENT_COMPAT, get_option( 'blog_charset' ) ) . "]]></category>\n"; |
9 | 414 |
} |
0 | 415 |
} |
416 |
||
5 | 417 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
418 |
* Filters all of the post categories for display in a feed. |
5 | 419 |
* |
420 |
* @since 1.2.0 |
|
421 |
* |
|
422 |
* @param string $the_list All of the RSS post categories. |
|
423 |
* @param string $type Type of feed. Possible values include 'rss2', 'atom'. |
|
424 |
* Default 'rss2'. |
|
425 |
*/ |
|
426 |
return apply_filters( 'the_category_rss', $the_list, $type ); |
|
0 | 427 |
} |
428 |
||
429 |
/** |
|
430 |
* Display the post categories in the feed. |
|
431 |
* |
|
432 |
* @since 0.71 |
|
16 | 433 |
* |
0 | 434 |
* @see get_the_category_rss() For better explanation. |
435 |
* |
|
436 |
* @param string $type Optional, default is the type returned by get_default_feed(). |
|
437 |
*/ |
|
9 | 438 |
function the_category_rss( $type = null ) { |
439 |
echo get_the_category_rss( $type ); |
|
0 | 440 |
} |
441 |
||
442 |
/** |
|
443 |
* Display the HTML type based on the blog setting. |
|
444 |
* |
|
445 |
* The two possible values are either 'xhtml' or 'html'. |
|
446 |
* |
|
447 |
* @since 2.2.0 |
|
448 |
*/ |
|
449 |
function html_type_rss() { |
|
9 | 450 |
$type = get_bloginfo( 'html_type' ); |
451 |
if ( strpos( $type, 'xhtml' ) !== false ) { |
|
0 | 452 |
$type = 'xhtml'; |
9 | 453 |
} else { |
0 | 454 |
$type = 'html'; |
9 | 455 |
} |
0 | 456 |
echo $type; |
457 |
} |
|
458 |
||
459 |
/** |
|
460 |
* Display the rss enclosure for the current post. |
|
461 |
* |
|
462 |
* Uses the global $post to check whether the post requires a password and if |
|
463 |
* the user has the password for the post. If not then it will return before |
|
464 |
* displaying. |
|
465 |
* |
|
466 |
* Also uses the function get_post_custom() to get the post's 'enclosure' |
|
467 |
* metadata field and parses the value to display the enclosure(s). The |
|
468 |
* enclosure(s) consist of enclosure HTML tag(s) with a URI and other |
|
469 |
* attributes. |
|
470 |
* |
|
471 |
* @since 1.5.0 |
|
472 |
*/ |
|
473 |
function rss_enclosure() { |
|
9 | 474 |
if ( post_password_required() ) { |
0 | 475 |
return; |
9 | 476 |
} |
0 | 477 |
|
9 | 478 |
foreach ( (array) get_post_custom() as $key => $val ) { |
16 | 479 |
if ( 'enclosure' === $key ) { |
0 | 480 |
foreach ( (array) $val as $enc ) { |
9 | 481 |
$enclosure = explode( "\n", $enc ); |
0 | 482 |
|
16 | 483 |
// Only get the first element, e.g. 'audio/mpeg' from 'audio/mpeg mpga mp2 mp3'. |
9 | 484 |
$t = preg_split( '/[ \t]/', trim( $enclosure[2] ) ); |
0 | 485 |
$type = $t[0]; |
486 |
||
5 | 487 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
488 |
* Filters the RSS enclosure HTML link tag for the current post. |
5 | 489 |
* |
490 |
* @since 2.2.0 |
|
491 |
* |
|
492 |
* @param string $html_link_tag The HTML link tag with a URI and other attributes. |
|
493 |
*/ |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
494 |
echo apply_filters( 'rss_enclosure', '<enclosure url="' . esc_url( trim( $enclosure[0] ) ) . '" length="' . absint( trim( $enclosure[1] ) ) . '" type="' . esc_attr( $type ) . '" />' . "\n" ); |
0 | 495 |
} |
496 |
} |
|
497 |
} |
|
498 |
} |
|
499 |
||
500 |
/** |
|
501 |
* Display the atom enclosure for the current post. |
|
502 |
* |
|
503 |
* Uses the global $post to check whether the post requires a password and if |
|
504 |
* the user has the password for the post. If not then it will return before |
|
505 |
* displaying. |
|
506 |
* |
|
507 |
* Also uses the function get_post_custom() to get the post's 'enclosure' |
|
508 |
* metadata field and parses the value to display the enclosure(s). The |
|
509 |
* enclosure(s) consist of link HTML tag(s) with a URI and other attributes. |
|
510 |
* |
|
511 |
* @since 2.2.0 |
|
512 |
*/ |
|
513 |
function atom_enclosure() { |
|
9 | 514 |
if ( post_password_required() ) { |
0 | 515 |
return; |
9 | 516 |
} |
0 | 517 |
|
518 |
foreach ( (array) get_post_custom() as $key => $val ) { |
|
16 | 519 |
if ( 'enclosure' === $key ) { |
0 | 520 |
foreach ( (array) $val as $enc ) { |
9 | 521 |
$enclosure = explode( "\n", $enc ); |
16 | 522 |
|
523 |
$url = ''; |
|
524 |
$type = ''; |
|
525 |
$length = 0; |
|
526 |
||
527 |
$mimes = get_allowed_mime_types(); |
|
528 |
||
529 |
// Parse URL. |
|
530 |
if ( isset( $enclosure[0] ) && is_string( $enclosure[0] ) ) { |
|
531 |
$url = trim( $enclosure[0] ); |
|
532 |
} |
|
533 |
||
534 |
// Parse length and type. |
|
535 |
for ( $i = 1; $i <= 2; $i++ ) { |
|
536 |
if ( isset( $enclosure[ $i ] ) ) { |
|
537 |
if ( is_numeric( $enclosure[ $i ] ) ) { |
|
538 |
$length = trim( $enclosure[ $i ] ); |
|
539 |
} elseif ( in_array( $enclosure[ $i ], $mimes, true ) ) { |
|
540 |
$type = trim( $enclosure[ $i ] ); |
|
541 |
} |
|
542 |
} |
|
543 |
} |
|
544 |
||
545 |
$html_link_tag = sprintf( |
|
546 |
"<link href=\"%s\" rel=\"enclosure\" length=\"%d\" type=\"%s\" />\n", |
|
547 |
esc_url( $url ), |
|
548 |
esc_attr( $length ), |
|
549 |
esc_attr( $type ) |
|
550 |
); |
|
551 |
||
5 | 552 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
553 |
* Filters the atom enclosure HTML link tag for the current post. |
5 | 554 |
* |
555 |
* @since 2.2.0 |
|
556 |
* |
|
557 |
* @param string $html_link_tag The HTML link tag with a URI and other attributes. |
|
558 |
*/ |
|
16 | 559 |
echo apply_filters( 'atom_enclosure', $html_link_tag ); |
0 | 560 |
} |
561 |
} |
|
562 |
} |
|
563 |
} |
|
564 |
||
565 |
/** |
|
566 |
* Determine the type of a string of data with the data formatted. |
|
567 |
* |
|
16 | 568 |
* Tell whether the type is text, HTML, or XHTML, per RFC 4287 section 3.1. |
0 | 569 |
* |
570 |
* In the case of WordPress, text is defined as containing no markup, |
|
16 | 571 |
* XHTML is defined as "well formed", and HTML as tag soup (i.e., the rest). |
0 | 572 |
* |
16 | 573 |
* Container div tags are added to XHTML values, per section 3.1.1.3. |
0 | 574 |
* |
575 |
* @link http://www.atomenabled.org/developers/syndication/atom-format-spec.php#rfc.section.3.1 |
|
576 |
* |
|
5 | 577 |
* @since 2.5.0 |
0 | 578 |
* |
579 |
* @param string $data Input string |
|
580 |
* @return array array(type, value) |
|
581 |
*/ |
|
9 | 582 |
function prep_atom_text_construct( $data ) { |
583 |
if ( strpos( $data, '<' ) === false && strpos( $data, '&' ) === false ) { |
|
584 |
return array( 'text', $data ); |
|
0 | 585 |
} |
586 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
587 |
if ( ! function_exists( 'xml_parser_create' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
588 |
trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
589 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
590 |
return array( 'html', "<![CDATA[$data]]>" ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
591 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
592 |
|
0 | 593 |
$parser = xml_parser_create(); |
9 | 594 |
xml_parse( $parser, '<div>' . $data . '</div>', true ); |
595 |
$code = xml_get_error_code( $parser ); |
|
596 |
xml_parser_free( $parser ); |
|
16 | 597 |
unset( $parser ); |
0 | 598 |
|
9 | 599 |
if ( ! $code ) { |
600 |
if ( strpos( $data, '<' ) === false ) { |
|
601 |
return array( 'text', $data ); |
|
0 | 602 |
} else { |
603 |
$data = "<div xmlns='http://www.w3.org/1999/xhtml'>$data</div>"; |
|
9 | 604 |
return array( 'xhtml', $data ); |
0 | 605 |
} |
606 |
} |
|
607 |
||
9 | 608 |
if ( strpos( $data, ']]>' ) === false ) { |
609 |
return array( 'html', "<![CDATA[$data]]>" ); |
|
0 | 610 |
} else { |
9 | 611 |
return array( 'html', htmlspecialchars( $data ) ); |
0 | 612 |
} |
613 |
} |
|
614 |
||
615 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
616 |
* Displays Site Icon in atom feeds. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
617 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
618 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
619 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
620 |
* @see get_site_icon_url() |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
621 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
622 |
function atom_site_icon() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
623 |
$url = get_site_icon_url( 32 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
624 |
if ( $url ) { |
16 | 625 |
echo '<icon>' . convert_chars( $url ) . "</icon>\n"; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
626 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
627 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
628 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
629 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
630 |
* Displays Site Icon in RSS2. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
631 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
632 |
* @since 4.3.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
633 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
634 |
function rss2_site_icon() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
635 |
$rss_title = get_wp_title_rss(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
636 |
if ( empty( $rss_title ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
637 |
$rss_title = get_bloginfo_rss( 'name' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
638 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
639 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
640 |
$url = get_site_icon_url( 32 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
641 |
if ( $url ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
642 |
echo ' |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
643 |
<image> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
644 |
<url>' . convert_chars( $url ) . '</url> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
645 |
<title>' . $rss_title . '</title> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
646 |
<link>' . get_bloginfo_rss( 'url' ) . '</link> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
647 |
<width>32</width> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
648 |
<height>32</height> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
649 |
</image> ' . "\n"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
650 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
651 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
652 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
653 |
/** |
16 | 654 |
* Returns the link for the currently displayed feed. |
655 |
* |
|
656 |
* @since 5.3.0 |
|
657 |
* |
|
658 |
* @return string Correct link for the atom:self element. |
|
659 |
*/ |
|
660 |
function get_self_link() { |
|
661 |
$host = parse_url( home_url() ); |
|
662 |
return set_url_scheme( 'http://' . $host['host'] . wp_unslash( $_SERVER['REQUEST_URI'] ) ); |
|
663 |
} |
|
664 |
||
665 |
/** |
|
0 | 666 |
* Display the link for the currently displayed feed in a XSS safe way. |
667 |
* |
|
668 |
* Generate a correct link for the atom:self element. |
|
669 |
* |
|
5 | 670 |
* @since 2.5.0 |
0 | 671 |
*/ |
672 |
function self_link() { |
|
5 | 673 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
674 |
* Filters the current feed URL. |
5 | 675 |
* |
676 |
* @since 3.6.0 |
|
677 |
* |
|
678 |
* @see set_url_scheme() |
|
679 |
* @see wp_unslash() |
|
680 |
* |
|
681 |
* @param string $feed_link The link for the feed with set URL scheme. |
|
682 |
*/ |
|
16 | 683 |
echo esc_url( apply_filters( 'self_link', get_self_link() ) ); |
0 | 684 |
} |
685 |
||
16 | 686 |
/** |
687 |
* Get the UTC time of the most recently modified post from WP_Query. |
|
9 | 688 |
* |
16 | 689 |
* If viewing a comment feed, the time of the most recently modified |
9 | 690 |
* comment will be returned. |
691 |
* |
|
16 | 692 |
* @global WP_Query $wp_query WordPress Query object. |
9 | 693 |
* |
694 |
* @since 5.2.0 |
|
695 |
* |
|
16 | 696 |
* @param string $format Date format string to return the time in. |
697 |
* @return string|false The time in requested format, or false on failure. |
|
9 | 698 |
*/ |
699 |
function get_feed_build_date( $format ) { |
|
700 |
global $wp_query; |
|
701 |
||
16 | 702 |
$datetime = false; |
703 |
$max_modified_time = false; |
|
704 |
$utc = new DateTimeZone( 'UTC' ); |
|
705 |
||
706 |
if ( ! empty( $wp_query ) && $wp_query->have_posts() ) { |
|
707 |
// Extract the post modified times from the posts. |
|
708 |
$modified_times = wp_list_pluck( $wp_query->posts, 'post_modified_gmt' ); |
|
709 |
||
710 |
// If this is a comment feed, check those objects too. |
|
711 |
if ( $wp_query->is_comment_feed() && $wp_query->comment_count ) { |
|
712 |
// Extract the comment modified times from the comments. |
|
713 |
$comment_times = wp_list_pluck( $wp_query->comments, 'comment_date_gmt' ); |
|
714 |
||
715 |
// Add the comment times to the post times for comparison. |
|
716 |
$modified_times = array_merge( $modified_times, $comment_times ); |
|
717 |
} |
|
718 |
||
719 |
// Determine the maximum modified time. |
|
720 |
$datetime = date_create_immutable_from_format( 'Y-m-d H:i:s', max( $modified_times ), $utc ); |
|
9 | 721 |
} |
722 |
||
16 | 723 |
if ( false === $datetime ) { |
724 |
// Fall back to last time any post was modified or published. |
|
725 |
$datetime = date_create_immutable_from_format( 'Y-m-d H:i:s', get_lastpostmodified( 'GMT' ), $utc ); |
|
9 | 726 |
} |
727 |
||
16 | 728 |
if ( false !== $datetime ) { |
729 |
$max_modified_time = $datetime->format( $format ); |
|
730 |
} |
|
9 | 731 |
|
732 |
/** |
|
733 |
* Filters the date the last post or comment in the query was modified. |
|
734 |
* |
|
735 |
* @since 5.2.0 |
|
736 |
* |
|
16 | 737 |
* @param string|false $max_modified_time Date the last post or comment was modified in the query, in UTC. |
738 |
* False on failure. |
|
739 |
* @param string $format The date format requested in get_feed_build_date(). |
|
9 | 740 |
*/ |
741 |
return apply_filters( 'get_feed_build_date', $max_modified_time, $format ); |
|
742 |
} |
|
743 |
||
0 | 744 |
/** |
745 |
* Return the content type for specified feed type. |
|
746 |
* |
|
747 |
* @since 2.8.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
748 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
749 |
* @param string $type Type of feed. Possible values include 'rss', rss2', 'atom', and 'rdf'. |
0 | 750 |
*/ |
751 |
function feed_content_type( $type = '' ) { |
|
9 | 752 |
if ( empty( $type ) ) { |
0 | 753 |
$type = get_default_feed(); |
9 | 754 |
} |
0 | 755 |
|
756 |
$types = array( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
757 |
'rss' => 'application/rss+xml', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
758 |
'rss2' => 'application/rss+xml', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
759 |
'rss-http' => 'text/xml', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
760 |
'atom' => 'application/atom+xml', |
9 | 761 |
'rdf' => 'application/rdf+xml', |
0 | 762 |
); |
763 |
||
9 | 764 |
$content_type = ( ! empty( $types[ $type ] ) ) ? $types[ $type ] : 'application/octet-stream'; |
0 | 765 |
|
5 | 766 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
767 |
* Filters the content type for a specific feed type. |
5 | 768 |
* |
769 |
* @since 2.8.0 |
|
770 |
* |
|
771 |
* @param string $content_type Content type indicating the type of data that a feed contains. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
772 |
* @param string $type Type of feed. Possible values include 'rss', rss2', 'atom', and 'rdf'. |
5 | 773 |
*/ |
0 | 774 |
return apply_filters( 'feed_content_type', $content_type, $type ); |
775 |
} |
|
776 |
||
777 |
/** |
|
778 |
* Build SimplePie object based on RSS or Atom feed from URL. |
|
779 |
* |
|
5 | 780 |
* @since 2.8.0 |
0 | 781 |
* |
16 | 782 |
* @param string|string[] $url URL of feed to retrieve. If an array of URLs, the feeds are merged |
783 |
* using SimplePie's multifeed feature. |
|
784 |
* See also {@link http://simplepie.org/wiki/faq/typical_multifeed_gotchas} |
|
785 |
* @return SimplePie|WP_Error SimplePie object on success or WP_Error object on failure. |
|
0 | 786 |
*/ |
787 |
function fetch_feed( $url ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
788 |
if ( ! class_exists( 'SimplePie', false ) ) { |
16 | 789 |
require_once ABSPATH . WPINC . '/class-simplepie.php'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
790 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
791 |
|
16 | 792 |
require_once ABSPATH . WPINC . '/class-wp-feed-cache-transient.php'; |
793 |
require_once ABSPATH . WPINC . '/class-wp-simplepie-file.php'; |
|
794 |
require_once ABSPATH . WPINC . '/class-wp-simplepie-sanitize-kses.php'; |
|
0 | 795 |
|
796 |
$feed = new SimplePie(); |
|
797 |
||
798 |
$feed->set_sanitize_class( 'WP_SimplePie_Sanitize_KSES' ); |
|
18 | 799 |
// We must manually overwrite $feed->sanitize because SimplePie's constructor |
800 |
// sets it before we have a chance to set the sanitization class. |
|
0 | 801 |
$feed->sanitize = new WP_SimplePie_Sanitize_KSES(); |
802 |
||
18 | 803 |
// Register the cache handler using the recommended method for SimplePie 1.3 or later. |
804 |
if ( method_exists( 'SimplePie_Cache', 'register' ) ) { |
|
805 |
SimplePie_Cache::register( 'wp_transient', 'WP_Feed_Cache_Transient' ); |
|
806 |
$feed->set_cache_location( 'wp_transient' ); |
|
807 |
} else { |
|
808 |
// Back-compat for SimplePie 1.2.x. |
|
809 |
require_once ABSPATH . WPINC . '/class-wp-feed-cache.php'; |
|
810 |
$feed->set_cache_class( 'WP_Feed_Cache' ); |
|
811 |
} |
|
812 |
||
0 | 813 |
$feed->set_file_class( 'WP_SimplePie_File' ); |
814 |
||
815 |
$feed->set_feed_url( $url ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
816 |
/** This filter is documented in wp-includes/class-wp-feed-cache-transient.php */ |
0 | 817 |
$feed->set_cache_duration( apply_filters( 'wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url ) ); |
16 | 818 |
|
5 | 819 |
/** |
820 |
* Fires just before processing the SimplePie feed object. |
|
821 |
* |
|
822 |
* @since 3.0.0 |
|
823 |
* |
|
16 | 824 |
* @param SimplePie $feed SimplePie feed object (passed by reference). |
825 |
* @param string|string[] $url URL of feed or array of URLs of feeds to retrieve. |
|
5 | 826 |
*/ |
0 | 827 |
do_action_ref_array( 'wp_feed_options', array( &$feed, $url ) ); |
16 | 828 |
|
0 | 829 |
$feed->init(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
830 |
$feed->set_output_encoding( get_option( 'blog_charset' ) ); |
0 | 831 |
|
9 | 832 |
if ( $feed->error() ) { |
0 | 833 |
return new WP_Error( 'simplepie-error', $feed->error() ); |
9 | 834 |
} |
0 | 835 |
|
836 |
return $feed; |
|
837 |
} |