Meta Box - Version 4.18.0

Version Description

Download this release

Release Info

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

Code changes from version 4.17.3 to 4.18.0

css/image.css CHANGED
@@ -1,7 +1,7 @@
1
  .rwmb-image-wrapper .rwmb-uploaded:empty {
2
  display: none;
3
  }
4
- .rwmb-uploaded:not(:empty) {
5
  display: block;
6
  margin: -8px 0 0 -8px;
7
  overflow: hidden;
1
  .rwmb-image-wrapper .rwmb-uploaded:empty {
2
  display: none;
3
  }
4
+ .rwmb-image-wrapper .rwmb-uploaded:not(:empty) {
5
  display: block;
6
  margin: -8px 0 0 -8px;
7
  overflow: hidden;
css/taxonomy.css ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .rwmb-taxonomy-add,
2
+ .rwmb-taxonomy-add-form {
3
+ margin-top: 6px;
4
+ }
5
+ .rwmb-taxonomy-add-button {
6
+ padding: 0;
7
+ border: 0;
8
+ background: none;
9
+ color: #0073aa;
10
+ text-decoration: underline;
11
+ cursor: pointer;
12
+ }
13
+ .rwmb-taxonomy-add-button:hover {
14
+ color: #00a0d2;
15
+ }
16
+ .rwmb-taxonomy-add-form.rwmb-hidden {
17
+ display: none;
18
+ }
inc/fields/file.php CHANGED
@@ -172,8 +172,12 @@ class RWMB_File_Field extends RWMB_Field {
172
  'name' => basename( get_attached_file( $file ) ),
173
  'url' => wp_get_attachment_url( $file ),
174
  'title' => get_the_title( $file ),
175
- 'edit_link' => sprintf( '<a href="%s" class="rwmb-file-edit" target="_blank"><span class="dashicons dashicons-edit"></span>%s</a>', get_edit_post_link( $file ), $i18n_edit ),
176
  );
 
 
 
 
177
  }
178
 
179
  return sprintf(
172
  'name' => basename( get_attached_file( $file ) ),
173
  'url' => wp_get_attachment_url( $file ),
174
  'title' => get_the_title( $file ),
175
+ 'edit_link' => '',
176
  );
177
+ $edit_link = get_edit_post_link( $file );
178
+ if ( $edit_link ) {
179
+ $data['edit_link'] = sprintf( '<a href="%s" class="rwmb-file-edit" target="_blank"><span class="dashicons dashicons-edit"></span>%s</a>', $edit_link, $i18n_edit );
180
+ }
181
  }
182
 
