'/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; if ( wc_admin_is_feature_enabled( 'dashboard' ) ) { add_submenu_page( 'woocommerce', __( 'WooCommerce Dashboard', 'woocommerce-admin' ), __( 'Dashboard', 'woocommerce-admin' ), 'manage_options', 'wc-admin', 'wc_admin_page' ); } if ( wc_admin_is_feature_enabled( 'analytics' ) ) { add_menu_page( __( 'WooCommerce Analytics', 'woocommerce-admin' ), __( 'Analytics', 'woocommerce-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', 'woocommerce-admin' ), 'parent' => '/analytics/revenue', 'path' => '/analytics/revenue', ) ); wc_admin_register_page( array( 'title' => __( 'Orders', 'woocommerce-admin' ), 'parent' => '/analytics/revenue', 'path' => '/analytics/orders', ) ); wc_admin_register_page( array( 'title' => __( 'Products', 'woocommerce-admin' ), 'parent' => '/analytics/revenue', 'path' => '/analytics/products', ) ); wc_admin_register_page( array( 'title' => __( 'Categories', 'woocommerce-admin' ), 'parent' => '/analytics/revenue', 'path' => '/analytics/categories', ) ); wc_admin_register_page( array( 'title' => __( 'Coupons', 'woocommerce-admin' ), 'parent' => '/analytics/revenue', 'path' => '/analytics/coupons', ) ); wc_admin_register_page( array( 'title' => __( 'Taxes', 'woocommerce-admin' ), 'parent' => '/analytics/revenue', 'path' => '/analytics/taxes', ) ); wc_admin_register_page( array( 'title' => __( 'Downloads', 'woocommerce-admin' ), 'parent' => '/analytics/revenue', 'path' => '/analytics/downloads', ) ); wc_admin_register_page( array( 'title' => __( 'Stock', 'woocommerce-admin' ), 'parent' => '/analytics/revenue', 'path' => '/analytics/stock', ) ); wc_admin_register_page( array( 'title' => __( 'Customers', 'woocommerce-admin' ), 'parent' => '/analytics/revenue', 'path' => '/analytics/customers', ) ); wc_admin_register_page( array( 'title' => __( 'Settings', 'woocommerce-admin' ), 'parent' => '/analytics/revenue', 'path' => '/analytics/settings', ) ); } if ( wc_admin_is_feature_enabled( 'devdocs' ) && 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 ); // Use server-side detection to prevent unneccessary stylesheet loading in other browsers. $user_agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : ''; // WPCS: sanitization ok. preg_match( '/MSIE (.*?);/', $user_agent, $matches ); if ( count( $matches ) < 2 ) { preg_match( '/Trident\/\d{1,2}.\d{1,2}; rv:([0-9]*)/', $user_agent, $matches ); } if ( count( $matches ) > 1 ) { wp_enqueue_style( 'wc-components-ie' ); } } add_action( 'admin_enqueue_scripts', 'wc_admin_enqueue_script' ); /** * Adds body classes to the main wp-admin wrapper, allowing us to better target elements in specific scenarios. * * @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'; } if ( function_exists( 'wc_admin_get_feature_config' ) ) { $features = wc_admin_get_feature_config(); foreach ( $features as $feature_key => $bool ) { if ( true === $bool ) { $classes[] = sanitize_html_class( 'woocommerce-feature-enabled-' . $feature_key ); } else { $classes[] = sanitize_html_class( 'woocommerce-feature-disabled-' . $feature_key ); } } } $admin_body_class = implode( ' ', array_unique( $classes ) ); return " $admin_body_class "; } add_filter( 'admin_body_class', 'wc_admin_admin_body_class' ); /** * Removes notices that should not be displayed on WC Admin pages. */ function wc_admin_remove_notices() { if ( ! wc_admin_is_admin_page() && ! wc_admin_is_embed_enabled_wc_page() ) { return; } // Hello Dolly. if ( function_exists( 'hello_dolly' ) ) { remove_action( 'admin_notices', 'hello_dolly' ); } } add_action( 'admin_head', 'wc_admin_remove_notices' ); /** * 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() ) || ! wc_admin_is_feature_enabled( 'activity-panels' ) ) { return; } echo '