dependencies_are_ok && ! current_user_can( 'wpml_manage_woocommerce_multilingual' ) && current_user_can( 'wpml_operate_woocommerce_multilingual' ) && ! current_user_can( 'translate' ) ) { add_filter( 'wpml_menu_page', [ __CLASS__, 'wpml_menu_page' ] ); } add_action( 'admin_menu', [ __CLASS__, 'register_menus' ], 80 ); if ( self::is_page_without_admin_language_switcher() ) { self::remove_wpml_admin_language_switcher(); } if ( is_admin() && ! is_null( $sitepress ) && self::$woocommerce_wpml->dependencies_are_ok ) { add_action( 'admin_footer', [ __CLASS__, 'documentation_links' ] ); add_action( 'admin_head', [ __CLASS__, 'hide_multilingual_content_setup_box' ] ); add_action( 'admin_init', [ __CLASS__, 'restrict_admin_with_redirect' ] ); } add_filter( 'woocommerce_prevent_admin_access', [ __CLASS__, 'check_user_admin_access' ] ); add_action( 'admin_head', [ __CLASS__, 'add_menu_warning' ] ); } /** * @return bool */ private static function is_page_without_admin_language_switcher() { global $pagenow; $get_post_type = isset( $_GET['post_type'] ) ? $_GET['post_type'] : false; $get_post = isset( $_GET['post'] ) ? $_GET['post'] : false; $get_page = isset( $_GET['page'] ) ? $_GET['page'] : false; $is_page_wpml_wcml = isset( $_GET['page'] ) && 'wpml-wcml' === $_GET['page']; $is_new_order_or_coupon = in_array( $pagenow, [ 'edit.php', 'post-new.php' ], true ) && $get_post_type && in_array( $get_post_type, [ 'shop_coupon', 'shop_order' ], true ); $is_edit_order_or_coupon = 'post.php' === $pagenow && $get_post && in_array( get_post_type( $get_post ), [ 'shop_coupon', 'shop_order' ], true ); $is_shipping_zones = 'shipping_zones' === $get_page; $is_attributes_page = apply_filters( 'wcml_is_attributes_page', 'product_attributes' === $get_page ); return is_admin() && ( $is_page_wpml_wcml || $is_new_order_or_coupon || $is_edit_order_or_coupon || $is_shipping_zones || $is_attributes_page ); } public static function remove_wpml_admin_language_switcher() { remove_action( 'wp_before_admin_bar_render', [ self::$sitepress, 'admin_language_switcher' ] ); } /** * @param array $menu * * @return array */ public static function wpml_menu_page( $menu ) { if ( isset( $menu['menu_slug'] ) && WPML_TM_FOLDER . '/menu/translations-queue.php' === $menu['menu_slug'] ) { $menu['capability'] = 'wpml_operate_woocommerce_multilingual'; } return $menu; } public static function register_menus() { if ( self::$woocommerce_wpml->dependencies_are_ok || class_exists( 'WooCommerce' ) ) { add_submenu_page( 'woocommerce', __( 'WooCommerce Multilingual', 'woocommerce-multilingual' ), __( 'WooCommerce Multilingual', 'woocommerce-multilingual' ), 'wpml_operate_woocommerce_multilingual', 'wpml-wcml', [ __CLASS__, 'render_menus' ] ); } else { add_menu_page( __( 'WooCommerce Multilingual', 'woocommerce-multilingual' ), __( 'WooCommerce Multilingual', 'woocommerce-multilingual' ), 'wpml_manage_woocommerce_multilingual', 'wpml-wcml', [ __CLASS__, 'render_menus' ], WCML_PLUGIN_URL . '/res/images/icon16.png' ); } } public static function render_menus() { if ( self::$woocommerce_wpml->dependencies_are_ok ) { $menus_wrap = new WCML_Menus_Wrap( self::$woocommerce_wpml ); $menus_wrap->show(); } else { global $sitepress; $plugins_wrap = new WCML_Plugins_Wrap( self::$woocommerce_wpml, $sitepress ); $plugins_wrap->show(); } } public static function documentation_links() { global $post, $pagenow; if ( $post && ! is_object( $post ) ) { $post = get_post( $post ); } if ( ! $post ) { return; } $tracking_link = new WCML_Tracking_Link(); $get_post_type = get_post_type( $post->ID ); if ( 'product' === $get_post_type && 'edit.php' === $pagenow ) { $quick_edit_notice = '
'; $quick_edit_notice_prod_link = ''; // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped ?>