Meta Box - Version 4.8.2

Version Description

  • Fix: re-add code for backward compatibility for helper function
  • Fix: undefined 'class' attribute for button
  • Improvement: speedup the helper function
Download this release

Release Info

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

Code changes from version 4.8.1 to 4.8.2

inc/core.php CHANGED
@@ -10,6 +10,12 @@
10
  */
11
  class RWMB_Core
12
  {
 
 
 
 
 
 
13
  /**
14
  * Register hooks.
15
  */
@@ -65,10 +71,14 @@ class RWMB_Core
65
  * - prevents duplicated global variables.
66
  * - allows users to remove/hide registered meta boxes.
67
  */
68
- static public function get_meta_boxes()
69
  {
70
- $meta_boxes = apply_filters( 'rwmb_meta_boxes', array() );
71
- return empty( $meta_boxes ) || ! is_array( $meta_boxes ) ? array() : $meta_boxes;
 
 
 
 
72
  }
73
 
74
  /**
10
  */
11
  class RWMB_Core
12
  {
13
+ /**
14
+ * Stores all registered meta boxes
15
+ * @var array
16
+ */
17
+ private static $meta_boxes = null;
18
+
19
  /**
20
  * Register hooks.
21
  */
71
  * - prevents duplicated global variables.
72
  * - allows users to remove/hide registered meta boxes.
73
  */
74
+ public static function get_meta_boxes()
75
  {
76
+ if ( null === self::$meta_boxes )
77
+ {
78
+ self::$meta_boxes = apply_filters( 'rwmb_meta_boxes', array() );
79
+ self::$meta_boxes = empty( self::$meta_boxes ) || ! is_array( self::$meta_boxes ) ? array() : self::$meta_boxes;
80
+ }
81
+ return self::$meta_boxes;
82
  }
83
 
84
  /**
inc/field.php CHANGED
@@ -469,7 +469,7 @@ abstract class RWMB_Field
469
  * rwmb_the_field function later.
470
  *
471
  * @use self::get_value()
472
- * @see rwmb_the_field()
473
  *
474
  * @param array $field Field parameters
475
  * @param array $args Additional arguments. Rarely used. See specific fields for details
469
  * rwmb_the_field function later.
470
  *
471
  * @use self::get_value()
472
+ * @see rwmb_the_value()
473
  *
474
  * @param array $field Field parameters
475
  * @param array $args Additional arguments. Rarely used. See specific fields for details
inc/fields/button.php CHANGED
@@ -39,11 +39,8 @@ class RWMB_Button_Field extends RWMB_Field
39
  */
40
  static function get_attributes( $field, $value = null )
41
  {
42
- $attributes = $field['attributes'];
43
- $attributes = wp_parse_args( $attributes, array(
44
- 'id' => $field['id'],
45
- ) );
46
- $attributes['class'] .= 'button hide-if-no-js';
47
 
48
  return $attributes;
49
  }
39
  */
40
  static function get_attributes( $field, $value = null )
41
  {
42
+ $attributes = parent::get_attributes( $field, $value );
43
+ $attributes['class'] .= ' button hide-if-no-js';
 
 
 
44
 
45
  return $attributes;
46
  }
inc/fields/checkbox.php CHANGED
@@ -71,7 +71,7 @@ class RWMB_Checkbox_Field extends RWMB_Input_Field
71
  * rwmb_the_field function later.
72
  *
73
  * @use self::get_value()
74
- * @see rwmb_the_field()
75
  *
76
  * @param array $field Field parameters
77
  * @param array $args Additional arguments. Rarely used. See specific fields for details
71
  * rwmb_the_field function later.
72
  *
73
  * @use self::get_value()
74
+ * @see rwmb_the_value()
75
  *
76
  * @param array $field Field parameters
77
  * @param array $args Additional arguments. Rarely used. See specific fields for details
inc/fields/key-value.php CHANGED
@@ -124,7 +124,7 @@ abstract class RWMB_Key_Value_Field extends RWMB_Text_Field
124
  * Display unordered list of key - value pairs
125
  *
126
  * @use self::get_value()
127
- * @see rwmb_the_field()
128
  *
129
  * @param array $field Field parameters
130
  * @param array $args Additional arguments. Rarely used. See specific fields for details
124
  * Display unordered list of key - value pairs
125
  *
126
  * @use self::get_value()
127
+ * @see rwmb_the_value()
128
  *
129
  * @param array $field Field parameters
130
  * @param array $args Additional arguments. Rarely used. See specific fields for details
inc/fields/taxonomy-advanced.php CHANGED
@@ -77,7 +77,7 @@ class RWMB_Taxonomy_Advanced_Field extends RWMB_Taxonomy_Field
77
  'include' => $value,
78
  'hide_empty' => false,
79
  ), $args );
80
- $value = get_terms( $field['options']['taxonomy'], $args );
81
 
82
  // Get single value if necessary
83
  if ( ! $field['clone'] && ! $field['multiple'] )
77
  'include' => $value,
78
  'hide_empty' => false,
