Meta Box - Version 5.6.10

Version Description

  • 2022-12-06 =
  • Fix padding for images in custom blocks
  • Fix sidebar::query not compatible with object_choice::query
  • Fix compatibility with custom models in MB Custom Table. Closes #1466.
  • Modernize code: use short array, add type hints, remove comments
Download this release

Release Info

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

Code changes from version 5.6.9 to 5.6.10

Files changed (77) hide show
  1. css/button-group.css +40 -112
  2. css/media.css +1 -0
  3. css/switch.css +20 -30
  4. inc/about/about.php +15 -81
  5. inc/about/dashboard.php +17 -23
  6. inc/about/sections/review.php +9 -0
  7. inc/about/sections/support.php +5 -5
  8. inc/autoloader.php +2 -10
  9. inc/clone.php +2 -15
  10. inc/core.php +1 -4
  11. inc/field.php +17 -62
  12. inc/fields/autocomplete.php +9 -22
  13. inc/fields/background.php +79 -105
  14. inc/fields/button-group.php +3 -12
  15. inc/fields/button.php +6 -18
  16. inc/fields/checkbox-list.php +0 -6
  17. inc/fields/checkbox.php +1 -13
  18. inc/fields/choice.php +8 -24
  19. inc/fields/color.php +16 -34
  20. inc/fields/custom-html.php +1 -7
  21. inc/fields/date.php +1 -14
  22. inc/fields/datetime.php +9 -20
  23. inc/fields/divider.php +1 -12
  24. inc/fields/fieldset-text.php +4 -27
  25. inc/fields/file-input.php +6 -16
  26. inc/fields/file-upload.php +8 -23
  27. inc/fields/heading.php +2 -13
  28. inc/fields/image-advanced.php +11 -26
  29. inc/fields/image-select.php +6 -14
  30. inc/fields/image-upload.php +1 -10
  31. inc/fields/image.php +0 -9
  32. inc/fields/input.php +1 -1
  33. inc/fields/key-value.php +7 -31
  34. inc/fields/map.php +57 -100
  35. inc/fields/media.php +1 -2
  36. inc/fields/multiple-values.php +0 -6
  37. inc/fields/number.php +10 -23
  38. inc/fields/object-choice.php +1 -3
  39. inc/fields/oembed.php +11 -32
  40. inc/fields/osm.php +42 -63
  41. inc/fields/password.php +0 -6
  42. inc/fields/post.php +32 -65
  43. inc/fields/range.php +5 -17
  44. inc/fields/select-advanced.php +19 -37
  45. inc/fields/select-tree.php +2 -11
  46. inc/fields/select.php +8 -23
  47. inc/fields/sidebar.php +7 -29
  48. inc/fields/single-image.php +6 -15
  49. inc/fields/slider.php +13 -28
  50. inc/fields/switch.php +6 -18
  51. inc/fields/taxonomy.php +51 -102
  52. inc/fields/text-list.php +5 -14
  53. inc/fields/textarea.php +20 -32
  54. inc/fields/time.php +0 -9
  55. inc/fields/user.php +26 -54
  56. inc/fields/video.php +22 -40
  57. inc/fields/wysiwyg.php +11 -26
  58. inc/functions.php +25 -33
  59. inc/helpers/array.php +6 -22
  60. inc/helpers/field.php +9 -34
  61. inc/helpers/string.php +2 -16
  62. inc/helpers/value.php +1 -1
  63. inc/interfaces/storage.php +2 -9
  64. inc/loader.php +1 -1
  65. inc/media-modal.php +9 -40
  66. inc/meta-box.php +43 -143
  67. inc/sanitizer.php +1 -14
  68. inc/storages/base.php +1 -8
  69. inc/update/notification.php +19 -47
  70. inc/update/option.php +7 -28
  71. inc/validation.php +3 -7
  72. inc/walkers/base.php +2 -8
  73. inc/walkers/select-tree.php +3 -9
  74. inc/walkers/select.php +1 -7
  75. js/button-group.js +3 -3
  76. meta-box.php +1 -1
  77. readme.txt +8 -2
css/button-group.css CHANGED
@@ -1,154 +1,82 @@
1
  .rwmb-button-input-list {
2
- margin: 0;
3
- display: inline-block;
4
- }
5
- .rwmb-button-input-list li {
6
- margin-bottom: 0;
7
- list-style: none;
8
  }
 
9
  .rwmb-button-input-list .rwmb-button_group {
10
  display: none;
11
  }
12
- .rwmb-button-input-list li label {
13
  display: block;
14
- border: #ccc solid 1px;
15
  position: relative;
16
  z-index: 1;
17
  padding: 5px 10px;
18
  background: #fff;
19
  }
20
- .rwmb-button-input-list li label.selected {
21
- border-color: #0073aa;
22
- background: #0073aa;
23
  color: #fff;
24
  z-index: 2;
25
  }
26
- /* Layout not inline
27
- -------------------------------------------------*/
28
- .rwmb-button-input-list:not(.rwmb-inline) li label {
29
  border-top-width: 0;
30
  }
31
- .rwmb-button-input-list:not(.rwmb-inline) li:first-child label {
32
- border-top-width: 1px;
33
- }
34
- .rwmb-button-input-list:not(.rwmb-inline) li label.selected {
35
- border-bottom: 1px solid #fff;
36
  }
37
- .rwmb-button-input-list:not(.rwmb-inline) li:last-child label.selected {
38
- border-bottom-color: #0073aa;
39
- }
40
- .rwmb-button-input-list:not(.rwmb-inline) > li:first-child:not(:last-child) label {
41
  border-top-left-radius: 3px;
42
  border-top-right-radius: 3px;
43
  }
44
- .rwmb-button-input-list:not(.rwmb-inline) > li:last-child:not(:first-child) label {
45
  border-bottom-right-radius: 3px;
46
  border-bottom-left-radius: 3px;
47
  }
48
- /* Layout inline
49
- ---------------------------------------------*/
50
- .rwmb-button-input-list.rwmb-inline li {
51
- display: inline-block;
52
  }
53
- .rwmb-button-input-list.rwmb-inline li label {
54
  border-left-width: 0;
55
  }
56
- .rwmb-button-input-list.rwmb-inline li:first-child label {
57
- border-left-width: 1px;
58
- }
59
- .rwmb-button-input-list.rwmb-inline li label.selected {
60
- border-right-color: rgb(255, 255, 255);
61
  }
62
- .rwmb-button-input-list.rwmb-inline li:last-child label.selected {
63
- border-right-color: #0073aa;
64
- }
65
- .rwmb-button-input-list.rwmb-inline > li:first-child:not(:last-child) label {
66
  border-top-left-radius: 3px;
67
  border-bottom-left-radius: 3px;
68
  }
69
- .rwmb-button-input-list.rwmb-inline > li:last-child:not(:first-child) label {
70
  border-top-right-radius: 3px;
71
  border-bottom-right-radius: 3px;
72
  }
73
 
74
  /* Admin color schemes */
75
- .admin-color-blue .rwmb-button-input-list li label.selected {
76
- border-color: #e1a948;
77
- background: #e1a948;
78
- }
79
- .admin-color-blue .rwmb-button-input-list:not(.rwmb-inline) li:last-child label.selected {
80
- border-bottom-color: #e1a948
81
- }
82
- .admin-color-blue .rwmb-button-input-list.rwmb-inline li:last-child label.selected {
83
- border-right-color: #e1a948
84
- }
85
- .admin-color-coffee .rwmb-button-input-list li label.selected {
86
- border-color: #c7a589;
87
- background: #c7a589;
88
- }
89
- .admin-color-coffee .rwmb-button-input-list:not(.rwmb-inline) li:last-child label.selected {
90
- border-bottom-color: #c7a589;
91
- }
92
- .admin-color-coffee .rwmb-button-input-list.rwmb-inline li:last-child label.selected {
93
- border-right-color: #c7a589;
94
- }
95
- .admin-color-ectoplasm .rwmb-button-input-list li label.selected {
96
- border-color: #a3b745;
97
- background: #a3b745;
98
- }
99
- .admin-color-ectoplasm .rwmb-button-input-list:not(.rwmb-inline) li:last-child label.selected {
100
- border-bottom-color: #a3b745;
101
- }
102
- .admin-color-ectoplasm .rwmb-button-input-list.rwmb-inline li:last-child label.selected {
103
- border-right-color: #a3b745;
104
- }
105
- .admin-color-light .rwmb-button-input-list li label.selected {
106
- border-color: #04a4cc;
107
- background: #04a4cc;
108
- }
109
- .admin-color-light .rwmb-button-input-list:not(.rwmb-inline) li:last-child label.selected {
110
- border-bottom-color: #04a4cc
111
- }
112
- .admin-color-light .rwmb-button-input-list.rwmb-inline li:last-child label.selected {
113
- border-right-color: #04a4cc
114
- }
115
- .admin-color-midnight .rwmb-button-input-list li label.selected {
116
- border-color: #e14d43;
117
- background: #e14d43;
118
- }
119
- .admin-color-midnight .rwmb-button-input-list:not(.rwmb-inline) li:last-child label.selected {
120
- border-bottom-color: #e14d43
121
- }
122
- .admin-color-midnight .rwmb-button-input-list.rwmb-inline li:last-child label.selected {
123
- border-right-color: #e14d43
124
- }
125
- .admin-color-modern .rwmb-button-input-list li label.selected {
126
- border-color: #3858e9;
127
- background: #3858e9;
128
- }
129
- .admin-color-modern .rwmb-button-input-list:not(.rwmb-inline) li:last-child label.selected {
130
- border-bottom-color: #3858e9
131
- }
132
- .admin-color-modern .rwmb-button-input-list.rwmb-inline li:last-child label.selected {
133
- border-right-color: #3858e9
134
  }
135
- .admin-color-ocean .rwmb-button-input-list li label.selected {
136
- border-color: #9ebaa0;
137
- background: #9ebaa0;
138
  }
139
- .admin-color-ocean .rwmb-button-input-list:not(.rwmb-inline) li:last-child label.selected {
140
- border-bottom-color: #9ebaa0
141
  }
142
- .admin-color-ocean .rwmb-button-input-list.rwmb-inline li:last-child label.selected {
143
- border-right-color: #9ebaa0
144
  }
145
- .admin-color-sunrise .rwmb-button-input-list li label.selected {
146
- border-color: #dd823b;
147
- background: #dd823b;
148
  }
149
- .admin-color-sunrise .rwmb-button-input-list:not(.rwmb-inline) li:last-child label.selected {
150
- border-bottom-color: #dd823b
151
  }
152
- .admin-color-sunrise .rwmb-button-input-list.rwmb-inline li:last-child label.selected {
153
- border-right-color: #dd823b
154
  }
 
 
 
