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/controllers/FrmDashboardController.php +63 -90 6.336.10 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,30 +61,28 @@
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() {
74 - $total_payments = self::view_args_payments();
75 - $counters_value = array(
69 + public static function route() {
70 + $latest_available_form = FrmForm::get_latest_form();
71 + $total_payments = self::view_args_payments();
72 + $counters_value = array(
76 73 'forms' => FrmForm::get_forms_count(),
77 74 'entries' => FrmEntry::get_entries_count(),
78 75 );
79 76
80 - return new FrmDashboardHelper(
77 + $dashboard_view = new FrmDashboardHelper(
81 78 array(
82 - 'counters' => array(
83 - 'counters' => self::view_args_counters( FrmForm::get_latest_form(), $counters_value ),
79 + 'counters' => array(
80 + 'counters' => self::view_args_counters( $latest_available_form, $counters_value ),
84 81 ),
85 - 'license' => array(),
86 - 'get_free_templates' => array(),
87 - 'inbox' => self::view_args_inbox(),
88 - 'entries' => array(
82 + 'license' => array(),
83 + 'inbox' => self::view_args_inbox(),
84 + 'entries' => array(
89 85 'widget-heading' => __( 'Latest Entries', 'formidable' ),
90 86 'cta' => array(
91 87 'label' => __( 'View All Entries', 'formidable' ),
92 88 'link' => admin_url( 'admin.php?page=formidable-entries' ),
@@ -94,10 +90,10 @@
94 90 'show-placeholder' => 0 >= (int) $counters_value['entries'],
95 91 'count' => $counters_value['entries'],
96 92 'placeholder' => self::view_args_entries_placeholder( $counters_value['forms'] ),
97 93 ),
98 - 'payments' => array(
99 - 'show-placeholder' => ! $total_payments,
94 + 'payments' => array(
95 + 'show-placeholder' => empty( $total_payments ),
100 96 'placeholder' => array(
101 97 'copy' => __( 'You don\'t have a payment form setup yet.', 'formidable' ),
102 98 'cta' => array(
103 99 'link' => admin_url( 'admin.php?page=formidable-form-templates' ),
@@ -111,20 +107,12 @@
111 107 'items' => $total_payments,
112 108 ),
113 109 ),
114 110 ),
115 - 'video' => array( 'id' => self::get_youtube_embed_video( $counters_value['entries'] ) ),
111 + 'video' => array( 'id' => self::get_youtube_embed_video( $counters_value['entries'] ) ),
116 112 )
117 113 );
118 - }
119 114
120 - /**
121 - * Init dashboard page.
122 - *
123 - * @return void
124 - */
125 - public static function route() {
126 - $dashboard_view = self::get_dashboard_helper();
127 115 $should_display_videos = is_callable( 'FrmProDashboardHelper::should_display_videos' ) ? FrmProDashboardHelper::should_display_videos() : true;
128 116
129 117 require FrmAppHelper::plugin_path() . '/classes/views/dashboard/dashboard.php';
130 118 }
@@ -131,15 +119,15 @@
131 119
132 120 /**
133 121 * Init top counters widgets view args used to construct FrmDashboardHelper.
134 122 *
135 - * @param false|object $latest_available_form If a form is available, we utilize its ID to direct the 'Create New Entry' link of the entries counter CTA when no entries exist.
123 + * @param false|object $latest_available_form If a form is availble, we utilize its ID to direct the 'Create New Entry' link of the entries counter CTA when no entries exist.
136 124 * @param array $counters_value The counter values for "Total Forms" & "Total Entries".
137 125 *
138 126 * @return array
139 127 */
140 128 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
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 ) : '';
142 130
143 131 $lite_counters = array(
144 132 self::view_args_build_counter( __( 'Total Forms', 'formidable' ), array(), $counters_value['forms'] ),
145 133 self::view_args_build_counter(
@@ -188,15 +176,15 @@
188 176 *
189 177 * @return array
190 178 */
191 179 public static function view_args_build_counter( $heading, $cta = array(), $value = 0, $type = 'default' ) {
180 +
192 181 $counter_args = array(
193 182 'heading' => $heading,
194 183 'counter' => $value,
195 184 'type' => 'default',
196 185 );
197 -
198 - if ( $cta ) {
186 + if ( ! empty( $cta ) ) {
199 187 $counter_args['cta'] = $cta;
200 188 }
201 189
202 190 return $counter_args;
@@ -224,12 +212,13 @@
224 212 *
225 213 * @return array
226 214 */
227 215 private static function view_args_payments() {
228 - $prepared_data = array();
216 +
217 + $prepared_data = array();
218 +
229 219 $model_payments = new FrmTransLitePayment();
230 220 $payments = $model_payments->get_payments_stats();
231 -
232 221 foreach ( $payments['total'] as $currency => $total_payments ) {
233 222 if ( 0 < (int) $total_payments ) {
234 223 $prepared_data[] = array(
235 224 'counter_label' => FrmCurrencyHelper::get_currency( $currency ),
@@ -244,17 +233,17 @@
244 233 /**
245 234 * Init view args for entries placeholder.
246 235 *
247 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.
248 - *
249 237 * @return array
250 238 */
251 239 private static function view_args_entries_placeholder( $forms_count ) {
240 +
252 241 if ( ! $forms_count ) {
253 242 $copy = sprintf(
254 243 /* translators: %1$s: HTML start of a tag, %2$s: HTML close a tag */
255 244 __( '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/' ) ) . '">',
245 + '<a target="_blank" href="' . FrmAppHelper::admin_upgrade_link( '', 'knowledgebase/publish-a-form/' ) . '">',
257 246 '</a>'
258 247 );
259 248 return array(
260 249 'background' => 'entries-placeholder',
@@ -269,9 +258,9 @@
269 258
270 259 $copy = sprintf(
271 260 /* translators: %1$s: HTML start of a tag, %2$s: HTML close a tag */
272 261 __( '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/' ) ) . '">',
262 + '<a target="_blank" href="' . FrmAppHelper::admin_upgrade_link( '', 'knowledgebase/publish-a-form/' ) . '">',
274 263 '</a>'
275 264 );
276 265 return array(
277 266 'background' => 'entries-placeholder',
@@ -285,15 +274,17 @@
285 274 * A function to handle the counters cta from the top: Total Forms, Total Entries, All Views, Installed Apps.
286 275 *
287 276 * @param string $counter_type
288 277 * @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 - *
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.
292 279 * @return array
293 280 */
294 281 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 );
282 + if ( $counter_value > 0 || ( 'entries' === $counter_type && false === $latest_available_form ) ) {
283 + return false;
284 + }
285 +
286 + return true;
296 287 }
297 288
298 289 /**
299 290 * Hide 3rd party notifications from dashboard
@@ -305,9 +296,8 @@
305 296 return;
306 297 }
307 298
308 299 global $wp_filter;
309 -
310 300 if ( isset( $wp_filter['admin_notices'] ) ) {
311 301 unset( $wp_filter['admin_notices'] );
312 302 }
313 303 }
@@ -340,9 +330,8 @@
340 330 * Handle the entries list. Called via add_filter.
341 331 * Hook name: manage_formidable_page_formidable-dashboard_columns.
342 332 *
343 333 * @param array $columns An associative array of column headings.
344 - *
345 334 * @return array
346 335 */
347 336 public static function entries_columns( $columns = array() ) {
348 337 $columns['0_form_id'] = esc_html__( 'Form', 'formidable' );
@@ -357,10 +346,15 @@
357 346 *
358 347 * @return bool
359 348 */
360 349 public static function welcome_banner_has_closed() {
350 + $user_id = get_current_user_id();
361 351 $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 );
352 +
353 + if ( ! empty( $banner_closed_by_users ) && in_array( $user_id, $banner_closed_by_users, true ) ) {
354 + return true;
355 + }
356 + return false;
363 357 }
364 358
365 359 /**
366 360 * Check if is dashboard page.
@@ -374,13 +368,13 @@
374 368 /**
375 369 * Detect if the logged user's email is subscribed. Used for inbox email subscribe.
376 370 *
377 371 * @param string $email The logged user's email.
378 - *
379 372 * @return bool
380 373 */
381 374 public static function email_is_subscribed( $email ) {
382 - return in_array( $email, self::get_subscribed_emails(), true );
375 + $subscribed_emails = self::get_subscribed_emails();
376 + return in_array( $email, $subscribed_emails, true );
383 377 }
384 378
385 379 /**
386 380 * Register controller assets.
@@ -397,8 +391,9 @@
397 391 *
398 392 * @return void
399 393 */
400 394 public static function enqueue_assets() {
395 +
401 396 if ( ! self::is_dashboard_page() ) {
402 397 return;
403 398 }
404 399
@@ -418,35 +413,24 @@
418 413
419 414 /**
420 415 * Prepare inbox messages data.
421 416 *
422 - * @param array $data
423 - *
424 417 * @return array
425 418 */
426 419 private static function inbox_prepare_messages( $data ) {
427 420 foreach ( $data as $key => $messages ) {
428 - if ( ! in_array( $key, array( 'unread', 'dismissed' ), true ) ) {
429 - continue;
421 + if ( in_array( $key, array( 'unread', 'dismissed' ), true ) ) {
422 + foreach ( $messages as $key_msg => $message ) {
423 + $data[ $key ][ $key_msg ]['cta'] = self::inbox_clean_messages_cta( $message['cta'] );
424 + }
430 425 }
431 -
432 - foreach ( $messages as $key_msg => $message ) {
433 - $data[ $key ][ $key_msg ]['cta'] = self::inbox_clean_messages_cta( $message['cta'] );
434 - }
435 426 }
436 -
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 }