79
  ), $args );
80
+ $value = get_terms( $field['taxonomy'], $args );
81
 
82
  // Get single value if necessary
83
  if ( ! $field['clone'] && ! $field['multiple'] )
inc/functions.php CHANGED
@@ -14,7 +14,21 @@
14
  */
15
  function rwmb_meta( $key, $args = array(), $post_id = null )
16
  {
17
- return RWMB_Helper::meta( $key, $args, $post_id );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  }
19
 
20
  /**
@@ -27,7 +41,7 @@ function rwmb_meta( $key, $args = array(), $post_id = null )
27
  *
28
  * @return mixed false if field doesn't exist. Field value otherwise.
29
  */
30
- function rwmb_get_field( $field_id, $args = array(), $post_id = null )
31
  {
32
  $field = RWMB_Helper::find_field( $field_id );
33
 
@@ -36,13 +50,14 @@ function rwmb_get_field( $field_id, $args = array(), $post_id = null )
36
 
37
  /**
38
  * Allow developers to change the returned value of field
 
39
  *
40
  * @param mixed $value Field value
41
  * @param array $field Field parameter
42
  * @param array $args Additional arguments. Rarely used. See specific fields for details
43
  * @param int|null $post_id Post ID. null for current post. Optional.
44
  */
45
- $value = apply_filters( 'rwmb_get_field', $value, $field, $args, $post_id );
46
 
47
  return $value;
48
  }
@@ -57,7 +72,7 @@ function rwmb_get_field( $field_id, $args = array(), $post_id = null )
57
  *
58
  * @return string
59
  */
60
- function rwmb_the_field( $field_id, $args = array(), $post_id = null, $echo = true )
61
  {
62
  // Find field
63
  $field = RWMB_Helper::find_field( $field_id );
@@ -69,13 +84,14 @@ function rwmb_the_field( $field_id, $args = array(), $post_id = null, $echo = tr
69
 
70
  /**
71
  * Allow developers to change the returned value of field
 
72
  *
73
  * @param mixed $value Field HTML output
74
  * @param array $field Field parameter
75
  * @param array $args Additional arguments. Rarely used. See specific fields for details
76
  * @param int|null $post_id Post ID. null for current post. Optional.
77
  */
78
- $output = apply_filters( 'rwmb_the_field', $output, $field, $args, $post_id );
79
 
80
  if ( $echo )
81
  echo $output;
@@ -104,7 +120,7 @@ function rwmb_meta_shortcode( $atts )
104
  $post_id = $atts['post_id'];
105
  unset( $atts['meta_key'], $atts['post_id'] );
106
 
107
- return rwmb_the_field( $field_id, $atts, $post_id, false );
108
  }
109
 
110
  add_shortcode( 'rwmb_meta', 'rwmb_meta_shortcode' );
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
  /**
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
 
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
  }
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 );
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;
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' );
inc/helper.php CHANGED
@@ -9,45 +9,113 @@
9
  class RWMB_Helper
10
  {
11
  /**
12
- * Find field by field ID.
13
- * This function finds field in meta boxes registered by 'rwmb_meta_boxes' filter.
14
- *
15
- * @param string $field_id Field ID
16
- * @return array|false Field params (array) if success. False otherwise.
 
 
17
  */
18
- static function find_field( $field_id )
19
  {
20
  $meta_boxes = RWMB_Core::get_meta_boxes();
21
  foreach ( $meta_boxes as $meta_box )
22
  {
23
- $meta_box = RW_Meta_Box::normalize( $meta_box );
24
  foreach ( $meta_box['fields'] as $field )
25
  {
26
- if ( $field_id == $field['id'] )
27
  {
28
- return $field;
29
  }
30
  }
31
  }
32
- return false;
33
  }
34
 
35
  /**
36
- * Get post meta.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  *
38
  * @param string $key Meta key. Required.
39
  * @param int|null $post_id Post ID. null for current post. Optional
40
  * @param array $args Array of arguments. Optional.
 
41
  * @return mixed
42
  */
43
- static function meta( $key, $args = array(), $post_id = null )
44
  {
45
- $args = wp_parse_args( $args, array(
46
- 'type' => 'text',
 
 
 
47
  ) );
48
- $meta = in_array( $args['type'], array( 'oembed', 'map' ) ) ?
49
- rwmb_the_field( $key, $args, $post_id, false ) :
50
- rwmb_get_field( $key, $args, $post_id );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  return apply_filters( 'rwmb_meta', $meta, $key, $args, $post_id );
52
  }
53
  }
9
  class RWMB_Helper
