cmb_sample_metaboxes

Define the metabox and field configurations.

Description

(array) cmb_sample_metaboxes( (array) array $meta_boxes ); 

Returns (array)

Parameters (1)

0. $meta_boxes (array) => array $meta_boxes
The meta boxes.

Usage

  1. if ( !function_exists( 'cmb_sample_metaboxes' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress-profile-tabs/admin/includes/CMBF/example-functions.php'; 
  3.  
  4. // The meta boxes. 
  5. $meta_boxes = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = cmb_sample_metaboxes($meta_boxes); 
  9.  

Defined (1)

The function is defined in the following location(s).

/admin/includes/CMBF/example-functions.php  
  1. function cmb_sample_metaboxes( array $meta_boxes ) { 
  2.  
  3. // Start with an underscore to hide fields from custom fields list 
  4. $prefix = '_cmb_'; 
  5.  
  6. /** 
  7. * Sample metabox to demonstrate each field type included 
  8. */ 
  9. $meta_boxes['test_metabox'] = array( 
  10. 'id' => 'test_metabox',  
  11. 'title' => __( 'Test Metabox', 'cmb' ),  
  12. 'pages' => array( 'page', ), // Post type 
  13. 'context' => 'normal',  
  14. 'priority' => 'high',  
  15. 'show_names' => true, // Show field names on the left 
  16. // 'cmb_styles' => true, // Enqueue the CMB stylesheet on the frontend 
  17. 'fields' => array( 
  18. array( 
  19. 'name' => __( 'Test Text', 'cmb' ),  
  20. 'desc' => __( 'field description (optional)', 'cmb' ),  
  21. 'id' => $prefix . 'test_text',  
  22. 'type' => 'text',  
  23. 'show_on_cb' => 'cmb_test_text_show_on_cb', // function should return a bool value 
  24. // 'sanitization_cb' => 'my_custom_sanitization', // custom sanitization callback parameter 
  25. // 'escape_cb' => 'my_custom_escaping', // custom escaping callback parameter 
  26. // 'on_front' => false, // Optionally designate a field to wp-admin only 
  27. // 'repeatable' => true,  
  28. ),  
  29. array( 
  30. 'name' => __( 'Test Text Small', 'cmb' ),  
  31. 'desc' => __( 'field description (optional)', 'cmb' ),  
  32. 'id' => $prefix . 'test_textsmall',  
  33. 'type' => 'text_small',  
  34. // 'repeatable' => true,  
  35. ),  
  36. array( 
  37. 'name' => __( 'Test Text Medium', 'cmb' ),  
  38. 'desc' => __( 'field description (optional)', 'cmb' ),  
  39. 'id' => $prefix . 'test_textmedium',  
  40. 'type' => 'text_medium',  
  41. // 'repeatable' => true,  
  42. ),  
  43. array( 
  44. 'name' => __( 'Website URL', 'cmb' ),  
  45. 'desc' => __( 'field description (optional)', 'cmb' ),  
  46. 'id' => $prefix . 'url',  
  47. 'type' => 'text_url',  
  48. // 'protocols' => array('http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet'), // Array of allowed protocols 
  49. // 'repeatable' => true,  
  50. ),  
  51. array( 
  52. 'name' => __( 'Test Text Email', 'cmb' ),  
  53. 'desc' => __( 'field description (optional)', 'cmb' ),  
  54. 'id' => $prefix . 'email',  
  55. 'type' => 'text_email',  
  56. // 'repeatable' => true,  
  57. ),  
  58. array( 
  59. 'name' => __( 'Test Time', 'cmb' ),  
  60. 'desc' => __( 'field description (optional)', 'cmb' ),  
  61. 'id' => $prefix . 'test_time',  
  62. 'type' => 'text_time',  
  63. ),  
  64. array( 
  65. 'name' => __( 'Time zone', 'cmb' ),  
  66. 'desc' => __( 'Time zone', 'cmb' ),  
  67. 'id' => $prefix . 'timezone',  
  68. 'type' => 'select_timezone',  
  69. ),  
  70. array( 
  71. 'name' => __( 'Test Date Picker', 'cmb' ),  
  72. 'desc' => __( 'field description (optional)', 'cmb' ),  
  73. 'id' => $prefix . 'test_textdate',  
  74. 'type' => 'text_date',  
  75. ),  
  76. array( 
  77. 'name' => __( 'Test Date Picker (UNIX timestamp)', 'cmb' ),  
  78. 'desc' => __( 'field description (optional)', 'cmb' ),  
  79. 'id' => $prefix . 'test_textdate_timestamp',  
  80. 'type' => 'text_date_timestamp',  
  81. // 'timezone_meta_key' => $prefix . 'timezone', // Optionally make this field honor the timezone selected in the select_timezone specified above 
  82. ),  
  83. array( 
  84. 'name' => __( 'Test Date/Time Picker Combo (UNIX timestamp)', 'cmb' ),  
  85. 'desc' => __( 'field description (optional)', 'cmb' ),  
  86. 'id' => $prefix . 'test_datetime_timestamp',  
  87. 'type' => 'text_datetime_timestamp',  
  88. ),  
  89. // This text_datetime_timestamp_timezone field type 
  90. // is only compatible with PHP versions 5.3 or above. 
  91. // Feel free to uncomment and use if your server meets the requirement 
  92. // array( 
  93. // 'name' => __( 'Test Date/Time Picker/Time zone Combo (serialized DateTime object)', 'cmb' ),  
  94. // 'desc' => __( 'field description (optional)', 'cmb' ),  
  95. // 'id' => $prefix . 'test_datetime_timestamp_timezone',  
  96. // 'type' => 'text_datetime_timestamp_timezone',  
  97. // ),  
  98. array( 
  99. 'name' => __( 'Test Money', 'cmb' ),  
  100. 'desc' => __( 'field description (optional)', 'cmb' ),  
  101. 'id' => $prefix . 'test_textmoney',  
  102. 'type' => 'text_money',  
  103. // 'before' => '', // override '$' symbol if needed 
  104. // 'repeatable' => true,  
  105. ),  
  106. array( 
  107. 'name' => __( 'Test Color Picker', 'cmb' ),  
  108. 'desc' => __( 'field description (optional)', 'cmb' ),  
  109. 'id' => $prefix . 'test_colorpicker',  
  110. 'type' => 'colorpicker',  
  111. 'default' => '#ffffff' 
  112. ),  
  113. array( 
  114. 'name' => __( 'Test Text Area', 'cmb' ),  
  115. 'desc' => __( 'field description (optional)', 'cmb' ),  
  116. 'id' => $prefix . 'test_textarea',  
  117. 'type' => 'textarea',  
  118. ),  
  119. array( 
  120. 'name' => __( 'Test Text Area Small', 'cmb' ),  
  121. 'desc' => __( 'field description (optional)', 'cmb' ),  
  122. 'id' => $prefix . 'test_textareasmall',  
  123. 'type' => 'textarea_small',  
  124. ),  
  125. array( 
  126. 'name' => __( 'Test Text Area for Code', 'cmb' ),  
  127. 'desc' => __( 'field description (optional)', 'cmb' ),  
  128. 'id' => $prefix . 'test_textarea_code',  
  129. 'type' => 'textarea_code',  
  130. ),  
  131. array( 
  132. 'name' => __( 'Test Title Weeeee', 'cmb' ),  
  133. 'desc' => __( 'This is a title description', 'cmb' ),  
  134. 'id' => $prefix . 'test_title',  
  135. 'type' => 'title',  
  136. ),  
  137. array( 
  138. 'name' => __( 'Test Select', 'cmb' ),  
  139. 'desc' => __( 'field description (optional)', 'cmb' ),  
  140. 'id' => $prefix . 'test_select',  
  141. 'type' => 'select',  
  142. 'options' => array( 
  143. 'standard' => __( 'Option One', 'cmb' ),  
  144. 'custom' => __( 'Option Two', 'cmb' ),  
  145. 'none' => __( 'Option Three', 'cmb' ),  
  146. ),  
  147. ),  
  148. array( 
  149. 'name' => __( 'Test Radio inline', 'cmb' ),  
  150. 'desc' => __( 'field description (optional)', 'cmb' ),  
  151. 'id' => $prefix . 'test_radio_inline',  
  152. 'type' => 'radio_inline',  
  153. 'options' => array( 
  154. 'standard' => __( 'Option One', 'cmb' ),  
  155. 'custom' => __( 'Option Two', 'cmb' ),  
  156. 'none' => __( 'Option Three', 'cmb' ),  
  157. ),  
  158. ),  
  159. array( 
  160. 'name' => __( 'Test Radio', 'cmb' ),  
  161. 'desc' => __( 'field description (optional)', 'cmb' ),  
  162. 'id' => $prefix . 'test_radio',  
  163. 'type' => 'radio',  
  164. 'options' => array( 
  165. 'option1' => __( 'Option One', 'cmb' ),  
  166. 'option2' => __( 'Option Two', 'cmb' ),  
  167. 'option3' => __( 'Option Three', 'cmb' ),  
  168. ),  
  169. ),  
  170. array( 
  171. 'name' => __( 'Test Taxonomy Radio', 'cmb' ),  
  172. 'desc' => __( 'field description (optional)', 'cmb' ),  
  173. 'id' => $prefix . 'text_taxonomy_radio',  
  174. 'type' => 'taxonomy_radio',  
  175. 'taxonomy' => 'category', // Taxonomy Slug 
  176. // 'inline' => true, // Toggles display to inline 
  177. ),  
  178. array( 
  179. 'name' => __( 'Test Taxonomy Select', 'cmb' ),  
  180. 'desc' => __( 'field description (optional)', 'cmb' ),  
  181. 'id' => $prefix . 'text_taxonomy_select',  
  182. 'type' => 'taxonomy_select',  
  183. 'taxonomy' => 'category', // Taxonomy Slug 
  184. ),  
  185. array( 
  186. 'name' => __( 'Test Taxonomy Multi Checkbox', 'cmb' ),  
  187. 'desc' => __( 'field description (optional)', 'cmb' ),  
  188. 'id' => $prefix . 'test_multitaxonomy',  
  189. 'type' => 'taxonomy_multicheck',  
  190. 'taxonomy' => 'post_tag', // Taxonomy Slug 
  191. // 'inline' => true, // Toggles display to inline 
  192. ),  
  193. array( 
  194. 'name' => __( 'Test Checkbox', 'cmb' ),  
  195. 'desc' => __( 'field description (optional)', 'cmb' ),  
  196. 'id' => $prefix . 'test_checkbox',  
  197. 'type' => 'checkbox',  
  198. ),  
  199. array( 
  200. 'name' => __( 'Test Multi Checkbox', 'cmb' ),  
  201. 'desc' => __( 'field description (optional)', 'cmb' ),  
  202. 'id' => $prefix . 'test_multicheckbox',  
  203. 'type' => 'multicheck',  
  204. 'options' => array( 
  205. 'check1' => __( 'Check One', 'cmb' ),  
  206. 'check2' => __( 'Check Two', 'cmb' ),  
  207. 'check3' => __( 'Check Three', 'cmb' ),  
  208. ),  
  209. // 'inline' => true, // Toggles display to inline 
  210. ),  
  211. array( 
  212. 'name' => __( 'Test wysiwyg', 'cmb' ),  
  213. 'desc' => __( 'field description (optional)', 'cmb' ),  
  214. 'id' => $prefix . 'test_wysiwyg',  
  215. 'type' => 'wysiwyg',  
  216. 'options' => array( 'textarea_rows' => 5, ),  
  217. ),  
  218. array( 
  219. 'name' => __( 'Test Image', 'cmb' ),  
  220. 'desc' => __( 'Upload an image or enter a URL.', 'cmb' ),  
  221. 'id' => $prefix . 'test_image',  
  222. 'type' => 'file',  
  223. ),  
  224. array( 
  225. 'name' => __( 'Multiple Files', 'cmb' ),  
  226. 'desc' => __( 'Upload or add multiple images/attachments.', 'cmb' ),  
  227. 'id' => $prefix . 'test_file_list',  
  228. 'type' => 'file_list',  
  229. 'preview_size' => array( 100, 100 ), // Default: array( 50, 50 ) 
  230. ),  
  231. array( 
  232. 'name' => __( 'oEmbed', 'cmb' ),  
  233. 'desc' => __( 'Enter a youtube, twitter, or instagram URL. Supports services listed at <a href="http://codex.wordpress.org/Embeds">http://codex.wordpress.org/Embeds</a>.', 'cmb' ),  
  234. 'id' => $prefix . 'test_embed',  
  235. 'type' => 'oembed',  
  236. ),  
  237. ),  
  238. ); 
  239.  
  240. /** 
  241. * Metabox to be displayed on a single page ID 
  242. */ 
  243. $meta_boxes['about_page_metabox'] = array( 
  244. 'id' => 'about_page_metabox',  
  245. 'title' => __( 'About Page Metabox', 'cmb' ),  
  246. 'pages' => array( 'page', ), // Post type 
  247. 'context' => 'normal',  
  248. 'priority' => 'high',  
  249. 'show_names' => true, // Show field names on the left 
  250. 'show_on' => array( 'key' => 'id', 'value' => array( 2, ), ), // Specific post IDs to display this metabox 
  251. 'fields' => array( 
  252. array( 
  253. 'name' => __( 'Test Text', 'cmb' ),  
  254. 'desc' => __( 'field description (optional)', 'cmb' ),  
  255. 'id' => $prefix . '_about_test_text',  
  256. 'type' => 'text',  
  257. ),  
  258. ); 
  259.  
  260. /** 
  261. * Repeatable Field Groups 
  262. */ 
  263. $meta_boxes['field_group'] = array( 
  264. 'id' => 'field_group',  
  265. 'title' => __( 'Repeating Field Group', 'cmb' ),  
  266. 'pages' => array( 'page', ),  
  267. 'fields' => array( 
  268. array( 
  269. 'id' => $prefix . 'repeat_group',  
  270. 'type' => 'group',  
  271. 'description' => __( 'Generates reusable form entries', 'cmb' ),  
  272. 'options' => array( 
  273. 'group_title' => __( 'Entry {#}', 'cmb' ), // {#} gets replaced by row number 
  274. 'add_button' => __( 'Add Another Entry', 'cmb' ),  
  275. 'remove_button' => __( 'Remove Entry', 'cmb' ),  
  276. 'sortable' => true, // beta 
  277. ),  
  278. // Fields array works the same, except id's only need to be unique for this group. Prefix is not needed. 
  279. 'fields' => array( 
  280. array( 
  281. 'name' => 'Entry Title',  
  282. 'id' => 'title',  
  283. 'type' => 'text',  
  284. // 'repeatable' => true, // Repeatable fields are supported w/in repeatable groups (for most types) 
  285. ),  
  286. array( 
  287. 'name' => 'Description',  
  288. 'description' => 'Write a short description for this entry',  
  289. 'id' => 'description',  
  290. 'type' => 'textarea_small',  
  291. ),  
  292. array( 
  293. 'name' => 'Entry Image',  
  294. 'id' => 'image',  
  295. 'type' => 'file',  
  296. ),  
  297. array( 
  298. 'name' => 'Image Caption',  
  299. 'id' => 'image_caption',  
  300. 'type' => 'text',  
  301. ),  
  302. ),  
  303. ),  
  304. ),  
  305. ); 
  306.  
  307. /** 
  308. * Metabox for the user profile screen 
  309. */ 
  310. $meta_boxes['user_edit'] = array( 
  311. 'id' => 'user_edit',  
  312. 'title' => __( 'User Profile Metabox', 'cmb' ),  
  313. 'pages' => array( 'user' ), // Tells CMB to use user_meta vs post_meta 
  314. 'show_names' => true,  
  315. 'cmb_styles' => false, // Show cmb bundled styles.. not needed on user profile page 
  316. 'fields' => array( 
  317. array( 
  318. 'name' => __( 'Extra Info', 'cmb' ),  
  319. 'desc' => __( 'field description (optional)', 'cmb' ),  
  320. 'id' => $prefix . 'exta_info',  
  321. 'type' => 'title',  
  322. 'on_front' => false,  
  323. ),  
  324. array( 
  325. 'name' => __( 'Avatar', 'cmb' ),  
  326. 'desc' => __( 'field description (optional)', 'cmb' ),  
  327. 'id' => $prefix . 'avatar',  
  328. 'type' => 'file',  
  329. 'save_id' => true,  
  330. ),  
  331. array( 
  332. 'name' => __( 'Facebook URL', 'cmb' ),  
  333. 'desc' => __( 'field description (optional)', 'cmb' ),  
  334. 'id' => $prefix . 'facebookurl',  
  335. 'type' => 'text_url',  
  336. ),  
  337. array( 
  338. 'name' => __( 'Twitter URL', 'cmb' ),  
  339. 'desc' => __( 'field description (optional)', 'cmb' ),  
  340. 'id' => $prefix . 'twitterurl',  
  341. 'type' => 'text_url',  
  342. ),  
  343. array( 
  344. 'name' => __( 'Google+ URL', 'cmb' ),  
  345. 'desc' => __( 'field description (optional)', 'cmb' ),  
  346. 'id' => $prefix . 'googleplusurl',  
  347. 'type' => 'text_url',  
  348. ),  
  349. array( 
  350. 'name' => __( 'Linkedin URL', 'cmb' ),  
  351. 'desc' => __( 'field description (optional)', 'cmb' ),  
  352. 'id' => $prefix . 'linkedinurl',  
  353. 'type' => 'text_url',  
  354. ),  
  355. array( 
  356. 'name' => __( 'User Field', 'cmb' ),  
  357. 'desc' => __( 'field description (optional)', 'cmb' ),  
  358. 'id' => $prefix . 'user_text_field',  
  359. 'type' => 'text',  
  360. ),  
  361. ); 
  362.  
  363. /** 
  364. * Metabox for an options page. Will not be added automatically, but needs to be called with 
  365. * the `cmb_metabox_form` helper function. See wiki for more info. 
  366. */ 
  367. $meta_boxes['options_page'] = array( 
  368. 'id' => 'options_page',  
  369. 'title' => __( 'Theme Options Metabox', 'cmb' ),  
  370. 'show_on' => array( 'key' => 'options-page', 'value' => array( $prefix . 'theme_options', ), ),  
  371. 'fields' => array( 
  372. array( 
  373. 'name' => __( 'Site Background Color', 'cmb' ),  
  374. 'desc' => __( 'field description (optional)', 'cmb' ),  
  375. 'id' => $prefix . 'bg_color',  
  376. 'type' => 'colorpicker',  
  377. 'default' => '#ffffff' 
  378. ),  
  379. ); 
  380.  
  381. // Add other metaboxes as needed 
  382.  
  383. return $meta_boxes;