PluginProbe
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster / 1.2.1
SellKit – Funnel builder and checkout optimizer for WooCommerce to sell more, faster v1.2.1
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 1.2.1, at includes/admin/settings/class-settings.php

174 lines 3.8 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
68 wp_send_json_success( __( 'The update process has been completed.', 'sellkit' ) );
69 }
70
71 /**
72 * Gets sellkit Settings.
73 *
74 * @since 1.1.0
75 */
76 public function get_settings() {
77 check_ajax_referer( 'sellkit', 'nonce' );
78
79 $options = get_option( 'sellkit', [] );
80
81 wp_send_json_success( $options );
82 }
83
84 /**
85 * Update Sellkit options.
86 *
87 * @since 1.1.0
88 * @return bool
89 * @param string $option Option.
90 * @param string $value String.
91 */
92 public function sellkit_update_option( $option, $value ) {
93 $options = get_option( 'sellkit', [] );
94
95 // No need to update the same value.
96 if ( isset( $options[ $option ] ) && $value === $options[ $option ] ) {
97 return false;
98 }
99
100 // Update the option.
101 $options[ $option ] = $value;
102
103 update_option( 'sellkit', $options );
104
105 return true;
106 }
107
108 /**
109 * Removes content box.
110 *
111 * @since 1.1.0
112 */
113 public function remove_content_box() {
114 $new_content_box_id = sellkit_htmlspecialchars( INPUT_POST, 'content_box_id' );
115 $removed_content_box_data = sellkit_get_option( 'removed_content_box_data' );
116 $removed_content_box_data = empty( $removed_content_box_data ) ? [] : $removed_content_box_data;
117 $new_removed_content_box_data = array_merge( $removed_content_box_data, [ $new_content_box_id ] );
118
119 sellkit_update_option( 'removed_content_box_data', array_unique( $new_removed_content_box_data ) );
120 }
121
122 /**
123 * Gets removed content box.
124 *
125 * @since 1.1.0
126 * @return array|bool|mixed
127 */
128 public static function get_removed_content_box() {
129 $removed_content_boxes = sellkit_get_option( 'removed_content_box_data' );
130
131 return ! empty( $removed_content_boxes ) ? $removed_content_boxes : [];
132 }
133
134 /**
135 * Gets Elementor templates for sellkit settings to set empty cart template.
136 *
137 * @since 1.1.0
138 * @return void
139 */
140 public function get_templates() {
141 check_ajax_referer( 'sellkit', 'nonce' );
142
143 $input = filter_input( INPUT_GET, 'input_value', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
144
145 if ( empty( $input ) ) {
146 wp_send_json_error();
147 }
148
149 $filtered_templates = [];
150 $args = [
151 'post_type' => 'elementor_library',
152 'post_status' => 'publish',
153 's' => $input,
154 'posts_per_page' => 20,
155 ];
156
157 $query = new \WP_Query( $args );
158
159 if ( $query->have_posts() ) {
160 while ( $query->have_posts() ) {
161 $query->the_post();
162 $filtered_templates[] = [
163 'label' => html_entity_decode( get_the_title() ),
164 'value' => get_the_ID(),
165 ];
166 }
167 }
168
169 wp_send_json_success( $filtered_templates );
170 }
171 }
172
173 Sellkit_Admin_Settings::get_instance();
174