PluginProbe
MaxButtons – Create buttons / 6.6
MaxButtons – Create buttons v6.6
6.23 6.24 6.25 6.26 6.26.1 6.27 6.28 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.1.1 7.1.2 7.1.3 7.10 7.11 7.13 7.13.1 7.13.2 7.13.3 All 100 releases
maxbuttons / classes / maxbuttons-class.php

maxbuttons-class.php in MaxButtons – Create buttons 6.6, at classes/maxbuttons-class.php

716 lines 22.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined('ABSPATH') or die('No direct access permitted');
3
4 define('MAXBUTTONS_VERSION_KEY', 'maxbuttons_version');
5
6 class maxButtonsPlugin
7 {
8
9 protected $installed_version = 0;
10 protected $plugin_name;
11 protected $plugin_url;
12 protected $plugin_path;
13 protected $debug_mode = false;
14 protected $footer = array();
15
16 protected static $notices = array();
17
18 protected $mainClasses = array();
19
20 protected static $instance;
21
22 /* Class constructor
23 Add hooks and actions used by this plugin. Sets plugin environment information
24 */
25 function __construct()
26 {
27 maxUtils::timeInit(); // benchmark timer init.
28
29 $this->plugin_url = self::get_plugin_url(); //plugins_url() . '/' . $this->plugin_name;
30 $this->plugin_path = self::get_plugin_path(); //plugin_dir_path($rootfile);
31 $this->plugin_name = trim(basename($this->plugin_path), '/');
32
33 $this->installed_version = get_option(MAXBUTTONS_VERSION_KEY);
34
35 if ( defined('MAXBUTTONS_DEBUG') && MAXBUTTONS_DEBUG)
36 $this->debug_mode = true;
37
38 add_action('plugins_loaded', array($this, 'load_textdomain'));
39
40 add_filter('widget_text', 'do_shortcode');
41 add_shortcode('maxbutton', array($this, 'shortcode'));
42
43 add_action("mb-footer", array($this, 'do_footer'),10,3);
44 add_action("wp_footer", array($this, "footer"));
45
46 // Media buttons
47 add_action('media_buttons', array($this,'media_button'));
48
49 add_filter('plugin_action_links', array($this, "plugin_action_links"), 10, 2);
50 add_filter('plugin_row_meta', array($this, 'plugin_row_meta'), 10, 2);
51
52 if( is_admin())
53 {
54 add_action('admin_enqueue_scripts', array($this,'add_admin_styles'));
55 add_action('admin_enqueue_scripts', array($this,'add_admin_scripts'));
56
57 add_action('admin_init', array($this,'register_settings' ));
58
59 add_action('admin_init', array($this, 'do_review_notice')); // Ask for review
60 add_action('admin_init', array('maxInstall','check_database'));
61
62 add_action('admin_menu', array($this, 'admin_menu'));
63 add_action('admin_footer', array($this, "footer"));
64 add_filter("admin_footer_text",array($this, "admin_footer_text"));
65
66 // errors in user space. No internal error but user output friendly issues
67 add_action("mb/editor/display_notices", array($this,"display_notices"), 99);
68 add_action("mb/collection/display_notices", array($this,"display_notices"), 99);
69 add_action('mb/header/display_notices', array($this, 'display_notices'), 99);
70
71 add_action("wp_ajax_getAjaxButtons", array('maxButtonsAdmin', 'getAjaxButtons'));
72 add_action("wp_ajax_set_review_notice_status", array($this, "setReviewNoticeStatus"));
73
74 // Collection AJAX
75 add_action("wp_ajax_collection-edit", array("maxCollections", "ajax_save"));
76 add_action('wp_ajax_mbpro_collection_block', array("maxCollections", "ajax_action")); // all block level ajax stuff - for logged in users - backend
77 add_action('wp_ajax_mb_button_action', array('maxButtons', "ajax_action"));
78 }
79 // FRONT AJAX
80 add_action('wp_ajax_mbpro_collection_block_front', array("maxCollections", "ajax_action_front")); // front end for all users
81 add_action('wp_ajax_nopriv_mbpro_collection_block_front', array("maxCollections", "ajax_action_front"));
82
83 // front scripts
84 add_action('wp_enqueue_scripts', array($this, 'front_scripts'));
85
86 $this->setMainClasses(); // struct for override functionality
87
88 // The second the blocks are being loaded, check dbase integrity
89 add_action("mb_blockclassesloaded", array($this, "check_database"));
90
91 // setup page hooks and shortcode
92 add_shortcode('maxcollection', array($this, 'collection_shortcode'));
93 if (! is_admin())
94 $hook_bool = maxCollections::setupHooks(); // setup the hooks to insert collections
95
96 self::$instance = $this;
97 maxIntegrations::init(); // fire the integrations.
98 }
99
100 public static function getInstance()
101 {
102 return self::$instance;
103 }
104
105 public function setMainClasses()
106 {
107 $classes = array(
108 "button" => "maxButton",
109 "buttons" => "maxButtons",
110 "block" => "maxBlock",
111 "admin" => "maxButtonsAdmin",
112 "install" => "maxInstall",
113 "groups" => "maxGroups",
114 "collections" => "maxCollections",
115 "collection" => "maxCollection",
116 "pack" => "maxPack",
117
118 );
119
120 $this->mainClasses = $classes;
121 }
122
123 // from block loader action. Checks if all parts of the table are there, or panic if not.
124 public function check_database($blocks)
125 {
126 maxUtils::addTime("Check database");
127
128 $sql = "SELECT id,name,status,cache, created ";
129 foreach ($blocks as $block => $class)
130 {
131 $sql .= ", $block";
132 }
133 $sql .= " from " . maxUtils::get_table_name() . " limit 1";
134
135 global $wpdb;
136 $wpdb->hide_errors();
137 $result = $wpdb->get_results($sql);
138
139
140 // check this query for errors. If there is an error, one or more database fields are missing. Fix that.
141 if (isset($wpdb->last_error) && $wpdb->last_error != '')
142 {
143
144 $install = $this->getClass("install");
145 $install::create_database_table();
146 $install::migrate();
147 }
148
149
150 maxUtils::addTime("End check database");
151 }
152
153 public function getClass($class)
154 {
155
156 if (isset($this->mainClasses[$class]))
157 {
158 $load_class = $this->mainClasses[$class];
159 if (method_exists($load_class,'getInstance'))
160 {
161 return $load_class::getInstance();
162 }
163 return new $load_class;
164 }
165 }
166
167 /* Load the plugin textdomain */
168 public function load_textdomain()
169 {
170 // see: http://geertdedeckere.be/article/loading-wordpress-language-files-the-right-way
171 $domain = 'maxbuttons';
172 // The "plugin_locale" filter is also used in load_plugin_textdomain()
173 $locale = apply_filters('plugin_locale', get_locale(), $domain);
174
175 load_textdomain($domain, WP_LANG_DIR.'/maxbuttons/'.$domain.'-'.$locale.'.mo');
176 $res = load_plugin_textdomain('maxbuttons', false, $this->plugin_name . '/languages/');
177
178 }
179
180
181 public function register_settings()
182 {
183 register_setting( 'maxbuttons_settings', 'maxbuttons_user_level' );
184 register_setting( 'maxbuttons_settings', 'maxbuttons_noshowtinymce' );
185 register_setting( 'maxbuttons_settings', 'maxbuttons_minify' );
186 register_setting( 'maxbuttons_settings', 'maxbuttons_hidedescription' );
187 }
188
189 protected function checkbox_option($options)
190 {
191 if (! isset($options["maxbuttons_minify"]))
192 $options["maxbuttons_minify"] = 0;
193
194 return $options;
195
196 }
197
198 /** Returns the full path of the plugin installation directory */
199 public static function get_plugin_path()
200 {
201 return plugin_dir_path(MAXBUTTONS_ROOT_FILE);
202 }
203
204 /** Returns the full URL of the plugin installation path */
205 public static function get_plugin_url()
206 {
207 $url = plugin_dir_url(MAXBUTTONS_ROOT_FILE);
208 return $url;
209 }
210
211 /** Returns the current installed version */
212 public function get_installed_version()
213 {
214 return $this->installed_version;
215 }
216
217 /** Installs and adds the main menu and the submenu items */
218 function admin_menu() {
219 $maxbuttons_capabilities = get_option('maxbuttons_user_level');
220 if(!$maxbuttons_capabilities) {
221 $maxbuttons_capabilities = 'manage_options';
222 settings_fields( 'maxbuttons_settings' );
223 update_option('maxbuttons_user_level', $maxbuttons_capabilities);
224 }
225 $admin_pages = array();
226
227 $page_title = __('MaxButtons: Buttons', 'maxbuttons');
228 $menu_title = __('MaxButtons', 'maxbuttons');
229 $capability = $maxbuttons_capabilities;
230 $admin_capability = 'manage_options';
231 $menu_slug = 'maxbuttons-controller';
232 $function = array($this, 'load_admin_page');
233 $icon_url = $this->plugin_url . 'images/mb-peach-icon.png';
234 $submenu_function = array($this, 'load_admin_page');
235
236 add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url);
237
238 // We add this submenu page with the same slug as the parent to ensure we don't get duplicates
239 $sub_menu_title = __('Buttons', 'maxbuttons');
240 $admin_pages[] = add_submenu_page($menu_slug, $page_title, $sub_menu_title, $capability, $menu_slug, $function);
241
242 // Now add the submenu page for the Add New page
243 $submenu_page_title = __('MaxButtons: Add/Edit Button', 'maxbuttons');
244 $submenu_title = __('Add New', 'maxbuttons');
245 $submenu_slug = 'maxbuttons-controller&action=edit';
246 //$submenu_function = 'maxbuttons_button';
247 $admin_pages[] = add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $capability, $submenu_slug, $submenu_function);
248
249 // Now add the submenu page for the Export page
250 $submenu_page_title = __('MaxButtons: Social Share', 'maxbuttons');
251 $submenu_title = __('Social Share', 'maxbuttons');
252 $submenu_slug = 'maxbuttons-collections';
253 $admin_pages[] = add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $capability, $submenu_slug, $submenu_function);
254
255 // Now add the submenu page for the Go Pro page
256 $submenu_page_title = __('MaxButtons: Upgrade to Pro', 'maxbuttons');
257 $submenu_title = __('Upgrade to Pro', 'maxbuttons');
258 $submenu_slug = 'maxbuttons-pro';
259 //$submenu_function = 'maxbuttons_pro';
260 $admin_pages[] = add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $capability, $submenu_slug, $submenu_function);
261
262 // Now add the submenu page for the Settings page
263 $submenu_page_title = __('MaxButtons: Settings', 'maxbuttons');
264 $submenu_title = __('Settings', 'maxbuttons');
265 $submenu_slug = 'maxbuttons-settings';
266 //$submenu_function = 'maxbuttons_settings';
267 $admin_pages[] = add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $admin_capability, $submenu_slug, $submenu_function);
268
269 // Now add the submenu page for the Support page
270 $submenu_page_title = __('MaxButtons: Support', 'maxbuttons');
271 $submenu_title = __('Support', 'maxbuttons');
272 $submenu_slug = 'maxbuttons-support';
273 //$submenu_function = 'maxbuttons_support';
274 $admin_pages[] = add_submenu_page($menu_slug, $submenu_page_title, $submenu_title, $admin_capability, $submenu_slug, $submenu_function);
275
276 }
277
278 function load_admin_page($page)
279 {
280 $page = sanitize_text_field($_GET["page"]);
281
282 switch($page)
283 {
284 case "maxbuttons-button":
285 $pagepath = "includes/maxbuttons-button.php";
286 break;
287 case "maxbuttons-support":
288 $pagepath = "includes/maxbuttons-support.php";
289 break;
290 case "maxbuttons-settings":
291 $pagepath = "includes/maxbuttons-settings.php";
292 break;
293 case "maxbuttons-pro":
294 $pagepath = "includes/maxbuttons-pro.php";
295 break;
296 case "maxbuttons-collections":
297 $pagepath = "includes/maxbuttons-collections.php";
298 break;
299 default:
300 $pagepath = "includes/maxbuttons-controller.php";
301 break;
302 }
303 $pagepath = $this->plugin_path . $pagepath;
304
305 include(apply_filters("mb-load-admin-page-$page", $pagepath));
306 }
307
308
309 function add_admin_styles($hook) {
310 // only hook in maxbuttons realm.
311 if ( strpos($hook,'maxbuttons') === false && $hook != 'post.php' && $hook != 'post-new.php' )
312 {
313 if (! isset($_GET['fl_builder'])) // exception for beaver builder
314 return;
315 }
316
317 $fa_url = apply_filters("mb_fa_url", $this->plugin_url . 'assets/libraries/font-awesome/css/font-awesome.min.css');
318 if ($fa_url != false && $fa_url != '')
319 {
320 wp_register_style('mbpro-font-awesome', $fa_url );
321 wp_enqueue_style('mbpro-font-awesome');
322 }
323
324 wp_enqueue_style('wp-color-picker');
325 wp_enqueue_style('maxbuttons-css', $this->plugin_url . 'assets/css/style.css');
326
327 }
328
329 /** Add Admin scripts
330 *
331 * Uses WP hook for Admin scripts to add needed js.
332 */
333 function add_admin_scripts($hook) {
334 // only hook in maxbuttons realm.
335 if ( strpos($hook,'maxbuttons') === false ) //&& $hook != 'post.php' && $hook != 'post-new.php'
336 return;
337
338 $version = MAXBUTTONS_VERSION_NUM;
339
340 $js_url = trailingslashit($this->plugin_url . 'js');
341 if (! $this->debug_mode)
342 $js_url .= 'min/';
343
344
345 wp_enqueue_script('jquery-ui-draggable');
346
347 //wp_enqueue_script('maxbuttons-colorpicker-js', $js_url .'colpick.js', array('jquery'), $version, true);
348
349 wp_enqueue_script('maxbutton-admin', $js_url . 'maxbuttons-admin.js', array('jquery', 'jquery-ui-draggable', 'maxbuttons-tabs','maxbuttons-modal', 'wp-color-picker', 'underscore'),$version, true);
350 wp_enqueue_script('maxbutton-js-init', $js_url . 'init.js', array('maxbutton-admin','maxcollections','maxbuttons-modal'),$version, true);
351 wp_enqueue_script('maxbuttons-tabs', $js_url . 'maxtabs.js', array('jquery'),$version, true);
352
353
354 wp_register_script('maxcollections', $js_url . 'maxcollections.js',
355 array('jquery', 'maxbutton-admin', 'jquery-ui-sortable'),$version, true );
356
357 $local = array();
358 $local["ajaxurl"] = admin_url( 'admin-ajax.php' );
359 $local["maxurl"] = $this->plugin_url;
360 wp_localize_script('maxbutton-admin', 'mb_ajax', $local);
361
362 $local = array(
363 "leave_page" => __("You have unsaved data, are you sure you want to leave the page?","maxbuttons"),
364 'picker_title' => __('Select your buttons','maxbuttons'),
365
366 );
367 wp_localize_script('maxcollections', 'maxcol_wp', $local);
368
369 $this->load_modal_script();
370
371 wp_enqueue_script('maxcollections');
372 }
373
374 /** Load the Modal Script
375 * The modal script is the generic solution for all popups within the plugin.
376 */
377 public function load_modal_script()
378 {
379 $version = MAXBUTTONS_VERSION_NUM;
380 $js_url = trailingslashit($this->plugin_url . 'js');
381 if (! $this->debug_mode)
382 $js_url .= 'min/';
383
384 wp_register_script('maxbuttons-modal', $js_url . 'maxmodal.js', array('jquery','jquery-ui-draggable'), $version, true);
385 // translations of controls and other elements that can be used in maxmodal
386 $translations = array(
387 'yes' => __("Yes","maxbuttons"),
388 'no' => __("No","maxbuttons"),
389 'ok' => __("OK","maxbuttons"),
390 'cancel' => __("Cancel","maxbuttons"),
391 );
392 wp_localize_script('maxbuttons-modal', 'modaltext', $translations);
393 wp_enqueue_script('maxbuttons-modal');
394
395 }
396
397 /** Load Media Buttons Script
398
399 Useful for integrations that don't implement the media button but uses the media button JS for loading the button picker
400
401 */
402 public function load_media_script()
403 {
404 $version = MAXBUTTONS_VERSION_NUM;
405
406 $js_url = trailingslashit($this->plugin_url . 'js');
407 if (! $this->debug_mode)
408 $js_url .= 'min/';
409
410 $fa_url = apply_filters("mb_fa_url", $this->plugin_url . 'assets/libraries/font-awesome/css/font-awesome.min.css');
411 if ($fa_url != false && $fa_url != '')
412 {
413 wp_register_style('mbpro-font-awesome', $fa_url);
414 wp_enqueue_style('mbpro-font-awesome');
415 }
416
417 wp_enqueue_script('mb-media-button', $js_url . 'maxbuttons_media_button.js', array('jquery', 'maxbuttons-modal'), $version, true);
418 $this->load_modal_script();
419
420 $translations = array(
421 'insert' => __('Insert Button into Editor', 'maxbuttons'),
422 'loading' => __("Loading your buttons","maxbuttons"),
423 'select' => __('Click on a button from the list below to place the button shortcode in the editor.', 'maxbuttons'),
424 'cancel' => __('Cancel', 'maxbuttons'),
425 'windowtitle' => __("Select a MaxButton","maxbuttons"),
426 'icon' => $this->plugin_url . 'images/mb-peach-32.png',
427 'ajax_url' => admin_url( 'admin-ajax.php' ),
428 );
429
430 wp_localize_script('mb-media-button','mbtrans', $translations);
431 }
432
433 /** Load Media Button in WP editor
434 *
435 * The 'add button' interface in WP post and page editor to simplify adding buttons. Loads button plus required Javascript.
436 */
437 function media_button($editor_id) {
438 $output = '';
439
440 // options
441 if (get_option('maxbuttons_noshowtinymce') == 1) return;
442
443 $this->load_media_script();
444
445 // Only run in post/page creation and edit screens
446
447 $title = __('Add Button', 'maxbuttons');
448 $icon = $this->plugin_url . 'images/mb-peach-icon.png';
449 $img = '<span class="wp-media-buttons-icon" style="background-image: url(' . $icon . '); width: 16px; height: 16px; margin-top: 1px;"></span>';
450 $output = '<a href="javascript:void(0);" class="button maxbutton_media_button" data-callback="window.maxMedia.buttonToEditor" title="' . $title . '" style="padding-left: .4em;">' . $img . ' ' . $title . '</a>';
451
452 echo $output;
453 }
454
455 /** Scripts run on front-end
456 Load font-awesome, and limited javascript for the front-end. This is being kept extremely limited for performance reasons.
457 */
458 public function front_scripts()
459 {
460
461 $fa_url = apply_filters("mb_fa_url", $this->plugin_url . 'assets/libraries/font-awesome/css/font-awesome.min.css');
462 if ($fa_url != false && $fa_url != '')
463 {
464 wp_register_style('mbpro-font-awesome', $fa_url);
465 wp_enqueue_style('mbpro-font-awesome');
466 }
467
468 // load backend script on front in Beaver Builder
469 if (isset($_GET['fl_builder']))
470 {
471 $this->add_admin_styles('maxbuttons');
472 }
473
474 wp_enqueue_script('maxbuttons-front', $this->plugin_url . 'js/min/front.js', array('jquery'), true);
475 $local = array();
476 $local["ajaxurl"] = admin_url( 'admin-ajax.php' );
477
478 wp_localize_script('maxbuttons-front', 'mb_ajax', $local);
479 }
480
481 /** Extra text to display in admin footer */
482 function admin_footer_text($text)
483 {
484 if (! isset($_GET["page"]))
485 return $text;
486
487 if ( strpos($_GET["page"],'maxbuttons') === false)
488 return $text;
489 $text = '';
490
491 $text .= sprintf("If you like MaxButtons please give us a %s�
492
493
494
495
496 %s rating!",
497 "<a href='https://wordpress.org/support/view/plugin-reviews/maxbuttons#postform' target='_blank'>",
498 "</a>") ;
499 return $text;
500
501 }
502
503
504 function shortcode($atts)
505 {
506 $button = $this->getClass("button");
507 return $button->shortcode($atts);
508 }
509
510 public function collection_shortcode($atts, $content = null)
511 {
512 $atts = shortcode_atts(array(
513 "id" => 0,
514 "name" => '',
515 "nocache" => false, // these are button options.
516 "mode" => "normal",
517 "style" => "footer",
518 ),
519
520 $atts);
521
522 $id = intval($atts["id"]);
523 $name = sanitize_text_field($atts["name"]);
524
525 if ($id > 0)
526 $collection = maxCollections::getCollectionByID($id);
527 elseif ($atts["name"] != '')
528 $collection = maxCollections::getCollectionByName($name);
529
530
531 if ($collection)
532 return $collection->shortcode($atts,$content);
533
534 }
535
536
537 function plugin_action_links($links, $file) {
538
539 if ($file == plugin_basename(dirname(MAXBUTTONS_ROOT_FILE) . '/maxbuttons.php')) {
540 $label = __('Buttons', 'maxbuttons');
541 $dashboard_link = '<a href="' . admin_url() . 'admin.php?page=maxbuttons-controller&action=list">' . $label . '</a>';
542 array_unshift($links, $dashboard_link);
543 }
544
545 return $links;
546 }
547
548
549 function plugin_row_meta($links, $file) {
550 if ($file == plugin_basename(dirname(__FILE__) . '/maxbuttons.php')) {
551 $links[] = sprintf(__('%sUpgrade to Pro Version%s', 'maxbuttons'), '<a href="http://maxbuttons.com/?ref=mbfree" target="_blank">', '</a>');
552 }
553
554 return $links;
555 }
556
557
558 function do_footer($id, $code, $type = "css")
559 {
560
561 $this->footer[$type][$id] = $code;
562
563 }
564 function footer()
565 {
566 if(count($this->footer) == 0) return; // nothing
567
568 foreach ($this->footer as $type => $part)
569 {
570 // add tag
571 if ($type == 'css')
572 {
573 echo "<!--email_off--><style type='text/css'>";
574 }
575 foreach ($part as $id => $statements)
576 {
577 if (strlen($statements) > 0) // prevent whitespace
578 echo $statements . "\n";
579 }
580 if ($type == 'css')
581 {
582 echo "</style><!--/email_off-->\n";
583 }
584 }
585
586 }
587
588 public function do_review_notice () {
589
590 $current_user_id = get_current_user_id();
591 $review = get_user_meta( $current_user_id, 'maxbuttons_review_notice' , true );
592
593 if ($review == '')
594 {
595 //$created = get_option("MBFREE_CREATED");
596 $show = time() + (7* DAY_IN_SECONDS);
597 update_user_meta($current_user_id, 'maxbuttons_review_notice', $show);
598 return;
599 }
600
601
602 $display_review = false;
603
604 if ($review == 'off')
605 { return; // no show
606
607 }
608 elseif (is_numeric($review))
609 {
610 $now = time();
611
612 if ($now > $review)
613 {
614 $display_review = true;
615
616 }
617 }
618
619 // load style / script. It's seperated since it should show everywhere in admin.
620 if ($display_review)
621 {
622 add_action( 'admin_notices', array('maxAdmin', 'mb_review_notice'));
623 wp_enqueue_style('maxbuttons-review-notice', $this->plugin_url . 'assets/css/review_notice.css');
624 wp_enqueue_script('maxbuttons-review-notice', $this->plugin_url . 'js/min/review-notice.js', array('jquery'), true);
625
626 $local = array();
627 $local["ajaxurl"] = admin_url( 'admin-ajax.php' );
628 wp_localize_script('maxbuttons-review-notice', 'mb_ajax_review', $local);
629 }
630
631 }
632
633 public function setReviewNoticeStatus()
634 {
635 $status = isset($_POST["status"]) ? sanitize_text_field($_POST["status"]) : '';
636 $current_user_id = get_current_user_id();
637
638 $updated = false;
639
640 if ($status == 'off')
641 {
642 $updated = true;
643 update_user_meta($current_user_id, 'maxbuttons_review_notice', 'off');
644
645 }
646 if ($status == 'later')
647 {
648 $updated = true;
649 $later = time() + (14 * DAY_IN_SECONDS );
650
651 update_user_meta($current_user_id, 'maxbuttons_review_notice', $later);
652 }
653 if ($status == 'reviewoffer-dismiss') // different ad!
654 {
655 $updated = true;
656 update_user_meta($current_user_id, 'maxbuttons_review_offer', 'off');
657
658 }
659
660 echo json_encode(array("updated" => $updated)) ;
661
662 exit();
663 }
664
665 /* Add a notice
666
667 The added notice will be displayed to the user in WordPress format.
668 @see display_notices
669
670 @param $type string message | notice | error | fatal
671 @param $message string User understandable message
672
673 */
674 public static function add_notice($type, $message)
675 {
676 self::$notices[] = array("type" => $type,
677 "message" => $message
678 );
679
680 }
681
682 /* Display all notices
683
684 Then notices added by @see add_notice will be displayed. This function is called by an action hook
685
686 @param $echo echo the results or silently return.
687 @return string|null If not written to screen via echo, the HTML output will be returned
688 */
689 public function display_notices($echo = true)
690 {
691
692 if ($echo === '') $echo = true;
693 $notices = self::$notices;
694 $output = '';
695 if (count($notices) == 0)
696 return;
697
698 foreach($notices as $index => $notice)
699 {
700 $type = $notice["type"];
701 $message = $notice["message"];
702 $output .= "<div class='mb-message $type'> ";
703 $output .= $message ;
704 $output .= "</div>";
705 }
706
707 self::$notices = array(); // empty notices to prevent double display
708
709 if ($echo) echo $output;
710 else return $output;
711 }
712
713 } // class
714
715
716