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