Meta Box - Version 4.15.8

Version Description

Download this release

Release Info

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

Code changes from version 4.15.7 to 4.15.8

Files changed (7) hide show
  1. inc/field.php +16 -50
  2. inc/fields/datetime.php +8 -6
  3. inc/loader.php +1 -1
  4. js/clone.js +11 -0
  5. js/wysiwyg.js +17 -0
  6. meta-box.php +1 -1
  7. readme.txt +2 -2
inc/field.php CHANGED
@@ -296,71 +296,37 @@ abstract class RWMB_Field {
296
  $name = $field['id'];
297
  $storage = $field['storage'];
298
 
299
- // Remove post meta if it's empty.
300
- if ( '' === $new || array() === $new ) {
301
- $storage->delete( $post_id, $name );
302
- return;
303
- }
304
-
305
- // Save cloned fields as multiple values instead serialized array.
306
- if ( $field['clone'] && $field['clone_as_multiple'] ) {
307
- $old = array_filter( (array) $old );
308
- $new = array_filter( (array) $new );
309
-
310
- if ( empty( $new ) ) {
311
- $storage->delete( $post_id, $name );
312
- }
313
-
314
- if ( $field['sort_clone'] && array_values( $new ) != array_values( $old ) ) {
315
- $storage->delete( $post_id, $name );
316
-
317
- foreach ( $new as $new_value ) {
318
- $storage->add( $post_id, $name, $new_value, false );
319
- }
320
-
321
- return;
322
- }
323
-
324
- $new_values = array_diff( $new, $old );
325
- foreach ( $new_values as $new_value ) {
326
- $storage->add( $post_id, $name, $new_value, false );
327
- }
328
-
329
- $old_values = array_diff( $old, $new );
330
- foreach ( $old_values as $old_value ) {
331
- $storage->delete( $post_id, $name, $old_value );
332
- }
333
-
334
- return;
335
- }
336
-
337
- // If field is cloneable, value is saved as a single entry in the database.
338
  if ( $field['clone'] ) {
339
- // Remove empty values.
340
  $new = (array) $new;
341
  foreach ( $new as $k => $v ) {
342
  if ( '' === $v || array() === $v ) {
343
  unset( $new[ $k ] );
344
  }
345
  }
 
 
 
 
 
 
 
 
 
 
346
  // Reset indexes.
347
  $new = array_values( $new );
348
  $storage->update( $post_id, $name, $new );
349
  return;
350
  }
351
 
352
- // If field is multiple, value is saved as multiple entries in the database (WordPress behaviour).
353
- if ( $field['multiple'] ) {
354
- $old = (array) $old;
355
- $new = (array) $new;
356
- $new_values = array_diff( $new, $old );
357
- foreach ( $new_values as $new_value ) {
358
  $storage->add( $post_id, $name, $new_value, false );
359
  }
360
- $old_values = array_diff( $old, $new );
361
- foreach ( $old_values as $old_value ) {
362
- $storage->delete( $post_id, $name, $old_value );
363
- }
364
  return;
365
  }
366
 
296
  $name = $field['id'];
297
  $storage = $field['storage'];
298
 
299
+ // Remove empty values for clones.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300
  if ( $field['clone'] ) {
 
301
  $new = (array) $new;
302
  foreach ( $new as $k => $v ) {
303
  if ( '' === $v || array() === $v ) {
304
  unset( $new[ $k ] );
305
  }
306
  }
307
+ }
308
+
309
+ // Remove post meta if it's empty.
310
+ if ( '' === $new || array() === $new ) {
311
+ $storage->delete( $post_id, $name );
312
+ return;
313
+ }
314
+
315
+ // If field is cloneable AND not force to save as multiple rows, value is saved as a single row in the database.
316
+ if ( $field['clone'] && ! $field['clone_as_multiple'] ) {
317
  // Reset indexes.
318
  $new = array_values( $new );
319
  $storage->update( $post_id, $name, $new );
320
  return;
321
  }
322
 
323
+ // Save cloned fields as multiple values instead serialized array.
324
+ if ( ( $field['clone'] && $field['clone_as_multiple'] ) || $field['multiple'] ) {
325
+ $storage->delete( $post_id, $name );
326
+ $new = (array) $new;
327
+ foreach ( $new as $new_value ) {
 
328
  $storage->add( $post_id, $name, $new_value, false );
329
  }
 
 
 
 
330
  return;
331
  }
332
 
inc/fields/datetime.php CHANGED
@@ -267,12 +267,14 @@ class RWMB_Datetime_Field extends RWMB_Text_Field {
267
  * @return string
268
  */
269
  public static function format_single_value( $field, $value, $args, $post_id ) {
270
- if ( empty( $args['format'] ) ) {
271
- return $value;
272
- }
273
- if ( ! $field['timestamp'] ) {
274
- $value = strtotime( $value );
 
 
275
  }
276
- return date( $args['format'], $value );
277
  }
278
  }
267
  * @return string
268
  */
269
  public static function format_single_value( $field, $value, $args, $post_id ) {
270
+ if ( $field['timestamp'] ) {
271
+ $value = self::prepare_meta( $value, $field );
272
+ } else {
273
+ $value = array(
274
+ 'timestamp' => strtotime( $value ),
275
+ 'formatted' => $value,
276
+ );
277
  }
278
+ return empty( $args['format'] ) ? $value['formatted'] : date( $args['format'], $value['timestamp'] );
279
  }
280
  }
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.15.7' );
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.15.8' );
22
 
