Nazmul Ahsan

WordPress Developer, PHP & JavaScript Fan, Open Source Enthusiastic

Skip to content
  • Home
  • বাংলা ব্লগ
  • Contact Me

I just released MDC Meta Box – a meta box library for WordPress

Leave a reply

I have released a new library for WordPress, MDC Meta Box.

It will allow you to add 12 type of fields in your meta box, e.g. text, number, email, file, color etc.

Examples

Basic Example

Basic example
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
// include library file
require dirname( __FILE__ ) . '/class.mdc-metabox.php';
 
$args = array(
    'meta_box_id'   =>  'your_unique_meta_box_id_here',
    'label'     =>  'Meta Box Title Here',
    'post_type' =>  array( 'post', 'page', 'cpt1', 'cpt2' ),
    'context'   =>  'context_of_meta_box', // see 'Full Working Example' for better understanding
    'priority'  =>  'priority_of_meta_box', // see 'Full Working Example' for better understanding
    'fields'    =>  array(
        array(
            'name'      =>  'sample_field_name',
            'label'     =>  __( 'Field Title' ),
            'type'      =>  'field_type_here', // see 'Full Working Example' for better understanding
        ),
        array(
            'name'      =>  'another_sample_field_name',
            'label'     =>  __( 'Another Field Title' ),
            'type'      =>  'field_type_here', // see 'Full Working Example' for better understanding
        ),
    )
);
 
mdc_meta_box( $args );

Full Working Example

Full working example
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
// include library file
require dirname( __FILE__ ) . '/class.mdc-metabox.php';
 
$args = array(
    'meta_box_id'   =>  'sample_meta_id',
    'label'     =>  'Sample Meta Box',
    'post_type' =>  array( 'post', 'page' ),
    'context'   =>  'advanced',
    'priority'  =>  'high',
    'fields'    =>  array(
        array(
            'name'      =>  'sample_text',
            'label'     =>  __( 'Text Field' ),
            'type'      =>  'text',
            'desc'      =>  __( 'This is a text field.' ),
            'class'     =>  'custom-class',
            'default'   =>  'Hello World!',
            'readonly'  =>  true,
        ),
        array(
            'name'      =>  'sample_number',
            'label'     =>  __( 'Number Field' ),
            'type'      =>  'number',
            'desc'      =>  __( 'This is a number field.' ),
            'class'     =>  'custom-class',
            'default'   =>  10,
            'readonly'  =>  false,
            'disabled'  =>  false,
        ),
        array(
            'name'      =>  'sample_email',
            'label'     =>  __( 'Email Field' ),
            'type'      =>  'email',
            'desc'      =>  __( 'This is a email field.' ),
            'class'     =>  'custom-class',
            'default'   =>  'john@doe.com',
            'readonly'  =>  false,
            'disabled'  =>  false,
        ),
        array(
            'name'      =>  'sample_url',
            'label'     =>  __( 'URL Field' ),
            'type'      =>  'url',
            'desc'      =>  __( 'This is a url field.' ),
            'class'     =>  'custom-class',
            'default'   =>  'http://johndoe.com',
            'readonly'  =>  false,
            'disabled'  =>  false,
        ),
        array(
            'name'      =>  'sample_password',
            'label'     =>  __( 'Password Field' ),
            'type'      =>  'password',
            'desc'      =>  __( 'This is a password field.' ),
            'class'     =>  'custom-class',
            'readonly'  =>  false,
            'disabled'  =>  false,
        ),
        array(
            'name'      =>  'sample_textarea',
            'label'     =>  __( 'Textarea Field' ),
            'type'      =>  'textarea',
            'desc'      =>  __( 'This is a textarea field.' ),
            'class'     =>  'custom-class',
            'columns'   =>  24,
            'rows'      =>  5,
            'default'   =>  'lorem ipsum dolor sit amet',
            'readonly'  =>  false,
            'disabled'  =>  false,
        ),
        array(
            'name'      =>  'sample_radio',
            'label'     =>  __( 'Radio Field' ),
            'type'      =>  'radio',
            'desc'      =>  __( 'This is a radio field.' ),
            'class'     =>  'custom-class',
            'options'   => array(
                'item_1'  => 'Item One',
                'item_2'  => 'Item Two',
                'item_3'  => 'Item Three',
                ),
            'default'   =>  'item_2',
            'disabled'  =>  false,
        ),
        array(
            'name'      =>  'sample_select',
            'label'     =>  __( 'Select Field' ),
            'type'      =>  'select',
            'desc'      =>  __( 'This is a select field.' ),
            'class'     =>  'custom-class',
            'options'   => array(
                'option_1'  => 'Option One',
                'option_2'  => 'Option Two',
                'option_3'  => 'Option Three',
                ),
            'default'   =>  'option_2',
            'disabled'  =>  false,
        ),
        array(
            'name'      =>  'sample_checkbox',
            'label'     =>  __( 'Checkbox Field' ),
            'type'      =>  'checkbox',
            'desc'      =>  __( 'This is a checkbox field.' ),
            'class'     =>  'custom-class',
            'disabled'  =>  false,
        ),
        array(
            'name'      =>  'sample_color',
            'label'     =>  __( 'Color Field' ),
            'type'      =>  'color',
            'desc'      =>  __( 'This is a color field.' ),
            'class'     =>  'regular-text',
            'default'   =>  '#f00'
        ),
        array(
            'name'      =>  'sample_wysiwyg',
            'label'     =>  __( 'WYSIWYG' ),
            'type'      =>  'wysiwyg',
            'desc'      =>  __( 'This is a wysiwyg field.' ),
            'class'     =>  'regular-text',
            'width'     =>  '100%',
            'rows'      =>  5,
            'teeny'     =>  true,
            'text_mode'     =>  false,
            'media_buttons' =>  false,
            'default'       =>  'Hello World'
        ),
        array(
            'name'      =>  'sample_file',
            'label'     =>  __( 'File Field' ),
            'type'      =>  'file',
            'button_text'     =>  __( 'Upload' ),
            'desc'      =>  __( 'This is a file field.' ),
            'class'     =>  'regular-text',
            'disabled'  =>  false,
            'default'   =>  'http://example.com/sample/file.txt'
        ),
    )
);
 
