PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.10
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.10
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 +162 -23 6.46.10 View file →
@@ -14,9 +14,9 @@
14 14
15 15 private static $messages = false;
16 16
17 17 /**
18 - * @param array
18 + * @var array
19 19 */
20 20 private static $banner_messages;
21 21
22 22 public function __construct( $for_parent = null ) {
@@ -47,9 +47,9 @@
47 47
48 48 /**
49 49 * @since 4.05
50 50 *
51 - * @param false|string $filter
51 + * @param array|false $filter
52 52 */
53 53 public function get_messages( $filter = false ) {
54 54 $messages = self::$messages;
55 55 if ( $filter === 'filter' ) {
@@ -139,9 +139,10 @@
139 139 'subject' => '',
140 140 'icon' => 'frm_tooltip_icon',
141 141 'cta' => '',
142 142 'expires' => false,
143 - 'who' => 'all', // use 'free', 'personal', 'business', 'elite', 'grandfathered'
143 + // Use 'free', 'personal', 'business', 'elite', 'grandfathered'.
144 + 'who' => 'all',
144 145 'type' => '',
145 146 );
146 147
147 148 $message = array_merge( $defaults, $message );
@@ -155,10 +156,10 @@
155 156 */
156 157 private function clean_messages() {
157 158 $removed = false;
158 159 foreach ( self::$messages as $t => $message ) {
159 - $read = isset( $message['read'] ) && ! empty( $message['read'] ) && isset( $message['read'][ get_current_user_id() ] ) && $message['read'][ get_current_user_id() ] < strtotime( '-1 month' );
160 - $dismissed = isset( $message['dismissed'] ) && ! empty( $message['dismissed'] ) && isset( $message['dismissed'][ get_current_user_id() ] ) && $message['dismissed'][ get_current_user_id() ] < strtotime( '-1 week' );
160 + $read = ! empty( $message['read'] ) && isset( $message['read'][ get_current_user_id() ] ) && $message['read'][ get_current_user_id() ] < strtotime( '-1 month' );
161 + $dismissed = ! empty( $message['dismissed'] ) && isset( $message['dismissed'][ get_current_user_id() ] ) && $message['dismissed'][ get_current_user_id() ] < strtotime( '-1 week' );
161 162 $expired = $this->is_expired( $message );
162 163 if ( $read || $expired || $dismissed ) {
163 164 unset( self::$messages[ $t ] );
164 165 $removed = true;
@@ -170,15 +171,17 @@
170 171 }
171 172 }
172 173
173 174 /**
175 + * @param array $messages
176 + * @param string $type
174 177 * @return void
175 178 */
176 - private function filter_messages( &$messages ) {
179 + public function filter_messages( &$messages, $type = 'unread' ) {
177 180 $user_id = get_current_user_id();
178 181 foreach ( $messages as $k => $message ) {
179 182 $dismissed = isset( $message['dismissed'] ) && isset( $message['dismissed'][ $user_id ] );
180 - if ( empty( $k ) || $this->is_expired( $message ) || $dismissed ) {
183 + if ( empty( $k ) || $this->is_expired( $message ) || ( $type === 'dismissed' ) !== $dismissed ) {
181 184 unset( $messages[ $k ] );
182 185 } elseif ( ! $this->is_for_user( $message ) ) {
183 186 unset( $messages[ $k ] );
184 187 }
@@ -191,9 +194,9 @@
191 194 *
192 195 * @return bool
193 196 */
194 197 private function is_expired( $message ) {
195 - return isset( $message['expires'] ) && ! empty( $message['expires'] ) && $message['expires'] < time();
198 + return ! empty( $message['expires'] ) && $message['expires'] < time();
196 199 }
197 200
198 201 /**
199 202 * Show different messages for different accounts.
@@ -208,9 +211,21 @@
208 211 $who = (array) $message['who'];
209 212 if ( in_array( 'all', $who, true ) || in_array( 'everyone', $who, true ) ) {
210 213 return true;
211 214 }
212 - return in_array( $this->get_user_type(), $who, true );
215 + if ( in_array( $this->get_user_type(), $who, true ) ) {
216 + return true;
217 + }
218 + /**
219 + * Allow for other special inbox cases in other add-ons.
220 + *
221 + * @since 6.8.1
222 + *
223 + * @param bool $is_for_user
224 + * @param array $who
225 + * @param array $message
226 + */
227 + return (bool) apply_filters( 'frm_inbox_message_is_for_user', false, $who, $message );
213 228 }
214 229
215 230 private function get_user_type() {
216 231 if ( ! FrmAppHelper::pro_is_installed() ) {
@@ -238,12 +253,11 @@
238 253 $this->update_list();
239 254 }
240 255
241 256 /**
242 - * @param string $key
243 - *
244 257 * @since 4.05.02
245 258 *
259 + * @param string $key
246 260 * @return void
247 261 */
248 262 public function mark_unread( $key ) {
249 263 $is_read = isset( self::$messages[ $key ] ) && isset( self::$messages[ $key ]['read'] ) && isset( self::$messages[ $key ]['read'][ get_current_user_id() ] );
@@ -305,20 +319,32 @@
305 319 }
306 320 return $messages;
307 321 }
308 322
309 - public function unread_html() {
310 - $html = '';
323 + /**
324 + * @since 6.8.4 The $filtered parameter was added.
325 + *
326 + * @param bool $filtered
327 + * @return string
328 + */
329 + public function unread_html( $filtered = true ) {
311 330 $count = count( $this->unread() );
312 - if ( $count ) {
313 - $html = ' <span class="update-plugins frm_inbox_count"><span class="plugin-count">' . absint( $count ) . '</span></span>';
331 + if ( ! $count ) {
332 + return '';
333 + }
314 334
315 - /**
316 - * @since 4.06.01
317 - */
318 - $html = apply_filters( 'frm_inbox_badge', $html );
335 + $html = ' <span class="update-plugins frm_inbox_count"><span class="plugin-count">' . absint( $count ) . '</span></span>';
336 +
337 + if ( ! $filtered ) {
338 + return $html;
319 339 }
320 - return $html;
340 +
341 + /**
342 + * @since 4.06.01
343 + *
344 + * @param string $html
345 + */
346 + return (string) apply_filters( 'frm_inbox_badge', $html );
321 347 }
322 348
323 349 /**
324 350 * @since 4.05.02
@@ -323,9 +349,8 @@
323 349 /**
324 350 * @since 4.05.02
325 351 *
326 352 * @param string $key
327 - *
328 353 * @return void
329 354 */
330 355 public function remove( $key ) {
331 356 if ( isset( self::$messages[ $key ] ) ) {
@@ -350,13 +375,53 @@
350 375 if ( empty( self::$banner_messages ) ) {
351 376 return false;
352 377 }
353 378 $message = end( self::$banner_messages );
379 + $cta = self::get_prepared_banner_cta( $message['cta'] );
380 +
354 381 require FrmAppHelper::plugin_path() . '/classes/views/inbox/banner.php';
355 382 return true;
356 383 }
357 384
358 385 /**
386 + * Make sure that the CTA uses utm_medium=banner.
387 + *
388 + * @since 6.8.4
389 + *
390 + * @param string $cta
391 + * @return string
392 + */
393 + private static function get_prepared_banner_cta( $cta ) {
394 + $cta = str_replace( 'button-secondary', 'button-primary', $cta );
395 + return preg_replace_callback(
396 + '/href=("|\')(.*?)("|\')/',
397 + /**
398 + * Replace a single href attribute in the CTA.
399 + *
400 + * @param array $matches The regex results for a single match.
401 + * @return string
402 + */
403 + function ( $matches ) {
404 + $url = $matches[2];
405 + $parts = parse_url( $url );
406 +
407 + if ( '#' === $url ) {
408 + return 'href="#"';
409 + }
410 +
411 + $query = array();
412 + if ( isset( $parts['query'] ) ) {
413 + parse_str( $parts['query'], $query );
414 + }
415 + $query['utm_medium'] = 'banner';
416 + $parts['query'] = http_build_query( $query );
417 + return 'href="' . $parts['scheme'] . '://' . $parts['host'] . $parts['path'] . '?' . $parts['query'] . '"';
418 + },
419 + $cta
420 + );
421 + }
422 +
423 + /**
359 424 * @return void
360 425 */
361 426 public static function maybe_disable_screen_options() {
362 427 self::$banner_messages = self::get_banner_messages();
@@ -366,16 +431,90 @@
366 431 }
367 432 }
368 433
369 434 /**
435 + * Get all message with a "banner" mesage key defined.
436 + *
370 437 * @return array
371 438 */
372 439 private static function get_banner_messages() {
440 + return self::get_messages_with_key( 'banner' );
441 + }
442 +
443 + /**
444 + * Get all messages with a "slidein" message key defined.
445 + *
446 + * @since 6.8.4
447 + *
448 + * @return array
449 + */
450 + private static function get_slidein_messages() {
451 + return self::get_messages_with_key( 'slidein' );
452 + }
453 +
454 + /**
455 + * Get all messages with a $key message key defined.
456 + *
457 + * @since 6.8.4
458 + *
459 + * @param string $key The key we are checking for (ie. banner or slidein).
460 + * @return array
461 + */
462 + private static function get_messages_with_key( $key ) {
373 463 $inbox = new self();
374 464 return array_filter(
375 465 $inbox->get_messages( 'filter' ),
376 - function( $message ) {
377 - return ! empty( $message['banner'] );
466 + function ( $message ) use ( $key ) {
467 + return ! empty( $message[ $key ] );
378 468 }
469 + );
470 + }
471 +
472 + /**
473 + * Check if there is at least one slidein message.
474 + *
475 + * @since 6.8.4
476 + *
477 + * @return bool
478 + */
479 + public static function has_a_slidein_message() {
480 + return (bool) self::get_slidein_messages();
481 + }
482 +
483 + /**
484 + * Get the array used for frmGlobal.inboxSlideIn
485 + *
486 + * @since 6.8.4
487 + *
488 + * @return array|false
489 + */
490 + public static function get_inbox_slide_in_value_for_js() {
491 + $messages = self::get_slidein_messages();
492 + if ( ! $messages ) {
493 + return false;
494 + }
495 +
496 + $message = reset( $messages );
497 +
498 + /**
499 + * Extend the keys in the global JS object.
500 + * This is used in Pro to include images.
501 + *
502 + * @since 6.8.4
503 + *
504 + * @param array $keys
505 + */
506 + $keys_to_return = apply_filters(
507 + 'frm_inbox_slidein_js_vars',
508 + array( 'key', 'slidein', 'subject', 'cta' )
509 + );
510 +
511 + return array_reduce(
512 + $keys_to_return,
513 + function ( $total, $key ) use ( $message ) {
514 + $total[ $key ] = isset( $message[ $key ] ) ? $message[ $key ] : '';
515 + return $total;
516 + },
517 + array()
379 518 );
380 519 }
381 520 }