Completed
Push — issues/1368 ( 8a6df6 )
by Ravinder
17:47
created

Give_Settings_Logs::get_sections()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 11
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 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
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
			// Get settings.
83
			$settings = apply_filters( 'give_settings_system', array(
84
				array(
85
					'id'   => 'give_tools_logs',
86
					'type' => 'title',
87
					'table_html' => false
88
				),
89
				array(
90
					'id'   => 'api',
91
					'name' => esc_html__( 'Log', 'give' ),
92
					'type' => 'logs',
93
94
				),
95
				array(
96
					'id'   => 'give_tools_logs',
97
					'type' => 'sectionend',
98
					'table_html' => false
99
				)
100
			));
101
102
			/**
103
			 * Filter the settings.
104
			 *
105
			 * @since  1.8
106
			 * @param  array $settings
107
			 */
108
			$settings = apply_filters( 'give_get_settings_' . $this->id, $settings );
109
110
			// Output.
111
			return $settings;
112
		}
113
114
		/**
115
		 * Get sections.
116
		 *
117
		 * @since 1.8
118
		 * @return array
119
		 */
120
		public function get_sections() {
121
			$sections = array(
122
				'sales'          => esc_html__( 'Donations', 'give' ),
123
				'gateway_errors' => esc_html__( 'Payment Errors', 'give' ),
124
				'api_requests'   => esc_html__( 'API Requests', 'give' )
125
			);
126
127
			$sections = apply_filters( 'give_log_views', $sections );
128
129
			return apply_filters( 'give_get_sections_' . $this->id, $sections );
130
		}
131
132
		/**
133
		 * Output the settings.
134
		 *
135
		 * @since  1.8
136
		 * @return void
137
		 */
138
		public function output() {
139
			$settings = $this->get_settings();
140
141
			Give_Admin_Settings::output_fields( $settings, 'give_settings' );
142
		}
143
	}
144
145
endif;
146
147
return new Give_Settings_Logs();
148