Make WordPress Core

Changeset 36646


Ignore:
Timestamp:
02/23/2016 08:06:25 PM (10 years ago)
Author:
boonebgorges
Message:

Make $taxonomy parameter optional in get_edit_term_link().

Props nicdford, sc0ttkclark.
Fixes #35922.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/link-template.php

    r36494 r36646  
    908908 *
    909909 * @since 3.1.0
     910 * @since 4.5.0 The `$taxonomy` argument was made optional.
    910911 *
    911912 * @param int    $term_id     Term ID.
    912  * @param string $taxonomy    Taxonomy.
    913  * @param string $object_type The object type. Used to highlight the proper post type menu on the linked page.
     913 * @param string $taxonomy    Optional. Taxonomy. Defaults to the taxonomy of the term identified by `$term_id`.
     914 * @param string $object_type Optional. The object type. Used to highlight the proper post type menu on the linked page.
    914915 *                            Defaults to the first object_type associated with the taxonomy.
    915916 * @return string|null The edit term link URL for the given term, or null on failure.
    916917 */
    917 function get_edit_term_link( $term_id, $taxonomy, $object_type = '' ) {
    918         $tax = get_taxonomy( $taxonomy );
    919         if ( ! $tax || ! current_user_can( $tax->cap->edit_terms ) ) {
    920                 return;
    921         }
    922 
     918function get_edit_term_link( $term_id, $taxonomy = '', $object_type = '' ) {
    923919        $term = get_term( $term_id, $taxonomy );
    924920        if ( ! $term || is_wp_error( $term ) ) {
     921                return;
     922        }
     923
     924        $tax = get_taxonomy( $term->taxonomy );
     925        if ( ! $tax || ! current_user_can( $tax->cap->edit_terms ) ) {
    925926                return;
    926927        }
  • trunk/tests/phpunit/tests/term/getEditTermLink.php

    r36309 r36646  
    5151        }
    5252
     53        /**
     54         * @ticket 35922
     55         */
     56        public function test_taxonomy_should_not_be_required() {
     57                $t = self::factory()->term->create( array(
     58                        'taxonomy' => 'wptests_tax',
     59                        'name' => 'foo',
     60                ) );
    5361
     62                $actual = get_edit_term_link( $t );
     63                $this->assertNotNull( $actual );
     64        }
     65
     66        /**
     67         * @ticket 35922
     68         */
     69        public function test_cap_check_should_use_correct_taxonomy_when_taxonomy_is_not_specified() {
     70                register_taxonomy( 'wptests_tax_subscriber', 'post', array(
     71                        'manage_terms' => 'read',
     72                ) );
     73
     74                $t = self::factory()->term->create( array(
     75                        'taxonomy' => 'wptests_tax',
     76                        'name' => 'foo',
     77                ) );
     78
     79                $u = self::factory()->user->create( array(
     80                        'role' => 'subscriber',
     81                ) );
     82                wp_set_current_user( $u );
     83
     84                $actual = get_edit_term_link( $t );
     85                $this->assertNull( $actual );
     86        }
    5487}
Note: See TracChangeset for help on using the changeset viewer.