Changeset 52180
- Timestamp:
- 11/16/2021 02:55:04 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-terms-list-table.php
r51896 r52180 398 398 $uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI']; 399 399 400 $edit_link = get_edit_term_link( $tag ->term_id, $taxonomy, $this->screen->post_type );400 $edit_link = get_edit_term_link( $tag, $taxonomy, $this->screen->post_type ); 401 401 402 402 if ( $edit_link ) { … … 467 467 'wp_http_referer', 468 468 urlencode( wp_unslash( $uri ) ), 469 get_edit_term_link( $tag ->term_id, $taxonomy, $this->screen->post_type )469 get_edit_term_link( $tag, $taxonomy, $this->screen->post_type ) 470 470 ); 471 471 -
trunk/src/wp-includes/category-template.php
r51837 r52180 738 738 foreach ( $tags as $key => $tag ) { 739 739 if ( 'edit' === $args['link'] ) { 740 $link = get_edit_term_link( $tag ->term_id, $tag->taxonomy, $args['post_type'] );740 $link = get_edit_term_link( $tag, $tag->taxonomy, $args['post_type'] ); 741 741 } else { 742 $link = get_term_link( (int) $tag->term_id, $tag->taxonomy );742 $link = get_term_link( $tag, $tag->taxonomy ); 743 743 } 744 744 -
trunk/src/wp-includes/class-walker-category.php
r51780 r52180 165 165 } 166 166 167 $link .= '<a href="' . esc_url( get_term_feed_link( $category ->term_id, $category->taxonomy, $args['feed_type'] ) ) . '"';167 $link .= '<a href="' . esc_url( get_term_feed_link( $category, $category->taxonomy, $args['feed_type'] ) ) . '"'; 168 168 169 169 if ( empty( $args['feed'] ) ) { -
trunk/src/wp-includes/link-template.php
r52111 r52180 905 905 * @since 2.5.0 906 906 * 907 * @param int $cat_id Category ID.908 * @param string $feedOptional. Feed type. Possible values include 'rss2', 'atom'.909 * Default is the value of get_default_feed().907 * @param int|WP_Term|object $cat The ID or term object whose feed link will be retrieved. 908 * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. 909 * Default is the value of get_default_feed(). 910 910 * @return string Link to the feed for the category specified by $cat_id. 911 911 */ 912 function get_category_feed_link( $cat _id, $feed = '' ) {913 return get_term_feed_link( $cat _id, 'category', $feed );912 function get_category_feed_link( $cat, $feed = '' ) { 913 return get_term_feed_link( $cat, 'category', $feed ); 914 914 } 915 915 … … 922 922 * @since 3.0.0 923 923 * 924 * @param int $term_id Term ID. 925 * @param string $taxonomy Optional. Taxonomy of `$term_id`. Default 'category'. 926 * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. 927 * Default is the value of get_default_feed(). 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`. 926 * Defaults to 'category' if term ID or non WP_Term object is passed. 927 * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. 928 * Default is the value of get_default_feed(). 928 929 * @return string|false Link to the feed for the term specified by $term_id and $taxonomy. 929 930 */ 930 function get_term_feed_link( $term_id, $taxonomy = 'category', $feed = '' ) { 931 $term_id = (int) $term_id; 932 933 $term = get_term( $term_id, $taxonomy ); 931 function get_term_feed_link( $term, $taxonomy = '', $feed = '' ) { 932 if ( ! is_object( $term ) ) { 933 $term = (int) $term; 934 $taxonomy = 'category'; 935 } elseif ( ! $term instanceof WP_Term ) { 936 $taxonomy = $term->taxonomy; 937 } 938 939 $term = get_term( $term, $taxonomy ); 934 940 935 941 if ( empty( $term ) || is_wp_error( $term ) ) { … … 945 951 if ( ! $permalink_structure ) { 946 952 if ( 'category' === $taxonomy ) { 947 $link = home_url( "?feed=$feed&cat=$term _id" );953 $link = home_url( "?feed=$feed&cat=$term->term_id" ); 948 954 } elseif ( 'post_tag' === $taxonomy ) { 949 955 $link = home_url( "?feed=$feed&tag=$term->slug" ); … … 953 959 } 954 960 } else { 955 $link = get_term_link( $term _id, $term->taxonomy );961 $link = get_term_link( $term, $term->taxonomy ); 956 962 if ( get_default_feed() == $feed ) { 957 963 $feed_link = 'feed'; … … 1004 1010 * @since 2.3.0 1005 1011 * 1006 * @param int $tag_id Tag ID.1007 * @param string $feedOptional. Feed type. Possible values include 'rss2', 'atom'.1008 * Default is the value of get_default_feed().1009 * @return string The feed permalink for the given tag.1010 */ 1011 function get_tag_feed_link( $tag _id, $feed = '' ) {1012 return get_term_feed_link( $tag _id, 'post_tag', $feed );1012 * @param int|WP_Term|object $tag The ID or term object whose feed link will be retrieved. 1013 * @param string $feed Optional. Feed type. Possible values include 'rss2', 'atom'. 1014 * Default is the value of get_default_feed(). 1015 * @return string The feed permalink for the given tag. 1016 */ 1017 function get_tag_feed_link( $tag, $feed = '' ) { 1018 return get_term_feed_link( $tag, 'post_tag', $feed ); 1013 1019 } 1014 1020 … … 1018 1024 * @since 2.7.0 1019 1025 * 1020 * @param int $tag_id Tag ID.1021 * @param string $taxonomy Optional. Taxonomy slug. Default 'post_tag'.1026 * @param int|WP_Term|object $tag The ID or term object whose edit link will be retrieved. 1027 * @param string $taxonomy Optional. Taxonomy slug. Default 'post_tag'. 1022 1028 * @return string The edit tag link URL for the given tag. 1023 1029 */ 1024 function get_edit_tag_link( $tag _id, $taxonomy = 'post_tag' ) {1030 function get_edit_tag_link( $tag, $taxonomy = 'post_tag' ) { 1025 1031 /** 1026 1032 * Filters the edit link for a tag (or term in another taxonomy). … … 1030 1036 * @param string $link The term edit link. 1031 1037 */ 1032 return apply_filters( 'get_edit_tag_link', get_edit_term_link( $tag _id, $taxonomy ) );1038 return apply_filters( 'get_edit_tag_link', get_edit_term_link( $tag, $taxonomy ) ); 1033 1039 } 1034 1040 … … 1063 1069 * @since 4.5.0 The `$taxonomy` parameter was made optional. 1064 1070 * 1065 * @param int $term_id Term ID.1066 * @param string $taxonomy Optional. Taxonomy. Defaults to the taxonomy of the term identified1067 * by `$term_id`.1068 * @param string $object_type Optional. The object type. Used to highlight the proper post type1069 * menu on the linked page. Defaults to the first object_type associated1070 * with the taxonomy.1071 * @param int|WP_Term|object $term The ID or term object whose edit link will be retrieved. 1072 * @param string $taxonomy Optional. Taxonomy. Defaults to the taxonomy of the term identified 1073 * by `$term`. 1074 * @param string $object_type Optional. The object type. Used to highlight the proper post type 1075 * menu on the linked page. Defaults to the first object_type associated 1076 * with the taxonomy. 1071 1077 * @return string|null The edit term link URL for the given term, or null on failure. 1072 1078 */ 1073 function get_edit_term_link( $term _id, $taxonomy = '', $object_type = '' ) {1074 $term = get_term( $term _id, $taxonomy );1079 function get_edit_term_link( $term, $taxonomy = '', $object_type = '' ) { 1080 $term = get_term( $term, $taxonomy ); 1075 1081 if ( ! $term || is_wp_error( $term ) ) { 1076 1082 return; 1077 1083 } 1078 1084 1079 $tax = get_taxonomy( $term->taxonomy ); 1080 if ( ! $tax || ! current_user_can( 'edit_term', $term->term_id ) ) { 1085 $tax = get_taxonomy( $term->taxonomy ); 1086 $term_id = $term->term_id; 1087 if ( ! $tax || ! current_user_can( 'edit_term', $term_id ) ) { 1081 1088 return; 1082 1089 } … … 1084 1091 $args = array( 1085 1092 'taxonomy' => $taxonomy, 1086 'tag_ID' => $term ->term_id,1093 'tag_ID' => $term_id, 1087 1094 ); 1088 1095 … … 1117 1124 * @since 3.1.0 1118 1125 * 1119 * @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.1121 * @param string $after Optional. Display after edit link. Default empty.1122 * @param WP_Term $term Optional. Termobject. If null, the queried object will be inspected. Default null.1123 * @param bool $echo Optional. Whether or not to echo the return. Default true.1126 * @param string $link Optional. Anchor text. If empty, default is 'Edit This'. Default empty. 1127 * @param string $before Optional. Display before edit link. Default empty. 1128 * @param string $after Optional. Display after edit link. Default empty. 1129 * @param int|WP_Term|null $term Optional. Term ID or object. If null, the queried object will be inspected. Default null. 1130 * @param bool $echo Optional. Whether or not to echo the return. Default true. 1124 1131 * @return string|void HTML content. 1125 1132 */ … … 1127 1134 if ( is_null( $term ) ) { 1128 1135 $term = get_queried_object(); 1136 } else { 1137 $term = get_term( $term ); 1129 1138 } 1130 1139 -
trunk/tests/phpunit/tests/term/getTermLink.php
r51568 r52180 3 3 /** 4 4 * @group taxonomy 5 * @covers ::get_term_link 5 6 */ 6 7 class Tests_Term_GetTermLink extends WP_UnitTestCase { 7 8 9 public static $terms; 10 11 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 12 self::register_custom_taxonomy(); 13 14 $taxonomies = array( 'category', 'post_tag', 'wptests_tax' ); 15 foreach ( $taxonomies as $taxonomy ) { 16 self::$terms[ $taxonomy ] = $factory->term->create_and_get( array( 'taxonomy' => $taxonomy ) ); 17 } 18 } 19 8 20 public function set_up() { 9 21 parent::set_up(); 10 11 register_taxonomy( 'wptests_tax', 'post' ); 22 self::register_custom_taxonomy(); 12 23 } 13 24 … … 208 219 $this->assertStringContainsString( '/foo/term2/', $actual ); 209 220 } 221 222 /** 223 * @dataProvider data_get_term_link 224 * 225 * @ticket 50225 226 * 227 * @param string $taxonomy Taxonomy been tested (used for index of term keys). 228 * @param bool $use_id When true, pass term ID. Else, pass term object. 229 */ 230 public function test_get_term_link_filter_is_object_by_term_id( $taxonomy, $use_id ) { 231 $term = $this->get_term( $taxonomy, $use_id ); 232 233 add_filter( 234 'term_link', 235 function( $location, $term ) { 236 $this->assertInstanceOf( 'WP_Term', $term ); 237 }, 238 10, 239 2 240 ); 241 242 get_term_link( $term, $taxonomy ); 243 } 244 245 /** 246 * @dataProvider data_get_term_link 247 * 248 * @ticket 50225 249 * 250 * @param string $taxonomy Taxonomy been tested (used for index of term keys). 251 * @param bool $use_id When true, pass term ID. Else, pass term object. 252 */ 253 public function test_get_term_link_filter_is_object_by_term_object( $taxonomy, $use_id ) { 254 $term = $this->get_term( $taxonomy, $use_id ); 255 256 add_filter( 257 'term_link', 258 function( $location, $term ) { 259 $this->assertInstanceOf( 'WP_Term', $term ); 260 }, 261 10, 262 2 263 ); 264 265 get_term_link( get_term( $term, $taxonomy ), $taxonomy ); 266 } 267 268 /** 269 * Data provider. 270 * 271 * @return array 272 */ 273 public function data_get_term_link() { 274 return array( 275 'category passing term_id' => array( 276 'taxonomy' => 'category', 277 'use_id' => false, 278 ), 279 'category passing term object' => array( 280 'taxonomy' => 'category', 281 'use_id' => true, 282 ), 283 'post_tag passing term_id' => array( 284 'taxonomy' => 'post_tag', 285 'use_id' => false, 286 ), 287 'post_tag passing term object' => array( 288 'taxonomy' => 'post_tag', 289 'use_id' => true, 290 ), 291 'a custom taxonomy passing term_id' => array( 292 'taxonomy' => 'wptests_tax', 293 'use_id' => false, 294 ), 295 'a custom taxonomy passing term_id' => array( 296 'taxonomy' => 'wptests_tax', 297 'use_id' => true, 298 'expected' => 'term.php?taxonomy=custom_taxonomy&tag_ID=%ID%&post_type=post', 299 ), 300 ); 301 } 302 303 /** 304 * Helper to register a custom taxonomy for use in tests. 305 * 306 * @since 5.9.0 307 */ 308 private static function register_custom_taxonomy() { 309 register_taxonomy( 'wptests_tax', 'post' ); 310 } 311 312 /** 313 * Helper to get the term for the given taxonomy. 314 * 315 * @since 5.9.0 316 * 317 * @param string $taxonomy Taxonomy been tested (used for index of term keys). 318 * @param bool $use_id When true, pass term ID. Else, pass term object. 319 * @return WP_Term|int If $use_id is true, term ID is returned; else instance of WP_Term. 320 */ 321 private function get_term( $taxonomy, $use_id ) { 322 $term = self::$terms[ $taxonomy ]; 323 if ( $use_id ) { 324 $term = $term->term_id; 325 } 326 327 return $term; 328 } 210 329 }
Note: See TracChangeset
for help on using the changeset viewer.