PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / trunk
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment vtrunk
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 / Framework / Inc / Base / Conditions / PluginBase.php

PluginBase.php in FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment trunk, at Inc/Framework/Inc/Base/Conditions/PluginBase.php

223 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package FirePlugins Framework
4 * @version 1.2.5
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 FPFramework\Base\Conditions;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 use FPFramework\Base\Functions;
20 use FPFramework\Libs\Registry;
21 use FPFramework\Helpers\StringHelper;
22
23 abstract class PluginBase extends Condition
24 {
25 /**
26 * Category/Taxonomy.
27 *
28 * @var string
29 */
30 protected $taxonomy = null;
31
32 /**
33 * The component's Single Page view name
34 *
35 * @var string
36 */
37 protected $postTypeSingle = 'post';
38
39 protected $request = [];
40
41 /**
42 * Class constructor
43 *
44 * @param array $options The rule options. Expected properties: selection, value, params
45 * @param object $factory The framework's factory class.
46 */
47 public function __construct($options = null, $factory = null)
48 {
49 parent::__construct($options, $factory);
50
51 $this->request = $this->getRequest();
52 }
53
54 private function getRequest()
55 {
56 $object = get_queried_object();
57
58 $request = new \stdClass;
59
60 $request->id = $object instanceof \WP_Term ? (int) $object->term_id : ($object instanceof \WP_Post ? (int) $object->ID : null);
61 $request->post_type = isset($object->post_type) ? $object->post_type : null;
62 $request->taxonomy = $object && $object instanceof \WP_Term ? $object->taxonomy : null;
63
64 return $request;
65 }
66 /**
67 * Base assignment check
68 *
69 * @return bool
70 */
71 public function pass()
72 {
73 return $this->passByOperator();
74 }
75
76 /**
77 * Indicates whether the current view concerncs a Single Page view
78 *
79 * @return boolean
80 */
81 public function isSinglePage()
82 {
83 return ($this->request->post_type === $this->postTypeSingle);
84 }
85
86 /**
87 * Indicates whether the current view concerns a Category view
88 *
89 * @return boolean
90 */
91 protected function isCategoryPage()
92 {
93 return $this->request->taxonomy === $this->taxonomy;
94 }
95
96 /**
97 * Check whether this page passes the validation
98 *
99 * @return bool
100 */
101 protected function passSinglePage()
102 {
103 if (empty($this->selection) || !$this->isSinglePage())
104 {
105 return false;
106 }
107
108 if (!is_array($this->selection))
109 {
110 $this->selection = Functions::makeArray($this->selection);
111 }
112
113 return $this->passByOperator();
114 }
115
116 /**
117 * Checks whether the current page is within the selected categories
118 *
119 * @return boolean
120 */
121 protected function passCategories()
122 {
123 if (empty($this->selection))
124 {
125 return false;
126 }
127
128 // Include Children switch: 0 = No, 1 = Yes, 2 = Child Only
129 $inc_children = $this->params->get('inc_children');
130
131 // Setup supported views
132 $view_single = $this->params->get('view_single', true);
133 $view_category = $this->params->get('view_category', false);
134
135 // Check if we are in a valid context
136 if (!($view_category && $this->isCategoryPage()) && !($view_single && $this->isSinglePage()))
137 {
138 return false;
139 }
140
141 // Start Checks
142 $pass = false;
143
144 // Get current page assosiated category IDs. It can be a single ID of the current Category view or multiple IDs assosiated to active item.
145 $catids = $this->getCategoryIds();
146 $catids = is_array($catids) ? $catids : (array) $catids;
147
148 foreach ($catids as $catid)
149 {
150 $pass = in_array($catid, $this->selection);
151
152 if ($pass)
153 {
154 // If inc_children is either disabled or set to 'Also on Childs', there's no need for further checks.
155 // The condition is already passed.
156 if (in_array($this->params->get('inc_children'), [0, 1]))
157 {
158 break;
159 }
160
161 // We are here because we need childs only. Disable pass and continue checking parent IDs.
162 $pass = false;
163 }
164
165 // Pass check for child items
166 if (!$pass && $this->params->get('inc_children'))
167 {
168 // Get parent categories
169 $parent_ids = get_ancestors($catid, $this->taxonomy);
170
171 foreach ($parent_ids as $id)
172 {
173 if (in_array($id, $this->selection))
174 {
175 $pass = true;
176 break 2;
177 }
178 }
179
180 unset($parent_ids);
181 }
182 }
183
184 return $pass;
185 }
186
187 /**
188 * Returns category IDs based
189 *
190 * @return array
191 */
192 protected function getCategoryIDs()
193 {
194 $id = $this->request->id;
195
196 // Make sure we have an ID.
197 if (empty($id))
198 {
199 return;
200 }
201
202 // If this is a Category page, return the Category ID from the Query String
203 if ($this->isCategoryPage())
204 {
205 return (array) $id;
206 }
207
208 // If this is a Single Page, return all assosiated Category IDs.
209 if ($this->isSinglePage())
210 {
211 return $this->getSinglePageCategories($id);
212 }
213 }
214
215 /**
216 * Get single page's assosiated categories
217 *
218 * @param Integer The Single Page id
219 *
220 * @return array
221 */
222 abstract protected function getSinglePageCategories($id);
223 }