PluginProbe
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more / 2.2
StockPack – Stock photos and AI images from Unsplash, Adobe Stock, Freepik and more v2.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 2.2, at vendor/tareq1988/wordpress-settings-api-class/example/oop-example.php

203 lines 7.1 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 );
45 return $sections;
46 }
47
48 /**
49 * Returns all the settings fields
50 *
51 * @return array settings fields
52 */
53 function get_settings_fields() {
54 $settings_fields = array(
55 'wedevs_basics' => array(
56 array(
57 'name' => 'text_val',
58 'label' => __( 'Text Input', 'wedevs' ),
59 'desc' => __( 'Text input description', 'wedevs' ),
60 'placeholder' => __( 'Text Input placeholder', 'wedevs' ),
61 'type' => 'text',
62 'default' => 'Title',
63 'sanitize_callback' => 'sanitize_text_field'
64 ),
65 array(
66 'name' => 'number_input',
67 'label' => __( 'Number Input', 'wedevs' ),
68 'desc' => __( 'Number field with validation callback `floatval`', 'wedevs' ),
69 'placeholder' => __( '1.99', 'wedevs' ),
70 'min' => 0,
71 'max' => 100,
72 'step' => '0.01',
73 'type' => 'number',
74 'default' => 'Title',
75 'sanitize_callback' => 'floatval'
76 ),
77 array(
78 'name' => 'textarea',
79 'label' => __( 'Textarea Input', 'wedevs' ),
80 'desc' => __( 'Textarea description', 'wedevs' ),
81 'placeholder' => __( 'Textarea placeholder', 'wedevs' ),
82 'type' => 'textarea'
83 ),
84 array(
85 'name' => 'html',
86 'desc' => __( 'HTML area description. You can use any <strong>bold</strong> or other HTML elements.', 'wedevs' ),
87 'type' => 'html'
88 ),
89 array(
90 'name' => 'checkbox',
91 'label' => __( 'Checkbox', 'wedevs' ),
92 'desc' => __( 'Checkbox Label', 'wedevs' ),
93 'type' => 'checkbox'
94 ),
95 array(
96 'name' => 'radio',
97 'label' => __( 'Radio Button', 'wedevs' ),
98 'desc' => __( 'A radio button', 'wedevs' ),
99 'type' => 'radio',
100 'options' => array(
101 'yes' => 'Yes',
102 'no' => 'No'
103 )
104 ),
105 array(
106 'name' => 'selectbox',
107 'label' => __( 'A Dropdown', 'wedevs' ),
108 'desc' => __( 'Dropdown description', 'wedevs' ),
109 'type' => 'select',
110 'default' => 'no',
111 'options' => array(
112 'yes' => 'Yes',
113 'no' => 'No'
114 )
115 ),
116 array(
117 'name' => 'password',
118 'label' => __( 'Password', 'wedevs' ),
119 'desc' => __( 'Password description', 'wedevs' ),
120 'type' => 'password',
121 'default' => ''
122 ),
123 array(
124 'name' => 'file',
125 'label' => __( 'File', 'wedevs' ),
126 'desc' => __( 'File description', 'wedevs' ),
127 'type' => 'file',
128 'default' => '',
129 'options' => array(
130 'button_label' => 'Choose Image'
131 )
132 )
133 ),
134 'wedevs_advanced' => array(
135 array(
136 'name' => 'color',
137 'label' => __( 'Color', 'wedevs' ),
138 'desc' => __( 'Color description', 'wedevs' ),
139 'type' => 'color',
140 'default' => ''
141 ),
142 array(
143 'name' => 'password',
144 'label' => __( 'Password', 'wedevs' ),
145 'desc' => __( 'Password description', 'wedevs' ),
146 'type' => 'password',
147 'default' => ''
148 ),
149 array(
150 'name' => 'wysiwyg',
151 'label' => __( 'Advanced Editor', 'wedevs' ),
152 'desc' => __( 'WP_Editor description', 'wedevs' ),
153 'type' => 'wysiwyg',
154 'default' => ''
155 ),
156 array(
157 'name' => 'multicheck',
158 'label' => __( 'Multile checkbox', 'wedevs' ),
159 'desc' => __( 'Multi checkbox description', 'wedevs' ),
160 'type' => 'multicheck',
161 'default' => array('one' => 'one', 'four' => 'four'),
162 'options' => array(
163 'one' => 'One',
164 'two' => 'Two',
165 'three' => 'Three',
166 'four' => 'Four'
167 )
168 ),
169 )
170 );
171
172 return $settings_fields;
173 }
174
175 function plugin_page() {
176 echo '<div class="wrap">';
177
178 $this->settings_api->show_navigation();
179 $this->settings_api->show_forms();
180
181 echo '</div>';
182 }
183
184 /**
185 * Get all the pages
186 *
187 * @return array page names with key value pairs
188 */
189 function get_pages() {
190 $pages = get_pages();
191 $pages_options = array();
192 if ( $pages ) {
193 foreach ($pages as $page) {
194 $pages_options[$page->ID] = $page->post_title;
195 }
196 }
197
198 return $pages_options;
199 }
200
201 }
202 endif;
203