Skip to content

Commit ab644e2

Browse files
committed
files moved to separate folder
1 parent dbdb46d commit ab644e2

File tree

4 files changed

+306
-301
lines changed

4 files changed

+306
-301
lines changed

example/oop-example.php

Lines changed: 295 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,295 @@
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+
)
135+
),
136+
'wedevs_advanced' => array(
137+
array(
138+
'name' => 'color',
139+
'label' => __( 'Color', 'wedevs' ),
140+
'desc' => __( 'Color description', 'wedevs' ),
141+
'type' => 'color',
142+
'default' => ''
143+
),
144+
array(
145+
'name' => 'password',
146+
'label' => __( 'Password', 'wedevs' ),
147+
'desc' => __( 'Password description', 'wedevs' ),
148+
'type' => 'password',
149+
'default' => ''
150+
),
151+
array(
152+
'name' => 'wysiwyg',
153+
'label' => __( 'Advanced Editor', 'wedevs' ),
154+
'desc' => __( 'WP_Editor description', 'wedevs' ),
155+
'type' => 'wysiwyg',
156+
'default' => ''
157+
),
158+
array(
159+
'name' => 'multicheck',
160+
'label' => __( 'Multile checkbox', 'wedevs' ),
161+
'desc' => __( 'Multi checkbox description', 'wedevs' ),
162+
'type' => 'multicheck',
163+
'default' => array('one' => 'one', 'four' => 'four'),
164+
'options' => array(
165+
'one' => 'One',
166+
'two' => 'Two',
167+
'three' => 'Three',
168+
'four' => 'Four'
169+
)
170+
),
171+
array(
172+
'name' => 'selectbox',
173+
'label' => __( 'A Dropdown', 'wedevs' ),
174+
'desc' => __( 'Dropdown description', 'wedevs' ),
175+
'type' => 'select',
176+
'options' => array(
177+
'yes' => 'Yes',
178+
'no' => 'No'
179+
)
180+
),
181+
array(
182+
'name' => 'password',
183+
'label' => __( 'Password', 'wedevs' ),
184+
'desc' => __( 'Password description', 'wedevs' ),
185+
'type' => 'password',
186+
'default' => ''
187+
),
188+
array(
189+
'name' => 'file',
190+
'label' => __( 'File', 'wedevs' ),
191+
'desc' => __( 'File description', 'wedevs' ),
192+
'type' => 'file',
193+
'default' => ''
194+
)
195+
),
196+
'wedevs_others' => array(
197+
array(
198+
'name' => 'text',
199+
'label' => __( 'Text Input', 'wedevs' ),
200+
'desc' => __( 'Text input description', 'wedevs' ),
201+
'type' => 'text',
202+
'default' => 'Title'
203+
),
204+
array(
205+
'name' => 'textarea',
206+
'label' => __( 'Textarea Input', 'wedevs' ),
207+
'desc' => __( 'Textarea description', 'wedevs' ),
208+
'type' => 'textarea'
209+
),
210+
array(
211+
'name' => 'checkbox',
212+
'label' => __( 'Checkbox', 'wedevs' ),
213+
'desc' => __( 'Checkbox Label', 'wedevs' ),
214+
'type' => 'checkbox'
215+
),
216+
array(
217+
'name' => 'radio',
218+
'label' => __( 'Radio Button', 'wedevs' ),
219+
'desc' => __( 'A radio button', 'wedevs' ),
220+
'type' => 'radio',
221+
'options' => array(
222+
'yes' => 'Yes',
223+
'no' => 'No'
224+
)
225+
),
226+
array(
227+
'name' => 'multicheck',
228+
'label' => __( 'Multile checkbox', 'wedevs' ),
229+
'desc' => __( 'Multi checkbox description', 'wedevs' ),
230+
'type' => 'multicheck',
231+
'options' => array(
232+
'one' => 'One',
233+
'two' => 'Two',
234+
'three' => 'Three',
235+
'four' => 'Four'
236+
)
237+
),
238+
array(
239+
'name' => 'selectbox',
240+
'label' => __( 'A Dropdown', 'wedevs' ),
241+
'desc' => __( 'Dropdown description', 'wedevs' ),
242+
'type' => 'select',
243+
'options' => array(
244+
'yes' => 'Yes',
245+
'no' => 'No'
246+
)
247+
),
248+
array(
249+
'name' => 'password',
250+
'label' => __( 'Password', 'wedevs' ),
251+
'desc' => __( 'Password description', 'wedevs' ),
252+
'type' => 'password',
253+
'default' => ''
254+
),
255+
array(
256+
'name' => 'file',
257+
'label' => __( 'File', 'wedevs' ),
258+
'desc' => __( 'File description', 'wedevs' ),
259+
'type' => 'file',
260+
'default' => ''
261+
)
262+
)
263+
);
264+
265+
return $settings_fields;
266+
}
267+
268+
function plugin_page() {
269+
echo '<div class="wrap">';
270+
271+
$this->settings_api->show_navigation();
272+
$this->settings_api->show_forms();
273+
274+
echo '</div>';
275+
}
276+
277+
/**
278+
* Get all the pages
279+
*
280+
* @return array page names with key value pairs
281+
*/
282+
function get_pages() {
283+
$pages = get_pages();
284+
$pages_options = array();
285+
if ( $pages ) {
286+
foreach ($pages as $page) {
287+
$pages_options[$page->ID] = $page->post_title;
288+
}
289+
}
290+
291+
return $pages_options;
292+
}
293+
294+
}
295+
endif;
File renamed without changes.

0 commit comments

Comments
 (0)