label. */ public static function tabs() { return array( 'dashboard' => __( 'Dashboard', 'markitmall-dropship' ), 'catalog' => __( 'Catalog', 'markitmall-dropship' ), 'imports' => __( 'My imports', 'markitmall-dropship' ), 'orders' => __( 'Orders', 'markitmall-dropship' ), 'settings' => __( 'Settings', 'markitmall-dropship' ), ); } /** Link to a tab, with extra query args. */ public static function url( $tab = 'dashboard', $args = array() ) { return add_query_arg( array_merge( array( 'page' => self::PAGE, 'tab' => $tab ), $args ), admin_url( 'admin.php' ) ); } /** Redirect back to a tab with a notice code (see notices()). */ public static function redirect( $tab, $notice = '', $args = array() ) { if ( $notice ) { $args['mm_notice'] = $notice; } wp_safe_redirect( self::url( $tab, $args ) ); exit; } public static function menu() { add_menu_page( __( 'MarkitMall Dropship', 'markitmall-dropship' ), __( 'MarkitMall', 'markitmall-dropship' ), 'manage_woocommerce', self::PAGE, array( __CLASS__, 'render' ), MARKITMALL_DS_URL . 'assets/icon.png', 56 ); // Sub-items that open the tabs, so each is one click from the menu. A // sub-item without a page of its own links to its slug as given, so the // slug is the tab's full admin URL. foreach ( self::tabs() as $tab => $label ) { add_submenu_page( self::PAGE, $label, $label, 'manage_woocommerce', self::submenu_slug( $tab ), 'dashboard' === $tab ? array( __CLASS__, 'render' ) : '' ); } } private static function submenu_slug( $tab ) { return 'dashboard' === $tab ? self::PAGE : 'admin.php?page=' . self::PAGE . '&tab=' . $tab; } /** Version 1.0 had the catalog on its own page; send its bookmarks to the tab. */ public static function old_catalog_url() { if ( isset( $_GET['page'] ) && 'markitmall-dropship-catalog' === $_GET['page'] ) { // phpcs:ignore WordPress.Security.NonceVerification wp_safe_redirect( self::url( 'catalog' ) ); exit; } } public static function current_tab() { $tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : 'dashboard'; // phpcs:ignore WordPress.Security.NonceVerification return isset( self::tabs()[ $tab ] ) ? $tab : 'dashboard'; } /** * The admin screens a MarkitMall notice may appear on (Guideline 11: no * notices across the whole dashboard): this plugin's screen, plus the * WooCommerce screens the notice is about — "orders" or "products". */ public static function is_notice_screen( $about ) { if ( self::is_our_page() ) { return true; } $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; if ( ! $screen ) { return false; } $ids = 'orders' === $about ? array( 'edit-shop_order', 'shop_order', 'woocommerce_page_wc-orders' ) : array( 'edit-product' ); return in_array( $screen->id, $ids, true ); } public static function is_our_page() { return isset( $_GET['page'] ) && self::PAGE === $_GET['page']; // phpcs:ignore WordPress.Security.NonceVerification } public static function assets() { // The menu icon is a photo-like PNG: size it like WordPress's own icons, on every admin page. wp_add_inline_style( 'admin-menu', '#adminmenu .toplevel_page_markitmall-dropship .wp-menu-image img{width:20px;height:20px;padding:7px 0 0;opacity:1}' ); if ( ! self::is_our_page() ) { return; } wp_enqueue_style( 'markitmall-dropship-admin', MARKITMALL_DS_URL . 'assets/admin.css', array(), MARKITMALL_DS_VERSION ); } /** Highlights the menu sub-item of the open tab. */ public static function submenu_highlight( $submenu_file ) { if ( ! self::is_our_page() ) { return $submenu_file; } return self::submenu_slug( self::current_tab() ); } public static function render() { if ( ! current_user_can( 'manage_woocommerce' ) ) { return; } $tab = self::current_tab(); $connected = MarkitMall_DS_API::is_configured(); $settings = MarkitMall_DS_Settings::get_all(); ?>
' . esc_html( $label ) . '
' . esc_html( $value ) . '
'; if ( $hint ) { echo '' . esc_html( $hint ) . '
'; } echo '