WCML_Resources

The WooCommerce Multilingual WCML Resources class.

Defined (1)

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

/inc/class-wcml-resources.php  
  1. class WCML_Resources { 
  2.  
  3. private static $page; 
  4. private static $tab; 
  5. private static $is_wpml_wcml_page; 
  6. private static $pagenow; 
  7.  
  8. private static $woocommerce_wpml; 
  9. private static $sitepress; 
  10.  
  11. public static function set_up_resources( &$woocommerce_wpml, &$sitepress ) { 
  12. global $pagenow; 
  13.  
  14. self::$woocommerce_wpml =& $woocommerce_wpml; 
  15. self::$sitepress =& $sitepress; 
  16.  
  17. self::$page = isset($_GET['page']) ? $_GET['page'] : null; 
  18. self::$tab = isset($_GET['tab']) ? $_GET['tab'] : null; 
  19. self::$is_wpml_wcml_page = self::$page == 'wpml-wcml'; 
  20. self::$pagenow = $pagenow; 
  21.  
  22. self::load_css(); 
  23. self::load_js(); 
  24.  
  25. $is_edit_product = self::$pagenow == 'post.php' && isset($_GET['post']) && get_post_type( $_GET['post'] ) == 'product'; 
  26. $is_original_product = isset( $_GET['post'] ) && !is_array( $_GET['post'] ) && self::$woocommerce_wpml->products->is_original_product( $_GET['post'] ); 
  27. $is_new_product = self::$pagenow == 'post-new.php' && isset($_GET['source_lang']) && isset($_GET['post_type']) && $_GET['post_type'] == 'product'; 
  28.  
  29. if ( ($is_edit_product && !$is_original_product) || $is_new_product && !self::$woocommerce_wpml->settings['trnsl_interface'] ) { 
  30. add_action( 'init', array(__CLASS__, 'load_lock_fields_js') ); 
  31. add_action( 'admin_footer', array(__CLASS__, 'hidden_label') ); 
  32.  
  33. private static function load_css() { 
  34.  
  35. if ( self::$is_wpml_wcml_page || self::$page == WPML_TM_FOLDER . '/menu/translations-queue.php' ) { 
  36.  
  37. self::load_management_css(); 
  38.  
  39. if ( in_array( self::$tab, array('multi-currency', 'slugs') ) ) { 
  40. wp_register_style( 'wcml-dialogs', WCML_PLUGIN_URL . '/res/css/dialogs.css', array('wpml-dialog'), WCML_VERSION ); 
  41. wp_enqueue_style( 'wcml-dialogs' ); 
  42.  
  43. wp_enqueue_style( 'wp-color-picker' ); 
  44.  
  45. if ( self::$pagenow == 'options-permalink.php' ) { 
  46. wp_register_style( 'wcml_op', WCML_PLUGIN_URL . '/res/css/options-permalink.css', null, WCML_VERSION ); 
  47. wp_enqueue_style( 'wcml_op' ); 
  48.  
  49. if( is_admin() ) { 
  50. wp_register_style( 'wcml_admin', WCML_PLUGIN_URL . '/res/css/admin.css', array( 'wp-pointer' ), WCML_VERSION ); 
  51. wp_enqueue_style( 'wcml_admin' ); 
  52.  
  53. public static function load_management_css() { 
  54. wp_register_style( 'wpml-wcml', WCML_PLUGIN_URL . '/res/css/management.css', array(), WCML_VERSION ); 
  55. wp_enqueue_style( 'wpml-wcml' ); 
  56.  
  57. private static function load_js() { 
  58.  
  59. if ( self::$is_wpml_wcml_page ) { 
  60.  
  61. wp_register_script( 'wcml-scripts', WCML_PLUGIN_URL . '/res/js/scripts' . WCML_JS_MIN . '.js', array( 
  62. 'jquery',  
  63. 'jquery-ui-core',  
  64. 'jquery-ui-resizable' 
  65. ), WCML_VERSION ); 
  66.  
  67.  
  68. wp_register_script( 'jquery-cookie', WCML_PLUGIN_URL . '/res/js/jquery.cookie' . WCML_JS_MIN . '.js', array('jquery'), WCML_VERSION ); 
  69. wp_register_script( 'wcml-dialogs', WCML_PLUGIN_URL . '/res/js/dialogs' . WCML_JS_MIN . '.js', array('jquery', 'jquery-ui-core', 'jquery-ui-dialog'), WCML_VERSION ); 
  70. wp_register_script( 'wcml-troubleshooting', WCML_PLUGIN_URL . '/res/js/troubleshooting' . WCML_JS_MIN . '.js', array('jquery'), WCML_VERSION ); 
  71.  
  72. wp_enqueue_script( 'wp-color-picker'); 
  73. wp_enqueue_script( 'wcml-dialogs' ); 
  74. wp_enqueue_script( 'wcml-scripts' ); 
  75. wp_enqueue_script( 'jquery-cookie' ); 
  76. wp_enqueue_script( 'wcml-troubleshooting' ); 
  77.  
  78. wp_localize_script( 'wcml-scripts', 'wcml_settings',  
  79. array( 
  80. 'nonce' => wp_create_nonce( 'woocommerce_multilingual' ) 
  81. ); 
  82.  
  83. self::load_tooltip_resources(); 
  84.  
  85. if ( self::$page == WPML_TM_FOLDER . '/menu/main.php' ) { 
  86. wp_register_script( 'wpml_tm', WCML_PLUGIN_URL . '/res/js/wpml_tm' . WCML_JS_MIN . '.js', array('jquery'), WCML_VERSION ); 
  87. wp_enqueue_script( 'wpml_tm' ); 
  88.  
  89. if ( self::$pagenow == 'widgets.php' ) { 
  90. wp_register_script( 'wcml_widgets', WCML_PLUGIN_URL . '/res/js/widgets' . WCML_JS_MIN . '.js', array('jquery'), WCML_VERSION ); 
  91. wp_enqueue_script( 'wcml_widgets' ); 
  92.  
  93. if ( self::$page == 'wpml-wcml' && self::$tab == 'multi-currency' ) { 
  94. wp_register_script( 'multi-currency', WCML_PLUGIN_URL . '/res/js/multi-currency' . WCML_JS_MIN . '.js', array('jquery', 'jquery-ui-sortable'), WCML_VERSION, true ); 
  95. wp_enqueue_script( 'multi-currency' ); 
  96.  
  97. wp_register_script( 'currency-switcher-settings', WCML_PLUGIN_URL . '/res/js/currency-switcher-settings' . WCML_JS_MIN . '.js', array('jquery', 'jquery-ui-sortable'), WCML_VERSION, true ); 
  98. wp_enqueue_script( 'currency-switcher-settings' ); 
  99. wp_localize_script( 'currency-switcher-settings', 'settings', array( 
  100. 'pre_selected_colors' => WCML_Currency_Switcher_Options_Dialog::currency_switcher_pre_selected_colors() 
  101. ) ); 
  102.  
  103. wp_register_script( 'exchange-rates', WCML_PLUGIN_URL . '/res/js/exchange-rates' . WCML_JS_MIN . '.js', array('jquery'), WCML_VERSION, true ); 
  104. wp_enqueue_script( 'exchange-rates' ); 
  105.  
  106. if ( self::$page == 'wpml-wcml' && self::$tab == 'product-attributes' ) { 
  107. wp_register_script( 'product-attributes', WCML_PLUGIN_URL . '/res/js/product-attributes' . WCML_JS_MIN . '.js', array('jquery'), WCML_VERSION, true ); 
  108. wp_enqueue_script( 'product-attributes' ); 
  109.  
  110. if ( self::$page == 'wpml-wcml' && self::$tab == 'custom-taxonomies' ) { 
  111. wp_register_script( 'custom-taxonomies', WCML_PLUGIN_URL . '/res/js/product-custom-taxonomies' . WCML_JS_MIN . '.js', array('jquery'), WCML_VERSION, true ); 
  112. wp_enqueue_script( 'custom-taxonomies' ); 
  113.  
  114. if ( !is_admin() && self::$pagenow != 'wp-login.php' ) { 
  115.  
  116. wp_register_script( 'wcml-front-scripts', WCML_PLUGIN_URL . '/res/js/front-scripts' . WCML_JS_MIN . '.js', array( 
  117. 'jquery' 
  118. ), WCML_VERSION ); 
  119. wp_enqueue_script( 'wcml-front-scripts' ); 
  120.  
  121. $referer = isset( $_SERVER[ 'HTTP_REFERER' ] ) ? $_SERVER[ 'HTTP_REFERER' ] : ''; 
  122.  
  123. wp_register_script( 'cart-widget', WCML_PLUGIN_URL . '/res/js/cart_widget' . WCML_JS_MIN . '.js', array('jquery'), WCML_VERSION ); 
  124. wp_enqueue_script( 'cart-widget' ); 
  125. wp_localize_script( 'cart-widget', 'actions', array( 
  126. 'is_lang_switched' => self::$sitepress->get_language_from_url( $referer ) != self::$sitepress->get_current_language() ? 1 : 0,  
  127. 'is_currency_switched' => isset( $_GET[ 'wcmlc' ] ) ? 1 : 0 
  128. ) ); 
  129. } elseif( is_admin() ) { 
  130.  
  131. wp_enqueue_script( 
  132. 'wcml-pointer',  
  133. WCML_PLUGIN_URL . '/res/js/pointer' . WCML_JS_MIN . '.js',  
  134. array( 'wp-pointer' ),  
  135. WCML_VERSION,  
  136. true 
  137. ); 
  138.  
  139. wp_register_script( 'wcml-messages', WCML_PLUGIN_URL . '/res/js/wcml-messages' . WCML_JS_MIN . '.js', array('jquery'), WCML_VERSION ); 
  140. wp_enqueue_script( 'wcml-messages' ); 
  141.  
  142. $is_attr_page = apply_filters( 'wcml_is_attributes_page', self::$page == 'product_attributes' && isset( $_GET[ 'post_type' ] ) && $_GET[ 'post_type' ] == 'product' ); 
  143.  
  144. if( $is_attr_page ) { 
  145. wp_register_script( 'wcml-attributes', WCML_PLUGIN_URL . '/res/js/wcml-attributes' . WCML_JS_MIN . '.js', array( 'jquery' ), WCML_VERSION ); 
  146. wp_enqueue_script( 'wcml-attributes' ); 
  147.  
  148. if( self::$page == WPML_TM_FOLDER . '/menu/translations-queue.php' ) { 
  149.  
  150. self::load_tooltip_resources(); 
  151. wp_enqueue_media(); 
  152. wp_register_script( 'wcml-editor', WCML_PLUGIN_URL . '/res/js/wcml-translation-editor' . WCML_JS_MIN . '.js', array('jquery', 'jquery-ui-core'), WCML_VERSION); 
  153. wp_enqueue_script( 'wcml-editor' ); 
  154. wp_localize_script( 'wcml-editor', 'wcml_settings',  
  155. array( 
  156. 'strings' => array( 
  157. 'choose' => __( 'Choose a file', 'woocommerce-multilingual' ),  
  158. 'save_tooltip' => __( 'At least one of these fields is required: title, content or excerpt', 'woocommerce-multilingual' ),  
  159. 'resign_tooltip'=> __( 'This translation job will no longer be assigned to you. Other translators will be able take it and continue the translation.', 'woocommerce-multilingual') 
  160. ),  
  161. 'hide_resign' => self::$woocommerce_wpml->products->is_hide_resign_button() 
  162. ); 
  163.  
  164. if ( isset( $_GET['post_type'] ) && 'product' === $_GET['post_type'] && 'edit.php' === self::$pagenow ) { 
  165. self::load_tooltip_resources(); 
  166. wp_enqueue_script( 'products-screen-options', WCML_PLUGIN_URL . '/res/js/products-screen-option.js', array( 'jquery', 'wcml-tooltip-init' ), WCML_VERSION ); 
  167. wp_localize_script( 'products-screen-options', 'products_screen_option', array( 'nonce' => wp_create_nonce( 'products-screen-option-action' ) ) ); 
  168.  
  169. public static function load_tooltip_resources() { 
  170.  
  171. if ( class_exists( 'WooCommerce' ) && function_exists( 'WC' ) ) { 
  172. wp_register_script( 'jquery-tiptip', WC()->plugin_url() . '/assets/js/jquery-tiptip/jquery.tipTip.min.js', array('jquery'), WC_VERSION, true ); 
  173. wp_register_script( 'wcml-tooltip-init', WCML_PLUGIN_URL . '/res/js/tooltip_init' . WCML_JS_MIN . '.js', array('jquery'), WCML_VERSION ); 
  174. wp_enqueue_script( 'jquery-tiptip' ); 
  175. wp_enqueue_script( 'wcml-tooltip-init' ); 
  176. wp_enqueue_style( 'woocommerce_admin_styles', WC()->plugin_url() . '/assets/css/admin.css', array(), WC_VERSION ); 
  177.  
  178.  
  179. public static function load_lock_fields_js() { 
  180. global $pagenow; 
  181.  
  182. wp_register_script( 'wcml-lock-script', WCML_PLUGIN_URL . '/res/js/lock_fields' . WCML_JS_MIN . '.js', array('jquery'), WCML_VERSION ); 
  183. wp_enqueue_script( 'wcml-lock-script' ); 
  184.  
  185. $file_path_sync = self::$woocommerce_wpml->settings['file_path_sync']; 
  186.  
  187. $product_id = false; 
  188. if( $pagenow === 'post.php' && isset( $_GET['post'] ) ) { 
  189. $product_id = $_GET['post']; 
  190. }elseif( isset( $_POST['product_id'] ) ) { 
  191. $product_id = $_POST['product_id']; 
  192.  
  193. if( $product_id ) { 
  194. $original_id = self::$woocommerce_wpml->products->get_original_product_id( $product_id ); 
  195. $custom_product_sync = get_post_meta( $original_id, 'wcml_sync_files', true ); 
  196. if( $custom_product_sync && $custom_product_sync == 'self' ) { 
  197. $file_path_sync = false; 
  198. }elseif( $custom_product_sync && $custom_product_sync == 'auto' ) { 
  199. $file_path_sync = true; 
  200.  
  201. wp_localize_script( 'wcml-lock-script', 'unlock_fields', array( 
  202. 'menu_order' => self::$woocommerce_wpml->settings['products_sync_order'],  
  203. 'file_paths' => $file_path_sync 
  204. ); 
  205. wp_localize_script( 'wcml-lock-script', 'non_standard_fields', array( 
  206. 'ids' => apply_filters( 'wcml_js_lock_fields_ids', array() ),  
  207. 'classes' => apply_filters( 'wcml_js_lock_fields_classes', array() ),  
  208. 'input_names' => apply_filters( 'wcml_js_lock_fields_input_names', array() ) 
  209. ) ); 
  210.  
  211. do_action( 'wcml_after_load_lock_fields_js' ); 
  212.  
  213.  
  214. public static function hidden_label() { 
  215. global $sitepress; 
  216.  
  217. echo '<img src="' . WCML_PLUGIN_URL . '/res/images/locked.png" class="wcml_lock_img wcml_lock_icon" alt="' . 
  218. __( 'This field is locked for editing because WPML will copy its value from the original language.', 'woocommerce-multilingual' ) . 
  219. '" title="' . __( 'This field is locked for editing because WPML will copy its value from the original language.', 'woocommerce-multilingual' ) . 
  220. '" style="display: none;position:relative;left:2px;top:2px;">'; 
  221.  
  222. if ( isset($_GET['post']) ) { 
  223. $original_id = self::$woocommerce_wpml->products->get_original_product_id( sanitize_text_field( $_GET['post'] ) ); 
  224. } elseif ( isset($_GET['trid']) ) { 
  225. $original_id = $sitepress->get_original_element_id_by_trid( sanitize_text_field( $_GET['trid'] ) ); 
  226.  
  227. if ( isset($_GET['lang']) ) { 
  228. $language = $_GET['lang']; 
  229. } else { 
  230. return; 
  231.  
  232. echo '<h3 class="wcml_prod_hidden_notice">' . 
  233. sprintf( __( "This is a translation of %s. Some of the fields are not editable. It's recommended to use the %s for translating products.",  
  234. 'woocommerce-multilingual' ),  
  235. '<a href="' . get_edit_post_link( $original_id ) . '" >' . get_the_title( $original_id ) . '</a>',  
  236. '<a data-action="product-translation-dialog" class="js-wcml-dialog-trigger" data-id="' . $original_id . '" data-job_id="" data-language="' . $language . '">' . 
  237. __( 'WooCommerce Multilingual products translator', 'woocommerce-multilingual' ) . '</a>' ) . '</h3>';