PluginProbe
MaxButtons – Create buttons / 7.1.3
MaxButtons – Create buttons v7.1.3
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 7.1.3, at classes/maxbuttons-class.php

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