PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 4.13.0
GiveWP – Donation Plugin and Fundraising Platform v4.13.0
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / admin / reports / reports.php
give / includes / admin / reports Last commit date
class-donor-reports-table.php 6 years ago class-earnings-report.php 5 years ago class-form-reports-table.php 5 years ago class-forms-report.php 7 years ago class-gateways-report.php 7 years ago class-gateways-reports-table.php 4 years ago class-give-graph.php 1 year ago graphing.php 4 years ago reports.php 1 year ago
reports.php
372 lines
1 <?php
2 /**
3 * Admin Reports Page
4 *
5 * Language Changes from EDD:
6 * 1. "Report Type" stays
7 * 2. "Earnings" changes to "Income"
8 * 3. "Donors" changes to "Donors"
9 * 4. "Payment Method" stays.
10 *
11 * @package Give
12 * @subpackage Admin/Reports
13 * @copyright Copyright (c) 2016, GiveWP
14 * @license https://opensource.org/licenses/gpl-license GNU Public License
15 * @since 1.0
16 */
17
18 // Exit if accessed directly.
19 if ( ! defined( 'ABSPATH' ) ) {
20 exit;
21 }
22
23 /**
24 * Reports Page
25 *
26 * Renders the reports page contents.
27 *
28 * @since 1.0
29 * @return void
30 */
31 function give_reports_page() {
32 $current_page = admin_url( 'edit.php?post_type=give_forms&page=give-reports' );
33 $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'earnings';
34 $views = give_reports_default_views();
35 ?>
36 <div class="wrap give-settings-page">
37
38 <h1 class="screen-reader-text"><?php echo get_admin_page_title(); ?></h1>
39
40 <h2 class="nav-tab-wrapper">
41 <?php foreach ( $views as $tab => $label ) { ?>
42 <a href="
43 <?php
44 echo esc_url(
45 add_query_arg(
46 [
47 'tab' => $tab,
48 'settings-updated' => false,
49 ],
50 $current_page
51 )
52 );
53 ?>
54 " class="nav-tab <?php echo $tab === $active_tab ? esc_attr( 'nav-tab-active' ) : ''; ?>"><?php echo esc_html( $label ); ?></a>
55 <?php } ?>
56 <?php if ( current_user_can( 'export_give_reports' ) ) { ?>
57 <a href="
58 <?php
59 echo esc_url(
60 add_query_arg(
61 [
62 'tab' => 'export',
63 'settings-updated' => false,
64 ],
65 $current_page
66 )
67 );
68 ?>
69 " class="nav-tab <?php echo 'export' === $active_tab ? esc_attr( 'nav-tab-active' ) : ''; ?>"><?php esc_html_e( 'Export', 'give' ); ?></a>
70 <?php
71 }
72 /**
73 * Fires in the report tabs.
74 *
75 * Allows you to add new report tabs.
76 *
77 * @since 1.0
78 */
79 do_action( 'give_reports_tabs' );
80 ?>
81 </h2>
82
83 <?php
84 /**
85 * Fires before the report page.
86 *
87 * @since 1.0
88 */
89 do_action( 'give_reports_page_top' );
90
91 // Set $active_tab prior to hook firing.
92 if ( in_array( $active_tab, array_keys( $views ) ) ) {
93 $active_tab = 'reports';
94 }
95
96 /**
97 * Fires the report page active tab.
98 *
99 * @since 1.0
100 */
101 do_action( "give_reports_tab_{$active_tab}" );
102
103 /**
104 * Fires after the report page.
105 *
106 * @since 1.0
107 */
108 do_action( 'give_reports_page_bottom' );
109 ?>
110 </div><!-- .wrap -->
111 <?php
112 }
113
114 /**
115 * Default Report Views
116 *
117 * @since 1.0
118 * @return array $views Report Views
119 */
120 function give_reports_default_views() {
121 $views = [
122 'earnings' => esc_html__( 'Revenue', 'give' ),
123 'forms' => esc_html__( 'Forms', 'give' ),
124 'gateways' => esc_html__( 'Donation Methods', 'give' ),
125 ];
126
127 $views = apply_filters( 'give_report_views', $views );
128
129 return $views;
130 }
131
132 /**
133 * Default Report Views
134 *
135 * Checks the $_GET['view'] parameter to ensure it exists within the default allowed views.
136 *
137 * @param string $default Default view to use.
138 *
139 * @since 1.0
140 * @return string $view Report View
141 */
142 function give_get_reporting_view( $default = 'earnings' ) {
143
144 if ( ! isset( $_GET['view'] ) || ! in_array( $_GET['view'], array_keys( give_reports_default_views() ) ) ) {
145 $view = $default;
146 } else {
147 $view = $_GET['view'];
148 }
149
150 return apply_filters( 'give_get_reporting_view', $view );
151 }
152
153 /**
154 * Renders the Reports page
155 *
156 * @since 1.0
157 * @return void
158 */
159 function give_reports_tab_reports() {
160
161 if ( ! current_user_can( 'view_give_reports' ) ) {
162 wp_die( __( 'You do not have permission to access this report', 'give' ), __( 'Error', 'give' ), [ 'response' => 403 ] );
163 }
164
165 $current_view = 'earnings';
166 $views = give_reports_default_views();
167
168 if ( isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $views ) ) {
169 $current_view = $_GET['tab'];
170 }
171
172 /**
173 * Fires the report page view.
174 *
175 * @since 1.0
176 */
177 do_action( "give_reports_view_{$current_view}" );
178 }
179
180 add_action( 'give_reports_tab_reports', 'give_reports_tab_reports' );
181
182 /**
183 * Renders the Reports Page Views Drop Downs
184 *
185 * @since 1.0
186 * @return void
187 */
188 function give_report_views() {
189 $views = give_reports_default_views();
190 $current_view = isset( $_GET['view'] ) ? $_GET['view'] : 'earnings';
191 /**
192 * Fires before the report page actions form.
193 *
194 * @since 1.0
195 */
196 do_action( 'give_report_view_actions_before' );
197 ?>
198 <form id="give-reports-filter" method="get">
199 <select id="give-reports-view" name="view">
200 <option value="-1"><?php esc_html_e( 'Report Type', 'give' ); ?></option>
201 <?php foreach ( $views as $view_id => $label ) : ?>
202 <option value="<?php echo esc_attr( $view_id ); ?>" <?php selected( $view_id, $current_view ); ?>><?php echo $label; ?></option>
203 <?php endforeach; ?>
204 </select>
205
206 <?php
207 /**
208 * Fires in the report page actions area.
209 *
210 * Allows you to add new elements/actions after the "Report Type" drop down.
211 *
212 * @since 1.0
213 */
214 do_action( 'give_report_view_actions' );
215 ?>
216
217 <input type="hidden" name="post_type" value="give_forms"/>
218 <input type="hidden" name="page" value="give-reports"/>
219 <?php submit_button( esc_html__( 'Show', 'give' ), 'secondary', 'submit', false ); ?>
220 </form>
221 <?php
222 /**
223 * Fires after the report page actions form.
224 *
225 * @since 1.0
226 */
227 do_action( 'give_report_view_actions_after' );
228 }
229
230 /**
231 * Renders the Reports Give Form Table
232 *
233 * @since 1.0
234 * @uses Give_Form_Reports_Table::prepare_items()
235 * @uses Give_Form_Reports_Table::display()
236 * @return void
237 */
238 function give_reports_forms_table() {
239
240 if ( isset( $_GET['form-id'] ) ) {
241 return;
242 }
243
244 include GIVE_PLUGIN_DIR . 'includes/admin/reports/class-form-reports-table.php';
245
246 $give_table = new Give_Form_Reports_Table();
247 $give_table->prepare_items();
248 $give_table->display();
249 ?>
250 <input type="hidden" name="post_type" value="give_forms"/>
251 <input type="hidden" name="page" value="give-reports"/>
252 <input type="hidden" name="tab" value="forms"/>
253 <?php
254 }
255
256 add_action( 'give_reports_view_forms', 'give_reports_forms_table' );
257
258 /**
259 * Renders the detailed report for a specific give form.
260 *
261 * @since 1.0
262 * @return void
263 */
264 function give_reports_form_details() {
265 if ( ! isset( $_GET['form-id'] ) ) {
266 return;
267 }
268 ?>
269 <div class="tablenav top reports-forms-details-wrap">
270 <div class="actions bulkactions">
271 <button onclick="history.go(-1);" class="button-secondary"><?php esc_html_e( 'Go Back', 'give' ); ?></button>
272 </div>
273 </div>
274 <?php
275 give_reports_graph_of_form( absint( $_GET['form-id'] ) );
276 }
277
278 add_action( 'give_reports_view_forms', 'give_reports_form_details' );
279
280 /**
281 * Renders the Gateways Table
282 *
283 * @since 1.3
284 * @uses Give_Gateway_Reports_Table::prepare_items()
285 * @uses Give_Gateway_Reports_Table::display()
286 * @return void
287 */
288 function give_reports_gateways_table() {
289 include GIVE_PLUGIN_DIR . 'includes/admin/reports/class-gateways-reports-table.php';
290
291 $give_table = new Give_Gateway_Reports_Table();
292 $give_table->prepare_items();
293 $give_table->display();
294 }
295
296 add_action( 'give_reports_view_gateways', 'give_reports_gateways_table' );
297
298 /**
299 * Renders the Reports Earnings Graphs
300 *
301 * @since 3.22.1 added permissions check
302 * @since 1.0
303 * @return void
304 */
305 function give_reports_earnings() {
306 if (!current_user_can('view_give_reports')){
307 wp_die(__('You do not have permission to access this report', 'give'), __('Error', 'give'), ['response' => 403]);
308 }
309
310 ?>
311 <div class="tablenav top reports-table-nav">
312 <h2 class="reports-earnings-title screen-reader-text"><?php _e( 'Revenue Report', 'give' ); ?></h2>
313 </div>
314 <?php
315 give_reports_graph();
316 }
317
318 add_action( 'give_reports_view_earnings', 'give_reports_earnings' );
319
320
321 /**
322 * Retrieves estimated monthly earnings and sales
323 *
324 * @since 1.0
325 * @return array
326 */
327 function give_estimated_monthly_stats() {
328
329 $estimated = Give_Cache::get( 'give_estimated_monthly_stats', true );
330
331 if ( false === $estimated ) {
332
333 $estimated = [
334 'earnings' => 0,
335 'sales' => 0,
336 ];
337
338 $stats = new Give_Payment_Stats();
339
340 $to_date_earnings = $stats->get_earnings( 0, 'this_month' );
341 $to_date_sales = $stats->get_sales( 0, 'this_month' );
342
343 $current_day = date( 'd', current_time( 'timestamp' ) );
344 $current_month = date( 'n', current_time( 'timestamp' ) );
345 $current_year = date( 'Y', current_time( 'timestamp' ) );
346 $days_in_month = cal_days_in_month( CAL_GREGORIAN, $current_month, $current_year );
347
348 $estimated['earnings'] = ( $to_date_earnings / $current_day ) * $days_in_month;
349 $estimated['sales'] = ( $to_date_sales / $current_day ) * $days_in_month;
350
351 // Cache for one day
352 Give_Cache::set( 'give_estimated_monthly_stats', $estimated, DAY_IN_SECONDS, true );
353 }
354
355 return maybe_unserialize( $estimated );
356 }
357
358 /**
359 * Assign Get form method for reporting tabs
360 *
361 * @since 1.8.12
362 *
363 * @return string
364 */
365 function give_reports_set_form_method() {
366 return 'get';
367 }
368 add_filter( 'give-reports_form_method_tab_forms', 'give_reports_set_form_method', 10 );
369 add_filter( 'give-reports_form_method_tab_donors', 'give_reports_set_form_method', 10 );
370
371 // @TODO: After release 1.8 Donations -> Reports generates with new setting api, so we can remove some old code from this file.
372