Completed
Push — issues/1038 ( 5071fd...ff8350 )
by Ravinder
30:44 queued 10:46
created

Give_Settings_Logs::get_settings()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 36
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 17
nc 1
nop 0
dl 0
loc 36
rs 8.8571
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 13.

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
 * Give Settings Page/Tab
4
 *
5
 * @package     Give
6
 * @subpackage  Classes/Give_Settings_Logs
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
if ( ! class_exists( 'Give_Settings_Logs' ) ) :
17
18
	/**
19
	 * Give_Settings_Logs.
20
	 *
21
	 * @sine 1.8
22
	 */
23
	class Give_Settings_Logs extends Give_Settings_Page {
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    = 'logs';
46
			$this->label = esc_html__( 'Logs', 'give' );
47
48
			$this->default_tab = 'sales';
49
50
			parent::__construct();
51
52
			// Do not use main form for this tab.
53
			if ( give_get_current_setting_tab() === $this->id ) {
54
				add_action( 'give-tools_open_form', '__return_empty_string' );
55
				add_action( 'give-tools_close_form', '__return_empty_string' );
56
			}
57
58
			// Render logs field type.
59
			add_action( 'give_admin_field_logs', array( $this, 'render_logs_field' ) );
60
		}
61
62
		/**
63
		 * Add this page to settings.
64
		 *
65
		 * @since  1.8
66
		 *
67
		 * @param  array $pages Lst of pages.
68
		 *
69
		 * @return array
70
		 */
71
		public function add_settings_page( $pages ) {
72
			$pages[ $this->id ] = $this->label;
73
74
			return $pages;
75
		}
76
77
		/**
78
		 * Get settings array.
79
		 *
80
		 * @since  1.8
81
		 * @return array
82
		 */
83
		public function get_settings() {
84
			// Hide save button.
85
			$GLOBALS['give_hide_save_button'] = true;
86
87
			// Get settings.
88
			$settings = apply_filters( 'give_settings_logs', array(
89
				array(
90
					'id'         => 'give_tools_logs',
91
					'type'       => 'title',
92
					'table_html' => false,
93
				),
94
				array(
95
					'id'   => 'api',
96
					'name' => esc_html__( 'Log', 'give' ),
97
					'type' => 'logs',
98
99
				),
100
				array(
101
					'id'         => 'give_tools_logs',
102
					'type'       => 'sectionend',
103
					'table_html' => false,
104
				),
105
			) );
106
107
			/**
108
			 * Filter the settings.
109
			 *
110
			 * @since  1.8
111
			 *
112
			 * @param  array $settings
113
			 */
114
			$settings = apply_filters( 'give_get_settings_' . $this->id, $settings );
115
116
			// Output.
117
			return $settings;
118
		}
119
120
		/**
121
		 * Get sections.
122
		 *
123
		 * @since 1.8
124
		 * @return array
125
		 */
126
		public function get_sections() {
127
			$sections = array(
128
				'sales'          => esc_html__( 'Donations', 'give' ),
129
				'gateway_errors' => esc_html__( 'Payment Errors', 'give' ),
130
				'api_requests'   => esc_html__( 'API Requests', 'give' ),
131
			);
132
133
			$sections = apply_filters( 'give_log_views', $sections );
134
135
			return apply_filters( 'give_get_sections_' . $this->id, $sections );
136
		}
137
138
		/**
139
		 * Output the settings.
140
		 *
141
		 * @since  1.8
142
		 * @return void
143
		 */
144
		public function output() {
145
			$settings = $this->get_settings();
146
147
			Give_Admin_Settings::output_fields( $settings, 'give_settings' );
148
		}
149
150
151
		/**
152
		 * Render logs field.
153
		 *
154
		 * @since 1.9
155
		 * @access public
156
		 * @param $field
157
		 */
158
		public function render_logs_field( $field ) {
159
			give_reports_tab_logs();
160
			echo Give_Admin_Settings::get_field_description( $field );
161
		}
162
	}
163
164
endif;
165
166
return new Give_Settings_Logs();
167