| @@ -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,9 +188,8 @@ | ||
| 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', |
| @@ -197,9 +194,9 @@ | ||
| 197 | 194 | 'counter' => $value, |
| 198 | 195 | 'type' => 'default', |
| 199 | 196 | ); |
| 200 | 197 | |
| 201 | - if ( ! empty( $cta ) ) { | |
| 198 | + if ( $cta ) { | |
| 202 | 199 | $counter_args['cta'] = $cta; |
| 203 | 200 | } |
| 204 | 201 | |
| 205 | 202 | return $counter_args; |
| @@ -227,11 +224,9 @@ | ||
| 227 | 224 | * |
| 228 | 225 | * @return array |
| 229 | 226 | */ |
| 230 | 227 | private static function view_args_payments() { |
| 231 | - | |
| 232 | - $prepared_data = array(); | |
| 233 | - | |
| 228 | + $prepared_data = array(); | |
| 234 | 229 | $model_payments = new FrmTransLitePayment(); |
| 235 | 230 | $payments = $model_payments->get_payments_stats(); |
| 236 | 231 | |
| 237 | 232 | foreach ( $payments['total'] as $currency => $total_payments ) { |
| @@ -253,9 +248,8 @@ | ||
| 253 | 248 | * |
| 254 | 249 | * @return array |
| 255 | 250 | */ |
| 256 | 251 | private static function view_args_entries_placeholder( $forms_count ) { |
| 257 | - | |
| 258 | 252 | if ( ! $forms_count ) { |
| 259 | 253 | $copy = sprintf( |
| 260 | 254 | /* translators: %1$s: HTML start of a tag, %2$s: HTML close a tag */ |
| 261 | 255 | __( 'See the %1$sform documentation%2$s for instructions on publishing your form', 'formidable' ), |
| @@ -275,9 +269,9 @@ | ||
| 275 | 269 | |
| 276 | 270 | $copy = sprintf( |
| 277 | 271 | /* translators: %1$s: HTML start of a tag, %2$s: HTML close a tag */ |
| 278 | 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' ), |
| 279 | - '<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/' ) ) . '">', | |
| 280 | 274 | '</a>' |
| 281 | 275 | ); |
| 282 | 276 | return array( |
| 283 | 277 | 'background' => 'entries-placeholder', |
| @@ -291,18 +285,15 @@ | ||
| 291 | 285 | * A function to handle the counters cta from the top: Total Forms, Total Entries, All Views, Installed Apps. |
| 292 | 286 | * |
| 293 | 287 | * @param string $counter_type |
| 294 | 288 | * @param int $counter_value |
| 295 | - * @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. | |
| 296 | 291 | * |
| 297 | 292 | * @return array |
| 298 | 293 | */ |
| 299 | 294 | public static function display_counter_cta( $counter_type, $counter_value, $latest_available_form = false ) { |
| 300 | - if ( $counter_value > 0 || ( 'entries' === $counter_type && false === $latest_available_form ) ) { | |
| 301 | - return false; | |
| 302 | - } | |
| 303 | - | |
| 304 | - return true; | |
| 295 | + return $counter_value <= 0 && ! ( 'entries' === $counter_type && false === $latest_available_form ); | |
| 305 | 296 | } |
| 306 | 297 | |
| 307 | 298 | /** |
| 308 | 299 | * Hide 3rd party notifications from dashboard |
| @@ -366,15 +357,10 @@ | ||
| 366 | 357 | * |
| 367 | 358 | * @return bool |
| 368 | 359 | */ |
| 369 | 360 | public static function welcome_banner_has_closed() { |
| 370 | - $user_id = get_current_user_id(); | |
| 371 | 361 | $banner_closed_by_users = self::get_closed_welcome_banner_user_ids(); |
| 372 | - | |
| 373 | - if ( ! empty( $banner_closed_by_users ) && in_array( $user_id, $banner_closed_by_users, true ) ) { | |
| 374 | - return true; | |
| 375 | - } | |
| 376 | - return false; | |
| 362 | + return $banner_closed_by_users && in_array( get_current_user_id(), $banner_closed_by_users, true ); | |
| 377 | 363 | } |
| 378 | 364 | |
| 379 | 365 | /** |
| 380 | 366 | * Check if is dashboard page. |
| @@ -392,10 +378,9 @@ | ||
| 392 | 378 | * |
| 393 | 379 | * @return bool |
| 394 | 380 | */ |
| 395 | 381 | public static function email_is_subscribed( $email ) { |
| 396 | - $subscribed_emails = self::get_subscribed_emails(); | |
| 397 | - return in_array( $email, $subscribed_emails, true ); | |
| 382 | + return in_array( $email, self::get_subscribed_emails(), true ); | |
| 398 | 383 | } |
| 399 | 384 | |
| 400 | 385 | /** |
| 401 | 386 | * Register controller assets. |
| @@ -412,9 +397,8 @@ | ||
| 412 | 397 | * |
| 413 | 398 | * @return void |
| 414 | 399 | */ |
| 415 | 400 | public static function enqueue_assets() { |
| 416 | - | |
| 417 | 401 | if ( ! self::is_dashboard_page() ) { |
| 418 | 402 | return; |
| 419 | 403 | } |
| 420 | 404 | |
| @@ -440,14 +424,17 @@ | ||
| 440 | 424 | * @return array |
| 441 | 425 | */ |
| 442 | 426 | private static function inbox_prepare_messages( $data ) { |
| 443 | 427 | foreach ( $data as $key => $messages ) { |
| 444 | - if ( in_array( $key, array( 'unread', 'dismissed' ), true ) ) { | |
| 445 | - foreach ( $messages as $key_msg => $message ) { | |
| 446 | - $data[ $key ][ $key_msg ]['cta'] = self::inbox_clean_messages_cta( $message['cta'] ); | |
| 447 | - } | |
| 428 | + if ( ! in_array( $key, array( 'unread', 'dismissed' ), true ) ) { | |
| 429 | + continue; | |
| 448 | 430 | } |
| 431 | + | |
| 432 | + foreach ( $messages as $key_msg => $message ) { | |
| 433 | + $data[ $key ][ $key_msg ]['cta'] = self::inbox_clean_messages_cta( $message['cta'] ); | |
| 434 | + } | |
| 449 | 435 | } |
| 436 | + | |
| 450 | 437 | return $data; |
| 451 | 438 | } |
| 452 | 439 | |
| 453 | 440 | /** |
| @@ -457,10 +444,9 @@ | ||
| 457 | 444 | * |
| 458 | 445 | * @return string |
| 459 | 446 | */ |
| 460 | 447 | private static function inbox_clean_messages_cta( $cta ) { |
| 461 | - | |
| 462 | - // remove dismiss button | |
| 448 | + // Remove dismiss button | |
| 463 | 449 | $pattern = '/<a[^>]*class="[^"]*frm_inbox_dismiss[^"]*"[^>]*>.*?<\/a>/is'; |
| 464 | 450 | return preg_replace( $pattern, ' ', $cta ); |
| 465 | 451 | } |
| 466 | 452 | |
| @@ -502,12 +488,14 @@ | ||
| 502 | 488 | */ |
| 503 | 489 | private static function save_subscribed_email( $email ) { |
| 504 | 490 | $subscribed_emails = self::get_subscribed_emails(); |
| 505 | 491 | |
| 506 | - if ( ! in_array( $email, $subscribed_emails, true ) ) { | |
| 507 | - $subscribed_emails[] = $email; | |
| 508 | - self::update_dashboard_options( $subscribed_emails, 'inbox-subscribed-emails' ); | |
| 492 | + if ( in_array( $email, $subscribed_emails, true ) ) { | |
| 493 | + return; | |
| 509 | 494 | } |
| 495 | + | |
| 496 | + $subscribed_emails[] = $email; | |
| 497 | + self::update_dashboard_options( $subscribed_emails, 'inbox-subscribed-emails' ); | |
| 510 | 498 | } |
| 511 | 499 | |
| 512 | 500 | /** |
| 513 | 501 | * Get list of users' ids that have closed the welcome banner. |
| @@ -540,12 +528,9 @@ | ||
| 540 | 528 | if ( null !== $option_name && ! isset( $options[ $option_name ] ) ) { |
| 541 | 529 | return array(); |
| 542 | 530 | } |
| 543 | 531 | |
| 544 | - if ( null !== $option_name ) { | |
| 545 | - return $options[ $option_name ]; | |
| 546 | - } | |
| 547 | - return $options; | |
| 532 | + return null !== $option_name ? $options[ $option_name ] : $options; | |
| 548 | 533 | } |
| 549 | 534 | |
| 550 | 535 | /** |
| 551 | 536 | * Update the dashboard options to db. |
| @@ -557,9 +542,9 @@ | ||
| 557 | 542 | */ |
| 558 | 543 | private static function update_dashboard_options( $data, $option_name ) { |
| 559 | 544 | $options = self::get_dashboard_options(); |
| 560 | 545 | $options[ $option_name ] = $data; |
| 561 | - update_option( self::OPTION_META_NAME, $options, 'no' ); | |
| 546 | + update_option( self::OPTION_META_NAME, $options, false ); | |
| 562 | 547 | } |
| 563 | 548 | |
| 564 | 549 | /** |
| 565 | 550 | * Save user id to closed banner list. |
| @@ -569,10 +554,12 @@ | ||
| 569 | 554 | private static function add_welcome_closed_banner_user_id() { |
| 570 | 555 | $users_list = self::get_closed_welcome_banner_user_ids(); |
| 571 | 556 | $user_id = get_current_user_id(); |
| 572 | 557 | |
| 573 | - if ( ! in_array( $user_id, $users_list, true ) ) { | |
| 574 | - $users_list[] = $user_id; | |
| 575 | - self::update_dashboard_options( $users_list, 'closed-welcome-banner-user-ids' ); | |
| 558 | + if ( in_array( $user_id, $users_list, true ) ) { | |
| 559 | + return; | |
| 576 | 560 | } |
| 561 | + | |
| 562 | + $users_list[] = $user_id; | |
| 563 | + self::update_dashboard_options( $users_list, 'closed-welcome-banner-user-ids' ); | |
| 577 | 564 | } |
| 578 | 565 | } |