PluginProbe
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more / 3.7.2
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more v3.7.2
3.7.2 3.7.1 3.7.0 3.6.0 3.6.1 3.5.2 trunk 2.0 2.1 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.6.0 2.6.1 All 73 releases
stockpack / vendor / tareq1988 / wordpress-settings-api-class / example / procedural-example.php

procedural-example.php in StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more 3.7.2, at vendor/tareq1988/wordpress-settings-api-class/example/procedural-example.php

298 lines 10.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * This page shows the procedural or functional example
4 *
5 * OOP way example is given on the main plugin file.
6 *
7 * @author Tareq Hasan <[email protected]>
8 */
9
10
11 /**
12 * Registers settings section and fields
13 */
14 if ( !function_exists( 'wedevs_admin_init' ) ):
15 function wedevs_admin_init() {
16
17 $sections = array(
18 array(
19 'id' => 'wedevs_basics',
20 'title' => __( 'Basic Settings', 'wedevs' )
21 ),
22 array(
23 'id' => 'wedevs_advanced',
24 'title' => __( 'Advanced Settings', 'wedevs' )
25 ),
26 array(
27 'id' => 'wedevs_others',
28 'title' => __( 'Other Settings', 'wpuf' )
29 )
30 );
31
32 $fields = array(
33 'wedevs_basics' => array(
34 array(
35 'name' => 'text',
36 'label' => __( 'Text Input', 'wedevs' ),
37 'desc' => __( 'Text input description', 'wedevs' ),
38 'type' => 'text',
39 'default' => 'Title'
40 ),
41 array(
42 'name' => 'textarea',
43 'label' => __( 'Textarea Input', 'wedevs' ),
44 'desc' => __( 'Textarea description', 'wedevs' ),
45 'type' => 'textarea'
46 ),
47 array(
48 'name' => 'checkbox',
49 'label' => __( 'Checkbox', 'wedevs' ),
50 'desc' => __( 'Checkbox Label', 'wedevs' ),
51 'type' => 'checkbox'
52 ),
53 array(
54 'name' => 'radio',
55 'label' => __( 'Radio Button', 'wedevs' ),
56 'desc' => __( 'A radio button', 'wedevs' ),
57 'type' => 'radio',
58 'options' => array(
59 'yes' => 'Yes',
60 'no' => 'No'
61 )
62 ),
63 array(
64 'name' => 'multicheck',
65 'label' => __( 'Multile checkbox', 'wedevs' ),
66 'desc' => __( 'Multi checkbox description', 'wedevs' ),
67 'type' => 'multicheck',
68 'options' => array(
69 'one' => 'One',
70 'two' => 'Two',
71 'three' => 'Three',
72 'four' => 'Four'
73 )
74 ),
75 array(
76 'name' => 'selectbox',
77 'label' => __( 'A Dropdown', 'wedevs' ),
78 'desc' => __( 'Dropdown description', 'wedevs' ),
79 'type' => 'select',
80 'default' => 'no',
81 'options' => array(
82 'yes' => 'Yes',
83 'no' => 'No'
84 )
85 ),
86 array(
87 'name' => 'password',
88 'label' => __( 'Password', 'wedevs' ),
89 'desc' => __( 'Password description', 'wedevs' ),
90 'type' => 'password',
91 'default' => ''
92 ),
93 array(
94 'name' => 'file',
95 'label' => __( 'File', 'wedevs' ),
96 'desc' => __( 'File description', 'wedevs' ),
97 'type' => 'file',
98 'default' => ''
99 ),
100 array(
101 'name' => 'color',
102 'label' => __( 'Color', 'wedevs' ),
103 'desc' => __( 'Color description', 'wedevs' ),
104 'type' => 'color',
105 'default' => ''
106 )
107 ),
108 'wedevs_advanced' => array(
109 array(
110 'name' => 'text',
111 'label' => __( 'Text Input', 'wedevs' ),
112 'desc' => __( 'Text input description', 'wedevs' ),
113 'type' => 'text',
114 'default' => 'Title'
115 ),
116 array(
117 'name' => 'textarea',
118 'label' => __( 'Textarea Input', 'wedevs' ),
119 'desc' => __( 'Textarea description', 'wedevs' ),
120 'type' => 'textarea'
121 ),
122 array(
123 'name' => 'checkbox',
124 'label' => __( 'Checkbox', 'wedevs' ),
125 'desc' => __( 'Checkbox Label', 'wedevs' ),
126 'type' => 'checkbox'
127 ),
128 array(
129 'name' => 'radio',
130 'label' => __( 'Radio Button', 'wedevs' ),
131 'desc' => __( 'A radio button', 'wedevs' ),
132 'type' => 'radio',
133 'default' => 'no',
134 'options' => array(
135 'yes' => 'Yes',
136 'no' => 'No'
137 )
138 ),
139 array(
140 'name' => 'multicheck',
141 'label' => __( 'Multile checkbox', 'wedevs' ),
142 'desc' => __( 'Multi checkbox description', 'wedevs' ),
143 'type' => 'multicheck',
144 'default' => array( 'one' => 'one', 'four' => 'four' ),
145 'options' => array(
146 'one' => 'One',
147 'two' => 'Two',
148 'three' => 'Three',
149 'four' => 'Four'
150 )
151 ),
152 array(
153 'name' => 'selectbox',
154 'label' => __( 'A Dropdown', 'wedevs' ),
155 'desc' => __( 'Dropdown description', 'wedevs' ),
156 'type' => 'select',
157 'options' => array(
158 'yes' => 'Yes',
159 'no' => 'No'
160 )
161 ),
162 array(
163 'name' => 'password',
164 'label' => __( 'Password', 'wedevs' ),
165 'desc' => __( 'Password description', 'wedevs' ),
166 'type' => 'password',
167 'default' => ''
168 ),
169 array(
170 'name' => 'file',
171 'label' => __( 'File', 'wedevs' ),
172 'desc' => __( 'File description', 'wedevs' ),
173 'type' => 'file',
174 'default' => ''
175 ),
176 array(
177 'name' => 'color',
178 'label' => __( 'Color', 'wedevs' ),
179 'desc' => __( 'Color description', 'wedevs' ),
180 'type' => 'color',
181 'default' => ''
182 )
183 ),
184 'wedevs_others' => array(
185 array(
186 'name' => 'text',
187 'label' => __( 'Text Input', 'wedevs' ),
188 'desc' => __( 'Text input description', 'wedevs' ),
189 'type' => 'text',
190 'default' => 'Title'
191 ),
192 array(
193 'name' => 'textarea',
194 'label' => __( 'Textarea Input', 'wedevs' ),
195 'desc' => __( 'Textarea description', 'wedevs' ),
196 'type' => 'textarea'
197 ),
198 array(
199 'name' => 'checkbox',
200 'label' => __( 'Checkbox', 'wedevs' ),
201 'desc' => __( 'Checkbox Label', 'wedevs' ),
202 'type' => 'checkbox'
203 ),
204 array(
205 'name' => 'radio',
206 'label' => __( 'Radio Button', 'wedevs' ),
207 'desc' => __( 'A radio button', 'wedevs' ),
208 'type' => 'radio',
209 'options' => array(
210 'yes' => 'Yes',
211 'no' => 'No'
212 )
213 ),
214 array(
215 'name' => 'multicheck',
216 'label' => __( 'Multile checkbox', 'wedevs' ),
217 'desc' => __( 'Multi checkbox description', 'wedevs' ),
218 'type' => 'multicheck',
219 'options' => array(
220 'one' => 'One',
221 'two' => 'Two',
222 'three' => 'Three',
223 'four' => 'Four'
224 )
225 ),
226 array(
227 'name' => 'selectbox',
228 'label' => __( 'A Dropdown', 'wedevs' ),
229 'desc' => __( 'Dropdown description', 'wedevs' ),
230 'type' => 'select',
231 'options' => array(
232 'yes' => 'Yes',
233 'no' => 'No'
234 )
235 ),
236 array(
237 'name' => 'password',
238 'label' => __( 'Password', 'wedevs' ),
239 'desc' => __( 'Password description', 'wedevs' ),
240 'type' => 'password',
241 'default' => ''
242 ),
243 array(
244 'name' => 'file',
245 'label' => __( 'File', 'wedevs' ),
246 'desc' => __( 'File description', 'wedevs' ),
247 'type' => 'file',
248 'default' => ''
249 ),
250 array(
251 'name' => 'color',
252 'label' => __( 'Color', 'wedevs' ),
253 'desc' => __( 'Color description', 'wedevs' ),
254 'type' => 'color',
255 'default' => ''
256 )
257 )
258 );
259
260 $settings_api = WeDevs_Settings_API::getInstance();
261
262 //set sections and fields
263 $settings_api->set_sections( $sections );
264 $settings_api->set_fields( $fields );
265
266 //initialize them
267 $settings_api->admin_init();
268 }
269 endif;
270 add_action( 'admin_init', 'wedevs_admin_init' );
271
272 if ( !function_exists( 'wedevs_admin_menu' ) ):
273 /**
274 * Register the plugin page
275 */
276 function wedevs_admin_menu() {
277 add_options_page( 'Settings API', 'Settings API', 'delete_posts', 'settings_api_test', 'wedevs_plugin_page' );
278 }
279 endif;
280 add_action( 'admin_menu', 'wedevs_admin_menu' );
281
282 /**
283 * Display the plugin settings options page
284 */
285 if ( !function_exists( 'wedevs_plugin_page' ) ):
286 function wedevs_plugin_page() {
287 $settings_api = new WeDevs_Settings_API;
288
289 echo '<div class="wrap">';
290 settings_errors();
291
292 $settings_api->show_navigation();
293 $settings_api->show_forms();
294
295 echo '</div>';
296 }
297 endif;
298