183
  return sprintf(
inc/fields/image.php CHANGED
@@ -30,6 +30,11 @@ class RWMB_Image_Field extends RWMB_File_Field {
30
  protected static function file_html( $file, $index, $field ) {
31
  $attributes = self::get_attributes( $field, $file );
32
 
 
 
 
 
 
33
  return sprintf(
34
  '<li class="rwmb-image-item attachment %s">
35
  <input type="hidden" name="%s[%s]" value="%s">
@@ -42,7 +47,7 @@ class RWMB_Image_Field extends RWMB_File_Field {
42
  </div>
43
  <div class="rwmb-image-overlay"></div>
44
  <div class="rwmb-image-actions">
45
- <a href="%s" class="rwmb-image-edit" target="_blank"><span class="dashicons dashicons-edit"></span></a>
46
  <a href="#" class="rwmb-image-delete rwmb-file-delete" data-attachment_id="%s"><span class="dashicons dashicons-no-alt"></span></a>
47
  </div>
48
  </li>',
@@ -51,7 +56,7 @@ class RWMB_Image_Field extends RWMB_File_Field {
51
  $index,
52
  $file,
53
  wp_get_attachment_image( $file, $field['image_size'] ),
54
- get_edit_post_link( $file ),
55
  $file
56
  );
57
  }
30
  protected static function file_html( $file, $index, $field ) {
31
  $attributes = self::get_attributes( $field, $file );
32
 
33
+ $edit_link = get_edit_post_link( $file );
34
+ if ( $edit_link ) {
35
+ $edit_link = sprintf( '<a href="%s" class="rwmb-image-edit" target="_blank"><span class="dashicons dashicons-edit"></span></a>', $edit_link );
36
+ }
37
+
38
  return sprintf(
39
  '<li class="rwmb-image-item attachment %s">
40
  <input type="hidden" name="%s[%s]" value="%s">
47
  </div>
48
  <div class="rwmb-image-overlay"></div>
49
  <div class="rwmb-image-actions">
50
+ %s
51
  <a href="#" class="rwmb-image-delete rwmb-file-delete" data-attachment_id="%s"><span class="dashicons dashicons-no-alt"></span></a>
52
  </div>
53
  </li>',
56
  $index,
57
  $file,
58
  wp_get_attachment_image( $file, $field['image_size'] ),
59
+ $edit_link,
60
  $file
61
  );
62
  }
inc/fields/object-choice.php CHANGED
@@ -32,7 +32,11 @@ abstract class RWMB_Object_Choice_Field extends RWMB_Choice_Field {
32
  */
33
  public static function html( $meta, $field ) {
34
  $html = call_user_func( array( self::get_type_class( $field ), 'html' ), $meta, $field );
35
- $html .= self::call( 'add_new_form', $field );
 
 
 
 
36
  return $html;
37
  }
38
 
@@ -61,6 +65,7 @@ abstract class RWMB_Object_Choice_Field extends RWMB_Choice_Field {
61
  'flatten' => true,
62
  'query_args' => array(),
63
  'field_type' => 'select_advanced',
 
64
  )
65
  );
66
 
32
  */
33
  public static function html( $meta, $field ) {
34
  $html = call_user_func( array( self::get_type_class( $field ), 'html' ), $meta, $field );
35
+
36
+ if ( $field['add_new'] ) {
37
+ $html .= self::call( 'add_new_form', $field );
38
+ }
39
+
40
  return $html;
41
  }
42
 
65
  'flatten' => true,
66
  'query_args' => array(),
67
  'field_type' => 'select_advanced',
68
+ 'add_new' => false,
69
  )
70
  );
71
 
inc/fields/taxonomy-advanced.php CHANGED
@@ -10,8 +10,7 @@
10
  */
11
  class RWMB_Taxonomy_Advanced_Field extends RWMB_Taxonomy_Field {
12
  /**
13
- * Get meta values to save.
14
- * Save terms in custom field in form of comma-separated IDs, no more by setting post terms.
15
  *
16
  * @param mixed $new The submitted meta value.
17
  * @param mixed $old The existing meta value.
@@ -21,7 +20,9 @@ class RWMB_Taxonomy_Advanced_Field extends RWMB_Taxonomy_Field {
21
  * @return string
22
  */
23
  public static function value( $new, $old, $post_id, $field ) {
24
- return implode( ',', array_filter( array_unique( (array) $new ) ) );
 
 
25
  }
26
 
27
  /**
10
  */
11
  class RWMB_Taxonomy_Advanced_Field extends RWMB_Taxonomy_Field {
12
  /**
13
+ * Save terms in form of comma-separated IDs.
 
14
  *
15
  * @param mixed $new The submitted meta value.
16
  * @param mixed $old The existing meta value.
20
  * @return string
21
  */
22
  public static function value( $new, $old, $post_id, $field ) {
23
+ $new = parent::value( $new, $old, $post_id, $field );
24
+
25
+ return implode( ',', $new );
26
  }
27
 
28
  /**
inc/fields/taxonomy.php CHANGED
@@ -44,14 +44,11 @@ class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
44
  * - If multiple taxonomies: show 'Select a term'.
45
  * - If single taxonomy: show 'Select a %taxonomy_name%'.
46
  */
47
- $placeholder = __( 'Select a term', 'meta-box' );
48
- if ( 1 === count( $field['taxonomy'] ) ) {
49
- $taxonomy = reset( $field['taxonomy'] );
50
- $taxonomy_object = get_taxonomy( $taxonomy );
51
- if ( false !== $taxonomy_object ) {
52
- // Translators: %s is the taxonomy singular label.
53
- $placeholder = sprintf( __( 'Select a %s', 'meta-box' ), strtolower( $taxonomy_object->labels->singular_name ) );
54
- }
55
  }
56
  $field = wp_parse_args(
57
  $field,
@@ -112,6 +109,24 @@ class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
112
  return $options;
113
  }
114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  /**
116
  * Save meta value.
117
  *
@@ -124,14 +139,30 @@ class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
124
  if ( empty( $field['id'] ) || ! $field['save_field'] ) {
125
  return;
126
  }
127
- $new = array_unique( array_map( 'intval', (array) $new ) );
128
- $new = empty( $new ) ? null : $new;
129
 
130
  foreach ( $field['taxonomy'] as $taxonomy ) {
131
  wp_set_object_terms( $post_id, $new, $taxonomy );
132
  }
133
  }
134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  /**
136
  * Get raw meta value.
137
  *
@@ -209,4 +240,65 @@ class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
209
  esc_html( $value->name )
210
  );
211
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  }
44
  * - If multiple taxonomies: show 'Select a term'.
45
  * - If single taxonomy: show 'Select a %taxonomy_name%'.
46
  */
47
+ $placeholder = __( 'Select a term', 'meta-box' );
48
+ $taxonomy_name = self::get_taxonomy_singular_name( $field );
49
+ if ( $taxonomy_name ) {
50
+ // Translators: %s is the taxonomy singular label.
51
+ $placeholder = sprintf( __( 'Select a %s', 'meta-box' ), strtolower( $taxonomy_name ) );
 
 
 
52
  }
53
  $field = wp_parse_args(
54
  $field,
109
  return $options;
110
  }
111
 
112
+ /**
113
+ * Get meta values to save.
114
+ *
115
+ * @param mixed $new The submitted meta value.
116
+ * @param mixed $old The existing meta value.
117
+ * @param int $post_id The post ID.
118
+ * @param array $field The field parameters.
119
+ *
120
+ * @return array
121
+ */
122
+ public static function value( $new, $old, $post_id, $field ) {
123
+ $new = (array) $new;
124
+ $new[] = self::add_term( $field );
125
+ $new = array_unique( array_map( 'intval', array_filter( $new ) ) );
126
+
127
+ return $new;
128
+ }
129
+
130
  /**
131
  * Save meta value.
132
  *
139
  if ( empty( $field['id'] ) || ! $field['save_field'] ) {
140
  return;
141
  }
 
 
142
 
143
  foreach ( $field['taxonomy'] as $taxonomy ) {
144
  wp_set_object_terms( $post_id, $new, $taxonomy );
145
  }
146
  }
147
 
148
+ /**
149
+ * Add new terms if users created some.
150
+ *
151
+ * @param array $field Field settings.
152
+ * @return int|null Term ID if added successfully, null otherwise.
153
+ */
154
+ protected static function add_term( $field ) {
155
+ $term = filter_input( INPUT_POST, $field['id'] . '_new' );
156
+ if ( ! $field['add_new'] || ! $term || 1 !== count( $field['taxonomy'] ) ) {
157
+ return null;
158
+ }
159
+
160
+ $taxonomy = reset( $field['taxonomy'] );
161
+ $term = wp_insert_term( $term, $taxonomy );
162
+
163
+ return isset( $term['term_id'] ) ? $term['term_id'] : null;
164
+ }
165
+
166
  /**
167
  * Get raw meta value.
168
  *
240
  esc_html( $value->name )
241
  );
242
  }
243
+
244
+ /**
245
+ * Render "Add New" form
246
+ *
247
+ * @param array $field Field settings.
248
+ * @return string
249
+ */
250
+ public static function add_new_form( $field ) {
251
+ // Only add new term if field has only one taxonomy.
252
+ if ( 1 !== count( $field['taxonomy'] ) ) {
253
+ return '';
254
+ }
255
+
256
+ $taxonomy = reset( $field['taxonomy'] );
257
+ $taxonomy_object = get_taxonomy( $taxonomy );
258
+ if ( false === $taxonomy_object ) {
259
+ return '';
260
+ }
261
+
262
+ $html = '
263
+ <div class="rwmb-taxonomy-add">
264
+ <button class="rwmb-taxonomy-add-button">%s</button>
265
+ <div class="rwmb-taxonomy-add-form rwmb-hidden">
266
+ <input type="text" name="%s_new" size="30" placeholder="%s">
267
+ </div>
268
+ </div>';
269
+
270
+ $html = sprintf(
271
+ $html,
272
+ esc_html( $taxonomy_object->labels->add_new_item ),
273
+ esc_attr( $field['id'] ),
274
+ esc_attr( $taxonomy_object->labels->new_item_name )
275
+ );
276
+
277
+ return $html;
278
+ }
279
+
280
+ /**
281
+ * Enqueue scripts and styles.
282
+ */
283
+ public static function admin_enqueue_scripts() {
284
+ parent::admin_enqueue_scripts();
285
+ wp_enqueue_style( 'rwmb-taxonomy', RWMB_CSS_URL . 'taxonomy.css', array(), RWMB_VER );
286
+ wp_enqueue_script( 'rwmb-taxonomy', RWMB_JS_URL . 'taxonomy.js', array( 'jquery' ), RWMB_VER, true );
287
+ }
288
+
289
+ /**
290
+ * Get taxonomy singular name.
291
+ *
292
+ * @param array $field Field settings.
293
+ * @return string
294
+ */
295
+ protected static function get_taxonomy_singular_name( $field ) {
296
+ if ( 1 !== count( $field['taxonomy'] ) ) {
297
+ return '';
298
+ }
299
+ $taxonomy = reset( $field['taxonomy'] );
300
+ $taxonomy_object = get_taxonomy( $taxonomy );
301
+
302
+ return false === $taxonomy_object ? '' : $taxonomy_object->labels->singular_name;
303
+ }
304
  }
inc/functions.php CHANGED
@@ -255,7 +255,7 @@ if ( ! function_exists( 'rwmb_meta_shortcode' ) ) {
255
  $atts,
256
  array(
257
  'id' => '',
258
- 'object_id' => get_queried_object_id(),
259
  'attribute' => '',
260
  )
261
  );
255
  $atts,
256
  array(
257
  'id' => '',
258
+ 'object_id' => null,
259
  'attribute' => '',
260
  )
261
  );
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.3' );
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.18.0' );
22
 
23
  list( $path, $url ) = self::get_path( dirname( dirname( __FILE__ ) ) );
24
 
js/input-list.js CHANGED
@@ -18,12 +18,17 @@ jQuery( function ( $ ) {
18
  .on( 'clone', '.rwmb-input-list.rwmb-collapse input[type="checkbox"]', update );
19
  $( '.rwmb-input-list.rwmb-collapse input[type="checkbox"]' ).each( update );
20
 
21
- $( '.rwmb-input-list-select-all-none' ).toggle(
22
- function () {
23
- $( this ).parent().siblings( '.rwmb-input-list' ).find( 'input' ).prop( 'checked', true );
24
- },
25
- function () {
26
- $( this ).parent().siblings( '.rwmb-input-list' ).find( 'input' ).prop( 'checked', false );
27
  }
28
- );
 
 
 
 
 
29
  } );
18
  .on( 'clone', '.rwmb-input-list.rwmb-collapse input[type="checkbox"]', update );
19
  $( '.rwmb-input-list.rwmb-collapse input[type="checkbox"]' ).each( update );
20
 
21
+ $( document ).on( 'click', '.rwmb-input-list-select-all-none', function() {
22
+ var $this = $( this ),
23
+ checked = $this.data( 'checked' );
24
+
25
+ if ( undefined === checked ) {
26
+ checked = true;
27
  }
28
+
29
+ $this.parent().siblings( '.rwmb-input-list' ).find( 'input' ).prop( 'checked', checked );
30
+
31
+ checked = ! checked;
32
+ $this.data( 'checked', checked );
33
+ } );
34
  } );
