PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.13
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.13
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmInbox.php +21 -66 6.256.13 View file →
@@ -18,9 +18,9 @@
18 18 * @var array
19 19 */
20 20 private static $banner_messages;
21 21
22 - public function __construct() {
22 + public function __construct( $for_parent = null ) {
23 23 $this->set_cache_key();
24 24
25 25 if ( false === self::$messages ) {
26 26 $this->set_messages();
@@ -109,9 +109,9 @@
109 109 // Don't replace messages unless required.
110 110 return;
111 111 }
112 112
113 - if ( ! $this->within_valid_timeframe( $message ) ) {
113 + if ( $this->is_expired( $message ) ) {
114 114 return;
115 115 }
116 116
117 117 if ( isset( self::$messages[ $message['key'] ] ) ) {
@@ -158,10 +158,10 @@
158 158 $removed = false;
159 159 foreach ( self::$messages as $t => $message ) {
160 160 $read = ! empty( $message['read'] ) && isset( $message['read'][ get_current_user_id() ] ) && $message['read'][ get_current_user_id() ] < strtotime( '-1 month' );
161 161 $dismissed = ! empty( $message['dismissed'] ) && isset( $message['dismissed'][ get_current_user_id() ] ) && $message['dismissed'][ get_current_user_id() ] < strtotime( '-1 week' );
162 -
163 - if ( $read || $dismissed || ! $this->within_valid_timeframe( $message ) ) {
162 + $expired = $this->is_expired( $message );
163 + if ( $read || $expired || $dismissed ) {
164 164 unset( self::$messages[ $t ] );
165 165 $removed = true;
166 166 }
167 167 }
@@ -179,9 +179,9 @@
179 179 public function filter_messages( &$messages, $type = 'unread' ) {
180 180 $user_id = get_current_user_id();
181 181 foreach ( $messages as $k => $message ) {
182 182 $dismissed = isset( $message['dismissed'] ) && isset( $message['dismissed'][ $user_id ] );
183 - if ( empty( $k ) || ! $this->within_valid_timeframe( $message ) || ( $type === 'dismissed' ) !== $dismissed ) {
183 + if ( empty( $k ) || $this->is_expired( $message ) || ( $type === 'dismissed' ) !== $dismissed ) {
184 184 unset( $messages[ $k ] );
185 185 } elseif ( ! $this->is_for_user( $message ) ) {
186 186 unset( $messages[ $k ] );
187 187 }
@@ -189,40 +189,12 @@
189 189 $messages = apply_filters( 'frm_filter_inbox', $messages );
190 190 }
191 191
192 192 /**
193 - * Check if a message has started and is not expired.
194 - *
195 - * @since 6.25
196 - *
197 193 * @param array $message
198 - * @return bool
199 - */
200 - private function within_valid_timeframe( $message ) {
201 - return $this->has_started( $message ) && ! $this->is_expired( $message );
202 - }
203 -
204 - /**
205 - * Check if a message has actually started, so we can prevent showing something that is queued up early.
206 194 *
207 - * @since 6.25
208 - *
209 - * @param array $message
210 195 * @return bool
211 196 */
212 - private function has_started( $message ) {
213 - if ( empty( $message['starts'] ) ) {
214 - return true;
215 - }
216 -
217 - return $message['starts'] <= time();
218 - }
219 -
220 - /**
221 - * @param array $message
222 - *
223 - * @return bool
224 - */
225 197 private function is_expired( $message ) {
226 198 return ! empty( $message['expires'] ) && $message['expires'] < time();
227 199 }
228 200
@@ -232,14 +204,18 @@
232 204 * @param array $message
233 205 * @return bool
234 206 */
235 207 private function is_for_user( $message ) {
236 - if ( FrmApiHelper::is_for_user( $message ) ) {
208 + if ( ! isset( $message['who'] ) || $message['who'] === 'all' ) {
237 209 return true;
238 210 }
239 -
240 211 $who = (array) $message['who'];
241 -
212 + if ( in_array( 'all', $who, true ) || in_array( 'everyone', $who, true ) ) {
213 + return true;
214 + }
215 + if ( in_array( $this->get_user_type(), $who, true ) ) {
216 + return true;
217 + }
242 218 /**
243 219 * Allow for other special inbox cases in other add-ons.
244 220 *
245 221 * @since 6.8.1
@@ -250,8 +226,16 @@
250 226 */
251 227 return (bool) apply_filters( 'frm_inbox_message_is_for_user', false, $who, $message );
252 228 }
253 229
230 + private function get_user_type() {
231 + if ( ! FrmAppHelper::pro_is_installed() ) {
232 + return 'free';
233 + }
234 +
235 + return FrmAddonsController::license_type();
236 + }
237 +
254 238 /**
255 239 * @param string $key
256 240 *
257 241 * @return void
@@ -526,40 +510,11 @@
526 510
527 511 return array_reduce(
528 512 $keys_to_return,
529 513 function ( $total, $key ) use ( $message ) {
530 - $total[ $key ] = $message[ $key ] ?? '';
514 + $total[ $key ] = isset( $message[ $key ] ) ? $message[ $key ] : '';
531 515 return $total;
532 516 },
533 517 array()
534 518 );
535 - }
536 -
537 - /**
538 - * Clear the inbox cache by deleting the associated option from the database.
539 - *
540 - * @since 6.17
541 - *
542 - * @return void
543 - */
544 - public static function clear_cache() {
545 - delete_option( 'frm_inbox' );
546 - }
547 -
548 - /**
549 - * Check inbox for an "error" type. This is displayed on the form list page if one exists.
550 - *
551 - * @since 6.19
552 - *
553 - * @return array|false
554 - */
555 - public static function check_for_error() {
556 - $inbox = new self();
557 - $messages = $inbox->get_messages( 'filter' );
558 - foreach ( $messages as $message ) {
559 - if ( is_array( $message ) && isset( $message['type'] ) && 'error' === $message['type'] ) {
560 - return $message;
561 - }
562 - }
563 - return false;
564 519 }
565 520 }