forked from bainternet/My-Meta-Box
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-usage-demo.php
128 lines (116 loc) · 5.42 KB
/
class-usage-demo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/*
Plugin Name: Demo MetaBox
Plugin URI: http://en.bainternet.info
Description: My Meta Box Class usage demo
Version: 2.9.2
Author: Bainternet, Ohad Raz
Author URI: http://en.bainternet.info
*/
//include the main class file
require_once("meta-box-class/my-meta-box-class.php");
if (is_admin()){
/*
* prefix of meta keys, optional
* use underscore (_) at the beginning to make keys hidden, for example $prefix = '_ba_';
* you also can make prefix empty to disable it
*
*/
$prefix = 'ba_';
/*
* configure your meta box
*/
$config = array(
'id' => 'demo_meta_box', // meta box id, unique per meta box
'title' => 'Simple Meta Box fields', // meta box title
'pages' => array('post', 'page'), // post types, accept custom post types as well, default is array('post'); optional
'context' => 'normal', // where the meta box appear: normal (default), advanced, side; optional
'priority' => 'high', // order of meta box: high (default), low; optional
'fields' => array(), // list of meta fields (can be added by field arrays)
'local_images' => false, // Use local or hosted images (meta box images for add/remove)
'use_with_theme' => false //change path if used with theme set to true, false for a plugin or anything else for a custom path(default false).
);
/*
* Initiate your meta box
*/
$my_meta = new AT_Meta_Box($config);
/*
* Add fields to your meta box
*/
//text field
$my_meta->addText($prefix.'text_field_id',array('name'=> 'My Text '));
//textarea field
$my_meta->addTextarea($prefix.'textarea_field_id',array('name'=> 'My Textarea '));
//checkbox field
$my_meta->addCheckbox($prefix.'checkbox_field_id',array('name'=> 'My Checkbox '));
//select field
$my_meta->addSelect($prefix.'select_field_id',array('selectkey1'=>'Select Value1','selectkey2'=>'Select Value2'),array('name'=> 'My select ', 'std'=> array('selectkey2')));
//radio field
$my_meta->addRadio($prefix.'radio_field_id',array('radiokey1'=>'Radio Value1','radiokey2'=>'Radio Value2'),array('name'=> 'My Radio Filed', 'std'=> array('radionkey2')));
//Image field
$my_meta->addImage($prefix.'image_field_id',array('name'=> 'My Image '));
//file upload field
$my_meta->addFile($prefix.'file_field_id',array('name'=> 'My File '));
/*
* Don't Forget to Close up the meta box decleration
*/
//Finish Meta Box Decleration
$my_meta->Finish();
/**
* Create a second metabox
*/
/*
* configure your meta box
*/
$config2 = array(
'id' => 'demo_meta_box2', // meta box id, unique per meta box
'title' => 'Advanced Meta Box fields', // meta box title
'pages' => array('post', 'page'), // post types, accept custom post types as well, default is array('post'); optional
'context' => 'normal', // where the meta box appear: normal (default), advanced, side; optional
'priority' => 'high', // order of meta box: high (default), low; optional
'fields' => array(), // list of meta fields (can be added by field arrays)
'local_images' => false, // Use local or hosted images (meta box images for add/remove)
'use_with_theme' => false //change path if used with theme set to true, false for a plugin or anything else for a custom path(default false).
);
/*
* Initiate your 2nd meta box
*/
$my_meta2 = new AT_Meta_Box($config2);
/*
* Add fields to your 2nd meta box
*/
//add checkboxes list
$my_meta2->addCheckboxList($prefix.'CheckboxList_field_id',array('checkboxkey1'=>'checkbox Value1','checkboxkey2'=>'checkbox Value2'),array('name'=> 'My checkbox list ', 'std'=> array('checkboxkey2')));
//date field
$my_meta2->addDate($prefix.'date_field_id',array('name'=> 'My Date '));
//Time field
$my_meta2->addTime($prefix.'time_field_id',array('name'=> 'My Time '));
//Color field
$my_meta2->addColor($prefix.'color_field_id',array('name'=> 'My Color '));
//wysiwyg field
$my_meta2->addWysiwyg($prefix.'wysiwyg_field_id',array('name'=> 'My wysiwyg Editor '));
//taxonomy field
$my_meta2->addTaxonomy($prefix.'taxonomy_field_id',array('taxonomy' => 'category'),array('name'=> 'My Taxonomy '));
//posts field
$my_meta2->addPosts($prefix.'posts_field_id',array('post_type' => 'post'),array('name'=> 'My Posts '));
//add Code editor field
$my_meta2->addCode($prefix.'code_field_id',array('name'=> 'Code editor Field', 'syntax' => 'php','theme' => 'light'));
/*
* To Create a reapeater Block first create an array of fields
* use the same functions as above but add true as a last param
*/
$repeater_fields[] = $my_meta2->addText($prefix.'re_text_field_id',array('name'=> 'My Text '),true);
$repeater_fields[] = $my_meta2->addTextarea($prefix.'re_textarea_field_id',array('name'=> 'My Textarea '),true);
$repeater_fields[] = $my_meta2->addCheckbox($prefix.'re_checkbox_field_id',array('name'=> 'My Checkbox '),true);
$repeater_fields[] = $my_meta2->addImage($prefix.'image_field_id',array('name'=> 'My Image '),true);
/*
* Then just add the fields to the repeater block
*/
//repeater block
$my_meta2->addRepeaterBlock($prefix.'re_',array('inline' => true, 'name' => 'This is a Repeater Block','fields' => $repeater_fields, 'sortable'=> true));
/*
* Don't Forget to Close up the meta box decleration
*/
//Finish Meta Box Decleration
$my_meta2->Finish();
}