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