Completed
Push — issue/1680 ( 7086f3 )
by Ravinder
18:25
created

export-actions.php ➔ give_export_earnings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 23 and the first side effect is on line 14.

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.

Loading history...
2
/**
3
 * Exports Actions
4
 *
5
 * These are actions related to exporting data from Give
6
 *
7
 * @package     Give
8
 * @subpackage  Admin/Export
9
 * @copyright   Copyright (c) 2016, WordImpress
10
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
11
 */
12
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * Process the download file generated by a batch export
19
 *
20
 * @since 1.5
21
 * @return void
22
 */
23
function give_process_batch_export_form() {
24
25
	if ( ! wp_verify_nonce( $_REQUEST['nonce'], 'give-batch-export' ) ) {
26
		wp_die( esc_html__( 'Nonce verification failed.', 'give' ), esc_html__( 'Error', 'give' ), array( 'response' => 403 ) );
27
	}
28
29
	require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/export/class-batch-export.php';
30
31
	/**
32
	 * Fires before batch export.
33
	 *
34
	 * @since 1.5
35
	 *
36
	 * @param string $class Export class.
37
	 */
38
	do_action( 'give_batch_export_class_include', $_REQUEST['class'] );
39
40
	$export = new $_REQUEST['class'];
41
	$export->export();
42
43
}
44
45
add_action( 'give_form_batch_export', 'give_process_batch_export_form' );
46
47
/**
48
 * Exports earnings for a specified time period
49
 *
50
 * Give_Earnings_Export class.
51
 *
52
 * @since 1.5
53
 * @return void
54
 */
55
function give_export_earnings() {
56
	require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/export/class-export-earnings.php';
57
58
	$earnings_export = new Give_Earnings_Export();
59
60
	$earnings_export->export();
61
}
62
63
add_action( 'give_earnings_export', 'give_export_earnings' );
64
65
66
/**
67
 * Add a hook allowing extensions to register a hook on the batch export process
68
 *
69
 * @since  1.5
70
 * @return void
71
 */
72
function give_register_batch_exporters() {
73
	if ( is_admin() ) {
74
		/**
75
		 * Fires in the admin, while plugins loaded.
76
		 *
77
		 * Allowing extensions to register a hook on the batch export process.
78
		 *
79
		 * @since 1.5
80
		 *
81
		 * @param string $class Export class.
82
		 */
83
		do_action( 'give_register_batch_exporter' );
84
	}
85
}
86
87
add_action( 'plugins_loaded', 'give_register_batch_exporters' );
88
89
/**
90
 * Register the payments batch exporter
91
 *
92
 * @since  1.5
93
 */
94
function give_register_payments_batch_export() {
95
	add_action( 'give_batch_export_class_include', 'give_include_payments_batch_processor', 10, 1 );
96
}
97
98
add_action( 'give_register_batch_exporter', 'give_register_payments_batch_export', 10 );
99
100
/**
101
 * Loads the payments batch process if needed
102
 *
103
 * @since  1.5
104
 *
105
 * @param  string $class The class being requested to run for the batch export
106
 *
107
 * @return void
108
 */
109
function give_include_payments_batch_processor( $class ) {
110
111
	if ( 'Give_Batch_Payments_Export' === $class ) {
112
		require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/export/class-batch-export-payments.php';
113
	}
114
115
}
116
117
/**
118
 * Register the customers batch exporter
119
 *
120
 * @since  1.5.2
121
 */
122
function give_register_customers_batch_export() {
123
	add_action( 'give_batch_export_class_include', 'give_include_customers_batch_processor', 10, 1 );
124
}
125
126
add_action( 'give_register_batch_exporter', 'give_register_customers_batch_export', 10 );
127
128
/**
129
 * Loads the customers batch process if needed
130
 *
131
 * @since  1.5.2
132
 *
133
 * @param  string $class The class being requested to run for the batch export
134
 *
135
 * @return void
136
 */
137
function give_include_customers_batch_processor( $class ) {
138
139
	if ( 'Give_Batch_Customers_Export' === $class ) {
140
		require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/export/class-batch-export-customers.php';
141
	}
142
143
}
144
145
/**
146
 * Register the download products batch exporter
147
 *
148
 * @since  1.5
149
 */
150
function give_register_forms_batch_export() {
151
	add_action( 'give_batch_export_class_include', 'give_include_forms_batch_processor', 10, 1 );
152
}
153
154
add_action( 'give_register_batch_exporter', 'give_register_forms_batch_export', 10 );
155
156
/**
157
 * Loads the file downloads batch process if needed
158
 *
159
 * @since  1.5
160
 *
161
 * @param  string $class The class being requested to run for the batch export
162
 *
163
 * @return void
164
 */
165
function give_include_forms_batch_processor( $class ) {
166
167
	if ( 'Give_Batch_Forms_Export' === $class ) {
168
		require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/export/class-batch-export-forms.php';
169
	}
170
171
}
172