PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.8
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.8
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 +133 -94 6.286.8 View file →
@@ -5,8 +5,13 @@
5 5
6 6 class FrmDashboardController {
7 7
8 8 /**
9 + * Option name used to store the time when auto redirected for welcome.
10 + */
11 + const REDIRECT_META_NAME = 'frm_activation_redirect';
12 +
13 + /**
9 14 * Handle name used for registering controller scripts and style.
10 15 */
11 16 const PAGE_SLUG = 'formidable-dashboard';
12 17
@@ -17,12 +22,15 @@
17 22
18 23 /**
19 24 * Register all of the hooks related to the welcome screen functionality
20 25 *
26 + * @access public
27 + *
21 28 * @return void
22 29 */
23 30 public static function load_admin_hooks() {
24 - add_action( 'admin_menu', self::class . '::menu', 9 );
31 + add_action( 'admin_init', __CLASS__ . '::redirect' );
32 + add_action( 'admin_menu', __CLASS__ . '::menu', 9 );
25 33 }
26 34
27 35 /**
28 36 * Register Dashboard page tp Formidable admin menu.
@@ -29,12 +37,64 @@
29 37 *
30 38 * @return void
31 39 */
32 40 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
41 + add_submenu_page( 'formidable', 'Formidable | ' . __( 'Dashboard', 'formidable' ), __( 'Dashboard', 'formidable' ) . FrmInboxController::get_notice_count(), 'frm_view_forms', 'formidable-dashboard', 'FrmDashboardController::route' );
34 42 }
35 43
36 44 /**
45 + * Performs a safe (local) redirect to the welcome screen
46 + * when the plugin is activated
47 + *
48 + * @return void
49 + */
50 + public static function redirect() {
51 + $current_page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
52 + if ( $current_page === self::PAGE_SLUG ) {
53 + // Prevent endless loop.
54 + return;
55 + }
56 +
57 + // phpcs:ignore WordPress.Security.NonceVerification
58 + if ( isset( $_GET['activate-multi'] ) || is_network_admin() ) {
59 + // Only do this for single site installs.
60 + return;
61 + }
62 +
63 + // Check if we should consider redirection.
64 + if ( ! self::is_dashboard_page() ) {
65 + return;
66 + }
67 +
68 + set_transient( self::REDIRECT_META_NAME, 'no', 60 );
69 +
70 + // Prevent redirect with every activation.
71 + if ( self::already_redirected() ) {
72 + return;
73 + }
74 +
75 + // Initial install.
76 + wp_safe_redirect( esc_url( admin_url( 'admin.php?page=' . self::PAGE_SLUG ) ) );
77 + exit;
78 + }
79 +
80 + /**
81 + * Don't redirect every time the plugin is activated.
82 + *
83 + * @return bool
84 + */
85 + private static function already_redirected() {
86 + $redirect_option = 'frm_welcome_redirect';
87 + $last_redirect = get_option( $redirect_option );
88 + if ( $last_redirect ) {
89 + return true;
90 + }
91 +
92 + update_option( $redirect_option, FrmAppHelper::plugin_version(), 'no' );
93 + return false;
94 + }
95 +
96 + /**
37 97 * Triggered from FrmAppController::load_page() with admin_init
38 98 *
39 99 * @since 6.8
40 100 *
@@ -43,11 +103,9 @@
43 103 public static function load_page() {
44 104 self::remove_admin_notices_on_dashboard();
45 105 self::load_assets();
46 106
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
107 + add_filter( 'manage_' . sanitize_title( FrmAppHelper::get_menu_name() ) . '_page_formidable-dashboard_columns', 'FrmDashboardController::entries_columns' );
50 108 add_filter( 'frm_show_footer_links', '__return_false' );
51 109 add_filter( 'screen_options_show_screen', '__return_false' );
52 110 }
53 111
@@ -63,15 +121,13 @@
63 121 self::enqueue_assets();
64 122 }
65 123
66 124 /**
67 - * Gets dashboard helper instance.
125 + * Init dashboard page.
68 126 *
69 - * @since 6.17
70 - *
71 - * @return FrmDashboardHelper
127 + * @return void
72 128 */
73 - public static function get_dashboard_helper() {
129 + public static function route() {
74 130 $latest_available_form = FrmForm::get_latest_form();
75 131 $total_payments = self::view_args_payments();
76 132 $counters_value = array(
77 133 'forms' => FrmForm::get_forms_count(),
@@ -77,17 +133,16 @@
77 133 'forms' => FrmForm::get_forms_count(),
78 134 'entries' => FrmEntry::get_entries_count(),
79 135 );
80 136
81 - return new FrmDashboardHelper(
137 + $dashboard_view = new FrmDashboardHelper(
82 138 array(
83 - 'counters' => array(
139 + 'counters' => array(
84 140 'counters' => self::view_args_counters( $latest_available_form, $counters_value ),
85 141 ),
86 - 'license' => array(),
87 - 'get_free_templates' => array(),
88 - 'inbox' => self::view_args_inbox(),
89 - 'entries' => array(
142 + 'license' => array(),
143 + 'inbox' => self::view_args_inbox(),
144 + 'entries' => array(
90 145 'widget-heading' => __( 'Latest Entries', 'formidable' ),
91 146 'cta' => array(
92 147 'label' => __( 'View All Entries', 'formidable' ),
93 148 'link' => admin_url( 'admin.php?page=formidable-entries' ),
@@ -95,9 +150,9 @@
95 150 'show-placeholder' => 0 >= (int) $counters_value['entries'],
96 151 'count' => $counters_value['entries'],
97 152 'placeholder' => self::view_args_entries_placeholder( $counters_value['forms'] ),
98 153 ),
99 - 'payments' => array(
154 + 'payments' => array(
100 155 'show-placeholder' => empty( $total_payments ),
101 156 'placeholder' => array(
102 157 'copy' => __( 'You don\'t have a payment form setup yet.', 'formidable' ),
103 158 'cta' => array(
@@ -112,22 +167,11 @@
112 167 'items' => $total_payments,
113 168 ),
114 169 ),
115 170 ),
116 - 'video' => array( 'id' => self::get_youtube_embed_video( $counters_value['entries'] ) ),
171 + 'video' => array( 'id' => self::get_youtube_embed_video( $counters_value['entries'] ) ),
117 172 )
118 173 );
119 - }
120 -
121 - /**
122 - * Init dashboard page.
123 - *
124 - * @return void
125 - */
126 - public static function route() {
127 - $dashboard_view = self::get_dashboard_helper();
128 - $should_display_videos = is_callable( 'FrmProDashboardHelper::should_display_videos' ) ? FrmProDashboardHelper::should_display_videos() : true;
129 -
130 174 require FrmAppHelper::plugin_path() . '/classes/views/dashboard/dashboard.php';
131 175 }
132 176
133 177 /**
@@ -132,15 +176,15 @@
132 176
133 177 /**
134 178 * Init top counters widgets view args used to construct FrmDashboardHelper.
135 179 *
136 - * @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.
180 + * @param object|false $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.
137 181 * @param array $counters_value The counter values for "Total Forms" & "Total Entries".
138 182 *
139 183 * @return array
140 184 */
141 185 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
186 + $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 187
144 188 $lite_counters = array(
145 189 self::view_args_build_counter( __( 'Total Forms', 'formidable' ), array(), $counters_value['forms'] ),
146 190 self::view_args_build_counter(
@@ -176,8 +220,9 @@
176 220 return array_merge( $lite_counters, $pro_counters );
177 221 }
178 222
179 223 return array_merge( $lite_counters, $pro_counters_placeholder );
224 +
180 225 }
181 226
182 227 /**
183 228 * Build view args for counter widget.
@@ -189,15 +234,15 @@
189 234 *
190 235 * @return array
191 236 */
192 237 public static function view_args_build_counter( $heading, $cta = array(), $value = 0, $type = 'default' ) {
238 +
193 239 $counter_args = array(
194 240 'heading' => $heading,
195 241 'counter' => $value,
196 242 'type' => 'default',
197 243 );
198 -
199 - if ( $cta ) {
244 + if ( ! empty( $cta ) ) {
200 245 $counter_args['cta'] = $cta;
201 246 }
202 247
203 248 return $counter_args;
@@ -205,11 +250,11 @@
205 250
206 251 /**
207 252 * Build view args for cta.
208 253 *
209 - * @param string $title
210 - * @param string $link
211 - * @param bool $display
254 + * @param string $title
255 + * @param string $link
256 + * @param boolean $display
212 257 *
213 258 * @return array
214 259 */
215 260 public static function view_args_build_cta( $title, $link = '#', $display = true ) {
@@ -225,12 +270,13 @@
225 270 *
226 271 * @return array
227 272 */
228 273 private static function view_args_payments() {
229 - $prepared_data = array();
274 +
275 + $prepared_data = array();
276 +
230 277 $model_payments = new FrmTransLitePayment();
231 278 $payments = $model_payments->get_payments_stats();
232 -
233 279 foreach ( $payments['total'] as $currency => $total_payments ) {
234 280 if ( 0 < (int) $total_payments ) {
235 281 $prepared_data[] = array(
236 282 'counter_label' => FrmCurrencyHelper::get_currency( $currency ),
@@ -245,17 +291,17 @@
245 291 /**
246 292 * Init view args for entries placeholder.
247 293 *
248 294 * @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 295 * @return array
251 296 */
252 297 private static function view_args_entries_placeholder( $forms_count ) {
298 +
253 299 if ( ! $forms_count ) {
254 300 $copy = sprintf(
255 301 /* translators: %1$s: HTML start of a tag, %2$s: HTML close a tag */
256 302 __( '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/' ) ) . '">',
303 + '<a target="_blank" href="' . FrmAppHelper::admin_upgrade_link( '', 'knowledgebase/publish-a-form/' ) . '">',
258 304 '</a>'
259 305 );
260 306 return array(
261 307 'background' => 'entries-placeholder',
@@ -262,9 +308,9 @@
262 308 'heading' => __( 'You Have No Entries Yet', 'formidable' ),
263 309 'copy' => $copy,
264 310 'button' => array(
265 311 'label' => esc_html__( 'Add New Form', 'formidable' ),
266 - 'link' => admin_url( 'admin.php?page=' . FrmFormTemplatesController::PAGE_SLUG ),
312 + 'link' => admin_url( 'admin.php?page=formidable-form-templates' ),
267 313 ),
268 314 );
269 315 }
270 316
@@ -286,15 +332,17 @@
286 332 * A function to handle the counters cta from the top: Total Forms, Total Entries, All Views, Installed Apps.
287 333 *
288 334 * @param string $counter_type
289 335 * @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 - *
336 + * @param object|false $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 337 * @return array
294 338 */
295 339 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 );
340 + if ( $counter_value > 0 || ( 'entries' === $counter_type && false === $latest_available_form ) ) {
341 + return false;
342 + }
343 +
344 + return true;
297 345 }
298 346
299 347 /**
300 348 * Hide 3rd party notifications from dashboard
@@ -306,9 +354,8 @@
306 354 return;
307 355 }
308 356
309 357 global $wp_filter;
310 -
311 358 if ( isset( $wp_filter['admin_notices'] ) ) {
312 359 unset( $wp_filter['admin_notices'] );
313 360 }
314 361 }
@@ -329,9 +376,9 @@
329 376 wp_send_json_success();
330 377 break;
331 378
332 379 case 'save-subscribed-email':
333 - $email = FrmAppHelper::get_post_param( 'email', '', 'sanitize_email' );
380 + $email = FrmAppHelper::get_post_param( 'email' );
334 381 self::save_subscribed_email( $email );
335 382 wp_send_json_success();
336 383 break;
337 384 }
@@ -341,16 +388,24 @@
341 388 * Handle the entries list. Called via add_filter.
342 389 * Hook name: manage_formidable_page_formidable-dashboard_columns.
343 390 *
344 391 * @param array $columns An associative array of column headings.
345 - *
346 392 * @return array
347 393 */
348 394 public static function entries_columns( $columns = array() ) {
349 - $columns['0_form_id'] = esc_html__( 'Form', 'formidable' );
350 - $columns['0_name'] = esc_html__( 'Name', 'formidable' );
351 - $columns['0_user_id'] = esc_html__( 'Author', 'formidable' );
352 - $columns['0_created_at'] = esc_html__( 'Created on', 'formidable' );
395 +
396 + $form_id = FrmForm::get_current_form_id();
397 +
398 + if ( $form_id ) {
399 + self::get_columns_for_form( $form_id, $columns );
400 + } else {
401 + $columns[ $form_id . '_form_id' ] = __( 'Form', 'formidable' );
402 + $columns[ $form_id . '_name' ] = __( 'Name', 'formidable' );
403 + $columns[ $form_id . '_user_id' ] = __( 'Author', 'formidable' );
404 + }
405 +
406 + $columns[ $form_id . '_created_at' ] = __( 'Created on', 'formidable' );
407 +
353 408 return $columns;
354 409 }
355 410
356 411 /**
@@ -355,20 +410,24 @@
355 410
356 411 /**
357 412 * Check if user has closed the welcome banner. The status of banner is saved in db options.
358 413 *
359 - * @return bool
414 + * @return boolean
360 415 */
361 416 public static function welcome_banner_has_closed() {
362 417 $user_id = get_current_user_id();
363 418 $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 );
419 +
420 + if ( ! empty( $banner_closed_by_users ) && false !== array_search( $user_id, $banner_closed_by_users, true ) ) {
421 + return true;
422 + }
423 + return false;
365 424 }
366 425
367 426 /**
368 427 * Check if is dashboard page.
369 428 *
370 - * @return bool
429 + * @return boolean
371 430 */
372 431 public static function is_dashboard_page() {
373 432 return FrmAppHelper::is_admin_page( 'formidable-dashboard' );
374 433 }
@@ -376,14 +435,13 @@
376 435 /**
377 436 * Detect if the logged user's email is subscribed. Used for inbox email subscribe.
378 437 *
379 438 * @param string $email The logged user's email.
380 - *
381 - * @return bool
439 + * @return boolean
382 440 */
383 441 public static function email_is_subscribed( $email ) {
384 442 $subscribed_emails = self::get_subscribed_emails();
385 - return in_array( $email, $subscribed_emails, true );
443 + return false !== in_array( $email, $subscribed_emails, true );
386 444 }
387 445
388 446 /**
389 447 * Register controller assets.
@@ -400,13 +458,13 @@
400 458 *
401 459 * @return void
402 460 */
403 461 public static function enqueue_assets() {
462 +
404 463 if ( ! self::is_dashboard_page() ) {
405 464 return;
406 465 }
407 466
408 - wp_enqueue_style( 'formidable-animations' );
409 467 wp_enqueue_style( self::PAGE_SLUG );
410 468 wp_enqueue_script( self::PAGE_SLUG );
411 469 }
412 470
@@ -421,10 +479,8 @@
421 479
422 480 /**
423 481 * Prepare inbox messages data.
424 482 *
425 - * @param array $data
426 - *
427 483 * @return array
428 484 */
429 485 private static function inbox_prepare_messages( $data ) {
430 486 foreach ( $data as $key => $messages ) {
@@ -436,17 +492,11 @@
436 492 }
437 493 return $data;
438 494 }
439 495
440 - /**
441 - * Clean messages CTA.
442 - *
443 - * @param string $cta
444 - *
445 - * @return string
446 - */
447 496 private static function inbox_clean_messages_cta( $cta ) {
448 - // Remove dismiss button
497 +
498 + // remove dismiss button
449 499 $pattern = '/<a[^>]*class="[^"]*frm_inbox_dismiss[^"]*"[^>]*>.*?<\/a>/is';
450 500 return preg_replace( $pattern, ' ', $cta );
451 501 }
452 502
@@ -452,10 +502,9 @@
452 502
453 503 /**
454 504 * 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 505 *
456 - * @param int|string $entries_count The total entries available.
457 - *
506 + * @param int $entries_count The total entries available.
458 507 * @return string|null The YouTube video ID.
459 508 */
460 509 private static function get_youtube_embed_video( $entries_count ) {
461 510 $youtube_api = new FrmYoutubeFeedApi();
@@ -464,19 +513,16 @@
464 513
465 514 if ( 0 === (int) $entries_count && false === $welcome_video && false === $featured_video ) {
466 515 return null;
467 516 }
468 -
469 517 if ( 0 === (int) $entries_count && false !== $welcome_video ) {
470 - return $welcome_video['video-id'] ?? null;
518 + return isset( $welcome_video['video-id'] ) ? $welcome_video['video-id'] : null;
471 519 }
472 -
473 520 // We might receive the most recent video feed as the featured selection.
474 521 if ( isset( $featured_video[0] ) ) {
475 522 return $featured_video[0]['video-id'];
476 523 }
477 -
478 - return $featured_video['video-id'] ?? null;
524 + return isset( $featured_video['video-id'] ) ? $featured_video['video-id'] : null;
479 525 }
480 526
481 527 /**
482 528 * Save subscribed user's email to dashboard options.
@@ -482,20 +528,16 @@
482 528 * Save subscribed user's email to dashboard options.
483 529 * Used for Inbox widget - email subscribe.
484 530 *
485 531 * @param string $email The user email address.
486 - *
487 532 * @return void
488 533 */
489 534 private static function save_subscribed_email( $email ) {
490 535 $subscribed_emails = self::get_subscribed_emails();
491 -
492 - if ( in_array( $email, $subscribed_emails, true ) ) {
493 - return;
536 + if ( false === array_search( $email, $subscribed_emails, true ) ) {
537 + $subscribed_emails[] = $email;
538 + self::update_dashboard_options( $subscribed_emails, 'inbox-subscribed-emails' );
494 539 }
495 -
496 - $subscribed_emails[] = $email;
497 - self::update_dashboard_options( $subscribed_emails, 'inbox-subscribed-emails' );
498 540 }
499 541
500 542 /**
501 543 * Get list of users' ids that have closed the welcome banner.
@@ -518,19 +560,19 @@
518 560 /**
519 561 * Get the dashboard options from db.
520 562 *
521 563 * @param string|null $option_name The dashboard option name. If null it will return all dashboard options.
522 - *
523 564 * @return array
524 565 */
525 566 private static function get_dashboard_options( $option_name = null ) {
526 567 $options = get_option( self::OPTION_META_NAME, array() );
527 -
528 568 if ( null !== $option_name && ! isset( $options[ $option_name ] ) ) {
529 569 return array();
530 570 }
531 -
532 - return null !== $option_name ? $options[ $option_name ] : $options;
571 + if ( null !== $option_name ) {
572 + return $options[ $option_name ];
573 + }
574 + return $options;
533 575 }
534 576
535 577 /**
536 578 * Update the dashboard options to db.
@@ -542,9 +584,9 @@
542 584 */
543 585 private static function update_dashboard_options( $data, $option_name ) {
544 586 $options = self::get_dashboard_options();
545 587 $options[ $option_name ] = $data;
546 - update_option( self::OPTION_META_NAME, $options, false );
588 + update_option( self::OPTION_META_NAME, $options, 'no' );
547 589 }
548 590
549 591 /**
550 592 * Save user id to closed banner list.
@@ -553,13 +595,10 @@
553 595 */
554 596 private static function add_welcome_closed_banner_user_id() {
555 597 $users_list = self::get_closed_welcome_banner_user_ids();
556 598 $user_id = get_current_user_id();
557 -
558 - if ( in_array( $user_id, $users_list, true ) ) {
559 - return;
599 + if ( false === array_search( $user_id, $users_list, true ) ) {
600 + $users_list[] = $user_id;
601 + self::update_dashboard_options( $users_list, 'closed-welcome-banner-user-ids' );
560 602 }
561 -
562 - $users_list[] = $user_id;
563 - self::update_dashboard_options( $users_list, 'closed-welcome-banner-user-ids' );
564 603 }
565 604 }