PluginProbe ʕ •ᴥ•ʔ
Products Compare for WooCommerce / 3.5.8
Products Compare for WooCommerce v3.5.8
3.6.2.8 3.6.2.7 trunk 1.0.1 1.0.10 1.0.10.1 1.0.11 1.0.11.1 1.0.12 1.0.13 1.0.13.1 1.0.2 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 3.5 3.5.0.1 3.5.0.2 3.5.1 3.5.1.1 3.5.1.2 3.5.1.3 3.5.1.4 3.5.1.5 3.5.1.6 3.5.1.7 3.5.2 3.5.2.1 3.5.2.2 3.5.2.3 3.5.3 3.5.4 3.5.5 3.5.6 3.5.7 3.5.7.1 3.5.7.2 3.5.7.3 3.5.7.4 3.5.7.5 3.5.7.6 3.5.7.7 3.5.7.8 3.5.7.9 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.6.2.1 3.6.2.2 3.6.2.3 3.6.2.4 3.6.2.5 3.6.2.6
products-compare-for-woocommerce / berocket / framework.php
products-compare-for-woocommerce / berocket Last commit date
assets 2 years ago includes 2 years ago languages 2 years ago libraries 2 years ago sale 2 years ago templates 2 years ago framework.php 2 years ago framework_version.php 2 years ago
framework.php
1253 lines
1 <?php
2 if( ! class_exists( 'BeRocket_Framework' ) && ! function_exists('BeRocket_Framework_load_newest') ) {
3 function BeRocket_Framework_load_newest() {
4 $active_plugins = get_option('active_plugins');
5 $framework_version = '0';
6 $framework_dir = false;
7 foreach($active_plugins as $active_plugin) {
8 $version_file = plugin_dir_path(WP_PLUGIN_DIR . '/' . $active_plugin) . 'berocket/framework_version.php';
9 if( file_exists($version_file) ) {
10 include_once($version_file);
11 }
12 }
13 if( ! empty($framework_version) && ! empty($framework_dir) ) {
14 include_once($framework_dir . '/framework.php');
15 }
16 }
17 BeRocket_Framework_load_newest();
18 }
19 if( ! class_exists( 'BeRocket_Framework' ) ) {
20 if( ! defined('BeRocket_framework_file') ) {
21 define( "BeRocket_framework_file", __FILE__ );
22 }
23 if( ! defined('BeRocket_framework_dir') ) {
24 define( "BeRocket_framework_dir", __DIR__ );
25 }
26 require_once( plugin_dir_path( __FILE__ ) . 'includes/functions.php');
27 require_once( plugin_dir_path( __FILE__ ) . 'includes/updater.php');
28 require_once( plugin_dir_path( __FILE__ ) . 'includes/widget.php');
29 require_once( plugin_dir_path( __FILE__ ) . 'includes/admin_notices.php');
30 require_once( plugin_dir_path( __FILE__ ) . 'includes/information_notices.php');
31 require_once( plugin_dir_path( __FILE__ ) . 'includes/custom_post.php');
32 require_once( plugin_dir_path( __FILE__ ) . 'includes/conditions.php');
33 require_once( plugin_dir_path( __FILE__ ) . 'includes/plugin-variation.php');
34 require_once( plugin_dir_path( __FILE__ ) . 'includes/libraries.php');
35 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
36 load_plugin_textdomain('BeRocket_domain', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/');
37 class BeRocket_Framework {
38 public static $framework_version = '2.9.1';
39 public $plugin_framework_version = '2.9.1';
40 public static $settings_name = '';
41 public $addons;
42 public $libraries;
43 protected $disable_settings_for_admin = array();
44 private $post;
45 private $cc;
46 protected static $instance;
47 protected $plugin_version_capability = 0;
48 protected $framework_data = array(
49 'fontawesome_frontend' => false,
50 );
51 protected $active_libraries = array();
52 protected $global_settings = array(
53 'fontawesome_frontend_disable',
54 'fontawesome_frontend_version',
55 'framework_products_per_page'
56 );
57 public $check_lib = null;
58 protected $check_init_array = array();
59 public static function getInstance()
60 {
61 if (null === static::$instance)
62 {
63 static::$instance = new static();
64 }
65 return static::$instance;
66 }
67
68 function __construct( $child ) {
69 if (null === static::$instance)
70 {
71 static::$instance = $child;
72 }
73 $this->include_once_files();
74 $this->cc = $child; // Child Class object
75 do_action('BeRocket_framework_init_plugin', $this->cc->info);
76 $this->plugin_version_capability = apply_filters('brfr_plugin_version_capability_'.$this->cc->info['plugin_name'], $this->plugin_version_capability, $this);
77 if( $this->plugin_version_capability == 15 && is_admin() ) {
78 $is_active_plugin = get_transient( 'berocket_framework_plugin_is_active_'.$this->info['id'] );
79 if( $is_active_plugin === false || is_admin() ) {
80 $active_plugin = get_option( 'berocket_key_activated_plugins' );
81 $active_site_plugin = get_site_option( 'berocket_key_activated_plugins' );
82 if ( ! is_array( $active_plugin ) ) {
83 $active_plugin = array();
84 }
85 if ( ! is_array( $active_site_plugin ) ) {
86 $active_site_plugin = array();
87 }
88 $is_active_plugin = ( empty( $active_plugin[ $this->info['id'] ] ) && empty( $active_site_plugin[ $this->info['id'] ] ) ) ? 3 : 17;
89 set_transient( 'berocket_framework_plugin_is_active_'.$this->info['id'], $is_active_plugin, 7200 );
90 }
91 $this->plugin_version_capability = $is_active_plugin;
92 }
93 $this->defaults = apply_filters('brfr_plugin_defaults_value_'.$this->cc->info['plugin_name'], $this->defaults, $this);
94
95 register_activation_hook( $this->cc->info[ 'plugin_file' ], array( $this->cc, 'activation' ) );
96 register_uninstall_hook( $this->cc->info[ 'plugin_file' ], array( get_class( $this->cc ), 'deactivation' ) );
97 add_filter( 'BeRocket_updater_add_plugin', array( $this->cc, 'updater_info' ) );
98 add_filter( 'berocket_admin_notices_rate_stars_plugins', array( $this, 'rate_stars_plugins' ) );
99
100 if ( $this->cc->init_validation() ) {
101 add_action( 'init', array( $this->cc, 'init' ) );
102 add_action( 'wp_head', array( $this->cc, 'set_styles' ) );
103 add_action( 'wp_footer', array( $this->cc, 'set_scripts' ), 9000 );
104 add_action( 'admin_init', array( $this->cc, 'admin_init' ) );
105 add_action( 'admin_menu', array( $this->cc, 'admin_menu' ) );
106 add_action( 'admin_enqueue_scripts', array( $this->cc, 'admin_enqueue_scripts' ) );
107 add_action( 'berocket_enqueue_media', array( $this, 'wp_enqueue_media' ) );
108
109 add_action( 'wp_ajax_br_' . $this->cc->info[ 'plugin_name' ] . '_settings_save', array(
110 $this->cc,
111 'save_settings'
112 ) );
113 add_filter( 'plugin_row_meta', array( $this->cc, 'plugin_row_meta' ), 10, 2 );
114 add_filter( 'is_berocket_settings_page', array( $this->cc, 'is_settings_page' ) );
115
116 $plugin_base_slug = plugin_basename( $this->cc->info[ 'plugin_file' ] );
117 add_filter( 'plugin_action_links_' . $plugin_base_slug, array( $this->cc, 'plugin_action_links' ) );
118
119 add_action( 'plugins_loaded', array( $this->cc, 'plugins_loaded' ) );
120 add_action( 'sanitize_comment_cookies', array( $this->cc, 'sanitize_comment_cookies' ) );
121 add_action ( 'install_plugins_pre_plugin-information', array( $this->cc, 'install_plugins_pre_plugin_information' ), 1 );
122 if( empty($this->plugin_version_capability) || $this->plugin_version_capability < 10 ) {
123 add_filter('berocket_admin_notices_subscribe_plugins', array($this, 'admin_notices_subscribe_plugins'));
124 }
125 $this->libraries = new BeRocket_framework_libraries($this->active_libraries, $this->info, $this->values, $this->get_option());
126 add_filter('BeRocket_admin_init_user_capabilities', array($this, 'init_user_capabilities'));
127 add_filter('berocket_sanitize_array_predefine', array($this, 'sanitize_array_predefine'), 10, 4);
128 add_filter('berocket_sanitize_array_kses', array($this, 'sanitize_array_kses'), 10, 4);
129 add_filter('brfr_menu_item_remove_'.$this->info['plugin_name'], array($this, 'menu_item_remove'), 10, 3);
130 //CHECK OLD FRAMEWORK
131 add_filter('berocket_sanitize_array_kses', array($this, 'disable_for_old_plugins'), 10, 4);
132 $framework_version_current = self::$framework_version;
133 $framework_version = $framework_version_current;
134 include($this->info['plugin_dir']."/berocket/framework_version.php");
135 $this->plugin_framework_version = $framework_version_current;
136 if( $this->plugin_version_capability < 10 ) {
137 if( file_exists(plugin_dir_path( __FILE__ ) . 'sale/sale.php') ) {
138 include_once( plugin_dir_path( __FILE__ ) . 'sale/sale.php');
139 }
140 }
141 add_action( 'before_woocommerce_init', array($this, 'hpos_compatible'));
142 }
143 do_action($this->info[ 'plugin_name' ].'_framework_construct', $this->cc);
144 add_filter('brfr_get_plugin_version_capability_'.$this->cc->info['plugin_name'], array($this, 'get_plugin_version_capability'));
145 }
146 public function include_once_files() {
147 foreach (glob($this->info['plugin_dir'] . "/includes/*.php") as $filename)
148 {
149 include_once($filename);
150 }
151 }
152 public function init_check_lib() {
153 if( empty($this->check_lib) ) {
154 include_once('libraries/check_init.php');
155 $this->check_lib = new BeRocket_framework_check_init_lib($this->check_init_array);
156 }
157 }
158 public function get_plugin_version_capability($version) {
159 return $this->plugin_version_capability;
160 }
161 public function admin_notices_subscribe_plugins($plugins) {
162 $plugins[] = $this->info['id'];
163 return $plugins;
164 }
165 public function install_plugins_pre_plugin_information() {
166 wp_print_styles('font-awesome');
167 }
168 public function init_validation() {
169 $this->init_check_lib();
170 return $this->check_lib->check();
171 }
172
173 public function plugins_loaded() {
174 if( ! empty($_POST[ $this->cc->values[ 'settings_name' ] ]) ) {
175 $previous_options = $this->get_option();
176 $this->post = berocket_sanitize_array($_POST[ $this->cc->values[ 'settings_name' ] ], array($this->cc->values[ 'settings_name' ]), $previous_options);
177 }
178 }
179
180 public function sanitize_comment_cookies() {
181 if( ! empty($this->post) ) {
182 if( ! empty($_POST[ $this->cc->values[ 'settings_name' ] ]['addons']) ) {
183 $this->post['addons'] = $_POST[ $this->cc->values[ 'settings_name' ] ]['addons'];
184 }
185 if( ! empty($_POST[ $this->cc->values[ 'settings_name' ] ]['template']) ) {
186 $this->post['template'] = $_POST[ $this->cc->values[ 'settings_name' ] ]['template'];
187 }
188 $_POST[ $this->cc->values[ 'settings_name' ] ] = $this->post;
189 }
190 }
191
192 /**
193 * Get plugin data from BeRocket
194 *
195 * @return array
196 */
197 public static function get_product_data_berocket($plugin_id) {
198 $products = get_transient('berocket_plugin_paid_info');
199 if( $products === FALSE ) {
200 $response = wp_remote_post('https://berocket.com/main/get_product_data/public', array(
201 'method' => 'POST',
202 'timeout' => 15,
203 'redirection' => 5,
204 'blocking' => true,
205 'sslverify' => false
206 ));
207 if( ! is_wp_error($response) ) {
208 $out = wp_remote_retrieve_body($response);
209 if( !empty($out) && json_decode($out) ) {
210 $products = json_decode($out, true);
211 set_transient('berocket_plugin_paid_info', $products, DAY_IN_SECONDS);
212 } else {
213 set_transient('berocket_plugin_paid_info', '', DAY_IN_SECONDS);
214 }
215 } else {
216 set_transient('berocket_plugin_paid_info', '', DAY_IN_SECONDS);
217 }
218 }
219 if( $plugin_id == 'all' ) {
220 return $products;
221 }
222 $product_return = '';
223 if( is_array($products) ) {
224 foreach($products as $product) {
225 if( ! empty($product['id']) && $product['id'] == $plugin_id ) {
226 $product_return = $product;
227 break;
228 }
229 }
230 }
231 return $product_return;
232 }
233
234 public function clear_product_data_transient() {
235 delete_transient($this->info[ 'plugin_name' ] . '_paid_info');
236 }
237
238 /**
239 * Function set default settings to database
240 *
241 * @return void
242 */
243 public function activation() {
244 add_option( $this->cc->values[ 'settings_name' ], $this->sanitize_option( $this->cc->defaults ) );
245 do_action('brfr_activate_' . $this->cc->info[ 'plugin_name' ]);
246 }
247
248 /**
249 * Function remove settings from database
250 *
251 * @return void
252 */
253 public static function deactivation() {
254 if( ! empty(static::$settings_name) ) {
255 do_action('brfr_deactivate_' . static::$settings_name);
256 delete_option( static::$settings_name );
257 }
258 }
259
260 /**
261 * Filter for BeRocket updater
262 */
263 public function updater_info( $plugins ) {
264 $option = $this->get_option();
265 $info = get_plugin_data( $this->cc->info[ 'plugin_file' ] );
266
267 $this->cc->info[ 'key' ] = ( isset($option[ 'plugin_key' ]) ? $option[ 'plugin_key' ] : '' );
268 $this->cc->info[ 'slug' ] = basename( $this->cc->info[ 'plugin_dir' ] );
269 $this->cc->info[ 'plugin' ] = plugin_basename( $this->cc->info[ 'plugin_file' ] );
270 $this->cc->info[ 'name' ] = $info[ 'Name' ];
271 $this->cc->info[ 'version_capability' ] = $this->plugin_version_capability;
272 if( ! empty($this->cc->values['free_slug']) ) {
273 $this->cc->info[ 'free_slug' ] = $this->cc->values['free_slug'];
274 }
275
276 $plugins[] = $this->cc->info;
277
278 return $plugins;
279 }
280
281 public function rate_stars_plugins($plugins) {
282 if( $this->plugin_version_capability < 10 ) {
283 $plugin = array(
284 'id' => $this->info['id'],
285 'name' => $this->info['name'],
286 'plugin_name' => $this->info['plugin_name'],
287 'free_slug' => $this->values['free_slug'],
288 );
289 $plugins[$this->info['id']] = $plugin;
290 }
291 return $plugins;
292 }
293
294 /**
295 * Action links on the Plugins page
296 */
297 public function plugin_action_links( $links ) {
298 $action_links = array(
299 'settings' => '<a href="' . admin_url( 'admin.php?page=' . $this->cc->values[ 'option_page' ] ) .
300 '" title="' . __( 'View Plugin Settings', 'BeRocket_domain' ) . '">' .
301 __( 'Settings', 'BeRocket_domain' ) . '</a>',
302 );
303
304 return apply_filters('brfr_action_link_' . $this->cc->info[ 'plugin_name' ], array_merge( $action_links, $links ));
305 }
306
307 /**
308 * Meta links on the Plugins page
309 */
310 public function plugin_row_meta( $links, $file ) {
311 $plugin_base_slug = plugin_basename( $this->cc->info[ 'plugin_file' ] );
312 if ( $file == $plugin_base_slug ) {
313 if( ! empty($this->plugin_version_capability) && $this->plugin_version_capability > 10 ) {
314 $meta_data = '?utm_source=paid_plugin&utm_medium=plugins&utm_campaign='.$this->info['plugin_name'];
315 } else {
316 $meta_data = '?utm_source=free_plugin&utm_medium=plugins&utm_campaign='.$this->info['plugin_name'];
317 }
318 $row_meta = array(
319 'docs' => '<a href="https://docs.berocket.com/plugin/' .
320 $this->cc->values[ 'premium_slug' ] . $meta_data . '" title="' .
321 __( 'View Plugin Documentation', 'BeRocket_domain' ) .
322 '" target="_blank">' . __( 'Docs', 'BeRocket_domain' ) . '</a>',
323 );
324 if( ! empty($this->plugin_version_capability) && $this->plugin_version_capability == 3 ) {
325 if( ! empty($this->cc->values[ 'free_slug' ]) ) {
326 $row_meta['support'] = '<a href="https://wordpress.org/support/plugin/' . $this->cc->values[ 'free_slug' ] .
327 '/' . $meta_data . '" title="' . __( 'View Support Page', 'BeRocket_domain' ) .
328 '" target="_blank">' . __( 'Support', 'BeRocket_domain' ) . '</a>';
329 }
330 } elseif( ! empty($this->plugin_version_capability) && $this->plugin_version_capability > 10 ) {
331 $row_meta['premium'] = '<a href="https://berocket.com/support/support-' . $this->cc->values[ 'premium_slug' ] .
332 '" title="' . __( 'View Premium Support Page', 'BeRocket_domain' ) .
333 '" target="_blank">' . __( 'Premium Support', 'BeRocket_domain' ) . '</a>';
334 } else {
335 $row_meta['premium'] = '<a href="https://berocket.com/' . $this->cc->values[ 'premium_slug' ] . $meta_data .
336 '" title="' . __( 'View Premium Version Page', 'BeRocket_domain' ) .
337 '" target="_blank">' . __( 'Premium Version', 'BeRocket_domain' ) . '</a>';
338 }
339
340 $links = array_merge( $links, $row_meta );
341 $links = apply_filters('brfr_plugin_row_meta_' . $this->cc->info[ 'plugin_name' ], $links, $file, $this);
342 }
343
344 return $links;
345 }
346
347 /**
348 * Initialize
349 */
350 public function init() {
351 $global_option = $this->get_global_option();
352 wp_enqueue_script( "jquery" );
353 if( is_admin() ) {
354 $this->register_font_awesome('fa5live');
355 } else {
356 if ( ! empty($global_option['framework_products_per_page']) && intval($global_option['framework_products_per_page']) > 0 ) {
357 add_filter( 'loop_shop_per_page', array($this, 'framework_products_per_page_set'), 999999999 );
358 }
359 if( ! empty($this->framework_data['fontawesome_frontend']) ) {
360 $this->enqueue_fontawesome();
361 }
362 }
363
364 wp_add_inline_script(
365 $this->cc->info['plugin_name'] . "_execute_func",
366 ";
367 (function ($){
368 $(document).ready( function () {
369 " . $this->cc->info['plugin_name'] . "_execute_func( the_" . $this->cc->info['plugin_name'] . "_js_data.script.js_page_load );
370 });
371 })(jQuery);
372
373 function " . $this->cc->info['plugin_name'] . "_execute_func ( func ) {
374 if( the_" . $this->cc->info['plugin_name'] . "_js_data.script != 'undefined'
375 && the_" . $this->cc->info['plugin_name'] . "_js_data.script != null
376 && typeof func != 'undefined'
377 && func.length > 0 ) {
378 try {
379 eval( func );
380 } catch(err) {
381 alert('You have some incorrect JavaScript code (" . $this->cc->info['norm_name'] . ")');
382 }
383 }"
384 );
385 if ( function_exists('icl_object_id') ) {
386 include_once('libraries/wpml_compatibility.php');
387 }
388 }
389
390 public function enqueue_fontawesome($force = false) {
391 $global_option = $this->get_global_option();
392 if( empty($global_option['fontawesome_frontend_disable']) ) {
393 if( br_get_value_from_array($global_option, 'fontawesome_frontend_version') == 'fontawesome5' ) {
394 $this->register_font_awesome('fa5');
395 wp_enqueue_style( 'font-awesome-5' );
396 } else {
397 $this->register_font_awesome('fa4');
398 wp_enqueue_style( 'font-awesome' );
399 }
400 } else {
401 if( br_get_value_from_array($global_option, 'fontawesome_frontend_version') == 'fontawesome5' ) {
402 $this->register_font_awesome('fa5c');
403 wp_enqueue_style( 'font-awesome-5-compat' );
404 }
405 }
406 }
407 public function framework_products_per_page_set() {
408 $global_option = $this->get_global_option();
409 return intval($global_option['framework_products_per_page']);
410 }
411
412 /**
413 * Function set styles in wp_head WordPress action
414 *
415 * @return void
416 */
417 public function set_styles() {
418 $options = $this->get_option();
419 $previous_options = $this->get_option();
420 $custom_css = berocket_sanitize_array($options[ 'custom_css' ], array($this->cc->values[ 'settings_name' ]), $previous_options);
421 echo '<style>' . $custom_css . '</style>';
422 }
423 public function set_scripts() {
424 $options = $this->get_option();
425 $javascript = br_get_value_from_array($options, array('javascript'));
426 $is_admin = current_user_can($this->option_page_capability());
427 if(is_array($javascript)) {
428 $html = '';
429 foreach($javascript as $trigger => $script) {
430 $script = trim($script);
431 if( ! empty($script) ) {
432 $function_name = strtolower($this->info['plugin_name'] . '_' . $trigger);
433 $function_name = preg_replace("/[^a-z0-9_\s-]/", "", $function_name);
434 $function_name = 'brjst_' . preg_replace("/[\s_-]+/", "_", $function_name);
435 $html .= 'function '.$function_name.'(){try{'.$script.'}catch(err){';
436 if( $is_admin ) {
437 $html .= 'alert("You have some incorrect custom JavaScript code (Plugin: '.$this->info['full_name'].', Trigger: '.$trigger.')");';
438 $html .= 'console.log(err);';
439 }
440 $html .= '}};';
441 if( $trigger == 'load' ) {
442 $html .='jQuery(document).ready('.$function_name.');';
443 } else {
444 $html .='jQuery(document).on("'.$trigger.'", '.$function_name.');';
445 }
446 }
447 }
448 $html = trim($html);
449 if( ! empty($html) ) {
450 echo '<script>', $html, '</script>';
451 }
452 }
453 }
454
455 /**
456 * Function adding styles/scripts and settings to admin_init WordPress action
457 *
458 * @access public
459 *
460 * @return void
461 */
462 public function admin_init() {
463 add_action('upgrader_process_complete', array($this, 'clear_product_data_transient'));
464 if( is_admin() ) {
465 $this->plugin_version_check();
466 }
467 if( isset($this->plugin_version_capability) && $this->plugin_version_capability <= 5 ) {
468 berocket_admin_notices::generate_subscribe_notice();
469 if( empty($this->feature_list) || ! is_array($this->feature_list) || ! count($this->feature_list) ) {
470 $products_info = $this->get_product_data_berocket($this->info['id']);
471 if( is_array($products_info) && isset($products_info['difference']) && is_array($products_info['difference']) ) {
472 $this->feature_list = $products_info['difference'];
473 }
474 }
475 }
476 require_once( plugin_dir_path( __FILE__ ) . 'includes/settings_fields.php');
477 wp_register_script(
478 'berocket_framework_admin',
479 plugins_url( 'assets/js/admin.js', __FILE__ ),
480 array( 'jquery' ),
481 BeRocket_Framework::$framework_version
482 );
483 wp_localize_script(
484 'berocket_framework_admin',
485 'berocket_framework_admin_text',
486 array(
487 'wizard_next' => __('Next', 'BeRocket_domain'),
488 'wizard_close' => __('Close', 'BeRocket_domain'),
489 )
490 );
491
492 wp_register_style(
493 'berocket_framework_admin_style',
494 plugins_url( 'assets/css/admin.css', __FILE__ ),
495 "",
496 BeRocket_Framework::$framework_version
497 );
498
499 wp_register_style(
500 'berocket_framework_global_admin_style',
501 plugins_url( 'assets/css/global-admin.css', __FILE__ ),
502 "",
503 BeRocket_Framework::$framework_version
504 );
505
506 wp_register_script(
507 'berocket_widget-colorpicker',
508 plugins_url( 'assets/js/colpick.js', __FILE__ ),
509 array( 'jquery' ),
510 BeRocket_Framework::$framework_version
511 );
512
513 wp_register_style(
514 'berocket_widget-colorpicker-style',
515 plugins_url( 'assets/css/colpick.css', __FILE__ ),
516 "",
517 BeRocket_Framework::$framework_version
518 );
519
520 wp_register_style(
521 'berocket_font_awesome',
522 plugins_url( 'assets/css/font-awesome.min.css', __FILE__ )
523 );
524 wp_localize_script( 'berocket_framework_admin', 'berocket_framework_admin', array(
525 'security' => wp_create_nonce("search-products")
526 ) );
527 if( ! empty($_GET['page']) && $_GET['page'] == $this->cc->values[ 'option_page' ] ) {
528 if( function_exists('wp_enqueue_code_editor') ) {
529 wp_enqueue_code_editor(
530 array(
531 'type' => 'css',
532 ) );
533 }
534 wp_enqueue_script( 'berocket_framework_admin' );
535
536 wp_enqueue_style( 'berocket_framework_admin_style' );
537
538 wp_enqueue_script( 'berocket_widget-colorpicker' );
539
540 wp_enqueue_style( 'berocket_widget-colorpicker-style' );
541
542 wp_enqueue_style( 'berocket_font_awesome' );
543 }
544
545 wp_enqueue_style( 'berocket_framework_global_admin_style' );
546
547 add_filter('option_page_capability_'.$this->cc->values[ 'option_page' ], array($this, 'option_page_capability'));
548 }
549
550 public function option_page_capability($capability = '') {
551 return 'manage_berocket';
552 }
553
554 /**
555 * Function add options button to admin panel if there are 3+ plugins from BeRocket and return false
556 * Other way it return true asking main function to add own options page
557 *
558 * @access public
559 *
560 * @return boolean
561 */
562 public function admin_menu() {
563 register_setting($this->cc->values[ 'option_page' ], $this->cc->values[ 'settings_name' ], array($this->cc, 'save_settings_callback'));
564 if ( method_exists( 'BeRocket_updater', 'get_plugin_count' ) ) {
565 add_submenu_page(
566 'berocket_account',
567 $this->cc->info[ 'norm_name' ] . ' ' . __( 'Settings', 'BeRocket_domain' ),
568 $this->cc->info[ 'norm_name' ],
569 $this->option_page_capability(),
570 $this->cc->values[ 'option_page' ],
571 array(
572 $this->cc,
573 'option_form'
574 )
575 );
576
577 return false;
578 }
579
580 return true;
581 }
582
583 /**
584 * Function add options form to settings page
585 *
586 * @return void
587 */
588 public function option_form() {
589 include __DIR__ . "/templates/settings.php";
590 }
591 public function admin_settings( $tabs_info = array(), $data = array() ) {
592 $setup_style = func_get_args();
593 $setup_style = (empty($setup_style[2]) || ! is_array($setup_style[2]) ? array() : $setup_style[2]);
594 $setup_style['settings_url'] = admin_url( 'admin.php?page=' . $this->cc->values[ 'option_page' ] );
595 $this->display_admin_settings($tabs_info, $data, $setup_style);
596 }
597
598 /**
599 * Function generate settings page
600 *
601 * @var $data - array with settings data, page will be build using this
602 *
603 * @return string
604 */
605 public function display_admin_settings( $tabs_info = array(), $data = array(), $setup_style = array() ) {
606 $plugin_info = get_plugin_data( $this->cc->info[ 'plugin_file' ] );
607 global $wp;
608 $settings_url = add_query_arg( NULL, NULL );
609 $settings_url = esc_url_raw($settings_url);
610 $def_setup_style = array(
611 'settings_url' => $settings_url,
612 'use_filters_hook' => true,
613 'hide_header' => false,
614 'hide_header_links' => false,
615 'hide_save_button' => false,
616 'hide_form' => false,
617 'hide_additional_blocks' => false,
618 'header_name' => "{$this->cc->info['norm_name']} by BeRocket",
619 'header_description' => str_replace( ' By BeRocket.', '', strip_tags( $plugin_info['Description'] ) ),
620 'settings_name' => $this->cc->values['settings_name'],
621 'options' => $this->get_option(),
622 'name_for_filters' => $this->cc->info[ 'plugin_name' ]
623 );
624 $setup_style = array_merge($def_setup_style, $setup_style);
625 if( $setup_style['use_filters_hook'] ) {
626 $tabs_info = apply_filters('brfr_tabs_info_' . $setup_style['name_for_filters'], $tabs_info);
627 $data = apply_filters('brfr_data_' . $setup_style['name_for_filters'], $data);
628 }
629 if ( isset($data) and is_array($data) and count( $data ) ) {
630 $page_menu = '';
631 $is_first = true;
632 $title = '';
633 $options = $setup_style['options'];
634
635 $selected_tab = false;
636 if( ! empty($_GET['tab']) ) {
637 foreach ( $tabs_info as $tab_name => $tab_info ) {
638 if( sanitize_title( $tab_name ) == $_GET['tab'] ) {
639 $selected_tab = true;
640 }
641 }
642 }
643
644 foreach ( $tabs_info as $tab_name => $tab_info ) {
645 if( isset($tab_info['name']) ) {
646 $display_name = $tab_info['name'];
647 } else {
648 $display_name = $tab_name;
649 }
650 $page_menu .= '<li>';
651
652 $page_menu .= '<a href="' . ( empty($tab_info['link']) ? add_query_arg('tab', sanitize_title( $tab_name ), $setup_style['settings_url']) : $tab_info['link'] ) .
653 '" class="' . ( empty($tab_info['priority']) ? 'default' : $tab_info['priority'] ) .
654 ( empty($tab_info['link']) ? '' : ' redirect_link' ) .
655 ( $selected_tab ? ( sanitize_title( $tab_name ) == $_GET['tab'] ? ' active' : '' ) : ( $is_first ? ' active' : '' ) ) .
656 '" data-block="' . ( empty($tab_info['link']) ? 'berocket_framework_menu_' . sanitize_title( $tab_name ) : 'redirect_link' ) . '">';
657 if ( $tab_info['icon'] ) {
658 $page_menu .= '<span class="fa fa-' . $tab_info['icon'] . '"></span>';
659 }
660 $page_menu .= $display_name . '</a>';
661
662 $page_menu .= '</li>';
663
664 if ( ($selected_tab && sanitize_title( $tab_name ) == $_GET['tab'] ) || ( ! $selected_tab && $is_first ) ) {
665 if ( $tab_info['icon'] ) {
666 $title .= '<span class="fa fa-' . $tab_info['icon'] . '"></span>';
667 }
668 $title .= $display_name;
669 }
670
671 $is_first = false;
672 }
673 if( ! $setup_style['hide_save_button'] ) {
674 $page_menu .= '<li class="berocket_framework_sidebar_save_button"><input type="submit" class="button-primary button" value="' . __( 'Save Changes', 'BeRocket_domain' ) . '" /></li>';
675 }
676 if( $setup_style['use_filters_hook'] ) {
677 $page_menu = apply_filters('brfr_page_menu_' . $setup_style['name_for_filters'], $page_menu, $tabs_info);
678 }
679
680 $is_first = true;
681 $page_content = '';
682
683 foreach ( $data as $tab_name => $tab_content ) {
684 $page_content .= '<div class="nav-block berocket_framework_menu_' . sanitize_title( $tab_name ) . '-block ' . ( $selected_tab ? ( sanitize_title( $tab_name ) == $_GET['tab'] ? ' nav-block-active' : '' ) : ( $is_first ? ' nav-block-active' : '' ) ) . '">';
685 $page_content .= '<table class="framework-form-table berocket_framework_menu_' . sanitize_title( $tab_name ) . '">';
686
687 if ( isset($tab_content) and is_array($tab_content) and count( $tab_content ) ) {
688 foreach ( $tab_content as $item ) {
689 $item = apply_filters('brfr_menu_item_remove_'.$this->info['plugin_name'], $item, $tab_name, $tab_content);
690 if( empty($item) ) continue;
691 $class = $extra = '';
692
693 if ( isset($item['class']) && trim( $item['class'] ) ) {
694 $class = " class='" . trim( $item['class'] ) . "'";
695 }
696
697 if ( isset($item['extra']) && trim( $item['extra'] ) ) {
698 $extra = " " . trim( $item['extra'] );
699 }
700
701 $item['tr_class'] = (empty($item['tr_class']) ? '' : ' class="'.$item['tr_class'].'"');
702 $page_content .= "<tr".$item['tr_class'].">";
703
704 if ( empty($item['section']) or $item['section'] == 'field' ) {
705 $item['td_class'] = (empty($item['td_class']) ? '' : ' class="'.$item['td_class'].'"');
706 $page_content .= '<th scope="row">' . $item['label'] .'</th><td'.$item['td_class'].'>';
707
708 $field_items = array();
709 if( isset($item['items']) && is_array($item['items']) ) {
710 $field_items = $item['items'];
711 } else {
712 $field_items[] = $item;
713 }
714 $item_i = 0;
715 foreach( $field_items as $item_key => $field_item ) {
716 $class = $extra = $item_content = '';
717 if ( isset($field_item['class']) && trim( $field_item['class'] ) ) {
718 $class = " class='" . trim( $field_item['class'] ) . "'";
719 }
720
721 if ( isset($field_item['extra']) && trim( $field_item['extra'] ) ) {
722 $extra = " " . trim( $field_item['extra'] );
723 }
724 if( isset($option_values) ) {
725 unset($option_values);
726 }
727 if( empty($field_item['custom_name']) && ! empty($field_item['name']) ) {
728 if( is_array($field_item['name']) ) {
729 $option_values = $options;
730 $option_deault_values = $this->cc->defaults;
731 foreach($field_item['name'] as $field_names) {
732 if( isset($option_values) && isset($field_names) && $field_names !== '' && isset($option_values[$field_names]) ) {
733 $option_values = $option_values[$field_names];
734 } else {
735 unset($option_values);
736 }
737 if( isset($option_values) && isset($field_names) && $field_names !== '' && isset($option_deault_values[$field_names]) ) {
738 $option_deault_values = $option_deault_values[$field_names];
739 } else {
740 unset($option_deault_values);
741 }
742 }
743 } elseif( isset($options[ $field_item['name'] ]) ) {
744 $option_values = $options[ $field_item['name'] ];
745 if( isset($this->cc->defaults[ $field_item['name'] ]) ) {
746 $option_deault_values = $this->cc->defaults[ $field_item['name'] ];
747 }
748 }
749 }
750 if( ! isset($option_values) ) {
751 $option_values = NULL;
752 }
753 if( ! isset($option_deault_values) ) {
754 $option_deault_values = NULL;
755 }
756 if ( $field_item['type'] != 'checkbox' and isset( $option_values ) ) {
757 $value = $option_values;
758 } else {
759 $value = $field_item['value'];
760 }
761 if( $item_i > 0 ) {
762 $page_content .= '<span class="br_line_delimiter"></span> ';
763 }
764 $field_item['label_for'] = ( isset($field_item['label_for']) ? $field_item['label_for'] : '' );
765 $field_item['label_be_for'] = ( isset($field_item['label_be_for']) ? $field_item['label_be_for'] : '' );
766
767 $field_name = (
768 empty($field_item['custom_name']) ?
769 (
770 empty($field_item['name']) ?
771 $setup_style['settings_name'] . '[]' :
772 (
773 is_array($field_item['name']) ?
774 $setup_style['settings_name'] . '[' . implode('][', $field_item['name']) . ']' :
775 $setup_style['settings_name'] . '[' . $field_item['name'] . ']'
776 )
777 ) :
778 $field_item['custom_name']
779 );
780 if( empty($field_item['type']) ) {
781 $field_item['type'] = 'text';
782 }
783 $item_filtered_content = apply_filters('berocket_framework_item_content_'.$field_item['type'], '', $field_item, $field_name, $value, $class, $extra, $option_values, $option_deault_values);
784 if( empty($item_filtered_content) ) {
785 $item_content .= "<td class='error'>Unsupported field type!</td>";
786 } else {
787 $item_content .= $item_filtered_content;
788 }
789 if( $setup_style['use_filters_hook'] ) {
790 $item_content = apply_filters('brfr_fields_html_' . $setup_style['name_for_filters'], $item_content, $field_name, $value, $field_item);
791 }
792 $page_content .= $item_content;
793 $item_i++;
794 }
795
796 $page_content .= '</td>';
797 } elseif ( $item['section'] == 'header' ) {
798 $page_content .= "
799 <th colspan='2'>
800 <h{$item['type']}" . $class . $extra . ">{$item['label']}</h{$item['type']}>
801 </th>";
802 } elseif ( $item['section'] == 'license' ) {
803 $page_content .= '
804 <th scope="row">' . __('Plugin key', 'BeRocket_domain') .'</th>
805 <td><div class="license-block">
806 <input id="berocket_product_key" size="50" name="' . $setup_style['settings_name'] . '[plugin_key]"
807 type="text" value="' . $options['plugin_key'] . '"/>
808 <input class="berocket_test_account_product button-secondary" data-id="' . $this->cc->info['id'] . '" type="button" value="Test"/>
809 <br />
810 <span style="color:#666666;margin-left:2px;">' . __('Key for plugin from BeRocket.com', 'BeRocket_domain') . '</span>
811 <br />
812 <div class="berocket_test_result"></div>
813 </div></td>';
814 } elseif ( method_exists( $this->cc, 'section_' . $item['section'] ) ) {
815 $section_filter = $this->cc->{'section_' . $item['section']}( $item, $options );
816 if( $setup_style['use_filters_hook'] ) {
817 $section_filter = apply_filters('brfr_' . $setup_style['name_for_filters'] . '_' . $item['section'], $section_filter, $item, $options, $setup_style['settings_name']);
818 }
819 $page_content .= $section_filter;
820 } else {
821 $section_filter = apply_filters('brfr_' . $setup_style['name_for_filters'] . '_' . $item['section'], '', $item, $options, $setup_style['settings_name']);
822 if( ! empty($section_filter) ) {
823 $page_content .= $section_filter;
824 } else {
825 $page_content .= "<th colspan='2' class='error'>Not supported section type `{$item['section']}`!</th>";
826 }
827 }
828
829 $page_content .= "</tr>";
830 }
831 }
832
833 $page_content .= '</table>';
834 $page_content .= '</div>';
835
836 $is_first = false;
837 }
838
839 if( $setup_style['use_filters_hook'] ) {
840 $page_content = apply_filters('brfr_page_content_' . $setup_style['name_for_filters'], $page_content, $data);
841 }
842
843 if( ! $setup_style['hide_header'] ) {
844 if( ! empty($this->plugin_version_capability) && $this->plugin_version_capability > 10 ) {
845 $meta_data = '?utm_source=paid_plugin&utm_medium=settings&utm_campaign='.$this->info['plugin_name'];
846 } else {
847 $meta_data = '?utm_source=free_plugin&utm_medium=settings&utm_campaign='.$this->info['plugin_name'];
848 }
849 echo "
850 <style>.notice:not(.berocket_admin_notice){display:none!important;}</style>
851 <header>
852 <div class='br_logo_white'>
853 <a href='https://berocket.com/plugins/{$meta_data}' title='BeRocket' target='_blank'><img src='" . ( plugins_url( 'assets/images/br_logo_white.webp', __FILE__ ) ) . "' /></a>
854 </div>
855 <nav class='premium'>";
856 if( ! $setup_style['hide_header_links'] ) {
857 $header_links = array(
858 'documentation' => array(
859 'text' => "<i class='fa fa-book'></i>",
860 'link' => apply_filters('brfr_docs_link_' . $setup_style['name_for_filters'],
861 "https://docs.berocket.com/plugin/{$this->cc->values['premium_slug']}" )
862 )
863 );
864 if( ! empty($this->plugin_version_capability) && $this->plugin_version_capability > 10 ) {
865 $header_links['support'] = array(
866 'text' => "<i class='fa fa-support'></i>",
867 'link' => apply_filters('brfr_support_link_' . $setup_style['name_for_filters'],
868 "https://berocket.com/support/support-{$this->cc->values['premium_slug']}{$meta_data}" )
869 );
870 } elseif( ! empty($this->cc->values['free_slug']) ) {
871 $header_links['support'] = array(
872 'text' => "<i class='fa fa-support'></i>",
873 'link' => apply_filters('brfr_support_link_' . $setup_style['name_for_filters'],
874 "https://wordpress.org/support/plugin/{$this->cc->values['free_slug']}{$meta_data}" )
875 );
876 }
877 $header_links = apply_filters('brfr_header_links_' . $setup_style['name_for_filters'], $header_links);
878 foreach($header_links as $header_link_title => $header_link) {
879 echo "<a href='" . $header_link['link'] . "' title='" . $header_link_title . "' target='_blank'>" . $header_link['text'] . "</a>";
880 }
881 }
882 echo "</nav>
883 <div class='br_plugin_name'>
884 <h1>{$setup_style['header_name']}</h1>
885 <h3>
886 {$setup_style['header_description']}
887 </h3>
888 </div>
889 </header>
890 ";
891 }
892 echo '<div class="body">';
893 echo '<ul class="side">';
894 echo $page_menu;
895 echo '</ul>';
896 echo '<div class="content">';
897 echo "<div class='title'>{$title}</div>";
898 if( ! $setup_style['hide_form'] ) {
899 echo '<form data-plugin="' . $this->cc->info['plugin_name'] . '" class="br_framework_submit_form ' . $this->cc->info['plugin_name'] . '_submit_form ' . ( ( isset($this->plugin_version_capability) && $this->plugin_version_capability <= 5 ) ? 'show_premium' : '' ) .
900 '" method="post" action="options.php">';
901 settings_fields( $_GET['page'] );
902 }
903 echo $page_content;
904 echo '<div class="clear-both"></div>';
905 if( ! $setup_style['hide_save_button'] ) {
906 echo '<input type="submit" class="berocket_framework_default_save_button button-primary button" value="' . __( 'Save Changes', 'BeRocket_domain' ) . '" />';
907 echo '<div class="br_save_error"></div>';
908 }
909 if( ! $setup_style['hide_form'] ) {
910 echo '</form>';
911 }
912 if( ! $setup_style['hide_additional_blocks'] ) {
913 if ( file_exists( $this->info['plugin_dir'] . '/templates/premium.php' ) ) {
914 require_once( $this->info['plugin_dir'] . '/templates/premium.php' );
915 } else {
916 require_once( plugin_dir_path( __FILE__ ) . 'templates/premium.php');
917 }
918 }
919 echo '</div>';
920 echo '<div class="clear-both"></div>';
921 echo '</div>';
922 }
923 }
924
925 /**
926 * Load template from theme | plugin
927 *
928 * @access public
929 *
930 * @param string $name template name
931 *
932 * @return void
933 */
934 public function br_get_template_part( $name = '' ) {
935 $template = '';
936
937 // Look in your_child_theme/woocommerce-%PLUGINNAME%/name.php
938 if ( $name ) {
939 $template = locate_template( "woocommerce-" . $this->cc->info[ 'plugin_name' ] . "/{$name}.php" );
940 }
941
942 // Get default slug-name.php
943 if ( ! $template && $name && file_exists( $this->cc->info[ 'templates' ] . "{$name}.php" ) ) {
944 $template = $this->cc->info[ 'templates' ] . "{$name}.php";
945 }
946
947 // Allow 3rd party plugin filter template file from their plugin
948 $template = apply_filters( $this->cc->info[ 'plugin_name' ] . '_get_template_part', $template, $name );
949
950 if ( $template ) {
951 load_template( $template, false );
952 }
953 }
954
955 /**
956 * Load admin file-upload scripts and styles
957 *
958 * @access public
959 *
960 * @return void
961 */
962 public static function admin_enqueue_scripts() {}
963 public static function wp_enqueue_media () {
964 if ( function_exists( 'wp_enqueue_media' ) ) {
965 wp_enqueue_media();
966 } else {
967 wp_enqueue_style( 'thickbox' );
968 wp_enqueue_script( 'media-upload' );
969 wp_enqueue_script( 'thickbox' );
970 }
971 }
972 public function save_settings_callback($settings) {
973 if ( isset( $settings ) ) {
974 $settings = $this->sanitize_option( $settings );
975 if( count($this->global_settings) ) {
976 $global_options = $this->get_global_option();
977 foreach($this->global_settings as $global_setting) {
978 if( isset($settings[$global_setting]) ) {
979 $global_options[$global_setting] = $settings[$global_setting];
980 }
981 }
982 $this->save_global_option($global_options);
983 }
984 }
985 return $settings;
986 }
987
988 /**
989 * Checking if we are on Settings page
990 *
991 * @access public
992 *
993 * @return boolean
994 */
995 public function check_screen() {
996 $screen = get_current_screen();
997 if ( $screen->id == 'woocommerce_page_br-' . $this->cc->info[ 'plugin_name' ] ) {
998 return true;
999 }
1000
1001 return false;
1002 }
1003
1004 /**
1005 * Sanitize option function
1006 *
1007 * @access public
1008 *
1009 * @return mixed
1010 */
1011 public function sanitize_option( $input ) {
1012 $previous_options = $this->get_option();
1013 $new_input = $this->recursive_array_set( $this->cc->defaults, $input );
1014 $new_input = berocket_sanitize_array($new_input, array($this->cc->values[ 'settings_name' ]), $previous_options);
1015 wp_cache_delete( $this->cc->values[ 'settings_name' ], 'berocket_framework_option' );
1016 return apply_filters('brfr_sanitize_option_' . $this->cc->info[ 'plugin_name' ], $new_input, $input, $this->cc->defaults);
1017 }
1018
1019 /**
1020 * Settings correct values for the array. If it exist in the input it will be used
1021 * if not - default will be used
1022 *
1023 * @access public
1024 *
1025 * @return mixed
1026 */
1027 public static function recursive_array_set( $default, $options ) {
1028 $result = array();
1029
1030 foreach ( $default as $key => $value ) {
1031 if ( array_key_exists( $key, $options ) ) {
1032 if ( is_array( $value ) ) {
1033 if ( is_array( $options[ $key ] ) ) {
1034 $result[ $key ] = self::recursive_array_set( $value, $options[ $key ] );
1035 } else {
1036 $result[ $key ] = self::recursive_array_set( $value, array() );
1037 }
1038 } else {
1039 $result[ $key ] = $options[ $key ];
1040 }
1041 } else {
1042 if ( is_array( $value ) ) {
1043 $result[ $key ] = self::recursive_array_set( $value, array() );
1044 } else {
1045 $result[ $key ] = '';
1046 }
1047 }
1048 }
1049
1050 foreach ( $options as $key => $value ) {
1051 if ( ! array_key_exists( $key, $result ) ) {
1052 $result[ $key ] = $value;
1053 }
1054 }
1055
1056 return $result;
1057 }
1058
1059 /**
1060 * Getting plugin option values
1061 *
1062 * @access public
1063 *
1064 * @return mixed
1065 */
1066 public function get_option() {
1067 if ( ! function_exists('icl_object_id') ) {
1068 $options = wp_cache_get( $this->cc->values[ 'settings_name' ], 'berocket_framework_option' );
1069 }
1070 if( empty($options) ) {
1071 $options = get_option( $this->cc->values[ 'settings_name' ] );
1072
1073 if ( ! empty($options) && is_array( $options ) ) {
1074 $options = array_merge( $this->cc->defaults, $options );
1075 } else {
1076 $options = $this->cc->defaults;
1077 }
1078 $options = apply_filters('brfr_get_option_cache_' . $this->cc->info[ 'plugin_name' ], $options, $this->cc->defaults);
1079 wp_cache_set( $this->cc->values[ 'settings_name' ], $options, 'berocket_framework_option', 600 );
1080 }
1081 $global_options = $this->get_global_option();
1082 if( count($this->global_settings) ) {
1083 foreach($this->global_settings as $global_setting) {
1084 if( isset($global_options[$global_setting]) ) {
1085 $options[$global_setting] = $global_options[$global_setting];
1086 }
1087 }
1088 }
1089
1090 $options = apply_filters('brfr_get_option_' . $this->cc->info[ 'plugin_name' ], $options, $this->cc->defaults);
1091
1092 return $options;
1093 }
1094 public function get_global_option() {
1095 $option = get_option('berocket_framework_option_global');
1096 if( ! is_array($option) ) {
1097 $option = array();
1098 }
1099 return $option;
1100 }
1101 public function save_global_option($option) {
1102 $option = update_option('berocket_framework_option_global', $option);
1103 return $option;
1104 }
1105 public function is_settings_page($settings_page) {
1106 if( ! empty($_GET['page']) && $_GET['page'] == $this->cc->values[ 'option_page' ] ) {
1107 $settings_page = true;
1108 }
1109 return $settings_page;
1110 }
1111
1112 public static function register_font_awesome($type = 'all') {
1113 if( $type == 'all' || $type == 'fa4' ) {
1114 wp_register_style( 'font-awesome', plugins_url( 'assets/css/font-awesome.min.css', __FILE__ ) );
1115 }
1116 if( $type == 'all' || $type == 'fa5' ) {
1117 wp_register_style( 'font-awesome-5', plugins_url( 'assets/css/fontawesome5.min.css', __FILE__ ) );
1118 }
1119 if( $type == 'all' || $type == 'fa5c' ) {
1120 wp_register_style( 'font-awesome-5-compat', plugins_url( 'assets/css/fontawesome4-compat.min.css', __FILE__ ) );
1121 }
1122 if( $type == 'fa5live' ) {
1123 add_action('admin_footer', array(__CLASS__, 'fa5live'));
1124 add_action('wp_footer', array(__CLASS__, 'fa5live'));
1125 wp_enqueue_style( 'font-awesome-5-compat', plugins_url( 'assets/css/fontawesome4-compat.min.css', __FILE__ ) );
1126 }
1127 }
1128 public static function fa5live() {
1129 echo '<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">';
1130 }
1131 public function plugin_version_check() {
1132 $plugins = get_option('BeRocket_Framework_plugins_version_check');
1133 if( empty($plugins) || ! is_array($plugins) ) {
1134 $plugins = array();
1135 }
1136 if( ! isset($plugins[$this->info['plugin_name']]) ) {
1137 $plugins[$this->info['plugin_name']] = '0';
1138 }
1139 if( $this->info['version'] != $plugins[$this->info['plugin_name']] ) {
1140 $this->update_version($plugins[$this->info['plugin_name']], $this->info['version']);
1141 $plugins[$this->info['plugin_name']] = $this->info['version'];
1142 }
1143 update_option('BeRocket_Framework_plugins_version_check', $plugins);
1144 }
1145 public function update_version($previous, $current) {
1146
1147 }
1148 public function init_user_capabilities($user_caps) {
1149 $user_caps[] = $this->option_page_capability();
1150 return $user_caps;
1151 }
1152 //disable fields for not admin
1153 function sanitize_array_predefine($value, $array, $option_name, $previous_settings) {
1154 if( ! is_super_admin() && $this->search_disabled_settings($option_name) ) {
1155 array_shift($option_name);
1156 $value = br_get_value_from_array($previous_settings, $option_name);
1157 }
1158 return $value;
1159 }
1160 function sanitize_array_kses($apply, $array, $option_name, $previous_settings) {
1161 if( is_super_admin() && $this->search_disabled_settings($option_name) ) {
1162 $apply = false;
1163 }
1164 return $apply;
1165 }
1166 function menu_item_remove($item, $tab_name, $tab_content) {
1167 if ( is_array($item) && ( empty($item['section']) or $item['section'] == 'field' ) ) {
1168 $field_items = array();
1169 $single = false;
1170 if( isset($item['items']) && is_array($item['items']) ) {
1171 $field_items = $item['items'];
1172 } else {
1173 $field_items[] = $item;
1174 $single = true;
1175 }
1176 $new_field_name = array();
1177 foreach($field_items as $field_name => $field_item) {
1178 $option_name = $field_item['name'];
1179 if( ! is_array($option_name) ) {
1180 $option_name = array($option_name);
1181 }
1182 array_unshift($option_name, $this->values[ 'settings_name' ]);
1183 if( ! is_super_admin() && $this->search_disabled_settings($option_name) ) {
1184 $field_item['disabled'] = true;
1185 $field_item['admin_disabled'] = true;
1186 }
1187 $new_field_name[$field_name] = $field_item;
1188
1189 }
1190 if( count($new_field_name) > 0 ) {
1191 if( $single ) {
1192 $item = array_pop($new_field_name);
1193 } else {
1194 $item['items'] = $new_field_name;
1195 }
1196 } else {
1197 $item = false;
1198 }
1199 } elseif( ! empty($item['name']) ) {
1200 $option_name = $item['name'];
1201 if( ! is_array($option_name) ) {
1202 $option_name = array($option_name);
1203 }
1204 array_unshift($option_name, $this->values[ 'settings_name' ]);
1205 if( ! is_super_admin() &&$this->search_disabled_settings($option_name) ) {
1206 $item = false;
1207 }
1208 }
1209 return $item;
1210 }
1211 function search_disabled_settings($option_name) {
1212 $disable = false;
1213 if( is_array($this->disable_settings_for_admin) && count($this->disable_settings_for_admin) > 0 ) {
1214 foreach($this->disable_settings_for_admin as $search_option_name) {
1215 array_unshift($search_option_name, $this->values[ 'settings_name' ]);
1216 if(berocket_check_array_same($option_name, $search_option_name) ) {
1217 $disable = true;
1218 }
1219 }
1220 }
1221 return $disable;
1222 }
1223 function disable_for_old_plugins($apply, $array, $option_name, $previous_settings) {
1224 if( is_array($option_name) && count($option_name) > 0 ) {
1225 $base_name = array_shift($option_name);
1226 if( $base_name === $this->values[ 'settings_name' ] && version_compare($this->plugin_framework_version, '2.7', '<') ) {
1227 $apply = false;
1228 }
1229 }
1230 return $apply;
1231 }
1232 function hpos_compatible() {
1233 if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
1234 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', $this->info['plugin_file'], ( ! empty($this->values['hpos_comp']) ) );
1235 }
1236 }
1237 }
1238 add_action('admin_init', 'BeRocket_admin_init_user_capabilities');
1239 function BeRocket_admin_init_user_capabilities() {
1240 global $wp_roles;
1241 $role_names = $wp_roles->get_names();
1242 $berocket_roles = apply_filters('BeRocket_admin_init_user_capabilities', array('manage_berocket', 'manage_berocket_account'));
1243 foreach($role_names as $role_name => $role_text) {
1244 $role_object = get_role( $role_name );
1245 if( $role_object->has_cap( 'manage_options' ) || $role_name == 'administrator' ) {
1246 foreach($berocket_roles as $berocket_role) {
1247 $role_object->add_cap( $berocket_role );
1248 }
1249 }
1250 }
1251 }
1252 }
1253