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