23
  list( $path, $url ) = self::get_path( dirname( dirname( __FILE__ ) ) );
24
 
js/clone.js CHANGED
@@ -254,6 +254,17 @@ jQuery( function ( $ ) {
254
  start: function ( event, ui ) {
255
  // Make the placeholder has the same height as dragged item
256
  ui.placeholder.height( ui.item.outerHeight() );
 
 
 
 
 
 
 
 
 
 
 
257
  }
258
  } );
259
  } );
254
  start: function ( event, ui ) {
255
  // Make the placeholder has the same height as dragged item
256
  ui.placeholder.height( ui.item.outerHeight() );
257
+
258
+ // Fixed WYSIWYG field blank when inside a sortable, cloneable group.
259
+ // https://stackoverflow.com/a/25667486/371240
260
+ $( ui.item ).find( '.rwmb-wysiwyg' ).each( function () {
261
+ tinymce.execCommand( 'mceRemoveEditor', false, this.id );
262
+ } );
263
+ },
264
+ stop: function(e,ui) {
265
+ $( ui.item ).find( '.rwmb-wysiwyg' ).each( function () {
266
+ tinymce.execCommand( 'mceAddEditor', true, this.id );
267
+ } );
268
  }
269
  } );
270
  } );
js/wysiwyg.js CHANGED
@@ -89,6 +89,23 @@ jQuery( function ( $ ) {
89
  .find( '.quicktags-toolbar' ).attr( 'id', 'qt_' + id + '_toolbar' ).html( '' );
90
  }
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  $( '.rwmb-wysiwyg' ).each( update );
93
  $( document ).on( 'clone', '.rwmb-wysiwyg', update );
 
94
  } );
89
  .find( '.quicktags-toolbar' ).attr( 'id', 'qt_' + id + '_toolbar' ).html( '' );
90
  }
91
 
92
+ /**
93
+ * Handles updating tiny mce instances when saving a gutenberg post.
94
+ * https://metabox.io/support/topic/data-are-not-saved-into-the-database/
95
+ * https://github.com/WordPress/gutenberg/issues/7176
96
+ */
97
+ function ensureSave() {
98
+ if ( ! wp.data || ! window.tinyMCE ) {
99
+ return;
100
+ }
101
+ wp.data.subscribe( function() {
102
+ if ( wp.data.select( 'core/editor' ).isSavingPost() ) {
103
+ window.tinyMCE.triggerSave();
104
+ }
105
+ } );
106
+ }
107
+
108
  $( '.rwmb-wysiwyg' ).each( update );
109
  $( document ).on( 'clone', '.rwmb-wysiwyg', update );
110
+ ensureSave();
111
  } );
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.15.7
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.15.8
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: 4.9.8
7
- Stable tag: 4.15.7
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.
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.0
7
+ Stable tag: 4.15.8
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.