902 * Returns a link to the feed for all posts in a given category. A specific feed |
902 * Returns a link to the feed for all posts in a given category. A specific feed |
903 * can be requested or left blank to get the default feed. |
903 * can be requested or left blank to get the default feed. |
904 * |
904 * |
905 * @since 2.5.0 |
905 * @since 2.5.0 |
906 * |
906 * |
907 * @param int $cat_id Category ID. |
907 * @param int|WP_Term|object $cat The ID or category object whose feed link will be retrieved. |
908 * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
908 * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
909 * Default is the value of get_default_feed(). |
909 * Default is the value of get_default_feed(). |
910 * @return string Link to the feed for the category specified by $cat_id. |
910 * @return string Link to the feed for the category specified by `$cat`. |
911 */ |
911 */ |
912 function get_category_feed_link( $cat_id, $feed = '' ) { |
912 function get_category_feed_link( $cat, $feed = '' ) { |
913 return get_term_feed_link( $cat_id, 'category', $feed ); |
913 return get_term_feed_link( $cat, 'category', $feed ); |
914 } |
914 } |
915 |
915 |
916 /** |
916 /** |
917 * Retrieves the feed link for a term. |
917 * Retrieves the feed link for a term. |
918 * |
918 * |
919 * Returns a link to the feed for all posts in a given term. A specific feed |
919 * Returns a link to the feed for all posts in a given term. A specific feed |
920 * can be requested or left blank to get the default feed. |
920 * can be requested or left blank to get the default feed. |
921 * |
921 * |
922 * @since 3.0.0 |
922 * @since 3.0.0 |
923 * |
923 * |
924 * @param int $term_id Term ID. |
924 * @param int|WP_Term|object $term The ID or term object whose feed link will be retrieved. |
925 * @param string $taxonomy Optional. Taxonomy of `$term_id`. Default 'category'. |
925 * @param string $taxonomy Optional. Taxonomy of `$term_id`. |
926 * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
926 * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
927 * Default is the value of get_default_feed(). |
927 * Default is the value of get_default_feed(). |
928 * @return string|false Link to the feed for the term specified by $term_id and $taxonomy. |
928 * @return string|false Link to the feed for the term specified by `$term` and `$taxonomy`. |
929 */ |
929 */ |
930 function get_term_feed_link( $term_id, $taxonomy = 'category', $feed = '' ) { |
930 function get_term_feed_link( $term, $taxonomy = '', $feed = '' ) { |
931 $term_id = (int) $term_id; |
931 if ( ! is_object( $term ) ) { |
932 |
932 $term = (int) $term; |
933 $term = get_term( $term_id, $taxonomy ); |
933 } |
|
934 |
|
935 $term = get_term( $term, $taxonomy ); |
934 |
936 |
935 if ( empty( $term ) || is_wp_error( $term ) ) { |
937 if ( empty( $term ) || is_wp_error( $term ) ) { |
936 return false; |
938 return false; |
937 } |
939 } |
938 |
940 |
|
941 $taxonomy = $term->taxonomy; |
|
942 |
939 if ( empty( $feed ) ) { |
943 if ( empty( $feed ) ) { |
940 $feed = get_default_feed(); |
944 $feed = get_default_feed(); |
941 } |
945 } |
942 |
946 |
943 $permalink_structure = get_option( 'permalink_structure' ); |
947 $permalink_structure = get_option( 'permalink_structure' ); |
944 |
948 |
945 if ( ! $permalink_structure ) { |
949 if ( ! $permalink_structure ) { |
946 if ( 'category' === $taxonomy ) { |
950 if ( 'category' === $taxonomy ) { |
947 $link = home_url( "?feed=$feed&cat=$term_id" ); |
951 $link = home_url( "?feed=$feed&cat=$term->term_id" ); |
948 } elseif ( 'post_tag' === $taxonomy ) { |
952 } elseif ( 'post_tag' === $taxonomy ) { |
949 $link = home_url( "?feed=$feed&tag=$term->slug" ); |
953 $link = home_url( "?feed=$feed&tag=$term->slug" ); |
950 } else { |
954 } else { |
951 $t = get_taxonomy( $taxonomy ); |
955 $t = get_taxonomy( $taxonomy ); |
952 $link = home_url( "?feed=$feed&$t->query_var=$term->slug" ); |
956 $link = home_url( "?feed=$feed&$t->query_var=$term->slug" ); |
953 } |
957 } |
954 } else { |
958 } else { |
955 $link = get_term_link( $term_id, $term->taxonomy ); |
959 $link = get_term_link( $term, $term->taxonomy ); |
956 if ( get_default_feed() == $feed ) { |
960 if ( get_default_feed() == $feed ) { |
957 $feed_link = 'feed'; |
961 $feed_link = 'feed'; |
958 } else { |
962 } else { |
959 $feed_link = "feed/$feed"; |
963 $feed_link = "feed/$feed"; |
960 } |
964 } |
1001 /** |
1005 /** |
1002 * Retrieves the permalink for a tag feed. |
1006 * Retrieves the permalink for a tag feed. |
1003 * |
1007 * |
1004 * @since 2.3.0 |
1008 * @since 2.3.0 |
1005 * |
1009 * |
1006 * @param int $tag_id Tag ID. |
1010 * @param int|WP_Term|object $tag The ID or term object whose feed link will be retrieved. |
1007 * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
1011 * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. |
1008 * Default is the value of get_default_feed(). |
1012 * Default is the value of get_default_feed(). |
1009 * @return string The feed permalink for the given tag. |
1013 * @return string The feed permalink for the given tag. |
1010 */ |
1014 */ |
1011 function get_tag_feed_link( $tag_id, $feed = '' ) { |
1015 function get_tag_feed_link( $tag, $feed = '' ) { |
1012 return get_term_feed_link( $tag_id, 'post_tag', $feed ); |
1016 return get_term_feed_link( $tag, 'post_tag', $feed ); |
1013 } |
1017 } |
1014 |
1018 |
1015 /** |
1019 /** |
1016 * Retrieves the edit link for a tag. |
1020 * Retrieves the edit link for a tag. |
1017 * |
1021 * |
1018 * @since 2.7.0 |
1022 * @since 2.7.0 |
1019 * |
1023 * |
1020 * @param int $tag_id Tag ID. |
1024 * @param int|WP_Term|object $tag The ID or term object whose edit link will be retrieved. |
1021 * @param string $taxonomy Optional. Taxonomy slug. Default 'post_tag'. |
1025 * @param string $taxonomy Optional. Taxonomy slug. Default 'post_tag'. |
1022 * @return string The edit tag link URL for the given tag. |
1026 * @return string The edit tag link URL for the given tag. |
1023 */ |
1027 */ |
1024 function get_edit_tag_link( $tag_id, $taxonomy = 'post_tag' ) { |
1028 function get_edit_tag_link( $tag, $taxonomy = 'post_tag' ) { |
1025 /** |
1029 /** |
1026 * Filters the edit link for a tag (or term in another taxonomy). |
1030 * Filters the edit link for a tag (or term in another taxonomy). |
1027 * |
1031 * |
1028 * @since 2.7.0 |
1032 * @since 2.7.0 |
1029 * |
1033 * |
1030 * @param string $link The term edit link. |
1034 * @param string $link The term edit link. |
1031 */ |
1035 */ |
1032 return apply_filters( 'get_edit_tag_link', get_edit_term_link( $tag_id, $taxonomy ) ); |
1036 return apply_filters( 'get_edit_tag_link', get_edit_term_link( $tag, $taxonomy ) ); |
1033 } |
1037 } |
1034 |
1038 |
1035 /** |
1039 /** |
1036 * Displays or retrieves the edit link for a tag with formatting. |
1040 * Displays or retrieves the edit link for a tag with formatting. |
1037 * |
1041 * |
1060 * Retrieves the URL for editing a given term. |
1064 * Retrieves the URL for editing a given term. |
1061 * |
1065 * |
1062 * @since 3.1.0 |
1066 * @since 3.1.0 |
1063 * @since 4.5.0 The `$taxonomy` parameter was made optional. |
1067 * @since 4.5.0 The `$taxonomy` parameter was made optional. |
1064 * |
1068 * |
1065 * @param int $term_id Term ID. |
1069 * @param int|WP_Term|object $term The ID or term object whose edit link will be retrieved. |
1066 * @param string $taxonomy Optional. Taxonomy. Defaults to the taxonomy of the term identified |
1070 * @param string $taxonomy Optional. Taxonomy. Defaults to the taxonomy of the term identified |
1067 * by `$term_id`. |
1071 * by `$term`. |
1068 * @param string $object_type Optional. The object type. Used to highlight the proper post type |
1072 * @param string $object_type Optional. The object type. Used to highlight the proper post type |
1069 * menu on the linked page. Defaults to the first object_type associated |
1073 * menu on the linked page. Defaults to the first object_type associated |
1070 * with the taxonomy. |
1074 * with the taxonomy. |
1071 * @return string|null The edit term link URL for the given term, or null on failure. |
1075 * @return string|null The edit term link URL for the given term, or null on failure. |
1072 */ |
1076 */ |
1073 function get_edit_term_link( $term_id, $taxonomy = '', $object_type = '' ) { |
1077 function get_edit_term_link( $term, $taxonomy = '', $object_type = '' ) { |
1074 $term = get_term( $term_id, $taxonomy ); |
1078 $term = get_term( $term, $taxonomy ); |
1075 if ( ! $term || is_wp_error( $term ) ) { |
1079 if ( ! $term || is_wp_error( $term ) ) { |
1076 return; |
1080 return; |
1077 } |
1081 } |
1078 |
1082 |
1079 $tax = get_taxonomy( $term->taxonomy ); |
1083 $tax = get_taxonomy( $term->taxonomy ); |
1080 if ( ! $tax || ! current_user_can( 'edit_term', $term->term_id ) ) { |
1084 $term_id = $term->term_id; |
|
1085 if ( ! $tax || ! current_user_can( 'edit_term', $term_id ) ) { |
1081 return; |
1086 return; |
1082 } |
1087 } |
1083 |
1088 |
1084 $args = array( |
1089 $args = array( |
1085 'taxonomy' => $taxonomy, |
1090 'taxonomy' => $taxonomy, |
1086 'tag_ID' => $term->term_id, |
1091 'tag_ID' => $term_id, |
1087 ); |
1092 ); |
1088 |
1093 |
1089 if ( $object_type ) { |
1094 if ( $object_type ) { |
1090 $args['post_type'] = $object_type; |
1095 $args['post_type'] = $object_type; |
1091 } elseif ( ! empty( $tax->object_type ) ) { |
1096 } elseif ( ! empty( $tax->object_type ) ) { |
1104 * @since 3.1.0 |
1109 * @since 3.1.0 |
1105 * |
1110 * |
1106 * @param string $location The edit link. |
1111 * @param string $location The edit link. |
1107 * @param int $term_id Term ID. |
1112 * @param int $term_id Term ID. |
1108 * @param string $taxonomy Taxonomy name. |
1113 * @param string $taxonomy Taxonomy name. |
1109 * @param string $object_type The object type (eg. the post type). |
1114 * @param string $object_type The object type. |
1110 */ |
1115 */ |
1111 return apply_filters( 'get_edit_term_link', $location, $term_id, $taxonomy, $object_type ); |
1116 return apply_filters( 'get_edit_term_link', $location, $term_id, $taxonomy, $object_type ); |
1112 } |
1117 } |
1113 |
1118 |
1114 /** |
1119 /** |
1115 * Displays or retrieves the edit term link with formatting. |
1120 * Displays or retrieves the edit term link with formatting. |
1116 * |
1121 * |
1117 * @since 3.1.0 |
1122 * @since 3.1.0 |
1118 * |
1123 * |
1119 * @param string $link Optional. Anchor text. If empty, default is 'Edit This'. Default empty. |
1124 * @param string $link Optional. Anchor text. If empty, default is 'Edit This'. Default empty. |
1120 * @param string $before Optional. Display before edit link. Default empty. |
1125 * @param string $before Optional. Display before edit link. Default empty. |
1121 * @param string $after Optional. Display after edit link. Default empty. |
1126 * @param string $after Optional. Display after edit link. Default empty. |
1122 * @param WP_Term $term Optional. Term object. If null, the queried object will be inspected. Default null. |
1127 * @param int|WP_Term|null $term Optional. Term ID or object. If null, the queried object will be inspected. Default null. |
1123 * @param bool $echo Optional. Whether or not to echo the return. Default true. |
1128 * @param bool $echo Optional. Whether or not to echo the return. Default true. |
1124 * @return string|void HTML content. |
1129 * @return string|void HTML content. |
1125 */ |
1130 */ |
1126 function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) { |
1131 function edit_term_link( $link = '', $before = '', $after = '', $term = null, $echo = true ) { |
1127 if ( is_null( $term ) ) { |
1132 if ( is_null( $term ) ) { |
1128 $term = get_queried_object(); |
1133 $term = get_queried_object(); |
|
1134 } else { |
|
1135 $term = get_term( $term ); |
1129 } |
1136 } |
1130 |
1137 |
1131 if ( ! $term ) { |
1138 if ( ! $term ) { |
1132 return; |
1139 return; |
1133 } |
1140 } |
1737 * @since 1.5.0 |
1744 * @since 1.5.0 |
1738 * |
1745 * |
1739 * @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false. |
1746 * @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false. |
1740 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
1747 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
1741 * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
1748 * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
1742 * @return null|string|WP_Post Post object if successful. Null if global $post is not set. Empty string if no |
1749 * @return WP_Post|null|string Post object if successful. Null if global $post is not set. Empty string if no |
1743 * corresponding post exists. |
1750 * corresponding post exists. |
1744 */ |
1751 */ |
1745 function get_previous_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
1752 function get_previous_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
1746 return get_adjacent_post( $in_same_term, $excluded_terms, true, $taxonomy ); |
1753 return get_adjacent_post( $in_same_term, $excluded_terms, true, $taxonomy ); |
1747 } |
1754 } |
1752 * @since 1.5.0 |
1759 * @since 1.5.0 |
1753 * |
1760 * |
1754 * @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false. |
1761 * @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false. |
1755 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
1762 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty. |
1756 * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
1763 * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
1757 * @return null|string|WP_Post Post object if successful. Null if global $post is not set. Empty string if no |
1764 * @return WP_Post|null|string Post object if successful. Null if global $post is not set. Empty string if no |
1758 * corresponding post exists. |
1765 * corresponding post exists. |
1759 */ |
1766 */ |
1760 function get_next_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
1767 function get_next_post( $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' ) { |
1761 return get_adjacent_post( $in_same_term, $excluded_terms, false, $taxonomy ); |
1768 return get_adjacent_post( $in_same_term, $excluded_terms, false, $taxonomy ); |
1762 } |
1769 } |
1772 * |
1779 * |
1773 * @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false. |
1780 * @param bool $in_same_term Optional. Whether post should be in a same taxonomy term. Default false. |
1774 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty string. |
1781 * @param int[]|string $excluded_terms Optional. Array or comma-separated list of excluded term IDs. Default empty string. |
1775 * @param bool $previous Optional. Whether to retrieve previous post. Default true |
1782 * @param bool $previous Optional. Whether to retrieve previous post. Default true |
1776 * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
1783 * @param string $taxonomy Optional. Taxonomy, if $in_same_term is true. Default 'category'. |
1777 * @return null|string|WP_Post Post object if successful. Null if global $post is not set. Empty string if no |
1784 * @return WP_Post|null|string Post object if successful. Null if global $post is not set. Empty string if no |
1778 * corresponding post exists. |
1785 * corresponding post exists. |
1779 */ |
1786 */ |
1780 function get_adjacent_post( $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { |
1787 function get_adjacent_post( $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) { |
1781 global $wpdb; |
1788 global $wpdb; |
1782 |
1789 |
1828 */ |
1835 */ |
1829 $excluded_terms = apply_filters( "get_{$adjacent}_post_excluded_terms", $excluded_terms ); |
1836 $excluded_terms = apply_filters( "get_{$adjacent}_post_excluded_terms", $excluded_terms ); |
1830 |
1837 |
1831 if ( $in_same_term || ! empty( $excluded_terms ) ) { |
1838 if ( $in_same_term || ! empty( $excluded_terms ) ) { |
1832 if ( $in_same_term ) { |
1839 if ( $in_same_term ) { |
1833 $join .= " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id"; |
1840 $join .= " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id"; |
1834 $where .= $wpdb->prepare( 'AND tt.taxonomy = %s', $taxonomy ); |
1841 $where .= $wpdb->prepare( 'AND tt.taxonomy = %s', $taxonomy ); |
1835 |
1842 |
1836 if ( ! is_object_in_taxonomy( $post->post_type, $taxonomy ) ) { |
1843 if ( ! is_object_in_taxonomy( $post->post_type, $taxonomy ) ) { |
1837 return ''; |
1844 return ''; |
1838 } |
1845 } |
1870 * Results should include private posts belonging to the current user, or private posts where the |
1877 * Results should include private posts belonging to the current user, or private posts where the |
1871 * current user has the 'read_private_posts' cap. |
1878 * current user has the 'read_private_posts' cap. |
1872 */ |
1879 */ |
1873 $private_states = get_post_stati( array( 'private' => true ) ); |
1880 $private_states = get_post_stati( array( 'private' => true ) ); |
1874 $where .= " AND ( p.post_status = 'publish'"; |
1881 $where .= " AND ( p.post_status = 'publish'"; |
1875 foreach ( (array) $private_states as $state ) { |
1882 foreach ( $private_states as $state ) { |
1876 if ( current_user_can( $read_private_cap ) ) { |
1883 if ( current_user_can( $read_private_cap ) ) { |
1877 $where .= $wpdb->prepare( ' OR p.post_status = %s', $state ); |
1884 $where .= $wpdb->prepare( ' OR p.post_status = %s', $state ); |
1878 } else { |
1885 } else { |
1879 $where .= $wpdb->prepare( ' OR (p.post_author = %d AND p.post_status = %s)', $user_id, $state ); |
1886 $where .= $wpdb->prepare( ' OR (p.post_author = %d AND p.post_status = %s)', $user_id, $state ); |
1880 } |
1887 } |
3978 * filter. |
3985 * filter. |
3979 * |
3986 * |
3980 * @since 3.0.0 |
3987 * @since 3.0.0 |
3981 * |
3988 * |
3982 * @param int $id Optional. A post or site ID. Default is 0, which means the current post or site. |
3989 * @param int $id Optional. A post or site ID. Default is 0, which means the current post or site. |
3983 * @param string $context Optional. Whether the ID is a 'site' id, 'post' id, or 'media' id. If 'post', |
3990 * @param string $context Optional. Whether the ID is a 'site' ID, 'post' ID, or 'media' ID. If 'post', |
3984 * the post_type of the post is consulted. If 'query', the current query is consulted |
3991 * the post_type of the post is consulted. If 'query', the current query is consulted |
3985 * to determine the ID and context. Default 'post'. |
3992 * to determine the ID and context. Default 'post'. |
3986 * @param bool $allow_slugs Optional. Whether to allow post slugs in the shortlink. It is up to the plugin how |
3993 * @param bool $allow_slugs Optional. Whether to allow post slugs in the shortlink. It is up to the plugin how |
3987 * and whether to honor this. Default true. |
3994 * and whether to honor this. Default true. |
3988 * @return string A shortlink or an empty string if no shortlink exists for the requested resource or if shortlinks |
3995 * @return string A shortlink or an empty string if no shortlink exists for the requested resource or if shortlinks |