PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/themes/gonzo/includes/classes/meta-box/demo/demo.php

https://bitbucket.org/ssellek/saywhatnation.bitbucket
PHP | 238 lines | 159 code | 16 blank | 63 comment | 1 complexity | 94c30f00ea7e604b75983d7e2780efda MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0, GPL-3.0
  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://www.deluxeblogtips.com/2010/04/how-to-create-meta-box-wordpress-post.html
  12. */
  13. /********************* META BOX DEFINITIONS ***********************/
  14. /**
  15. * Prefix of meta keys (optional)
  16. * Use underscore (_) at the beginning to make keys hidden
  17. * Alt.: You also can make prefix empty to disable it
  18. */
  19. // Better has an underscore as last sign
  20. $prefix = 'YOUR_PREFIX_';
  21. global $meta_boxes;
  22. $meta_boxes = array();
  23. // 1st meta box
  24. $meta_boxes[] = array(
  25. // Meta box id, UNIQUE per meta box
  26. 'id' => 'personal',
  27. // Meta box title - Will appear at the drag and drop handle bar
  28. 'title' => 'Personal Information',
  29. // Post types, accept custom post types as well - DEFAULT is array('post'); (optional)
  30. 'pages' => array( 'post', 'slider' ),
  31. // Where the meta box appear: normal (default), advanced, side; optional
  32. 'context' => 'normal',
  33. // Order of meta box: high (default), low; optional
  34. 'priority' => 'high',
  35. // List of meta fields
  36. 'fields' => array(
  37. array(
  38. // Field name - Will be used as label
  39. 'name' => 'Full name',
  40. // Field ID, i.e. the meta key
  41. 'id' => $prefix . 'fname',
  42. // Field description (optional)
  43. 'desc' => 'Format: First Last',
  44. // CLONES: Add to make the field cloneable (i.e. have multiple value)
  45. 'clone' => true,
  46. 'type' => 'text',
  47. // Default value (optional)
  48. 'std' => 'Anh Tran'
  49. ),
  50. array(
  51. 'name' => 'Day of Birth',
  52. 'id' => "{$prefix}dob",
  53. 'type' => 'date',
  54. // Date format, default yy-mm-dd. Optional. See: http://goo.gl/po8vf
  55. 'format' => 'd MM, yy'
  56. ),
  57. // RADIO BUTTONS
  58. array(
  59. 'name' => 'Gender',
  60. 'id' => "{$prefix}gender",
  61. 'type' => 'radio',
  62. // Array of 'key' => 'value' pairs for radio options.
  63. // Note: the 'key' is stored in meta field, not the 'value'
  64. 'options' => array(
  65. 'm' => 'Male',
  66. 'f' => 'Female'
  67. ),
  68. 'std' => 'm',
  69. 'desc' => 'Need an explaination?'
  70. ),
  71. // TEXTAREA
  72. array(
  73. 'name' => 'Bio',
  74. 'desc' => "What's your professions? What have you done so far?",
  75. 'id' => "{$prefix}bio",
  76. 'type' => 'textarea',
  77. 'std' => "I'm a special agent from Vietnam.",
  78. 'cols' => "40",
  79. 'rows' => "8"
  80. ),
  81. // File type: select box
  82. array(
  83. 'name' => 'Where do you live?',
  84. 'id' => "{$prefix}place",
  85. 'type' => 'select',
  86. // Array of 'key' => 'value' pairs for select box
  87. 'options' => array(
  88. 'usa' => 'USA',
  89. 'vn' => 'Vietnam'
  90. ),
  91. // Select multiple values, optional. Default is false.
  92. 'multiple' => true,
  93. // Default value, can be string (single value) or array (for both single and multiple values)
  94. 'std' => array( 'vn' ),
  95. 'desc' => 'Select the current place, not in the past'
  96. ),
  97. array(
  98. 'name' => 'About WordPress', // File type: checkbox
  99. 'id' => "{$prefix}love_wp",
  100. 'type' => 'checkbox',
  101. 'desc' => 'I love WordPress',
  102. // Value can be 0 or 1
  103. 'std' => 1
  104. ),
  105. // HIDDEN
  106. array(
  107. 'id' => "{$prefix}invisible",
  108. 'type' => 'hidden',
  109. // Hidden field must have predefined value
  110. 'std' => "no, i'm visible"
  111. ),
  112. // PASSWORD
  113. array(
  114. 'name' => 'Your favorite password',
  115. 'id' => "{$prefix}pass",
  116. 'type' => 'password'
  117. ),
  118. )
  119. );
  120. // 2nd meta box
  121. $meta_boxes[] = array(
  122. 'id' => 'additional',
  123. 'title' => 'Additional Information',
  124. 'pages' => array( 'post', 'film', 'slider' ),
  125. 'fields' => array(
  126. // WYSIWYG/RICH TEXT EDITOR
  127. array(
  128. 'name' => 'Your thoughts about Deluxe Blog Tips',
  129. 'id' => "{$prefix}thoughts",
  130. 'type' => 'wysiwyg',
  131. 'std' => sprintf( "%1\$sIt's great!", '<b>', '</b>' ),
  132. 'desc' => 'Do you think so?'
  133. ),
  134. // FILE UPLOAD
  135. array(
  136. 'name' => 'Upload your source code',
  137. 'desc' => 'Any modified code, or extending code',
  138. 'id' => "{$prefix}code",
  139. 'type' => 'file'
  140. ),
  141. // IMAGE UPLOAD
  142. array(
  143. 'name' => 'Screenshots',
  144. 'desc' => 'Screenshots of problems, warnings, etc.',
  145. 'id' => "{$prefix}screenshot",
  146. 'type' => 'image'
  147. ),
  148. // NEW(!) PLUPLOAD IMAGE UPLOAD (WP 3.3+)
  149. array(
  150. 'name' => 'Screenshots (plupload)',
  151. 'desc' => 'Screenshots of problems, warnings, etc.',
  152. 'id' => "{$prefix}screenshot2",
  153. 'type' => 'plupload_image'
  154. )
  155. )
  156. );
  157. // 3rd meta box
  158. $meta_boxes[] = array(
  159. 'id' => 'survey',
  160. 'title' => 'Survey',
  161. 'pages' => array( 'post', 'slider', 'page' ),
  162. 'fields' => array(
  163. // COLOR
  164. array(
  165. 'name' => 'Your favorite color',
  166. 'id' => "{$prefix}color",
  167. 'type' => 'color'
  168. ),
  169. // CHECKBOX LIST
  170. array(
  171. 'name' => 'Your hobby',
  172. 'id' => "{$prefix}hobby",
  173. 'type' => 'checkbox_list',
  174. // Options of checkboxes, in format 'key' => 'value'
  175. 'options' => array(
  176. 'reading' => 'Books',
  177. 'sport' => 'Gym, Boxing'
  178. ),
  179. 'desc' => 'What do you do in free time?'
  180. ),
  181. // TIME
  182. array(
  183. 'name' => 'When do you get up?',
  184. 'id' => "{$prefix}getdown",
  185. 'type' => 'time',
  186. // Time format, default hh:mm. Optional. @link See: http://goo.gl/hXHWz
  187. 'format' => 'hh:mm:ss'
  188. ),
  189. // DATETIME
  190. array(
  191. 'name' => 'When were you born?',
  192. 'id' => "{$prefix}born_time",
  193. 'type' => 'datetime',
  194. // Time format, default hh:mm. Optional. @link See: http://goo.gl/hXHWz
  195. 'format' => 'hh:mm:ss'
  196. )
  197. )
  198. );
  199. /********************* META BOX REGISTERING ***********************/
  200. /**
  201. * Register meta boxes
  202. *
  203. * @return void
  204. */
  205. function YOUR_PREFIX_register_meta_boxes()
  206. {
  207. global $meta_boxes;
  208. // Make sure there's no errors when the plugin is deactivated or during upgrade
  209. if ( class_exists( 'RW_Meta_Box' ) )
  210. {
  211. foreach ( $meta_boxes as $meta_box )
  212. {
  213. new RW_Meta_Box( $meta_box );
  214. }
  215. }
  216. }
  217. // Hook to 'admin_init' to make sure the meta box class is loaded
  218. // before (in case using the meta box class in another plugin)
  219. // This is also helpful for some conditionals like checking page template, categories, etc.
  220. add_action( 'admin_init', 'YOUR_PREFIX_register_meta_boxes' );