Completed
Pull Request — master (#1412)
by Ravinder
17:25
created

Give_Settings_Addon::get_settings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 20
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_Addon
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_Addon' ) ) :
17
18
	/**
19
	 * Give_Settings_Addon.
20
	 *
21
	 * @sine 1.8
22
	 */
23
	class Give_Settings_Addon extends Give_Settings_Page {
24
		/**
25
		 * Constructor.
26
		 */
27
		public function __construct() {
28
			$this->id    = 'addons';
29
			$this->label = esc_html__( 'Add-ons', 'give' );
30
31
			parent::__construct();
32
		}
33
34
		/**
35
		 * Default setting tab.
36
		 *
37
		 * @since  1.8
38
		 * @param  $setting_tab
39
		 * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be integer|string|false?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
40
		 */
41
		function set_default_setting_tab( $setting_tab ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
42
			$default_tab = '';
43
44
			// Set default tab to first setting tab.
45
			if( $sections = array_keys( $this->get_sections() ) ) {
46
				$default_tab = current( $sections );
47
			}
48
			return $default_tab;
49
		}
50
51
		/**
52
		 * Add this page to settings.
53
		 *
54
		 * @since  1.8
55
		 * @param  array $pages Lst of pages.
56
		 * @return array
57
		 */
58
		public function add_settings_page( $pages ) {
59
			$setting = $this->get_settings();
60
			// Bailout: Do not add addons setting tab if it does not contain any setting fields.
61
			if( ! empty( $setting ) ) {
62
				$pages[ $this->id ] = $this->label;
63
			}
64
65
			return $pages;
66
		}
67
68
		/**
69
		 * Get settings array.
70
		 *
71
		 * @since  1.8
72
		 * @return array
73
		 */
74
		public function get_settings() {
75
			$settings = array();
76
77
			/**
78
			 * Filter the addons settings.
79
			 * Backward compatibility: Please do not use this filter. This filter is deprecated in 1.8
80
			 */
81
			$settings = apply_filters( 'give_settings_addons', $settings );
82
83
			/**
84
			 * Filter the settings.
85
			 *
86
			 * @since  1.8
87
			 * @param  array $settings
88
			 */
89
			$settings = apply_filters( 'give_get_settings_' . $this->id, $settings );
90
91
			// Output.
92
			return $settings;
93
		}
94
	}
95
96
endif;
97
98
return new Give_Settings_Addon();
99