Changeset 65531
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-plugins-list-table.php
r64586 r65531 1637 1637 } 1638 1638 1639 $dependency_note = __( 'Note: This plugin cannot be deactivated or deleted until the plugins that require it are deactivated or deleted.' ); 1639 $dependency_note = ''; 1640 1641 if ( $this->screen->in_admin( 'network' ) ) { 1642 $is_network_active = is_plugin_active_for_network( $dependency ); 1643 1644 if ( $is_network_active && current_user_can( 'manage_network_plugins' ) && WP_Plugin_Dependencies::has_active_dependents( $dependency ) ) { 1645 $dependency_note = __( 'Note: This plugin cannot be deactivated until the plugins that require it are deactivated.' ); 1646 } elseif ( ! $is_network_active && ! is_plugin_active( $dependency ) && current_user_can( 'delete_plugins' ) && ! WP_Plugin_Dependencies::has_circular_dependency( $dependency ) ) { 1647 $dependency_note = __( 'Note: This plugin cannot be deleted until the plugins that require it are deleted.' ); 1648 } 1649 } else { 1650 $is_active = is_plugin_active( $dependency ); 1651 1652 if ( $is_active && ! is_plugin_active_for_network( $dependency ) && current_user_can( 'deactivate_plugin', $dependency ) && WP_Plugin_Dependencies::has_active_dependents( $dependency ) ) { 1653 $dependency_note = __( 'Note: This plugin cannot be deactivated until the plugins that require it are deactivated.' ); 1654 } elseif ( ! $is_active && ! is_multisite() && current_user_can( 'delete_plugins' ) && ! WP_Plugin_Dependencies::has_circular_dependency( $dependency ) ) { 1655 $dependency_note = __( 'Note: This plugin cannot be deleted until the plugins that require it are deleted.' ); 1656 } 1657 } 1658 1659 $dependency_notice = ''; 1660 if ( '' !== $dependency_note ) { 1661 $dependency_notice = wp_get_admin_notice( 1662 $dependency_note, 1663 array( 1664 'type' => 'warning', 1665 'additional_classes' => array( 'inline' ), 1666 ) 1667 ); 1668 } 1640 1669 1641 1670 $comma = wp_get_list_item_separator(); … … 1647 1676 1648 1677 printf( 1649 '<div class="required-by"><p>%1$s</p> <p>%2$s</p></div>',1678 '<div class="required-by"><p>%1$s</p>%2$s</div>', 1650 1679 $required_by, 1651 $dependency_not e1680 $dependency_notice 1652 1681 ); 1653 1682 } -
trunk/tests/phpunit/tests/admin/wpPluginsListTableRequiredByRow.php
r65388 r65531 13 13 class Tests_Admin_wpPluginsListTableRequiredByRow extends WP_PluginDependencies_UnitTestCase { 14 14 15 protected static $admin_id; 16 17 public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { 18 self::$admin_id = $factory->user->create( array( 'role' => 'administrator' ) ); 19 } 20 15 21 /** 16 22 * Tests that nothing is output for a plugin that no plugin requires. … … 25 31 26 32 /** 27 * Tests the row for one plugin that requires the dependency.33 * Tests the row for one deactivated plugin that requires the dependency. 28 34 * 29 35 * @ticket 65819 … … 37 43 ) 38 44 ); 45 wp_set_current_user( self::$admin_id ); 46 47 $notice = ''; 48 if ( ! is_multisite() ) { 49 $notice = '<div class="notice notice-warning inline"><p>Note: This plugin cannot be deleted until the plugins that require it are deleted.</p></div>'; 50 } 39 51 40 52 $this->assertSame( 41 53 '<div class="required-by"><p><strong>Required by:</strong> Alpha Plugin, Zeta Plugin</p>' 42 . '<p>Note: This plugin cannot be deactivated or deleted until the plugins that require it are deactivated or deleted.</p></div>',54 . $notice . '</div>', 43 55 $this->get_row( 'dependency/dependency.php' ) 56 ); 57 } 58 59 /** 60 * Tests the deletion notice on the network Plugins screen. 61 * 62 * @ticket 65819 63 * @group ms-required 64 * 65 * @dataProvider data_should_show_network_deletion_notice_only_to_super_admins 66 * 67 * @param bool $is_super_admin Whether the current user is a super admin. 68 */ 69 public function test_should_show_network_deletion_notice_only_to_super_admins( $is_super_admin ) { 70 $this->skipWithoutMultisite(); 71 $this->set_dependencies( array( 'dependent/dependent.php' => array( 'dependency' ) ) ); 72 wp_set_current_user( self::$admin_id ); 73 74 if ( $is_super_admin ) { 75 $this->assertTrue( grant_super_admin( self::$admin_id ) ); 76 } 77 78 $this->assertSame( $is_super_admin, current_user_can( 'delete_plugins' ) ); 79 80 $notice = ''; 81 if ( $is_super_admin ) { 82 $notice = '<div class="notice notice-warning inline"><p>Note: This plugin cannot be deleted until the plugins that require it are deleted.</p></div>'; 83 } 84 85 $this->assertSame( 86 '<div class="required-by"><p><strong>Required by:</strong> Dependent Plugin</p>' 87 . $notice . '</div>', 88 $this->get_row( 'dependency/dependency.php', 'plugins-network' ) 89 ); 90 } 91 92 /** 93 * Provides users with and without network plugin deletion permissions. 94 * 95 * @return array[] 96 */ 97 public static function data_should_show_network_deletion_notice_only_to_super_admins() { 98 return array( 99 'site administrator' => array( false ), 100 'super admin' => array( true ), 44 101 ); 45 102 } … … 79 136 */ 80 137 private function set_dependencies( $dependencies ) { 81 $plugins = array(); 138 $plugins = array(); 139 $dependent_slugs = array(); 82 140 foreach ( array_keys( $dependencies ) as $file ) { 83 $plugins[ $file ] = array( 'Name' => ucfirst( dirname( $file ) ) . ' Plugin' ); 141 $plugins[ $file ] = array( 'Name' => ucfirst( dirname( $file ) ) . ' Plugin' ); 142 $dependent_slugs[ $file ] = dirname( $file ); 84 143 } 85 144 86 145 $this->set_property_value( 'plugins', $plugins ); 87 146 $this->set_property_value( 'dependencies', $dependencies ); 147 $this->set_property_value( 'dependent_slugs', $dependent_slugs ); 88 148 } 89 149 … … 92 152 * 93 153 * @param string $plugin_file The plugin file. 154 * @param string $screen The Plugins screen. 94 155 * @return string The output. 95 156 */ 96 private function get_row( $plugin_file ) {97 $table = _get_list_table( 'WP_Plugins_List_Table', array( 'screen' => 'plugins') );157 private function get_row( $plugin_file, $screen = 'plugins' ) { 158 $table = _get_list_table( 'WP_Plugins_List_Table', array( 'screen' => $screen ) ); 98 159 99 160 $method = new ReflectionMethod( $table, 'add_dependents_to_dependency_plugin_row' );
Note:
See TracChangeset
for help on using the changeset viewer.