'/analytics', ); $options = wp_parse_args( $options, $defaults ); add_submenu_page( '/' === $options['parent'][0] ? "wc-admin#{$options['parent']}" : $options['parent'], $options['title'], $options['title'], 'manage_options', "wc-admin#{$options['path']}", 'wc_admin_page' ); } /** * Register menu pages for the Dashboard and Analytics sections. */ function wc_admin_register_pages() { global $menu, $submenu; add_submenu_page( 'woocommerce', __( 'WooCommerce Dashboard', 'wc-admin' ), __( 'Dashboard', 'wc-admin' ), 'manage_options', 'wc-admin', 'wc_admin_page' ); add_menu_page( __( 'WooCommerce Analytics', 'wc-admin' ), __( 'Analytics', 'wc-admin' ), 'manage_options', 'wc-admin#/analytics/revenue', 'wc_admin_page', 'dashicons-chart-bar', 56 // After WooCommerce & Product menu items. ); wc_admin_register_page( array( 'title' => __( 'Revenue', 'wc-admin' ), 'parent' => '/analytics/revenue', 'path' => '/analytics/revenue', ) ); wc_admin_register_page( array( 'title' => __( 'Orders', 'wc-admin' ), 'parent' => '/analytics/revenue', 'path' => '/analytics/orders', ) ); wc_admin_register_page( array( 'title' => __( 'Products', 'wc-admin' ), 'parent' => '/analytics/revenue', 'path' => '/analytics/products', ) ); if ( defined( 'WP_DEBUG' ) && WP_DEBUG && defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { wc_admin_register_page( array( 'title' => 'DevDocs', 'parent' => 'woocommerce', // Exposed on the main menu for now. 'path' => '/devdocs', ) ); } } add_action( 'admin_menu', 'wc_admin_register_pages' ); /** * This method is temporary while this is a feature plugin. As a part of core, * we can integrate this better with wc-admin-menus. * * It makes dashboard the top level link for 'WooCommerce' and renames the first Analytics menu item. */ function wc_admin_link_structure() { global $submenu; // User does not have capabilites to see the submenu. if ( ! current_user_can( 'manage_woocommerce' ) ) { return; } $wc_admin_key = null; foreach ( $submenu['woocommerce'] as $submenu_key => $submenu_item ) { if ( 'wc-admin' === $submenu_item[2] ) { $wc_admin_key = $submenu_key; break; } } if ( ! $wc_admin_key ) { return; } $menu = $submenu['woocommerce'][ $wc_admin_key ]; // Move menu item to top of array. unset( $submenu['woocommerce'][ $wc_admin_key ] ); array_unshift( $submenu['woocommerce'], $menu ); } // priority is 20 to run after https://github.com/woocommerce/woocommerce/blob/a55ae325306fc2179149ba9b97e66f32f84fdd9c/includes/admin/class-wc-admin-menus.php#L165. add_action( 'admin_head', 'wc_admin_link_structure', 20 ); /** * Load the assets on the admin pages */ function wc_admin_enqueue_script() { if ( ! wc_admin_is_admin_page() && ! wc_admin_is_embed_enabled_wc_page() ) { return; } wp_enqueue_script( WC_ADMIN_APP ); wp_enqueue_style( WC_ADMIN_APP ); } add_action( 'admin_enqueue_scripts', 'wc_admin_enqueue_script' ); /** * Adds an admin body class. * * @param string $admin_body_class Body class to add. */ function wc_admin_admin_body_class( $admin_body_class = '' ) { global $hook_suffix; if ( ! wc_admin_is_admin_page() && ! wc_admin_is_embed_enabled_wc_page() ) { return $admin_body_class; } $classes = explode( ' ', trim( $admin_body_class ) ); $classes[] = 'woocommerce-page'; if ( wc_admin_is_embed_enabled_wc_page() ) { $classes[] = 'woocommerce-embed-page'; } $admin_body_class = implode( ' ', array_unique( $classes ) ); return " $admin_body_class "; } add_filter( 'admin_body_class', 'wc_admin_admin_body_class' ); /** * Runs before admin notices action and hides them. */ function wc_admin_admin_before_notices() { if ( ! wc_admin_is_admin_page() && ! wc_admin_is_embed_enabled_wc_page() ) { return; } echo '