mdc_meta_box( $args );

Requirement (minimum)

  • PHP 5.3.0
  • WordPress 3.0+

 

Need help with your WordPress tasks?

This entry was posted in WordPress and tagged add_meta_box, add_meta_boxed, meta box, meta box class, meta field, post meta box, wp meta field on April 27, 2016 by Nazmul Ahsan.

Post navigation

← How to remove default widgets (aka meta boxes) from WordPress dashboard How to stop WordPress from generating multiple image sizes →

Recent Comments

  • rabiul on A simple two-way function to encrypt or decrypt a string
  • Nazmul Ahsan on A simple two-way function to encrypt or decrypt a string
  • Eberechukwu Iherumadu on A simple two-way function to encrypt or decrypt a string
  • lala on A simple two-way function to encrypt or decrypt a string
  • Ashraful Ash on Transfer large files from one server to another in seconds

Recent Posts

  • How to share logins and user accounts across multiple WordPress sites
  • Ncrypt : A 2-way encryption library for PHP
  • What actually are Hooks in WordPress?
  • How to remove items from +New admin menu?
  • How to handle error messages in PHP
  • Generate activation or deactivation link of WordPress plugin
  • Edit Next Post – my 16th plugin published on the WP repository
  • Add a ‘Scroll to Top’ button to your WordPress site
  • How to customize WordPress login page
  • A simple two-way function to encrypt or decrypt a string
  • Change WordPress password when ‘reset password’ is not working
  • How to stop WordPress from generating multiple image sizes
  • I just released MDC Meta Box – a meta box library for WordPress
  • How to remove default widgets (aka meta boxes) from WordPress dashboard
  • How to clone or add new user roles – WordPress
  • How to rename user roles – WordPress
  • Transfer large files from one server to another in seconds
  • Visitor Counter for WordPress (Hit Counter)
  • Get back to an older version of WordPress (Downgrade WP)
  • Bengali Digits in WordPress
Copyright & Policy Proudly powered by WordPress