Meta Box - Version 4.3.4

Version Description

  • Bug fix: not show upload button after delete image when reach max_file_upload. #347
  • Bug fix: autocomplete for map which conflicts with tags (terms) autocomplete
  • Bug fix: random image order when reorder
  • Bug fix: undefined index, notices in WordPress 3.6, notice error for oembed field
  • Improvement: add default location for map field (via std param as usual)
  • Improvement: add placeholder for text fields (url, email, etc.)
  • Improvement: add multiple param for helper function to get value of multiple fields
  • Improvement: width & height for map in helper function now requires units (allow to set %)
  • Drop support for WordPress 3.3 (wysiwyg) and < 3.5 (for file & image field which uses new json functions)
Download this release

Release Info

Developer rilwis
Plugin Icon 128x128 Meta Box
Version 4.3.4
Comparing to
See all releases

Code changes from version 4.3.3 to 4.3.4

css/image.css CHANGED
@@ -8,13 +8,12 @@
8
  width: 150px;
9
  height: 150px;
10
  text-align: center;
11
- border: 2px solid #ccc;
12
  cursor: move;
13
  position: relative;
14
- -moz-transition:width 0.25s, opacity 0.25s, -moz-opacity 0.25s;
15
- -webkit-transition:width 0.25s, opacity 0.25s, -webkit-opacity 0.25s;
16
- -o-transition:width 0.25s, opacity 0.25s, -o-opacity 0.25s;
17
- transition:width 0.25s, opacity 0.25s;
18
  }
19
  .rwmb-images img {
20
  width: 150px;
@@ -29,45 +28,39 @@
29
  top: 0;
30
  right: 0;
31
  padding: 5px;
32
- display:none;
33
  text-align: center;
34
- vertical-align:middle;
35
  }
36
  li:hover .rwmb-image-bar{
37
- display:block;
38
  }
39
-
40
  .rwmb-image-bar a {
41
  color: #fff;
42
  font-weight: bold;
43
- text-decoration:none;
44
- text-align: center;
45
- vertical-align:inherit;
46
  }
47
-
48
  .rwmb-image-bar a.rwmb-delete-file {
49
- font-weight:lighter;
50
- font-size:23px;
51
- width:18px;
52
  }
53
-
54
  .rwmb-images li.removed {
55
  width: 0;
56
  margin: 0;
57
  opacity: 0;
58
  -webkit-opacity: 0;
59
  -moz-opacity: 0;
60
- -o-opacity: 0;
61
  }
62
-
63
  .rwmb-images li.removed:after {
64
  content: ' ';
65
  position: absolute;
66
- top:0;
67
- left:0;
68
- right:0;
69
- bottom:0;
70
  z-index: 2;
71
  opacity: .4;
72
- background-color: #F00;
73
  }
8
  width: 150px;
9
  height: 150px;
10
  text-align: center;
 
11
  cursor: move;
12
  position: relative;
13
+ -moz-transition: width 0.25s, opacity 0.25s, -moz-opacity 0.25s;
14
+ -webkit-transition: width 0.25s, opacity 0.25s, -webkit-opacity 0.25s;
15
+ -o-transition: width 0.25s, opacity 0.25s, -o-opacity 0.25s;
16
+ transition: width 0.25s, opacity 0.25s;
17
  }
18
  .rwmb-images img {
19
  width: 150px;
28
  top: 0;
29
  right: 0;
30
  padding: 5px;
31
+ display: none;
32
  text-align: center;
 
33
  }
34
  li:hover .rwmb-image-bar{
35
+ display: block;
36
  }
 
37
  .rwmb-image-bar a {
38
  color: #fff;
39
  font-weight: bold;
40
+ text-decoration: none;
41
+ vertical-align: middle;
 
42
  }
 
43
  .rwmb-image-bar a.rwmb-delete-file {
44
+ font-size: 23px;
45
+ width: 18px;
46
+ font-weight: normal;
47
  }
 
48
  .rwmb-images li.removed {
49
  width: 0;
50
  margin: 0;
51
  opacity: 0;
52
  -webkit-opacity: 0;
53
  -moz-opacity: 0;
54
+ -o-opacity: 0;
55
  }
 
56
  .rwmb-images li.removed:after {
57
  content: ' ';
58
  position: absolute;
59
+ top: 0;
60
+ left: 0;
61
+ right: 0;
62
+ bottom: 0;
63
  z-index: 2;
64
  opacity: .4;
65
+ background-color: #f00;
66
  }
css/oembed.css ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ .rwmb-oembed-wrapper .spinner {
2
+ float: none;
3
+ vertical-align: top;
4
+ display: inline-block;
5
+ }
6
+ .rwmb-oembed-wrapper .embed-code {
7
+ margin-top: 1em;
8
+ }
css/style.css CHANGED
@@ -72,6 +72,7 @@ select.error {
72
  background: #ffebe8 !important;
73
  }
74
 
 
75
  /* =Styles for 'side' meta boxes
76
  -------------------------------------------------------------- */
77
 
72
  background: #ffebe8 !important;
73
  }
74
 
75
+
76
  /* =Styles for 'side' meta boxes
77
  -------------------------------------------------------------- */
78
 
