Meta Box - Version 4.8.3

Version Description

  • Improvement: WYSIWYG field now can be cloned. Sorting clone hasn't worked yet.
  • Fix: 'std' value not working if there is 'divider' or 'heading' field withough 'id'
  • Fix: helper function not working in AJAX or admin.
  • Fix: getting plugin's path on Windows system.
  • Fix: warning get_value of taxonomy field
  • Fix: guarantee file ids are in an array
Download this release

Release Info

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

Code changes from version 4.8.2 to 4.8.3

css/wysiwyg.css CHANGED
@@ -1,3 +1,6 @@
1
  .rwmb-field .mceIframeContainer {
2
  background: #fff;
3
- }
 
 
 
1
  .rwmb-field .mceIframeContainer {
2
  background: #fff;
3
+ }
4
+ .rwmb-wysiwyg-clone {
5
+ padding-top: 20px;
6
+ }
inc/fields/file.php CHANGED
@@ -299,7 +299,7 @@ class RWMB_File_Field extends RWMB_Field
299
 
300
  // For each file, get full file info
301
  $value = array();
302
- foreach ( $file_ids as $file_id )
303
  {
304
  if ( $file_info = call_user_func( array( RW_Meta_Box::get_class_name( $field ), 'file_info' ), $file_id, $args ) )
305
  {
299
 
300
  // For each file, get full file info
301
  $value = array();
302
+ foreach ( (array) $file_ids as $file_id )
303
  {
304
  if ( $file_info = call_user_func( array( RW_Meta_Box::get_class_name( $field ), 'file_info' ), $file_id, $args ) )
305
  {
inc/fields/taxonomy.php CHANGED
@@ -139,7 +139,7 @@ class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field
139
  $value = get_the_terms( $post_id, $field['taxonomy'] );
140
 
141
  // Get single value if necessary
142
- if ( ! $field['clone'] && ! $field['multiple'] )
143
  {
144
  $value = reset( $value );
145
  }
139
  $value = get_the_terms( $post_id, $field['taxonomy'] );
140
 
141
  // Get single value if necessary
142
+ if ( ! $field['clone'] && ! $field['multiple'] && is_array( $value ) )
143
  {
144
  $value = reset( $value );
145
  }
inc/fields/wysiwyg.php CHANGED
@@ -1,4 +1,5 @@
1
  <?php
 
2
  /**
3
  * WYSIWYG (editor) field class.
4
  */
@@ -15,7 +16,8 @@ class RWMB_Wysiwyg_Field extends RWMB_Field
15
  */
16
  static function admin_enqueue_scripts()
17
  {
18
- wp_enqueue_style( 'rwmb-meta-box-wysiwyg', RWMB_CSS_URL . 'wysiwyg.css', array(), RWMB_VER );
 
19
  }
20
 
21
  /**
@@ -58,18 +60,12 @@ class RWMB_Wysiwyg_Field extends RWMB_Field
58
  ob_start();
59
 
60
  $field['options']['textarea_name'] = $field['field_name'];
 
61
 
62
  // Use new wp_editor() since WP 3.3
63
- wp_editor( $meta, $field['id'], $field['options'] );
64
 
65
- $editor = ob_get_clean();
66
- if ( $field['clone'] )
67
- {
68
- self::$cloneable_editors[$field['id']] = $editor;
69
- add_action( 'admin_print_footer_scripts', array( __CLASS__, 'footer_scripts' ), 51 );
70
- }
71
-
72
- return $editor;
73
  }
74
 
75
  /**
@@ -107,12 +103,4 @@ class RWMB_Wysiwyg_Field extends RWMB_Field
107
 
108
  return $field;
109
  }
110
-
111
- /**
112
- * Display list of editors' IDs in the footer for clone.
113
- */
114
- static function footer_scripts()
115
- {
116
- echo '<script>var rwmb_cloneable_editors = ', wp_json_encode( self::$cloneable_editors ), ';</script>';
117
- }
118
  }
1
  <?php
2
+
3
  /**
4
  * WYSIWYG (editor) field class.
5
  */
16
  */
17
  static function admin_enqueue_scripts()
18
  {
19
+ wp_enqueue_style( 'rwmb-wysiwyg', RWMB_CSS_URL . 'wysiwyg.css', array(), RWMB_VER );
20
+ wp_enqueue_script( 'rwmb-wysiwyg', RWMB_JS_URL . 'wysiwyg.js', array( 'jquery' ), RWMB_VER, true );
21
  }
22
 
23
  /**
60
  ob_start();
61
 
62
  $field['options']['textarea_name'] = $field['field_name'];
63
+ $attributes = self::get_attributes( $field );
64
 
65
  // Use new wp_editor() since WP 3.3
66
+ wp_editor( $meta, $attributes['id'], $field['options'] );
67
 
68
+ return ob_get_clean();
 
 
 
 
 
 
 
69
  }
70
 
71
  /**
103
 
104
  return $field;
105
  }
 
 
 
 
 
 
 
 
106
  }
inc/functions.php CHANGED
@@ -3,124 +3,136 @@
3
  * Plugin public functions.
4
  */
5
 
6
- /**
7
- * Get post meta
8
- *
9
- * @param string $key Meta key. Required.
10
- * @param int|null $post_id Post ID. null for current post. Optional
11
- * @param array $args Array of arguments. Optional.
12
- *
13
- * @return mixed
14
- */
15
- function rwmb_meta( $key, $args = array(), $post_id = null )
16
  {
17
  /**
18
- * If meta boxes is registered in the backend only, we can't get field's params
19
- * This is for backward compatibility with version < 4.8.0
 
 
 
 
 
20
  */
21
- if ( false == RWMB_Helper::find_field( $key ) )
22
  {
23
- return apply_filters( 'rwmb_meta', RWMB_Helper::meta( $key, $args, $post_id ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  }
25
- $args = wp_parse_args( $args, array(
26
- 'type' => 'text',
27
- ) );
28
- $meta = in_array( $args['type'], array( 'oembed', 'map' ) ) ?
29
- rwmb_the_value( $key, $args, $post_id, false ) :
30
- rwmb_get_value( $key, $args, $post_id );
31
- return apply_filters( 'rwmb_meta', $meta, $key, $args, $post_id );
32
  }
33
 
34
- /**
35
- * Get value of custom field.
36
- * This is used to replace old version of rwmb_meta key.
37
- *
38
- * @param string $field_id Field ID. Required.
39
- * @param array $args Additional arguments. Rarely used. See specific fields for details
40
- * @param int|null $post_id Post ID. null for current post. Optional.
41
- *
42
- * @return mixed false if field doesn't exist. Field value otherwise.
43
- */
44
- function rwmb_get_value( $field_id, $args = array(), $post_id = null )
45
  {
46
- $field = RWMB_Helper::find_field( $field_id );
47
-
48
- // Get field value
49
- $value = $field ? call_user_func( array( RW_Meta_Box::get_class_name( $field ), 'get_value' ), $field, $args, $post_id ) : false;
50
-
51
  /**
52
- * Allow developers to change the returned value of field
53
- * For version < 4.8.2, the filter name was 'rwmb_get_field'
 
 
 
 
54
  *
55
- * @param mixed $value Field value
56
- * @param array $field Field parameter
57
- * @param array $args Additional arguments. Rarely used. See specific fields for details
58
- * @param int|null $post_id Post ID. null for current post. Optional.
59
  */
60
- $value = apply_filters( 'rwmb_get_value', $value, $field, $args, $post_id );
 
 
61
 
62
- return $value;
63
- }
64
 
65
- /**
66
- * Display the value of a field
67
- *
68
- * @param string $field_id Field ID. Required.
69
- * @param array $args Additional arguments. Rarely used. See specific fields for details
70
- * @param int|null $post_id Post ID. null for current post. Optional.
71
- * @param bool $echo Display field meta value? Default `true` which works in almost all cases. We use `false` for the [rwmb_meta] shortcode
72
- *
73
- * @return string
74
- */
75
- function rwmb_the_value( $field_id, $args = array(), $post_id = null, $echo = true )
76
- {
77
- // Find field
78
- $field = RWMB_Helper::find_field( $field_id );
79
 
80
- if ( ! $field )
81
- return '';
82
-
83
- $output = call_user_func( array( RW_Meta_Box::get_class_name( $field ), 'the_value' ), $field, $args, $post_id );
84
 
 
 
85
  /**
86
- * Allow developers to change the returned value of field
87
- * For version < 4.8.2, the filter name was 'rwmb_get_field'
88
  *
89
- * @param mixed $value Field HTML output
90
- * @param array $field Field parameter
91
- * @param array $args Additional arguments. Rarely used. See specific fields for details
92
- * @param int|null $post_id Post ID. null for current post. Optional.
 
 
93
  */
94
- $output = apply_filters( 'rwmb_the_value', $output, $field, $args, $post_id );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
 
96
- if ( $echo )
97
- echo $output;
98
 
99
- return $output;
 
100
  }
101
 
102
- /**
103
- * Shortcode to display meta value
104
- *
105
- * @param array $atts Shortcode attributes, same as meta() function, but has more "meta_key" parameter
106
- *
107
- * @see meta() function below
108
- *
109
- * @return string
110
- */
111
- function rwmb_meta_shortcode( $atts )
112
  {
113
- $atts = wp_parse_args( $atts, array(
114
- 'post_id' => get_the_ID(),
115
- ) );
116
- if ( empty( $atts['meta_key'] ) )
117
- return '';
 
 
 
 
 
 
 
 
 
 
 
118
 
119
- $field_id = $atts['meta_key'];
120
- $post_id = $atts['post_id'];
121
- unset( $atts['meta_key'], $atts['post_id'] );
122
 
123
- return rwmb_the_value( $field_id, $atts, $post_id, false );
124
- }
125
 
126
- add_shortcode( 'rwmb_meta', 'rwmb_meta_shortcode' );
 
3
  * Plugin public functions.
4
  */
5
 
6
+ if ( ! function_exists( 'rwmb_meta' ) )
 
 
 
 
 
 
 
 
 
7
  {
8
  /**
9
+ * Get post meta
10
+ *
11
+ * @param string $key Meta key. Required.
12
+ * @param int|null $post_id Post ID. null for current post. Optional
13
+ * @param array $args Array of arguments. Optional.
14
+ *
15
+ * @return mixed
16
  */
17
+ function rwmb_meta( $key, $args = array(), $post_id = null )
18
  {
19
+ /**
20
+ * If meta boxes is registered in the backend only, we can't get field's params
21
+ * This is for backward compatibility with version < 4.8.0
22
+ */
23
+ if ( false === RWMB_Helper::find_field( $key ) )
24
+ {
25
+ return apply_filters( 'rwmb_meta', RWMB_Helper::meta( $key, $args, $post_id ) );
26
+ }
27
+ $args = wp_parse_args( $args, array(
28
+ 'type' => 'text',
29
+ ) );
30
+ $meta = in_array( $args['type'], array( 'oembed', 'map' ) ) ?
31
+ rwmb_the_value( $key, $args, $post_id, false ) :
32
+ rwmb_get_value( $key, $args, $post_id );
33
+ return apply_filters( 'rwmb_meta', $meta, $key, $args, $post_id );
34
  }
 
 
 
 
 
 
 
35
  }
36
 
37
+ if ( ! function_exists( 'rwmb_get_value' ) )
 
 
 
 
 
 
 
 
 
 
38
  {
 
 
 
 
 
39
  /**
40
+ * Get value of custom field.
41
+ * This is used to replace old version of rwmb_meta key.
42
+ *
43
+ * @param string $field_id Field ID. Required.
44
+ * @param array $args Additional arguments. Rarely used. See specific fields for details
45
+ * @param int|null $post_id Post ID. null for current post. Optional.
46
  *
47
+ * @return mixed false if field doesn't exist. Field value otherwise.
 
 
 
48
  */
49
+ function rwmb_get_value( $field_id, $args = array(), $post_id = null )
50
+ {
51
+ $field = RWMB_Helper::find_field( $field_id );
52
 
53
+ // Get field value
54
+ $value = $field ? call_user_func( array( RW_Meta_Box::get_class_name( $field ), 'get_value' ), $field, $args, $post_id ) : false;
55
 
56
+ /**
57
+ * Allow developers to change the returned value of field
58
+ * For version < 4.8.2, the filter name was 'rwmb_get_field'
59
+ *
60
+ * @param mixed $value Field value
61
+ * @param array $field Field parameter
62
+ * @param array $args Additional arguments. Rarely used. See specific fields for details
63
+ * @param int|null $post_id Post ID. null for current post. Optional.
64
+ */
65
+ $value = apply_filters( 'rwmb_get_value', $value, $field, $args, $post_id );
 
 
 
 
66
 
67
+ return $value;
68
+ }
69
+ }
 
70
 
71
+ if ( ! function_exists( 'rwmb_the_value' ) )
72
+ {
73
  /**
74
+ * Display the value of a field
 
75
  *
76
+ * @param string $field_id Field ID. Required.
77
+ * @param array $args Additional arguments. Rarely used. See specific fields for details
78
+ * @param int|null $post_id Post ID. null for current post. Optional.
79
+ * @param bool $echo Display field meta value? Default `true` which works in almost all cases. We use `false` for the [rwmb_meta] shortcode
80
+ *
81
+ * @return string
82
  */
83
+ function rwmb_the_value( $field_id, $args = array(), $post_id = null, $echo = true )
84
+ {
85
+ // Find field
86
+ $field = RWMB_Helper::find_field( $field_id );
87
+
88
+ if ( ! $field )
89
+ return '';
90
+
91
+ $output = call_user_func( array( RW_Meta_Box::get_class_name( $field ), 'the_value' ), $field, $args, $post_id );
92
+
93
+ /**
94
+ * Allow developers to change the returned value of field
95
+ * For version < 4.8.2, the filter name was 'rwmb_get_field'
96
+ *
97
+ * @param mixed $value Field HTML output
98
+ * @param array $field Field parameter
99
+ * @param array $args Additional arguments. Rarely used. See specific fields for details
100
+ * @param int|null $post_id Post ID. null for current post. Optional.
101
+ */
102
+ $output = apply_filters( 'rwmb_the_value', $output, $field, $args, $post_id );
103
 
104
+ if ( $echo )
105
+ echo $output;
106
 
107
+ return $output;
108
+ }
109
  }
110
 
111
+ if ( ! function_exists( 'rwmb_meta_shortcode' ) )
 
 
 
 
 
 
 
 
 
112
  {
113
+ /**
114
+ * Shortcode to display meta value
115
+ *
116
+ * @param array $atts Shortcode attributes, same as meta() function, but has more "meta_key" parameter
117
+ *
118
+ * @see meta() function below
119
+ *
120
+ * @return string
121
+ */
122
+ function rwmb_meta_shortcode( $atts )
123
+ {
124
+ $atts = wp_parse_args( $atts, array(
125
+ 'post_id' => get_the_ID(),
126
+ ) );
127
+ if ( empty( $atts['meta_key'] ) )
128
+ return '';
129
 
130
+ $field_id = $atts['meta_key'];
131
+ $post_id = $atts['post_id'];
132
+ unset( $atts['meta_key'], $atts['post_id'] );
133
 
134
+ return rwmb_the_value( $field_id, $atts, $post_id, false );
135
+ }
136
 
137
+ add_shortcode( 'rwmb_meta', 'rwmb_meta_shortcode' );
138
+ }
inc/loader.php CHANGED
@@ -28,7 +28,7 @@ class RWMB_Loader
28
  public function constants()
29
  {
30
  // Script version, used to add version for scripts and styles
31
- define( 'RWMB_VER', '4.8.2' );
32
 
33
  list( $path, $url ) = self::get_path();
34
 
@@ -53,10 +53,12 @@ class RWMB_Loader
53
  static public function get_path( $base = '' )
54
  {
55
  // Plugin base path
56
- $path = $base ? $base : dirname( dirname( __FILE__ ) );
 
 
57
 
58
  // Check if plugin is a symbolic link (only when it's installed as a standalone plugin).
59
- if ( false === strpos( $path, ABSPATH ) )
60
  {
61
  if ( ! function_exists( 'is_plugin_active' ) )
62
  {
@@ -69,13 +71,13 @@ class RWMB_Loader
69
  }
70
  }
71
 
72
- $path = trailingslashit( wp_normalize_path( $path ) );
73
-
74
  // Get plugin base URL
75
  $content_url = untrailingslashit( dirname( dirname( get_stylesheet_directory_uri() ) ) );
76
  $content_dir = untrailingslashit( WP_CONTENT_DIR );
77
- $content_dir = wp_normalize_path( $content_dir );
78
- $url = str_replace( $content_dir, $content_url, $path );
 
 
79
 
80
  return array( $path, $url );
81
  }
@@ -129,10 +131,8 @@ class RWMB_Loader
129
  // Validation module
130
  new RWMB_Validation;
131
  }
132
- else
133
- {
134
- // Public functions
135
- require RWMB_INC_DIR . 'functions.php';
136
- }
137
  }
138
  }
28
  public function constants()
29
  {
30
  // Script version, used to add version for scripts and styles
31
+ define( 'RWMB_VER', '4.8.3' );
32
 
33
  list( $path, $url ) = self::get_path();
34
 
53
  static public function get_path( $base = '' )
54
  {
55
  // Plugin base path
56
+ $path = $base ? $base : dirname( dirname( __FILE__ ) );
57
+ $path = untrailingslashit( $path );
58
+ $abspath = untrailingslashit( ABSPATH );
59
 
60
  // Check if plugin is a symbolic link (only when it's installed as a standalone plugin).
61
+ if ( false === strpos( $path, $abspath ) )
62
  {
63
  if ( ! function_exists( 'is_plugin_active' ) )
64
  {
71
  }
72
  }
73
 
 
 
74
  // Get plugin base URL
75
  $content_url = untrailingslashit( dirname( dirname( get_stylesheet_directory_uri() ) ) );
76
  $content_dir = untrailingslashit( WP_CONTENT_DIR );
77
+ $url = str_replace( wp_normalize_path( $content_dir ), $content_url, wp_normalize_path( $path ) );
78
+
79
+ $path = trailingslashit( $path );
80
+ $url = trailingslashit( $url );
81
 
82
  return array( $path, $url );
83
  }
131
  // Validation module
132
  new RWMB_Validation;
133
  }
134
+
135
+ // Public functions
136
+ require RWMB_INC_DIR . 'functions.php';
 
 
137
  }
138
  }
inc/meta-box.php CHANGED
@@ -392,6 +392,10 @@ class RW_Meta_Box
392
 
393
  foreach ( $this->fields as $field )
394
  {
 
 
 
 
395
  $value = get_post_meta( $post->ID, $field['id'], ! $field['multiple'] );
396
  if (
397
  ( ! $field['multiple'] && '' !== $value )
392
 
393
  foreach ( $this->fields as $field )
394
  {
395
+ if ( empty( $field['id'] ) )
396
+ {
397
+ continue;
398
+ }
399
  $value = get_post_meta( $post->ID, $field['id'], ! $field['multiple'] );
400
  if (
401
  ( ! $field['multiple'] && '' !== $value )
js/clone.js CHANGED
@@ -158,100 +158,6 @@ jQuery( function ( $ )
158
  $button.toggle( isNaN( maxClone ) || ( maxClone && numClone < maxClone ) );
159
  }
160
 
161
- /**
162
- * Clone WYSIWYG field
163
- * @param $container
164
- * @return void
165
- */
166
- function cloneWYSIWYG( $container )
167
- {
168
- var $clone_first = $container.find( '.rwmb-clone:first' ),
169
- $clone_last = $container.find( '.rwmb-clone:last' ),
170
- $clone = $( '<div />' ).addClass( 'rwmb-clone' ),
171
- field_name = $clone_last.find( 'textarea.wp-editor-area' ).attr( 'name' ),
172
- field_id = field_name.replace( /\[(\d+)]/, '' );
173
-
174
- //Create some global vars
175
- var new_index = 0;
176
- var new_name = field_name.replace( /\[(\d+)]/, function ( match, p1 )
177
- {
178
- new_index = ( parseInt( p1, 10 ) + 1 );
179
- return '[' + new_index + ']';
180
- } );
181
-
182
- if ( typeof rwmb_cloneable_editors !== 'undefined' && typeof rwmb_cloneable_editors[field_id] !== 'undefined' )
183
- {
184
- //Get HTML of editor from global object
185
- var cloned_editor = $( rwmb_cloneable_editors[field_id] );
186
-
187
- //Fill new clone with html form global object
188
- $clone.append( cloned_editor );
189
-
190
- //Add remove button to clone
191
- $clone.append( $clone_last.find( '.remove-clone' ).clone() );
192
-
193
- //Add new clone after the last clone
194
- $clone.insertAfter( $clone_last );
195
-
196
- //Replace ID of field with new ID
197
- var new_id = cloned_editor.attr( 'id' ).replace( /\[(\d+)]/, '[' + new_index + ']' );
198
- cloned_editor.attr( 'id', new_id );
199
-
200
- //Replace all IDs within cloned field
201
- cloned_editor.find( '[id*="' + field_id + '"]' ).each( function ()
202
- {
203
- var id = $( this ).attr( 'id' ).replace( /\[(\d+)]/, '[' + new_index + ']' );
204
- $( this ).attr( 'id', id );
205
- } );
206
-
207
- //Get the new textarea element
208
- var textarea = $( cloned_editor ).find( 'textarea.wp-editor-area' );
209
-
210
- // Update the "name" attribute
211
- textarea.attr( 'name', new_name );
212
-
213
- //Empty the textarea
214
- textarea.html( '' );
215
-
216
- //Update editor link, so we can add media to the new editor
217
- cloned_editor.find( '#insert-media-button' ).data( 'editor', new_name );
218
-
219
-
220
- //Get TinyMCE setting for our fields
221
- var tmceinit = tinyMCEPreInit.mceInit[$clone_first.find( 'textarea.wp-editor-area' ).attr( 'name' )];
222
- var tmceqtinit = tinyMCEPreInit.qtInit[$clone_first.find( 'textarea.wp-editor-area' ).attr( 'name' )];
223
-
224
- //Replace id & elements with new created field names
225
- tmceinit.elements = new_name;
226
- tmceqtinit.id = new_name;
227
-
228
- //Initialize TinyMCE
229
- try
230
- {
231
- tinymce.init( tmceinit );
232
- }
233
- catch ( e )
234
- {
235
- }
236
- if ( typeof(QTags) === 'function' )
237
- {
238
- try
239
- {
240
- quicktags( tmceqtinit );
241
- }
242
- catch ( e )
243
- {
244
- }
245
- }
246
-
247
- // Toggle remove buttons
248
- toggleRemoveButtons( $clone );
249
-
250
- //Trigger custom clone event
251
- textarea.trigger( 'clone' );
252
- }
253
- }
254
-
255
  $( '#wpbody-content' )
256
  // Add clones
257
  .on( 'click', '.add-clone', function ( e )
@@ -259,15 +165,7 @@ jQuery( function ( $ )
259
  e.preventDefault();
260
 
261
  var $container = $( this ).closest( '.rwmb-input' );
262
-
263
- if ( $( this ).closest( '.rwmb-field' ).hasClass( 'rwmb-wysiwyg-wrapper' ) )
264
- {
265
- cloneWYSIWYG( $container );
266
- }
267
- else
268
- {
269
- clone( $container );
270
- }
271
 
272
  toggleRemoveButtons( $container );
273
  toggleAddButton( $container );
158
  $button.toggle( isNaN( maxClone ) || ( maxClone && numClone < maxClone ) );
159
  }
160
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  $( '#wpbody-content' )
162
  // Add clones
163
  .on( 'click', '.add-clone', function ( e )
165
  e.preventDefault();
166
 
167
  var $container = $( this ).closest( '.rwmb-input' );
168
+ clone( $container );
 
 
 
 
 
 
 
 
169
 
170
  toggleRemoveButtons( $container );
171
  toggleAddButton( $container );
js/wysiwyg.js ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* global tinymce, quicktags */
2
+
3
+ jQuery( function ( $ )
4
+ {
5
+ 'use strict';
6
+
7
+ /**
8
+ * Update date picker element
9
+ * Used for static & dynamic added elements (when clone)
10
+ */
11
+ function update()
12
+ {
13
+ var $this = $( this ),
14
+ $wrapper = $this.closest( '.wp-editor-wrap' ),
15
+ id = $this.attr( 'id' );
16
+
17
+ // Ignore existing editor.
18
+ if ( tinyMCEPreInit.mceInit[id] )
19
+ {
20
+ return;
21
+ }
22
+
23
+ // Get id of the original editor to get its tinyMCE and quick tags settings
24
+ var originalId = getOriginalId( $this );
25
+ if ( !originalId )
26
+ {
27
+ return;
28
+ }
29
+
30
+ // Update the DOM
31
+ $this.show();
32
+ updateDom( $wrapper, id );
33
+
34
+ // TinyMCE
35
+ var settings = tinyMCEPreInit.mceInit[originalId];
36
+ settings.selector = '#' + id;
37
+ tinymce.init( settings );
38
+
39
+ // Quick tags
40
+ if ( typeof quicktags === 'function' && tinyMCEPreInit.qtInit.hasOwnProperty( originalId ) )
41
+ {
42
+ var qtSettings = tinyMCEPreInit.qtInit[originalId];
43
+ qtSettings.id = id;
44
+ quicktags( qtSettings );
45
+ QTags._buttonsInit();
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Get original ID of the textarea
51
+ * The ID will be used to reference to tinyMCE and quick tags settings
52
+ * @param $el Current cloned textarea
53
+ */
54
+ function getOriginalId( $el )
55
+ {
56
+ var $clones = $el.closest( '.rwmb-clone' ).siblings( '.rwmb-clone' ),
57
+ id = '';
58
+ $clones.each( function ()
59
+ {
60
+ var currentId = $( this ).find( '.rwmb-wysiwyg' ).attr( 'id' );
61
+ if ( tinyMCEPreInit.mceInit.hasOwnProperty( currentId ) )
62
+ {
63
+ id = currentId;
64
+ return false; // Immediately stop the .each() loop
65
+ }
66
+ } );
67
+ return id;
68
+ }
69
+
70
+ /**
71
+ * Update id, class, [data-] attributes, ... of the cloned editor.
72
+ * @param $wrapper Editor wrapper element
73
+ * @param id Editor ID
74
+ */
75
+ function updateDom( $wrapper, id )
76
+ {
77
+ // Wrapper div and media buttons
78
+ $wrapper.attr( 'id', 'wp-' + id + '-wrap' )
79
+ .removeClass( 'html-active' ).addClass( 'mce-active' ) // Active the visual mode by default
80
+ .find( '.mce-container' ).remove().end() // Remove rendered tinyMCE editor
81
+ .find( '.wp-editor-tools' ).attr( 'id', 'wp-' + id + '-editor-tools' )
82
+ .find( '.wp-media-buttons' ).attr( 'id', 'wp-' + id + '-media-buttons' )
83
+ .find( 'button' ).data( 'editor', id ).attr( 'data-editor', id );
84
+
85
+ // Editor tabs
86
+ $wrapper.find( '.switch-tmce' )
87
+ .attr( 'id', id + 'tmce' )
88
+ .data( 'wp-editor-id', id ).attr( 'data-wp-editor-id', id ).end()
89
+ .find( '.switch-html' )
90
+ .attr( 'id', id + 'html' )
91
+ .data( 'wp-editor-id', id ).attr( 'data-wp-editor-id', id );
92
+
93
+ // Quick tags
94
+ $wrapper.find( '.wp-editor-container' ).attr( 'id', 'wp-' + id + '-editor-container' )
95
+ .find( '.quicktags-toolbar' ).attr( 'id', 'qt_' + id + '_toolbar' ).html( '' );
96
+ }
97
+
98
+ $( ':input.rwmb-date' ).each( update );
99
+ $( '.rwmb-input' ).on( 'clone', ':input.rwmb-wysiwyg', update );
100
+ } );
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 for any post type in WordPress.
6
- * Version: 4.8.2
7
  * Author: Rilwis
8
  * Author URI: http://www.deluxeblogtips.com
9
  * License: GPL2+
3
  * Plugin Name: Meta Box
4
  * Plugin URI: https://metabox.io
5
  * Description: Create custom meta boxes and custom fields for any post type in WordPress.
6
+ * Version: 4.8.3
7
  * Author: Rilwis
8
  * Author URI: http://www.deluxeblogtips.com
9
  * License: GPL2+
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.deluxeblogtips.com/donate
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.1
6
  Tested up to: 4.4.2
7
- Stable tag: 4.8.2
8
  License: GPLv2 or later
9
 
10
  Meta Box plugin is a powerful, professional solution to create custom meta boxes and custom fields for WordPress websites.
@@ -77,6 +77,14 @@ To getting started with the plugin API, please read [this tutorial](https://meta
77
 
78
  == Changelog ==
79
 
 
 
 
 
 
 
 
 
80
  = 4.8.2 =
81
  * Fix: re-add code for backward compatibility for helper function
82
  * Fix: undefined 'class' attribute for button
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.1
6
  Tested up to: 4.4.2
7
+ Stable tag: 4.8.3
8
  License: GPLv2 or later
9
 
10
  Meta Box plugin is a powerful, professional solution to create custom meta boxes and custom fields for WordPress websites.
77
 
78
  == Changelog ==
79
 
80
+ = 4.8.3 =
81
+ * Improvement: WYSIWYG field now can be cloned. Sorting clone hasn't worked yet.
82
+ * Fix: 'std' value not working if there is 'divider' or 'heading' field withough 'id'
83
+ * Fix: helper function not working in AJAX or admin.
84
+ * Fix: getting plugin's path on Windows system.
85
+ * Fix: warning get_value of taxonomy field
86
+ * Fix: guarantee file ids are in an array
87
+
88
  = 4.8.2 =
89
  * Fix: re-add code for backward compatibility for helper function
90
  * Fix: undefined 'class' attribute for button