PluginProbe
Boxzilla – WordPress Popup Builder / 3.4.0
Boxzilla – WordPress Popup Builder v3.4.0
3.4.11 3.4.10 3.4.9 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 trunk 3.0 3.0.1 3.0.2 3.0.3 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 All 72 releases
← All changes | src/admin/class-admin.php +674 -688 3.4.73.4.0 View file →
@@ -7,819 +7,805 @@
7 7 use Boxzilla\Boxzilla;
8 8 use WP_Post;
9 9 use WP_Screen;
10 10
11 -class Admin
12 -{
13 - /**
14 - * @var Plugin $plugin
15 - */
16 - private $plugin;
11 +class Admin {
17 12
18 - /**
19 - * @var Boxzilla
20 - */
21 - protected $boxzilla;
22 13
23 - /**
24 - * @var ReviewNotice
25 - */
26 - protected $review_notice;
14 + /**
15 + * @var Plugin $plugin
16 + */
17 + private $plugin;
27 18
28 - /**
29 - * @param Plugin $plugin
30 - * @param Boxzilla $boxzilla
31 - */
32 - public function __construct(Plugin $plugin, Boxzilla $boxzilla)
33 - {
34 - $this->plugin = $plugin;
35 - $this->boxzilla = $boxzilla;
36 - $this->review_notice = new ReviewNotice();
37 - }
19 + /**
20 + * @var Boxzilla
21 + */
22 + protected $boxzilla;
38 23
39 - /**
40 - * Initialise the all admin related stuff
41 - */
42 - public function init()
43 - {
44 - $this->add_hooks();
45 - $this->run_migrations();
46 - $this->review_notice->init();
47 - }
24 + /**
25 + * @var ReviewNotice
26 + */
27 + protected $review_notice;
48 28
49 - /**
50 - * Add necessary hooks
51 - */
52 - protected function add_hooks()
53 - {
54 - add_action('admin_init', [ $this, 'lazy_add_hooks' ]);
55 - add_action('admin_init', [ $this, 'register' ]);
56 - add_action('init', [ $this, 'listen_for_actions' ]);
57 - add_action('admin_menu', [ $this, 'menu' ]);
58 - add_action('admin_notices', [ $this, 'notices' ]);
59 - add_action('save_post_boxzilla-box', [ $this, 'save_box_options' ], 20, 2);
60 - add_action('trashed_post', [ $this, 'flush_rules' ]);
61 - add_action('untrashed_post', [ $this, 'flush_rules' ]);
62 - add_filter('bulk_actions-edit-boxzilla-box', [ $this, 'bulk_action_add' ]);
63 - add_filter('handle_bulk_actions-edit-boxzilla-box', [ $this, 'bulk_action_handle' ], 10, 3);
64 - }
29 + /**
30 + * @param Plugin $plugin
31 + * @param Boxzilla $boxzilla
32 + */
33 + public function __construct( Plugin $plugin, Boxzilla $boxzilla ) {
34 + $this->plugin = $plugin;
35 + $this->boxzilla = $boxzilla;
36 + $this->review_notice = new ReviewNotice();
37 + }
65 38
66 - /**
67 - * Listen for admin actions.
68 - */
69 - public function listen_for_actions()
70 - {
71 - // triggered?
72 - $vars = array_merge($_POST, $_GET);
73 - if (empty($vars['_boxzilla_admin_action'])) {
74 - return false;
75 - }
39 + /**
40 + * Initialise the all admin related stuff
41 + */
42 + public function init() {
43 + $this->add_hooks();
44 + $this->run_migrations();
45 + $this->review_notice->init();
46 + }
76 47
77 - // authorized?
78 - if (! current_user_can('edit_posts')) {
79 - return false;
80 - }
48 + /**
49 + * Add necessary hooks
50 + */
51 + protected function add_hooks() {
52 + add_action( 'admin_init', array( $this, 'lazy_add_hooks' ) );
53 + add_action( 'admin_init', array( $this, 'register' ) );
54 + add_action( 'init', array( $this, 'listen_for_actions' ) );
55 + add_action( 'admin_menu', array( $this, 'menu' ) );
56 + add_action( 'admin_notices', array( $this, 'notices' ) );
57 + add_action( 'save_post_boxzilla-box', array( $this, 'save_box_options' ), 20, 2 );
58 + add_action( 'trashed_post', array( $this, 'flush_rules' ) );
59 + add_action( 'untrashed_post', array( $this, 'flush_rules' ) );
60 + add_filter( 'bulk_actions-edit-boxzilla-box', array( $this, 'bulk_action_add' ) );
61 + add_filter( 'handle_bulk_actions-edit-boxzilla-box', array( $this, 'bulk_action_handle' ), 10, 3 );
81 62
82 - // fire action
83 - $action = $vars['_boxzilla_admin_action'];
84 - do_action('boxzilla_admin_' . $action);
63 + }
85 64
86 - return true;
87 - }
65 + /**
66 + * Listen for admin actions.
67 + */
68 + public function listen_for_actions() {
69 + // triggered?
70 + $vars = array_merge( $_POST, $_GET );
71 + if ( empty( $vars['_boxzilla_admin_action'] ) ) {
72 + return false;
73 + }
88 74
89 - public function bulk_action_add($bulk_actions)
90 - {
91 - $bulk_actions['boxzilla_duplicate_box'] = esc_attr__('Duplicate box', 'boxzilla');
92 - return $bulk_actions;
93 - }
75 + // authorized?
76 + if ( ! current_user_can( 'edit_posts' ) ) {
77 + return false;
78 + }
94 79
95 - public function bulk_action_handle($redirect_to, $doaction, $post_ids)
96 - {
97 - if ($doaction !== 'boxzilla_duplicate_box' || empty($post_ids)) {
98 - return $redirect_to;
99 - }
80 + // fire action
81 + $action = $vars['_boxzilla_admin_action'];
82 + do_action( 'boxzilla_admin_' . $action );
100 83
101 - foreach ($post_ids as $post_id) {
102 - $post = get_post($post_id);
103 - if ($post->post_type !== 'boxzilla-box') {
104 - continue;
105 - }
84 + return true;
85 + }
106 86
107 - $new_post_id = wp_insert_post(
108 - [
109 - 'post_type' => $post->post_type,
110 - 'post_title' => $post->post_title,
111 - 'post_content' => $post->post_content,
112 - 'post_status' => 'draft',
113 - ]
114 - );
87 + public function bulk_action_add( $bulk_actions ) {
88 + $bulk_actions['boxzilla_duplicate_box'] = esc_attr__( 'Duplicate box', 'boxzilla' );
89 + return $bulk_actions;
90 + }
115 91
116 - $options = get_post_meta($post_id, 'boxzilla_options', true);
117 - add_post_meta($new_post_id, 'boxzilla_options', $options);
92 + public function bulk_action_handle( $redirect_to, $doaction, $post_ids ) {
93 + if ( $doaction !== 'boxzilla_duplicate_box' || empty( $post_ids ) ) {
94 + return $redirect_to;
95 + }
118 96
119 - $this->flush_rules($new_post_id);
120 - }
97 + foreach ( $post_ids as $post_id ) {
98 + $post = get_post( $post_id );
99 + if ( $post->post_type !== 'boxzilla-box' ) {
100 + continue;
101 + }
121 102
122 - return $redirect_to;
123 - }
103 + $new_post_id = wp_insert_post(
104 + array(
105 + 'post_type' => $post->post_type,
106 + 'post_title' => $post->post_title,
107 + 'post_content' => $post->post_content,
108 + 'post_status' => 'draft',
109 + )
110 + );
124 111
125 - /**
126 - * All logic for admin notices lives here.
127 - */
128 - public function notices()
129 - {
130 - global $pagenow,
131 - $current_screen;
112 + $options = get_post_meta( $post_id, 'boxzilla_options', true );
113 + add_post_meta( $new_post_id, 'boxzilla_options', $options );
132 114
133 - if (
134 - ( $pagenow === 'plugins.php' || ( $current_screen && $current_screen->post_type === 'boxzilla-box' ) )
135 - && current_user_can('install_plugins')
136 - && is_plugin_active('scroll-triggered-boxes/index.php')
137 - ) {
138 - ?>
139 - <div class="notice notice-info">
140 - <p><?php esc_html_e('Awesome, you are using Boxzilla! You can now safely deactivate the Scroll Triggered Boxes plugin.', 'boxzilla'); ?></p>
141 - </div>
142 - <?php
143 - }
144 - }
115 + $this->flush_rules( $new_post_id );
116 + }
145 117
146 - /**
147 - * Checks current version against stored version & runs necessary update routines.
148 - */
149 - protected function run_migrations()
150 - {
118 + return $redirect_to;
119 + }
151 120
152 - // Only run if db option is at older version than code constant
153 - $previous_version = get_option('boxzilla_version', '0');
154 - $current_version = $this->plugin->version();
121 + /**
122 + * All logic for admin notices lives here.
123 + */
124 + public function notices() {
125 + global $pagenow,
126 + $current_screen;
155 127
156 - if (version_compare($current_version, $previous_version, '<=')) {
157 - return;
158 - }
128 + if ( ( $pagenow === 'plugins.php' || ( $current_screen && $current_screen->post_type === 'boxzilla-box' ) )
129 + && current_user_can( 'install_plugins' )
130 + && is_plugin_active( 'scroll-triggered-boxes/index.php' ) ) {
131 + ?>
132 + <div class="notice notice-info">
133 + <p><?php esc_html_e( 'Awesome, you are using Boxzilla! You can now safely deactivate the Scroll Triggered Boxes plugin.', 'boxzilla' ); ?></p>
134 + </div>
135 + <?php
136 + }
137 + }
159 138
160 - $upgrade_routines = new Migrations($previous_version, $current_version, __DIR__ . '/migrations');
161 - $upgrade_routines->run();
162 - update_option('boxzilla_version', $current_version);
163 - }
139 + /**
140 + * Checks current version against stored version & runs necessary update routines.
141 + *
142 + * @return bool
143 + */
144 + protected function run_migrations() {
164 145
165 - public function lazy_add_hooks()
166 - {
167 - global $pagenow;
146 + // Only run if db option is at older version than code constant
147 + $previous_version = get_option( 'boxzilla_version', '0' );
148 + $current_version = $this->plugin->version();
168 149
169 - add_action('admin_enqueue_scripts', [ $this, 'load_assets' ]);
170 - add_action('add_meta_boxes', [ $this, 'add_meta_boxes' ]);
171 - add_filter('tiny_mce_before_init', [ $this, 'tinymce_init' ]);
172 - add_filter('manage_edit-boxzilla-box_columns', [ $this, 'post_type_column_titles' ]);
173 - add_action('manage_boxzilla-box_posts_custom_column', [ $this, 'post_type_column_content' ], 10, 2);
174 - add_filter('admin_footer_text', [ $this, 'admin_footer_text' ]);
150 + if ( version_compare( $current_version, $previous_version, '<=' ) ) {
151 + return false;
152 + }
175 153
176 - if ($pagenow === 'plugins.php') {
177 - add_filter('plugin_action_links', [ $this, 'add_plugin_settings_link' ], 10, 2);
178 - add_filter('plugin_row_meta', [ $this, 'add_plugin_meta_links' ], 10, 2);
179 - }
180 - }
154 + $upgrade_routines = new Migrations( $previous_version, $current_version, __DIR__ . '/migrations' );
155 + $upgrade_routines->run();
156 + update_option( 'boxzilla_version', $current_version );
157 + }
181 158
182 - /**
183 - * @param $post_id
184 - */
185 - public function post_type_column_box_id_content($post_id)
186 - {
187 - echo $post_id;
188 - }
159 + public function lazy_add_hooks() {
160 + global $pagenow;
189 161
190 - /**
191 - * @param $column
192 - * @param $post_id
193 - */
194 - public function post_type_column_content($column, $post_id)
195 - {
196 - $method_name = 'post_type_column_' . $column . '_content';
197 - if (method_exists($this, $method_name)) {
198 - call_user_func([ $this, $method_name ], $post_id);
199 - }
200 - }
162 + add_action( 'admin_enqueue_scripts', array( $this, 'load_assets' ) );
163 + add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
164 + add_filter( 'tiny_mce_before_init', array( $this, 'tinymce_init' ) );
165 + add_filter( 'manage_edit-boxzilla-box_columns', array( $this, 'post_type_column_titles' ) );
166 + add_action( 'manage_boxzilla-box_posts_custom_column', array( $this, 'post_type_column_content' ), 10, 2 );
167 + add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
201 168
202 - /**
203 - * @param $columns
204 - *
205 - * @return mixed
206 - */
207 - public function post_type_column_titles($columns)
208 - {
209 - $columns = self::array_insert(
210 - $columns,
211 - [
212 - 'box_id' => esc_html__('Box ID', 'boxzilla'),
213 - ],
214 - 1
215 - );
169 + if ( $pagenow === 'plugins.php' ) {
170 + add_filter( 'plugin_action_links', array( $this, 'add_plugin_settings_link' ), 10, 2 );
171 + add_filter( 'plugin_row_meta', array( $this, 'add_plugin_meta_links' ), 10, 2 );
172 + }
173 + }
216 174
217 - $columns['title'] = esc_html__('Box Title', 'boxzilla');
175 + /**
176 + * @param $post_id
177 + */
178 + public function post_type_column_box_id_content( $post_id ) {
179 + echo $post_id;
180 + }
218 181
219 - return $columns;
220 - }
182 + /**
183 + * @param $column
184 + * @param $post_id
185 + */
186 + public function post_type_column_content( $column, $post_id ) {
187 + $method_name = 'post_type_column_' . $column . '_content';
188 + if ( method_exists( $this, $method_name ) ) {
189 + call_user_func( array( $this, $method_name ), $post_id );
190 + }
191 + }
221 192
222 - /**
223 - * Register stuffs
224 - */
225 - public function register()
226 - {
193 + /**
194 + * @param $columns
195 + *
196 + * @return mixed
197 + */
198 + public function post_type_column_titles( $columns ) {
199 + $columns = self::array_insert(
200 + $columns,
201 + array(
202 + 'box_id' => esc_html__( 'Box ID', 'boxzilla' ),
203 + ),
204 + 1
205 + );
227 206
228 - register_setting('boxzilla_settings', 'boxzilla_settings', [ $this, 'sanitize_settings' ]);
207 + $columns['title'] = esc_html__( 'Box Title', 'boxzilla' );
229 208
230 - wp_register_script(
231 - 'boxzilla-admin',
232 - $this->plugin->url('/assets/js/admin-script.js'),
233 - [
234 - 'jquery',
235 - 'wp-util',
236 - 'wp-color-picker',
237 - 'suggest',
238 - ],
239 - $this->plugin->version(),
240 - true
241 - );
209 + return $columns;
210 + }
242 211
243 - wp_register_style('boxzilla-admin', $this->plugin->url('/assets/css/admin-styles.css'), [], $this->plugin->version());
244 - }
212 + /**
213 + * Register stuffs
214 + */
215 + public function register() {
245 216
246 - /**
247 - * Renders the Boxzilla admin menu items
248 - */
249 - public function menu()
250 - {
251 - $menu_items = [
252 - [
253 - esc_html__('Settings', 'boxzilla'),
254 - esc_html__('Settings', 'boxzilla'),
255 - 'boxzilla-settings',
256 - [ $this, 'show_settings_page' ],
257 - ],
258 - [
259 - esc_html__('Extensions', 'boxzilla'),
260 - '<span style="color: orange">' . esc_html__('Extensions', 'boxzilla') . '</span>',
261 - 'boxzilla-extensions',
262 - [ $this, 'show_extensions_page' ],
263 - ],
264 - ];
217 + register_setting( 'boxzilla_settings', 'boxzilla_settings', array( $this, 'sanitize_settings' ) );
265 218
266 - $menu_items = apply_filters('boxzilla_admin_menu_items', $menu_items);
219 + wp_register_script(
220 + 'boxzilla-admin',
221 + $this->plugin->url( '/assets/js/admin-script.js' ),
222 + array(
223 + 'jquery',
224 + 'wp-util',
225 + 'wp-color-picker',
226 + 'suggest',
227 + ),
228 + $this->plugin->version(),
229 + true
230 + );
267 231
268 - foreach ($menu_items as $item) {
269 - add_submenu_page('edit.php?post_type=boxzilla-box', $item[0] . '- Boxzilla', $item[1], 'manage_options', $item[2], $item[3]);
270 - }
271 - }
232 + wp_register_style( 'boxzilla-admin', $this->plugin->url( '/assets/css/admin-styles.css' ), array(), $this->plugin->version() );
233 + }
272 234
273 - /**
274 - * Shows the settings page
275 - */
276 - public function show_settings_page()
277 - {
278 - $opts = $this->boxzilla->options;
279 - require __DIR__ . '/views/settings.php';
280 - }
235 + /**
236 + * Renders the Boxzilla admin menu items
237 + */
238 + public function menu() {
239 + $menu_items = array(
240 + array(
241 + esc_html__( 'Settings', 'boxzilla' ),
242 + esc_html__( 'Settings', 'boxzilla' ),
243 + 'boxzilla-settings',
244 + array( $this, 'show_settings_page' ),
245 + ),
246 + array(
247 + esc_html__( 'Extensions', 'boxzilla' ),
248 + '<span style="color: orange">' . esc_html__( 'Extensions', 'boxzilla' ) . '</span>',
249 + 'boxzilla-extensions',
250 + array( $this, 'show_extensions_page' ),
251 + ),
252 + );
281 253
282 - /**
283 - * Shows the extensions page
284 - */
285 - public function show_extensions_page()
286 - {
287 - $extensions = $this->fetch_extensions();
288 - require __DIR__ . '/views/extensions.php';
289 - }
254 + $menu_items = apply_filters( 'boxzilla_admin_menu_items', $menu_items );
290 255
291 - /**
292 - * Are we currently editing a box?
293 - *
294 - * @return bool
295 - */
296 - protected function on_edit_box_page()
297 - {
298 - global $pagenow;
256 + foreach ( $menu_items as $item ) {
257 + add_submenu_page( 'edit.php?post_type=boxzilla-box', $item[0] . '- Boxzilla', $item[1], 'manage_options', $item[2], $item[3] );
258 + }
259 + }
299 260
300 - if (! in_array($pagenow, [ 'post-new.php', 'post.php' ], true)) {
301 - return false;
302 - }
261 + /**
262 + * Shows the settings page
263 + */
264 + public function show_settings_page() {
265 + $opts = $this->boxzilla->options;
266 + require __DIR__ . '/views/settings.php';
267 + }
303 268
304 - if (isset($_GET['post_type']) && $_GET['post_type'] === 'boxzilla-box') {
305 - return true;
306 - }
269 + /**
270 + * Shows the extensions page
271 + */
272 + public function show_extensions_page() {
273 + $extensions = $this->fetch_extensions();
274 + require __DIR__ . '/views/extensions.php';
275 + }
307 276
308 - if (get_post_type() === 'boxzilla-box') {
309 - return true;
310 - }
277 + /**
278 + * Are we currently editing a box?
279 + *
280 + * @return bool
281 + */
282 + protected function on_edit_box_page() {
283 + global $pagenow;
311 284
312 - return false;
313 - }
285 + if ( ! in_array( $pagenow, array( 'post-new.php', 'post.php' ), true ) ) {
286 + return false;
287 + }
314 288
315 - /**
316 - * @param $args
317 - *
318 - * @return mixed
319 - */
320 - public function tinymce_init($args)
321 - {
289 + if ( isset( $_GET['post_type'] ) && $_GET['post_type'] === 'boxzilla-box' ) {
290 + return true;
291 + }
322 292
323 - // only act on our post type
324 - if (get_post_type() !== 'boxzilla-box') {
325 - return $args;
326 - }
293 + if ( get_post_type() === 'boxzilla-box' ) {
294 + return true;
295 + }
327 296
328 - $args['setup'] = 'function( editor ) { if(typeof(window.Boxzilla_Admin) === \'undefined\') { return; } editor.on("PreInit", window.Boxzilla_Admin.Designer.init ); }';
297 + return false;
298 + }
329 299
330 - return $args;
331 - }
300 + /**
301 + * @param $args
302 + *
303 + * @return mixed
304 + */
305 + public function tinymce_init( $args ) {
332 306
333 - /**
334 - * Load plugin assets
335 - */
336 - public function load_assets()
337 - {
338 - $screen = get_current_screen();
307 + // only act on our post type
308 + if ( get_post_type() !== 'boxzilla-box' ) {
309 + return $args;
310 + }
339 311
340 - if (! $screen instanceof WP_Screen) {
341 - return false;
342 - }
312 + $args['setup'] = 'function( editor ) { if(typeof(window.Boxzilla_Admin) === \'undefined\') { return; } editor.on("PreInit", window.Boxzilla_Admin.Designer.init ); }';
343 313
344 - if ($screen->base === 'edit' && $screen->post_type === 'boxzilla-box') {
345 - wp_enqueue_style('boxzilla-admin');
346 - }
314 + return $args;
315 + }
347 316
348 - if ($screen->base === 'post' && $screen->post_type === 'boxzilla-box') {
349 - // color picker
350 - wp_enqueue_style('wp-color-picker');
317 + /**
318 + * Load plugin assets
319 + */
320 + public function load_assets() {
321 + $screen = get_current_screen();
351 322
352 - // load scripts
353 - wp_enqueue_script('boxzilla-admin');
323 + if ( ! $screen instanceof WP_Screen ) {
324 + return false;
325 + }
354 326
355 - $data = [
356 - 'and' => esc_html__('and', 'boxzilla'),
357 - 'or' => esc_html__('or', 'boxzilla'),
358 - 'enterCommaSeparatedValues' => esc_html__('Enter a comma-separated list of values.', 'boxzilla'),
359 - 'enterCommaSeparatedPosts' => esc_html__("Enter a comma-separated list of post slugs or post ID's..", 'boxzilla'),
360 - 'enterCommaSeparatedPages' => esc_html__("Enter a comma-separated list of page slugs or page ID's..", 'boxzilla'),
361 - 'enterCommaSeparatedPostTypes' => esc_html__('Enter a comma-separated list of post types..', 'boxzilla'),
362 - 'enterCommaSeparatedRelativeUrls' => esc_html__("Enter a comma-separated list of relative URL's, eg /contact/", 'boxzilla'),
363 - ];
364 - wp_localize_script('boxzilla-admin', 'boxzilla_i18n', $data);
327 + if ( $screen->base === 'edit' && $screen->post_type === 'boxzilla-box' ) {
328 + wp_enqueue_style( 'boxzilla-admin' );
329 + }
365 330
366 - // load stylesheets
367 - wp_enqueue_style('boxzilla-admin');
331 + if ( $screen->base === 'post' && $screen->post_type === 'boxzilla-box' ) {
332 + // color picker
333 + wp_enqueue_style( 'wp-color-picker' );
368 334
369 - // allow add-ons to easily load their own scripts or stylesheets
370 - do_action('boxzilla_load_admin_assets');
371 - }
335 + // load scripts
336 + wp_enqueue_script( 'boxzilla-admin' );
372 337
373 - if (isset($_GET['page']) && $_GET['page'] === 'boxzilla-settings') {
374 - wp_enqueue_style('boxzilla-admin');
375 - }
376 - }
338 + $data = array(
339 + 'and' => esc_html__( 'and', 'boxzilla' ),
340 + 'or' => esc_html__( 'or', 'boxzilla' ),
341 + 'enterCommaSeparatedValues' => esc_html__( 'Enter a comma-separated list of values.', 'boxzilla' ),
342 + 'enterCommaSeparatedPosts' => esc_html__( "Enter a comma-separated list of post slugs or post ID's..", 'boxzilla' ),
343 + 'enterCommaSeparatedPages' => esc_html__( "Enter a comma-separated list of page slugs or page ID's..", 'boxzilla' ),
344 + 'enterCommaSeparatedPostTypes' => esc_html__( 'Enter a comma-separated list of post types..', 'boxzilla' ),
345 + 'enterCommaSeparatedRelativeUrls' => esc_html__( "Enter a comma-separated list of relative URL's, eg /contact/", 'boxzilla' ),
346 + );
347 + wp_localize_script( 'boxzilla-admin', 'boxzilla_i18n', $data );
377 348
378 - /**
379 - * Register meta boxes
380 - *
381 - * @param string $post_type
382 - */
383 - public function add_meta_boxes($post_type)
384 - {
385 - if ($post_type !== 'boxzilla-box') {
386 - return;
387 - }
349 + // load stylesheets
350 + wp_enqueue_style( 'boxzilla-admin' );
388 351
389 - add_meta_box(
390 - 'boxzilla-box-appearance-controls',
391 - esc_html__('Box Appearance', 'boxzilla'),
392 - [ $this, 'metabox_box_appearance_controls' ],
393 - 'boxzilla-box',
394 - 'normal',
395 - 'core'
396 - );
352 + // allow add-ons to easily load their own scripts or stylesheets
353 + do_action( 'boxzilla_load_admin_assets' );
354 + }
397 355
398 - add_meta_box(
399 - 'boxzilla-box-options-controls',
400 - esc_html__('Box Options', 'boxzilla'),
401 - [ $this, 'metabox_box_option_controls' ],
402 - 'boxzilla-box',
403 - 'normal',
404 - 'core'
405 - );
356 + if ( isset( $_GET['page'] ) && $_GET['page'] === 'boxzilla-settings' ) {
357 + wp_enqueue_style( 'boxzilla-admin' );
358 + }
359 + }
406 360
407 - add_meta_box(
408 - 'boxzilla-support',
409 - esc_html__('Looking for help?', 'boxzilla'),
410 - [ $this, 'metabox_support' ],
411 - 'boxzilla-box',
412 - 'side'
413 - );
361 + /**
362 + * Register meta boxes
363 + *
364 + * @param string $post_type
365 + *
366 + * @return bool
367 + */
368 + public function add_meta_boxes( $post_type ) {
369 + if ( $post_type !== 'boxzilla-box' ) {
370 + return false;
371 + }
414 372
415 - add_meta_box(
416 - 'boxzilla-our-other-plugins',
417 - esc_html__('Our other plugins', 'boxzilla'),
418 - [ $this, 'metabox_our_other_plugins' ],
419 - 'boxzilla-box',
420 - 'side'
421 - );
422 - }
373 + add_meta_box(
374 + 'boxzilla-box-appearance-controls',
375 + esc_html__( 'Box Appearance', 'boxzilla' ),
376 + array( $this, 'metabox_box_appearance_controls' ),
377 + 'boxzilla-box',
378 + 'normal',
379 + 'core'
380 + );
423 381
424 - /**
425 - * @param \WP_Post $post
426 - * @param $metabox
427 - */
428 - public function metabox_box_appearance_controls(\WP_Post $post, $metabox)
429 - {
382 + add_meta_box(
383 + 'boxzilla-box-options-controls',
384 + esc_html__( 'Box Options', 'boxzilla' ),
385 + array( $this, 'metabox_box_option_controls' ),
386 + 'boxzilla-box',
387 + 'normal',
388 + 'core'
389 + );
430 390
431 - // get box options
432 - $box = new Box($post);
433 - $opts = $box->get_options();
391 + add_meta_box(
392 + 'boxzilla-support',
393 + esc_html__( 'Looking for help?', 'boxzilla' ),
394 + array( $this, 'metabox_support' ),
395 + 'boxzilla-box',
396 + 'side'
397 + );
434 398
435 - // include view
436 - include __DIR__ . '/views/metaboxes/box-appearance-controls.php';
437 - }
399 + add_meta_box(
400 + 'boxzilla-our-other-plugins',
401 + esc_html__( 'Our other plugins', 'boxzilla' ),
402 + array( $this, 'metabox_our_other_plugins' ),
403 + 'boxzilla-box',
404 + 'side'
405 + );
438 406
439 - /**
440 - * @param \WP_Post $post
441 - * @param $metabox
442 - */
443 - public function metabox_box_option_controls(\WP_Post $post, $metabox)
444 - {
407 + add_meta_box(
408 + 'boxzilla-email-optin',
409 + esc_html__( 'Subscribe to our newsletter', 'boxzilla' ),
410 + array( $this, 'metabox_email_optin' ),
411 + 'boxzilla-box',
412 + 'side'
413 + );
445 414
446 - // get box options
447 - $box = new Box($post);
448 - $opts = $box->get_options();
449 - $global_opts = $this->boxzilla->options;
415 + return true;
416 + }
450 417
451 - if (empty($opts['rules'])) {
452 - $opts['rules'][] = [
453 - 'condition' => '',
454 - 'qualifier' => 1,
455 - 'value' => '',
456 - ];
457 - }
418 + /**
419 + * @param \WP_Post $post
420 + * @param $metabox
421 + */
422 + public function metabox_box_appearance_controls( \WP_Post $post, $metabox ) {
458 423
459 - // include view
460 - include __DIR__ . '/views/metaboxes/box-option-controls.php';
461 - }
424 + // get box options
425 + $box = new Box( $post );
426 + $opts = $box->get_options();
462 427
463 - /**
464 - * @param \WP_Post $post
465 - * @param $metabox
466 - */
467 - public function metabox_our_other_plugins(\WP_Post $post, $metabox)
468 - {
469 - include __DIR__ . '/views/metaboxes/our-other-plugins.php';
470 - }
428 + // include view
429 + include __DIR__ . '/views/metaboxes/box-appearance-controls.php';
430 + }
471 431
472 - /**
473 - * @param \WP_Post $post
474 - * @param $metabox
475 - */
476 - public function metabox_support(\WP_Post $post, $metabox)
477 - {
478 - include __DIR__ . '/views/metaboxes/need-help.php';
479 - }
432 + /**
433 + * @param \WP_Post $post
434 + * @param $metabox
435 + */
436 + public function metabox_box_option_controls( \WP_Post $post, $metabox ) {
480 437
438 + // get box options
439 + $box = new Box( $post );
440 + $opts = $box->get_options();
441 + $global_opts = $this->boxzilla->options;
481 442
482 - /**
483 - * Saves box options and rules
484 - *
485 - * @param int $box_id
486 - * @param \WP_Post $post
487 - */
488 - public function save_box_options($box_id, $post)
489 - {
490 - // Only act on our own post type
491 - if ($post->post_type !== 'boxzilla-box') {
492 - return;
493 - }
443 + if ( empty( $opts['rules'] ) ) {
444 + $opts['rules'][] = array(
445 + 'condition' => '',
446 + 'qualifier' => 1,
447 + 'value' => '',
448 + );
449 + }
494 450
495 - // is this a revision save?
496 - if (wp_is_post_revision($box_id) || ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )) {
497 - return;
498 - }
451 + // include view
452 + include __DIR__ . '/views/metaboxes/box-option-controls.php';
453 + }
499 454
500 - // can user edit this post?
501 - if (! current_user_can('edit_post', $box_id)) {
502 - return;
503 - }
455 + /**
456 + * @param \WP_Post $post
457 + * @param $metabox
458 + */
459 + public function metabox_email_optin( \WP_Post $post, $metabox ) {
460 + include __DIR__ . '/views/metaboxes/email-optin.php';
461 + }
504 462
505 - // make sure options array is set
506 - if (! isset($_POST['boxzilla_box']) || ! is_array($_POST['boxzilla_box'])) {
507 - return;
508 - }
463 + /**
464 + * @param \WP_Post $post
465 + * @param $metabox
466 + */
467 + public function metabox_our_other_plugins( \WP_Post $post, $metabox ) {
468 + include __DIR__ . '/views/metaboxes/our-other-plugins.php';
469 + }
509 470
510 - // get new options from $_POST
511 - $opts = $this->sanitize_box_options($_POST['boxzilla_box']);
471 + /**
472 + * @param \WP_Post $post
473 + * @param $metabox
474 + */
475 + public function metabox_support( \WP_Post $post, $metabox ) {
476 + include __DIR__ . '/views/metaboxes/need-help.php';
477 + }
512 478
513 - // allow extensions to filter the saved options
514 - $opts = apply_filters('boxzilla_saved_options', $opts, $box_id);
515 479
516 - // save individual box settings
517 - update_post_meta($box_id, 'boxzilla_options', $opts);
480 + /**
481 + * Saves box options and rules
482 + *
483 + * @param int $box_id
484 + *
485 + * @return bool
486 + */
487 + public function save_box_options( $box_id, $post ) {
518 488
519 - // update global settings if given
520 - if (! empty($_POST['boxzilla_global_settings'])) {
521 - $raw_global_settings = $_POST['boxzilla_global_settings'];
522 - $global_settings = get_option('boxzilla_settings', []);
523 - if (! is_array($global_settings)) {
524 - $global_settings = [];
525 - }
526 - if (isset($raw_global_settings['test_mode'])) {
527 - $global_settings['test_mode'] = absint($raw_global_settings['test_mode']);
528 - }
529 - update_option('boxzilla_settings', $global_settings);
530 - }
489 + // Only act on our own post type
490 + if ( $post->post_type !== 'boxzilla-box' ) {
491 + return false;
492 + }
531 493
532 - $this->flush_rules($box_id);
533 - }
494 + // is this a revision save?
495 + if ( wp_is_post_revision( $box_id ) || ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) ) {
496 + return false;
497 + }
534 498
535 - /**
536 - * @param array $opts
537 - *
538 - * @return array
539 - */
540 - public function sanitize_settings($opts)
541 - {
542 - $opts['test_mode'] = (int) $opts['test_mode'] ? 1 : 0;
543 - return $opts;
544 - }
499 + // can user edit this post?
500 + if ( ! current_user_can( 'edit_post', $box_id ) ) {
501 + return false;
502 + }
545 503
546 - /**
547 - * @param string $url_string
548 - *
549 - * @return string
550 - */
551 - public function sanitize_url($url_string)
552 - {
504 + // make sure options array is set
505 + if ( ! isset( $_POST['boxzilla_box'] ) || ! is_array( $_POST['boxzilla_box'] ) ) {
506 + return false;
507 + }
553 508
554 - // if empty, just return a slash
555 - if (empty($url_string)) {
556 - return '/';
557 - }
509 + // get new options from $_POST
510 + $opts = $this->sanitize_box_options( $_POST['boxzilla_box'] );
558 511
559 - // if string looks like an absolute URL, extract just the path
560 - if (preg_match('/^((https|http)?\:\/\/)?(\w+\.)?\w+\.\w+\.*/i', $url_string)) {
561 - // make sure URL has scheme prepended, to make parse_url() understand..
562 - $url_string = 'https://' . str_replace([ 'http://', 'https://' ], '', $url_string);
512 + // allow extensions to filter the saved options
513 + $opts = apply_filters( 'boxzilla_saved_options', $opts, $box_id );
563 514
564 - // get just the path
565 - $url_string = parse_url($url_string, PHP_URL_PATH);
566 - }
515 + // save individual box settings
516 + update_post_meta( $box_id, 'boxzilla_options', $opts );
567 517
568 - // leading slash it
569 - return $url_string;
570 - }
518 + // update global settings if given
519 + if ( ! empty( $_POST['boxzilla_global_settings'] ) ) {
520 + $global_settings = get_option( 'boxzilla_settings', array() );
521 + if ( ! is_array( $global_settings ) ) {
522 + $global_settings = array();
523 + }
524 + $global_settings = array_merge( $global_settings, $_POST['boxzilla_global_settings'] );
525 + update_option( 'boxzilla_settings', $global_settings );
526 + }
571 527
572 - /**
573 - * @param array $rule
574 - * @return array The sanitized rule array
575 - */
576 - public function sanitize_box_rule($rule)
577 - {
578 - $rule['value'] = trim($rule['value']);
528 + $this->flush_rules( $box_id );
579 529
580 - // convert to array
581 - $rule['value'] = explode(',', trim($rule['value'], ','));
530 + return true;
531 + }
582 532
583 - // trim all whitespace in value field
584 - $rule['value'] = array_map('trim', $rule['value']);
533 + /**
534 + * @param array $opts
535 + *
536 + * @return array
537 + */
538 + public function sanitize_settings( $opts ) {
539 + return $opts;
540 + }
585 541
586 - // Make sure "is_url" values have a leading slash
587 - if ($rule['condition'] === 'is_url') {
588 - $rule['value'] = array_map([ $this, 'sanitize_url' ], $rule['value']);
589 - }
542 + /**
543 + * @param string $url_string
544 + *
545 + * @return string
546 + */
547 + public function sanitize_url( $url_string ) {
590 548
591 - // (re)set value to 0 when condition is everywhere
592 - if ($rule['condition'] === 'everywhere') {
593 - $rule['value'] = '';
594 - }
549 + // if empty, just return a slash
550 + if ( empty( $url_string ) ) {
551 + return '/';
552 + }
595 553
596 - // convert back to string before saving
597 - if (is_array($rule['value'])) {
598 - $rule['value'] = join(',', $rule['value']);
599 - }
554 + // if string looks like an absolute URL, extract just the path
555 + if ( preg_match( '/^((https|http)?\:\/\/)?(\w+\.)?\w+\.\w+\.*/i', $url_string ) ) {
600 556
601 - return $rule;
602 - }
557 + // make sure URL has scheme prepended, to make parse_url() understand..
558 + $url_string = 'https://' . str_replace( array( 'http://', 'https://' ), '', $url_string );
603 559
604 - /**
605 - * @param array $css
606 - * @return array
607 - */
608 - public function sanitize_box_css($css)
609 - {
560 + // get just the path
561 + $url_string = parse_url( $url_string, PHP_URL_PATH );
562 + }
610 563
611 - // sanitize settings
612 - if ('' !== $css['width']) {
613 - $css['width'] = absint($css['width']);
614 - }
564 + // leading slash it
565 + return $url_string;
566 + }
615 567
616 - if ('' !== $css['border_width']) {
617 - $css['border_width'] = absint($css['border_width']);
618 - }
568 + /**
569 + * @param array $rule
570 + * @return array The sanitized rule array
571 + */
572 + public function sanitize_box_rule( $rule ) {
573 + $rule['value'] = trim( $rule['value'] );
619 574
620 - // make sure colors start with `#`
621 - $color_keys = [ 'color', 'background_color', 'border_color' ];
622 - foreach ($color_keys as $key) {
623 - $value = $css[ $key ];
624 - $color = sanitize_text_field($value);
575 + // convert to array
576 + $rule['value'] = explode( ',', trim( $rule['value'], ',' ) );
625 577
626 - // make sure color starts with `#`
627 - if ('' !== $color && $color[0] !== '#') {
628 - $color = '#' . $color;
629 - }
630 - $css[ $key ] = $color;
631 - }
578 + // trim all whitespace in value field
579 + $rule['value'] = array_map( 'trim', $rule['value'] );
632 580
633 - return $css;
634 - }
581 + // Make sure "is_url" values have a leading slash
582 + if ( $rule['condition'] === 'is_url' ) {
583 + $rule['value'] = array_map( array( $this, 'sanitize_url' ), $rule['value'] );
584 + }
635 585
636 - /**
637 - * Sanitize the options for this box.
638 - *
639 - * @param array $opts
640 - *
641 - * @return array
642 - */
643 - protected function sanitize_box_options($opts)
644 - {
645 - $defaults = [
646 - 'rules' => [],
647 - 'css' => [],
648 - ];
586 + // (re)set value to 0 when condition is everywhere
587 + if ( $rule['condition'] === 'everywhere' ) {
588 + $rule['value'] = '';
589 + }
649 590
650 - $opts = array_replace_recursive($defaults, $opts);
591 + // convert back to string before saving
592 + if ( is_array( $rule['value'] ) ) {
593 + $rule['value'] = join( ',', $rule['value'] );
594 + }
651 595
652 - $opts['rules'] = array_map([ $this, 'sanitize_box_rule' ], $opts['rules']);
653 - $opts['css'] = $this->sanitize_box_css($opts['css']);
654 - $opts['cookie']['triggered'] = absint($opts['cookie']['triggered']);
655 - $opts['cookie']['dismissed'] = absint($opts['cookie']['dismissed']);
656 - $opts['trigger'] = sanitize_text_field($opts['trigger']);
657 - $opts['trigger_percentage'] = absint($opts['trigger_percentage']);
658 - $opts['trigger_element'] = sanitize_text_field($opts['trigger_element']);
659 - $opts['screen_size_condition']['value'] = intval($opts['screen_size_condition']['value']);
596 + return $rule;
597 + }
660 598
661 - return $opts;
662 - }
599 + /**
600 + * @param array $css
601 + * @return array
602 + */
603 + public function sanitize_box_css( $css ) {
663 604
664 - /**
665 - * Add the settings link to the Plugins overview
666 - *
667 - * @param array $links
668 - * @param string $slug
669 - *
670 - * @return array
671 - */
672 - public function add_plugin_settings_link($links, $slug)
673 - {
674 - if ($slug !== $this->plugin->slug() || ! is_array($links)) {
675 - return $links;
676 - }
605 + // sanitize settings
606 + if ( '' !== $css['width'] ) {
607 + $css['width'] = absint( $css['width'] );
608 + }
677 609
678 - $href = admin_url('edit.php?post_type=boxzilla-box');
679 - $label = esc_html__('Boxes', 'boxzilla');
680 - $settings_link = "<a href=\"{$href}\">{$label}</a>";
681 - array_unshift($links, $settings_link);
682 - return $links;
683 - }
610 + if ( '' !== $css['border_width'] ) {
611 + $css['border_width'] = absint( $css['border_width'] );
612 + }
684 613
685 - /**
686 - * Adds meta links to the plugin in the WP Admin > Plugins screen
687 - *
688 - * @param array $links
689 - * @param string $slug
690 - *
691 - * @return array
692 - */
693 - public function add_plugin_meta_links($links, $slug)
694 - {
695 - if ($slug !== $this->plugin->slug()) {
696 - return $links;
697 - }
614 + // make sure colors start with `#`
615 + $color_keys = array( 'color', 'background_color', 'border_color' );
616 + foreach ( $color_keys as $key ) {
617 + $value = $css[ $key ];
618 + $color = sanitize_text_field( $value );
698 619
699 - $links[] = '<a href="https://boxzillaplugin.com/kb/">Documentation</a>';
700 - $links[] = '<a href="https://boxzillaplugin.com/add-ons/">Add-ons</a>';
620 + // make sure color starts with `#`
621 + if ( '' !== $color && $color[0] !== '#' ) {
622 + $color = '#' . $color;
623 + }
624 + $css[ $key ] = $color;
625 + }
701 626
702 - return $links;
703 - }
627 + return $css;
628 + }
704 629
705 - /**
706 - * Flush all box rules
707 - *
708 - * Loops through all published boxes and fills the rules option
709 - *
710 - * @param int $post_id
711 - */
712 - public function flush_rules($post_id)
713 - {
630 + /**
631 + * Sanitize the options for this box.
632 + *
633 + * @param array $opts
634 + *
635 + * @return array
636 + */
637 + protected function sanitize_box_options( $opts ) {
638 + $defaults = array(
639 + 'rules' => array(),
640 + 'css' => array(),
641 + );
714 642
715 - // only act on our own post type
716 - $post = get_post($post_id);
717 - if (! $post instanceof WP_Post || $post->post_type !== 'boxzilla-box') {
718 - return;
719 - }
643 + $opts = array_replace_recursive( $defaults, $opts );
720 644
721 - // get all published boxes
722 - $query = new \WP_Query();
723 - $boxes = $query->query(
724 - [
725 - 'post_type' => 'boxzilla-box',
726 - 'post_status' => 'publish',
727 - 'posts_per_page' => - 1,
728 - 'ignore_sticky_posts' => true,
729 - 'no_found_rows' => true,
730 - ]
731 - );
645 + $opts['rules'] = array_map( array( $this, 'sanitize_box_rule' ), $opts['rules'] );
646 + $opts['css'] = $this->sanitize_box_css( $opts['css'] );
647 + $opts['cookie']['triggered'] = absint( $opts['cookie']['triggered'] );
648 + $opts['cookie']['dismissed'] = absint( $opts['cookie']['dismissed'] );
649 + $opts['trigger'] = sanitize_text_field( $opts['trigger'] );
650 + $opts['trigger_percentage'] = absint( $opts['trigger_percentage'] );
651 + $opts['trigger_element'] = sanitize_text_field( $opts['trigger_element'] );
652 + $opts['screen_size_condition']['value'] = intval( $opts['screen_size_condition']['value'] );
732 653
733 - // setup empty array of rules
734 - $rules = [];
654 + return $opts;
655 + }
735 656
736 - // fill rules array
737 - if (is_array($boxes)) {
738 - foreach ($boxes as $box) {
739 - // get box meta data
740 - $box_meta = get_post_meta($box->ID, 'boxzilla_options', true);
741 - if (! $box_meta || ! is_array($box_meta) || empty($box_meta['rules'])) {
742 - continue;
743 - }
657 + /**
658 + * Add the settings link to the Plugins overview
659 + *
660 + * @param array $links
661 + * @param string $slug
662 + *
663 + * @return array
664 + */
665 + public function add_plugin_settings_link( $links, $slug ) {
666 + if ( $slug !== $this->plugin->slug() || ! is_array( $links ) ) {
667 + return $links;
668 + }
744 669
745 - // add box rules to all rules
746 - $rules[ $box->ID ] = (array) $box_meta['rules'];
747 - $rules[ $box->ID ]['comparision'] = isset($box_meta['rules_comparision']) ? $box_meta['rules_comparision'] : 'any';
748 - }
749 - }
670 + $href = admin_url( 'edit.php?post_type=boxzilla-box' );
671 + $label = esc_html__( 'Boxes', 'boxzilla' );
672 + $settings_link = "<a href=\"{$href}\">{$label}</a>";
673 + array_unshift( $links, $settings_link );
674 + return $links;
675 + }
750 676
751 - update_option('boxzilla_rules', $rules);
752 - }
677 + /**
678 + * Adds meta links to the plugin in the WP Admin > Plugins screen
679 + *
680 + * @param array $links
681 + * @param string $slug
682 + *
683 + * @return array
684 + */
685 + public function add_plugin_meta_links( $links, $slug ) {
686 + if ( $slug !== $this->plugin->slug() ) {
687 + return $links;
688 + }
753 689
754 - /**
755 - * Fetches a list of available add-on plugins
756 - *
757 - * @return array
758 - */
759 - protected function fetch_extensions()
760 - {
761 - $extensions = get_transient('boxzilla_remote_extensions');
762 - if ($extensions) {
763 - return $extensions;
764 - }
690 + $links[] = '<a href="https://kb.boxzillaplugin.com/">Documentation</a>';
691 + $links[] = '<a href="https://boxzillaplugin.com/add-ons/">Add-ons</a>';
765 692
766 - $response = wp_remote_get('https://my.boxzillaplugin.com/api/v2/plugins');
767 - if (is_wp_error($response) || wp_remote_retrieve_response_code($response) >= 400) {
768 - return [];
769 - }
693 + return $links;
694 + }
770 695
771 - $body = wp_remote_retrieve_body($response);
772 - $data = json_decode($body);
773 - if (is_array($data)) {
774 - set_transient('boxzilla_remote_extensions', $data, 24 * HOUR_IN_SECONDS);
775 - return $data;
776 - }
696 + /**
697 + * Flush all box rules
698 + *
699 + * Loops through all published boxes and fills the rules option
700 + *
701 + * @param int $post_id
702 + */
703 + public function flush_rules( $post_id ) {
777 704
778 - return [];
779 - }
705 + // only act on our own post type
706 + $post = get_post( $post_id );
707 + if ( ! $post instanceof WP_Post || $post->post_type !== 'boxzilla-box' ) {
708 + return;
709 + }
780 710
781 - /**
782 - * @param $arr
783 - * @param $insert
784 - * @param $position
785 - *
786 - * @return array
787 - */
788 - public static function array_insert($arr, $insert, $position)
789 - {
790 - $i = 0;
791 - $ret = [];
792 - foreach ($arr as $key => $value) {
793 - if ($i == $position) {
794 - foreach ($insert as $ikey => $ivalue) {
795 - $ret[ $ikey ] = $ivalue;
796 - }
797 - }
798 - $ret[ $key ] = $value;
799 - $i++;
800 - }
711 + // get all published boxes
712 + $query = new \WP_Query;
713 + $boxes = $query->query(
714 + array(
715 + 'post_type' => 'boxzilla-box',
716 + 'post_status' => 'publish',
717 + 'posts_per_page' => - 1,
718 + 'ignore_sticky_posts' => true,
719 + 'no_found_rows' => true,
720 + )
721 + );
801 722
802 - return $ret;
803 - }
723 + // setup empty array of rules
724 + $rules = array();
804 725
805 - /**
806 - * @param string $text
807 - *
808 - * @return string
809 - */
810 - public function admin_footer_text($text)
811 - {
812 - $screen = get_current_screen();
726 + // fill rules array
727 + if ( is_array( $boxes ) ) {
728 + foreach ( $boxes as $box ) {
729 + // get box meta data
730 + $box_meta = get_post_meta( $box->ID, 'boxzilla_options', true );
813 731
814 - if (! $screen instanceof WP_Screen) {
815 - return $text;
816 - }
732 + // add box rules to all rules
733 + $rules[ $box->ID ] = (array) $box_meta['rules'];
734 + $rules[ $box->ID ]['comparision'] = isset( $box_meta['rules_comparision'] ) ? $box_meta['rules_comparision'] : 'any';
735 + }
736 + }
817 737
818 - $on_edit_page = $screen->parent_base === 'edit' && $screen->post_type === 'boxzilla-box';
819 - if ($on_edit_page) {
820 - return sprintf('If you enjoy using <strong>Boxzilla</strong>, please <a href="%s" target="_blank">leave us a ★★★★★ rating</a>. A <strong style="text-decoration: underline;">huge</strong> thank you in advance!', 'https://wordpress.org/support/view/plugin-reviews/boxzilla?rate=5#postform');
821 - }
738 + update_option( 'boxzilla_rules', $rules );
739 + }
822 740
823 - return $text;
824 - }
741 + /**
742 + * Fetches a list of available add-on plugins
743 + *
744 + * @return array
745 + */
746 + protected function fetch_extensions() {
747 + $extensions = get_transient( 'boxzilla_remote_extensions' );
748 + if ( $extensions ) {
749 + return $extensions;
750 + }
751 +
752 + $response = wp_remote_get( 'https://my.boxzillaplugin.com/api/v2/plugins' );
753 + if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) >= 400 ) {
754 + return array();
755 + }
756 +
757 + $body = wp_remote_retrieve_body( $response );
758 + $data = json_decode( $body );
759 + if ( is_array( $data ) ) {
760 + set_transient( 'boxzilla_remote_extensions', $data, 24 * HOUR_IN_SECONDS );
761 + return $data;
762 + }
763 +
764 + return array();
765 + }
766 +
767 + /**
768 + * @param $arr
769 + * @param $insert
770 + * @param $position
771 + *
772 + * @return array
773 + */
774 + public static function array_insert( $arr, $insert, $position ) {
775 + $i = 0;
776 + $ret = array();
777 + foreach ( $arr as $key => $value ) {
778 + if ( $i == $position ) {
779 + foreach ( $insert as $ikey => $ivalue ) {
780 + $ret[ $ikey ] = $ivalue;
781 + }
782 + }
783 + $ret[ $key ] = $value;
784 + $i ++;
785 + }
786 +
787 + return $ret;
788 + }
789 +
790 + /**
791 + * @param string $text
792 + *
793 + * @return string
794 + */
795 + public function admin_footer_text( $text ) {
796 + $screen = get_current_screen();
797 +
798 + if ( ! $screen instanceof WP_Screen ) {
799 + return $text;
800 + }
801 +
802 + $on_edit_page = $screen->parent_base === 'edit' && $screen->post_type === 'boxzilla-box';
803 + if ( $on_edit_page ) {
804 + return sprintf( 'If you enjoy using <strong>Boxzilla</strong>, please <a href="%s" target="_blank">leave us a ★★★★★ rating</a>. A <strong style="text-decoration: underline;">huge</strong> thank you in advance!', 'https://wordpress.org/support/view/plugin-reviews/boxzilla?rate=5#postform' );
805 + }
806 +
807 + return $text;
808 + }
809 +
810 +
825 811 }