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