-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-functions.php
229 lines (220 loc) · 6.78 KB
/
example-functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
/**
* Include and setup custom metaboxes and fields.
*
* @category YourThemeOrPlugin
* @package Metaboxes
* @license http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)
* @link https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress
*/
add_filter( 'cmb_meta_boxes', 'cmb_sample_metaboxes' );
/**
* Define the metabox and field configurations.
*
* @param array $meta_boxes
* @return array
*/
function cmb_sample_metaboxes( array $meta_boxes ) {
// Start with an underscore to hide fields from custom fields list
$prefix = '_cmb_';
$meta_boxes[] = array(
'id' => 'test_metabox',
'title' => 'Test Metabox',
'pages' => array( 'page', ), // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
'fields' => array(
array(
'name' => 'Test Text',
'desc' => 'field description (optional)',
'id' => $prefix . 'test_text',
'type' => 'text',
),
array(
'name' => 'Test Text Small',
'desc' => 'field description (optional)',
'id' => $prefix . 'test_textsmall',
'type' => 'text_small',
),
array(
'name' => 'Test Text Medium',
'desc' => 'field description (optional)',
'id' => $prefix . 'test_textmedium',
'type' => 'text_medium',
),
array(
'name' => 'Test Date Picker',
'desc' => 'field description (optional)',
'id' => $prefix . 'test_textdate',
'type' => 'text_date',
),
array(
'name' => 'Test Date Picker (UNIX timestamp)',
'desc' => 'field description (optional)',
'id' => $prefix . 'test_textdate_timestamp',
'type' => 'text_date_timestamp',
),
array(
'name' => 'Test Date/Time Picker Combo (UNIX timestamp)',
'desc' => 'field description (optional)',
'id' => $prefix . 'test_datetime_timestamp',
'type' => 'text_datetime_timestamp',
),
array(
'name' => 'Test Time',
'desc' => 'field description (optional)',
'id' => $prefix . 'test_time',
'type' => 'text_time',
),
array(
'name' => 'Test Money',
'desc' => 'field description (optional)',
'id' => $prefix . 'test_textmoney',
'type' => 'text_money',
),
array(
'name' => 'Test Color Picker',
'desc' => 'field description (optional)',
'id' => $prefix . 'test_colorpicker',
'type' => 'colorpicker',
'std' => '#ffffff'
),
array(
'name' => 'Test Text Area',
'desc' => 'field description (optional)',
'id' => $prefix . 'test_textarea',
'type' => 'textarea',
),
array(
'name' => 'Test Text Area Small',
'desc' => 'field description (optional)',
'id' => $prefix . 'test_textareasmall',
'type' => 'textarea_small',
),
array(
'name' => 'Test Text Area Code',
'desc' => 'field description (optional)',
'id' => $prefix . 'test_textarea_code',
'type' => 'textarea_code',
),
array(
'name' => 'Test Title Weeeee',
'desc' => 'This is a title description',
'id' => $prefix . 'test_title',
'type' => 'title',
),
array(
'name' => 'Test Select',
'desc' => 'field description (optional)',
'id' => $prefix . 'test_select',
'type' => 'select',
'options' => array(
array( 'name' => 'Option One', 'value' => 'standard', ),
array( 'name' => 'Option Two', 'value' => 'custom', ),
array( 'name' => 'Option Three', 'value' => 'none', ),
),
),
array(
'name' => 'Test Radio inline',
'desc' => 'field description (optional)',
'id' => $prefix . 'test_radio_inline',
'type' => 'radio_inline',
'options' => array(
array( 'name' => 'Option One', 'value' => 'standard', ),
array( 'name' => 'Option Two', 'value' => 'custom', ),
array( 'name' => 'Option Three', 'value' => 'none', ),
),
),
array(
'name' => 'Test Radio',
'desc' => 'field description (optional)',
'id' => $prefix . 'test_radio',
'type' => 'radio',
'options' => array(
array( 'name' => 'Option One', 'value' => 'standard', ),
array( 'name' => 'Option Two', 'value' => 'custom', ),
array( 'name' => 'Option Three', 'value' => 'none', ),
),
),
array(
'name' => 'Test Taxonomy Radio',
'desc' => 'Description Goes Here',
'id' => $prefix . 'text_taxonomy_radio',
'type' => 'taxonomy_radio',
'taxonomy' => '', // Taxonomy Slug
),
array(
'name' => 'Test Taxonomy Select',
'desc' => 'Description Goes Here',
'id' => $prefix . 'text_taxonomy_select',
'type' => 'taxonomy_select',
'taxonomy' => '', // Taxonomy Slug
),
array(
'name' => 'Test Taxonomy Multi Checkbox',
'desc' => 'field description (optional)',
'id' => $prefix . 'test_multitaxonomy',
'type' => 'taxonomy_multicheck',
'taxonomy' => '', // Taxonomy Slug
),
array(
'name' => 'Test Checkbox',
'desc' => 'field description (optional)',
'id' => $prefix . 'test_checkbox',
'type' => 'checkbox',
),
array(
'name' => 'Test Multi Checkbox',
'desc' => 'field description (optional)',
'id' => $prefix . 'test_multicheckbox',
'type' => 'multicheck',
'options' => array(
'check1' => 'Check One',
'check2' => 'Check Two',
'check3' => 'Check Three',
),
),
array(
'name' => 'Test wysiwyg',
'desc' => 'field description (optional)',
'id' => $prefix . 'test_wysiwyg',
'type' => 'wysiwyg',
'options' => array( 'textarea_rows' => 5, ),
),
array(
'name' => 'Test Image',
'desc' => 'Upload an image or enter an URL.',
'id' => $prefix . 'test_image',
'type' => 'file',
),
),
);
$meta_boxes[] = array(
'id' => 'about_page_metabox',
'title' => 'About Page Metabox',
'pages' => array( 'page', ), // Post type
'context' => 'normal',
'priority' => 'high',
'show_names' => true, // Show field names on the left
'show_on' => array( 'key' => 'id', 'value' => array( 2, ), ), // Specific post IDs to display this metabox
'fields' => array(
array(
'name' => 'Test Text',
'desc' => 'field description (optional)',
'id' => $prefix . 'test_text',
'type' => 'text',
),
)
);
// Add other metaboxes as needed
return $meta_boxes;
}
add_action( 'init', 'cmb_initialize_cmb_meta_boxes', 9999 );
/**
* Initialize the metabox class.
*/
function cmb_initialize_cmb_meta_boxes() {
if ( ! class_exists( 'cmb_Meta_Box' ) )
require_once 'init.php';
}