https://github.com/WordPress/gutenberg/pull/6151 */ remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); } /** * Gets an array of enabled WooCommerce Admin features/sections. * * @return bool Enabled Woocommerce Admin features/sections. */ public static function get_features() { return apply_filters( 'woocommerce_admin_features', array() ); } /** * Returns if a specific wc-admin feature is enabled. * * @param string $feature Feature slug. * @return bool Returns true if the feature is enabled. */ public static function is_feature_enabled( $feature ) { $features = self::get_features(); return in_array( $feature, $features, true ); } /** * Gets the URL to an asset file. * * @param string $file name. * @return string URL to asset. */ public static function get_url( $file ) { return plugins_url( self::get_path( $file ) . $file, WC_ADMIN_PLUGIN_FILE ); } /** * Gets the file modified time as a cache buster if we're in dev mode, or the plugin version otherwise. * * @param string $file Local path to the file. * @return string The cache buster value to use for the given file. */ public static function get_file_version( $file ) { if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { $file = trim( $file, '/' ); return filemtime( WC_ADMIN_ABSPATH . self::get_path( $file ) ); } return WC_ADMIN_VERSION_NUMBER; } /** * Gets the path for the asset depending on file type. * * @param string $file name. * @return string Folder path of asset. */ private static function get_path( $file ) { return '.css' === substr( $file, -4 ) ? WC_ADMIN_DIST_CSS_FOLDER : WC_ADMIN_DIST_JS_FOLDER; } /** * Class loader for enabled WooCommerce Admin features/sections. */ public static function load_features() { $features = self::get_features(); foreach ( $features as $feature ) { $feature = strtolower( str_replace( '-', '_', $feature ) ); $feature = 'WC_Admin_' . ucwords( $feature, '_' ); if ( class_exists( $feature ) ) { new $feature; } } } /** * Registers a basic page handler for the app entry point. * * @todo The entry point for the embed needs moved to this class as well. */ public static function register_page_handler() { $analytics_cap = apply_filters( 'woocommerce_admin_analytics_menu_capability', 'view_woocommerce_reports' ); wc_admin_register_page( array( 'id' => 'woocommerce-dashboard', // Expected to be overridden if dashboard is enabled. 'parent' => 'woocommerce', 'title' => null, 'path' => self::APP_ENTRY_POINT, 'capability' => $analytics_cap, ) ); // Connect existing WooCommerce pages. require_once WC_ADMIN_ABSPATH . 'includes/page-controller/connect-existing-pages.php'; } /** * Remove the menu item for the app entry point page. */ public static function remove_app_entry_page_menu_item() { global $submenu; // User does not have capabilites to see the submenu. if ( ! current_user_can( 'manage_woocommerce' ) || empty( $submenu['woocommerce'] ) ) { return; } $wc_admin_key = null; foreach ( $submenu['woocommerce'] as $submenu_key => $submenu_item ) { // Our app entry page menu item has no title. if ( is_null( $submenu_item[0] ) && self::APP_ENTRY_POINT === $submenu_item[2] ) { $wc_admin_key = $submenu_key; break; } } if ( ! $wc_admin_key ) { return; } unset( $submenu['woocommerce'][ $wc_admin_key ] ); } /** * Registers all the neccessary scripts and styles to show the admin experience. */ public static function register_scripts() { if ( ! function_exists( 'wp_set_script_translations' ) ) { return; } wp_register_script( 'wc-csv', self::get_url( 'csv-export/index.js' ), array(), self::get_file_version( 'csv-export/index.js' ), true ); wp_register_script( 'wc-currency', self::get_url( 'currency/index.js' ), array( 'wc-number' ), self::get_file_version( 'currency/index.js' ), true ); wp_set_script_translations( 'wc-currency', 'woocommerce-admin' ); wp_register_script( 'wc-navigation', self::get_url( 'navigation/index.js' ), array(), self::get_file_version( 'navigation/index.js' ), true ); wp_register_script( 'wc-number', self::get_url( 'number/index.js' ), array(), self::get_file_version( 'number/index.js' ), true ); wp_register_script( 'wc-date', self::get_url( 'date/index.js' ), array( 'wp-date', 'wp-i18n' ), self::get_file_version( 'date/index.js' ), true ); wp_set_script_translations( 'wc-date', 'woocommerce-admin' ); wp_register_script( 'wc-components', self::get_url( 'components/index.js' ), array( 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-keycodes', 'wc-csv', 'wc-currency', 'wc-date', 'wc-navigation', 'wc-number', ), self::get_file_version( 'components/index.js' ), true ); wp_set_script_translations( 'wc-components', 'woocommerce-admin' ); wp_register_style( 'wc-components', self::get_url( 'components/style.css' ), array( 'wp-components' ), self::get_file_version( 'components/style.css' ) ); wp_style_add_data( 'wc-components', 'rtl', 'replace' ); wp_register_style( 'wc-components-ie', self::get_url( 'components/ie.css' ), array( 'wp-components' ), self::get_file_version( 'components/ie.css' ) ); wp_style_add_data( 'wc-components-ie', 'rtl', 'replace' ); $entry = 'app'; if ( self::is_embed_page() ) { $entry = 'embedded'; } wp_register_script( WC_ADMIN_APP, self::get_url( "{$entry}/index.js" ), array( 'wc-components', 'wc-navigation', 'wp-date', 'wp-html-entities', 'wp-keycodes', 'wp-i18n' ), self::get_file_version( "{$entry}/index.js" ), true ); wp_set_script_translations( WC_ADMIN_APP, 'woocommerce-admin' ); wp_register_style( WC_ADMIN_APP, self::get_url( "{$entry}/style.css" ), array( 'wc-components' ), self::get_file_version( "{$entry}/style.css" ) ); wp_style_add_data( WC_ADMIN_APP, 'rtl', 'replace' ); wp_register_style( 'wc-material-icons', 'https://fonts.googleapis.com/icon?family=Material+Icons+Outlined', array(), self::get_file_version( 'https://fonts.googleapis.com/icon?family=Material+Icons' ) ); } /** * Loads the required scripts on the correct pages. */ public static function load_scripts() { if ( ! self::is_admin_page() && ! self::is_embed_page() ) { return; } wp_enqueue_script( WC_ADMIN_APP ); wp_enqueue_style( WC_ADMIN_APP ); wp_enqueue_style( 'wc-material-icons' ); // 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' ); } } /** * Returns true if we are on a JS powered admin page. */ public static function is_admin_page() { return wc_admin_is_registered_page(); } /** * Returns true if we are on a "classic" (non JS app) powered admin page. * * @todo See usage in `admin.php`. This needs refactored and implemented properly in core. */ public static function is_embed_page() { return wc_admin_is_connected_page(); } /** * Returns breadcrumbs for the current page. */ private static function get_embed_breadcrumbs() { return wc_admin_get_breadcrumbs(); } /** * Outputs breadcrumbs via PHP for the initial load of an embedded page. * * @param array $section Section to create breadcrumb from. */ private static function output_breadcrumbs( $section ) { ?>
` is rendered. if ( self::is_admin_page() && apply_filters( 'woocommerce_admin_is_loading', false ) ) { $classes[] = 'woocommerce-admin-is-loading'; } $features = self::get_features(); foreach ( $features as $feature_key ) { $classes[] = sanitize_html_class( 'woocommerce-feature-enabled-' . $feature_key ); } $admin_body_class = implode( ' ', array_unique( $classes ) ); return " $admin_body_class "; } /** * Removes notices that should not be displayed on WC Admin pages. */ public static function remove_notices() { if ( ! self::is_admin_page() && ! self::is_embed_page() ) { return; } // Hello Dolly. if ( function_exists( 'hello_dolly' ) ) { remove_action( 'admin_notices', 'hello_dolly' ); } } /** * Runs before admin notices action and hides them. */ public static function inject_before_notices() { if ( ( ! self::is_admin_page() && ! self::is_embed_page() ) ) { return; } echo '