Completed
Push — master ( 9e3902...3c0417 )
by Devin
39:54 queued 19:56
created

Give_Settings_License   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 106
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A add_settings_page() 0 9 2
A get_settings() 0 20 1
A output() 0 5 1
A save() 0 13 1
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_License
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_License' ) ) :
17
18
	/**
19
	 * Give_Settings_License.
20
	 *
21
	 * @sine 1.8
22
	 */
23
	class Give_Settings_License {
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    = 'licenses';
46
			$this->label = esc_html__( 'Licenses', 'give' );
47
48
			add_filter( 'give-settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
49
			add_action( "give-settings_settings_{$this->id}_page", array( $this, 'output' ) );
50
			add_action( "give-settings_save_{$this->id}", array( $this, 'save' ) );
51
		}
52
53
		/**
54
		 * Add this page to settings.
55
		 *
56
		 * @since  1.8
57
		 * @param  array $pages Lst of pages.
58
		 * @return array
59
		 */
60
		public function add_settings_page( $pages ) {
61
			$setting = $this->get_settings();
62
			// Bailout: Do not add licenses setting tab if it does not contain any setting fields.
63
			if( ! empty( $setting ) ) {
64
				$pages[ $this->id ] = $this->label;
65
			}
66
67
			return $pages;
68
		}
69
70
		/**
71
		 * Get settings array.
72
		 *
73
		 * @since  1.8
74
		 * @return array
75
		 */
76
		public function get_settings() {
77
			$settings = array();
78
79
			/**
80
			 * Filter the licenses settings.
81
			 * Backward compatibility: Please do not use this filter. This filter is deprecated in 1.8
82
			 */
83
			$settings = apply_filters( 'give_settings_licenses', $settings );
84
85
			/**
86
			 * Filter the settings.
87
			 *
88
			 * @since  1.8
89
			 * @param  array $settings
90
			 */
91
			$settings = apply_filters( 'give_get_settings_' . $this->id, $settings );
92
93
			// Output.
94
			return $settings;
95
		}
96
97
		/**
98
		 * Output the settings.
99
		 *
100
		 * @since  1.8
101
		 * @return void
102
		 */
103
		public function output() {
104
			$settings = $this->get_settings();
105
106
			Give_Admin_Settings::output_fields( $settings, 'give_settings' );
107
		}
108
109
		/**
110
		 * Save settings.
111
		 *
112
		 * @since  1.8
113
		 * @return void
114
		 */
115
		public function save() {
116
			$settings        = $this->get_settings();
117
			$current_section = give_get_current_setting_section();
118
119
			Give_Admin_Settings::save_fields( $settings, 'give_settings' );
120
121
			/**
122
			 * Trigger Action
123
			 *
124
			 * @since 1.8
125
			 */
126
			do_action( 'give_update_options_' . $this->id . '_' . $current_section );
127
		}
128
	}
129
130
endif;
131
132
return new Give_Settings_License();
133