PluginProbe
Themify Event Post / 1.3.2
Themify Event Post v1.3.2
1.3.7 trunk 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6
themify-event-post / includes / themify-metabox / example-functions.php

example-functions.php in Themify Event Post 1.3.2, at includes/themify-metabox/example-functions.php

281 lines 8.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Example of how Themify Metabox plugin can be used in themes and plugins.
4 *
5 * To use this file, enable the Themify Metabox plugin and then copy the contents of this file to
6 * your theme's functions.php file, or "include" it.'
7 *
8 * @package Themify Metabox
9 * @since 1.0
10 */
11
12 defined( 'ABSPATH' ) || exit;
13
14 /**
15 * Register a custom meta box to display on Page post type
16 *
17 * @return array
18 */
19 function themify_metabox_example_meta_box( $meta_boxes ) {
20 $meta_boxes['tm-example'] = array(
21 'id' => 'tm-example', // later, to add fields to this metabox we'll use "themify_metabox/fields/tm-example" filter hook, see function
22 'title' => __( 'Themify Metabox Example', 'themify' ),
23 'context' => 'normal',
24 'priority' => 'high',
25 'screen' => array( 'page' ),
26 );
27
28 return $meta_boxes;
29 }
30 add_filter( 'themify_metaboxes', 'themify_metabox_example_meta_box' );
31
32 /**
33 * Setup the custom fields for our Themify Metabox Example meta box, added earlier in the themify_metabox_example_meta_box function
34 *
35 * @return array
36 */
37 function themify_metabox_example_meta_box_fields( $fields, $post_type ) {
38 $first_tab_options = array(
39 array(
40 'name' => 'text_field',
41 'title' => __( 'Text field', 'themify' ),
42 'description' => __( 'Field description is displayed below the field.', 'themify' ),
43 'type' => 'textbox',
44 ),
45 array(
46 'name' => 'textarea_field',
47 'title' => __( 'Textarea field', 'themify' ),
48 'type' => 'textarea',
49 'size' => 55,
50 'rows' => 4,
51 ),
52 array(
53 'name' => 'image_field',
54 'title' => __( 'Image field', 'themify' ),
55 'description' => '',
56 'type' => 'image',
57 'meta' => array()
58 ),
59 array(
60 'name' => 'dropdown_field',
61 'title' => __( 'Dropdown', 'themify' ),
62 'type' => 'dropdown',
63 'meta' => array(
64 array( 'value' => '', 'name' => '' ),
65 array( 'value' => 'yes', 'name' => __( 'Yes', 'themify' ), 'selected' => true ),
66 array( 'value' => 'no', 'name' => __( 'No', 'themify' ) ),
67 ),
68 'description' => __( 'You can set which option is selected by default. Cool, eh?', 'themify' ),
69 // do not save the custom field when the option is set to Yes
70 'default' => 'yes',
71 ),
72 array(
73 'name' => 'dropdownbutton_field',
74 'title' => __( 'Dropdown Button', 'themify' ),
75 'type' => 'dropdownbutton',
76 'states' => array(
77 array( 'value' => '', 'title' => __( 'Default', 'themify' ), 'icon' => '%s/ddbtn-blank.png', 'name' => __( 'Default', 'themify' ) ),
78 array( 'value' => 'yes', 'title' => __( 'Yes', 'themify' ), 'icon' => '%s/ddbtn-check.svg', 'name' => __( 'Yes', 'themify' ) ),
79 array( 'value' => 'no', 'title' => __( 'No', 'themify' ), 'icon' => '%s/ddbtn-cross.svg', 'name' => __( 'No', 'themify' ) ),
80 ),
81 'description' => __( 'Similar to "dropdown" field, but allows setting custom icons for each state.', 'themify' ),
82 ),
83 array(
84 'name' => 'checkbox_field',
85 'title' => __( 'Checkbox', 'themify' ),
86 'label' => __( 'Checkbox label', 'themify' ),
87 'type' => 'checkbox',
88 ),
89 array(
90 'name' => 'radio_field',
91 'title' => __( 'Radio field', 'themify' ),
92 'description' => __( 'You can hide or show option based on how other options are configured', 'themify' ),
93 'type' => 'radio',
94 'meta' => array(
95 array( 'value' => 'yes', 'name' => __( 'Yes', 'themify' ), 'selected' => true ),
96 array( 'value' => 'no', 'name' => __( 'No', 'themify' ) ),
97 ),
98 'enable_toggle' => true,
99 'default' => 'yes',
100 ),
101 array(
102 'name' => 'separator_image_size',
103 'type' => 'separator',
104 //'description' => __( 'Optional text to show after the separator', 'themify'. )
105 ),
106 array(
107 'type' => 'multi',
108 'name' => 'multi_field',
109 'title' => __( 'Multi fields', 'themify' ),
110 'meta' => array(
111 'fields' => array(
112 array(
113 'name' => 'image_width',
114 'label' => __( 'width', 'themify' ),
115 'description' => '',
116 'type' => 'textbox',
117 'meta' => array( 'size' => 'small' )
118 ),
119 // Image Height
120 array(
121 'name' => 'image_height',
122 'label' => __( 'height', 'themify' ),
123 'type' => 'textbox',
124 'meta' => array( 'size' => 'small' )
125 ),
126 ),
127 'description' => __( '"Multi" field type allows displaying multiple fields together.', 'themify'),
128 'before' => '',
129 'after' => '',
130 'separator' => ''
131 )
132 ),
133 array(
134 'name' => 'color_field',
135 'title' => __( 'Color', 'themify' ),
136 'description' => '',
137 'type' => 'color',
138 'meta' => array( 'default' => null ),
139 'class' => 'yes-toggle'
140 ),
141 array(
142 'name' => 'post_id_info_field',
143 'title' => __( 'Post ID', 'themify' ),
144 'description' => __( 'This field type shows text with the ID of the post, which is: <code>%s</code>', 'themify' ),
145 'type' => 'post_id_info',
146 ),
147 );
148
149 $second_tab_options = array(
150 array(
151 'name' => 'audio_field',
152 'title' => __( 'Audio field', 'themify' ),
153 'description' => '',
154 'type' => 'audio',
155 'meta' => array(),
156 ),
157 array(
158 'name' => 'video_field',
159 'title' => __( 'Video field', 'themify' ),
160 'description' => '',
161 'type' => 'video',
162 'meta' => array(),
163 ),
164 array(
165 'name' => 'gallery_shortcode_field',
166 'title' => __( 'Gallery Shortcode field', 'themify' ),
167 'description' => __( 'Using this field type you can add a gallery manager.', 'themify' ),
168 'type' => 'gallery_shortcode',
169 ),
170 array(
171 'name' => 'date_field',
172 'title' => __( 'Date field', 'themify' ),
173 'description' => '',
174 'type' => 'date',
175 'meta' => array(
176 'default' => '',
177 'pick' => __( 'Pick Date', 'themify' ),
178 'close' => __( 'Done', 'themify' ),
179 'clear' => __( 'Clear Date', 'themify' ),
180 'time_format' => 'HH:mm:ss',
181 'date_format' => 'yy-mm-dd',
182 'timeseparator' => ' ',
183 )
184 ),
185 array(
186 'name' => 'repeater_field',
187 'title' => __( 'Repeater', 'themify' ),
188 'type' => 'repeater',
189 'fields' => array(
190 array(
191 'name' => 'text_1',
192 'title' => __( 'Text Field', 'themify' ),
193 'type' => 'textbox',
194 'class' => 'small'
195 ),
196 array(
197 'name' => 'color_field',
198 'title' => __( 'Color', 'themify' ),
199 'description' => '',
200 'type' => 'color',
201 ),
202 array(
203 'name' => 'field_3',
204 'title' => __( 'Dropdown', 'themify' ),
205 'type' => 'dropdown',
206 'meta' => array(
207 array( 'value' => 'yes', 'name' => __( 'Yes', 'themify' ) ),
208 array( 'value' => 'no', 'name' => __( 'No', 'themify' ) ),
209 ),
210 ),
211 ),
212 'add_new_label' => __( 'Add new item', 'themify' ),
213 ),
214 );
215
216 $fields[] = array(
217 'name' => __( 'First Tab', 'themify' ), // Name displayed in box
218 'id' => 'first-tab',
219 'options' => $first_tab_options,
220 );
221 $fields[] = array(
222 'name' => __( 'Second Tab', 'themify' ), // Name displayed in box
223 'id' => 'second-tab',
224 'options' => $second_tab_options,
225 );
226
227 return $fields;
228 }
229 add_filter( 'themify_metabox/fields/tm-example', 'themify_metabox_example_meta_box_fields', 10, 2 );
230
231
232 /**
233 * Add sample fields to the user profile screen
234 *
235 * @return array
236 * @since 1.0.1
237 */
238 function themify_metabox_example_user_fields( $fields ) {
239 $fields['themify-metabox-sample'] = array(
240 'title' => __( 'Sample fields added by Themify Metabox.', 'themify' ),
241 'description' => __( 'Description text about the fields.', 'themify' ),
242 'fields' => array(
243 array(
244 'name' => 'textbox_field',
245 'title' => __( 'Text box', 'themify' ),
246 'type' => 'textbox',
247 ),
248 array(
249 'name' => 'image_field',
250 'title' => __( 'Image field', 'themify' ),
251 'description' => __( 'This is only to show how field types can be used in user profile pages.', 'themify' ),
252 'type' => 'image',
253 ),
254 ),
255 );
256
257 return $fields;
258 }
259 add_filter( 'themify_metabox/user/fields', 'themify_metabox_example_user_fields' );
260
261 /**
262 * Add a sample Color field to Category taxonomy
263 *
264 * @since 1.0.3
265 * @return array
266 */
267 function themify_metabox_example_category_fields( $fields ) {
268 $new_fields = array(
269 array(
270 'name' => 'color_field',
271 'title' => __( 'Color', 'themify' ),
272 'description' => '',
273 'type' => 'color',
274 'meta' => array( 'default' => null ),
275 ),
276 );
277
278 return array_merge( $fields, $new_fields );
279 }
280 add_filter( 'themify_metabox/taxonomy/category/fields', 'themify_metabox_example_category_fields', 10 );
281