settings.php ➔ s214_settings_demo_settings_sections()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 15
ccs 0
cts 9
cp 0
crap 2
rs 9.4285
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 22 and the first side effect is on line 11.

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
 * Settings
4
 *
5
 * @package     S214_Settings_Demo\Settings
6
 * @since       1.0.0
7
 */
8
9
// Exit if accessed directly
10
if( ! defined( 'ABSPATH' ) ) {
11
	exit;
12
}
13
14
15
/**
16
 * Add the plugin menu item
17
 *
18
 * @since       1.0.0
19
 * @param       array $menu The default menu settings
20
 * @return      array $menu Our customized settings
21
 */
22
function s214_settings_demo_add_menu( $menu ) {
23
	$menu['page_title']   = __( 'S214 Settings Demo', 's214-settings-demo' ); // Can be set to 'submenu' or 'menu'. Defaults to 'menu'.
24
	//$menu['parent']     = 'options-general.php';                            // If 'type' is set to 'submenu', defines the parent menu to place our menu under. Defaults to 'options-general.php'
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
25
	$menu['page_title']   = __( 'S214 Settings Demo', 's214-settings-demo' ); // The page title. Defaults to 'Section214 Settings'.
26
	$menu['show_title']   = true;                                             // Whether or not to display the title at the top of the page.
27
	$menu['menu_title']   = __( 'S214 Settings', 's214-settings-demo' );      // The menu title. Defaults to 'Section214 Settings'.
28
	//$menu['capability'] = 'manage_options';                                 // The minimum capability required to access the settings panel. Defaults to 'manage_options'.
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
29
	$menu['icon']         = 'dashicons-warning';                              // An (optional) icon for your menu item. Follows the same standards as the add_menu_item() function in WordPress.
30
	//$menu['position']   = null;                                             // Where in the menu to display our new menu. Defaults to 'null' (bottom of the menu).
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
31
32
	return $menu;
33
}
34
add_filter( 's214_settings_demo_menu', 's214_settings_demo_add_menu' );
35
36
37
/**
38
 * Define the tabs for the settings panel
39
 *
40
 * @since       1.0.0
41
 * @param       array $tabs The default settings tabs
42
 * @return      array $tabs Our customized tabs
43
 */
44
function s214_settings_demo_settings_tabs( $tabs ) {
0 ignored issues
show
Unused Code introduced by
The parameter $tabs is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
45
	$tabs = array(
46
		'welcome' => __( 'Welcome', 's214-settings-demo' ),
47
		'fields'  => __( 'Fields', 's214-settings-demo' )
48
	);
49
50
	return $tabs;
51
}
52
add_filter( 's214_settings_demo_settings_tabs', 's214_settings_demo_settings_tabs' );
53
54
55
/**
56
 * Define the unsavable tabs for the settings panel
57
 *
58
 * @since       1.0.0
59
 * @param       array $tabs The default unsavable tabs
60
 * @return      array $tabs Our customized tabs
61
 */
62
function s214_settings_demo_unsavable_tabs( $tabs ) {
0 ignored issues
show
Unused Code introduced by
The parameter $tabs is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
63
	$tabs = array(
64
		'welcome'
65
	);
66
67
	return $tabs;
68
}
69
add_filter( 's214_settings_demo_unsavable_tabs', 's214_settings_demo_unsavable_tabs' );
70
71
72
/**
73
 * Define the settings sections for the each tab
74
 *
75
 * @since       1.0.0
76
 * @param       array $tabs The default settings sections
0 ignored issues
show
Bug introduced by
There is no parameter named $tabs. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
77
 * @return      array $tabs Our customized sections
78
 */
