PluginProbe
Themify Builder / trunk
Themify Builder vtrunk
7.8.1 7.8.0 7.7.9 7.7.8 7.7.7 7.7.6 7.7.5 7.7.4 7.7.3 7.7.2 trunk 7.6.0 7.6.1 7.6.2 7.6.3 7.6.4 7.6.5 7.6.6 7.6.7 7.6.8 7.6.9 7.7.0 7.7.1
themify-builder / themify / themify-metabox / example-functions.php

example-functions.php in Themify Builder trunk, at themify/themify-metabox/example-functions.php

270 lines 9.5 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' => 'checkbox_field',
74 'title' => __( 'Checkbox', 'themify' ),
75 'label' => __( 'Checkbox label', 'themify' ),
76 'type' => 'checkbox',
77 ),
78 array(
79 'name' => 'radio_field',
80 'title' => __( 'Radio field', 'themify' ),
81 'description' => __( 'You can hide or show option based on how other options are configured', 'themify' ),
82 'type' => 'radio',
83 'meta' => array(
84 array( 'value' => 'yes', 'name' => __( 'Yes', 'themify' ), 'selected' => true ),
85 array( 'value' => 'no', 'name' => __( 'No', 'themify' ) ),
86 ),
87 'enable_toggle' => true,
88 'default' => 'yes',
89 ),
90 array(
91 'name' => 'separator_image_size',
92 'type' => 'separator',
93 //'description' => __( 'Optional text to show after the separator', 'themify'. )
94 ),
95 array(
96 'type' => 'multi',
97 'name' => 'multi_field',
98 'title' => __( 'Multi fields', 'themify' ),
99 'meta' => array(
100 'fields' => array(
101 array(
102 'name' => 'image_width',
103 'label' => __( 'width', 'themify' ),
104 'description' => '',
105 'type' => 'textbox',
106 'meta' => array( 'size' => 'small' )
107 ),
108 // Image Height
109 array(
110 'name' => 'image_height',
111 'label' => __( 'height', 'themify' ),
112 'type' => 'textbox',
113 'meta' => array( 'size' => 'small' )
114 ),
115 ),
116 'description' => __( '"Multi" field type allows displaying multiple fields together.', 'themify'),
117 'before' => '',
118 'after' => '',
119 'separator' => ''
120 )
121 ),
122 array(
123 'name' => 'color_field',
124 'title' => __( 'Color', 'themify' ),
125 'description' => '',
126 'type' => 'color',
127 'meta' => array( 'default' => null ),
128 'class' => 'yes-toggle'
129 ),
130 array(
131 'name' => 'post_id_info_field',
132 'title' => __( 'Post ID', 'themify' ),
133 'description' => __( 'This field type shows text with the ID of the post, which is: <code>%s</code>', 'themify' ),
134 'type' => 'post_id_info',
135 ),
136 );
137
138 $second_tab_options = array(
139 array(
140 'name' => 'audio_field',
141 'title' => __( 'Audio field', 'themify' ),
142 'description' => '',
143 'type' => 'audio',
144 'meta' => array(),
145 ),
146 array(
147 'name' => 'video_field',
148 'title' => __( 'Video field', 'themify' ),
149 'description' => '',
150 'type' => 'video',
151 'meta' => array(),
152 ),
153 array(
154 'name' => 'gallery_shortcode_field',
155 'title' => __( 'Gallery Shortcode field', 'themify' ),
156 'description' => __( 'Using this field type you can add a gallery manager.', 'themify' ),
157 'type' => 'gallery_shortcode',
158 ),
159 array(
160 'name' => 'date_field',
161 'title' => __( 'Date field', 'themify' ),
162 'description' => '',
163 'type' => 'date',
164 'meta' => array(
165 'default' => '',
166 'pick' => __( 'Pick Date', 'themify' ),
167 'close' => __( 'Done', 'themify' ),
168 'clear' => __( 'Clear Date', 'themify' ),
169 'time_format' => 'HH:mm:ss',
170 'date_format' => 'yy-mm-dd',
171 'timeseparator' => ' ',
172 )
173 ),
174 array(
175 'name' => 'repeater_field',
176 'title' => __( 'Repeater', 'themify' ),
177 'type' => 'repeater',
178 'fields' => array(
179 array(
180 'name' => 'text_1',
181 'title' => __( 'Text Field', 'themify' ),
182 'type' => 'textbox',
183 'class' => 'small'
184 ),
185 array(
186 'name' => 'color_field',
187 'title' => __( 'Color', 'themify' ),
188 'description' => '',
189 'type' => 'color',
190 ),
191 array(
192 'name' => 'field_3',
193 'title' => __( 'Dropdown', 'themify' ),
194 'type' => 'dropdown',
195 'meta' => array(
196 array( 'value' => 'yes', 'name' => __( 'Yes', 'themify' ) ),
197 array( 'value' => 'no', 'name' => __( 'No', 'themify' ) ),
198 ),
199 ),
200 ),
201 'add_new_label' => __( 'Add new item', 'themify' ),
202 ),
203 );
204
205 $fields[] = array(
206 'name' => __( 'First Tab', 'themify' ), // Name displayed in box
207 'id' => 'first-tab',
208 'options' => $first_tab_options,
209 );
210 $fields[] = array(
211 'name' => __( 'Second Tab', 'themify' ), // Name displayed in box
212 'id' => 'second-tab',
213 'options' => $second_tab_options,
214 );
215
216 return $fields;
217 }
218 add_filter( 'themify_metabox/fields/tm-example', 'themify_metabox_example_meta_box_fields', 10, 2 );
219
220
221 /**
222 * Add sample fields to the user profile screen
223 *
224 * @return array
225 * @since 1.0.1
226 */
227 function themify_metabox_example_user_fields( $fields ) {
228 $fields['themify-metabox-sample'] = array(
229 'title' => __( 'Sample fields added by Themify Metabox.', 'themify' ),
230 'description' => __( 'Description text about the fields.', 'themify' ),
231 'fields' => array(
232 array(
233 'name' => 'textbox_field',
234 'title' => __( 'Text box', 'themify' ),
235 'type' => 'textbox',
236 ),
237 array(
238 'name' => 'image_field',
239 'title' => __( 'Image field', 'themify' ),
240 'description' => __( 'This is only to show how field types can be used in user profile pages.', 'themify' ),
241 'type' => 'image',
242 ),
243 ),
244 );
245
246 return $fields;
247 }
248 add_filter( 'themify_metabox/user/fields', 'themify_metabox_example_user_fields' );
249
250 /**
251 * Add a sample Color field to Category taxonomy
252 *
253 * @since 1.0.3
254 * @return array
255 */
256 function themify_metabox_example_category_fields( $fields ) {
257 $new_fields = array(
258 array(
259 'name' => 'color_field',
260 'title' => __( 'Color', 'themify' ),
261 'description' => '',
262 'type' => 'color',
263 'meta' => array( 'default' => null ),
264 ),
265 );
266
267 return array_merge( $fields, $new_fields );
268 }
269 add_filter( 'themify_metabox/taxonomy/category/fields', 'themify_metabox_example_category_fields', 10 );
270