|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Give Reports Page/Tab |
|
4
|
|
|
* |
|
5
|
|
|
* @package Give |
|
6
|
|
|
* @subpackage Classes/Give_Gateways_Report |
|
7
|
|
|
* @copyright Copyright (c) 2016, WordImpress |
|
8
|
|
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
|
9
|
|
|
* @since 1.8 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
13
|
|
|
exit; // Exit if accessed directly |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
View Code Duplication |
if ( ! class_exists( 'Give_Gateways_Report' ) ) : |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Give_Gateways_Report. |
|
20
|
|
|
* |
|
21
|
|
|
* @sine 1.8 |
|
22
|
|
|
*/ |
|
23
|
|
|
class Give_Gateways_Report { |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Setting page id. |
|
27
|
|
|
* |
|
28
|
|
|
* @since 1.8 |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $id = ''; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Setting page label. |
|
35
|
|
|
* |
|
36
|
|
|
* @since 1.8 |
|
37
|
|
|
* @var string |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $label = ''; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Constructor. |
|
43
|
|
|
*/ |
|
44
|
|
|
public function __construct() { |
|
45
|
|
|
$this->id = 'gateways'; |
|
46
|
|
|
$this->label = esc_html__( 'Donation Methods', 'give' ); |
|
47
|
|
|
|
|
48
|
|
|
add_filter( 'give-reports_tabs_array', array( $this, 'add_settings_page' ), 20 ); |
|
49
|
|
|
add_action( "give-reports_settings_{$this->id}_page", array( $this, 'output' ) ); |
|
50
|
|
|
add_action( 'give_admin_field_report_gateways', array( $this, 'render_report_gateways_field' ), 10, 2 ); |
|
51
|
|
|
|
|
52
|
|
|
// Do not use main form for this tab. |
|
53
|
|
|
if( give_get_current_setting_tab() === $this->id ) { |
|
|
|
|
|
|
54
|
|
|
add_action( 'give-reports_open_form', '__return_empty_string' ); |
|
55
|
|
|
add_action( 'give-reports_close_form', '__return_empty_string' ); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Add this page to settings. |
|
61
|
|
|
* |
|
62
|
|
|
* @since 1.8 |
|
63
|
|
|
* @param array $pages Lst of pages. |
|
64
|
|
|
* @return array |
|
65
|
|
|
*/ |
|
66
|
|
|
public function add_settings_page( $pages ) { |
|
67
|
|
|
$pages[ $this->id ] = $this->label; |
|
68
|
|
|
|
|
69
|
|
|
return $pages; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Get settings array. |
|
74
|
|
|
* |
|
75
|
|
|
* @since 1.8 |
|
76
|
|
|
* @return array |
|
77
|
|
|
*/ |
|
78
|
|
|
public function get_settings() { |
|
79
|
|
|
// Hide save button. |
|
80
|
|
|
$GLOBALS['give_hide_save_button'] = true; |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Filter the settings. |
|
84
|
|
|
* |
|
85
|
|
|
* @since 1.8 |
|
86
|
|
|
* @param array $settings |
|
87
|
|
|
*/ |
|
88
|
|
|
$settings = apply_filters( |
|
89
|
|
|
'give_get_settings_' . $this->id, |
|
90
|
|
|
array( |
|
91
|
|
|
array( |
|
92
|
|
|
'id' => 'give_reports_gateways', |
|
93
|
|
|
'type' => 'title', |
|
94
|
|
|
'table_html' => false |
|
|
|
|
|
|
95
|
|
|
), |
|
96
|
|
|
array( |
|
97
|
|
|
'id' => 'gateways', |
|
98
|
|
|
'name' => esc_html__( 'Gateways', 'give' ), |
|
99
|
|
|
'type' => 'report_gateways', |
|
100
|
|
|
), |
|
101
|
|
|
array( |
|
102
|
|
|
'id' => 'give_reports_gateways', |
|
103
|
|
|
'type' => 'sectionend', |
|
104
|
|
|
'table_html' => false |
|
|
|
|
|
|
105
|
|
|
) |
|
|
|
|
|
|
106
|
|
|
) |
|
107
|
|
|
); |
|
108
|
|
|
|
|
109
|
|
|
// Output. |
|
110
|
|
|
return $settings; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Output the settings. |
|
115
|
|
|
* |
|
116
|
|
|
* @since 1.8 |
|
117
|
|
|
* @return void |
|
118
|
|
|
*/ |
|
119
|
|
|
public function output() { |
|
120
|
|
|
$settings = $this->get_settings(); |
|
121
|
|
|
|
|
122
|
|
|
Give_Admin_Settings::output_fields( $settings, 'give_settings' ); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Render earning field |
|
127
|
|
|
* |
|
128
|
|
|
* @since 1.8 |
|
129
|
|
|
* @access public |
|
130
|
|
|
* |
|
131
|
|
|
* @param $field |
|
132
|
|
|
* @param $option_value |
|
133
|
|
|
*/ |
|
134
|
|
|
public function render_report_gateways_field( $field, $option_value ) { |
|
|
|
|
|
|
135
|
|
|
do_action( 'give_reports_view_gateways'); |
|
|
|
|
|
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
endif; |
|
140
|
|
|
|
|
141
|
|
|
return new Give_Gateways_Report(); |
|
142
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.