Meta Box - Version 4.17.3

Version Description

  • 2019-04-09 =

Fixed

  • Fixed image_upload, file_upload field not working.

See full changelog here.

=

Download this release

Release Info

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

Code changes from version 4.17.2 to 4.17.3

Files changed (4) hide show
  1. inc/loader.php +1 -1
  2. js/media.js +96 -81
  3. meta-box.php +1 -1
  4. readme.txt +3 -4
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.2' );
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.3' );
22
 
23
  list( $path, $url ) = self::get_path( dirname( dirname( __FILE__ ) ) );
24
 
js/media.js CHANGED
@@ -42,16 +42,19 @@ jQuery( function ( $ ) {
42
  models = _.first( models, left );
43
  }
44
 
45
- /**
46
- * Make a copy version of models. Do not work directly on models since WordPress might sent some events (like 'remove') to those models.
47
- * @see https://metabox.io/support/topic/error-with-image-advanced-in-gutenberg/
48
- * @see https://stackoverflow.com/a/5344074/371240
49
- */
50
- models = JSON.parse( JSON.stringify( models ) );
51
-
52
  return media.model.Attachments.prototype.add.call( this, models, options );
53
  },
54
 
 
 
 
 
 
 
 
 
 
 
55
  destroyAll: function () {
56
  _.each( _.clone( this.models ), function ( model ) {
57
  model.destroy();
@@ -90,6 +93,7 @@ jQuery( function ( $ ) {
90
  } );
91
  },
92
 
 
93
  // Load initial media
94
  load: function () {
95
  if ( _.isEmpty( this.get( 'ids' ) ) ) {
@@ -204,6 +208,8 @@ jQuery( function ( $ ) {
204
  controller: this.controller
205
  } );
206
 
 
 
207
  return itemView;
208
  },
209
  function ( item ) {
@@ -212,6 +218,7 @@ jQuery( function ( $ ) {
212
  );
213
 
214
  this.listenTo( this.collection, 'add', this.addItemView );
 
215
  this.listenTo( this.collection, 'reset', this.resetItemViews );
216
 
217
  // Sort items using helper 'clone' to prevent trigger click on the image, which means reselect.
@@ -220,6 +227,12 @@ jQuery( function ( $ ) {
220
  } );
221
  },
222
 
 
 
 
 
 
 
223
  addItemView: function ( item ) {
224
  var index = this.collection.indexOf( item ),
225
  itemEl = this.getItemView( item ).el,
@@ -234,12 +247,71 @@ jQuery( function ( $ ) {
234
  }
235
  },
236
 
 
 
 
 
 
 
 
 
 
237
  resetItemViews: function( items ){
238
  var that = this;
239
- this.$el.empty();
240
- items.each( function( item ) {
241
- that.addItemView( item );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  } );
 
 
243
  }
244
  } );
245
 
@@ -336,83 +408,26 @@ jQuery( function ( $ ) {
336
  this.collection = this.controller.get( 'items' );
337
  this.render();
338
  this.listenTo( this.model, 'change', this.render );
339
- this.listenTo( this.model, 'remove', this.remove );
340
 
341
  this.$el.data( 'id', this.model.cid );
342
  },
343
 
344
  events: {
345
- 'click .rwmb-image-overlay': 'replace',
346
- 'click .rwmb-remove-media': 'delete',
347
- 'click .rwmb-edit-media': 'edit',
348
- },
349
-
350
- replace: function() {
351
- if ( this._replaceFrame ) {
352
- this._replaceFrame.dispose();
353
- }
354
- this._replaceFrame = new MediaSelect( {
355
- multiple: false,
356
- editing: true,
357
- library: {
358
- type: this.controller.get( 'mimeType' )
359
- },
360
- edit: this.collection
361
- } );
362
-
363
- this._replaceFrame.on( 'select', function () {
364
- var selection = this._replaceFrame.state().get( 'selection' );
365
-
366
- if ( _.isEmpty( selection ) ) {
367
- return;
368
- }
369
-
370
- var index = this.collection.indexOf( this.model );
371
- // Remove from collection also triggers 'remove' event for the model, which calls this.remove() to remove the element from DOM.
372
- this.collection.remove( this.model );
373
- this.collection.add( selection, {at: index} );
374
- }, this );
375
-
376
- this._replaceFrame.open();
377
-
378
- return false;
379
- },
380
-
381
- edit: function() {
382
- if ( this._editFrame ) {
383
- this._editFrame.dispose();
384
- }
385
-
386
- // Trigger the media frame to open the correct item.
387
- this._editFrame = new EditMedia( {
388
- frame: 'edit-attachments',
389
- controller: {
390
- // Needed to trick Edit modal to think there is a gridRouter.
391
- gridRouter: {
392
- navigate: function ( destination ) {
393
- },
394
- baseUrl: function ( url ) {
395
- }
396
- }
397
- },
398
- library: this.collection,
399
- model: this.model
400
- } );
401
-
402
- this._editFrame.open();
403
-
404
- return false;
405
- },
406
-
407
- delete: function() {
408
- // Remove from collection also triggers 'remove' event for the model, which calls this.remove() to remove the element from DOM.
409
- this.collection.remove( this.model );
410
-
411
- if ( true === this.controller.get( 'forceDelete' ) ) {
412
- this.model.destroy();
413
  }
414
-
415
- return false;
416
  },
417
 
418
  render: function () {
42
  models = _.first( models, left );
43
  }
44
 
 
 
 
 
 
 
 
45
  return media.model.Attachments.prototype.add.call( this, models, options );
46
  },
47
 
48
+ remove: function ( models, options ) {
49
+ models = media.model.Attachments.prototype.remove.call( this, models, options );
50
+ if ( this.controller.get( 'forceDelete' ) === true ) {
51
+ models = ! _.isArray( models ) ? [models] : models;
52
+ _.each( models, function ( model ) {
53
+ model.destroy();
54
+ } );
55
+ }
56
+ },
57
+
58
  destroyAll: function () {
59
  _.each( _.clone( this.models ), function ( model ) {
60
  model.destroy();
93
  } );
94
  },
95
 
96
+
97
  // Load initial media
98
  load: function () {
99
  if ( _.isEmpty( this.get( 'ids' ) ) ) {
208
  controller: this.controller
209
  } );
210
 
211
+ this.listenToItemView( itemView );
212
+
213
  return itemView;
214
  },
215
  function ( item ) {
218
  );
219
 
220
  this.listenTo( this.collection, 'add', this.addItemView );
221
+ this.listenTo( this.collection, 'remove', this.removeItemView );
222
  this.listenTo( this.collection, 'reset', this.resetItemViews );
223
 
224
  // Sort items using helper 'clone' to prevent trigger click on the image, which means reselect.
227
  } );
