37 * |
37 * |
38 * @since 2.2.0 |
38 * @since 2.2.0 |
39 * |
39 * |
40 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
40 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
41 * |
41 * |
42 * @param string $string URL with or without a trailing slash. |
42 * @param string $url URL with or without a trailing slash. |
43 * @param string $type_of_url Optional. The type of URL being considered (e.g. single, category, etc) |
43 * @param string $type_of_url Optional. The type of URL being considered (e.g. single, category, etc) |
44 * for use in the filter. Default empty string. |
44 * for use in the filter. Default empty string. |
45 * @return string The URL with the trailing slash appended or stripped. |
45 * @return string The URL with the trailing slash appended or stripped. |
46 */ |
46 */ |
47 function user_trailingslashit( $string, $type_of_url = '' ) { |
47 function user_trailingslashit( $url, $type_of_url = '' ) { |
48 global $wp_rewrite; |
48 global $wp_rewrite; |
49 if ( $wp_rewrite->use_trailing_slashes ) { |
49 if ( $wp_rewrite->use_trailing_slashes ) { |
50 $string = trailingslashit( $string ); |
50 $url = trailingslashit( $url ); |
51 } else { |
51 } else { |
52 $string = untrailingslashit( $string ); |
52 $url = untrailingslashit( $url ); |
53 } |
53 } |
54 |
54 |
55 /** |
55 /** |
56 * Filters the trailing-slashed string, depending on whether the site is set to use trailing slashes. |
56 * Filters the trailing-slashed string, depending on whether the site is set to use trailing slashes. |
57 * |
57 * |
58 * @since 2.2.0 |
58 * @since 2.2.0 |
59 * |
59 * |
60 * @param string $string URL with or without a trailing slash. |
60 * @param string $url URL with or without a trailing slash. |
61 * @param string $type_of_url The type of URL being considered. Accepts 'single', 'single_trackback', |
61 * @param string $type_of_url The type of URL being considered. Accepts 'single', 'single_trackback', |
62 * 'single_feed', 'single_paged', 'commentpaged', 'paged', 'home', 'feed', |
62 * 'single_feed', 'single_paged', 'commentpaged', 'paged', 'home', 'feed', |
63 * 'category', 'page', 'year', 'month', 'day', 'post_type_archive'. |
63 * 'category', 'page', 'year', 'month', 'day', 'post_type_archive'. |
64 */ |
64 */ |
65 return apply_filters( 'user_trailingslashit', $string, $type_of_url ); |
65 return apply_filters( 'user_trailingslashit', $url, $type_of_url ); |
66 } |
66 } |
67 |
67 |
68 /** |
68 /** |
69 * Displays the permalink anchor for the current post. |
69 * Displays the permalink anchor for the current post. |
70 * |
70 * |
247 $category = $category_object->slug; |
247 $category = $category_object->slug; |
248 if ( $category_object->parent ) { |
248 if ( $category_object->parent ) { |
249 $category = get_category_parents( $category_object->parent, false, '/', true ) . $category; |
249 $category = get_category_parents( $category_object->parent, false, '/', true ) . $category; |
250 } |
250 } |
251 } |
251 } |
252 // Show default category in permalinks, |
252 /* |
253 // without having to assign it explicitly. |
253 * Show default category in permalinks, |
|
254 * without having to assign it explicitly. |
|
255 */ |
254 if ( empty( $category ) ) { |
256 if ( empty( $category ) ) { |
255 $default_category = get_term( get_option( 'default_category' ), 'category' ); |
257 $default_category = get_term( get_option( 'default_category' ), 'category' ); |
256 if ( $default_category && ! is_wp_error( $default_category ) ) { |
258 if ( $default_category && ! is_wp_error( $default_category ) ) { |
257 $category = $default_category->slug; |
259 $category = $default_category->slug; |
258 } |
260 } |
259 } |
261 } |
260 } |
262 } |
261 |
263 |
262 $author = ''; |
264 $author = ''; |
263 if ( strpos( $permalink, '%author%' ) !== false ) { |
265 if ( str_contains( $permalink, '%author%' ) ) { |
264 $authordata = get_userdata( $post->post_author ); |
266 $authordata = get_userdata( $post->post_author ); |
265 $author = $authordata->user_nicename; |
267 $author = $authordata->user_nicename; |
266 } |
268 } |
267 |
269 |
268 // This is not an API call because the permalink is based on the stored post_date value, |
270 /* |
269 // which should be parsed as local time regardless of the default PHP timezone. |
271 * This is not an API call because the permalink is based on the stored post_date value, |
|
272 * which should be parsed as local time regardless of the default PHP timezone. |
|
273 */ |
270 $date = explode( ' ', str_replace( array( '-', ':' ), ' ', $post->post_date ) ); |
274 $date = explode( ' ', str_replace( array( '-', ':' ), ' ', $post->post_date ) ); |
271 |
275 |
272 $rewritereplace = array( |
276 $rewritereplace = array( |
273 $date[0], |
277 $date[0], |
274 $date[1], |
278 $date[1], |
306 |
310 |
307 /** |
311 /** |
308 * Retrieves the permalink for a post of a custom post type. |
312 * Retrieves the permalink for a post of a custom post type. |
309 * |
313 * |
310 * @since 3.0.0 |
314 * @since 3.0.0 |
|
315 * @since 6.1.0 Returns false if the post does not exist. |
311 * |
316 * |
312 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
317 * @global WP_Rewrite $wp_rewrite WordPress rewrite component. |
313 * |
318 * |
314 * @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. |
319 * @param int|WP_Post $post Optional. Post ID or post object. Default is the global `$post`. |
315 * @param bool $leavename Optional. Whether to keep post name. Default false. |
320 * @param bool $leavename Optional. Whether to keep post name. Default false. |
316 * @param bool $sample Optional. Is it a sample permalink. Default false. |
321 * @param bool $sample Optional. Is it a sample permalink. Default false. |
317 * @return string|WP_Error The post permalink. |
322 * @return string|false The post permalink URL. False if the post does not exist. |
318 */ |
323 */ |
319 function get_post_permalink( $id = 0, $leavename = false, $sample = false ) { |
324 function get_post_permalink( $post = 0, $leavename = false, $sample = false ) { |
320 global $wp_rewrite; |
325 global $wp_rewrite; |
321 |
326 |
322 $post = get_post( $id ); |
327 $post = get_post( $post ); |
323 |
328 |
324 if ( is_wp_error( $post ) ) { |
329 if ( ! $post ) { |
325 return $post; |
330 return false; |
326 } |
331 } |
327 |
332 |
328 $post_link = $wp_rewrite->get_extra_permastruct( $post->post_type ); |
333 $post_link = $wp_rewrite->get_extra_permastruct( $post->post_type ); |
329 |
334 |
330 $slug = $post->post_name; |
335 $slug = $post->post_name; |
493 $parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front. |
498 $parentlink = _get_page_link( $post->post_parent ); // Ignores page_on_front. |
494 } else { |
499 } else { |
495 $parentlink = get_permalink( $post->post_parent ); |
500 $parentlink = get_permalink( $post->post_parent ); |
496 } |
501 } |
497 |
502 |
498 if ( is_numeric( $post->post_name ) || false !== strpos( get_option( 'permalink_structure' ), '%category%' ) ) { |
503 if ( is_numeric( $post->post_name ) || str_contains( get_option( 'permalink_structure' ), '%category%' ) ) { |
499 $name = 'attachment/' . $post->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker. |
504 $name = 'attachment/' . $post->post_name; // <permalink>/<int>/ is paged so we use the explicit attachment marker. |
500 } else { |
505 } else { |
501 $name = $post->post_name; |
506 $name = $post->post_name; |
502 } |
507 } |
503 |
508 |
504 if ( strpos( $parentlink, '?' ) === false ) { |
509 if ( ! str_contains( $parentlink, '?' ) ) { |
505 $link = user_trailingslashit( trailingslashit( $parentlink ) . '%postname%' ); |
510 $link = user_trailingslashit( trailingslashit( $parentlink ) . '%postname%' ); |
506 } |
511 } |
507 |
512 |
508 if ( ! $leavename ) { |
513 if ( ! $leavename ) { |
509 $link = str_replace( '%postname%', $name, $link ); |
514 $link = str_replace( '%postname%', $name, $link ); |
689 global $wp_rewrite; |
694 global $wp_rewrite; |
690 |
695 |
691 $permalink = $wp_rewrite->get_feed_permastruct(); |
696 $permalink = $wp_rewrite->get_feed_permastruct(); |
692 |
697 |
693 if ( $permalink ) { |
698 if ( $permalink ) { |
694 if ( false !== strpos( $feed, 'comments_' ) ) { |
699 if ( str_contains( $feed, 'comments_' ) ) { |
695 $feed = str_replace( 'comments_', '', $feed ); |
700 $feed = str_replace( 'comments_', '', $feed ); |
696 $permalink = $wp_rewrite->get_comment_feed_permastruct(); |
701 $permalink = $wp_rewrite->get_comment_feed_permastruct(); |
697 } |
702 } |
698 |
703 |
699 if ( get_default_feed() == $feed ) { |
704 if ( get_default_feed() === $feed ) { |
700 $feed = ''; |
705 $feed = ''; |
701 } |
706 } |
702 |
707 |
703 $permalink = str_replace( '%feed%', $feed, $permalink ); |
708 $permalink = str_replace( '%feed%', $feed, $permalink ); |
704 $permalink = preg_replace( '#/+#', '/', "/$permalink" ); |
709 $permalink = preg_replace( '#/+#', '/', "/$permalink" ); |
1119 /** |
1124 /** |
1120 * Displays or retrieves the edit term link with formatting. |
1125 * Displays or retrieves the edit term link with formatting. |
1121 * |
1126 * |
1122 * @since 3.1.0 |
1127 * @since 3.1.0 |
1123 * |
1128 * |
1124 * @param string $link Optional. Anchor text. If empty, default is 'Edit This'. Default empty. |
1129 * @param string $link Optional. Anchor text. If empty, default is 'Edit This'. Default empty. |
1125 * @param string $before Optional. Display before edit link. Default empty. |
1130 * @param string $before Optional. Display before edit link. Default empty. |
1126 * @param string $after Optional. Display after edit link. Default empty. |
1131 * @param string $after Optional. Display after edit link. Default empty. |
1127 * @param int|WP_Term|null $term Optional. Term ID or object. If null, the queried object will be inspected. Default null. |
1132 * @param int|WP_Term|null $term Optional. Term ID or object. If null, the queried object will be inspected. Default null. |
1128 * @param bool $echo Optional. Whether or not to echo the return. Default true. |
1133 * @param bool $display Optional. Whether or not to echo the return. Default true. |
1129 * @return string|void HTML content. |
1134 * @return string|void HTML content. |
1130 */ |
1135 */ |
1131 function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) { |
1136 function edit_term_link( $link = '', $before = '', $after = '', $term = null, $display = true ) { |
1132 if ( is_null( $term ) ) { |
1137 if ( is_null( $term ) ) { |
1133 $term = get_queried_object(); |
1138 $term = get_queried_object(); |
1134 } else { |
1139 } else { |
1135 $term = get_term( $term ); |
1140 $term = get_term( $term ); |
1136 } |
1141 } |
1430 |
1437 |
1431 /** |
1438 /** |
1432 * Retrieves the edit post link for post. |
1439 * Retrieves the edit post link for post. |
1433 * |
1440 * |
1434 * Can be used within the WordPress loop or outside of it. Can be used with |
1441 * Can be used within the WordPress loop or outside of it. Can be used with |
1435 * pages, posts, attachments, and revisions. |
1442 * pages, posts, attachments, revisions, global styles, templates, and template parts. |
1436 * |
1443 * |
1437 * @since 2.3.0 |
1444 * @since 2.3.0 |
1438 * |
1445 * @since 6.3.0 Adds custom link for wp_navigation post types. |
1439 * @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. |
1446 * Adds custom links for wp_template_part and wp_template post types. |
|
1447 * |
|
1448 * @param int|WP_Post $post Optional. Post ID or post object. Default is the global `$post`. |
1440 * @param string $context Optional. How to output the '&' character. Default '&'. |
1449 * @param string $context Optional. How to output the '&' character. Default '&'. |
1441 * @return string|null The edit post link for the given post. Null if the post type does not exist |
1450 * @return string|null The edit post link for the given post. Null if the post type does not exist |
1442 * or does not allow an editing UI. |
1451 * or does not allow an editing UI. |
1443 */ |
1452 */ |
1444 function get_edit_post_link( $id = 0, $context = 'display' ) { |
1453 function get_edit_post_link( $post = 0, $context = 'display' ) { |
1445 $post = get_post( $id ); |
1454 $post = get_post( $post ); |
|
1455 |
1446 if ( ! $post ) { |
1456 if ( ! $post ) { |
1447 return; |
1457 return; |
1448 } |
1458 } |
1449 |
1459 |
1450 if ( 'revision' === $post->post_type ) { |
1460 if ( 'revision' === $post->post_type ) { |
1454 } else { |
1464 } else { |
1455 $action = '&action=edit'; |
1465 $action = '&action=edit'; |
1456 } |
1466 } |
1457 |
1467 |
1458 $post_type_object = get_post_type_object( $post->post_type ); |
1468 $post_type_object = get_post_type_object( $post->post_type ); |
|
1469 |
1459 if ( ! $post_type_object ) { |
1470 if ( ! $post_type_object ) { |
1460 return; |
1471 return; |
1461 } |
1472 } |
1462 |
1473 |
1463 if ( ! current_user_can( 'edit_post', $post->ID ) ) { |
1474 if ( ! current_user_can( 'edit_post', $post->ID ) ) { |
1464 return; |
1475 return; |
1465 } |
1476 } |
1466 |
1477 |
1467 if ( $post_type_object->_edit_link ) { |
1478 $link = ''; |
|
1479 |
|
1480 if ( 'wp_template' === $post->post_type || 'wp_template_part' === $post->post_type ) { |
|
1481 $slug = urlencode( get_stylesheet() . '//' . $post->post_name ); |
|
1482 $link = admin_url( sprintf( $post_type_object->_edit_link, $post->post_type, $slug ) ); |
|
1483 } elseif ( 'wp_navigation' === $post->post_type ) { |
|
1484 $link = admin_url( sprintf( $post_type_object->_edit_link, (string) $post->ID ) ); |
|
1485 } elseif ( $post_type_object->_edit_link ) { |
1468 $link = admin_url( sprintf( $post_type_object->_edit_link . $action, $post->ID ) ); |
1486 $link = admin_url( sprintf( $post_type_object->_edit_link . $action, $post->ID ) ); |
1469 } else { |
|
1470 $link = ''; |
|
1471 } |
1487 } |
1472 |
1488 |
1473 /** |
1489 /** |
1474 * Filters the post edit link. |
1490 * Filters the post edit link. |
1475 * |
1491 * |
1485 |
1501 |
1486 /** |
1502 /** |
1487 * Displays the edit post link for post. |
1503 * Displays the edit post link for post. |
1488 * |
1504 * |
1489 * @since 1.0.0 |
1505 * @since 1.0.0 |
1490 * @since 4.4.0 The `$class` argument was added. |
1506 * @since 4.4.0 The `$css_class` argument was added. |
1491 * |
1507 * |
1492 * @param string $text Optional. Anchor text. If null, default is 'Edit This'. Default null. |
1508 * @param string $text Optional. Anchor text. If null, default is 'Edit This'. Default null. |
1493 * @param string $before Optional. Display before edit link. Default empty. |
1509 * @param string $before Optional. Display before edit link. Default empty. |
1494 * @param string $after Optional. Display after edit link. Default empty. |
1510 * @param string $after Optional. Display after edit link. Default empty. |
1495 * @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. |
1511 * @param int|WP_Post $post Optional. Post ID or post object. Default is the global `$post`. |
1496 * @param string $class Optional. Add custom class to link. Default 'post-edit-link'. |
1512 * @param string $css_class Optional. Add custom class to link. Default 'post-edit-link'. |
1497 */ |
1513 */ |
1498 function edit_post_link( $text = null, $before = '', $after = '', $id = 0, $class = 'post-edit-link' ) { |
1514 function edit_post_link( $text = null, $before = '', $after = '', $post = 0, $css_class = 'post-edit-link' ) { |
1499 $post = get_post( $id ); |
1515 $post = get_post( $post ); |
|
1516 |
1500 if ( ! $post ) { |
1517 if ( ! $post ) { |
1501 return; |
1518 return; |
1502 } |
1519 } |
1503 |
1520 |
1504 $url = get_edit_post_link( $post->ID ); |
1521 $url = get_edit_post_link( $post->ID ); |
|
1522 |
1505 if ( ! $url ) { |
1523 if ( ! $url ) { |
1506 return; |
1524 return; |
1507 } |
1525 } |
1508 |
1526 |
1509 if ( null === $text ) { |
1527 if ( null === $text ) { |
1510 $text = __( 'Edit This' ); |
1528 $text = __( 'Edit This' ); |
1511 } |
1529 } |
1512 |
1530 |
1513 $link = '<a class="' . esc_attr( $class ) . '" href="' . esc_url( $url ) . '">' . $text . '</a>'; |
1531 $link = '<a class="' . esc_attr( $css_class ) . '" href="' . esc_url( $url ) . '">' . $text . '</a>'; |
1514 |
1532 |
1515 /** |
1533 /** |
1516 * Filters the post edit link anchor tag. |
1534 * Filters the post edit link anchor tag. |
1517 * |
1535 * |
1518 * @since 2.3.0 |
1536 * @since 2.3.0 |
1529 * |
1547 * |
1530 * Can be used within the WordPress loop or outside of it, with any post type. |
1548 * Can be used within the WordPress loop or outside of it, with any post type. |
1531 * |
1549 * |
1532 * @since 2.9.0 |
1550 * @since 2.9.0 |
1533 * |
1551 * |
1534 * @param int|WP_Post $id Optional. Post ID or post object. Default is the global `$post`. |
1552 * @param int|WP_Post $post Optional. Post ID or post object. Default is the global `$post`. |
1535 * @param string $deprecated Not used. |
1553 * @param string $deprecated Not used. |
1536 * @param bool $force_delete Optional. Whether to bypass Trash and force deletion. Default false. |
1554 * @param bool $force_delete Optional. Whether to bypass Trash and force deletion. Default false. |
1537 * @return string|void The delete post link URL for the given post. |
1555 * @return string|void The delete post link URL for the given post. |
1538 */ |
1556 */ |
1539 function get_delete_post_link( $id = 0, $deprecated = '', $force_delete = false ) { |
1557 function get_delete_post_link( $post = 0, $deprecated = '', $force_delete = false ) { |
1540 if ( ! empty( $deprecated ) ) { |
1558 if ( ! empty( $deprecated ) ) { |
1541 _deprecated_argument( __FUNCTION__, '3.0.0' ); |
1559 _deprecated_argument( __FUNCTION__, '3.0.0' ); |
1542 } |
1560 } |
1543 |
1561 |
1544 $post = get_post( $id ); |
1562 $post = get_post( $post ); |
|
1563 |
1545 if ( ! $post ) { |
1564 if ( ! $post ) { |
1546 return; |
1565 return; |
1547 } |
1566 } |
1548 |
1567 |
1549 $post_type_object = get_post_type_object( $post->post_type ); |
1568 $post_type_object = get_post_type_object( $post->post_type ); |
|
1569 |
1550 if ( ! $post_type_object ) { |
1570 if ( ! $post_type_object ) { |
1551 return; |
1571 return; |
1552 } |
1572 } |
1553 |
1573 |
1554 if ( ! current_user_can( 'delete_post', $post->ID ) ) { |
1574 if ( ! current_user_can( 'delete_post', $post->ID ) ) { |
1741 /** |
1761 /** |
1742 * Retrieves the previous post that is adjacent to the current post. |
1762 * Retrieves the previous post that is adjacent to the current post. |
1743 * |
1763 * |
1744 * @since 1.5.0 |
1764 * @since 1.5.0 |
1745 * |
1765 * |
1746 * @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false. |
1766 * @param bool $in_same_term Optional. Whether post should be in the same taxonomy term. |
1747 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
1767 * Default false. |
1748 * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
1768 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. |
1749 * @return WP_Post|null|string Post object if successful. Null if global $post is not set. Empty string if no |
1769 * Default empty. |
1750 * corresponding post exists. |
1770 * @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'. |
|
1771 * @return WP_Post|null|string Post object if successful. Null if global `$post` is not set. |
|
1772 * Empty string if no corresponding post exists. |
1751 */ |
1773 */ |
1752 function get_previous_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
1774 function get_previous_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
1753 return get_adjacent_post( $in_same_term, $excluded_terms, true, $taxonomy ); |
1775 return get_adjacent_post( $in_same_term, $excluded_terms, true, $taxonomy ); |
1754 } |
1776 } |
1755 |
1777 |
1756 /** |
1778 /** |
1757 * Retrieves the next post that is adjacent to the current post. |
1779 * Retrieves the next post that is adjacent to the current post. |
1758 * |
1780 * |
1759 * @since 1.5.0 |
1781 * @since 1.5.0 |
1760 * |
1782 * |
1761 * @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false. |
1783 * @param bool $in_same_term Optional. Whether post should be in the same taxonomy term. |
1762 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
1784 * Default false. |
1763 * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
1785 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. |
1764 * @return WP_Post|null|string Post object if successful. Null if global $post is not set. Empty string if no |
1786 * Default empty. |
1765 * corresponding post exists. |
1787 * @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'. |
|
1788 * @return WP_Post|null|string Post object if successful. Null if global `$post` is not set. |
|
1789 * Empty string if no corresponding post exists. |
1766 */ |
1790 */ |
1767 function get_next_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
1791 function get_next_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
1768 return get_adjacent_post( $in_same_term, $excluded_terms, false, $taxonomy ); |
1792 return get_adjacent_post( $in_same_term, $excluded_terms, false, $taxonomy ); |
1769 } |
1793 } |
1770 |
1794 |
1775 * |
1799 * |
1776 * @since 2.5.0 |
1800 * @since 2.5.0 |
1777 * |
1801 * |
1778 * @global wpdb $wpdb WordPress database abstraction object. |
1802 * @global wpdb $wpdb WordPress database abstraction object. |
1779 * |
1803 * |
1780 * @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false. |
1804 * @param bool $in_same_term Optional. Whether post should be in the same taxonomy term. |
1781 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty string. |
1805 * Default false. |
1782 * @param bool $previous Optional. Whether to retrieve previous post. Default true |
1806 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. |
1783 * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
1807 * Default empty string. |
1784 * @return WP_Post|null|string Post object if successful. Null if global $post is not set. Empty string if no |
1808 * @param bool $previous Optional. Whether to retrieve previous post. |
1785 * corresponding post exists. |
1809 * Default true. |
|
1810 * @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'. |
|
1811 * @return WP_Post|null|string Post object if successful. Null if global `$post` is not set. |
|
1812 * Empty string if no corresponding post exists. |
1786 */ |
1813 */ |
1787 function get_adjacent_post( $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { |
1814 function get_adjacent_post( $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { |
1788 global $wpdb; |
1815 global $wpdb; |
1789 |
1816 |
1790 $post = get_post(); |
1817 $post = get_post(); |
|
1818 |
1791 if ( ! $post || ! taxonomy_exists( $taxonomy ) ) { |
1819 if ( ! $post || ! taxonomy_exists( $taxonomy ) ) { |
1792 return null; |
1820 return null; |
1793 } |
1821 } |
1794 |
1822 |
1795 $current_post_date = $post->post_date; |
1823 $current_post_date = $post->post_date; |
1906 * - `get_previous_post_join` |
1934 * - `get_previous_post_join` |
1907 * |
1935 * |
1908 * @since 2.5.0 |
1936 * @since 2.5.0 |
1909 * @since 4.4.0 Added the `$taxonomy` and `$post` parameters. |
1937 * @since 4.4.0 Added the `$taxonomy` and `$post` parameters. |
1910 * |
1938 * |
1911 * @param string $join The JOIN clause in the SQL. |
1939 * @param string $join The JOIN clause in the SQL. |
1912 * @param bool $in_same_term Whether post should be in a same taxonomy term. |
1940 * @param bool $in_same_term Whether post should be in the same taxonomy term. |
1913 * @param array $excluded_terms Array of excluded term IDs. |
1941 * @param int[]|string $excluded_terms Array of excluded term IDs. Empty string if none were provided. |
1914 * @param string $taxonomy Taxonomy. Used to identify the term used when `$in_same_term` is true. |
1942 * @param string $taxonomy Taxonomy. Used to identify the term used when `$in_same_term` is true. |
1915 * @param WP_Post $post WP_Post object. |
1943 * @param WP_Post $post WP_Post object. |
1916 */ |
1944 */ |
1917 $join = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_term, $excluded_terms, $taxonomy, $post ); |
1945 $join = apply_filters( "get_{$adjacent}_post_join", $join, $in_same_term, $excluded_terms, $taxonomy, $post ); |
1918 |
1946 |
1919 /** |
1947 /** |
1920 * Filters the WHERE clause in the SQL for an adjacent post query. |
1948 * Filters the WHERE clause in the SQL for an adjacent post query. |
1928 * - `get_previous_post_where` |
1956 * - `get_previous_post_where` |
1929 * |
1957 * |
1930 * @since 2.5.0 |
1958 * @since 2.5.0 |
1931 * @since 4.4.0 Added the `$taxonomy` and `$post` parameters. |
1959 * @since 4.4.0 Added the `$taxonomy` and `$post` parameters. |
1932 * |
1960 * |
1933 * @param string $where The `WHERE` clause in the SQL. |
1961 * @param string $where The `WHERE` clause in the SQL. |
1934 * @param bool $in_same_term Whether post should be in a same taxonomy term. |
1962 * @param bool $in_same_term Whether post should be in the same taxonomy term. |
1935 * @param array $excluded_terms Array of excluded term IDs. |
1963 * @param int[]|string $excluded_terms Array of excluded term IDs. Empty string if none were provided. |
1936 * @param string $taxonomy Taxonomy. Used to identify the term used when `$in_same_term` is true. |
1964 * @param string $taxonomy Taxonomy. Used to identify the term used when `$in_same_term` is true. |
1937 * @param WP_Post $post WP_Post object. |
1965 * @param WP_Post $post WP_Post object. |
1938 */ |
1966 */ |
1939 $where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare( "WHERE p.post_date $op %s AND p.post_type = %s $where", $current_post_date, $post->post_type ), $in_same_term, $excluded_terms, $taxonomy, $post ); |
1967 $where = apply_filters( "get_{$adjacent}_post_where", $wpdb->prepare( "WHERE p.post_date $op %s AND p.post_type = %s $where", $current_post_date, $post->post_type ), $in_same_term, $excluded_terms, $taxonomy, $post ); |
1940 |
1968 |
1941 /** |
1969 /** |
1942 * Filters the ORDER BY clause in the SQL for an adjacent post query. |
1970 * Filters the ORDER BY clause in the SQL for an adjacent post query. |
1957 * @param WP_Post $post WP_Post object. |
1985 * @param WP_Post $post WP_Post object. |
1958 * @param string $order Sort order. 'DESC' for previous post, 'ASC' for next. |
1986 * @param string $order Sort order. 'DESC' for previous post, 'ASC' for next. |
1959 */ |
1987 */ |
1960 $sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1", $post, $order ); |
1988 $sort = apply_filters( "get_{$adjacent}_post_sort", "ORDER BY p.post_date $order LIMIT 1", $post, $order ); |
1961 |
1989 |
1962 $query = "SELECT p.ID FROM $wpdb->posts AS p $join $where $sort"; |
1990 $query = "SELECT p.ID FROM $wpdb->posts AS p $join $where $sort"; |
1963 $query_key = 'adjacent_post_' . md5( $query ); |
1991 $key = md5( $query ); |
1964 $result = wp_cache_get( $query_key, 'counts' ); |
1992 $last_changed = wp_cache_get_last_changed( 'posts' ); |
|
1993 if ( $in_same_term || ! empty( $excluded_terms ) ) { |
|
1994 $last_changed .= wp_cache_get_last_changed( 'terms' ); |
|
1995 } |
|
1996 $cache_key = "adjacent_post:$key:$last_changed"; |
|
1997 |
|
1998 $result = wp_cache_get( $cache_key, 'post-queries' ); |
1965 if ( false !== $result ) { |
1999 if ( false !== $result ) { |
1966 if ( $result ) { |
2000 if ( $result ) { |
1967 $result = get_post( $result ); |
2001 $result = get_post( $result ); |
1968 } |
2002 } |
1969 return $result; |
2003 return $result; |
1989 * Can either be next or previous post relational link. |
2023 * Can either be next or previous post relational link. |
1990 * |
2024 * |
1991 * @since 2.8.0 |
2025 * @since 2.8.0 |
1992 * |
2026 * |
1993 * @param string $title Optional. Link title format. Default '%title'. |
2027 * @param string $title Optional. Link title format. Default '%title'. |
1994 * @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
2028 * @param bool $in_same_term Optional. Whether link should be in the same taxonomy term. |
1995 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
2029 * Default false. |
1996 * @param bool $previous Optional. Whether to display link to previous or next post. Default true. |
2030 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. |
1997 * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
2031 * Default empty. |
|
2032 * @param bool $previous Optional. Whether to display link to previous or next post. |
|
2033 * Default true. |
|
2034 * @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'. |
1998 * @return string|void The adjacent post relational link URL. |
2035 * @return string|void The adjacent post relational link URL. |
1999 */ |
2036 */ |
2000 function get_adjacent_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { |
2037 function get_adjacent_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { |
2001 $post = get_post(); |
2038 $post = get_post(); |
2002 if ( $previous && is_attachment() && $post ) { |
2039 if ( $previous && is_attachment() && $post ) { |
2053 * Displays the relational links for the posts adjacent to the current post. |
2090 * Displays the relational links for the posts adjacent to the current post. |
2054 * |
2091 * |
2055 * @since 2.8.0 |
2092 * @since 2.8.0 |
2056 * |
2093 * |
2057 * @param string $title Optional. Link title format. Default '%title'. |
2094 * @param string $title Optional. Link title format. Default '%title'. |
2058 * @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
2095 * @param bool $in_same_term Optional. Whether link should be in the same taxonomy term. |
2059 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
2096 * Default false. |
2060 * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
2097 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. |
|
2098 * Default empty. |
|
2099 * @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'. |
2061 */ |
2100 */ |
2062 function adjacent_posts_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
2101 function adjacent_posts_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
2063 echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, true, $taxonomy ); |
2102 echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, true, $taxonomy ); |
2064 echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy ); |
2103 echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy ); |
2065 } |
2104 } |
2088 * @since 2.8.0 |
2127 * @since 2.8.0 |
2089 * |
2128 * |
2090 * @see get_adjacent_post_rel_link() |
2129 * @see get_adjacent_post_rel_link() |
2091 * |
2130 * |
2092 * @param string $title Optional. Link title format. Default '%title'. |
2131 * @param string $title Optional. Link title format. Default '%title'. |
2093 * @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
2132 * @param bool $in_same_term Optional. Whether link should be in the same taxonomy term. |
2094 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
|
2095 * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
|
2096 */ |
|
2097 function next_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
|
2098 echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy ); |
|
2099 } |
|
2100 |
|
2101 /** |
|
2102 * Displays the relational link for the previous post adjacent to the current post. |
|
2103 * |
|
2104 * @since 2.8.0 |
|
2105 * |
|
2106 * @see get_adjacent_post_rel_link() |
|
2107 * |
|
2108 * @param string $title Optional. Link title format. Default '%title'. |
|
2109 * @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
|
2110 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default true. |
|
2111 * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
|
2112 */ |
|
2113 function prev_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
|
2114 echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, true, $taxonomy ); |
|
2115 } |
|
2116 |
|
2117 /** |
|
2118 * Retrieves the boundary post. |
|
2119 * |
|
2120 * Boundary being either the first or last post by publish date within the constraints specified |
|
2121 * by $in_same_term or $excluded_terms. |
|
2122 * |
|
2123 * @since 2.8.0 |
|
2124 * |
|
2125 * @param bool $in_same_term Optional. Whether returned post should be in a same taxonomy term. |
|
2126 * Default false. |
2133 * Default false. |
2127 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. |
2134 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. |
2128 * Default empty. |
2135 * Default empty. |
2129 * @param bool $start Optional. Whether to retrieve first or last post. Default true |
2136 * @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'. |
2130 * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
2137 */ |
2131 * @return null|array Array containing the boundary post object if successful, null otherwise. |
2138 function next_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
|
2139 echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, false, $taxonomy ); |
|
2140 } |
|
2141 |
|
2142 /** |
|
2143 * Displays the relational link for the previous post adjacent to the current post. |
|
2144 * |
|
2145 * @since 2.8.0 |
|
2146 * |
|
2147 * @see get_adjacent_post_rel_link() |
|
2148 * |
|
2149 * @param string $title Optional. Link title format. Default '%title'. |
|
2150 * @param bool $in_same_term Optional. Whether link should be in the same taxonomy term. |
|
2151 * Default false. |
|
2152 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. |
|
2153 * Default true. |
|
2154 * @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'. |
|
2155 */ |
|
2156 function prev_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
|
2157 echo get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, true, $taxonomy ); |
|
2158 } |
|
2159 |
|
2160 /** |
|
2161 * Retrieves the boundary post. |
|
2162 * |
|
2163 * Boundary being either the first or last post by publish date within the constraints specified |
|
2164 * by `$in_same_term` or `$excluded_terms`. |
|
2165 * |
|
2166 * @since 2.8.0 |
|
2167 * |
|
2168 * @param bool $in_same_term Optional. Whether returned post should be in the same taxonomy term. |
|
2169 * Default false. |
|
2170 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. |
|
2171 * Default empty. |
|
2172 * @param bool $start Optional. Whether to retrieve first or last post. |
|
2173 * Default true. |
|
2174 * @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'. |
|
2175 * @return array|null Array containing the boundary post object if successful, null otherwise. |
2132 */ |
2176 */ |
2133 function get_boundary_post( $in_same_term = false, $excluded_terms = '', $start = true, $taxonomy = 'category' ) { |
2177 function get_boundary_post( $in_same_term = false, $excluded_terms = '', $start = true, $taxonomy = 'category' ) { |
2134 $post = get_post(); |
2178 $post = get_post(); |
|
2179 |
2135 if ( ! $post || ! is_single() || is_attachment() || ! taxonomy_exists( $taxonomy ) ) { |
2180 if ( ! $post || ! is_single() || is_attachment() || ! taxonomy_exists( $taxonomy ) ) { |
2136 return null; |
2181 return null; |
2137 } |
2182 } |
2138 |
2183 |
2139 $query_args = array( |
2184 $query_args = array( |
2185 * |
2230 * |
2186 * @since 3.7.0 |
2231 * @since 3.7.0 |
2187 * |
2232 * |
2188 * @param string $format Optional. Link anchor format. Default '« %link'. |
2233 * @param string $format Optional. Link anchor format. Default '« %link'. |
2189 * @param string $link Optional. Link permalink format. Default '%title'. |
2234 * @param string $link Optional. Link permalink format. Default '%title'. |
2190 * @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
2235 * @param bool $in_same_term Optional. Whether link should be in the same taxonomy term. |
2191 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
2236 * Default false. |
2192 * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
2237 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. |
|
2238 * Default empty. |
|
2239 * @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'. |
2193 * @return string The link URL of the previous post in relation to the current post. |
2240 * @return string The link URL of the previous post in relation to the current post. |
2194 */ |
2241 */ |
2195 function get_previous_post_link( $format = '« %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
2242 function get_previous_post_link( $format = '« %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
2196 return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, true, $taxonomy ); |
2243 return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, true, $taxonomy ); |
2197 } |
2244 } |
2203 * |
2250 * |
2204 * @see get_previous_post_link() |
2251 * @see get_previous_post_link() |
2205 * |
2252 * |
2206 * @param string $format Optional. Link anchor format. Default '« %link'. |
2253 * @param string $format Optional. Link anchor format. Default '« %link'. |
2207 * @param string $link Optional. Link permalink format. Default '%title'. |
2254 * @param string $link Optional. Link permalink format. Default '%title'. |
2208 * @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
2255 * @param bool $in_same_term Optional. Whether link should be in the same taxonomy term. |
2209 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
2256 * Default false. |
2210 * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
2257 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. |
|
2258 * Default empty. |
|
2259 * @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'. |
2211 */ |
2260 */ |
2212 function previous_post_link( $format = '« %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
2261 function previous_post_link( $format = '« %link', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
2213 echo get_previous_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy ); |
2262 echo get_previous_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy ); |
2214 } |
2263 } |
2215 |
2264 |
2218 * |
2267 * |
2219 * @since 3.7.0 |
2268 * @since 3.7.0 |
2220 * |
2269 * |
2221 * @param string $format Optional. Link anchor format. Default '« %link'. |
2270 * @param string $format Optional. Link anchor format. Default '« %link'. |
2222 * @param string $link Optional. Link permalink format. Default '%title'. |
2271 * @param string $link Optional. Link permalink format. Default '%title'. |
2223 * @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
2272 * @param bool $in_same_term Optional. Whether link should be in the same taxonomy term. |
2224 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
2273 * Default false. |
2225 * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
2274 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. |
|
2275 * Default empty. |
|
2276 * @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'. |
2226 * @return string The link URL of the next post in relation to the current post. |
2277 * @return string The link URL of the next post in relation to the current post. |
2227 */ |
2278 */ |
2228 function get_next_post_link( $format = '%link »', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
2279 function get_next_post_link( $format = '%link »', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
2229 return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, false, $taxonomy ); |
2280 return get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, false, $taxonomy ); |
2230 } |
2281 } |
2235 * @since 1.5.0 |
2286 * @since 1.5.0 |
2236 * |
2287 * |
2237 * @see get_next_post_link() |
2288 * @see get_next_post_link() |
2238 * |
2289 * |
2239 * @param string $format Optional. Link anchor format. Default '« %link'. |
2290 * @param string $format Optional. Link anchor format. Default '« %link'. |
2240 * @param string $link Optional. Link permalink format. Default '%title' |
2291 * @param string $link Optional. Link permalink format. Default '%title'. |
2241 * @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
2292 * @param bool $in_same_term Optional. Whether link should be in the same taxonomy term. |
2242 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
2293 * Default false. |
2243 * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
2294 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. |
|
2295 * Default empty. |
|
2296 * @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'. |
2244 */ |
2297 */ |
2245 function next_post_link( $format = '%link »', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
2298 function next_post_link( $format = '%link »', $link = '%title', $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
2246 echo get_next_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy ); |
2299 echo get_next_post_link( $format, $link, $in_same_term, $excluded_terms, $taxonomy ); |
2247 } |
2300 } |
2248 |
2301 |
2253 * |
2306 * |
2254 * @since 3.7.0 |
2307 * @since 3.7.0 |
2255 * |
2308 * |
2256 * @param string $format Link anchor format. |
2309 * @param string $format Link anchor format. |
2257 * @param string $link Link permalink format. |
2310 * @param string $link Link permalink format. |
2258 * @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
2311 * @param bool $in_same_term Optional. Whether link should be in the same taxonomy term. |
2259 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded terms IDs. Default empty. |
2312 * Default false. |
2260 * @param bool $previous Optional. Whether to display link to previous or next post. Default true. |
2313 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded terms IDs. |
2261 * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
2314 * Default empty. |
|
2315 * @param bool $previous Optional. Whether to display link to previous or next post. |
|
2316 * Default true. |
|
2317 * @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'. |
2262 * @return string The link URL of the previous or next post in relation to the current post. |
2318 * @return string The link URL of the previous or next post in relation to the current post. |
2263 */ |
2319 */ |
2264 function get_adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { |
2320 function get_adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { |
2265 if ( $previous && is_attachment() ) { |
2321 if ( $previous && is_attachment() ) { |
2266 $post = get_post( get_post()->post_parent ); |
2322 $post = get_post( get_post()->post_parent ); |
2305 * - `previous_post_link` |
2361 * - `previous_post_link` |
2306 * |
2362 * |
2307 * @since 2.6.0 |
2363 * @since 2.6.0 |
2308 * @since 4.2.0 Added the `$adjacent` parameter. |
2364 * @since 4.2.0 Added the `$adjacent` parameter. |
2309 * |
2365 * |
2310 * @param string $output The adjacent post link. |
2366 * @param string $output The adjacent post link. |
2311 * @param string $format Link anchor format. |
2367 * @param string $format Link anchor format. |
2312 * @param string $link Link permalink format. |
2368 * @param string $link Link permalink format. |
2313 * @param WP_Post $post The adjacent post. |
2369 * @param WP_Post|string $post The adjacent post. Empty string if no corresponding post exists. |
2314 * @param string $adjacent Whether the post is previous or next. |
2370 * @param string $adjacent Whether the post is previous or next. |
2315 */ |
2371 */ |
2316 return apply_filters( "{$adjacent}_post_link", $output, $format, $link, $post, $adjacent ); |
2372 return apply_filters( "{$adjacent}_post_link", $output, $format, $link, $post, $adjacent ); |
2317 } |
2373 } |
2318 |
2374 |
2319 /** |
2375 /** |
2323 * |
2379 * |
2324 * @since 2.5.0 |
2380 * @since 2.5.0 |
2325 * |
2381 * |
2326 * @param string $format Link anchor format. |
2382 * @param string $format Link anchor format. |
2327 * @param string $link Link permalink format. |
2383 * @param string $link Link permalink format. |
2328 * @param bool $in_same_term Optional. Whether link should be in a same taxonomy term. Default false. |
2384 * @param bool $in_same_term Optional. Whether link should be in the same taxonomy term. |
2329 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded category IDs. Default empty. |
2385 * Default false. |
2330 * @param bool $previous Optional. Whether to display link to previous or next post. Default true. |
2386 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded category IDs. |
2331 * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
2387 * Default empty. |
|
2388 * @param bool $previous Optional. Whether to display link to previous or next post. |
|
2389 * Default true. |
|
2390 * @param string $taxonomy Optional. Taxonomy, if `$in_same_term` is true. Default 'category'. |
2332 */ |
2391 */ |
2333 function adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { |
2392 function adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { |
2334 echo get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, $previous, $taxonomy ); |
2393 echo get_adjacent_post_link( $format, $link, $in_same_term, $excluded_terms, $previous, $taxonomy ); |
2335 } |
2394 } |
2336 |
2395 |
2381 |
2443 |
2382 $request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request ); |
2444 $request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request ); |
2383 $request = preg_replace( '|^' . preg_quote( $wp_rewrite->index, '|' ) . '|i', '', $request ); |
2445 $request = preg_replace( '|^' . preg_quote( $wp_rewrite->index, '|' ) . '|i', '', $request ); |
2384 $request = ltrim( $request, '/' ); |
2446 $request = ltrim( $request, '/' ); |
2385 |
2447 |
2386 $base = trailingslashit( get_bloginfo( 'url' ) ); |
|
2387 |
|
2388 if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' !== $request ) ) { |
2448 if ( $wp_rewrite->using_index_permalinks() && ( $pagenum > 1 || '' !== $request ) ) { |
2389 $base .= $wp_rewrite->index . '/'; |
2449 $parts[] = $wp_rewrite->index; |
2390 } |
2450 } |
|
2451 |
|
2452 $parts[] = untrailingslashit( $request ); |
2391 |
2453 |
2392 if ( $pagenum > 1 ) { |
2454 if ( $pagenum > 1 ) { |
2393 $request = ( ( ! empty( $request ) ) ? trailingslashit( $request ) : $request ) . user_trailingslashit( $wp_rewrite->pagination_base . '/' . $pagenum, 'paged' ); |
2455 $parts[] = $wp_rewrite->pagination_base; |
2394 } |
2456 $parts[] = $pagenum; |
2395 |
2457 } |
2396 $result = $base . $request . $query_string; |
2458 |
|
2459 $result = user_trailingslashit( implode( '/', array_filter( $parts ) ), 'paged' ); |
|
2460 if ( ! empty( $query_string ) ) { |
|
2461 $result .= $query_string; |
|
2462 } |
2397 } |
2463 } |
2398 |
2464 |
2399 /** |
2465 /** |
2400 * Filters the page number link for the current request. |
2466 * Filters the page number link for the current request. |
2401 * |
2467 * |
2431 |
2497 |
2432 if ( ! is_single() ) { |
2498 if ( ! is_single() ) { |
2433 if ( ! $paged ) { |
2499 if ( ! $paged ) { |
2434 $paged = 1; |
2500 $paged = 1; |
2435 } |
2501 } |
2436 $nextpage = (int) $paged + 1; |
2502 |
2437 if ( ! $max_page || $max_page >= $nextpage ) { |
2503 $next_page = (int) $paged + 1; |
2438 return get_pagenum_link( $nextpage ); |
2504 |
|
2505 if ( ! $max_page || $max_page >= $next_page ) { |
|
2506 return get_pagenum_link( $next_page ); |
2439 } |
2507 } |
2440 } |
2508 } |
2441 } |
2509 } |
2442 |
2510 |
2443 /** |
2511 /** |
2444 * Displays or retrieves the next posts page link. |
2512 * Displays or retrieves the next posts page link. |
2445 * |
2513 * |
2446 * @since 0.71 |
2514 * @since 0.71 |
2447 * |
2515 * |
2448 * @param int $max_page Optional. Max pages. Default 0. |
2516 * @param int $max_page Optional. Max pages. Default 0. |
2449 * @param bool $echo Optional. Whether to echo the link. Default true. |
2517 * @param bool $display Optional. Whether to echo the link. Default true. |
2450 * @return string|void The link URL for next posts page if `$echo = false`. |
2518 * @return string|void The link URL for next posts page if `$display = false`. |
2451 */ |
2519 */ |
2452 function next_posts( $max_page = 0, $echo = true ) { |
2520 function next_posts( $max_page = 0, $display = true ) { |
2453 $output = esc_url( get_next_posts_page_link( $max_page ) ); |
2521 $link = get_next_posts_page_link( $max_page ); |
2454 |
2522 $output = $link ? esc_url( $link ) : ''; |
2455 if ( $echo ) { |
2523 |
|
2524 if ( $display ) { |
2456 echo $output; |
2525 echo $output; |
2457 } else { |
2526 } else { |
2458 return $output; |
2527 return $output; |
2459 } |
2528 } |
2460 } |
2529 } |
2480 |
2549 |
2481 if ( ! $paged ) { |
2550 if ( ! $paged ) { |
2482 $paged = 1; |
2551 $paged = 1; |
2483 } |
2552 } |
2484 |
2553 |
2485 $nextpage = (int) $paged + 1; |
2554 $next_page = (int) $paged + 1; |
2486 |
2555 |
2487 if ( null === $label ) { |
2556 if ( null === $label ) { |
2488 $label = __( 'Next Page »' ); |
2557 $label = __( 'Next Page »' ); |
2489 } |
2558 } |
2490 |
2559 |
2491 if ( ! is_single() && ( $nextpage <= $max_page ) ) { |
2560 if ( ! is_single() && ( $next_page <= $max_page ) ) { |
2492 /** |
2561 /** |
2493 * Filters the anchor tag attributes for the next posts page link. |
2562 * Filters the anchor tag attributes for the next posts page link. |
2494 * |
2563 * |
2495 * @since 2.7.0 |
2564 * @since 2.7.0 |
2496 * |
2565 * |
2497 * @param string $attributes Attributes for the anchor tag. |
2566 * @param string $attributes Attributes for the anchor tag. |
2498 */ |
2567 */ |
2499 $attr = apply_filters( 'next_posts_link_attributes', '' ); |
2568 $attr = apply_filters( 'next_posts_link_attributes', '' ); |
2500 |
2569 |
2501 return '<a href="' . next_posts( $max_page, false ) . "\" $attr>" . preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) . '</a>'; |
2570 return sprintf( |
|
2571 '<a href="%1$s" %2$s>%3$s</a>', |
|
2572 next_posts( $max_page, false ), |
|
2573 $attr, |
|
2574 preg_replace( '/&([^#])(?![a-z]{1,8};)/i', '&$1', $label ) |
|
2575 ); |
2502 } |
2576 } |
2503 } |
2577 } |
2504 |
2578 |
2505 /** |
2579 /** |
2506 * Displays the next posts page link. |
2580 * Displays the next posts page link. |
2670 * @since 5.5.0 Added the `class` parameter. |
2751 * @since 5.5.0 Added the `class` parameter. |
2671 * |
2752 * |
2672 * @param array $args { |
2753 * @param array $args { |
2673 * Optional. Default post navigation arguments. Default empty array. |
2754 * Optional. Default post navigation arguments. Default empty array. |
2674 * |
2755 * |
2675 * @type string $prev_text Anchor text to display in the previous post link. Default '%title'. |
2756 * @type string $prev_text Anchor text to display in the previous post link. |
2676 * @type string $next_text Anchor text to display in the next post link. Default '%title'. |
2757 * Default '%title'. |
2677 * @type bool $in_same_term Whether link should be in a same taxonomy term. Default false. |
2758 * @type string $next_text Anchor text to display in the next post link. |
2678 * @type int[]|string $excluded_terms Array or comma-separated list of excluded term IDs. Default empty. |
2759 * Default '%title'. |
|
2760 * @type bool $in_same_term Whether link should be in the same taxonomy term. |
|
2761 * Default false. |
|
2762 * @type int[]|string $excluded_terms Array or comma-separated list of excluded term IDs. |
|
2763 * Default empty. |
2679 * @type string $taxonomy Taxonomy, if `$in_same_term` is true. Default 'category'. |
2764 * @type string $taxonomy Taxonomy, if `$in_same_term` is true. Default 'category'. |
2680 * @type string $screen_reader_text Screen reader text for the nav element. Default 'Post navigation'. |
2765 * @type string $screen_reader_text Screen reader text for the nav element. |
|
2766 * Default 'Post navigation'. |
2681 * @type string $aria_label ARIA label text for the nav element. Default 'Posts'. |
2767 * @type string $aria_label ARIA label text for the nav element. Default 'Posts'. |
2682 * @type string $class Custom class for the nav element. Default 'post-navigation'. |
2768 * @type string $class Custom class for the nav element. Default 'post-navigation'. |
2683 * } |
2769 * } |
2684 * @return string Markup for post links. |
2770 * @return string Markup for post links. |
2685 */ |
2771 */ |
2851 'aria_label' => __( 'Posts' ), |
2943 'aria_label' => __( 'Posts' ), |
2852 'class' => 'pagination', |
2944 'class' => 'pagination', |
2853 ) |
2945 ) |
2854 ); |
2946 ); |
2855 |
2947 |
|
2948 /** |
|
2949 * Filters the arguments for posts pagination links. |
|
2950 * |
|
2951 * @since 6.1.0 |
|
2952 * |
|
2953 * @param array $args { |
|
2954 * Optional. Default pagination arguments, see paginate_links(). |
|
2955 * |
|
2956 * @type string $screen_reader_text Screen reader text for navigation element. |
|
2957 * Default 'Posts navigation'. |
|
2958 * @type string $aria_label ARIA label text for the nav element. Default 'Posts'. |
|
2959 * @type string $class Custom class for the nav element. Default 'pagination'. |
|
2960 * } |
|
2961 */ |
|
2962 $args = apply_filters( 'the_posts_pagination_args', $args ); |
|
2963 |
2856 // Make sure we get a string back. Plain is the next best thing. |
2964 // Make sure we get a string back. Plain is the next best thing. |
2857 if ( isset( $args['type'] ) && 'array' === $args['type'] ) { |
2965 if ( isset( $args['type'] ) && 'array' === $args['type'] ) { |
2858 $args['type'] = 'plain'; |
2966 $args['type'] = 'plain'; |
2859 } |
2967 } |
2860 |
2968 |
2887 * @since 4.1.0 |
2995 * @since 4.1.0 |
2888 * @since 5.3.0 Added the `aria_label` parameter. |
2996 * @since 5.3.0 Added the `aria_label` parameter. |
2889 * @access private |
2997 * @access private |
2890 * |
2998 * |
2891 * @param string $links Navigational links. |
2999 * @param string $links Navigational links. |
2892 * @param string $class Optional. Custom class for the nav element. |
3000 * @param string $css_class Optional. Custom class for the nav element. |
2893 * Default 'posts-navigation'. |
3001 * Default 'posts-navigation'. |
2894 * @param string $screen_reader_text Optional. Screen reader text for the nav element. |
3002 * @param string $screen_reader_text Optional. Screen reader text for the nav element. |
2895 * Default 'Posts navigation'. |
3003 * Default 'Posts navigation'. |
2896 * @param string $aria_label Optional. ARIA label for the nav element. |
3004 * @param string $aria_label Optional. ARIA label for the nav element. |
2897 * Defaults to the value of `$screen_reader_text`. |
3005 * Defaults to the value of `$screen_reader_text`. |
2898 * @return string Navigation template tag. |
3006 * @return string Navigation template tag. |
2899 */ |
3007 */ |
2900 function _navigation_markup( $links, $class = 'posts-navigation', $screen_reader_text = '', $aria_label = '' ) { |
3008 function _navigation_markup( $links, $css_class = 'posts-navigation', $screen_reader_text = '', $aria_label = '' ) { |
2901 if ( empty( $screen_reader_text ) ) { |
3009 if ( empty( $screen_reader_text ) ) { |
2902 $screen_reader_text = __( 'Posts navigation' ); |
3010 $screen_reader_text = /* translators: Hidden accessibility text. */ __( 'Posts navigation' ); |
2903 } |
3011 } |
2904 if ( empty( $aria_label ) ) { |
3012 if ( empty( $aria_label ) ) { |
2905 $aria_label = $screen_reader_text; |
3013 $aria_label = $screen_reader_text; |
2906 } |
3014 } |
2907 |
3015 |
2923 * <div class="nav-links">%3$s</div> |
3031 * <div class="nav-links">%3$s</div> |
2924 * </nav> |
3032 * </nav> |
2925 * |
3033 * |
2926 * @since 4.4.0 |
3034 * @since 4.4.0 |
2927 * |
3035 * |
2928 * @param string $template The default template. |
3036 * @param string $template The default template. |
2929 * @param string $class The class passed by the calling function. |
3037 * @param string $css_class The class passed by the calling function. |
2930 * @return string Navigation template. |
3038 * @return string Navigation template. |
2931 */ |
3039 */ |
2932 $template = apply_filters( 'navigation_markup_template', $template, $class ); |
3040 $template = apply_filters( 'navigation_markup_template', $template, $css_class ); |
2933 |
3041 |
2934 return sprintf( $template, sanitize_html_class( $class ), esc_html( $screen_reader_text ), $links, esc_html( $aria_label ) ); |
3042 return sprintf( $template, sanitize_html_class( $css_class ), esc_html( $screen_reader_text ), $links, esc_attr( $aria_label ) ); |
2935 } |
3043 } |
2936 |
3044 |
2937 /** |
3045 /** |
2938 * Retrieves the comments page number link. |
3046 * Retrieves the comments page number link. |
2939 * |
3047 * |
2946 * @return string The comments page number link URL. |
3054 * @return string The comments page number link URL. |
2947 */ |
3055 */ |
2948 function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) { |
3056 function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) { |
2949 global $wp_rewrite; |
3057 global $wp_rewrite; |
2950 |
3058 |
2951 $pagenum = (int) $pagenum; |
3059 $pagenum = (int) $pagenum; |
|
3060 $max_page = (int) $max_page; |
2952 |
3061 |
2953 $result = get_permalink(); |
3062 $result = get_permalink(); |
2954 |
3063 |
2955 if ( 'newest' === get_option( 'default_comments_page' ) ) { |
3064 if ( 'newest' === get_option( 'default_comments_page' ) ) { |
2956 if ( $pagenum != $max_page ) { |
3065 if ( $pagenum !== $max_page ) { |
2957 if ( $wp_rewrite->using_permalinks() ) { |
3066 if ( $wp_rewrite->using_permalinks() ) { |
2958 $result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' ); |
3067 $result = user_trailingslashit( trailingslashit( $result ) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged' ); |
2959 } else { |
3068 } else { |
2960 $result = add_query_arg( 'cpage', $pagenum, $result ); |
3069 $result = add_query_arg( 'cpage', $pagenum, $result ); |
2961 } |
3070 } |
4133 $link = apply_filters( 'the_shortlink', $link, $shortlink, $text, $title ); |
4258 $link = apply_filters( 'the_shortlink', $link, $shortlink, $text, $title ); |
4134 echo $before, $link, $after; |
4259 echo $before, $link, $after; |
4135 } |
4260 } |
4136 } |
4261 } |
4137 |
4262 |
4138 |
|
4139 /** |
4263 /** |
4140 * Retrieves the avatar URL. |
4264 * Retrieves the avatar URL. |
4141 * |
4265 * |
4142 * @since 4.2.0 |
4266 * @since 4.2.0 |
4143 * |
4267 * |
4144 * @param mixed $id_or_email The Gravatar to retrieve a URL for. Accepts a user_id, gravatar md5 hash, |
4268 * @param mixed $id_or_email The avatar to retrieve a URL for. Accepts a user ID, Gravatar MD5 hash, |
4145 * user email, WP_User object, WP_Post object, or WP_Comment object. |
4269 * user email, WP_User object, WP_Post object, or WP_Comment object. |
4146 * @param array $args { |
4270 * @param array $args { |
4147 * Optional. Arguments to return instead of the default arguments. |
4271 * Optional. Arguments to use instead of the default arguments. |
4148 * |
4272 * |
4149 * @type int $size Height and width of the avatar in pixels. Default 96. |
4273 * @type int $size Height and width of the avatar in pixels. Default 96. |
4150 * @type string $default URL for the default image or a default type. Accepts '404' (return |
4274 * @type string $default URL for the default image or a default type. Accepts: |
4151 * a 404 instead of a default image), 'retro' (8bit), 'monsterid' (monster), |
4275 * - '404' (return a 404 instead of a default image) |
4152 * 'wavatar' (cartoon face), 'indenticon' (the "quilt"), 'mystery', 'mm', |
4276 * - 'retro' (a 8-bit arcade-style pixelated face) |
4153 * or 'mysteryman' (The Oyster Man), 'blank' (transparent GIF), or |
4277 * - 'robohash' (a robot) |
4154 * 'gravatar_default' (the Gravatar logo). Default is the value of the |
4278 * - 'monsterid' (a monster) |
4155 * 'avatar_default' option, with a fallback of 'mystery'. |
4279 * - 'wavatar' (a cartoon face) |
4156 * @type bool $force_default Whether to always show the default image, never the Gravatar. Default false. |
4280 * - 'identicon' (the "quilt", a geometric pattern) |
4157 * @type string $rating What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are |
4281 * - 'mystery', 'mm', or 'mysteryman' (The Oyster Man) |
4158 * judged in that order. Default is the value of the 'avatar_rating' option. |
4282 * - 'blank' (transparent GIF) |
|
4283 * - 'gravatar_default' (the Gravatar logo) |
|
4284 * Default is the value of the 'avatar_default' option, |
|
4285 * with a fallback of 'mystery'. |
|
4286 * @type bool $force_default Whether to always show the default image, never the Gravatar. |
|
4287 * Default false. |
|
4288 * @type string $rating What rating to display avatars up to. Accepts: |
|
4289 * - 'G' (suitable for all audiences) |
|
4290 * - 'PG' (possibly offensive, usually for audiences 13 and above) |
|
4291 * - 'R' (intended for adult audiences above 17) |
|
4292 * - 'X' (even more mature than above) |
|
4293 * Default is the value of the 'avatar_rating' option. |
4159 * @type string $scheme URL scheme to use. See set_url_scheme() for accepted values. |
4294 * @type string $scheme URL scheme to use. See set_url_scheme() for accepted values. |
4160 * Default null. |
4295 * Default null. |
4161 * @type array $processed_args When the function returns, the value will be the processed/sanitized $args |
4296 * @type array $processed_args When the function returns, the value will be the processed/sanitized $args |
4162 * plus a "found_avatar" guess. Pass as a reference. Default null. |
4297 * plus a "found_avatar" guess. Pass as a reference. Default null. |
4163 * } |
4298 * } |
4188 $allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) ); |
4322 $allowed_comment_types = apply_filters( 'get_avatar_comment_types', array( 'comment' ) ); |
4189 |
4323 |
4190 return in_array( $comment_type, (array) $allowed_comment_types, true ); |
4324 return in_array( $comment_type, (array) $allowed_comment_types, true ); |
4191 } |
4325 } |
4192 |
4326 |
4193 |
|
4194 /** |
4327 /** |
4195 * Retrieves default data about the avatar. |
4328 * Retrieves default data about the avatar. |
4196 * |
4329 * |
4197 * @since 4.2.0 |
4330 * @since 4.2.0 |
4198 * |
4331 * |
4199 * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash, |
4332 * @param mixed $id_or_email The avatar to retrieve. Accepts a user ID, Gravatar MD5 hash, |
4200 * user email, WP_User object, WP_Post object, or WP_Comment object. |
4333 * user email, WP_User object, WP_Post object, or WP_Comment object. |
4201 * @param array $args { |
4334 * @param array $args { |
4202 * Optional. Arguments to return instead of the default arguments. |
4335 * Optional. Arguments to use instead of the default arguments. |
4203 * |
4336 * |
4204 * @type int $size Height and width of the avatar image file in pixels. Default 96. |
4337 * @type int $size Height and width of the avatar in pixels. Default 96. |
4205 * @type int $height Display height of the avatar in pixels. Defaults to $size. |
4338 * @type int $height Display height of the avatar in pixels. Defaults to $size. |
4206 * @type int $width Display width of the avatar in pixels. Defaults to $size. |
4339 * @type int $width Display width of the avatar in pixels. Defaults to $size. |
4207 * @type string $default URL for the default image or a default type. Accepts '404' (return |
4340 * @type string $default URL for the default image or a default type. Accepts: |
4208 * a 404 instead of a default image), 'retro' (8bit), 'monsterid' (monster), |
4341 * - '404' (return a 404 instead of a default image) |
4209 * 'wavatar' (cartoon face), 'indenticon' (the "quilt"), 'mystery', 'mm', |
4342 * - 'retro' (a 8-bit arcade-style pixelated face) |
4210 * or 'mysteryman' (The Oyster Man), 'blank' (transparent GIF), or |
4343 * - 'robohash' (a robot) |
4211 * 'gravatar_default' (the Gravatar logo). Default is the value of the |
4344 * - 'monsterid' (a monster) |
4212 * 'avatar_default' option, with a fallback of 'mystery'. |
4345 * - 'wavatar' (a cartoon face) |
4213 * @type bool $force_default Whether to always show the default image, never the Gravatar. Default false. |
4346 * - 'identicon' (the "quilt", a geometric pattern) |
4214 * @type string $rating What rating to display avatars up to. Accepts 'G', 'PG', 'R', 'X', and are |
4347 * - 'mystery', 'mm', or 'mysteryman' (The Oyster Man) |
4215 * judged in that order. Default is the value of the 'avatar_rating' option. |
4348 * - 'blank' (transparent GIF) |
|
4349 * - 'gravatar_default' (the Gravatar logo) |
|
4350 * Default is the value of the 'avatar_default' option, |
|
4351 * with a fallback of 'mystery'. |
|
4352 * @type bool $force_default Whether to always show the default image, never the Gravatar. |
|
4353 * Default false. |
|
4354 * @type string $rating What rating to display avatars up to. Accepts: |
|
4355 * - 'G' (suitable for all audiences) |
|
4356 * - 'PG' (possibly offensive, usually for audiences 13 and above) |
|
4357 * - 'R' (intended for adult audiences above 17) |
|
4358 * - 'X' (even more mature than above) |
|
4359 * Default is the value of the 'avatar_rating' option. |
4216 * @type string $scheme URL scheme to use. See set_url_scheme() for accepted values. |
4360 * @type string $scheme URL scheme to use. See set_url_scheme() for accepted values. |
4217 * Default null. |
4361 * Default null. |
4218 * @type array $processed_args When the function returns, the value will be the processed/sanitized $args |
4362 * @type array $processed_args When the function returns, the value will be the processed/sanitized $args |
4219 * plus a "found_avatar" guess. Pass as a reference. Default null. |
4363 * plus a "found_avatar" guess. Pass as a reference. Default null. |
4220 * @type string $extra_attr HTML attributes to insert in the IMG element. Is not sanitized. Default empty. |
4364 * @type string $extra_attr HTML attributes to insert in the IMG element. Is not sanitized. |
|
4365 * Default empty. |
4221 * } |
4366 * } |
4222 * @return array { |
4367 * @return array { |
4223 * Along with the arguments passed in `$args`, this will contain a couple of extra arguments. |
4368 * Along with the arguments passed in `$args`, this will contain a couple of extra arguments. |
4224 * |
4369 * |
4225 * @type bool $found_avatar True if we were able to find an avatar for this user, |
4370 * @type bool $found_avatar True if an avatar was found for this user, |
4226 * false or not set if we couldn't. |
4371 * false or not set if none was found. |
4227 * @type string $url The URL of the avatar we found. |
4372 * @type string|false $url The URL of the avatar that was found, or false. |
4228 * } |
4373 * } |
4229 */ |
4374 */ |
4230 function get_avatar_data( $id_or_email, $args = null ) { |
4375 function get_avatar_data( $id_or_email, $args = null ) { |
4231 $args = wp_parse_args( |
4376 $args = wp_parse_args( |
4232 $args, |
4377 $args, |
4299 * the {@see 'get_avatar_data'} filter and returning early. |
4444 * the {@see 'get_avatar_data'} filter and returning early. |
4300 * |
4445 * |
4301 * @since 4.2.0 |
4446 * @since 4.2.0 |
4302 * |
4447 * |
4303 * @param array $args Arguments passed to get_avatar_data(), after processing. |
4448 * @param array $args Arguments passed to get_avatar_data(), after processing. |
4304 * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash, |
4449 * @param mixed $id_or_email The avatar to retrieve. Accepts a user ID, Gravatar MD5 hash, |
4305 * user email, WP_User object, WP_Post object, or WP_Comment object. |
4450 * user email, WP_User object, WP_Post object, or WP_Comment object. |
4306 */ |
4451 */ |
4307 $args = apply_filters( 'pre_get_avatar_data', $args, $id_or_email ); |
4452 $args = apply_filters( 'pre_get_avatar_data', $args, $id_or_email ); |
4308 |
4453 |
4309 if ( isset( $args['url'] ) ) { |
4454 if ( isset( $args['url'] ) ) { |
4390 * Filters the avatar URL. |
4535 * Filters the avatar URL. |
4391 * |
4536 * |
4392 * @since 4.2.0 |
4537 * @since 4.2.0 |
4393 * |
4538 * |
4394 * @param string $url The URL of the avatar. |
4539 * @param string $url The URL of the avatar. |
4395 * @param mixed $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash, |
4540 * @param mixed $id_or_email The avatar to retrieve. Accepts a user ID, Gravatar MD5 hash, |
4396 * user email, WP_User object, WP_Post object, or WP_Comment object. |
4541 * user email, WP_User object, WP_Post object, or WP_Comment object. |
4397 * @param array $args Arguments passed to get_avatar_data(), after processing. |
4542 * @param array $args Arguments passed to get_avatar_data(), after processing. |
4398 */ |
4543 */ |
4399 $args['url'] = apply_filters( 'get_avatar_url', $url, $id_or_email, $args ); |
4544 $args['url'] = apply_filters( 'get_avatar_url', $url, $id_or_email, $args ); |
4400 |
4545 |
4483 * @return string The path of the file. |
4630 * @return string The path of the file. |
4484 */ |
4631 */ |
4485 function get_theme_file_path( $file = '' ) { |
4632 function get_theme_file_path( $file = '' ) { |
4486 $file = ltrim( $file, '/' ); |
4633 $file = ltrim( $file, '/' ); |
4487 |
4634 |
|
4635 $stylesheet_directory = get_stylesheet_directory(); |
|
4636 $template_directory = get_template_directory(); |
|
4637 |
4488 if ( empty( $file ) ) { |
4638 if ( empty( $file ) ) { |
4489 $path = get_stylesheet_directory(); |
4639 $path = $stylesheet_directory; |
4490 } elseif ( file_exists( get_stylesheet_directory() . '/' . $file ) ) { |
4640 } elseif ( $stylesheet_directory !== $template_directory && file_exists( $stylesheet_directory . '/' . $file ) ) { |
4491 $path = get_stylesheet_directory() . '/' . $file; |
4641 $path = $stylesheet_directory . '/' . $file; |
4492 } else { |
4642 } else { |
4493 $path = get_template_directory() . '/' . $file; |
4643 $path = $template_directory . '/' . $file; |
4494 } |
4644 } |
4495 |
4645 |
4496 /** |
4646 /** |
4497 * Filters the path to a file in the theme. |
4647 * Filters the path to a file in the theme. |
4498 * |
4648 * |
4611 return $before . $link . $after; |
4762 return $before . $link . $after; |
4612 } |
4763 } |
4613 |
4764 |
4614 return ''; |
4765 return ''; |
4615 } |
4766 } |
|
4767 |
|
4768 /** |
|
4769 * Returns an array of URL hosts which are considered to be internal hosts. |
|
4770 * |
|
4771 * By default the list of internal hosts is comprised of the host name of |
|
4772 * the site's home_url() (as parsed by wp_parse_url()). |
|
4773 * |
|
4774 * This list is used when determining if a specified URL is a link to a page on |
|
4775 * the site itself or a link offsite (to an external host). This is used, for |
|
4776 * example, when determining if the "nofollow" attribute should be applied to a |
|
4777 * link. |
|
4778 * |
|
4779 * @see wp_is_internal_link |
|
4780 * |
|
4781 * @since 6.2.0 |
|
4782 * |
|
4783 * @return string[] An array of URL hosts. |
|
4784 */ |
|
4785 function wp_internal_hosts() { |
|
4786 static $internal_hosts; |
|
4787 |
|
4788 if ( empty( $internal_hosts ) ) { |
|
4789 /** |
|
4790 * Filters the array of URL hosts which are considered internal. |
|
4791 * |
|
4792 * @since 6.2.0 |
|
4793 * |
|
4794 * @param string[] $internal_hosts An array of internal URL hostnames. |
|
4795 */ |
|
4796 $internal_hosts = apply_filters( |
|
4797 'wp_internal_hosts', |
|
4798 array( |
|
4799 wp_parse_url( home_url(), PHP_URL_HOST ), |
|
4800 ) |
|
4801 ); |
|
4802 $internal_hosts = array_unique( |
|
4803 array_map( 'strtolower', (array) $internal_hosts ) |
|
4804 ); |
|
4805 } |
|
4806 |
|
4807 return $internal_hosts; |
|
4808 } |
|
4809 |
|
4810 /** |
|
4811 * Determines whether or not the specified URL is of a host included in the internal hosts list. |
|
4812 * |
|
4813 * @see wp_internal_hosts() |
|
4814 * |
|
4815 * @since 6.2.0 |
|
4816 * |
|
4817 * @param string $link The URL to test. |
|
4818 * @return bool Returns true for internal URLs and false for all other URLs. |
|
4819 */ |
|
4820 function wp_is_internal_link( $link ) { |
|
4821 $link = strtolower( $link ); |
|
4822 if ( in_array( wp_parse_url( $link, PHP_URL_SCHEME ), wp_allowed_protocols(), true ) ) { |
|
4823 return in_array( wp_parse_url( $link, PHP_URL_HOST ), wp_internal_hosts(), true ); |
|
4824 } |
|
4825 return false; |
|
4826 } |