| 111 | /** |
| 112 | * @ticket 42791 |
| 113 | */ |
| 114 | public function test_wp_add_dashboard_widget() { |
| 115 | global $wp_meta_boxes; |
| 116 | |
| 117 | set_current_screen( 'dashboard' ); |
| 118 | |
| 119 | if ( ! function_exists( 'wp_add_dashboard_widget' ) ) { |
| 120 | require_once ABSPATH . 'wp-admin/includes/dashboard.php'; |
| 121 | } |
| 122 | |
| 123 | // Some hardcoded defaults for core widgets |
| 124 | wp_add_dashboard_widget( 'dashboard_quick_press', 'Quick', '__return_false' ); |
| 125 | wp_add_dashboard_widget( 'dashboard_browser_nag', 'Nag', '__return_false' ); |
| 126 | |
| 127 | $this->assertArrayHasKey( 'dashboard_quick_press', $wp_meta_boxes['dashboard']['side']['core'] ); |
| 128 | $this->assertArrayHasKey( 'dashboard_browser_nag', $wp_meta_boxes['dashboard']['normal']['high'] ); |
| 129 | |
| 130 | // Location and priority defaults |
| 131 | wp_add_dashboard_widget( 'dashboard1', 'Widget 1', '__return_false', null, null, 'foo' ); |
| 132 | wp_add_dashboard_widget( 'dashboard2', 'Widget 2', '__return_false', null, null, null, 'bar' ); |
| 133 | |
| 134 | $this->assertArrayHasKey( 'dashboard1', $wp_meta_boxes['dashboard']['foo']['core'] ); |
| 135 | $this->assertArrayHasKey( 'dashboard2', $wp_meta_boxes['dashboard']['normal']['bar'] ); |
| 136 | |
| 137 | // Cleanup |
| 138 | remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' ); |
| 139 | remove_meta_box( 'dashboard_browser_nag', 'dashboard', 'normal' ); |
| 140 | remove_meta_box( 'dashboard1', 'dashboard', 'foo' ); |
| 141 | |
| 142 | // This doesn't actually get removed due to the invalid priority |
| 143 | remove_meta_box( 'dashboard2', 'dashboard', 'normal' ); |
| 144 | |
| 145 | set_current_screen( 'front' ); |
| 146 | } |
| 147 | |