1
|
|
|
<?php |
|
|
|
|
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 |
|
|
|
|
40
|
|
|
*/ |
41
|
|
|
function set_default_setting_tab( $setting_tab ) { |
|
|
|
|
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
|
|
|
|
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.