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