Version Description
- 2020-04-17 =
- Fix cloning default value not working for some fields.
Download this release
Release Info
Developer | rilwis |
Plugin | Meta Box |
Version | 5.2.9 |
Comparing to | |
See all releases |
Code changes from version 5.2.8 to 5.2.9
- css/slider.css +2 -2
- inc/field.php +20 -20
- inc/fields/slider.php +6 -5
- inc/helpers/array.php +9 -0
- inc/loader.php +1 -1
- js/button-group.js +1 -1
- js/clone.js +35 -45
- js/slider.js +9 -9
- meta-box.php +1 -1
- readme.txt +4 -1
css/slider.css
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
-
.rwmb-slider {
|
2 |
display: inline-block;
|
3 |
vertical-align: middle;
|
4 |
width: 50%;
|
5 |
}
|
6 |
-
.rwmb-slider-
|
7 |
margin-left: 10px;
|
8 |
vertical-align: middle;
|
9 |
}
|
1 |
+
.rwmb-slider-ui {
|
2 |
display: inline-block;
|
3 |
vertical-align: middle;
|
4 |
width: 50%;
|
5 |
}
|
6 |
+
.rwmb-slider-label {
|
7 |
margin-left: 10px;
|
8 |
vertical-align: middle;
|
9 |
}
|
inc/field.php
CHANGED
@@ -182,7 +182,9 @@ abstract class RWMB_Field {
|
|
182 |
$args['single'] = false;
|
183 |
}
|
184 |
|
185 |
-
|
|
|
|
|
186 |
}
|
187 |
|
188 |
/**
|
@@ -209,30 +211,28 @@ abstract class RWMB_Field {
|
|
209 |
// Use $field['std'] only when the meta box hasn't been saved (i.e. the first time we run).
|
210 |
$meta = ! $saved || ! $field['save_field'] ? $field['std'] : $meta;
|
211 |
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
}
|
219 |
}
|
220 |
-
}
|
221 |
-
// Escape attributes.
|
222 |
-
$meta = self::call( $field, 'esc_meta', $meta );
|
223 |
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
* @see self::show()
|
231 |
-
*/
|
232 |
-
$meta = $field['clone'] ? array( '' ) : array();
|
233 |
}
|
|
|
|
|
234 |
}
|
235 |
|
|
|
|
|
|
|
236 |
return $meta;
|
237 |
}
|
238 |
|
182 |
$args['single'] = false;
|
183 |
}
|
184 |
|
185 |
+
$value = $storage->get( $object_id, $field['id'], $args );
|
186 |
+
$value = self::filter( 'raw_meta', $value, $field, $object_id, $args );
|
187 |
+
return $value;
|
188 |
}
|
189 |
|
190 |
/**
|
211 |
// Use $field['std'] only when the meta box hasn't been saved (i.e. the first time we run).
|
212 |
$meta = ! $saved || ! $field['save_field'] ? $field['std'] : $meta;
|
213 |
|
214 |
+
if ( $field['clone'] ) {
|
215 |
+
$meta = RWMB_Helpers_Array::ensure( $meta );
|
216 |
+
|
217 |
+
// Ensure $meta is an array with values so that the foreach loop in self::show() runs properly.
|
218 |
+
if ( empty( $meta ) ) {
|
219 |
+
$meta = array( '' );
|
|
|
220 |
}
|
|
|
|
|
|
|
221 |
|
222 |
+
if ( $field['multiple'] ) {
|
223 |
+
$first = reset( $meta );
|
224 |
+
|
225 |
+
// If users set std for a cloneable checkbox list field in the Builder, they can only set [value1, value2]. We need to transform it to [[value1, value2]].
|
226 |
+
// In other cases, make sure each value is an array.
|
227 |
+
$meta = is_array( $first ) ? array_walk( $meta, 'RWMB_Helpers_Array::ensure' ) : array( $meta );
|
|
|
|
|
|
|
228 |
}
|
229 |
+
} elseif ( $field['multiple'] ) {
|
230 |
+
$meta = RWMB_Helpers_Array::ensure( $meta );
|
231 |
}
|
232 |
|
233 |
+
// Escape attributes.
|
234 |
+
$meta = self::call( $field, 'esc_meta', $meta );
|
235 |
+
|
236 |
return $meta;
|
237 |
}
|
238 |
|
inc/fields/slider.php
CHANGED
@@ -31,19 +31,20 @@ class RWMB_Slider_Field extends RWMB_Field {
|
|
31 |
* @return string
|
32 |
*/
|
33 |
public static function html( $meta, $field ) {
|
|
|
34 |
return sprintf(
|
35 |
'<div class="clearfix">
|
36 |
-
<div class="rwmb-slider" id="%s" data-options="%s"></div>
|
37 |
-
<span class="rwmb-slider-
|
38 |
-
<input type="hidden"
|
39 |
</div>',
|
40 |
$field['id'],
|
41 |
esc_attr( wp_json_encode( $field['js_options'] ) ),
|
42 |
$field['prefix'],
|
43 |
$meta,
|
44 |
$field['suffix'],
|
45 |
-
$
|
46 |
-
$
|
47 |
);
|
48 |
}
|
49 |
|
31 |
* @return string
|
32 |
*/
|
33 |
public static function html( $meta, $field ) {
|
34 |
+
$attributes = self::call( 'get_attributes', $field, $meta );
|
35 |
return sprintf(
|
36 |
'<div class="clearfix">
|
37 |
+
<div class="rwmb-slider-ui" id="%s" data-options="%s"></div>
|
38 |
+
<span class="rwmb-slider-label">%s<span>%s</span>%s</span>
|
39 |
+
<input type="hidden" value="%s" %s>
|
40 |
</div>',
|
41 |
$field['id'],
|
42 |
esc_attr( wp_json_encode( $field['js_options'] ) ),
|
43 |
$field['prefix'],
|
44 |
$meta,
|
45 |
$field['suffix'],
|
46 |
+
$meta,
|
47 |
+
self::render_attributes( $attributes )
|
48 |
);
|
49 |
}
|
50 |
|
inc/helpers/array.php
CHANGED
@@ -78,4 +78,13 @@ class RWMB_Helpers_Array {
|
|
78 |
);
|
79 |
return $return;
|
80 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
}
|
78 |
);
|
79 |
return $return;
|
80 |
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Ensure a variable is an array.
|
84 |
+
* @param mixed $input Input value.
|
85 |
+
* @return array
|
86 |
+
*/
|
87 |
+
public static function ensure( $input ) {
|
88 |
+
return (array) $input;
|
89 |
+
}
|
90 |
}
|
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', '5.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', '5.2.9' );
|
22 |
|
23 |
list( $path, $url ) = self::get_path( dirname( dirname( __FILE__ ) ) );
|
24 |
|
js/button-group.js
CHANGED
@@ -38,5 +38,5 @@
|
|
38 |
rwmb.$document
|
39 |
.on( 'mb_ready', init )
|
40 |
.on( 'click', '.rwmb-button-input-list li', clickHandler )
|
41 |
-
.on( 'clone', '.rwmb-button-input-list', setActiveClass );
|
42 |
} )( jQuery, rwmb );
|
38 |
rwmb.$document
|
39 |
.on( 'mb_ready', init )
|
40 |
.on( 'click', '.rwmb-button-input-list li', clickHandler )
|
41 |
+
.on( 'clone', '.rwmb-button-input-list li', setActiveClass );
|
42 |
} )( jQuery, rwmb );
|
js/clone.js
CHANGED
@@ -26,13 +26,6 @@
|
|
26 |
|
27 |
$field.trigger( 'update_index', index );
|
28 |
} );
|
29 |
-
|
30 |
-
// Address button's value attribute
|
31 |
-
var $address = $inputs.filter( '.rwmb-map-goto-address-button' );
|
32 |
-
if ( $address.length ) {
|
33 |
-
var value = $address.attr( 'value' );
|
34 |
-
$address.attr( 'value', cloneIndex.replace( index, value, '_' ) );
|
35 |
-
}
|
36 |
},
|
37 |
|
38 |
/**
|
@@ -85,45 +78,39 @@
|
|
85 |
|
86 |
// Object holds all method related to fields' value when clone.
|
87 |
var cloneValue = {
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
cloneValue.type = cloneValue.$field.attr( 'type' );
|
94 |
-
cloneValue.isHiddenField = cloneValue.$field.hasClass( 'rwmb-hidden' );
|
95 |
-
|
96 |
-
if ( true === cloneValue.$field.data( 'clone-default' ) ) {
|
97 |
-
cloneValue.resetToDefault();
|
98 |
-
} else {
|
99 |
-
cloneValue.clear();
|
100 |
}
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
if ( '
|
108 |
-
|
109 |
-
} else if ( '
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
|
|
115 |
}
|
116 |
},
|
117 |
-
/**
|
118 |
-
* Clear field value.
|
119 |
-
*/
|
120 |
clear: function() {
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
|
|
|
|
|
|
127 |
}
|
128 |
}
|
129 |
};
|
@@ -137,11 +124,11 @@
|
|
137 |
$clone = $last.clone(),
|
138 |
nextIndex = cloneIndex.nextIndex( $container );
|
139 |
|
140 |
-
//
|
141 |
var $inputs = $clone.find( rwmb.inputSelectors );
|
142 |
-
$inputs.each( cloneValue.
|
143 |
|
144 |
-
// Insert
|
145 |
$clone.insertAfter( $last );
|
146 |
|
147 |
// Trigger custom event for the clone instance. Required for Group extension to update sub fields.
|
@@ -150,6 +137,9 @@
|
|
150 |
// Set fields index. Must run before trigger clone event.
|
151 |
cloneIndex.set( $inputs, nextIndex );
|
152 |
|
|
|
|
|
|
|
153 |
// Trigger custom clone event.
|
154 |
$inputs.trigger( 'clone', nextIndex );
|
155 |
|
26 |
|
27 |
$field.trigger( 'update_index', index );
|
28 |
} );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
},
|
30 |
|
31 |
/**
|
78 |
|
79 |
// Object holds all method related to fields' value when clone.
|
80 |
var cloneValue = {
|
81 |
+
setDefault: function() {
|
82 |
+
var $field = $( this );
|
83 |
+
|
84 |
+
if ( true !== $field.data( 'clone-default' ) ) {
|
85 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
}
|
87 |
+
|
88 |
+
var type = $field.attr( 'type' ),
|
89 |
+
defaultValue = $field.data( 'default' );
|
90 |
+
|
91 |
+
if ( 'radio' === type ) {
|
92 |
+
$field.prop( 'checked', $field.val() === defaultValue );
|
93 |
+
} else if ( $field.hasClass( 'rwmb-checkbox' ) ) {
|
94 |
+
$field.prop( 'checked', !! defaultValue );
|
95 |
+
} else if ( $field.hasClass( 'rwmb-checkbox_list' ) ) {
|
96 |
+
var value = $field.val();
|
97 |
+
$field.prop( 'checked', Array.isArray( defaultValue ) ? -1 !== defaultValue.indexOf( value ) : value == defaultValue );
|
98 |
+
} else if ( 'select' === type ) {
|
99 |
+
$field.find( 'option[value="' + defaultValue + '"]' ).prop( 'selected', true );
|
100 |
+
} else if ( ! $field.hasClass( 'rwmb-hidden' ) ) {
|
101 |
+
$field.val( defaultValue );
|
102 |
}
|
103 |
},
|
|
|
|
|
|
|
104 |
clear: function() {
|
105 |
+
var $field = $( this ),
|
106 |
+
type = $field.attr( 'type' );
|
107 |
+
|
108 |
+
if ( 'radio' === type || 'checkbox' === type ) {
|
109 |
+
$field.prop( 'checked', false );
|
110 |
+
} else if ( 'select' === type ) {
|
111 |
+
$field.prop( 'selectedIndex', - 1 );
|
112 |
+
} else if ( ! $field.hasClass( 'rwmb-hidden' ) ) {
|
113 |
+
$field.val( '' );
|
114 |
}
|
115 |
}
|
116 |
};
|
124 |
$clone = $last.clone(),
|
125 |
nextIndex = cloneIndex.nextIndex( $container );
|
126 |
|
127 |
+
// Clear fields' values.
|
128 |
var $inputs = $clone.find( rwmb.inputSelectors );
|
129 |
+
$inputs.each( cloneValue.clear );
|
130 |
|
131 |
+
// Insert clone.
|
132 |
$clone.insertAfter( $last );
|
133 |
|
134 |
// Trigger custom event for the clone instance. Required for Group extension to update sub fields.
|
137 |
// Set fields index. Must run before trigger clone event.
|
138 |
cloneIndex.set( $inputs, nextIndex );
|
139 |
|
140 |
+
// Set fields' default values: do after index is set to prevent previous radio fields from unchecking.
|
141 |
+
$inputs.each( cloneValue.setDefault );
|
142 |
+
|
143 |
// Trigger custom clone event.
|
144 |
$inputs.trigger( 'clone', nextIndex );
|
145 |
|
js/slider.js
CHANGED
@@ -2,14 +2,14 @@
|
|
2 |
'use strict';
|
3 |
|
4 |
function transform() {
|
5 |
-
var $input
|
6 |
-
$slider
|
7 |
-
$
|
8 |
-
value
|
9 |
-
options
|
10 |
|
11 |
$slider.html( '' );
|
12 |
-
$
|
13 |
|
14 |
if ( true === options.range ) {
|
15 |
value = value.split( '|' );
|
@@ -25,17 +25,17 @@
|
|
25 |
}
|
26 |
|
27 |
$input.val( value ).trigger( 'change' );
|
28 |
-
$
|
29 |
};
|
30 |
|
31 |
$slider.slider( options );
|
32 |
}
|
33 |
|
34 |
function init( e ) {
|
35 |
-
$( e.target ).find( '.rwmb-slider
|
36 |
}
|
37 |
|
38 |
rwmb.$document
|
39 |
.on( 'mb_ready', init )
|
40 |
-
.on( 'clone', '.rwmb-slider
|
41 |
} )( jQuery, rwmb );
|
2 |
'use strict';
|
3 |
|
4 |
function transform() {
|
5 |
+
var $input = $( this ),
|
6 |
+
$slider = $input.siblings( '.rwmb-slider-ui' ),
|
7 |
+
$label = $slider.siblings( '.rwmb-slider-label' ).find( 'span' ),
|
8 |
+
value = $input.val(),
|
9 |
+
options = $slider.data( 'options' );
|
10 |
|
11 |
$slider.html( '' );
|
12 |
+
$label.text( value );
|
13 |
|
14 |
if ( true === options.range ) {
|
15 |
value = value.split( '|' );
|
25 |
}
|
26 |
|
27 |
$input.val( value ).trigger( 'change' );
|
28 |
+
$label.html( value );
|
29 |
};
|
30 |
|
31 |
$slider.slider( options );
|
32 |
}
|
33 |
|
34 |
function init( e ) {
|
35 |
+
$( e.target ).find( '.rwmb-slider' ).each( transform );
|
36 |
}
|
37 |
|
38 |
rwmb.$document
|
39 |
.on( 'mb_ready', init )
|
40 |
+
.on( 'clone', '.rwmb-slider', transform );
|
41 |
} )( jQuery, rwmb );
|
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: 5.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: 5.2.9
|
7 |
* Author: MetaBox.io
|
8 |
* Author URI: https://metabox.io
|
9 |
* License: GPL2+
|
readme.txt
CHANGED
@@ -5,7 +5,7 @@ Tags: meta-box, custom fields, custom field, meta, meta-boxes, admin, advanced,
|
|
5 |
Requires at least: 4.3
|
6 |
Requires PHP: 5.3
|
7 |
Tested up to: 5.4
|
8 |
-
Stable tag: 5.2.
|
9 |
License: GPLv2 or later
|
10 |
|
11 |
Meta Box plugin is a powerful, professional developer toolkit to create custom meta boxes and custom fields for WordPress.
|
@@ -167,6 +167,9 @@ To getting started with the plugin, please read the [Quick Start Guide](https://
|
|
167 |
|
168 |
== Changelog ==
|
169 |
|
|
|
|
|
|
|
170 |
= 5.2.8 - 2020-04-06 =
|
171 |
|
172 |
**Added**
|
5 |
Requires at least: 4.3
|
6 |
Requires PHP: 5.3
|
7 |
Tested up to: 5.4
|
8 |
+
Stable tag: 5.2.9
|
9 |
License: GPLv2 or later
|
10 |
|
11 |
Meta Box plugin is a powerful, professional developer toolkit to create custom meta boxes and custom fields for WordPress.
|
167 |
|
168 |
== Changelog ==
|
169 |
|
170 |
+
= 5.2.9 - 2020-04-17 =
|
171 |
+
- Fix cloning default value not working for some fields.
|
172 |
+
|
173 |
= 5.2.8 - 2020-04-06 =
|
174 |
|
175 |
**Added**
|