10
  {
11
  /**
12
+ * Stores all registered fields
13
+ * @var array
14
+ */
15
+ private static $fields = array();
16
+
17
+ /**
18
+ * Hash all fields into an indexed array for search
19
  */
20
+ public static function hash_fields()
21
  {
22
  $meta_boxes = RWMB_Core::get_meta_boxes();
23
  foreach ( $meta_boxes as $meta_box )
24
  {
 
25
  foreach ( $meta_box['fields'] as $field )
26
  {
27
+ if ( ! empty( $field['id'] ) )
28
  {
29
+ self::$fields[$field['id']] = $field;
30
  }
31
  }
32
  }
 
33
  }
34
 
35
  /**
36
+ * Find field by field ID.
37
+ * This function finds field in meta boxes registered by 'rwmb_meta_boxes' filter.
38
+ *
39
+ * @param string $field_id Field ID
40
+ * @return array|false Field params (array) if success. False otherwise.
41
+ */
42
+ public static function find_field( $field_id )
43
+ {
44
+ if ( empty( self::$fields ) )
45
+ {
46
+ self::hash_fields();
47
+ }
48
+
49
+ $field = isset( self::$fields[$field_id] ) ? self::$fields[$field_id] : false;
50
+ return $field ? call_user_func( array( RW_Meta_Box::get_class_name( $field ), 'normalize' ), $field ) : false;
51
+ }
52
+
53
+ /**
54
+ * Get post meta
55
  *
56
  * @param string $key Meta key. Required.
57
  * @param int|null $post_id Post ID. null for current post. Optional
58
  * @param array $args Array of arguments. Optional.
59
+ *
60
  * @return mixed
61
  */
62
+ public static function meta( $key, $args = array(), $post_id = null )
63
  {
64
+ $post_id = empty( $post_id ) ? get_the_ID() : $post_id;
65
+ $args = wp_parse_args( $args, array(
66
+ 'type' => 'text',
67
+ 'multiple' => false,
68
+ 'clone' => false,
69
  ) );
70
+ // Always set 'multiple' true for following field types
71
+ if ( in_array( $args['type'], array( 'checkbox_list', 'autocomplete', 'file', 'file_advanced', 'image', 'image_advanced', 'plupload_image', 'thickbox_image' ) ) )
72
+ {
73
+ $args['multiple'] = true;
74
+ }
75
+
76
+ $field = array(
77
+ 'id' => $key,
78
+ 'type' => $args['type'],
79
+ 'clone' => $args['clone'],
80
+ 'multiple' => $args['multiple'],
81
+ );
82
+ $class = RW_Meta_Box::get_class_name( $field );
83
+
84
+ switch ( $args['type'] )
85
+ {
86
+ case 'taxonomy_advanced':
87
+ if ( empty( $args['taxonomy'] ) )
88
+ {
89
+ break;
90
+ }
91
+ $meta = get_post_meta( $post_id, $key, ! $args['multiple'] );
92
+ $term_ids = wp_parse_id_list( $meta );
93
+ // Allow to pass more arguments to "get_terms"
94
+ $func_args = wp_parse_args( array(
95
+ 'include' => $term_ids,
96
+ 'hide_empty' => false,
97
+ ), $args );
98
+ unset( $func_args['type'], $func_args['taxonomy'], $func_args['multiple'] );
99
+ $meta = get_terms( $args['taxonomy'], $func_args );
100
+ break;
101
+ case 'taxonomy':
102
+ $meta = empty( $args['taxonomy'] ) ? array() : get_the_terms( $post_id, $args['taxonomy'] );
103
+ break;
104
+ case 'map':
105
+ $field = array(
106
+ 'id' => $key,
107
+ 'multiple' => false,
108
+ 'clone' => false,
109
+ );
110
+ $meta = RWMB_Map_Field::the_value( $field, $args, $post_id );
111
+ break;
112
+ case 'oembed':
113
+ $meta = RWMB_OEmbed_Field::the_value( $field, $args, $post_id );
114
+ break;
115
+ default:
116
+ $meta = call_user_func( array( $class, 'get_value' ), $field, $args, $post_id );
117
+ break;
118
+ }
119
  return apply_filters( 'rwmb_meta', $meta, $key, $args, $post_id );
120
  }
121
  }
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.1' );
32
 
33
  list( $path, $url ) = self::get_path();
34
 
@@ -124,10 +124,15 @@ class RWMB_Loader
124
  // Plugin core
125
  new RWMB_Core;
126
 
127
- // Validation module
128
- new RWMB_Validation;
129
-
130
- // Public functions
131
- require RWMB_INC_DIR . 'functions.php';
 
 
 
 
 
132
  }
133
  }
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
 
124
  // Plugin core
125
  new RWMB_Core;
126
 
127
+ if ( is_admin() )
128
+ {
129
+ // Validation module
130
+ new RWMB_Validation;
131
+ }
132
+ else
133
+ {
134
+ // Public functions
135
+ require RWMB_INC_DIR . 'functions.php';
136
+ }
137
  }
138
  }
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.1
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.2
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.1
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,11 @@ To getting started with the plugin API, please read [this tutorial](https://meta
77
 
78
  == Changelog ==
79
 
 
 
 
 
 
80
  = 4.8.1 =
81
 
82
  * Fix: select multiple value with post, user and taxonomy
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
 
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
83
+ * Improvement: speedup the helper function
84
+
85
  = 4.8.1 =
86
 
87
  * Fix: select multiple value with post, user and taxonomy