1
  .rwmb-button-input-list {
2
+ --color: var(--wp-admin-theme-color, #2271b1);
 
 
 
 
 
3
  }
4
+
5
  .rwmb-button-input-list .rwmb-button_group {
6
  display: none;
7
  }
8
+ .rwmb-button-input-list label {
9
  display: block;
10
+ border: 1px solid #8c8f94;
11
  position: relative;
12
  z-index: 1;
13
  padding: 5px 10px;
14
  background: #fff;
15
  }
16
+ .rwmb-button-input-list .selected {
17
+ border-color: var(--color);
18
+ background: var(--color);
19
  color: #fff;
20
  z-index: 2;
21
  }
22
+
23
+ /* Layout not inline */
24
+ .rwmb-button-input-list:not(.rwmb-inline) label:not(:first-child) {
25
  border-top-width: 0;
26
  }
27
+ .rwmb-button-input-list:not(.rwmb-inline) .selected:not(:last-child) {
28
+ border-bottom-color: rgba(255, 255, 255, .25);
 
 
 
29
  }
30
+ .rwmb-button-input-list:not(.rwmb-inline) > label:first-child:not(:last-child) {
 
 
 
31
  border-top-left-radius: 3px;
32
  border-top-right-radius: 3px;
33
  }
34
+ .rwmb-button-input-list:not(.rwmb-inline) > label:last-child:not(:first-child) {
35
  border-bottom-right-radius: 3px;
36
  border-bottom-left-radius: 3px;
37
  }
38
+
39
+ /* Layout inline */
40
+ .rwmb-button-input-list.rwmb-inline {
41
+ display: flex;
42
  }
43
+ .rwmb-button-input-list.rwmb-inline label:not(:first-child) {
44
  border-left-width: 0;
45
  }
46
+ .rwmb-button-input-list.rwmb-inline .selected:not(:last-child) {
47
+ border-right-color: rgba(255, 255, 255, .25);
 
 
 
48
  }
49
+ .rwmb-button-input-list.rwmb-inline > label:first-child:not(:last-child) {
 
 
 
50
  border-top-left-radius: 3px;
51
  border-bottom-left-radius: 3px;
52
  }
53
+ .rwmb-button-input-list.rwmb-inline > label:last-child:not(:first-child) {
54
  border-top-right-radius: 3px;
55
  border-bottom-right-radius: 3px;
56
  }
57
 
58
  /* Admin color schemes */
59
+ .admin-color-blue .rwmb-button-input-list {
60
+ --color: var(--wp-admin-theme-color, #e1a948);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  }
62
+ .admin-color-coffee .rwmb-button-input-list {
63
+ --color: var(--wp-admin-theme-color, #c7a589);
 
64
  }
65
+ .admin-color-ectoplasm .rwmb-button-input-list {
66
+ --color: var(--wp-admin-theme-color, #a3b745);
67
  }
68
+ .admin-color-light .rwmb-button-input-list {
69
+ --color: var(--wp-admin-theme-color, #04a4cc);
70
  }
71
+ .admin-color-midnight .rwmb-button-input-list {
72
+ --color: var(--wp-admin-theme-color, #e14d43);
 
73
  }
74
+ .admin-color-modern .rwmb-button-input-list {
75
+ --color: var(--wp-admin-theme-color, #3858e9);
76
  }
77
+ .admin-color-ocean .rwmb-button-input-list {
78
+ --color: var(--wp-admin-theme-color, #9ebaa0);
79
  }
80
+ .admin-color-sunrise .rwmb-button-input-list {
81
+ --color: var(--wp-admin-theme-color, #dd823b);
82
+ }
css/media.css CHANGED
@@ -1,5 +1,6 @@
1
  .rwmb-media-list {
2
  margin: 0;
 
3
  overflow: hidden;
4
  }
5
  .rwmb-edit-media,
1
  .rwmb-media-list {
2
  margin: 0;
3
+ padding: 0;
4
  overflow: hidden;
5
  }
6
  .rwmb-edit-media,
css/switch.css CHANGED
@@ -1,5 +1,3 @@
1
- /* style switch
2
- -----------------------------*/
3
  .rwmb-switch-label {
4
  position: relative;
5
  display: inline-block;
@@ -9,6 +7,8 @@
9
  min-width: 40px;
10
  height: 22px;
11
  box-sizing: border-box;
 
 
12
  }
13
 
14
  .rwmb-switch.rwmb-switch {
@@ -16,8 +16,8 @@
16
  }
17
 
18
  .rwmb-switch:checked + .rwmb-switch-status .rwmb-switch-slider {
19
- background-color: #0073aa;
20
- box-shadow: 0 0 1px #0073aa;
21
  }
22
 
23
  .rwmb-switch:checked + .rwmb-switch-status .rwmb-switch-slider:before {
@@ -42,7 +42,6 @@
42
  right: 0;
43
  bottom: 0;
44
  z-index: 15;
45
- -webkit-transition: .4s;
46
  transition: .4s;
47
  }
48
 
@@ -55,7 +54,6 @@
55
  bottom: 2px;
56
  z-index: 99;
57
  background-color: white;
58
- -webkit-transition: .4s;
59
  transition: .4s;
60
  border-radius: 2px;
61
  }
@@ -94,35 +92,27 @@
94
  }
95
 
96
  /* Admin color schemes */
97
- .admin-color-blue .rwmb-switch:checked + .rwmb-switch-status .rwmb-switch-slider {
98
- background-color: #e1a948;
99
- box-shadow: 0 0 1px #e1a948;
100
  }
101
- .admin-color-coffee .rwmb-switch:checked + .rwmb-switch-status .rwmb-switch-slider {
102
- background-color: #c7a589;
103
- box-shadow: 0 0 1px #c7a589;
104
  }
105
- .admin-color-ectoplasm .rwmb-switch:checked + .rwmb-switch-status .rwmb-switch-slider {
106
- background-color: #a3b745;
107
- box-shadow: 0 0 1px #a3b745;
108
  }
109
- .admin-color-light .rwmb-switch:checked + .rwmb-switch-status .rwmb-switch-slider {
110
- background-color: #04a4cc;
111
- box-shadow: 0 0 1px #04a4cc;
112
  }
113
- .admin-color-midnight .rwmb-switch:checked + .rwmb-switch-status .rwmb-switch-slider {
114
- background-color: #e14d43;
115
- box-shadow: 0 0 1px #e14d43;
116
  }
117
- .admin-color-modern .rwmb-switch:checked + .rwmb-switch-status .rwmb-switch-slider {
118
- background-color: #3858e9;
119
- box-shadow: 0 0 1px #3858e9;
120
  }
121
- .admin-color-ocean .rwmb-switch:checked + .rwmb-switch-status .rwmb-switch-slider {
122
- background-color: #9ebaa0;
123
- box-shadow: 0 0 1px #9ebaa0;
124
  }
125
- .admin-color-sunrise .rwmb-switch:checked + .rwmb-switch-status .rwmb-switch-slider {
126
- background-color: #dd823b;
127
- box-shadow: 0 0 1px #dd823b;
128
  }
 
 
1
  .rwmb-switch-label {
2
  position: relative;
3
  display: inline-block;
7
  min-width: 40px;
8
  height: 22px;
9
  box-sizing: border-box;
10
+
11
+ --color: var(--wp-admin-theme-color, #2271b1);
12
  }
13
 
14
  .rwmb-switch.rwmb-switch {
16
  }
17
 
18
  .rwmb-switch:checked + .rwmb-switch-status .rwmb-switch-slider {
19
+ background-color: var(--color);
20
+ box-shadow: 0 0 1px var(--color);
21
  }
22
 
23
  .rwmb-switch:checked + .rwmb-switch-status .rwmb-switch-slider:before {
42
  right: 0;
43
  bottom: 0;
44
  z-index: 15;
 
45
  transition: .4s;
46
  }
47
 
54
  bottom: 2px;
55
  z-index: 99;
56
  background-color: white;
 
57
  transition: .4s;
58
  border-radius: 2px;
59
  }
92
  }
93
 
94
  /* Admin color schemes */
95
+ .admin-color-blue .rwmb-switch-label {
96
+ --color: var(--wp-admin-theme-color, #e1a948);
 
97
  }
98
+ .admin-color-coffee .rwmb-switch-label {
99
+ --color: var(--wp-admin-theme-color, #c7a589);
 
100
  }
101
+ .admin-color-ectoplasm .rwmb-switch-label {
102
+ --color: var(--wp-admin-theme-color, #a3b745);
 
103
  }
104
+ .admin-color-light .rwmb-switch-label {
105
+ --color: var(--wp-admin-theme-color, #04a4cc);
 
106
  }
107
+ .admin-color-midnight .rwmb-switch-label {
108
+ --color: var(--wp-admin-theme-color, #e14d43);
 
109
  }
110
+ .admin-color-modern .rwmb-switch-label {
111
+ --color: var(--wp-admin-theme-color, #3858e9);
 
112
  }
113
+ .admin-color-ocean .rwmb-switch-label {
114
+ --color: var(--wp-admin-theme-color, #9ebaa0);
 
115
  }
116
+ .admin-color-sunrise .rwmb-switch-label {
117
+ --color: var(--wp-admin-theme-color, #dd823b);
 
118
  }
inc/about/about.php CHANGED
@@ -1,12 +1,6 @@
1
  <?php
2
  /**
3
  * Add about page for the Meta Box plugin.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * About page class.
10
  */
11
  class RWMB_About {
12
  /**
@@ -25,32 +19,22 @@ class RWMB_About {
25
  $this->update_checker = $update_checker;
26
  }
27
 
28
- /**
29
- * Init hooks.
30
- */
31
  public function init() {
32
  // Add links to about page in the plugin action links.
33
- add_filter( 'plugin_action_links_meta-box/meta-box.php', array( $this, 'plugin_links' ), 20 );
34
 
35
  // Add a shared top-level admin menu and Dashboard page. Use priority 5 to show Dashboard at the top.
36
- add_action( 'admin_menu', array( $this, 'add_menu' ), 5 );
37
- add_action( 'admin_menu', array( $this, 'add_submenu' ), 5 );
38
 
39
  // If no admin menu, then hide the About page.
40
- add_action( 'admin_head', array( $this, 'hide_page' ) );
41
 
42
  // Redirect to about page after activation.
43
- add_action( 'activated_plugin', array( $this, 'redirect' ), 10, 2 );
44
  }
45
 
46
- /**
47
- * Add links to About page.
48
- *
49
- * @param array $links Array of plugin links.
50
- *
51
- * @return array
52
- */
53
- public function plugin_links( $links ) {
54
  $links[] = '<a href="' . esc_url( $this->get_menu_link() ) . '">' . esc_html__( 'About', 'meta-box' ) . '</a>';
55
  if ( ! $this->update_checker->has_extensions() ) {
56
  $links[] = '<a href="https://metabox.io/pricing/" style="color: #39b54a; font-weight: bold">' . esc_html__( 'Go Pro', 'meta-box' ) . '</a>';
@@ -58,9 +42,6 @@ class RWMB_About {
58
  return $links;
59
  }
60
 
61
- /**
62
- * Register admin page.
63
- */
64
  public function add_menu() {
65
  if ( ! $this->has_menu() ) {
66
  return;
@@ -75,9 +56,6 @@ class RWMB_About {
75
  );
76
  }
77
 
78
- /**
79
- * Add submenu for the About page.
80
- */
81
  public function add_submenu() {
82
  $parent_menu = $this->has_menu() ? 'meta-box' : $this->get_parent_menu();
83
  $about = add_submenu_page(
@@ -86,29 +64,15 @@ class RWMB_About {
86
  __( 'Dashboard', 'meta-box' ),
87
  'activate_plugins',
88
  'meta-box',
89
- array( $this, 'render' )
90
  );
91
- add_action( "load-$about", array( $this, 'load_about' ) );
92
- }
93
-
94
- /**
95
- * Functions and hooks for about page.
96
- */
97
- public function load_about() {
98
- $this->enqueue();
99
- add_filter( 'admin_footer_text', array( $this, 'change_footer_text' ) );
100
  }
101
 
102
- /**
103
- * Hide about page from the admin menu.
104
- */
105
  public function hide_page() {
106
  remove_submenu_page( $this->get_parent_menu(), 'meta-box' );
107
  }
108
 
109
- /**
110
- * Render admin page.
111
- */
112
  public function render() {
113
  ?>
114
  <div class="wrap">
@@ -133,6 +97,7 @@ class RWMB_About {
133
  <div id="postbox-container-1" class="postbox-container">
134
  <?php
135
  include __DIR__ . '/sections/products.php';
 
136
  if ( ! $this->update_checker->has_extensions() ) {
137
  include __DIR__ . '/sections/upgrade.php';
138
  }
@@ -144,20 +109,9 @@ class RWMB_About {
144
  <?php
145
  }
146
 
147
- /**
148
- * Enqueue CSS and JS.
149
- */
150
  public function enqueue() {
151
- wp_enqueue_style( 'meta-box-about', RWMB_URL . 'inc/about/css/about.css', array(), RWMB_VER );
152
- wp_enqueue_script( 'meta-box-about', RWMB_URL . 'inc/about/js/about.js', array( 'jquery' ), RWMB_VER, true );
153
- }
154
-
155
- /**
156
- * Change WordPress footer text on about page.
157
- */
158
- public function change_footer_text() {
159
- // Translators: %1$s - link to review form.
160
- echo wp_kses_post( sprintf( __( 'Please rate <strong>Meta Box</strong> <a href="%1$s" target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733;</a> on <a href="%1$s" target="_blank">WordPress.org</a> to help us spread the word. Thank you from the Meta Box team!', 'meta-box' ), 'https://wordpress.org/support/view/plugin-reviews/meta-box?filter=5#new-post' ) );
161
  }
162
 
163
  /**
@@ -179,40 +133,20 @@ class RWMB_About {
179
  die;
180
  }
181
 
182
- /**
183
- * Get link to the plugin admin menu.
184
- *
185
- * @return string
186
- */
187
- protected function get_menu_link() {
188
  $menu = $this->has_menu() ? 'admin.php?page=meta-box' : $this->get_parent_menu() . '?page=meta-box';
189
  return admin_url( $menu );
190
  }
191
 
192
- /**
193
- * Get default parent menu, which is Plugins.
194
- *
195
- * @return string
196
- */
197
- protected function get_parent_menu() {
198
  return 'plugins.php';
199
  }
200
 
201
- /**
202
- * Check if the plugin has a top-level admin menu.
203
- *
204
- * @return bool
205
- */
206
- protected function has_menu() {
207
  return apply_filters( 'rwmb_admin_menu', false );
208
  }
209
 
210
- /**
211
- * Check if Meta Box is bundled by TGM Activation Class.
212
- *
213
- * @return bool
214
- */
215
- protected function is_bundled() {
216
  // @codingStandardsIgnoreLine
217
  foreach ( $_REQUEST as $key => $value ) {
218
  if ( false !== strpos( $key, 'tgmpa' ) || ( ! is_array( $value ) && false !== strpos( $value, 'tgmpa' ) ) ) {
1
  <?php
2
  /**
3
  * Add about page for the Meta Box plugin.
 
 
 
 
 
 
4
  */
5
  class RWMB_About {
6
  /**
19
  $this->update_checker = $update_checker;
20
  }
21
 
 
 
 
22
  public function init() {
23
  // Add links to about page in the plugin action links.
24
+ add_filter( 'plugin_action_links_meta-box/meta-box.php', [ $this, 'plugin_links' ], 20 );
25
 
26
  // Add a shared top-level admin menu and Dashboard page. Use priority 5 to show Dashboard at the top.
27
+ add_action( 'admin_menu', [ $this, 'add_menu' ], 5 );
28
+ add_action( 'admin_menu', [ $this, 'add_submenu' ], 5 );
29
 
30
  // If no admin menu, then hide the About page.
31
+ add_action( 'admin_head', [ $this, 'hide_page' ] );
32
 
33
  // Redirect to about page after activation.
34
+ add_action( 'activated_plugin', [ $this, 'redirect' ], 10, 2 );
35
  }
36
 
37
+ public function plugin_links( array $links ) : array {
 
 
 
 
 
 
 
38
  $links[] = '<a href="' . esc_url( $this->get_menu_link() ) . '">' . esc_html__( 'About', 'meta-box' ) . '</a>';
39
  if ( ! $this->update_checker->has_extensions() ) {
40
  $links[] = '<a href="https://metabox.io/pricing/" style="color: #39b54a; font-weight: bold">' . esc_html__( 'Go Pro', 'meta-box' ) . '</a>';
42
  return $links;
43
  }
44
 
 
 
 
45
  public function add_menu() {
46
  if ( ! $this->has_menu() ) {
47
  return;
56
  );
57
  }
58
 
 
 
 
59
  public function add_submenu() {
60
  $parent_menu = $this->has_menu() ? 'meta-box' : $this->get_parent_menu();
61
  $about = add_submenu_page(
64
  __( 'Dashboard', 'meta-box' ),
65
  'activate_plugins',
66
  'meta-box',
67
+ [ $this, 'render' ]
68
  );
69
+ add_action( "load-$about", [ $this, 'enqueue' ] );
 
 
 
 
 
 
 
 
70
  }
71
 
 
 
 
72
  public function hide_page() {
73
  remove_submenu_page( $this->get_parent_menu(), 'meta-box' );
74
  }
75
 
 
 
 
76
  public function render() {
77
  ?>
78
  <div class="wrap">
97
  <div id="postbox-container-1" class="postbox-container">
98
  <?php
99
  include __DIR__ . '/sections/products.php';
100
+ include __DIR__ . '/sections/review.php';
101
  if ( ! $this->update_checker->has_extensions() ) {
102
  include __DIR__ . '/sections/upgrade.php';
103
  }
109
  <?php
110
  }
111
 
 
 
 
112
  public function enqueue() {
113
+ wp_enqueue_style( 'meta-box-about', RWMB_URL . 'inc/about/css/about.css', [], RWMB_VER );
114
+ wp_enqueue_script( 'meta-box-about', RWMB_URL . 'inc/about/js/about.js', [ 'jquery' ], RWMB_VER, true );
 
 
 
 
 
 
 
 
115
  }
116
 
117
  /**
133
  die;
134
  }
135
 
136
+ private function get_menu_link() : string {
 
 
 
 
 
137
  $menu = $this->has_menu() ? 'admin.php?page=meta-box' : $this->get_parent_menu() . '?page=meta-box';
138
  return admin_url( $menu );
139
  }
140
 
141
+ private function get_parent_menu() : string {
 
 
 
 
 
142
  return 'plugins.php';
143
  }
144
 
145
+ private function has_menu() : bool {
 
 
 
 
 
146
  return apply_filters( 'rwmb_admin_menu', false );
147
  }
148
 
149
+ private function is_bundled() : bool {
 
 
 
 
 
150
  // @codingStandardsIgnoreLine
151
  foreach ( $_REQUEST as $key => $value ) {
152
  if ( false !== strpos( $key, 'tgmpa' ) || ( ! is_array( $value ) && false !== strpos( $value, 'tgmpa' ) ) ) {
inc/about/dashboard.php CHANGED
@@ -5,29 +5,23 @@ class RWMB_Dashboard {
5
  private $translations;
6
  private $slug;
7
 
8
- public function __construct( $feed_url, $link, $translations ) {
9
  $this->feed_url = $feed_url;
10
  $this->link = $link;
11
  $this->translations = $translations;
12
  $this->slug = sanitize_title( $translations['title'] );
13
 
14
  $transient_name = $this->get_transient_name();
15
- add_filter( "transient_$transient_name", array( $this, 'add_news' ) );
16
- add_action( "wp_ajax_{$this->slug}-dismiss-news", array( $this, 'ajax_dismiss' ) );
17
  }
18
 
19
- private function get_transient_name() {
20
- include ABSPATH . WPINC . '/version.php';
21
- global $wp_version;
22
-
23
- $locale = function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
24
- $prefix = version_compare( $wp_version, '4.8', '>=') ? 'dash_v2_' : 'dash_';
25
- $widget_id = 'dashboard_primary';
26
-
27
- return version_compare( $wp_version, '4.3', '>=' ) ? $prefix . md5( "{$widget_id}_{$locale}" ) : 'dash_' . md5( $widget_id );
28
  }
29
 
30
- public function add_news( $value ) {
31
  $is_dismissed = get_user_meta( get_current_user_id(), $this->slug . '_dismiss_news', true );
32
  $is_dismissed = apply_filters( 'rwmb_dismiss_dashboard_widget', $is_dismissed );
33
  if ( $is_dismissed ) {
@@ -41,15 +35,15 @@ class RWMB_Dashboard {
41
  return $value . $this->get_html() . $script;
42
  }
43
 
44
- private function get_html() {
45
  $cache_key = $this->slug . '-news';
46
- $output = get_transient( $cache_key );
47
- if ( false !== $output) {
48
  return $output;
49
  }
50
 
51
- $feeds = array(
52
- $this->slug => array(
53
  'link' => $this->link,
54
  'url' => $this->feed_url,
55
  'title' => $this->translations['title'],
@@ -57,13 +51,13 @@ class RWMB_Dashboard {
57
  'show_summary' => 0,
58
  'show_author' => 0,
59
  'show_date' => 0,
60
- )
61
- );
62
  ob_start();
63
  wp_dashboard_primary_output( 'dashboard_primary', $feeds );
64
- $output = ob_get_clean();
65
 
66
- $output = preg_replace( '/<a(.+?)>(.+?)<\/a>/i', '<a$1>' . esc_html( $this->translations['title'] ) . ': $2</a>', $output );
67
  $output = str_replace( '<li>', '<li class="' . esc_attr( $this->slug ) . '-news-item"><a href="#" class="dashicons dashicons-no-alt" title="' . esc_attr( $this->translations['dismiss_tooltip'] ) . '" style="float: right; box-shadow: none; margin-left: 5px;"></a>', $output );
68
 
69
  set_transient( $cache_key, $output, DAY_IN_SECONDS );
@@ -93,4 +87,4 @@ class RWMB_Dashboard {
93
  update_user_meta( get_current_user_id(), $this->slug . '_dismiss_news', 1 );
94
  wp_send_json_success();
95
  }
96
- }
5
  private $translations;
6
  private $slug;
7
 
8
+ public function __construct( string $feed_url, string $link, array $translations ) {
9
  $this->feed_url = $feed_url;
10
  $this->link = $link;
11
  $this->translations = $translations;
12
  $this->slug = sanitize_title( $translations['title'] );
13
 
14
  $transient_name = $this->get_transient_name();
15
+ add_filter( "transient_$transient_name", [ $this, 'add_news' ] );
16
+ add_action( "wp_ajax_{$this->slug}-dismiss-news", [ $this, 'ajax_dismiss' ] );
17
  }
18
 
19
+ private function get_transient_name() : string {
20
+ $locale = get_user_locale();
21
+ return 'dash_v2_' . md5( "dashboard_primary_{$locale}" );
 
 
 
 
 
 
22
  }
23
 
24
+ public function add_news( string $value ) : string {
25
  $is_dismissed = get_user_meta( get_current_user_id(), $this->slug . '_dismiss_news', true );
26
  $is_dismissed = apply_filters( 'rwmb_dismiss_dashboard_widget', $is_dismissed );
27
  if ( $is_dismissed ) {
35
  return $value . $this->get_html() . $script;
36
  }
37
 
38
+ private function get_html() : string {
39
  $cache_key = $this->slug . '-news';
40
+ $output = get_transient( $cache_key );
41
+ if ( false !== $output ) {
42
  return $output;
43
  }
44
 
45
+ $feeds = [
46
+ $this->slug => [
47
  'link' => $this->link,
48
  'url' => $this->feed_url,
49
  'title' => $this->translations['title'],
51
  'show_summary' => 0,
52
  'show_author' => 0,
53
  'show_date' => 0,
54
+ ],
55
+ ];
56
  ob_start();
57
  wp_dashboard_primary_output( 'dashboard_primary', $feeds );
58
+ $output = (string) ob_get_clean();
59
 
60
+ $output = (string) preg_replace( '/<a(.+?)>(.+?)<\/a>/i', '<a$1>' . esc_html( $this->translations['title'] ) . ': $2</a>', $output );
61
  $output = str_replace( '<li>', '<li class="' . esc_attr( $this->slug ) . '-news-item"><a href="#" class="dashicons dashicons-no-alt" title="' . esc_attr( $this->translations['dismiss_tooltip'] ) . '" style="float: right; box-shadow: none; margin-left: 5px;"></a>', $output );
62
 
63
  set_transient( $cache_key, $output, DAY_IN_SECONDS );
87
  update_user_meta( get_current_user_id(), $this->slug . '_dismiss_news', 1 );
88
  wp_send_json_success();
89
  }
90
+ }
inc/about/sections/review.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <div class="postbox">
2
+ <h3 class="hndle">
3
+ <span><?php esc_html_e( 'Write a review for Meta Box', 'meta-box' ) ?></span>
4
+ </h3>
5
+ <div class="inside">
6
+ <p><?php esc_html_e( 'If you like Meta Box, please write a review on WordPress.org to help us spread the word. We really appreciate that!', 'meta-box' ) ?></p>
7
+ <p><a href="https://wordpress.org/support/plugin/meta-box/reviews/?filter=5" class="button" target="_blank" rel="noopenner noreferrer"><?php esc_html_e( 'Write a review', 'meta-box' ) ?></a></p>
8
+ </div>
9
+ </div>
inc/about/sections/support.php CHANGED
@@ -1,11 +1,11 @@
1
  <div id="support" class="gt-tab-pane">
2
  <p class="about-description">
3
  <?php
4
- $allowed_html = array(
5
- 'a' => array(
6
- 'href' => array(),
7
- ),
8
- );
9
  // Translators: %s - link to documentation.
10
  echo wp_kses( sprintf( __( 'Still need help with Meta Box? We offer excellent support for you. But don\'t forget to check our <a href="%s">documentation</a> first.', 'meta-box' ), 'https://docs.metabox.io?utm_source=WordPress&utm_medium=link&utm_campaign=plugin' ), $allowed_html );
11
  ?>
1
  <div id="support" class="gt-tab-pane">
2
  <p class="about-description">
3
  <?php
4
+ $allowed_html = [
5
+ 'a' => [
6
+ 'href' => [],
7
+ ],
8
+ ];
9
  // Translators: %s - link to documentation.
10
  echo wp_kses( sprintf( __( 'Still need help with Meta Box? We offer excellent support for you. But don\'t forget to check our <a href="%s">documentation</a> first.', 'meta-box' ), 'https://docs.metabox.io?utm_source=WordPress&utm_medium=link&utm_campaign=plugin' ), $allowed_html );
11
  ?>
inc/autoloader.php CHANGED
@@ -20,18 +20,10 @@ class RWMB_Autoloader {
20
  ];
21
  }
22
 
23
- /**
24
- * Register autoloader for plugin classes.
25
- */
26
  public function register() {
27
  spl_autoload_register( [ $this, 'autoload' ] );
28
  }
29
 
30
- /**
31
- * Autoload classes.
32
- *
33
- * @param string $class Class name.
34
- */
35
  public function autoload( string $class ) {
36
  foreach ( $this->dirs as $dir ) {
37
  if (
@@ -50,11 +42,11 @@ class RWMB_Autoloader {
50
  $file = strtolower( str_replace( '_', '-', $file ) ) . '.php';
51
  }
52
  $file = $dir['dir'] . $file;
53
- $this->require_file( $file );
54
  }
55
  }
56
 
57
- protected function require_file( $file ) {
58
  if ( file_exists( $file ) ) {
59
  require_once $file;
60
  }
20
  ];
21
  }
22
 
 
 
 
23
  public function register() {
24
  spl_autoload_register( [ $this, 'autoload' ] );
25
  }
26
 
 
 
 
 
 
27
  public function autoload( string $class ) {
28
  foreach ( $this->dirs as $dir ) {
29
  if (
42
  $file = strtolower( str_replace( '_', '-', $file ) ) . '.php';
43
  }
44
  $file = $dir['dir'] . $file;
45
+ $this->require( $file );
46
  }
47
  }
48
 
49
+ private function require( string $file ) {
50
  if ( file_exists( $file ) ) {
51
  require_once $file;
52
  }
inc/clone.php CHANGED
@@ -3,22 +3,9 @@
3
  * The clone module, allowing users to clone (duplicate) fields.
4
  */
5
  class RWMB_Clone {
6
- /**
7
- * Get clone field HTML.
8
- *
9
- * @param mixed $meta The meta value.
10
- * @param array $field The field parameters.
11
- *
12
- * @return string
13
- */
14
- public static function html( $meta, $field ) {
15
  $field_html = '';
16
 
17
- /**
18
- * Note: $meta must contain value so that the foreach loop runs!
19
- *
20
- * @see meta()
21
- */
22
  foreach ( $meta as $index => $sub_meta ) {
23
  $sub_field = $field;
24
  $sub_field['field_name'] = $field['field_name'] . "[{$index}]";
@@ -73,7 +60,7 @@ class RWMB_Clone {
73
  *
74
  * @return mixed
75
  */
76
- public static function value( $new, $old, $object_id, $field ) {
77
  if ( ! is_array( $new ) ) {
78
  $new = [];
79
  }
3
  * The clone module, allowing users to clone (duplicate) fields.
4
  */
5
  class RWMB_Clone {
6
+ public static function html( array $meta, array $field ) : string {
 
 
 
 
 
 
 
 
7
  $field_html = '';
8
 
 
 
 
 
 
9
  foreach ( $meta as $index => $sub_meta ) {
10
  $sub_field = $field;
11
  $sub_field['field_name'] = $field['field_name'] . "[{$index}]";
60
  *
61
  * @return mixed
62
  */
63
+ public static function value( $new, $old, $object_id, array $field ) {
64
  if ( ! is_array( $new ) ) {
65
  $new = [];
66
  }
inc/core.php CHANGED
@@ -16,9 +16,6 @@ class RWMB_Core {
16
  load_plugin_textdomain( 'meta-box', false, plugin_basename( RWMB_DIR ) . '/languages/' );
17
  }
18
 
19
- /**
20
- * Add links to Documentation in plugin's list of action links.
21
- */
22
  public function plugin_links( array $links ) : array {
23
  $links[] = '<a href="https://docs.metabox.io">' . esc_html__( 'Docs', 'meta-box' ) . '</a>';
24
  return $links;
@@ -71,7 +68,7 @@ class RWMB_Core {
71
  }
72
  }
73
 
74
- public function render_meta_boxes_for_context( WP_Post $post ) {
75
  $hook = current_filter();
76
  $context = 'edit_form_top' === $hook ? 'form_top' : substr( $hook, 10 );
77
  do_meta_boxes( null, $context, $post );
16
  load_plugin_textdomain( 'meta-box', false, plugin_basename( RWMB_DIR ) . '/languages/' );
17
  }
18
 
 
 
 
19
  public function plugin_links( array $links ) : array {
20
  $links[] = '<a href="https://docs.metabox.io">' . esc_html__( 'Docs', 'meta-box' ) . '</a>';
21
  return $links;
68
  }
69
  }
70
 
71
+ public function render_meta_boxes_for_context( $post ) {
72
  $hook = current_filter();
73
  $context = 'edit_form_top' === $hook ? 'form_top' : substr( $hook, 10 );
74
  do_meta_boxes( null, $context, $post );
inc/field.php CHANGED
@@ -3,25 +3,11 @@
3
  * The field base class.
4
  * This is the parent class of all custom fields defined by the plugin, which defines all the common methods.
5
  * Fields must inherit this class and overwrite methods with its own.
6
- *
7
- * @package Meta Box
8
- */
9
-
10
- /**
11
- * The field base class.
12
  */
13
  abstract class RWMB_Field {
14
- /**
15
- * Add actions.
16
- */
17
- public static function add_actions() {
18
- }
19
 
20
- /**
21
- * Enqueue scripts and styles.
22
- */
23
- public static function admin_enqueue_scripts() {
24
- }
25
 
26
  /**
27
  * Show field HTML
@@ -33,11 +19,11 @@ abstract class RWMB_Field {
33
  * @param bool $saved Whether the meta box is saved at least once.
34
  * @param int $post_id Post ID.
35
  */
36
- public static function show( $field, $saved, $post_id = 0 ) {
37
  $meta = self::call( $field, 'meta', $post_id, $saved );
38
  $meta = self::filter( 'field_meta', $meta, $field, $saved );
39
 
40
- $begin = self::call( $field, 'begin_html', $meta );
41
  $begin = self::filter( 'begin_html', $begin, $field, $meta );
42
 
43
  // Separate code for cloneable and non-cloneable fields to make easy to maintain.
@@ -67,7 +53,7 @@ abstract class RWMB_Field {
67
  );
68
  $outer_html = self::filter( 'outer_html', $outer_html, $field, $meta );
69
 
70
- echo $outer_html; // WPCS: XSS OK.
71
  }
72
 
73
  /**
@@ -82,15 +68,7 @@ abstract class RWMB_Field {
82
  return '';
83
  }
84
 
85
- /**
86
- * Show begin HTML markup for fields.
87
- *
88
- * @param mixed $meta Meta value.
89
- * @param array $field Field parameters.
90
- *
91
- * @return string
92
- */
93
- public static function begin_html( $meta, $field ) {
94
  $id = $field['attributes']['id'] ?? $field['id'];
95
  $required = $field['required'] || ! empty( $field['attributes']['required'] );
96
 
@@ -121,31 +99,16 @@ abstract class RWMB_Field {
121
  return $label . $input_open;
122
  }
123
 
124
- /**
125
- * Show end HTML markup for fields.
126
- */
127
- public static function end_html( array $field ) : string {
128
  return RWMB_Clone::add_clone_button( $field ) . static::input_description( $field ) . '</div>';
129
  }
130
 
131
- /**
132
- * Display field label description.
133
- *
134
- * @param array $field Field parameters.
135
- * @return string
136
- */
137
- protected static function label_description( $field ) {
138
  $id = $field['id'] ? ' id="' . esc_attr( $field['id'] ) . '-label-description"' : '';
139
  return $field['label_description'] ? "<p{$id} class='description'>{$field['label_description']}</p>" : '';
140
  }
141
 
142
- /**
143
- * Display field description.
144
- *
145
- * @param array $field Field parameters.
146
- * @return string
147
- */
148
- protected static function input_description( $field ) {
149
  $id = $field['id'] ? ' id="' . esc_attr( $field['id'] ) . '-description"' : '';
150
  return $field['desc'] ? "<p{$id} class='description'>{$field['desc']}</p>" : '';
151
  }
@@ -238,7 +201,7 @@ abstract class RWMB_Field {
238
  * @param int $object_id The object ID.
239
  * @param array $field The field settings.
240
  */
241
- public static function process_value( $value, $object_id, $field ) {
242
  $old_value = self::call( $field, 'raw_meta', $object_id );
243
 
244
  // Allow field class change the value.
@@ -404,14 +367,7 @@ abstract class RWMB_Field {
404
  return $attributes;
405
  }
406
 
407
- /**
408
- * Renders an attribute array into an html attributes string.
409
- *
410
- * @param array $attributes HTML attributes.
411
- *
412
- * @return string
413
- */
414
- public static function render_attributes( $attributes ) {
415
  $output = '';
416
 
417
  $attributes = array_filter( $attributes, 'RWMB_Helpers_Value::is_valid_for_attribute' );
@@ -435,9 +391,9 @@ abstract class RWMB_Field {
435
  * Each field can extend this function and add more data to the returned value.
436
  * See specific field classes for details.
437
  *
438
- * @param array $field Field parameters.
439
- * @param array $args Additional arguments. Rarely used. See specific fields for details.
440
- * @param int|null $post_id Post ID. null for current post. Optional.
441
  *
442
  * @return mixed Field value
443
  */
@@ -456,7 +412,7 @@ abstract class RWMB_Field {
456
 
457
  // Make sure meta value is an array for cloneable and multiple fields.
458
  if ( $field['clone'] || $field['multiple'] ) {
459
- $value = is_array( $value ) && $value ? $value : [];
460
  }
461
 
462
  return $value;
@@ -559,9 +515,8 @@ abstract class RWMB_Field {
559
  if ( is_string( $check ) ) {
560
  $method = array_shift( $args );
561
  $field = reset( $args ); // Keep field as 1st param.
562
- }
563
- // Params: field, method name, other params.
564
- else {
565
  $field = array_shift( $args );
566
  $method = array_shift( $args );
567
 
3
  * The field base class.
4
  * This is the parent class of all custom fields defined by the plugin, which defines all the common methods.
5
  * Fields must inherit this class and overwrite methods with its own.
 
 
 
 
 
 
6
  */
7
  abstract class RWMB_Field {
8
+ public static function add_actions() {}
 
 
 
 
9
 
10
+ public static function admin_enqueue_scripts() {}
 
 
 
 
11
 
12
  /**
13
  * Show field HTML
19
  * @param bool $saved Whether the meta box is saved at least once.
20
  * @param int $post_id Post ID.
21
  */
22
+ public static function show( array $field, bool $saved, $post_id = 0 ) {
23
  $meta = self::call( $field, 'meta', $post_id, $saved );
24
  $meta = self::filter( 'field_meta', $meta, $field, $saved );
25
 
26
+ $begin = static::begin_html( $field );
27
  $begin = self::filter( 'begin_html', $begin, $field, $meta );
28
 
29
  // Separate code for cloneable and non-cloneable fields to make easy to maintain.
53
  );
54
  $outer_html = self::filter( 'outer_html', $outer_html, $field, $meta );
55
 
56
+ echo $outer_html; // phpcs:ignore WordPress.Security.EscapeOutput
57
  }
58
 
59
  /**
68
  return '';
69
  }
70
 
71
+ protected static function begin_html( array $field ) : string {
 
 
 
 
 
 
 
 
72
  $id = $field['attributes']['id'] ?? $field['id'];
73
  $required = $field['required'] || ! empty( $field['attributes']['required'] );
74
 
99
  return $label . $input_open;
100
  }
101
 
102
+ protected static function end_html( array $field ) : string {
 
 
 
103
  return RWMB_Clone::add_clone_button( $field ) . static::input_description( $field ) . '</div>';
104
  }
105
 
106
+ protected static function label_description( array $field ) : string {
 
 
 
 
 
 
107
  $id = $field['id'] ? ' id="' . esc_attr( $field['id'] ) . '-label-description"' : '';
108
  return $field['label_description'] ? "<p{$id} class='description'>{$field['label_description']}</p>" : '';
109
  }
110
 
111
+ protected static function input_description( array $field ) : string {
 
 
 
 
 
 
112
  $id = $field['id'] ? ' id="' . esc_attr( $field['id'] ) . '-description"' : '';
113
  return $field['desc'] ? "<p{$id} class='description'>{$field['desc']}</p>" : '';
114
  }
201
  * @param int $object_id The object ID.
202
  * @param array $field The field settings.
203
  */
204
+ public static function process_value( $value, $object_id, array $field ) {
205
  $old_value = self::call( $field, 'raw_meta', $object_id );
206
 
207
  // Allow field class change the value.
367
  return $attributes;
368
  }
369
 
370
+ public static function render_attributes( array $attributes ) : string {
 
 
 
 
 
 
 
371
  $output = '';
372
 
373
  $attributes = array_filter( $attributes, 'RWMB_Helpers_Value::is_valid_for_attribute' );
391
  * Each field can extend this function and add more data to the returned value.
392
  * See specific field classes for details.
393
  *
394
+ * @param array $field Field parameters.
395
+ * @param array $args Additional arguments. Rarely used. See specific fields for details.
396
+ * @param ?int $post_id Post ID.
397
  *
398
  * @return mixed Field value
399
  */
412
 
413
  // Make sure meta value is an array for cloneable and multiple fields.
414
  if ( $field['clone'] || $field['multiple'] ) {
415
+ $value = is_array( $value ) && ! empty( $value ) ? $value : [];
416
  }
417
 
418
  return $value;
515
  if ( is_string( $check ) ) {
516
  $method = array_shift( $args );
517
  $field = reset( $args ); // Keep field as 1st param.
518
+ } else {
519
+ // Params: field, method name, other params.
 
520
  $field = array_shift( $args );
521
  $method = array_shift( $args );
522
 
inc/fields/autocomplete.php CHANGED
@@ -1,28 +1,15 @@
1
  <?php
2
  /**
3
  * The autocomplete field.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Autocomplete field class.
10
  */
11
  class RWMB_Autocomplete_Field extends RWMB_Multiple_Values_Field {
12
- /**
13
- * Enqueue scripts and styles.
14
- */
15
  public static function admin_enqueue_scripts() {
16
- wp_enqueue_style( 'rwmb-autocomplete', RWMB_CSS_URL . 'autocomplete.css', '', RWMB_VER );
17
- wp_enqueue_script( 'rwmb-autocomplete', RWMB_JS_URL . 'autocomplete.js', array( 'jquery-ui-autocomplete' ), RWMB_VER, true );
18
 
19
- RWMB_Helpers_Field::localize_script_once(
20
- 'rwmb-autocomplete',
21
- 'RWMB_Autocomplete',
22
- array(
23
- 'delete' => __( 'Delete', 'meta-box' ),
24
- )
25
- );
26
  }
27
 
28
  /**
@@ -34,19 +21,19 @@ class RWMB_Autocomplete_Field extends RWMB_Multiple_Values_Field {
34
  */
35
  public static function html( $meta, $field ) {
36
  if ( ! is_array( $meta ) ) {
37
- $meta = array( $meta );
38
  }
39
 
40
  $field = apply_filters( 'rwmb_autocomplete_field', $field, $meta );
41
  $options = $field['options'];
42
 
43
  if ( is_array( $field['options'] ) ) {
44
- $options = array();
45
  foreach ( $field['options'] as $value => $label ) {
46
- $options[] = array(
47
  'value' => $value,
48
  'label' => $label,
49
- );
50
  }
51
  $options = wp_json_encode( $options );
52
  }
1
  <?php
2
  /**
3
  * The autocomplete field.
 
 
 
 
 
 
4
  */
5
  class RWMB_Autocomplete_Field extends RWMB_Multiple_Values_Field {
 
 
 
6
  public static function admin_enqueue_scripts() {
7
+ wp_enqueue_style( 'rwmb-autocomplete', RWMB_CSS_URL . 'autocomplete.css', [], RWMB_VER );
8
+ wp_enqueue_script( 'rwmb-autocomplete', RWMB_JS_URL . 'autocomplete.js', [ 'jquery-ui-autocomplete' ], RWMB_VER, true );
9
 
10
+ RWMB_Helpers_Field::localize_script_once( 'rwmb-autocomplete', 'RWMB_Autocomplete', [
11
+ 'delete' => __( 'Delete', 'meta-box' ),
12
+ ] );
 
 
 
 
13
  }
14
 
15
  /**
21
  */
22
  public static function html( $meta, $field ) {
23
  if ( ! is_array( $meta ) ) {
24
+ $meta = [ $meta ];
25
  }
26
 
27
  $field = apply_filters( 'rwmb_autocomplete_field', $field, $meta );
28
  $options = $field['options'];
29
 
30
  if ( is_array( $field['options'] ) ) {
31
+ $options = [];
32
  foreach ( $field['options'] as $value => $label ) {
33
+ $options[] = [
34
  'value' => $value,
35
  'label' => $label,
36
+ ];
37
  }
38
  $options = wp_json_encode( $options );
39
  }
inc/fields/background.php CHANGED
@@ -1,30 +1,19 @@
1
  <?php
2
  /**
3
  * The background field.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * The Background field.
10
  */
11
  class RWMB_Background_Field extends RWMB_Field {
12
- /**
13
- * Enqueue scripts and styles.
14
- */
15
  public static function admin_enqueue_scripts() {
16
- wp_enqueue_style( 'rwmb-background', RWMB_CSS_URL . 'background.css', '', RWMB_VER );
17
 
18
  $args = func_get_args();
19
  $field = reset( $args );
20
- $color = RWMB_Color_Field::normalize(
21
- array(
22
- 'type' => 'color',
23
- 'id' => "{$field['id']}_color",
24
- 'field_name' => "{$field['field_name']}[color]",
25
- 'alpha_channel' => true,
26
- )
27
- );
28
  RWMB_Color_Field::admin_enqueue_scripts( $color );
29
  RWMB_File_Input_Field::admin_enqueue_scripts();
30
  }
@@ -38,118 +27,103 @@ class RWMB_Background_Field extends RWMB_Field {
38
  * @return string
39
  */
40
  public static function html( $meta, $field ) {
41
- $meta = wp_parse_args(
42
- $meta,
43
- array(
44
- 'color' => '',
45
- 'image' => '',
46
- 'repeat' => '',
47
- 'attachment' => '',
48
- 'position' => '',
49
- 'size' => '',
50
- )
51
- );
52
 
53
  $output = '<div class="rwmb-background-row">';
54
 
55
  // Color.
56
- $color = RWMB_Color_Field::normalize(
57
- array(
58
- 'type' => 'color',
59
- 'id' => "{$field['id']}_color",
60
- 'field_name' => "{$field['field_name']}[color]",
61
- 'alpha_channel' => true,
62
- )
63
- );
64
  $output .= RWMB_Color_Field::html( $meta['color'], $color );
65
 
66
  $output .= '</div><!-- .rwmb-background-row -->';
67
  $output .= '<div class="rwmb-background-row">';
68
 
69
  // Image.
70
- $image = RWMB_File_Input_Field::normalize(
71
- array(
72
- 'type' => 'file_input',
73
- 'id' => "{$field['id']}_image",
74
- 'field_name' => "{$field['field_name']}[image]",
75
- 'placeholder' => __( 'Background Image', 'meta-box' ),
76
- )
77
- );
78
  $output .= RWMB_File_Input_Field::html( $meta['image'], $image );
79
 
80
  $output .= '</div><!-- .rwmb-background-row -->';
81
  $output .= '<div class="rwmb-background-row">';
82
 
83
  // Repeat.
84
- $repeat = RWMB_Select_Field::normalize(
85
- array(
86
- 'type' => 'select',
87
- 'id' => "{$field['id']}_repeat",
88
- 'field_name' => "{$field['field_name']}[repeat]",
89
- 'placeholder' => esc_html__( '-- Repeat --', 'meta-box' ),
90
- 'options' => array(
91
- 'no-repeat' => esc_html__( 'No Repeat', 'meta-box' ),
92
- 'repeat' => esc_html__( 'Repeat All', 'meta-box' ),
93
- 'repeat-x' => esc_html__( 'Repeat Horizontally', 'meta-box' ),
94
- 'repeat-y' => esc_html__( 'Repeat Vertically', 'meta-box' ),
95
- 'inherit' => esc_html__( 'Inherit', 'meta-box' ),
96
- ),
97
- )
98
- );
99
  $output .= RWMB_Select_Field::html( $meta['repeat'], $repeat );
100
 
101
  // Position.
102
- $position = RWMB_Select_Field::normalize(
103
- array(
104
- 'type' => 'select',
105
- 'id' => "{$field['id']}_position",
106
- 'field_name' => "{$field['field_name']}[position]",
107
- 'placeholder' => esc_html__( '-- Position --', 'meta-box' ),
108
- 'options' => array(
109
- 'top left' => esc_html__( 'Top Left', 'meta-box' ),
110
- 'top center' => esc_html__( 'Top Center', 'meta-box' ),
111
- 'top right' => esc_html__( 'Top Right', 'meta-box' ),
112
- 'center left' => esc_html__( 'Center Left', 'meta-box' ),
113
- 'center center' => esc_html__( 'Center Center', 'meta-box' ),
114
- 'center right' => esc_html__( 'Center Right', 'meta-box' ),
115
- 'bottom left' => esc_html__( 'Bottom Left', 'meta-box' ),
116
- 'bottom center' => esc_html__( 'Bottom Center', 'meta-box' ),
117
- 'bottom right' => esc_html__( 'Bottom Right', 'meta-box' ),
118
- ),
119
- )
120
- );
121
  $output .= RWMB_Select_Field::html( $meta['position'], $position );
122
 
123
  // Attachment.
124
- $attachment = RWMB_Select_Field::normalize(
125
- array(
126
- 'type' => 'select',
127
- 'id' => "{$field['id']}_attachment",
128
- 'field_name' => "{$field['field_name']}[attachment]",
129
- 'placeholder' => esc_html__( '-- Attachment --', 'meta-box' ),
130
- 'options' => array(
131
- 'fixed' => esc_html__( 'Fixed', 'meta-box' ),
132
- 'scroll' => esc_html__( 'Scroll', 'meta-box' ),
133
- 'inherit' => esc_html__( 'Inherit', 'meta-box' ),
134
- ),
135
- )
136
- );
137
  $output .= RWMB_Select_Field::html( $meta['attachment'], $attachment );
138
 
139
  // Size.
140
- $size = RWMB_Select_Field::normalize(
141
- array(
142
- 'type' => 'select',
143
- 'id' => "{$field['id']}_size",
144
- 'field_name' => "{$field['field_name']}[size]",
145
- 'placeholder' => esc_html__( '-- Size --', 'meta-box' ),
146
- 'options' => array(
147
- 'inherit' => esc_html__( 'Inherit', 'meta-box' ),
148
- 'cover' => esc_html__( 'Cover', 'meta-box' ),
149
- 'contain' => esc_html__( 'Contain', 'meta-box' ),
150
- ),
151
- )
152
- );
153
  $output .= RWMB_Select_Field::html( $meta['size'], $size );
154
  $output .= '</div><!-- .rwmb-background-row -->';
155
 
1
  <?php
2
  /**
3
  * The background field.
 
 
 
 
 
 
4
  */
5
  class RWMB_Background_Field extends RWMB_Field {
 
 
 
6
  public static function admin_enqueue_scripts() {
7
+ wp_enqueue_style( 'rwmb-background', RWMB_CSS_URL . 'background.css', [], RWMB_VER );
8
 
9
  $args = func_get_args();
10
  $field = reset( $args );
11
+ $color = RWMB_Color_Field::normalize( [
12
+ 'type' => 'color',
13
+ 'id' => "{$field['id']}_color",
14
+ 'field_name' => "{$field['field_name']}[color]",
15
+ 'alpha_channel' => true,
16
+ ] );
 
 
17
  RWMB_Color_Field::admin_enqueue_scripts( $color );
18
  RWMB_File_Input_Field::admin_enqueue_scripts();
19
  }
27
  * @return string
28
  */
29
  public static function html( $meta, $field ) {
30
+ $meta = wp_parse_args( $meta, [
31
+ 'color' => '',
32
+ 'image' => '',
33
+ 'repeat' => '',
34
+ 'attachment' => '',
35
+ 'position' => '',
36
+ 'size' => '',
37
+ ] );
 
 
 
38
 
39
  $output = '<div class="rwmb-background-row">';
40
 
41
  // Color.
42
+ $color = RWMB_Color_Field::normalize( [
43
+ 'type' => 'color',
44
+ 'id' => "{$field['id']}_color",
45
+ 'field_name' => "{$field['field_name']}[color]",
46
+ 'alpha_channel' => true,
47
+ ] );
 
 
48
  $output .= RWMB_Color_Field::html( $meta['color'], $color );
49
 
50
  $output .= '</div><!-- .rwmb-background-row -->';
51
  $output .= '<div class="rwmb-background-row">';
52
 
53
  // Image.
54
+ $image = RWMB_File_Input_Field::normalize( [
55
+ 'type' => 'file_input',
56
+ 'id' => "{$field['id']}_image",
57
+ 'field_name' => "{$field['field_name']}[image]",
58
+ 'placeholder' => __( 'Background Image', 'meta-box' ),
59
+ ] );
 
 
60
  $output .= RWMB_File_Input_Field::html( $meta['image'], $image );
61
 
62
  $output .= '</div><!-- .rwmb-background-row -->';
63
  $output .= '<div class="rwmb-background-row">';
64
 
65
  // Repeat.
66
+ $repeat = RWMB_Select_Field::normalize( [
67
+ 'type' => 'select',
68
+ 'id' => "{$field['id']}_repeat",
69
+ 'field_name' => "{$field['field_name']}[repeat]",
70
+ 'placeholder' => esc_html__( '-- Repeat --', 'meta-box' ),
71
+ 'options' => [
72
+ 'no-repeat' => esc_html__( 'No Repeat', 'meta-box' ),
73
+ 'repeat' => esc_html__( 'Repeat All', 'meta-box' ),
74
+ 'repeat-x' => esc_html__( 'Repeat Horizontally', 'meta-box' ),
75
+ 'repeat-y' => esc_html__( 'Repeat Vertically', 'meta-box' ),
76
+ 'inherit' => esc_html__( 'Inherit', 'meta-box' ),
77
+ ],
78
+ ] );
 
 
79
  $output .= RWMB_Select_Field::html( $meta['repeat'], $repeat );
80
 
81
  // Position.
82
+ $position = RWMB_Select_Field::normalize( [
83
+ 'type' => 'select',
84
+ 'id' => "{$field['id']}_position",
85
+ 'field_name' => "{$field['field_name']}[position]",
86
+ 'placeholder' => esc_html__( '-- Position --', 'meta-box' ),
87
+ 'options' => [
88
+ 'top left' => esc_html__( 'Top Left', 'meta-box' ),
89
+ 'top center' => esc_html__( 'Top Center', 'meta-box' ),
90
+ 'top right' => esc_html__( 'Top Right', 'meta-box' ),
91
+ 'center left' => esc_html__( 'Center Left', 'meta-box' ),
92
+ 'center center' => esc_html__( 'Center Center', 'meta-box' ),
93
+ 'center right' => esc_html__( 'Center Right', 'meta-box' ),
94
+ 'bottom left' => esc_html__( 'Bottom Left', 'meta-box' ),
95
+ 'bottom center' => esc_html__( 'Bottom Center', 'meta-box' ),
96
+ 'bottom right' => esc_html__( 'Bottom Right', 'meta-box' ),
97
+ ],
98
+ ] );
 
 
99
  $output .= RWMB_Select_Field::html( $meta['position'], $position );
100
 
101
  // Attachment.
102
+ $attachment = RWMB_Select_Field::normalize( [
103
+ 'type' => 'select',
104
+ 'id' => "{$field['id']}_attachment",
105
+ 'field_name' => "{$field['field_name']}[attachment]",
106
+ 'placeholder' => esc_html__( '-- Attachment --', 'meta-box' ),
107
+ 'options' => [
108
+ 'fixed' => esc_html__( 'Fixed', 'meta-box' ),
109
+ 'scroll' => esc_html__( 'Scroll', 'meta-box' ),
110
+ 'inherit' => esc_html__( 'Inherit', 'meta-box' ),
111
+ ],
112
+ ] );
 
 
113
  $output .= RWMB_Select_Field::html( $meta['attachment'], $attachment );
114
 
115
  // Size.
116
+ $size = RWMB_Select_Field::normalize( [
117
+ 'type' => 'select',
118
+ 'id' => "{$field['id']}_size",
119
+ 'field_name' => "{$field['field_name']}[size]",
120
+ 'placeholder' => esc_html__( '-- Size --', 'meta-box' ),
121
+ 'options' => [
122
+ 'inherit' => esc_html__( 'Inherit', 'meta-box' ),
123
+ 'cover' => esc_html__( 'Cover', 'meta-box' ),
124
+ 'contain' => esc_html__( 'Contain', 'meta-box' ),
125
+ ],
126
+ ] );
 
 
127
  $output .= RWMB_Select_Field::html( $meta['size'], $size );
128
  $output .= '</div><!-- .rwmb-background-row -->';
129
 
inc/fields/button-group.php CHANGED
@@ -1,19 +1,10 @@
1
  <?php
2
  /**
3
  * The Button group.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Button group class.
10
  */
11
  class RWMB_Button_Group_Field extends RWMB_Choice_Field {
12
- /**
13
- * Enqueue scripts and styles.
14
- */
15
  public static function admin_enqueue_scripts() {
16
- wp_enqueue_style( 'rwmb-button-group', RWMB_CSS_URL . 'button-group.css', '', RWMB_VER );
17
  wp_enqueue_script( 'rwmb-button-group', RWMB_JS_URL . 'button-group.js', [ 'rwmb' ], RWMB_VER, true );
18
  }
19
 
@@ -29,11 +20,11 @@ class RWMB_Button_Group_Field extends RWMB_Choice_Field {
29
  $walker = new RWMB_Walker_Input_List( $field, $meta );
30
 
31
  $output = sprintf(
32
- '<ul class="rwmb-button-input-list %s">',
33
  $field['inline'] ? 'rwmb-inline' : ''
34
  );
35
  $output .= $walker->walk( $options, -1 );
36
- $output .= '</ul>';
37
 
38
  return $output;
39
  }
1
  <?php
2
  /**
3
  * The Button group.
 
 
 
 
 
 
4
  */
5
  class RWMB_Button_Group_Field extends RWMB_Choice_Field {
 
 
 
6
  public static function admin_enqueue_scripts() {
7
+ wp_enqueue_style( 'rwmb-button-group', RWMB_CSS_URL . 'button-group.css', [], RWMB_VER );
8
  wp_enqueue_script( 'rwmb-button-group', RWMB_JS_URL . 'button-group.js', [ 'rwmb' ], RWMB_VER, true );
9
  }
10
 
20
  $walker = new RWMB_Walker_Input_List( $field, $meta );
21
 
22
  $output = sprintf(
23
+ '<fieldset class="rwmb-button-input-list %s">',
24
  $field['inline'] ? 'rwmb-inline' : ''
25
  );
26
  $output .= $walker->walk( $options, -1 );
27
+ $output .= '</fieldset>';
28
 
29
  return $output;
30
  }
inc/fields/button.php CHANGED
@@ -1,12 +1,6 @@
1
  <?php
2
  /**
3
  * The button field. Simply displays a HTML button which might be used for JavaScript actions.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Button field class.
10
  */
11
  class RWMB_Button_Field extends RWMB_Field {
12
  /**
@@ -28,12 +22,9 @@ class RWMB_Button_Field extends RWMB_Field {
28
  * @return array
29
  */
30
  public static function normalize( $field ) {
31
- $field = wp_parse_args(
32
- $field,
33
- array(
34
- 'std' => __( 'Click me', 'meta-box' ),
35
- )
36
- );
37
  $field = parent::normalize( $field );
38
  return $field;
39
  }
@@ -47,12 +38,9 @@ class RWMB_Button_Field extends RWMB_Field {
47
  */
48
  public static function get_attributes( $field, $value = null ) {
49
  $attributes = parent::get_attributes( $field, $value );
50
- $attributes = wp_parse_args(
51
- $attributes,
52
- array(
53
- 'type' => $field['type'],
54
- )
55
- );
56
  $attributes['class'] .= ' button hide-if-no-js';
57
 
58
  return $attributes;
1
  <?php
2
  /**
3
  * The button field. Simply displays a HTML button which might be used for JavaScript actions.
 
 
 
 
 
 
4
  */
5
  class RWMB_Button_Field extends RWMB_Field {
6
  /**
22
  * @return array
23
  */
24
  public static function normalize( $field ) {
25
+ $field = wp_parse_args( $field, [
26
+ 'std' => __( 'Click me', 'meta-box' ),
27
+ ] );
 
 
 
28
  $field = parent::normalize( $field );
29
  return $field;
30
  }
38
  */
39
  public static function get_attributes( $field, $value = null ) {
40
  $attributes = parent::get_attributes( $field, $value );
41
+ $attributes = wp_parse_args( $attributes, [
42
+ 'type' => $field['type'],
43
+ ] );
 
 
 
44
  $attributes['class'] .= ' button hide-if-no-js';
45
 
46
  return $attributes;
inc/fields/checkbox-list.php CHANGED
@@ -1,12 +1,6 @@
1
  <?php
2
  /**
3
  * The checkbox list field which shows a list of choices and allow users to select multiple options.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Checkbox list field class.
10
  */
11
  class RWMB_Checkbox_List_Field extends RWMB_Input_List_Field {
12
  /**
1
  <?php
2
  /**
3
  * The checkbox list field which shows a list of choices and allow users to select multiple options.
 
 
 
 
 
 
4
  */
5
  class RWMB_Checkbox_List_Field extends RWMB_Input_List_Field {
6
  /**
inc/fields/checkbox.php CHANGED
@@ -1,12 +1,6 @@
1
  <?php
2
  /**
3
  * The checkbox field.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Checkbox field class.
10
  */
11
  class RWMB_Checkbox_Field extends RWMB_Input_Field {
12
  /**
@@ -29,13 +23,7 @@ class RWMB_Checkbox_Field extends RWMB_Input_Field {
29
  return $output;
30
  }
31
 
32
- /**
33
- * Do not show field description.
34
- *
35
- * @param array $field Field parameters.
36
- * @return string
37
- */
38
- public static function input_description( $field ) {
39
  return '';
40
  }
41
 
1
  <?php
2
  /**
3
  * The checkbox field.
 
 
 
 
 
 
4
  */
5
  class RWMB_Checkbox_Field extends RWMB_Input_Field {
6
  /**
23
  return $output;
24
  }
25
 
26
+ protected static function input_description( array $field ) : string {
 
 
 
 
 
 
27
  return '';
28
  }
29
 
inc/fields/choice.php CHANGED
@@ -1,12 +1,6 @@
1
  <?php
2
  /**
3
  * The abstract choice field.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Abstract class for any kind of choice field.
10
  */
11
  abstract class RWMB_Choice_Field extends RWMB_Field {
12
  /**
@@ -28,13 +22,10 @@ abstract class RWMB_Choice_Field extends RWMB_Field {
28
  */
29
  public static function normalize( $field ) {
30
  $field = parent::normalize( $field );
31
- $field = wp_parse_args(
32
- $field,
33
- array(
34
- 'flatten' => true,
35
- 'options' => array(),
36
- )
37
- );
38
 
39
  // Use callback: function_name format from Meta Box Builder.
40
  if ( isset( $field['_callback'] ) && is_callable( $field['_callback'] ) ) {
@@ -44,21 +35,14 @@ abstract class RWMB_Choice_Field extends RWMB_Field {
44
  return $field;
45
  }
46
 
47
- /**
48
- * Transform field options into the verbose format.
49
- *
50
- * @param array $options Field options.
51
- *
52
- * @return array
53
- */
54
- public static function transform_options( $options ) {
55
- $transformed = array();
56
  $options = (array) $options;
57
  foreach ( $options as $value => $label ) {
58
- $option = is_array( $label ) ? $label : array(
59
  'label' => (string) $label,
60
  'value' => (string) $value,
61
- );
62
  if ( isset( $option['label'] ) && isset( $option['value'] ) ) {
63
  $transformed[ $option['value'] ] = (object) $option;
64
  }
1
  <?php
2
  /**
3
  * The abstract choice field.
 
 
 
 
 
 
4
  */
5
  abstract class RWMB_Choice_Field extends RWMB_Field {
6
  /**
22
  */
23
  public static function normalize( $field ) {
24
  $field = parent::normalize( $field );
25
+ $field = wp_parse_args( $field, [
26
+ 'flatten' => true,
27
+ 'options' => [],
28
+ ] );
 
 
 
29
 
30
  // Use callback: function_name format from Meta Box Builder.
31
  if ( isset( $field['_callback'] ) && is_callable( $field['_callback'] ) ) {
35
  return $field;
36
  }
37
 
38
+ public static function transform_options( $options ) : array {
39
+ $transformed = [];
 
 
 
 
 
 
 
40
  $options = (array) $options;
41
  foreach ( $options as $value => $label ) {
42
+ $option = is_array( $label ) ? $label : [
43
  'label' => (string) $label,
44
  'value' => (string) $value,
45
+ ];
46
  if ( isset( $option['label'] ) && isset( $option['value'] ) ) {
47
  $transformed[ $option['value'] ] = (object) $option;
48
  }
inc/fields/color.php CHANGED
@@ -1,26 +1,17 @@
1
  <?php
2
  /**
3
  * The color field which uses WordPress color picker to select a color.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Color field class.
10
  */
11
  class RWMB_Color_Field extends RWMB_Input_Field {
12
- /**
13
- * Enqueue scripts and styles.
14
- */
15
  public static function admin_enqueue_scripts() {
16
- wp_enqueue_style( 'rwmb-color', RWMB_CSS_URL . 'color.css', array( 'wp-color-picker' ), RWMB_VER );
17
 
18
- $dependencies = array( 'wp-color-picker' );
19
  $args = func_get_args();
20
  $field = reset( $args );
21
  if ( ! empty( $field['alpha_channel'] ) ) {
22
- wp_enqueue_script( 'wp-color-picker-alpha', RWMB_JS_URL . 'wp-color-picker-alpha/wp-color-picker-alpha.min.js', array( 'wp-color-picker' ), RWMB_VER, true );
23
- $dependencies = array( 'wp-color-picker-alpha' );
24
  }
25
  wp_enqueue_script( 'rwmb-color', RWMB_JS_URL . 'color.js', $dependencies, RWMB_VER, true );
26
  }
@@ -33,22 +24,16 @@ class RWMB_Color_Field extends RWMB_Input_Field {
33
  * @return array
34
  */
35
  public static function normalize( $field ) {
36
- $field = wp_parse_args(
37
- $field,
38
- array(
39
- 'alpha_channel' => false,
40
- 'js_options' => array(),
41
- )
42
- );
43
 
44
- $field['js_options'] = wp_parse_args(
45
- $field['js_options'],
46
- array(
47
- 'defaultColor' => false,
48
- 'hide' => true,
49
- 'palettes' => true,
50
- )
51
- );
52
 
53
  $field = parent::normalize( $field );
54
 
@@ -65,12 +50,9 @@ class RWMB_Color_Field extends RWMB_Input_Field {
65
  */
66
  public static function get_attributes( $field, $value = null ) {
67
  $attributes = parent::get_attributes( $field, $value );
68
- $attributes = wp_parse_args(
69
- $attributes,
70
- array(
71
- 'data-options' => wp_json_encode( $field['js_options'] ),
72
- )
73
- );
74
  $attributes['type'] = 'text';
75
 
76
  if ( $field['alpha_channel'] ) {
1
  <?php
2
  /**
3
  * The color field which uses WordPress color picker to select a color.
 
 
 
 
 
 
4
  */
5
  class RWMB_Color_Field extends RWMB_Input_Field {
 
 
 
6
  public static function admin_enqueue_scripts() {
7
+ wp_enqueue_style( 'rwmb-color', RWMB_CSS_URL . 'color.css', [ 'wp-color-picker' ], RWMB_VER );
8
 
9
+ $dependencies = [ 'wp-color-picker' ];
10
  $args = func_get_args();
11
  $field = reset( $args );
12
  if ( ! empty( $field['alpha_channel'] ) ) {
13
+ wp_enqueue_script( 'wp-color-picker-alpha', RWMB_JS_URL . 'wp-color-picker-alpha/wp-color-picker-alpha.min.js', [ 'wp-color-picker' ], RWMB_VER, true );
14
+ $dependencies = [ 'wp-color-picker-alpha' ];
15
  }
16
  wp_enqueue_script( 'rwmb-color', RWMB_JS_URL . 'color.js', $dependencies, RWMB_VER, true );
17
  }
24
  * @return array
25
  */
26
  public static function normalize( $field ) {
27
+ $field = wp_parse_args( $field, [
28
+ 'alpha_channel' => false,
29
+ 'js_options' => [],
30
+ ] );
 
 
 
31
 
32
+ $field['js_options'] = wp_parse_args( $field['js_options'], [
33
+ 'defaultColor' => false,
34
+ 'hide' => true,
35
+ 'palettes' => true,
36
+ ] );
 
 
 
37
 
38
  $field = parent::normalize( $field );
39
 
50
  */
51
  public static function get_attributes( $field, $value = null ) {
52
  $attributes = parent::get_attributes( $field, $value );
53
+ $attributes = wp_parse_args( $attributes, [
54
+ 'data-options' => wp_json_encode( $field['js_options'] ),
55
+ ] );
 
 
 
56
  $attributes['type'] = 'text';
57
 
58
  if ( $field['alpha_channel'] ) {
inc/fields/custom-html.php CHANGED
@@ -1,12 +1,6 @@
1
  <?php
2
  /**
3
  * The custom HTML field which allows users to output any kind of content to the meta box.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Custom HTML field class.
10
  */
11
  class RWMB_Custom_Html_Field extends RWMB_Field {
12
  /**
@@ -20,7 +14,7 @@ class RWMB_Custom_Html_Field extends RWMB_Field {
20
  public static function html( $meta, $field ) {
21
  $html = ! empty( $field['std'] ) ? $field['std'] : '';
22
  if ( ! empty( $field['callback'] ) && is_callable( $field['callback'] ) ) {
23
- $html = call_user_func_array( $field['callback'], array( $meta, $field ) );
24
  }
25
  return $html;
26
  }
1
  <?php
2
  /**
3
  * The custom HTML field which allows users to output any kind of content to the meta box.
 
 
 
 
 
 
4
  */
5
  class RWMB_Custom_Html_Field extends RWMB_Field {
6
  /**
14
  public static function html( $meta, $field ) {
15
  $html = ! empty( $field['std'] ) ? $field['std'] : '';
16
  if ( ! empty( $field['callback'] ) && is_callable( $field['callback'] ) ) {
17
+ $html = call_user_func_array( $field['callback'], [ $meta, $field ] );
18
  }
19
  return $html;
20
  }
inc/fields/date.php CHANGED
@@ -1,17 +1,8 @@
1
  <?php
2
  /**
3
  * The date picker field, which uses built-in jQueryUI date picker widget.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Date field class.
10
  */
11
  class RWMB_Date_Field extends RWMB_Datetime_Field {
12
- /**
13
- * Enqueue scripts and styles.
14
- */
15
  public static function admin_enqueue_scripts() {
16
  parent::register_assets();
17
  wp_enqueue_style( 'rwmb-date' );
@@ -20,13 +11,9 @@ class RWMB_Date_Field extends RWMB_Datetime_Field {
20
 
21
  /**
22
  * Returns a date() compatible format string from the JavaScript format.
23
- *
24
  * @link http://www.php.net/manual/en/function.date.php
25
- * @param array $js_options JavaScript options.
26
- *
27
- * @return string
28
  */
29
- public static function get_php_format( $js_options ) {
30
  return strtr( $js_options['dateFormat'], self::$date_formats );
31
  }
32
  }
1
  <?php
2
  /**
3
  * The date picker field, which uses built-in jQueryUI date picker widget.
 
 
 
 
 
 
4
  */
5
  class RWMB_Date_Field extends RWMB_Datetime_Field {
 
 
 
6
  public static function admin_enqueue_scripts() {
7
  parent::register_assets();
8
  wp_enqueue_style( 'rwmb-date' );
11
 
12
  /**
13
  * Returns a date() compatible format string from the JavaScript format.
 
14
  * @link http://www.php.net/manual/en/function.date.php
 
 
 
15
  */
16
+ protected static function get_php_format( array $js_options ) : string {
17
  return strtr( $js_options['dateFormat'], self::$date_formats );
18
  }
19
  }
inc/fields/datetime.php CHANGED
@@ -100,14 +100,16 @@ class RWMB_Datetime_Field extends RWMB_Input_Field {
100
  $output = '';
101
 
102
  if ( $field['timestamp'] ) {
103
- $name = $field['field_name'];
104
- $field = wp_parse_args( [ 'field_name' => $name . '[formatted]' ], $field );
105
- $output .= sprintf(
 
106
  '<input type="hidden" name="%s" class="rwmb-datetime-timestamp" value="%s">',
107
  esc_attr( $name . '[timestamp]' ),
108
- isset( $meta['timestamp'] ) ? intval( $meta['timestamp'] ) : ''
109
  );
110
- $meta = isset( $meta['formatted'] ) ? $meta['formatted'] : '';
 
111
  }
112
 
113
  $output .= parent::html( $meta, $field );
@@ -173,10 +175,6 @@ class RWMB_Datetime_Field extends RWMB_Input_Field {
173
 
174
  /**
175
  * Format meta value if set 'timestamp'.
176
- *
177
- * @param string $meta The meta value.
178
- * @param array $field Field parameters.
179
- * @return array
180
  */
181
  public static function from_timestamp( $meta, array $field ) : array {
182
  return [
@@ -187,12 +185,8 @@ class RWMB_Datetime_Field extends RWMB_Input_Field {
187
 
188
  /**
189
  * Transform meta value from save format to the JS format.
190
- *
191
- * @param string $meta The meta value.
192
- * @param array $field Field parameters.
193
- * @return array
194
  */
195
- public static function from_save_format( $meta, $field ) {
196
  $date = DateTime::createFromFormat( $field['save_format'], $meta );
197
  return false === $date ? $meta : $date->format( $field['php_format'] );
198
  }
@@ -222,7 +216,6 @@ class RWMB_Datetime_Field extends RWMB_Input_Field {
222
  'changeYear' => true,
223
  'yearRange' => '-100:+100',
224
  'changeMonth' => true,
225
- 'showButtonPanel' => true,
226
  'oneLine' => true,
227
  'controlType' => 'select', // select or slider
228
  'addSliderAccess' => true,
@@ -260,13 +253,9 @@ class RWMB_Datetime_Field extends RWMB_Input_Field {
260
 
261
  /**
262
  * Returns a date() compatible format string from the JavaScript format.
263
- *
264
  * @link http://www.php.net/manual/en/function.date.php
265
- * @param array $js_options JavaScript options.
266
- *
267
- * @return string
268
  */
269
- protected static function get_php_format( $js_options ) {
270
  return strtr( $js_options['dateFormat'], self::$date_formats )
271
  . $js_options['separator']
272
  . strtr( $js_options['timeFormat'], self::$time_formats );
100
  $output = '';
101
 
102
  if ( $field['timestamp'] ) {
103
+ $name = $field['field_name'];
104
+ $field = wp_parse_args( [ 'field_name' => $name . '[formatted]' ], $field );
105
+ $timestamp = $meta['timestamp'] ?? 0;
106
+ $output .= sprintf(
107
  '<input type="hidden" name="%s" class="rwmb-datetime-timestamp" value="%s">',
108
  esc_attr( $name . '[timestamp]' ),
109
+ (int) $timestamp
110
  );
111
+
112
+ $meta = $meta['formatted'] ?? '';
113
  }
114
 
115
  $output .= parent::html( $meta, $field );
175
 
176
  /**
177
  * Format meta value if set 'timestamp'.
 
 
 
 
178
  */
179
  public static function from_timestamp( $meta, array $field ) : array {
180
  return [
185
 
186
  /**
187
  * Transform meta value from save format to the JS format.
 
 
 
 
188
  */
189
+ public static function from_save_format( $meta, array $field ) : string {
190
  $date = DateTime::createFromFormat( $field['save_format'], $meta );
191
  return false === $date ? $meta : $date->format( $field['php_format'] );
192
  }
216
  'changeYear' => true,
217
  'yearRange' => '-100:+100',
218
  'changeMonth' => true,
 
219
  'oneLine' => true,
220
  'controlType' => 'select', // select or slider
221
  'addSliderAccess' => true,
253
 
254
  /**
255
  * Returns a date() compatible format string from the JavaScript format.
 
256
  * @link http://www.php.net/manual/en/function.date.php
 
 
 
257
  */
258
+ protected static function get_php_format( array $js_options ) : string {
259
  return strtr( $js_options['dateFormat'], self::$date_formats )
260
  . $js_options['separator']
261
  . strtr( $js_options['timeFormat'], self::$time_formats );
inc/fields/divider.php CHANGED
@@ -7,22 +7,11 @@ class RWMB_Divider_Field extends RWMB_Field {
7
  wp_enqueue_style( 'rwmb-divider', RWMB_CSS_URL . 'divider.css', [], RWMB_VER );
8
  }
9
 
10
- /**
11
- * Show begin HTML markup for fields.
12
- *
13
- * @param mixed $meta Meta value.
14
- * @param array $field Field parameters.
15
- *
16
- * @return string
17
- */
18
- public static function begin_html( $meta, $field ) {
19
  $attributes = empty( $field['id'] ) ? '' : " id='{$field['id']}'";
20
  return "<hr$attributes>";
21
  }
22
 
23
- /**
24
- * Show end HTML markup for fields.
25
- */
26
  public static function end_html( array $field ) : string {
27
  return '';
28
  }
7
  wp_enqueue_style( 'rwmb-divider', RWMB_CSS_URL . 'divider.css', [], RWMB_VER );
8
  }
9
 
10
+ protected static function begin_html( array $field ) : string {
 
 
 
 
 
 
 
 
11
  $attributes = empty( $field['id'] ) ? '' : " id='{$field['id']}'";
12
  return "<hr$attributes>";
13
  }
14
 
 
 
 
15
  public static function end_html( array $field ) : string {
16
  return '';
17
  }
inc/fields/fieldset-text.php CHANGED
@@ -1,19 +1,10 @@
1
  <?php
2
  /**
3
  * The text fieldset field, which allows users to enter content for a list of text fields.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Fieldset text class.
10
  */
11
  class RWMB_Fieldset_Text_Field extends RWMB_Input_Field {
12
- /**
13
- * Enqueue field scripts and styles.
14
- */
15
  public static function admin_enqueue_scripts() {
16
- wp_enqueue_style( 'rwmb-fieldset-text', RWMB_CSS_URL . 'fieldset-text.css', '', RWMB_VER );
17
  }
18
 
19
  /**
@@ -25,7 +16,7 @@ class RWMB_Fieldset_Text_Field extends RWMB_Input_Field {
25
  * @return string
26
  */
27
  public static function html( $meta, $field ) {
28
- $html = array();
29
  $tpl = '<p><label>%s</label> %s</p>';
30
 
31
  foreach ( $field['options'] as $key => $label ) {
@@ -39,25 +30,11 @@ class RWMB_Fieldset_Text_Field extends RWMB_Input_Field {
39
  return $out;
40
  }
41
 
42
- /**
43
- * Do not show field description.
44
- *
45
- * @param array $field Field parameters.
46
- *
47
- * @return string
48
- */
49
- public static function input_description( $field ) {
50
  return '';
51
  }
52
 
53
- /**
54
- * Do not show field description.
55
- *
56
- * @param array $field Field parameters.
57
- *
58
- * @return string
59
- */
60
- public static function label_description( $field ) {
61
  return '';
62
  }
63
 
1
  <?php
2
  /**
3
  * The text fieldset field, which allows users to enter content for a list of text fields.
 
 
 
 
 
 
4
  */
5
  class RWMB_Fieldset_Text_Field extends RWMB_Input_Field {
 
 
 
6
  public static function admin_enqueue_scripts() {
7
+ wp_enqueue_style( 'rwmb-fieldset-text', RWMB_CSS_URL . 'fieldset-text.css', [], RWMB_VER );
8
  }
9
 
10
  /**
16
  * @return string
17
  */
18
  public static function html( $meta, $field ) {
19
+ $html = [];
20
  $tpl = '<p><label>%s</label> %s</p>';
21
 
22
  foreach ( $field['options'] as $key => $label ) {
30
  return $out;
31
  }
32
 
33
+ protected static function input_description( array $field ) : string {
 
 
 
 
 
 
 
34
  return '';
35
  }
36
 
37
+ protected static function label_description( array $field ) : string {
 
 
 
 
 
 
 
38
  return '';
39
  }
40
 
inc/fields/file-input.php CHANGED
@@ -1,12 +1,6 @@
1
  <?php
2
  /**
3
  * The file input field which allows users to enter a file URL or select it from the Media Library.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * File input field class which uses an input for file URL.
10
  */
11
  class RWMB_File_Input_Field extends RWMB_Input_Field {
12
  /**
@@ -14,15 +8,11 @@ class RWMB_File_Input_Field extends RWMB_Input_Field {
14
  */
15
  public static function admin_enqueue_scripts() {
16
  wp_enqueue_media();
17
- wp_enqueue_style( 'rwmb-file-input', RWMB_CSS_URL . 'file-input.css', array(), RWMB_VER );
18
- wp_enqueue_script( 'rwmb-file-input', RWMB_JS_URL . 'file-input.js', array( 'jquery' ), RWMB_VER, true );
19
- RWMB_Helpers_Field::localize_script_once(
20
- 'rwmb-file-input',
21
- 'rwmbFileInput',
22
- array(
23
- 'frameTitle' => esc_html__( 'Select File', 'meta-box' ),
24
- )
25
- );
26
  }
27
 
28
  /**
@@ -47,7 +37,7 @@ class RWMB_File_Input_Field extends RWMB_Input_Field {
47
  <a href="#" class="rwmb-file-input-select button">%s</a>
48
  <a href="#" class="rwmb-file-input-remove button %s">%s</a>
49
  </div>',
50
- in_array( $file_ext, $extensions ) ? '' : 'rwmb-file-input-hidden',
51
  $meta,
52
  self::render_attributes( $attributes ),
53
  esc_html__( 'Select', 'meta-box' ),
1
  <?php
2
  /**
3
  * The file input field which allows users to enter a file URL or select it from the Media Library.
 
 
 
 
 
 
4
  */
5
  class RWMB_File_Input_Field extends RWMB_Input_Field {
6
  /**
8
  */
9
  public static function admin_enqueue_scripts() {
10
  wp_enqueue_media();
11
+ wp_enqueue_style( 'rwmb-file-input', RWMB_CSS_URL . 'file-input.css', [], RWMB_VER );
12
+ wp_enqueue_script( 'rwmb-file-input', RWMB_JS_URL . 'file-input.js', [ 'jquery' ], RWMB_VER, true );
13
+ RWMB_Helpers_Field::localize_script_once( 'rwmb-file-input', 'rwmbFileInput', [
14
+ 'frameTitle' => esc_html__( 'Select File', 'meta-box' ),
15
+ ] );
 
 
 
 
16
  }
17
 
18
  /**
37
  <a href="#" class="rwmb-file-input-select button">%s</a>
38
  <a href="#" class="rwmb-file-input-remove button %s">%s</a>
39
  </div>',
40
+ in_array( $file_ext, $extensions, true ) ? '' : 'rwmb-file-input-hidden',
41
  $meta,
42
  self::render_attributes( $attributes ),
43
  esc_html__( 'Select', 'meta-box' ),
inc/fields/file-upload.php CHANGED
@@ -1,21 +1,12 @@
1
  <?php
2
  /**
3
  * The file upload field which allows users to drag and drop files to upload.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * The file upload field class.
10
  */
11
  class RWMB_File_Upload_Field extends RWMB_Media_Field {
12
- /**
13
- * Enqueue scripts and styles.
14
- */
15
  public static function admin_enqueue_scripts() {
16
  parent::admin_enqueue_scripts();
17
- wp_enqueue_style( 'rwmb-upload', RWMB_CSS_URL . 'upload.css', array( 'rwmb-media' ), RWMB_VER );
18
- wp_enqueue_script( 'rwmb-file-upload', RWMB_JS_URL . 'file-upload.js', array( 'rwmb-media' ), RWMB_VER, true );
19
  }
20
 
21
  /**
@@ -27,19 +18,13 @@ class RWMB_File_Upload_Field extends RWMB_Media_Field {
27
  */
28
  public static function normalize( $field ) {
29
  $field = parent::normalize( $field );
30
- $field = wp_parse_args(
31
- $field,
32
- array(
33
- 'max_file_size' => 0,
34
- )
35
- );
36
 
37
- $field['js_options'] = wp_parse_args(
38
- $field['js_options'],
39
- array(
40
- 'maxFileSize' => $field['max_file_size'],
41
- )
42
- );
43
 
44
  return $field;
45
  }
1
  <?php
2
  /**
3
  * The file upload field which allows users to drag and drop files to upload.
 
 
 
 
 
 
4
  */
5
  class RWMB_File_Upload_Field extends RWMB_Media_Field {
 
 
 
6
  public static function admin_enqueue_scripts() {
7
  parent::admin_enqueue_scripts();
8
+ wp_enqueue_style( 'rwmb-upload', RWMB_CSS_URL . 'upload.css', [ 'rwmb-media' ], RWMB_VER );
9
+ wp_enqueue_script( 'rwmb-file-upload', RWMB_JS_URL . 'file-upload.js', [ 'rwmb-media' ], RWMB_VER, true );
10
  }
11
 
12
  /**
18
  */
19
  public static function normalize( $field ) {
20
  $field = parent::normalize( $field );
21
+ $field = wp_parse_args( $field, [
22
+ 'max_file_size' => 0,
23
+ ] );
 
 
 
24
 
25
+ $field['js_options'] = wp_parse_args( $field['js_options'], [
26
+ 'maxFileSize' => $field['max_file_size'],
27
+ ] );
 
 
 
28
 
29
  return $field;
30
  }
inc/fields/heading.php CHANGED
@@ -7,23 +7,12 @@ class RWMB_Heading_Field extends RWMB_Field {
7
  wp_enqueue_style( 'rwmb-heading', RWMB_CSS_URL . 'heading.css', [], RWMB_VER );
8
  }
9
 
10
- /**
11
- * Show begin HTML markup for fields.
12
- *
13
- * @param mixed $meta Meta value.
14
- * @param array $field Field parameters.
15
- *
16
- * @return string
17
- */
18
- public static function begin_html( $meta, $field ) {
19
  $attributes = empty( $field['id'] ) ? '' : " id='{$field['id']}'";
20
  return sprintf( '<h4%s>%s</h4>', $attributes, $field['name'] );
21
  }
22
 
23
- /**
24
- * Show end HTML markup for fields.
25
- */
26
- public static function end_html( array $field ) : string {
27
  return self::input_description( $field );
28
  }
29
  }
7
  wp_enqueue_style( 'rwmb-heading', RWMB_CSS_URL . 'heading.css', [], RWMB_VER );
8
  }
9
 
10
+ protected static function begin_html( array $field ) : string {
 
 
 
 
 
 
 
 
11
  $attributes = empty( $field['id'] ) ? '' : " id='{$field['id']}'";
12
  return sprintf( '<h4%s>%s</h4>', $attributes, $field['name'] );
13
  }
14
 
15
+ protected static function end_html( array $field ) : string {
 
 
 
16
  return self::input_description( $field );
17
  }
18
  }
inc/fields/image-advanced.php CHANGED
@@ -1,21 +1,12 @@
1
  <?php
2
  /**
3
  * The advanced image upload field which uses WordPress media popup to upload and select images.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Image advanced field class.
10
  */
11
  class RWMB_Image_Advanced_Field extends RWMB_Media_Field {
12
- /**
13
- * Enqueue scripts and styles.
14
- */
15
  public static function admin_enqueue_scripts() {
16
  parent::admin_enqueue_scripts();
17
  RWMB_Image_Field::admin_enqueue_scripts();
18
- wp_enqueue_script( 'rwmb-image-advanced', RWMB_JS_URL . 'image-advanced.js', array( 'rwmb-media' ), RWMB_VER, true );
19
  }
20
 
21
  /**
@@ -27,21 +18,15 @@ class RWMB_Image_Advanced_Field extends RWMB_Media_Field {
27
  */
28
  public static function normalize( $field ) {
29
  $field['mime_type'] = 'image';
30
- $field = wp_parse_args(
31
- $field,
32
- array(
33
- 'image_size' => 'thumbnail',
34
- )
35
- );
36
 
37
  $field = parent::normalize( $field );
38
 
39
- $field['js_options'] = wp_parse_args(
40
- $field['js_options'],
41
- array(
42
- 'imageSize' => $field['image_size'],
43
- )
44
- );
45
 
46
  return $field;
47
  }
@@ -51,10 +36,10 @@ class RWMB_Image_Advanced_Field extends RWMB_Media_Field {
51
  *
52
  * @param array $field Field parameters.
53
  * @param array $args Additional arguments.
54
- * @param null $post_id Post ID.
55
  * @return mixed
56
  */
57
- public static function get_value( $field, $args = array(), $post_id = null ) {
58
  return RWMB_Image_Field::get_value( $field, $args, $post_id );
59
  }
60
 
@@ -67,7 +52,7 @@ class RWMB_Image_Advanced_Field extends RWMB_Media_Field {
67
  *
68
  * @return array|bool False if file not found. Array of image info on success.
69
  */
70
- public static function file_info( $file, $args = array(), $field = array() ) {
71
  return RWMB_Image_Field::file_info( $file, $args, $field );
72
  }
73
 
@@ -75,7 +60,7 @@ class RWMB_Image_Advanced_Field extends RWMB_Media_Field {
75
  * Format a single value for the helper functions. Sub-fields should overwrite this method if necessary.
76
  *
77
  * @param array $field Field parameters.
78
- * @param string $value The value.
79
  * @param array $args Additional arguments. Rarely used. See specific fields for details.
80
  * @param int|null $post_id Post ID. null for current post. Optional.
81
  *
1
  <?php
2
  /**
3
  * The advanced image upload field which uses WordPress media popup to upload and select images.
 
 
 
 
 
 
4
  */
5
  class RWMB_Image_Advanced_Field extends RWMB_Media_Field {
 
 
 
6
  public static function admin_enqueue_scripts() {
7
  parent::admin_enqueue_scripts();
8
  RWMB_Image_Field::admin_enqueue_scripts();
9
+ wp_enqueue_script( 'rwmb-image-advanced', RWMB_JS_URL . 'image-advanced.js', [ 'rwmb-media' ], RWMB_VER, true );
10
  }
11
 
12
  /**
18
  */
19
  public static function normalize( $field ) {
20
  $field['mime_type'] = 'image';
21
+ $field = wp_parse_args( $field, [
22
+ 'image_size' => 'thumbnail',
23
+ ] );
 
 
 
24
 
25
  $field = parent::normalize( $field );
26
 
27
+ $field['js_options'] = wp_parse_args( $field['js_options'], [
28
+ 'imageSize' => $field['image_size'],
29
+ ] );
 
 
 
30
 
31
  return $field;
32
  }
36
  *
37
  * @param array $field Field parameters.
38
  * @param array $args Additional arguments.
39
+ * @param ?int $post_id Post ID.
40
  * @return mixed
41
  */
42
+ public static function get_value( $field, $args = [], $post_id = null ) {
43
  return RWMB_Image_Field::get_value( $field, $args, $post_id );
44
  }
45
 
52
  *
53
  * @return array|bool False if file not found. Array of image info on success.
54
  */
55
+ public static function file_info( $file, $args = [], $field = [] ) {
56
  return RWMB_Image_Field::file_info( $file, $args, $field );
57
  }
58
 
60
  * Format a single value for the helper functions. Sub-fields should overwrite this method if necessary.
61
  *
62
  * @param array $field Field parameters.
63
+ * @param array $value The value.
64
  * @param array $args Additional arguments. Rarely used. See specific fields for details.
65
  * @param int|null $post_id Post ID. null for current post. Optional.
66
  *
inc/fields/image-select.php CHANGED
@@ -1,20 +1,11 @@
1
  <?php
2
  /**
3
  * The image select field which behaves similar to the radio field but uses images as options.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * The image select field class.
10
  */
11
  class RWMB_Image_Select_Field extends RWMB_Field {
12
- /**
13
- * Enqueue scripts and styles.
14
- */
15
  public static function admin_enqueue_scripts() {
16
- wp_enqueue_style( 'rwmb-image-select', RWMB_CSS_URL . 'image-select.css', array(), RWMB_VER );
17
- wp_enqueue_script( 'rwmb-image-select', RWMB_JS_URL . 'image-select.js', array( 'jquery' ), RWMB_VER, true );
18
  }
19
 
20
  /**
@@ -25,11 +16,11 @@ class RWMB_Image_Select_Field extends RWMB_Field {
25
  * @return string
26
  */
27
  public static function html( $meta, $field ) {
28
- $html = array();
29
  $meta = (array) $meta;
30
  foreach ( $field['options'] as $value => $image ) {
31
  $attributes = self::get_attributes( $field, $value );
32
- $html[] = sprintf(
33
  '<label class="rwmb-image-select"><img src="%s"><input %s%s></label>',
34
  $image,
35
  self::render_attributes( $attributes ),
@@ -61,13 +52,14 @@ class RWMB_Image_Select_Field extends RWMB_Field {
61
  * @return array
62
  */
63
  public static function get_attributes( $field, $value = null ) {
64
- $attributes = parent::get_attributes( $field, $value );
65
  $attributes['id'] = false;
66
  $attributes['type'] = $field['multiple'] ? 'checkbox' : 'radio';
67
  $attributes['value'] = $value;
68
 
69
  return $attributes;
70
  }
 
71
  /**
72
  * Format a single value for the helper functions. Sub-fields should overwrite this method if necessary.
73
  *
1
  <?php
2
  /**
3
  * The image select field which behaves similar to the radio field but uses images as options.
 
 
 
 
 
 
4
  */
5
  class RWMB_Image_Select_Field extends RWMB_Field {
 
 
 
6
  public static function admin_enqueue_scripts() {
7
+ wp_enqueue_style( 'rwmb-image-select', RWMB_CSS_URL . 'image-select.css', [], RWMB_VER );
8
+ wp_enqueue_script( 'rwmb-image-select', RWMB_JS_URL . 'image-select.js', [ 'jquery' ], RWMB_VER, true );
9
  }
10
 
11
  /**
16
  * @return string
17
  */
18
  public static function html( $meta, $field ) {
19
+ $html = [];
20
  $meta = (array) $meta;
21
  foreach ( $field['options'] as $value => $image ) {
22
  $attributes = self::get_attributes( $field, $value );
23
+ $html[] = sprintf(
24
  '<label class="rwmb-image-select"><img src="%s"><input %s%s></label>',
25
  $image,
26
  self::render_attributes( $attributes ),
52
  * @return array
53
  */
54
  public static function get_attributes( $field, $value = null ) {
55
+ $attributes = parent::get_attributes( $field, $value );
56
  $attributes['id'] = false;
57
  $attributes['type'] = $field['multiple'] ? 'checkbox' : 'radio';
58
  $attributes['value'] = $value;
59
 
60
  return $attributes;
61
  }
62
+
63
  /**
64
  * Format a single value for the helper functions. Sub-fields should overwrite this method if necessary.
65
  *
inc/fields/image-upload.php CHANGED
@@ -1,21 +1,12 @@
1
  <?php
2
  /**
3
  * The image upload field which allows users to drag and drop images.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * File advanced field class which users WordPress media popup to upload and select files.
10
  */
11
  class RWMB_Image_Upload_Field extends RWMB_Image_Advanced_Field {
12
- /**
13
- * Enqueue scripts and styles.
14
- */
15
  public static function admin_enqueue_scripts() {
16
  parent::admin_enqueue_scripts();
17
  RWMB_File_Upload_Field::admin_enqueue_scripts();
18
- wp_enqueue_script( 'rwmb-image-upload', RWMB_JS_URL . 'image-upload.js', array( 'rwmb-file-upload', 'rwmb-image-advanced' ), RWMB_VER, true );
19
  }
20
 
21
  /**
1
  <?php
2
  /**
3
  * The image upload field which allows users to drag and drop images.
 
 
 
 
 
 
4
  */
5
  class RWMB_Image_Upload_Field extends RWMB_Image_Advanced_Field {
 
 
 
6
  public static function admin_enqueue_scripts() {
7
  parent::admin_enqueue_scripts();
8
  RWMB_File_Upload_Field::admin_enqueue_scripts();
9
+ wp_enqueue_script( 'rwmb-image-upload', RWMB_JS_URL . 'image-upload.js', [ 'rwmb-file-upload', 'rwmb-image-advanced' ], RWMB_VER, true );
10
  }
11
 
12
  /**
inc/fields/image.php CHANGED
@@ -1,17 +1,8 @@
1
  <?php
2
  /**
3
  * The image field which uploads images via HTML <input type="file">.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Image field class which uses <input type="file"> to upload.
10
  */
11
  class RWMB_Image_Field extends RWMB_File_Field {
12
- /**
13
- * Enqueue scripts and styles.
14
- */
15
  public static function admin_enqueue_scripts() {
16
  parent::admin_enqueue_scripts();
17
  wp_enqueue_media();
1
  <?php
2
  /**
3
  * The image field which uploads images via HTML <input type="file">.
 
 
 
 
 
 
4
  */
5
  class RWMB_Image_Field extends RWMB_File_Field {
 
 
 
6
  public static function admin_enqueue_scripts() {
7
  parent::admin_enqueue_scripts();
8
  wp_enqueue_media();
inc/fields/input.php CHANGED
@@ -4,7 +4,7 @@
4
  */
5
  abstract class RWMB_Input_Field extends RWMB_Field {
6
  public static function admin_enqueue_scripts() {
7
- wp_enqueue_style( 'rwmb-input', RWMB_CSS_URL . 'input.css', '', RWMB_VER );
8
  }
9
 
10
  /**
4
  */
5
  abstract class RWMB_Input_Field extends RWMB_Field {
6
  public static function admin_enqueue_scripts() {
7
+ wp_enqueue_style( 'rwmb-input', RWMB_CSS_URL . 'input.css', [], RWMB_VER );
8
  }
9
 
10
  /**
inc/fields/key-value.php CHANGED
@@ -1,16 +1,10 @@
1
  <?php
2
  /**
3
  * The key-value field which allows users to add pairs of keys and values.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Key-value field class.
10
  */
11
  class RWMB_Key_Value_Field extends RWMB_Input_Field {
12
  public static function admin_enqueue_scripts() {
13
- wp_enqueue_style( 'rwmb-key-value', RWMB_CSS_URL . 'key-value.css', array(), RWMB_VER );
14
  }
15
 
16
  /**
@@ -37,15 +31,7 @@ class RWMB_Key_Value_Field extends RWMB_Input_Field {
37
  return $html;
38
  }
39
 
40
- /**
41
- * Show begin HTML markup for fields.
42
- *
43
- * @param mixed $meta Meta value.
44
- * @param array $field Field parameters.
45
- *
46
- * @return string
47
- */
48
- public static function begin_html( $meta, $field ) {
49
  $desc = $field['desc'] ? "<p id='{$field['id']}_description' class='description'>{$field['desc']}</p>" : '';
50
 
51
  if ( empty( $field['name'] ) ) {
@@ -64,14 +50,7 @@ class RWMB_Key_Value_Field extends RWMB_Input_Field {
64
  );
65
  }
66
 
67
- /**
68
- * Do not show field description.
69
- *
70
- * @param array $field Field parameters.
71
- *
72
- * @return string
73
- */
74
- public static function input_description( $field ) {
75
  return '';
76
  }
77
 
@@ -108,13 +87,10 @@ class RWMB_Key_Value_Field extends RWMB_Input_Field {
108
  $field = parent::normalize( $field );
109
 
110
  $field['attributes']['type'] = 'text';
111
- $field['placeholder'] = wp_parse_args(
112
- (array) $field['placeholder'],
113
- array(
114
- 'key' => __( 'Key', 'meta-box' ),
115
- 'value' => __( 'Value', 'meta-box' ),
116
- )
117
- );
118
  return $field;
119
  }
120
 
1
  <?php
2
  /**
3
  * The key-value field which allows users to add pairs of keys and values.
 
 
 
 
 
 
4
  */
5
  class RWMB_Key_Value_Field extends RWMB_Input_Field {
6
  public static function admin_enqueue_scripts() {
7
+ wp_enqueue_style( 'rwmb-key-value', RWMB_CSS_URL . 'key-value.css', [], RWMB_VER );
8
  }
9
 
10
  /**
31
  return $html;
32
  }
33
 
34
+ protected static function begin_html( array $field ) : string {
 
 
 
 
 
 
 
 
35
  $desc = $field['desc'] ? "<p id='{$field['id']}_description' class='description'>{$field['desc']}</p>" : '';
36
 
37
  if ( empty( $field['name'] ) ) {
50
  );
51
  }
52
 
53
+ protected static function input_description( array $field ) : string {
 
 
 
 
 
 
 
54
  return '';
55
  }
56
 
87
  $field = parent::normalize( $field );
88
 
89
  $field['attributes']['type'] = 'text';
90
+ $field['placeholder'] = wp_parse_args( (array) $field['placeholder'], [
91
+ 'key' => __( 'Key', 'meta-box' ),
92
+ 'value' => __( 'Value', 'meta-box' ),
93
+ ] );
 
 
 
94
  return $field;
95
  }
96
 
inc/fields/map.php CHANGED
@@ -1,61 +1,30 @@
1
  <?php
2
  /**
3
  * The Google Maps field.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Map field class.
10
  */
11
  class RWMB_Map_Field extends RWMB_Field {
12
- /**
13
- * Enqueue scripts and styles.
14
- */
15
  public static function admin_enqueue_scripts() {
16
- wp_enqueue_style( 'rwmb-map', RWMB_CSS_URL . 'map.css', array(), RWMB_VER );
17
 
18
- /**
19
- * Since June 2016, Google Maps requires a valid API key.
20
- *
21
- * @link http://googlegeodevelopers.blogspot.com/2016/06/building-for-scale-updates-to-google.html
22
- * @link https://developers.google.com/maps/documentation/javascript/get-api-key
23
- */
24
  $args = func_get_args();
25
  $field = $args[0];
26
- $google_maps_url = add_query_arg(
27
- array(
28
- 'key' => $field['api_key'],
29
- 'language' => $field['language'],
30
- 'libraries' => 'places'
31
- ),
32
- 'https://maps.google.com/maps/api/js'
33
- );
34
 
35
  /**
36
  * Allows developers load more libraries via a filter.
37
- *
38
  * @link https://developers.google.com/maps/documentation/javascript/libraries
39
  */
40
  $google_maps_url = apply_filters( 'rwmb_google_maps_url', $google_maps_url );
41
- wp_register_script( 'google-maps', esc_url_raw( $google_maps_url ), array(), RWMB_VER, true );
42
- wp_enqueue_script(
43
- 'rwmb-map',
44
- RWMB_JS_URL . 'map.js',
45
- array(
46
- 'jquery-ui-autocomplete',
47
- 'google-maps',
48
- ),
49
- RWMB_VER,
50
- true
51
- );
52
- RWMB_Helpers_Field::localize_script_once(
53
- 'rwmb-map',
54
- 'RWMB_Map',
55
- array(
56
- 'no_results_string' => __( 'No results found', 'meta-box' ),
57
- )
58
- );
59
  }
60
 
61
  /**
@@ -99,19 +68,16 @@ class RWMB_Map_Field extends RWMB_Field {
99
  */
100
  public static function normalize( $field ) {
101
  $field = parent::normalize( $field );
102
- $field = wp_parse_args(
103
- $field,
104
- array(
105
- 'std' => '',
106
- 'address_field' => '',
107
- 'language' => '',
108
- 'region' => '',
109
-
110
- // Default API key, required by Google Maps since June 2016.
111
- // Users should overwrite this key with their own key.
112
- 'api_key' => 'AIzaSyC1mUh87SGFyf133tpZQJa-s96p0tgnraQ',
113
- )
114
- );
115
 
116
  return $field;
117
  }
@@ -127,7 +93,7 @@ class RWMB_Map_Field extends RWMB_Field {
127
  *
128
  * @return mixed Array(latitude, longitude, zoom)
129
  */
130
- public static function get_value( $field, $args = array(), $post_id = null ) {
131
  $value = parent::get_value( $field, $args, $post_id );
132
  list( $latitude, $longitude, $zoom ) = explode( ',', $value . ',,' );
133
  return compact( 'latitude', 'longitude', 'zoom' );
@@ -143,49 +109,43 @@ class RWMB_Map_Field extends RWMB_Field {
143
  *
144
  * @return string HTML output of the field
145
  */
146
- public static function the_value( $field, $args = array(), $post_id = null ) {
147
  $value = parent::get_value( $field, $args, $post_id );
148
- $args = wp_parse_args(
149
- $args,
150
- array(
151
- 'api_key' => isset( $field['api_key'] ) ? $field['api_key'] : '',
152
- )
153
- );
154
  return self::render_map( $value, $args );
155
  }
156
 
157
  /**
158
  * Render a map in the frontend.
159
  *
160
- * @param array $location The [latitude, longitude[, zoom]] location.
161
- * @param array $args Additional arguments for the map.
162
  *
163
  * @return string
164
  */
165
- public static function render_map( $location, $args = array() ) {
166
  list( $latitude, $longitude, $zoom ) = explode( ',', $location . ',,' );
167
  if ( ! $latitude || ! $longitude ) {
168
  return '';
169
  }
170
 
171
- $args = wp_parse_args(
172
- $args,
173
- array(
174
- 'latitude' => $latitude,
175
- 'longitude' => $longitude,
176
- 'width' => '100%',
177
- 'height' => '480px',
178
- 'marker' => true, // Display marker?
179
- 'marker_title' => '', // Marker title, when hover.
180
- 'info_window' => '', // Content of info window (when click on marker). HTML allowed.
181
- 'js_options' => array(),
182
- 'zoom' => $zoom,
183
-
184
- // Default API key, required by Google Maps since June 2016.
185
- // Users should overwrite this key with their own key.
186
- 'api_key' => 'AIzaSyC1mUh87SGFyf133tpZQJa-s96p0tgnraQ',
187
- )
188
- );
189
 
190
  $google_maps_url = add_query_arg( 'key', $args['api_key'], 'https://maps.google.com/maps/api/js' );
191
 
@@ -194,8 +154,8 @@ class RWMB_Map_Field extends RWMB_Field {
194
  * @link https://developers.google.com/maps/documentation/javascript/libraries
195
  */
196
  $google_maps_url = apply_filters( 'rwmb_google_maps_url', $google_maps_url );
197
- wp_register_script( 'google-maps', esc_url_raw( $google_maps_url ), array(), RWMB_VER, true );
198
- wp_enqueue_script( 'rwmb-map-frontend', RWMB_JS_URL . 'map-frontend.js', array( 'google-maps', 'jquery' ), RWMB_VER, true );
199
 
200
  /*
201
  * Google Maps options.
@@ -203,19 +163,16 @@ class RWMB_Map_Field extends RWMB_Field {
203
  * This array will be convert to Javascript Object and pass as map options.
204
  * @link https://developers.google.com/maps/documentation/javascript/reference
205
  */
206
- $args['js_options'] = wp_parse_args(
207
- $args['js_options'],
208
- array(
209
- // Default to 'zoom' level set in admin, but can be overwritten.
210
- 'zoom' => $args['zoom'],
211
-
212
- // Map type, see https://developers.google.com/maps/documentation/javascript/reference#MapTypeId.
213
- 'mapTypeId' => 'ROADMAP',
214
-
215
- // Open Info Window
216
- 'openInfoWindow' => false,
217
- )
218
- );
219
 
220
  $output = sprintf(
221
  '<div class="rwmb-map-canvas" data-map_options="%s" style="width:%s;height:%s"></div>',
1
  <?php
2
  /**
3
  * The Google Maps field.
 
 
 
 
 
 
4
  */
5
  class RWMB_Map_Field extends RWMB_Field {
 
 
 
6
  public static function admin_enqueue_scripts() {
7
+ wp_enqueue_style( 'rwmb-map', RWMB_CSS_URL . 'map.css', [], RWMB_VER );
8
 
 
 
 
 
 
 
9
  $args = func_get_args();
10
  $field = $args[0];
11
+ $google_maps_url = add_query_arg( [
12
+ 'key' => $field['api_key'],
13
+ 'language' => $field['language'],
14
+ 'libraries' => 'places',
15
+ ], 'https://maps.google.com/maps/api/js' );
 
 
 
16
 
17
  /**
18
  * Allows developers load more libraries via a filter.
 
19
  * @link https://developers.google.com/maps/documentation/javascript/libraries
20
  */
21
  $google_maps_url = apply_filters( 'rwmb_google_maps_url', $google_maps_url );
22
+
23
+ wp_register_script( 'google-maps', esc_url_raw( $google_maps_url ), [], RWMB_VER, true );
24
+ wp_enqueue_script( 'rwmb-map', RWMB_JS_URL . 'map.js', [ 'jquery-ui-autocomplete', 'google-maps' ], RWMB_VER, true );
25
+ RWMB_Helpers_Field::localize_script_once( 'rwmb-map', 'RWMB_Map', [
26
+ 'no_results_string' => __( 'No results found', 'meta-box' ),
27
+ ] );
 
 
 
 
 
 
 
 
 
 
 
 
28
  }
29
 
30
  /**
68
  */
69
  public static function normalize( $field ) {
70
  $field = parent::normalize( $field );
71
+ $field = wp_parse_args( $field, [
72
+ 'std' => '',
73
+ 'address_field' => '',
74
+ 'language' => '',
75
+ 'region' => '',
76
+
77
+ // Default API key, required by Google Maps since June 2016.
78
+ // Users should overwrite this key with their own key.
79
+ 'api_key' => 'AIzaSyC1mUh87SGFyf133tpZQJa-s96p0tgnraQ',
80
+ ] );
 
 
 
81
 
82
  return $field;
83
  }
93
  *
94
  * @return mixed Array(latitude, longitude, zoom)
95
  */
96
+ public static function get_value( $field, $args = [], $post_id = null ) {
97
  $value = parent::get_value( $field, $args, $post_id );
98
  list( $latitude, $longitude, $zoom ) = explode( ',', $value . ',,' );
99
  return compact( 'latitude', 'longitude', 'zoom' );
109
  *
110
  * @return string HTML output of the field
111
  */
112
+ public static function the_value( $field, $args = [], $post_id = null ) {
113
  $value = parent::get_value( $field, $args, $post_id );
114
+ $args = wp_parse_args( $args, [
115
+ 'api_key' => $field['api_key'] ?? '',
116
+ ] );
 
 
 
117
  return self::render_map( $value, $args );
118
  }
119
 
120
  /**
121
  * Render a map in the frontend.
122
  *
123
+ * @param string $location The "latitude,longitude[,zoom]" location.
124
+ * @param array $args Additional arguments for the map.
125
  *
126
  * @return string
127
  */
128
+ public static function render_map( $location, $args = [] ) {
129
  list( $latitude, $longitude, $zoom ) = explode( ',', $location . ',,' );
130
  if ( ! $latitude || ! $longitude ) {
131
  return '';
132
  }
133
 
134
+ $args = wp_parse_args( $args, [
135
+ 'latitude' => $latitude,
136
+ 'longitude' => $longitude,
137
+ 'width' => '100%',
138
+ 'height' => '480px',
139
+ 'marker' => true, // Display marker?
140
+ 'marker_title' => '', // Marker title, when hover.
141
+ 'info_window' => '', // Content of info window (when click on marker). HTML allowed.
142
+ 'js_options' => [],
143
+ 'zoom' => $zoom,
144
+
145
+ // Default API key, required by Google Maps since June 2016.
146
+ // Users should overwrite this key with their own key.
147
+ 'api_key' => 'AIzaSyC1mUh87SGFyf133tpZQJa-s96p0tgnraQ',
148
+ ] );
 
 
 
149
 
150
  $google_maps_url = add_query_arg( 'key', $args['api_key'], 'https://maps.google.com/maps/api/js' );
151
 
154
  * @link https://developers.google.com/maps/documentation/javascript/libraries
155
  */
156
  $google_maps_url = apply_filters( 'rwmb_google_maps_url', $google_maps_url );
157
+ wp_register_script( 'google-maps', esc_url_raw( $google_maps_url ), [], RWMB_VER, true );
158
+ wp_enqueue_script( 'rwmb-map-frontend', RWMB_JS_URL . 'map-frontend.js', [ 'google-maps', 'jquery' ], RWMB_VER, true );
159
 
160
  /*
161
  * Google Maps options.
163
  * This array will be convert to Javascript Object and pass as map options.
164
  * @link https://developers.google.com/maps/documentation/javascript/reference
165
  */
166
+ $args['js_options'] = wp_parse_args( $args['js_options'], [
167
+ // Default to 'zoom' level set in admin, but can be overwritten.
168
+ 'zoom' => $args['zoom'],
169
+
170
+ // Map type, see https://developers.google.com/maps/documentation/javascript/reference#MapTypeId.
171
+ 'mapTypeId' => 'ROADMAP',
172
+
173
+ // Open Info Window
174
+ 'openInfoWindow' => false,
175
+ ] );
 
 
 
176
 
177
  $output = sprintf(
178
  '<div class="rwmb-map-canvas" data-map_options="%s" style="width:%s;height:%s"></div>',
inc/fields/media.php CHANGED
@@ -179,8 +179,7 @@ class RWMB_Media_Field extends RWMB_File_Field {
179
  * @return array|mixed
180
  */
181
  public static function value( $new, $old, $post_id, $field ) {
182
- $new = RWMB_Helpers_Array::from_csv( $new );
183
- $new = array_filter( array_unique( array_map( 'absint', $new ) ) );
184
 
185
  // Attach the uploaded images to the post if needed.
186
  global $wpdb;
179
  * @return array|mixed
180
  */
181
  public static function value( $new, $old, $post_id, $field ) {
182
+ $new = wp_parse_id_list( $new );
 
183
 
184
  // Attach the uploaded images to the post if needed.
185
  global $wpdb;
inc/fields/multiple-values.php CHANGED
@@ -7,12 +7,6 @@
7
  * meta value. Briefly:
8
  * - If field is cloneable, value is saved as a single entry in the database
9
  * - Otherwise value is saved as multiple entries
10
- *
11
- * @package Meta Box
12
- */
13
-
14
- /**
15
- * Multiple values field class.
16
  */
17
  abstract class RWMB_Multiple_Values_Field extends RWMB_Field {
18
  /**
7
  * meta value. Briefly:
8
  * - If field is cloneable, value is saved as a single entry in the database
9
  * - Otherwise value is saved as multiple entries
 
 
 
 
 
 
10
  */
11
  abstract class RWMB_Multiple_Values_Field extends RWMB_Field {
12
  /**
inc/fields/number.php CHANGED
@@ -1,12 +1,6 @@
1
  <?php
2
  /**
3
  * The number field which uses HTML <input type="number">.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Number field class.
10
  */
11
  class RWMB_Number_Field extends RWMB_Input_Field {
12
  /**
@@ -18,15 +12,11 @@ class RWMB_Number_Field extends RWMB_Input_Field {
18
  */
19
  public static function normalize( $field ) {
20
  $field = parent::normalize( $field );
21
-
22
- $field = wp_parse_args(
23
- $field,
24
- array(
25
- 'step' => 1,
26
- 'min' => 0,
27
- 'max' => false,
28
- )
29
- );
30
 
31
  return $field;
32
  }
@@ -41,14 +31,11 @@ class RWMB_Number_Field extends RWMB_Input_Field {
41
  */
42
  public static function get_attributes( $field, $value = null ) {
43
  $attributes = parent::get_attributes( $field, $value );
44
- $attributes = wp_parse_args(
45
- $attributes,
46
- array(
47
- 'step' => $field['step'],
48
- 'max' => $field['max'],
49
- 'min' => $field['min'],
50
- )
51
- );
52
  return $attributes;
53
  }
54
  }
1
  <?php
2
  /**
3
  * The number field which uses HTML <input type="number">.
 
 
 
 
 
 
4
  */
5
  class RWMB_Number_Field extends RWMB_Input_Field {
6
  /**
12
  */
13
  public static function normalize( $field ) {
14
  $field = parent::normalize( $field );
15
+ $field = wp_parse_args( $field, [
16
+ 'step' => 1,
17
+ 'min' => 0,
18
+ 'max' => false,
19
+ ] );
 
 
 
 
20
 
21
  return $field;
22
  }
31
  */
32
  public static function get_attributes( $field, $value = null ) {
33
  $attributes = parent::get_attributes( $field, $value );
34
+ $attributes = wp_parse_args( $attributes, [
35
+ 'step' => $field['step'],
36
+ 'max' => $field['max'],
37
+ 'min' => $field['min'],
38
+ ] );
 
 
 
39
  return $attributes;
40
  }
41
  }
inc/fields/object-choice.php CHANGED
@@ -24,9 +24,7 @@ abstract class RWMB_Object_Choice_Field extends RWMB_Choice_Field {
24
  parent::show( $field, $saved, $post_id );
25
  }
26
 
27
- public static function query( $meta, $field ) {
28
- return [];
29
- }
30
 
31
  /**
32
  * Get field HTML.
24
  parent::show( $field, $saved, $post_id );
25
  }
26
 
27
+ abstract protected static function query( $meta, array $field ) : array;
 
 
28
 
29
  /**
30
  * Get field HTML.
inc/fields/oembed.php CHANGED
@@ -1,12 +1,6 @@
1
  <?php
2
  /**
3
  * The oEmbed field which allows users to enter oEmbed URLs.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * OEmbed field class.
10
  */
11
  class RWMB_OEmbed_Field extends RWMB_Input_Field {
12
  /**
@@ -18,41 +12,26 @@ class RWMB_OEmbed_Field extends RWMB_Input_Field {
18
  public static function normalize( $field ) {
19
  $field = parent::normalize( $field );
20
 
21
- $field = wp_parse_args(
22
- $field,
23
- array(
24
- 'not_available_string' => __( 'Embed HTML not available.', 'meta-box' ),
25
- )
26
- );
27
- $field['attributes'] = wp_parse_args(
28
- $field['attributes'],
29
- array(
30
- 'data-not-available' => $field['not_available_string'],
31
- )
32
- );
33
 
34
  return $field;
35
  }
36
 
37
- /**
38
- * Enqueue scripts and styles.
39
- */
40
  public static function admin_enqueue_scripts() {
41
- wp_enqueue_style( 'rwmb-oembed', RWMB_CSS_URL . 'oembed.css', '', RWMB_VER );
42
- wp_enqueue_script( 'rwmb-oembed', RWMB_JS_URL . 'oembed.js', array( 'jquery', 'underscore' ), RWMB_VER, true );
43
  }
44
 
45
- /**
46
- * Add actions.
47
- */
48
  public static function add_actions() {
49
- add_action( 'wp_ajax_rwmb_get_embed', array( __CLASS__, 'wp_ajax_get_embed' ) );
50
  }
51
 
52
- /**
53
- * Ajax callback for returning oEmbed HTML.
54
- */
55
- public static function wp_ajax_get_embed() {
56
  $request = rwmb_request();
57
  $url = (string) $request->filter_post( 'url', FILTER_SANITIZE_URL );
58
  $not_available = (string) $request->post( 'not_available' );
@@ -76,7 +55,7 @@ class RWMB_OEmbed_Field extends RWMB_Input_Field {
76
  * @see WP_Embed::shortcode()
77
  * @see wp_embed_defaults()
78
  */
79
- $args = array();
80
  if ( is_admin() ) {
81
  $args['width'] = 360;
82
  }
1
  <?php
2
  /**
3
  * The oEmbed field which allows users to enter oEmbed URLs.
 
 
 
 
 
 
4
  */
5
  class RWMB_OEmbed_Field extends RWMB_Input_Field {
6
  /**
12
  public static function normalize( $field ) {
13
  $field = parent::normalize( $field );
14
 
15
+ $field = wp_parse_args( $field, [
16
+ 'not_available_string' => __( 'Embed HTML not available.', 'meta-box' ),
17
+ ] );
18
+ $field['attributes'] = wp_parse_args( $field['attributes'], [
19
+ 'data-not-available' => $field['not_available_string'],
20
+ ] );
 
 
 
 
 
 
21
 
22
  return $field;
23
  }
24
 
 
 
 
25
  public static function admin_enqueue_scripts() {
26
+ wp_enqueue_style( 'rwmb-oembed', RWMB_CSS_URL . 'oembed.css', [], RWMB_VER );
27
+ wp_enqueue_script( 'rwmb-oembed', RWMB_JS_URL . 'oembed.js', [ 'jquery', 'underscore' ], RWMB_VER, true );
28
  }
29
 
 
 
 
30
  public static function add_actions() {
31
+ add_action( 'wp_ajax_rwmb_get_embed', [ __CLASS__, 'ajax_get_embed' ] );
32
  }
33
 
34
+ public static function ajax_get_embed() {
 
 
 
35
  $request = rwmb_request();
36
  $url = (string) $request->filter_post( 'url', FILTER_SANITIZE_URL );
37
  $not_available = (string) $request->post( 'not_available' );
55
  * @see WP_Embed::shortcode()
56
  * @see wp_embed_defaults()
57
  */
58
+ $args = [];
59
  if ( is_admin() ) {
60
  $args['width'] = 360;
61
  }
inc/fields/osm.php CHANGED
@@ -1,33 +1,17 @@
1
  <?php
2
  /**
3
  * The Open Street Map field.
4
- *
5
- * @package Meta Box
6
- * @since 4.15.0
7
- */
8
-
9
- /**
10
- * Open Street Map field class.
11
  */
12
  class RWMB_OSM_Field extends RWMB_Field {
13
- /**
14
- * Enqueue scripts and styles.
15
- */
16
  public static function admin_enqueue_scripts() {
17
- // Because map is a hosted service, it's ok to use hosted Leaflet scripts.
18
- wp_enqueue_style( 'leaflet', 'https://unpkg.com/leaflet@1.7.1/dist/leaflet.css', array(), '1.7.1' );
19
- wp_enqueue_script( 'leaflet', 'https://unpkg.com/leaflet@1.7.1/dist/leaflet.js', array(), '1.7.1', true );
20
-
21
- wp_enqueue_style( 'rwmb-osm', RWMB_CSS_URL . 'osm.css', array( 'leaflet' ), RWMB_VER );
22
- wp_enqueue_script( 'rwmb-osm', RWMB_JS_URL . 'osm.js', array( 'jquery', 'jquery-ui-autocomplete', 'leaflet' ), RWMB_VER, true );
23
-
24
- RWMB_Helpers_Field::localize_script_once(
25
- 'rwmb-osm',
26
- 'RWMB_Osm',
27
- array(
28
- 'no_results_string' => __( 'No results found', 'meta-box' ),
29
- )
30
- );
31
  }
32
 
33
  /**
@@ -72,15 +56,12 @@ class RWMB_OSM_Field extends RWMB_Field {
72
  */
73
  public static function normalize( $field ) {
74
  $field = parent::normalize( $field );
75
- $field = wp_parse_args(
76
- $field,
77
- array(
78
- 'std' => '',
79
- 'address_field' => '',
80
- 'language' => '',
81
- 'region' => '',
82
- )
83
- );
84
 
85
  return $field;
86
  }
@@ -96,7 +77,7 @@ class RWMB_OSM_Field extends RWMB_Field {
96
  *
97
  * @return mixed Array(latitude, longitude, zoom)
98
  */
99
- public static function get_value( $field, $args = array(), $post_id = null ) {
100
  $value = parent::get_value( $field, $args, $post_id );
101
  list( $latitude, $longitude, $zoom ) = explode( ',', $value . ',,' );
102
  return compact( 'latitude', 'longitude', 'zoom' );
@@ -112,7 +93,7 @@ class RWMB_OSM_Field extends RWMB_Field {
112
  *
113
  * @return string HTML output of the field
114
  */
115
- public static function the_value( $field, $args = array(), $post_id = null ) {
116
  $value = parent::get_value( $field, $args, $post_id );
117
  return self::render_map( $value, $args );
118
  }
@@ -120,47 +101,40 @@ class RWMB_OSM_Field extends RWMB_Field {
120
  /**
121
  * Render a map in the frontend.
122
  *
123
- * @param array $location The [latitude, longitude[, zoom]] location.
124
- * @param array $args Additional arguments for the map.
125
  *
126
  * @return string
127
  */
128
- public static function render_map( $location, $args = array() ) {
129
  list( $latitude, $longitude, $zoom ) = explode( ',', $location . ',,' );
130
  if ( ! $latitude || ! $longitude ) {
131
  return '';
132
  }
133
 
134
- $args = wp_parse_args(
135
- $args,
136
- array(
137
- 'latitude' => $latitude,
138
- 'longitude' => $longitude,
139
- 'width' => '100%',
140
- 'height' => '480px',
141
- 'marker' => true, // Display marker?
142
- 'marker_title' => '', // Marker title, when hover.
143
- 'info_window' => '', // Content of info window (when click on marker). HTML allowed.
144
- 'js_options' => array(),
145
- 'zoom' => $zoom,
146
- )
147
- );
148
-
149
- wp_enqueue_style( 'leaflet', 'https://unpkg.com/leaflet@1.5.1/dist/leaflet.css', array(), '1.5.1' );
150
- wp_enqueue_script( 'leaflet', 'https://unpkg.com/leaflet@1.5.1/dist/leaflet.js', array(), '1.5.1', true );
151
- wp_enqueue_script( 'rwmb-osm-frontend', RWMB_JS_URL . 'osm-frontend.js', array( 'jquery', 'leaflet' ), RWMB_VER, true );
152
 
153
  /*
154
  * More Open Street Map options
155
  * @link https://leafletjs.com/reference-1.5.0.html#map-option
156
  */
157
- $args['js_options'] = wp_parse_args(
158
- $args['js_options'],
159
- array(
160
- // Default to 'zoom' level set in admin, but can be overwritten.
161
- 'zoom' => $args['zoom'],
162
- )
163
- );
164
 
165
  $output = sprintf(
166
  '<div class="rwmb-osm-canvas" data-osm_options="%s" style="width:%s;height:%s"></div>',
@@ -170,4 +144,9 @@ class RWMB_OSM_Field extends RWMB_Field {
170
  );
171
  return $output;
172
  }
 
 
 
 
 
173
  }
1
  <?php
2
  /**
3
  * The Open Street Map field.
 
 
 
 
 
 
 
4
  */
5
  class RWMB_OSM_Field extends RWMB_Field {
 
 
 
6
  public static function admin_enqueue_scripts() {
7
+ self::enqueue_map_assets();
8
+
9
+ wp_enqueue_style( 'rwmb-osm', RWMB_CSS_URL . 'osm.css', [ 'leaflet' ], RWMB_VER );
10
+ wp_enqueue_script( 'rwmb-osm', RWMB_JS_URL . 'osm.js', [ 'jquery', 'jquery-ui-autocomplete', 'leaflet' ], RWMB_VER, true );
11
+
12
+ RWMB_Helpers_Field::localize_script_once( 'rwmb-osm', 'RWMB_Osm', [
13
+ 'no_results_string' => __( 'No results found', 'meta-box' ),
14
+ ] );
 
 
 
 
 
 
15
  }
16
 
17
  /**
56
  */
57
  public static function normalize( $field ) {
58
  $field = parent::normalize( $field );
59
+ $field = wp_parse_args( $field, [
60
+ 'std' => '',
61
+ 'address_field' => '',
62
+ 'language' => '',
63
+ 'region' => '',
64
+ ] );
 
 
 
65
 
66
  return $field;
67
  }
77
  *
78
  * @return mixed Array(latitude, longitude, zoom)
79
  */
80
+ public static function get_value( $field, $args = [], $post_id = null ) {
81
  $value = parent::get_value( $field, $args, $post_id );
82
  list( $latitude, $longitude, $zoom ) = explode( ',', $value . ',,' );
83
  return compact( 'latitude', 'longitude', 'zoom' );
93
  *
94
  * @return string HTML output of the field
95
  */
96
+ public static function the_value( $field, $args = [], $post_id = null ) {
97
  $value = parent::get_value( $field, $args, $post_id );
98
  return self::render_map( $value, $args );
99
  }
101
  /**
102
  * Render a map in the frontend.
103
  *
104
+ * @param string $location The "latitude,longitude[,zoom]" location.
105
+ * @param array $args Additional arguments for the map.
106
  *
107
  * @return string
108
  */
109
+ public static function render_map( $location, $args = [] ) {
110
  list( $latitude, $longitude, $zoom ) = explode( ',', $location . ',,' );
111
  if ( ! $latitude || ! $longitude ) {
112
  return '';
113
  }
114
 
115
+ $args = wp_parse_args( $args, [
116
+ 'latitude' => $latitude,
117
+ 'longitude' => $longitude,
118
+ 'width' => '100%',
119
+ 'height' => '480px',
120
+ 'marker' => true, // Display marker?
121
+ 'marker_title' => '', // Marker title, when hover.
122
+ 'info_window' => '', // Content of info window (when click on marker). HTML allowed.
123
+ 'js_options' => [],
124
+ 'zoom' => $zoom,
125
+ ] );
126
+
127
+ self::enqueue_map_assets();
128
+ wp_enqueue_script( 'rwmb-osm-frontend', RWMB_JS_URL . 'osm-frontend.js', [ 'jquery', 'leaflet' ], RWMB_VER, true );
 
 
 
 
129
 
130
  /*
131
  * More Open Street Map options
132
  * @link https://leafletjs.com/reference-1.5.0.html#map-option
133
  */
134
+ $args['js_options'] = wp_parse_args( $args['js_options'], [
135
+ // Default to 'zoom' level set in admin, but can be overwritten.
136
+ 'zoom' => $args['zoom'],
137
+ ] );
 
 
 
138
 
139
  $output = sprintf(
140
  '<div class="rwmb-osm-canvas" data-osm_options="%s" style="width:%s;height:%s"></div>',
144
  );
145
  return $output;
146
  }
147
+
148
+ private static function enqueue_map_assets() {
149
+ wp_enqueue_style( 'leaflet', 'https://unpkg.com/leaflet@1.9.3/dist/leaflet.css', [], '1.9.3' );
150
+ wp_enqueue_script( 'leaflet', 'https://unpkg.com/leaflet@1.9.3/dist/leaflet.js', [], '1.9.3', true );
151
+ }
152
  }
inc/fields/password.php CHANGED
@@ -1,12 +1,6 @@
1
  <?php
2
  /**
3
  * The secured password field.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Password field class.
10
  */
11
  class RWMB_Password_Field extends RWMB_Input_Field {
12
  /**
1
  <?php
2
  /**
3
  * The secured password field.
 
 
 
 
 
 
4
  */
5
  class RWMB_Password_Field extends RWMB_Input_Field {
6
  /**
inc/fields/post.php CHANGED
@@ -1,25 +1,13 @@
1
  <?php
2
  /**
3
  * The post field which allows users to select existing posts.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Post field class.
10
  */
11
  class RWMB_Post_Field extends RWMB_Object_Choice_Field {
12
- /**
13
- * Add ajax actions callback.
14
- */
15
  public static function add_actions() {
16
- add_action( 'wp_ajax_rwmb_get_posts', array( __CLASS__, 'ajax_get_posts' ) );
17
- add_action( 'wp_ajax_nopriv_rwmb_get_posts', array( __CLASS__, 'ajax_get_posts' ) );
18
  }
19
 
20
- /**
21
- * Query posts via ajax.
22
- */
23
  public static function ajax_get_posts() {
24
  check_ajax_referer( 'query' );
25
 
@@ -43,7 +31,7 @@ class RWMB_Post_Field extends RWMB_Object_Choice_Field {
43
  $items = self::query( null, $field );
44
  $items = array_values( $items );
45
 
46
- $data = array( 'items' => $items );
47
 
48
  // More items for pagination.
49
  $limit = (int) $field['query_args']['posts_per_page'];
@@ -61,14 +49,11 @@ class RWMB_Post_Field extends RWMB_Object_Choice_Field {
61
  * @return array
62
  */
63
  public static function normalize( $field ) {
64
- $field = wp_parse_args(
65
- $field,
66
- array(
67
- 'post_type' => 'post',
68
- 'parent' => false,
69
- 'query_args' => array(),
70
- )
71
- );
72
 
73
  $field['post_type'] = (array) $field['post_type'];
74
 
@@ -86,12 +71,9 @@ class RWMB_Post_Field extends RWMB_Object_Choice_Field {
86
  $placeholder = sprintf( __( 'Select a %s', 'meta-box' ), strtolower( $post_type_object->labels->singular_name ) );
87
  }
88
  }
89
- $field = wp_parse_args(
90
- $field,
91
- array(
92
- 'placeholder' => $placeholder,
93
- )
94
- );
95
 
96
  // Set parent option, which will change field name to `parent_id` to save as post parent.
97
  if ( $field['parent'] ) {
@@ -103,36 +85,23 @@ class RWMB_Post_Field extends RWMB_Object_Choice_Field {
103
 
104
  // Set default query args.
105
  $posts_per_page = $field['ajax'] ? 10 : -1;
106
- $field['query_args'] = wp_parse_args(
107
- $field['query_args'],
108
- array(
109
- 'post_type' => $field['post_type'],
110
- 'post_status' => 'publish',
111
- 'posts_per_page' => $posts_per_page,
112
- )
113
- );
114
 
115
  parent::set_ajax_params( $field );
116
 
117
  return $field;
118
  }
119
 
120
- /**
121
- * Query posts for field options.
122
- *
123
- * @param array $meta Saved meta value.
124
- * @param array $field Field settings.
125
- * @return array Field options array.
126
- */
127
- public static function query( $meta, $field ) {
128
- $args = wp_parse_args(
129
- $field['query_args'],
130
- array(
131
- 'no_found_rows' => true,
132
- 'update_post_meta_cache' => false,
133
- 'update_post_term_cache' => false,
134
- )
135
- );
136
 
137
  // Query only selected items.
138
  if ( ! empty( $field['ajax'] ) && ! empty( $meta ) ) {
@@ -155,15 +124,15 @@ class RWMB_Post_Field extends RWMB_Object_Choice_Field {
155
  $query = new WP_Query( $args );
156
  remove_filter( 'posts_search', [ __CLASS__, 'search_by_title' ] );
157
 
158
- $options = array();
159
  foreach ( $query->posts as $post ) {
160
  $label = $post->post_title ? $post->post_title : __( '(No title)', 'meta-box' );
161
  $label = self::filter( 'choice_label', $label, $field, $post );
162
- $options[ $post->ID ] = array(
163
  'value' => $post->ID,
164
  'label' => $label,
165
  'parent' => $post->post_parent,
166
- );
167
  }
168
 
169
  // Cache the query.
@@ -185,7 +154,7 @@ class RWMB_Post_Field extends RWMB_Object_Choice_Field {
185
  }
186
  $q = $wp_query->query_vars;
187
  $n = ! empty( $q['exact'] ) ? '' : '%';
188
- $search = array();
189
  foreach ( (array) $q['search_terms'] as $term ) {
190
  $term = esc_sql( $wpdb->esc_like( $term ) );
191
  $search[] = "($wpdb->posts.post_title LIKE '{$n}{$term}{$n}')";
@@ -220,10 +189,10 @@ class RWMB_Post_Field extends RWMB_Object_Choice_Field {
220
  /**
221
  * Format a single value for the helper functions. Sub-fields should overwrite this method if necessary.
222
  *
223
- * @param array $field Field parameters.
224
- * @param string $value The value.
225
- * @param array $args Additional arguments. Rarely used. See specific fields for details.
226
- * @param ?int $post_id Post ID. null for current post. Optional.
227
  *
228
  * @return string
229
  */
@@ -232,15 +201,13 @@ class RWMB_Post_Field extends RWMB_Object_Choice_Field {
232
  return '';
233
  }
234
 
235
- $link = isset( $args['link'] ) ? $args['link'] : 'view';
236
  $text = get_the_title( $value );
237
 
238
  if ( false === $link ) {
239
  return $text;
240
  }
241
- if ( 'view' === $link ) {
242
- $url = get_permalink( $value );
243
- }
244
  if ( 'edit' === $link ) {
245
  $url = get_edit_post_link( $value );
246
  }
1
  <?php
2
  /**
3
  * The post field which allows users to select existing posts.
 
 
 
 
 
 
4
  */
5
  class RWMB_Post_Field extends RWMB_Object_Choice_Field {
 
 
 
6
  public static function add_actions() {
7
+ add_action( 'wp_ajax_rwmb_get_posts', [ __CLASS__, 'ajax_get_posts' ] );
8
+ add_action( 'wp_ajax_nopriv_rwmb_get_posts', [ __CLASS__, 'ajax_get_posts' ] );
9
  }
10
 
 
 
 
11
  public static function ajax_get_posts() {
12
  check_ajax_referer( 'query' );
13
 
31
  $items = self::query( null, $field );
32
  $items = array_values( $items );
33
 
34
+ $data = [ 'items' => $items ];
35
 
36
  // More items for pagination.
37
  $limit = (int) $field['query_args']['posts_per_page'];
49
  * @return array
50
  */
51
  public static function normalize( $field ) {
52
+ $field = wp_parse_args( $field, [
53
+ 'post_type' => 'post',
54
+ 'parent' => false,
55
+ 'query_args' => [],
56
+ ] );
 
 
 
57
 
58
  $field['post_type'] = (array) $field['post_type'];
59
 
71
  $placeholder = sprintf( __( 'Select a %s', 'meta-box' ), strtolower( $post_type_object->labels->singular_name ) );
72
  }
73
  }
74
+ $field = wp_parse_args( $field, [
75
+ 'placeholder' => $placeholder,
76
+ ] );
 
 
 
77
 
78
  // Set parent option, which will change field name to `parent_id` to save as post parent.
79
  if ( $field['parent'] ) {
85
 
86
  // Set default query args.
87
  $posts_per_page = $field['ajax'] ? 10 : -1;
88
+ $field['query_args'] = wp_parse_args( $field['query_args'], [
89
+ 'post_type' => $field['post_type'],
90
+ 'post_status' => 'publish',
91
+ 'posts_per_page' => $posts_per_page,
92
+ ] );
 
 
 
93
 
94
  parent::set_ajax_params( $field );
95
 
96
  return $field;
97
  }
98
 
99
+ protected static function query( $meta, array $field ) : array {
100
+ $args = wp_parse_args( $field['query_args'], [
101
+ 'no_found_rows' => true,
102
+ 'update_post_meta_cache' => false,
103
+ 'update_post_term_cache' => false,
104
+ ] );
 
 
 
 
 
 
 
 
 
 
105
 
106
  // Query only selected items.
107
  if ( ! empty( $field['ajax'] ) && ! empty( $meta ) ) {
124
  $query = new WP_Query( $args );
125
  remove_filter( 'posts_search', [ __CLASS__, 'search_by_title' ] );
126
 
127
+ $options = [];
128
  foreach ( $query->posts as $post ) {
129
  $label = $post->post_title ? $post->post_title : __( '(No title)', 'meta-box' );
130
  $label = self::filter( 'choice_label', $label, $field, $post );
131
+ $options[ $post->ID ] = [
132
  'value' => $post->ID,
133
  'label' => $label,
134
  'parent' => $post->post_parent,
135
+ ];
136
  }
137
 
138
  // Cache the query.
154
  }
155
  $q = $wp_query->query_vars;
156
  $n = ! empty( $q['exact'] ) ? '' : '%';
157
+ $search = [];
158
  foreach ( (array) $q['search_terms'] as $term ) {
159
  $term = esc_sql( $wpdb->esc_like( $term ) );
160
  $search[] = "($wpdb->posts.post_title LIKE '{$n}{$term}{$n}')";
189
  /**
190
  * Format a single value for the helper functions. Sub-fields should overwrite this method if necessary.
191
  *
192
+ * @param array $field Field parameters.
193
+ * @param int $value The value.
194
+ * @param array $args Additional arguments. Rarely used. See specific fields for details.
195
+ * @param ?int $post_id Post ID. null for current post. Optional.
196
  *
197
  * @return string
198
  */
201
  return '';
202
  }
203
 
204
+ $link = $args['link'] ?? 'view';
205
  $text = get_the_title( $value );
206
 
207
  if ( false === $link ) {
208
  return $text;
209
  }
210
+ $url = get_permalink( $value );
 
 
211
  if ( 'edit' === $link ) {
212
  $url = get_edit_post_link( $value );
213
  }
inc/fields/range.php CHANGED
@@ -1,12 +1,6 @@
1
  <?php
2
  /**
3
  * The HTML5 range field.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * HTML5 range field class.
10
  */
11
  class RWMB_Range_Field extends RWMB_Number_Field {
12
  /**
@@ -27,12 +21,9 @@ class RWMB_Range_Field extends RWMB_Number_Field {
27
  );
28
  }
29
 
30
- /**
31
- * Enqueue styles.
32
- */
33
  public static function admin_enqueue_scripts() {
34
- wp_enqueue_style( 'rwmb-range', RWMB_CSS_URL . 'range.css', array(), RWMB_VER );
35
- wp_enqueue_script( 'rwmb-range', RWMB_JS_URL . 'range.js', array(), RWMB_VER, true );
36
  }
37
 
38
  /**
@@ -42,12 +33,9 @@ class RWMB_Range_Field extends RWMB_Number_Field {
42
  * @return array
43
  */
44
  public static function normalize( $field ) {
45
- $field = wp_parse_args(
46
- $field,
47
- array(
48
- 'max' => 10,
49
- )
50
- );
51
  $field = parent::normalize( $field );
52
  return $field;
53
  }
1
  <?php
2
  /**
3
  * The HTML5 range field.
 
 
 
 
 
 
4
  */
5
  class RWMB_Range_Field extends RWMB_Number_Field {
6
  /**
21
  );
22
  }
23
 
 
 
 
24
  public static function admin_enqueue_scripts() {
25
+ wp_enqueue_style( 'rwmb-range', RWMB_CSS_URL . 'range.css', [], RWMB_VER );
26
+ wp_enqueue_script( 'rwmb-range', RWMB_JS_URL . 'range.js', [], RWMB_VER, true );
27
  }
28
 
29
  /**
33
  * @return array
34
  */
35
  public static function normalize( $field ) {
36
+ $field = wp_parse_args( $field, [
37
+ 'max' => 10,
38
+ ] );
 
 
 
39
  $field = parent::normalize( $field );
40
  return $field;
41
  }
inc/fields/select-advanced.php CHANGED
@@ -1,32 +1,23 @@
1
  <?php
2
  /**
3
- * The beautiful select field which uses select2 library.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Select advanced field which uses select2 library.
10
  */
11
  class RWMB_Select_Advanced_Field extends RWMB_Select_Field {
12
- /**
13
- * Enqueue scripts and styles.
14
- */
15
  public static function admin_enqueue_scripts() {
16
  parent::admin_enqueue_scripts();
17
- wp_enqueue_style( 'rwmb-select2', RWMB_CSS_URL . 'select2/select2.css', array(), '4.0.10' );
18
- wp_enqueue_style( 'rwmb-select-advanced', RWMB_CSS_URL . 'select-advanced.css', array(), RWMB_VER );
19
 
20
- wp_register_script( 'rwmb-select2', RWMB_JS_URL . 'select2/select2.min.js', array( 'jquery' ), '4.0.10', true );
21
 
22
  // Localize.
23
- $dependencies = array( 'rwmb-select2', 'rwmb-select' );
24
  $locale = str_replace( '_', '-', get_locale() );
25
  $locale_short = substr( $locale, 0, 2 );
26
  $locale = file_exists( RWMB_DIR . "js/select2/i18n/$locale.js" ) ? $locale : $locale_short;
27
 
28
  if ( file_exists( RWMB_DIR . "js/select2/i18n/$locale.js" ) ) {
29
- wp_register_script( 'rwmb-select2-i18n', RWMB_JS_URL . "select2/i18n/$locale.js", array( 'rwmb-select2' ), '4.0.10', true );
30
  $dependencies[] = 'rwmb-select2-i18n';
31
  }
32
 
@@ -40,25 +31,19 @@ class RWMB_Select_Advanced_Field extends RWMB_Select_Field {
40
  * @return array
41
  */
42
  public static function normalize( $field ) {
43
- $field = wp_parse_args(
44
- $field,
45
- array(
46
- 'js_options' => array(),
47
- 'placeholder' => __( 'Select an item', 'meta-box' ),
48
- )
49
- );
50
 
51
  $field = parent::normalize( $field );
52
 
53
- $field['js_options'] = wp_parse_args(
54
- $field['js_options'],
55
- array(
56
- 'allowClear' => true,
57
- 'dropdownAutoWidth' => true,
58
- 'placeholder' => $field['placeholder'],
59
- 'width' => 'style',
60
- )
61
- );
62
 
63
  return $field;
64
  }
@@ -72,12 +57,9 @@ class RWMB_Select_Advanced_Field extends RWMB_Select_Field {
72
  */
73
  public static function get_attributes( $field, $value = null ) {
74
  $attributes = parent::get_attributes( $field, $value );
75
- $attributes = wp_parse_args(
76
- $attributes,
77
- array(
78
- 'data-options' => wp_json_encode( $field['js_options'] ),
79
- )
80
- );
81
 
82
  return $attributes;
83
  }
1
  <?php
2
  /**
3
+ * The beautiful select field using select2 library.
 
 
 
 
 
 
4
  */
5
  class RWMB_Select_Advanced_Field extends RWMB_Select_Field {
 
 
 
6
  public static function admin_enqueue_scripts() {
7
  parent::admin_enqueue_scripts();
8
+ wp_enqueue_style( 'rwmb-select2', RWMB_CSS_URL . 'select2/select2.css', [], '4.0.10' );
9
+ wp_enqueue_style( 'rwmb-select-advanced', RWMB_CSS_URL . 'select-advanced.css', [], RWMB_VER );
10
 
11
+ wp_register_script( 'rwmb-select2', RWMB_JS_URL . 'select2/select2.min.js', [ 'jquery' ], '4.0.10', true );
12
 
13
  // Localize.
14
+ $dependencies = [ 'rwmb-select2', 'rwmb-select' ];
15
  $locale = str_replace( '_', '-', get_locale() );
16
  $locale_short = substr( $locale, 0, 2 );
17
  $locale = file_exists( RWMB_DIR . "js/select2/i18n/$locale.js" ) ? $locale : $locale_short;
18
 
19
  if ( file_exists( RWMB_DIR . "js/select2/i18n/$locale.js" ) ) {
20
+ wp_register_script( 'rwmb-select2-i18n', RWMB_JS_URL . "select2/i18n/$locale.js", [ 'rwmb-select2' ], '4.0.10', true );
21
  $dependencies[] = 'rwmb-select2-i18n';
22
  }
23
 
31
  * @return array
32
  */
33
  public static function normalize( $field ) {
34
+ $field = wp_parse_args( $field, [
35
+ 'js_options' => [],
36
+ 'placeholder' => __( 'Select an item', 'meta-box' ),
37
+ ] );
 
 
 
38
 
39
  $field = parent::normalize( $field );
40
 
41
+ $field['js_options'] = wp_parse_args( $field['js_options'], [
42
+ 'allowClear' => true,
43
+ 'dropdownAutoWidth' => true,
44
+ 'placeholder' => $field['placeholder'],
45
+ 'width' => 'style',
46
+ ] );
 
 
 
47
 
48
  return $field;
49
  }
57
  */
58
  public static function get_attributes( $field, $value = null ) {
59
  $attributes = parent::get_attributes( $field, $value );
60
+ $attributes = wp_parse_args( $attributes, [
61
+ 'data-options' => wp_json_encode( $field['js_options'] ),
62
+ ] );
 
 
 
63
 
64
  return $attributes;
65
  }
inc/fields/select-tree.php CHANGED
@@ -1,12 +1,6 @@
1
  <?php
2
  /**
3
  * The select tree field.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Select tree field class.
10
  */
11
  class RWMB_Select_Tree_Field extends RWMB_Select_Advanced_Field {
12
  /**
@@ -22,13 +16,10 @@ class RWMB_Select_Tree_Field extends RWMB_Select_Advanced_Field {
22
  return $options ? $walker->walk( $options ) : '';
23
  }
24
 
25
- /**
26
- * Enqueue scripts and styles.
27
- */
28
  public static function admin_enqueue_scripts() {
29
  parent::admin_enqueue_scripts();
30
- wp_enqueue_style( 'rwmb-select-tree', RWMB_CSS_URL . 'select-tree.css', array( 'rwmb-select' ), RWMB_VER );
31
- wp_enqueue_script( 'rwmb-select-tree', RWMB_JS_URL . 'select-tree.js', array( 'rwmb-select' ), RWMB_VER, true );
32
  }
33
 
34
  /**
1
  <?php
2
  /**
3
  * The select tree field.
 
 
 
 
 
 
4
  */
5
  class RWMB_Select_Tree_Field extends RWMB_Select_Advanced_Field {
6
  /**
16
  return $options ? $walker->walk( $options ) : '';
17
  }
18
 
 
 
 
19
  public static function admin_enqueue_scripts() {
20
  parent::admin_enqueue_scripts();
21
+ wp_enqueue_style( 'rwmb-select-tree', RWMB_CSS_URL . 'select-tree.css', [ 'rwmb-select' ], RWMB_VER );
22
+ wp_enqueue_script( 'rwmb-select-tree', RWMB_JS_URL . 'select-tree.js', [ 'rwmb-select' ], RWMB_VER, true );
23
  }
24
 
25
  /**
inc/fields/select.php CHANGED
@@ -1,20 +1,11 @@
1
  <?php
2
  /**
3
  * The select field.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Select field class.
10
  */
11
  class RWMB_Select_Field extends RWMB_Choice_Field {
12
- /**
13
- * Enqueue scripts and styles.
14
- */
15
  public static function admin_enqueue_scripts() {
16
- wp_enqueue_style( 'rwmb-select', RWMB_CSS_URL . 'select.css', array(), RWMB_VER );
17
- wp_enqueue_script( 'rwmb-select', RWMB_JS_URL . 'select.js', array( 'jquery' ), RWMB_VER, true );
18
  }
19
 
20
  /**
@@ -51,12 +42,9 @@ class RWMB_Select_Field extends RWMB_Choice_Field {
51
  public static function normalize( $field ) {
52
  $field = parent::normalize( $field );
53
  $field = $field['multiple'] ? RWMB_Multiple_Values_Field::normalize( $field ) : $field;
54
- $field = wp_parse_args(
55
- $field,
56
- array(
57
- 'select_all_none' => false,
58
- )
59
- );
60
 
61
  return $field;
62
  }
@@ -71,12 +59,9 @@ class RWMB_Select_Field extends RWMB_Choice_Field {
71
  */
72
  public static function get_attributes( $field, $value = null ) {
73
  $attributes = parent::get_attributes( $field, $value );
74
- $attributes = wp_parse_args(
75
- $attributes,
76
- array(
77
- 'multiple' => $field['multiple'],
78
- )
79
- );
80
 
81
  return $attributes;
82
  }
1
  <?php
2
  /**
3
  * The select field.
 
 
 
 
 
 
4
  */
5
  class RWMB_Select_Field extends RWMB_Choice_Field {
 
 
 
6
  public static function admin_enqueue_scripts() {
7
+ wp_enqueue_style( 'rwmb-select', RWMB_CSS_URL . 'select.css', [], RWMB_VER );
8
+ wp_enqueue_script( 'rwmb-select', RWMB_JS_URL . 'select.js', [ 'jquery' ], RWMB_VER, true );
9
  }
10
 
11
  /**
42
  public static function normalize( $field ) {
43
  $field = parent::normalize( $field );
44
  $field = $field['multiple'] ? RWMB_Multiple_Values_Field::normalize( $field ) : $field;
45
+ $field = wp_parse_args( $field, [
46
+ 'select_all_none' => false,
47
+ ] );
 
 
 
48
 
49
  return $field;
50
  }
59
  */
60
  public static function get_attributes( $field, $value = null ) {
61
  $attributes = parent::get_attributes( $field, $value );
62
+ $attributes = wp_parse_args( $attributes, [
63
+ 'multiple' => $field['multiple'],
64
+ ] );
 
 
 
65
 
66
  return $attributes;
67
  }
inc/fields/sidebar.php CHANGED
@@ -1,48 +1,26 @@
1
  <?php
2
  /**
3
  * The sidebar select field.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Sidebar field class.
10
  */
11
  class RWMB_Sidebar_Field extends RWMB_Object_Choice_Field {
12
- /**
13
- * Normalize parameters for field.
14
- *
15
- * @param array $field Field parameters.
16
- *
17
- * @return array
18
- */
19
  public static function normalize( $field ) {
20
- $field = wp_parse_args(
21
- $field,
22
- array(
23
- 'placeholder' => __( 'Select a sidebar', 'meta-box' ),
24
- )
25
- );
26
 
27
  $field = parent::normalize( $field );
28
 
29
  return $field;
30
  }
31
 
32
- /**
33
- * Get sidebars for field options.
34
- *
35
- * @param array $field Field settings.
36
- * @return array Field options array.
37
- */
38
- public static function query( $field ) {
39
  global $wp_registered_sidebars;
40
- $options = array();
41
  foreach ( $wp_registered_sidebars as $sidebar ) {
42
- $options[ $sidebar['id'] ] = array(
43
  'value' => $sidebar['id'],
44
  'label' => $sidebar['name'],
45
- );
46
  }
47
  return $options;
48
  }
1
  <?php
2
  /**
3
  * The sidebar select field.
 
 
 
 
 
 
4
  */
5
  class RWMB_Sidebar_Field extends RWMB_Object_Choice_Field {
 
 
 
 
 
 
 
6
  public static function normalize( $field ) {
7
+ $field = wp_parse_args( $field, [
8
+ 'placeholder' => __( 'Select a sidebar', 'meta-box' ),
9
+ ] );
 
 
 
10
 
11
  $field = parent::normalize( $field );
12
 
13
  return $field;
14
  }
15
 
16
+ protected static function query( $meta, array $field ) : array {
 
 
 
 
 
 
17
  global $wp_registered_sidebars;
18
+ $options = [];
19
  foreach ( $wp_registered_sidebars as $sidebar ) {
20
+ $options[ $sidebar['id'] ] = [
21
  'value' => $sidebar['id'],
22
  'label' => $sidebar['name'],
23
+ ];
24
  }
25
  return $options;
26
  }
inc/fields/single-image.php CHANGED
@@ -1,12 +1,6 @@
1
  <?php
2
  /**
3
  * The advanced image upload field which uses WordPress media popup to upload and select images.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Image advanced field class.
10
  */
11
  class RWMB_Single_Image_Field extends RWMB_Image_Advanced_Field {
12
  /**
@@ -22,13 +16,10 @@ class RWMB_Single_Image_Field extends RWMB_Image_Advanced_Field {
22
 
23
  $field = parent::normalize( $field );
24
 
25
- $field['attributes'] = wp_parse_args(
26
- $field['attributes'],
27
- array(
28
- 'class' => '',
29
- 'data-single-image' => 1,
30
- )
31
- );
32
 
33
  $field['attributes']['class'] .= ' rwmb-image_advanced';
34
  $field['multiple'] = false;
@@ -59,14 +50,14 @@ class RWMB_Single_Image_Field extends RWMB_Image_Advanced_Field {
59
  *
60
  * @return mixed Full info of uploaded files
61
  */
62
- public static function get_value( $field, $args = array(), $post_id = null ) {
63
  $value = RWMB_Field::get_value( $field, $args, $post_id );
64
 
65
  if ( ! is_array( $value ) ) {
66
  return RWMB_Image_Field::file_info( $value, $args, $field );
67
  }
68
 
69
- $return = array();
70
  foreach ( $value as $image_id ) {
71
  $return[] = RWMB_Image_Field::file_info( $image_id, $args, $field );
72
  }
1
  <?php
2
  /**
3
  * The advanced image upload field which uses WordPress media popup to upload and select images.
 
 
 
 
 
 
4
  */
5
  class RWMB_Single_Image_Field extends RWMB_Image_Advanced_Field {
6
  /**
16
 
17
  $field = parent::normalize( $field );
18
 
19
+ $field['attributes'] = wp_parse_args( $field['attributes'], [
20
+ 'class' => '',
21
+ 'data-single-image' => 1,
22
+ ] );
 
 
 
23
 
24
  $field['attributes']['class'] .= ' rwmb-image_advanced';
25
  $field['multiple'] = false;
50
  *
51
  * @return mixed Full info of uploaded files
52
  */
53
+ public static function get_value( $field, $args = [], $post_id = null ) {
54
  $value = RWMB_Field::get_value( $field, $args, $post_id );
55
 
56
  if ( ! is_array( $value ) ) {
57
  return RWMB_Image_Field::file_info( $value, $args, $field );
58
  }
59
 
60
+ $return = [];
61
  foreach ( $value as $image_id ) {
62
  $return[] = RWMB_Image_Field::file_info( $image_id, $args, $field );
63
  }
inc/fields/slider.php CHANGED
@@ -1,25 +1,16 @@
1
  <?php
2
  /**
3
  * The slider field which users jQueryUI slider widget.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Slider field class.
10
  */
11
  class RWMB_Slider_Field extends RWMB_Field {
12
- /**
13
- * Enqueue scripts and styles.
14
- */
15
  public static function admin_enqueue_scripts() {
16
  $url = RWMB_CSS_URL . 'jqueryui';
17
  wp_register_style( 'jquery-ui-core', "$url/core.css", [], '1.12.1' );
18
  wp_register_style( 'jquery-ui-theme', "$url/theme.css", [], '1.12.1' );
19
- wp_register_style( 'jquery-ui-slider', "$url/slider.css", ['jquery-ui-core', 'jquery-ui-theme'], '1.12.1' );
20
 
21
- wp_enqueue_style( 'rwmb-slider', RWMB_CSS_URL . 'slider.css', ['jquery-ui-slider'], RWMB_VER );
22
- wp_enqueue_script( 'rwmb-slider', RWMB_JS_URL . 'slider.js', ['jquery-ui-slider', 'jquery-ui-widget', 'jquery-ui-mouse', 'jquery-ui-core'], RWMB_VER, true );
23
  }
24
 
25
  /**
@@ -57,22 +48,16 @@ class RWMB_Slider_Field extends RWMB_Field {
57
  */
58
  public static function normalize( $field ) {
59
  $field = parent::normalize( $field );
60
- $field = wp_parse_args(
61
- $field,
62
- array(
63
- 'prefix' => '',
64
- 'suffix' => '',
65
- 'std' => '',
66
- 'js_options' => array(),
67
- )
68
- );
69
- $field['js_options'] = wp_parse_args(
70
- $field['js_options'],
71
- array(
72
- 'range' => 'min', // range = 'min' will add a dark background to sliding part, better UI.
73
- 'value' => $field['std'],
74
- )
75
- );
76
 
77
  return $field;
78
  }
1
  <?php
2
  /**
3
  * The slider field which users jQueryUI slider widget.
 
 
 
 
 
 
4
  */
5
  class RWMB_Slider_Field extends RWMB_Field {
 
 
 
6
  public static function admin_enqueue_scripts() {
7
  $url = RWMB_CSS_URL . 'jqueryui';
8
  wp_register_style( 'jquery-ui-core', "$url/core.css", [], '1.12.1' );
9
  wp_register_style( 'jquery-ui-theme', "$url/theme.css", [], '1.12.1' );
10
+ wp_register_style( 'jquery-ui-slider', "$url/slider.css", [ 'jquery-ui-core', 'jquery-ui-theme' ], '1.12.1' );
11
 
12
+ wp_enqueue_style( 'rwmb-slider', RWMB_CSS_URL . 'slider.css', [ 'jquery-ui-slider' ], RWMB_VER );
13
+ wp_enqueue_script( 'rwmb-slider', RWMB_JS_URL . 'slider.js', [ 'jquery-ui-slider', 'jquery-ui-widget', 'jquery-ui-mouse', 'jquery-ui-core' ], RWMB_VER, true );
14
  }
15
 
16
  /**
48
  */
49
  public static function normalize( $field ) {
50
  $field = parent::normalize( $field );
51
+ $field = wp_parse_args( $field, [
52
+ 'prefix' => '',
53
+ 'suffix' => '',
54
+ 'std' => '',
55
+ 'js_options' => [],
56
+ ] );
57
+ $field['js_options'] = wp_parse_args( $field['js_options'], [
58
+ 'range' => 'min', // range = 'min' will add a dark background to sliding part, better UI.
59
+ 'value' => $field['std'],
60
+ ] );
 
 
 
 
 
 
61
 
62
  return $field;
63
  }
inc/fields/switch.php CHANGED
@@ -1,19 +1,10 @@
1
  <?php
2
  /**
3
  * The Switch field.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Switch field class.
10
  */
11
  class RWMB_Switch_Field extends RWMB_Input_Field {
12
- /**
13
- * Enqueue scripts and styles.
14
- */
15
  public static function admin_enqueue_scripts() {
16
- wp_enqueue_style( 'rwmb-switch', RWMB_CSS_URL . 'switch.css', '', RWMB_VER );
17
  }
18
 
19
  /**
@@ -52,14 +43,11 @@ class RWMB_Switch_Field extends RWMB_Input_Field {
52
  */
53
  public static function normalize( $field ) {
54
  $field = parent::normalize( $field );
55
- $field = wp_parse_args(
56
- $field,
57
- array(
58
- 'style' => 'rounded',
59
- 'on_label' => '',
60
- 'off_label' => '',
61
- )
62
- );
63
 
64
  return $field;
65
  }
1
  <?php
2
  /**
3
  * The Switch field.
 
 
 
 
 
 
4
  */
5
  class RWMB_Switch_Field extends RWMB_Input_Field {
 
 
 
6
  public static function admin_enqueue_scripts() {
7
+ wp_enqueue_style( 'rwmb-switch', RWMB_CSS_URL . 'switch.css', [], RWMB_VER );
8
  }
9
 
10
  /**
43
  */
44
  public static function normalize( $field ) {
45
  $field = parent::normalize( $field );
46
+ $field = wp_parse_args( $field, [
47
+ 'style' => 'rounded',
48
+ 'on_label' => '',
49
+ 'off_label' => '',
50
+ ] );
 
 
 
51
 
52
  return $field;
53
  }
inc/fields/taxonomy.php CHANGED
@@ -1,25 +1,13 @@
1
  <?php
2
  /**
3
  * The taxonomy field which aims to replace the built-in WordPress taxonomy UI with more options.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Taxonomy field class which set post terms when saving.
10
  */
11
  class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
12
- /**
13
- * Add ajax actions callback.
14
- */
15
  public static function add_actions() {
16
- add_action( 'wp_ajax_rwmb_get_terms', array( __CLASS__, 'ajax_get_terms' ) );
17
- add_action( 'wp_ajax_nopriv_rwmb_get_terms', array( __CLASS__, 'ajax_get_terms' ) );
18
  }
19
 
20
- /**
21
- * Query terms via ajax.
22
- */
23
  public static function ajax_get_terms() {
24
  check_ajax_referer( 'query' );
25
 
@@ -35,7 +23,8 @@ class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
35
  $field['query_args']['name__like'] = $request->filter_post( 'term' );
36
 
37
  // Pagination.
38
- $limit = isset( $field['query_args']['number'] ) ? (int) $field['query_args']['number'] : 0;
 
39
  if ( 'query:append' === $request->filter_post( '_type' ) ) {
40
  $page = $request->filter_post( 'page', FILTER_SANITIZE_NUMBER_INT );
41
  $field['query_args']['offset'] = $limit * ( $page - 1 );
@@ -45,7 +34,7 @@ class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
45
  $items = self::query( null, $field );
46
  $items = array_values( $items );
47
 
48
- $data = array( 'items' => $items );
49
 
50
  // More items for pagination.
51
  if ( $limit && count( $items ) === $limit ) {
@@ -74,14 +63,11 @@ class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
74
  }
75
 
76
  // Set default field args.
77
- $field = wp_parse_args(
78
- $field,
79
- array(
80
- 'taxonomy' => 'category',
81
- 'query_args' => array(),
82
- 'remove_default' => false,
83
- )
84
- );
85
 
86
  // Force taxonomy to be an array.
87
  $field['taxonomy'] = (array) $field['taxonomy'];
@@ -97,24 +83,18 @@ class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
97
  // Translators: %s is the taxonomy singular label.
98
  $placeholder = sprintf( __( 'Select a %s', 'meta-box' ), strtolower( $taxonomy_name ) );
99
  }
100
- $field = wp_parse_args(
101
- $field,
102
- array(
103
- 'placeholder' => $placeholder,
104
- )
105
- );
106
 
107
  $field = parent::normalize( $field );
108
 
109
  // Set default query args.
110
  $limit = $field['ajax'] ? 10 : 0;
111
- $field['query_args'] = wp_parse_args(
112
- $field['query_args'],
113
- array(
114
- 'taxonomy' => $field['taxonomy'],
115
- 'number' => $limit,
116
- )
117
- );
118
 
119
  parent::set_ajax_params( $field );
120
 
@@ -126,22 +106,12 @@ class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
126
  return $field;
127
  }
128
 
129
- /**
130
- * Query terms for field options.
131
- *
132
- * @param array $meta Saved meta value.
133
- * @param array $field Field settings.
134
- * @return array Field options array.
135
- */
136
- public static function query( $meta, $field ) {
137
- $args = wp_parse_args(
138
- $field['query_args'],
139
- array(
140
- 'hide_empty' => false,
141
- 'count' => false,
142
- 'update_term_meta_cache' => false,
143
- )
144
- );
145
 
146
  // Query only selected items.
147
  if ( ! empty( $field['ajax'] ) && ! empty( $meta ) ) {
@@ -150,17 +120,18 @@ class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
150
 
151
  $terms = get_terms( $args );
152
  if ( ! is_array( $terms ) ) {
153
- return array();
154
  }
155
- $options = array();
156
  foreach ( $terms as $term ) {
157
  $label = $term->name ? $term->name : __( '(No title)', 'meta-box' );
158
  $label = self::filter( 'choice_label', $label, $field, $term );
159
- $options[ $term->term_id ] = array(
 
160
  'value' => $term->term_id,
161
  'label' => $label,
162
  'parent' => $term->parent,
163
- );
164
  }
165
  return $options;
166
  }
@@ -218,7 +189,7 @@ class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
218
  if ( is_wp_error( $term ) ) {
219
  return null;
220
  }
221
- return isset( $term['term_id'] ) ? $term['term_id'] : null;
222
  }
223
 
224
  /**
@@ -230,21 +201,14 @@ class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
230
  *
231
  * @return mixed
232
  */
233
- public static function raw_meta( $object_id, $field, $args = array() ) {
234
  if ( empty( $field['id'] ) ) {
235
  return '';
236
  }
237
 
238
- $meta = wp_get_object_terms(
239
- $object_id,
240
- $field['taxonomy'],
241
- array(
242
- 'orderby' => 'term_order',
243
- )
244
- );
245
- if ( is_wp_error( $meta ) ) {
246
- return '';
247
- }
248
  $meta = wp_list_pluck( $meta, 'term_id' );
249
 
250
  return $field['multiple'] ? $meta : reset( $meta );
@@ -254,38 +218,34 @@ class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
254
  * Get the field value.
255
  * Return list of post term objects.
256
  *
257
- * @param array $field Field parameters.
258
- * @param array $args Additional arguments.
259
- * @param int|null $post_id Post ID. null for current post. Optional.
260
  *
261
  * @return array List of post term objects.
262
  */
263
- public static function get_value( $field, $args = array(), $post_id = null ) {
264
  if ( ! $post_id ) {
265
  $post_id = get_the_ID();
266
  }
267
- $value = wp_get_object_terms(
268
- $post_id,
269
- $field['taxonomy'],
270
- array(
271
- 'orderby' => 'term_order',
272
- )
273
- );
274
 
275
  // Get single value if necessary.
276
- if ( ! $field['clone'] && ! $field['multiple'] && is_array( $value ) ) {
277
  $value = reset( $value );
278
  }
279
  return $value;
280
  }
281
 
282
  /**
283
- * Format a single value for the helper functions. Sub-fields should overwrite this method if necessary.
284
  *
285
- * @param array $field Field parameters.
286
- * @param object|array $value The value.
287
- * @param array $args Additional arguments. Rarely used. See specific fields for details.
288
- * @param ?int $post_id Post ID. null for current post. Optional.
289
  *
290
  * @return string
291
  */
@@ -294,15 +254,13 @@ class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
294
  return '';
295
  }
296
 
297
- $link = isset( $args['link'] ) ? $args['link'] : 'view';
298
  $text = $value->name;
299
 
300
  if ( false === $link ) {
301
  return $text;
302
  }
303
- if ( 'view' === $link ) {
304
- $url = get_term_link( $value );
305
- }
306
  if ( 'edit' === $link ) {
307
  $url = get_edit_term_link( $value );
308
  }
@@ -346,13 +304,10 @@ class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
346
  return $html;
347
  }
348
 
349
- /**
350
- * Enqueue scripts and styles.
351
- */
352
  public static function admin_enqueue_scripts() {
353
  parent::admin_enqueue_scripts();
354
- wp_enqueue_style( 'rwmb-taxonomy', RWMB_CSS_URL . 'taxonomy.css', array(), RWMB_VER );
355
- wp_enqueue_script( 'rwmb-taxonomy', RWMB_JS_URL . 'taxonomy.js', array( 'jquery' ), RWMB_VER, true );
356
 
357
  // Field is the 1st param.
358
  $args = func_get_args();
@@ -375,13 +330,7 @@ class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
375
  }
376
  }
377
 
378
- /**
379
- * Get taxonomy singular name.
380
- *
381
- * @param array $field Field settings.
382
- * @return string
383
- */
384
- protected static function get_taxonomy_singular_name( $field ) {
385
  if ( 1 !== count( $field['taxonomy'] ) ) {
386
  return '';
387
  }
1
  <?php
2
  /**
3
  * The taxonomy field which aims to replace the built-in WordPress taxonomy UI with more options.
 
 
 
 
 
 
4
  */
5
  class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
 
 
 
6
  public static function add_actions() {
7
+ add_action( 'wp_ajax_rwmb_get_terms', [ __CLASS__, 'ajax_get_terms' ] );
8
+ add_action( 'wp_ajax_nopriv_rwmb_get_terms', [ __CLASS__, 'ajax_get_terms' ] );
9
  }
10
 
 
 
 
11
  public static function ajax_get_terms() {
12
  check_ajax_referer( 'query' );
13
 
23
  $field['query_args']['name__like'] = $request->filter_post( 'term' );
24
 
25
  // Pagination.
26
+ $limit = $field['query_args']['number'] ?? 0;
27
+ $limit = (int) $limit;
28
  if ( 'query:append' === $request->filter_post( '_type' ) ) {
29
  $page = $request->filter_post( 'page', FILTER_SANITIZE_NUMBER_INT );
30
  $field['query_args']['offset'] = $limit * ( $page - 1 );
34
  $items = self::query( null, $field );
35
  $items = array_values( $items );
36
 
37
+ $data = [ 'items' => $items ];
38
 
39
  // More items for pagination.
40
  if ( $limit && count( $items ) === $limit ) {
63
  }
64
 
65
  // Set default field args.
66
+ $field = wp_parse_args( $field, [
67
+ 'taxonomy' => 'category',
68
+ 'query_args' => [],
69
+ 'remove_default' => false,
70
+ ] );
 
 
 
71
 
72
  // Force taxonomy to be an array.
73
  $field['taxonomy'] = (array) $field['taxonomy'];
83
  // Translators: %s is the taxonomy singular label.
84
  $placeholder = sprintf( __( 'Select a %s', 'meta-box' ), strtolower( $taxonomy_name ) );
85
  }
86
+ $field = wp_parse_args( $field, [
87
+ 'placeholder' => $placeholder,
88
+ ] );
 
 
 
89
 
90
  $field = parent::normalize( $field );
91
 
92
  // Set default query args.
93
  $limit = $field['ajax'] ? 10 : 0;
94
+ $field['query_args'] = wp_parse_args( $field['query_args'], [
95
+ 'taxonomy' => $field['taxonomy'],
96
+ 'number' => $limit,
97
+ ] );
 
 
 
98
 
99
  parent::set_ajax_params( $field );
100
 
106
  return $field;
107
  }
108
 
109
+ protected static function query( $meta, array $field ) : array {
110
+ $args = wp_parse_args( $field['query_args'], [
111
+ 'hide_empty' => false,
112
+ 'count' => false,
113
+ 'update_term_meta_cache' => false,
114
+ ] );
 
 
 
 
 
 
 
 
 
 
115
 
116
  // Query only selected items.
117
  if ( ! empty( $field['ajax'] ) && ! empty( $meta ) ) {
120
 
121
  $terms = get_terms( $args );
122
  if ( ! is_array( $terms ) ) {
123
+ return [];
124
  }
125
+ $options = [];
126
  foreach ( $terms as $term ) {
127
  $label = $term->name ? $term->name : __( '(No title)', 'meta-box' );
128
  $label = self::filter( 'choice_label', $label, $field, $term );
129
+
130
+ $options[ $term->term_id ] = [
131
  'value' => $term->term_id,
132
  'label' => $label,
133
  'parent' => $term->parent,
134
+ ];
135
  }
136
  return $options;
137
  }
189
  if ( is_wp_error( $term ) ) {
190
  return null;
191
  }
192
+ return $term['term_id'] ?? null;
193
  }
194
 
195
  /**
201
  *
202
  * @return mixed
203
  */
204
+ public static function raw_meta( $object_id, $field, $args = [] ) {
205
  if ( empty( $field['id'] ) ) {
206
  return '';
207
  }
208
 
209
+ $meta = wp_get_object_terms( $object_id, $field['taxonomy'], [
210
+ 'orderby' => 'term_order',
211
+ ] );
 
 
 
 
 
 
 
212
  $meta = wp_list_pluck( $meta, 'term_id' );
213
 
214
  return $field['multiple'] ? $meta : reset( $meta );
218
  * Get the field value.
219
  * Return list of post term objects.
220
  *
221
+ * @param array $field Field parameters.
222
+ * @param array $args Additional arguments.
223
+ * @param ?int $post_id Post ID.
224
  *
225
  * @return array List of post term objects.
226
  */
227
+ public static function get_value( $field, $args = [], $post_id = null ) {
228
  if ( ! $post_id ) {
229
  $post_id = get_the_ID();
230
  }
231
+ $value = wp_get_object_terms( $post_id, $field['taxonomy'], [
232
+ 'orderby' => 'term_order',
233
+ ] );
 
 
 
 
234
 
235
  // Get single value if necessary.
236
+ if ( ! $field['clone'] && ! $field['multiple'] ) {
237
  $value = reset( $value );
238
  }
239
  return $value;
240
  }
241
 
242
  /**
243
+ * Format a single value for the helper functions.
244
  *
245
+ * @param array $field Field parameters.
246
+ * @param WP_Term $value The term object.
247
+ * @param array $args Additional arguments. Rarely used. See specific fields for details.
248
+ * @param ?int $post_id Post ID. null for current post. Optional.
249
  *
250
  * @return string
251
  */
254
  return '';
255
  }
256
 
257
+ $link = $args['link'] ?? 'view';
258
  $text = $value->name;
259
 
260
  if ( false === $link ) {
261
  return $text;
262
  }
263
+ $url = get_term_link( $value );
 
 
264
  if ( 'edit' === $link ) {
265
  $url = get_edit_term_link( $value );
266
  }
304
  return $html;
305
  }
306
 
 
 
 
307
  public static function admin_enqueue_scripts() {
308
  parent::admin_enqueue_scripts();
309
+ wp_enqueue_style( 'rwmb-taxonomy', RWMB_CSS_URL . 'taxonomy.css', [], RWMB_VER );
310
+ wp_enqueue_script( 'rwmb-taxonomy', RWMB_JS_URL . 'taxonomy.js', [ 'jquery' ], RWMB_VER, true );
311
 
312
  // Field is the 1st param.
313
  $args = func_get_args();
330
  }
331
  }
332
 
333
+ protected static function get_taxonomy_singular_name( array $field ) : string {
 
 
 
 
 
 
334
  if ( 1 !== count( $field['taxonomy'] ) ) {
335
  return '';
336
  }
inc/fields/text-list.php CHANGED
@@ -1,19 +1,10 @@
1
  <?php
2
  /**
3
  * The text list field which allows users to enter multiple texts.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Text list field class.
10
  */
11
  class RWMB_Text_List_Field extends RWMB_Multiple_Values_Field {
12
- /**
13
- * Enqueue scripts and styles.
14
- */
15
  public static function admin_enqueue_scripts() {
16
- wp_enqueue_style( 'rwmb-text-list', RWMB_CSS_URL . 'text-list.css', '', RWMB_VER );
17
  }
18
 
19
  /**
@@ -28,15 +19,15 @@ class RWMB_Text_List_Field extends RWMB_Multiple_Values_Field {
28
  if ( empty( $field['options'] ) ) {
29
  return '';
30
  }
31
- $html = array();
32
  $input = '<label><span class="rwmb-text-list-label">%s</span> <input %s></label>';
33
 
34
- $attributes = self::get_attributes( $field, $meta );
35
  $attributes['type'] = 'text';
36
 
37
  $count = 0;
38
  foreach ( $field['options'] as $placeholder => $label ) {
39
- $attributes['value'] = isset( $meta[ $count ] ) ? esc_attr( $meta[ $count ] ) : '';
40
  $attributes['placeholder'] = $placeholder;
41
 
42
  $html[] = sprintf(
@@ -78,7 +69,7 @@ class RWMB_Text_List_Field extends RWMB_Multiple_Values_Field {
78
  */
79
  public static function value( $new, $old, $post_id, $field ) {
80
  $filtered = array_filter( $new );
81
- return count( $filtered ) ? $new : array();
82
  }
83
 
84
  /**
1
  <?php
2
  /**
3
  * The text list field which allows users to enter multiple texts.
 
 
 
 
 
 
4
  */
5
  class RWMB_Text_List_Field extends RWMB_Multiple_Values_Field {
 
 
 
6
  public static function admin_enqueue_scripts() {
7
+ wp_enqueue_style( 'rwmb-text-list', RWMB_CSS_URL . 'text-list.css', [], RWMB_VER );
8
  }
9
 
10
  /**
19
  if ( empty( $field['options'] ) ) {
20
  return '';
21
  }
22
+ $html = [];
23
  $input = '<label><span class="rwmb-text-list-label">%s</span> <input %s></label>';
24
 
25
+ $attributes = self::get_attributes( $field, $meta );
26
  $attributes['type'] = 'text';
27
 
28
  $count = 0;
29
  foreach ( $field['options'] as $placeholder => $label ) {
30
+ $attributes['value'] = $meta[ $count ] ?? '';
31
  $attributes['placeholder'] = $placeholder;
32
 
33
  $html[] = sprintf(
69
  */
70
  public static function value( $new, $old, $post_id, $field ) {
71
  $filtered = array_filter( $new );
72
+ return count( $filtered ) ? $new : [];
73
  }
74
 
75
  /**
inc/fields/textarea.php CHANGED
@@ -1,12 +1,6 @@
1
  <?php
2
  /**
3
  * The textarea field.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Textarea field class.
10
  */
11
  class RWMB_Textarea_Field extends RWMB_Field {
12
  /**
@@ -34,18 +28,15 @@ class RWMB_Textarea_Field extends RWMB_Field {
34
  */
35
  public static function normalize( $field ) {
36
  $field = parent::normalize( $field );
37
- $field = wp_parse_args(
38
- $field,
39
- array(
40
- 'autocomplete' => false,
41
- 'cols' => false,
42
- 'rows' => 3,
43
- 'maxlength' => false,
44
- 'minlength' => false,
45
- 'wrap' => false,
46
- 'readonly' => false,
47
- )
48
- );
49
 
50
  return $field;
51
  }
@@ -59,20 +50,17 @@ class RWMB_Textarea_Field extends RWMB_Field {
59
  * @return array
60
  */
61
  public static function get_attributes( $field, $value = null ) {
62
- $attributes = parent::get_attributes( $field, $value );
63
- $attributes = wp_parse_args(
64
- $attributes,
65
- array(
66
- 'autocomplete' => $field['autocomplete'],
67
- 'cols' => $field['cols'],
68
- 'rows' => $field['rows'],
69
- 'maxlength' => $field['maxlength'],
70
- 'minlength' => $field['minlength'],
71
- 'wrap' => $field['wrap'],
72
- 'readonly' => $field['readonly'],
73
- 'placeholder' => $field['placeholder'],
74
- )
75
- );
76
 
77
  return $attributes;
78
  }
1
  <?php
2
  /**
3
  * The textarea field.
 
 
 
 
 
 
4
  */
5
  class RWMB_Textarea_Field extends RWMB_Field {
6
  /**
28
  */
29
  public static function normalize( $field ) {
30
  $field = parent::normalize( $field );
31
+ $field = wp_parse_args( $field, [
32
+ 'autocomplete' => false,
33
+ 'cols' => false,
34
+ 'rows' => 3,
35
+ 'maxlength' => false,
36
+ 'minlength' => false,
37
+ 'wrap' => false,
38
+ 'readonly' => false,
39
+ ] );
 
 
 
40
 
41
  return $field;
42
  }
50
  * @return array
51
  */
52
  public static function get_attributes( $field, $value = null ) {
53
+ $attributes = parent::get_attributes( $field, $value );
54
+ $attributes = wp_parse_args( $attributes, [
55
+ 'autocomplete' => $field['autocomplete'],
56
+ 'cols' => $field['cols'],
57
+ 'rows' => $field['rows'],
58
+ 'maxlength' => $field['maxlength'],
59
+ 'minlength' => $field['minlength'],
60
+ 'wrap' => $field['wrap'],
61
+ 'readonly' => $field['readonly'],
62
+ 'placeholder' => $field['placeholder'],
63
+ ] );
 
 
 
64
 
65
  return $attributes;
66
  }
inc/fields/time.php CHANGED
@@ -1,17 +1,8 @@
1
  <?php
2
  /**
3
  * The time picker field.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Time field class.
10
  */
11
  class RWMB_Time_Field extends RWMB_Datetime_Field {
12
- /**
13
- * Enqueue scripts and styles.
14
- */
15
  public static function admin_enqueue_scripts() {
16
  parent::register_assets();
17
  wp_enqueue_style( 'jquery-ui-timepicker' );
1
  <?php
2
  /**
3
  * The time picker field.
 
 
 
 
 
 
4
  */
5
  class RWMB_Time_Field extends RWMB_Datetime_Field {
 
 
 
6
  public static function admin_enqueue_scripts() {
7
  parent::register_assets();
8
  wp_enqueue_style( 'jquery-ui-timepicker' );
inc/fields/user.php CHANGED
@@ -1,26 +1,14 @@
1
  <?php
2
  /**
3
  * The user select field.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * User field class.
10
  */
11
  class RWMB_User_Field extends RWMB_Object_Choice_Field {
12
- /**
13
- * Add actions.
14
- */
15
  public static function add_actions() {
16
- add_action( 'wp_ajax_rwmb_get_users', array( __CLASS__, 'ajax_get_users' ) );
17
- add_action( 'wp_ajax_nopriv_rwmb_get_users', array( __CLASS__, 'ajax_get_users' ) );
18
- add_action( 'clean_user_cache', array( __CLASS__, 'update_cache' ) );
19
  }
20
 
21
- /**
22
- * Query users via ajax.
23
- */
24
  public static function ajax_get_users() {
25
  check_ajax_referer( 'query' );
26
 
@@ -39,7 +27,8 @@ class RWMB_User_Field extends RWMB_Object_Choice_Field {
39
  }
40
 
41
  // Pagination.
42
- $limit = isset( $field['query_args']['number'] ) ? (int) $field['query_args']['number'] : 0;
 
43
  if ( $limit && 'query:append' === $request->filter_post( '_type' ) ) {
44
  $field['query_args']['paged'] = $request->filter_post( 'page', FILTER_SANITIZE_NUMBER_INT );
45
  }
@@ -48,7 +37,7 @@ class RWMB_User_Field extends RWMB_Object_Choice_Field {
48
  $items = self::query( null, $field );
49
  $items = array_values( $items );
50
 
51
- $data = array( 'items' => $items );
52
 
53
  // More items for pagination.
54
  if ( $limit && count( $items ) === $limit ) {
@@ -78,25 +67,19 @@ class RWMB_User_Field extends RWMB_Object_Choice_Field {
78
  */
79
  public static function normalize( $field ) {
80
  // Set default field args.
81
- $field = wp_parse_args(
82
- $field,
83
- array(
84
- 'placeholder' => __( 'Select a user', 'meta-box' ),
85
- 'query_args' => array(),
86
- 'display_field' => 'display_name',
87
- )
88
- );
89
 
90
  $field = parent::normalize( $field );
91
 
92
  // Set default query args.
93
  $limit = $field['ajax'] ? 10 : 0;
94
- $field['query_args'] = wp_parse_args(
95
- $field['query_args'],
96
- array(
97
- 'number' => $limit,
98
- )
99
- );
100
 
101
  parent::set_ajax_params( $field );
102
 
@@ -107,22 +90,12 @@ class RWMB_User_Field extends RWMB_Object_Choice_Field {
107
  return $field;
108
  }
109
 
110
- /**
111
- * Query users for field options.
112
- *
113
- * @param array $meta Saved meta value.
114
- * @param array $field Field settings.
115
- * @return array Field options array.
116
- */
117
- public static function query( $meta, $field ) {
118
  $display_field = $field['display_field'];
119
- $args = wp_parse_args(
120
- $field['query_args'],
121
- array(
122
- 'orderby' => $display_field,
123
- 'order' => 'asc',
124
- )
125
- );
126
 
127
  // Query only selected items.
128
  if ( ! empty( $field['ajax'] ) && ! empty( $meta ) ) {
@@ -139,14 +112,15 @@ class RWMB_User_Field extends RWMB_Object_Choice_Field {
139
  }
140
 
141
  $users = get_users( $args );
142
- $options = array();
143
  foreach ( $users as $user ) {
144
  $label = $user->$display_field ? $user->$display_field : __( '(No title)', 'meta-box' );
145
  $label = self::filter( 'choice_label', $label, $field, $user );
146
- $options[ $user->ID ] = array(
 
147
  'value' => $user->ID,
148
  'label' => $label,
149
- );
150
  }
151
 
152
  // Cache the query.
@@ -159,7 +133,7 @@ class RWMB_User_Field extends RWMB_Object_Choice_Field {
159
  * Format a single value for the helper functions. Sub-fields should overwrite this method if necessary.
160
  *
161
  * @param array $field Field parameters.
162
- * @param string $value The value.
163
  * @param array $args Additional arguments. Rarely used. See specific fields for details.
164
  * @param int|null $post_id Post ID. null for current post. Optional.
165
  *
@@ -170,7 +144,7 @@ class RWMB_User_Field extends RWMB_Object_Choice_Field {
170
  return '';
171
  }
172
 
173
- $link = isset( $args['link'] ) ? $args['link'] : 'view';
174
  $user = get_userdata( $value );
175
  $display_field = $field['display_field'];
176
  $text = $user->$display_field;
@@ -178,9 +152,7 @@ class RWMB_User_Field extends RWMB_Object_Choice_Field {
178
  if ( false === $link ) {
179
  return $text;
180
  }
181
- if ( 'view' === $link ) {
182
- $url = get_author_posts_url( $value );
183
- }
184
  if ( 'edit' === $link ) {
185
  $url = get_edit_user_link( $value );
186
  }
1
  <?php
2
  /**
3
  * The user select field.
 
 
 
 
 
 
4
  */
5
  class RWMB_User_Field extends RWMB_Object_Choice_Field {
 
 
 
6
  public static function add_actions() {
7
+ add_action( 'wp_ajax_rwmb_get_users', [ __CLASS__, 'ajax_get_users' ] );
8
+ add_action( 'wp_ajax_nopriv_rwmb_get_users', [ __CLASS__, 'ajax_get_users' ] );
9
+ add_action( 'clean_user_cache', [ __CLASS__, 'update_cache' ] );
10
  }
11
 
 
 
 
12
  public static function ajax_get_users() {
13
  check_ajax_referer( 'query' );
14
 
27
  }
28
 
29
  // Pagination.
30
+ $limit = $field['query_args']['number'] ?? 0;
31
+ $limit = (int) $limit;
32
  if ( $limit && 'query:append' === $request->filter_post( '_type' ) ) {
33
  $field['query_args']['paged'] = $request->filter_post( 'page', FILTER_SANITIZE_NUMBER_INT );
34
  }
37
  $items = self::query( null, $field );
38
  $items = array_values( $items );
39
 
40
+ $data = [ 'items' => $items ];
41
 
42
  // More items for pagination.
43
  if ( $limit && count( $items ) === $limit ) {
67
  */
68
  public static function normalize( $field ) {
69
  // Set default field args.
70
+ $field = wp_parse_args( $field, [
71
+ 'placeholder' => __( 'Select a user', 'meta-box' ),
72
+ 'query_args' => [],
73
+ 'display_field' => 'display_name',
74
+ ] );
 
 
 
75
 
76
  $field = parent::normalize( $field );
77
 
78
  // Set default query args.
79
  $limit = $field['ajax'] ? 10 : 0;
80
+ $field['query_args'] = wp_parse_args( $field['query_args'], [
81
+ 'number' => $limit,
82
+ ] );
 
 
 
83
 
84
  parent::set_ajax_params( $field );
85
 
90
  return $field;
91
  }
92
 
93
+ protected static function query( $meta, array $field ) : array {
 
 
 
 
 
 
 
94
  $display_field = $field['display_field'];
95
+ $args = wp_parse_args( $field['query_args'], [
96
+ 'orderby' => $display_field,
97
+ 'order' => 'asc',
98
+ ] );
 
 
 
99
 
100
  // Query only selected items.
101
  if ( ! empty( $field['ajax'] ) && ! empty( $meta ) ) {
112
  }
113
 
114
  $users = get_users( $args );
115
+ $options = [];
116
  foreach ( $users as $user ) {
117
  $label = $user->$display_field ? $user->$display_field : __( '(No title)', 'meta-box' );
118
  $label = self::filter( 'choice_label', $label, $field, $user );
119
+
120
+ $options[ $user->ID ] = [
121
  'value' => $user->ID,
122
  'label' => $label,
123
+ ];
124
  }
125
 
126
  // Cache the query.
133
  * Format a single value for the helper functions. Sub-fields should overwrite this method if necessary.
134
  *
135
  * @param array $field Field parameters.
136
+ * @param int $value User ID.
137
  * @param array $args Additional arguments. Rarely used. See specific fields for details.
138
  * @param int|null $post_id Post ID. null for current post. Optional.
139
  *
144
  return '';
145
  }
146
 
147
+ $link = $args['link'] ?? 'view';
148
  $user = get_userdata( $value );
149
  $display_field = $field['display_field'];
150
  $text = $user->$display_field;
152
  if ( false === $link ) {
153
  return $text;
154
  }
155
+ $url = get_author_posts_url( $value );
 
 
156
  if ( 'edit' === $link ) {
157
  $url = get_edit_user_link( $value );
158
  }
inc/fields/video.php CHANGED
@@ -1,29 +1,15 @@
1
  <?php
2
  /**
3
  * Video field which uses WordPress media popup to upload and select video.
4
- *
5
- * @package Meta Box
6
- * @since 4.10
7
- */
8
-
9
- /**
10
- * The video field class.
11
  */
12
  class RWMB_Video_Field extends RWMB_Media_Field {
13
- /**
14
- * Enqueue scripts and styles.
15
- */
16
  public static function admin_enqueue_scripts() {
17
  parent::admin_enqueue_scripts();
18
- wp_enqueue_style( 'rwmb-video', RWMB_CSS_URL . 'video.css', array( 'rwmb-media' ), RWMB_VER );
19
- wp_enqueue_script( 'rwmb-video', RWMB_JS_URL . 'video.js', array( 'rwmb-media' ), RWMB_VER, true );
20
- RWMB_Helpers_Field::localize_script_once(
21
- 'rwmb-video',
22
- 'i18nRwmbVideo',
23
- array(
24
- 'extensions' => wp_get_video_extensions(),
25
- )
26
- );
27
  }
28
 
29
  /**
@@ -49,23 +35,23 @@ class RWMB_Video_Field extends RWMB_Media_Field {
49
  *
50
  * @return array|bool False if file not found. Array of image info on success.
51
  */
52
- public static function file_info( $file_id, $args = array(), $field = array() ) {
53
  if ( ! get_attached_file( $file_id ) ) {
54
  return false;
55
  }
56
  $attachment = get_post( $file_id );
57
  $url = wp_get_attachment_url( $attachment->ID );
58
  $file_type = wp_check_filetype( $url, wp_get_mime_types() );
59
- $data = array(
60
  'ID' => $file_id,
61
  'src' => $url,
62
  'type' => $file_type['type'],
63
  'title' => $attachment->post_title,
64
  'caption' => $attachment->post_excerpt,
65
  'description' => $attachment->post_content,
66
- );
67
 
68
- $data['meta'] = array();
69
  $meta = wp_get_attachment_metadata( $attachment->ID );
70
  if ( ! empty( $meta ) ) {
71
  foreach ( wp_get_attachment_id3_keys( $attachment ) as $key => $label ) {
@@ -75,15 +61,15 @@ class RWMB_Video_Field extends RWMB_Media_Field {
75
  }
76
 
77
  if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) {
78
- $data['dimensions'] = array(
79
  'width' => $meta['width'],
80
  'height' => $meta['height'],
81
- );
82
  } else {
83
- $data['dimensions'] = array(
84
  'width' => 640,
85
  'height' => 360,
86
- );
87
  }
88
  }
89
 
@@ -120,22 +106,18 @@ class RWMB_Video_Field extends RWMB_Media_Field {
120
  // Display single video.
121
  if ( 1 === count( $value ) ) {
122
  $video = reset( $value );
123
- return wp_video_shortcode(
124
- array(
125
- 'src' => $video['src'],
126
- 'width' => $video['dimensions']['width'],
127
- 'height' => $video['dimensions']['height'],
128
- )
129
- );
130
  }
131
 
132
  // Display multiple videos in a playlist.
133
- return wp_playlist_shortcode(
134
- array(
135
- 'ids' => $ids,
136
- 'type' => 'video',
137
- )
138
- );
139
  }
140
 
141
  /**
1
  <?php
2
  /**
3
  * Video field which uses WordPress media popup to upload and select video.
 
 
 
 
 
 
 
4
  */
5
  class RWMB_Video_Field extends RWMB_Media_Field {
 
 
 
6
  public static function admin_enqueue_scripts() {
7
  parent::admin_enqueue_scripts();
8
+ wp_enqueue_style( 'rwmb-video', RWMB_CSS_URL . 'video.css', [ 'rwmb-media' ], RWMB_VER );
9
+ wp_enqueue_script( 'rwmb-video', RWMB_JS_URL . 'video.js', [ 'rwmb-media' ], RWMB_VER, true );
10
+ RWMB_Helpers_Field::localize_script_once( 'rwmb-video', 'i18nRwmbVideo', [
11
+ 'extensions' => wp_get_video_extensions(),
12
+ ] );
 
 
 
 
13
  }
14
 
15
  /**
35
  *
36
  * @return array|bool False if file not found. Array of image info on success.
37
  */
38
+ public static function file_info( $file_id, $args = [], $field = [] ) {
39
  if ( ! get_attached_file( $file_id ) ) {
40
  return false;
41
  }
42
  $attachment = get_post( $file_id );
43
  $url = wp_get_attachment_url( $attachment->ID );
44
  $file_type = wp_check_filetype( $url, wp_get_mime_types() );
45
+ $data = [
46
  'ID' => $file_id,
47
  'src' => $url,
48
  'type' => $file_type['type'],
49
  'title' => $attachment->post_title,
50
  'caption' => $attachment->post_excerpt,
51
  'description' => $attachment->post_content,
52
+ ];
53
 
54
+ $data['meta'] = [];
55
  $meta = wp_get_attachment_metadata( $attachment->ID );
56
  if ( ! empty( $meta ) ) {
57
  foreach ( wp_get_attachment_id3_keys( $attachment ) as $key => $label ) {
61
  }
62
 
63
  if ( ! empty( $meta['width'] ) && ! empty( $meta['height'] ) ) {
64
+ $data['dimensions'] = [
65
  'width' => $meta['width'],
66
  'height' => $meta['height'],
67
+ ];
68
  } else {
69
+ $data['dimensions'] = [
70
  'width' => 640,
71
  'height' => 360,
72
+ ];
73
  }
74
  }
75
 
106
  // Display single video.
107
  if ( 1 === count( $value ) ) {
108
  $video = reset( $value );
109
+ return wp_video_shortcode( [
110
+ 'src' => $video['src'],
111
+ 'width' => $video['dimensions']['width'],
112
+ 'height' => $video['dimensions']['height'],
113
+ ] );
 
 
114
  }
115
 
116
  // Display multiple videos in a playlist.
117
+ return wp_playlist_shortcode( [
118
+ 'ids' => $ids,
119
+ 'type' => 'video',
120
+ ] );
 
 
121
  }
122
 
123
  /**
inc/fields/wysiwyg.php CHANGED
@@ -1,21 +1,12 @@
1
  <?php
2
  /**
3
  * The WYSIWYG (editor) field.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * WYSIWYG (editor) field class.
10
  */
11
  class RWMB_Wysiwyg_Field extends RWMB_Field {
12
- /**
13
- * Enqueue scripts and styles.
14
- */
15
  public static function admin_enqueue_scripts() {
16
  wp_enqueue_editor();
17
- wp_enqueue_style( 'rwmb-wysiwyg', RWMB_CSS_URL . 'wysiwyg.css', array(), RWMB_VER );
18
- wp_enqueue_script( 'rwmb-wysiwyg', RWMB_JS_URL . 'wysiwyg.js', ['jquery', 'rwmb'], RWMB_VER, true );
19
  }
20
 
21
  /**
@@ -44,7 +35,7 @@ class RWMB_Wysiwyg_Field extends RWMB_Field {
44
 
45
  $attributes = self::get_attributes( $field );
46
 
47
- $options = $field['options'];
48
  $options['textarea_name'] = $field['field_name'];
49
  if ( ! empty( $attributes['required'] ) ) {
50
  $options['editor_class'] .= ' rwmb-wysiwyg-required';
@@ -65,21 +56,15 @@ class RWMB_Wysiwyg_Field extends RWMB_Field {
65
  */
66
  public static function normalize( $field ) {
67
  $field = parent::normalize( $field );
68
- $field = wp_parse_args(
69
- $field,
70
- array(
71
- 'raw' => false,
72
- 'options' => array(),
73
- )
74
- );
75
 
76
- $field['options'] = wp_parse_args(
77
- $field['options'],
78
- array(
79
- 'editor_class' => 'rwmb-wysiwyg',
80
- 'dfw' => true, // Use default WordPress full screen UI.
81
- )
82
- );
83
 
84
  // Keep the filter to be compatible with previous versions.
85
  $field['options'] = apply_filters( 'rwmb_wysiwyg_settings', $field['options'] );
1
  <?php
2
  /**
3
  * The WYSIWYG (editor) field.
 
 
 
 
 
 
4
  */
5
  class RWMB_Wysiwyg_Field extends RWMB_Field {
 
 
 
6
  public static function admin_enqueue_scripts() {
7
  wp_enqueue_editor();
8
+ wp_enqueue_style( 'rwmb-wysiwyg', RWMB_CSS_URL . 'wysiwyg.css', [], RWMB_VER );
9
+ wp_enqueue_script( 'rwmb-wysiwyg', RWMB_JS_URL . 'wysiwyg.js', [ 'jquery', 'rwmb' ], RWMB_VER, true );
10
  }
11
 
12
  /**
35
 
36
  $attributes = self::get_attributes( $field );
37
 
38
+ $options = $field['options'];
39
  $options['textarea_name'] = $field['field_name'];
40
  if ( ! empty( $attributes['required'] ) ) {
41
  $options['editor_class'] .= ' rwmb-wysiwyg-required';
56
  */
57
  public static function normalize( $field ) {
58
  $field = parent::normalize( $field );
59
+ $field = wp_parse_args( $field, [
60
+ 'raw' => false,
61
+ 'options' => [],
62
+ ] );
 
 
 
63
 
64
+ $field['options'] = wp_parse_args( $field['options'], [
65
+ 'editor_class' => 'rwmb-wysiwyg',
66
+ 'dfw' => true, // Use default WordPress full screen UI.
67
+ ] );
 
 
 
68
 
69
  // Keep the filter to be compatible with previous versions.
70
  $field['options'] = apply_filters( 'rwmb_wysiwyg_settings', $field['options'] );
inc/functions.php CHANGED
@@ -1,8 +1,6 @@
1
  <?php
2
  /**
3
  * Plugin public functions.
4
- *
5
- * @package Meta Box
6
  */
7
 
8
  if ( ! function_exists( 'rwmb_meta' ) ) {
@@ -15,7 +13,7 @@ if ( ! function_exists( 'rwmb_meta' ) ) {
15
  *
16
  * @return mixed
17
  */
18
- function rwmb_meta( $key, $args = array(), $post_id = null ) {
19
  $args = wp_parse_args( $args );
20
  $field = rwmb_get_field_settings( $key, $args, $post_id );
21
 
@@ -26,7 +24,7 @@ if ( ! function_exists( 'rwmb_meta' ) ) {
26
  if ( false === $field ) {
27
  return apply_filters( 'rwmb_meta', rwmb_meta_legacy( $key, $args, $post_id ) );
28
  }
29
- $meta = in_array( $field['type'], array( 'oembed', 'map', 'osm' ), true ) ?
30
  rwmb_the_value( $key, $args, $post_id, false ) :
31
  rwmb_get_value( $key, $args, $post_id );
32
  return apply_filters( 'rwmb_meta', $meta, $key, $args, $post_id );
@@ -42,8 +40,8 @@ if ( ! function_exists( 'rwmb_set_meta' ) ) {
42
  * @param string $value Meta value. Required.
43
  * @param array $args Array of arguments. Optional.
44
  */
45
- function rwmb_set_meta( $object_id, $key, $value, $args = array() ) {
46
- $args = wp_parse_args( $args );
47
  $field = rwmb_get_field_settings( $key, $args, $object_id );
48
 
49
  if ( false === $field ) {
@@ -66,14 +64,11 @@ if ( ! function_exists( 'rwmb_get_field_settings' ) ) {
66
  *
67
  * @return array
68
  */
69
- function rwmb_get_field_settings( $key, $args = array(), $object_id = null ) {
70
- $args = wp_parse_args(
71
- $args,
72
- array(
73
- 'object_type' => 'post',
74
- 'type' => '',
75
- )
76
- );
77
 
78
  /**
79
  * Filter meta type from object type and object id.
@@ -101,21 +96,18 @@ if ( ! function_exists( 'rwmb_meta_legacy' ) ) {
101
  *
102
  * @return mixed
103
  */
104
- function rwmb_meta_legacy( $key, $args = array(), $post_id = null ) {
105
- $args = wp_parse_args(
106
- $args,
107
- array(
108
- 'type' => 'text',
109
- 'multiple' => false,
110
- 'clone' => false,
111
- )
112
- );
113
- $field = array(
114
  'id' => $key,
115
  'type' => $args['type'],
116
  'clone' => $args['clone'],
117
  'multiple' => $args['multiple'],
118
- );
119
 
120
  $method = 'get_value';
121
  switch ( $args['type'] ) {
@@ -146,7 +138,7 @@ if ( ! function_exists( 'rwmb_get_value' ) ) {
146
  *
147
  * @return mixed false if field doesn't exist. Field value otherwise.
148
  */
149
- function rwmb_get_value( $field_id, $args = array(), $post_id = null ) {
150
  $args = wp_parse_args( $args );
151
  $field = rwmb_get_field_settings( $field_id, $args, $post_id );
152
 
@@ -179,7 +171,7 @@ if ( ! function_exists( 'rwmb_the_value' ) ) {
179
  *
180
  * @return string
181
  */
182
- function rwmb_the_value( $field_id, $args = array(), $post_id = null, $echo = true ) {
183
  $args = wp_parse_args( $args );
184
  $field = rwmb_get_field_settings( $field_id, $args, $post_id );
185
 
@@ -201,7 +193,7 @@ if ( ! function_exists( 'rwmb_the_value' ) ) {
201
  $output = apply_filters( 'rwmb_the_value', $output, $field, $args, $post_id );
202
 
203
  if ( $echo ) {
204
- echo $output; // WPCS: XSS OK.
205
  }
206
 
207
  return $output;
@@ -218,11 +210,11 @@ if ( ! function_exists( 'rwmb_get_object_fields' ) ) {
218
  * @return array
219
  */
220
  function rwmb_get_object_fields( $type_or_id, $object_type = 'post' ) {
221
- $meta_boxes = rwmb_get_registry( 'meta_box' )->get_by( array( 'object_type' => $object_type ) );
222
- array_walk( $meta_boxes, 'rwmb_check_meta_box_supports', array( $object_type, $type_or_id ) );
223
  $meta_boxes = array_filter( $meta_boxes );
224
 
225
- $fields = array();
226
  foreach ( $meta_boxes as $meta_box ) {
227
  foreach ( $meta_box->fields as $field ) {
228
  $fields[ $field['id'] ] = $field;
@@ -255,7 +247,7 @@ if ( ! function_exists( 'rwmb_check_meta_box_supports' ) ) {
255
  $type = $type_or_id;
256
  if ( is_numeric( $type_or_id ) ) {
257
  $term = get_term( $type_or_id );
258
- $type = is_array( $term ) ? $term->taxonomy : null;
259
  }
260
  $prop = 'taxonomies';
261
  break;
@@ -288,7 +280,7 @@ if ( ! function_exists( 'rwmb_get_registry' ) ) {
288
  * @return object
289
  */
290
  function rwmb_get_registry( $type ) {
291
- static $data = array();
292
 
293
  $class = 'RWMB_' . RWMB_Helpers_String::title_case( $type ) . '_Registry';
294
  if ( ! isset( $data[ $type ] ) ) {
1
  <?php
2
  /**
3
  * Plugin public functions.
 
 
4
  */
5
 
6
  if ( ! function_exists( 'rwmb_meta' ) ) {
13
  *
14
  * @return mixed
15
  */
16
+ function rwmb_meta( $key, $args = [], $post_id = null ) {
17
  $args = wp_parse_args( $args );
18
  $field = rwmb_get_field_settings( $key, $args, $post_id );
19
 
24
  if ( false === $field ) {
25
  return apply_filters( 'rwmb_meta', rwmb_meta_legacy( $key, $args, $post_id ) );
26
  }
27
+ $meta = in_array( $field['type'], [ 'oembed', 'map', 'osm' ], true ) ?
28
  rwmb_the_value( $key, $args, $post_id, false ) :
29
  rwmb_get_value( $key, $args, $post_id );
30
  return apply_filters( 'rwmb_meta', $meta, $key, $args, $post_id );
40
  * @param string $value Meta value. Required.
41
  * @param array $args Array of arguments. Optional.
42
  */
43
+ function rwmb_set_meta( $object_id, $key, $value, $args = [] ) {
44
+ $args = wp_parse_args( $args );
45
  $field = rwmb_get_field_settings( $key, $args, $object_id );
46
 
47
  if ( false === $field ) {
64
  *
65
  * @return array
66
  */
67
+ function rwmb_get_field_settings( $key, $args = [], $object_id = null ) {
68
+ $args = wp_parse_args( $args, [
69
+ 'object_type' => 'post',
70
+ 'type' => '',
71
+ ] );
 
 
 
72
 
73
  /**
74
  * Filter meta type from object type and object id.
96
  *
97
  * @return mixed
98
  */
99
+ function rwmb_meta_legacy( $key, $args = [], $post_id = null ) {
100
+ $args = wp_parse_args( $args, [
101
+ 'type' => 'text',
102
+ 'multiple' => false,
103
+ 'clone' => false,
104
+ ] );
105
+ $field = [
 
 
 
106
  'id' => $key,
107
  'type' => $args['type'],
108
  'clone' => $args['clone'],
109
  'multiple' => $args['multiple'],
110
+ ];
111
 
112
  $method = 'get_value';
113
  switch ( $args['type'] ) {
138
  *
139
  * @return mixed false if field doesn't exist. Field value otherwise.
140
  */
141
+ function rwmb_get_value( $field_id, $args = [], $post_id = null ) {
142
  $args = wp_parse_args( $args );
143
  $field = rwmb_get_field_settings( $field_id, $args, $post_id );
144
 
171
  *
172
  * @return string
173
  */
174
+ function rwmb_the_value( $field_id, $args = [], $post_id = null, $echo = true ) {
175
  $args = wp_parse_args( $args );
176
  $field = rwmb_get_field_settings( $field_id, $args, $post_id );
177
 
193
  $output = apply_filters( 'rwmb_the_value', $output, $field, $args, $post_id );
194
 
195
  if ( $echo ) {
196
+ echo $output; // phpcs:ignore WordPress.Security.EscapeOutput
197
  }
198
 
199
  return $output;
210
  * @return array
211
  */
212
  function rwmb_get_object_fields( $type_or_id, $object_type = 'post' ) {
213
+ $meta_boxes = rwmb_get_registry( 'meta_box' )->get_by( [ 'object_type' => $object_type ] );
214
+ array_walk( $meta_boxes, 'rwmb_check_meta_box_supports', [ $object_type, $type_or_id ] );
215
  $meta_boxes = array_filter( $meta_boxes );
216
 
217
+ $fields = [];
218
  foreach ( $meta_boxes as $meta_box ) {
219
  foreach ( $meta_box->fields as $field ) {
220
  $fields[ $field['id'] ] = $field;
247
  $type = $type_or_id;
248
  if ( is_numeric( $type_or_id ) ) {
249
  $term = get_term( $type_or_id );
250
+ $type = is_wp_error( $term ) || ! $term ? null : $term->taxonomy;
251
  }
252
  $prop = 'taxonomies';
253
  break;
280
  * @return object
281
  */
282
  function rwmb_get_registry( $type ) {
283
+ static $data = [];
284
 
285
  $class = 'RWMB_' . RWMB_Helpers_String::title_case( $type ) . '_Registry';
286
  if ( ! isset( $data[ $type ] ) ) {
inc/helpers/array.php CHANGED
@@ -1,23 +1,13 @@
1
  <?php
2
  /**
3
  * Array helper functions.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Array helper class.
10
- *
11
- * @package Meta Box
12
  */
13
  class RWMB_Helpers_Array {
14
  /**
15
  * New array map function that accepts more params than just values.
16
  * Params: array|item, callback, other params.
17
- *
18
- * @return array
19
  */
20
- public static function map() {
21
  $args = func_get_args();
22
  $items = array_shift( $args );
23
  $callback = array_shift( $args );
@@ -39,10 +29,9 @@ class RWMB_Helpers_Array {
39
  /**
40
  * Convert a comma separated string to array.
41
  *
42
- * @param string $csv Comma separated string.
43
- * @return array
44
  */
45
- public static function from_csv( $csv ) {
46
  return is_array( $csv ) ? $csv : array_filter( array_map( 'trim', explode( ',', $csv . ',' ) ) );
47
  }
48
 
@@ -62,14 +51,10 @@ class RWMB_Helpers_Array {
62
 
63
  /**
64
  * Flatten an array.
65
- *
66
  * @link https://stackoverflow.com/a/1320156/371240
67
- *
68
- * @param array $array Input array.
69
- * @return array
70
  */
71
- public static function flatten( $array ) {
72
- $return = array();
73
  array_walk_recursive(
74
  $array,
75
  function( $a ) use ( &$return ) {
@@ -82,9 +67,8 @@ class RWMB_Helpers_Array {
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
  }
1
  <?php
2
  /**
3
  * Array helper functions.
 
 
 
 
 
 
 
 
4
  */
5
  class RWMB_Helpers_Array {
6
  /**
7
  * New array map function that accepts more params than just values.
8
  * Params: array|item, callback, other params.
 
 
9
  */
10
+ public static function map() : array {
11
  $args = func_get_args();
12
  $items = array_shift( $args );
13
  $callback = array_shift( $args );
29
  /**
30
  * Convert a comma separated string to array.
31
  *
32
+ * @param string|array $csv Comma separated string.
 
33
  */
34
+ public static function from_csv( $csv ) : array {
35
  return is_array( $csv ) ? $csv : array_filter( array_map( 'trim', explode( ',', $csv . ',' ) ) );
36
  }
37
 
51
 
52
  /**
53
  * Flatten an array.
 
54
  * @link https://stackoverflow.com/a/1320156/371240
 
 
 
55
  */
56
+ public static function flatten( array $array ) : array {
57
+ $return = [];
58
  array_walk_recursive(
59
  $array,
60
  function( $a ) use ( &$return ) {
67
  /**
68
  * Ensure a variable is an array.
69
  * @param mixed $input Input value.
 
70
  */
71
+ public static function ensure( $input ) : array {
72
  return (array) $input;
73
  }
74
  }
inc/helpers/field.php CHANGED
@@ -1,66 +1,41 @@
1
  <?php
2
  /**
3
  * Field helper functions.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Field helper class.
10
- *
11
- * @package Meta Box
12
  */
13
  class RWMB_Helpers_Field {
14
  /**
15
  * Localize a script only once.
16
- *
17
  * @link https://github.com/rilwis/meta-box/issues/850
18
- *
19
- * @param string $handle Script handle.
20
- * @param string $name Object name.
21
- * @param array $data Localized data.
22
  */
23
- public static function localize_script_once( $handle, $name, $data ) {
24
  if ( ! wp_scripts()->get_data( $handle, 'data' ) ) {
25
  wp_localize_script( $handle, $name, $data );
26
  }
27
  }
28
 
29
- public static function add_inline_script_once( $handle, $text ) {
30
  if ( ! wp_scripts()->get_data( $handle, 'after' ) ) {
31
  wp_add_inline_script( $handle, $text );
32
  }
33
  }
34
 
35
- /**
36
- * Get field class name.
37
- *
38
- * @param array $field Field settings.
39
- * @return string
40
- */
41
- public static function get_class( $field ) {
42
  $type = self::get_type( $field );
43
  $class = 'RWMB_' . RWMB_Helpers_String::title_case( $type ) . '_Field';
44
  return class_exists( $class ) ? $class : 'RWMB_Input_Field';
45
  }
46
 
47
- /**
48
- * Get field type.
49
- *
50
- * @param array $field Field settings.
51
- * @return string
52
- */
53
- private static function get_type( $field ) {
54
- $type = isset( $field['type'] ) ? $field['type'] : 'text';
55
  $map = array_merge(
56
- array(
57
  $type => $type,
58
- ),
59
- array(
60
  'file_advanced' => 'media',
61
  'plupload_image' => 'image_upload',
62
  'url' => 'text',
63
- )
64
  );
65
 
66
  return $map[ $type ];
1
  <?php
2
  /**
3
  * Field helper functions.
 
 
 
 
 
 
 
 
4
  */
5
  class RWMB_Helpers_Field {
6
  /**
7
  * Localize a script only once.
 
8
  * @link https://github.com/rilwis/meta-box/issues/850
 
 
 
 
9
  */
10
+ public static function localize_script_once( string $handle, string $name, array $data ) {
11
  if ( ! wp_scripts()->get_data( $handle, 'data' ) ) {
12
  wp_localize_script( $handle, $name, $data );
13
  }
14
  }
15
 
16
+ public static function add_inline_script_once( string $handle, string $text ) {
17
  if ( ! wp_scripts()->get_data( $handle, 'after' ) ) {
18
  wp_add_inline_script( $handle, $text );
19
  }
20
  }
21
 
22
+ public static function get_class( array $field ) : string {
 
 
 
 
 
 
23
  $type = self::get_type( $field );
24
  $class = 'RWMB_' . RWMB_Helpers_String::title_case( $type ) . '_Field';
25
  return class_exists( $class ) ? $class : 'RWMB_Input_Field';
26
  }
27
 
28
+ private static function get_type( array $field ) : string {
29
+ $type = $field['type'] ?? 'text';
 
 
 
 
 
 
30
  $map = array_merge(
31
+ [
32
  $type => $type,
33
+ ],
34
+ [
35
  'file_advanced' => 'media',
36
  'plupload_image' => 'image_upload',
37
  'url' => 'text',
38
+ ]
39
  );
40
 
41
  return $map[ $type ];
inc/helpers/string.php CHANGED
@@ -1,24 +1,10 @@
1
  <?php
2
  /**
3
  * String helper functions.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * String helper class.
10
- *
11
- * @package Meta Box
12
  */
13
  class RWMB_Helpers_String {
14
- /**
15
- * Convert text to Title_Case.
16
- *
17
- * @param string $text Input text.
18
- * @return string
19
- */
20
- public static function title_case( $text ) {
21
- $text = str_replace( array( '-', '_' ), ' ', $text );
22
  $text = ucwords( $text );
23
  $text = str_replace( ' ', '_', $text );
24
 
1
  <?php
2
  /**
3
  * String helper functions.
 
 
 
 
 
 
 
 
4
  */
5
  class RWMB_Helpers_String {
6
+ public static function title_case( string $text ) : string {
7
+ $text = str_replace( [ '-', '_' ], ' ', $text );
 
 
 
 
 
 
8
  $text = ucwords( $text );
9
  $text = str_replace( ' ', '_', $text );
10
 
inc/helpers/value.php CHANGED
@@ -18,7 +18,7 @@ class RWMB_Helpers_Value {
18
  * @return bool
19
  */
20
  public static function is_valid_for_field( $value ) {
21
- return '' !== $value && array() !== $value;
22
  }
23
 
24
  /**
18
  * @return bool
19
  */
20
  public static function is_valid_for_field( $value ) {
21
+ return '' !== $value && [] !== $value;
22
  }
23
 
24
  /**
inc/interfaces/storage.php CHANGED
@@ -1,15 +1,8 @@
1
  <?php
2
  /**
3
- * Storage interface
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Interface RWMB_Storage_Interface
10
  */
11
  interface RWMB_Storage_Interface {
12
-
13
  /**
14
  * Get value from storage.
15
  *
@@ -18,5 +11,5 @@ interface RWMB_Storage_Interface {
18
  * @param array $args Custom arguments..
19
  * @return mixed
20
  */
21
- public function get( $object_id, $name, $args = array() );
22
  }
1
  <?php
2
  /**
3
+ * Storage interface.
 
 
 
 
 
 
4
  */
5
  interface RWMB_Storage_Interface {
 
6
  /**
7
  * Get value from storage.
8
  *
11
  * @param array $args Custom arguments..
12
  * @return mixed
13
  */
14
+ public function get( $object_id, $name, $args = [] );
15
  }
inc/loader.php CHANGED
@@ -7,7 +7,7 @@
7
  class RWMB_Loader {
8
  protected function constants() {
9
  // Script version, used to add version for scripts and styles.
10
- define( 'RWMB_VER', '5.6.8' );
11
 
12
  list( $path, $url ) = self::get_path( dirname( __DIR__ ) );
13
 
7
  class RWMB_Loader {
8
  protected function constants() {
9
  // Script version, used to add version for scripts and styles.
10
+ define( 'RWMB_VER', '5.6.10' );
11
 
12
  list( $path, $url ) = self::get_path( dirname( __DIR__ ) );
13
 
inc/media-modal.php CHANGED
@@ -1,13 +1,6 @@
1
  <?php
2
  /**
3
  * Add support for editing attachment custom fields in the media modal.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * The media modal class.
10
- * Handling showing and saving custom fields in the media modal.
11
  */
12
  class RWMB_Media_Modal {
13
  /**
@@ -15,35 +8,26 @@ class RWMB_Media_Modal {
15
  *
16
  * @var array
17
  */
18
- protected $fields = array();
19
 
20
- /**
21
- * Initialize.
22
- */
23
  public function init() {
24
  // Meta boxes are registered at priority 20, so we use 30 to capture them all.
25
- add_action( 'init', array( $this, 'get_fields' ), 30 );
26
 
27
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
28
 
29
- add_filter( 'attachment_fields_to_edit', array( $this, 'add_fields' ), 11, 2 );
30
- add_filter( 'attachment_fields_to_save', array( $this, 'save_fields' ), 11, 2 );
31
 
32
- add_filter( 'rwmb_show', array( $this, 'is_in_normal_mode' ), 10, 2 );
33
  }
34
 
35
- /**
36
- * Enqueue common scripts and styles.
37
- */
38
  public function enqueue() {
39
  if ( get_current_screen()->post_type === 'attachment' ) {
40
- wp_enqueue_style( 'rwmb', RWMB_CSS_URL . 'media-modal.css', array(), RWMB_VER );
41
  }
42
  }
43
 
44
- /**
45
- * Get list of custom fields and store in the current object for future use.
46
- */
47
  public function get_fields() {
48
  $meta_boxes = rwmb_get_registry( 'meta_box' )->all();
49
  foreach ( $meta_boxes as $meta_box ) {
@@ -109,15 +93,7 @@ class RWMB_Media_Modal {
109
  return $post;
110
  }
111
 
112
- /**
113
- * Whether or not show the meta box when editing custom fields in the normal mode.
114
- *
115
- * @param bool $show Whether to show the meta box in normal editing mode.
116
- * @param array $meta_box Meta Box parameters.
117
- *
118
- * @return bool
119
- */
120
- public function is_in_normal_mode( $show, $meta_box ) {
121
  if ( ! $show ) {
122
  return $show;
123
  }
@@ -132,14 +108,7 @@ class RWMB_Media_Modal {
132
  return ! $this->is_in_modal( $meta_box );
133
  }
134
 
135
- /**
136
- * Check if the meta box is for editing custom fields in the media modal.
137
- *
138
- * @param array $meta_box Meta Box parameters.
139
- *
140
- * @return bool
141
- */
142
- protected function is_in_modal( $meta_box ) {
143
  return in_array( 'attachment', $meta_box['post_types'], true ) && ! empty( $meta_box['media_modal'] );
144
  }
145
  }
1
  <?php
2
  /**
3
  * Add support for editing attachment custom fields in the media modal.
 
 
 
 
 
 
 
4
  */
5
  class RWMB_Media_Modal {
6
  /**
8
  *
9
  * @var array
10
  */
11
+ protected $fields = [];
12
 
 
 
 
13
  public function init() {
14
  // Meta boxes are registered at priority 20, so we use 30 to capture them all.
15
+ add_action( 'init', [ $this, 'get_fields' ], 30 );
16
 
17
+ add_action( 'admin_enqueue_scripts', [ $this, 'enqueue' ] );
18
 
19
+ add_filter( 'attachment_fields_to_edit', [ $this, 'add_fields' ], 11, 2 );
20
+ add_filter( 'attachment_fields_to_save', [ $this, 'save_fields' ], 11, 2 );
21
 
22
+ add_filter( 'rwmb_show', [ $this, 'is_in_normal_mode' ], 10, 2 );
23
  }
24
 
 
 
 
25
  public function enqueue() {
26
  if ( get_current_screen()->post_type === 'attachment' ) {
27
+ wp_enqueue_style( 'rwmb', RWMB_CSS_URL . 'media-modal.css', [], RWMB_VER );
28
  }
29
  }
30
 
 
 
 
31
  public function get_fields() {
32
  $meta_boxes = rwmb_get_registry( 'meta_box' )->all();
33
  foreach ( $meta_boxes as $meta_box ) {
93
  return $post;
94
  }
95
 
96
+ public function is_in_normal_mode( bool $show, array $meta_box ) : bool {
 
 
 
 
 
 
 
 
97
  if ( ! $show ) {
98
  return $show;
99
  }
108
  return ! $this->is_in_modal( $meta_box );
109
  }
110
 
111
+ private function is_in_modal( array $meta_box ) : bool {
 
 
 
 
 
 
 
112
  return in_array( 'attachment', $meta_box['post_types'], true ) && ! empty( $meta_box['media_modal'] );
113
  }
114
  }
inc/meta-box.php CHANGED
@@ -1,15 +1,6 @@
1
  <?php
2
  /**
3
  * A class to rapid develop meta boxes for custom & built in content types
4
- * Piggybacks on WordPress
5
- *
6
- * @author Tran Ngoc Tuan Anh <rilwis@gmail.com>
7
- * @license GNU GPL2+
8
- * @package Meta Box
9
- */
10
-
11
- /**
12
- * The main meta box class.
13
  *
14
  * @property string $id Meta Box ID.
15
  * @property string $title Meta Box title.
@@ -22,8 +13,6 @@
22
  * @property bool $default_hidden Whether the meta box is hidden by default.
23
  * @property bool $autosave Whether the meta box auto saves.
24
  * @property bool $media_modal Add custom fields to media modal when viewing/editing an attachment.
25
- *
26
- * @package Meta Box
27
  */
28
  class RW_Meta_Box {
29
  /**
@@ -55,12 +44,7 @@ class RW_Meta_Box {
55
  */
56
  protected $object_type = 'post';
57
 
58
- /**
59
- * Create meta box based on given data.
60
- *
61
- * @param array $meta_box Meta box definition.
62
- */
63
- public function __construct( $meta_box ) {
64
  $meta_box = static::normalize( $meta_box );
65
  $this->meta_box = $meta_box;
66
 
@@ -74,9 +58,6 @@ class RW_Meta_Box {
74
  }
75
  }
76
 
77
- /**
78
- * Add fields to field registry.
79
- */
80
  public function register_fields() {
81
  $field_registry = rwmb_get_registry( 'field' );
82
 
@@ -87,26 +68,14 @@ class RW_Meta_Box {
87
  }
88
  }
89
 
90
- /**
91
- * Conditional check for whether initializing meta box.
92
- *
93
- * - 1st filter applies to all meta boxes.
94
- * - 2nd filter applies to only current meta box.
95
- *
96
- * @return bool
97
- */
98
- public function is_shown() {
99
  $show = apply_filters( 'rwmb_show', true, $this->meta_box );
100
-
101
  return apply_filters( "rwmb_show_{$this->id}", $show, $this->meta_box );
102
  }
103
 
104
- /**
105
- * Add global hooks.
106
- */
107
  protected function global_hooks() {
108
  // Enqueue common styles and scripts.
109
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
110
 
111
  // Add additional actions for fields.
112
  foreach ( $this->fields as $field ) {
@@ -120,43 +89,40 @@ class RW_Meta_Box {
120
  */
121
  protected function object_hooks() {
122
  // Add meta box.
123
- add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
124
 
125
  // Hide meta box if it's set 'default_hidden'.
126
- add_filter( 'default_hidden_meta_boxes', array( $this, 'hide' ), 10, 2 );
127
 
128
  // Save post meta.
129
  foreach ( $this->post_types as $post_type ) {
130
  if ( 'attachment' === $post_type ) {
131
  // Attachment uses other hooks.
132
  // @see wp_update_post(), wp_insert_attachment().
133
- add_action( 'edit_attachment', array( $this, 'save_post' ) );
134
- add_action( 'add_attachment', array( $this, 'save_post' ) );
135
  } else {
136
- add_action( "save_post_{$post_type}", array( $this, 'save_post' ) );
137
  }
138
  }
139
  }
140
 
141
- /**
142
- * Enqueue common scripts and styles.
143
- */
144
  public function enqueue() {
145
  if ( is_admin() && ! $this->is_edit_screen() ) {
146
  return;
147
  }
148
 
149
- wp_enqueue_style( 'rwmb', RWMB_CSS_URL . 'style.css', array(), RWMB_VER );
150
  if ( is_rtl() ) {
151
- wp_enqueue_style( 'rwmb-rtl', RWMB_CSS_URL . 'style-rtl.css', array(), RWMB_VER );
152
  }
153
 
154
- wp_enqueue_script( 'rwmb', RWMB_JS_URL . 'script.js', array( 'jquery' ), RWMB_VER, true );
155
 
156
  // Load clone script conditionally.
157
  foreach ( $this->fields as $field ) {
158
  if ( $field['clone'] ) {
159
- wp_enqueue_script( 'rwmb-clone', RWMB_JS_URL . 'clone.js', array( 'jquery-ui-sortable' ), RWMB_VER, true );
160
  break;
161
  }
162
  }
@@ -168,7 +134,7 @@ class RW_Meta_Box {
168
 
169
  // Auto save.
170
  if ( $this->autosave ) {
171
- wp_enqueue_script( 'rwmb-autosave', RWMB_JS_URL . 'autosave.js', array( 'jquery' ), RWMB_VER, true );
172
  }
173
 
174
  /**
@@ -184,13 +150,13 @@ class RW_Meta_Box {
184
  */
185
  public function add_meta_boxes() {
186
  $screen = get_current_screen();
187
- add_filter( "postbox_classes_{$screen->id}_{$this->id}", array( $this, 'postbox_classes' ) );
188
 
189
  foreach ( $this->post_types as $post_type ) {
190
  add_meta_box(
191
  $this->id,
192
  $this->title,
193
- array( $this, 'show' ),
194
  $post_type,
195
  $this->context,
196
  $this->priority
@@ -198,13 +164,7 @@ class RW_Meta_Box {
198
  }
199
  }
200
 
201
- /**
202
- * Modify meta box postbox classes.
203
- *
204
- * @param array $classes Array of classes.
205
- * @return array
206
- */
207
- public function postbox_classes( $classes ) {
208
  if ( $this->closed ) {
209
  $classes[] = 'closed';
210
  }
@@ -213,15 +173,7 @@ class RW_Meta_Box {
213
  return $classes;
214
  }
215
 
216
- /**
217
- * Hide meta box if it's set 'default_hidden'
218
- *
219
- * @param array $hidden Array of default hidden meta boxes.
220
- * @param object $screen Current screen information.
221
- *
222
- * @return array
223
- */
224
- public function hide( $hidden, $screen ) {
225
  if ( $this->is_edit_screen( $screen ) && $this->default_hidden ) {
226
  $hidden[] = $this->id;
227
  }
@@ -229,9 +181,6 @@ class RW_Meta_Box {
229
  return $hidden;
230
  }
231
 
232
- /**
233
- * Callback function to show fields in meta box
234
- */
235
  public function show() {
236
  if ( null === $this->object_id ) {
237
  $this->object_id = $this->get_current_object_id();
@@ -287,21 +236,16 @@ class RW_Meta_Box {
287
  do_action( 'rwmb_before_save_post', $object_id );
288
  do_action( "rwmb_{$this->id}_before_save_post", $object_id );
289
 
290
- array_map( array( $this, 'save_field' ), $this->fields );
291
 
292
  // After save action.
293
  do_action( 'rwmb_after_save_post', $object_id );
294
  do_action( "rwmb_{$this->id}_after_save_post", $object_id );
295
  }
296
 
297
- /**
298
- * Save field.
299
- *
300
- * @param array $field Field settings.
301
- */
302
- public function save_field( $field ) {
303
  $single = $field['clone'] || ! $field['multiple'];
304
- $default = $single ? '' : array();
305
  $old = RWMB_Field::call( $field, 'raw_meta', $this->object_id );
306
  $new = rwmb_request()->post( $field['id'], $default );
307
  $new = RWMB_Field::process_value( $new, $this->object_id, $field );
@@ -315,15 +259,7 @@ class RW_Meta_Box {
315
  RWMB_Field::filter( 'after_save_field', null, $field, $new, $old, $this->object_id );
316
  }
317
 
318
- /**
319
- * Validate form when submit. Check:
320
- * - If this function is called to prevent duplicated calls like revisions, manual hook to wp_insert_post, etc.
321
- * - Autosave
322
- * - If form is submitted properly
323
- *
324
- * @return bool
325
- */
326
- public function validate() {
327
  $nonce = rwmb_request()->filter_post( "nonce_{$this->id}" );
328
 
329
  return ! $this->saved
@@ -331,35 +267,23 @@ class RW_Meta_Box {
331
  && wp_verify_nonce( $nonce, "rwmb-save-{$this->id}" );
332
  }
333
 
334
- /**
335
- * Normalize parameters for meta box
336
- *
337
- * @param array $meta_box Meta box definition.
338
- *
339
- * @return array $meta_box Normalized meta box.
340
- */
341
- public static function normalize( $meta_box ) {
342
  $default_title = __( 'Meta Box Title', 'meta-box' );
343
- // Set default values for meta box.
344
- $meta_box = wp_parse_args(
345
- $meta_box,
346
- array(
347
- 'title' => $default_title,
348
- 'id' => ! empty( $meta_box['title'] ) ? sanitize_title( $meta_box['title'] ) : sanitize_title( $default_title ),
349
- 'context' => 'normal',
350
- 'priority' => 'high',
351
- 'post_types' => 'post',
352
- 'autosave' => false,
353
- 'default_hidden' => false,
354
- 'style' => 'default',
355
- 'class' => '',
356
- 'fields' => array(),
357
- )
358
- );
359
 
360
  /**
361
  * Use 'post_types' for better understanding and fallback to 'pages' for previous versions.
362
- *
363
  * @since 4.4.1
364
  */
365
  RWMB_Helpers_Array::change_key( $meta_box, 'pages', 'post_types' );
@@ -370,15 +294,7 @@ class RW_Meta_Box {
370
  return $meta_box;
371
  }
372
 
373
- /**
374
- * Normalize an array of fields
375
- *
376
- * @param array $fields Array of fields.
377
- * @param RWMB_Storage_Interface $storage Storage object. Optional.
378
- *
379
- * @return array $fields Normalized fields.
380
- */
381
- public static function normalize_fields( $fields, $storage = null ) {
382
  foreach ( $fields as $k => $field ) {
383
  $field = RWMB_Field::call( 'normalize', $field );
384
 
@@ -398,10 +314,8 @@ class RW_Meta_Box {
398
  /**
399
  * Check if meta box is saved before.
400
  * This helps saving empty value in meta fields (text, check box, etc.) and set the correct default values.
401
- *
402
- * @return bool
403
  */
404
- public function is_saved() {
405
  foreach ( $this->fields as $field ) {
406
  if ( empty( $field['id'] ) ) {
407
  continue;
@@ -419,7 +333,7 @@ class RW_Meta_Box {
419
 
420
  if (
421
  ( $single && '' !== $value )
422
- || ( ! $single && is_array( $value ) && array() !== $value )
423
  ) {
424
  return true;
425
  }
@@ -431,27 +345,18 @@ class RW_Meta_Box {
431
  /**
432
  * Check if we're on the right edit screen.
433
  *
434
- * @param WP_Screen $screen Screen object. Optional. Use current screen object by default.
435
- *
436
- * @return bool
437
  */
438
- public function is_edit_screen( $screen = null ) {
439
  if ( ! ( $screen instanceof WP_Screen ) ) {
440
  $screen = get_current_screen();
441
  }
442
 
443
- return in_array( $screen->base, array( 'post', 'upload' ), true ) && in_array( $screen->post_type, $this->post_types, true );
444
  }
445
 
446
- /**
447
- * Magic function to get meta box property.
448
- *
449
- * @param string $key Meta box property name.
450
- *
451
- * @return mixed
452
- */
453
- public function __get( $key ) {
454
- return isset( $this->meta_box[ $key ] ) ? $this->meta_box[ $key ] : false;
455
  }
456
 
457
  /**
@@ -463,12 +368,7 @@ class RW_Meta_Box {
463
  $this->object_id = $id;
464
  }
465
 
466
- /**
467
- * Get object type.
468
- *
469
- * @return string
470
- */
471
- public function get_object_type() {
472
  return $this->object_type;
473
  }
474
 
1
  <?php
2
  /**
3
  * A class to rapid develop meta boxes for custom & built in content types
 
 
 
 
 
 
 
 
 
4
  *
5
  * @property string $id Meta Box ID.
6
  * @property string $title Meta Box title.
13
  * @property bool $default_hidden Whether the meta box is hidden by default.
14
  * @property bool $autosave Whether the meta box auto saves.
15
  * @property bool $media_modal Add custom fields to media modal when viewing/editing an attachment.
 
 
16
  */
17
  class RW_Meta_Box {
18
  /**
44
  */
45
  protected $object_type = 'post';
46
 
47
+ public function __construct( array $meta_box ) {
 
 
 
 
 
48
  $meta_box = static::normalize( $meta_box );
49
  $this->meta_box = $meta_box;
50
 
58
  }
59
  }
60
 
 
 
 
61
  public function register_fields() {
62
  $field_registry = rwmb_get_registry( 'field' );
63
 
68
  }
69
  }
70
 
71
+ public function is_shown() : bool {
 
 
 
 
 
 
 
 
72
  $show = apply_filters( 'rwmb_show', true, $this->meta_box );
 
73
  return apply_filters( "rwmb_show_{$this->id}", $show, $this->meta_box );
74
  }
75
 
 
 
 
76
  protected function global_hooks() {
77
  // Enqueue common styles and scripts.
78
+ add_action( 'admin_enqueue_scripts', [ $this, 'enqueue' ] );
79
 
80
  // Add additional actions for fields.
81
  foreach ( $this->fields as $field ) {
89
  */
90
  protected function object_hooks() {
91
  // Add meta box.
92
+ add_action( 'add_meta_boxes', [ $this, 'add_meta_boxes' ] );
93
 
94
  // Hide meta box if it's set 'default_hidden'.
95
+ add_filter( 'default_hidden_meta_boxes', [ $this, 'hide' ], 10, 2 );
96
 
97
  // Save post meta.
98
  foreach ( $this->post_types as $post_type ) {
99
  if ( 'attachment' === $post_type ) {
100
  // Attachment uses other hooks.
101
  // @see wp_update_post(), wp_insert_attachment().
102
+ add_action( 'edit_attachment', [ $this, 'save_post' ] );
103
+ add_action( 'add_attachment', [ $this, 'save_post' ] );
104
  } else {
105
+ add_action( "save_post_{$post_type}", [ $this, 'save_post' ] );
106
  }
107
  }
108
  }
109
 
 
 
 
110
  public function enqueue() {
111
  if ( is_admin() && ! $this->is_edit_screen() ) {
112
  return;
113
  }
114
 
115
+ wp_enqueue_style( 'rwmb', RWMB_CSS_URL . 'style.css', [], RWMB_VER );
116
  if ( is_rtl() ) {
117
+ wp_enqueue_style( 'rwmb-rtl', RWMB_CSS_URL . 'style-rtl.css', [], RWMB_VER );
118
  }
119
 
120
+ wp_enqueue_script( 'rwmb', RWMB_JS_URL . 'script.js', [ 'jquery' ], RWMB_VER, true );
121
 
122
  // Load clone script conditionally.
123
  foreach ( $this->fields as $field ) {
124
  if ( $field['clone'] ) {
125
+ wp_enqueue_script( 'rwmb-clone', RWMB_JS_URL . 'clone.js', [ 'jquery-ui-sortable' ], RWMB_VER, true );
126
  break;
127
  }
128
  }
134
 
135
  // Auto save.
136
  if ( $this->autosave ) {
137
+ wp_enqueue_script( 'rwmb-autosave', RWMB_JS_URL . 'autosave.js', [ 'jquery' ], RWMB_VER, true );
138
  }
139
 
140
  /**
150
  */
151
  public function add_meta_boxes() {
152
  $screen = get_current_screen();
153
+ add_filter( "postbox_classes_{$screen->id}_{$this->id}", [ $this, 'postbox_classes' ] );
154
 
155
  foreach ( $this->post_types as $post_type ) {
156
  add_meta_box(
157
  $this->id,
158
  $this->title,
159
+ [ $this, 'show' ],
160
  $post_type,
161
  $this->context,
162
  $this->priority
164
  }
165
  }
166
 
167
+ public function postbox_classes( array $classes ) : array {
 
 
 
 
 
 
168
  if ( $this->closed ) {
169
  $classes[] = 'closed';
170
  }
173
  return $classes;
174
  }
175
 
176
+ public function hide( array $hidden, $screen ) : array {
 
 
 
 
 
 
 
 
177
  if ( $this->is_edit_screen( $screen ) && $this->default_hidden ) {
178
  $hidden[] = $this->id;
179
  }
181
  return $hidden;
182
  }
183
 
 
 
 
184
  public function show() {
185
  if ( null === $this->object_id ) {
186
  $this->object_id = $this->get_current_object_id();
236
  do_action( 'rwmb_before_save_post', $object_id );
237
  do_action( "rwmb_{$this->id}_before_save_post", $object_id );
238
 
239
+ array_map( [ $this, 'save_field' ], $this->fields );
240
 
241
  // After save action.
242
  do_action( 'rwmb_after_save_post', $object_id );
243
  do_action( "rwmb_{$this->id}_after_save_post", $object_id );
244
  }
245
 
246
+ public function save_field( array $field ) {
 
 
 
 
 
247
  $single = $field['clone'] || ! $field['multiple'];
248
+ $default = $single ? '' : [];
249
  $old = RWMB_Field::call( $field, 'raw_meta', $this->object_id );
250
  $new = rwmb_request()->post( $field['id'], $default );
251
  $new = RWMB_Field::process_value( $new, $this->object_id, $field );
259
  RWMB_Field::filter( 'after_save_field', null, $field, $new, $old, $this->object_id );
260
  }
261
 
262
+ public function validate() : bool {
 
 
 
 
 
 
 
 
263
  $nonce = rwmb_request()->filter_post( "nonce_{$this->id}" );
264
 
265
  return ! $this->saved
267
  && wp_verify_nonce( $nonce, "rwmb-save-{$this->id}" );
268
  }
269
 
270
+ public static function normalize( array $meta_box ) : array {
 
 
 
 
 
 
 
271
  $default_title = __( 'Meta Box Title', 'meta-box' );
272
+ $meta_box = wp_parse_args( $meta_box, [
273
+ 'title' => $default_title,
274
+ 'id' => ! empty( $meta_box['title'] ) ? sanitize_title( $meta_box['title'] ) : sanitize_title( $default_title ),
275
+ 'context' => 'normal',
276
+ 'priority' => 'high',
277
+ 'post_types' => 'post',
278
+ 'autosave' => false,
279
+ 'default_hidden' => false,
280
+ 'style' => 'default',
281
+ 'class' => '',
282
+ 'fields' => [],
283
+ ] );
 
 
 
 
284
 
285
  /**
286
  * Use 'post_types' for better understanding and fallback to 'pages' for previous versions.
 
287
  * @since 4.4.1
288
  */
289
  RWMB_Helpers_Array::change_key( $meta_box, 'pages', 'post_types' );
294
  return $meta_box;
295
  }
296
 
297
+ public static function normalize_fields( array $fields, $storage = null ) : array {
 
 
 
 
 
 
 
 
298
  foreach ( $fields as $k => $field ) {
299
  $field = RWMB_Field::call( 'normalize', $field );
300
 
314
  /**
315
  * Check if meta box is saved before.
316
  * This helps saving empty value in meta fields (text, check box, etc.) and set the correct default values.
 
 
317
  */
318
+ public function is_saved() : bool {
319
  foreach ( $this->fields as $field ) {
320
  if ( empty( $field['id'] ) ) {
321
  continue;
333
 
334
  if (
335
  ( $single && '' !== $value )
336
+ || ( ! $single && is_array( $value ) && [] !== $value )
337
  ) {
338
  return true;
339
  }
345
  /**
346
  * Check if we're on the right edit screen.
347
  *
348
+ * @param ?WP_Screen $screen Screen object.
 
 
349
  */
350
+ public function is_edit_screen( $screen = null ) : bool {
351
  if ( ! ( $screen instanceof WP_Screen ) ) {
352
  $screen = get_current_screen();
353
  }
354
 
355
+ return in_array( $screen->base, [ 'post', 'upload' ], true ) && in_array( $screen->post_type, $this->post_types, true );
356
  }
357
 
358
+ public function __get( string $key ) {
359
+ return $this->meta_box[ $key ] ?? false;
 
 
 
 
 
 
 
360
  }
361
 
362
  /**
368
  $this->object_id = $id;
369
  }
370
 
371
+ public function get_object_type() : string {
 
 
 
 
 
372
  return $this->object_type;
373
  }
374
 
inc/sanitizer.php CHANGED
@@ -219,11 +219,6 @@ class RWMB_Sanitizer {
219
  return $field['timestamp'] ? floor( abs( (float) $value ) ) : sanitize_text_field( $value );
220
  }
221
 
222
- /**
223
- * Sanitize map field.
224
- *
225
- * @param mixed $value The submitted value.
226
- */
227
  private function sanitize_map( $value ) : string {
228
  $value = sanitize_text_field( $value );
229
  list( $latitude, $longitude, $zoom ) = explode( ',', $value . ',,' );
@@ -235,16 +230,8 @@ class RWMB_Sanitizer {
235
  return "$latitude,$longitude,$zoom";
236
  }
237
 
238
- /**
239
- * Sanitize taxonomy advanced field.
240
- *
241
- * @param mixed $value The submitted value.
242
- */
243
  private function sanitize_taxonomy_advanced( $value ) : string {
244
- $value = RWMB_Helpers_Array::from_csv( $value );
245
- $value = array_filter( array_map( 'absint', $value ) );
246
-
247
- return implode( ',', $value );
248
  }
249
 
250
  private function sanitize_url( string $value ) : string {
219
  return $field['timestamp'] ? floor( abs( (float) $value ) ) : sanitize_text_field( $value );
220
  }
221
 
 
 
 
 
 
222
  private function sanitize_map( $value ) : string {
223
  $value = sanitize_text_field( $value );
224
  list( $latitude, $longitude, $zoom ) = explode( ',', $value . ',,' );
230
  return "$latitude,$longitude,$zoom";
231
  }
232
 
 
 
 
 
 
233
  private function sanitize_taxonomy_advanced( $value ) : string {
234
+ return implode( ',', wp_parse_id_list( $value ) );
 
 
 
235
  }
236
 
237
  private function sanitize_url( string $value ) : string {
inc/storages/base.php CHANGED
@@ -1,15 +1,8 @@
1
  <?php
2
  /**
3
- * Base storage
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Class RWMB_Base_Storage
10
  */
11
  class RWMB_Base_Storage implements RWMB_Storage_Interface {
12
-
13
  /**
14
  * Object type.
15
  *
1
  <?php
2
  /**
3
+ * Base storage.
 
 
 
 
 
 
4
  */
5
  class RWMB_Base_Storage implements RWMB_Storage_Interface {
 
6
  /**
7
  * Object type.
8
  *
inc/update/notification.php CHANGED
@@ -1,14 +1,6 @@
1
  <?php
2
  /**
3
  * This class notifies users to enter or update license key.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Meta Box Update Notification class
10
- *
11
- * @package Meta Box
12
  */
13
  class RWMB_Update_Notification {
14
  /**
@@ -57,8 +49,8 @@ class RWMB_Update_Notification {
57
  $extensions = $this->checker->get_extensions();
58
  foreach ( $extensions as $extension ) {
59
  $file = "{$extension}/{$extension}.php";
60
- add_action( "in_plugin_update_message-$file", array( $this, 'show_update_message' ), 10, 2 );
61
- add_filter( "plugin_action_links_$file", array( $this, 'plugin_links' ), 20 );
62
  }
63
 
64
  // Show global update notification.
@@ -67,47 +59,36 @@ class RWMB_Update_Notification {
67
  }
68
 
69
  $admin_notices_hook = $this->option->is_network_activated() ? 'network_admin_notices' : 'admin_notices';
70
- add_action( $admin_notices_hook, array( $this, 'notify' ) );
71
 
72
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
73
- add_action( 'wp_ajax_mb_dismiss_notification', array( $this, 'dismiss' ) );
74
  }
75
 
76
- /**
77
- * Enqueue the notification script.
78
- */
79
  public function enqueue() {
80
- wp_enqueue_script( 'mb-notification', RWMB_JS_URL . 'notification.js', array( 'jquery' ), RWMB_VER, true );
81
- wp_localize_script( 'mb-notification', 'MBNotification', array( 'nonce' => wp_create_nonce( 'dismiss' ) ) );
82
  }
83
 
84
- /**
85
- * Dismiss the notification permanently via ajax.
86
- */
87
  public function dismiss() {
88
  check_ajax_referer( 'dismiss', 'nonce' );
89
 
90
- $this->option->update(
91
- array(
92
- 'notification_dismissed' => 1,
93
- 'notification_dismissed_time' => time(),
94
- )
95
- );
96
 
97
  wp_send_json_success();
98
  }
99
 
100
- /**
101
- * Notify users to enter license key.
102
- */
103
  public function notify() {
104
  // Do not show notification on License page.
105
  $screen = get_current_screen();
106
- if ( in_array( $screen->id, array( 'meta-box_page_meta-box-updater', 'settings_page_meta-box-updater-network' ), true ) ) {
107
  return;
108
  }
109
 
110
- $messages = array(
111
  // Translators: %1$s - URL to the settings page, %2$s - URL to the pricing page.
112
  'no_key' => __( 'You have not set your Meta Box license key yet, which means you are missing out on automatic updates and support! Please <a href="%1$s">enter your license key</a> or <a href="%2$s" target="_blank">get a new one here</a>.', 'meta-box' ),
113
  // Translators: %1$s - URL to the settings page, %2$s - URL to the pricing page.
@@ -116,7 +97,7 @@ class RWMB_Update_Notification {
116
  'error' => __( 'Your license key for Meta Box is <b>invalid</b>. Please <a href="%1$s">update your license key</a> or <a href="%2$s" target="_blank">get a new one</a> to enable automatic updates.', 'meta-box' ),
117
  // Translators: %3$s - URL to the My Account page.
118
  'expired' => __( 'Your license key for Meta Box is <b>expired</b>. Please <a href="%3$s" target="_blank">renew your license</a> to get automatic updates and premium support.', 'meta-box' ),
119
- );
120
  $status = $this->option->get_license_status();
121
  if ( ! isset( $messages[ $status ] ) ) {
122
  return;
@@ -137,7 +118,7 @@ class RWMB_Update_Notification {
137
  return;
138
  }
139
 
140
- $messages = array(
141
  // Translators: %1$s - URL to the settings page, %2$s - URL to the pricing page.
142
  'no_key' => __( 'Please <a href="%1$s">enter your license key</a> or <a href="%2$s" target="_blank">get a new one here</a>.', 'meta-box' ),
143
  // Translators: %1$s - URL to the settings page, %2$s - URL to the pricing page.
@@ -146,7 +127,7 @@ class RWMB_Update_Notification {
146
  'error' => __( 'Your license key is <b>invalid</b>. Please <a href="%1$s">update your license key</a> or <a href="%2$s" target="_blank">get a new one here</a>.', 'meta-box' ),
147
  // Translators: %3$s - URL to the My Account page.
148
  'expired' => __( 'Your license key is <b>expired</b>. Please <a href="%3$s" target="_blank">renew your license</a>.', 'meta-box' ),
149
- );
150
  $status = $this->option->get_license_status();
151
  if ( ! isset( $messages[ $status ] ) ) {
152
  return;
@@ -155,14 +136,7 @@ class RWMB_Update_Notification {
155
  echo '<br><span style="width: 26px; height: 20px; display: inline-block;">&nbsp;</span>' . wp_kses_post( sprintf( $messages[ $status ], $this->settings_page, 'https://metabox.io/pricing/', 'https://metabox.io/my-account/' ) );
156
  }
157
 
158
- /**
159
- * Add link for activate or update the license key.
160
- *
161
- * @param array $links Array of plugin links.
162
- *
163
- * @return array
164
- */
165
- public function plugin_links( $links ) {
166
  $status = $this->option->get_license_status();
167
  if ( 'active' === $status ) {
168
  return $links;
@@ -176,11 +150,9 @@ class RWMB_Update_Notification {
176
 
177
  /**
178
  * Check if the global notification is dismissed.
179
- * Auto re-enable the notification every 2 weeks after it's dissmissed.
180
- *
181
- * @return bool
182
  */
183
- private function is_dismissed() {
184
  $time = $this->option->get( 'notification_dismissed_time' );
185
 
186
  return $this->option->get( 'notification_dismissed' ) && time() - $time < 14 * DAY_IN_SECONDS;
1
  <?php
2
  /**
3
  * This class notifies users to enter or update license key.
 
 
 
 
 
 
 
 
4
  */
5
  class RWMB_Update_Notification {
6
  /**
49
  $extensions = $this->checker->get_extensions();
50
  foreach ( $extensions as $extension ) {
51
  $file = "{$extension}/{$extension}.php";
52
+ add_action( "in_plugin_update_message-$file", [ $this, 'show_update_message' ], 10, 2 );
53
+ add_filter( "plugin_action_links_$file", [ $this, 'plugin_links' ], 20 );
54
  }
55
 
56
  // Show global update notification.
59
  }
60
 
61
  $admin_notices_hook = $this->option->is_network_activated() ? 'network_admin_notices' : 'admin_notices';
62
+ add_action( $admin_notices_hook, [ $this, 'notify' ] );
63
 
64
+ add_action( 'admin_enqueue_scripts', [ $this, 'enqueue' ] );
65
+ add_action( 'wp_ajax_mb_dismiss_notification', [ $this, 'dismiss' ] );
66
  }
67
 
 
 
 
68
  public function enqueue() {
69
+ wp_enqueue_script( 'mb-notification', RWMB_JS_URL . 'notification.js', [ 'jquery' ], RWMB_VER, true );
70
+ wp_localize_script( 'mb-notification', 'MBNotification', [ 'nonce' => wp_create_nonce( 'dismiss' ) ] );
71
  }
72
 
 
 
 
73
  public function dismiss() {
74
  check_ajax_referer( 'dismiss', 'nonce' );
75
 
76
+ $this->option->update( [
77
+ 'notification_dismissed' => 1,
78
+ 'notification_dismissed_time' => time(),
79
+ ] );
 
 
80
 
81
  wp_send_json_success();
82
  }
83
 
 
 
 
84
  public function notify() {
85
  // Do not show notification on License page.
86
  $screen = get_current_screen();
87
+ if ( in_array( $screen->id, [ 'meta-box_page_meta-box-updater', 'settings_page_meta-box-updater-network' ], true ) ) {
88
  return;
89
  }
90
 
91
+ $messages = [
92
  // Translators: %1$s - URL to the settings page, %2$s - URL to the pricing page.
93
  'no_key' => __( 'You have not set your Meta Box license key yet, which means you are missing out on automatic updates and support! Please <a href="%1$s">enter your license key</a> or <a href="%2$s" target="_blank">get a new one here</a>.', 'meta-box' ),
94
  // Translators: %1$s - URL to the settings page, %2$s - URL to the pricing page.
97
  'error' => __( 'Your license key for Meta Box is <b>invalid</b>. Please <a href="%1$s">update your license key</a> or <a href="%2$s" target="_blank">get a new one</a> to enable automatic updates.', 'meta-box' ),
98
  // Translators: %3$s - URL to the My Account page.
99
  'expired' => __( 'Your license key for Meta Box is <b>expired</b>. Please <a href="%3$s" target="_blank">renew your license</a> to get automatic updates and premium support.', 'meta-box' ),
100
+ ];
101
  $status = $this->option->get_license_status();
102
  if ( ! isset( $messages[ $status ] ) ) {
103
  return;
118
  return;
119
  }
120
 
121
+ $messages = [
122
  // Translators: %1$s - URL to the settings page, %2$s - URL to the pricing page.
123
  'no_key' => __( 'Please <a href="%1$s">enter your license key</a> or <a href="%2$s" target="_blank">get a new one here</a>.', 'meta-box' ),
124
  // Translators: %1$s - URL to the settings page, %2$s - URL to the pricing page.
127
  'error' => __( 'Your license key is <b>invalid</b>. Please <a href="%1$s">update your license key</a> or <a href="%2$s" target="_blank">get a new one here</a>.', 'meta-box' ),
128
  // Translators: %3$s - URL to the My Account page.
129
  'expired' => __( 'Your license key is <b>expired</b>. Please <a href="%3$s" target="_blank">renew your license</a>.', 'meta-box' ),
130
+ ];
131
  $status = $this->option->get_license_status();
132
  if ( ! isset( $messages[ $status ] ) ) {
133
  return;
136
  echo '<br><span style="width: 26px; height: 20px; display: inline-block;">&nbsp;</span>' . wp_kses_post( sprintf( $messages[ $status ], $this->settings_page, 'https://metabox.io/pricing/', 'https://metabox.io/my-account/' ) );
137
  }
138
 
139
+ public function plugin_links( array $links ) : array {
 
 
 
 
 
 
 
140
  $status = $this->option->get_license_status();
141
  if ( 'active' === $status ) {
142
  return $links;
150
 
151
  /**
152
  * Check if the global notification is dismissed.
153
+ * Auto re-enable the notification every 2 weeks after it's dismissed.
 
 
154
  */
155
+ private function is_dismissed() : bool {
156
  $time = $this->option->get( 'notification_dismissed_time' );
157
 
158
  return $this->option->get( 'notification_dismissed' ) && time() - $time < 14 * DAY_IN_SECONDS;
inc/update/option.php CHANGED
@@ -1,14 +1,6 @@
1
  <?php
2
  /**
3
  * This class handles getting and saving the updater option.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * Meta Box Update Option class
10
- *
11
- * @package Meta Box
12
  */
13
  class RWMB_Update_Option {
14
  /**
@@ -21,30 +13,22 @@ class RWMB_Update_Option {
21
  /**
22
  * Get an option.
23
  *
24
- * @param string $name Option name. Pass null to return the option array.
25
- * @param mixed $default Default value.
26
  *
27
  * @return mixed Option value or option array.
28
  */
29
  public function get( $name = null, $default = null ) {
30
- $option = $this->is_network_activated() ? get_site_option( $this->option, array() ) : get_option( $this->option, array() );
31
 
32
- return null === $name ? $option : ( isset( $option[ $name ] ) ? $option[ $name ] : $default );
33
  }
34
 
35
- /**
36
- * Get the API key.
37
- *
38
- * @return string
39
- */
40
- public function get_api_key() {
41
  return defined( 'META_BOX_KEY' ) ? META_BOX_KEY : $this->get( 'api_key' );
42
  }
43
 
44
- /**
45
- * Get license status.
46
- */
47
- public function get_license_status() {
48
  return $this->get_api_key() ? $this->get( 'status', 'active' ) : 'no_key';
49
  }
50
 
@@ -64,12 +48,7 @@ class RWMB_Update_Option {
64
  }
65
  }
66
 
67
- /**
68
- * Detect if the plugin is network activated in Multisite environment.
69
- *
70
- * @return bool
71
- */
72
- public function is_network_activated() {
73
  if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
74
  require_once ABSPATH . '/wp-admin/includes/plugin.php';
75
  }
1
  <?php
2
  /**
3
  * This class handles getting and saving the updater option.
 
 
 
 
 
 
 
 
4
  */
5
  class RWMB_Update_Option {
6
  /**
13
  /**
14
  * Get an option.
15
  *
16
+ * @param ?string $name Option name. Pass null to return the option array.
17
+ * @param mixed $default Default value.
18
  *
19
  * @return mixed Option value or option array.
20
  */
21
  public function get( $name = null, $default = null ) {
22
+ $option = $this->is_network_activated() ? get_site_option( $this->option, [] ) : get_option( $this->option, [] );
23
 
24
+ return null === $name ? $option : ( $option[ $name ] ?? $default );
25
  }
26
 
27
+ public function get_api_key() : string {
 
 
 
 
 
28
  return defined( 'META_BOX_KEY' ) ? META_BOX_KEY : $this->get( 'api_key' );
29
  }
30
 
31
+ public function get_license_status() : string {
 
 
 
32
  return $this->get_api_key() ? $this->get( 'status', 'active' ) : 'no_key';
33
  }
34
 
48
  }
49
  }
50
 
51
+ public function is_network_activated() : bool {
 
 
 
 
 
52
  if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
53
  require_once ABSPATH . '/wp-admin/includes/plugin.php';
54
  }
inc/validation.php CHANGED
@@ -21,12 +21,8 @@ class RWMB_Validation {
21
  public function enqueue() {
22
  wp_enqueue_script( 'rwmb-validation', RWMB_JS_URL . 'validation.min.js', [ 'jquery', 'rwmb' ], RWMB_VER, true );
23
 
24
- RWMB_Helpers_Field::localize_script_once(
25
- 'rwmb-validation',
26
- 'rwmbValidation',
27
- [
28
- 'message' => esc_html( apply_filters( 'rwmb_validation_message_string', __( 'Please correct the errors highlighted below and try again.', 'meta-box' ) ) ),
29
- ]
30
- );
31
  }
32
  }
21
  public function enqueue() {
22
  wp_enqueue_script( 'rwmb-validation', RWMB_JS_URL . 'validation.min.js', [ 'jquery', 'rwmb' ], RWMB_VER, true );
23
 
24
+ RWMB_Helpers_Field::localize_script_once( 'rwmb-validation', 'rwmbValidation', [
25
+ 'message' => esc_html( apply_filters( 'rwmb_validation_message_string', __( 'Please correct the errors highlighted below and try again.', 'meta-box' ) ) ),
26
+ ] );
 
 
 
 
27
  }
28
  }
inc/walkers/base.php CHANGED
@@ -2,12 +2,6 @@
2
  /**
3
  * Base walker.
4
  * Walkers must inherit this class and overwrite methods with its own.
5
- *
6
- * @package Meta Box
7
- */
8
-
9
- /**
10
- * Base walker class.
11
  */
12
  abstract class RWMB_Walker_Base extends Walker {
13
  /**
@@ -31,10 +25,10 @@ abstract class RWMB_Walker_Base extends Walker {
31
  * @param mixed $meta Meta value.
32
  */
33
  public function __construct( $field, $meta ) {
34
- $this->db_fields = array(
35
  'id' => 'value',
36
  'parent' => 'parent',
37
- );
38
 
39
  $this->field = $field;
40
  $this->meta = (array) $meta;
2
  /**
3
  * Base walker.
4
  * Walkers must inherit this class and overwrite methods with its own.
 
 
 
 
 
 
5
  */
6
  abstract class RWMB_Walker_Base extends Walker {
7
  /**
25
  * @param mixed $meta Meta value.
26
  */
27
  public function __construct( $field, $meta ) {
28
+ $this->db_fields = [
29
  'id' => 'value',
30
  'parent' => 'parent',
31
+ ];
32
 
33
  $this->field = $field;
34
  $this->meta = (array) $meta;
inc/walkers/select-tree.php CHANGED
@@ -1,18 +1,12 @@
1
  <?php
2
  /**
3
  * Select tree walker for cascading select fields.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * The select tree walker class.
10
  */
11
  class RWMB_Walker_Select_Tree {
12
  /**
13
  * Field settings.
14
  *
15
- * @var string
16
  */
17
  public $field;
18
 
@@ -42,10 +36,10 @@ class RWMB_Walker_Select_Tree {
42
  * @return string
43
  */
44
  public function walk( $options ) {
45
- $children = array();
46
 
47
  foreach ( $options as $option ) {
48
- $parent = isset( $option->parent ) ? $option->parent : 0;
49
  $children[ $parent ][] = $option;
50
  }
51
 
1
  <?php
2
  /**
3
  * Select tree walker for cascading select fields.
 
 
 
 
 
 
4
  */
5
  class RWMB_Walker_Select_Tree {
6
  /**
7
  * Field settings.
8
  *
9
+ * @var array
10
  */
11
  public $field;
12
 
36
  * @return string
37
  */
38
  public function walk( $options ) {
39
+ $children = [];
40
 
41
  foreach ( $options as $option ) {
42
+ $parent = $option->parent ?? 0;
43
  $children[ $parent ][] = $option;
44
  }
45
 
inc/walkers/select.php CHANGED
@@ -1,12 +1,6 @@
1
  <?php
2
  /**
3
  * Select walker select fields.
4
- *
5
- * @package Meta Box
6
- */
7
-
8
- /**
9
- * The select walker class.
10
  */
11
  class RWMB_Walker_Select extends RWMB_Walker_Base {
12
  /**
@@ -20,7 +14,7 @@ class RWMB_Walker_Select extends RWMB_Walker_Base {
20
  * @param array $args An array of additional arguments.
21
  * @param int $current_object_id ID of the current item.
22
  */
23
- public function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {
24
  $indent = str_repeat( '&nbsp;', $depth * 4 );
25
 
26
  $output .= sprintf(
1
  <?php
2
  /**
3
  * Select walker select fields.
 
 
 
 
 
 
4
  */
5
  class RWMB_Walker_Select extends RWMB_Walker_Base {
6
  /**
14
  * @param array $args An array of additional arguments.
15
  * @param int $current_object_id ID of the current item.
16
  */
17
+ public function start_el( &$output, $object, $depth = 0, $args = [], $current_object_id = 0 ) {
18
  $indent = str_repeat( '&nbsp;', $depth * 4 );
19
 
20
  $output .= sprintf(
js/button-group.js CHANGED
@@ -32,11 +32,11 @@
32
  }
33
 
34
  function init( e ) {
35
- $( e.target ).find( '.rwmb-button-input-list li' ).each( setActiveClass );
36
  }
37
 
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 );
32
  }
33
 
34
  function init( e ) {
35
+ $( e.target ).find( '.rwmb-button-input-list label' ).each( setActiveClass );
36
  }
37
 
38
  rwmb.$document
39
  .on( 'mb_ready', init )
40
+ .on( 'click', '.rwmb-button-input-list label', clickHandler )
41
+ .on( 'clone', '.rwmb-button-input-list label', setActiveClass );
42
  } )( 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.6.9
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.6.10
7
  * Author: MetaBox.io
8
  * Author URI: https://metabox.io
9
  * License: GPL2+
readme.txt CHANGED
@@ -2,10 +2,10 @@
2
  Contributors: elightup, metabox, rilwis, fitwp, f-j-kaiser, funkatronic, PerWiklander, ruanmer, Omnicia
3
  Donate link: https://metabox.io/pricing/
4
  Tags: meta box, custom fields, custom post types, custom taxonomies, cpt, meta boxes, custom field, post type, taxonomy, meta, admin, advanced, custom, edit, field, file, image, magic fields, post types, more fields, post, repeater, simple fields, text, textarea, type, cms, fields post
5
- Requires at least: 4.3
6
  Requires PHP: 7.0
7
  Tested up to: 6.1.1
8
- Stable tag: 5.6.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 your custom post types in WordPress.
@@ -177,6 +177,12 @@ To getting started with the plugin, please read the [Quick Start Guide](https://
177
 
178
  == Changelog ==
179
 
 
 
 
 
 
 
180
  = 5.6.9 - 2022-12-05 =
181
  - Improve accessibility for form controls, especially when using on the front end
182
  - Use all admin themes for switch and button group
2
  Contributors: elightup, metabox, rilwis, fitwp, f-j-kaiser, funkatronic, PerWiklander, ruanmer, Omnicia
3
  Donate link: https://metabox.io/pricing/
4
  Tags: meta box, custom fields, custom post types, custom taxonomies, cpt, meta boxes, custom field, post type, taxonomy, meta, admin, advanced, custom, edit, field, file, image, magic fields, post types, more fields, post, repeater, simple fields, text, textarea, type, cms, fields post
5
+ Requires at least: 4.8
6
  Requires PHP: 7.0
7
  Tested up to: 6.1.1
8
+ Stable tag: 5.6.10
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 your custom post types in WordPress.
177
 
178
  == Changelog ==
179
 
180
+ = 5.6.10 - 2022-12-06 =
181
+ - Fix padding for images in custom blocks
182
+ - Fix sidebar::query not compatible with object_choice::query
183
+ - Fix compatibility with custom models in MB Custom Table. Closes #1466.
184
+ - Modernize code: use short array, add type hints, remove comments
185
+
186
  = 5.6.9 - 2022-12-05 =
187
  - Improve accessibility for form controls, especially when using on the front end
188
  - Use all admin themes for switch and button group