WCML_Admin_Menus

The WordPress Core WCML Admin Menus class.

Defined (1)

The class is defined in the following location(s).

/inc/admin-menus/class-wcml-admin-menus.php  
  1. class WCML_Admin_Menus{ 
  2.  
  3. private static $woocommerce_wpml; 
  4. private static $sitepress; 
  5. private static $wpdb; 
  6.  
  7. public static function set_up_menus( &$woocommerce_wpml, &$sitepress, &$wpdb, $check_dependencies ) { 
  8. self::$woocommerce_wpml =& $woocommerce_wpml; 
  9. self::$sitepress =& $sitepress; 
  10. self::$wpdb =& $wpdb; 
  11.  
  12. add_action( 'admin_menu', array(__CLASS__, 'register_menus' ), 80 ); 
  13.  
  14. if( self::is_page_without_admin_language_switcher() ) { 
  15. self::remove_wpml_admin_language_switcher(); 
  16.  
  17. if( is_admin() && !is_null( $sitepress ) && $check_dependencies ) { 
  18. add_action( 'admin_footer', array(__CLASS__, 'documentation_links' ) ); 
  19. add_action( 'admin_head', array( __CLASS__, 'hide_multilingual_content_setup_box' ) ); 
  20. add_action( 'admin_init', array( __CLASS__, 'restrict_admin_with_redirect' ) ); 
  21.  
  22. add_filter( 'woocommerce_prevent_admin_access', array( __CLASS__, 'check_user_admin_access' ) ); 
  23.  
  24. add_action( 'admin_head', array( __CLASS__, 'add_menu_warning' ) ); 
  25.  
  26. public static function register_menus() { 
  27. global $WPML_Translation_Management; 
  28.  
  29. if( self::$woocommerce_wpml->check_dependencies || class_exists( 'WooCommerce' ) ) { 
  30.  
  31. add_submenu_page( 
  32. 'woocommerce',  
  33. __( 'WooCommerce Multilingual', 'woocommerce-multilingual' ),  
  34. __( 'WooCommerce Multilingual', 'woocommerce-multilingual' ),  
  35. 'wpml_operate_woocommerce_multilingual',  
  36. 'wpml-wcml',  
  37. array( __CLASS__, 'render_menus' ) 
  38. ); 
  39.  
  40. if( !current_user_can('wpml_manage_woocommerce_multilingual') && current_user_can('wpml_operate_woocommerce_multilingual') ) { 
  41. //force add translations-queue page for shop manager 
  42. $wp_api = self::$sitepress->get_wp_api(); 
  43. if (!$wp_api->current_user_can('wpml_manage_translation_management')) { 
  44. $wp_api->add_submenu_page(null,  
  45. __('Translations', 'wpml-translation-management'), __('Translations', 'wpml-translation-management'),  
  46. 'wpml_operate_woocommerce_multilingual', WPML_TM_FOLDER . '/menu/translations-queue.php', array($WPML_Translation_Management, 'translation_queue_page')); 
  47. } else { 
  48.  
  49. add_menu_page( 
  50. __( 'WooCommerce Multilingual', 'woocommerce-multilingual' ),  
  51. __( 'WooCommerce Multilingual', 'woocommerce-multilingual' ),  
  52. 'wpml_manage_woocommerce_multilingual',  
  53. 'wpml-wcml',  
  54. array( __CLASS__, 'render_menus' ),  
  55. WCML_PLUGIN_URL . '/res/images/icon16.png' 
  56. ); 
  57.  
  58.  
  59. public static function render_menus() { 
  60.  
  61. if( self::$woocommerce_wpml->check_dependencies ) { 
  62. $menus_wrap = new WCML_Menus_Wrap( self::$woocommerce_wpml ); 
  63. $menus_wrap->show(); 
  64. }else{ 
  65. global $sitepress; 
  66. $plugins_wrap = new WCML_Plugins_Wrap( self::$woocommerce_wpml, $sitepress ); 
  67. $plugins_wrap->show(); 
  68.  
  69.  
  70. private static function is_page_without_admin_language_switcher() { 
  71. global $pagenow; 
  72.  
  73. $get_post_type = isset( $_GET['post_type'] ) ? $_GET['post_type'] : false; 
  74. $get_post = isset( $_GET['post'] ) ? $_GET['post'] : false; 
  75. $get_page = isset( $_GET['page'] ) ? $_GET['page'] : false; 
  76.  
  77. $is_page_wpml_wcml = isset($_GET['page']) && $_GET['page'] == 'wpml-wcml'; 
  78. $is_new_order_or_coupon = in_array( $pagenow, array( 'edit.php', 'post-new.php' ) ) && 
  79. $get_post_type && 
  80. in_array( $get_post_type, array( 'shop_coupon', 'shop_order' ) ); 
  81. $is_edit_order_or_coupon = $pagenow == 'post.php' && $get_post && 
  82. in_array( get_post_type( $get_post ), array( 'shop_coupon', 'shop_order' ) ); 
  83. $is_shipping_zones = $get_page == 'shipping_zones'; 
  84. $is_attributes_page = apply_filters( 'wcml_is_attributes_page', $get_page == 'product_attributes' ); 
  85.  
  86.  
  87. return is_admin() && ( 
  88. $is_page_wpml_wcml || 
  89. $is_new_order_or_coupon || 
  90. $is_edit_order_or_coupon || 
  91. $is_shipping_zones || 
  92. $is_attributes_page 
  93. ); 
  94.  
  95.  
  96. public static function remove_wpml_admin_language_switcher() { 
  97.  
  98. remove_action( 'wp_before_admin_bar_render', array(self::$sitepress, 'admin_language_switcher') ); 
  99.  
  100.  
  101. public static function documentation_links() { 
  102. global $post, $pagenow; 
  103.  
  104. if ( is_null( $post ) ) 
  105. return; 
  106.  
  107. $get_post_type = get_post_type( $post->ID ); 
  108.  
  109. if ( $get_post_type == 'product' && $pagenow == 'edit.php' ) { 
  110. $quick_edit_notice = '<div id="quick_edit_notice" style="display:none;"><p>' . 
  111. sprintf( __( "Quick edit is disabled for product translations. It\'s recommended to use the %s for editing products translations. %s",  
  112. 'woocommerce-multilingual' ), '<a href="' . admin_url( 'admin.php?page=wpml-wcml&tab=products' ) . '" >' . 
  113. __( 'WooCommerce Multilingual products editor', 'woocommerce-multilingual' ) . '</a>',  
  114. '<a href="" class="quick_product_trnsl_link" >' . __( 'Edit this product translation', 'woocommerce-multilingual' ) . '</a>' 
  115. ) . '</p></div>'; 
  116. $quick_edit_notice_prod_link = '<input type="hidden" id="wcml_product_trnsl_link" value="' . admin_url( 'admin.php?page=wpml-wcml&tab=products&prid=' ) . '">'; 
  117. ?> 
  118. <script type="text/javascript"> 
  119. jQuery(".subsubsub").append('<?php echo $quick_edit_notice ?>'); 
  120. jQuery(".subsubsub").append('<?php echo $quick_edit_notice_prod_link ?>'); 
  121. jQuery(".quick_hide a").on('click', function () { 
  122. jQuery(".quick_product_trnsl_link").attr('href', jQuery("#wcml_product_trnsl_link").val() + jQuery(this).closest('tr').attr('id').replace(/post-/, '')); 
  123. }); 
  124.  
  125. //lock feature for translations 
  126. jQuery(document).on('click', '.featured a', function () { 
  127. if (jQuery(this).closest('tr').find('.quick_hide').size() > 0) { 
  128. return false; 
  129.  
  130. }); 
  131. </script> 
  132. <?php 
  133.  
  134. if ( isset($_GET['taxonomy']) ) { 
  135. $pos = strpos( $_GET['taxonomy'], 'pa_' ); 
  136.  
  137. if ( $pos !== false && $pagenow == 'edit-tags.php' ) { 
  138. $prot_link = '<span class="button" style="padding:4px;margin-top:0px; float: left;"><img align="baseline" src="' . ICL_PLUGIN_URL . '/res/img/icon16.png" width="16" height="16" style="margin-bottom:-4px" /> <a href="' . WCML_Links::generate_tracking_link( 'https://wpml.org/documentation/related-projects/woocommerce-multilingual/', 'woocommerce-multilingual', 'documentation', '#3' ) . '" target="_blank" style="text-decoration: none;">' . 
  139. __( 'How to translate attributes', 'sitepress' ) . '<\/a>' . '<\/span><br \/><br \/>'; 
  140. ?> 
  141. <script type="text/javascript"> 
  142. jQuery("table.widefat").before('<?php echo $prot_link ?>'); 
  143. </script> 
  144. <?php 
  145.  
  146. if ( isset($_GET['taxonomy']) && $_GET['taxonomy'] == 'product_cat' ) { 
  147.  
  148. $prot_link = '<span class="button" style="padding:4px;margin-top:0px; float: left;"><img align="baseline" src="' . ICL_PLUGIN_URL . '/res/img/icon16.png" width="16" height="16" style="margin-bottom:-4px" /> <a href="' . WCML_Links::generate_tracking_link( 'https://wpml.org/documentation/related-projects/woocommerce-multilingual/', 'woocommerce-multilingual', 'documentation', '#3' ) . '" target="_blank" style="text-decoration: none;">' . 
  149. __( 'How to translate product categories', 'sitepress' ) . '<\/a>' . '<\/span><br \/><br \/>'; 
  150. ?> 
  151. <script type="text/javascript"> 
  152. jQuery("table.widefat").before('<?php echo $prot_link ?>'); 
  153. </script> 
  154. <?php 
  155.  
  156. public static function hide_multilingual_content_setup_box() { 
  157. remove_meta_box('icl_div_config', convert_to_screen('shop_order'), 'normal'); 
  158. remove_meta_box('icl_div_config', convert_to_screen('shop_coupon'), 'normal'); 
  159.  
  160. public static function restrict_admin_with_redirect() { 
  161. global $pagenow; 
  162.  
  163. $default_lang = self::$sitepress->get_default_language(); 
  164. $current_lang = self::$sitepress->get_current_language(); 
  165.  
  166. if( 
  167. ( $pagenow == 'post.php' && isset( $_GET[ 'post' ] ) ) || 
  168. ( $pagenow == 'admin.php' && 
  169. isset( $_GET[ 'action' ] ) && 
  170. $_GET[ 'action'] == 'duplicate_product' && 
  171. isset( $_GET[ 'post' ] ) 
  172. ) { 
  173. $prod_lang = self::$sitepress->get_language_for_element( $_GET[ 'post' ], 'post_product' ); 
  174.  
  175. if( 
  176. !self::$woocommerce_wpml->settings[ 'trnsl_interface' ] && 
  177. $pagenow == 'post.php' && 
  178. isset( $_GET[ 'post' ] )&& 
  179. get_post_type( $_GET[ 'post' ] ) == 'product' && 
  180. !self::$woocommerce_wpml->products->is_original_product( $_GET[ 'post' ] ) ) 
  181. add_action( 'admin_notices', array( __CLASS__, 'inf_editing_product_in_non_default_lang' ) ); 
  182.  
  183. if( 
  184. self::$woocommerce_wpml->settings[ 'trnsl_interface' ] && 
  185. $pagenow == 'post.php' && 
  186. !is_ajax() && 
  187. isset( $_GET[ 'post' ] ) && 
  188. !self::$woocommerce_wpml->products->is_original_product( $_GET[ 'post' ] ) && 
  189. get_post_type( $_GET[ 'post' ] ) == 'product' 
  190. ) { 
  191. if( 
  192. !isset( $_GET[ 'action' ] ) || 
  193. ( isset( $_GET[ 'action' ] ) && !in_array( $_GET[ 'action' ], array( 'trash', 'delete' ) ) ) 
  194. ) { 
  195. $prid = (int)$_GET[ 'post' ]; 
  196. wp_redirect( admin_url( 'admin.php?page=wpml-wcml&tab=products&prid='.$prid ) ); 
  197. exit; 
  198.  
  199. if( 
  200. self::$woocommerce_wpml->settings[ 'trnsl_interface' ] && 
  201. $pagenow == 'admin.php' && 
  202. isset( $_GET[ 'action' ] ) && 
  203. $_GET[ 'action' ] == 'duplicate_product' && 
  204. $default_lang != $prod_lang ) 
  205. wp_redirect( admin_url( 'admin.php?page=wpml-wcml&tab=products' ) ); 
  206. exit; 
  207.  
  208. public static function inf_editing_product_in_non_default_lang() { 
  209. if( !self::$woocommerce_wpml->settings[ 'dismiss_tm_warning' ] ) { 
  210. $url = $_SERVER['REQUEST_URI']; 
  211.  
  212. $message = '<div class="message error otgs-is-dismissible"><p>'; 
  213. $message .= sprintf( 
  214. __('The recommended way to translate WooCommerce products is using the 
  215. %sWooCommerce Multilingual products translation%s page. 
  216. Please use this page only for translating elements that are not available in the WooCommerce Multilingual products translation table.',  
  217. 'woocommerce-multilingual'),  
  218. '<strong><a href="' . admin_url('admin.php?page=wpml-wcml&tab=products') . '">', '</a></strong>'); 
  219. $message .= '</p><a class="notice-dismiss" href="' . $url . '&wcml_action=dismiss_tm_warning"><span class="screen-reader-text">' . __('Dismiss', 'woocommerce-multilingual') . '</a>'; 
  220. $message .= '</div>'; 
  221.  
  222. echo $message; 
  223.  
  224. public static function check_user_admin_access( $prevent_access ) { 
  225.  
  226. if( self::$woocommerce_wpml->check_dependencies ) { 
  227. $user_lang_pairs = get_user_meta( get_current_user_id(), self::$wpdb->prefix.'language_pairs', true ); 
  228. if( current_user_can( 'wpml_manage_woocommerce_multilingual' ) || !empty( $user_lang_pairs ) ) { 
  229. return false; 
  230.  
  231. return $prevent_access; 
  232.  
  233. public static function add_menu_warning() { 
  234. global $submenu, $menu; 
  235.  
  236. if ( 
  237. class_exists( 'WooCommerce' ) && 
  238. empty( self::$woocommerce_wpml->settings['set_up_wizard_run'] ) || 
  239. empty( self::$woocommerce_wpml->settings['set_up_wizard_run'] ) && 
  240. self::$woocommerce_wpml->settings['set_up_wizard_splash'] 
  241. ) { 
  242. if( isset( $submenu[ 'woocommerce' ] ) ) { 
  243. foreach( $submenu[ 'woocommerce' ] as $key => $menu_item ) { 
  244. if ( $menu_item[ 0 ] == __( 'WooCommerce Multilingual', 'woocommerce-multilingual' ) ) { 
  245. $submenu[ 'woocommerce' ][ $key ][ 0 ] .= '<span class="wcml-menu-warn"><i class="otgs-ico-warning"></i></span>'; 
  246. break; 
  247.  
  248. foreach( $menu as $key => $menu_item ) { 
  249. if ( $menu_item[ 0 ] == __( 'WooCommerce', 'woocommerce' ) ) { 
  250. $menu[ $key ][ 0 ] .= '<span class="wcml-menu-warn"><i class="otgs-ico-warning"></i></span>'; 
  251. break; 
  252.