79
function s214_settings_demo_settings_sections( $sections ) {
0 ignored issues
show
Unused Code introduced by
The parameter $sections is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
80
	$sections = array(
81
		'welcome' => array(
82
			'main' => __( 'Welcome Aboard!', 's214-settings-demo' )
83
		),
84
		'fields' => array(
85
			'text'     => __( 'Text Fields', 's214-settings-demo' ),
86
			'option'   => __( 'Option Fields', 's214-settings-demo' ),
87
			'misc'     => __( 'Misc Fields', 's214-settings-demo' ),
88
			'advanced' => __( 'Advanced Fields', 's214-settings-demo' )
89
		)
90
	);
91
92
	return $sections;
93
}
94
add_filter( 's214_settings_demo_registered_settings_sections', 's214_settings_demo_settings_sections' );
95
96
97
/**
98
 * Define the settings for the settings panel
99
 *
100
 * @since       1.0.0
101
 * @param       array $settings The default settings
102
 * @return      array $settings Our customized settings
103
 */
104
function s214_settings_demo_settings( $settings ) {
105
	$plugin_settings = array(
106
		'welcome' => array(
107
			'main' => array(
108
				array(
109
					'id'   => 'welcome_header',
110
					'name' => __( 'Welcome Aboard!', 's214-settings-demo' ),
111
					'desc' => '',
112
					'type' => 'header'
113
				),
114
				array(
115
					'id'            => 'welcome_note',
116
					'name'          => '',
117
					'desc'          => sprintf( __( 'This plugin will attempt to familiarize you with the various things this library is capable of. Just in case it wasn\'t obvious, the "Welcome Aboard" text above is an example of a %s field, and this field is a %s field. Remember, every field takes \'id\', \'name\', \'desc\' and \'type\' arguments!', 's214-settings-demo' ), '<a href="https://github.com/Section214/S214-Settings/wiki/Settings-Reference#header-implements-a-simple-header" target="_blank"><code>header</code></a>', '<a href="https://github.com/Section214/S214-Settings/wiki/Settings-Reference#descriptive_text-implements-a-descriptive-text-field" target="_blank"><code>descriptive_text</code></a>' ),
118
					'type'          => 'descriptive_text',
119
					'tooltip_title' => __( 'Hi There!', 's214-settings-demo' ),
120
					'tooltip_desc'  => __( 'Other than the \'header\' and \'hook\' field types, all fields can display a tooltip. Do this by adding \'tooltip_title\' and \'tooltip_desc\' arguments to the field array.', 's214-settings-demo' )
121
				),
122
				array(
123
					'id'   => 'thanks',
124
					'name' => __( 'Thanks EDD!', 's214-settings-demo' ),
125
					'desc' => '',
126
					'type' => 'hook'
127
				)
128
			)
129
		),
130
		'fields' => array(
131
			'text' => array(
132
				array(
133
					'id'   => 'text_header',
134
					'name' => __( 'Text Field Examples', 's214-settings-demo' ),
135
					'desc' => '',
136
					'type' => 'header'
137
				),
138
				array(
139
					'id'   => 'text',
140
					'name' => sprintf( __( '%s Field', 's214-settings-demo' ), 'text' ),
141
					'desc' => sprintf( __( 'Text fields can take \'std\', \'readonly\' and \'size\' arguements. Read more about text fields %s.', 's214-settings-demo' ), '<a href="https://github.com/Section214/S214-Settings/wiki/Settings-Reference#text-implements-a-text-field" target="_blank">' . __( 'here', 's214-settings-demo' ) . '</a>' ),
142
					'type' => 'text',
143
					'std'  => 'This is a text field'
144
				),
145
				array(
146
					'id'   => 'textarea',
147
					'name' => sprintf( __( '%s Field', 's214-settings-demo' ), 'textarea' ),
148
					'desc' => sprintf( __( 'Textarea fields can take a \'std\' arguement. Read more about textarea fields %s.', 's214-settings-demo' ), '<a href="https://github.com/Section214/S214-Settings/wiki/Settings-Reference#textarea-implements-a-text-area" target="_blank">' . __( 'here', 's214-settings-demo' ) . '</a>' ),
149
					'type' => 'textarea'
150
				),
151
				array(
152
					'id'   => 'editor',
153
					'name' => sprintf( __( '%s Field', 's214-settings-demo' ), 'editor' ),
154
					'desc' => sprintf( __( 'Editor fields can take \'std\', \'allow_blank\', \'size\', \'wpautop\', \'buttons\' and \'teeny\' arguements. Read more about editor fields %s.', 's214-settings-demo' ), '<a href="https://github.com/Section214/S214-Settings/wiki/Settings-Reference#editor-implements-a-rich-text-editor" target="_blank">' . __( 'here', 's214-settings-demo' ) . '</a>' ),
155
					'type' => 'editor'
156
				),
157
				array(
158
					'id'   => 'html',
159
					'name' => sprintf( __( '%s Field', 's214-settings-demo' ), 'html' ),
160
					'desc' => sprintf( __( 'HTML fields can take a \'std\' arguement. Read more about HTML fields %s.', 's214-settings-demo' ), '<a href="https://github.com/Section214/S214-Settings/wiki/Settings-Reference#html-implements-a-codemirror-html-field" target="_blank">' . __( 'here', 's214-settings-demo' ) . '</a>' ),
161
					'type' => 'html'
162
				),
163
				array(
164
					'id'   => 'password',
165
					'name' => sprintf( __( '%s Field', 's214-settings-demo' ), 'password' ),
166
					'desc' => sprintf( __( 'Password fields can take \'std\' and \'size\' arguements. Read more about password fields %s.', 's214-settings-demo' ), '<a href="https://github.com/Section214/S214-Settings/wiki/Settings-Reference#password-implements-a-password-field" target="_blank">' . __( 'here', 's214-settings-demo' ) . '</a>' ),
167
					'type' => 'password'
168
				)
169
			),
170
			'option' => array(
171
				array(
172
					'id'   => 'option_header',
173
					'name' => __( 'Option Field Examples', 's214-settings-demo' ),
174
					'desc' => '',
175
					'type' => 'header'
176
				),
177
				array(
178
					'id'   => 'checkbox',
179
					'name' => sprintf( __( '%s Field', 's214-settings-demo' ), 'checkbox' ),
180
					'desc' => sprintf( __( 'Checkbox fields only take the basic arguements. Read more about checkbox fields %s.', 's214-settings-demo' ), '<a href="https://github.com/Section214/S214-Settings/wiki/Settings-Reference#checkbox-implements-a-checkbox" target="_blank">' . __( 'here', 's214-settings-demo' ) . '</a>' ),
181
					'type' => 'checkbox'
182
				),
183
				array(
184
					'id'      => 'multicheck',
185
					'name'    => sprintf( __( '%s Field', 's214-settings-demo' ), 'multicheck' ),
186
					'desc'    => sprintf( __( 'Multicheck fields only take the basic arguements. Read more about multicheck fields %s.', 's214-settings-demo' ), '<a href="https://github.com/Section214/S214-Settings/wiki/Settings-Reference#multicheck-implements-a-multicheck-field" target="_blank">' . __( 'here', 's214-settings-demo' ) . '</a>' ),
187
					'type'    => 'multicheck',
188
					'options' => array(
189
						'option1' => __( 'Option 1', 's214-settings-demo' ),
190
						'option2' => __( 'Option 2', 's214-settings-demo' ),
191
						'option3' => __( 'Option 3', 's214-settings-demo' )
192
					)
193
				),
194
				array(
195
					'id'      => 'radio',
196
					'name'    => sprintf( __( '%s Field', 's214-settings-demo' ), 'radio' ),
197
					'desc'    => sprintf( __( 'Radio fields can take a \'std\' arguement. Read more about radio fields %s.', 's214-settings-demo' ), '<a href="https://github.com/Section214/S214-Settings/wiki/Settings-Reference#radio-implements-a-radio-button-list-field" target="_blank">' . __( 'here', 's214-settings-demo' ) . '</a>' ),
198
					'type'    => 'radio',
199
					'options' => array(
200
						'option1' => __( 'Option 1', 's214-settings-demo' ),
201
						'option2' => __( 'Option 2', 's214-settings-demo' ),
202
						'option3' => __( 'Option 3', 's214-settings-demo' )
203
					)
204
				),
205
				array(
206
					'id'      => 'select',
207
					'name'    => sprintf( __( '%s Field', 's214-settings-demo' ), 'select' ),
208
					'desc'    => sprintf( __( 'Select fields can take \'std\', \'placeholder\', \'select2\' and \'multiple\' arguements. Read more about select fields %s.', 's214-settings-demo' ), '<a href="https://github.com/Section214/S214-Settings/wiki/Settings-Reference#select-implements-a-select-field" target="_blank">' . __( 'here', 's214-settings-demo' ) . '</a>' ),
209
					'type'    => 'select',
210
					'options' => array(
211
						'option1' => __( 'Option 1', 's214-settings-demo' ),
212
						'option2' => __( 'Option 2', 's214-settings-demo' ),
213
						'option3' => __( 'Option 3', 's214-settings-demo' )
214
					)
215
				)
216
			),
217
			'misc' => array(
218
				array(
219
					'id'   => 'misc_header',
220
					'name' => __( 'Misc Field Examples', 's214-settings-demo' ),
221
					'desc' => '',
222
					'type' => 'header'
223
				),
224
				array(
225
					'id'   => 'color',
226
					'name' => sprintf( __( '%s Field', 's214-settings-demo' ), 'color' ),
227
					'desc' => sprintf( __( 'Color fields can take a \'std\' arguement. Read more about color fields %s.', 's214-settings-demo' ), '<a href="https://github.com/Section214/S214-Settings/wiki/Settings-Reference#color-implements-a-color-select-field" target="_blank">' . __( 'here', 's214-settings-demo' ) . '</a>' ),
228
					'type' => 'color',
229
					'std'  => '#000000'
230
				),
231
				array(
232
					'id'   => 'number',
233
					'name' => sprintf( __( '%s Field', 's214-settings-demo' ), 'number' ),
234
					'desc' => sprintf( __( 'Number fields can take \'std\', \'max\', \'min\', \'step\', \'size\' and \'readonly\' arguements. Read more about number fields %s.', 's214-settings-demo' ), '<a href="https://github.com/Section214/S214-Settings/wiki/Settings-Reference#number-implements-a-number-field" target="_blank">' . __( 'here', 's214-settings-demo' ) . '</a>' ),
235
					'type' => 'number',
236
					'std'  => 1227
237
				),
238
				array(
239
					'id'   => 'upload',
240
					'name' => sprintf( __( '%s Field', 's214-settings-demo' ), 'upload' ),
241
					'desc' => sprintf( __( 'Upload fields can take \'std\' and \'size\' arguements. Read more about upload fields %s.', 's214-settings-demo' ), '<a href="https://github.com/Section214/S214-Settings/wiki/Settings-Reference#upload-implements-an-upload-field" target="_blank">' . __( 'here', 's214-settings-demo' ) . '</a>' ),
242
					'type' => 'upload'
243
				)
244
			),
245
			'advanced' => array(
246
				array(
247
					'id'   => 'advanced_header',
248
					'name' => __( 'Advanced Field Examples', 's214-settings-demo' ),
249
					'desc' => '',
250
					'type' => 'header'
251
				),
252
				array(
253
					'id'   => 'sysinfo',
254
					'name' => sprintf( __( '%s Field', 's214-settings-demo' ), 'sysinfo' ),
255
					'desc' => sprintf( __( 'Sysinfo fields only take the basic arguements. Read more about sysinfo fields %s.', 's214-settings-demo' ), '<a href="https://github.com/Section214/S214-Settings/wiki/Settings-Reference#sysinfo-implements-a-system-info-display-field" target="_blank">' . __( 'here', 's214-settings-demo' ) . '</a>' ),
256
					'type' => 'sysinfo',
257
					'tab'  => 'advanced'
258
				)
259
			)
260
		)
261
	);
262
263
	return array_merge( $settings, $plugin_settings );
264
}
265
add_filter( 's214_settings_demo_registered_settings', 's214_settings_demo_settings' );
266