PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/demo/demo.php

https://gitlab.com/alanfsp/meta-box
PHP | 413 lines | 288 code | 22 blank | 103 comment | 0 complexity | 5a05d6aa3f50cd6a03d53281534f6409 MD5 | raw file
  1. <?php
  2. /**
  3. * Registering meta boxes
  4. *
  5. * All the definitions of meta boxes are listed below with comments.
  6. * Please read them CAREFULLY.
  7. *
  8. * You also should read the changelog to know what has been changed before updating.
  9. *
  10. * For more information, please visit:
  11. * @link http://metabox.io/docs/registering-meta-boxes/
  12. */
  13. add_filter( 'rwmb_meta_boxes', 'your_prefix_register_meta_boxes' );
  14. /**
  15. * Register meta boxes
  16. *
  17. * Remember to change "your_prefix" to actual prefix in your project
  18. *
  19. * @param array $meta_boxes List of meta boxes
  20. *
  21. * @return array
  22. */
  23. function your_prefix_register_meta_boxes( $meta_boxes )
  24. {
  25. /**
  26. * prefix of meta keys (optional)
  27. * Use underscore (_) at the beginning to make keys hidden
  28. * Alt.: You also can make prefix empty to disable it
  29. */
  30. // Better has an underscore as last sign
  31. $prefix = 'your_prefix_';
  32. // 1st meta box
  33. $meta_boxes[] = array(
  34. // Meta box id, UNIQUE per meta box. Optional since 4.1.5
  35. 'id' => 'standard',
  36. // Meta box title - Will appear at the drag and drop handle bar. Required.
  37. 'title' => __( 'Standard Fields', 'your-prefix' ),
  38. // Post types, accept custom post types as well - DEFAULT is 'post'. Can be array (multiple post types) or string (1 post type). Optional.
  39. 'post_types' => array( 'post', 'page' ),
  40. // Where the meta box appear: normal (default), advanced, side. Optional.
  41. 'context' => 'normal',
  42. // Order of meta box: high (default), low. Optional.
  43. 'priority' => 'high',
  44. // Auto save: true, false (default). Optional.
  45. 'autosave' => true,
  46. // List of meta fields
  47. 'fields' => array(
  48. // TEXT
  49. array(
  50. // Field name - Will be used as label
  51. 'name' => __( 'Text', 'your-prefix' ),
  52. // Field ID, i.e. the meta key
  53. 'id' => "{$prefix}text",
  54. // Field description (optional)
  55. 'desc' => __( 'Text description', 'your-prefix' ),
  56. 'type' => 'text',
  57. // Default value (optional)
  58. 'std' => __( 'Default text value', 'your-prefix' ),
  59. // CLONES: Add to make the field cloneable (i.e. have multiple value)
  60. 'clone' => true,
  61. ),
  62. // CHECKBOX
  63. array(
  64. 'name' => __( 'Checkbox', 'your-prefix' ),
  65. 'id' => "{$prefix}checkbox",
  66. 'type' => 'checkbox',
  67. // Value can be 0 or 1
  68. 'std' => 1,
  69. ),
  70. // RADIO BUTTONS
  71. array(
  72. 'name' => __( 'Radio', 'your-prefix' ),
  73. 'id' => "{$prefix}radio",
  74. 'type' => 'radio',
  75. // Array of 'value' => 'Label' pairs for radio options.
  76. // Note: the 'value' is stored in meta field, not the 'Label'
  77. 'options' => array(
  78. 'value1' => __( 'Label1', 'your-prefix' ),
  79. 'value2' => __( 'Label2', 'your-prefix' ),
  80. ),
  81. ),
  82. // SELECT BOX
  83. array(
  84. 'name' => __( 'Select', 'your-prefix' ),
  85. 'id' => "{$prefix}select",
  86. 'type' => 'select',
  87. // Array of 'value' => 'Label' pairs for select box
  88. 'options' => array(
  89. 'value1' => __( 'Label1', 'your-prefix' ),
  90. 'value2' => __( 'Label2', 'your-prefix' ),
  91. ),
  92. // Select multiple values, optional. Default is false.
  93. 'multiple' => false,
  94. 'std' => 'value2',
  95. 'placeholder' => __( 'Select an Item', 'your-prefix' ),
  96. ),
  97. // HIDDEN
  98. array(
  99. 'id' => "{$prefix}hidden",
  100. 'type' => 'hidden',
  101. // Hidden field must have predefined value
  102. 'std' => __( 'Hidden value', 'your-prefix' ),
  103. ),
  104. // PASSWORD
  105. array(
  106. 'name' => __( 'Password', 'your-prefix' ),
  107. 'id' => "{$prefix}password",
  108. 'type' => 'password',
  109. ),
  110. // TEXTAREA
  111. array(
  112. 'name' => __( 'Textarea', 'your-prefix' ),
  113. 'desc' => __( 'Textarea description', 'your-prefix' ),
  114. 'id' => "{$prefix}textarea",
  115. 'type' => 'textarea',
  116. 'cols' => 20,
  117. 'rows' => 3,
  118. ),
  119. ),
  120. 'validation' => array(
  121. 'rules' => array(
  122. "{$prefix}password" => array(
  123. 'required' => true,
  124. 'minlength' => 7,
  125. ),
  126. ),
  127. // optional override of default jquery.validate messages
  128. 'messages' => array(
  129. "{$prefix}password" => array(
  130. 'required' => __( 'Password is required', 'your-prefix' ),
  131. 'minlength' => __( 'Password must be at least 7 characters', 'your-prefix' ),
  132. ),
  133. )
  134. )
  135. );
  136. // 2nd meta box
  137. $meta_boxes[] = array(
  138. 'title' => __( 'Advanced Fields', 'your-prefix' ),
  139. 'fields' => array(
  140. // HEADING
  141. array(
  142. 'type' => 'heading',
  143. 'name' => __( 'Heading', 'your-prefix' ),
  144. 'id' => 'fake_id', // Not used but needed for plugin
  145. 'desc' => __( 'Optional description for this heading', 'your-prefix' ),
  146. ),
  147. // SLIDER
  148. array(
  149. 'name' => __( 'Slider', 'your-prefix' ),
  150. 'id' => "{$prefix}slider",
  151. 'type' => 'slider',
  152. // Text labels displayed before and after value
  153. 'prefix' => __( '$', 'your-prefix' ),
  154. 'suffix' => __( ' USD', 'your-prefix' ),
  155. // jQuery UI slider options. See here http://api.jqueryui.com/slider/
  156. 'js_options' => array(
  157. 'min' => 10,
  158. 'max' => 255,
  159. 'step' => 5,
  160. ),
  161. ),
  162. // NUMBER
  163. array(
  164. 'name' => __( 'Number', 'your-prefix' ),
  165. 'id' => "{$prefix}number",
  166. 'type' => 'number',
  167. 'min' => 0,
  168. 'step' => 5,
  169. ),
  170. // DATE
  171. array(
  172. 'name' => __( 'Date picker', 'your-prefix' ),
  173. 'id' => "{$prefix}date",
  174. 'type' => 'date',
  175. // jQuery date picker options. See here http://api.jqueryui.com/datepicker
  176. 'js_options' => array(
  177. 'appendText' => __( '(yyyy-mm-dd)', 'your-prefix' ),
  178. 'dateFormat' => __( 'yy-mm-dd', 'your-prefix' ),
  179. 'changeMonth' => true,
  180. 'changeYear' => true,
  181. 'showButtonPanel' => true,
  182. ),
  183. ),
  184. // DATETIME
  185. array(
  186. 'name' => __( 'Datetime picker', 'your-prefix' ),
  187. 'id' => $prefix . 'datetime',
  188. 'type' => 'datetime',
  189. // jQuery datetime picker options.
  190. // For date options, see here http://api.jqueryui.com/datepicker
  191. // For time options, see here http://trentrichardson.com/examples/timepicker/
  192. 'js_options' => array(
  193. 'stepMinute' => 15,
  194. 'showTimepicker' => true,
  195. ),
  196. ),
  197. // TIME
  198. array(
  199. 'name' => __( 'Time picker', 'your-prefix' ),
  200. 'id' => $prefix . 'time',
  201. 'type' => 'time',
  202. // jQuery datetime picker options.
  203. // For date options, see here http://api.jqueryui.com/datepicker
  204. // For time options, see here http://trentrichardson.com/examples/timepicker/
  205. 'js_options' => array(
  206. 'stepMinute' => 5,
  207. 'showSecond' => true,
  208. 'stepSecond' => 10,
  209. ),
  210. ),
  211. // COLOR
  212. array(
  213. 'name' => __( 'Color picker', 'your-prefix' ),
  214. 'id' => "{$prefix}color",
  215. 'type' => 'color',
  216. ),
  217. // CHECKBOX LIST
  218. array(
  219. 'name' => __( 'Checkbox list', 'your-prefix' ),
  220. 'id' => "{$prefix}checkbox_list",
  221. 'type' => 'checkbox_list',
  222. // Options of checkboxes, in format 'value' => 'Label'
  223. 'options' => array(
  224. 'value1' => __( 'Label1', 'your-prefix' ),
  225. 'value2' => __( 'Label2', 'your-prefix' ),
  226. ),
  227. ),
  228. // AUTOCOMPLETE
  229. array(
  230. 'name' => __( 'Autocomplete', 'your-prefix' ),
  231. 'id' => "{$prefix}autocomplete",
  232. 'type' => 'autocomplete',
  233. // Options of autocomplete, in format 'value' => 'Label'
  234. 'options' => array(
  235. 'value1' => __( 'Label1', 'your-prefix' ),
  236. 'value2' => __( 'Label2', 'your-prefix' ),
  237. ),
  238. // Input size
  239. 'size' => 30,
  240. // Clone?
  241. 'clone' => false,
  242. ),
  243. // EMAIL
  244. array(
  245. 'name' => __( 'Email', 'your-prefix' ),
  246. 'id' => "{$prefix}email",
  247. 'desc' => __( 'Email description', 'your-prefix' ),
  248. 'type' => 'email',
  249. 'std' => 'name@email.com',
  250. ),
  251. // RANGE
  252. array(
  253. 'name' => __( 'Range', 'your-prefix' ),
  254. 'id' => "{$prefix}range",
  255. 'desc' => __( 'Range description', 'your-prefix' ),
  256. 'type' => 'range',
  257. 'min' => 0,
  258. 'max' => 100,
  259. 'step' => 5,
  260. 'std' => 0,
  261. ),
  262. // URL
  263. array(
  264. 'name' => __( 'URL', 'your-prefix' ),
  265. 'id' => "{$prefix}url",
  266. 'desc' => __( 'URL description', 'your-prefix' ),
  267. 'type' => 'url',
  268. 'std' => 'http://google.com',
  269. ),
  270. // OEMBED
  271. array(
  272. 'name' => __( 'oEmbed', 'your-prefix' ),
  273. 'id' => "{$prefix}oembed",
  274. 'desc' => __( 'oEmbed description', 'your-prefix' ),
  275. 'type' => 'oembed',
  276. ),
  277. // SELECT ADVANCED BOX
  278. array(
  279. 'name' => __( 'Select', 'your-prefix' ),
  280. 'id' => "{$prefix}select_advanced",
  281. 'type' => 'select_advanced',
  282. // Array of 'value' => 'Label' pairs for select box
  283. 'options' => array(
  284. 'value1' => __( 'Label1', 'your-prefix' ),
  285. 'value2' => __( 'Label2', 'your-prefix' ),
  286. ),
  287. // Select multiple values, optional. Default is false.
  288. 'multiple' => false,
  289. // 'std' => 'value2', // Default value, optional
  290. 'placeholder' => __( 'Select an Item', 'your-prefix' ),
  291. ),
  292. // TAXONOMY
  293. array(
  294. 'name' => __( 'Taxonomy', 'your-prefix' ),
  295. 'id' => "{$prefix}taxonomy",
  296. 'type' => 'taxonomy',
  297. 'options' => array(
  298. // Taxonomy name
  299. 'taxonomy' => 'category',
  300. // How to show taxonomy: 'checkbox_list' (default) or 'checkbox_tree', 'select_tree', select_advanced or 'select'. Optional
  301. 'type' => 'checkbox_list',
  302. // Additional arguments for get_terms() function. Optional
  303. 'args' => array()
  304. ),
  305. ),
  306. // POST
  307. array(
  308. 'name' => __( 'Posts (Pages)', 'your-prefix' ),
  309. 'id' => "{$prefix}pages",
  310. 'type' => 'post',
  311. // Post type
  312. 'post_type' => 'page',
  313. // Field type, either 'select' or 'select_advanced' (default)
  314. 'field_type' => 'select_advanced',
  315. 'placeholder' => __( 'Select an Item', 'your-prefix' ),
  316. // Query arguments (optional). No settings means get all published posts
  317. 'query_args' => array(
  318. 'post_status' => 'publish',
  319. 'posts_per_page' => - 1,
  320. )
  321. ),
  322. // WYSIWYG/RICH TEXT EDITOR
  323. array(
  324. 'name' => __( 'WYSIWYG / Rich Text Editor', 'your-prefix' ),
  325. 'id' => "{$prefix}wysiwyg",
  326. 'type' => 'wysiwyg',
  327. // Set the 'raw' parameter to TRUE to prevent data being passed through wpautop() on save
  328. 'raw' => false,
  329. 'std' => __( 'WYSIWYG default value', 'your-prefix' ),
  330. // Editor settings, see wp_editor() function: look4wp.com/wp_editor
  331. 'options' => array(
  332. 'textarea_rows' => 4,
  333. 'teeny' => true,
  334. 'media_buttons' => false,
  335. ),
  336. ),
  337. // DIVIDER
  338. array(
  339. 'type' => 'divider',
  340. 'id' => 'fake_divider_id', // Not used, but needed
  341. ),
  342. // FILE UPLOAD
  343. array(
  344. 'name' => __( 'File Upload', 'your-prefix' ),
  345. 'id' => "{$prefix}file",
  346. 'type' => 'file',
  347. ),
  348. // FILE ADVANCED (WP 3.5+)
  349. array(
  350. 'name' => __( 'File Advanced Upload', 'your-prefix' ),
  351. 'id' => "{$prefix}file_advanced",
  352. 'type' => 'file_advanced',
  353. 'max_file_uploads' => 4,
  354. 'mime_type' => 'application,audio,video', // Leave blank for all file types
  355. ),
  356. // IMAGE UPLOAD
  357. array(
  358. 'name' => __( 'Image Upload', 'your-prefix' ),
  359. 'id' => "{$prefix}image",
  360. 'type' => 'image',
  361. ),
  362. // THICKBOX IMAGE UPLOAD (WP 3.3+)
  363. array(
  364. 'name' => __( 'Thickbox Image Upload', 'your-prefix' ),
  365. 'id' => "{$prefix}thickbox",
  366. 'type' => 'thickbox_image',
  367. ),
  368. // PLUPLOAD IMAGE UPLOAD (WP 3.3+)
  369. array(
  370. 'name' => __( 'Plupload Image Upload', 'your-prefix' ),
  371. 'id' => "{$prefix}plupload",
  372. 'type' => 'plupload_image',
  373. 'max_file_uploads' => 4,
  374. ),
  375. // IMAGE ADVANCED (WP 3.5+)
  376. array(
  377. 'name' => __( 'Image Advanced Upload', 'your-prefix' ),
  378. 'id' => "{$prefix}imgadv",
  379. 'type' => 'image_advanced',
  380. 'max_file_uploads' => 4,
  381. ),
  382. // BUTTON
  383. array(
  384. 'id' => "{$prefix}button",
  385. 'type' => 'button',
  386. 'name' => ' ', // Empty name will "align" the button to all field inputs
  387. ),
  388. )
  389. );
  390. return $meta_boxes;
  391. }