admin-menus
1 week ago
currencies
1 week ago
template-classes
1 week ago
translation-editor
1 week ago
class-wcml-ajax-setup.php
1 week ago
class-wcml-attributes.php
1 week ago
class-wcml-capabilities.php
1 week ago
class-wcml-cart-removed-items-widget.php
1 year ago
class-wcml-cart-switch-lang-functions.php
1 week ago
class-wcml-cart-sync-warnings.php
1 week ago
class-wcml-cart.php
1 week ago
class-wcml-comments.php
1 week ago
class-wcml-compatibility.php
1 week ago
class-wcml-coupons.php
1 week ago
class-wcml-dependencies.php
1 week ago
class-wcml-emails.php
1 week ago
class-wcml-endpoints.php
1 week ago
class-wcml-install.php
1 week ago
class-wcml-languages-upgrader.php
1 week ago
class-wcml-locale.php
1 week ago
class-wcml-orders.php
1 week ago
class-wcml-products-screen-options.php
1 week ago
class-wcml-products.php
1 week ago
class-wcml-reports.php
1 week ago
class-wcml-requests.php
1 week ago
class-wcml-resources.php
1 week ago
class-wcml-store-pages.php
1 week ago
class-wcml-terms.php
1 week ago
class-wcml-tp-support.php
1 week ago
class-wcml-troubleshooting.php
1 week ago
class-wcml-upgrade.php
1 week ago
class-wcml-url-translation.php
1 week ago
class-wcml-wc-gateways.php
1 week ago
class-wcml-wc-shipping.php
1 week ago
class-wcml-wc-strings.php
1 week ago
class-wcml-widgets.php
1 week ago
constants.php
1 week ago
functions-pure.php
1 week ago
functions.php
1 week ago
installer-loader.php
1 week ago
missing-php-functions.php
1 week ago
wcml-core-functions.php
1 week ago
wcml-switch-lang-request.php
1 week ago
class-wcml-resources.php
303 lines
| 1 | <?php |
| 2 | |
| 3 | use function WCML\functions\isStandAlone; |
| 4 | use WCML\Utilities\AdminPages; |
| 5 | use WCML\Utilities\AdminUrl; |
| 6 | use WPML\FP\Relation; |
| 7 | |
| 8 | class WCML_Resources { |
| 9 | |
| 10 | private static $pagenow; |
| 11 | |
| 12 | private static $woocommerce_wpml; |
| 13 | |
| 14 | private static $sitepress; |
| 15 | |
| 16 | public static function add_hooks() { |
| 17 | add_action( 'admin_enqueue_scripts', [ __CLASS__, 'admin_scripts' ] ); |
| 18 | add_action( 'wp_enqueue_scripts', [ __CLASS__, 'front_scripts' ] ); |
| 19 | } |
| 20 | |
| 21 | public static function set_up_resources( $woocommerce_wpml, $sitepress ) { |
| 22 | global $pagenow; |
| 23 | |
| 24 | self::$woocommerce_wpml = $woocommerce_wpml; |
| 25 | self::$sitepress = $sitepress; |
| 26 | self::$pagenow = $pagenow; |
| 27 | |
| 28 | self::load_css(); |
| 29 | |
| 30 | if ( isStandAlone() ) { |
| 31 | return; |
| 32 | } |
| 33 | |
| 34 | $is_edit_product = 'post.php' === self::$pagenow && isset( $_GET['post'] ) && 'product' === get_post_type( (int) $_GET['post'] ); |
| 35 | $is_original_product = isset( $_GET['post'] ) && ! is_array( $_GET['post'] ) && self::$woocommerce_wpml->products->is_original_product( (int) $_GET['post'] ); |
| 36 | $is_new_product = 'post-new.php' === self::$pagenow && isset( $_GET['source_lang'] ) && isset( $_GET['post_type'] ) && 'product' === $_GET['post_type']; |
| 37 | |
| 38 | if ( self::$woocommerce_wpml->is_wpml_prior_4_2() ) { |
| 39 | $is_using_native_editor = ! self::$woocommerce_wpml->settings['trnsl_interface']; |
| 40 | } else { |
| 41 | $tm_settings = $sitepress->get_setting( 'translation-management', [] ); |
| 42 | if ( $is_edit_product ) { |
| 43 | $is_using_native_editor = WPML_TM_Post_Edit_TM_Editor_Mode::is_using_tm_editor( self::$sitepress, filter_var( $_GET['post'], FILTER_SANITIZE_NUMBER_INT ) ); |
| 44 | } else { |
| 45 | $is_using_native_editor = $tm_settings[ WPML_TM_Post_Edit_TM_Editor_Mode::TM_KEY_FOR_POST_TYPE_USE_NATIVE ]['product'] ?? false; |
| 46 | |
| 47 | if ( ! $is_using_native_editor ) { |
| 48 | $is_using_native_editor = $tm_settings[ WPML_TM_Post_Edit_TM_Editor_Mode::TM_KEY_GLOBAL_USE_NATIVE ] ?? false; |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | if ( ( $is_edit_product && ! $is_original_product ) || $is_new_product && $is_using_native_editor ) { |
| 54 | add_action( 'init', [ __CLASS__, 'load_lock_fields_js' ] ); |
| 55 | add_action( 'admin_footer', [ __CLASS__, 'hidden_label' ] ); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | private static function load_css() { |
| 60 | |
| 61 | if ( AdminPages::isWcmlSettings() || AdminPages::isTranslationQueue() ) { |
| 62 | |
| 63 | self::load_management_css(); |
| 64 | |
| 65 | if ( AdminPages::isMultiCurrency() || AdminPages::isTab( AdminUrl::TAB_STORE_URL ) ) { |
| 66 | wp_register_style( 'wcml-dialogs', WCML_PLUGIN_URL . '/res/css/dialogs.css', [ 'wpml-dialog' ], WCML_VERSION ); |
| 67 | wp_enqueue_style( 'wcml-dialogs' ); |
| 68 | } |
| 69 | |
| 70 | wp_enqueue_style( 'wp-color-picker' ); |
| 71 | } |
| 72 | |
| 73 | if ( is_admin() ) { |
| 74 | wp_register_style( 'wcml_admin', WCML_PLUGIN_URL . '/res/css/admin.css', [ 'wp-pointer' ], WCML_VERSION ); |
| 75 | wp_enqueue_style( 'wcml_admin' ); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | public static function load_management_css() { |
| 80 | wp_register_style( 'wpml-wcml', WCML_PLUGIN_URL . '/res/css/management.css', [], WCML_VERSION ); |
| 81 | wp_enqueue_style( 'wpml-wcml' ); |
| 82 | } |
| 83 | |
| 84 | public static function load_taxonomy_translation_scripts() { |
| 85 | wp_register_script( 'wcml-taxonomy-translation-scripts', WCML_PLUGIN_URL . '/res/js/taxonomy_translation' . WCML_JS_MIN . '.js', [ 'jquery' ], WCML_VERSION, true ); |
| 86 | wp_enqueue_script( 'wcml-taxonomy-translation-scripts' ); |
| 87 | } |
| 88 | |
| 89 | public static function admin_scripts() { |
| 90 | |
| 91 | if ( AdminPages::isWcmlSettings() ) { |
| 92 | |
| 93 | wp_register_script( 'wcml-scripts', WCML_PLUGIN_URL . '/res/js/scripts' . WCML_JS_MIN . '.js', [ 'jquery', 'jquery-ui-core', 'jquery-ui-resizable' ], WCML_VERSION, true ); |
| 94 | |
| 95 | self::load_taxonomy_translation_scripts(); |
| 96 | |
| 97 | wp_register_script( 'wcml-dialogs', WCML_PLUGIN_URL . '/res/js/dialogs' . WCML_JS_MIN . '.js', [ 'jquery', 'jquery-ui-core', 'jquery-ui-dialog', 'underscore' ], WCML_VERSION, true ); |
| 98 | wp_register_script( 'wcml-troubleshooting', WCML_PLUGIN_URL . '/res/js/troubleshooting' . WCML_JS_MIN . '.js', [ 'jquery' ], WCML_VERSION, true ); |
| 99 | |
| 100 | if ( ! isStandalone() && self::$woocommerce_wpml->is_wpml_prior_4_2() ) { |
| 101 | wp_register_script( 'wcml-translation-interface-dialog-warning', WCML_PLUGIN_URL . '/res/js/trnsl_interface_dialog_warning' . WCML_JS_MIN . '.js', [ 'jquery' ], WCML_VERSION, true ); |
| 102 | wp_enqueue_script( 'wcml-translation-interface-dialog-warning' ); |
| 103 | } |
| 104 | |
| 105 | wp_enqueue_script( 'wcml-scripts' ); |
| 106 | wp_enqueue_script( 'wp-color-picker' ); |
| 107 | wp_enqueue_script( 'wcml-dialogs' ); |
| 108 | wp_enqueue_script( 'wcml-troubleshooting' ); |
| 109 | |
| 110 | wp_localize_script( |
| 111 | 'wcml-scripts', |
| 112 | 'wcml_settings', |
| 113 | [ |
| 114 | 'nonce' => wp_create_nonce( 'woocommerce_multilingual' ), |
| 115 | ] |
| 116 | ); |
| 117 | |
| 118 | self::load_tooltip_resources(); |
| 119 | } |
| 120 | |
| 121 | if ( AdminPages::isTranslationsDashboard() ) { |
| 122 | wp_register_script( 'wpml_tm', WCML_PLUGIN_URL . '/res/js/wpml_tm' . WCML_JS_MIN . '.js', [ 'jquery' ], WCML_VERSION, true ); |
| 123 | wp_enqueue_script( 'wpml_tm' ); |
| 124 | } |
| 125 | |
| 126 | if ( self::$pagenow == 'widgets.php' ) { |
| 127 | wp_register_script( 'wcml_widgets', WCML_PLUGIN_URL . '/res/js/widgets' . WCML_JS_MIN . '.js', [ 'jquery' ], WCML_VERSION, true ); |
| 128 | wp_enqueue_script( 'wcml_widgets' ); |
| 129 | } |
| 130 | |
| 131 | if ( AdminPages::isMultiCurrency() ) { |
| 132 | wp_register_script( 'multi-currency', WCML_PLUGIN_URL . '/res/js/multi-currency' . WCML_JS_MIN . '.js', [ 'jquery', 'jquery-ui-sortable' ], WCML_VERSION, true ); |
| 133 | wp_enqueue_script( 'multi-currency' ); |
| 134 | |
| 135 | wp_register_script( 'currency-switcher-settings', WCML_PLUGIN_URL . '/res/js/currency-switcher-settings' . WCML_JS_MIN . '.js', [ 'jquery', 'jquery-ui-sortable', 'underscore' ], WCML_VERSION, true ); |
| 136 | wp_enqueue_script( 'currency-switcher-settings' ); |
| 137 | wp_localize_script( |
| 138 | 'currency-switcher-settings', |
| 139 | 'settings', |
| 140 | [ |
| 141 | 'pre_selected_colors' => WCML_Currency_Switcher_Options_Dialog::currency_switcher_pre_selected_colors(), |
| 142 | ] |
| 143 | ); |
| 144 | |
| 145 | wp_register_script( 'exchange-rates', WCML_PLUGIN_URL . '/res/js/exchange-rates' . WCML_JS_MIN . '.js', [ 'jquery' ], WCML_VERSION, true ); |
| 146 | wp_enqueue_script( 'exchange-rates' ); |
| 147 | } |
| 148 | |
| 149 | wp_enqueue_script( |
| 150 | 'wcml-pointer', |
| 151 | WCML_PLUGIN_URL . '/res/js/pointer' . WCML_JS_MIN . '.js', |
| 152 | [ 'wp-pointer' ], |
| 153 | WCML_VERSION, |
| 154 | true |
| 155 | ); |
| 156 | |
| 157 | wp_register_script( 'wcml-messages', WCML_PLUGIN_URL . '/res/js/wcml-messages' . WCML_JS_MIN . '.js', [ 'jquery' ], WCML_VERSION, true ); |
| 158 | wp_enqueue_script( 'wcml-messages' ); |
| 159 | |
| 160 | $is_attr_page = apply_filters( 'wcml_is_attributes_page', AdminPages::isWcProductAttributesPage() ); |
| 161 | |
| 162 | if ( $is_attr_page ) { |
| 163 | wp_register_script( 'wcml-attributes', WCML_PLUGIN_URL . '/res/js/wcml-attributes' . WCML_JS_MIN . '.js', [ 'jquery' ], WCML_VERSION, true ); |
| 164 | wp_enqueue_script( 'wcml-attributes' ); |
| 165 | } |
| 166 | |
| 167 | if ( AdminPages::isTranslationQueue() ) { |
| 168 | |
| 169 | self::load_tooltip_resources(); |
| 170 | wp_enqueue_media(); |
| 171 | wp_register_script( 'wcml-editor', WCML_PLUGIN_URL . '/res/js/wcml-translation-editor' . WCML_JS_MIN . '.js', [ 'jquery', 'jquery-ui-core' ], WCML_VERSION, true ); |
| 172 | wp_enqueue_script( 'wcml-editor' ); |
| 173 | wp_localize_script( |
| 174 | 'wcml-editor', |
| 175 | 'wcml_settings', |
| 176 | [ |
| 177 | 'strings' => [ |
| 178 | 'choose' => __( 'Choose a file', 'woocommerce-multilingual' ), |
| 179 | 'save_tooltip' => __( 'At least one of these fields is required: title, content or excerpt', 'woocommerce-multilingual' ), |
| 180 | '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' ), |
| 181 | ], |
| 182 | 'hide_resign' => self::$woocommerce_wpml->products->is_hide_resign_button(), |
| 183 | 'nonce' => wp_create_nonce( WCML_Translation_Editor::AUTO_SLUG_NONCE ), |
| 184 | ] |
| 185 | ); |
| 186 | } |
| 187 | |
| 188 | if ( isset( $_GET['post_type'] ) && 'product' === $_GET['post_type'] && 'edit.php' === self::$pagenow ) { |
| 189 | self::load_tooltip_resources(); |
| 190 | wp_enqueue_script( 'products-screen-options', WCML_PLUGIN_URL . '/res/js/products-screen-option.js', [ 'jquery', 'wcml-tooltip-init' ], WCML_VERSION, true ); |
| 191 | wp_localize_script( 'products-screen-options', 'products_screen_option', [ 'nonce' => wp_create_nonce( 'products-screen-option-action' ) ] ); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | public static function front_scripts() { |
| 196 | |
| 197 | if ( self::$pagenow !== 'wp-login.php' ) { |
| 198 | wcml_register_script( 'cart-widget', 'res/js/cart_widget' . WCML_JS_MIN . '.js', [], [ 'strategy' => 'defer', 'in_footer' => true ] ); |
| 199 | wp_enqueue_script( 'cart-widget' ); |
| 200 | wp_localize_script( |
| 201 | 'cart-widget', |
| 202 | 'actions', |
| 203 | [ |
| 204 | 'current_language' => self::$sitepress->get_current_language(), |
| 205 | 'force_reset' => apply_filters( 'wcml_force_reset_cart_fragments', 0 ), |
| 206 | ] |
| 207 | ); |
| 208 | } |
| 209 | |
| 210 | } |
| 211 | |
| 212 | public static function load_tooltip_resources() { |
| 213 | |
| 214 | if ( class_exists( 'WooCommerce' ) && function_exists( 'WC' ) ) { |
| 215 | add_action( 'admin_enqueue_scripts', function() { |
| 216 | $jQueryTipTipHandler = 'wc-jquery-tiptip'; |
| 217 | |
| 218 | if ( defined( 'WC_VERSION' ) && version_compare( WC_VERSION, '10.3', '<' ) ) { |
| 219 | $jQueryTipTipHandler = 'jquery-tiptip'; |
| 220 | } |
| 221 | |
| 222 | if ( wp_script_is( $jQueryTipTipHandler, 'registered' ) ) { |
| 223 | wp_register_script( 'wcml-tooltip-init', WCML_PLUGIN_URL . '/res/js/tooltip_init' . WCML_JS_MIN . '.js', [ 'jquery' ], WCML_VERSION, true ); |
| 224 | wp_enqueue_script( $jQueryTipTipHandler ); |
| 225 | wp_enqueue_script( 'wcml-tooltip-init' ); |
| 226 | } |
| 227 | if ( wp_style_is( 'woocommerce_admin_styles', 'registered') ) { |
| 228 | wp_enqueue_style( 'woocommerce_admin_styles' ); |
| 229 | } |
| 230 | }, 11 ); |
| 231 | } |
| 232 | |
| 233 | } |
| 234 | |
| 235 | public static function load_lock_fields_js() { |
| 236 | global $pagenow; |
| 237 | |
| 238 | wp_register_script( 'wcml-lock-script', WCML_PLUGIN_URL . '/res/js/lock_fields' . WCML_JS_MIN . '.js', [ 'jquery' ], WCML_VERSION, true ); |
| 239 | wp_enqueue_script( 'wcml-lock-script' ); |
| 240 | |
| 241 | $product_id = false; |
| 242 | if ( $pagenow === 'post.php' && isset( $_GET['post'] ) ) { |
| 243 | $product_id = $_GET['post']; |
| 244 | } elseif ( isset( $_POST['product_id'] ) ) { |
| 245 | $product_id = $_POST['product_id']; |
| 246 | } |
| 247 | |
| 248 | $file_path_sync = WCML_Downloadable_Products::isDownloadableFilesSetToUseSame( $product_id ); |
| 249 | |
| 250 | wp_localize_script( |
| 251 | 'wcml-lock-script', |
| 252 | 'unlock_fields', |
| 253 | [ |
| 254 | 'menu_order' => self::$woocommerce_wpml->settings['products_sync_order'], |
| 255 | 'file_paths' => $file_path_sync, |
| 256 | ] |
| 257 | ); |
| 258 | wp_localize_script( |
| 259 | 'wcml-lock-script', |
| 260 | 'non_standard_fields', |
| 261 | [ |
| 262 | 'ids' => apply_filters( 'wcml_js_lock_fields_ids', [] ), |
| 263 | 'classes' => apply_filters( 'wcml_js_lock_fields_classes', [] ), |
| 264 | 'input_names' => apply_filters( 'wcml_js_lock_fields_input_names', [] ), |
| 265 | ] |
| 266 | ); |
| 267 | |
| 268 | do_action( 'wcml_after_load_lock_fields_js' ); |
| 269 | |
| 270 | } |
| 271 | |
| 272 | public static function hidden_label() { |
| 273 | global $sitepress; |
| 274 | |
| 275 | echo '<img src="' . WCML_PLUGIN_URL . '/res/images/locked.png" class="wcml_lock_img wcml_lock_icon" alt="' . |
| 276 | __( 'This field is locked for editing because WPML will copy its value from the original language.', 'woocommerce-multilingual' ) . |
| 277 | '" title="' . __( 'This field is locked for editing because WPML will copy its value from the original language.', 'woocommerce-multilingual' ) . |
| 278 | '" style="display: none;position:relative;left:2px;top:2px;">'; |
| 279 | |
| 280 | if ( isset( $_GET['post'] ) ) { |
| 281 | $original_id = self::$woocommerce_wpml->products->get_original_product_id( sanitize_text_field( $_GET['post'] ) ); |
| 282 | } elseif ( isset( $_GET['trid'] ) ) { |
| 283 | $original_id = $sitepress->get_original_element_id_by_trid( sanitize_text_field( $_GET['trid'] ) ); |
| 284 | } |
| 285 | |
| 286 | if ( ! isset( $_GET['lang'], $original_id ) ) { |
| 287 | return; |
| 288 | } |
| 289 | |
| 290 | echo '<h3 class="wcml_prod_hidden_notice">' . |
| 291 | sprintf( |
| 292 | /* translators: %1$s is the post title inside a HTML link pointing to the post edit screen, %2$s and %3$s are opening and closing HTML link tags */ |
| 293 | esc_html__( |
| 294 | "This is a translation of %1\$s. Some of the fields are not editable. It's recommended that you translate products from the %2\$sTranslation Dashboard%3\$s.", |
| 295 | 'woocommerce-multilingual' |
| 296 | ), |
| 297 | '<a href="' . esc_url( get_edit_post_link( $original_id ) ) . '" >' . get_the_title( $original_id ) . '</a>', |
| 298 | '<a href="' . esc_url( AdminUrl::getWPMLTMDashboardProducts() ) . '">', |
| 299 | '</a>' |
| 300 | ) . '</h3>'; |
| 301 | } |
| 302 | } |
| 303 |