Completed
Push — master ( 45f118...bcc91e )
by Devin
17:37 queued 14:12
created

Give_Settings_License::save()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 13
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_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
		}
51
52
		/**
53
		 * Add this page to settings.
54
		 *
55
		 * @since  1.8
56
		 * @param  array $pages Lst of pages.
57
		 * @return array
58
		 */
59
		public function add_settings_page( $pages ) {
60
			$setting = $this->get_settings();
61
			// Bailout: Do not add licenses setting tab if it does not contain any setting fields.
62
			if( ! empty( $setting ) ) {
63
				$pages[ $this->id ] = $this->label;
64
			}
65
66
			return $pages;
67
		}
68
69
		/**
70
		 * Get settings array.
71
		 *
72
		 * @since  1.8
73
		 * @return array
74
		 */
75
		public function get_settings() {
76
			$settings = array();
77
78
			/**
79
			 * Filter the licenses settings.
80
			 * Backward compatibility: Please do not use this filter. This filter is deprecated in 1.8
81
			 */
82
			$settings = apply_filters( 'give_settings_licenses', $settings );
83
84
			/**
85
			 * Filter the settings.
86
			 *
87
			 * @since  1.8
88
			 * @param  array $settings
89
			 */
90
			$settings = apply_filters( 'give_get_settings_' . $this->id, $settings );
91
92
			// Output.
93
			return $settings;
94
		}
95
96
		/**
97
		 * Output the settings.
98
		 *
99
		 * @since  1.8
100
		 * @return void
101
		 */
102
		public function output() {
103
			$settings = $this->get_settings();
104
105
			Give_Admin_Settings::output_fields( $settings, 'give_settings' );
106
		}
107
	}
108
109
endif;
110
111
return new Give_Settings_License();
112