js/osm-frontend.js CHANGED
@@ -33,7 +33,9 @@ jQuery( function( $ ) {
33
 
34
  // Set marker icon
35
  if ( options.marker_icon ) {
36
- markerOptions.icon = L.icon( options.marker_icon );
 
 
37
  }
38
 
39
  var marker = L.marker( center, markerOptions ).addTo( map )
33
 
34
  // Set marker icon
35
  if ( options.marker_icon ) {
36
+ markerOptions.icon = L.icon( {
37
+ iconUrl: options.marker_icon
38
+ } );
39
  }
40
 
41
  var marker = L.marker( center, markerOptions ).addTo( map )
js/slider.js CHANGED
@@ -1,7 +1,7 @@
1
  jQuery( function ( $ ) {
2
  'use strict';
3
 
4
- function rwmb_update_slider() {
5
  var $input = $( this ),
6
  $slider = $input.siblings( '.rwmb-slider' ),
7
  $valueLabel = $slider.siblings( '.rwmb-slider-value-label' ).find( 'span' ),
@@ -11,22 +11,26 @@ jQuery( function ( $ ) {
11
  $slider.html( '' );
12
  $valueLabel.text( value );
13
 
14
- value = options.range === true ? value.split( '|' ) : value;
15
- options.values = value;
 
 
 
 
16
 
17
  options.slide = function ( event, ui ) {
 
18
  if ( options.range === true ) {
19
- $input.val( ui.values[ 0 ] + '|' + ui.values[ 1 ] );
20
- $valueLabel.html( ui.values[ 0 ] + '|' + ui.values[ 1 ] );
21
- } else {
22
- $input.val( ui.value );
23
- $valueLabel.html( ui.value );
24
  }
 
 
 
25
  };
26
 
27
  $slider.slider( options );
28
  }
29
 
30
- $( '.rwmb-slider-value' ).each( rwmb_update_slider );
31
- $( document ).on( 'clone', '.rwmb-slider-value', rwmb_update_slider );
32
  } );
1
  jQuery( function ( $ ) {
2
  'use strict';
3
 
4
+ function update() {
5
  var $input = $( this ),
6
  $slider = $input.siblings( '.rwmb-slider' ),
7
  $valueLabel = $slider.siblings( '.rwmb-slider-value-label' ).find( 'span' ),
11
  $slider.html( '' );
12
  $valueLabel.text( value );
13
 
14
+ if ( true === options.range ) {
15
+ value = value.split( '|' );
16
+ options.values = value;
17
+ } else {
18
+ options.value = value;
19
+ }
20
 
21
  options.slide = function ( event, ui ) {
22
+ var value = ui.value;
23
  if ( options.range === true ) {
24
+ value = ui.values[ 0 ] + '|' + ui.values[ 1 ];
 
 
 
 
25
  }
26
+
27
+ $input.val( value );
28
+ $valueLabel.html( value );
29
  };
30
 
31
  $slider.slider( options );
32
  }
33
 
34
+ $( '.rwmb-slider-value' ).each( update );
35
+ $( document ).on( 'clone', '.rwmb-slider-value', update );
36
  } );
js/taxonomy.js ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ jQuery( function ( $ ) {
2
+ 'use strict';
3
+
4
+ $( document ).on( 'click', '.rwmb-taxonomy-add-button', function( e ) {
5
+ e.preventDefault();
6
+ this.nextElementSibling.classList.toggle( 'rwmb-hidden' );
7
+ } );
8
+ } );
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.3
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.18.0
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.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,12 +165,6 @@ To getting started with the plugin, please read the [Quick Start Guide](https://
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
 
176
  == Upgrade Notice ==
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.18.0
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
  [See full changelog here](https://metabox.io/changelog/).
169
 
170
  == Upgrade Notice ==