Make WordPress Core


Ignore:
Timestamp:
07/04/2017 07:58:35 PM (9 years 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.