PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 2.3.0
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v2.3.0
2.6.0 trunk 1.1.0 1.1.4 1.2.1 1.2.2 1.2.3 1.2.5 1.2.9 1.3.1 1.3.2 1.5.0 1.5.1 1.5.4 1.5.7 1.5.8 1.5.9 1.6.2 1.6.5 1.6.8 1.7.2 1.7.4 1.7.5 1.7.9 1.8.1 All 42 releases
sellkit / includes / admin / settings / class-settings.php

class-settings.php in SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster 2.3.0, at includes/admin/settings/class-settings.php

186 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Sellkit\Admin\Settings;
4
5 defined( 'ABSPATH' ) || die();
6
7 /**
8 * Steps class.
9 *
10 * @since 1.1.0
11 */
12 class Sellkit_Admin_Settings {
13
14 /**
15 * Class instance.
16 *
17 * @since 1.1.0
18 * @var Sellkit_Admin_Settings
19 */
20 private static $instance = null;
21
22 /**
23 * Sellkit_Admin_Settings constructor.
24 *
25 * @since 1.1.0
26 */
27 public function __construct() {
28 add_action( 'wp_ajax_sellkit_save_settings', [ $this, 'save_settings' ] );
29 add_action( 'wp_ajax_sellkit_get_settings', [ $this, 'get_settings' ] );
30
31 add_action( 'wp_ajax_sellkit_remove_content_box', [ $this, 'remove_content_box' ] );
32
33 add_action( 'wp_ajax_sellkit_settings_get_templates', [ $this, 'get_templates' ] );
34 }
35
36 /**
37 * Get the class instance.
38 *
39 * @since 1.1.0
40 */
41 public static function get_instance() {
42 if ( null === self::$instance ) {
43 self::$instance = new self();
44 }
45
46 return self::$instance;
47 }
48
49 /**
50 * Saving Settings.
51 *
52 * @since 1.1.0
53 */
54 public function save_settings() {
55 check_ajax_referer( 'sellkit', 'nonce' );
56
57 $fields = sellkit_post( 'fields' );
58
59 if ( ! is_array( $fields ) ) {
60 wp_send_json_error( __( 'Somethings went wrong.', 'sellkit' ) );
61 }
62
63 foreach ( $fields as $option => $value ) {
64 $safe_value = ! is_array( $value ) ? sanitize_text_field( $value ) : $value;
65 $this->sellkit_update_option( $option, $safe_value );
66
67 if ( 'delete_data' === $option ) {
68 update_site_option( 'delete_data', $safe_value );
69 }
70
71 if ( 'funnel_permalink_base' === $option ) {
72 $permalink_base = empty( $safe_value ) ? 'sellkit_step' : $safe_value;
73
74 update_option( 'sellkit_funnel_permalink_base', $permalink_base );
75 }
76 }
77
78 wp_send_json_success( __( 'The update process has been completed.', 'sellkit' ) );
79 }
80
81 /**
82 * Gets sellkit Settings.
83 *
84 * @since 1.1.0
85 */
86 public function get_settings() {
87 check_ajax_referer( 'sellkit', 'nonce' );
88
89 $options = get_option( 'sellkit', [] );
90
91 wp_send_json_success( $options );
92 }
93
94 /**
95 * Update Sellkit options.
96 *
97 * @since 1.1.0
98 * @return bool
99 * @param string $option Option.
100 * @param string $value String.
101 */
102 public function sellkit_update_option( $option, $value ) {
103 $options = get_option( 'sellkit', [] );
104
105 // No need to update the same value.
106 if ( isset( $options[ $option ] ) && $value === $options[ $option ] ) {
107 return false;
108 }
109
110 // Update the option.
111 $options[ $option ] = $value;
112
113 update_option( 'sellkit', $options );
114
115 return true;
116 }
117
118 /**
119 * Removes content box.
120 *
121 * @since 1.1.0
122 */
123 public function remove_content_box() {
124 check_ajax_referer( 'sellkit', 'nonce' );
125
126 $new_content_box_id = sellkit_htmlspecialchars( INPUT_POST, 'content_box_id' );
127 $removed_content_box_data = sellkit_get_option( 'removed_content_box_data' );
128 $removed_content_box_data = empty( $removed_content_box_data ) ? [] : $removed_content_box_data;
129 $new_removed_content_box_data = array_merge( $removed_content_box_data, [ $new_content_box_id ] );
130
131 sellkit_update_option( 'removed_content_box_data', array_unique( $new_removed_content_box_data ) );
132 }
133
134 /**
135 * Gets removed content box.
136 *
137 * @since 1.1.0
138 * @return array|bool|mixed
139 */
140 public static function get_removed_content_box() {
141 $removed_content_boxes = sellkit_get_option( 'removed_content_box_data' );
142
143 return ! empty( $removed_content_boxes ) ? $removed_content_boxes : [];
144 }
145
146 /**
147 * Gets Elementor templates for sellkit settings to set empty cart template.
148 *
149 * @since 1.1.0
150 * @return void
151 */
152 public function get_templates() {
153 check_ajax_referer( 'sellkit', 'nonce' );
154
155 $input = filter_input( INPUT_GET, 'input_value', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
156
157 if ( empty( $input ) ) {
158 wp_send_json_error();
159 }
160
161 $filtered_templates = [];
162 $args = [
163 'post_type' => 'elementor_library',
164 'post_status' => 'publish',
165 's' => $input,
166 'posts_per_page' => 20,
167 ];
168
169 $query = new \WP_Query( $args );
170
171 if ( $query->have_posts() ) {
172 while ( $query->have_posts() ) {
173 $query->the_post();
174 $filtered_templates[] = [
175 'label' => html_entity_decode( get_the_title() ),
176 'value' => get_the_ID(),
177 ];
178 }
179 }
180
181 wp_send_json_success( $filtered_templates );
182 }
183 }
184
185 Sellkit_Admin_Settings::get_instance();
186