PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 1.1.0
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v1.1.0
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 / Admin.php

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

285 lines 5.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 1.1.0 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2022 FirePlugins All Rights Reserved
9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 */
11
12 namespace FireBox\Core\Admin;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 class Admin
20 {
21 /**
22 * Admin Page Settings
23 *
24 * @var AdminPageSettings
25 */
26 private $pageSettings;
27
28 /**
29 * Library
30 *
31 * @var Library
32 */
33 public $library;
34
35 /**
36 * Admin constructor
37 */
38 public function __construct()
39 {
40 // init dependencies
41 $this->initDependencies();
42
43 // Admin Page Settings
44 $this->pageSettings = new AdminPageSettings();
45
46 // run actions
47 $this->handleActions();
48
49 // run filters
50 $this->handleFilters();
51 }
52
53 /**
54 * Load admin dependencies.
55 *
56 * @return void
57 */
58 private function initDependencies()
59 {
60 new Media();
61
62 $this->library = firebox()->library;
63
64 // Update Notice
65 $valid_pages = [
66 'firebox',
67 'firebox-analytics',
68 'firebox-import',
69 'firebox-settings'
70 ];
71 $updateNotice = new \FPFramework\Admin\Includes\UpdateNotice(
72 firebox()->plugin_slug,
73 firebox()->plugin_name,
74 FBOX_VERSION,
75 $valid_pages
76 );
77 $updateNotice->init();
78
79 // Top Bar Navigation
80 new Includes\TopBarNavigation();
81
82 // Review Reminder
83 new \FPFramework\Admin\Includes\ReviewReminder(
84 firebox()->plugin_slug,
85 firebox()->plugin_name,
86 FBOX_MEDIA_ADMIN_URL
87 );
88 }
89
90 /**
91 * Runs all Admin Actions
92 *
93 * @return void
94 */
95 private function handleActions()
96 {
97 add_action('admin_enqueue_scripts', [$this, 'registerMedia'], 20);
98
99
100 add_action('plugin_action_links_' . plugin_basename(FBOX_PLUGIN_BASE_FILE), [$this, 'plugin_action_links']);
101
102 add_action('fpframework/admin/template/footer/nav_links', [$this, 'add_admin_page_template_footer_nav_links']);
103
104 }
105
106
107 /**
108 * Adds extra links to the Plugins page in the free version.
109 * - Upgrade to Pro button
110 *
111 * @param array $links
112 *
113 * @return array
114 */
115 public function plugin_action_links($links)
116 {
117 $links = array_merge( $links, array(
118 '<a href="' . FBOX_GO_PRO_URL . '" class="firebox-go-pro-link" title="' . fpframework()->_('FPF_UNLOCK_MORE_FEATURES_WITH_PRO_READ_MORE') . '">' . fpframework()->_('FPF_GO_PRO') . '</a>'
119 ) );
120
121 return $links;
122 }
123
124 /**
125 * Adds links to the admin template footer nav links
126 *
127 * @return void
128 */
129 public function add_admin_page_template_footer_nav_links()
130 {
131 ?>
132 <li><a href="https://www.fireplugins.com/<?php echo esc_attr(firebox()->plugin_slug); ?>" target="_blank"><?php echo esc_html(fpframework()->_('FPF_GET_PRO_FEATURES')); ?></a></li>
133 <?php
134 }
135
136
137 /**
138 * Runs all Admin Filters
139 *
140 * @return void
141 */
142 private function handleFilters()
143 {
144 add_filter('admin_body_class', [$this, 'setPluginPageBodyClass']);
145 }
146
147 /**
148 * Sets a class to the body of the FireBox Admin Pages
149 *
150 * @return string
151 */
152 public function setPluginPageBodyClass($classes)
153 {
154 if (!$this->isPluginPage())
155 {
156 return $classes;
157 }
158
159 $classes .= ' fpf-admin-page fpf-firebox-page';
160
161 if ($this->isControllerPage())
162 {
163 $classes .= ' fpf-controller-page';
164 }
165
166 return $classes;
167 }
168
169 /**
170 * Checks if we are in a plugin page
171 *
172 * @return boolean
173 */
174 private function isPluginPage()
175 {
176 if ($this->getPageNow() == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'firebox')
177 {
178 return true;
179 }
180
181 if ($this->getPageNow() == 'post.php')
182 {
183 return true;
184 }
185
186 if ($this->isControllerPage())
187 {
188 return true;
189 }
190
191 if (current_user_can('manage_options'))
192 {
193 return true;
194 }
195
196 return false;
197 }
198
199 /**
200 * Whether we are browsing a plugin page from the plugin's menu
201 *
202 * @return boolean
203 */
204 private function isControllerPage()
205 {
206 if (!firebox()->menu)
207 {
208 return false;
209 }
210
211 $current_plugin_page = fpframework()->getPluginPage();
212 $plugin_menu_items = firebox()->menu->getPluginMenuItems();
213
214 // Only set the class to the plugin pages
215 return $this->getPageNow() == 'admin.php' && in_array($current_plugin_page, $plugin_menu_items);
216 }
217
218 /**
219 * Returns page now
220 *
221 * @return string
222 */
223 protected function getPageNow()
224 {
225 global $pagenow;
226 return $pagenow;
227 }
228
229 /**
230 * Registers CSS and JS files
231 *
232 * @return void
233 */
234 public function registerMedia()
235 {
236 $this->registerStyles();
237 $this->registerScripts();
238 }
239
240 /**
241 * Register admin styles.
242 *
243 * @return void
244 */
245 public function registerStyles()
246 {
247 // load dashicons
248 wp_enqueue_style('dashicons');
249
250 // firebox main admin css
251 wp_register_style(
252 'firebox-admin',
253 FBOX_MEDIA_ADMIN_URL . 'css/firebox.css',
254 [],
255 FBOX_VERSION,
256 false
257 );
258 wp_enqueue_style('firebox-admin');
259
260 $css = '
261 :root {
262 --fpf-templates-library-header-logo: url(' . FBOX_MEDIA_ADMIN_URL . 'images/logo.svg);
263 }
264 ';
265 wp_add_inline_style('firebox-admin', $css);
266 }
267
268 /**
269 * Registers admin scripts.
270 *
271 * @return void
272 */
273 public function registerScripts()
274 {
275 wp_register_script('firebox-admin', false);
276 wp_enqueue_script('firebox-admin');
277
278 $data = array(
279 'media_url' => FBOX_MEDIA_URL,
280 'admin_url' => get_admin_url()
281 );
282
283 wp_localize_script('firebox-admin', 'fbox_admin_js_object', $data);
284 }
285 }