admin-menus
2 weeks ago
currencies
2 weeks ago
template-classes
2 weeks ago
translation-editor
2 weeks ago
class-wcml-ajax-setup.php
2 weeks ago
class-wcml-attributes.php
2 weeks ago
class-wcml-capabilities.php
2 weeks ago
class-wcml-cart-removed-items-widget.php
1 year ago
class-wcml-cart-switch-lang-functions.php
2 weeks ago
class-wcml-cart-sync-warnings.php
2 weeks ago
class-wcml-cart.php
2 weeks ago
class-wcml-comments.php
2 weeks ago
class-wcml-compatibility.php
2 weeks ago
class-wcml-coupons.php
2 weeks ago
class-wcml-dependencies.php
2 weeks ago
class-wcml-emails.php
2 weeks ago
class-wcml-endpoints.php
2 weeks ago
class-wcml-install.php
2 weeks ago
class-wcml-languages-upgrader.php
2 weeks ago
class-wcml-locale.php
2 weeks ago
class-wcml-orders.php
2 weeks ago
class-wcml-products-screen-options.php
2 weeks ago
class-wcml-products.php
2 weeks ago
class-wcml-reports.php
2 weeks ago
class-wcml-requests.php
2 weeks ago
class-wcml-resources.php
2 weeks ago
class-wcml-store-pages.php
2 weeks ago
class-wcml-terms.php
2 weeks ago
class-wcml-tp-support.php
2 weeks ago
class-wcml-troubleshooting.php
2 weeks ago
class-wcml-upgrade.php
2 weeks ago
class-wcml-url-translation.php
2 weeks ago
class-wcml-wc-gateways.php
2 weeks ago
class-wcml-wc-shipping.php
2 weeks ago
class-wcml-wc-strings.php
2 weeks ago
class-wcml-widgets.php
2 weeks ago
constants.php
2 weeks ago
functions-pure.php
2 weeks ago
functions.php
2 weeks ago
installer-loader.php
2 weeks ago
missing-php-functions.php
2 weeks ago
wcml-core-functions.php
2 weeks ago
wcml-switch-lang-request.php
2 weeks ago
class-wcml-requests.php
106 lines
| 1 | <?php |
| 2 | class WCML_Requests { |
| 3 | |
| 4 | public function __construct() { |
| 5 | |
| 6 | add_action( 'init', [ $this, 'run' ] ); |
| 7 | |
| 8 | } |
| 9 | |
| 10 | public function run() { |
| 11 | global $woocommerce_wpml; |
| 12 | |
| 13 | $nonce = filter_input( INPUT_POST, 'wcml_nonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); |
| 14 | $settings_needs_update = false; |
| 15 | |
| 16 | if ( isset( $_GET['wcml_action'] ) ) { |
| 17 | $settings_needs_update = true; |
| 18 | |
| 19 | if ( 'dismiss' === $_GET['wcml_action'] ) { |
| 20 | $woocommerce_wpml->settings['dismiss_doc_main'] = 1; |
| 21 | } elseif ( 'dismiss_tm_warning' === $_GET['wcml_action'] ) { |
| 22 | $woocommerce_wpml->settings['dismiss_tm_warning'] = 1; |
| 23 | } elseif ( 'dismiss_cart_warning' === $_GET['wcml_action'] ) { |
| 24 | $woocommerce_wpml->settings['dismiss_cart_warning'] = 1; |
| 25 | } else { |
| 26 | $settings_needs_update = false; |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | if ( isset( $_POST['wcml_save_settings'] ) && wp_verify_nonce( $nonce, 'wcml_save_settings_nonce' ) ) { |
| 31 | global $sitepress,$sitepress_settings; |
| 32 | |
| 33 | if ( isset( $_POST['trnsl_interface'] ) ) { |
| 34 | $woocommerce_wpml->settings['trnsl_interface'] = filter_input( INPUT_POST, 'trnsl_interface', FILTER_SANITIZE_NUMBER_INT ); |
| 35 | } |
| 36 | |
| 37 | $woocommerce_wpml->settings['products_sync_date'] = empty( $_POST['products_sync_date'] ) ? 0 : 1; |
| 38 | $woocommerce_wpml->settings['products_sync_order'] = empty( $_POST['products_sync_order'] ) ? 0 : 1; |
| 39 | |
| 40 | $wcml_sync_media = empty( $_POST['sync_media'] ) ? 0 : 1; |
| 41 | $woocommerce_wpml->update_setting( 'sync_media', $wcml_sync_media, true ); |
| 42 | |
| 43 | $reviews_in_all_languages = ! empty( $_POST['reviews_in_all_languages'] ); |
| 44 | $woocommerce_wpml->update_setting( 'reviews_in_all_languages', $reviews_in_all_languages, true ); |
| 45 | |
| 46 | $wcml_file_path_sync = filter_input( INPUT_POST, 'wcml_file_path_sync', FILTER_SANITIZE_NUMBER_INT ); |
| 47 | |
| 48 | $woocommerce_wpml->settings[ \WCML_Downloadable_Products::SYNC_MODE_SETTING_KEY ] = $wcml_file_path_sync; |
| 49 | |
| 50 | if ( isset( $_POST['cart_sync_lang'] ) && isset( $_POST['cart_sync_currencies'] ) ) { |
| 51 | $woocommerce_wpml->settings['cart_sync']['lang_switch'] = (int) filter_input( INPUT_POST, 'cart_sync_lang', FILTER_SANITIZE_NUMBER_INT ); |
| 52 | $woocommerce_wpml->settings['cart_sync']['currency_switch'] = (int) filter_input( INPUT_POST, 'cart_sync_currencies', FILTER_SANITIZE_NUMBER_INT ); |
| 53 | } |
| 54 | |
| 55 | $new_value = $wcml_file_path_sync == 0 ? 2 : $wcml_file_path_sync; |
| 56 | $sitepress_settings['translation-management']['custom_fields_translation']['_downloadable_files'] = $new_value; |
| 57 | $sitepress_settings['translation-management']['custom_fields_translation']['_file_paths'] = $new_value; |
| 58 | |
| 59 | $sitepress->save_settings( $sitepress_settings ); |
| 60 | |
| 61 | $message = [ |
| 62 | 'id' => 'wcml-settings-saved', |
| 63 | 'text' => __( 'Your settings have been saved.', 'woocommerce-multilingual' ), |
| 64 | 'group' => 'wcml-settings', |
| 65 | 'admin_notice' => true, |
| 66 | 'limit_to_page' => true, |
| 67 | 'classes' => [ 'updated', 'notice', 'notice-success' ], |
| 68 | 'show_once' => true, |
| 69 | ]; |
| 70 | ICL_AdminNotifier::add_message( $message ); |
| 71 | |
| 72 | $settings_needs_update = true; |
| 73 | } |
| 74 | |
| 75 | if ( $settings_needs_update ) { |
| 76 | $woocommerce_wpml->update_settings(); |
| 77 | } |
| 78 | |
| 79 | add_action( 'wp_ajax_wcml_ignore_warning', [ $this, 'update_settings_from_warning' ] ); |
| 80 | |
| 81 | add_filter( 'woocommerce_cached_widget_id', [ $this, 'override_cached_widget_id' ] ); |
| 82 | } |
| 83 | |
| 84 | public function update_settings_from_warning() { |
| 85 | $nonce = filter_input( INPUT_POST, 'wcml_nonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); |
| 86 | if ( ! $nonce || ! wp_verify_nonce( $nonce, 'wcml_ignore_warning' ) ) { |
| 87 | die( 'Invalid nonce' ); |
| 88 | } |
| 89 | global $woocommerce_wpml; |
| 90 | |
| 91 | $woocommerce_wpml->settings[ $_POST['setting'] ] = 1; |
| 92 | $woocommerce_wpml->update_settings(); |
| 93 | |
| 94 | } |
| 95 | |
| 96 | public function override_cached_widget_id( $widget_id ) { |
| 97 | |
| 98 | if ( defined( 'ICL_LANGUAGE_CODE' ) ) { |
| 99 | $widget_id .= ':' . ICL_LANGUAGE_CODE; |
| 100 | } |
| 101 | |
| 102 | return $widget_id; |
| 103 | } |
| 104 | |
| 105 | } |
| 106 |