PluginProbe
Contact Forms by Cimatti / trunk
Contact Forms by Cimatti vtrunk
2.3.6 2.3.5 2.3.0 2.2.32 2.2.4 2.2.0 2.1.2 2.1.1 trunk 1.0 1.1 1.2 1.2.1 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 All 62 releases
contact-forms / admin / dashboard-widget.php

dashboard-widget.php in Contact Forms by Cimatti trunk, at admin/dashboard-widget.php

81 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Contact Forms dashboard widget.
4 *
5 * Loaded on demand from accua_contact_forms_dashboard_add_widgets() in
6 * contact-forms.php, so this file is only included on the WordPress
7 * dashboard screen and only for users who can see the widget.
8 */
9
10 if ( ! defined( 'ABSPATH' ) ) exit;
11
12 /**
13 * Get the statistics shown in the dashboard widget.
14 *
15 * Results are cached in a transient for 5 minutes so repeated dashboard
16 * loads do not run COUNT queries against the submissions tables.
17 *
18 * @return array{active_forms:int, pages:int, submissions:int, emails:int}
19 */
20 function accua_contact_forms_dashboard_get_stats()
21 {
22 $stats = get_transient('accua_forms_dashboard_stats');
23 if (is_array($stats)) {
24 return $stats;
25 }
26
27 global $wpdb;
28
29 // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Custom tables; results cached in a transient.
30 $stats = array(
31 'active_forms' => count(get_option('accua_forms_saved_forms', array())),
32 'pages' => (int) $wpdb->get_var("SELECT COUNT(DISTINCT afs_uri) FROM `{$wpdb->prefix}accua_forms_submissions`"),
33 'submissions' => (int) $wpdb->get_var("SELECT COUNT(*) FROM `{$wpdb->prefix}accua_forms_submissions` WHERE afs_status >= 0"),
34 'emails' => (int) $wpdb->get_var("SELECT COUNT(DISTINCT afsv_value) FROM `{$wpdb->prefix}accua_forms_submissions_values` WHERE afsv_type = 'autoreply_email'"),
35 );
36 // phpcs:enable
37
38 set_transient('accua_forms_dashboard_stats', $stats, 5 * MINUTE_IN_SECONDS);
39
40 return $stats;
41 }
42
43 /**
44 * Dashboard widget handler for Contact Forms stats.
45 *
46 * Shows form statistics including active forms, pages, submissions, and distinct emails.
47 * Only accessible to users with the 'manage_options' capability.
48 */
49 function accua_contact_forms_dashboard_widget_news_handler()
50 {
51 if (!current_user_can('manage_options')) {
52 return;
53 }
54
55 $stats = accua_contact_forms_dashboard_get_stats();
56 $rows = array(
57 array($stats['active_forms'], __('Active forms', 'contact-forms')),
58 array($stats['pages'], __('Pages', 'contact-forms')),
59 array($stats['submissions'], __('Submissions', 'contact-forms')),
60 array($stats['emails'], __('Distinct Emails', 'contact-forms')),
61 );
62
63 $plugin_data = get_plugin_data(ACCUA_FORMS_FILE, false, false); ?>
64 <table>
65 <?php foreach ($rows as $row) : ?>
66 <tr class="first">
67 <td class="first b"><?php echo esc_html(number_format_i18n($row[0])); ?></td>
68 <td class="t"><?php echo esc_html($row[1]); ?></td>
69 </tr>
70 <?php endforeach; ?>
71 </table>
72 <br />
73 <span id="accua-forms-version"><a href="<?php echo esc_url('https://www.cimatti.it/en/wordpress-plugins/contact-forms/'); ?>">
74 <?php
75 esc_html_e('Version', 'contact-forms');
76 echo " " . esc_html($plugin_data['Version']); ?></a> | <a href="<?php echo esc_url(admin_url('admin.php?page=accua_forms')); ?>"><?php esc_html_e('Dashboard', 'contact-forms'); ?></a>
77 </span>
78
79 <?php
80 }
81