WCML_Requests

The WooCommerce Multilingual WCML Requests class.

Defined (1)

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

/inc/class-wcml-requests.php  
  1. class WCML_Requests{ 
  2.  
  3. function __construct() { 
  4.  
  5. add_action('init', array($this, 'run') ); 
  6.  
  7.  
  8.  
  9. function run() { 
  10. global $woocommerce_wpml; 
  11.  
  12. $nonce = filter_input( INPUT_POST, 'wcml_nonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); 
  13.  
  14. if(isset($_POST['wcml_save_settings']) && wp_verify_nonce($nonce, 'wcml_save_settings_nonce')) { 
  15. global $sitepress, $sitepress_settings; 
  16.  
  17. $woocommerce_wpml->settings['trnsl_interface'] = filter_input( INPUT_POST, 'trnsl_interface', FILTER_SANITIZE_NUMBER_INT ); 
  18.  
  19. $woocommerce_wpml->settings['products_sync_date'] = empty($_POST['products_sync_date']) ? 0 : 1; 
  20. $woocommerce_wpml->settings['products_sync_order'] = empty($_POST['products_sync_order']) ? 0 : 1; 
  21.  
  22. $wcml_file_path_sync = filter_input( INPUT_POST, 'wcml_file_path_sync', FILTER_SANITIZE_NUMBER_INT ); 
  23.  
  24. $woocommerce_wpml->settings['file_path_sync'] = $wcml_file_path_sync; 
  25.  
  26. $woocommerce_wpml->settings['cart_sync']['lang_switch'] = intval( filter_input( INPUT_POST, 'cart_sync_lang', FILTER_SANITIZE_NUMBER_INT ) ); 
  27. $woocommerce_wpml->settings['cart_sync']['currency_switch'] = intval( filter_input( INPUT_POST, 'cart_sync_currencies', FILTER_SANITIZE_NUMBER_INT ) ); 
  28.  
  29. $woocommerce_wpml->update_settings(); 
  30.  
  31. $new_value = $wcml_file_path_sync == 0 ? 2 :$wcml_file_path_sync; 
  32. $sitepress_settings['translation-management']['custom_fields_translation']['_downloadable_files'] = $new_value; 
  33. $sitepress_settings['translation-management']['custom_fields_translation']['_file_paths'] = $new_value; 
  34.  
  35. $sitepress->save_settings($sitepress_settings); 
  36.  
  37. $message = array( 
  38. 'id' => 'wcml-settings-saved',  
  39. 'text' => __('Your settings have been saved.', 'woocommerce-multilingual' ),  
  40. 'group' => 'wcml-settings',  
  41. 'admin_notice' => true,  
  42. 'limit_to_page' => true,  
  43. 'classes' => array('updated', 'notice', 'notice-success'),  
  44. 'show_once' => true 
  45. ); 
  46. ICL_AdminNotifier::add_message( $message ); 
  47.  
  48. if( isset( $_GET[ 'wcml_action' ] ) ) { 
  49. if( $_GET['wcml_action'] == 'dismiss' ) { 
  50. $woocommerce_wpml->settings['dismiss_doc_main'] = 1; 
  51. }elseif( $_GET['wcml_action'] == 'dismiss_tm_warning' ) { 
  52. $woocommerce_wpml->settings['dismiss_tm_warning'] = 1; 
  53. $woocommerce_wpml->update_settings(); 
  54.  
  55. add_action('wp_ajax_wcml_ignore_warning', array( $this, 'update_settings_from_warning') ); 
  56.  
  57. // Override cached widget id 
  58. add_filter( 'woocommerce_cached_widget_id', array( $this, 'override_cached_widget_id' ) ); 
  59.  
  60. function update_settings_from_warning() { 
  61. $nonce = filter_input( INPUT_POST, 'wcml_nonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); 
  62. if(!$nonce || !wp_verify_nonce($nonce, 'wcml_ignore_warning')) { 
  63. die('Invalid nonce'); 
  64. global $woocommerce_wpml; 
  65.  
  66. $woocommerce_wpml->settings[$_POST['setting']] = 1; 
  67. $woocommerce_wpml->update_settings(); 
  68.  
  69.  
  70. public function override_cached_widget_id( $widget_id ) { 
  71.  
  72. if( defined( 'ICL_LANGUAGE_CODE' ) ) { 
  73. $widget_id .= ':' . ICL_LANGUAGE_CODE; 
  74.  
  75. return $widget_id; 
  76.