Version Description
- 2019-04-01 =
Fixed
- Fixed JavaScript error for
slider
field when creating a new post. - Fixed images of the
image_advanced
cleared when changing image the post content in Gutenberg.
Changed
-
text_list
: Do not save if all inputs has no value.
See full changelog here.
=
Download this release
Release Info
Developer | rilwis |
Plugin | Meta Box |
Version | 4.17.1 |
Comparing to | |
See all releases |
Code changes from version 4.17.0 to 4.17.1
- inc/clone.php +6 -0
- inc/field.php +2 -17
- inc/fields/text-list.php +17 -18
- inc/helpers/field.php +11 -6
- inc/helpers/value.php +33 -0
- inc/loader.php +1 -1
- js/media.js +101 -137
- js/slider.js +2 -7
- meta-box.php +1 -1
- readme.txt +8 -19
inc/clone.php
CHANGED
@@ -93,6 +93,12 @@ class RWMB_Clone {
|
|
93 |
$new[ $key ] = RWMB_Field::filter( 'sanitize', $value, $field );
|
94 |
}
|
95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
return $new;
|
97 |
}
|
98 |
|
93 |
$new[ $key ] = RWMB_Field::filter( 'sanitize', $value, $field );
|
94 |
}
|
95 |
|
96 |
+
// Remove empty clones.
|
97 |
+
$new = array_filter( $new, 'RWMB_Helpers_Value::is_valid_for_field' );
|
98 |
+
|
99 |
+
// Reset indexes.
|
100 |
+
$new = array_values( $new );
|
101 |
+
|
102 |
return $new;
|
103 |
}
|
104 |
|
inc/field.php
CHANGED
@@ -275,26 +275,14 @@ abstract class RWMB_Field {
|
|
275 |
$name = $field['id'];
|
276 |
$storage = $field['storage'];
|
277 |
|
278 |
-
// Remove empty values for clones.
|
279 |
-
if ( $field['clone'] ) {
|
280 |
-
$new = (array) $new;
|
281 |
-
foreach ( $new as $k => $v ) {
|
282 |
-
if ( '' === $v || array() === $v ) {
|
283 |
-
unset( $new[ $k ] );
|
284 |
-
}
|
285 |
-
}
|
286 |
-
}
|
287 |
-
|
288 |
// Remove post meta if it's empty.
|
289 |
-
if (
|
290 |
$storage->delete( $post_id, $name );
|
291 |
return;
|
292 |
}
|
293 |
|
294 |
// If field is cloneable AND not force to save as multiple rows, value is saved as a single row in the database.
|
295 |
if ( $field['clone'] && ! $field['clone_as_multiple'] ) {
|
296 |
-
// Reset indexes.
|
297 |
-
$new = array_values( $new );
|
298 |
$storage->update( $post_id, $name, $new );
|
299 |
return;
|
300 |
}
|
@@ -401,11 +389,8 @@ abstract class RWMB_Field {
|
|
401 |
public static function render_attributes( $attributes ) {
|
402 |
$output = '';
|
403 |
|
|
|
404 |
foreach ( $attributes as $key => $value ) {
|
405 |
-
if ( false === $value || '' === $value ) {
|
406 |
-
continue;
|
407 |
-
}
|
408 |
-
|
409 |
if ( is_array( $value ) ) {
|
410 |
$value = wp_json_encode( $value );
|
411 |
}
|
275 |
$name = $field['id'];
|
276 |
$storage = $field['storage'];
|
277 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
278 |
// Remove post meta if it's empty.
|
279 |
+
if ( ! RWMB_Helpers_Value::is_valid_for_field( $new ) ) {
|
280 |
$storage->delete( $post_id, $name );
|
281 |
return;
|
282 |
}
|
283 |
|
284 |
// If field is cloneable AND not force to save as multiple rows, value is saved as a single row in the database.
|
285 |
if ( $field['clone'] && ! $field['clone_as_multiple'] ) {
|
|
|
|
|
286 |
$storage->update( $post_id, $name, $new );
|
287 |
return;
|
288 |
}
|
389 |
public static function render_attributes( $attributes ) {
|
390 |
$output = '';
|
391 |
|
392 |
+
$attributes = array_filter( $attributes, 'RWMB_Helpers_Value::is_valid_for_attribute' );
|
393 |
foreach ( $attributes as $key => $value ) {
|
|
|
|
|
|
|
|
|
394 |
if ( is_array( $value ) ) {
|
395 |
$value = wp_json_encode( $value );
|
396 |
}
|
inc/fields/text-list.php
CHANGED
@@ -38,7 +38,7 @@ class RWMB_Text_List_Field extends RWMB_Multiple_Values_Field {
|
|
38 |
$label,
|
39 |
$field['field_name'],
|
40 |
isset( $meta[ $count ] ) ? esc_attr( $meta[ $count ] ) : '',
|
41 |
-
$placeholder
|
42 |
);
|
43 |
$count ++;
|
44 |
}
|
@@ -61,6 +61,22 @@ class RWMB_Text_List_Field extends RWMB_Multiple_Values_Field {
|
|
61 |
return $field;
|
62 |
}
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
/**
|
65 |
* Format value for the helper functions.
|
66 |
*
|
@@ -107,21 +123,4 @@ class RWMB_Text_List_Field extends RWMB_Multiple_Values_Field {
|
|
107 |
$output .= '</tr>';
|
108 |
return $output;
|
109 |
}
|
110 |
-
|
111 |
-
/**
|
112 |
-
* Save meta value.
|
113 |
-
*
|
114 |
-
* @param mixed $new The submitted meta value.
|
115 |
-
* @param mixed $old The existing meta value.
|
116 |
-
* @param int $post_id The post ID.
|
117 |
-
* @param array $field The field parameters.
|
118 |
-
*/
|
119 |
-
public static function save( $new, $old, $post_id, $field ) {
|
120 |
-
if ( empty( $field['id'] ) || ! $field['save_field'] ) {
|
121 |
-
return;
|
122 |
-
}
|
123 |
-
$storage = $field['storage'];
|
124 |
-
$storage->delete( $post_id, $field['id'] );
|
125 |
-
parent::save( $new, array(), $post_id, $field );
|
126 |
-
}
|
127 |
}
|
38 |
$label,
|
39 |
$field['field_name'],
|
40 |
isset( $meta[ $count ] ) ? esc_attr( $meta[ $count ] ) : '',
|
41 |
+
esc_attr( $placeholder )
|
42 |
);
|
43 |
$count ++;
|
44 |
}
|
61 |
return $field;
|
62 |
}
|
63 |
|
64 |
+
/**
|
65 |
+
* Set value of meta before saving into database.
|
66 |
+
* Do not save if all inputs has no value.
|
67 |
+
*
|
68 |
+
* @param mixed $new The submitted meta value.
|
69 |
+
* @param mixed $old The existing meta value.
|
70 |
+
* @param int $post_id The post ID.
|
71 |
+
* @param array $field The field parameters.
|
72 |
+
*
|
73 |
+
* @return mixed
|
74 |
+
*/
|
75 |
+
public static function value( $new, $old, $post_id, $field ) {
|
76 |
+
$filtered = array_filter( $new );
|
77 |
+
return count( $filtered ) ? $new : array();
|
78 |
+
}
|
79 |
+
|
80 |
/**
|
81 |
* Format value for the helper functions.
|
82 |
*
|
123 |
$output .= '</tr>';
|
124 |
return $output;
|
125 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
}
|
inc/helpers/field.php
CHANGED
@@ -45,13 +45,18 @@ class RWMB_Helpers_Field {
|
|
45 |
* @return string
|
46 |
*/
|
47 |
private static function get_type( $field ) {
|
48 |
-
$type = isset( $field['type'] ) ? $field['type'] : '
|
49 |
-
$map =
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
53 |
);
|
54 |
|
55 |
-
return
|
56 |
}
|
57 |
}
|
45 |
* @return string
|
46 |
*/
|
47 |
private static function get_type( $field ) {
|
48 |
+
$type = isset( $field['type'] ) ? $field['type'] : 'text';
|
49 |
+
$map = array_merge(
|
50 |
+
array(
|
51 |
+
$type => $type,
|
52 |
+
),
|
53 |
+
array(
|
54 |
+
'file_advanced' => 'media',
|
55 |
+
'plupload_image' => 'image_upload',
|
56 |
+
'url' => 'text',
|
57 |
+
)
|
58 |
);
|
59 |
|
60 |
+
return $map[ $type ];
|
61 |
}
|
62 |
}
|
inc/helpers/value.php
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Helper functions for checking values.
|
4 |
+
*
|
5 |
+
* @package Meta Box
|
6 |
+
*/
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Helper class for checking values.
|
10 |
+
*
|
11 |
+
* @package Meta Box
|
12 |
+
*/
|
13 |
+
class RWMB_Helpers_Value {
|
14 |
+
/**
|
15 |
+
* Check if a value is valid for field (not empty "WordPress way"), e.g. equals to empty string or array.
|
16 |
+
*
|
17 |
+
* @param mixed $value Input value.
|
18 |
+
* @return bool
|
19 |
+
*/
|
20 |
+
public static function is_valid_for_field( $value ) {
|
21 |
+
return '' !== $value && array() !== $value;
|
22 |
+
}
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Check if a value is valid for attribute.
|
26 |
+
*
|
27 |
+
* @param mixed $value Input value.
|
28 |
+
* @return bool
|
29 |
+
*/
|
30 |
+
public static function is_valid_for_attribute( $value ) {
|
31 |
+
return '' !== $value && false !== $value;
|
32 |
+
}
|
33 |
+
}
|
inc/loader.php
CHANGED
@@ -18,7 +18,7 @@ class RWMB_Loader {
|
|
18 |
*/
|
19 |
protected function constants() {
|
20 |
// Script version, used to add version for scripts and styles.
|
21 |
-
define( 'RWMB_VER', '4.17.
|
22 |
|
23 |
list( $path, $url ) = self::get_path( dirname( dirname( __FILE__ ) ) );
|
24 |
|
18 |
*/
|
19 |
protected function constants() {
|
20 |
// Script version, used to add version for scripts and styles.
|
21 |
+
define( 'RWMB_VER', '4.17.1' );
|
22 |
|
23 |
list( $path, $url ) = self::get_path( dirname( dirname( __FILE__ ) ) );
|
24 |
|
js/media.js
CHANGED
@@ -28,32 +28,26 @@ jQuery( function ( $ ) {
|
|
28 |
var max = this.controller.get( 'maxFiles' ),
|
29 |
left = max - this.length;
|
30 |
|
31 |
-
if ( max > 0 && left <= 0 ) {
|
32 |
return this;
|
33 |
}
|
34 |
-
if( models) {
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
models = models.models;
|
39 |
-
}
|
40 |
-
}
|
41 |
-
if ( left > 0 ) {
|
42 |
-
models = _.difference( models, this.models );
|
43 |
-
models = _.first( models, left );
|
44 |
}
|
45 |
|
46 |
-
|
47 |
-
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
},
|
58 |
|
59 |
destroyAll: function () {
|
@@ -94,7 +88,6 @@ jQuery( function ( $ ) {
|
|
94 |
} );
|
95 |
},
|
96 |
|
97 |
-
|
98 |
// Load initial media
|
99 |
load: function () {
|
100 |
if ( _.isEmpty( this.get( 'ids' ) ) ) {
|
@@ -209,8 +202,6 @@ jQuery( function ( $ ) {
|
|
209 |
controller: this.controller
|
210 |
} );
|
211 |
|
212 |
-
this.listenToItemView( itemView );
|
213 |
-
|
214 |
return itemView;
|
215 |
},
|
216 |
function ( item ) {
|
@@ -219,7 +210,6 @@ jQuery( function ( $ ) {
|
|
219 |
);
|
220 |
|
221 |
this.listenTo( this.collection, 'add', this.addItemView );
|
222 |
-
this.listenTo( this.collection, 'remove', this.removeItemView );
|
223 |
this.listenTo( this.collection, 'reset', this.resetItemViews );
|
224 |
|
225 |
// Sort items using helper 'clone' to prevent trigger click on the image, which means reselect.
|
@@ -228,102 +218,26 @@ jQuery( function ( $ ) {
|
|
228 |
} );
|
229 |
},
|
230 |
|
231 |
-
listenToItemView: function ( itemView ) {
|
232 |
-
this.listenTo( itemView, 'click:remove', this.removeItem );
|
233 |
-
this.listenTo( itemView, 'click:switch', this.switchItem );
|
234 |
-
this.listenTo( itemView, 'click:edit', this.editItem );
|
235 |
-
},
|
236 |
-
|
237 |
-
//Add item view
|
238 |
addItemView: function ( item ) {
|
239 |
var index = this.collection.indexOf( item ),
|
240 |
-
itemEl = this.getItemView( item ).el
|
|
|
241 |
|
242 |
if ( 0 >= index ) {
|
243 |
this.$el.prepend( itemEl );
|
244 |
-
}
|
245 |
-
else if ( this.$el.children().length <= index ) {
|
246 |
this.$el.append( itemEl )
|
|
|
|
|
247 |
}
|
248 |
-
else {
|
249 |
-
this.$el.children().eq( index - 1 ).after( itemEl );
|
250 |
-
}
|
251 |
-
},
|
252 |
-
|
253 |
-
// Remove item view
|
254 |
-
removeItemView: function ( item ) {
|
255 |
-
this.getItemView( item ).$el.detach();
|
256 |
-
},
|
257 |
-
|
258 |
-
removeItem: function ( item ) {
|
259 |
-
this.collection.remove( item );
|
260 |
},
|
261 |
|
262 |
resetItemViews: function( items ){
|
263 |
var that = this;
|
264 |
-
|
265 |
-
that.removeItemView( item );
|
266 |
-
} );
|
267 |
items.each( function( item ) {
|
268 |
that.addItemView( item );
|
269 |
} );
|
270 |
-
},
|
271 |
-
|
272 |
-
switchItem: function ( item ) {
|
273 |
-
if ( this._switchFrame ) {
|
274 |
-
//this.stopListening( this._frame );
|
275 |
-
this._switchFrame.dispose();
|
276 |
-
}
|
277 |
-
this._switchFrame = new MediaSelect( {
|
278 |
-
className: 'media-frame rwmb-media-frame',
|
279 |
-
multiple: false,
|
280 |
-
title: i18nRwmbMedia.select,
|
281 |
-
editing: true,
|
282 |
-
library: {
|
283 |
-
type: this.controller.get( 'mimeType' )
|
284 |
-
},
|
285 |
-
edit: this.controller.get( 'items' )
|
286 |
-
} );
|
287 |
-
|
288 |
-
this._switchFrame.on( 'select', function () {
|
289 |
-
var selection = this._switchFrame.state().get( 'selection' ),
|
290 |
-
collection = this.collection,
|
291 |
-
index = collection.indexOf( item );
|
292 |
-
|
293 |
-
if ( ! _.isEmpty( selection ) ) {
|
294 |
-
collection.remove( item );
|
295 |
-
collection.add( selection, {at: index} );
|
296 |
-
}
|
297 |
-
}, this );
|
298 |
-
|
299 |
-
this._switchFrame.open();
|
300 |
-
return false;
|
301 |
-
},
|
302 |
-
|
303 |
-
editItem: function ( item ) {
|
304 |
-
// Destroy the previous collection frame.
|
305 |
-
if ( this._editFrame ) {
|
306 |
-
//this.stopListening( this._frame );
|
307 |
-
this._editFrame.dispose();
|
308 |
-
}
|
309 |
-
|
310 |
-
// Trigger the media frame to open the correct item
|
311 |
-
this._editFrame = new EditMedia( {
|
312 |
-
frame: 'edit-attachments',
|
313 |
-
controller: {
|
314 |
-
// Needed to trick Edit modal to think there is a gridRouter
|
315 |
-
gridRouter: {
|
316 |
-
navigate: function ( destination ) {
|
317 |
-
},
|
318 |
-
baseUrl: function ( url ) {
|
319 |
-
}
|
320 |
-
}
|
321 |
-
},
|
322 |
-
library: this.collection,
|
323 |
-
model: item
|
324 |
-
} );
|
325 |
-
|
326 |
-
this._editFrame.open();
|
327 |
}
|
328 |
} );
|
329 |
|
@@ -354,8 +268,7 @@ jQuery( function ( $ ) {
|
|
354 |
},
|
355 |
|
356 |
render: function () {
|
357 |
-
|
358 |
-
this.$el.html( this.template( attributes ) );
|
359 |
}
|
360 |
} );
|
361 |
|
@@ -369,26 +282,22 @@ jQuery( function ( $ ) {
|
|
369 |
template: wp.template( 'rwmb-media-button' ),
|
370 |
events: {
|
371 |
'click .button': function () {
|
372 |
-
// Destroy the previous collection frame.
|
373 |
if ( this._frame ) {
|
374 |
-
//this.stopListening( this._frame );
|
375 |
this._frame.dispose();
|
376 |
}
|
377 |
var maxFiles = this.controller.get( 'maxFiles' );
|
378 |
this._frame = new MediaSelect( {
|
379 |
-
className: 'media-frame rwmb-media-frame',
|
380 |
multiple: maxFiles > 1 || maxFiles <= 0 ? 'add' : false,
|
381 |
-
title: i18nRwmbMedia.select,
|
382 |
editing: true,
|
383 |
library: {
|
384 |
type: this.controller.get( 'mimeType' )
|
385 |
},
|
386 |
-
edit: this.
|
387 |
} );
|
388 |
|
389 |
this._frame.on( 'select', function () {
|
390 |
var selection = this._frame.state().get( 'selection' );
|
391 |
-
this.
|
392 |
}, this );
|
393 |
|
394 |
this._frame.open();
|
@@ -422,36 +331,92 @@ jQuery( function ( $ ) {
|
|
422 |
template: wp.template( 'rwmb-media-item' ),
|
423 |
initialize: function ( options ) {
|
424 |
this.controller = options.controller;
|
|
|
425 |
this.render();
|
426 |
-
this.listenTo( this.model, 'change',
|
427 |
-
|
428 |
-
} );
|
429 |
|
430 |
this.$el.data( 'id', this.model.cid );
|
431 |
},
|
432 |
|
433 |
events: {
|
434 |
-
'click .rwmb-image-overlay':
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
this.
|
442 |
-
return false;
|
443 |
-
},
|
444 |
-
|
445 |
-
'click .rwmb-edit-media': function () {
|
446 |
-
this.trigger( 'click:edit', this.model );
|
447 |
-
return false;
|
448 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
449 |
},
|
450 |
|
451 |
render: function () {
|
452 |
-
var
|
453 |
-
|
454 |
-
this.$el.html( this.template(
|
455 |
return this;
|
456 |
}
|
457 |
} );
|
@@ -486,7 +451,7 @@ jQuery( function ( $ ) {
|
|
486 |
MediaLibrary = media.controller.Library.extend( {
|
487 |
defaults: _.defaults( {
|
488 |
multiple: 'add',
|
489 |
-
filterable: '
|
490 |
priority: 100,
|
491 |
syncSelection: false
|
492 |
}, media.controller.Library.prototype.defaults ),
|
@@ -537,7 +502,6 @@ jQuery( function ( $ ) {
|
|
537 |
new MediaLibrary( {
|
538 |
library: media.query( options.library ),
|
539 |
multiple: options.multiple,
|
540 |
-
title: options.title,
|
541 |
priority: 20
|
542 |
} )
|
543 |
] );
|
28 |
var max = this.controller.get( 'maxFiles' ),
|
29 |
left = max - this.length;
|
30 |
|
31 |
+
if ( ! models || ( max > 0 && left <= 0 ) ) {
|
32 |
return this;
|
33 |
}
|
34 |
+
if ( ! models.hasOwnProperty( 'length' ) ) {
|
35 |
+
models = [models];
|
36 |
+
} else if ( models instanceof media.model.Attachments ) {
|
37 |
+
models = models.models;
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
}
|
39 |
|
40 |
+
models = _.difference( models, this.models );
|
41 |
+
models = _.first( models, left );
|
42 |
|
43 |
+
/**
|
44 |
+
* Make a copy version of models. Do not work directly on models since WordPress might sent some events (like 'remove') to those models.
|
45 |
+
* @see https://metabox.io/support/topic/error-with-image-advanced-in-gutenberg/
|
46 |
+
* @see https://stackoverflow.com/a/5344074/371240
|
47 |
+
*/
|
48 |
+
models = JSON.parse( JSON.stringify( models ) );
|
49 |
+
|
50 |
+
return media.model.Attachments.prototype.add.call( this, models, options );
|
51 |
},
|
52 |
|
53 |
destroyAll: function () {
|
88 |
} );
|
89 |
},
|
90 |
|
|
|
91 |
// Load initial media
|
92 |
load: function () {
|
93 |
if ( _.isEmpty( this.get( 'ids' ) ) ) {
|
202 |
controller: this.controller
|
203 |
} );
|
204 |
|
|
|
|
|
205 |
return itemView;
|
206 |
},
|
207 |
function ( item ) {
|
210 |
);
|
211 |
|
212 |
this.listenTo( this.collection, 'add', this.addItemView );
|
|
|
213 |
this.listenTo( this.collection, 'reset', this.resetItemViews );
|
214 |
|
215 |
// Sort items using helper 'clone' to prevent trigger click on the image, which means reselect.
|
218 |
} );
|
219 |
},
|
220 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
addItemView: function ( item ) {
|
222 |
var index = this.collection.indexOf( item ),
|
223 |
+
itemEl = this.getItemView( item ).el,
|
224 |
+
$children = this.$el.children();
|
225 |
|
226 |
if ( 0 >= index ) {
|
227 |
this.$el.prepend( itemEl );
|
228 |
+
} else if ( $children.length <= index ) {
|
|
|
229 |
this.$el.append( itemEl )
|
230 |
+
} else {
|
231 |
+
$children.eq( index - 1 ).after( itemEl );
|
232 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
233 |
},
|
234 |
|
235 |
resetItemViews: function( items ){
|
236 |
var that = this;
|
237 |
+
this.$el.empty();
|
|
|
|
|
238 |
items.each( function( item ) {
|
239 |
that.addItemView( item );
|
240 |
} );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
241 |
}
|
242 |
} );
|
243 |
|
268 |
},
|
269 |
|
270 |
render: function () {
|
271 |
+
this.$el.html( this.template( this.controller.toJSON() ) );
|
|
|
272 |
}
|
273 |
} );
|
274 |
|
282 |
template: wp.template( 'rwmb-media-button' ),
|
283 |
events: {
|
284 |
'click .button': function () {
|
|
|
285 |
if ( this._frame ) {
|
|
|
286 |
this._frame.dispose();
|
287 |
}
|
288 |
var maxFiles = this.controller.get( 'maxFiles' );
|
289 |
this._frame = new MediaSelect( {
|
|
|
290 |
multiple: maxFiles > 1 || maxFiles <= 0 ? 'add' : false,
|
|
|
291 |
editing: true,
|
292 |
library: {
|
293 |
type: this.controller.get( 'mimeType' )
|
294 |
},
|
295 |
+
edit: this.collection
|
296 |
} );
|
297 |
|
298 |
this._frame.on( 'select', function () {
|
299 |
var selection = this._frame.state().get( 'selection' );
|
300 |
+
this.collection.add( selection.models );
|
301 |
}, this );
|
302 |
|
303 |
this._frame.open();
|
331 |
template: wp.template( 'rwmb-media-item' ),
|
332 |
initialize: function ( options ) {
|
333 |
this.controller = options.controller;
|
334 |
+
this.collection = this.controller.get( 'items' );
|
335 |
this.render();
|
336 |
+
this.listenTo( this.model, 'change', this.render );
|
337 |
+
this.listenTo( this.model, 'remove', this.remove );
|
|
|
338 |
|
339 |
this.$el.data( 'id', this.model.cid );
|
340 |
},
|
341 |
|
342 |
events: {
|
343 |
+
'click .rwmb-image-overlay': 'replace',
|
344 |
+
'click .rwmb-remove-media': 'delete',
|
345 |
+
'click .rwmb-edit-media': 'edit',
|
346 |
+
},
|
347 |
+
|
348 |
+
replace: function() {
|
349 |
+
if ( this._replaceFrame ) {
|
350 |
+
this._replaceFrame.dispose();
|
|
|
|
|
|
|
|
|
|
|
|
|
351 |
}
|
352 |
+
this._replaceFrame = new MediaSelect( {
|
353 |
+
multiple: false,
|
354 |
+
editing: true,
|
355 |
+
library: {
|
356 |
+
type: this.controller.get( 'mimeType' )
|
357 |
+
},
|
358 |
+
edit: this.collection
|
359 |
+
} );
|
360 |
+
|
361 |
+
this._replaceFrame.on( 'select', function () {
|
362 |
+
var selection = this._replaceFrame.state().get( 'selection' );
|
363 |
+
|
364 |
+
if ( _.isEmpty( selection ) ) {
|
365 |
+
return;
|
366 |
+
}
|
367 |
+
|
368 |
+
var index = this.collection.indexOf( this.model );
|
369 |
+
// Remove from collection also triggers 'remove' event for the model, which calls this.remove() to remove the element from DOM.
|
370 |
+
this.collection.remove( this.model );
|
371 |
+
this.collection.add( selection, {at: index} );
|
372 |
+
}, this );
|
373 |
+
|
374 |
+
this._replaceFrame.open();
|
375 |
+
|
376 |
+
return false;
|
377 |
+
},
|
378 |
+
|
379 |
+
edit: function() {
|
380 |
+
if ( this._editFrame ) {
|
381 |
+
this._editFrame.dispose();
|
382 |
+
}
|
383 |
+
|
384 |
+
// Trigger the media frame to open the correct item.
|
385 |
+
this._editFrame = new EditMedia( {
|
386 |
+
frame: 'edit-attachments',
|
387 |
+
controller: {
|
388 |
+
// Needed to trick Edit modal to think there is a gridRouter.
|
389 |
+
gridRouter: {
|
390 |
+
navigate: function ( destination ) {
|
391 |
+
},
|
392 |
+
baseUrl: function ( url ) {
|
393 |
+
}
|
394 |
+
}
|
395 |
+
},
|
396 |
+
library: this.collection,
|
397 |
+
model: this.model
|
398 |
+
} );
|
399 |
+
|
400 |
+
this._editFrame.open();
|
401 |
+
|
402 |
+
return false;
|
403 |
+
},
|
404 |
+
|
405 |
+
delete: function() {
|
406 |
+
// Remove from collection also triggers 'remove' event for the model, which calls this.remove() to remove the element from DOM.
|
407 |
+
this.collection.remove( this.model );
|
408 |
+
|
409 |
+
if ( true === this.controller.get( 'forceDelete' ) ) {
|
410 |
+
this.model.destroy();
|
411 |
+
}
|
412 |
+
|
413 |
+
return false;
|
414 |
},
|
415 |
|
416 |
render: function () {
|
417 |
+
var data = this.model.toJSON();
|
418 |
+
data.controller = this.controller.toJSON();
|
419 |
+
this.$el.html( this.template( data ) );
|
420 |
return this;
|
421 |
}
|
422 |
} );
|
451 |
MediaLibrary = media.controller.Library.extend( {
|
452 |
defaults: _.defaults( {
|
453 |
multiple: 'add',
|
454 |
+
filterable: 'all',
|
455 |
priority: 100,
|
456 |
syncSelection: false
|
457 |
}, media.controller.Library.prototype.defaults ),
|
502 |
new MediaLibrary( {
|
503 |
library: media.query( options.library ),
|
504 |
multiple: options.multiple,
|
|
|
505 |
priority: 20
|
506 |
} )
|
507 |
] );
|
js/slider.js
CHANGED
@@ -9,18 +9,13 @@ jQuery( function ( $ ) {
|
|
9 |
options = $slider.data( 'options' );
|
10 |
|
11 |
$slider.html( '' );
|
12 |
-
|
13 |
-
if ( ! value ) {
|
14 |
-
value = 0;
|
15 |
-
}
|
16 |
-
$input.val( value );
|
17 |
$valueLabel.text( value );
|
18 |
|
19 |
-
value
|
20 |
options.values = value;
|
21 |
|
22 |
options.slide = function ( event, ui ) {
|
23 |
-
if ( options.range
|
24 |
$input.val( ui.values[ 0 ] + '|' + ui.values[ 1 ] );
|
25 |
$valueLabel.html( ui.values[ 0 ] + '|' + ui.values[ 1 ] );
|
26 |
} else {
|
9 |
options = $slider.data( 'options' );
|
10 |
|
11 |
$slider.html( '' );
|
|
|
|
|
|
|
|
|
|
|
12 |
$valueLabel.text( value );
|
13 |
|
14 |
+
value = options.range === true ? value.split( '|' ) : value;
|
15 |
options.values = value;
|
16 |
|
17 |
options.slide = function ( event, ui ) {
|
18 |
+
if ( options.range === true ) {
|
19 |
$input.val( ui.values[ 0 ] + '|' + ui.values[ 1 ] );
|
20 |
$valueLabel.html( ui.values[ 0 ] + '|' + ui.values[ 1 ] );
|
21 |
} else {
|
meta-box.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: Meta Box
|
4 |
* Plugin URI: https://metabox.io
|
5 |
* Description: Create custom meta boxes and custom fields in WordPress.
|
6 |
-
* Version: 4.17.
|
7 |
* Author: MetaBox.io
|
8 |
* Author URI: https://metabox.io
|
9 |
* License: GPL2+
|
3 |
* Plugin Name: Meta Box
|
4 |
* Plugin URI: https://metabox.io
|
5 |
* Description: Create custom meta boxes and custom fields in WordPress.
|
6 |
+
* Version: 4.17.1
|
7 |
* Author: MetaBox.io
|
8 |
* Author URI: https://metabox.io
|
9 |
* License: GPL2+
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: metabox, rilwis, fitwp, f-j-kaiser, funkatronic, PerWiklander, rua
|
|
3 |
Donate link: https://metabox.io/pricing/
|
4 |
Tags: meta-box, custom fields, custom field, meta, meta-boxes, admin, advanced, custom, edit, field, file, image, magic fields, matrix, more fields, Post, repeater, simple fields, text, textarea, type, cms, fields post
|
5 |
Requires at least: 4.3
|
6 |
-
Tested up to: 5.1
|
7 |
-
Stable tag: 4.17.
|
8 |
License: GPLv2 or later
|
9 |
|
10 |
Meta Box plugin is a powerful, professional developer toolkit to create custom meta boxes and custom fields for WordPress.
|
@@ -165,28 +165,17 @@ To getting started with the plugin, please read the [Quick Start Guide](https://
|
|
165 |
|
166 |
== Changelog ==
|
167 |
|
168 |
-
= 4.17.
|
169 |
|
170 |
-
**
|
171 |
|
172 |
-
-
|
173 |
-
-
|
174 |
-
- Added `prepend` and `append` attributes for inputs like Bootstrap's input group.
|
175 |
|
176 |
**Changed**
|
177 |
|
178 |
-
-
|
179 |
-
- Changed shortcode attributes to use `id` (instead of `meta_key`), `object_id` (instead of `post_id`).
|
180 |
-
|
181 |
-
**Fixed**
|
182 |
-
|
183 |
-
- Fixed empty date field with save_format causes error.
|
184 |
-
- Fixed wrong position of the asterisk when the field is required and has label description.
|
185 |
-
- Fixed indirect modification of `meta_box->$fields`.
|
186 |
-
- Fixed `required` attribute not working for `file`, `image` fields.
|
187 |
-
- Fixed warning in the about page.
|
188 |
-
- Fixed box-sizing issue for settings page.
|
189 |
|
190 |
-
[See full changelog here](https://
|
191 |
|
192 |
== Upgrade Notice ==
|
3 |
Donate link: https://metabox.io/pricing/
|
4 |
Tags: meta-box, custom fields, custom field, meta, meta-boxes, admin, advanced, custom, edit, field, file, image, magic fields, matrix, more fields, Post, repeater, simple fields, text, textarea, type, cms, fields post
|
5 |
Requires at least: 4.3
|
6 |
+
Tested up to: 5.1.1
|
7 |
+
Stable tag: 4.17.1
|
8 |
License: GPLv2 or later
|
9 |
|
10 |
Meta Box plugin is a powerful, professional developer toolkit to create custom meta boxes and custom fields for WordPress.
|
165 |
|
166 |
== Changelog ==
|
167 |
|
168 |
+
= 4.17.1 - 2019-04-01 =
|
169 |
|
170 |
+
**Fixed**
|
171 |
|
172 |
+
- Fixed JavaScript error for `slider` field when creating a new post.
|
173 |
+
- Fixed images of the `image_advanced` cleared when changing image the post content in Gutenberg.
|
|
|
174 |
|
175 |
**Changed**
|
176 |
|
177 |
+
- `text_list`: Do not save if all inputs has no value.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
|
179 |
+
[See full changelog here](https://metabox.io/changelog/).
|
180 |
|
181 |
== Upgrade Notice ==
|