demo/all-custom-post-types.php DELETED
@@ -1,38 +0,0 @@
1
- <?php
2
-
3
- // This file shows a demo for register meta boxes for ALL custom post types
4
-
5
- add_action( 'admin_init', 'YOUR_PREFIX_register_meta_boxes' );
6
-
7
- function YOUR_PREFIX_register_meta_boxes()
8
- {
9
- if ( ! class_exists( 'RW_Meta_Box' ) )
10
- return;
11
-
12
- $prefix = 'YOUR_PREFIX_';
13
- $meta_boxes = array();
14
-
15
- $post_types = get_post_types();
16
-
17
- // 1st meta box
18
- $meta_boxes[] = array(
19
- 'id' => 'personal',
20
- 'title' => __( 'Personal Information', 'rwmb' ),
21
- 'pages' => $post_types,
22
-
23
- 'fields' => array(
24
- array(
25
- 'name' => __( 'Full name', 'rwmb' ),
26
- 'id' => $prefix . 'fname',
27
- 'type' => 'text',
28
- ),
29
- // Other fields go here
30
- )
31
- );
32
- // Other meta boxes go here
33
-
34
- foreach ( $meta_boxes as $meta_box )
35
- {
36
- new RW_Meta_Box( $meta_box );
37
- }
38
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
demo/better-include.php DELETED
@@ -1,119 +0,0 @@
1
- <?php
2
- /**
3
- * This file show you an improvement of better include meta box in some pages
4
- * based on post ID, post slug, page template and page parent
5
- *
6
- * @author Charlie Rosenbury <charlie@40digits.com>
7
- */
8
-
9
- $prefix = 'rw_';
10
-
11
- global $meta_boxes;
12
-
13
- $meta_boxes = array();
14
-
15
- $meta_boxes[] = array(
16
- 'title' => __( 'Meta Box Title', 'rwmb' ),
17
- 'fields' => array(
18
- array(
19
- 'name' => __( 'Your images', 'rwmb' ),
20
- 'id' => "{$prefix}img",
21
- 'type' => 'plupload_image',
22
- ),
23
- ),
24
- 'only_on' => array(
25
- 'id' => array( 1, 2 ),
26
- // 'slug' => array( 'news', 'blog' ),
27
- 'template' => array( 'fullwidth.php', 'simple.php' ),
28
- 'parent' => array( 10 )
29
- ),
30
- );
31
-
32
- /**
33
- * Register meta boxes
34
- *
35
- * @return void
36
- */
37
- function rw_register_meta_boxes()
38
- {
39
- global $meta_boxes;
40
-
41
- // Make sure there's no errors when the plugin is deactivated or during upgrade
42
- if ( class_exists( 'RW_Meta_Box' ) ) {
43
- foreach ( $meta_boxes as $meta_box ) {
44
- if ( isset( $meta_box['only_on'] ) && ! rw_maybe_include( $meta_box['only_on'] ) ) {
45
- continue;
46
- }
47
-
48
- new RW_Meta_Box( $meta_box );
49
- }
50
- }
51
- }
52
-
53
- add_action( 'admin_init', 'rw_register_meta_boxes' );
54
-
55
- /**
56
- * Check if meta boxes is included
57
- *
58
- * @return bool
59
- */
60
- function rw_maybe_include( $conditions ) {
61
- // Include in back-end only
62
- if ( ! defined( 'WP_ADMIN' ) || ! WP_ADMIN ) {
63
- return false;
64
- }
65
-
66
- // Always include for ajax
67
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
68
- return true;
69
- }
70
-
71
- if ( isset( $_GET['post'] ) ) {
72
- $post_id = $_GET['post'];
73
- }
74
- elseif ( isset( $_POST['post_ID'] ) ) {
75
- $post_id = $_POST['post_ID'];
76
- }
77
- else {
78
- $post_id = false;
79
- }
80
-
81
- $post_id = (int) $post_id;
82
- $post = get_post( $post_id );
83
-
84
- foreach ( $conditions as $cond => $v ) {
85
- // Catch non-arrays too
86
- if ( ! is_array( $v ) ) {
87
- $v = array( $v );
88
- }
89
-
90
- switch ( $cond ) {
91
- case 'id':
92
- if ( in_array( $post_id, $v ) ) {
93
- return true;
94
- }
95
- break;
96
- case 'parent':
97
- $post_parent = $post->post_parent;
98
- if ( in_array( $post_parent, $v ) ) {
99
- return true;
100
- }
101
- break;
102
- case 'slug':
103
- $post_slug = $post->post_name;
104
- if ( in_array( $post_slug, $v ) ) {
105
- return true;
106
- }
107
- break;
108
- case 'template':
109
- $template = get_post_meta( $post_id, '_wp_page_template', true );
110
- if ( in_array( $template, $v ) ) {
111
- return true;
112
- }
113
- break;
114
- }
115
- }
116
-
117
- // If no condition matched
118
- return false;
119
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
demo/date-time-js-options.php DELETED
@@ -1,56 +0,0 @@
1
- <?php
2
- add_action( 'admin_init', 'YOUR_PREFIX_register_meta_boxes' );
3
-
4
- function YOUR_PREFIX_register_meta_boxes()
5
- {
6
- if ( !class_exists( 'RW_Meta_Box' ) )
7
- return;
8
-
9
- $prefix = 'YOUR_PREFIX_';
10
- $meta_box = array(
11
- 'title' => __( 'Date Time Picker With JS Options', 'rwmb' ),
12
-
13
- 'fields' => array(
14
- array(
15
- 'name' => __( 'Date', 'rwmb' ),
16
- 'id' => $prefix . 'date',
17
- 'type' => 'date',
18
-
19
- // jQuery date picker options. See here http://jqueryui.com/demos/datepicker
20
- 'js_options' => array(
21
- 'appendText' => __( '(yyyy-mm-dd)', 'rwmb' ),
22
- 'autoSize' => true,
23
- 'buttonText' => __( 'Select Date', 'rwmb' ),
24
- 'dateFormat' => __( 'yy-mm-dd', 'rwmb' ),
25
- 'numberOfMonths' => 2,
26
- 'showButtonPanel' => true,
27
- ),
28
- ),
29
- array(
30
- 'name' => __( 'Datetime', 'rwmb' ),
31
- 'id' => $prefix . 'datetime',
32
- 'type' => 'datetime',
33
-
34
- // jQuery datetime picker options. See here http://trentrichardson.com/examples/timepicker/
35
- 'js_options' => array(
36
- 'stepMinute' => 15,
37
- 'showTimepicker' => true,
38
- ),
39
- ),
40
- array(
41
- 'name' => __( 'Time', 'rwmb' ),
42
- 'id' => $prefix . 'time',
43
- 'type' => 'time',
44
-
45
- // jQuery datetime picker options. See here http://trentrichardson.com/examples/timepicker/
46
- 'js_options' => array(
47
- 'stepMinute' => 5,
48
- 'showSecond' => true,
49
- 'stepSecond' => 10,
50
- ),
51
- ),
52
- ),
53
- );
54
-
55
- new RW_Meta_Box( $meta_box );
56
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
demo/demo.php DELETED
@@ -1,409 +0,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/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
- // EMAIL
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' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
demo/force-delete.php DELETED
@@ -1,45 +0,0 @@
1
- <?php
2
- add_action( 'admin_init', 'force_delete_register_meta_boxes' );
3
- function force_delete_register_meta_boxes()
4
- {
5
- if ( !class_exists( 'RW_Meta_Box' ) )
6
- return;
7
-
8
- $prefix = '';
9
-
10
- $meta_box = array(
11
- 'title' => __( 'Test Meta Box', 'rwmb' ),
12
- 'fields' => array(
13
- // FILE UPLOAD
14
- array(
15
- 'name' => __( 'File Upload', 'rwmb' ),
16
- 'id' => "{$prefix}file",
17
- 'type' => 'file',
18
- 'force_delete' => true,
19
- ),
20
- // IMAGE UPLOAD
21
- array(
22
- 'name' => __( 'Image Upload', 'rwmb' ),
23
- 'id' => "{$prefix}image",
24
- 'type' => 'image',
25
- ),
26
- // THICKBOX IMAGE UPLOAD (WP 3.3+)
27
- array(
28
- 'name' => __( 'Thickbox Image Upload', 'rwmb' ),
29
- 'id' => "{$prefix}thickbox",
30
- 'type' => 'thickbox_image',
31
- 'force_delete' => true,
32
- ),
33
- // PLUPLOAD IMAGE UPLOAD (WP 3.3+)
34
- array(
35
- 'name' => __( 'Plupload Image Upload', 'rwmb' ),
36
- 'id' => "{$prefix}plupload",
37
- 'type' => 'plupload_image',
38
- 'max_file_uploads' => 4,
39
- 'force_delete' => true,
40
- ),
41
- ),
42
- );
43
-
44
- new RW_Meta_Box( $meta_box );
45
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
demo/include-by-ID-or-page-template.php DELETED
@@ -1,85 +0,0 @@
1
- <?php
2
- $prefix = 'rw_';
3
-
4
- global $meta_boxes;
5
- $meta_boxes = array();
6
- $meta_boxes[] = array(
7
- 'id' => 'any_id',
8
- 'title' => __( 'Meta Box Title', 'rwmb' ),
9
- 'pages' => array( 'post' ),
10
- 'fields' => array(
11
-
12
- // IMAGE UPLOAD
13
- array(
14
- 'name' => __( 'Your images', 'rwmb' ),
15
- 'id' => "{$prefix}img",
16
- 'type' => 'plupload_image',
17
- ),
18
- ),
19
- );
20
-
21
- /**
22
- * Register meta boxes
23
- *
24
- * @return void
25
- */
26
- function rw_register_meta_boxes()
27
- {
28
- global $meta_boxes;
29
-
30
- // Make sure there's no errors when the plugin is deactivated or during upgrade
31
- if ( ! class_exists( 'RW_Meta_Box' ) )
32
- return;
33
-
34
- // Register meta boxes only for some posts/pages
35
- if ( ! rw_maybe_include() )
36
- return;
37
-
38
- foreach ( $meta_boxes as $meta_box )
39
- {
40
- new RW_Meta_Box( $meta_box );
41
- }
42
- }
43
-
44
- add_action( 'admin_init', 'rw_register_meta_boxes' );
45
-
46
- /**
47
- * Check if meta boxes is included
48
- *
49
- * @return bool
50
- */
51
- function rw_maybe_include()
52
- {
53
- // Include in back-end only
54
- if ( ! defined( 'WP_ADMIN' ) || ! WP_ADMIN )
55
- return false;
56
-
57
- // Always include for ajax
58
- if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
59
- return true;
60
-
61
- // Check for post IDs
62
- $checked_post_IDs = array( 61, 63, 65, 67, 2 );
63
-
64
- if ( isset( $_GET['post'] ) )
65
- $post_id = $_GET['post'];
66
- elseif ( isset( $_POST['post_ID'] ) )
67
- $post_id = $_POST['post_ID'];
68
- else
69
- $post_id = false;
70
-
71
- $post_id = (int) $post_id;
72
-
73
- if ( in_array( $post_id, $checked_post_IDs ) )
74
- return true;
75
-
76
- // Check for page template
77
- $checked_templates = array( 'full-width.php', 'sidebar-page.php' );
78
-
79
- $template = get_post_meta( $post_id, '_wp_page_template', true );
80
- if ( in_array( $template, $checked_templates ) )
81
- return true;
82
-
83
- // If no condition matched
84
- return false;
85
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
demo/map.php DELETED
@@ -1,29 +0,0 @@
1
- <?php
2
- add_action( 'admin_init', 'test_register_meta_boxes' );
3
- function test_register_meta_boxes()
4
- {
5
- if ( !class_exists( 'RW_Meta_Box' ) )
6
- return;
7
-
8
- $meta_box = array(
9
- 'title' => __( 'Google Map', 'rwmb' ),
10
- 'fields' => array(
11
- array(
12
- 'id' => 'address',
13
- 'name' => __( 'Address', 'rwmb' ),
14
- 'type' => 'text',
15
- 'std' => __( 'Hanoi, Vietnam', 'rwmb' ),
16
- ),
17
- array(
18
- 'id' => 'loc',
19
- 'name' => __( 'Location', 'rwmb' ),
20
- 'type' => 'map',
21
- 'std' => '-6.233406,-35.049906,15', // 'latitude,longitude[,zoom]' (zoom is optional)
22
- 'style' => 'width: 500px; height: 500px',
23
- 'address_field' => 'address', // Name of text field where address is entered. Can be list of text fields, separated by commas (for ex. city, state)
24
- ),
25
- ),
26
- );
27
-
28
- new RW_Meta_Box( $meta_box );
29
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inc/fields/email.php CHANGED
@@ -21,11 +21,12 @@ if ( !class_exists( 'RWMB_Email_Field' ) )
21
  static function html( $html, $meta, $field )
22
  {
23
  return sprintf(
24
- '<input type="email" class="rwmb-email" name="%s" id="%s" value="%s" size="%s" />',
25
  $field['field_name'],
26
  $field['id'],
27
  $meta,
28
- $field['size']
 
29
  );
30
  }
31
 
21
  static function html( $html, $meta, $field )
22
  {
23
  return sprintf(
24
+ '<input type="email" class="rwmb-email" name="%s" id="%s" value="%s" size="%s" placeholder="%s"/>',
25
  $field['field_name'],
26
  $field['id'],
27
  $meta,
28
+ $field['size'],
29
+ $field['placeholder']
30
  );
31
  }
32
 
inc/fields/file.php CHANGED
@@ -14,7 +14,7 @@ if ( ! class_exists( 'RWMB_File_Field' ) )
14
  static function admin_enqueue_scripts()
15
  {
16
  wp_enqueue_style( 'rwmb-file', RWMB_CSS_URL . 'file.css', array(), RWMB_VER );
17
- wp_enqueue_script( 'rwmb-file', RWMB_JS_URL . 'file.js', array( 'jquery', 'wp-ajax-response' ), RWMB_VER, true );
18
  wp_localize_script( 'rwmb-file', 'rwmbFile', array(
19
  'maxFileUploadsSingle' => __( 'You may only upload maximum %d file', 'rwmb' ),
20
  'maxFileUploadsPlural' => __( 'You may only upload maximum %d files', 'rwmb' ),
@@ -65,9 +65,9 @@ if ( ! class_exists( 'RWMB_File_Field' ) )
65
  $ok = $force_delete ? wp_delete_attachment( $attachment_id ) : true;
66
 
67
  if ( $ok )
68
- RW_Meta_Box::ajax_response( '', 'success' );
69
  else
70
- RW_Meta_Box::ajax_response( __( 'Error: Cannot delete file', 'rwmb' ), 'error' );
71
  }
72
 
73
  /**
14
  static function admin_enqueue_scripts()
15
  {
16
  wp_enqueue_style( 'rwmb-file', RWMB_CSS_URL . 'file.css', array(), RWMB_VER );
17
+ wp_enqueue_script( 'rwmb-file', RWMB_JS_URL . 'file.js', array( 'jquery' ), RWMB_VER, true );
18
  wp_localize_script( 'rwmb-file', 'rwmbFile', array(
19
  'maxFileUploadsSingle' => __( 'You may only upload maximum %d file', 'rwmb' ),
20
  'maxFileUploadsPlural' => __( 'You may only upload maximum %d files', 'rwmb' ),
65
  $ok = $force_delete ? wp_delete_attachment( $attachment_id ) : true;
66
 
67
  if ( $ok )
68
+ wp_send_json_success();
69
  else
70
+ wp_send_json_error( __( 'Error: Cannot delete file', 'rwmb' ) );
71
  }
72
 
73
  /**
inc/fields/image.php CHANGED
@@ -17,8 +17,7 @@ if ( ! class_exists( 'RWMB_Image_Field' ) )
17
  parent::admin_enqueue_scripts();
18
 
19
  wp_enqueue_style( 'rwmb-image', RWMB_CSS_URL . 'image.css', array(), RWMB_VER );
20
-
21
- wp_enqueue_script( 'rwmb-image', RWMB_JS_URL . 'image.js', array( 'jquery-ui-sortable', 'wp-ajax-response' ), RWMB_VER, true );
22
  }
23
 
24
  /**
@@ -44,24 +43,18 @@ if ( ! class_exists( 'RWMB_Image_Field' ) )
44
  {
45
  $field_id = isset( $_POST['field_id'] ) ? $_POST['field_id'] : 0;
46
  $order = isset( $_POST['order'] ) ? $_POST['order'] : 0;
 
47
 
48
  check_ajax_referer( "rwmb-reorder-images_{$field_id}" );
49
 
50
  parse_str( $order, $items );
51
- $items = $items['item'];
52
- $order = 1;
53
 
54
- foreach ( $items as $item )
 
55
  {
56
- wp_update_post(
57
- array(
58
- 'ID' => $item,
59
- 'menu_order' => $order++,
60
- )
61
- );
62
  }
63
-
64
- RW_Meta_Box::ajax_response( __( 'Order saved', 'rwmb' ), 'success' );
65
  }
66
 
67
  /**
@@ -108,7 +101,7 @@ if ( ! class_exists( 'RWMB_Image_Field' ) )
108
  {
109
  $reorder_nonce = wp_create_nonce( "rwmb-reorder-images_{$field['id']}" );
110
  $delete_nonce = wp_create_nonce( "rwmb-delete-file_{$field['id']}" );
111
- $classes = array('rwmb-images', 'rwmb-uploaded');
112
  if ( count( $images ) <= 0 )
113
  $classes[] = 'hidden';
114
  $ul = '<ul class="%s" data-field_id="%s" data-delete_nonce="%s" data-reorder_nonce="%s" data-force_delete="%s" data-max_file_uploads="%s">';
@@ -180,22 +173,13 @@ if ( ! class_exists( 'RWMB_Image_Field' ) )
180
  {
181
  global $wpdb;
182
 
183
- $meta = RW_Meta_Box::meta( $meta, $post_id, $saved, $field );
184
-
185
- if ( empty( $meta ) )
186
- return array();
187
-
188
- $meta = implode( ',' , (array) $meta );
189
-
190
- // Re-arrange images with 'menu_order'
191
- $meta = $wpdb->get_col( "
192
- SELECT ID FROM {$wpdb->posts}
193
- WHERE post_type = 'attachment'
194
- AND ID in ({$meta})
195
- ORDER BY menu_order ASC
196
- " );
197
 
198
- return (array) $meta;
199
  }
200
  }
201
  }
17
  parent::admin_enqueue_scripts();
18
 
19
  wp_enqueue_style( 'rwmb-image', RWMB_CSS_URL . 'image.css', array(), RWMB_VER );
20
+ wp_enqueue_script( 'rwmb-image', RWMB_JS_URL . 'image.js', array( 'jquery-ui-sortable' ), RWMB_VER, true );
 
21
  }
22
 
23
  /**
43
  {
44
  $field_id = isset( $_POST['field_id'] ) ? $_POST['field_id'] : 0;
45
  $order = isset( $_POST['order'] ) ? $_POST['order'] : 0;
46
+ $post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : 0;
47
 
48
  check_ajax_referer( "rwmb-reorder-images_{$field_id}" );
49
 
50
  parse_str( $order, $items );
 
 
51
 
52
+ delete_post_meta( $post_id, $field_id );
53
+ foreach ( $items['item'] as $item )
54
  {
55
+ add_post_meta( $post_id, $field_id, $item, false );
 
 
 
 
 
56
  }
57
+ wp_send_json_success();
 
58
  }
59
 
60
  /**
101
  {
102
  $reorder_nonce = wp_create_nonce( "rwmb-reorder-images_{$field['id']}" );
103
  $delete_nonce = wp_create_nonce( "rwmb-delete-file_{$field['id']}" );
104
+ $classes = array( 'rwmb-images', 'rwmb-uploaded' );
105
  if ( count( $images ) <= 0 )
106
  $classes[] = 'hidden';
107
  $ul = '<ul class="%s" data-field_id="%s" data-delete_nonce="%s" data-reorder_nonce="%s" data-force_delete="%s" data-max_file_uploads="%s">';
173
  {
174
  global $wpdb;
175
 
176
+ $meta = $wpdb->get_col( $wpdb->prepare( "
177
+ SELECT meta_value FROM $wpdb->postmeta
178
+ WHERE post_id = %d AND meta_key = '%s'
179
+ ORDER BY meta_id ASC
180
+ ", $post_id, $field['id'] ) );
 
 
 
 
 
 
 
 
 
181
 
182
+ return empty( $meta ) ? array() : $meta;
183
  }
184
  }
185
  }
inc/fields/map.php CHANGED
@@ -33,9 +33,10 @@ if ( !class_exists( 'RWMB_Map_Field' ) )
33
  $html = '<div class="rwmb-map-field">';
34
 
35
  $html .= sprintf(
36
- '<div class="rwmb-map-canvas" style="%s"></div>
37
  <input type="hidden" name="%s" class="rwmb-map-coordinate" value="%s">',
38
  isset( $field['style'] ) ? $field['style'] : '',
 
39
  $field['field_name'],
40
  $meta
41
  );
33
  $html = '<div class="rwmb-map-field">';
34
 
35
  $html .= sprintf(
36
+ '<div class="rwmb-map-canvas" style="%s"%s></div>
37
  <input type="hidden" name="%s" class="rwmb-map-coordinate" value="%s">',
38
  isset( $field['style'] ) ? $field['style'] : '',
39
+ isset( $field['std'] ) ? " data-default-loc=\"{$field['std']}\"" : '',
40
  $field['field_name'],
41
  $meta
42
  );
inc/fields/number.php CHANGED
@@ -18,12 +18,13 @@ if ( !class_exists( 'RWMB_Number_Field' ) )
18
  static function html( $html, $meta, $field )
19
  {
20
  return sprintf(
21
- '<input type="number" class="rwmb-number" name="%s" id="%s" value="%s" step="%s" min="%s" />',
22
  $field['field_name'],
23
  empty( $field['clone'] ) ? $field['id'] : '',
24
  $meta,
25
  $field['step'],
26
- $field['min']
 
27
  );
28
  }
29
 
18
  static function html( $html, $meta, $field )
19
  {
20
  return sprintf(
21
+ '<input type="number" class="rwmb-number" name="%s" id="%s" value="%s" step="%s" min="%s" placeholder="%s"/>',
22
  $field['field_name'],
23
  empty( $field['clone'] ) ? $field['id'] : '',
24
  $meta,
25
  $field['step'],
26
+ $field['min'],
27
+ $field['placeholder']
28
  );
29
  }
30
 
inc/fields/oembed.php CHANGED
@@ -16,9 +16,8 @@ if ( ! class_exists( 'RWMB_OEmbed_Field' ) )
16
  */
17
  static function admin_enqueue_scripts()
18
  {
19
- wp_enqueue_script( 'rwmb-oembed', RWMB_JS_URL . 'oembed.js', array( ), RWMB_VER, true );
20
- //wp_enqueue_style( 'rwmb-oembed', RWMB_CSS_URL . 'oembed.css', array( ), RWMB_VER );
21
- wp_localize_script( 'rwmb-oembed', 'RWMB_OEmbed', array( 'url' => RWMB_URL ) );
22
  }
23
 
24
  /**
@@ -28,7 +27,6 @@ if ( ! class_exists( 'RWMB_OEmbed_Field' ) )
28
  */
29
  static function add_actions()
30
  {
31
- // Attach images via Ajax
32
  add_action( 'wp_ajax_rwmb_get_embed', array( __CLASS__, 'wp_ajax_get_embed' ) );
33
  }
34
 
@@ -39,36 +37,21 @@ if ( ! class_exists( 'RWMB_OEmbed_Field' ) )
39
  */
40
  static function wp_ajax_get_embed()
41
  {
42
- global $post;
43
- $url = isset( $_POST['oembed_url'] ) ? $_POST['oembed_url'] : 0;
44
- $post_id = is_numeric( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
45
- if ( isset( $_REQUEST['post_id'] ) )
46
- $post = get_post( $_REQUEST['post_id'] );
47
- $embed = self::get_embed( $url );
48
- RW_Meta_Box::ajax_response( $embed, 'success' );
49
- exit;
50
  }
51
 
52
- /***
53
- * Get embed html from url
54
- * @param string $url
55
- * $return string
56
- */
57
-
 
58
  static function get_embed( $url )
59
  {
60
-
61
- $embed = wp_oembed_get( esc_url( $url ) );
62
-
63
- if( $embed )
64
- {
65
- return $embed;
66
- }
67
- else
68
- {
69
- return 'Embed not available.';
70
- }
71
-
72
  }
73
 
74
  /**
@@ -83,15 +66,16 @@ if ( ! class_exists( 'RWMB_OEmbed_Field' ) )
83
  static function html( $html, $meta, $field )
84
  {
85
  return sprintf(
86
- '<input type="url" class="rwmb-oembed" name="%s" id="%s" value="%s" size="%s" />
87
- <span class="spinner" style="display: none;"></span>
88
- <a href="#" class="show-embed button-secondary">Show embed</a>
89
- <div class="embed-code"> %s </div>',
90
  $field['field_name'],
91
  $field['id'],
92
  $meta,
93
  $field['size'],
94
- self::get_embed( $meta )
 
95
  );
96
  }
97
  }
16
  */
17
  static function admin_enqueue_scripts()
18
  {
19
+ wp_enqueue_style( 'rwmb-oembed', RWMB_CSS_URL . 'oembed.css' );
20
+ wp_enqueue_script( 'rwmb-oembed', RWMB_JS_URL . 'oembed.js', array(), RWMB_VER, true );
 
21
  }
22
 
23
  /**
27
  */
28
  static function add_actions()
29
  {
 
30
  add_action( 'wp_ajax_rwmb_get_embed', array( __CLASS__, 'wp_ajax_get_embed' ) );
31
  }
32
 
37
  */
38
  static function wp_ajax_get_embed()
39
  {
40
+ $url = isset( $_POST['url'] ) ? $_POST['url'] : '';
41
+ wp_send_json_success( self::get_embed( $url ) );
 
 
 
 
 
 
42
  }
43
 
44
+ /**
45
+ * Get embed html from url
46
+ *
47
+ * @param string $url
48
+ *
49
+ * @return string
50
+ */
51
  static function get_embed( $url )
52
  {
53
+ $embed = @wp_oembed_get( $url );
54
+ return $embed ? $embed : __( 'Embed HTML not available.', 'rwmb' );
 
 
 
 
 
 
 
 
 
 
55
  }
56
 
57
  /**
66
  static function html( $html, $meta, $field )
67
  {
68
  return sprintf(
69
+ '<input type="url" class="rwmb-oembed" name="%s" id="%s" value="%s" size="%s">
70
+ <a href="#" class="show-embed button">%s</a>
71
+ <span class="spinner"></span>
72
+ <div class="embed-code">%s</div>',
73
  $field['field_name'],
74
  $field['id'],
75
  $meta,
76
  $field['size'],
77
+ __( 'Show embed', 'rwmb' ),
78
+ $meta ? self::get_embed( $meta ) : ''
79
  );
80
  }
81
  }
inc/fields/plupload-image.php CHANGED
@@ -65,8 +65,7 @@ if ( ! class_exists( 'RWMB_Plupload_Image_Field' ) )
65
 
66
  // Save file ID in meta field
67
  add_post_meta( $post_id, $field_id, $id, false );
68
-
69
- RW_Meta_Box::ajax_response( self::img_html( $id ), 'success' );
70
  }
71
 
72
  exit;
65
 
66
  // Save file ID in meta field
67
  add_post_meta( $post_id, $field_id, $id, false );
68
+ wp_send_json_success( self::img_html( $id ) );
 
69
  }
70
 
71
  exit;
inc/fields/text-list.php CHANGED
@@ -19,7 +19,7 @@ if ( ! class_exists( 'RWMB_Text_List_Field' ) )
19
  {
20
  $meta = (array) $meta;
21
  $html = array();
22
- $tpl = '<label><input type="text" class="rwmb-text-list" name="%s" id="%s" value="%s" /> %s</label>';
23
 
24
  foreach ( $field['options'] as $value => $label )
25
  {
@@ -28,6 +28,7 @@ if ( ! class_exists( 'RWMB_Text_List_Field' ) )
28
  $field['field_name'],
29
  $field['id'],
30
  $value,
 
31
  $label
32
  );
33
  }
19
  {
20
  $meta = (array) $meta;
21
  $html = array();
22
+ $tpl = '<label><input type="text" class="rwmb-text-list" name="%s" id="%s" value="%s" placeholder="%s"/> %s</label>';
23
 
24
  foreach ( $field['options'] as $value => $label )
25
  {
28
  $field['field_name'],
29
  $field['id'],
30
  $value,
31
+ $field['placeholder'],
32
  $label
33
  );
34
  }
inc/fields/text.php CHANGED
@@ -18,10 +18,11 @@ if ( ! class_exists( 'RWMB_Text_Field' ) )
18
  static function html( $html, $meta, $field )
19
  {
20
  return sprintf(
21
- '<input type="text" class="rwmb-text" name="%s" id="%s" value="%s" size="%s" %s/>%s',
22
  $field['field_name'],
23
  $field['id'],
24
  $meta,
 
25
  $field['size'],
26
  !$field['datalist'] ? '' : "list='{$field['datalist']['id']}'",
27
  self::datalist_html($field)
@@ -38,12 +39,13 @@ if ( ! class_exists( 'RWMB_Text_Field' ) )
38
  static function normalize_field( $field )
39
  {
40
  $field = wp_parse_args( $field, array(
41
- 'size' => 30,
42
- 'datalist' => false
 
43
  ) );
44
  return $field;
45
  }
46
-
47
  /**
48
  * Create datalist, if any
49
  *
@@ -60,14 +62,14 @@ if ( ! class_exists( 'RWMB_Text_Field' ) )
60
  '<datalist id="%s">',
61
  $datalist['id']
62
  );
63
-
64
  foreach( $datalist['options'] as $option ) {
65
- $html.= sprintf('<option value="%s"></option>', $option);
66
  }
67
-
68
  $html .= '</datalist>';
69
-
70
  return $html;
71
  }
72
  }
73
- }
18
  static function html( $html, $meta, $field )
19
  {
20
  return sprintf(
21
+ '<input type="text" class="rwmb-text" name="%s" id="%s" value="%s" placeholder="%s" size="%s" %s>%s',
22
  $field['field_name'],
23
  $field['id'],
24
  $meta,
25
+ $field['placeholder'],
26
  $field['size'],
27
  !$field['datalist'] ? '' : "list='{$field['datalist']['id']}'",
28
  self::datalist_html($field)
39
  static function normalize_field( $field )
40
  {
41
  $field = wp_parse_args( $field, array(
42
+ 'size' => 30,
43
+ 'datalist' => false,
44
+ 'placeholder' => '',
45
  ) );
46
  return $field;
47
  }
48
+
49
  /**
50
  * Create datalist, if any
51
  *
62
  '<datalist id="%s">',
63
  $datalist['id']
64
  );
65
+
66
  foreach( $datalist['options'] as $option ) {
67
+ $html.= sprintf('<option value="%s"></option>', $option);
68
  }
69
+
70
  $html .= '</datalist>';
71
+
72
  return $html;
73
  }
74
  }
75
+ }
inc/fields/textarea.php CHANGED
@@ -18,11 +18,12 @@ if ( ! class_exists( 'RWMB_Textarea_Field' ) )
18
  static function html( $html, $meta, $field )
19
  {
20
  return sprintf(
21
- '<textarea class="rwmb-textarea large-text" name="%s" id="%s" cols="%s" rows="%s">%s</textarea>',
22
  $field['field_name'],
23
  $field['id'],
24
  $field['cols'],
25
  $field['rows'],
 
26
  $meta
27
  );
28
  }
18
  static function html( $html, $meta, $field )
19
  {
20
  return sprintf(
21
+ '<textarea class="rwmb-textarea large-text" name="%s" id="%s" cols="%s" rows="%s" placeholder="%s">%s</textarea>',
22
  $field['field_name'],
23
  $field['id'],
24
  $field['cols'],
25
  $field['rows'],
26
+ $field['placeholder'],
27
  $meta
28
  );
29
  }
inc/fields/url.php CHANGED
@@ -21,11 +21,12 @@ if ( ! class_exists( 'RWMB_URL_Field' ) )
21
  static function html( $html, $meta, $field )
22
  {
23
  return sprintf(
24
- '<input type="url" class="rwmb-url" name="%s" id="%s" value="%s" size="%s" />',
25
  $field['field_name'],
26
  $field['id'],
27
  $meta,
28
- $field['size']
 
29
  );
30
  }
31
 
21
  static function html( $html, $meta, $field )
22
  {
23
  return sprintf(
24
+ '<input type="url" class="rwmb-url" name="%s" id="%s" value="%s" size="%s" placeholder="%s"/>',
25
  $field['field_name'],
26
  $field['id'],
27
  $meta,
28
+ $field['size'],
29
+ $field['placeholder']
30
  );
31
  }
32
 
inc/fields/wysiwyg.php CHANGED
@@ -16,23 +16,6 @@ if ( !class_exists( 'RWMB_Wysiwyg_Field' ) )
16
  wp_enqueue_style( 'rwmb-meta-box-wysiwyg', RWMB_CSS_URL . 'wysiwyg.css', array(), RWMB_VER );
17
  }
18
 
19
- /**
20
- * Add field actions
21
- *
22
- * @return void
23
- */
24
- static function add_actions()
25
- {
26
- // Add TinyMCE script for WP version < 3.3
27
- global $wp_version;
28
-
29
- if ( version_compare( $wp_version, '3.2.1' ) < 1 )
30
- {
31
- add_action( 'admin_print_footer-post.php', 'wp_tiny_mce', 25 );
32
- add_action( 'admin_print_footer-post-new.php', 'wp_tiny_mce', 25 );
33
- }
34
- }
35
-
36
  /**
37
  * Change field value on save
38
  *
@@ -59,29 +42,15 @@ if ( !class_exists( 'RWMB_Wysiwyg_Field' ) )
59
  */
60
  static function html( $html, $meta, $field )
61
  {
62
- global $wp_version;
63
-
64
- if ( version_compare( $wp_version, '3.2.1' ) < 1 )
65
- {
66
- return sprintf(
67
- '<textarea class="rwmb-wysiwyg theEditor large-text" name="%s" id="%s" cols="60" rows="4">%s</textarea>',
68
- $field['field_name'],
69
- $field['id'],
70
- $meta
71
- );
72
- }
73
- else
74
- {
75
- // Using output buffering because wp_editor() echos directly
76
- ob_start();
77
 
78
- $field['options']['textarea_name'] = $field['field_name'];
79
 
80
- // Use new wp_editor() since WP 3.3
81
- wp_editor( $meta, $field['id'], $field['options'] );
82
 
83
- return ob_get_clean();
84
- }
85
  }
86
 
87
  /**
16
  wp_enqueue_style( 'rwmb-meta-box-wysiwyg', RWMB_CSS_URL . 'wysiwyg.css', array(), RWMB_VER );
17
  }
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  /**
20
  * Change field value on save
21
  *
42
  */
43
  static function html( $html, $meta, $field )
44
  {
45
+ // Using output buffering because wp_editor() echos directly
46
+ ob_start();
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
+ $field['options']['textarea_name'] = $field['field_name'];
49
 
50
+ // Use new wp_editor() since WP 3.3
51
+ wp_editor( $meta, $field['id'], $field['options'] );
52
 
53
+ return ob_get_clean();
 
54
  }
55
 
56
  /**
inc/helpers.php CHANGED
@@ -123,7 +123,8 @@ function rwmb_meta( $key, $args = array(), $post_id = null )
123
  ) );
124
 
125
  // Set 'multiple' for fields based on 'type'
126
- $args['multiple'] = in_array( $args['type'], array( 'checkbox_list', 'file', 'file_advanced', 'image', 'image_advanced', 'plupload_image', 'thickbox_image' ) );
 
127
 
128
  $meta = get_post_meta( $post_id, $key, !$args['multiple'] );
129
 
@@ -144,19 +145,16 @@ function rwmb_meta( $key, $args = array(), $post_id = null )
144
  // Get uploaded images info
145
  elseif ( in_array( $args['type'], array( 'image', 'plupload_image', 'thickbox_image', 'image_advanced' ) ) )
146
  {
147
- if ( is_array( $meta ) && !empty( $meta ) )
148
- {
149
- global $wpdb;
150
- $meta = implode( ',', $meta );
151
 
152
- // Re-arrange images with 'menu_order'
153
- $meta = $wpdb->get_col( "
154
- SELECT ID FROM {$wpdb->posts}
155
- WHERE post_type = 'attachment'
156
- AND ID in ({$meta})
157
- ORDER BY menu_order ASC
158
- " );
159
 
 
 
160
  $images = array();
161
  foreach ( $meta as $id )
162
  {
@@ -237,7 +235,7 @@ function rwmb_image_info( $id, $args = array() )
237
  if ( empty( $img_src ) )
238
  return false;
239
 
240
- $attachment = &get_post( $id );
241
  $path = get_attached_file( $id );
242
  return array(
243
  'ID' => $id,
@@ -278,8 +276,8 @@ function rwmb_meta_map( $key, $args = array(), $post_id = null )
278
 
279
  // Map parameters
280
  $args = wp_parse_args( $args, array(
281
- 'width' => 640,
282
- 'height' => 480,
283
  'zoom' => $parts[2], // Default to 'zoom' level set in admin, but can be overwritten
284
  'marker' => true, // Display marker?
285
  'marker_title' => '', // Marker title, when hover
@@ -292,15 +290,16 @@ function rwmb_meta_map( $key, $args = array(), $post_id = null )
292
  $html = sprintf(
293
  '<div id="rwmb-map-canvas-%d" style="width:%s;height:%s"></div>',
294
  $counter,
295
- $args['width'] . 'px',
296
- $args['height'] . 'px'
297
  );
298
- $html .= '<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>';
 
 
 
299
  $html .= '<script>
300
- (function()
301
  {
302
- function initialize()
303
- {
304
  ';
305
 
306
  $html .= sprintf( '
@@ -342,10 +341,7 @@ function rwmb_meta_map( $key, $args = array(), $post_id = null )
342
  }
343
  }
344
 
345
- $html .= '
346
- }
347
- google.maps.event.addDomListener(window, "load", initialize);
348
- }());
349
  </script>';
350
 
351
  $counter++;
123
  ) );
124
 
125
  // Set 'multiple' for fields based on 'type'
126
+ if ( !isset( $args['multiple'] ) )
127
+ $args['multiple'] = in_array( $args['type'], array( 'checkbox_list', 'file', 'file_advanced', 'image', 'image_advanced', 'plupload_image', 'thickbox_image' ) );
128
 
129
  $meta = get_post_meta( $post_id, $key, !$args['multiple'] );
130
 
145
  // Get uploaded images info
146
  elseif ( in_array( $args['type'], array( 'image', 'plupload_image', 'thickbox_image', 'image_advanced' ) ) )
147
  {
148
+ global $wpdb;
 
 
 
149
 
150
+ $meta = $wpdb->get_col( $wpdb->prepare( "
151
+ SELECT meta_value FROM $wpdb->postmeta
152
+ WHERE post_id = %d AND meta_key = '%s'
153
+ ORDER BY meta_id ASC
154
+ ", $post_id, $key ) );
 
 
155
 
156
+ if ( is_array( $meta ) && !empty( $meta ) )
157
+ {
158
  $images = array();
159
  foreach ( $meta as $id )
160
  {
235
  if ( empty( $img_src ) )
236
  return false;
237
 
238
+ $attachment = get_post( $id );
239
  $path = get_attached_file( $id );
240
  return array(
241
  'ID' => $id,
276
 
277
  // Map parameters
278
  $args = wp_parse_args( $args, array(
279
+ 'width' => '640px',
280
+ 'height' => '480px',
281
  'zoom' => $parts[2], // Default to 'zoom' level set in admin, but can be overwritten
282
  'marker' => true, // Display marker?
283
  'marker_title' => '', // Marker title, when hover
290
  $html = sprintf(
291
  '<div id="rwmb-map-canvas-%d" style="width:%s;height:%s"></div>',
292
  $counter,
293
+ $args['width'],
294
+ $args['height']
295
  );
296
+
297
+ // Load Google Maps script only when needed
298
+ $html .= '<script>if ( typeof google !== "object" || typeof google.maps !== "object" )
299
+ document.write(\'<script src="//maps.google.com/maps/api/js?sensor=false"><\/script>\')</script>';
300
  $html .= '<script>
301
+ ( function()
302
  {
 
 
303
  ';
304
 
305
  $html .= sprintf( '
341
  }
342
  }
343
 
344
+ $html .= '} )();
 
 
 
345
  </script>';
346
 
347
  $counter++;
inc/{classes/meta-box.php → meta-box.php} RENAMED
@@ -56,11 +56,11 @@ if ( ! class_exists( 'RW_Meta_Box' ) )
56
  $this->fields = &$this->meta_box['fields'];
57
  $this->validation = &$this->meta_box['validation'];
58
 
59
- // Allow users to show/hide (e.g. include/exclude) meta boxes
60
  // 1st action applies to all meta boxes
61
  // 2nd action applies to only current meta box
62
  $show = true;
63
- $show = apply_filters( 'rwmb_show', $show, $meta_box );
64
  $show = apply_filters( "rwmb_show_{$this->meta_box['id']}", $show, $this->meta_box );
65
  if ( !$show )
66
  return;
@@ -68,23 +68,17 @@ if ( ! class_exists( 'RW_Meta_Box' ) )
68
  // Enqueue common styles and scripts
69
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
70
 
71
- // All fields
72
- $fields = self::get_fields( $this->fields );
73
-
74
  // Add additional actions for fields
 
75
  foreach ( $fields as $field )
76
  {
77
  $class = self::get_class_name( $field );
78
-
79
  if ( method_exists( $class, 'add_actions' ) )
80
- call_user_func( array( $class, 'add_actions' ) );
81
  }
82
 
83
  // Add meta box
84
- foreach ( $this->meta_box['pages'] as $page )
85
- {
86
- add_action( "add_meta_boxes_{$page}", array( $this, 'add_meta_boxes' ) );
87
- }
88
 
89
  // Hide meta box if it's set 'default_hidden'
90
  add_filter( 'default_hidden_meta_boxes', array( $this, 'hide' ), 10, 2 );
@@ -125,7 +119,7 @@ if ( ! class_exists( 'RW_Meta_Box' ) )
125
  // Enqueue scripts and styles for fields
126
  $class = self::get_class_name( $field );
127
  if ( method_exists( $class, 'admin_enqueue_scripts' ) )
128
- call_user_func( array( $class, 'admin_enqueue_scripts' ) );
129
  }
130
 
131
  if ( $has_clone )
@@ -156,9 +150,7 @@ if ( ! class_exists( 'RW_Meta_Box' ) )
156
  {
157
  $all_fields[] = $field;
158
  if ( isset( $field['fields'] ) )
159
- {
160
  $all_fields = array_merge( $all_fields, self::get_fields( $field['fields'] ) );
161
- }
162
  }
163
 
164
  return $all_fields;
@@ -236,7 +228,7 @@ if ( ! class_exists( 'RW_Meta_Box' ) )
236
 
237
  foreach ( $this->fields as $field )
238
  {
239
- $meta = self::apply_field_class_filters( $field, 'meta', '', $post->ID, $saved );
240
  echo self::show_field( $field, $meta );
241
  }
242
 
@@ -289,7 +281,7 @@ if ( ! class_exists( 'RW_Meta_Box' ) )
289
  $meta = apply_filters( "rwmb_{$type}_meta", $meta );
290
  $meta = apply_filters( "rwmb_{$id}_meta", $meta );
291
 
292
- $begin = self::apply_field_class_filters( $field, 'begin_html', '', $meta );
293
 
294
  // Apply filter to field begin HTML
295
  // 1st filter applies to all fields
@@ -324,7 +316,7 @@ if ( ! class_exists( 'RW_Meta_Box' ) )
324
  $input_html = '<div class="rwmb-clone">';
325
 
326
  // Call separated methods for displaying each type of field
327
- $input_html .= self::apply_field_class_filters( $sub_field, 'html', '', $meta_data );
328
 
329
  // Apply filter to field HTML
330
  // 1st filter applies to all fields with the same type
@@ -341,7 +333,7 @@ if ( ! class_exists( 'RW_Meta_Box' ) )
341
  else
342
  {
343
  // Call separated methods for displaying each type of field
344
- $field_html = self::apply_field_class_filters( $field, 'html', '', $meta );
345
 
346
  // Apply filter to field HTML
347
  // 1st filter applies to all fields with the same type
@@ -350,7 +342,7 @@ if ( ! class_exists( 'RW_Meta_Box' ) )
350
  $field_html = apply_filters( "rwmb_{$id}_html", $field_html, $field, $meta );
351
  }
352
 
353
- $end = self::apply_field_class_filters( $field, 'end_html', '', $meta );
354
 
355
  // Apply filter to field end HTML
356
  // 1st filter applies to all fields
@@ -514,7 +506,7 @@ if ( ! class_exists( 'RW_Meta_Box' ) )
514
  $new = isset( $_POST[$name] ) ? $_POST[$name] : ( $field['multiple'] ? array() : '' );
515
 
516
  // Allow field class change the value
517
- $new = self::apply_field_class_filters( $field, 'value', $new, $old, $post_id );
518
 
519
  // Use filter to change field value
520
  // 1st filter applies to all fields with the same type
@@ -523,7 +515,7 @@ if ( ! class_exists( 'RW_Meta_Box' ) )
523
  $new = apply_filters( "rwmb_{$name}_value", $new, $field, $old );
524
 
525
  // Call defined method to save meta value, if there's no methods, call common one
526
- self::do_field_class_actions( $field, 'save', $new, $old, $post_id );
527
  }
528
 
529
  // After save action
@@ -614,24 +606,23 @@ if ( ! class_exists( 'RW_Meta_Box' ) )
614
  foreach ( $fields as &$field )
615
  {
616
  $field = wp_parse_args( $field, array(
617
- 'multiple' => false,
618
- 'clone' => false,
619
- 'std' => '',
620
- 'desc' => '',
621
- 'format' => '',
622
- 'before' => '',
623
- 'after' => '',
624
- 'field_name' => isset( $field['id'] ) ? $field['id'] : '',
625
- 'required' => false
 
626
  ) );
627
 
628
  // Allow field class add/change default field values
629
- $field = self::apply_field_class_filters( $field, 'normalize_field', $field );
630
 
631
- if( isset( $field['fields'] ) )
632
- {
633
  $field['fields'] = self::normalize_fields( $field['fields'] );
634
- }
635
  }
636
 
637
  return $fields;
@@ -646,9 +637,7 @@ if ( ! class_exists( 'RW_Meta_Box' ) )
646
  */
647
  static function get_class_name( $field )
648
  {
649
- $type = ucwords( $field['type'] );
650
- $class = "RWMB_{$type}_Field";
651
-
652
  if ( class_exists( $class ) )
653
  return $class;
654
 
@@ -659,12 +648,12 @@ if ( ! class_exists( 'RW_Meta_Box' ) )
659
  * Apply filters by field class, fallback to RW_Meta_Box method
660
  *
661
  * @param array $field
662
- * @param string $method_name
663
  * @param mixed $value
664
  *
665
  * @return mixed $value
666
  */
667
- static function apply_field_class_filters( $field, $method_name, $value )
668
  {
669
  $args = array_slice( func_get_args(), 2 );
670
  $args[] = $field;
@@ -672,14 +661,10 @@ if ( ! class_exists( 'RW_Meta_Box' ) )
672
  // Call: field class method
673
  // Fallback: RW_Meta_Box method
674
  $class = self::get_class_name( $field );
675
- if ( method_exists( $class, $method_name ) )
676
- {
677
- $value = call_user_func_array( array( $class, $method_name ), $args );
678
- }
679
- elseif ( method_exists( __CLASS__, $method_name ) )
680
- {
681
- $value = call_user_func_array( array( __CLASS__, $method_name ), $args );
682
- }
683
 
684
  return $value;
685
  }
@@ -688,42 +673,13 @@ if ( ! class_exists( 'RW_Meta_Box' ) )
688
  * Call field class method for actions, fallback to RW_Meta_Box method
689
  *
690
  * @param array $field
691
- * @param string $method_name
692
  *
693
  * @return mixed
694
  */
695
- static function do_field_class_actions( $field, $method_name )
696
- {
697
- $args = array_slice( func_get_args(), 2 );
698
- $args[] = $field;
699
-
700
- // Call: field class method
701
- // Fallback: RW_Meta_Box method
702
- $class = self::get_class_name( $field );
703
- if ( method_exists( $class, $method_name ) )
704
- {
705
- call_user_func_array( array( $class, $method_name ), $args );
706
- }
707
- elseif ( method_exists( __CLASS__, $method_name ) )
708
- {
709
- call_user_func_array( array( __CLASS__, $method_name ), $args );
710
- }
711
- }
712
-
713
- /**
714
- * Format Ajax response
715
- *
716
- * @param string $message
717
- * @param string $status
718
- *
719
- * @return void
720
- */
721
- static function ajax_response( $message, $status )
722
  {
723
- $response = array( 'what' => 'meta-box' );
724
- $response['data'] = 'error' === $status ? new WP_Error( 'error', $message ) : $message;
725
- $x = new WP_Ajax_Response( $response );
726
- $x->send();
727
  }
728
 
729
  /**
56
  $this->fields = &$this->meta_box['fields'];
57
  $this->validation = &$this->meta_box['validation'];
58
 
59
+ // Allow users to show/hide meta box
60
  // 1st action applies to all meta boxes
61
  // 2nd action applies to only current meta box
62
  $show = true;
63
+ $show = apply_filters( 'rwmb_show', $show, $this->meta_box );
64
  $show = apply_filters( "rwmb_show_{$this->meta_box['id']}", $show, $this->meta_box );
65
  if ( !$show )
66
  return;
68
  // Enqueue common styles and scripts
69
  add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
70
 
 
 
 
71
  // Add additional actions for fields
72
+ $fields = self::get_fields( $this->fields );
73
  foreach ( $fields as $field )
74
  {
75
  $class = self::get_class_name( $field );
 
76
  if ( method_exists( $class, 'add_actions' ) )
77
+ $class::add_actions();
78
  }
79
 
80
  // Add meta box
81
+ add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
 
 
 
82
 
83
  // Hide meta box if it's set 'default_hidden'
84
  add_filter( 'default_hidden_meta_boxes', array( $this, 'hide' ), 10, 2 );
119
  // Enqueue scripts and styles for fields
120
  $class = self::get_class_name( $field );
121
  if ( method_exists( $class, 'admin_enqueue_scripts' ) )
122
+ $class::admin_enqueue_scripts();
123
  }
124
 
125
  if ( $has_clone )
150
  {
151
  $all_fields[] = $field;
152
  if ( isset( $field['fields'] ) )
 
153
  $all_fields = array_merge( $all_fields, self::get_fields( $field['fields'] ) );
 
154
  }
155
 
156
  return $all_fields;
228
 
229
  foreach ( $this->fields as $field )
230
  {
231
+ $meta = self::apply_field_filters( $field, 'meta', '', $post->ID, $saved );
232
  echo self::show_field( $field, $meta );
233
  }
234
 
281
  $meta = apply_filters( "rwmb_{$type}_meta", $meta );
282
  $meta = apply_filters( "rwmb_{$id}_meta", $meta );
283
 
284
+ $begin = self::apply_field_filters( $field, 'begin_html', '', $meta );
285
 
286
  // Apply filter to field begin HTML
287
  // 1st filter applies to all fields
316
  $input_html = '<div class="rwmb-clone">';
317
 
318
  // Call separated methods for displaying each type of field
319
+ $input_html .= self::apply_field_filters( $sub_field, 'html', '', $meta_data );
320
 
321
  // Apply filter to field HTML
322
  // 1st filter applies to all fields with the same type
333
  else
334
  {
335
  // Call separated methods for displaying each type of field
336
+ $field_html = self::apply_field_filters( $field, 'html', '', $meta );
337
 
338
  // Apply filter to field HTML
339
  // 1st filter applies to all fields with the same type
342
  $field_html = apply_filters( "rwmb_{$id}_html", $field_html, $field, $meta );
343
  }
344
 
345
+ $end = self::apply_field_filters( $field, 'end_html', '', $meta );
346
 
347
  // Apply filter to field end HTML
348
  // 1st filter applies to all fields
506
  $new = isset( $_POST[$name] ) ? $_POST[$name] : ( $field['multiple'] ? array() : '' );
507
 
508
  // Allow field class change the value
509
+ $new = self::apply_field_filters( $field, 'value', $new, $old, $post_id );
510
 
511
  // Use filter to change field value
512
  // 1st filter applies to all fields with the same type
515
  $new = apply_filters( "rwmb_{$name}_value", $new, $field, $old );
516
 
517
  // Call defined method to save meta value, if there's no methods, call common one
518
+ self::do_field_actions( $field, 'save', $new, $old, $post_id );
519
  }
520
 
521
  // After save action
606
  foreach ( $fields as &$field )
607
  {
608
  $field = wp_parse_args( $field, array(
609
+ 'multiple' => false,
610
+ 'clone' => false,
611
+ 'std' => '',
612
+ 'desc' => '',
613
+ 'format' => '',
614
+ 'before' => '',
615
+ 'after' => '',
616
+ 'field_name' => isset( $field['id'] ) ? $field['id'] : '',
617
+ 'required' => false,
618
+ 'placeholder' => ''
619
  ) );
620
 
621
  // Allow field class add/change default field values
622
+ $field = self::apply_field_filters( $field, 'normalize_field', $field );
623
 
624
+ if ( isset( $field['fields'] ) )
 
625
  $field['fields'] = self::normalize_fields( $field['fields'] );
 
626
  }
627
 
628
  return $fields;
637
  */
638
  static function get_class_name( $field )
639
  {
640
+ $class = 'RWMB_' . ucwords( $field['type'] ) . '_Field';
 
 
641
  if ( class_exists( $class ) )
642
  return $class;
643
 
648
  * Apply filters by field class, fallback to RW_Meta_Box method
649
  *
650
  * @param array $field
651
+ * @param string $method
652
  * @param mixed $value
653
  *
654
  * @return mixed $value
655
  */
656
+ static function apply_field_filters( $field, $method, $value )
657
  {
658
  $args = array_slice( func_get_args(), 2 );
659
  $args[] = $field;
661
  // Call: field class method
662
  // Fallback: RW_Meta_Box method
663
  $class = self::get_class_name( $field );
664
+ if ( method_exists( $class, $method ) )
665
+ $value = call_user_func_array( array( $class, $method ), $args );
666
+ elseif ( method_exists( __CLASS__, $method ) )
667
+ $value = call_user_func_array( array( __CLASS__, $method ), $args );
 
 
 
 
668
 
669
  return $value;
670
  }
673
  * Call field class method for actions, fallback to RW_Meta_Box method
674
  *
675
  * @param array $field
676
+ * @param string $method
677
  *
678
  * @return mixed
679
  */
680
+ static function do_field_actions( $field, $method )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
681
  {
682
+ call_user_func_array( array( __CLASS__, 'apply_field_filters' ), func_get_args() );
 
 
 
683
  }
684
 
685
  /**
js/autosave.js CHANGED
@@ -2,7 +2,7 @@ jQuery( function( $ )
2
  {
3
  $( document ).ajaxSend( function( e, xhr, s )
4
  {
5
- if ( -1 != s.data.indexOf( 'action=autosave' ) )
6
  {
7
  $( '.rwmb-meta-box').each( function()
8
  {
2
  {
3
  $( document ).ajaxSend( function( e, xhr, s )
4
  {
5
+ if ( typeof s.data != 'undefined' && -1 != s.data.indexOf( 'action=autosave' ) )
6
  {
7
  $( '.rwmb-meta-box').each( function()
8
  {
js/file.js CHANGED
@@ -54,30 +54,40 @@ jQuery( document ).ready( function( $ )
54
 
55
  $.post( ajaxurl, data, function( r )
56
  {
57
- var res = wpAjax.parseAjaxResponse( r, 'ajax-response' );
58
-
59
- if ( res.errors )
60
  {
61
- alert( res.responses[0].errors[0].message );
 
62
  }
63
- else
 
 
 
 
 
 
 
 
64
  {
65
- $parent.addClass( 'removed' );
66
- //If transition events not supported
67
- if( !('ontransitionend' in window) && ('onwebkittransitionend' in window) && !('onotransitionend' in myDiv || navigator.appName == 'Opera') )
68
- $parent.remove();
69
  $container.trigger( 'update.rwmbFile' );
70
  }
71
- }, 'xml' );
 
 
 
 
 
 
72
 
73
  return false;
74
  } );
75
-
76
  //Remove deleted file
77
  $( '.rwmb-uploaded' ).on( 'transitionend webkitTransitionEnd otransitionend', 'li.removed', function() {
78
  $( this ).remove();
79
  });
80
-
81
  $( 'body' ).on( 'update.rwmbFile', '.rwmb-uploaded', function()
82
  {
83
  var $fileList = $( this ),
54
 
55
  $.post( ajaxurl, data, function( r )
56
  {
57
+ if ( !r.success )
 
 
58
  {
59
+ alert( r.data );
60
+ return;
61
  }
62
+
63
+ $parent.addClass( 'removed' );
64
+
65
+ // If transition events not supported
66
+ if (
67
+ !( 'ontransitionend' in window )
68
+ && ( 'onwebkittransitionend' in window )
69
+ && !( 'onotransitionend' in myDiv || navigator.appName == 'Opera' )
70
+ )
71
  {
72
+ $parent.remove();
 
 
 
73
  $container.trigger( 'update.rwmbFile' );
74
  }
75
+
76
+ $( '.rwmb-uploaded' ).on( 'transitionend webkitTransitionEnd otransitionend', 'li.removed', function()
77
+ {
78
+ $( this ).remove();
79
+ $container.trigger( 'update.rwmbFile' );
80
+ } );
81
+ }, 'json' );
82
 
83
  return false;
84
  } );
85
+
86
  //Remove deleted file
87
  $( '.rwmb-uploaded' ).on( 'transitionend webkitTransitionEnd otransitionend', 'li.removed', function() {
88
  $( this ).remove();
89
  });
90
+
91
  $( 'body' ).on( 'update.rwmbFile', '.rwmb-uploaded', function()
92
  {
93
  var $fileList = $( this ),
js/image-advanced.js CHANGED
@@ -56,7 +56,6 @@ jQuery( function( $ )
56
  return $imageList.children( 'li#item_' + attachment.id ).length == 0;
57
  } );
58
  ids = _.pluck( selection, 'id' );
59
- console.log( selection );
60
 
61
  if( ids.length > 0 )
62
  {
56
  return $imageList.children( 'li#item_' + attachment.id ).length == 0;
57
  } );
58
  ids = _.pluck( selection, 'id' );
 
59
 
60
  if( ids.length > 0 )
61
  {
js/image.js CHANGED
@@ -1,15 +1,14 @@
1
- jQuery( document ).ready( function( $ )
2
  {
3
  // Reorder images
4
  $( '.rwmb-images' ).each( function()
5
  {
6
- var $this = $( this ),
7
- $container = $this.closest('.rwmb-uploaded'),
8
- data = {
9
  action : 'rwmb_reorder_images',
10
- _ajax_nonce : $container.data('reorder_nonce'),
11
  post_id : $( '#post_ID' ).val(),
12
- field_id : $container.data('field_id')
13
  };
14
  $this.sortable( {
15
  placeholder: 'ui-state-highlight',
@@ -17,13 +16,7 @@ jQuery( document ).ready( function( $ )
17
  update : function()
18
  {
19
  data.order = $this.sortable( 'serialize' );
20
-
21
- $.post( ajaxurl, data, function( r )
22
- {
23
- var res = wpAjax.parseAjaxResponse( r, 'ajax-response' );
24
- if ( res.errors )
25
- alert( res.responses[0].errors[0].message );
26
- }, 'xml' );
27
  }
28
  } );
29
  } );
1
+ jQuery( function( $ )
2
  {
3
  // Reorder images
4
  $( '.rwmb-images' ).each( function()
5
  {
6
+ var $this = $( this ),
7
+ data = {
 
8
  action : 'rwmb_reorder_images',
9
+ _ajax_nonce : $this.data( 'reorder_nonce' ),
10
  post_id : $( '#post_ID' ).val(),
11
+ field_id : $this.data( 'field_id' )
12
  };
13
  $this.sortable( {
14
  placeholder: 'ui-state-highlight',
16
  update : function()
17
  {
18
  data.order = $this.sortable( 'serialize' );
19
+ $.post( ajaxurl, data );
 
 
 
 
 
 
20
  }
21
  } );
22
  } );
js/map.js CHANGED
@@ -33,7 +33,16 @@
33
  // Initialize map elements
34
  initMapElements: function()
35
  {
36
- var latLng = new google.maps.LatLng( 53.346881, -6.258860 ); // Initial position for map
 
 
 
 
 
 
 
 
 
37
 
38
  this.map = new google.maps.Map( this.canvas, {
39
  center: latLng,
33
  // Initialize map elements
34
  initMapElements: function()
35
  {
36
+ var defaultLoc = $(this.canvas).data('default-loc'),
37
+ latLng;
38
+
39
+ if (defaultLoc) {
40
+ defaultLoc = defaultLoc.split(',');
41
+ } else {
42
+ defaultLoc = [53.346881, -6.258860];
43
+ }
44
+
45
+ latLng = new google.maps.LatLng( defaultLoc[0], defaultLoc[1] ); // Initial position for map
46
 
47
  this.map = new google.maps.Map( this.canvas, {
48
  center: latLng,
js/oembed.js CHANGED
@@ -1,28 +1,22 @@
1
- jQuery( document ).ready( function( $ )
2
  {
3
- $( '.rwmb-input' ).on( 'click', 'a.show-embed', function() {
 
 
4
  var $this = $( this ),
5
- $input = $this.siblings( ':input.rwmb-oembed' );
6
- $embed_container = $this.siblings( '.embed-code' ),
7
  data = {
8
- action : 'rwmb_get_embed',
9
- oembed_url: $input.val(),
10
- post_id : $( '#post_ID' ).val()
11
  };
12
- $embed_container.html( "<img class='rwmb-loader' height='64' width='64' src='" + RWMB_OEmbed.url + "img/loader.gif'>" );
 
13
  $.post( ajaxurl, data, function( r )
14
  {
15
- var res = wpAjax.parseAjaxResponse( r, 'ajax-response' );
16
-
17
- if ( res.errors )
18
- alert( res.responses[0].errors[0].message );
19
- else
20
- $embed_container.html( res.responses[0].data );
21
-
22
- }, 'xml' );
23
-
24
 
25
  return false;
26
-
27
- });
28
  } );
1
+ jQuery( function( $ )
2
  {
3
+ $( '.rwmb-oembed-wrapper .spinner' ).hide();
4
+
5
+ $( 'body' ).on( 'click', '.rwmb-oembed-wrapper .show-embed', function() {
6
  var $this = $( this ),
7
+ $spinner = $this.siblings( '.spinner' ),
 
8
  data = {
9
+ action: 'rwmb_get_embed',
10
+ url: $this.siblings( 'input' ).val()
 
11
  };
12
+
13
+ $spinner.show();
14
  $.post( ajaxurl, data, function( r )
15
  {
16
+ $spinner.hide();
17
+ $this.siblings( '.embed-code' ).html( r.data );
18
+ }, 'json' );
 
 
 
 
 
 
19
 
20
  return false;
21
+ } );
 
22
  } );
js/plupload-image.js CHANGED
@@ -10,13 +10,13 @@ jQuery( function( $ )
10
  $dragndrop.removeClass('hidden');
11
  } );
12
 
13
- $('.rwmb-drag-drop').each(function()
14
  {
15
  // Declare vars
16
  var $dropArea = $( this ),
17
  $imageList = $dropArea.siblings( '.rwmb-uploaded' ),
18
  uploaderData = $dropArea.data( 'js_options' ),
19
- rwmbUploader = {};
20
 
21
  // Extend uploaderData
22
  uploaderData.multipart_params = $.extend(
@@ -28,13 +28,13 @@ jQuery( function( $ )
28
  );
29
 
30
  // Create uploader
31
- rwmbUploader = new plupload.Uploader( uploaderData );
32
- rwmbUploader.init();
33
 
34
  // Add files
35
- rwmbUploader.bind( 'FilesAdded', function( up, files )
36
  {
37
- var maxFileUploads = $imageList.data('max_file_uploads'),
38
  uploaded = $imageList.children().length,
39
  msg = maxFileUploads > 1 ? rwmbFile.maxFileUploadsPlural : rwmbFile.maxFileUploadsSingle;
40
 
@@ -71,17 +71,17 @@ jQuery( function( $ )
71
 
72
  } );
73
 
74
- rwmbUploader.bind( 'Error', function( up, e )
75
  {
76
  addLoading( up, e.file, $imageList );
77
  removeError( e.file );
78
  up.removeFile( e.file );
79
  } );
80
 
81
- rwmbUploader.bind( 'FileUploaded', function( up, file, response )
82
  {
83
- var res = wpAjax.parseAjaxResponse( $.parseXML( response.response ), 'ajax-response' );
84
- false === res.errors ? $( 'li#' + file.id ).replaceWith( res.responses[0].data ) : removeError( file );
85
  } );
86
  });
87
 
10
  $dragndrop.removeClass('hidden');
11
  } );
12
 
13
+ $( '.rwmb-drag-drop' ).each(function()
14
  {
15
  // Declare vars
16
  var $dropArea = $( this ),
17
  $imageList = $dropArea.siblings( '.rwmb-uploaded' ),
18
  uploaderData = $dropArea.data( 'js_options' ),
19
+ uploader = {};
20
 
21
  // Extend uploaderData
22
  uploaderData.multipart_params = $.extend(
28
  );
29
 
30
  // Create uploader
31
+ uploader = new plupload.Uploader( uploaderData );
32
+ uploader.init();
33
 
34
  // Add files
35
+ uploader.bind( 'FilesAdded', function( up, files )
36
  {
37
+ var maxFileUploads = $imageList.data( 'max_file_uploads' ),
38
  uploaded = $imageList.children().length,
39
  msg = maxFileUploads > 1 ? rwmbFile.maxFileUploadsPlural : rwmbFile.maxFileUploadsSingle;
40
 
71
 
72
  } );
73
 
74
+ uploader.bind( 'Error', function( up, e )
75
  {
76
  addLoading( up, e.file, $imageList );
77
  removeError( e.file );
78
  up.removeFile( e.file );
79
  } );
80
 
81
+ uploader.bind( 'FileUploaded', function( up, file, r )
82
  {
83
+ r = $.parseJSON( r.response );
84
+ r.success ? $( 'li#' + file.id ).replaceWith( r.data ) : removeError( file );
85
  } );
86
  });
87
 
meta-box.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Meta Box
4
  Plugin URI: http://www.deluxeblogtips.com/meta-box
5
  Description: Create meta box for editing pages in WordPress. Compatible with custom post types since WP 3.0
6
- Version: 4.3.3
7
  Author: Rilwis
8
  Author URI: http://www.deluxeblogtips.com
9
  License: GPL2+
@@ -13,7 +13,7 @@ License: GPL2+
13
  defined( 'ABSPATH' ) || exit;
14
 
15
  // Script version, used to add version for scripts and styles
16
- define( 'RWMB_VER', '4.3.3' );
17
 
18
  // Define plugin URLs, for fast enqueuing scripts and styles
19
  if ( ! defined( 'RWMB_URL' ) )
@@ -26,7 +26,6 @@ if ( ! defined( 'RWMB_DIR' ) )
26
  define( 'RWMB_DIR', plugin_dir_path( __FILE__ ) );
27
  define( 'RWMB_INC_DIR', trailingslashit( RWMB_DIR . 'inc' ) );
28
  define( 'RWMB_FIELDS_DIR', trailingslashit( RWMB_INC_DIR . 'fields' ) );
29
- define( 'RWMB_CLASSES_DIR', trailingslashit( RWMB_INC_DIR . 'classes' ) );
30
 
31
  // Optimize code for loading plugin files ONLY on admin side
32
  // @see http://www.deluxeblogtips.com/?p=345
@@ -45,5 +44,5 @@ if ( is_admin() )
45
  }
46
 
47
  // Main file
48
- require_once RWMB_CLASSES_DIR . 'meta-box.php';
49
  }
3
  Plugin Name: Meta Box
4
  Plugin URI: http://www.deluxeblogtips.com/meta-box
5
  Description: Create meta box for editing pages in WordPress. Compatible with custom post types since WP 3.0
6
+ Version: 4.3.4
7
  Author: Rilwis
8
  Author URI: http://www.deluxeblogtips.com
9
  License: GPL2+
13
  defined( 'ABSPATH' ) || exit;
14
 
15
  // Script version, used to add version for scripts and styles
16
+ define( 'RWMB_VER', '4.3.4' );
17
 
18
  // Define plugin URLs, for fast enqueuing scripts and styles
19
  if ( ! defined( 'RWMB_URL' ) )
26
  define( 'RWMB_DIR', plugin_dir_path( __FILE__ ) );
27
  define( 'RWMB_INC_DIR', trailingslashit( RWMB_DIR . 'inc' ) );
28
  define( 'RWMB_FIELDS_DIR', trailingslashit( RWMB_INC_DIR . 'fields' ) );
 
29
 
30
  // Optimize code for loading plugin files ONLY on admin side
31
  // @see http://www.deluxeblogtips.com/?p=345
44
  }
45
 
46
  // Main file
47
+ require_once RWMB_INC_DIR . 'meta-box.php';
48
  }
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: rilwis, franz-josef-kaiser, Omnicia, funkedgeek, PerWiklander, ruanmer
3
  Donate link: http://www.deluxeblogtips.com/donate
4
  Tags: meta-box, custom-fields, custom-field, meta, meta-boxes
5
- Requires at least: 3.3
6
- Tested up to: 3.5.2
7
- Stable tag: 4.3.3
8
 
9
  Meta Box plugin helps you easily implement multiple meta boxes in editing pages in WordPress. Works with custom post types and various field types.
10
 
@@ -21,35 +21,27 @@ Meta Box plugin provides an API to easily implement custom meta boxes in editing
21
  **Supported fields**
22
 
23
  - button
24
- - checkbox_list
25
- - checkbox
26
  - color
27
- - date
28
- - datetime
29
  - divider
30
  - email
31
- - file
32
- - file_advanced
33
  - heading
34
  - hidden
35
- - image
36
- - image_advanced
37
  - map
38
  - number
39
  - oembed
40
  - password
41
- - plupload_image
42
  - post
43
  - radio
44
  - range
45
- - select
46
- - select_advanced (uses [select2](http://ivaynberg.github.com/select2/))
47
  - slider
48
  - taxonomy
49
  - text
50
  - textarea
51
- - thickbox_image
52
- - time
53
  - url
54
  - wysiwyg
55
 
@@ -71,6 +63,17 @@ To getting started with the plugin API, please read [this tutorial](http://www.d
71
 
72
  == Changelog ==
73
 
 
 
 
 
 
 
 
 
 
 
 
74
  = 4.3.3 =
75
  * Bug fix: cannot clear all terms in taxonomy field
76
  * Bug fix: potential problem with autosave
2
  Contributors: rilwis, franz-josef-kaiser, Omnicia, funkedgeek, PerWiklander, ruanmer
3
  Donate link: http://www.deluxeblogtips.com/donate
4
  Tags: meta-box, custom-fields, custom-field, meta, meta-boxes
5
+ Requires at least: 3.5
6
+ Tested up to: 3.6.1
7
+ Stable tag: 4.3.4
8
 
9
  Meta Box plugin helps you easily implement multiple meta boxes in editing pages in WordPress. Works with custom post types and various field types.
10
 
21
  **Supported fields**
22
 
23
  - button
24
+ - checkbox, checkbox_list
 
25
  - color
26
+ - date, time, datetime
 
27
  - divider
28
  - email
29
+ - file, file_advanced
 
30
  - heading
31
  - hidden
32
+ - image, thickbox_image, plupload_image, image_advanced
 
33
  - map
34
  - number
35
  - oembed
36
  - password
 
37
  - post
38
  - radio
39
  - range
40
+ - select, select_advanced (uses [select2](http://ivaynberg.github.com/select2/))
 
41
  - slider
42
  - taxonomy
43
  - text
44
  - textarea
 
 
45
  - url
46
  - wysiwyg
47
 
63
 
64
  == Changelog ==
65
 
66
+ = 4.3.4 =
67
+ * Bug fix: not show upload button after delete image when reach max_file_upload. #347
68
+ * Bug fix: autocomplete for map which conflicts with tags (terms) autocomplete
69
+ * Bug fix: random image order when reorder
70
+ * Bug fix: undefined index, notices in WordPress 3.6, notice error for oembed field
71
+ * Improvement: add default location for map field (via `std` param as usual)
72
+ * Improvement: add `placeholder` for text fields (url, email, etc.)
73
+ * Improvement: add `multiple` param for helper function to get value of multiple fields
74
+ * Improvement: `width` & `height` for map in helper function now requires units (allow to set %)
75
+ * Drop support for WordPress 3.3 (wysiwyg) and < 3.5 (for file & image field which uses new json functions)
76
+
77
  = 4.3.3 =
78
  * Bug fix: cannot clear all terms in taxonomy field
79
  * Bug fix: potential problem with autosave