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