From 193196a552e3648e97d35a3042d80d44972648d8 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Tue, 23 Feb 2016 20:06:25 +0000 Subject: [PATCH] Make `$taxonomy` parameter optional in `get_edit_term_link()`. Props nicdford, sc0ttkclark. Fixes #35922. git-svn-id: https://develop.svn.wordpress.org/trunk@36646 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/link-template.php | 15 ++++----- tests/phpunit/tests/term/getEditTermLink.php | 33 ++++++++++++++++++++ 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/wp-includes/link-template.php b/src/wp-includes/link-template.php index 3db5c289c8..d872123e61 100644 --- a/src/wp-includes/link-template.php +++ b/src/wp-includes/link-template.php @@ -907,21 +907,22 @@ function edit_tag_link( $link = '', $before = '', $after = '', $tag = null ) { * Retrieve edit term url. * * @since 3.1.0 + * @since 4.5.0 The `$taxonomy` argument was made optional. * * @param int $term_id Term ID. - * @param string $taxonomy Taxonomy. - * @param string $object_type The object type. Used to highlight the proper post type menu on the linked page. + * @param string $taxonomy Optional. Taxonomy. Defaults to the taxonomy of the term identified by `$term_id`. + * @param string $object_type Optional. The object type. Used to highlight the proper post type menu on the linked page. * Defaults to the first object_type associated with the taxonomy. * @return string|null The edit term link URL for the given term, or null on failure. */ -function get_edit_term_link( $term_id, $taxonomy, $object_type = '' ) { - $tax = get_taxonomy( $taxonomy ); - if ( ! $tax || ! current_user_can( $tax->cap->edit_terms ) ) { +function get_edit_term_link( $term_id, $taxonomy = '', $object_type = '' ) { + $term = get_term( $term_id, $taxonomy ); + if ( ! $term || is_wp_error( $term ) ) { return; } - $term = get_term( $term_id, $taxonomy ); - if ( ! $term || is_wp_error( $term ) ) { + $tax = get_taxonomy( $term->taxonomy ); + if ( ! $tax || ! current_user_can( $tax->cap->edit_terms ) ) { return; } diff --git a/tests/phpunit/tests/term/getEditTermLink.php b/tests/phpunit/tests/term/getEditTermLink.php index e6749da590..54023271d7 100644 --- a/tests/phpunit/tests/term/getEditTermLink.php +++ b/tests/phpunit/tests/term/getEditTermLink.php @@ -50,5 +50,38 @@ class Tests_Term_GetEditTermLink extends WP_UnitTestCase { $this->assertNull( $actual ); } + /** + * @ticket 35922 + */ + public function test_taxonomy_should_not_be_required() { + $t = self::factory()->term->create( array( + 'taxonomy' => 'wptests_tax', + 'name' => 'foo', + ) ); + $actual = get_edit_term_link( $t ); + $this->assertNotNull( $actual ); + } + + /** + * @ticket 35922 + */ + public function test_cap_check_should_use_correct_taxonomy_when_taxonomy_is_not_specified() { + register_taxonomy( 'wptests_tax_subscriber', 'post', array( + 'manage_terms' => 'read', + ) ); + + $t = self::factory()->term->create( array( + 'taxonomy' => 'wptests_tax', + 'name' => 'foo', + ) ); + + $u = self::factory()->user->create( array( + 'role' => 'subscriber', + ) ); + wp_set_current_user( $u ); + + $actual = get_edit_term_link( $t ); + $this->assertNull( $actual ); + } }