Meta Box - Version 4.17.2

Version Description

Download this release

Release Info

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

Code changes from version 4.17.1 to 4.17.2

Files changed (7) hide show
  1. inc/fields/file.php +10 -0
  2. inc/fields/image.php +0 -1
  3. inc/loader.php +1 -1
  4. js/file.js +25 -1
  5. js/media.js +3 -1
  6. meta-box.php +1 -1
  7. readme.txt +4 -8
inc/fields/file.php CHANGED
@@ -94,6 +94,16 @@ class RWMB_File_Field extends RWMB_Field {
94
  $attributes['name'] = "{$field['file_input_name']}[]";
95
  $attributes['class'] = 'rwmb-file-input';
96
 
 
 
 
 
 
 
 
 
 
 
97
  $html .= sprintf(
98
  '<div class="rwmb-file-new">
99
  <input %s>
94
  $attributes['name'] = "{$field['file_input_name']}[]";
95
  $attributes['class'] = 'rwmb-file-input';
96
 
97
+ /*
98
+ * Use JavaScript to toggle 'required' attribute, because:
99
+ * - Field might already have value (uploaded files).
100
+ * - Be able to detect when uploading multiple files.
101
+ */
102
+ if ( $attributes['required'] ) {
103
+ $attributes['data-required'] = 1;
104
+ $attributes['required'] = false;
105
+ }
106
+
107
  $html .= sprintf(
108
  '<div class="rwmb-file-new">
109
  <input %s>
inc/fields/image.php CHANGED
@@ -56,7 +56,6 @@ class RWMB_Image_Field extends RWMB_File_Field {
56
  );
57
  }
58
 
59
-
60
  /**
61
  * Normalize field settings.
62
  *
56
  );
57
  }
58
 
 
59
  /**
60
  * Normalize field settings.
61
  *
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.1' );
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.2' );
22
 
23
  list( $path, $url ) = self::get_path( dirname( dirname( __FILE__ ) ) );
24
 
js/file.js CHANGED
@@ -17,7 +17,10 @@
17
  $clone = $this.prev().clone();
18
 
19
  $clone.insertBefore( this ).val( '' );
20
- file.updateVisibility.call( $this.closest( '.rwmb-input' ).find( '.rwmb-uploaded' )[0] );
 
 
 
21
  };
22
 
23
  /**
@@ -37,6 +40,8 @@
37
  $item.remove();
38
  file.updateVisibility.call( $uploaded );
39
 
 
 
40
  if ( 1 > $uploaded.data( 'force_delete' ) ) {
41
  return;
42
  }
@@ -97,6 +102,23 @@
97
  $clone.find( '.rwmb-file-input' ).not( ':first' ).remove();
98
  };
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  // Initialize when document ready.
101
  $( function ( $ ) {
102
  $( document )
@@ -107,5 +129,7 @@
107
  var $uploaded = $( '.rwmb-uploaded' );
108
  $uploaded.each( file.sort );
109
  $uploaded.each( file.updateVisibility );
 
 
110
  } );
111
  } )( jQuery, document );
17
  $clone = $this.prev().clone();
18
 
19
  $clone.insertBefore( this ).val( '' );
20
+
21
+ var $fieldInput = $this.closest( '.rwmb-input' );
22
+ file.updateVisibility.call( $fieldInput.find( '.rwmb-uploaded' ) );
23
+ file.setRequired.call( $fieldInput );
24
  };
25
 
26
  /**
40
  $item.remove();
41
  file.updateVisibility.call( $uploaded );
42
 
43
+ file.setRequired.call( $uploaded.parent() );
44
+
45
  if ( 1 > $uploaded.data( 'force_delete' ) ) {
46
  return;
47
  }
102
  $clone.find( '.rwmb-file-input' ).not( ':first' ).remove();
103
  };
104
 
105
+ // Set 'required' attribute. 'this' is the wrapper field input.
106
+ file.setRequired = function() {
107
+ var $this = $( this ),
108
+ $uploaded = $this.find( '.rwmb-uploaded' ),
109
+ $inputs = $this.find( '.rwmb-file-new input' );
110
+ $inputs.prop( 'required', false );
111
+
112
+ if ( $uploaded.children().length ) {
113
+ return;
114
+ }
115
+
116
+ var $firstInput = $inputs.first();
117
+ if ( 1 === $firstInput.data( 'required' ) ) {
118
+ $firstInput.prop( 'required', true );
119
+ }
120
+ };
121
+
122
  // Initialize when document ready.
123
  $( function ( $ ) {
124
  $( document )
129
  var $uploaded = $( '.rwmb-uploaded' );
130
  $uploaded.each( file.sort );
131
  $uploaded.each( file.updateVisibility );
132
+
133
+ $( '.rwmb-file-wrapper' ).each( file.setRequired );
134
  } );
135
  } )( jQuery, document );
js/media.js CHANGED
@@ -38,7 +38,9 @@ jQuery( function ( $ ) {
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.
38
  }
39
 
40
  models = _.difference( models, this.models );
41
+ if ( left > 0 ) {
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.
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.1
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.2
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.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,16 +165,12 @@ To getting started with the plugin, please read the [Quick Start Guide](https://
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
 
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
 
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