PluginProbe ʕ •ᴥ•ʔ
Spider Elements – Premium Elementor Widgets & Addons Library / trunk
Spider Elements – Premium Elementor Widgets & Addons Library vtrunk
trunk 1.0.0 1.1.0 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.7.0 1.8.0 1.9.0
spider-elements / includes / filters.php
spider-elements / includes Last commit date
Admin 1 month ago Frontend 4 months ago freemius 4 months ago filters.php 1 month ago functions.php 1 month ago
filters.php
197 lines
1 <?php
2 /**
3 * Plugin Filters and Actions
4 *
5 * This file handles various hooks, including image sizes, constants,
6 * and admin form submissions.
7 *
8 * @package SpiderElements
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly
13 }
14
15 add_image_size( 'spel_270x152', 270, 152, true ); // Video Playlist Thumb
16
17 /**
18 * Constants for the widget badge
19 */
20 add_action( 'after_setup_theme', function () {
21
22 if ( ! defined( 'SPEL_TEXT_BADGE' ) ) {
23 define( 'SPEL_TEXT_BADGE',
24 '<span class="spe-text-badge-control">' . esc_html__( 'SPIDER', 'spider-elements' ) . '</span>'
25 );
26 }
27
28 if ( ! defined( 'SPEL_PRO_BADGE' ) ) {
29 define( 'SPEL_PRO_BADGE',
30 '<span class="spel-pro-badge-control">' . esc_html__( 'PRO', 'spider-elements' ) . '</span>'
31 );
32 }
33
34 }, 20 );
35
36
37 /**
38 * Handle Element Settings Form Submission
39 */
40 add_action( 'admin_init', function () {
41
42 // Retrieve the field values from the form
43 if ( isset( $_POST['elements-submit'] ) ) {
44
45 // Verify nonce for security
46 if ( ! isset( $_POST['spel_elements_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['spel_elements_nonce'] ) ), 'spel_elements_nonce' ) ) {
47 return;
48 }
49
50 if ( ! current_user_can( 'manage_options' ) ) {
51 return;
52 }
53
54 // Free Widgets
55 $free_widgets = [
56 'spel_accordion',
57 'docy_testimonial',
58 'docly_list_item',
59 'docy_team_carousel',
60 'docy_integrations',
61 'docy_video_popup',
62 'docy_blog_grid',
63 'spe_timeline_widget',
64 'spe_counter',
65 'spel_icon_box',
66 ];
67
68 // Pro Widgets
69 $pro_widgets = [
70 'spel_accordion_article',
71 'docy_box_hover',
72 'spel_business_hours',
73 'spe_feature_box',
74 'docy_flip_box',
75 'docly_hotspot',
76 'docy_image_hover',
77 'docy_image_slides',
78 'spel_marquee_slider',
79 'spe_skill_showcase_widget',
80 'spel_stacked_image',
81 ];
82
83 // Docy Widgets
84 $docy_widgets = [
85 'docly_cheatsheet',
86 'spel_videos_playlist',
87 'docy_tabs',
88 'docly_alerts_box',
89 'spel_dynamic_faq',
90 ];
91
92 // Collect Free Widgets Values
93 $data = [];
94 foreach ( $free_widgets as $widget ) {
95 $data[ $widget ] = isset( $_POST[ $widget ] ) ? sanitize_text_field( $_POST[ $widget ] ) : '';
96 }
97
98 // Collect Pro Widgets Values
99 foreach ( $pro_widgets as $widget ) {
100 $data[ $widget ] = isset( $_POST[ $widget ] ) ? sanitize_text_field( $_POST[ $widget ] ) : '';
101 }
102
103 // Collect Docy Widgets Values
104 foreach ( $docy_widgets as $widget ) {
105 $data[ $widget ] = isset( $_POST[ $widget ] ) ? sanitize_text_field( $_POST[ $widget ] ) : '';
106 }
107
108 // Global Switcher
109 $data['element_global_switcher'] = isset( $_POST['element_global_switcher'] ) ? sanitize_text_field( $_POST['element_global_switcher'] ) : '';
110
111 // Save the data in the option table using update_option
112 update_option( 'spe_widget_settings', $data );
113
114 // If the user is not on a pro plan, reset pro-widgets
115 if ( ! spel_is_premium() ) {
116 foreach ( $pro_widgets as $widget ) {
117 $data[ $widget ] = 'off';
118 }
119 update_option( 'spe_widget_settings', $data );
120 }
121
122 // If the user is not on a pro-plan or Docy theme, reset pro-widgets
123 $is_premium_or_theme = spel_unlock_docy_theme();
124 if ( ! $is_premium_or_theme ) {
125 foreach ( $docy_widgets as $widget ) {
126 $data[ $widget ] = 'off';
127 }
128 update_option( 'spe_widget_settings', $data );
129 }
130 }
131
132 } );
133
134
135 /**
136 * Handle Features Settings Form Submission
137 */
138 add_action( 'admin_init', function () {
139
140 if ( isset( $_POST['features-submit'] ) ) {
141
142 // Verify nonce for security
143 if ( ! isset( $_POST['spel_features_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['spel_features_nonce'] ) ), 'spel_features_nonce' ) ) {
144 return;
145 }
146
147 if ( ! current_user_can( 'manage_options' ) ) {
148 return;
149 }
150
151 // Pro Widgets
152 $pro_features = [
153 'spel_badge',
154 'spel_reveal_animation',
155 'spel_heading_highlighted',
156 'spel_feature_box',
157 'spel_smooth_animation',
158 ];
159
160 $data = get_option( 'spel_features_settings', [] );
161
162 // Collect Pro Features Values
163 foreach ( $pro_features as $feature ) {
164 $data[ $feature ] = isset( $_POST[ $feature ] ) ? sanitize_text_field( $_POST[ $feature ] ) : '';
165 }
166
167 // Global Switcher
168 $data['features_global_switcher'] = isset( $_POST['features_global_switcher'] ) ? sanitize_text_field( $_POST['features_global_switcher'] ) : '';
169
170 // Save the data in the option table using update_option
171 update_option( 'spel_features_settings', $data );
172
173 // If the user is not on a pro-plan or Jobi theme, reset pro-features
174 $theme = wp_get_theme();
175 $theme_name = $theme->get( 'Name' );
176 $is_premium_or_theme = spel_is_premium() || in_array( $theme_name, [ 'jobi', 'Jobi', 'jobi-child', 'Jobi Child' ], true );
177
178 // Smooth Animation is unlocked for Docy, Jobi, Docly, or Ama theme users
179 $is_smooth_anim_unlocked = spel_unlock_docy_theme()
180 || in_array( $theme_name, [ 'jobi', 'Jobi', 'jobi-child', 'Jobi Child' ], true )
181 || in_array( $theme_name, [ 'Docly', 'docly', 'Docly Child', 'docly-child' ], true )
182 || in_array( $theme_name, [ 'Ama', 'ama', 'Ama Child', 'ama-child' ], true );
183
184 if ( ! $is_premium_or_theme ) {
185 foreach ( $pro_features as $feature ) {
186 // Keep Smooth Animation enabled for Docy, Jobi, or Docly theme users
187 if ( $feature === 'spel_smooth_animation' && $is_smooth_anim_unlocked ) {
188 continue;
189 }
190 $data[ $feature ] = 'off';
191 }
192 update_option( 'spel_features_settings', $data );
193 }
194 }
195
196 } );
197