| @@ -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,9 +94,9 @@ | ||
| 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( | |
| 98 | + 'payments' => array( | |
| 100 | 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( |
| @@ -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', |
| @@ -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,10 +426,8 @@ | ||
| 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 ) { |
| @@ -436,17 +439,11 @@ | ||
| 436 | 439 | } |
| 437 | 440 | return $data; |
| 438 | 441 | } |
| 439 | 442 | |
| 440 | - /** | |
| 441 | - * Clean messages CTA. | |
| 442 | - * | |
| 443 | - * @param string $cta | |
| 444 | - * | |
| 445 | - * @return string | |
| 446 | - */ | |
| 447 | 443 | private static function inbox_clean_messages_cta( $cta ) { |
| 448 | - // Remove dismiss button | |
| 444 | + | |
| 445 | + // remove dismiss button | |
| 449 | 446 | $pattern = '/<a[^>]*class="[^"]*frm_inbox_dismiss[^"]*"[^>]*>.*?<\/a>/is'; |
| 450 | 447 | return preg_replace( $pattern, ' ', $cta ); |
| 451 | 448 | } |
| 452 | 449 | |
| @@ -452,10 +449,9 @@ | ||
| 452 | 449 | |
| 453 | 450 | /** |
| 454 | 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. |
| 455 | 452 | * |
| 456 | - * @param int|string $entries_count The total entries available. | |
| 457 | - * | |
| 453 | + * @param int $entries_count The total entries available. | |
| 458 | 454 | * @return string|null The YouTube video ID. |
| 459 | 455 | */ |
| 460 | 456 | private static function get_youtube_embed_video( $entries_count ) { |
| 461 | 457 | $youtube_api = new FrmYoutubeFeedApi(); |
| @@ -464,19 +460,16 @@ | ||
| 464 | 460 | |
| 465 | 461 | if ( 0 === (int) $entries_count && false === $welcome_video && false === $featured_video ) { |
| 466 | 462 | return null; |
| 467 | 463 | } |
| 468 | - | |
| 469 | 464 | if ( 0 === (int) $entries_count && false !== $welcome_video ) { |
| 470 | - return $welcome_video['video-id'] ?? null; | |
| 465 | + return isset( $welcome_video['video-id'] ) ? $welcome_video['video-id'] : null; | |
| 471 | 466 | } |
| 472 | - | |
| 473 | 467 | // We might receive the most recent video feed as the featured selection. |
| 474 | 468 | if ( isset( $featured_video[0] ) ) { |
| 475 | 469 | return $featured_video[0]['video-id']; |
| 476 | 470 | } |
| 477 | - | |
| 478 | - return $featured_video['video-id'] ?? null; | |
| 471 | + return isset( $featured_video['video-id'] ) ? $featured_video['video-id'] : null; | |
| 479 | 472 | } |
| 480 | 473 | |
| 481 | 474 | /** |
| 482 | 475 | * Save subscribed user's email to dashboard options. |
| @@ -482,20 +475,16 @@ | ||
| 482 | 475 | * Save subscribed user's email to dashboard options. |
| 483 | 476 | * Used for Inbox widget - email subscribe. |
| 484 | 477 | * |
| 485 | 478 | * @param string $email The user email address. |
| 486 | - * | |
| 487 | 479 | * @return void |
| 488 | 480 | */ |
| 489 | 481 | private static function save_subscribed_email( $email ) { |
| 490 | 482 | $subscribed_emails = self::get_subscribed_emails(); |
| 491 | - | |
| 492 | - if ( in_array( $email, $subscribed_emails, true ) ) { | |
| 493 | - return; | |
| 483 | + if ( ! in_array( $email, $subscribed_emails, true ) ) { | |
| 484 | + $subscribed_emails[] = $email; | |
| 485 | + self::update_dashboard_options( $subscribed_emails, 'inbox-subscribed-emails' ); | |
| 494 | 486 | } |
| 495 | - | |
| 496 | - $subscribed_emails[] = $email; | |
| 497 | - self::update_dashboard_options( $subscribed_emails, 'inbox-subscribed-emails' ); | |
| 498 | 487 | } |
| 499 | 488 | |
| 500 | 489 | /** |
| 501 | 490 | * Get list of users' ids that have closed the welcome banner. |
| @@ -518,19 +507,19 @@ | ||
| 518 | 507 | /** |
| 519 | 508 | * Get the dashboard options from db. |
| 520 | 509 | * |
| 521 | 510 | * @param string|null $option_name The dashboard option name. If null it will return all dashboard options. |
| 522 | - * | |
| 523 | 511 | * @return array |
| 524 | 512 | */ |
| 525 | 513 | private static function get_dashboard_options( $option_name = null ) { |
| 526 | 514 | $options = get_option( self::OPTION_META_NAME, array() ); |
| 527 | - | |
| 528 | 515 | if ( null !== $option_name && ! isset( $options[ $option_name ] ) ) { |
| 529 | 516 | return array(); |
| 530 | 517 | } |
| 531 | - | |
| 532 | - return null !== $option_name ? $options[ $option_name ] : $options; | |
| 518 | + if ( null !== $option_name ) { | |
| 519 | + return $options[ $option_name ]; | |
| 520 | + } | |
| 521 | + return $options; | |
| 533 | 522 | } |
| 534 | 523 | |
| 535 | 524 | /** |
| 536 | 525 | * Update the dashboard options to db. |
| @@ -542,9 +531,9 @@ | ||
| 542 | 531 | */ |
| 543 | 532 | private static function update_dashboard_options( $data, $option_name ) { |
| 544 | 533 | $options = self::get_dashboard_options(); |
| 545 | 534 | $options[ $option_name ] = $data; |
| 546 | - update_option( self::OPTION_META_NAME, $options, false ); | |
| 535 | + update_option( self::OPTION_META_NAME, $options, 'no' ); | |
| 547 | 536 | } |
| 548 | 537 | |
| 549 | 538 | /** |
| 550 | 539 | * Save user id to closed banner list. |
| @@ -553,13 +542,10 @@ | ||
| 553 | 542 | */ |
| 554 | 543 | private static function add_welcome_closed_banner_user_id() { |
| 555 | 544 | $users_list = self::get_closed_welcome_banner_user_ids(); |
| 556 | 545 | $user_id = get_current_user_id(); |
| 557 | - | |
| 558 | - if ( in_array( $user_id, $users_list, true ) ) { | |
| 559 | - 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' ); | |
| 560 | 549 | } |
| 561 | - | |
| 562 | - $users_list[] = $user_id; | |
| 563 | - self::update_dashboard_options( $users_list, 'closed-welcome-banner-user-ids' ); | |
| 564 | 550 | } |
| 565 | 551 | } |