userSettings = new UserSettings(); } public function settingsPage() { $settings = new SettingsController(); wp_enqueue_script('jquery'); wp_enqueue_script('jquery-ui-sortable'); wp_enqueue_style('barcode_lp_settings', Variables::$A4B_PLUGIN_BASE_URL . '/src/templates/settings/assets/css/index.css'); wp_enqueue_script('barcode_lp_settings', Variables::$A4B_PLUGIN_BASE_URL . '/src/templates/settings/assets/js/index-4.0.3-1793007717960.js', array('jquery'), null, true); wp_enqueue_style('barcode_lp_chosen', Variables::$A4B_PLUGIN_BASE_URL . 'assets/chosen/css/chosen.min.css', array(), false); wp_enqueue_script('barcode_lp_chosen', Variables::$A4B_PLUGIN_BASE_URL . 'assets/chosen/js/chosen.jquery.min.js', array('jquery'), false, true); $tab = isset($_GET["tab"]) ? sanitize_key(wp_unslash($_GET["tab"])) : "general"; if (!in_array($tab, array('general', 'buttons', 'profiles'), true)) { $tab = 'general'; } require_once Variables::$A4B_PLUGIN_BASE_PATH . "src/templates/settings/index.php"; } public function formSubmitted() { check_admin_referer('wp_rest', 'nonce'); if (!current_user_can('manage_options')) { wp_die( esc_html__('You are not allowed to perform this action.', 'a4-barcode-generator'), esc_html__('Permission denied', 'a4-barcode-generator'), ['response' => 403] ); } try { $data = array(); foreach (array( 'clearProfileLabels', 'lwhFormat', 'cfPriority', 'attrPriority', 'disableCreationOrderItems', 'settings-type', 'wizardCompleted', 'role', 'default_product_profile', 'default_order_profile', 'default_user_profile', 'showOnlyOwnedByUserProfiles', 'doNotAllowToEditProfiles', 'permissions', ) as $key) { if (isset($_POST[$key])) { $data[$key] = uslp_a4bRecursiveSanitizeTextField($_POST[$key]); } } foreach ($data as $key => $value) { if (in_array($key, array("excludedProdStatuses")) && is_array($data[$key])) { $value = implode(",", $value); } if ('permissions' === $key) { (new ProfilesPermissions())->saveGrouped($value); } else { $this->userSettings->save($key, $value); } } if (isset($data["tab"])) { $this->activeTab = $data["tab"]; } $tab = isset($_POST["tab"]) ? "&tab=" . sanitize_text_field($_POST["tab"]) : ""; wp_safe_redirect(admin_url('/admin.php?page=uslp-label-printing-settings' . $tab)); exit(); } catch (\Throwable $th) { } } public function wizardReset() { check_admin_referer('wp_rest', 'nonce'); if (!current_user_can('manage_options')) { wp_die( esc_html__('You are not allowed to perform this action.', 'a4-barcode-generator'), esc_html__('Permission denied', 'a4-barcode-generator'), ['response' => 403] ); } $this->userSettings->save("wizardCompleted", 0, null); wp_safe_redirect(admin_url('/admin.php?page=uslp-label-printing-settings')); exit(); } public function updateUserSettings() { Request::checkNonce(); if (!current_user_can('read')) { wp_die(); } $post = Request::getData(); $data = array(); foreach (array( 'useStockQuantity', 'copies', 'importShowMatchingForm', 'wizardCompleted', 'bsPrintCounter', ) as $key) { if (isset($post[$key])) { $data[$key] = sanitize_text_field($post[$key]); } } $productIds = array(); if (!empty($data['wizardCompleted'])) { $this->userSettings->save('wizardCompleted', 1, null); unset($data['wizardCompleted']); $productIds = get_posts( array( 'post_type' => 'product', 'posts_per_page' => 2, 'orderby' => 'date', 'order' => 'DESC', 'fields' => 'ids', ) ); } foreach ($data as $param => $value) { if (is_array($value)) { $value = json_encode($value); } $this->userSettings->save($param, $value, get_current_user_id()); } return array( "success" => true, "userSettings" => UserSettingsHelper::get(), "generalSettings" => UserSettingsHelper::getGeneral(true), "autoGeneratedIds" => $productIds ); } public function saveSession() { Request::checkNonce(); if (!current_user_can('read')) { wp_die(); } $post = Request::getData(); if (isset($post['session'])) { $session = sanitize_key($post['session']); } if (isset($post['sessionStamp'])) { $sessionStamp = sanitize_text_field($post['sessionStamp']); } if (empty($session) || empty($sessionStamp)) { return array("success" => false); } $this->userSettings->save("session", $session); $this->userSettings->save("sessionStamp", $sessionStamp); return array("status" => "success"); } }