$id, 'title' => $class::getName(), 'callback' => [$class, 'renderCallback'], 'args' => null, 'context' => 'normal', 'priority' => 'low', 'group' => $class::getGroup(), ]; } self::$widgets = $list + self::getOtherWidgets(); } return self::$widgets; } /** * Retrieve list of all widgets (except native WordPress widgets). * * @return array */ protected static function collectAllWidgets(): array { $widgets = [ \Tekod\ADWMAN\Widgets\General\PostsInDraft::class, \Tekod\ADWMAN\Widgets\General\ErrorLog::class, \Tekod\ADWMAN\Widgets\General\HostingInfo::class, \Tekod\ADWMAN\Widgets\Users\CommentsForApprovement::class, \Tekod\ADWMAN\Widgets\Users\UserLatest::class, \Tekod\ADWMAN\Widgets\WooCommerce\WcOrdersInProcessing::class, \Tekod\ADWMAN\Widgets\WooCommerce\WcOrdersOnHold::class, \Tekod\ADWMAN\Widgets\WooCommerce\WcProductsOutOfStock::class, \Tekod\ADWMAN\Widgets\WooCommerce\WcProductsLowInStock::class, \Tekod\ADWMAN\Widgets\WooCommerce\WcProductsInDraft::class, ]; $widgets = array_merge($widgets, self::$registeredWidgets); return apply_filters('tekod-adwman-collect-widgets', $widgets); // theme can add additional widgets here } /** * Register new custom widget. * * @param string $class */ public static function registerWidget(string $class): void { self::$registeredWidgets[] = $class; } /** * Retrieve list of built-in WordPress widgets. * * @return array */ protected static function getOtherWidgets(): array { global $wp_meta_boxes; // if not happen, emulate dashboard page opening if ($wp_meta_boxes === null) { self::emulateDashboardOpeningPage(); } // enumerate widgets $list = []; foreach ($wp_meta_boxes['dashboard'] ?? [] as $context) { foreach ($context as $widgets) { foreach ($widgets as $widget) { $group = in_array($widget['id'], self::$nativeWordPressWidgets, true) ? 'WordPress built-in widgets' : 'Other plugins'; $list[$widget['id']] = ['title' => wp_strip_all_tags($widget['title']), 'group' => $group] + $widget; } } } return $list; } protected static function emulateDashboardOpeningPage(): void { // emulate dashboard page opening $backup = get_current_screen(); set_current_screen('dashboard'); require_once(ABSPATH . 'wp-admin/includes/dashboard.php'); if (function_exists('wpseo_admin_init') && !isset($GLOBALS['wpseo_admin'])) { wpseo_admin_init(); } if (class_exists('AIOSEO\Plugin\AIOSEO')) { $AIOSEO = \AIOSEO\Plugin\AIOSEO::instance(); if (!$AIOSEO->dashboard) { $AIOSEO->dashboard = $AIOSEO->pro ? new \AIOSEO\Plugin\Pro\Admin\Dashboard() : new \AIOSEO\Plugin\Common\Admin\Dashboard(); $AIOSEO->help = new \AIOSEO\Plugin\Common\Help\Help(); } } do_action('admin_enqueue_scripts'); do_action('admin_init'); wp_dashboard_setup(); $GLOBALS['current_screen'] = $backup; } }