PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.22.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.22.2
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/controllers/FrmDashboardController.php +60 -74 6.346.22.2 View file →
@@ -20,9 +20,9 @@
20 20 *
21 21 * @return void
22 22 */
23 23 public static function load_admin_hooks() {
24 - add_action( 'admin_menu', self::class . '::menu', 9 );
24 + add_action( 'admin_menu', __CLASS__ . '::menu', 9 );
25 25 }
26 26
27 27 /**
28 28 * Register Dashboard page tp Formidable admin menu.
@@ -29,9 +29,9 @@
29 29 *
30 30 * @return void
31 31 */
32 32 public static function menu() {
33 - add_submenu_page( 'formidable', 'Formidable | ' . __( 'Dashboard', 'formidable' ), esc_html__( 'Dashboard', 'formidable' ) . wp_kses_post( FrmInboxController::get_notice_count() ), 'frm_view_forms', 'formidable-dashboard', 'FrmDashboardController::route' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
33 + add_submenu_page( 'formidable', 'Formidable | ' . __( 'Dashboard', 'formidable' ), esc_html__( 'Dashboard', 'formidable' ) . wp_kses_post( FrmInboxController::get_notice_count() ), 'frm_view_forms', 'formidable-dashboard', 'FrmDashboardController::route' );
34 34 }
35 35
36 36 /**
37 37 * Triggered from FrmAppController::load_page() with admin_init
@@ -45,9 +45,9 @@
45 45 self::load_assets();
46 46
47 47 $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count();
48 48
49 - add_filter( 'manage_' . sanitize_title( FrmAppHelper::get_menu_name() ) . ( $unread_count ? '-' . $unread_count : '' ) . '_page_formidable-dashboard_columns', 'FrmDashboardController::entries_columns' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
49 + add_filter( 'manage_' . sanitize_title( FrmAppHelper::get_menu_name() ) . ( $unread_count ? '-' . $unread_count : '' ) . '_page_formidable-dashboard_columns', 'FrmDashboardController::entries_columns' );
50 50 add_filter( 'frm_show_footer_links', '__return_false' );
51 51 add_filter( 'screen_options_show_screen', '__return_false' );
52 52 }
53 53
@@ -70,10 +70,11 @@
70 70 *
71 71 * @return FrmDashboardHelper
72 72 */
73 73 public static function get_dashboard_helper() {
74 - $total_payments = self::view_args_payments();
75 - $counters_value = array(
74 + $latest_available_form = FrmForm::get_latest_form();
75 + $total_payments = self::view_args_payments();
76 + $counters_value = array(
76 77 'forms' => FrmForm::get_forms_count(),
77 78 'entries' => FrmEntry::get_entries_count(),
78 79 );
79 80
@@ -78,15 +79,14 @@
78 79 );
79 80
80 81 return new FrmDashboardHelper(
81 82 array(
82 - 'counters' => array(
83 - 'counters' => self::view_args_counters( FrmForm::get_latest_form(), $counters_value ),
83 + 'counters' => array(
84 + 'counters' => self::view_args_counters( $latest_available_form, $counters_value ),
84 85 ),
85 - 'license' => array(),
86 - 'get_free_templates' => array(),
87 - 'inbox' => self::view_args_inbox(),
88 - 'entries' => array(
86 + 'license' => array(),
87 + 'inbox' => self::view_args_inbox(),
88 + 'entries' => array(
89 89 'widget-heading' => __( 'Latest Entries', 'formidable' ),
90 90 'cta' => array(
91 91 'label' => __( 'View All Entries', 'formidable' ),
92 92 'link' => admin_url( 'admin.php?page=formidable-entries' ),
@@ -94,10 +94,10 @@
94 94 'show-placeholder' => 0 >= (int) $counters_value['entries'],
95 95 'count' => $counters_value['entries'],
96 96 'placeholder' => self::view_args_entries_placeholder( $counters_value['forms'] ),
97 97 ),
98 - 'payments' => array(
99 - 'show-placeholder' => ! $total_payments,
98 + 'payments' => array(
99 + 'show-placeholder' => empty( $total_payments ),
100 100 'placeholder' => array(
101 101 'copy' => __( 'You don\'t have a payment form setup yet.', 'formidable' ),
102 102 'cta' => array(
103 103 'link' => admin_url( 'admin.php?page=formidable-form-templates' ),
@@ -111,9 +111,9 @@
111 111 'items' => $total_payments,
112 112 ),
113 113 ),
114 114 ),
115 - 'video' => array( 'id' => self::get_youtube_embed_video( $counters_value['entries'] ) ),
115 + 'video' => array( 'id' => self::get_youtube_embed_video( $counters_value['entries'] ) ),
116 116 )
117 117 );
118 118 }
119 119
@@ -122,9 +122,10 @@
122 122 *
123 123 * @return void
124 124 */
125 125 public static function route() {
126 - $dashboard_view = self::get_dashboard_helper();
126 + $dashboard_view = self::get_dashboard_helper();
127 +
127 128 $should_display_videos = is_callable( 'FrmProDashboardHelper::should_display_videos' ) ? FrmProDashboardHelper::should_display_videos() : true;
128 129
129 130 require FrmAppHelper::plugin_path() . '/classes/views/dashboard/dashboard.php';
130 131 }
@@ -137,9 +138,9 @@
137 138 *
138 139 * @return array
139 140 */
140 141 private static function view_args_counters( $latest_available_form, $counters_value ) {
141 - $add_entry_cta_link = false !== $latest_available_form && isset( $latest_available_form->id ) ? admin_url( 'admin.php?page=formidable-entries&frm_action=new&form=' . $latest_available_form->id ) : ''; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
142 + $add_entry_cta_link = false !== $latest_available_form && isset( $latest_available_form->id ) ? admin_url( 'admin.php?page=formidable-entries&frm_action=new&form=' . $latest_available_form->id ) : '';
142 143
143 144 $lite_counters = array(
144 145 self::view_args_build_counter( __( 'Total Forms', 'formidable' ), array(), $counters_value['forms'] ),
145 146 self::view_args_build_counter(
@@ -188,15 +189,15 @@
188 189 *
189 190 * @return array
190 191 */
191 192 public static function view_args_build_counter( $heading, $cta = array(), $value = 0, $type = 'default' ) {
193 +
192 194 $counter_args = array(
193 195 'heading' => $heading,
194 196 'counter' => $value,
195 197 'type' => 'default',
196 198 );
197 -
198 - if ( $cta ) {
199 + if ( ! empty( $cta ) ) {
199 200 $counter_args['cta'] = $cta;
200 201 }
201 202
202 203 return $counter_args;
@@ -224,12 +225,13 @@
224 225 *
225 226 * @return array
226 227 */
227 228 private static function view_args_payments() {
228 - $prepared_data = array();
229 +
230 + $prepared_data = array();
231 +
229 232 $model_payments = new FrmTransLitePayment();
230 233 $payments = $model_payments->get_payments_stats();
231 -
232 234 foreach ( $payments['total'] as $currency => $total_payments ) {
233 235 if ( 0 < (int) $total_payments ) {
234 236 $prepared_data[] = array(
235 237 'counter_label' => FrmCurrencyHelper::get_currency( $currency ),
@@ -244,17 +246,17 @@
244 246 /**
245 247 * Init view args for entries placeholder.
246 248 *
247 249 * @param array $forms_count The total forms count. If there are no any forms yet, we'll have CTA pointing to creating a form.
248 - *
249 250 * @return array
250 251 */
251 252 private static function view_args_entries_placeholder( $forms_count ) {
253 +
252 254 if ( ! $forms_count ) {
253 255 $copy = sprintf(
254 256 /* translators: %1$s: HTML start of a tag, %2$s: HTML close a tag */
255 257 __( 'See the %1$sform documentation%2$s for instructions on publishing your form', 'formidable' ),
256 - '<a target="_blank" href="' . esc_url( FrmAppHelper::admin_upgrade_link( '', 'knowledgebase/publish-a-form/' ) ) . '">',
258 + '<a target="_blank" href="' . FrmAppHelper::admin_upgrade_link( '', 'knowledgebase/publish-a-form/' ) . '">',
257 259 '</a>'
258 260 );
259 261 return array(
260 262 'background' => 'entries-placeholder',
@@ -269,9 +271,9 @@
269 271
270 272 $copy = sprintf(
271 273 /* translators: %1$s: HTML start of a tag, %2$s: HTML close a tag */
272 274 __( 'See the %1$sform documentation%2$s for instructions on publishing a form. Once vou have at least one entry you\'ll see it here.', 'formidable' ),
273 - '<a target="_blank" href="' . esc_url( FrmAppHelper::admin_upgrade_link( '', 'knowledgebase/publish-a-form/' ) ) . '">',
275 + '<a target="_blank" href="' . FrmAppHelper::admin_upgrade_link( '', 'knowledgebase/publish-a-form/' ) . '">',
274 276 '</a>'
275 277 );
276 278 return array(
277 279 'background' => 'entries-placeholder',
@@ -285,15 +287,17 @@
285 287 * A function to handle the counters cta from the top: Total Forms, Total Entries, All Views, Installed Apps.
286 288 *
287 289 * @param string $counter_type
288 290 * @param int $counter_value
289 - * @param false|object $latest_available_form The form object of the latest form available. If there are at least one
290 - * form available we show "Add Entry" cta for entries counter.
291 - *
291 + * @param false|object $latest_available_form The form object of the latest form available. If there are at least one form available we show "Add Entry" cta for entries counter.
292 292 * @return array
293 293 */
294 294 public static function display_counter_cta( $counter_type, $counter_value, $latest_available_form = false ) {
295 - return $counter_value <= 0 && ! ( 'entries' === $counter_type && false === $latest_available_form );
295 + if ( $counter_value > 0 || ( 'entries' === $counter_type && false === $latest_available_form ) ) {
296 + return false;
297 + }
298 +
299 + return true;
296 300 }
297 301
298 302 /**
299 303 * Hide 3rd party notifications from dashboard
@@ -305,9 +309,8 @@
305 309 return;
306 310 }
307 311
308 312 global $wp_filter;
309 -
310 313 if ( isset( $wp_filter['admin_notices'] ) ) {
311 314 unset( $wp_filter['admin_notices'] );
312 315 }
313 316 }
@@ -340,9 +343,8 @@
340 343 * Handle the entries list. Called via add_filter.
341 344 * Hook name: manage_formidable_page_formidable-dashboard_columns.
342 345 *
343 346 * @param array $columns An associative array of column headings.
344 - *
345 347 * @return array
346 348 */
347 349 public static function entries_columns( $columns = array() ) {
348 350 $columns['0_form_id'] = esc_html__( 'Form', 'formidable' );
@@ -357,10 +359,15 @@
357 359 *
358 360 * @return bool
359 361 */
360 362 public static function welcome_banner_has_closed() {
363 + $user_id = get_current_user_id();
361 364 $banner_closed_by_users = self::get_closed_welcome_banner_user_ids();
362 - return $banner_closed_by_users && in_array( get_current_user_id(), $banner_closed_by_users, true );
365 +
366 + if ( ! empty( $banner_closed_by_users ) && in_array( $user_id, $banner_closed_by_users, true ) ) {
367 + return true;
368 + }
369 + return false;
363 370 }
364 371
365 372 /**
366 373 * Check if is dashboard page.
@@ -374,13 +381,13 @@
374 381 /**
375 382 * Detect if the logged user's email is subscribed. Used for inbox email subscribe.
376 383 *
377 384 * @param string $email The logged user's email.
378 - *
379 385 * @return bool
380 386 */
381 387 public static function email_is_subscribed( $email ) {
382 - return in_array( $email, self::get_subscribed_emails(), true );
388 + $subscribed_emails = self::get_subscribed_emails();
389 + return in_array( $email, $subscribed_emails, true );
383 390 }
384 391
385 392 /**
386 393 * Register controller assets.
@@ -397,8 +404,9 @@
397 404 *
398 405 * @return void
399 406 */
400 407 public static function enqueue_assets() {
408 +
401 409 if ( ! self::is_dashboard_page() ) {
402 410 return;
403 411 }
404 412
@@ -418,35 +426,24 @@
418 426
419 427 /**
420 428 * Prepare inbox messages data.
421 429 *
422 - * @param array $data
423 - *
424 430 * @return array
425 431 */
426 432 private static function inbox_prepare_messages( $data ) {
427 433 foreach ( $data as $key => $messages ) {
428 - if ( ! in_array( $key, array( 'unread', 'dismissed' ), true ) ) {
429 - continue;
434 + if ( in_array( $key, array( 'unread', 'dismissed' ), true ) ) {
435 + foreach ( $messages as $key_msg => $message ) {
436 + $data[ $key ][ $key_msg ]['cta'] = self::inbox_clean_messages_cta( $message['cta'] );
437 + }
430 438 }
431 -
432 - foreach ( $messages as $key_msg => $message ) {
433 - $data[ $key ][ $key_msg ]['cta'] = self::inbox_clean_messages_cta( $message['cta'] );
434 - }
435 439 }
436 -
437 440 return $data;
438 441 }
439 442
440 - /**
441 - * Clean messages CTA.
442 - *
443 - * @param string $cta
444 - *
445 - * @return string
446 - */
447 443 private static function inbox_clean_messages_cta( $cta ) {
448 - // Remove dismiss button
444 +
445 + // remove dismiss button
449 446 $pattern = '/<a[^>]*class="[^"]*frm_inbox_dismiss[^"]*"[^>]*>.*?<\/a>/is';
450 447 return preg_replace( $pattern, ' ', $cta );
451 448 }
452 449
@@ -452,10 +449,9 @@
452 449
453 450 /**
454 451 * Get the embed YouTube video from YouTube feed api. If there are 0 entries we show the welcome video otherwise latest video from FF YouTube channel is displayed.
455 452 *
456 - * @param int|string $entries_count The total entries available.
457 - *
453 + * @param int $entries_count The total entries available.
458 454 * @return string|null The YouTube video ID.
459 455 */
460 456 private static function get_youtube_embed_video( $entries_count ) {
461 457 $youtube_api = new FrmYoutubeFeedApi();
@@ -464,19 +460,16 @@
464 460
465 461 if ( 0 === (int) $entries_count && false === $welcome_video && false === $featured_video ) {
466 462 return null;
467 463 }
468 -
469 464 if ( 0 === (int) $entries_count && false !== $welcome_video ) {
470 - return $welcome_video['video-id'] ?? null;
465 + return isset( $welcome_video['video-id'] ) ? $welcome_video['video-id'] : null;
471 466 }
472 -
473 467 // We might receive the most recent video feed as the featured selection.
474 468 if ( isset( $featured_video[0] ) ) {
475 469 return $featured_video[0]['video-id'];
476 470 }
477 -
478 - return $featured_video['video-id'] ?? null;
471 + return isset( $featured_video['video-id'] ) ? $featured_video['video-id'] : null;
479 472 }
480 473
481 474 /**
482 475 * Save subscribed user's email to dashboard options.
@@ -482,20 +475,16 @@
482 475 * Save subscribed user's email to dashboard options.
483 476 * Used for Inbox widget - email subscribe.
484 477 *
485 478 * @param string $email The user email address.
486 - *
487 479 * @return void
488 480 */
489 481 private static function save_subscribed_email( $email ) {
490 482 $subscribed_emails = self::get_subscribed_emails();
491 -
492 - if ( in_array( $email, $subscribed_emails, true ) ) {
493 - return;
483 + if ( ! in_array( $email, $subscribed_emails, true ) ) {
484 + $subscribed_emails[] = $email;
485 + self::update_dashboard_options( $subscribed_emails, 'inbox-subscribed-emails' );
494 486 }
495 -
496 - $subscribed_emails[] = $email;
497 - self::update_dashboard_options( $subscribed_emails, 'inbox-subscribed-emails' );
498 487 }
499 488
500 489 /**
501 490 * Get list of users' ids that have closed the welcome banner.
@@ -518,19 +507,19 @@
518 507 /**
519 508 * Get the dashboard options from db.
520 509 *
521 510 * @param string|null $option_name The dashboard option name. If null it will return all dashboard options.
522 - *
523 511 * @return array
524 512 */
525 513 private static function get_dashboard_options( $option_name = null ) {
526 514 $options = get_option( self::OPTION_META_NAME, array() );
527 -
528 515 if ( null !== $option_name && ! isset( $options[ $option_name ] ) ) {
529 516 return array();
530 517 }
531 -
532 - return null !== $option_name ? $options[ $option_name ] : $options;
518 + if ( null !== $option_name ) {
519 + return $options[ $option_name ];
520 + }
521 + return $options;
533 522 }
534 523
535 524 /**
536 525 * Update the dashboard options to db.
@@ -542,9 +531,9 @@
542 531 */
543 532 private static function update_dashboard_options( $data, $option_name ) {
544 533 $options = self::get_dashboard_options();
545 534 $options[ $option_name ] = $data;
546 - update_option( self::OPTION_META_NAME, $options, false );
535 + update_option( self::OPTION_META_NAME, $options, 'no' );
547 536 }
548 537
549 538 /**
550 539 * Save user id to closed banner list.
@@ -553,13 +542,10 @@
553 542 */
554 543 private static function add_welcome_closed_banner_user_id() {
555 544 $users_list = self::get_closed_welcome_banner_user_ids();
556 545 $user_id = get_current_user_id();
557 -
558 - if ( in_array( $user_id, $users_list, true ) ) {
559 - return;
546 + if ( ! in_array( $user_id, $users_list, true ) ) {
547 + $users_list[] = $user_id;
548 + self::update_dashboard_options( $users_list, 'closed-welcome-banner-user-ids' );
560 549 }
561 -
562 - $users_list[] = $user_id;
563 - self::update_dashboard_options( $users_list, 'closed-welcome-banner-user-ids' );
564 550 }
565 551 }