PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 3.1.13
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v3.1.13
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 / Helpers / Expression.php

Expression.php in FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment 3.1.13, at Inc/Core/Helpers/Expression.php

95 lines 2.3 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 3.1.13 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2026 FirePlugins All Rights Reserved
9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 */
11
12 namespace FireBox\Core\Helpers;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 /**
20 * Gatekeeper for the {fbExpr ...} shortcode, which evaluates JavaScript from campaign
21 * content in the visitor's browser.
22 *
23 * "{fbExpr ...}" is plain text, so kses passes it through untouched — it is the one way a
24 * user without unfiltered_html could smuggle executable JavaScript into a campaign. The
25 * feature is therefore limited to campaigns whose author holds that capability, which is
26 * the same bar WordPress applies to writing raw script anywhere else.
27 *
28 * The check is deliberately a plain function of the post author, with no stored state:
29 * an earlier version recorded the decision at save time and that machinery twice grew
30 * bugs of its own. The trade is documented — see docs/audits/security-audit.md F10.
31 */
32 class Expression
33 {
34 /**
35 * Marker that switches the feature on for a campaign.
36 *
37 * @var string
38 */
39 const SHORTCODE_PREFIX = '{fbExpr';
40
41 /**
42 * Returns whether the given campaign may run expressions.
43 *
44 * @param int $post_id
45 * @param string $content
46 *
47 * @return bool
48 */
49 public static function isAllowedForCampaign($post_id, $content = '')
50 {
51 // Nothing to run.
52 if (!is_string($content) || strpos($content, self::SHORTCODE_PREFIX) === false)
53 {
54 return false;
55 }
56
57 if (!self::isFeatureEnabled())
58 {
59 return false;
60 }
61
62 $post_id = (int) $post_id;
63
64 if (!$post_id)
65 {
66 return false;
67 }
68
69 $author_id = (int) get_post_field('post_author', $post_id);
70
71 if (!$author_id)
72 {
73 return false;
74 }
75
76 return user_can($author_id, 'unfiltered_html');
77 }
78
79 /**
80 * Whether the feature is enabled site-wide.
81 *
82 * @return bool
83 */
84 public static function isFeatureEnabled()
85 {
86 /**
87 * Allows a site to switch off JavaScript expressions entirely, regardless of who
88 * authored the campaign.
89 *
90 * @param bool $enabled
91 */
92 return (bool) apply_filters('firebox/expressions/enabled', true);
93 }
94 }
95