WordPress.org

Make WordPress Core

Changeset 40999


Ignore:
Timestamp:
07/04/17 19:58:35 (3 weeks ago)
Author:
boonebgorges
Message:

Avoid PHP notices when checking termmeta capabilities against a non-existent term.

Previously, checks like current_user_can( 'edit_term_meta', $term_id )
returned the proper value, but generated a PHP notice due to the fact
that get_term( $term_id ) could, in certain instances, return
WP_Error objects.

Props caercam.
Fixes #40891.

Location:
trunk
Files:
2 edited

Legend:

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

    r40638 r40999  
    281281            case 'term': 
    282282                $term = get_term( $object_id ); 
    283                 if ( ! $term ) { 
     283                if ( ! $term instanceof WP_Term ) { 
    284284                    break; 
    285285                } 
  • trunk/tests/phpunit/tests/user/capabilities.php

    r40993 r40999  
    13551355 
    13561356    /** 
     1357     * @ticket 40891 
     1358     */ 
     1359    public function test_taxonomy_meta_capabilities_with_non_existent_terms() { 
     1360        $caps = array( 
     1361            'add_term_meta', 
     1362            'delete_term_meta', 
     1363            'edit_term_meta', 
     1364        ); 
     1365 
     1366        $taxonomy = 'wptests_tax'; 
     1367        register_taxonomy( $taxonomy, 'post' ); 
     1368 
     1369        $editor = self::$users['editor']; 
     1370 
     1371        foreach ( $caps as $cap ) { 
     1372            // `null` represents a non-existent term ID. 
     1373            $this->assertFalse( user_can( $editor->ID, $cap, null ) ); 
     1374        } 
     1375    } 
     1376 
     1377    /** 
    13571378     * @ticket 21786 
    13581379     */ 
Note: See TracChangeset for help on using the changeset viewer.