[ 'core' => [], 'sorted' => [ [ 'id' => $widget['id'], 'title' => $widget['title'], 'callback' => $widget['callback'], 'args' => null, ], ], ], ]; ob_start(); do_meta_boxes('dashboard', 'normal', null) ; $html = ob_get_clean(); // remove wrapping div $html = substr($html, strpos($html, '>') + 1); $html = substr($html, 0, strrpos($html, '<')); // restore backup $wp_meta_boxes['dashboard'] = $original; return $html; } public static function renderSingleWidgetContent(string $widgetId): string { $widget = Render::findWidgetById($widgetId); $callable = [$widget['callback'][0], 'render']; ob_start(); $callable(); return ob_get_clean(); } public static function findWidgetById(string $widgetId): array { foreach (Widgets::getAllWidgets() as $widget) { if ($widget['id'] === $widgetId) { return $widget; } } return []; } public static function renderColumns(array $columns): array { require_once ABSPATH . 'wp-admin/includes/dashboard.php'; //Widgets::getAllWidgets(); // pre-fetch return [ 'normal' => self::renderColumn($columns['normal'] ?? ''), 'side' => self::renderColumn($columns['side'] ?? ''), 'column3' => self::renderColumn($columns['column3'] ?? ''), 'column4' => self::renderColumn($columns['column4'] ?? ''), ]; } protected static function renderColumn(string $list): string { global $wp_meta_boxes; // clear dashboard and insert selected widgets $wp_meta_boxes['dashboard'] = [ 'normal' => [ 'core' => [], 'sorted' => [], ], ]; foreach (array_filter(array_map('trim', explode(',', $list))) as $id) { $struct = self::findWidgetById($id); if ($struct) { $wp_meta_boxes['dashboard']['normal']['sorted'][] = $struct; } } $html = ''; if (!empty($wp_meta_boxes['dashboard']['normal']['sorted'])) { ob_start(); do_meta_boxes('dashboard', 'normal', null); $html = ob_get_clean(); // remove wrapping div $html = substr($html, strpos($html, '>') + 1); $html = substr($html, 0, strrpos($html, '<')); } return $html; } public static function renderScripts(): string { ob_start(); wp_print_scripts(); wp_print_footer_scripts(); return ob_get_clean(); } }