PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.12.3
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.12.3
1.8.13.1 1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 All 212 releases
charitable / includes / admin / views / tools / logs.php

logs.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.12.3, at includes/admin/views/tools/logs.php

175 lines 6.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Display the Logs tab on the Tools page.
4 *
5 * @author David Bisset
6 * @package Charitable/Admin View/Tools
7 * @copyright Copyright (c) 2023, WP Charitable LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.8.11
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 $is_enabled = Charitable_Log::is_enabled();
18 $retention_days = Charitable_Log::get_retention_days();
19 $nonce = wp_create_nonce( 'charitable_logs_nonce' );
20 $db = Charitable_Log::get_instance()->get_db();
21 $table_exists = $db->table_exists();
22 $has_logs = $table_exists && $db->count() > 0;
23
24 // Build base URL for exports.
25 $base_url = admin_url( 'admin-ajax.php' );
26
27 // Current filter params for filtered export.
28 $filter_params = array(
29 'action' => 'charitable_export_logs_csv',
30 'nonce' => $nonce,
31 'log_type' => isset( $_GET['log_type'] ) ? sanitize_key( $_GET['log_type'] ) : '', // phpcs:ignore WordPress.Security.NonceVerification.Recommended
32 'log_level' => isset( $_GET['log_level'] ) ? sanitize_key( $_GET['log_level'] ) : '', // phpcs:ignore WordPress.Security.NonceVerification.Recommended
33 'log_source' => isset( $_GET['log_source'] ) ? sanitize_key( $_GET['log_source'] ) : '', // phpcs:ignore WordPress.Security.NonceVerification.Recommended
34 's' => isset( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : '', // phpcs:ignore WordPress.Security.NonceVerification.Recommended
35 );
36
37 $export_filtered_url = add_query_arg( $filter_params, $base_url );
38 $export_all_url = add_query_arg(
39 array(
40 'action' => 'charitable_export_logs_csv',
41 'nonce' => $nonce,
42 'export_all' => '1',
43 ),
44 $base_url
45 );
46 ?>
47
48 <div class="charitable-logs-wrap">
49
50 <h4 id="charitable-logs-heading"><?php esc_html_e( 'Logs', 'charitable' ); ?></h4>
51
52 <?php // A. Settings bar. ?>
53 <div class="charitable-logs-settings">
54 <table class="form-table">
55 <tr>
56 <th scope="row"><?php esc_html_e( 'Enable Logging', 'charitable' ); ?></th>
57 <td>
58 <label class="charitable-toggle">
59 <input type="checkbox"
60 id="charitable-logs-enable"
61 value="1"
62 <?php checked( $is_enabled ); ?>
63 />
64 <span class="charitable-toggle-slider"></span>
65 </label>
66 <span class="charitable-logs-status" data-enabled="<?php echo esc_attr__( 'Enabled', 'charitable' ); ?>" data-disabled="<?php echo esc_attr__( 'Disabled', 'charitable' ); ?>"><?php echo $is_enabled ? esc_html__( 'Enabled', 'charitable' ) : esc_html__( 'Disabled', 'charitable' ); ?></span>
67 </td>
68 </tr>
69 <tr>
70 <th scope="row">
71 <label for="charitable-logs-retention"><?php esc_html_e( 'Auto-Delete After', 'charitable' ); ?></label>
72 </th>
73 <td>
74 <select id="charitable-logs-retention">
75 <?php
76 $retention_options = array( 7, 14, 30, 60, 90 );
77 foreach ( $retention_options as $days ) :
78 ?>
79 <option value="<?php echo esc_attr( $days ); ?>" <?php selected( $retention_days, $days ); ?>>
80 <?php
81 /* translators: %d: number of days */
82 echo esc_html( sprintf( _n( '%d day', '%d days', $days, 'charitable' ), $days ) );
83 ?>
84 </option>
85 <?php endforeach; ?>
86 </select>
87 <p class="description">
88 <?php esc_html_e( 'Log records older than this will be automatically deleted daily.', 'charitable' ); ?>
89 </p>
90 </td>
91 </tr>
92 </table>
93 </div>
94
95 <?php if ( ! $table_exists ) : ?>
96
97 <?php // Missing table notice — shown instead of the list table to avoid DB errors. ?>
98 <div class="notice notice-error inline charitable-logs-missing-table" style="margin: 15px 0;">
99 <p>
100 <strong><?php esc_html_e( 'Logs table missing.', 'charitable' ); ?></strong>
101 <?php esc_html_e( 'The charitable_logs database table does not exist. This can happen after upgrading from a version prior to 1.8.11 or on a fresh install where the table was not created.', 'charitable' ); ?>
102 </p>
103 <p>
104 <?php esc_html_e( 'Deactivating and reactivating the Charitable plugin will recreate the table.', 'charitable' ); ?>
105 </p>
106 </div>
107
108 <?php elseif ( $is_enabled || $has_logs ) : ?>
109
110 <?php // B. Action buttons. ?>
111 <div class="charitable-logs-actions">
112 <?php if ( $has_logs ) : ?>
113 <a href="<?php echo esc_url( $export_filtered_url ); ?>" class="button"><?php esc_html_e( 'Export Filtered (CSV)', 'charitable' ); ?></a>
114 <a href="<?php echo esc_url( $export_all_url ); ?>" class="button"><?php esc_html_e( 'Export All (CSV)', 'charitable' ); ?></a>
115 <button type="button" class="button button-link-delete" id="charitable-delete-all-logs"><?php esc_html_e( 'Delete All Logs', 'charitable' ); ?></button>
116 <?php endif; ?>
117 </div>
118
119 <?php // C. List table. ?>
120 <form method="get" action="<?php echo esc_url( admin_url( 'admin.php' ) ); ?>">
121 <input type="hidden" name="page" value="charitable-tools" />
122 <input type="hidden" name="tab" value="logs" />
123 <?php
124 $list_table = new Charitable_Log_List_Table();
125 $list_table->prepare_items();
126 $list_table->search_box( __( 'Search Logs', 'charitable' ), 'charitable-logs' );
127 $list_table->display();
128 ?>
129 </form>
130
131 <?php else : ?>
132 <div class="charitable-logs-empty">
133 <p><?php esc_html_e( 'Logging is currently disabled. Enable it above to start capturing log entries.', 'charitable' ); ?></p>
134 </div>
135 <?php endif; ?>
136
137 </div>
138
139 <?php // D. Modal template. ?>
140 <div id="charitable-log-modal" class="charitable-log-modal" style="display:none;">
141 <div class="charitable-log-modal-overlay"></div>
142 <div class="charitable-log-modal-content">
143 <button type="button" class="charitable-log-modal-close">&times;</button>
144 <div class="charitable-log-modal-body">
145 <h2 class="charitable-log-modal-title"></h2>
146 <div class="charitable-log-modal-meta">
147 <div class="charitable-log-modal-meta-row">
148 <span class="charitable-log-modal-label"><?php esc_html_e( 'Date:', 'charitable' ); ?></span>
149 <span class="charitable-log-modal-date"></span>
150 </div>
151 <div class="charitable-log-modal-meta-row">
152 <span class="charitable-log-modal-label"><?php esc_html_e( 'Level:', 'charitable' ); ?></span>
153 <span class="charitable-log-modal-level"></span>
154 </div>
155 <div class="charitable-log-modal-meta-row">
156 <span class="charitable-log-modal-label"><?php esc_html_e( 'Types:', 'charitable' ); ?></span>
157 <span class="charitable-log-modal-types"></span>
158 </div>
159 <div class="charitable-log-modal-meta-row">
160 <span class="charitable-log-modal-label"><?php esc_html_e( 'Source:', 'charitable' ); ?></span>
161 <span class="charitable-log-modal-source"></span>
162 </div>
163 </div>
164 <div class="charitable-log-modal-message-wrap">
165 <h4><?php esc_html_e( 'Message', 'charitable' ); ?></h4>
166 <div class="charitable-log-modal-message"></div>
167 </div>
168 <div class="charitable-log-modal-ids" style="display:none;">
169 <h4><?php esc_html_e( 'Related Records', 'charitable' ); ?></h4>
170 <div class="charitable-log-modal-ids-grid"></div>
171 </div>
172 </div>
173 </div>
174 </div>
175