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/controllers/FrmDashboardController.php +49 -76 6.286.13 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
@@ -43,11 +43,9 @@
43 43 public static function load_page() {
44 44 self::remove_admin_notices_on_dashboard();
45 45 self::load_assets();
46 46
47 - $unread_count = FrmEntriesHelper::get_visible_unread_inbox_count();
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
47 + add_filter( 'manage_' . sanitize_title( FrmAppHelper::get_menu_name() ) . '_page_formidable-dashboard_columns', 'FrmDashboardController::entries_columns' );
50 48 add_filter( 'frm_show_footer_links', '__return_false' );
51 49 add_filter( 'screen_options_show_screen', '__return_false' );
52 50 }
53 51
@@ -63,15 +61,13 @@
63 61 self::enqueue_assets();
64 62 }
65 63
66 64 /**
67 - * Gets dashboard helper instance.
65 + * Init dashboard page.
68 66 *
69 - * @since 6.17
70 - *
71 - * @return FrmDashboardHelper
67 + * @return void
72 68 */
73 - public static function get_dashboard_helper() {
69 + public static function route() {
74 70 $latest_available_form = FrmForm::get_latest_form();
75 71 $total_payments = self::view_args_payments();
76 72 $counters_value = array(
77 73 'forms' => FrmForm::get_forms_count(),
@@ -77,17 +73,16 @@
77 73 'forms' => FrmForm::get_forms_count(),
78 74 'entries' => FrmEntry::get_entries_count(),
79 75 );
80 76
81 - return new FrmDashboardHelper(
77 + $dashboard_view = new FrmDashboardHelper(
82 78 array(
83 - 'counters' => array(
79 + 'counters' => array(
84 80 'counters' => self::view_args_counters( $latest_available_form, $counters_value ),
85 81 ),
86 - 'license' => array(),
87 - 'get_free_templates' => array(),
88 - 'inbox' => self::view_args_inbox(),
89 - 'entries' => array(
82 + 'license' => array(),
83 + 'inbox' => self::view_args_inbox(),
84 + 'entries' => array(
90 85 'widget-heading' => __( 'Latest Entries', 'formidable' ),
91 86 'cta' => array(
92 87 'label' => __( 'View All Entries', 'formidable' ),
93 88 'link' => admin_url( 'admin.php?page=formidable-entries' ),
@@ -95,9 +90,9 @@
95 90 'show-placeholder' => 0 >= (int) $counters_value['entries'],
96 91 'count' => $counters_value['entries'],
97 92 'placeholder' => self::view_args_entries_placeholder( $counters_value['forms'] ),
98 93 ),
99 - 'payments' => array(
94 + 'payments' => array(
100 95 'show-placeholder' => empty( $total_payments ),
101 96 'placeholder' => array(
102 97 'copy' => __( 'You don\'t have a payment form setup yet.', 'formidable' ),
103 98 'cta' => array(
@@ -112,20 +107,12 @@
112 107 'items' => $total_payments,
113 108 ),
114 109 ),
115 110 ),
116 - 'video' => array( 'id' => self::get_youtube_embed_video( $counters_value['entries'] ) ),
111 + 'video' => array( 'id' => self::get_youtube_embed_video( $counters_value['entries'] ) ),
117 112 )
118 113 );
119 - }
120 114
121 - /**
122 - * Init dashboard page.
123 - *
124 - * @return void
125 - */
126 - public static function route() {
127 - $dashboard_view = self::get_dashboard_helper();
128 115 $should_display_videos = is_callable( 'FrmProDashboardHelper::should_display_videos' ) ? FrmProDashboardHelper::should_display_videos() : true;
129 116
130 117 require FrmAppHelper::plugin_path() . '/classes/views/dashboard/dashboard.php';
131 118 }
@@ -138,9 +125,9 @@
138 125 *
139 126 * @return array
140 127 */
141 128 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
129 + $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 130
144 131 $lite_counters = array(
145 132 self::view_args_build_counter( __( 'Total Forms', 'formidable' ), array(), $counters_value['forms'] ),
146 133 self::view_args_build_counter(
@@ -189,15 +176,15 @@
189 176 *
190 177 * @return array
191 178 */
192 179 public static function view_args_build_counter( $heading, $cta = array(), $value = 0, $type = 'default' ) {
180 +
193 181 $counter_args = array(
194 182 'heading' => $heading,
195 183 'counter' => $value,
196 184 'type' => 'default',
197 185 );
198 -
199 - if ( $cta ) {
186 + if ( ! empty( $cta ) ) {
200 187 $counter_args['cta'] = $cta;
201 188 }
202 189
203 190 return $counter_args;
@@ -225,12 +212,13 @@
225 212 *
226 213 * @return array
227 214 */
228 215 private static function view_args_payments() {
229 - $prepared_data = array();
216 +
217 + $prepared_data = array();
218 +
230 219 $model_payments = new FrmTransLitePayment();
231 220 $payments = $model_payments->get_payments_stats();
232 -
233 221 foreach ( $payments['total'] as $currency => $total_payments ) {
234 222 if ( 0 < (int) $total_payments ) {
235 223 $prepared_data[] = array(
236 224 'counter_label' => FrmCurrencyHelper::get_currency( $currency ),
@@ -245,17 +233,17 @@
245 233 /**
246 234 * Init view args for entries placeholder.
247 235 *
248 236 * @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 237 * @return array
251 238 */
252 239 private static function view_args_entries_placeholder( $forms_count ) {
240 +
253 241 if ( ! $forms_count ) {
254 242 $copy = sprintf(
255 243 /* translators: %1$s: HTML start of a tag, %2$s: HTML close a tag */
256 244 __( '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/' ) ) . '">',
245 + '<a target="_blank" href="' . FrmAppHelper::admin_upgrade_link( '', 'knowledgebase/publish-a-form/' ) . '">',
258 246 '</a>'
259 247 );
260 248 return array(
261 249 'background' => 'entries-placeholder',
@@ -286,15 +274,17 @@
286 274 * A function to handle the counters cta from the top: Total Forms, Total Entries, All Views, Installed Apps.
287 275 *
288 276 * @param string $counter_type
289 277 * @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 - *
278 + * @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 279 * @return array
294 280 */
295 281 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 );
282 + if ( $counter_value > 0 || ( 'entries' === $counter_type && false === $latest_available_form ) ) {
283 + return false;
284 + }
285 +
286 + return true;
297 287 }
298 288
299 289 /**
300 290 * Hide 3rd party notifications from dashboard
@@ -306,9 +296,8 @@
306 296 return;
307 297 }
308 298
309 299 global $wp_filter;
310 -
311 300 if ( isset( $wp_filter['admin_notices'] ) ) {
312 301 unset( $wp_filter['admin_notices'] );
313 302 }
314 303 }
@@ -341,9 +330,8 @@
341 330 * Handle the entries list. Called via add_filter.
342 331 * Hook name: manage_formidable_page_formidable-dashboard_columns.
343 332 *
344 333 * @param array $columns An associative array of column headings.
345 - *
346 334 * @return array
347 335 */
348 336 public static function entries_columns( $columns = array() ) {
349 337 $columns['0_form_id'] = esc_html__( 'Form', 'formidable' );
@@ -360,9 +348,13 @@
360 348 */
361 349 public static function welcome_banner_has_closed() {
362 350 $user_id = get_current_user_id();
363 351 $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 );
352 +
353 + if ( ! empty( $banner_closed_by_users ) && in_array( $user_id, $banner_closed_by_users, true ) ) {
354 + return true;
355 + }
356 + return false;
365 357 }
366 358
367 359 /**
368 360 * Check if is dashboard page.
@@ -376,9 +368,8 @@
376 368 /**
377 369 * Detect if the logged user's email is subscribed. Used for inbox email subscribe.
378 370 *
379 371 * @param string $email The logged user's email.
380 - *
381 372 * @return bool
382 373 */
383 374 public static function email_is_subscribed( $email ) {
384 375 $subscribed_emails = self::get_subscribed_emails();
@@ -400,8 +391,9 @@
400 391 *
401 392 * @return void
402 393 */
403 394 public static function enqueue_assets() {
395 +
404 396 if ( ! self::is_dashboard_page() ) {
405 397 return;
406 398 }
407 399
@@ -421,10 +413,8 @@
421 413
422 414 /**
423 415 * Prepare inbox messages data.
424 416 *
425 - * @param array $data
426 - *
427 417 * @return array
428 418 */
429 419 private static function inbox_prepare_messages( $data ) {
430 420 foreach ( $data as $key => $messages ) {
@@ -436,17 +426,11 @@
436 426 }
437 427 return $data;
438 428 }
439 429
440 - /**
441 - * Clean messages CTA.
442 - *
443 - * @param string $cta
444 - *
445 - * @return string
446 - */
447 430 private static function inbox_clean_messages_cta( $cta ) {
448 - // Remove dismiss button
431 +
432 + // remove dismiss button
449 433 $pattern = '/<a[^>]*class="[^"]*frm_inbox_dismiss[^"]*"[^>]*>.*?<\/a>/is';
450 434 return preg_replace( $pattern, ' ', $cta );
451 435 }
452 436
@@ -452,10 +436,9 @@
452 436
453 437 /**
454 438 * 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 439 *
456 - * @param int|string $entries_count The total entries available.
457 - *
440 + * @param int $entries_count The total entries available.
458 441 * @return string|null The YouTube video ID.
459 442 */
460 443 private static function get_youtube_embed_video( $entries_count ) {
461 444 $youtube_api = new FrmYoutubeFeedApi();
@@ -464,19 +447,16 @@
464 447
465 448 if ( 0 === (int) $entries_count && false === $welcome_video && false === $featured_video ) {
466 449 return null;
467 450 }
468 -
469 451 if ( 0 === (int) $entries_count && false !== $welcome_video ) {
470 - return $welcome_video['video-id'] ?? null;
452 + return isset( $welcome_video['video-id'] ) ? $welcome_video['video-id'] : null;
471 453 }
472 -
473 454 // We might receive the most recent video feed as the featured selection.
474 455 if ( isset( $featured_video[0] ) ) {
475 456 return $featured_video[0]['video-id'];
476 457 }
477 -
478 - return $featured_video['video-id'] ?? null;
458 + return isset( $featured_video['video-id'] ) ? $featured_video['video-id'] : null;
479 459 }
480 460
481 461 /**
482 462 * Save subscribed user's email to dashboard options.
@@ -482,20 +462,16 @@
482 462 * Save subscribed user's email to dashboard options.
483 463 * Used for Inbox widget - email subscribe.
484 464 *
485 465 * @param string $email The user email address.
486 - *
487 466 * @return void
488 467 */
489 468 private static function save_subscribed_email( $email ) {
490 469 $subscribed_emails = self::get_subscribed_emails();
491 -
492 - if ( in_array( $email, $subscribed_emails, true ) ) {
493 - return;
470 + if ( ! in_array( $email, $subscribed_emails, true ) ) {
471 + $subscribed_emails[] = $email;
472 + self::update_dashboard_options( $subscribed_emails, 'inbox-subscribed-emails' );
494 473 }
495 -
496 - $subscribed_emails[] = $email;
497 - self::update_dashboard_options( $subscribed_emails, 'inbox-subscribed-emails' );
498 474 }
499 475
500 476 /**
501 477 * Get list of users' ids that have closed the welcome banner.
@@ -518,19 +494,19 @@
518 494 /**
519 495 * Get the dashboard options from db.
520 496 *
521 497 * @param string|null $option_name The dashboard option name. If null it will return all dashboard options.
522 - *
523 498 * @return array
524 499 */
525 500 private static function get_dashboard_options( $option_name = null ) {
526 501 $options = get_option( self::OPTION_META_NAME, array() );
527 -
528 502 if ( null !== $option_name && ! isset( $options[ $option_name ] ) ) {
529 503 return array();
530 504 }
531 -
532 - return null !== $option_name ? $options[ $option_name ] : $options;
505 + if ( null !== $option_name ) {
506 + return $options[ $option_name ];
507 + }
508 + return $options;
533 509 }
534 510
535 511 /**
536 512 * Update the dashboard options to db.
@@ -542,9 +518,9 @@
542 518 */
543 519 private static function update_dashboard_options( $data, $option_name ) {
544 520 $options = self::get_dashboard_options();
545 521 $options[ $option_name ] = $data;
546 - update_option( self::OPTION_META_NAME, $options, false );
522 + update_option( self::OPTION_META_NAME, $options, 'no' );
547 523 }
548 524
549 525 /**
550 526 * Save user id to closed banner list.
@@ -553,13 +529,10 @@
553 529 */
554 530 private static function add_welcome_closed_banner_user_id() {
555 531 $users_list = self::get_closed_welcome_banner_user_ids();
556 532 $user_id = get_current_user_id();
557 -
558 - if ( in_array( $user_id, $users_list, true ) ) {
559 - return;
533 + if ( ! in_array( $user_id, $users_list, true ) ) {
534 + $users_list[] = $user_id;
535 + self::update_dashboard_options( $users_list, 'closed-welcome-banner-user-ids' );
560 536 }
561 -
562 - $users_list[] = $user_id;
563 - self::update_dashboard_options( $users_list, 'closed-welcome-banner-user-ids' );
564 537 }
565 538 }