1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* Logs UI |
4
|
|
|
* |
5
|
|
|
* @package Give |
6
|
|
|
* @subpackage Admin/Reports |
7
|
|
|
* @copyright Copyright (c) 2016, WordImpress |
8
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
9
|
|
|
* @since 1.0 |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
// Exit if accessed directly |
13
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
14
|
|
|
exit; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Sales Log View |
19
|
|
|
* |
20
|
|
|
* @since 1.0 |
21
|
|
|
* @uses Give_Sales_Log_Table::prepare_items() |
22
|
|
|
* @uses Give_Sales_Log_Table::display() |
23
|
|
|
* @return void |
24
|
|
|
*/ |
25
|
|
|
function give_logs_view_sales() { |
26
|
|
|
include( dirname( __FILE__ ) . '/class-sales-logs-list-table.php' ); |
27
|
|
|
|
28
|
|
|
$logs_table = new Give_Sales_Log_Table(); |
29
|
|
|
$logs_table->prepare_items(); |
30
|
|
|
$logs_table->display(); |
31
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
add_action( 'give_logs_view_sales', 'give_logs_view_sales' ); |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Gateway Error Logs |
39
|
|
|
* |
40
|
|
|
* @since 1.0 |
41
|
|
|
* @uses Give_File_Downloads_Log_Table::prepare_items() |
42
|
|
|
* @uses Give_File_Downloads_Log_Table::display() |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
|
|
function give_logs_view_gateway_errors() { |
46
|
|
|
include( dirname( __FILE__ ) . '/class-gateway-error-logs-list-table.php' ); |
47
|
|
|
|
48
|
|
|
$logs_table = new Give_Gateway_Error_Log_Table(); |
49
|
|
|
$logs_table->prepare_items(); |
50
|
|
|
$logs_table->display(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
add_action( 'give_logs_view_gateway_errors', 'give_logs_view_gateway_errors' ); |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* API Request Logs |
57
|
|
|
* |
58
|
|
|
* @since 1.0 |
59
|
|
|
* @uses Give_API_Request_Log_Table::prepare_items() |
60
|
|
|
* @uses Give_API_Request_Log_Table::search_box() |
61
|
|
|
* @uses Give_API_Request_Log_Table::display() |
62
|
|
|
* @return void |
63
|
|
|
*/ |
64
|
|
|
function give_logs_view_api_requests() { |
65
|
|
|
include( dirname( __FILE__ ) . '/class-api-requests-logs-list-table.php' ); |
66
|
|
|
|
67
|
|
|
$logs_table = new Give_API_Request_Log_Table(); |
68
|
|
|
$logs_table->prepare_items(); |
69
|
|
|
?> |
70
|
|
|
<div class="wrap"> |
71
|
|
|
|
72
|
|
|
<?php do_action( 'give_logs_api_requests_top' ); ?> |
73
|
|
|
|
74
|
|
|
<form id="give-logs-filter" method="get" action="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-reports&tab=logs' ); ?>"> |
75
|
|
|
<?php |
76
|
|
|
$logs_table->search_box( esc_html__( 'Search', 'give' ), 'give-api-requests' ); |
77
|
|
|
$logs_table->display(); |
78
|
|
|
?> |
79
|
|
|
<input type="hidden" name="post_type" value="give_forms"/> |
80
|
|
|
<input type="hidden" name="page" value="give-reports"/> |
81
|
|
|
<input type="hidden" name="tab" value="logs"/> |
82
|
|
|
</form> |
83
|
|
|
<?php do_action( 'give_logs_api_requests_bottom' ); ?> |
84
|
|
|
|
85
|
|
|
</div> |
86
|
|
|
<?php |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
add_action( 'give_logs_view_api_requests', 'give_logs_view_api_requests' ); |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Default Log Views |
94
|
|
|
* |
95
|
|
|
* @since 1.0 |
96
|
|
|
* @return array $views Log Views |
97
|
|
|
*/ |
98
|
|
|
function give_log_default_views() { |
99
|
|
|
$views = array( |
100
|
|
|
'sales' => esc_html__( 'Donations', 'give' ), |
101
|
|
|
'gateway_errors' => esc_html__( 'Payment Errors', 'give' ), |
102
|
|
|
'api_requests' => esc_html__( 'API Requests', 'give' ) |
103
|
|
|
); |
104
|
|
|
|
105
|
|
|
$views = apply_filters( 'give_log_views', $views ); |
106
|
|
|
|
107
|
|
|
return $views; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Renders the Reports page views drop down |
112
|
|
|
* |
113
|
|
|
* @since 1.0 |
114
|
|
|
* @return void |
115
|
|
|
*/ |
116
|
|
|
function give_log_views() { |
117
|
|
|
$views = give_log_default_views(); |
118
|
|
|
$current_view = isset( $_GET['view'] ) && array_key_exists( $_GET['view'], give_log_default_views() ) ? sanitize_text_field( $_GET['view'] ) : 'sales'; |
119
|
|
|
?> |
120
|
|
|
<form id="give-logs-filter" method="get" action="edit.php"> |
121
|
|
|
<select id="give-logs-view" name="view"> |
122
|
|
|
<optgroup label="Log Type:"> |
123
|
|
|
<?php foreach ( $views as $view_id => $label ): ?> |
124
|
|
|
<option value="<?php echo esc_attr( $view_id ); ?>" <?php selected( $view_id, $current_view ); ?>><?php echo $label; ?></option> |
125
|
|
|
<?php endforeach; ?> |
126
|
|
|
</optgroup> |
127
|
|
|
</select> |
128
|
|
|
|
129
|
|
|
<?php do_action( 'give_log_view_actions' ); ?> |
130
|
|
|
|
131
|
|
|
<input type="hidden" name="post_type" value="give_forms"/> |
132
|
|
|
<input type="hidden" name="page" value="give-reports"/> |
133
|
|
|
<input type="hidden" name="tab" value="logs"/> |
134
|
|
|
|
135
|
|
|
<?php submit_button( esc_html__( 'Apply', 'give' ), 'secondary', 'submit', false ); ?> |
136
|
|
|
</form> |
137
|
|
|
<?php |
138
|
|
|
} |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.