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 / oop-example.php

oop-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/oop-example.php

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