true are read as 'user', see swiftdash_screen_location(). * * @return array[] */ function swiftdash_screens() { $screens = array( 'swift-dash' => array( 'key' => 'dashboard', 'menu' => __( 'Dashboard', 'swiftwebdev-dashboard-analytics' ), 'title' => __( 'Dashboard', 'swiftwebdev-dashboard-analytics' ), 'description' => __( 'Here is what is happening on your website today.', 'swiftwebdev-dashboard-analytics' ), 'icon' => 'house', 'location' => 'left', ), 'swift-dash-speed' => array( 'key' => 'speed', 'menu' => __( 'Speed & Optimize', 'swiftwebdev-dashboard-analytics' ), 'title' => __( 'Speed & Optimize', 'swiftwebdev-dashboard-analytics' ), 'description' => __( 'See your mobile and desktop speed scores and what to fix to reach 90+.', 'swiftwebdev-dashboard-analytics' ), 'icon' => 'gauge', 'location' => 'user', ), 'swift-dash-links' => array( 'key' => 'links', 'menu' => __( 'Quick Links', 'swiftwebdev-dashboard-analytics' ), 'title' => __( 'Quick Links', 'swiftwebdev-dashboard-analytics' ), 'description' => __( 'Shortcuts to the WordPress tasks you use most.', 'swiftwebdev-dashboard-analytics' ), 'icon' => 'link-simple', 'location' => 'user', ), 'swift-dash-settings' => array( 'key' => 'settings', 'menu' => __( 'SwiftWebDev Dashboard settings', 'swiftwebdev-dashboard-analytics' ), 'title' => __( 'SwiftWebDev Dashboard Settings', 'swiftwebdev-dashboard-analytics' ), 'description' => __( 'Choose how SwiftWebDev Dashboard behaves on this site.', 'swiftwebdev-dashboard-analytics' ), 'icon' => 'gear-six', 'location' => 'user', ), ); /** * Filters the SwiftWebDev Dashboard screens. * * @param array $screens Screens keyed by admin page slug. */ return apply_filters( 'swiftdash_screens', $screens ); } /** * Hook suffixes of SwiftWebDev Dashboard screens. * * @param string|null $add Hook suffix to record. * @return string[] */ function swiftdash_screen_hooks( $add = null ) { static $hooks = array(); if ( $add ) { $hooks[] = $add; } return $hooks; } /** * Where a screen is linked from: 'left', 'user' or 'hidden'. * * @param array $screen Screen definition. * @return string */ function swiftdash_screen_location( $screen ) { if ( isset( $screen['location'] ) && in_array( $screen['location'], array( 'left', 'user', 'hidden' ), true ) ) { return $screen['location']; } return empty( $screen['nav'] ) ? 'hidden' : 'user'; } /** * Whether the current admin request is a SwiftWebDev Dashboard screen. * * @return bool */ function swiftdash_is_screen() { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; return $screen && in_array( $screen->id, swiftdash_screen_hooks(), true ); } /** * Body class that switches off the WordPress admin chrome on SwiftWebDev Dashboard screens only. * * @param string $classes Space-separated classes. * @return string */ function swiftdash_admin_body_class( $classes ) { return swiftdash_is_screen() ? $classes . ' swiftdash-screen' : $classes; } add_filter( 'admin_body_class', 'swiftdash_admin_body_class' ); /** * Enqueue assets on SwiftWebDev Dashboard screens only. * * @param string $hook_suffix Current admin page hook. */ function swiftdash_enqueue_assets( $hook_suffix ) { if ( ! in_array( $hook_suffix, swiftdash_screen_hooks(), true ) ) { return; } wp_enqueue_style( 'swiftdash-tokens', SWIFTDASH_URL . 'assets/css/tokens.css', array(), SWIFTDASH_VERSION ); wp_enqueue_style( 'swiftdash-app', SWIFTDASH_URL . 'assets/css/app.css', array( 'swiftdash-tokens' ), SWIFTDASH_VERSION ); wp_enqueue_script( 'swiftdash-app', SWIFTDASH_URL . 'assets/js/app.js', array( 'wp-api-fetch', 'wp-i18n' ), SWIFTDASH_VERSION, true ); wp_set_script_translations( 'swiftdash-app', 'swiftwebdev-dashboard-analytics' ); wp_add_inline_script( 'swiftdash-app', 'window.swiftdashData = ' . wp_json_encode( array( 'prefs' => swiftdash_prefs(), 'destinations' => swiftdash_destinations(), ) ) . ';', 'before' ); global $plugin_page; $screens = swiftdash_screens(); if ( 'swift-dash-settings' === $plugin_page ) { wp_enqueue_media(); } /** * Fires after the core SwiftWebDev Dashboard assets are enqueued on a SwiftWebDev Dashboard screen. * Feature files enqueue their own CSS/JS here (depend on the 'swiftdash-app' script and style). * * @param string $screen_key Current screen key (dashboard, analytics, speed, links, settings). */ do_action( 'swiftdash_enqueue_assets', isset( $screens[ $plugin_page ] ) ? $screens[ $plugin_page ]['key'] : '' ); } add_action( 'admin_enqueue_scripts', 'swiftdash_enqueue_assets' ); /** * Optional: open SwiftWebDev Dashboard instead of the WordPress dashboard. */ function swiftdash_maybe_redirect_dashboard() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only opt-out flag on a GET link. $bypass = isset( $_GET['swiftdash'] ) && '0' === $_GET['swiftdash']; if ( ! $bypass && swiftdash_setting( 'open_after_login' ) && current_user_can( swiftdash_capability() ) ) { wp_safe_redirect( admin_url( 'admin.php?page=swift-dash' ) ); exit; } } add_action( 'load-index.php', 'swiftdash_maybe_redirect_dashboard' ); /** * Register the widgets of every screen. Feature files and add-ons register or replace widgets here. */ function swiftdash_setup_widgets() { /** * Fires before a screen renders. Register or replace widgets with swiftdash_register_widget(). */ do_action( 'swiftdash_register_widgets' ); } /** * Render any SwiftWebDev Dashboard screen inside the shared shell. */ function swiftdash_render_screen() { global $plugin_page; $screens = swiftdash_screens(); if ( ! isset( $screens[ $plugin_page ] ) || ! current_user_can( swiftdash_capability() ) ) { return; } $screen = $screens[ $plugin_page ]; swiftdash_setup_widgets(); ?>
first_name ? $user->first_name : $user->display_name; swiftdash_render_page_header( /* translators: %s: user's first name. */ sprintf( __( 'Welcome back, %s', 'swiftwebdev-dashboard-analytics' ), $name ), $screen['description'], function () { swiftdash_render_range_picker(); ?> array( 'kpis', 'overview', 'performance', 'site' ), ); /** * Filters the widget areas of each screen, top to bottom. * * @param array $areas Area keys per screen key. */ $areas = apply_filters( 'swiftdash_screen_areas', $areas ); return isset( $areas[ $screen_key ] ) ? $areas[ $screen_key ] : array( 'main' ); } /** * All widgets of a screen in display order (area by area). * * @param string $screen_key Screen key. * @return array[] */ function swiftdash_get_screen_widgets( $screen_key ) { $widgets = array(); foreach ( swiftdash_screen_areas( $screen_key ) as $area ) { $widgets = array_merge( $widgets, array_values( swiftdash_get_widgets( $screen_key, $area ) ) ); } return $widgets; } /** * Screens whose content arrives in a later build phase. * * @param array $screen Screen definition. */ function swiftdash_screen_pending( $screen ) { swiftdash_render_page_header( $screen['title'], $screen['description'] ); swiftdash_render_empty_state( 'clock', __( 'This screen is not ready yet', 'swiftwebdev-dashboard-analytics' ), __( 'It will be added in an upcoming version of SwiftWebDev Dashboard.', 'swiftwebdev-dashboard-analytics' ) ); } /** * Settings screen. Saves through core /wp/v2/settings. * * @param array $screen Screen definition. */ function swiftdash_screen_settings( $screen ) { $brand = swiftdash_brand(); swiftdash_render_page_header( $screen['title'], $screen['description'] ); ?>
>

>