PluginProbe
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification / 3.1.0
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification v3.1.0
5.12.0 5.13.0 5.13.1 5.11.0 5.10.0 5.9.0 5.8.0 5.8.1 5.7.0 5.6.2 5.6.3 5.6.1 5.6.0 5.5.0 5.4.0 5.3.2 5.3.1 5.1.6 5.1.5 trunk 2.1.5 2.11 2.12 2.13 2.15 All 47 releases
double-opt-in / core / Messages.class.php

Messages.class.php in Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification 3.1.0, at core/Messages.class.php

164 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace forge12\contactform7\CF7DoubleOptIn {
4
5 use Forge12\Shared\Logger;
6 use Forge12\Shared\LoggerInterface;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Class Messages
14 *
15 * @package forge12\contactform7\CF7DoubleOptIn
16 */
17 class Messages {
18 /**
19 * @var Messages|null
20 */
21 private static $instance;
22
23 /**
24 * @var array
25 */
26 private $messages = [];
27 private LoggerInterface $logger;
28
29 /**
30 * @return Messages|null
31 */
32 public static function getInstance() {
33 if ( null === self::$instance ) {
34 self::$instance = new Messages( Logger::getInstance() );
35 }
36
37 return self::$instance;
38 }
39
40 private function __clone() {
41
42 }
43
44 public function __wakeup() {
45
46 }
47
48 private function __construct( LoggerInterface $logger ) {
49 $this->logger = $logger;
50 }
51
52 public function get_logger() {
53 return $this->logger;
54 }
55
56 /**
57 * getAll function.
58 *
59 * @access public
60 * @return string
61 */
62 public function getAll() {
63 $this->get_logger()->info( 'Retrieving all messages and combining them into a single string.', [
64 'plugin' => 'double-opt-in',
65 ] );
66
67 if ( empty( $this->messages ) ) {
68 $this->get_logger()->warning( 'No messages found to combine.', [
69 'plugin' => 'double-opt-in',
70 ] );
71 return '';
72 }
73
74 $combined_messages = implode( "\n", $this->messages );
75
76 $this->get_logger()->debug( 'Combined ' . count($this->messages) . ' messages.', [
77 'plugin' => 'double-opt-in',
78 'message_count' => count( $this->messages ),
79 ] );
80
81 return $combined_messages;
82 }
83
84 /**
85 * add function.
86 *
87 * @access public
88 *
89 * @param mixed $message
90 * @param mixed $type
91 *
92 * @return void
93 */
94 public function add( $message, $type ) {
95 $this->get_logger()->info( 'Adding a new UI message.', [
96 'plugin' => 'double-opt-in',
97 'message' => $message,
98 'original_type' => $type,
99 ] );
100
101 // Convert the given message type to a specific CSS class.
102 switch ($type) {
103 case 'error':
104 $type = 'alert-danger';
105 $this->get_logger()->error( 'An error message has been added to the UI.', [
106 'plugin' => 'double-opt-in',
107 'message_content' => $message,
108 ] );
109 break;
110 case 'success':
111 $type = 'alert-success';
112 $this->get_logger()->info( 'A success message has been added to the UI.', [
113 'plugin' => 'double-opt-in',
114 'message_content' => $message,
115 ] );
116 break;
117 case 'info':
118 $type = 'alert-info';
119 $this->get_logger()->info( 'An info message has been added to the UI.', [
120 'plugin' => 'double-opt-in',
121 'message_content' => $message,
122 ] );
123 break;
124 case 'warning':
125 $type = 'alert-warning';
126 $this->get_logger()->warning( 'A warning message has been added to the UI.', [
127 'plugin' => 'double-opt-in',
128 'message_content' => $message,
129 ] );
130 break;
131 case 'offer':
132 $type = 'alert-offer';
133 $this->get_logger()->notice( 'An offer message has been added to the UI.', [
134 'plugin' => 'double-opt-in',
135 'message_content' => $message,
136 ] );
137 break;
138 case 'critical':
139 $type = 'alert-critical';
140 $this->get_logger()->critical( 'A critical message has been added to the UI.', [
141 'plugin' => 'double-opt-in',
142 'message_content' => $message,
143 ] );
144 break;
145 default:
146 $this->get_logger()->debug( 'An unknown message type was provided. Using default type.', [
147 'plugin' => 'double-opt-in',
148 'unknown_type' => $type,
149 ] );
150 // Fallback for unknown types
151 $type = 'alert-info';
152 break;
153 }
154
155 $this->messages[] = '<div class="box ' . \esc_attr( $type ) . '" role="alert">' . esc_html( $message ) . '</div>';
156
157 $this->get_logger()->debug( 'Message added to messages array.', [
158 'plugin' => 'double-opt-in',
159 'final_html' => end($this->messages),
160 'message_count' => count($this->messages),
161 ] );
162 }
163 }
164 }