| 1 |
<?php |
| 2 |
|
| 3 |
namespace forge12\contactform7\CF7DoubleOptIn { |
| 4 |
if(!defined('ABSPATH')){ |
| 5 |
exit; |
| 6 |
} |
| 7 |
/** |
| 8 |
* Class Messages |
| 9 |
* @package forge12\contactform7\CF7DoubleOptIn |
| 10 |
*/ |
| 11 |
class Messages |
| 12 |
{ |
| 13 |
/** |
| 14 |
* @var Messages|null |
| 15 |
*/ |
| 16 |
private static $instance; |
| 17 |
|
| 18 |
/** |
| 19 |
* @var array |
| 20 |
*/ |
| 21 |
private $messages = []; |
| 22 |
|
| 23 |
/** |
| 24 |
* @return Messages|null |
| 25 |
*/ |
| 26 |
public static function getInstance() |
| 27 |
{ |
| 28 |
if (null === self::$instance) { |
| 29 |
self::$instance = new Messages(); |
| 30 |
} |
| 31 |
|
| 32 |
return self::$instance; |
| 33 |
} |
| 34 |
|
| 35 |
private function __clone() |
| 36 |
{ |
| 37 |
|
| 38 |
} |
| 39 |
|
| 40 |
public function __wakeup() |
| 41 |
{ |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
private function __construct() |
| 46 |
{ |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* getAll function. |
| 51 |
* |
| 52 |
* @access public |
| 53 |
* @return string |
| 54 |
*/ |
| 55 |
public function getAll() |
| 56 |
{ |
| 57 |
return implode("\n", $this->messages); |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* add function. |
| 62 |
* |
| 63 |
* @access public |
| 64 |
* @param mixed $message |
| 65 |
* @param mixed $type |
| 66 |
* @return void |
| 67 |
*/ |
| 68 |
public function add($message, $type) |
| 69 |
{ |
| 70 |
if ($type === 'error') { |
| 71 |
$type = 'alert-danger'; |
| 72 |
|
| 73 |
} elseif ($type === 'success') { |
| 74 |
$type = 'alert-success'; |
| 75 |
|
| 76 |
} elseif ($type === 'info') { |
| 77 |
$type = 'alert-info'; |
| 78 |
|
| 79 |
} elseif ($type === 'warning') { |
| 80 |
$type = 'alert-warning'; |
| 81 |
|
| 82 |
} elseif ($type === 'offer') { |
| 83 |
$type = 'alert-offer'; |
| 84 |
|
| 85 |
} elseif ($type === 'critical') { |
| 86 |
$type = 'alert-critical'; |
| 87 |
} |
| 88 |
|
| 89 |
$this->messages[] = '<div class="box ' . \esc_attr($type) . '" role="alert">' . esc_html($message) . '</div>'; |
| 90 |
} |
| 91 |
} |
| 92 |
} |