PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 2.1.23
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v2.1.23
3.1.13 3.1.12 3.1.11 3.1.10 3.1.9 3.1.8 3.1.7 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 All 122 releases
firebox / Inc / Core / Admin / Includes / Cpts / Firebox.php

Firebox.php in FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment 2.1.23, at Inc/Core/Admin/Includes/Cpts/Firebox.php

382 lines 7.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package FireBox
4 * @version 2.1.23 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2024 FirePlugins All Rights Reserved
9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 */
11
12 namespace FireBox\Core\Admin\Includes\Cpts;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 use FPFramework\Libs\Cpt;
20 use FireBox\Core\Helpers\BoxHelper;
21
22 class Firebox extends Cpt
23 {
24 public $singular;
25 public $plural;
26
27 public function __construct()
28 {
29 $this->singular = firebox()->_('FB_FIREBOX_CAMPAIGN');
30 $this->plural = firebox()->_('FB_FIREBOX_CAMPAIGNS');
31
32 parent::__construct($this->getPayload());
33
34 $this->init();
35 }
36
37 public function init()
38 {
39 add_action('admin_init', [$this, 'custom_post_edit_redirect']);
40
41 // load dependencies
42 $this->initDependencies();
43
44 // set default post title
45 add_filter('default_title', [$this, 'set_default_campaign_title'], 10, 2);
46
47 // handle box duplication
48 add_action('admin_action_fb_duplicate_post_as_draft', [$this, 'handle_box_duplication']);
49
50 // handle box cookie clear
51 add_action('admin_action_fb_clear_cookie', [$this, 'handle_box_cookie_clear']);
52
53 // delete hook for FireBox
54 add_action('delete_post', [$this, 'before_delete_firebox_callback']);
55
56 add_action('load-firebox_page_firebox-campaigns', [$this, 'handle_bulk_actions']);
57
58 add_filter('fpframework/metabox/after_filter', [$this, 'after_save'], 10, 3);
59
60 add_filter('the_content', [$this, 'prepareContent'], 0);
61
62 // Exclude FireBox from sitemaps
63 add_filter('wp_sitemaps_post_types', [$this, 'remove_post_type_from_wp_sitemap']);
64 add_filter('wpseo_sitemap_exclude_post_type', [$this, 'yoastseo_exclude_post_type'], 10, 2 );
65 }
66
67 /**
68 * Exclude FireBox from Yoast SEO sitemaps
69 *
70 * @param bool $value
71 * @param string $post_type
72 *
73 * @return bool
74 */
75 public function yoastseo_exclude_post_type($value, $post_type)
76 {
77 $post_type_to_exclude = [
78 'firebox'
79 ];
80
81 if (in_array($post_type, $post_type_to_exclude))
82 {
83 $value = true;
84 }
85
86 return $value;
87 }
88
89 /**
90 * Remove thw wptexturize filter as it replaces double dashes with em dash.
91 *
92 * @param string $content
93 *
94 * @return string
95 */
96 public function prepareContent($content)
97 {
98 global $post;
99
100 if (!$post instanceof \WP_Post)
101 {
102 return $content;
103 }
104
105 // Check if the current post type is 'firebox'
106 if ($post->post_type === 'firebox')
107 {
108 remove_filter('the_content', 'wptexturize');
109 }
110
111 return $content;
112 }
113
114 /**
115 * Remove the FireBox custom post type from the sitemap.
116 *
117 * This is not needed as published FireBox campaigns are not public.
118 *
119 * @param array $cpts
120 *
121 * @return array
122 */
123 public function remove_post_type_from_wp_sitemap($cpts)
124 {
125 if (isset($cpts['firebox']))
126 {
127 unset($cpts['firebox']);
128 }
129
130 return $cpts;
131 }
132
133 /**
134 * When going to edit.php?post_type=firebox, then
135 * redirect to: admin.php?page=firebox-campaigns
136 *
137 * @return void
138 */
139 function custom_post_edit_redirect()
140 {
141 global $pagenow;
142 if ($pagenow !== 'post-new.php' && isset($_GET['post_type']) && $_GET['post_type'] === 'firebox') //phpcs:ignore WordPress.Security.NonceVerification.Recommended
143 {
144 wp_redirect(admin_url('admin.php?page=firebox-campaigns'));
145 exit;
146 }
147 }
148
149 public function handle_bulk_actions()
150 {
151 if (empty($_GET))
152 {
153 return;
154 }
155
156 $action = isset($_GET['action']) ? sanitize_key($_GET['action']) : false;
157 if (!$action)
158 {
159 return;
160 }
161
162 if ($action !== 'fb_export')
163 {
164 return;
165 }
166
167 // Ensure we have IDs
168 $ids = isset($_GET['id']) ? array_map('intval', $_GET['id']) : [];
169 if (!$ids)
170 {
171 return;
172 }
173
174 // Get nonce
175 $nonce = isset($_GET['_wpnonce']) ? sanitize_text_field(wp_unslash($_GET['_wpnonce'])) : '';
176 if (!$nonce)
177 {
178 return;
179 }
180
181 // Verify nonce
182 $nonce_action = 'bulk-fireboxes';
183 if (!wp_verify_nonce($nonce, $nonce_action))
184 {
185 return;
186 }
187
188 BoxHelper::exportBoxes($ids);
189 \FPFramework\Libs\AdminNotice::displaySuccess(sprintf(firebox()->_('FB_X_CAMPAIGNS_HAVE_BEEN_EXPORTED'), count($ids)));
190 }
191
192 public function set_default_campaign_title($post_title, $post)
193 {
194 if (!isset($post->post_type))
195 {
196 return $post_title;
197 }
198
199 if ($post->post_type !== 'firebox')
200 {
201 return $post_title;
202 }
203
204 if (empty(trim($post_title)))
205 {
206 $post_title = firebox()->_('FB_UNTITLED_CAMPAIGN');
207 }
208
209 return $post_title;
210 }
211
212 /**
213 * Prepare conditions after save.
214 *
215 * @param array $fields
216 * @param int $post_id
217 * @param string $cpt
218 *
219 * @return array
220 */
221 public function after_save($fields, $post_id, $cpt)
222 {
223 if ($cpt !== 'firebox')
224 {
225 return $fields;
226 }
227
228
229
230 \FPFramework\Libs\Cache::invalidate();
231
232 return $fields;
233 }
234
235 /**
236 * Load dependencies
237 *
238 * @return void
239 */
240 private function initDependencies()
241 {
242 new FireBox\AddFireBoxButtonAboveEditor();
243 new FireBox\TinyMCEButton();
244 new FireBox\SmartTagsCPTButton();
245
246 }
247
248 /**
249 * Before deleting the FireBox, delete its box logs and box logs details data
250 *
251 * @param int $ID
252 *
253 * @return void
254 */
255 public function before_delete_firebox_callback($ID)
256 {
257 $post = get_post($ID);
258
259 if (!$post)
260 {
261 return;
262 }
263
264 if ($post->post_type !== 'firebox')
265 {
266 return;
267 }
268
269 $logs_table = firebox()->tables->boxlog->getFullTableName();
270 $logs_details_table = firebox()->tables->boxlogdetails->getFullTableName();
271
272 // Get all popup forms
273 $forms = \FPFramework\Helpers\Plugins\FireBox\Form::getCampaignForms($ID);
274
275 // delete logs details
276 firebox()->tables->boxlogdetails->executeRaw("DELETE FROM `$logs_details_table` WHERE log_id IN (SELECT id FROM `$logs_table` WHERE box = %d)", [$ID]);
277
278 // delete logs
279 firebox()->tables->boxlog->delete([
280 'box' => $ID
281 ]);
282
283 if ($forms)
284 {
285 foreach ($forms as $form_id => $form_label)
286 {
287 global $wpdb;
288
289 // Delete submission meta records first
290 $wpdb->query(
291 $wpdb->prepare(
292 "DELETE sm
293 FROM {$wpdb->prefix}firebox_submission_meta AS sm
294 INNER JOIN {$wpdb->prefix}firebox_submissions AS s ON sm.submission_id = s.id
295 WHERE s.form_id = %s"
296 ,
297 $form_id
298 )
299 );
300
301 // Delete submissions
302 $wpdb->delete("{$wpdb->prefix}firebox_submissions", ['form_id' => $form_id]);
303 }
304 }
305 }
306
307 /**
308 * Handles Box duplication
309 *
310 * @return void
311 */
312 public function handle_box_duplication()
313 {
314 check_admin_referer('duplicate-firebox-campaign');
315
316 $post_id = isset($_GET['post']) ? intval($_GET['post']) : '';
317
318 $redirect_url = admin_url() . 'admin.php?page=firebox-campaigns';
319
320 if (empty($post_id))
321 {
322 wp_redirect($redirect_url);
323 exit();
324 }
325
326 BoxHelper::duplicateBox($post_id);
327
328 \FPFramework\Libs\AdminNotice::displaySuccess(firebox()->_('FB_CAMPAIGN_DUPLICATED'));
329
330 // redirect back to box list
331 wp_redirect($redirect_url);
332 }
333
334 /**
335 * Clears cookie from box
336 *
337 * @return void
338 */
339 public function handle_box_cookie_clear()
340 {
341 check_admin_referer('clearcookie-firebox-campaign');
342
343 $post_id = isset($_GET['post']) ? intval($_GET['post']) : '';
344
345 $redirect_url = admin_url() . 'admin.php?page=firebox-campaigns';
346
347 if (empty($post_id))
348 {
349 wp_redirect($redirect_url);
350 exit();
351 }
352
353 $cookie = new \FireBox\Core\FB\Cookie(firebox()->box->get($post_id));
354 $cookie->remove();
355
356 // redirect back to box list
357 wp_redirect($redirect_url);
358 }
359
360 /**
361 * Returns CPT payload
362 *
363 * @return array
364 */
365 protected function getPayload()
366 {
367 return [
368 'label_name' => firebox()->_('FB_PLUGIN_NAME'),
369 'singular' => $this->singular,
370 'label' => firebox()->_('FB_PLUGIN_NAME'),
371 'plural' => $this->plural,
372 'name' => 'firebox',
373 'slug' => 'firebox',
374 'has_archive' => false,
375 'show_in_menu' => false,
376 'is_public' => true,
377 'exclude_from_search' => true,
378 'supports' => ['title', 'editor'],
379 'capability_type' => ['firebox', 'fireboxes']
380 ];
381 }
382 }