-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathplugin.php
More file actions
162 lines (159 loc) · 6.59 KB
/
plugin.php
File metadata and controls
162 lines (159 loc) · 6.59 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/**
* Plugin name: MDC Meta Box Example
* Description: A sample meta box for post, page or custom post types.
* Author: Nazmul Ahsan
* Author URI: https://nazmulahsan.me
* Plugin URI: https://wppeople.net
* Version: 1.1
*/
require dirname( __FILE__ ) . '/src/class.mdc-meta-box.php';
add_action( 'admin_init', 'my_meta_fields' );
function my_meta_fields() {
$args = array(
'meta_box_id' => 'sample_meta_id',
'label' => __( 'Sample Meta Box' ),
'post_type' => array( 'post', 'page' ),
'context' => 'normal', // side|normal|advanced
'priority' => 'high', // high|low
'hook_priority' => 10,
'fields' => array(
/**
* PLEASE NOTE
* desc, desc_nop, class, default, readonly, disabled, cols, rows, text_mode, teeny and media_buttons are optional.
*/
array(
'name' => 'sample_text',
'label' => __( 'Text Field' ),
'type' => 'text',
'desc' => __( 'This is a text field.' ),
'class' => 'mdc-meta-field',
'default' => 'Hello World!',
'readonly' => false, // true|false
'disabled' => false, // true|false
'desc_nop' => false, // true|false
),
array(
'name' => 'sample_number',
'label' => __( 'Number Field' ),
'type' => 'number',
'desc' => __( 'This is a number field.' ),
'class' => 'mdc-meta-field',
'default' => 10,
'readonly' => false, // true|false
'disabled' => false, // true|false
),
array(
'name' => 'sample_email',
'label' => __( 'Email Field' ),
'type' => 'email',
'desc' => __( 'This is an email field.' ),
'class' => 'mdc-meta-field',
'default' => 'john@doe.com',
'readonly' => false, // true|false
'disabled' => false, // true|false
),
array(
'name' => 'sample_url',
'label' => __( 'URL Field' ),
'type' => 'url',
'desc' => __( 'This is a url field.' ),
'class' => 'mdc-meta-field',
'default' => 'http://johndoe.com',
'readonly' => false, // true|false
'disabled' => false, // true|false
),
array(
'name' => 'sample_password',
'label' => __( 'Password Field' ),
'type' => 'password',
'desc' => __( 'This is a password field.' ),
'class' => 'mdc-meta-field',
'readonly' => false, // true|false
'disabled' => false, // true|false
),
array(
'name' => 'sample_textarea',
'label' => __( 'Textarea Field' ),
'type' => 'textarea',
'desc' => __( 'This is a textarea field.' ),
'class' => 'mdc-meta-field',
'columns' => 24,
'rows' => 5,
'default' => 'lorem ipsum dolor sit amet',
'readonly' => false, // true|false
'disabled' => false, // true|false
),
array(
'name' => 'sample_radio',
'label' => __( 'Radio Field' ),
'type' => 'radio',
'desc' => __( 'This is a radio field.' ),
'class' => 'mdc-meta-field',
'options' => array(
'item_1' => 'Item One',
'item_2' => 'Item Two',
'item_3' => 'Item Three',
),
'default' => 'item_2',
'disabled' => false, // true|false
),
array(
'name' => 'sample_select',
'label' => __( 'Select Field' ),
'type' => 'select',
'desc' => __( 'This is a select field.' ),
'class' => 'mdc-meta-field',
'options' => array(
'option_1' => 'Option One',
'option_2' => 'Option Two',
'option_3' => 'Option Three',
),
'default' => 'option_2',
'disabled' => false, // true|false
'multiple' => true, // true|false
),
array(
'name' => 'sample_checkbox',
'label' => __( 'Checkbox Field' ),
'type' => 'checkbox',
'desc' => __( 'This is a checkbox field.' ),
'class' => 'mdc-meta-field',
'disabled' => false, // true|false
),
array(
'name' => 'sample_color',
'label' => __( 'Color Field' ),
'type' => 'color',
'desc' => __( 'This is a color field.' ),
'class' => 'mdc-meta-field',
'default' => '#f00'
),
array(
'name' => 'sample_wysiwyg',
'label' => __( 'WYSIWYG Field' ),
'type' => 'wysiwyg',
'desc' => __( 'This is a wysiwyg field.' ),
'class' => 'mdc-meta-field',
'width' => '100%',
'rows' => 5,
'teeny' => true,
'text_mode' => false, // true|false
'media_buttons' => false, // true|false
'default' => 'Hello World'
),
array(
'name' => 'sample_fise',
'label' => __( 'File Field' ),
'type' => 'file',
'upload_button' => __( 'Choose File' ),
'select_button' => __( 'Select File' ),
'desc' => __( 'This is a file field.' ),
'class' => 'mdc-meta-field',
'disabled' => false, // true|false
'default' => 'http://example.com/sample/file.txt'
),
)
);
mdc_meta_box( $args );
}