228
  },
229
 
230
+ listenToItemView: function ( itemView ) {
231
+ this.listenTo( itemView, 'click:remove', this.removeItem );
232
+ this.listenTo( itemView, 'click:switch', this.switchItem );
233
+ this.listenTo( itemView, 'click:edit', this.editItem );
234
+ },
235
+
236
  addItemView: function ( item ) {
237
  var index = this.collection.indexOf( item ),
238
  itemEl = this.getItemView( item ).el,
247
  }
248
  },
249
 
250
+ // Remove item view
251
+ removeItemView: function ( item ) {
252
+ this.getItemView( item ).$el.detach();
253
+ },
254
+
255
+ removeItem: function ( item ) {
256
+ this.collection.remove( item );
257
+ },
258
+
259
  resetItemViews: function( items ){
260
  var that = this;
261
+ _.each( that.models, that.removeItemView );
262
+ items.each( that.addItemView );
263
+ },
264
+
265
+ switchItem: function ( item ) {
266
+ if ( this._switchFrame ) {
267
+ this._switchFrame.dispose();
268
+ }
269
+ this._switchFrame = new MediaSelect( {
270
+ multiple: false,
271
+ editing: true,
272
+ library: {
273
+ type: this.controller.get( 'mimeType' )
274
+ },
275
+ edit: this.collection
276
+ } );
277
+
278
+ this._switchFrame.on( 'select', function () {
279
+ var selection = this._switchFrame.state().get( 'selection' ),
280
+ collection = this.collection,
281
+ index = collection.indexOf( item );
282
+
283
+ if ( ! _.isEmpty( selection ) ) {
284
+ collection.remove( item );
285
+ collection.add( selection, {at: index} );
286
+ }
287
+ }, this );
288
+
289
+ this._switchFrame.open();
290
+ return false;
291
+ },
292
+
293
+ editItem: function ( item ) {
294
+ if ( this._editFrame ) {
295
+ this._editFrame.dispose();
296
+ }
297
+
298
+ // Trigger the media frame to open the correct item.
299
+ this._editFrame = new EditMedia( {
300
+ frame: 'edit-attachments',
301
+ controller: {
302
+ // Needed to trick Edit modal to think there is a gridRouter.
303
+ gridRouter: {
304
+ navigate: function ( destination ) {
305
+ },
306
+ baseUrl: function ( url ) {
307
+ }
308
+ }
309
+ },
310
+ library: this.collection,
311
+ model: item
312
  } );
313
+
314
+ this._editFrame.open();
315
  }
316
  } );
317
 
408
  this.collection = this.controller.get( 'items' );
409
  this.render();
410
  this.listenTo( this.model, 'change', this.render );
 
411
 
412
  this.$el.data( 'id', this.model.cid );
413
  },
414
 
415
  events: {
416
+ 'click .rwmb-image-overlay': function () {
417
+ this.trigger( 'click:switch', this.model );
418
+ return false;
419
+ },
420
+
421
+ // Event when remove button clicked
422
+ 'click .rwmb-remove-media': function () {
423
+ this.trigger( 'click:remove', this.model );
424
+ return false;
425
+ },
426
+
427
+ 'click .rwmb-edit-media': function () {
428
+ this.trigger( 'click:edit', this.model );
429
+ return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
430
  }
 
 
431
  },
432
 
433
  render: function () {
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.2
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.3
7
  * Author: MetaBox.io
8
  * Author URI: https://metabox.io
9
  * License: GPL2+
readme.txt CHANGED
@@ -4,7 +4,7 @@ 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.2
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,12 +165,11 @@ To getting started with the plugin, please read the [Quick Start Guide](https://
165
 
166
  == Changelog ==
167
 
168
- = 4.17.1 - 2019-04-02 =
169
 
170
  **Fixed**
171
 
172
- - Fixed `required` attribute for `file` prevents updating posts when the field already has value.
173
- - Fixed couldn't add images if `max_file_uploads` is not set (`image_advanced`).
174
 
175
  [See full changelog here](https://metabox.io/changelog/).
176
 
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.3
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.3 - 2019-04-09 =
169
 
170
  **Fixed**
171
 
172
+ - Fixed image_upload, file_upload field not working.
 
173
 
174
  [See full changelog here](https://metabox.io/changelog/).
175