Make WordPress Core

Ticket #39252: 39252.2.diff

File 39252.2.diff, 3.2 KB (added by dlh, 7 years ago)
  • src/wp-includes/admin-bar.php

     
    718718        if ( isset( $actions['post-new.php?post_type=content'] ) )
    719719                $actions['post-new.php?post_type=content'][1] = 'add-new-content';
    720720
    721         if ( current_user_can( 'create_users' ) || current_user_can( 'promote_users' ) )
     721        if ( current_user_can( 'create_users' ) || ( is_multisite() && current_user_can( 'promote_users' ) ) ) {
    722722                $actions[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user' );
     723        }
    723724
    724725        if ( ! $actions )
    725726                return;
  • tests/phpunit/tests/adminbar.php

     
    551551                $this->assertNull( $node );
    552552        }
    553553
     554        public function map_meta_cap_grant_create_users( $caps, $cap ) {
     555                if ( 'create_users' === $cap ) {
     556                        $caps = array( 'exist' );
     557                }
     558
     559                return $caps;
     560        }
     561
     562        public function map_meta_cap_deny_create_users( $caps, $cap ) {
     563                if ( 'create_users' === $cap ) {
     564                        $caps = array( 'do_not_allow' );
     565                }
     566
     567                return $caps;
     568        }
     569
     570        public function map_meta_cap_grant_promote_users( $caps, $cap ) {
     571                if ( 'promote_users' === $cap ) {
     572                        $caps = array( 'exist' );
     573                }
     574
     575                return $caps;
     576        }
     577
     578        public function map_meta_cap_deny_promote_users( $caps, $cap ) {
     579                if ( 'promote_users' === $cap ) {
     580                        $caps = array( 'do_not_allow' );
     581                }
     582
     583                return $caps;
     584        }
     585
    554586        /**
     587         * @ticket 39252
     588         */
     589        public function test_new_user_link_for_user_with_create_users() {
     590                add_filter( 'map_meta_cap', array( $this, 'map_meta_cap_grant_create_users' ), 10, 2 );
     591                add_filter( 'map_meta_cap', array( $this, 'map_meta_cap_deny_promote_users' ), 10, 2 );
     592
     593                $admin_bar = new WP_Admin_Bar;
     594                wp_admin_bar_new_content_menu( $admin_bar );
     595
     596                // 'create_users' is sufficient in single- and multisite.
     597                $this->assertArrayHasKey( 'new-user', (array) $admin_bar->get_nodes() );
     598        }
     599
     600        /**
     601         * @ticket 39252
     602         */
     603        public function test_new_user_link_for_user_with_promote_users() {
     604                add_filter( 'map_meta_cap', array( $this, 'map_meta_cap_deny_create_users' ), 10, 2 );
     605                add_filter( 'map_meta_cap', array( $this, 'map_meta_cap_grant_promote_users' ), 10, 2 );
     606
     607                $admin_bar = new WP_Admin_Bar;
     608                wp_admin_bar_new_content_menu( $admin_bar );
     609
     610                $nodes = (array) $admin_bar->get_nodes();
     611
     612                if ( is_multisite() ) {
     613                        $this->assertArrayHasKey( 'new-user', $nodes );
     614                } else {
     615                        // 'promote_users' is insufficient in single-site.
     616                        $this->assertArrayNotHasKey( 'new-user', $nodes );
     617                }
     618        }
     619
     620        /**
     621         * @ticket 39252
     622         */
     623        public function test_new_user_link_for_user_without_create_or_promote_users() {
     624                add_filter( 'map_meta_cap', array( $this, 'map_meta_cap_deny_create_users' ), 10, 2 );
     625                add_filter( 'map_meta_cap', array( $this, 'map_meta_cap_deny_promote_users' ), 10, 2 );
     626
     627                $admin_bar = new WP_Admin_Bar;
     628                wp_admin_bar_new_content_menu( $admin_bar );
     629
     630                $this->assertArrayNotHasKey( 'new-user', (array) $admin_bar->get_nodes() );
     631        }
     632
     633        /**
    555634         * @ticket 30937
    556635         * @covers ::wp_admin_bar_customize_menu
    557636         */