Version Description
- Improvement: Add
max_file_size
to upload fields (File_Upload
,Image_Upload
,Plupload_Image
). - Improvement: Add support for attributes for file input.
- Improvement: Update Polish translation.
- Improvement: Add translation support for Key and Value strings (@prop saqibsarwar).
- Fix: Shorter width of email field vs. other fields (@prop saqibsarwar).
- Fix: Fix cloneable datetime field with timestamp=true.
- Fix: Remove margin bottom in select_advanced options.
- Fix: Showing the correct selected value for select_advanced field when the option value contains '&' character.
- Fix: Fix default values not working with taxonomy and taxonomy_advanced fields.
Download this release
Release Info
Developer | rilwis |
Plugin | Meta Box |
Version | 4.10.2 |
Comparing to | |
See all releases |
Code changes from version 4.10.1 to 4.10.2
- css/select-advanced.css +3 -0
- inc/autoloader.php +4 -4
- inc/clone.php +19 -17
- inc/core.php +8 -8
- inc/field.php +94 -93
- inc/fields/autocomplete.php +19 -14
- inc/fields/button.php +17 -12
- inc/fields/checkbox-list.php +9 -4
- inc/fields/checkbox.php +11 -7
- inc/fields/choice.php +30 -22
- inc/fields/color.php +16 -12
- inc/fields/custom-html.php +10 -5
- inc/fields/date.php +9 -6
- inc/fields/datetime.php +44 -36
- inc/fields/divider.php +16 -13
- inc/fields/fieldset-text.php +17 -13
- inc/fields/file-input.php +25 -29
- inc/fields/file-upload.php +29 -4
- inc/fields/file.php +50 -38
- inc/fields/heading.php +15 -13
- inc/fields/image-advanced.php +25 -21
- inc/fields/image-select.php +18 -14
- inc/fields/image-upload.php +20 -3
- inc/fields/image.php +14 -9
- inc/fields/input-list.php +17 -12
- inc/fields/input.php +18 -12
- inc/fields/key-value.php +32 -28
- inc/fields/map.php +36 -32
- inc/fields/media.php +40 -31
- inc/fields/multiple-values.php +12 -7
- inc/fields/number.php +13 -8
- inc/fields/object-choice.php +24 -19
- inc/fields/oembed.php +22 -18
- inc/fields/password.php +12 -7
- inc/fields/post.php +30 -29
- inc/fields/radio.php +9 -4
- inc/fields/range.php +15 -10
- inc/fields/select-advanced.php +13 -8
- inc/fields/select-tree.php +17 -12
- inc/fields/select.php +19 -14
- inc/fields/slider.php +17 -14
- inc/fields/taxonomy-advanced.php +33 -24
- inc/fields/taxonomy.php +48 -42
- inc/fields/text-list.php +13 -9
- inc/fields/text.php +13 -8
- inc/fields/textarea.php +20 -15
- inc/fields/thickbox-image.php +20 -16
- inc/fields/time.php +9 -6
- inc/fields/user.php +19 -24
- inc/fields/video.php +11 -13
- inc/fields/wysiwyg.php +27 -23
- inc/functions.php +27 -24
- inc/helper.php +24 -11
- inc/loader.php +12 -13
- inc/meta-box.php +51 -42
- inc/sanitizer.php +3 -3
- inc/templates/media.php +39 -39
- inc/templates/upload.php +5 -5
- inc/templates/video.php +24 -24
- inc/validation.php +5 -5
- inc/walkers/base.php +15 -3
- inc/walkers/input-list.php +22 -19
- inc/walkers/select-tree.php +32 -7
- inc/walkers/select.php +16 -10
- inc/wpml.php +30 -21
- js/file-upload.js +6 -1
- js/jquery-validation/additional-methods.min.js +3 -3
- js/media.js +1 -1
- languages/default.pot +44 -44
- languages/meta-box-pl_PL.mo +0 -0
- meta-box.php +3 -1
- readme.txt +16 -5
css/select-advanced.css
CHANGED
@@ -11,3 +11,6 @@
|
|
11 |
.select2-dropdown {
|
12 |
border-color: #ddd;
|
13 |
}
|
|
|
|
|
|
11 |
.select2-dropdown {
|
12 |
border-color: #ddd;
|
13 |
}
|
14 |
+
.select2-results__option {
|
15 |
+
margin-bottom: 0;
|
16 |
+
}
|
inc/autoloader.php
CHANGED
@@ -50,7 +50,7 @@ class RWMB_Autoloader {
|
|
50 |
/**
|
51 |
* Autoload fields' classes.
|
52 |
*
|
53 |
-
* @param string $class Class name
|
54 |
* @return mixed Boolean false if no mapped file can be loaded, or the name of the mapped file that was loaded.
|
55 |
*/
|
56 |
public function autoload( $class ) {
|
@@ -79,7 +79,7 @@ class RWMB_Autoloader {
|
|
79 |
*/
|
80 |
protected function fallback() {
|
81 |
$files = array(
|
82 |
-
// Core
|
83 |
'core',
|
84 |
'clone',
|
85 |
'helper',
|
@@ -87,13 +87,13 @@ class RWMB_Autoloader {
|
|
87 |
'validation',
|
88 |
'sanitize',
|
89 |
|
90 |
-
// Walkers
|
91 |
'walkers/walker',
|
92 |
'walkers/select',
|
93 |
'walkers/select-tree',
|
94 |
'walkers/input-list',
|
95 |
|
96 |
-
// Fields
|
97 |
'field',
|
98 |
|
99 |
'fields/multiple-values',
|
50 |
/**
|
51 |
* Autoload fields' classes.
|
52 |
*
|
53 |
+
* @param string $class Class name.
|
54 |
* @return mixed Boolean false if no mapped file can be loaded, or the name of the mapped file that was loaded.
|
55 |
*/
|
56 |
public function autoload( $class ) {
|
79 |
*/
|
80 |
protected function fallback() {
|
81 |
$files = array(
|
82 |
+
// Core.
|
83 |
'core',
|
84 |
'clone',
|
85 |
'helper',
|
87 |
'validation',
|
88 |
'sanitize',
|
89 |
|
90 |
+
// Walkers.
|
91 |
'walkers/walker',
|
92 |
'walkers/select',
|
93 |
'walkers/select-tree',
|
94 |
'walkers/input-list',
|
95 |
|
96 |
+
// Fields.
|
97 |
'field',
|
98 |
|
99 |
'fields/multiple-values',
|
inc/clone.php
CHANGED
@@ -1,17 +1,19 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
/**
|
4 |
-
* The
|
5 |
*
|
6 |
* @package Meta Box
|
7 |
*/
|
8 |
-
class RWMB_Clone {
|
9 |
|
|
|
|
|
|
|
|
|
10 |
/**
|
11 |
-
* Get clone field HTML
|
12 |
*
|
13 |
-
* @param mixed $meta
|
14 |
-
* @param array $field
|
15 |
*
|
16 |
* @return string
|
17 |
*/
|
@@ -36,7 +38,7 @@ class RWMB_Clone {
|
|
36 |
$sub_field['field_name'] .= '[]';
|
37 |
}
|
38 |
|
39 |
-
// Wrap field HTML in a div with class="rwmb-clone" if needed
|
40 |
$class = "rwmb-clone rwmb-{$field['type']}-clone";
|
41 |
$sort_icon = '';
|
42 |
if ( $field['sort_clone'] ) {
|
@@ -45,11 +47,11 @@ class RWMB_Clone {
|
|
45 |
}
|
46 |
$input_html = "<div class='$class'>" . $sort_icon;
|
47 |
|
48 |
-
// Call separated methods for displaying each type of field
|
49 |
$input_html .= RWMB_Field::call( $sub_field, 'html', $sub_meta );
|
50 |
$input_html = RWMB_Field::filter( 'html', $input_html, $sub_field, $sub_meta );
|
51 |
|
52 |
-
// Remove clone button
|
53 |
$input_html .= self::remove_clone_button( $sub_field );
|
54 |
$input_html .= '</div>';
|
55 |
|
@@ -62,10 +64,10 @@ class RWMB_Clone {
|
|
62 |
/**
|
63 |
* Set value of meta before saving into database
|
64 |
*
|
65 |
-
* @param mixed $new
|
66 |
-
* @param mixed $old
|
67 |
-
* @param int $post_id
|
68 |
-
* @param array $field
|
69 |
*
|
70 |
* @return mixed
|
71 |
*/
|
@@ -83,9 +85,9 @@ class RWMB_Clone {
|
|
83 |
}
|
84 |
|
85 |
/**
|
86 |
-
* Add clone button
|
87 |
*
|
88 |
-
* @param array $field Field
|
89 |
* @return string $html
|
90 |
*/
|
91 |
public static function add_clone_button( $field ) {
|
@@ -97,9 +99,9 @@ class RWMB_Clone {
|
|
97 |
}
|
98 |
|
99 |
/**
|
100 |
-
* Remove clone button
|
101 |
*
|
102 |
-
* @param array $field Field
|
103 |
* @return string $html
|
104 |
*/
|
105 |
public static function remove_clone_button( $field ) {
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
+
* The clone module, allowing users to clone (duplicate) fields.
|
4 |
*
|
5 |
* @package Meta Box
|
6 |
*/
|
|
|
7 |
|
8 |
+
/**
|
9 |
+
* The clone class.
|
10 |
+
*/
|
11 |
+
class RWMB_Clone {
|
12 |
/**
|
13 |
+
* Get clone field HTML.
|
14 |
*
|
15 |
+
* @param mixed $meta The meta value.
|
16 |
+
* @param array $field The field parameters.
|
17 |
*
|
18 |
* @return string
|
19 |
*/
|
38 |
$sub_field['field_name'] .= '[]';
|
39 |
}
|
40 |
|
41 |
+
// Wrap field HTML in a div with class="rwmb-clone" if needed.
|
42 |
$class = "rwmb-clone rwmb-{$field['type']}-clone";
|
43 |
$sort_icon = '';
|
44 |
if ( $field['sort_clone'] ) {
|
47 |
}
|
48 |
$input_html = "<div class='$class'>" . $sort_icon;
|
49 |
|
50 |
+
// Call separated methods for displaying each type of field.
|
51 |
$input_html .= RWMB_Field::call( $sub_field, 'html', $sub_meta );
|
52 |
$input_html = RWMB_Field::filter( 'html', $input_html, $sub_field, $sub_meta );
|
53 |
|
54 |
+
// Remove clone button.
|
55 |
$input_html .= self::remove_clone_button( $sub_field );
|
56 |
$input_html .= '</div>';
|
57 |
|
64 |
/**
|
65 |
* Set value of meta before saving into database
|
66 |
*
|
67 |
+
* @param mixed $new The submitted meta value.
|
68 |
+
* @param mixed $old The existing meta value.
|
69 |
+
* @param int $post_id The post ID.
|
70 |
+
* @param array $field The field parameters.
|
71 |
*
|
72 |
* @return mixed
|
73 |
*/
|
85 |
}
|
86 |
|
87 |
/**
|
88 |
+
* Add clone button.
|
89 |
*
|
90 |
+
* @param array $field Field parameters.
|
91 |
* @return string $html
|
92 |
*/
|
93 |
public static function add_clone_button( $field ) {
|
99 |
}
|
100 |
|
101 |
/**
|
102 |
+
* Remove clone button.
|
103 |
*
|
104 |
+
* @param array $field Field parameters.
|
105 |
* @return string $html
|
106 |
*/
|
107 |
public static function remove_clone_button( $field ) {
|
inc/core.php
CHANGED
@@ -13,7 +13,7 @@
|
|
13 |
class RWMB_Core {
|
14 |
|
15 |
/**
|
16 |
-
* Stores all registered meta boxes
|
17 |
*
|
18 |
* @var array
|
19 |
*/
|
@@ -35,7 +35,7 @@ class RWMB_Core {
|
|
35 |
* Add links to Documentation and Extensions in plugin's list of action links.
|
36 |
*
|
37 |
* @since 4.3.11
|
38 |
-
* @param array $links Array of
|
39 |
* @return array
|
40 |
*/
|
41 |
public function plugin_links( $links ) {
|
@@ -98,25 +98,25 @@ class RWMB_Core {
|
|
98 |
}
|
99 |
|
100 |
/**
|
101 |
-
* WordPress will prevent post data saving if a page template has been selected that does not exist
|
102 |
-
* This is especially a problem when switching to our theme, and old page templates are in the post data
|
103 |
-
* Unset the page template if the page does not exist to allow the post to save
|
104 |
*
|
105 |
-
* @param WP_Post $post
|
106 |
* @since 4.3.10
|
107 |
*/
|
108 |
public function fix_page_template( WP_Post $post ) {
|
109 |
$template = get_post_meta( $post->ID, '_wp_page_template', true );
|
110 |
$page_templates = wp_get_theme()->get_page_templates();
|
111 |
|
112 |
-
// If the template doesn't exists, remove the data to allow WordPress to save
|
113 |
if ( ! isset( $page_templates[ $template ] ) ) {
|
114 |
delete_post_meta( $post->ID, '_wp_page_template' );
|
115 |
}
|
116 |
}
|
117 |
|
118 |
/**
|
119 |
-
* Register wpml compatibility hooks
|
120 |
*/
|
121 |
public function register_wpml_hooks() {
|
122 |
if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
|
13 |
class RWMB_Core {
|
14 |
|
15 |
/**
|
16 |
+
* Stores all registered meta boxes.
|
17 |
*
|
18 |
* @var array
|
19 |
*/
|
35 |
* Add links to Documentation and Extensions in plugin's list of action links.
|
36 |
*
|
37 |
* @since 4.3.11
|
38 |
+
* @param array $links Array of plugin links.
|
39 |
* @return array
|
40 |
*/
|
41 |
public function plugin_links( $links ) {
|
98 |
}
|
99 |
|
100 |
/**
|
101 |
+
* WordPress will prevent post data saving if a page template has been selected that does not exist.
|
102 |
+
* This is especially a problem when switching to our theme, and old page templates are in the post data.
|
103 |
+
* Unset the page template if the page does not exist to allow the post to save.
|
104 |
*
|
105 |
+
* @param WP_Post $post Post object.
|
106 |
* @since 4.3.10
|
107 |
*/
|
108 |
public function fix_page_template( WP_Post $post ) {
|
109 |
$template = get_post_meta( $post->ID, '_wp_page_template', true );
|
110 |
$page_templates = wp_get_theme()->get_page_templates();
|
111 |
|
112 |
+
// If the template doesn't exists, remove the data to allow WordPress to save.
|
113 |
if ( ! isset( $page_templates[ $template ] ) ) {
|
114 |
delete_post_meta( $post->ID, '_wp_page_template' );
|
115 |
}
|
116 |
}
|
117 |
|
118 |
/**
|
119 |
+
* Register wpml compatibility hooks.
|
120 |
*/
|
121 |
public function register_wpml_hooks() {
|
122 |
if ( defined( 'ICL_SITEPRESS_VERSION' ) ) {
|
inc/field.php
CHANGED
@@ -1,19 +1,24 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
/**
|
4 |
-
*
|
|
|
5 |
* Fields must inherit this class and overwrite methods with its own.
|
|
|
|
|
6 |
*/
|
7 |
-
abstract class RWMB_Field {
|
8 |
|
|
|
|
|
|
|
|
|
9 |
/**
|
10 |
-
* Add actions
|
11 |
*/
|
12 |
public static function add_actions() {
|
13 |
}
|
14 |
|
15 |
/**
|
16 |
-
* Enqueue scripts and styles
|
17 |
*/
|
18 |
public static function admin_enqueue_scripts() {
|
19 |
}
|
@@ -25,11 +30,11 @@ abstract class RWMB_Field {
|
|
25 |
*
|
26 |
* @param string $handle Script handle.
|
27 |
* @param string $name Object name.
|
28 |
-
* @param mixed
|
29 |
*/
|
30 |
public static function localize_script( $handle, $name, $data ) {
|
31 |
/*
|
32 |
-
* Check with function_exists to make it work in WordPress 4.1
|
33 |
* @link https://github.com/rilwis/meta-box/issues/1009
|
34 |
*/
|
35 |
if ( ! function_exists( 'wp_scripts' ) || ! wp_scripts()->get_data( $handle, 'data' ) ) {
|
@@ -40,11 +45,11 @@ abstract class RWMB_Field {
|
|
40 |
/**
|
41 |
* Show field HTML
|
42 |
* Filters are put inside this method, not inside methods such as "meta", "html", "begin_html", etc.
|
43 |
-
* That ensures the returned value are always been applied filters
|
44 |
-
* This method is not meant to be overwritten in specific fields
|
45 |
*
|
46 |
-
* @param array $field
|
47 |
-
* @param bool $saved
|
48 |
*/
|
49 |
public static function show( $field, $saved ) {
|
50 |
$post = get_post();
|
@@ -56,13 +61,11 @@ abstract class RWMB_Field {
|
|
56 |
$begin = self::call( $field, 'begin_html', $meta );
|
57 |
$begin = self::filter( 'begin_html', $begin, $field, $meta );
|
58 |
|
59 |
-
// Separate code for cloneable and non-cloneable fields to make easy to maintain
|
60 |
-
// Cloneable fields
|
61 |
if ( $field['clone'] ) {
|
62 |
$field_html = RWMB_Clone::html( $meta, $field );
|
63 |
-
}
|
64 |
-
|
65 |
-
// Call separated methods for displaying each type of field
|
66 |
$field_html = self::call( $field, 'html', $meta );
|
67 |
$field_html = self::filter( 'html', $field_html, $field, $meta );
|
68 |
}
|
@@ -72,7 +75,7 @@ abstract class RWMB_Field {
|
|
72 |
|
73 |
$html = self::filter( 'wrapper_html', "$begin$field_html$end", $field, $meta );
|
74 |
|
75 |
-
// Display label and input in DIV and allow user-defined classes to be appended
|
76 |
$classes = "rwmb-field rwmb-{$field['type']}-wrapper " . $field['class'];
|
77 |
if ( 'hidden' === $field['type'] ) {
|
78 |
$classes .= ' hidden';
|
@@ -88,14 +91,14 @@ abstract class RWMB_Field {
|
|
88 |
);
|
89 |
$outer_html = self::filter( 'outer_html', $outer_html, $field, $meta );
|
90 |
|
91 |
-
echo $outer_html;
|
92 |
}
|
93 |
|
94 |
/**
|
95 |
-
* Get field HTML
|
96 |
*
|
97 |
-
* @param mixed $meta
|
98 |
-
* @param array $field
|
99 |
*
|
100 |
* @return string
|
101 |
*/
|
@@ -104,10 +107,10 @@ abstract class RWMB_Field {
|
|
104 |
}
|
105 |
|
106 |
/**
|
107 |
-
* Show begin HTML markup for fields
|
108 |
*
|
109 |
-
* @param mixed $meta
|
110 |
-
* @param array $field
|
111 |
*
|
112 |
* @return string
|
113 |
*/
|
@@ -132,10 +135,10 @@ abstract class RWMB_Field {
|
|
132 |
}
|
133 |
|
134 |
/**
|
135 |
-
* Show end HTML markup for fields
|
136 |
*
|
137 |
-
* @param mixed $meta
|
138 |
-
* @param array $field
|
139 |
*
|
140 |
* @return string
|
141 |
*/
|
@@ -146,7 +149,7 @@ abstract class RWMB_Field {
|
|
146 |
/**
|
147 |
* Display field description.
|
148 |
*
|
149 |
-
* @param array $field
|
150 |
* @return string
|
151 |
*/
|
152 |
protected static function element_description( $field ) {
|
@@ -155,10 +158,10 @@ abstract class RWMB_Field {
|
|
155 |
}
|
156 |
|
157 |
/**
|
158 |
-
* Get raw meta value
|
159 |
*
|
160 |
-
* @param int $post_id
|
161 |
-
* @param array $field
|
162 |
*
|
163 |
* @return mixed
|
164 |
*/
|
@@ -172,38 +175,37 @@ abstract class RWMB_Field {
|
|
172 |
}
|
173 |
|
174 |
/**
|
175 |
-
* Get meta value
|
176 |
*
|
177 |
-
* @param int $post_id
|
178 |
-
* @param bool $saved
|
179 |
-
* @param array $field
|
180 |
*
|
181 |
* @return mixed
|
182 |
*/
|
183 |
public static function meta( $post_id, $saved, $field ) {
|
184 |
/**
|
185 |
* For special fields like 'divider', 'heading' which don't have ID, just return empty string
|
186 |
-
* to prevent notice error when displaying fields
|
187 |
*/
|
188 |
if ( empty( $field['id'] ) ) {
|
189 |
return '';
|
190 |
}
|
191 |
|
192 |
-
// Get raw meta
|
193 |
$meta = self::call( $field, 'raw_meta', $post_id );
|
194 |
|
195 |
-
// Use $field['std'] only when the meta box hasn't been saved (i.e. the first time we run)
|
196 |
$meta = ! $saved ? $field['std'] : $meta;
|
197 |
|
198 |
-
// Escape attributes
|
199 |
$meta = self::call( $field, 'esc_meta', $meta );
|
200 |
|
201 |
-
// Make sure meta value is an array for clonable and multiple fields
|
202 |
if ( $field['clone'] || $field['multiple'] ) {
|
203 |
if ( empty( $meta ) || ! is_array( $meta ) ) {
|
204 |
/**
|
205 |
-
*
|
206 |
-
* so that the foreach loop in self::show() runs properly
|
207 |
*
|
208 |
* @see self::show()
|
209 |
*/
|
@@ -215,9 +217,9 @@ abstract class RWMB_Field {
|
|
215 |
}
|
216 |
|
217 |
/**
|
218 |
-
* Escape meta for field output
|
219 |
*
|
220 |
-
* @param mixed $meta
|
221 |
*
|
222 |
* @return mixed
|
223 |
*/
|
@@ -226,12 +228,12 @@ abstract class RWMB_Field {
|
|
226 |
}
|
227 |
|
228 |
/**
|
229 |
-
* Set value of meta before saving into database
|
230 |
*
|
231 |
-
* @param mixed $new
|
232 |
-
* @param mixed $old
|
233 |
-
* @param int $post_id
|
234 |
-
* @param array $field
|
235 |
*
|
236 |
* @return int
|
237 |
*/
|
@@ -240,38 +242,38 @@ abstract class RWMB_Field {
|
|
240 |
}
|
241 |
|
242 |
/**
|
243 |
-
* Save meta value
|
244 |
*
|
245 |
-
* @param $new
|
246 |
-
* @param $old
|
247 |
-
* @param $post_id
|
248 |
-
* @param $field
|
249 |
*/
|
250 |
public static function save( $new, $old, $post_id, $field ) {
|
251 |
$name = $field['id'];
|
252 |
|
253 |
-
// Remove post meta if it's empty
|
254 |
if ( '' === $new || array() === $new ) {
|
255 |
delete_post_meta( $post_id, $name );
|
256 |
return;
|
257 |
}
|
258 |
|
259 |
-
// If field is cloneable, value is saved as a single entry in the database
|
260 |
if ( $field['clone'] ) {
|
261 |
-
// Remove empty values
|
262 |
$new = (array) $new;
|
263 |
foreach ( $new as $k => $v ) {
|
264 |
if ( '' === $v || array() === $v ) {
|
265 |
unset( $new[ $k ] );
|
266 |
}
|
267 |
}
|
268 |
-
// Reset indexes
|
269 |
$new = array_values( $new );
|
270 |
update_post_meta( $post_id, $name, $new );
|
271 |
return;
|
272 |
}
|
273 |
|
274 |
-
// If field is multiple, value is saved as multiple entries in the database (WordPress behaviour)
|
275 |
if ( $field['multiple'] ) {
|
276 |
$new_values = array_diff( $new, $old );
|
277 |
foreach ( $new_values as $new_value ) {
|
@@ -284,14 +286,14 @@ abstract class RWMB_Field {
|
|
284 |
return;
|
285 |
}
|
286 |
|
287 |
-
// Default: just update post meta
|
288 |
update_post_meta( $post_id, $name, $new );
|
289 |
}
|
290 |
|
291 |
/**
|
292 |
-
* Normalize parameters for field
|
293 |
*
|
294 |
-
* @param array $field
|
295 |
*
|
296 |
* @return array
|
297 |
*/
|
@@ -322,10 +324,10 @@ abstract class RWMB_Field {
|
|
322 |
}
|
323 |
|
324 |
/**
|
325 |
-
* Get the attributes for a field
|
326 |
*
|
327 |
-
* @param array $field
|
328 |
-
* @param mixed $value
|
329 |
*
|
330 |
* @return array
|
331 |
*/
|
@@ -344,9 +346,9 @@ abstract class RWMB_Field {
|
|
344 |
}
|
345 |
|
346 |
/**
|
347 |
-
* Renders an attribute array into an html attributes string
|
348 |
*
|
349 |
-
* @param array $attributes
|
350 |
*
|
351 |
* @return string
|
352 |
*/
|
@@ -359,7 +361,7 @@ abstract class RWMB_Field {
|
|
359 |
}
|
360 |
|
361 |
if ( is_array( $value ) ) {
|
362 |
-
$value =
|
363 |
}
|
364 |
|
365 |
$output .= sprintf( true === $value ? ' %s' : ' %s="%s"', $key, esc_attr( $value ) );
|
@@ -369,16 +371,16 @@ abstract class RWMB_Field {
|
|
369 |
}
|
370 |
|
371 |
/**
|
372 |
-
* Get the field value
|
373 |
* The difference between this function and 'meta' function is 'meta' function always returns the escaped value
|
374 |
* of the field saved in the database, while this function returns more meaningful value of the field, for ex.:
|
375 |
-
* for file/image: return array of file/image information instead of file/image IDs
|
376 |
*
|
377 |
* Each field can extend this function and add more data to the returned value.
|
378 |
* See specific field classes for details.
|
379 |
*
|
380 |
-
* @param array $field Field parameters
|
381 |
-
* @param array $args Additional arguments. Rarely used. See specific fields for details
|
382 |
* @param int|null $post_id Post ID. null for current post. Optional.
|
383 |
*
|
384 |
* @return mixed Field value
|
@@ -393,10 +395,10 @@ abstract class RWMB_Field {
|
|
393 |
$post_id = get_the_ID();
|
394 |
}
|
395 |
|
396 |
-
// Get raw meta value in the database, no escape
|
397 |
$value = self::call( $field, 'raw_meta', $post_id );
|
398 |
|
399 |
-
// Make sure meta value is an array for cloneable and multiple fields
|
400 |
if ( $field['clone'] || $field['multiple'] ) {
|
401 |
$value = is_array( $value ) && $value ? $value : array();
|
402 |
}
|
@@ -405,7 +407,7 @@ abstract class RWMB_Field {
|
|
405 |
}
|
406 |
|
407 |
/**
|
408 |
-
* Output the field value
|
409 |
* Depends on field value and field types, each field can extend this method to output its value in its own way
|
410 |
* See specific field classes for details.
|
411 |
*
|
@@ -415,8 +417,8 @@ abstract class RWMB_Field {
|
|
415 |
* @use self::get_value()
|
416 |
* @see rwmb_the_value()
|
417 |
*
|
418 |
-
* @param array $field Field parameters
|
419 |
-
* @param array $args Additional arguments. Rarely used. See specific fields for details
|
420 |
* @param int|null $post_id Post ID. null for current post. Optional.
|
421 |
*
|
422 |
* @return string HTML output of the field
|
@@ -429,8 +431,8 @@ abstract class RWMB_Field {
|
|
429 |
/**
|
430 |
* Format value for the helper functions.
|
431 |
*
|
432 |
-
* @param array $field Field
|
433 |
-
* @param string|array $value The field meta value
|
434 |
* @return string
|
435 |
*/
|
436 |
public static function format_value( $field, $value ) {
|
@@ -448,8 +450,8 @@ abstract class RWMB_Field {
|
|
448 |
/**
|
449 |
* Format a single value for the helper functions. Sub-fields should overwrite this method if necessary.
|
450 |
*
|
451 |
-
* @param array $field Field
|
452 |
-
* @param string $value The value
|
453 |
* @return string
|
454 |
*/
|
455 |
public static function format_single_value( $field, $value ) {
|
@@ -470,22 +472,21 @@ abstract class RWMB_Field {
|
|
470 |
// Params: method name, field, other params.
|
471 |
if ( is_string( $check ) ) {
|
472 |
$method = array_shift( $args );
|
473 |
-
$field = reset( $args ); // Keep field as 1st param
|
474 |
-
}
|
475 |
-
else {
|
476 |
$field = array_shift( $args );
|
477 |
$method = array_shift( $args );
|
478 |
-
$args[] = $field; // Add field as last param
|
479 |
}
|
480 |
|
481 |
return call_user_func_array( array( self::get_class_name( $field ), $method ), $args );
|
482 |
}
|
483 |
|
484 |
/**
|
485 |
-
* Map types
|
486 |
*
|
487 |
-
* @param array $field Field
|
488 |
-
* @return string Field mapped type
|
489 |
*/
|
490 |
public static function map_types( $field ) {
|
491 |
$type = isset( $field['type'] ) ? $field['type'] : 'input';
|
@@ -494,7 +495,7 @@ abstract class RWMB_Field {
|
|
494 |
array(
|
495 |
'file_advanced' => 'media',
|
496 |
'plupload_image' => 'image_upload',
|
497 |
-
'url' => 'text'
|
498 |
)
|
499 |
);
|
500 |
|
@@ -502,10 +503,10 @@ abstract class RWMB_Field {
|
|
502 |
}
|
503 |
|
504 |
/**
|
505 |
-
* Get field class name
|
506 |
*
|
507 |
-
* @param array $field Field
|
508 |
-
* @return string Field class name
|
509 |
*/
|
510 |
public static function get_class_name( $field ) {
|
511 |
$type = self::map_types( $field );
|
@@ -532,7 +533,7 @@ abstract class RWMB_Field {
|
|
532 |
$value = array_shift( $args );
|
533 |
$field = array_shift( $args );
|
534 |
|
535 |
-
// List of filters
|
536 |
$filters = array(
|
537 |
'rwmb_' . $name,
|
538 |
'rwmb_' . $field['type'] . '_' . $name,
|
1 |
<?php
|
|
|
2 |
/**
|
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 |
}
|
30 |
*
|
31 |
* @param string $handle Script handle.
|
32 |
* @param string $name Object name.
|
33 |
+
* @param mixed $data Localized data.
|
34 |
*/
|
35 |
public static function localize_script( $handle, $name, $data ) {
|
36 |
/*
|
37 |
+
* Check with function_exists to make it work in WordPress 4.1.
|
38 |
* @link https://github.com/rilwis/meta-box/issues/1009
|
39 |
*/
|
40 |
if ( ! function_exists( 'wp_scripts' ) || ! wp_scripts()->get_data( $handle, 'data' ) ) {
|
45 |
/**
|
46 |
* Show field HTML
|
47 |
* Filters are put inside this method, not inside methods such as "meta", "html", "begin_html", etc.
|
48 |
+
* That ensures the returned value are always been applied filters.
|
49 |
+
* This method is not meant to be overwritten in specific fields.
|
50 |
*
|
51 |
+
* @param array $field Field parameters.
|
52 |
+
* @param bool $saved Whether the meta box is saved at least once.
|
53 |
*/
|
54 |
public static function show( $field, $saved ) {
|
55 |
$post = get_post();
|
61 |
$begin = self::call( $field, 'begin_html', $meta );
|
62 |
$begin = self::filter( 'begin_html', $begin, $field, $meta );
|
63 |
|
64 |
+
// Separate code for cloneable and non-cloneable fields to make easy to maintain.
|
|
|
65 |
if ( $field['clone'] ) {
|
66 |
$field_html = RWMB_Clone::html( $meta, $field );
|
67 |
+
} else {
|
68 |
+
// Call separated methods for displaying each type of field.
|
|
|
69 |
$field_html = self::call( $field, 'html', $meta );
|
70 |
$field_html = self::filter( 'html', $field_html, $field, $meta );
|
71 |
}
|
75 |
|
76 |
$html = self::filter( 'wrapper_html', "$begin$field_html$end", $field, $meta );
|
77 |
|
78 |
+
// Display label and input in DIV and allow user-defined classes to be appended.
|
79 |
$classes = "rwmb-field rwmb-{$field['type']}-wrapper " . $field['class'];
|
80 |
if ( 'hidden' === $field['type'] ) {
|
81 |
$classes .= ' hidden';
|
91 |
);
|
92 |
$outer_html = self::filter( 'outer_html', $outer_html, $field, $meta );
|
93 |
|
94 |
+
echo $outer_html; // WPCS: XSS OK.
|
95 |
}
|
96 |
|
97 |
/**
|
98 |
+
* Get field HTML.
|
99 |
*
|
100 |
+
* @param mixed $meta Meta value.
|
101 |
+
* @param array $field Field parameters.
|
102 |
*
|
103 |
* @return string
|
104 |
*/
|
107 |
}
|
108 |
|
109 |
/**
|
110 |
+
* Show begin HTML markup for fields.
|
111 |
*
|
112 |
+
* @param mixed $meta Meta value.
|
113 |
+
* @param array $field Field parameters.
|
114 |
*
|
115 |
* @return string
|
116 |
*/
|
135 |
}
|
136 |
|
137 |
/**
|
138 |
+
* Show end HTML markup for fields.
|
139 |
*
|
140 |
+
* @param mixed $meta Meta value.
|
141 |
+
* @param array $field Field parameters.
|
142 |
*
|
143 |
* @return string
|
144 |
*/
|
149 |
/**
|
150 |
* Display field description.
|
151 |
*
|
152 |
+
* @param array $field Field parameters.
|
153 |
* @return string
|
154 |
*/
|
155 |
protected static function element_description( $field ) {
|
158 |
}
|
159 |
|
160 |
/**
|
161 |
+
* Get raw meta value.
|
162 |
*
|
163 |
+
* @param int $post_id Post ID.
|
164 |
+
* @param array $field Field parameters.
|
165 |
*
|
166 |
* @return mixed
|
167 |
*/
|
175 |
}
|
176 |
|
177 |
/**
|
178 |
+
* Get meta value.
|
179 |
*
|
180 |
+
* @param int $post_id Post ID.
|
181 |
+
* @param bool $saved Whether the meta box is saved at least once.
|
182 |
+
* @param array $field Field parameters.
|
183 |
*
|
184 |
* @return mixed
|
185 |
*/
|
186 |
public static function meta( $post_id, $saved, $field ) {
|
187 |
/**
|
188 |
* For special fields like 'divider', 'heading' which don't have ID, just return empty string
|
189 |
+
* to prevent notice error when displaying fields.
|
190 |
*/
|
191 |
if ( empty( $field['id'] ) ) {
|
192 |
return '';
|
193 |
}
|
194 |
|
195 |
+
// Get raw meta.
|
196 |
$meta = self::call( $field, 'raw_meta', $post_id );
|
197 |
|
198 |
+
// Use $field['std'] only when the meta box hasn't been saved (i.e. the first time we run).
|
199 |
$meta = ! $saved ? $field['std'] : $meta;
|
200 |
|
201 |
+
// Escape attributes.
|
202 |
$meta = self::call( $field, 'esc_meta', $meta );
|
203 |
|
204 |
+
// Make sure meta value is an array for clonable and multiple fields.
|
205 |
if ( $field['clone'] || $field['multiple'] ) {
|
206 |
if ( empty( $meta ) || ! is_array( $meta ) ) {
|
207 |
/**
|
208 |
+
* If field is clonable, $meta must be an array with values so that the foreach loop in self::show() runs properly.
|
|
|
209 |
*
|
210 |
* @see self::show()
|
211 |
*/
|
217 |
}
|
218 |
|
219 |
/**
|
220 |
+
* Escape meta for field output.
|
221 |
*
|
222 |
+
* @param mixed $meta Meta value.
|
223 |
*
|
224 |
* @return mixed
|
225 |
*/
|
228 |
}
|
229 |
|
230 |
/**
|
231 |
+
* Set value of meta before saving into database.
|
232 |
*
|
233 |
+
* @param mixed $new The submitted meta value.
|
234 |
+
* @param mixed $old The existing meta value.
|
235 |
+
* @param int $post_id The post ID.
|
236 |
+
* @param array $field The field parameters.
|
237 |
*
|
238 |
* @return int
|
239 |
*/
|
242 |
}
|
243 |
|
244 |
/**
|
245 |
+
* Save meta value.
|
246 |
*
|
247 |
+
* @param mixed $new The submitted meta value.
|
248 |
+
* @param mixed $old The existing meta value.
|
249 |
+
* @param int $post_id The post ID.
|
250 |
+
* @param array $field The field parameters.
|
251 |
*/
|
252 |
public static function save( $new, $old, $post_id, $field ) {
|
253 |
$name = $field['id'];
|
254 |
|
255 |
+
// Remove post meta if it's empty.
|
256 |
if ( '' === $new || array() === $new ) {
|
257 |
delete_post_meta( $post_id, $name );
|
258 |
return;
|
259 |
}
|
260 |
|
261 |
+
// If field is cloneable, value is saved as a single entry in the database.
|
262 |
if ( $field['clone'] ) {
|
263 |
+
// Remove empty values.
|
264 |
$new = (array) $new;
|
265 |
foreach ( $new as $k => $v ) {
|
266 |
if ( '' === $v || array() === $v ) {
|
267 |
unset( $new[ $k ] );
|
268 |
}
|
269 |
}
|
270 |
+
// Reset indexes.
|
271 |
$new = array_values( $new );
|
272 |
update_post_meta( $post_id, $name, $new );
|
273 |
return;
|
274 |
}
|
275 |
|
276 |
+
// If field is multiple, value is saved as multiple entries in the database (WordPress behaviour).
|
277 |
if ( $field['multiple'] ) {
|
278 |
$new_values = array_diff( $new, $old );
|
279 |
foreach ( $new_values as $new_value ) {
|
286 |
return;
|
287 |
}
|
288 |
|
289 |
+
// Default: just update post meta.
|
290 |
update_post_meta( $post_id, $name, $new );
|
291 |
}
|
292 |
|
293 |
/**
|
294 |
+
* Normalize parameters for field.
|
295 |
*
|
296 |
+
* @param array $field Field parameters.
|
297 |
*
|
298 |
* @return array
|
299 |
*/
|
324 |
}
|
325 |
|
326 |
/**
|
327 |
+
* Get the attributes for a field.
|
328 |
*
|
329 |
+
* @param array $field Field parameters.
|
330 |
+
* @param mixed $value Meta value.
|
331 |
*
|
332 |
* @return array
|
333 |
*/
|
346 |
}
|
347 |
|
348 |
/**
|
349 |
+
* Renders an attribute array into an html attributes string.
|
350 |
*
|
351 |
+
* @param array $attributes HTML attributes.
|
352 |
*
|
353 |
* @return string
|
354 |
*/
|
361 |
}
|
362 |
|
363 |
if ( is_array( $value ) ) {
|
364 |
+
$value = wp_json_encode( $value );
|
365 |
}
|
366 |
|
367 |
$output .= sprintf( true === $value ? ' %s' : ' %s="%s"', $key, esc_attr( $value ) );
|
371 |
}
|
372 |
|
373 |
/**
|
374 |
+
* Get the field value.
|
375 |
* The difference between this function and 'meta' function is 'meta' function always returns the escaped value
|
376 |
* of the field saved in the database, while this function returns more meaningful value of the field, for ex.:
|
377 |
+
* for file/image: return array of file/image information instead of file/image IDs.
|
378 |
*
|
379 |
* Each field can extend this function and add more data to the returned value.
|
380 |
* See specific field classes for details.
|
381 |
*
|
382 |
+
* @param array $field Field parameters.
|
383 |
+
* @param array $args Additional arguments. Rarely used. See specific fields for details.
|
384 |
* @param int|null $post_id Post ID. null for current post. Optional.
|
385 |
*
|
386 |
* @return mixed Field value
|
395 |
$post_id = get_the_ID();
|
396 |
}
|
397 |
|
398 |
+
// Get raw meta value in the database, no escape.
|
399 |
$value = self::call( $field, 'raw_meta', $post_id );
|
400 |
|
401 |
+
// Make sure meta value is an array for cloneable and multiple fields.
|
402 |
if ( $field['clone'] || $field['multiple'] ) {
|
403 |
$value = is_array( $value ) && $value ? $value : array();
|
404 |
}
|
407 |
}
|
408 |
|
409 |
/**
|
410 |
+
* Output the field value.
|
411 |
* Depends on field value and field types, each field can extend this method to output its value in its own way
|
412 |
* See specific field classes for details.
|
413 |
*
|
417 |
* @use self::get_value()
|
418 |
* @see rwmb_the_value()
|
419 |
*
|
420 |
+
* @param array $field Field parameters.
|
421 |
+
* @param array $args Additional arguments. Rarely used. See specific fields for details.
|
422 |
* @param int|null $post_id Post ID. null for current post. Optional.
|
423 |
*
|
424 |
* @return string HTML output of the field
|
431 |
/**
|
432 |
* Format value for the helper functions.
|
433 |
*
|
434 |
+
* @param array $field Field parameters.
|
435 |
+
* @param string|array $value The field meta value.
|
436 |
* @return string
|
437 |
*/
|
438 |
public static function format_value( $field, $value ) {
|
450 |
/**
|
451 |
* Format a single value for the helper functions. Sub-fields should overwrite this method if necessary.
|
452 |
*
|
453 |
+
* @param array $field Field parameters.
|
454 |
+
* @param string $value The value.
|
455 |
* @return string
|
456 |
*/
|
457 |
public static function format_single_value( $field, $value ) {
|
472 |
// Params: method name, field, other params.
|
473 |
if ( is_string( $check ) ) {
|
474 |
$method = array_shift( $args );
|
475 |
+
$field = reset( $args ); // Keep field as 1st param.
|
476 |
+
} else {
|
|
|
477 |
$field = array_shift( $args );
|
478 |
$method = array_shift( $args );
|
479 |
+
$args[] = $field; // Add field as last param.
|
480 |
}
|
481 |
|
482 |
return call_user_func_array( array( self::get_class_name( $field ), $method ), $args );
|
483 |
}
|
484 |
|
485 |
/**
|
486 |
+
* Map field types.
|
487 |
*
|
488 |
+
* @param array $field Field parameters.
|
489 |
+
* @return string Field mapped type.
|
490 |
*/
|
491 |
public static function map_types( $field ) {
|
492 |
$type = isset( $field['type'] ) ? $field['type'] : 'input';
|
495 |
array(
|
496 |
'file_advanced' => 'media',
|
497 |
'plupload_image' => 'image_upload',
|
498 |
+
'url' => 'text',
|
499 |
)
|
500 |
);
|
501 |
|
503 |
}
|
504 |
|
505 |
/**
|
506 |
+
* Get field class name.
|
507 |
*
|
508 |
+
* @param array $field Field parameters.
|
509 |
+
* @return string Field class name.
|
510 |
*/
|
511 |
public static function get_class_name( $field ) {
|
512 |
$type = self::map_types( $field );
|
533 |
$value = array_shift( $args );
|
534 |
$field = array_shift( $args );
|
535 |
|
536 |
+
// List of filters.
|
537 |
$filters = array(
|
538 |
'rwmb_' . $name,
|
539 |
'rwmb_' . $field['type'] . '_' . $name,
|
inc/fields/autocomplete.php
CHANGED
@@ -1,29 +1,34 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
* Autocomplete field class.
|
5 |
*/
|
6 |
class RWMB_Autocomplete_Field extends RWMB_Multiple_Values_Field {
|
7 |
-
|
8 |
/**
|
9 |
* Enqueue scripts and styles.
|
10 |
*/
|
11 |
-
static function admin_enqueue_scripts() {
|
12 |
wp_enqueue_style( 'rwmb-autocomplete', RWMB_CSS_URL . 'autocomplete.css', array( 'wp-admin' ), RWMB_VER );
|
13 |
wp_enqueue_script( 'rwmb-autocomplete', RWMB_JS_URL . 'autocomplete.js', array( 'jquery-ui-autocomplete' ), RWMB_VER, true );
|
14 |
|
15 |
-
self::localize_script( 'rwmb-autocomplete', 'RWMB_Autocomplete', array(
|
16 |
-
|
|
|
17 |
}
|
18 |
|
19 |
/**
|
20 |
-
* Get field HTML
|
21 |
*
|
22 |
-
* @param mixed $meta
|
23 |
-
* @param array $field
|
24 |
* @return string
|
25 |
*/
|
26 |
-
static function html( $meta, $field ) {
|
27 |
if ( ! is_array( $meta ) ) {
|
28 |
$meta = array( $meta );
|
29 |
}
|
@@ -55,8 +60,8 @@ class RWMB_Autocomplete_Field extends RWMB_Multiple_Values_Field {
|
|
55 |
|
56 |
$html .= '<div class="rwmb-autocomplete-results">';
|
57 |
|
58 |
-
// Each value is displayed with label and 'Delete' option
|
59 |
-
// The hidden input has to have ".rwmb-*" class to make clone work
|
60 |
$tpl = '
|
61 |
<div class="rwmb-autocomplete-result">
|
62 |
<div class="label">%s</div>
|
@@ -93,18 +98,18 @@ class RWMB_Autocomplete_Field extends RWMB_Multiple_Values_Field {
|
|
93 |
}
|
94 |
}
|
95 |
|
96 |
-
$html .= '</div>'; // .rwmb-autocomplete-results
|
97 |
|
98 |
return $html;
|
99 |
}
|
100 |
|
101 |
/**
|
102 |
-
* Normalize parameters for field
|
103 |
*
|
104 |
-
* @param array $field
|
105 |
* @return array
|
106 |
*/
|
107 |
-
static function normalize( $field ) {
|
108 |
$field = parent::normalize( $field );
|
109 |
$field = wp_parse_args( $field, array(
|
110 |
'size' => 30,
|
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', array( 'wp-admin' ), RWMB_VER );
|
17 |
wp_enqueue_script( 'rwmb-autocomplete', RWMB_JS_URL . 'autocomplete.js', array( 'jquery-ui-autocomplete' ), RWMB_VER, true );
|
18 |
|
19 |
+
self::localize_script( 'rwmb-autocomplete', 'RWMB_Autocomplete', array(
|
20 |
+
'delete' => __( 'Delete', 'meta-box' ),
|
21 |
+
) );
|
22 |
}
|
23 |
|
24 |
/**
|
25 |
+
* Get field HTML.
|
26 |
*
|
27 |
+
* @param mixed $meta Meta value.
|
28 |
+
* @param array $field Field parameters.
|
29 |
* @return string
|
30 |
*/
|
31 |
+
public static function html( $meta, $field ) {
|
32 |
if ( ! is_array( $meta ) ) {
|
33 |
$meta = array( $meta );
|
34 |
}
|
60 |
|
61 |
$html .= '<div class="rwmb-autocomplete-results">';
|
62 |
|
63 |
+
// Each value is displayed with label and 'Delete' option.
|
64 |
+
// The hidden input has to have ".rwmb-*" class to make clone work.
|
65 |
$tpl = '
|
66 |
<div class="rwmb-autocomplete-result">
|
67 |
<div class="label">%s</div>
|
98 |
}
|
99 |
}
|
100 |
|
101 |
+
$html .= '</div>'; // .rwmb-autocomplete-results.
|
102 |
|
103 |
return $html;
|
104 |
}
|
105 |
|
106 |
/**
|
107 |
+
* Normalize parameters for field.
|
108 |
*
|
109 |
+
* @param array $field Field parameters.
|
110 |
* @return array
|
111 |
*/
|
112 |
+
public static function normalize( $field ) {
|
113 |
$field = parent::normalize( $field );
|
114 |
$field = wp_parse_args( $field, array(
|
115 |
'size' => 30,
|
inc/fields/button.php
CHANGED
@@ -1,41 +1,46 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Button field class.
|
4 |
*/
|
5 |
class RWMB_Button_Field extends RWMB_Field {
|
6 |
-
|
7 |
/**
|
8 |
-
* Get field HTML
|
9 |
*
|
10 |
-
* @param mixed $meta
|
11 |
-
* @param array $field
|
12 |
* @return string
|
13 |
*/
|
14 |
-
static function html( $meta, $field ) {
|
15 |
$attributes = self::get_attributes( $field );
|
16 |
return sprintf( '<a href="#" %s>%s</a>', self::render_attributes( $attributes ), $field['std'] );
|
17 |
}
|
18 |
|
19 |
/**
|
20 |
-
* Normalize parameters for field
|
21 |
*
|
22 |
-
* @param array $field
|
23 |
* @return array
|
24 |
*/
|
25 |
-
static function normalize( $field ) {
|
26 |
$field = parent::normalize( $field );
|
27 |
$field['std'] = $field['std'] ? $field['std'] : __( 'Click me', 'meta-box' );
|
28 |
return $field;
|
29 |
}
|
30 |
|
31 |
/**
|
32 |
-
* Get the attributes for a field
|
33 |
*
|
34 |
-
* @param array $field
|
35 |
-
* @param mixed $value
|
36 |
* @return array
|
37 |
*/
|
38 |
-
static function get_attributes( $field, $value = null ) {
|
39 |
$attributes = parent::get_attributes( $field, $value );
|
40 |
$attributes['class'] .= ' button hide-if-no-js';
|
41 |
|
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 |
/**
|
13 |
+
* Get field HTML.
|
14 |
*
|
15 |
+
* @param mixed $meta Meta value.
|
16 |
+
* @param array $field The field parameters.
|
17 |
* @return string
|
18 |
*/
|
19 |
+
public static function html( $meta, $field ) {
|
20 |
$attributes = self::get_attributes( $field );
|
21 |
return sprintf( '<a href="#" %s>%s</a>', self::render_attributes( $attributes ), $field['std'] );
|
22 |
}
|
23 |
|
24 |
/**
|
25 |
+
* Normalize parameters for field.
|
26 |
*
|
27 |
+
* @param array $field The field parameters.
|
28 |
* @return array
|
29 |
*/
|
30 |
+
public static function normalize( $field ) {
|
31 |
$field = parent::normalize( $field );
|
32 |
$field['std'] = $field['std'] ? $field['std'] : __( 'Click me', 'meta-box' );
|
33 |
return $field;
|
34 |
}
|
35 |
|
36 |
/**
|
37 |
+
* Get the attributes for a field.
|
38 |
*
|
39 |
+
* @param array $field The field parameters.
|
40 |
+
* @param mixed $value The attribute value.
|
41 |
* @return array
|
42 |
*/
|
43 |
+
public static function get_attributes( $field, $value = null ) {
|
44 |
$attributes = parent::get_attributes( $field, $value );
|
45 |
$attributes['class'] .= ' button hide-if-no-js';
|
46 |
|
inc/fields/checkbox-list.php
CHANGED
@@ -1,16 +1,21 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Checkbox list field class.
|
4 |
*/
|
5 |
class RWMB_Checkbox_List_Field extends RWMB_Input_List_Field {
|
6 |
-
|
7 |
/**
|
8 |
-
* Normalize parameters for field
|
9 |
*
|
10 |
-
* @param array $field
|
11 |
* @return array
|
12 |
*/
|
13 |
-
static function normalize( $field ) {
|
14 |
$field['multiple'] = true;
|
15 |
$field = parent::normalize( $field );
|
16 |
|
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 |
/**
|
13 |
+
* Normalize parameters for field.
|
14 |
*
|
15 |
+
* @param array $field Field parameters.
|
16 |
* @return array
|
17 |
*/
|
18 |
+
public static function normalize( $field ) {
|
19 |
$field['multiple'] = true;
|
20 |
$field = parent::normalize( $field );
|
21 |
|
inc/fields/checkbox.php
CHANGED
@@ -1,10 +1,14 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
* Checkbox field class.
|
5 |
*/
|
6 |
class RWMB_Checkbox_Field extends RWMB_Input_Field {
|
7 |
-
|
8 |
/**
|
9 |
* Enqueue scripts and styles.
|
10 |
*/
|
@@ -13,10 +17,10 @@ class RWMB_Checkbox_Field extends RWMB_Input_Field {
|
|
13 |
}
|
14 |
|
15 |
/**
|
16 |
-
* Get field HTML
|
17 |
*
|
18 |
-
* @param mixed $meta
|
19 |
-
* @param array $field
|
20 |
* @return string
|
21 |
*/
|
22 |
public static function html( $meta, $field ) {
|
@@ -35,7 +39,7 @@ class RWMB_Checkbox_Field extends RWMB_Input_Field {
|
|
35 |
/**
|
36 |
* Do not show field description.
|
37 |
*
|
38 |
-
* @param array $field
|
39 |
* @return string
|
40 |
*/
|
41 |
public static function element_description( $field ) {
|
@@ -45,8 +49,8 @@ class RWMB_Checkbox_Field extends RWMB_Input_Field {
|
|
45 |
/**
|
46 |
* Format a single value for the helper functions.
|
47 |
*
|
48 |
-
* @param array $field Field
|
49 |
-
* @param string $value The value
|
50 |
* @return string
|
51 |
*/
|
52 |
public static function format_single_value( $field, $value ) {
|
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 |
/**
|
13 |
* Enqueue scripts and styles.
|
14 |
*/
|
17 |
}
|
18 |
|
19 |
/**
|
20 |
+
* Get field HTML.
|
21 |
*
|
22 |
+
* @param mixed $meta Meta value.
|
23 |
+
* @param array $field Field parameters.
|
24 |
* @return string
|
25 |
*/
|
26 |
public static function html( $meta, $field ) {
|
39 |
/**
|
40 |
* Do not show field description.
|
41 |
*
|
42 |
+
* @param array $field Field parameters.
|
43 |
* @return string
|
44 |
*/
|
45 |
public static function element_description( $field ) {
|
49 |
/**
|
50 |
* Format a single value for the helper functions.
|
51 |
*
|
52 |
+
* @param array $field Field parameters.
|
53 |
+
* @param string $value The value.
|
54 |
* @return string
|
55 |
*/
|
56 |
public static function format_single_value( $field, $value ) {
|
inc/fields/choice.php
CHANGED
@@ -1,17 +1,21 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
* Abstract class for any kind of choice field.
|
5 |
*/
|
6 |
abstract class RWMB_Choice_Field extends RWMB_Field {
|
7 |
-
|
8 |
/**
|
9 |
-
* Walk options
|
10 |
*
|
11 |
-
* @param
|
12 |
-
* @param
|
13 |
-
* @param mixed $
|
14 |
-
* @param mixed $
|
15 |
* @return string
|
16 |
*/
|
17 |
public static function walk( $field, $options, $db_fields, $meta ) {
|
@@ -19,10 +23,10 @@ abstract class RWMB_Choice_Field extends RWMB_Field {
|
|
19 |
}
|
20 |
|
21 |
/**
|
22 |
-
* Get field HTML
|
23 |
*
|
24 |
-
* @param mixed $meta
|
25 |
-
* @param array $field
|
26 |
* @return string
|
27 |
*/
|
28 |
public static function html( $meta, $field ) {
|
@@ -34,9 +38,9 @@ abstract class RWMB_Choice_Field extends RWMB_Field {
|
|
34 |
}
|
35 |
|
36 |
/**
|
37 |
-
* Normalize parameters for field
|
38 |
*
|
39 |
-
* @param array $field
|
40 |
* @return array
|
41 |
*/
|
42 |
public static function normalize( $field ) {
|
@@ -50,7 +54,7 @@ abstract class RWMB_Choice_Field extends RWMB_Field {
|
|
50 |
}
|
51 |
|
52 |
/**
|
53 |
-
* Get field names of object to be used by walker
|
54 |
*
|
55 |
* @return array
|
56 |
*/
|
@@ -63,16 +67,19 @@ abstract class RWMB_Choice_Field extends RWMB_Field {
|
|
63 |
}
|
64 |
|
65 |
/**
|
66 |
-
* Get options for walker
|
67 |
*
|
68 |
-
* @param array $field
|
69 |
*
|
70 |
* @return array
|
71 |
*/
|
72 |
public static function get_options( $field ) {
|
73 |
$options = array();
|
74 |
foreach ( (array) $field['options'] as $value => $label ) {
|
75 |
-
$option = is_array( $label ) ? $label : array(
|
|
|
|
|
|
|
76 |
if ( isset( $option['label'] ) && isset( $option['value'] ) ) {
|
77 |
$options[ $option['value'] ] = (object) $option;
|
78 |
}
|
@@ -81,9 +88,10 @@ abstract class RWMB_Choice_Field extends RWMB_Field {
|
|
81 |
}
|
82 |
|
83 |
/**
|
84 |
-
* Filter options for walker
|
85 |
*
|
86 |
-
* @param array $field
|
|
|
87 |
*
|
88 |
* @return array
|
89 |
*/
|
@@ -100,8 +108,8 @@ abstract class RWMB_Choice_Field extends RWMB_Field {
|
|
100 |
/**
|
101 |
* Format a single value for the helper functions.
|
102 |
*
|
103 |
-
* @param array $field Field
|
104 |
-
* @param string $value
|
105 |
* @return string
|
106 |
*/
|
107 |
public static function format_single_value( $field, $value ) {
|
@@ -109,10 +117,10 @@ abstract class RWMB_Choice_Field extends RWMB_Field {
|
|
109 |
}
|
110 |
|
111 |
/**
|
112 |
-
* Get option label
|
113 |
*
|
114 |
-
* @param
|
115 |
-
* @param
|
116 |
*
|
117 |
* @return string
|
118 |
*/
|
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 |
/**
|
13 |
+
* Walk options.
|
14 |
*
|
15 |
+
* @param array $field Field parameters.
|
16 |
+
* @param mixed $options Select options.
|
17 |
+
* @param mixed $db_fields Database fields to use in the output.
|
18 |
+
* @param mixed $meta Meta value.
|
19 |
* @return string
|
20 |
*/
|
21 |
public static function walk( $field, $options, $db_fields, $meta ) {
|
23 |
}
|
24 |
|
25 |
/**
|
26 |
+
* Get field HTML.
|
27 |
*
|
28 |
+
* @param mixed $meta Meta value.
|
29 |
+
* @param array $field Field parameters.
|
30 |
* @return string
|
31 |
*/
|
32 |
public static function html( $meta, $field ) {
|
38 |
}
|
39 |
|
40 |
/**
|
41 |
+
* Normalize parameters for field.
|
42 |
*
|
43 |
+
* @param array $field Field parameters.
|
44 |
* @return array
|
45 |
*/
|
46 |
public static function normalize( $field ) {
|
54 |
}
|
55 |
|
56 |
/**
|
57 |
+
* Get field names of object to be used by walker.
|
58 |
*
|
59 |
* @return array
|
60 |
*/
|
67 |
}
|
68 |
|
69 |
/**
|
70 |
+
* Get options for walker.
|
71 |
*
|
72 |
+
* @param array $field Field parameters.
|
73 |
*
|
74 |
* @return array
|
75 |
*/
|
76 |
public static function get_options( $field ) {
|
77 |
$options = array();
|
78 |
foreach ( (array) $field['options'] as $value => $label ) {
|
79 |
+
$option = is_array( $label ) ? $label : array(
|
80 |
+
'label' => (string) $label,
|
81 |
+
'value' => (string) $value,
|
82 |
+
);
|
83 |
if ( isset( $option['label'] ) && isset( $option['value'] ) ) {
|
84 |
$options[ $option['value'] ] = (object) $option;
|
85 |
}
|
88 |
}
|
89 |
|
90 |
/**
|
91 |
+
* Filter options for walker.
|
92 |
*
|
93 |
+
* @param array $field Field parameters.
|
94 |
+
* @param array $options Array of choice options.
|
95 |
*
|
96 |
* @return array
|
97 |
*/
|
108 |
/**
|
109 |
* Format a single value for the helper functions.
|
110 |
*
|
111 |
+
* @param array $field Field parameters.
|
112 |
+
* @param string $value Meta value.
|
113 |
* @return string
|
114 |
*/
|
115 |
public static function format_single_value( $field, $value ) {
|
117 |
}
|
118 |
|
119 |
/**
|
120 |
+
* Get option label.
|
121 |
*
|
122 |
+
* @param array $field Field parameters.
|
123 |
+
* @param string $value Option value.
|
124 |
*
|
125 |
* @return string
|
126 |
*/
|
inc/fields/color.php
CHANGED
@@ -1,14 +1,18 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
* Color field class.
|
5 |
*/
|
6 |
class RWMB_Color_Field extends RWMB_Text_Field {
|
7 |
-
|
8 |
/**
|
9 |
-
* Enqueue scripts and styles
|
10 |
*/
|
11 |
-
static function admin_enqueue_scripts() {
|
12 |
wp_enqueue_style( 'rwmb-color', RWMB_CSS_URL . 'color.css', array( 'wp-color-picker' ), RWMB_VER );
|
13 |
wp_enqueue_script( 'rwmb-color', RWMB_JS_URL . 'color.js', array( 'wp-color-picker' ), RWMB_VER, true );
|
14 |
}
|
@@ -16,10 +20,10 @@ class RWMB_Color_Field extends RWMB_Text_Field {
|
|
16 |
/**
|
17 |
* Normalize parameters for field.
|
18 |
*
|
19 |
-
* @param array $field
|
20 |
* @return array
|
21 |
*/
|
22 |
-
static function normalize( $field ) {
|
23 |
$field = wp_parse_args( $field, array(
|
24 |
'size' => 7,
|
25 |
'maxlength' => 7,
|
@@ -39,13 +43,13 @@ class RWMB_Color_Field extends RWMB_Text_Field {
|
|
39 |
}
|
40 |
|
41 |
/**
|
42 |
-
* Get the attributes for a field
|
43 |
*
|
44 |
-
* @param array $field
|
45 |
-
* @param mixed $value
|
46 |
* @return array
|
47 |
*/
|
48 |
-
static function get_attributes( $field, $value = null ) {
|
49 |
$attributes = parent::get_attributes( $field, $value );
|
50 |
$attributes = wp_parse_args( $attributes, array(
|
51 |
'data-options' => wp_json_encode( $field['js_options'] ),
|
@@ -58,11 +62,11 @@ class RWMB_Color_Field extends RWMB_Text_Field {
|
|
58 |
/**
|
59 |
* Format a single value for the helper functions.
|
60 |
*
|
61 |
-
* @param array $field Field
|
62 |
-
* @param string $value The value
|
63 |
* @return string
|
64 |
*/
|
65 |
-
static function format_single_value( $field, $value ) {
|
66 |
return sprintf( "<span style='display:inline-block;width:20px;height:20px;border-radius:50%%;background:%s;'></span>", $value );
|
67 |
}
|
68 |
}
|
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_Text_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 |
wp_enqueue_script( 'rwmb-color', RWMB_JS_URL . 'color.js', array( 'wp-color-picker' ), RWMB_VER, true );
|
18 |
}
|
20 |
/**
|
21 |
* Normalize parameters for field.
|
22 |
*
|
23 |
+
* @param array $field Field parameters.
|
24 |
* @return array
|
25 |
*/
|
26 |
+
public static function normalize( $field ) {
|
27 |
$field = wp_parse_args( $field, array(
|
28 |
'size' => 7,
|
29 |
'maxlength' => 7,
|
43 |
}
|
44 |
|
45 |
/**
|
46 |
+
* Get the attributes for a field.
|
47 |
*
|
48 |
+
* @param array $field Field parameters.
|
49 |
+
* @param mixed $value Meta value.
|
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, array(
|
55 |
'data-options' => wp_json_encode( $field['js_options'] ),
|
62 |
/**
|
63 |
* Format a single value for the helper functions.
|
64 |
*
|
65 |
+
* @param array $field Field parameters.
|
66 |
+
* @param string $value The value.
|
67 |
* @return string
|
68 |
*/
|
69 |
+
public static function format_single_value( $field, $value ) {
|
70 |
return sprintf( "<span style='display:inline-block;width:20px;height:20px;border-radius:50%%;background:%s;'></span>", $value );
|
71 |
}
|
72 |
}
|
inc/fields/custom-html.php
CHANGED
@@ -1,18 +1,23 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Custom HTML field class.
|
4 |
*/
|
5 |
class RWMB_Custom_Html_Field extends RWMB_Field {
|
6 |
-
|
7 |
/**
|
8 |
-
* Get field HTML
|
9 |
*
|
10 |
-
* @param mixed $meta
|
11 |
-
* @param array $field
|
12 |
*
|
13 |
* @return string
|
14 |
*/
|
15 |
-
static function html( $meta, $field ) {
|
16 |
$html = ! empty( $field['std'] ) ? $field['std'] : '';
|
17 |
if ( ! empty( $field['callback'] ) && is_callable( $field['callback'] ) ) {
|
18 |
$html = call_user_func_array( $field['callback'], array( $meta, $field ) );
|
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 |
/**
|
13 |
+
* Get field HTML.
|
14 |
*
|
15 |
+
* @param mixed $meta Meta value.
|
16 |
+
* @param array $field Field parameters.
|
17 |
*
|
18 |
* @return string
|
19 |
*/
|
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 ) );
|
inc/fields/date.php
CHANGED
@@ -1,13 +1,16 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Date field class.
|
4 |
*/
|
5 |
class RWMB_Date_Field extends RWMB_Datetime_Field {
|
6 |
-
|
7 |
/**
|
8 |
-
* Enqueue scripts and styles
|
9 |
-
*
|
10 |
-
* @return void
|
11 |
*/
|
12 |
public static function admin_enqueue_scripts() {
|
13 |
parent::admin_register_scripts();
|
@@ -16,10 +19,10 @@ class RWMB_Date_Field extends RWMB_Datetime_Field {
|
|
16 |
}
|
17 |
|
18 |
/**
|
19 |
-
* Returns a date() compatible format string from the JavaScript format
|
20 |
*
|
21 |
* @link http://www.php.net/manual/en/function.date.php
|
22 |
-
* @param array $field
|
23 |
*
|
24 |
* @return string
|
25 |
*/
|
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::admin_register_scripts();
|
19 |
}
|
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 $field Field parameters.
|
26 |
*
|
27 |
* @return string
|
28 |
*/
|
inc/fields/datetime.php
CHANGED
@@ -1,14 +1,18 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
* Datetime field class.
|
5 |
*/
|
6 |
class RWMB_Datetime_Field extends RWMB_Text_Field {
|
7 |
-
|
8 |
/**
|
9 |
-
* Translate date format from jQuery UI date picker to PHP date()
|
10 |
-
* It's used to store timestamp value of the field
|
11 |
-
* Missing: '!' => '', 'oo' => '', '@' => '', "''" => "'"
|
12 |
*
|
13 |
* @var array
|
14 |
*/
|
@@ -28,9 +32,9 @@ class RWMB_Datetime_Field extends RWMB_Text_Field {
|
|
28 |
);
|
29 |
|
30 |
/**
|
31 |
-
* Translate time format from jQuery UI time picker to PHP date()
|
32 |
-
* It's used to store timestamp value of the field
|
33 |
-
* Missing: 't' => '', T' => '', 'm' => '', 's' => ''
|
34 |
*
|
35 |
* @var array
|
36 |
*/
|
@@ -79,7 +83,7 @@ class RWMB_Datetime_Field extends RWMB_Text_Field {
|
|
79 |
}
|
80 |
|
81 |
/**
|
82 |
-
* Enqueue scripts and styles
|
83 |
*/
|
84 |
public static function admin_enqueue_scripts() {
|
85 |
self::admin_register_scripts();
|
@@ -88,10 +92,10 @@ class RWMB_Datetime_Field extends RWMB_Text_Field {
|
|
88 |
}
|
89 |
|
90 |
/**
|
91 |
-
* Get field HTML
|
92 |
*
|
93 |
-
* @param mixed $meta
|
94 |
-
* @param array $field
|
95 |
*
|
96 |
* @return string
|
97 |
*/
|
@@ -100,7 +104,9 @@ class RWMB_Datetime_Field extends RWMB_Text_Field {
|
|
100 |
|
101 |
if ( $field['timestamp'] ) {
|
102 |
$name = $field['field_name'];
|
103 |
-
$field = wp_parse_args( array(
|
|
|
|
|
104 |
$output .= sprintf(
|
105 |
'<input type="hidden" name="%s" class="rwmb-datetime-timestamp" value="%s">',
|
106 |
esc_attr( $name . '[timestamp]' ),
|
@@ -119,26 +125,25 @@ class RWMB_Datetime_Field extends RWMB_Text_Field {
|
|
119 |
}
|
120 |
|
121 |
/**
|
122 |
-
* Calculates the timestamp from the datetime string and returns it
|
123 |
-
* if $field['timestamp'] is set or the datetime string if not
|
124 |
*
|
125 |
-
* @param mixed $new
|
126 |
-
* @param mixed $old
|
127 |
-
* @param int $post_id
|
128 |
-
* @param array $field
|
129 |
*
|
130 |
* @return string|int
|
131 |
*/
|
132 |
public static function value( $new, $old, $post_id, $field ) {
|
133 |
-
return
|
134 |
}
|
135 |
|
136 |
/**
|
137 |
-
* Get meta value
|
138 |
*
|
139 |
-
* @param int $post_id
|
140 |
-
* @param bool $saved
|
141 |
-
* @param array $field
|
142 |
*
|
143 |
* @return mixed
|
144 |
*/
|
@@ -151,15 +156,18 @@ class RWMB_Datetime_Field extends RWMB_Text_Field {
|
|
151 |
}
|
152 |
|
153 |
/**
|
154 |
-
* Format meta value if set 'timestamp'
|
155 |
*
|
156 |
-
* @param array|string $meta The meta value
|
157 |
-
* @param array $field Field
|
158 |
* @return array
|
159 |
*/
|
160 |
protected static function prepare_meta( $meta, $field ) {
|
161 |
if ( is_array( $meta ) ) {
|
162 |
-
|
|
|
|
|
|
|
163 |
}
|
164 |
return array(
|
165 |
'timestamp' => $meta ? $meta : null,
|
@@ -168,9 +176,9 @@ class RWMB_Datetime_Field extends RWMB_Text_Field {
|
|
168 |
}
|
169 |
|
170 |
/**
|
171 |
-
* Normalize parameters for field
|
172 |
*
|
173 |
-
* @param array $field
|
174 |
* @return array
|
175 |
*/
|
176 |
public static function normalize( $field ) {
|
@@ -180,8 +188,8 @@ class RWMB_Datetime_Field extends RWMB_Text_Field {
|
|
180 |
'js_options' => array(),
|
181 |
) );
|
182 |
|
183 |
-
// Deprecate 'format', but keep it for backward compatible
|
184 |
-
// Use 'js_options' instead
|
185 |
$field['js_options'] = wp_parse_args( $field['js_options'], array(
|
186 |
'timeFormat' => 'HH:mm',
|
187 |
'separator' => ' ',
|
@@ -201,10 +209,10 @@ class RWMB_Datetime_Field extends RWMB_Text_Field {
|
|
201 |
}
|
202 |
|
203 |
/**
|
204 |
-
* Get the attributes for a field
|
205 |
*
|
206 |
-
* @param array $field
|
207 |
-
* @param mixed $value
|
208 |
*
|
209 |
* @return array
|
210 |
*/
|
@@ -219,10 +227,10 @@ class RWMB_Datetime_Field extends RWMB_Text_Field {
|
|
219 |
}
|
220 |
|
221 |
/**
|
222 |
-
* Returns a date() compatible format string from the JavaScript format
|
223 |
*
|
224 |
* @link http://www.php.net/manual/en/function.date.php
|
225 |
-
* @param array $field
|
226 |
*
|
227 |
* @return string
|
228 |
*/
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* The date and time picker field which allows users to select both date and time via jQueryUI datetime picker.
|
4 |
+
*
|
5 |
+
* @package Meta Box
|
6 |
+
*/
|
7 |
|
8 |
/**
|
9 |
* Datetime field class.
|
10 |
*/
|
11 |
class RWMB_Datetime_Field extends RWMB_Text_Field {
|
|
|
12 |
/**
|
13 |
+
* Translate date format from jQuery UI date picker to PHP date().
|
14 |
+
* It's used to store timestamp value of the field.
|
15 |
+
* Missing: '!' => '', 'oo' => '', '@' => '', "''" => "'".
|
16 |
*
|
17 |
* @var array
|
18 |
*/
|
32 |
);
|
33 |
|
34 |
/**
|
35 |
+
* Translate time format from jQuery UI time picker to PHP date().
|
36 |
+
* It's used to store timestamp value of the field.
|
37 |
+
* Missing: 't' => '', T' => '', 'm' => '', 's' => ''.
|
38 |
*
|
39 |
* @var array
|
40 |
*/
|
83 |
}
|
84 |
|
85 |
/**
|
86 |
+
* Enqueue scripts and styles.
|
87 |
*/
|
88 |
public static function admin_enqueue_scripts() {
|
89 |
self::admin_register_scripts();
|
92 |
}
|
93 |
|
94 |
/**
|
95 |
+
* Get field HTML.
|
96 |
*
|
97 |
+
* @param mixed $meta The field meta value.
|
98 |
+
* @param array $field The field parameters.
|
99 |
*
|
100 |
* @return string
|
101 |
*/
|
104 |
|
105 |
if ( $field['timestamp'] ) {
|
106 |
$name = $field['field_name'];
|
107 |
+
$field = wp_parse_args( array(
|
108 |
+
'field_name' => $name . '[formatted]',
|
109 |
+
), $field );
|
110 |
$output .= sprintf(
|
111 |
'<input type="hidden" name="%s" class="rwmb-datetime-timestamp" value="%s">',
|
112 |
esc_attr( $name . '[timestamp]' ),
|
125 |
}
|
126 |
|
127 |
/**
|
128 |
+
* Calculates the timestamp from the datetime string and returns it if $field['timestamp'] is set or the datetime string if not.
|
|
|
129 |
*
|
130 |
+
* @param mixed $new The submitted meta value.
|
131 |
+
* @param mixed $old The existing meta value.
|
132 |
+
* @param int $post_id The post ID.
|
133 |
+
* @param array $field The field parameters.
|
134 |
*
|
135 |
* @return string|int
|
136 |
*/
|
137 |
public static function value( $new, $old, $post_id, $field ) {
|
138 |
+
return $field['timestamp'] ? $new['timestamp'] : $new;
|
139 |
}
|
140 |
|
141 |
/**
|
142 |
+
* Get meta value.
|
143 |
*
|
144 |
+
* @param int $post_id The post ID.
|
145 |
+
* @param bool $saved Whether the meta box is saved at least once.
|
146 |
+
* @param array $field The field parameters.
|
147 |
*
|
148 |
* @return mixed
|
149 |
*/
|
156 |
}
|
157 |
|
158 |
/**
|
159 |
+
* Format meta value if set 'timestamp'.
|
160 |
*
|
161 |
+
* @param array|string $meta The meta value.
|
162 |
+
* @param array $field Field parameters.
|
163 |
* @return array
|
164 |
*/
|
165 |
protected static function prepare_meta( $meta, $field ) {
|
166 |
if ( is_array( $meta ) ) {
|
167 |
+
foreach ( $meta as $key => $value ) {
|
168 |
+
$meta[ $key ] = self::prepare_meta( $value, $field );
|
169 |
+
}
|
170 |
+
return $meta;
|
171 |
}
|
172 |
return array(
|
173 |
'timestamp' => $meta ? $meta : null,
|
176 |
}
|
177 |
|
178 |
/**
|
179 |
+
* Normalize parameters for field.
|
180 |
*
|
181 |
+
* @param array $field The field parameters.
|
182 |
* @return array
|
183 |
*/
|
184 |
public static function normalize( $field ) {
|
188 |
'js_options' => array(),
|
189 |
) );
|
190 |
|
191 |
+
// Deprecate 'format', but keep it for backward compatible.
|
192 |
+
// Use 'js_options' instead.
|
193 |
$field['js_options'] = wp_parse_args( $field['js_options'], array(
|
194 |
'timeFormat' => 'HH:mm',
|
195 |
'separator' => ' ',
|
209 |
}
|
210 |
|
211 |
/**
|
212 |
+
* Get the attributes for a field.
|
213 |
*
|
214 |
+
* @param array $field The field parameters.
|
215 |
+
* @param mixed $value The meta value.
|
216 |
*
|
217 |
* @return array
|
218 |
*/
|
227 |
}
|
228 |
|
229 |
/**
|
230 |
+
* Returns a date() compatible format string from the JavaScript format.
|
231 |
*
|
232 |
* @link http://www.php.net/manual/en/function.date.php
|
233 |
+
* @param array $field The field parameters.
|
234 |
*
|
235 |
* @return string
|
236 |
*/
|
inc/fields/divider.php
CHANGED
@@ -1,40 +1,43 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Divider field class.
|
4 |
*/
|
5 |
class RWMB_Divider_Field extends RWMB_Field {
|
6 |
-
|
7 |
/**
|
8 |
-
* Enqueue scripts and styles
|
9 |
-
*
|
10 |
-
* @return void
|
11 |
*/
|
12 |
-
static function admin_enqueue_scripts() {
|
13 |
wp_enqueue_style( 'rwmb-divider', RWMB_CSS_URL . 'divider.css', array(), RWMB_VER );
|
14 |
}
|
15 |
|
16 |
/**
|
17 |
-
* Show begin HTML markup for fields
|
18 |
*
|
19 |
-
* @param mixed $meta
|
20 |
-
* @param array $field
|
21 |
*
|
22 |
* @return string
|
23 |
*/
|
24 |
-
static function begin_html( $meta, $field ) {
|
25 |
$attributes = empty( $field['id'] ) ? '' : " id='{$field['id']}'";
|
26 |
return "<hr$attributes>";
|
27 |
}
|
28 |
|
29 |
/**
|
30 |
-
* Show end HTML markup for fields
|
31 |
*
|
32 |
-
* @param mixed $meta
|
33 |
-
* @param array $field
|
34 |
*
|
35 |
* @return string
|
36 |
*/
|
37 |
-
static function end_html( $meta, $field ) {
|
38 |
return '';
|
39 |
}
|
40 |
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* The divider field which displays a simple horizontal line.
|
4 |
+
*
|
5 |
+
* @package Meta Box
|
6 |
+
*/
|
7 |
+
|
8 |
/**
|
9 |
* Divider field class.
|
10 |
*/
|
11 |
class RWMB_Divider_Field extends RWMB_Field {
|
|
|
12 |
/**
|
13 |
+
* Enqueue scripts and styles.
|
|
|
|
|
14 |
*/
|
15 |
+
public static function admin_enqueue_scripts() {
|
16 |
wp_enqueue_style( 'rwmb-divider', RWMB_CSS_URL . 'divider.css', array(), RWMB_VER );
|
17 |
}
|
18 |
|
19 |
/**
|
20 |
+
* Show begin HTML markup for fields.
|
21 |
*
|
22 |
+
* @param mixed $meta Meta value.
|
23 |
+
* @param array $field Field parameters.
|
24 |
*
|
25 |
* @return string
|
26 |
*/
|
27 |
+
public static function begin_html( $meta, $field ) {
|
28 |
$attributes = empty( $field['id'] ) ? '' : " id='{$field['id']}'";
|
29 |
return "<hr$attributes>";
|
30 |
}
|
31 |
|
32 |
/**
|
33 |
+
* Show end HTML markup for fields.
|
34 |
*
|
35 |
+
* @param mixed $meta Meta value.
|
36 |
+
* @param array $field Field parameters.
|
37 |
*
|
38 |
* @return string
|
39 |
*/
|
40 |
+
public static function end_html( $meta, $field ) {
|
41 |
return '';
|
42 |
}
|
43 |
}
|
inc/fields/fieldset-text.php
CHANGED
@@ -1,19 +1,23 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
* Fieldset text class.
|
5 |
*/
|
6 |
class RWMB_Fieldset_Text_Field extends RWMB_Text_Field {
|
7 |
-
|
8 |
/**
|
9 |
-
* Get field HTML
|
10 |
*
|
11 |
-
* @param mixed $meta
|
12 |
-
* @param array $field
|
13 |
*
|
14 |
* @return string
|
15 |
*/
|
16 |
-
static function html( $meta, $field ) {
|
17 |
$html = array();
|
18 |
$tpl = '<label>%s %s</label>';
|
19 |
|
@@ -31,7 +35,7 @@ class RWMB_Fieldset_Text_Field extends RWMB_Text_Field {
|
|
31 |
/**
|
32 |
* Do not show field description.
|
33 |
*
|
34 |
-
* @param array $field
|
35 |
* @return string
|
36 |
*/
|
37 |
public static function element_description( $field ) {
|
@@ -39,13 +43,13 @@ class RWMB_Fieldset_Text_Field extends RWMB_Text_Field {
|
|
39 |
}
|
40 |
|
41 |
/**
|
42 |
-
* Normalize parameters for field
|
43 |
*
|
44 |
-
* @param array $field
|
45 |
*
|
46 |
* @return array
|
47 |
*/
|
48 |
-
static function normalize( $field ) {
|
49 |
$field = parent::normalize( $field );
|
50 |
$field['multiple'] = false;
|
51 |
$field['attributes']['id'] = false;
|
@@ -56,8 +60,8 @@ class RWMB_Fieldset_Text_Field extends RWMB_Text_Field {
|
|
56 |
/**
|
57 |
* Format value for the helper functions.
|
58 |
*
|
59 |
-
* @param array $field Field
|
60 |
-
* @param string|array $value
|
61 |
* @return string
|
62 |
*/
|
63 |
public static function format_value( $field, $value ) {
|
@@ -81,8 +85,8 @@ class RWMB_Fieldset_Text_Field extends RWMB_Text_Field {
|
|
81 |
/**
|
82 |
* Format a single value for the helper functions.
|
83 |
*
|
84 |
-
* @param array $field Field
|
85 |
-
* @param array $value The value
|
86 |
* @return string
|
87 |
*/
|
88 |
public static function format_single_value( $field, $value ) {
|
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_Text_Field {
|
|
|
12 |
/**
|
13 |
+
* Get field HTML.
|
14 |
*
|
15 |
+
* @param mixed $meta Meta value.
|
16 |
+
* @param array $field Field parameters.
|
17 |
*
|
18 |
* @return string
|
19 |
*/
|
20 |
+
public static function html( $meta, $field ) {
|
21 |
$html = array();
|
22 |
$tpl = '<label>%s %s</label>';
|
23 |
|
35 |
/**
|
36 |
* Do not show field description.
|
37 |
*
|
38 |
+
* @param array $field Field parameters.
|
39 |
* @return string
|
40 |
*/
|
41 |
public static function element_description( $field ) {
|
43 |
}
|
44 |
|
45 |
/**
|
46 |
+
* Normalize parameters for field.
|
47 |
*
|
48 |
+
* @param array $field Field parameters.
|
49 |
*
|
50 |
* @return array
|
51 |
*/
|
52 |
+
public static function normalize( $field ) {
|
53 |
$field = parent::normalize( $field );
|
54 |
$field['multiple'] = false;
|
55 |
$field['attributes']['id'] = false;
|
60 |
/**
|
61 |
* Format value for the helper functions.
|
62 |
*
|
63 |
+
* @param array $field Field parameters.
|
64 |
+
* @param string|array $value Meta value.
|
65 |
* @return string
|
66 |
*/
|
67 |
public static function format_value( $field, $value ) {
|
85 |
/**
|
86 |
* Format a single value for the helper functions.
|
87 |
*
|
88 |
+
* @param array $field Field parameters.
|
89 |
+
* @param array $value The value.
|
90 |
* @return string
|
91 |
*/
|
92 |
public static function format_single_value( $field, $value ) {
|
inc/fields/file-input.php
CHANGED
@@ -1,61 +1,57 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
* File input field class which uses an input for file URL.
|
5 |
*/
|
6 |
-
class RWMB_File_Input_Field extends
|
7 |
-
|
8 |
/**
|
9 |
-
* Enqueue scripts and styles
|
10 |
-
*
|
11 |
-
* @return void
|
12 |
*/
|
13 |
-
static function admin_enqueue_scripts() {
|
14 |
wp_enqueue_media();
|
15 |
wp_enqueue_script( 'rwmb-file-input', RWMB_JS_URL . 'file-input.js', array( 'jquery' ), RWMB_VER, true );
|
16 |
self::localize_script('rwmb-file-input', 'rwmbFileInput', array(
|
17 |
-
'frameTitle' =>
|
18 |
) );
|
19 |
}
|
20 |
|
21 |
/**
|
22 |
-
* Get field HTML
|
23 |
*
|
24 |
-
* @param mixed $meta
|
25 |
-
* @param array $field
|
26 |
*
|
27 |
* @return string
|
28 |
*/
|
29 |
-
static function html( $meta, $field ) {
|
|
|
30 |
return sprintf(
|
31 |
-
'<input
|
32 |
<a href="#" class="rwmb-file-input-select button-primary">%s</a>
|
33 |
<a href="#" class="rwmb-file-input-remove button %s">%s</a>',
|
34 |
-
$
|
35 |
-
|
36 |
-
$meta,
|
37 |
-
$field['placeholder'],
|
38 |
-
$field['size'],
|
39 |
-
__( 'Select', 'meta-box' ),
|
40 |
$meta ? '' : 'hidden',
|
41 |
-
|
42 |
);
|
43 |
}
|
44 |
|
45 |
/**
|
46 |
-
*
|
47 |
-
*
|
48 |
-
* @param array $field
|
49 |
*
|
|
|
|
|
50 |
* @return array
|
51 |
*/
|
52 |
-
static function
|
53 |
-
$
|
54 |
-
$
|
55 |
-
'size' => 30,
|
56 |
-
'placeholder' => '',
|
57 |
-
) );
|
58 |
|
59 |
-
return $
|
60 |
}
|
61 |
}
|
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 |
/**
|
13 |
+
* Enqueue scripts and styles.
|
|
|
|
|
14 |
*/
|
15 |
+
public static function admin_enqueue_scripts() {
|
16 |
wp_enqueue_media();
|
17 |
wp_enqueue_script( 'rwmb-file-input', RWMB_JS_URL . 'file-input.js', array( 'jquery' ), RWMB_VER, true );
|
18 |
self::localize_script('rwmb-file-input', 'rwmbFileInput', array(
|
19 |
+
'frameTitle' => esc_html__( 'Select File', 'meta-box' ),
|
20 |
) );
|
21 |
}
|
22 |
|
23 |
/**
|
24 |
+
* Get field HTML.
|
25 |
*
|
26 |
+
* @param mixed $meta Meta value.
|
27 |
+
* @param array $field Field parameters.
|
28 |
*
|
29 |
* @return string
|
30 |
*/
|
31 |
+
public static function html( $meta, $field ) {
|
32 |
+
$attributes = self::get_attributes( $field, $meta );
|
33 |
return sprintf(
|
34 |
+
'<input %s>
|
35 |
<a href="#" class="rwmb-file-input-select button-primary">%s</a>
|
36 |
<a href="#" class="rwmb-file-input-remove button %s">%s</a>',
|
37 |
+
self::render_attributes( $attributes ),
|
38 |
+
esc_html__( 'Select', 'meta-box' ),
|
|
|
|
|
|
|
|
|
39 |
$meta ? '' : 'hidden',
|
40 |
+
esc_html__( 'Remove', 'meta-box' )
|
41 |
);
|
42 |
}
|
43 |
|
44 |
/**
|
45 |
+
* Get the attributes for a field.
|
|
|
|
|
46 |
*
|
47 |
+
* @param array $field Field parameters.
|
48 |
+
* @param mixed $value Meta value.
|
49 |
* @return array
|
50 |
*/
|
51 |
+
public static function get_attributes( $field, $value = null ) {
|
52 |
+
$attributes = parent::get_attributes( $field, $value );
|
53 |
+
$attributes['type'] = 'text';
|
|
|
|
|
|
|
54 |
|
55 |
+
return $attributes;
|
56 |
}
|
57 |
}
|
inc/fields/file-upload.php
CHANGED
@@ -1,11 +1,16 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
*
|
|
|
|
|
4 |
*/
|
5 |
-
class RWMB_File_Upload_Field extends RWMB_Media_Field {
|
6 |
|
|
|
|
|
|
|
|
|
7 |
/**
|
8 |
-
* Enqueue scripts and styles
|
9 |
*/
|
10 |
public static function admin_enqueue_scripts() {
|
11 |
parent::admin_enqueue_scripts();
|
@@ -14,7 +19,27 @@ class RWMB_File_Upload_Field extends RWMB_Media_Field {
|
|
14 |
}
|
15 |
|
16 |
/**
|
17 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
*/
|
19 |
public static function print_templates() {
|
20 |
parent::print_templates();
|
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();
|
19 |
}
|
20 |
|
21 |
/**
|
22 |
+
* Normalize parameters for field.
|
23 |
+
*
|
24 |
+
* @param array $field Field parameters.
|
25 |
+
*
|
26 |
+
* @return array
|
27 |
+
*/
|
28 |
+
public static function normalize( $field ) {
|
29 |
+
$field = parent::normalize( $field );
|
30 |
+
$field = wp_parse_args( $field, array(
|
31 |
+
'max_file_size' => 0,
|
32 |
+
) );
|
33 |
+
|
34 |
+
$field['js_options'] = wp_parse_args( $field['js_options'], array(
|
35 |
+
'maxFileSize' => $field['max_file_size'],
|
36 |
+
) );
|
37 |
+
|
38 |
+
return $field;
|
39 |
+
}
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Template for media item.
|
43 |
*/
|
44 |
public static function print_templates() {
|
45 |
parent::print_templates();
|
inc/fields/file.php
CHANGED
@@ -1,25 +1,31 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
* File field class which uses HTML <input type="file"> to upload file.
|
5 |
*/
|
6 |
class RWMB_File_Field extends RWMB_Field {
|
7 |
-
|
8 |
/**
|
9 |
-
* Enqueue scripts and styles
|
10 |
*/
|
11 |
public static function admin_enqueue_scripts() {
|
12 |
wp_enqueue_style( 'rwmb-file', RWMB_CSS_URL . 'file.css', array(), RWMB_VER );
|
13 |
wp_enqueue_script( 'rwmb-file', RWMB_JS_URL . 'file.js', array( 'jquery' ), RWMB_VER, true );
|
14 |
|
15 |
self::localize_script( 'rwmb-file', 'rwmbFile', array(
|
|
|
16 |
'maxFileUploadsSingle' => __( 'You may only upload maximum %d file', 'meta-box' ),
|
|
|
17 |
'maxFileUploadsPlural' => __( 'You may only upload maximum %d files', 'meta-box' ),
|
18 |
) );
|
19 |
}
|
20 |
|
21 |
/**
|
22 |
-
* Add custom actions
|
23 |
*/
|
24 |
public static function add_actions() {
|
25 |
add_action( 'post_edit_form_tag', array( __CLASS__, 'post_edit_form_tag' ) );
|
@@ -53,7 +59,7 @@ class RWMB_File_Field extends RWMB_Field {
|
|
53 |
|
54 |
/**
|
55 |
* Ajax callback for deleting files.
|
56 |
-
* Modified from a function used by "Verve Meta Boxes" plugin
|
57 |
*
|
58 |
* @link http://goo.gl/LzYSq
|
59 |
*/
|
@@ -74,10 +80,10 @@ class RWMB_File_Field extends RWMB_Field {
|
|
74 |
}
|
75 |
|
76 |
/**
|
77 |
-
* Get field HTML
|
78 |
*
|
79 |
-
* @param mixed $meta
|
80 |
-
* @param array $field
|
81 |
*
|
82 |
* @return string
|
83 |
*/
|
@@ -85,14 +91,14 @@ class RWMB_File_Field extends RWMB_Field {
|
|
85 |
$i18n_title = apply_filters( 'rwmb_file_upload_string', _x( 'Upload Files', 'file upload', 'meta-box' ), $field );
|
86 |
$i18n_more = apply_filters( 'rwmb_file_add_string', _x( '+ Add new file', 'file upload', 'meta-box' ), $field );
|
87 |
|
88 |
-
// Uploaded files
|
89 |
$html = self::get_uploaded_files( $meta, $field );
|
90 |
$classes = 'new-files';
|
91 |
if ( ! empty( $field['max_file_uploads'] ) && count( $meta ) >= (int) $field['max_file_uploads'] ) {
|
92 |
$classes .= ' hidden';
|
93 |
}
|
94 |
|
95 |
-
// Show form upload
|
96 |
$html .= sprintf(
|
97 |
'<div class="%s">
|
98 |
<h4>%s</h4>
|
@@ -111,8 +117,8 @@ class RWMB_File_Field extends RWMB_Field {
|
|
111 |
/**
|
112 |
* Get HTML for uploaded files.
|
113 |
*
|
114 |
-
* @param array $files List of uploaded files
|
115 |
-
* @param array $field Field parameters
|
116 |
* @return string
|
117 |
*/
|
118 |
protected static function get_uploaded_files( $files, $field ) {
|
@@ -143,7 +149,7 @@ class RWMB_File_Field extends RWMB_Field {
|
|
143 |
/**
|
144 |
* Get HTML for uploaded file.
|
145 |
*
|
146 |
-
* @param int $file Attachment (file) ID
|
147 |
* @return string
|
148 |
*/
|
149 |
protected static function file_html( $file ) {
|
@@ -174,21 +180,23 @@ class RWMB_File_Field extends RWMB_Field {
|
|
174 |
}
|
175 |
|
176 |
/**
|
177 |
-
* Get meta values to save
|
178 |
*
|
179 |
-
* @param mixed $new
|
180 |
-
* @param mixed $old
|
181 |
-
* @param int $post_id
|
182 |
-
* @param array $field
|
183 |
*
|
184 |
* @return array|mixed
|
185 |
*/
|
186 |
public static function value( $new, $old, $post_id, $field ) {
|
|
|
187 |
if ( empty( $_FILES[ $field['id'] ] ) ) {
|
188 |
return $new;
|
189 |
}
|
190 |
|
191 |
$new = array();
|
|
|
192 |
$files = self::transform( $_FILES[ $field['id'] ] );
|
193 |
foreach ( $files as $file ) {
|
194 |
$new[] = self::upload( $file, $post_id );
|
@@ -200,12 +208,14 @@ class RWMB_File_Field extends RWMB_Field {
|
|
200 |
/**
|
201 |
* Handle upload file.
|
202 |
*
|
203 |
-
* @param array $file
|
204 |
-
* @param int $post Post parent ID
|
205 |
* @return int Attachment ID on success, false on failure.
|
206 |
*/
|
207 |
protected static function upload( $file, $post ) {
|
208 |
-
$file = wp_handle_upload( $file, array(
|
|
|
|
|
209 |
if ( ! isset( $file['file'] ) ) {
|
210 |
return false;
|
211 |
}
|
@@ -225,9 +235,9 @@ class RWMB_File_Field extends RWMB_Field {
|
|
225 |
}
|
226 |
|
227 |
/**
|
228 |
-
* Transform $_FILES from $_FILES['field']['key']['index'] to $_FILES['field']['index']['key']
|
229 |
*
|
230 |
-
* @param array $files
|
231 |
* @return array
|
232 |
*/
|
233 |
protected static function transform( $files ) {
|
@@ -242,9 +252,9 @@ class RWMB_File_Field extends RWMB_Field {
|
|
242 |
}
|
243 |
|
244 |
/**
|
245 |
-
* Normalize parameters for field
|
246 |
*
|
247 |
-
* @param array $field
|
248 |
* @return array
|
249 |
*/
|
250 |
public static function normalize( $field ) {
|
@@ -263,8 +273,8 @@ class RWMB_File_Field extends RWMB_Field {
|
|
263 |
/**
|
264 |
* Get the field value. Return meaningful info of the files.
|
265 |
*
|
266 |
-
* @param array $field Field parameters
|
267 |
-
* @param array $args Not used for this field
|
268 |
* @param int|null $post_id Post ID. null for current post. Optional.
|
269 |
*
|
270 |
* @return mixed Full info of uploaded files
|
@@ -287,17 +297,18 @@ class RWMB_File_Field extends RWMB_Field {
|
|
287 |
}
|
288 |
|
289 |
/**
|
290 |
-
* Get uploaded files information
|
291 |
*
|
292 |
-
* @param array $field Field
|
293 |
-
* @param array $files Files IDs
|
294 |
-
* @param array $args Additional arguments (for image size)
|
295 |
* @return array
|
296 |
*/
|
297 |
public static function files_info( $field, $files, $args ) {
|
298 |
$return = array();
|
299 |
foreach ( (array) $files as $file ) {
|
300 |
-
|
|
|
301 |
$return[ $file ] = $info;
|
302 |
}
|
303 |
}
|
@@ -305,15 +316,16 @@ class RWMB_File_Field extends RWMB_Field {
|
|
305 |
}
|
306 |
|
307 |
/**
|
308 |
-
* Get uploaded file information
|
309 |
*
|
310 |
* @param int $file Attachment file ID (post ID). Required.
|
311 |
* @param array $args Array of arguments (for size).
|
312 |
*
|
313 |
-
* @return array|bool False if file not found. Array of (id, name, path, url) on success
|
314 |
*/
|
315 |
public static function file_info( $file, $args = array() ) {
|
316 |
-
|
|
|
317 |
return false;
|
318 |
}
|
319 |
|
@@ -329,8 +341,8 @@ class RWMB_File_Field extends RWMB_Field {
|
|
329 |
/**
|
330 |
* Format value for the helper functions.
|
331 |
*
|
332 |
-
* @param array $field Field
|
333 |
-
* @param string|array $value The field meta value
|
334 |
* @return string
|
335 |
*/
|
336 |
public static function format_value( $field, $value ) {
|
@@ -348,8 +360,8 @@ class RWMB_File_Field extends RWMB_Field {
|
|
348 |
/**
|
349 |
* Format a single value for the helper functions.
|
350 |
*
|
351 |
-
* @param array $field Field
|
352 |
-
* @param array $value The value
|
353 |
* @return string
|
354 |
*/
|
355 |
public static function format_single_value( $field, $value ) {
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* The file upload file which allows users to upload files via the default HTML <input type="file">.
|
4 |
+
*
|
5 |
+
* @package Meta Box
|
6 |
+
*/
|
7 |
|
8 |
/**
|
9 |
* File field class which uses HTML <input type="file"> to upload file.
|
10 |
*/
|
11 |
class RWMB_File_Field extends RWMB_Field {
|
|
|
12 |
/**
|
13 |
+
* Enqueue scripts and styles.
|
14 |
*/
|
15 |
public static function admin_enqueue_scripts() {
|
16 |
wp_enqueue_style( 'rwmb-file', RWMB_CSS_URL . 'file.css', array(), RWMB_VER );
|
17 |
wp_enqueue_script( 'rwmb-file', RWMB_JS_URL . 'file.js', array( 'jquery' ), RWMB_VER, true );
|
18 |
|
19 |
self::localize_script( 'rwmb-file', 'rwmbFile', array(
|
20 |
+
// Translators: %d is the number of files in singular form.
|
21 |
'maxFileUploadsSingle' => __( 'You may only upload maximum %d file', 'meta-box' ),
|
22 |
+
// Translators: %d is the number of files in plural form.
|
23 |
'maxFileUploadsPlural' => __( 'You may only upload maximum %d files', 'meta-box' ),
|
24 |
) );
|
25 |
}
|
26 |
|
27 |
/**
|
28 |
+
* Add custom actions.
|
29 |
*/
|
30 |
public static function add_actions() {
|
31 |
add_action( 'post_edit_form_tag', array( __CLASS__, 'post_edit_form_tag' ) );
|
59 |
|
60 |
/**
|
61 |
* Ajax callback for deleting files.
|
62 |
+
* Modified from a function used by "Verve Meta Boxes" plugin.
|
63 |
*
|
64 |
* @link http://goo.gl/LzYSq
|
65 |
*/
|
80 |
}
|
81 |
|
82 |
/**
|
83 |
+
* Get field HTML.
|
84 |
*
|
85 |
+
* @param mixed $meta Meta value.
|
86 |
+
* @param array $field Field parameters.
|
87 |
*
|
88 |
* @return string
|
89 |
*/
|
91 |
$i18n_title = apply_filters( 'rwmb_file_upload_string', _x( 'Upload Files', 'file upload', 'meta-box' ), $field );
|
92 |
$i18n_more = apply_filters( 'rwmb_file_add_string', _x( '+ Add new file', 'file upload', 'meta-box' ), $field );
|
93 |
|
94 |
+
// Uploaded files.
|
95 |
$html = self::get_uploaded_files( $meta, $field );
|
96 |
$classes = 'new-files';
|
97 |
if ( ! empty( $field['max_file_uploads'] ) && count( $meta ) >= (int) $field['max_file_uploads'] ) {
|
98 |
$classes .= ' hidden';
|
99 |
}
|
100 |
|
101 |
+
// Show form upload.
|
102 |
$html .= sprintf(
|
103 |
'<div class="%s">
|
104 |
<h4>%s</h4>
|
117 |
/**
|
118 |
* Get HTML for uploaded files.
|
119 |
*
|
120 |
+
* @param array $files List of uploaded files.
|
121 |
+
* @param array $field Field parameters.
|
122 |
* @return string
|
123 |
*/
|
124 |
protected static function get_uploaded_files( $files, $field ) {
|
149 |
/**
|
150 |
* Get HTML for uploaded file.
|
151 |
*
|
152 |
+
* @param int $file Attachment (file) ID.
|
153 |
* @return string
|
154 |
*/
|
155 |
protected static function file_html( $file ) {
|
180 |
}
|
181 |
|
182 |
/**
|
183 |
+
* Get meta values to save.
|
184 |
*
|
185 |
+
* @param mixed $new The submitted meta value.
|
186 |
+
* @param mixed $old The existing meta value.
|
187 |
+
* @param int $post_id The post ID.
|
188 |
+
* @param array $field The field parameters.
|
189 |
*
|
190 |
* @return array|mixed
|
191 |
*/
|
192 |
public static function value( $new, $old, $post_id, $field ) {
|
193 |
+
// @codingStandardsIgnoreLine
|
194 |
if ( empty( $_FILES[ $field['id'] ] ) ) {
|
195 |
return $new;
|
196 |
}
|
197 |
|
198 |
$new = array();
|
199 |
+
// @codingStandardsIgnoreLine
|
200 |
$files = self::transform( $_FILES[ $field['id'] ] );
|
201 |
foreach ( $files as $file ) {
|
202 |
$new[] = self::upload( $file, $post_id );
|
208 |
/**
|
209 |
* Handle upload file.
|
210 |
*
|
211 |
+
* @param array $file Uploaded file info.
|
212 |
+
* @param int $post Post parent ID.
|
213 |
* @return int Attachment ID on success, false on failure.
|
214 |
*/
|
215 |
protected static function upload( $file, $post ) {
|
216 |
+
$file = wp_handle_upload( $file, array(
|
217 |
+
'test_form' => false,
|
218 |
+
) );
|
219 |
if ( ! isset( $file['file'] ) ) {
|
220 |
return false;
|
221 |
}
|
235 |
}
|
236 |
|
237 |
/**
|
238 |
+
* Transform $_FILES from $_FILES['field']['key']['index'] to $_FILES['field']['index']['key'].
|
239 |
*
|
240 |
+
* @param array $files Uploaded files info.
|
241 |
* @return array
|
242 |
*/
|
243 |
protected static function transform( $files ) {
|
252 |
}
|
253 |
|
254 |
/**
|
255 |
+
* Normalize parameters for field.
|
256 |
*
|
257 |
+
* @param array $field Field parameters.
|
258 |
* @return array
|
259 |
*/
|
260 |
public static function normalize( $field ) {
|
273 |
/**
|
274 |
* Get the field value. Return meaningful info of the files.
|
275 |
*
|
276 |
+
* @param array $field Field parameters.
|
277 |
+
* @param array $args Not used for this field.
|
278 |
* @param int|null $post_id Post ID. null for current post. Optional.
|
279 |
*
|
280 |
* @return mixed Full info of uploaded files
|
297 |
}
|
298 |
|
299 |
/**
|
300 |
+
* Get uploaded files information.
|
301 |
*
|
302 |
+
* @param array $field Field parameters.
|
303 |
+
* @param array $files Files IDs.
|
304 |
+
* @param array $args Additional arguments (for image size).
|
305 |
* @return array
|
306 |
*/
|
307 |
public static function files_info( $field, $files, $args ) {
|
308 |
$return = array();
|
309 |
foreach ( (array) $files as $file ) {
|
310 |
+
$info = self::call( $field, 'file_info', $file, $args );
|
311 |
+
if ( $info ) {
|
312 |
$return[ $file ] = $info;
|
313 |
}
|
314 |
}
|
316 |
}
|
317 |
|
318 |
/**
|
319 |
+
* Get uploaded file information.
|
320 |
*
|
321 |
* @param int $file Attachment file ID (post ID). Required.
|
322 |
* @param array $args Array of arguments (for size).
|
323 |
*
|
324 |
+
* @return array|bool False if file not found. Array of (id, name, path, url) on success.
|
325 |
*/
|
326 |
public static function file_info( $file, $args = array() ) {
|
327 |
+
$path = get_attached_file( $file );
|
328 |
+
if ( ! $path ) {
|
329 |
return false;
|
330 |
}
|
331 |
|
341 |
/**
|
342 |
* Format value for the helper functions.
|
343 |
*
|
344 |
+
* @param array $field Field parameters.
|
345 |
+
* @param string|array $value The field meta value.
|
346 |
* @return string
|
347 |
*/
|
348 |
public static function format_value( $field, $value ) {
|
360 |
/**
|
361 |
* Format a single value for the helper functions.
|
362 |
*
|
363 |
+
* @param array $field Field parameters.
|
364 |
+
* @param array $value The value.
|
365 |
* @return string
|
366 |
*/
|
367 |
public static function format_single_value( $field, $value ) {
|
inc/fields/heading.php
CHANGED
@@ -1,41 +1,43 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
* Heading field class.
|
5 |
*/
|
6 |
class RWMB_Heading_Field extends RWMB_Field {
|
7 |
-
|
8 |
/**
|
9 |
-
* Enqueue scripts and styles
|
10 |
-
*
|
11 |
-
* @return void
|
12 |
*/
|
13 |
-
static function admin_enqueue_scripts() {
|
14 |
wp_enqueue_style( 'rwmb-heading', RWMB_CSS_URL . 'heading.css', array(), RWMB_VER );
|
15 |
}
|
16 |
|
17 |
/**
|
18 |
-
* Show begin HTML markup for fields
|
19 |
*
|
20 |
-
* @param mixed $meta
|
21 |
-
* @param array $field
|
22 |
*
|
23 |
* @return string
|
24 |
*/
|
25 |
-
static function begin_html( $meta, $field ) {
|
26 |
$attributes = empty( $field['id'] ) ? '' : " id='{$field['id']}'";
|
27 |
return sprintf( '<h4%s>%s</h4>', $attributes, $field['name'] );
|
28 |
}
|
29 |
|
30 |
/**
|
31 |
-
* Show end HTML markup for fields
|
32 |
*
|
33 |
-
* @param mixed $meta
|
34 |
-
* @param array $field
|
35 |
*
|
36 |
* @return string
|
37 |
*/
|
38 |
-
static function end_html( $meta, $field ) {
|
39 |
return self::element_description( $field );
|
40 |
}
|
41 |
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* The heading field which displays a simple heading text.
|
4 |
+
*
|
5 |
+
* @package Meta Box
|
6 |
+
*/
|
7 |
|
8 |
/**
|
9 |
* Heading field class.
|
10 |
*/
|
11 |
class RWMB_Heading_Field extends RWMB_Field {
|
|
|
12 |
/**
|
13 |
+
* Enqueue scripts and styles.
|
|
|
|
|
14 |
*/
|
15 |
+
public static function admin_enqueue_scripts() {
|
16 |
wp_enqueue_style( 'rwmb-heading', RWMB_CSS_URL . 'heading.css', array(), RWMB_VER );
|
17 |
}
|
18 |
|
19 |
/**
|
20 |
+
* Show begin HTML markup for fields.
|
21 |
*
|
22 |
+
* @param mixed $meta Meta value.
|
23 |
+
* @param array $field Field parameters.
|
24 |
*
|
25 |
* @return string
|
26 |
*/
|
27 |
+
public static function begin_html( $meta, $field ) {
|
28 |
$attributes = empty( $field['id'] ) ? '' : " id='{$field['id']}'";
|
29 |
return sprintf( '<h4%s>%s</h4>', $attributes, $field['name'] );
|
30 |
}
|
31 |
|
32 |
/**
|
33 |
+
* Show end HTML markup for fields.
|
34 |
*
|
35 |
+
* @param mixed $meta Meta value.
|
36 |
+
* @param array $field Field parameters.
|
37 |
*
|
38 |
* @return string
|
39 |
*/
|
40 |
+
public static function end_html( $meta, $field ) {
|
41 |
return self::element_description( $field );
|
42 |
}
|
43 |
}
|
inc/fields/image-advanced.php
CHANGED
@@ -1,40 +1,46 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
*
|
|
|
|
|
4 |
*/
|
5 |
-
class RWMB_Image_Advanced_Field extends RWMB_Media_Field {
|
6 |
|
|
|
|
|
|
|
|
|
7 |
/**
|
8 |
-
* Enqueue scripts and styles
|
9 |
*/
|
10 |
-
static function admin_enqueue_scripts() {
|
11 |
parent::admin_enqueue_scripts();
|
12 |
wp_enqueue_style( 'rwmb-image-advanced', RWMB_CSS_URL . 'image-advanced.css', array( 'rwmb-media' ), RWMB_VER );
|
13 |
wp_enqueue_script( 'rwmb-image-advanced', RWMB_JS_URL . 'image-advanced.js', array( 'rwmb-media' ), RWMB_VER, true );
|
14 |
}
|
15 |
|
16 |
/**
|
17 |
-
* Normalize parameters for field
|
18 |
*
|
19 |
-
* @param array $field
|
20 |
*
|
21 |
* @return array
|
22 |
*/
|
23 |
-
static function normalize( $field ) {
|
24 |
-
$field = parent::normalize( $field );
|
25 |
$field['mime_type'] = 'image';
|
|
|
|
|
26 |
return $field;
|
27 |
}
|
28 |
|
29 |
/**
|
30 |
* Get the field value.
|
31 |
*
|
32 |
-
* @param array $field
|
33 |
-
* @param array $args
|
34 |
-
* @param null $post_id
|
35 |
* @return mixed
|
36 |
*/
|
37 |
-
static function get_value( $field, $args = array(), $post_id = null ) {
|
38 |
return RWMB_Image_Field::get_value( $field, $args, $post_id );
|
39 |
}
|
40 |
|
@@ -43,17 +49,17 @@ class RWMB_Image_Advanced_Field extends RWMB_Media_Field {
|
|
43 |
*
|
44 |
* @param int $file Attachment image ID (post ID). Required.
|
45 |
* @param array $args Array of arguments (for size).
|
46 |
-
* @return array|bool False if file not found. Array of image info on success
|
47 |
*/
|
48 |
-
static function file_info( $file, $args = array() ) {
|
49 |
return RWMB_Image_Field::file_info( $file, $args );
|
50 |
}
|
51 |
|
52 |
/**
|
53 |
* Format value for the helper functions.
|
54 |
*
|
55 |
-
* @param array $field Field
|
56 |
-
* @param string|array $value The field meta value
|
57 |
* @return string
|
58 |
*/
|
59 |
public static function format_value( $field, $value ) {
|
@@ -63,8 +69,8 @@ class RWMB_Image_Advanced_Field extends RWMB_Media_Field {
|
|
63 |
/**
|
64 |
* Format a single value for the helper functions.
|
65 |
*
|
66 |
-
* @param array $field Field
|
67 |
-
* @param array $value The value
|
68 |
* @return string
|
69 |
*/
|
70 |
public static function format_single_value( $field, $value ) {
|
@@ -72,9 +78,7 @@ class RWMB_Image_Advanced_Field extends RWMB_Media_Field {
|
|
72 |
}
|
73 |
|
74 |
/**
|
75 |
-
* Template for media item
|
76 |
-
*
|
77 |
-
* @return void
|
78 |
*/
|
79 |
public static function print_templates() {
|
80 |
parent::print_templates();
|
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 |
wp_enqueue_style( 'rwmb-image-advanced', RWMB_CSS_URL . 'image-advanced.css', array( 'rwmb-media' ), RWMB_VER );
|
18 |
wp_enqueue_script( 'rwmb-image-advanced', RWMB_JS_URL . 'image-advanced.js', array( 'rwmb-media' ), RWMB_VER, true );
|
19 |
}
|
20 |
|
21 |
/**
|
22 |
+
* Normalize parameters for field.
|
23 |
*
|
24 |
+
* @param array $field Field parameters.
|
25 |
*
|
26 |
* @return array
|
27 |
*/
|
28 |
+
public static function normalize( $field ) {
|
|
|
29 |
$field['mime_type'] = 'image';
|
30 |
+
$field = parent::normalize( $field );
|
31 |
+
|
32 |
return $field;
|
33 |
}
|
34 |
|
35 |
/**
|
36 |
* Get the field value.
|
37 |
*
|
38 |
+
* @param array $field Field parameters.
|
39 |
+
* @param array $args Additional arguments.
|
40 |
+
* @param null $post_id Post ID.
|
41 |
* @return mixed
|
42 |
*/
|
43 |
+
public static function get_value( $field, $args = array(), $post_id = null ) {
|
44 |
return RWMB_Image_Field::get_value( $field, $args, $post_id );
|
45 |
}
|
46 |
|
49 |
*
|
50 |
* @param int $file Attachment image ID (post ID). Required.
|
51 |
* @param array $args Array of arguments (for size).
|
52 |
+
* @return array|bool False if file not found. Array of image info on success.
|
53 |
*/
|
54 |
+
public static function file_info( $file, $args = array() ) {
|
55 |
return RWMB_Image_Field::file_info( $file, $args );
|
56 |
}
|
57 |
|
58 |
/**
|
59 |
* Format value for the helper functions.
|
60 |
*
|
61 |
+
* @param array $field Field parameters.
|
62 |
+
* @param string|array $value The field meta value.
|
63 |
* @return string
|
64 |
*/
|
65 |
public static function format_value( $field, $value ) {
|
69 |
/**
|
70 |
* Format a single value for the helper functions.
|
71 |
*
|
72 |
+
* @param array $field Field parameters.
|
73 |
+
* @param array $value The value.
|
74 |
* @return string
|
75 |
*/
|
76 |
public static function format_single_value( $field, $value ) {
|
78 |
}
|
79 |
|
80 |
/**
|
81 |
+
* Template for media item.
|
|
|
|
|
82 |
*/
|
83 |
public static function print_templates() {
|
84 |
parent::print_templates();
|
inc/fields/image-select.php
CHANGED
@@ -1,26 +1,30 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
-
*
|
5 |
*/
|
6 |
class RWMB_Image_Select_Field extends RWMB_Field {
|
7 |
-
|
8 |
/**
|
9 |
-
* Enqueue scripts and styles
|
10 |
*/
|
11 |
-
static function admin_enqueue_scripts() {
|
12 |
wp_enqueue_style( 'rwmb-image-select', RWMB_CSS_URL . 'image-select.css', array(), RWMB_VER );
|
13 |
wp_enqueue_script( 'rwmb-image-select', RWMB_JS_URL . 'image-select.js', array( 'jquery' ), RWMB_VER, true );
|
14 |
}
|
15 |
|
16 |
/**
|
17 |
-
* Get field HTML
|
18 |
*
|
19 |
-
* @param mixed $meta
|
20 |
-
* @param array $field
|
21 |
* @return string
|
22 |
*/
|
23 |
-
static function html( $meta, $field ) {
|
24 |
$html = array();
|
25 |
$tpl = '<label class="rwmb-image-select"><img src="%s"><input type="%s" class="rwmb-image_select hidden" name="%s" value="%s"%s></label>';
|
26 |
|
@@ -40,12 +44,12 @@ class RWMB_Image_Select_Field extends RWMB_Field {
|
|
40 |
}
|
41 |
|
42 |
/**
|
43 |
-
* Normalize parameters for field
|
44 |
*
|
45 |
-
* @param array $field
|
46 |
* @return array
|
47 |
*/
|
48 |
-
static function normalize( $field ) {
|
49 |
$field = parent::normalize( $field );
|
50 |
$field['field_name'] .= $field['multiple'] ? '[]' : '';
|
51 |
|
@@ -55,11 +59,11 @@ class RWMB_Image_Select_Field extends RWMB_Field {
|
|
55 |
/**
|
56 |
* Format a single value for the helper functions.
|
57 |
*
|
58 |
-
* @param array $field Field
|
59 |
-
* @param string $value The value
|
60 |
* @return string
|
61 |
*/
|
62 |
-
static function format_single_value( $field, $value ) {
|
63 |
return sprintf( '<img src="%s">', esc_url( $field['options'][ $value ] ) );
|
64 |
}
|
65 |
}
|
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 |
/**
|
21 |
+
* Get field HTML.
|
22 |
*
|
23 |
+
* @param mixed $meta Meta value.
|
24 |
+
* @param array $field Field parameters.
|
25 |
* @return string
|
26 |
*/
|
27 |
+
public static function html( $meta, $field ) {
|
28 |
$html = array();
|
29 |
$tpl = '<label class="rwmb-image-select"><img src="%s"><input type="%s" class="rwmb-image_select hidden" name="%s" value="%s"%s></label>';
|
30 |
|
44 |
}
|
45 |
|
46 |
/**
|
47 |
+
* Normalize parameters for field.
|
48 |
*
|
49 |
+
* @param array $field Field parameters.
|
50 |
* @return array
|
51 |
*/
|
52 |
+
public static function normalize( $field ) {
|
53 |
$field = parent::normalize( $field );
|
54 |
$field['field_name'] .= $field['multiple'] ? '[]' : '';
|
55 |
|
59 |
/**
|
60 |
* Format a single value for the helper functions.
|
61 |
*
|
62 |
+
* @param array $field Field parameters.
|
63 |
+
* @param string $value The meta value.
|
64 |
* @return string
|
65 |
*/
|
66 |
+
public static function format_single_value( $field, $value ) {
|
67 |
return sprintf( '<img src="%s">', esc_url( $field['options'][ $value ] ) );
|
68 |
}
|
69 |
}
|
inc/fields/image-upload.php
CHANGED
@@ -1,11 +1,16 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* File advanced field class which users WordPress media popup to upload and select files.
|
4 |
*/
|
5 |
class RWMB_Image_Upload_Field extends RWMB_Image_Advanced_Field {
|
6 |
-
|
7 |
/**
|
8 |
-
* Enqueue scripts and styles
|
9 |
*/
|
10 |
public static function admin_enqueue_scripts() {
|
11 |
parent::admin_enqueue_scripts();
|
@@ -14,7 +19,19 @@ class RWMB_Image_Upload_Field extends RWMB_Image_Advanced_Field {
|
|
14 |
}
|
15 |
|
16 |
/**
|
17 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
*/
|
19 |
public static function print_templates() {
|
20 |
parent::print_templates();
|
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();
|
19 |
}
|
20 |
|
21 |
/**
|
22 |
+
* Normalize parameters for field.
|
23 |
+
*
|
24 |
+
* @param array $field Field parameters.
|
25 |
+
*
|
26 |
+
* @return array
|
27 |
+
*/
|
28 |
+
public static function normalize( $field ) {
|
29 |
+
$field = parent::normalize( $field );
|
30 |
+
return RWMB_File_Upload_Field::normalize( $field );
|
31 |
+
}
|
32 |
+
|
33 |
+
/**
|
34 |
+
* Template for media item.
|
35 |
*/
|
36 |
public static function print_templates() {
|
37 |
parent::print_templates();
|
inc/fields/image.php
CHANGED
@@ -1,10 +1,14 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
* Image field class which uses <input type="file"> to upload.
|
5 |
*/
|
6 |
class RWMB_Image_Field extends RWMB_File_Field {
|
7 |
-
|
8 |
/**
|
9 |
* Enqueue scripts and styles.
|
10 |
*/
|
@@ -14,9 +18,9 @@ class RWMB_Image_Field extends RWMB_File_Field {
|
|
14 |
}
|
15 |
|
16 |
/**
|
17 |
-
* Get HTML markup for ONE uploaded image
|
18 |
*
|
19 |
-
* @param int $image Image ID
|
20 |
* @return string
|
21 |
*/
|
22 |
public static function file_html( $image ) {
|
@@ -39,8 +43,8 @@ class RWMB_Image_Field extends RWMB_File_Field {
|
|
39 |
/**
|
40 |
* Format a single value for the helper functions.
|
41 |
*
|
42 |
-
* @param array $field Field
|
43 |
-
* @param array $value The value
|
44 |
* @return string
|
45 |
*/
|
46 |
public static function format_single_value( $field, $value ) {
|
@@ -59,15 +63,16 @@ class RWMB_Image_Field extends RWMB_File_Field {
|
|
59 |
}
|
60 |
|
61 |
/**
|
62 |
-
* Get uploaded file information
|
63 |
*
|
64 |
* @param int $file Attachment image ID (post ID). Required.
|
65 |
* @param array $args Array of arguments (for size).
|
66 |
*
|
67 |
-
* @return array|bool False if file not found. Array of image info on success
|
68 |
*/
|
69 |
public static function file_info( $file, $args = array() ) {
|
70 |
-
|
|
|
71 |
return false;
|
72 |
}
|
73 |
|
@@ -93,7 +98,7 @@ class RWMB_Image_Field extends RWMB_File_Field {
|
|
93 |
|
94 |
$info = wp_parse_args( $info, wp_get_attachment_metadata( $file ) );
|
95 |
|
96 |
-
// Do not overwrite width and height by returned value of image meta
|
97 |
$info['width'] = $image[1];
|
98 |
$info['height'] = $image[2];
|
99 |
|
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 |
*/
|
18 |
}
|
19 |
|
20 |
/**
|
21 |
+
* Get HTML markup for ONE uploaded image.
|
22 |
*
|
23 |
+
* @param int $image Image ID.
|
24 |
* @return string
|
25 |
*/
|
26 |
public static function file_html( $image ) {
|
43 |
/**
|
44 |
* Format a single value for the helper functions.
|
45 |
*
|
46 |
+
* @param array $field Field parameters.
|
47 |
+
* @param array $value The value.
|
48 |
* @return string
|
49 |
*/
|
50 |
public static function format_single_value( $field, $value ) {
|
63 |
}
|
64 |
|
65 |
/**
|
66 |
+
* Get uploaded file information.
|
67 |
*
|
68 |
* @param int $file Attachment image ID (post ID). Required.
|
69 |
* @param array $args Array of arguments (for size).
|
70 |
*
|
71 |
+
* @return array|bool False if file not found. Array of image info on success.
|
72 |
*/
|
73 |
public static function file_info( $file, $args = array() ) {
|
74 |
+
$path = get_attached_file( $file );
|
75 |
+
if ( ! $path ) {
|
76 |
return false;
|
77 |
}
|
78 |
|
98 |
|
99 |
$info = wp_parse_args( $info, wp_get_attachment_metadata( $file ) );
|
100 |
|
101 |
+
// Do not overwrite width and height by returned value of image meta.
|
102 |
$info['width'] = $image[1];
|
103 |
$info['height'] = $image[2];
|
104 |
|
inc/fields/input-list.php
CHANGED
@@ -1,9 +1,14 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
*
|
|
|
|
|
4 |
*/
|
5 |
-
class RWMB_Input_List_Field extends RWMB_Choice_Field {
|
6 |
|
|
|
|
|
|
|
|
|
7 |
/**
|
8 |
* Enqueue scripts and styles
|
9 |
*/
|
@@ -13,12 +18,12 @@ class RWMB_Input_List_Field extends RWMB_Choice_Field {
|
|
13 |
}
|
14 |
|
15 |
/**
|
16 |
-
* Walk options
|
17 |
*
|
18 |
-
* @param
|
19 |
-
* @param
|
20 |
-
* @param mixed $
|
21 |
-
* @param mixed $
|
22 |
*
|
23 |
* @return string
|
24 |
*/
|
@@ -35,9 +40,9 @@ class RWMB_Input_List_Field extends RWMB_Choice_Field {
|
|
35 |
}
|
36 |
|
37 |
/**
|
38 |
-
* Normalize parameters for field
|
39 |
*
|
40 |
-
* @param array $field
|
41 |
* @return array
|
42 |
*/
|
43 |
public static function normalize( $field ) {
|
@@ -56,10 +61,10 @@ class RWMB_Input_List_Field extends RWMB_Choice_Field {
|
|
56 |
}
|
57 |
|
58 |
/**
|
59 |
-
* Get the attributes for a field
|
60 |
*
|
61 |
-
* @param array $field
|
62 |
-
* @param mixed $value
|
63 |
*
|
64 |
* @return array
|
65 |
*/
|
1 |
<?php
|
2 |
/**
|
3 |
+
* The input list field which displays choices in a list of inputs.
|
4 |
+
*
|
5 |
+
* @package Meta Box
|
6 |
*/
|
|
|
7 |
|
8 |
+
/**
|
9 |
+
* Input list field class.
|
10 |
+
*/
|
11 |
+
class RWMB_Input_List_Field extends RWMB_Choice_Field {
|
12 |
/**
|
13 |
* Enqueue scripts and styles
|
14 |
*/
|
18 |
}
|
19 |
|
20 |
/**
|
21 |
+
* Walk options.
|
22 |
*
|
23 |
+
* @param array $field Field parameters.
|
24 |
+
* @param mixed $options Select options.
|
25 |
+
* @param mixed $db_fields Database fields to use in the output.
|
26 |
+
* @param mixed $meta Meta value.
|
27 |
*
|
28 |
* @return string
|
29 |
*/
|
40 |
}
|
41 |
|
42 |
/**
|
43 |
+
* Normalize parameters for field.
|
44 |
*
|
45 |
+
* @param array $field Field parameters.
|
46 |
* @return array
|
47 |
*/
|
48 |
public static function normalize( $field ) {
|
61 |
}
|
62 |
|
63 |
/**
|
64 |
+
* Get the attributes for a field.
|
65 |
*
|
66 |
+
* @param array $field Field parameters.
|
67 |
+
* @param mixed $value Meta value.
|
68 |
*
|
69 |
* @return array
|
70 |
*/
|
inc/fields/input.php
CHANGED
@@ -1,15 +1,19 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
-
* Abstract input field class
|
5 |
*/
|
6 |
abstract class RWMB_Input_Field extends RWMB_Field {
|
7 |
-
|
8 |
/**
|
9 |
-
* Get field HTML
|
10 |
*
|
11 |
-
* @param mixed $meta
|
12 |
-
* @param array $field
|
13 |
* @return string
|
14 |
*/
|
15 |
public static function html( $meta, $field ) {
|
@@ -18,14 +22,15 @@ abstract class RWMB_Input_Field extends RWMB_Field {
|
|
18 |
}
|
19 |
|
20 |
/**
|
21 |
-
* Normalize parameters for field
|
22 |
*
|
23 |
-
* @param array $field
|
24 |
* @return array
|
25 |
*/
|
26 |
public static function normalize( $field ) {
|
27 |
$field = parent::normalize( $field );
|
28 |
$field = wp_parse_args( $field, array(
|
|
|
29 |
'datalist' => false,
|
30 |
'readonly' => false,
|
31 |
) );
|
@@ -39,10 +44,10 @@ abstract class RWMB_Input_Field extends RWMB_Field {
|
|
39 |
}
|
40 |
|
41 |
/**
|
42 |
-
* Get the attributes for a field
|
43 |
*
|
44 |
-
* @param array $field
|
45 |
-
* @param mixed $value
|
46 |
* @return array
|
47 |
*/
|
48 |
public static function get_attributes( $field, $value = null ) {
|
@@ -53,6 +58,7 @@ abstract class RWMB_Input_Field extends RWMB_Field {
|
|
53 |
'value' => $value,
|
54 |
'placeholder' => $field['placeholder'],
|
55 |
'type' => $field['type'],
|
|
|
56 |
) );
|
57 |
|
58 |
return $attributes;
|
@@ -61,8 +67,8 @@ abstract class RWMB_Input_Field extends RWMB_Field {
|
|
61 |
/**
|
62 |
* Create datalist, if any.
|
63 |
*
|
64 |
-
* @param array $field
|
65 |
-
* @return
|
66 |
*/
|
67 |
protected static function datalist( $field ) {
|
68 |
if ( empty( $field['datalist'] ) ) {
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* The abstract input field which is used for all <input> fields.
|
4 |
+
*
|
5 |
+
* @package Meta Box
|
6 |
+
*/
|
7 |
|
8 |
/**
|
9 |
+
* Abstract input field class.
|
10 |
*/
|
11 |
abstract class RWMB_Input_Field extends RWMB_Field {
|
|
|
12 |
/**
|
13 |
+
* Get field HTML.
|
14 |
*
|
15 |
+
* @param mixed $meta Meta value.
|
16 |
+
* @param array $field Field parameters.
|
17 |
* @return string
|
18 |
*/
|
19 |
public static function html( $meta, $field ) {
|
22 |
}
|
23 |
|
24 |
/**
|
25 |
+
* Normalize parameters for field.
|
26 |
*
|
27 |
+
* @param array $field Field parameters.
|
28 |
* @return array
|
29 |
*/
|
30 |
public static function normalize( $field ) {
|
31 |
$field = parent::normalize( $field );
|
32 |
$field = wp_parse_args( $field, array(
|
33 |
+
'size' => 30,
|
34 |
'datalist' => false,
|
35 |
'readonly' => false,
|
36 |
) );
|
44 |
}
|
45 |
|
46 |
/**
|
47 |
+
* Get the attributes for a field.
|
48 |
*
|
49 |
+
* @param array $field Field parameters.
|
50 |
+
* @param mixed $value Meta value.
|
51 |
* @return array
|
52 |
*/
|
53 |
public static function get_attributes( $field, $value = null ) {
|
58 |
'value' => $value,
|
59 |
'placeholder' => $field['placeholder'],
|
60 |
'type' => $field['type'],
|
61 |
+
'size' => $field['size'],
|
62 |
) );
|
63 |
|
64 |
return $attributes;
|
67 |
/**
|
68 |
* Create datalist, if any.
|
69 |
*
|
70 |
+
* @param array $field Field parameters.
|
71 |
+
* @return string
|
72 |
*/
|
73 |
protected static function datalist( $field ) {
|
74 |
if ( empty( $field['datalist'] ) ) {
|
inc/fields/key-value.php
CHANGED
@@ -1,25 +1,29 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
* Key-value field class.
|
5 |
*/
|
6 |
-
|
7 |
-
|
8 |
/**
|
9 |
-
* Get field HTML
|
10 |
*
|
11 |
-
* @param mixed $meta
|
12 |
-
* @param array $field
|
13 |
* @return string
|
14 |
*/
|
15 |
-
static function html( $meta, $field ) {
|
16 |
-
// Key
|
17 |
$key = isset( $meta[0] ) ? $meta[0] : '';
|
18 |
$attributes = self::get_attributes( $field, $key );
|
19 |
$attributes['placeholder'] = $field['placeholder']['key'];
|
20 |
$html = sprintf( '<input %s>', self::render_attributes( $attributes ) );
|
21 |
|
22 |
-
// Value
|
23 |
$val = isset( $meta[1] ) ? $meta[1] : '';
|
24 |
$attributes = self::get_attributes( $field, $val );
|
25 |
$attributes['placeholder'] = $field['placeholder']['value'];
|
@@ -29,13 +33,13 @@ abstract class RWMB_Key_Value_Field extends RWMB_Text_Field {
|
|
29 |
}
|
30 |
|
31 |
/**
|
32 |
-
* Show begin HTML markup for fields
|
33 |
*
|
34 |
-
* @param mixed $meta
|
35 |
-
* @param array $field
|
36 |
* @return string
|
37 |
*/
|
38 |
-
static function begin_html( $meta, $field ) {
|
39 |
$desc = $field['desc'] ? "<p id='{$field['id']}_description' class='description'>{$field['desc']}</p>" : '';
|
40 |
|
41 |
if ( empty( $field['name'] ) ) {
|
@@ -57,7 +61,7 @@ abstract class RWMB_Key_Value_Field extends RWMB_Text_Field {
|
|
57 |
/**
|
58 |
* Do not show field description.
|
59 |
*
|
60 |
-
* @param array $field
|
61 |
* @return string
|
62 |
*/
|
63 |
public static function element_description( $field ) {
|
@@ -65,12 +69,12 @@ abstract class RWMB_Key_Value_Field extends RWMB_Text_Field {
|
|
65 |
}
|
66 |
|
67 |
/**
|
68 |
-
* Escape meta for field output
|
69 |
*
|
70 |
-
* @param mixed $meta
|
71 |
* @return mixed
|
72 |
*/
|
73 |
-
static function esc_meta( $meta ) {
|
74 |
foreach ( (array) $meta as $k => $pairs ) {
|
75 |
$meta[ $k ] = array_map( 'esc_attr', (array) $pairs );
|
76 |
}
|
@@ -80,14 +84,14 @@ abstract class RWMB_Key_Value_Field extends RWMB_Text_Field {
|
|
80 |
/**
|
81 |
* Sanitize field value.
|
82 |
*
|
83 |
-
* @param mixed $new
|
84 |
-
* @param mixed $old
|
85 |
-
* @param int $post_id
|
86 |
-
* @param array $field
|
87 |
*
|
88 |
* @return string
|
89 |
*/
|
90 |
-
static function value( $new, $old, $post_id, $field ) {
|
91 |
foreach ( $new as &$arr ) {
|
92 |
if ( empty( $arr[0] ) && empty( $arr[1] ) ) {
|
93 |
$arr = false;
|
@@ -98,19 +102,19 @@ abstract class RWMB_Key_Value_Field extends RWMB_Text_Field {
|
|
98 |
}
|
99 |
|
100 |
/**
|
101 |
-
* Normalize parameters for field
|
102 |
*
|
103 |
-
* @param array $field
|
104 |
* @return array
|
105 |
*/
|
106 |
-
static function normalize( $field ) {
|
107 |
$field = parent::normalize( $field );
|
108 |
$field['clone'] = true;
|
109 |
$field['multiple'] = true;
|
110 |
$field['attributes']['type'] = 'text';
|
111 |
$field['placeholder'] = wp_parse_args( (array) $field['placeholder'], array(
|
112 |
-
'key' => 'Key',
|
113 |
-
'value' => 'Value',
|
114 |
) );
|
115 |
return $field;
|
116 |
}
|
@@ -118,8 +122,8 @@ abstract class RWMB_Key_Value_Field extends RWMB_Text_Field {
|
|
118 |
/**
|
119 |
* Format value for the helper functions.
|
120 |
*
|
121 |
-
* @param array $field Field
|
122 |
-
* @param string|array $value The field meta value
|
123 |
* @return string
|
124 |
*/
|
125 |
public static function format_value( $field, $value ) {
|
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_Text_Field {
|
|
|
12 |
/**
|
13 |
+
* Get field HTML.
|
14 |
*
|
15 |
+
* @param mixed $meta Meta value.
|
16 |
+
* @param array $field Field parameters.
|
17 |
* @return string
|
18 |
*/
|
19 |
+
public static function html( $meta, $field ) {
|
20 |
+
// Key.
|
21 |
$key = isset( $meta[0] ) ? $meta[0] : '';
|
22 |
$attributes = self::get_attributes( $field, $key );
|
23 |
$attributes['placeholder'] = $field['placeholder']['key'];
|
24 |
$html = sprintf( '<input %s>', self::render_attributes( $attributes ) );
|
25 |
|
26 |
+
// Value.
|
27 |
$val = isset( $meta[1] ) ? $meta[1] : '';
|
28 |
$attributes = self::get_attributes( $field, $val );
|
29 |
$attributes['placeholder'] = $field['placeholder']['value'];
|
33 |
}
|
34 |
|
35 |
/**
|
36 |
+
* Show begin HTML markup for fields.
|
37 |
*
|
38 |
+
* @param mixed $meta Meta value.
|
39 |
+
* @param array $field Field parameters.
|
40 |
* @return string
|
41 |
*/
|
42 |
+
public static function begin_html( $meta, $field ) {
|
43 |
$desc = $field['desc'] ? "<p id='{$field['id']}_description' class='description'>{$field['desc']}</p>" : '';
|
44 |
|
45 |
if ( empty( $field['name'] ) ) {
|
61 |
/**
|
62 |
* Do not show field description.
|
63 |
*
|
64 |
+
* @param array $field Field parameters.
|
65 |
* @return string
|
66 |
*/
|
67 |
public static function element_description( $field ) {
|
69 |
}
|
70 |
|
71 |
/**
|
72 |
+
* Escape meta for field output.
|
73 |
*
|
74 |
+
* @param mixed $meta Meta value.
|
75 |
* @return mixed
|
76 |
*/
|
77 |
+
public static function esc_meta( $meta ) {
|
78 |
foreach ( (array) $meta as $k => $pairs ) {
|
79 |
$meta[ $k ] = array_map( 'esc_attr', (array) $pairs );
|
80 |
}
|
84 |
/**
|
85 |
* Sanitize field value.
|
86 |
*
|
87 |
+
* @param mixed $new The submitted meta value.
|
88 |
+
* @param mixed $old The existing meta value.
|
89 |
+
* @param int $post_id The post ID.
|
90 |
+
* @param array $field The field parameters.
|
91 |
*
|
92 |
* @return string
|
93 |
*/
|
94 |
+
public static function value( $new, $old, $post_id, $field ) {
|
95 |
foreach ( $new as &$arr ) {
|
96 |
if ( empty( $arr[0] ) && empty( $arr[1] ) ) {
|
97 |
$arr = false;
|
102 |
}
|
103 |
|
104 |
/**
|
105 |
+
* Normalize parameters for field.
|
106 |
*
|
107 |
+
* @param array $field Field parameters.
|
108 |
* @return array
|
109 |
*/
|
110 |
+
public static function normalize( $field ) {
|
111 |
$field = parent::normalize( $field );
|
112 |
$field['clone'] = true;
|
113 |
$field['multiple'] = true;
|
114 |
$field['attributes']['type'] = 'text';
|
115 |
$field['placeholder'] = wp_parse_args( (array) $field['placeholder'], array(
|
116 |
+
'key' => __( 'Key', 'meta-box' ),
|
117 |
+
'value' => __( 'Value', 'meta-box' ),
|
118 |
) );
|
119 |
return $field;
|
120 |
}
|
122 |
/**
|
123 |
* Format value for the helper functions.
|
124 |
*
|
125 |
+
* @param array $field Field parameters.
|
126 |
+
* @param string|array $value The field meta value.
|
127 |
* @return string
|
128 |
*/
|
129 |
public static function format_value( $field, $value ) {
|
inc/fields/map.php
CHANGED
@@ -1,15 +1,18 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Map field class.
|
4 |
*/
|
5 |
class RWMB_Map_Field extends RWMB_Field {
|
6 |
-
|
7 |
/**
|
8 |
-
* Enqueue scripts and styles
|
9 |
-
*
|
10 |
-
* @return void
|
11 |
*/
|
12 |
-
static function admin_enqueue_scripts() {
|
13 |
/**
|
14 |
* Since June 2016, Google Maps requires a valid API key.
|
15 |
*
|
@@ -32,14 +35,14 @@ class RWMB_Map_Field extends RWMB_Field {
|
|
32 |
}
|
33 |
|
34 |
/**
|
35 |
-
* Get field HTML
|
36 |
*
|
37 |
-
* @param mixed $meta
|
38 |
-
* @param array $field
|
39 |
*
|
40 |
* @return string
|
41 |
*/
|
42 |
-
static function html( $meta, $field ) {
|
43 |
$html = '<div class="rwmb-map-field">';
|
44 |
|
45 |
$html .= sprintf(
|
@@ -50,7 +53,8 @@ class RWMB_Map_Field extends RWMB_Field {
|
|
50 |
esc_attr( $meta )
|
51 |
);
|
52 |
|
53 |
-
|
|
|
54 |
$html .= sprintf(
|
55 |
'<button class="button rwmb-map-goto-address-button" value="%s">%s</button>',
|
56 |
is_array( $address ) ? implode( ',', $address ) : $address,
|
@@ -64,13 +68,13 @@ class RWMB_Map_Field extends RWMB_Field {
|
|
64 |
}
|
65 |
|
66 |
/**
|
67 |
-
* Normalize parameters for field
|
68 |
*
|
69 |
-
* @param array $field
|
70 |
*
|
71 |
* @return array
|
72 |
*/
|
73 |
-
static function normalize( $field ) {
|
74 |
$field = parent::normalize( $field );
|
75 |
$field = wp_parse_args( $field, array(
|
76 |
'std' => '',
|
@@ -85,33 +89,33 @@ class RWMB_Map_Field extends RWMB_Field {
|
|
85 |
}
|
86 |
|
87 |
/**
|
88 |
-
* Get the field value
|
89 |
* The difference between this function and 'meta' function is 'meta' function always returns the escaped value
|
90 |
-
* of the field saved in the database, while this function returns more meaningful value of the field
|
91 |
*
|
92 |
-
* @param array $field Field parameters
|
93 |
-
* @param array $args Not used for this field
|
94 |
* @param int|null $post_id Post ID. null for current post. Optional.
|
95 |
*
|
96 |
* @return mixed Array(latitude, longitude, zoom)
|
97 |
*/
|
98 |
-
static function get_value( $field, $args = array(), $post_id = null ) {
|
99 |
$value = parent::get_value( $field, $args, $post_id );
|
100 |
list( $latitude, $longitude, $zoom ) = explode( ',', $value . ',,' );
|
101 |
return compact( 'latitude', 'longitude', 'zoom' );
|
102 |
}
|
103 |
|
104 |
/**
|
105 |
-
* Output the field value
|
106 |
-
* Display Google maps
|
107 |
*
|
108 |
-
* @param array $field Field parameters
|
109 |
* @param array $args Additional arguments. Not used for these fields.
|
110 |
* @param int|null $post_id Post ID. null for current post. Optional.
|
111 |
*
|
112 |
* @return mixed Field value
|
113 |
*/
|
114 |
-
static function the_value( $field, $args = array(), $post_id = null ) {
|
115 |
$value = self::get_value( $field, $args, $post_id );
|
116 |
if ( ! $value['latitude'] || ! $value['longitude'] ) {
|
117 |
return '';
|
@@ -126,8 +130,8 @@ class RWMB_Map_Field extends RWMB_Field {
|
|
126 |
'width' => '100%',
|
127 |
'height' => '480px',
|
128 |
'marker' => true, // Display marker?
|
129 |
-
'marker_title' => '', // Marker title, when hover
|
130 |
-
'info_window' => '', // Content of info window (when click on marker). HTML allowed
|
131 |
'js_options' => array(),
|
132 |
|
133 |
// Default API key, required by Google Maps since June 2016.
|
@@ -136,9 +140,9 @@ class RWMB_Map_Field extends RWMB_Field {
|
|
136 |
) );
|
137 |
|
138 |
/*
|
139 |
-
* Enqueue scripts
|
140 |
-
* API key is get from $field (if found by RWMB_Helper::find_field()) or $args as a fallback
|
141 |
-
* Note: We still can enqueue script which outputs in the footer
|
142 |
*/
|
143 |
$api_key = isset( $field['api_key'] ) ? $field['api_key'] : $args['api_key'];
|
144 |
$google_maps_url = add_query_arg( 'key', $api_key, 'https://maps.google.com/maps/api/js' );
|
@@ -152,16 +156,16 @@ class RWMB_Map_Field extends RWMB_Field {
|
|
152 |
wp_enqueue_script( 'rwmb-map-frontend', RWMB_JS_URL . 'map-frontend.js', array( 'google-maps' ), '', true );
|
153 |
|
154 |
/*
|
155 |
-
* Google Maps options
|
156 |
-
* Option name is the same as specified in Google Maps documentation
|
157 |
-
* This array will be convert to Javascript Object and pass as map options
|
158 |
* @link https://developers.google.com/maps/documentation/javascript/reference
|
159 |
*/
|
160 |
$args['js_options'] = wp_parse_args( $args['js_options'], array(
|
161 |
-
// Default to 'zoom' level set in admin, but can be overwritten
|
162 |
'zoom' => $value['zoom'],
|
163 |
|
164 |
-
// Map type, see https://developers.google.com/maps/documentation/javascript/reference#MapTypeId
|
165 |
'mapTypeId' => 'ROADMAP',
|
166 |
) );
|
167 |
|
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 |
/**
|
17 |
* Since June 2016, Google Maps requires a valid API key.
|
18 |
*
|
35 |
}
|
36 |
|
37 |
/**
|
38 |
+
* Get field HTML.
|
39 |
*
|
40 |
+
* @param mixed $meta Meta value.
|
41 |
+
* @param array $field Field parameters.
|
42 |
*
|
43 |
* @return string
|
44 |
*/
|
45 |
+
public static function html( $meta, $field ) {
|
46 |
$html = '<div class="rwmb-map-field">';
|
47 |
|
48 |
$html .= sprintf(
|
53 |
esc_attr( $meta )
|
54 |
);
|
55 |
|
56 |
+
$address = $field['address_field'];
|
57 |
+
if ( $address ) {
|
58 |
$html .= sprintf(
|
59 |
'<button class="button rwmb-map-goto-address-button" value="%s">%s</button>',
|
60 |
is_array( $address ) ? implode( ',', $address ) : $address,
|
68 |
}
|
69 |
|
70 |
/**
|
71 |
+
* Normalize parameters for field.
|
72 |
*
|
73 |
+
* @param array $field Field parameters.
|
74 |
*
|
75 |
* @return array
|
76 |
*/
|
77 |
+
public static function normalize( $field ) {
|
78 |
$field = parent::normalize( $field );
|
79 |
$field = wp_parse_args( $field, array(
|
80 |
'std' => '',
|
89 |
}
|
90 |
|
91 |
/**
|
92 |
+
* Get the field value.
|
93 |
* The difference between this function and 'meta' function is 'meta' function always returns the escaped value
|
94 |
+
* of the field saved in the database, while this function returns more meaningful value of the field.
|
95 |
*
|
96 |
+
* @param array $field Field parameters.
|
97 |
+
* @param array $args Not used for this field.
|
98 |
* @param int|null $post_id Post ID. null for current post. Optional.
|
99 |
*
|
100 |
* @return mixed Array(latitude, longitude, zoom)
|
101 |
*/
|
102 |
+
public static function get_value( $field, $args = array(), $post_id = null ) {
|
103 |
$value = parent::get_value( $field, $args, $post_id );
|
104 |
list( $latitude, $longitude, $zoom ) = explode( ',', $value . ',,' );
|
105 |
return compact( 'latitude', 'longitude', 'zoom' );
|
106 |
}
|
107 |
|
108 |
/**
|
109 |
+
* Output the field value.
|
110 |
+
* Display Google maps.
|
111 |
*
|
112 |
+
* @param array $field Field parameters.
|
113 |
* @param array $args Additional arguments. Not used for these fields.
|
114 |
* @param int|null $post_id Post ID. null for current post. Optional.
|
115 |
*
|
116 |
* @return mixed Field value
|
117 |
*/
|
118 |
+
public static function the_value( $field, $args = array(), $post_id = null ) {
|
119 |
$value = self::get_value( $field, $args, $post_id );
|
120 |
if ( ! $value['latitude'] || ! $value['longitude'] ) {
|
121 |
return '';
|
130 |
'width' => '100%',
|
131 |
'height' => '480px',
|
132 |
'marker' => true, // Display marker?
|
133 |
+
'marker_title' => '', // Marker title, when hover.
|
134 |
+
'info_window' => '', // Content of info window (when click on marker). HTML allowed.
|
135 |
'js_options' => array(),
|
136 |
|
137 |
// Default API key, required by Google Maps since June 2016.
|
140 |
) );
|
141 |
|
142 |
/*
|
143 |
+
* Enqueue scripts.
|
144 |
+
* API key is get from $field (if found by RWMB_Helper::find_field()) or $args as a fallback.
|
145 |
+
* Note: We still can enqueue script which outputs in the footer.
|
146 |
*/
|
147 |
$api_key = isset( $field['api_key'] ) ? $field['api_key'] : $args['api_key'];
|
148 |
$google_maps_url = add_query_arg( 'key', $api_key, 'https://maps.google.com/maps/api/js' );
|
156 |
wp_enqueue_script( 'rwmb-map-frontend', RWMB_JS_URL . 'map-frontend.js', array( 'google-maps' ), '', true );
|
157 |
|
158 |
/*
|
159 |
+
* Google Maps options.
|
160 |
+
* Option name is the same as specified in Google Maps documentation.
|
161 |
+
* This array will be convert to Javascript Object and pass as map options.
|
162 |
* @link https://developers.google.com/maps/documentation/javascript/reference
|
163 |
*/
|
164 |
$args['js_options'] = wp_parse_args( $args['js_options'], array(
|
165 |
+
// Default to 'zoom' level set in admin, but can be overwritten.
|
166 |
'zoom' => $value['zoom'],
|
167 |
|
168 |
+
// Map type, see https://developers.google.com/maps/documentation/javascript/reference#MapTypeId.
|
169 |
'mapTypeId' => 'ROADMAP',
|
170 |
) );
|
171 |
|
inc/fields/media.php
CHANGED
@@ -1,12 +1,16 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
/**
|
4 |
* Media field class which users WordPress media popup to upload and select files.
|
|
|
|
|
5 |
*/
|
6 |
-
class RWMB_Media_Field extends RWMB_File_Field {
|
7 |
|
|
|
|
|
|
|
|
|
8 |
/**
|
9 |
-
* Enqueue scripts and styles
|
10 |
*/
|
11 |
public static function admin_enqueue_scripts() {
|
12 |
wp_enqueue_media();
|
@@ -30,7 +34,7 @@ class RWMB_Media_Field extends RWMB_File_Field {
|
|
30 |
}
|
31 |
|
32 |
/**
|
33 |
-
* Add actions
|
34 |
*/
|
35 |
public static function add_actions() {
|
36 |
$args = func_get_args();
|
@@ -39,35 +43,32 @@ class RWMB_Media_Field extends RWMB_File_Field {
|
|
39 |
}
|
40 |
|
41 |
/**
|
42 |
-
* Get field HTML
|
43 |
*
|
44 |
-
* @param mixed $meta
|
45 |
-
* @param array $field
|
46 |
*
|
47 |
* @return string
|
48 |
*/
|
49 |
public static function html( $meta, $field ) {
|
50 |
$meta = (array) $meta;
|
51 |
$meta = implode( ',', $meta );
|
52 |
-
$attributes =
|
53 |
|
54 |
$html = sprintf(
|
55 |
'<input %s>
|
56 |
-
<div class="rwmb-media-view" data-
|
57 |
self::render_attributes( $attributes ),
|
58 |
-
$field['
|
59 |
-
$field['max_file_uploads'],
|
60 |
-
$field['force_delete'] ? 'true' : 'false',
|
61 |
-
$field['max_status']
|
62 |
);
|
63 |
|
64 |
return $html;
|
65 |
}
|
66 |
|
67 |
/**
|
68 |
-
* Normalize parameters for field
|
69 |
*
|
70 |
-
* @param array $field
|
71 |
*
|
72 |
* @return array
|
73 |
*/
|
@@ -79,6 +80,14 @@ class RWMB_Media_Field extends RWMB_File_Field {
|
|
79 |
'max_file_uploads' => 0,
|
80 |
'force_delete' => false,
|
81 |
'max_status' => true,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
) );
|
83 |
|
84 |
$field['multiple'] = true;
|
@@ -87,10 +96,10 @@ class RWMB_Media_Field extends RWMB_File_Field {
|
|
87 |
}
|
88 |
|
89 |
/**
|
90 |
-
* Get the attributes for a field
|
91 |
*
|
92 |
-
* @param array $field
|
93 |
-
* @param mixed $value
|
94 |
*
|
95 |
* @return array
|
96 |
*/
|
@@ -121,20 +130,20 @@ class RWMB_Media_Field extends RWMB_File_Field {
|
|
121 |
if ( empty( $extensions[ $mime_parts[0] ] ) ) {
|
122 |
$extensions[ $mime_parts[0] ] = array();
|
123 |
}
|
124 |
-
$extensions[ $mime_parts[0] ]
|
125 |
-
|
126 |
}
|
127 |
|
128 |
return $extensions;
|
129 |
}
|
130 |
|
131 |
/**
|
132 |
-
* Get meta values to save
|
133 |
*
|
134 |
-
* @param mixed $new
|
135 |
-
* @param mixed $old
|
136 |
-
* @param int $post_id
|
137 |
-
* @param array $field
|
138 |
*
|
139 |
* @return array|mixed
|
140 |
*/
|
@@ -144,12 +153,12 @@ class RWMB_Media_Field extends RWMB_File_Field {
|
|
144 |
}
|
145 |
|
146 |
/**
|
147 |
-
* Save meta value
|
148 |
*
|
149 |
-
* @param $new
|
150 |
-
* @param $old
|
151 |
-
* @param $post_id
|
152 |
-
* @param $field
|
153 |
*/
|
154 |
public static function save( $new, $old, $post_id, $field ) {
|
155 |
delete_post_meta( $post_id, $field['id'] );
|
@@ -157,7 +166,7 @@ class RWMB_Media_Field extends RWMB_File_Field {
|
|
157 |
}
|
158 |
|
159 |
/**
|
160 |
-
* Template for media item
|
161 |
*/
|
162 |
public static function print_templates() {
|
163 |
require_once RWMB_INC_DIR . 'templates/media.php';
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
* Media field class which users WordPress media popup to upload and select files.
|
4 |
+
*
|
5 |
+
* @package Meta Box
|
6 |
*/
|
|
|
7 |
|
8 |
+
/**
|
9 |
+
* The media field class.
|
10 |
+
*/
|
11 |
+
class RWMB_Media_Field extends RWMB_File_Field {
|
12 |
/**
|
13 |
+
* Enqueue scripts and styles.
|
14 |
*/
|
15 |
public static function admin_enqueue_scripts() {
|
16 |
wp_enqueue_media();
|
34 |
}
|
35 |
|
36 |
/**
|
37 |
+
* Add actions.
|
38 |
*/
|
39 |
public static function add_actions() {
|
40 |
$args = func_get_args();
|
43 |
}
|
44 |
|
45 |
/**
|
46 |
+
* Get field HTML.
|
47 |
*
|
48 |
+
* @param mixed $meta Meta value.
|
49 |
+
* @param array $field Field parameters.
|
50 |
*
|
51 |
* @return string
|
52 |
*/
|
53 |
public static function html( $meta, $field ) {
|
54 |
$meta = (array) $meta;
|
55 |
$meta = implode( ',', $meta );
|
56 |
+
$attributes = self::get_attributes( $field, $meta );
|
57 |
|
58 |
$html = sprintf(
|
59 |
'<input %s>
|
60 |
+
<div class="rwmb-media-view" data-options="%s"></div>',
|
61 |
self::render_attributes( $attributes ),
|
62 |
+
esc_attr( wp_json_encode( $field['js_options'] ) )
|
|
|
|
|
|
|
63 |
);
|
64 |
|
65 |
return $html;
|
66 |
}
|
67 |
|
68 |
/**
|
69 |
+
* Normalize parameters for field.
|
70 |
*
|
71 |
+
* @param array $field Field parameters.
|
72 |
*
|
73 |
* @return array
|
74 |
*/
|
80 |
'max_file_uploads' => 0,
|
81 |
'force_delete' => false,
|
82 |
'max_status' => true,
|
83 |
+
'js_options' => array(),
|
84 |
+
) );
|
85 |
+
|
86 |
+
$field['js_options'] = wp_parse_args( $field['js_options'], array(
|
87 |
+
'mimeType' => $field['mime_type'],
|
88 |
+
'maxFileUploads' => $field['max_file_uploads'],
|
89 |
+
'forceDelete' => $field['force_delete'] ? 'true' : 'false',
|
90 |
+
'maxStatus' => $field['max_status'],
|
91 |
) );
|
92 |
|
93 |
$field['multiple'] = true;
|
96 |
}
|
97 |
|
98 |
/**
|
99 |
+
* Get the attributes for a field.
|
100 |
*
|
101 |
+
* @param array $field Field parameters.
|
102 |
+
* @param mixed $value Meta value.
|
103 |
*
|
104 |
* @return array
|
105 |
*/
|
130 |
if ( empty( $extensions[ $mime_parts[0] ] ) ) {
|
131 |
$extensions[ $mime_parts[0] ] = array();
|
132 |
}
|
133 |
+
$extensions[ $mime_parts[0] ] = array_merge( $extensions[ $mime_parts[0] ], $ext );
|
134 |
+
$extensions[ $mime_parts[0] . '/*' ] = $extensions[ $mime_parts[0] ];
|
135 |
}
|
136 |
|
137 |
return $extensions;
|
138 |
}
|
139 |
|
140 |
/**
|
141 |
+
* Get meta values to save.
|
142 |
*
|
143 |
+
* @param mixed $new The submitted meta value.
|
144 |
+
* @param mixed $old The existing meta value.
|
145 |
+
* @param int $post_id The post ID.
|
146 |
+
* @param array $field The field parameters.
|
147 |
*
|
148 |
* @return array|mixed
|
149 |
*/
|
153 |
}
|
154 |
|
155 |
/**
|
156 |
+
* Save meta value.
|
157 |
*
|
158 |
+
* @param mixed $new The submitted meta value.
|
159 |
+
* @param mixed $old The existing meta value.
|
160 |
+
* @param int $post_id The post ID.
|
161 |
+
* @param array $field The field parameters.
|
162 |
*/
|
163 |
public static function save( $new, $old, $post_id, $field ) {
|
164 |
delete_post_meta( $post_id, $field['id'] );
|
166 |
}
|
167 |
|
168 |
/**
|
169 |
+
* Template for media item.
|
170 |
*/
|
171 |
public static function print_templates() {
|
172 |
require_once RWMB_INC_DIR . 'templates/media.php';
|
inc/fields/multiple-values.php
CHANGED
@@ -7,17 +7,22 @@
|
|
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 |
|
|
|
|
|
|
|
|
|
13 |
/**
|
14 |
-
* Normalize parameters for field
|
15 |
*
|
16 |
-
* @param array $field
|
17 |
*
|
18 |
* @return array
|
19 |
*/
|
20 |
-
static function normalize( $field ) {
|
21 |
$field = parent::normalize( $field );
|
22 |
$field['multiple'] = true;
|
23 |
$field['field_name'] = $field['id'];
|
@@ -31,11 +36,11 @@ abstract class RWMB_Multiple_Values_Field extends RWMB_Field {
|
|
31 |
/**
|
32 |
* Format a single value for the helper functions.
|
33 |
*
|
34 |
-
* @param array $field Field
|
35 |
-
* @param string $value The value
|
36 |
* @return string
|
37 |
*/
|
38 |
-
static function format_single_value( $field, $value ) {
|
39 |
return $field['options'][ $value ];
|
40 |
}
|
41 |
}
|
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 |
/**
|
19 |
+
* Normalize parameters for field.
|
20 |
*
|
21 |
+
* @param array $field Field parameters.
|
22 |
*
|
23 |
* @return array
|
24 |
*/
|
25 |
+
public static function normalize( $field ) {
|
26 |
$field = parent::normalize( $field );
|
27 |
$field['multiple'] = true;
|
28 |
$field['field_name'] = $field['id'];
|
36 |
/**
|
37 |
* Format a single value for the helper functions.
|
38 |
*
|
39 |
+
* @param array $field Field parameters.
|
40 |
+
* @param string $value The value.
|
41 |
* @return string
|
42 |
*/
|
43 |
+
public static function format_single_value( $field, $value ) {
|
44 |
return $field['options'][ $value ];
|
45 |
}
|
46 |
}
|
inc/fields/number.php
CHANGED
@@ -1,17 +1,22 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Number field class.
|
4 |
*/
|
5 |
class RWMB_Number_Field extends RWMB_Input_Field {
|
6 |
-
|
7 |
/**
|
8 |
-
* Normalize parameters for field
|
9 |
*
|
10 |
-
* @param array $field
|
11 |
*
|
12 |
* @return array
|
13 |
*/
|
14 |
-
static function normalize( $field ) {
|
15 |
$field = parent::normalize( $field );
|
16 |
|
17 |
$field = wp_parse_args( $field, array(
|
@@ -24,14 +29,14 @@ class RWMB_Number_Field extends RWMB_Input_Field {
|
|
24 |
}
|
25 |
|
26 |
/**
|
27 |
-
* Get the attributes for a field
|
28 |
*
|
29 |
-
* @param array $field
|
30 |
-
* @param mixed $value
|
31 |
*
|
32 |
* @return array
|
33 |
*/
|
34 |
-
static function get_attributes( $field, $value = null ) {
|
35 |
$attributes = parent::get_attributes( $field, $value );
|
36 |
$attributes = wp_parse_args( $attributes, array(
|
37 |
'step' => $field['step'],
|
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 |
/**
|
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 = parent::normalize( $field );
|
21 |
|
22 |
$field = wp_parse_args( $field, array(
|
29 |
}
|
30 |
|
31 |
/**
|
32 |
+
* Get the attributes for a field.
|
33 |
*
|
34 |
+
* @param array $field Field parameters.
|
35 |
+
* @param mixed $value Meta value.
|
36 |
*
|
37 |
* @return array
|
38 |
*/
|
39 |
+
public static function get_attributes( $field, $value = null ) {
|
40 |
$attributes = parent::get_attributes( $field, $value );
|
41 |
$attributes = wp_parse_args( $attributes, array(
|
42 |
'step' => $field['step'],
|
inc/fields/object-choice.php
CHANGED
@@ -1,17 +1,21 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
* Abstract field to select an object: post, user, taxonomy, etc.
|
5 |
*/
|
6 |
abstract class RWMB_Object_Choice_Field extends RWMB_Choice_Field {
|
7 |
-
|
8 |
/**
|
9 |
* Get field HTML
|
10 |
*
|
11 |
-
* @param
|
12 |
-
* @param mixed $
|
13 |
-
* @param mixed $
|
14 |
-
* @param
|
15 |
* @return string
|
16 |
*/
|
17 |
public static function walk( $field, $options, $db_fields, $meta ) {
|
@@ -19,9 +23,9 @@ abstract class RWMB_Object_Choice_Field extends RWMB_Choice_Field {
|
|
19 |
}
|
20 |
|
21 |
/**
|
22 |
-
* Normalize parameters for field
|
23 |
*
|
24 |
-
* @param array $field
|
25 |
*
|
26 |
* @return array
|
27 |
*/
|
@@ -37,33 +41,33 @@ abstract class RWMB_Object_Choice_Field extends RWMB_Choice_Field {
|
|
37 |
$field['field_type'] = 'checkbox_list';
|
38 |
$field['flatten'] = false;
|
39 |
}
|
40 |
-
if ( 'radio_list'
|
41 |
$field['multiple'] = false;
|
42 |
}
|
43 |
-
if ( 'checkbox_list'
|
44 |
$field['multiple'] = true;
|
45 |
}
|
46 |
return call_user_func( array( self::get_type_class( $field ), 'normalize' ), $field );
|
47 |
}
|
48 |
|
49 |
/**
|
50 |
-
* Get the attributes for a field
|
51 |
*
|
52 |
-
* @param array $field
|
53 |
-
* @param mixed $value
|
54 |
*
|
55 |
* @return array
|
56 |
*/
|
57 |
public static function get_attributes( $field, $value = null ) {
|
58 |
$attributes = call_user_func( array( self::get_type_class( $field ), 'get_attributes' ), $field, $value );
|
59 |
-
if ( 'select_advanced'
|
60 |
$attributes['class'] .= ' rwmb-select_advanced';
|
61 |
}
|
62 |
return $attributes;
|
63 |
}
|
64 |
|
65 |
/**
|
66 |
-
* Get field names of object to be used by walker
|
67 |
*
|
68 |
* @return array
|
69 |
*/
|
@@ -75,9 +79,8 @@ abstract class RWMB_Object_Choice_Field extends RWMB_Choice_Field {
|
|
75 |
);
|
76 |
}
|
77 |
|
78 |
-
|
79 |
/**
|
80 |
-
* Enqueue scripts and styles
|
81 |
*/
|
82 |
public static function admin_enqueue_scripts() {
|
83 |
RWMB_Input_List_Field::admin_enqueue_scripts();
|
@@ -89,13 +92,15 @@ abstract class RWMB_Object_Choice_Field extends RWMB_Choice_Field {
|
|
89 |
/**
|
90 |
* Get correct rendering class for the field.
|
91 |
*
|
92 |
-
* @param array $field Field
|
93 |
* @return string
|
94 |
*/
|
95 |
protected static function get_type_class( $field ) {
|
96 |
-
if ( in_array( $field['field_type'], array( 'checkbox_list', 'radio_list' ) ) ) {
|
97 |
return 'RWMB_Input_List_Field';
|
98 |
}
|
99 |
-
return self::get_class_name( array(
|
|
|
|
|
100 |
}
|
101 |
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* The object choice class which allows users to select specific objects in WordPress.
|
4 |
+
*
|
5 |
+
* @package Meta Box
|
6 |
+
*/
|
7 |
|
8 |
/**
|
9 |
* Abstract field to select an object: post, user, taxonomy, etc.
|
10 |
*/
|
11 |
abstract class RWMB_Object_Choice_Field extends RWMB_Choice_Field {
|
|
|
12 |
/**
|
13 |
* Get field HTML
|
14 |
*
|
15 |
+
* @param array $field Field parameters.
|
16 |
+
* @param mixed $options Select options.
|
17 |
+
* @param mixed $db_fields Database fields to use in the output.
|
18 |
+
* @param mixed $meta Meta value.
|
19 |
* @return string
|
20 |
*/
|
21 |
public static function walk( $field, $options, $db_fields, $meta ) {
|
23 |
}
|
24 |
|
25 |
/**
|
26 |
+
* Normalize parameters for field.
|
27 |
*
|
28 |
+
* @param array $field Field parameters.
|
29 |
*
|
30 |
* @return array
|
31 |
*/
|
41 |
$field['field_type'] = 'checkbox_list';
|
42 |
$field['flatten'] = false;
|
43 |
}
|
44 |
+
if ( 'radio_list' === $field['field_type'] ) {
|
45 |
$field['multiple'] = false;
|
46 |
}
|
47 |
+
if ( 'checkbox_list' === $field['field_type'] ) {
|
48 |
$field['multiple'] = true;
|
49 |
}
|
50 |
return call_user_func( array( self::get_type_class( $field ), 'normalize' ), $field );
|
51 |
}
|
52 |
|
53 |
/**
|
54 |
+
* Get the attributes for a field.
|
55 |
*
|
56 |
+
* @param array $field Field parameters.
|
57 |
+
* @param mixed $value Meta value.
|
58 |
*
|
59 |
* @return array
|
60 |
*/
|
61 |
public static function get_attributes( $field, $value = null ) {
|
62 |
$attributes = call_user_func( array( self::get_type_class( $field ), 'get_attributes' ), $field, $value );
|
63 |
+
if ( 'select_advanced' === $field['field_type'] ) {
|
64 |
$attributes['class'] .= ' rwmb-select_advanced';
|
65 |
}
|
66 |
return $attributes;
|
67 |
}
|
68 |
|
69 |
/**
|
70 |
+
* Get field names of object to be used by walker.
|
71 |
*
|
72 |
* @return array
|
73 |
*/
|
79 |
);
|
80 |
}
|
81 |
|
|
|
82 |
/**
|
83 |
+
* Enqueue scripts and styles.
|
84 |
*/
|
85 |
public static function admin_enqueue_scripts() {
|
86 |
RWMB_Input_List_Field::admin_enqueue_scripts();
|
92 |
/**
|
93 |
* Get correct rendering class for the field.
|
94 |
*
|
95 |
+
* @param array $field Field parameters.
|
96 |
* @return string
|
97 |
*/
|
98 |
protected static function get_type_class( $field ) {
|
99 |
+
if ( in_array( $field['field_type'], array( 'checkbox_list', 'radio_list' ), true ) ) {
|
100 |
return 'RWMB_Input_List_Field';
|
101 |
}
|
102 |
+
return self::get_class_name( array(
|
103 |
+
'type' => $field['field_type'],
|
104 |
+
) );
|
105 |
}
|
106 |
}
|
inc/fields/oembed.php
CHANGED
@@ -1,12 +1,16 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
-
*
|
5 |
*/
|
6 |
class RWMB_OEmbed_Field extends RWMB_Text_Field {
|
7 |
-
|
8 |
/**
|
9 |
-
* Enqueue scripts and styles
|
10 |
*/
|
11 |
public static function admin_enqueue_scripts() {
|
12 |
wp_enqueue_style( 'rwmb-oembed', RWMB_CSS_URL . 'oembed.css' );
|
@@ -14,14 +18,14 @@ class RWMB_OEmbed_Field extends RWMB_Text_Field {
|
|
14 |
}
|
15 |
|
16 |
/**
|
17 |
-
* Add actions
|
18 |
*/
|
19 |
public static function add_actions() {
|
20 |
add_action( 'wp_ajax_rwmb_get_embed', array( __CLASS__, 'wp_ajax_get_embed' ) );
|
21 |
}
|
22 |
|
23 |
/**
|
24 |
-
* Ajax callback for returning oEmbed HTML
|
25 |
*/
|
26 |
public static function wp_ajax_get_embed() {
|
27 |
$url = (string) filter_input( INPUT_POST, 'url', FILTER_SANITIZE_URL );
|
@@ -29,15 +33,15 @@ class RWMB_OEmbed_Field extends RWMB_Text_Field {
|
|
29 |
}
|
30 |
|
31 |
/**
|
32 |
-
* Get embed html from url
|
33 |
*
|
34 |
-
* @param string $url
|
35 |
* @return string
|
36 |
*/
|
37 |
public static function get_embed( $url ) {
|
38 |
/**
|
39 |
* Set arguments for getting embeded HTML.
|
40 |
-
* Without arguments, default width will be taken from global $content_width, which can break UI in the admin
|
41 |
*
|
42 |
* @link https://github.com/rilwis/meta-box/issues/801
|
43 |
* @see WP_oEmbed::fetch()
|
@@ -49,10 +53,10 @@ class RWMB_OEmbed_Field extends RWMB_Text_Field {
|
|
49 |
$args['width'] = 360;
|
50 |
}
|
51 |
|
52 |
-
// Try oembed first
|
53 |
$embed = wp_oembed_get( $url, $args );
|
54 |
|
55 |
-
// If no oembed provides found, try WordPress auto embed
|
56 |
if ( ! $embed ) {
|
57 |
$embed = $GLOBALS['wp_embed']->shortcode( $args, $url );
|
58 |
}
|
@@ -61,10 +65,10 @@ class RWMB_OEmbed_Field extends RWMB_Text_Field {
|
|
61 |
}
|
62 |
|
63 |
/**
|
64 |
-
* Get field HTML
|
65 |
*
|
66 |
-
* @param mixed $meta
|
67 |
-
* @param array $field
|
68 |
* @return string
|
69 |
*/
|
70 |
public static function html( $meta, $field ) {
|
@@ -78,10 +82,10 @@ class RWMB_OEmbed_Field extends RWMB_Text_Field {
|
|
78 |
}
|
79 |
|
80 |
/**
|
81 |
-
* Get the attributes for a field
|
82 |
*
|
83 |
-
* @param array $field
|
84 |
-
* @param mixed $value
|
85 |
*
|
86 |
* @return array
|
87 |
*/
|
@@ -94,8 +98,8 @@ class RWMB_OEmbed_Field extends RWMB_Text_Field {
|
|
94 |
/**
|
95 |
* Format a single value for the helper functions.
|
96 |
*
|
97 |
-
* @param array $field Field
|
98 |
-
* @param string $value
|
99 |
* @return string
|
100 |
*/
|
101 |
public static function format_single_value( $field, $value ) {
|
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_Text_Field {
|
|
|
12 |
/**
|
13 |
+
* Enqueue scripts and styles.
|
14 |
*/
|
15 |
public static function admin_enqueue_scripts() {
|
16 |
wp_enqueue_style( 'rwmb-oembed', RWMB_CSS_URL . 'oembed.css' );
|
18 |
}
|
19 |
|
20 |
/**
|
21 |
+
* Add actions.
|
22 |
*/
|
23 |
public static function add_actions() {
|
24 |
add_action( 'wp_ajax_rwmb_get_embed', array( __CLASS__, 'wp_ajax_get_embed' ) );
|
25 |
}
|
26 |
|
27 |
/**
|
28 |
+
* Ajax callback for returning oEmbed HTML.
|
29 |
*/
|
30 |
public static function wp_ajax_get_embed() {
|
31 |
$url = (string) filter_input( INPUT_POST, 'url', FILTER_SANITIZE_URL );
|
33 |
}
|
34 |
|
35 |
/**
|
36 |
+
* Get embed html from url.
|
37 |
*
|
38 |
+
* @param string $url URL.
|
39 |
* @return string
|
40 |
*/
|
41 |
public static function get_embed( $url ) {
|
42 |
/**
|
43 |
* Set arguments for getting embeded HTML.
|
44 |
+
* Without arguments, default width will be taken from global $content_width, which can break UI in the admin.
|
45 |
*
|
46 |
* @link https://github.com/rilwis/meta-box/issues/801
|
47 |
* @see WP_oEmbed::fetch()
|
53 |
$args['width'] = 360;
|
54 |
}
|
55 |
|
56 |
+
// Try oembed first.
|
57 |
$embed = wp_oembed_get( $url, $args );
|
58 |
|
59 |
+
// If no oembed provides found, try WordPress auto embed.
|
60 |
if ( ! $embed ) {
|
61 |
$embed = $GLOBALS['wp_embed']->shortcode( $args, $url );
|
62 |
}
|
65 |
}
|
66 |
|
67 |
/**
|
68 |
+
* Get field HTML.
|
69 |
*
|
70 |
+
* @param mixed $meta Meta value.
|
71 |
+
* @param array $field Field parameters.
|
72 |
* @return string
|
73 |
*/
|
74 |
public static function html( $meta, $field ) {
|
82 |
}
|
83 |
|
84 |
/**
|
85 |
+
* Get the attributes for a field.
|
86 |
*
|
87 |
+
* @param array $field Field parameters.
|
88 |
+
* @param mixed $value Meta value.
|
89 |
*
|
90 |
* @return array
|
91 |
*/
|
98 |
/**
|
99 |
* Format a single value for the helper functions.
|
100 |
*
|
101 |
+
* @param array $field Field parameters.
|
102 |
+
* @param string $value Meta value.
|
103 |
* @return string
|
104 |
*/
|
105 |
public static function format_single_value( $field, $value ) {
|
inc/fields/password.php
CHANGED
@@ -1,20 +1,25 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Password field class.
|
4 |
*/
|
5 |
class RWMB_Password_Field extends RWMB_Text_Field {
|
6 |
-
|
7 |
/**
|
8 |
* Store secured password in the database.
|
9 |
*
|
10 |
-
* @param mixed $new
|
11 |
-
* @param mixed $old
|
12 |
-
* @param int $post_id
|
13 |
-
* @param array $field
|
14 |
* @return string
|
15 |
*/
|
16 |
-
static function value( $new, $old, $post_id, $field ) {
|
17 |
-
$new = $new
|
18 |
return $new;
|
19 |
}
|
20 |
}
|
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_Text_Field {
|
|
|
12 |
/**
|
13 |
* Store secured password in the database.
|
14 |
*
|
15 |
+
* @param mixed $new The submitted meta value.
|
16 |
+
* @param mixed $old The existing meta value.
|
17 |
+
* @param int $post_id The post ID.
|
18 |
+
* @param array $field The field parameters.
|
19 |
* @return string
|
20 |
*/
|
21 |
+
public static function value( $new, $old, $post_id, $field ) {
|
22 |
+
$new = $new !== $old ? wp_hash_password( $new ) : $new;
|
23 |
return $new;
|
24 |
}
|
25 |
}
|
inc/fields/post.php
CHANGED
@@ -1,19 +1,22 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Post field class.
|
4 |
*/
|
5 |
class RWMB_Post_Field extends RWMB_Object_Choice_Field {
|
6 |
-
|
7 |
/**
|
8 |
-
* Normalize parameters for field
|
9 |
*
|
10 |
-
* @param array $field
|
11 |
* @return array
|
12 |
*/
|
13 |
public static function normalize( $field ) {
|
14 |
-
|
15 |
-
* Set default field args
|
16 |
-
*/
|
17 |
$field = parent::normalize( $field );
|
18 |
$field = wp_parse_args( $field, array(
|
19 |
'post_type' => 'post',
|
@@ -25,29 +28,27 @@ class RWMB_Post_Field extends RWMB_Object_Choice_Field {
|
|
25 |
}
|
26 |
|
27 |
/**
|
28 |
-
* Set default placeholder
|
29 |
-
* - If multiple post types: show 'Select a post'
|
30 |
-
* - If single post type: show 'Select a %post_type_name%'
|
31 |
*/
|
32 |
if ( empty( $field['placeholder'] ) ) {
|
33 |
$field['placeholder'] = __( 'Select a post', 'meta-box' );
|
34 |
if ( is_string( $field['query_args']['post_type'] ) && post_type_exists( $field['query_args']['post_type'] ) ) {
|
35 |
-
$post_type_object
|
|
|
|
|
36 |
$field['placeholder'] = sprintf( __( 'Select a %s', 'meta-box' ), $post_type_object->labels->singular_name );
|
37 |
}
|
38 |
}
|
39 |
|
40 |
-
|
41 |
-
* Set parent option, which will change field name to `parent_id` to save as post parent
|
42 |
-
*/
|
43 |
if ( $field['parent'] ) {
|
44 |
$field['multiple'] = false;
|
45 |
$field['field_name'] = 'parent_id';
|
46 |
}
|
47 |
|
48 |
-
|
49 |
-
* Set default query args
|
50 |
-
*/
|
51 |
$field['query_args'] = wp_parse_args( $field['query_args'], array(
|
52 |
'post_status' => 'publish',
|
53 |
'posts_per_page' => - 1,
|
@@ -57,7 +58,7 @@ class RWMB_Post_Field extends RWMB_Object_Choice_Field {
|
|
57 |
}
|
58 |
|
59 |
/**
|
60 |
-
* Get field names of object to be used by walker
|
61 |
*
|
62 |
* @return array
|
63 |
*/
|
@@ -70,17 +71,17 @@ class RWMB_Post_Field extends RWMB_Object_Choice_Field {
|
|
70 |
}
|
71 |
|
72 |
/**
|
73 |
-
* Get meta value
|
74 |
-
* If field is cloneable, value is saved as a single entry in DB
|
75 |
-
* Otherwise value is saved as multiple entries (for backward compatibility)
|
76 |
*
|
77 |
* @see "save" method for better understanding
|
78 |
*
|
79 |
-
* @param $post_id
|
80 |
-
* @param $saved
|
81 |
-
* @param $field
|
82 |
*
|
83 |
-
* @return
|
84 |
*/
|
85 |
public static function meta( $post_id, $saved, $field ) {
|
86 |
if ( isset( $field['parent'] ) && $field['parent'] ) {
|
@@ -92,9 +93,9 @@ class RWMB_Post_Field extends RWMB_Object_Choice_Field {
|
|
92 |
}
|
93 |
|
94 |
/**
|
95 |
-
* Get options for walker
|
96 |
*
|
97 |
-
* @param array $field
|
98 |
* @return array
|
99 |
*/
|
100 |
public static function get_options( $field ) {
|
@@ -103,10 +104,10 @@ class RWMB_Post_Field extends RWMB_Object_Choice_Field {
|
|
103 |
}
|
104 |
|
105 |
/**
|
106 |
-
* Get option label
|
107 |
*
|
108 |
-
* @param
|
109 |
-
* @param
|
110 |
*
|
111 |
* @return string
|
112 |
*/
|
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 |
+
* Normalize parameters for field.
|
14 |
*
|
15 |
+
* @param array $field Field parameters.
|
16 |
* @return array
|
17 |
*/
|
18 |
public static function normalize( $field ) {
|
19 |
+
// Set default field args.
|
|
|
|
|
20 |
$field = parent::normalize( $field );
|
21 |
$field = wp_parse_args( $field, array(
|
22 |
'post_type' => 'post',
|
28 |
}
|
29 |
|
30 |
/**
|
31 |
+
* Set default placeholder.
|
32 |
+
* - If multiple post types: show 'Select a post'.
|
33 |
+
* - If single post type: show 'Select a %post_type_name%'.
|
34 |
*/
|
35 |
if ( empty( $field['placeholder'] ) ) {
|
36 |
$field['placeholder'] = __( 'Select a post', 'meta-box' );
|
37 |
if ( is_string( $field['query_args']['post_type'] ) && post_type_exists( $field['query_args']['post_type'] ) ) {
|
38 |
+
$post_type_object = get_post_type_object( $field['query_args']['post_type'] );
|
39 |
+
|
40 |
+
// Translators: %s is the post type singular label.
|
41 |
$field['placeholder'] = sprintf( __( 'Select a %s', 'meta-box' ), $post_type_object->labels->singular_name );
|
42 |
}
|
43 |
}
|
44 |
|
45 |
+
// Set parent option, which will change field name to `parent_id` to save as post parent.
|
|
|
|
|
46 |
if ( $field['parent'] ) {
|
47 |
$field['multiple'] = false;
|
48 |
$field['field_name'] = 'parent_id';
|
49 |
}
|
50 |
|
51 |
+
// Set default query args.
|
|
|
|
|
52 |
$field['query_args'] = wp_parse_args( $field['query_args'], array(
|
53 |
'post_status' => 'publish',
|
54 |
'posts_per_page' => - 1,
|
58 |
}
|
59 |
|
60 |
/**
|
61 |
+
* Get field names of object to be used by walker.
|
62 |
*
|
63 |
* @return array
|
64 |
*/
|
71 |
}
|
72 |
|
73 |
/**
|
74 |
+
* Get meta value.
|
75 |
+
* If field is cloneable, value is saved as a single entry in DB.
|
76 |
+
* Otherwise value is saved as multiple entries (for backward compatibility).
|
77 |
*
|
78 |
* @see "save" method for better understanding
|
79 |
*
|
80 |
+
* @param int $post_id Post ID.
|
81 |
+
* @param bool $saved Is the meta box saved.
|
82 |
+
* @param array $field Field parameters.
|
83 |
*
|
84 |
+
* @return mixed
|
85 |
*/
|
86 |
public static function meta( $post_id, $saved, $field ) {
|
87 |
if ( isset( $field['parent'] ) && $field['parent'] ) {
|
93 |
}
|
94 |
|
95 |
/**
|
96 |
+
* Get options for walker.
|
97 |
*
|
98 |
+
* @param array $field Field parameters.
|
99 |
* @return array
|
100 |
*/
|
101 |
public static function get_options( $field ) {
|
104 |
}
|
105 |
|
106 |
/**
|
107 |
+
* Get option label.
|
108 |
*
|
109 |
+
* @param array $field Field parameters.
|
110 |
+
* @param string $value Option value.
|
111 |
*
|
112 |
* @return string
|
113 |
*/
|
inc/fields/radio.php
CHANGED
@@ -1,16 +1,21 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Radio field class.
|
4 |
*/
|
5 |
class RWMB_Radio_Field extends RWMB_Input_List_Field {
|
6 |
-
|
7 |
/**
|
8 |
-
* Normalize parameters for field
|
9 |
*
|
10 |
-
* @param array $field
|
11 |
* @return array
|
12 |
*/
|
13 |
-
static function normalize( $field ) {
|
14 |
$field['multiple'] = false;
|
15 |
$field = parent::normalize( $field );
|
16 |
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* The radio field.
|
4 |
+
*
|
5 |
+
* @package Meta Box
|
6 |
+
*/
|
7 |
+
|
8 |
/**
|
9 |
* Radio field class.
|
10 |
*/
|
11 |
class RWMB_Radio_Field extends RWMB_Input_List_Field {
|
|
|
12 |
/**
|
13 |
+
* Normalize parameters for field.
|
14 |
*
|
15 |
+
* @param array $field Field parameters.
|
16 |
* @return array
|
17 |
*/
|
18 |
+
public static function normalize( $field ) {
|
19 |
$field['multiple'] = false;
|
20 |
$field = parent::normalize( $field );
|
21 |
|
inc/fields/range.php
CHANGED
@@ -1,14 +1,19 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* HTML5 range field class.
|
4 |
*/
|
5 |
class RWMB_Range_Field extends RWMB_Number_Field {
|
6 |
-
|
7 |
/**
|
8 |
-
* Get field HTML
|
9 |
*
|
10 |
-
* @param mixed $meta
|
11 |
-
* @param array $field
|
12 |
* @return string
|
13 |
*/
|
14 |
public static function html( $meta, $field ) {
|
@@ -18,7 +23,7 @@ class RWMB_Range_Field extends RWMB_Number_Field {
|
|
18 |
}
|
19 |
|
20 |
/**
|
21 |
-
* Enqueue styles
|
22 |
*/
|
23 |
public static function admin_enqueue_scripts() {
|
24 |
wp_enqueue_style( 'rwmb-range', RWMB_CSS_URL . 'range.css', array(), RWMB_VER );
|
@@ -28,7 +33,7 @@ class RWMB_Range_Field extends RWMB_Number_Field {
|
|
28 |
/**
|
29 |
* Normalize parameters for field.
|
30 |
*
|
31 |
-
* @param array $field
|
32 |
* @return array
|
33 |
*/
|
34 |
public static function normalize( $field ) {
|
@@ -42,10 +47,10 @@ class RWMB_Range_Field extends RWMB_Number_Field {
|
|
42 |
/**
|
43 |
* Ensure number in range.
|
44 |
*
|
45 |
-
* @param mixed $new
|
46 |
-
* @param mixed $old
|
47 |
-
* @param int $post_id
|
48 |
-
* @param array $field
|
49 |
*
|
50 |
* @return int
|
51 |
*/
|
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 |
/**
|
13 |
+
* Get field HTML.
|
14 |
*
|
15 |
+
* @param mixed $meta Meta value.
|
16 |
+
* @param array $field Field parameters.
|
17 |
* @return string
|
18 |
*/
|
19 |
public static function html( $meta, $field ) {
|
23 |
}
|
24 |
|
25 |
/**
|
26 |
+
* Enqueue styles.
|
27 |
*/
|
28 |
public static function admin_enqueue_scripts() {
|
29 |
wp_enqueue_style( 'rwmb-range', RWMB_CSS_URL . 'range.css', array(), RWMB_VER );
|
33 |
/**
|
34 |
* Normalize parameters for field.
|
35 |
*
|
36 |
+
* @param array $field Field parameters.
|
37 |
* @return array
|
38 |
*/
|
39 |
public static function normalize( $field ) {
|
47 |
/**
|
48 |
* Ensure number in range.
|
49 |
*
|
50 |
+
* @param mixed $new The submitted meta value.
|
51 |
+
* @param mixed $old The existing meta value.
|
52 |
+
* @param int $post_id The post ID.
|
53 |
+
* @param array $field The field parameters.
|
54 |
*
|
55 |
* @return int
|
56 |
*/
|
inc/fields/select-advanced.php
CHANGED
@@ -1,11 +1,16 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Select advanced field which uses select2 library.
|
4 |
*/
|
5 |
class RWMB_Select_Advanced_Field extends RWMB_Select_Field {
|
6 |
-
|
7 |
/**
|
8 |
-
* Enqueue scripts and styles
|
9 |
*/
|
10 |
public static function admin_enqueue_scripts() {
|
11 |
parent::admin_enqueue_scripts();
|
@@ -14,7 +19,7 @@ class RWMB_Select_Advanced_Field extends RWMB_Select_Field {
|
|
14 |
|
15 |
wp_register_script( 'rwmb-select2', RWMB_JS_URL . 'select2/select2.min.js', array( 'jquery' ), '4.0.2', true );
|
16 |
|
17 |
-
// Localize
|
18 |
$dependencies = array( 'rwmb-select2', 'rwmb-select' );
|
19 |
$locale = str_replace( '_', '-', get_locale() );
|
20 |
$locale_short = substr( $locale, 0, 2 );
|
@@ -30,9 +35,9 @@ class RWMB_Select_Advanced_Field extends RWMB_Select_Field {
|
|
30 |
}
|
31 |
|
32 |
/**
|
33 |
-
* Normalize parameters for field
|
34 |
*
|
35 |
-
* @param array $field
|
36 |
* @return array
|
37 |
*/
|
38 |
public static function normalize( $field ) {
|
@@ -53,10 +58,10 @@ class RWMB_Select_Advanced_Field extends RWMB_Select_Field {
|
|
53 |
}
|
54 |
|
55 |
/**
|
56 |
-
* Get the attributes for a field
|
57 |
*
|
58 |
-
* @param array $field
|
59 |
-
* @param mixed $value
|
60 |
* @return array
|
61 |
*/
|
62 |
public static function get_attributes( $field, $value = null ) {
|
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();
|
19 |
|
20 |
wp_register_script( 'rwmb-select2', RWMB_JS_URL . 'select2/select2.min.js', array( 'jquery' ), '4.0.2', true );
|
21 |
|
22 |
+
// Localize.
|
23 |
$dependencies = array( 'rwmb-select2', 'rwmb-select' );
|
24 |
$locale = str_replace( '_', '-', get_locale() );
|
25 |
$locale_short = substr( $locale, 0, 2 );
|
35 |
}
|
36 |
|
37 |
/**
|
38 |
+
* Normalize parameters for field.
|
39 |
*
|
40 |
+
* @param array $field Field parameters.
|
41 |
* @return array
|
42 |
*/
|
43 |
public static function normalize( $field ) {
|
58 |
}
|
59 |
|
60 |
/**
|
61 |
+
* Get the attributes for a field.
|
62 |
*
|
63 |
+
* @param array $field Field parameters.
|
64 |
+
* @param mixed $value Meta value.
|
65 |
* @return array
|
66 |
*/
|
67 |
public static function get_attributes( $field, $value = null ) {
|
inc/fields/select-tree.php
CHANGED
@@ -1,16 +1,21 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Select tree field class.
|
4 |
*/
|
5 |
class RWMB_Select_Tree_Field extends RWMB_Select_Field {
|
6 |
-
|
7 |
/**
|
8 |
-
* Walk options
|
9 |
*
|
10 |
-
* @param
|
11 |
-
* @param
|
12 |
-
* @param mixed $
|
13 |
-
* @param mixed $
|
14 |
*
|
15 |
* @return string
|
16 |
*/
|
@@ -20,7 +25,7 @@ class RWMB_Select_Tree_Field extends RWMB_Select_Field {
|
|
20 |
}
|
21 |
|
22 |
/**
|
23 |
-
* Enqueue scripts and styles
|
24 |
*/
|
25 |
public static function admin_enqueue_scripts() {
|
26 |
parent::admin_enqueue_scripts();
|
@@ -29,9 +34,9 @@ class RWMB_Select_Tree_Field extends RWMB_Select_Field {
|
|
29 |
}
|
30 |
|
31 |
/**
|
32 |
-
* Normalize parameters for field
|
33 |
*
|
34 |
-
* @param array $field
|
35 |
* @return array
|
36 |
*/
|
37 |
public static function normalize( $field ) {
|
@@ -43,10 +48,10 @@ class RWMB_Select_Tree_Field extends RWMB_Select_Field {
|
|
43 |
}
|
44 |
|
45 |
/**
|
46 |
-
* Get the attributes for a field
|
47 |
*
|
48 |
-
* @param array $field
|
49 |
-
* @param mixed $value
|
50 |
*
|
51 |
* @return array
|
52 |
*/
|
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_Field {
|
|
|
12 |
/**
|
13 |
+
* Walk options.
|
14 |
*
|
15 |
+
* @param array $field Field parameters.
|
16 |
+
* @param mixed $options Select options.
|
17 |
+
* @param mixed $db_fields Database fields to use in the output.
|
18 |
+
* @param mixed $meta Meta value.
|
19 |
*
|
20 |
* @return string
|
21 |
*/
|
25 |
}
|
26 |
|
27 |
/**
|
28 |
+
* Enqueue scripts and styles.
|
29 |
*/
|
30 |
public static function admin_enqueue_scripts() {
|
31 |
parent::admin_enqueue_scripts();
|
34 |
}
|
35 |
|
36 |
/**
|
37 |
+
* Normalize parameters for field.
|
38 |
*
|
39 |
+
* @param array $field Field parameters.
|
40 |
* @return array
|
41 |
*/
|
42 |
public static function normalize( $field ) {
|
48 |
}
|
49 |
|
50 |
/**
|
51 |
+
* Get the attributes for a field.
|
52 |
*
|
53 |
+
* @param array $field Field parameters.
|
54 |
+
* @param mixed $value Meta value.
|
55 |
*
|
56 |
* @return array
|
57 |
*/
|
inc/fields/select.php
CHANGED
@@ -1,11 +1,16 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Select field class.
|
4 |
*/
|
5 |
class RWMB_Select_Field extends RWMB_Choice_Field {
|
6 |
-
|
7 |
/**
|
8 |
-
* Enqueue scripts and styles
|
9 |
*/
|
10 |
public static function admin_enqueue_scripts() {
|
11 |
wp_enqueue_style( 'rwmb-select', RWMB_CSS_URL . 'select.css', array(), RWMB_VER );
|
@@ -13,12 +18,12 @@ class RWMB_Select_Field extends RWMB_Choice_Field {
|
|
13 |
}
|
14 |
|
15 |
/**
|
16 |
-
* Walk options
|
17 |
*
|
18 |
-
* @param
|
19 |
-
* @param
|
20 |
-
* @param mixed $
|
21 |
-
* @param mixed $
|
22 |
*
|
23 |
* @return string
|
24 |
*/
|
@@ -39,9 +44,9 @@ class RWMB_Select_Field extends RWMB_Choice_Field {
|
|
39 |
}
|
40 |
|
41 |
/**
|
42 |
-
* Normalize parameters for field
|
43 |
*
|
44 |
-
* @param array $field
|
45 |
* @return array
|
46 |
*/
|
47 |
public static function normalize( $field ) {
|
@@ -56,10 +61,10 @@ class RWMB_Select_Field extends RWMB_Choice_Field {
|
|
56 |
}
|
57 |
|
58 |
/**
|
59 |
-
* Get the attributes for a field
|
60 |
*
|
61 |
-
* @param array $field
|
62 |
-
* @param mixed $value
|
63 |
*
|
64 |
* @return array
|
65 |
*/
|
@@ -74,9 +79,9 @@ class RWMB_Select_Field extends RWMB_Choice_Field {
|
|
74 |
}
|
75 |
|
76 |
/**
|
77 |
-
* Get html for select all|none for multiple select
|
78 |
*
|
79 |
-
* @param array $field
|
80 |
* @return string
|
81 |
*/
|
82 |
public static function get_select_all_html( $field ) {
|
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 );
|
18 |
}
|
19 |
|
20 |
/**
|
21 |
+
* Walk options.
|
22 |
*
|
23 |
+
* @param array $field Field parameters.
|
24 |
+
* @param mixed $options Select options.
|
25 |
+
* @param mixed $db_fields Database fields to use in the output.
|
26 |
+
* @param mixed $meta Meta value.
|
27 |
*
|
28 |
* @return string
|
29 |
*/
|
44 |
}
|
45 |
|
46 |
/**
|
47 |
+
* Normalize parameters for field.
|
48 |
*
|
49 |
+
* @param array $field Field parameters.
|
50 |
* @return array
|
51 |
*/
|
52 |
public static function normalize( $field ) {
|
61 |
}
|
62 |
|
63 |
/**
|
64 |
+
* Get the attributes for a field.
|
65 |
*
|
66 |
+
* @param array $field Field parameters.
|
67 |
+
* @param mixed $value Meta value.
|
68 |
*
|
69 |
* @return array
|
70 |
*/
|
79 |
}
|
80 |
|
81 |
/**
|
82 |
+
* Get html for select all|none for multiple select.
|
83 |
*
|
84 |
+
* @param array $field Field parameters.
|
85 |
* @return string
|
86 |
*/
|
87 |
public static function get_select_all_html( $field ) {
|
inc/fields/slider.php
CHANGED
@@ -1,15 +1,18 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
*
|
|
|
|
|
4 |
*/
|
5 |
-
class RWMB_Slider_Field extends RWMB_Field {
|
6 |
|
|
|
|
|
|
|
|
|
7 |
/**
|
8 |
-
* Enqueue scripts and styles
|
9 |
-
*
|
10 |
-
* @return void
|
11 |
*/
|
12 |
-
static function admin_enqueue_scripts() {
|
13 |
$url = RWMB_CSS_URL . 'jqueryui';
|
14 |
wp_enqueue_style( 'jquery-ui-core', "{$url}/jquery.ui.core.css", array(), '1.8.17' );
|
15 |
wp_enqueue_style( 'jquery-ui-theme', "{$url}/jquery.ui.theme.css", array(), '1.8.17' );
|
@@ -20,14 +23,14 @@ class RWMB_Slider_Field extends RWMB_Field {
|
|
20 |
}
|
21 |
|
22 |
/**
|
23 |
-
* Get div HTML
|
24 |
*
|
25 |
-
* @param mixed $meta
|
26 |
-
* @param array $field
|
27 |
*
|
28 |
* @return string
|
29 |
*/
|
30 |
-
static function html( $meta, $field ) {
|
31 |
return sprintf(
|
32 |
'<div class="clearfix">
|
33 |
<div class="rwmb-slider" id="%s" data-options="%s"></div>
|
@@ -41,13 +44,13 @@ class RWMB_Slider_Field extends RWMB_Field {
|
|
41 |
}
|
42 |
|
43 |
/**
|
44 |
-
* Normalize parameters for field
|
45 |
*
|
46 |
-
* @param array $field
|
47 |
*
|
48 |
* @return array
|
49 |
*/
|
50 |
-
static function normalize( $field ) {
|
51 |
$field = parent::normalize( $field );
|
52 |
$field = wp_parse_args( $field, array(
|
53 |
'prefix' => '',
|
@@ -56,7 +59,7 @@ class RWMB_Slider_Field extends RWMB_Field {
|
|
56 |
'js_options' => array(),
|
57 |
) );
|
58 |
$field['js_options'] = wp_parse_args( $field['js_options'], array(
|
59 |
-
'range' => 'min', // range = 'min' will add a dark background to sliding part, better UI
|
60 |
'value' => $field['std'],
|
61 |
) );
|
62 |
|
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_enqueue_style( 'jquery-ui-core', "{$url}/jquery.ui.core.css", array(), '1.8.17' );
|
18 |
wp_enqueue_style( 'jquery-ui-theme', "{$url}/jquery.ui.theme.css", array(), '1.8.17' );
|
23 |
}
|
24 |
|
25 |
/**
|
26 |
+
* Get div HTML.
|
27 |
*
|
28 |
+
* @param mixed $meta Meta value.
|
29 |
+
* @param array $field Field parameters.
|
30 |
*
|
31 |
* @return string
|
32 |
*/
|
33 |
+
public static function html( $meta, $field ) {
|
34 |
return sprintf(
|
35 |
'<div class="clearfix">
|
36 |
<div class="rwmb-slider" id="%s" data-options="%s"></div>
|
44 |
}
|
45 |
|
46 |
/**
|
47 |
+
* Normalize parameters for field.
|
48 |
*
|
49 |
+
* @param array $field Field parameters.
|
50 |
*
|
51 |
* @return array
|
52 |
*/
|
53 |
+
public static function normalize( $field ) {
|
54 |
$field = parent::normalize( $field );
|
55 |
$field = wp_parse_args( $field, array(
|
56 |
'prefix' => '',
|
59 |
'js_options' => array(),
|
60 |
) );
|
61 |
$field['js_options'] = wp_parse_args( $field['js_options'], array(
|
62 |
+
'range' => 'min', // range = 'min' will add a dark background to sliding part, better UI.
|
63 |
'value' => $field['std'],
|
64 |
) );
|
65 |
|
inc/fields/taxonomy-advanced.php
CHANGED
@@ -9,6 +9,13 @@
|
|
9 |
* The taxonomy advanced field class.
|
10 |
*/
|
11 |
class RWMB_Taxonomy_Advanced_Field extends RWMB_Taxonomy_Field {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
public static function normalize( $field ) {
|
13 |
$field = wp_parse_args( $field, array(
|
14 |
'clone' => false,
|
@@ -22,14 +29,13 @@ class RWMB_Taxonomy_Advanced_Field extends RWMB_Taxonomy_Field {
|
|
22 |
}
|
23 |
|
24 |
/**
|
25 |
-
* Get meta values to save
|
26 |
-
* Save terms in custom field, no more by setting post terms
|
27 |
-
* Save in form of comma-separated IDs
|
28 |
*
|
29 |
-
* @param mixed $new
|
30 |
-
* @param mixed $old
|
31 |
-
* @param int $post_id
|
32 |
-
* @param array $field
|
33 |
*
|
34 |
* @return string
|
35 |
*/
|
@@ -38,12 +44,12 @@ class RWMB_Taxonomy_Advanced_Field extends RWMB_Taxonomy_Field {
|
|
38 |
}
|
39 |
|
40 |
/**
|
41 |
-
* Save meta value
|
42 |
*
|
43 |
-
* @param mixed $new
|
44 |
-
* @param mixed $old
|
45 |
-
* @param int $post_id
|
46 |
-
* @param array $field
|
47 |
*/
|
48 |
public static function save( $new, $old, $post_id, $field ) {
|
49 |
if ( $new ) {
|
@@ -54,29 +60,32 @@ class RWMB_Taxonomy_Advanced_Field extends RWMB_Taxonomy_Field {
|
|
54 |
}
|
55 |
|
56 |
/**
|
57 |
-
* Get raw meta value
|
58 |
*
|
59 |
-
* @param int $post_id
|
60 |
-
* @param array $field
|
61 |
*
|
62 |
* @return mixed
|
63 |
*/
|
64 |
public static function raw_meta( $post_id, $field ) {
|
65 |
$meta = get_post_meta( $post_id, $field['id'], true );
|
66 |
-
|
|
|
|
|
|
|
67 |
|
68 |
-
return
|
69 |
}
|
70 |
|
71 |
/**
|
72 |
-
* Get the field value
|
73 |
-
* Return list of post term objects
|
74 |
*
|
75 |
-
* @param array $field Field parameters
|
76 |
-
* @param array $args Additional arguments.
|
77 |
* @param int|null $post_id Post ID. null for current post. Optional.
|
78 |
*
|
79 |
-
* @return array List of post term objects
|
80 |
*/
|
81 |
public static function get_value( $field, $args = array(), $post_id = null ) {
|
82 |
if ( ! $post_id ) {
|
@@ -88,14 +97,14 @@ class RWMB_Taxonomy_Advanced_Field extends RWMB_Taxonomy_Field {
|
|
88 |
return null;
|
89 |
}
|
90 |
|
91 |
-
// Allow to pass more arguments to "get_terms"
|
92 |
$args = wp_parse_args( array(
|
93 |
'include' => $value,
|
94 |
'hide_empty' => false,
|
95 |
), $args );
|
96 |
$value = get_terms( $field['taxonomy'], $args );
|
97 |
|
98 |
-
// Get single value if necessary
|
99 |
if ( ! $field['clone'] && ! $field['multiple'] ) {
|
100 |
$value = reset( $value );
|
101 |
}
|
9 |
* The taxonomy advanced field class.
|
10 |
*/
|
11 |
class RWMB_Taxonomy_Advanced_Field extends RWMB_Taxonomy_Field {
|
12 |
+
/**
|
13 |
+
* Normalize the field parameters.
|
14 |
+
*
|
15 |
+
* @param array $field Field parameters.
|
16 |
+
*
|
17 |
+
* @return array
|
18 |
+
*/
|
19 |
public static function normalize( $field ) {
|
20 |
$field = wp_parse_args( $field, array(
|
21 |
'clone' => false,
|
29 |
}
|
30 |
|
31 |
/**
|
32 |
+
* Get meta values to save.
|
33 |
+
* Save terms in custom field in form of comma-separated IDs, no more by setting post terms.
|
|
|
34 |
*
|
35 |
+
* @param mixed $new The submitted meta value.
|
36 |
+
* @param mixed $old The existing meta value.
|
37 |
+
* @param int $post_id The post ID.
|
38 |
+
* @param array $field The field parameters.
|
39 |
*
|
40 |
* @return string
|
41 |
*/
|
44 |
}
|
45 |
|
46 |
/**
|
47 |
+
* Save meta value.
|
48 |
*
|
49 |
+
* @param mixed $new The submitted meta value.
|
50 |
+
* @param mixed $old The existing meta value.
|
51 |
+
* @param int $post_id The post ID.
|
52 |
+
* @param array $field The field parameters.
|
53 |
*/
|
54 |
public static function save( $new, $old, $post_id, $field ) {
|
55 |
if ( $new ) {
|
60 |
}
|
61 |
|
62 |
/**
|
63 |
+
* Get raw meta value.
|
64 |
*
|
65 |
+
* @param int $post_id The post ID.
|
66 |
+
* @param array $field The field parameters.
|
67 |
*
|
68 |
* @return mixed
|
69 |
*/
|
70 |
public static function raw_meta( $post_id, $field ) {
|
71 |
$meta = get_post_meta( $post_id, $field['id'], true );
|
72 |
+
if ( empty( $meta ) ) {
|
73 |
+
return $field['multiple'] ? array() : '';
|
74 |
+
}
|
75 |
+
$meta = array_filter( wp_parse_id_list( $meta ) );
|
76 |
|
77 |
+
return $field['multiple'] ? $meta : reset( $meta );
|
78 |
}
|
79 |
|
80 |
/**
|
81 |
+
* Get the field value.
|
82 |
+
* Return list of post term objects.
|
83 |
*
|
84 |
+
* @param array $field Field parameters.
|
85 |
+
* @param array $args Additional arguments.
|
86 |
* @param int|null $post_id Post ID. null for current post. Optional.
|
87 |
*
|
88 |
+
* @return array List of post term objects.
|
89 |
*/
|
90 |
public static function get_value( $field, $args = array(), $post_id = null ) {
|
91 |
if ( ! $post_id ) {
|
97 |
return null;
|
98 |
}
|
99 |
|
100 |
+
// Allow to pass more arguments to "get_terms".
|
101 |
$args = wp_parse_args( array(
|
102 |
'include' => $value,
|
103 |
'hide_empty' => false,
|
104 |
), $args );
|
105 |
$value = get_terms( $field['taxonomy'], $args );
|
106 |
|
107 |
+
// Get single value if necessary.
|
108 |
if ( ! $field['clone'] && ! $field['multiple'] ) {
|
109 |
$value = reset( $value );
|
110 |
}
|
inc/fields/taxonomy.php
CHANGED
@@ -1,19 +1,22 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Taxonomy field class which set post terms when saving.
|
4 |
*/
|
5 |
class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
|
6 |
-
|
7 |
/**
|
8 |
-
* Add default value for 'taxonomy' field
|
9 |
*
|
10 |
-
* @param $field
|
11 |
* @return array
|
12 |
*/
|
13 |
public static function normalize( $field ) {
|
14 |
-
|
15 |
-
* Backwards compatibility with field args
|
16 |
-
*/
|
17 |
if ( isset( $field['options']['args'] ) ) {
|
18 |
$field['query_args'] = $field['options']['args'];
|
19 |
}
|
@@ -24,44 +27,40 @@ class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
|
|
24 |
$field['field_type'] = $field['options']['type'];
|
25 |
}
|
26 |
|
27 |
-
|
28 |
-
* Set default field args
|
29 |
-
*/
|
30 |
$field = parent::normalize( $field );
|
31 |
$field = wp_parse_args( $field, array(
|
32 |
'taxonomy' => 'category',
|
33 |
) );
|
34 |
|
35 |
-
|
36 |
-
* Set default query args
|
37 |
-
*/
|
38 |
$field['query_args'] = wp_parse_args( $field['query_args'], array(
|
39 |
'hide_empty' => false,
|
40 |
) );
|
41 |
|
42 |
-
|
43 |
-
* Set default placeholder
|
44 |
-
* - If multiple taxonomies: show 'Select a term'
|
45 |
-
* - If single taxonomy: show 'Select a %taxonomy_name%'
|
46 |
*/
|
47 |
if ( empty( $field['placeholder'] ) ) {
|
48 |
$field['placeholder'] = __( 'Select a term', 'meta-box' );
|
49 |
if ( is_string( $field['taxonomy'] ) && taxonomy_exists( $field['taxonomy'] ) ) {
|
50 |
-
$taxonomy_object
|
|
|
|
|
51 |
$field['placeholder'] = sprintf( __( 'Select a %s', 'meta-box' ), $taxonomy_object->labels->singular_name );
|
52 |
}
|
53 |
}
|
54 |
|
55 |
-
|
56 |
-
* Prevent cloning for taxonomy field
|
57 |
-
*/
|
58 |
$field['clone'] = false;
|
59 |
|
60 |
return $field;
|
61 |
}
|
62 |
|
63 |
/**
|
64 |
-
* Get field names of object to be used by walker
|
65 |
*
|
66 |
* @return array
|
67 |
*/
|
@@ -74,9 +73,9 @@ class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
|
|
74 |
}
|
75 |
|
76 |
/**
|
77 |
-
* Get options for selects, checkbox list, etc via the terms
|
78 |
*
|
79 |
-
* @param array $field Field parameters
|
80 |
*
|
81 |
* @return array
|
82 |
*/
|
@@ -86,12 +85,12 @@ class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
|
|
86 |
}
|
87 |
|
88 |
/**
|
89 |
-
* Save meta value
|
90 |
*
|
91 |
-
* @param mixed $new
|
92 |
-
* @param mixed $old
|
93 |
-
* @param int $post_id
|
94 |
-
* @param array $field
|
95 |
*/
|
96 |
public static function save( $new, $old, $post_id, $field ) {
|
97 |
$new = array_unique( array_map( 'intval', (array) $new ) );
|
@@ -100,10 +99,10 @@ class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
|
|
100 |
}
|
101 |
|
102 |
/**
|
103 |
-
* Get raw meta value
|
104 |
*
|
105 |
-
* @param int $post_id
|
106 |
-
* @param array $field
|
107 |
*
|
108 |
* @return mixed
|
109 |
*/
|
@@ -113,24 +112,30 @@ class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
|
|
113 |
}
|
114 |
|
115 |
$meta = get_the_terms( $post_id, $field['taxonomy'] );
|
116 |
-
|
117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
}
|
119 |
|
120 |
/**
|
121 |
-
* Get the field value
|
122 |
-
* Return list of post term objects
|
123 |
*
|
124 |
-
* @param array $field Field parameters
|
125 |
-
* @param array $args Additional arguments.
|
126 |
* @param int|null $post_id Post ID. null for current post. Optional.
|
127 |
*
|
128 |
-
* @return array List of post term objects
|
129 |
*/
|
130 |
public static function get_value( $field, $args = array(), $post_id = null ) {
|
131 |
$value = get_the_terms( $post_id, $field['taxonomy'] );
|
132 |
|
133 |
-
// Get single value if necessary
|
134 |
if ( ! $field['clone'] && ! $field['multiple'] && is_array( $value ) ) {
|
135 |
$value = reset( $value );
|
136 |
}
|
@@ -138,16 +143,17 @@ class RWMB_Taxonomy_Field extends RWMB_Object_Choice_Field {
|
|
138 |
}
|
139 |
|
140 |
/**
|
141 |
-
* Get option label
|
142 |
*
|
143 |
-
* @param
|
144 |
-
* @param
|
145 |
*
|
146 |
* @return string
|
147 |
*/
|
148 |
public static function get_option_label( $field, $value ) {
|
149 |
return sprintf(
|
150 |
'<a href="%s" title="%s">%s</a>',
|
|
|
151 |
esc_url( get_term_link( $value ) ),
|
152 |
esc_attr( $value->name ),
|
153 |
$value->name
|
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 default value for 'taxonomy' field.
|
14 |
*
|
15 |
+
* @param array $field Field parameters.
|
16 |
* @return array
|
17 |
*/
|
18 |
public static function normalize( $field ) {
|
19 |
+
// Backwards compatibility with field args.
|
|
|
|
|
20 |
if ( isset( $field['options']['args'] ) ) {
|
21 |
$field['query_args'] = $field['options']['args'];
|
22 |
}
|
27 |
$field['field_type'] = $field['options']['type'];
|
28 |
}
|
29 |
|
30 |
+
// Set default field args.
|
|
|
|
|
31 |
$field = parent::normalize( $field );
|
32 |
$field = wp_parse_args( $field, array(
|
33 |
'taxonomy' => 'category',
|
34 |
) );
|
35 |
|
36 |
+
// Set default query args.
|
|
|
|
|
37 |
$field['query_args'] = wp_parse_args( $field['query_args'], array(
|
38 |
'hide_empty' => false,
|
39 |
) );
|
40 |
|
41 |
+
/*
|
42 |
+
* Set default placeholder:
|
43 |
+
* - If multiple taxonomies: show 'Select a term'.
|
44 |
+
* - If single taxonomy: show 'Select a %taxonomy_name%'.
|
45 |
*/
|
46 |
if ( empty( $field['placeholder'] ) ) {
|
47 |
$field['placeholder'] = __( 'Select a term', 'meta-box' );
|
48 |
if ( is_string( $field['taxonomy'] ) && taxonomy_exists( $field['taxonomy'] ) ) {
|
49 |
+
$taxonomy_object = get_taxonomy( $field['taxonomy'] );
|
50 |
+
|
51 |
+
// Translators: %s is the taxonomy singular label.
|
52 |
$field['placeholder'] = sprintf( __( 'Select a %s', 'meta-box' ), $taxonomy_object->labels->singular_name );
|
53 |
}
|
54 |
}
|
55 |
|
56 |
+
// Prevent cloning for taxonomy field.
|
|
|
|
|
57 |
$field['clone'] = false;
|
58 |
|
59 |
return $field;
|
60 |
}
|
61 |
|
62 |
/**
|
63 |
+
* Get field names of object to be used by walker.
|
64 |
*
|
65 |
* @return array
|
66 |
*/
|
73 |
}
|
74 |
|
75 |
/**
|
76 |
+
* Get options for selects, checkbox list, etc via the terms.
|
77 |
*
|
78 |
+
* @param array $field Field parameters.
|
79 |
*
|
80 |
* @return array
|
81 |
*/
|
85 |
}
|
86 |
|
87 |
/**
|
88 |
+
* Save meta value.
|
89 |
*
|
90 |
+
* @param mixed $new The submitted meta value.
|
91 |
+
* @param mixed $old The existing meta value.
|
92 |
+
* @param int $post_id The post ID.
|
93 |
+
* @param array $field The field parameters.
|
94 |
*/
|
95 |
public static function save( $new, $old, $post_id, $field ) {
|
96 |
$new = array_unique( array_map( 'intval', (array) $new ) );
|
99 |
}
|
100 |
|
101 |
/**
|
102 |
+
* Get raw meta value.
|
103 |
*
|
104 |
+
* @param int $post_id The post ID.
|
105 |
+
* @param array $field The field parameters.
|
106 |
*
|
107 |
* @return mixed
|
108 |
*/
|
112 |
}
|
113 |
|
114 |
$meta = get_the_terms( $post_id, $field['taxonomy'] );
|
115 |
+
|
116 |
+
if ( ! is_array( $meta ) || empty( $meta ) ) {
|
117 |
+
return $field['multiple'] ? array() : '';
|
118 |
+
}
|
119 |
+
|
120 |
+
$meta = wp_list_pluck( $meta, 'term_id' );
|
121 |
+
|
122 |
+
return $field['multiple'] ? $meta : reset( $meta );
|
123 |
}
|
124 |
|
125 |
/**
|
126 |
+
* Get the field value.
|
127 |
+
* Return list of post term objects.
|
128 |
*
|
129 |
+
* @param array $field Field parameters.
|
130 |
+
* @param array $args Additional arguments.
|
131 |
* @param int|null $post_id Post ID. null for current post. Optional.
|
132 |
*
|
133 |
+
* @return array List of post term objects.
|
134 |
*/
|
135 |
public static function get_value( $field, $args = array(), $post_id = null ) {
|
136 |
$value = get_the_terms( $post_id, $field['taxonomy'] );
|
137 |
|
138 |
+
// Get single value if necessary.
|
139 |
if ( ! $field['clone'] && ! $field['multiple'] && is_array( $value ) ) {
|
140 |
$value = reset( $value );
|
141 |
}
|
143 |
}
|
144 |
|
145 |
/**
|
146 |
+
* Get option label.
|
147 |
*
|
148 |
+
* @param array $field Field parameters.
|
149 |
+
* @param object $value The term object.
|
150 |
*
|
151 |
* @return string
|
152 |
*/
|
153 |
public static function get_option_label( $field, $value ) {
|
154 |
return sprintf(
|
155 |
'<a href="%s" title="%s">%s</a>',
|
156 |
+
// @codingStandardsIgnoreLine
|
157 |
esc_url( get_term_link( $value ) ),
|
158 |
esc_attr( $value->name ),
|
159 |
$value->name
|
inc/fields/text-list.php
CHANGED
@@ -1,19 +1,23 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
* Text list field class.
|
5 |
*/
|
6 |
class RWMB_Text_List_Field extends RWMB_Multiple_Values_Field {
|
7 |
-
|
8 |
/**
|
9 |
-
* Get field HTML
|
10 |
*
|
11 |
-
* @param mixed $meta
|
12 |
-
* @param array $field
|
13 |
*
|
14 |
* @return string
|
15 |
*/
|
16 |
-
static function html( $meta, $field ) {
|
17 |
$html = array();
|
18 |
$input = '<label><input type="text" class="rwmb-text-list" name="%s" value="%s" placeholder="%s"> %s</label>';
|
19 |
|
@@ -35,8 +39,8 @@ class RWMB_Text_List_Field extends RWMB_Multiple_Values_Field {
|
|
35 |
/**
|
36 |
* Format value for the helper functions.
|
37 |
*
|
38 |
-
* @param array $field Field
|
39 |
-
* @param string|array $value The field meta value
|
40 |
* @return string
|
41 |
*/
|
42 |
public static function format_value( $field, $value ) {
|
@@ -60,8 +64,8 @@ class RWMB_Text_List_Field extends RWMB_Multiple_Values_Field {
|
|
60 |
/**
|
61 |
* Format a single value for the helper functions.
|
62 |
*
|
63 |
-
* @param array $field Field
|
64 |
-
* @param array $value The value
|
65 |
* @return string
|
66 |
*/
|
67 |
public static function format_single_value( $field, $value ) {
|
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 |
+
* Get field HTML.
|
14 |
*
|
15 |
+
* @param mixed $meta Meta value.
|
16 |
+
* @param array $field Field parameters.
|
17 |
*
|
18 |
* @return string
|
19 |
*/
|
20 |
+
public static function html( $meta, $field ) {
|
21 |
$html = array();
|
22 |
$input = '<label><input type="text" class="rwmb-text-list" name="%s" value="%s" placeholder="%s"> %s</label>';
|
23 |
|
39 |
/**
|
40 |
* Format value for the helper functions.
|
41 |
*
|
42 |
+
* @param array $field Field parameters.
|
43 |
+
* @param string|array $value The field meta value.
|
44 |
* @return string
|
45 |
*/
|
46 |
public static function format_value( $field, $value ) {
|
64 |
/**
|
65 |
* Format a single value for the helper functions.
|
66 |
*
|
67 |
+
* @param array $field Field parameters.
|
68 |
+
* @param array $value The value.
|
69 |
* @return string
|
70 |
*/
|
71 |
public static function format_single_value( $field, $value ) {
|
inc/fields/text.php
CHANGED
@@ -1,16 +1,21 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Text field class.
|
4 |
*/
|
5 |
class RWMB_Text_Field extends RWMB_Input_Field {
|
6 |
-
|
7 |
/**
|
8 |
-
* Normalize parameters for field
|
9 |
*
|
10 |
-
* @param array $field
|
11 |
* @return array
|
12 |
*/
|
13 |
-
static function normalize( $field ) {
|
14 |
$field = parent::normalize( $field );
|
15 |
|
16 |
$field = wp_parse_args( $field, array(
|
@@ -23,14 +28,14 @@ class RWMB_Text_Field extends RWMB_Input_Field {
|
|
23 |
}
|
24 |
|
25 |
/**
|
26 |
-
* Get the attributes for a field
|
27 |
*
|
28 |
-
* @param array $field
|
29 |
-
* @param mixed $value
|
30 |
*
|
31 |
* @return array
|
32 |
*/
|
33 |
-
static function get_attributes( $field, $value = null ) {
|
34 |
$attributes = parent::get_attributes( $field, $value );
|
35 |
$attributes = wp_parse_args( $attributes, array(
|
36 |
'size' => $field['size'],
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* The text field.
|
4 |
+
*
|
5 |
+
* @package Meta Box
|
6 |
+
*/
|
7 |
+
|
8 |
/**
|
9 |
* Text field class.
|
10 |
*/
|
11 |
class RWMB_Text_Field extends RWMB_Input_Field {
|
|
|
12 |
/**
|
13 |
+
* Normalize parameters for field.
|
14 |
*
|
15 |
+
* @param array $field Field parameters.
|
16 |
* @return array
|
17 |
*/
|
18 |
+
public static function normalize( $field ) {
|
19 |
$field = parent::normalize( $field );
|
20 |
|
21 |
$field = wp_parse_args( $field, array(
|
28 |
}
|
29 |
|
30 |
/**
|
31 |
+
* Get the attributes for a field.
|
32 |
*
|
33 |
+
* @param array $field Field parameters.
|
34 |
+
* @param mixed $value Meta value.
|
35 |
*
|
36 |
* @return array
|
37 |
*/
|
38 |
+
public static function get_attributes( $field, $value = null ) {
|
39 |
$attributes = parent::get_attributes( $field, $value );
|
40 |
$attributes = wp_parse_args( $attributes, array(
|
41 |
'size' => $field['size'],
|
inc/fields/textarea.php
CHANGED
@@ -1,18 +1,23 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Textarea field class.
|
4 |
*/
|
5 |
class RWMB_Textarea_Field extends RWMB_Field {
|
6 |
-
|
7 |
/**
|
8 |
-
* Get field HTML
|
9 |
*
|
10 |
-
* @param mixed $meta
|
11 |
-
* @param array $field
|
12 |
*
|
13 |
* @return string
|
14 |
*/
|
15 |
-
static function html( $meta, $field ) {
|
16 |
$attributes = self::get_attributes( $field, $meta );
|
17 |
return sprintf(
|
18 |
'<textarea %s>%s</textarea>',
|
@@ -22,22 +27,22 @@ class RWMB_Textarea_Field extends RWMB_Field {
|
|
22 |
}
|
23 |
|
24 |
/**
|
25 |
-
* Escape meta for field output
|
26 |
*
|
27 |
-
* @param mixed $meta
|
28 |
* @return mixed
|
29 |
*/
|
30 |
-
static function esc_meta( $meta ) {
|
31 |
return is_array( $meta ) ? array_map( 'esc_textarea', $meta ) : esc_textarea( $meta );
|
32 |
}
|
33 |
|
34 |
/**
|
35 |
-
* Normalize parameters for field
|
36 |
*
|
37 |
-
* @param array $field
|
38 |
* @return array
|
39 |
*/
|
40 |
-
static function normalize( $field ) {
|
41 |
$field = parent::normalize( $field );
|
42 |
$field = wp_parse_args( $field, array(
|
43 |
'cols' => 60,
|
@@ -51,14 +56,14 @@ class RWMB_Textarea_Field extends RWMB_Field {
|
|
51 |
}
|
52 |
|
53 |
/**
|
54 |
-
* Get the attributes for a field
|
55 |
*
|
56 |
-
* @param array $field
|
57 |
-
* @param mixed $value
|
58 |
*
|
59 |
* @return array
|
60 |
*/
|
61 |
-
static function get_attributes( $field, $value = null ) {
|
62 |
$attributes = parent::get_attributes( $field, $value );
|
63 |
$attributes = wp_parse_args( $attributes, array(
|
64 |
'cols' => $field['cols'],
|
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 |
/**
|
13 |
+
* Get field HTML.
|
14 |
*
|
15 |
+
* @param mixed $meta Meta value.
|
16 |
+
* @param array $field Field parameters.
|
17 |
*
|
18 |
* @return string
|
19 |
*/
|
20 |
+
public static function html( $meta, $field ) {
|
21 |
$attributes = self::get_attributes( $field, $meta );
|
22 |
return sprintf(
|
23 |
'<textarea %s>%s</textarea>',
|
27 |
}
|
28 |
|
29 |
/**
|
30 |
+
* Escape meta for field output.
|
31 |
*
|
32 |
+
* @param mixed $meta Meta value.
|
33 |
* @return mixed
|
34 |
*/
|
35 |
+
public static function esc_meta( $meta ) {
|
36 |
return is_array( $meta ) ? array_map( 'esc_textarea', $meta ) : esc_textarea( $meta );
|
37 |
}
|
38 |
|
39 |
/**
|
40 |
+
* Normalize parameters for field.
|
41 |
*
|
42 |
+
* @param array $field Field parameters.
|
43 |
* @return array
|
44 |
*/
|
45 |
+
public static function normalize( $field ) {
|
46 |
$field = parent::normalize( $field );
|
47 |
$field = wp_parse_args( $field, array(
|
48 |
'cols' => 60,
|
56 |
}
|
57 |
|
58 |
/**
|
59 |
+
* Get the attributes for a field.
|
60 |
*
|
61 |
+
* @param array $field Field parameters.
|
62 |
+
* @param mixed $value Meta value.
|
63 |
*
|
64 |
* @return array
|
65 |
*/
|
66 |
+
public static function get_attributes( $field, $value = null ) {
|
67 |
$attributes = parent::get_attributes( $field, $value );
|
68 |
$attributes = wp_parse_args( $attributes, array(
|
69 |
'cols' => $field['cols'],
|
inc/fields/thickbox-image.php
CHANGED
@@ -2,10 +2,14 @@
|
|
2 |
/**
|
3 |
* Image upload field which uses thickbox library to upload.
|
4 |
*
|
|
|
5 |
* @deprecated Use image_advanced instead
|
6 |
*/
|
7 |
-
class RWMB_Thickbox_Image_Field extends RWMB_Image_Field {
|
8 |
|
|
|
|
|
|
|
|
|
9 |
/**
|
10 |
* Add custom actions for the field.
|
11 |
*/
|
@@ -15,20 +19,20 @@ class RWMB_Thickbox_Image_Field extends RWMB_Image_Field {
|
|
15 |
}
|
16 |
|
17 |
/**
|
18 |
-
* Always enable insert to post button in the popup
|
19 |
*
|
20 |
* @link https://github.com/rilwis/meta-box/issues/809
|
21 |
* @link http://wordpress.stackexchange.com/q/22175/2051
|
22 |
-
* @param array $vars
|
23 |
* @return array
|
24 |
*/
|
25 |
public static function allow_img_insertion( $vars ) {
|
26 |
-
$vars['send'] = true; // 'send' as in "Send to Editor"
|
27 |
return $vars;
|
28 |
}
|
29 |
|
30 |
/**
|
31 |
-
* Enqueue scripts and styles
|
32 |
*/
|
33 |
public static function admin_enqueue_scripts() {
|
34 |
parent::admin_enqueue_scripts();
|
@@ -40,33 +44,33 @@ class RWMB_Thickbox_Image_Field extends RWMB_Image_Field {
|
|
40 |
}
|
41 |
|
42 |
/**
|
43 |
-
* Get field HTML
|
44 |
*
|
45 |
-
* @param mixed $meta
|
46 |
-
* @param array $field
|
47 |
*
|
48 |
* @return string
|
49 |
*/
|
50 |
public static function html( $meta, $field ) {
|
51 |
$i18n_title = apply_filters( 'rwmb_thickbox_image_upload_string', _x( 'Upload Images', 'image upload', 'meta-box' ), $field );
|
52 |
|
53 |
-
// Uploaded images
|
54 |
$html = parent::get_uploaded_files( $meta, $field );
|
55 |
|
56 |
-
// Show form upload
|
57 |
$html .= "<a href='#' class='button rwmb-thickbox-upload' data-field_id='{$field['id']}'>{$i18n_title}</a>";
|
58 |
|
59 |
return $html;
|
60 |
}
|
61 |
|
62 |
/**
|
63 |
-
* Get field value
|
64 |
-
* It's the combination of new (uploaded) images and saved images
|
65 |
*
|
66 |
-
* @param
|
67 |
-
* @param
|
68 |
-
* @param int $post_id
|
69 |
-
* @param array $field
|
70 |
*
|
71 |
* @return array
|
72 |
*/
|
2 |
/**
|
3 |
* Image upload field which uses thickbox library to upload.
|
4 |
*
|
5 |
+
* @package Meta Box
|
6 |
* @deprecated Use image_advanced instead
|
7 |
*/
|
|
|
8 |
|
9 |
+
/**
|
10 |
+
* The thickbox image field class.
|
11 |
+
*/
|
12 |
+
class RWMB_Thickbox_Image_Field extends RWMB_Image_Field {
|
13 |
/**
|
14 |
* Add custom actions for the field.
|
15 |
*/
|
19 |
}
|
20 |
|
21 |
/**
|
22 |
+
* Always enable insert to post button in the popup.
|
23 |
*
|
24 |
* @link https://github.com/rilwis/meta-box/issues/809
|
25 |
* @link http://wordpress.stackexchange.com/q/22175/2051
|
26 |
+
* @param array $vars Media item arguments in the popup.
|
27 |
* @return array
|
28 |
*/
|
29 |
public static function allow_img_insertion( $vars ) {
|
30 |
+
$vars['send'] = true; // 'send' as in "Send to Editor".
|
31 |
return $vars;
|
32 |
}
|
33 |
|
34 |
/**
|
35 |
+
* Enqueue scripts and styles.
|
36 |
*/
|
37 |
public static function admin_enqueue_scripts() {
|
38 |
parent::admin_enqueue_scripts();
|
44 |
}
|
45 |
|
46 |
/**
|
47 |
+
* Get field HTML.
|
48 |
*
|
49 |
+
* @param mixed $meta Meta value.
|
50 |
+
* @param array $field Field parameters.
|
51 |
*
|
52 |
* @return string
|
53 |
*/
|
54 |
public static function html( $meta, $field ) {
|
55 |
$i18n_title = apply_filters( 'rwmb_thickbox_image_upload_string', _x( 'Upload Images', 'image upload', 'meta-box' ), $field );
|
56 |
|
57 |
+
// Uploaded images.
|
58 |
$html = parent::get_uploaded_files( $meta, $field );
|
59 |
|
60 |
+
// Show form upload.
|
61 |
$html .= "<a href='#' class='button rwmb-thickbox-upload' data-field_id='{$field['id']}'>{$i18n_title}</a>";
|
62 |
|
63 |
return $html;
|
64 |
}
|
65 |
|
66 |
/**
|
67 |
+
* Get field value.
|
68 |
+
* It's the combination of new (uploaded) images and saved images.
|
69 |
*
|
70 |
+
* @param mixed $new The submitted meta value.
|
71 |
+
* @param mixed $old The existing meta value.
|
72 |
+
* @param int $post_id The post ID.
|
73 |
+
* @param array $field The field parameters.
|
74 |
*
|
75 |
* @return array
|
76 |
*/
|
inc/fields/time.php
CHANGED
@@ -1,13 +1,16 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* Time field class.
|
4 |
*/
|
5 |
class RWMB_Time_Field extends RWMB_Datetime_Field {
|
6 |
-
|
7 |
/**
|
8 |
-
* Enqueue scripts and styles
|
9 |
-
*
|
10 |
-
* @return void
|
11 |
*/
|
12 |
public static function admin_enqueue_scripts() {
|
13 |
parent::admin_register_scripts();
|
@@ -16,9 +19,9 @@ class RWMB_Time_Field extends RWMB_Datetime_Field {
|
|
16 |
}
|
17 |
|
18 |
/**
|
19 |
-
* Normalize parameters for field
|
20 |
*
|
21 |
-
* @param array $field
|
22 |
* @return array
|
23 |
*/
|
24 |
public static function normalize( $field ) {
|
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::admin_register_scripts();
|
19 |
}
|
20 |
|
21 |
/**
|
22 |
+
* Normalize parameters for field.
|
23 |
*
|
24 |
+
* @param array $field Field parameters.
|
25 |
* @return array
|
26 |
*/
|
27 |
public static function normalize( $field ) {
|
inc/fields/user.php
CHANGED
@@ -1,40 +1,35 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
* User field class.
|
4 |
*/
|
5 |
class RWMB_User_Field extends RWMB_Object_Choice_Field {
|
6 |
-
|
7 |
/**
|
8 |
-
* Normalize parameters for field
|
9 |
*
|
10 |
-
* @param array $field
|
11 |
*
|
12 |
* @return array
|
13 |
*/
|
14 |
public static function normalize( $field ) {
|
15 |
-
|
16 |
-
* Set default field args
|
17 |
-
*/
|
18 |
$field = parent::normalize( $field );
|
19 |
|
20 |
-
|
21 |
-
* Prevent select tree for user since it's not hierarchical
|
22 |
-
*/
|
23 |
$field['field_type'] = 'select_tree' === $field['field_type'] ? 'select' : $field['field_type'];
|
24 |
|
25 |
-
|
26 |
-
* Set to always flat
|
27 |
-
*/
|
28 |
$field['flatten'] = true;
|
29 |
|
30 |
-
|
31 |
-
* Set default placeholder
|
32 |
-
*/
|
33 |
$field['placeholder'] = empty( $field['placeholder'] ) ? __( 'Select an user', 'meta-box' ) : $field['placeholder'];
|
34 |
|
35 |
-
|
36 |
-
* Set default query args
|
37 |
-
*/
|
38 |
$field['query_args'] = wp_parse_args( $field['query_args'], array(
|
39 |
'orderby' => 'display_name',
|
40 |
'order' => 'asc',
|
@@ -46,9 +41,9 @@ class RWMB_User_Field extends RWMB_Object_Choice_Field {
|
|
46 |
}
|
47 |
|
48 |
/**
|
49 |
-
* Get users
|
50 |
*
|
51 |
-
* @param array $field
|
52 |
*
|
53 |
* @return array
|
54 |
*/
|
@@ -58,7 +53,7 @@ class RWMB_User_Field extends RWMB_Object_Choice_Field {
|
|
58 |
}
|
59 |
|
60 |
/**
|
61 |
-
* Get field names of object to be used by walker
|
62 |
*
|
63 |
* @return array
|
64 |
*/
|
@@ -71,10 +66,10 @@ class RWMB_User_Field extends RWMB_Object_Choice_Field {
|
|
71 |
}
|
72 |
|
73 |
/**
|
74 |
-
* Get option label
|
75 |
*
|
76 |
-
* @param
|
77 |
-
* @param
|
78 |
*
|
79 |
* @return string
|
80 |
*/
|
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 |
+
* Normalize parameters for field.
|
14 |
*
|
15 |
+
* @param array $field Field parameters.
|
16 |
*
|
17 |
* @return array
|
18 |
*/
|
19 |
public static function normalize( $field ) {
|
20 |
+
// Set default field args.
|
|
|
|
|
21 |
$field = parent::normalize( $field );
|
22 |
|
23 |
+
// Prevent select tree for user since it's not hierarchical.
|
|
|
|
|
24 |
$field['field_type'] = 'select_tree' === $field['field_type'] ? 'select' : $field['field_type'];
|
25 |
|
26 |
+
// Set to always flat.
|
|
|
|
|
27 |
$field['flatten'] = true;
|
28 |
|
29 |
+
// Set default placeholder.
|
|
|
|
|
30 |
$field['placeholder'] = empty( $field['placeholder'] ) ? __( 'Select an user', 'meta-box' ) : $field['placeholder'];
|
31 |
|
32 |
+
// Set default query args.
|
|
|
|
|
33 |
$field['query_args'] = wp_parse_args( $field['query_args'], array(
|
34 |
'orderby' => 'display_name',
|
35 |
'order' => 'asc',
|
41 |
}
|
42 |
|
43 |
/**
|
44 |
+
* Get users.
|
45 |
*
|
46 |
+
* @param array $field Field parameters.
|
47 |
*
|
48 |
* @return array
|
49 |
*/
|
53 |
}
|
54 |
|
55 |
/**
|
56 |
+
* Get field names of object to be used by walker.
|
57 |
*
|
58 |
* @return array
|
59 |
*/
|
66 |
}
|
67 |
|
68 |
/**
|
69 |
+
* Get option label.
|
70 |
*
|
71 |
+
* @param array $field Field parameters.
|
72 |
+
* @param string $value Option value.
|
73 |
*
|
74 |
* @return string
|
75 |
*/
|
inc/fields/video.php
CHANGED
@@ -3,6 +3,7 @@
|
|
3 |
* Video field which uses WordPress media popup to upload and select video.
|
4 |
*
|
5 |
* @package Meta Box
|
|
|
6 |
*/
|
7 |
|
8 |
/**
|
@@ -10,9 +11,7 @@
|
|
10 |
*/
|
11 |
class RWMB_Video_Field extends RWMB_Media_Field {
|
12 |
/**
|
13 |
-
* Enqueue scripts and styles
|
14 |
-
*
|
15 |
-
* @return void
|
16 |
*/
|
17 |
public static function admin_enqueue_scripts() {
|
18 |
parent::admin_enqueue_scripts();
|
@@ -24,15 +23,15 @@ class RWMB_Video_Field extends RWMB_Media_Field {
|
|
24 |
}
|
25 |
|
26 |
/**
|
27 |
-
* Normalize parameters for field
|
28 |
*
|
29 |
-
* @param array $field
|
30 |
*
|
31 |
* @return array
|
32 |
*/
|
33 |
public static function normalize( $field ) {
|
34 |
-
$field = parent::normalize( $field );
|
35 |
$field['mime_type'] = 'video';
|
|
|
36 |
|
37 |
return $field;
|
38 |
}
|
@@ -40,13 +39,13 @@ class RWMB_Video_Field extends RWMB_Media_Field {
|
|
40 |
/**
|
41 |
* Get uploaded file information.
|
42 |
*
|
43 |
-
* @param int
|
44 |
* @param array $args Array of arguments (for size).
|
45 |
*
|
46 |
-
* @return array|bool False if file not found. Array of image info on success
|
47 |
*/
|
48 |
public static function file_info( $file_id, $args = array() ) {
|
49 |
-
if ( !
|
50 |
return false;
|
51 |
}
|
52 |
$attachment = get_post( $file_id );
|
@@ -103,8 +102,8 @@ class RWMB_Video_Field extends RWMB_Media_Field {
|
|
103 |
/**
|
104 |
* Format a single value for the helper functions.
|
105 |
*
|
106 |
-
* @param array $field Field
|
107 |
-
* @param array $value The value
|
108 |
*
|
109 |
* @return string
|
110 |
*/
|
@@ -118,8 +117,7 @@ class RWMB_Video_Field extends RWMB_Media_Field {
|
|
118 |
}
|
119 |
|
120 |
/**
|
121 |
-
* Template for media item
|
122 |
-
* @return void
|
123 |
*/
|
124 |
public static function print_templates() {
|
125 |
parent::print_templates();
|
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 |
/**
|
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();
|
23 |
}
|
24 |
|
25 |
/**
|
26 |
+
* Normalize parameters for field.
|
27 |
*
|
28 |
+
* @param array $field Field parameters.
|
29 |
*
|
30 |
* @return array
|
31 |
*/
|
32 |
public static function normalize( $field ) {
|
|
|
33 |
$field['mime_type'] = 'video';
|
34 |
+
$field = parent::normalize( $field );
|
35 |
|
36 |
return $field;
|
37 |
}
|
39 |
/**
|
40 |
* Get uploaded file information.
|
41 |
*
|
42 |
+
* @param int $file_id Attachment image ID (post ID). Required.
|
43 |
* @param array $args Array of arguments (for size).
|
44 |
*
|
45 |
+
* @return array|bool False if file not found. Array of image info on success.
|
46 |
*/
|
47 |
public static function file_info( $file_id, $args = array() ) {
|
48 |
+
if ( ! get_attached_file( $file_id ) ) {
|
49 |
return false;
|
50 |
}
|
51 |
$attachment = get_post( $file_id );
|
102 |
/**
|
103 |
* Format a single value for the helper functions.
|
104 |
*
|
105 |
+
* @param array $field Field parameters.
|
106 |
+
* @param array $value The value.
|
107 |
*
|
108 |
* @return string
|
109 |
*/
|
117 |
}
|
118 |
|
119 |
/**
|
120 |
+
* Template for media item.
|
|
|
121 |
*/
|
122 |
public static function print_templates() {
|
123 |
parent::print_templates();
|
inc/fields/wysiwyg.php
CHANGED
@@ -1,75 +1,79 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
* WYSIWYG (editor) field class.
|
5 |
*/
|
6 |
class RWMB_Wysiwyg_Field extends RWMB_Field {
|
7 |
-
|
8 |
/**
|
9 |
* Array of cloneable editors.
|
10 |
*
|
11 |
* @var array
|
12 |
*/
|
13 |
-
static $cloneable_editors = array();
|
14 |
|
15 |
/**
|
16 |
* Enqueue scripts and styles.
|
17 |
*/
|
18 |
-
static function admin_enqueue_scripts() {
|
19 |
wp_enqueue_style( 'rwmb-wysiwyg', RWMB_CSS_URL . 'wysiwyg.css', array(), RWMB_VER );
|
20 |
wp_enqueue_script( 'rwmb-wysiwyg', RWMB_JS_URL . 'wysiwyg.js', array( 'jquery' ), RWMB_VER, true );
|
21 |
}
|
22 |
|
23 |
/**
|
24 |
-
* Change field value on save
|
25 |
*
|
26 |
-
* @param mixed $new
|
27 |
-
* @param mixed $old
|
28 |
-
* @param int $post_id
|
29 |
-
* @param array $field
|
30 |
* @return string
|
31 |
*/
|
32 |
-
static function value( $new, $old, $post_id, $field ) {
|
33 |
return $field['raw'] ? $new : wpautop( $new );
|
34 |
}
|
35 |
|
36 |
/**
|
37 |
-
* Get field HTML
|
38 |
*
|
39 |
-
* @param mixed $meta
|
40 |
-
* @param array $field
|
41 |
* @return string
|
42 |
*/
|
43 |
-
static function html( $meta, $field ) {
|
44 |
-
// Using output buffering because wp_editor() echos directly
|
45 |
ob_start();
|
46 |
|
47 |
$field['options']['textarea_name'] = $field['field_name'];
|
48 |
$attributes = self::get_attributes( $field );
|
49 |
|
50 |
-
// Use new wp_editor() since WP 3.3
|
51 |
wp_editor( $meta, $attributes['id'], $field['options'] );
|
52 |
|
53 |
return ob_get_clean();
|
54 |
}
|
55 |
|
56 |
/**
|
57 |
-
* Escape meta for field output
|
58 |
*
|
59 |
-
* @param mixed $meta
|
60 |
* @return mixed
|
61 |
*/
|
62 |
-
static function esc_meta( $meta ) {
|
63 |
return $meta;
|
64 |
}
|
65 |
|
66 |
/**
|
67 |
-
* Normalize parameters for field
|
68 |
*
|
69 |
-
* @param array $field
|
70 |
* @return array
|
71 |
*/
|
72 |
-
static function normalize( $field ) {
|
73 |
$field = parent::normalize( $field );
|
74 |
$field = wp_parse_args( $field, array(
|
75 |
'raw' => false,
|
@@ -78,10 +82,10 @@ class RWMB_Wysiwyg_Field extends RWMB_Field {
|
|
78 |
|
79 |
$field['options'] = wp_parse_args( $field['options'], array(
|
80 |
'editor_class' => 'rwmb-wysiwyg',
|
81 |
-
'dfw' => true, // Use default WordPress full screen UI
|
82 |
) );
|
83 |
|
84 |
-
// Keep the filter to be compatible with previous versions
|
85 |
$field['options'] = apply_filters( 'rwmb_wysiwyg_settings', $field['options'] );
|
86 |
|
87 |
return $field;
|
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 |
* Array of cloneable editors.
|
14 |
*
|
15 |
* @var array
|
16 |
*/
|
17 |
+
protected static $cloneable_editors = array();
|
18 |
|
19 |
/**
|
20 |
* Enqueue scripts and styles.
|
21 |
*/
|
22 |
+
public static function admin_enqueue_scripts() {
|
23 |
wp_enqueue_style( 'rwmb-wysiwyg', RWMB_CSS_URL . 'wysiwyg.css', array(), RWMB_VER );
|
24 |
wp_enqueue_script( 'rwmb-wysiwyg', RWMB_JS_URL . 'wysiwyg.js', array( 'jquery' ), RWMB_VER, true );
|
25 |
}
|
26 |
|
27 |
/**
|
28 |
+
* Change field value on save.
|
29 |
*
|
30 |
+
* @param mixed $new The submitted meta value.
|
31 |
+
* @param mixed $old The existing meta value.
|
32 |
+
* @param int $post_id The post ID.
|
33 |
+
* @param array $field The field parameters.
|
34 |
* @return string
|
35 |
*/
|
36 |
+
public static function value( $new, $old, $post_id, $field ) {
|
37 |
return $field['raw'] ? $new : wpautop( $new );
|
38 |
}
|
39 |
|
40 |
/**
|
41 |
+
* Get field HTML.
|
42 |
*
|
43 |
+
* @param mixed $meta Meta value.
|
44 |
+
* @param array $field Field parameters.
|
45 |
* @return string
|
46 |
*/
|
47 |
+
public static function html( $meta, $field ) {
|
48 |
+
// Using output buffering because wp_editor() echos directly.
|
49 |
ob_start();
|
50 |
|
51 |
$field['options']['textarea_name'] = $field['field_name'];
|
52 |
$attributes = self::get_attributes( $field );
|
53 |
|
54 |
+
// Use new wp_editor() since WP 3.3.
|
55 |
wp_editor( $meta, $attributes['id'], $field['options'] );
|
56 |
|
57 |
return ob_get_clean();
|
58 |
}
|
59 |
|
60 |
/**
|
61 |
+
* Escape meta for field output.
|
62 |
*
|
63 |
+
* @param mixed $meta Meta value.
|
64 |
* @return mixed
|
65 |
*/
|
66 |
+
public static function esc_meta( $meta ) {
|
67 |
return $meta;
|
68 |
}
|
69 |
|
70 |
/**
|
71 |
+
* Normalize parameters for field.
|
72 |
*
|
73 |
+
* @param array $field Field parameters.
|
74 |
* @return array
|
75 |
*/
|
76 |
+
public static function normalize( $field ) {
|
77 |
$field = parent::normalize( $field );
|
78 |
$field = wp_parse_args( $field, array(
|
79 |
'raw' => false,
|
82 |
|
83 |
$field['options'] = wp_parse_args( $field['options'], array(
|
84 |
'editor_class' => 'rwmb-wysiwyg',
|
85 |
+
'dfw' => true, // Use default WordPress full screen UI.
|
86 |
) );
|
87 |
|
88 |
+
// Keep the filter to be compatible with previous versions.
|
89 |
$field['options'] = apply_filters( 'rwmb_wysiwyg_settings', $field['options'] );
|
90 |
|
91 |
return $field;
|
inc/functions.php
CHANGED
@@ -1,34 +1,37 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Plugin public functions.
|
|
|
|
|
4 |
*/
|
5 |
|
6 |
if ( ! function_exists( 'rwmb_meta' ) ) {
|
7 |
/**
|
8 |
-
* Get post meta
|
9 |
*
|
10 |
* @param string $key Meta key. Required.
|
11 |
-
* @param int|null $post_id Post ID. null for current post. Optional
|
12 |
* @param array $args Array of arguments. Optional.
|
|
|
13 |
*
|
14 |
* @return mixed
|
15 |
*/
|
16 |
function rwmb_meta( $key, $args = array(), $post_id = null ) {
|
17 |
$args = wp_parse_args( $args );
|
|
|
18 |
/*
|
19 |
-
* If meta boxes is registered in the backend only, we can't get field's params
|
20 |
-
* This is for backward compatibility with version < 4.8.0
|
21 |
*/
|
22 |
$field = RWMB_Helper::find_field( $key, $post_id );
|
23 |
|
24 |
/*
|
25 |
-
* If field is not found, which can caused by registering meta boxes for the backend only or conditional registration
|
26 |
-
* Then fallback to the old method to retrieve meta (which uses get_post_meta() as the latest fallback)
|
27 |
*/
|
28 |
if ( false === $field ) {
|
29 |
return apply_filters( 'rwmb_meta', RWMB_Helper::meta( $key, $args, $post_id ) );
|
30 |
}
|
31 |
-
$meta = in_array( $field['type'], array( 'oembed', 'map' ) ) ?
|
32 |
rwmb_the_value( $key, $args, $post_id, false ) :
|
33 |
rwmb_get_value( $key, $args, $post_id );
|
34 |
return apply_filters( 'rwmb_meta', $meta, $key, $args, $post_id );
|
@@ -41,7 +44,7 @@ if ( ! function_exists( 'rwmb_get_value' ) ) {
|
|
41 |
* This is used to replace old version of rwmb_meta key.
|
42 |
*
|
43 |
* @param string $field_id Field ID. Required.
|
44 |
-
* @param array $args Additional arguments. Rarely used. See specific fields for details
|
45 |
* @param int|null $post_id Post ID. null for current post. Optional.
|
46 |
*
|
47 |
* @return mixed false if field doesn't exist. Field value otherwise.
|
@@ -50,16 +53,16 @@ if ( ! function_exists( 'rwmb_get_value' ) ) {
|
|
50 |
$args = wp_parse_args( $args );
|
51 |
$field = RWMB_Helper::find_field( $field_id, $post_id );
|
52 |
|
53 |
-
// Get field value
|
54 |
$value = $field ? RWMB_Field::call( 'get_value', $field, $args, $post_id ) : false;
|
55 |
|
56 |
/*
|
57 |
-
* Allow developers to change the returned value of field
|
58 |
-
* For version < 4.8.2, the filter name was 'rwmb_get_field'
|
59 |
*
|
60 |
-
* @param mixed $value Field value
|
61 |
-
* @param array $field Field
|
62 |
-
* @param array $args Additional arguments. Rarely used. See specific fields for details
|
63 |
* @param int|null $post_id Post ID. null for current post. Optional.
|
64 |
*/
|
65 |
$value = apply_filters( 'rwmb_get_value', $value, $field, $args, $post_id );
|
@@ -73,9 +76,9 @@ if ( ! function_exists( 'rwmb_the_value' ) ) {
|
|
73 |
* Display the value of a field
|
74 |
*
|
75 |
* @param string $field_id Field ID. Required.
|
76 |
-
* @param array $args Additional arguments. Rarely used. See specific fields for details
|
77 |
* @param int|null $post_id Post ID. null for current post. Optional.
|
78 |
-
* @param bool $echo Display field meta value? Default `true` which works in almost all cases. We use `false` for the [rwmb_meta] shortcode
|
79 |
*
|
80 |
* @return string
|
81 |
*/
|
@@ -90,18 +93,18 @@ if ( ! function_exists( 'rwmb_the_value' ) ) {
|
|
90 |
$output = RWMB_Field::call( 'the_value', $field, $args, $post_id );
|
91 |
|
92 |
/*
|
93 |
-
* Allow developers to change the returned value of field
|
94 |
-
* For version < 4.8.2, the filter name was 'rwmb_get_field'
|
95 |
*
|
96 |
-
* @param mixed $value Field HTML output
|
97 |
-
* @param array $field Field
|
98 |
-
* @param array $args Additional arguments. Rarely used. See specific fields for details
|
99 |
* @param int|null $post_id Post ID. null for current post. Optional.
|
100 |
*/
|
101 |
$output = apply_filters( 'rwmb_the_value', $output, $field, $args, $post_id );
|
102 |
|
103 |
if ( $echo ) {
|
104 |
-
echo $output;
|
105 |
}
|
106 |
|
107 |
return $output;
|
@@ -110,9 +113,9 @@ if ( ! function_exists( 'rwmb_the_value' ) ) {
|
|
110 |
|
111 |
if ( ! function_exists( 'rwmb_meta_shortcode' ) ) {
|
112 |
/**
|
113 |
-
* Shortcode to display meta value
|
114 |
*
|
115 |
-
* @param array $atts Shortcode attributes, same as rwmb_meta() function, but has more "meta_key" parameter
|
116 |
*
|
117 |
* @return string
|
118 |
*/
|
1 |
<?php
|
2 |
/**
|
3 |
* Plugin public functions.
|
4 |
+
*
|
5 |
+
* @package Meta Box
|
6 |
*/
|
7 |
|
8 |
if ( ! function_exists( 'rwmb_meta' ) ) {
|
9 |
/**
|
10 |
+
* Get post meta.
|
11 |
*
|
12 |
* @param string $key Meta key. Required.
|
|
|
13 |
* @param array $args Array of arguments. Optional.
|
14 |
+
* @param int|null $post_id Post ID. null for current post. Optional.
|
15 |
*
|
16 |
* @return mixed
|
17 |
*/
|
18 |
function rwmb_meta( $key, $args = array(), $post_id = null ) {
|
19 |
$args = wp_parse_args( $args );
|
20 |
+
|
21 |
/*
|
22 |
+
* If meta boxes is registered in the backend only, we can't get field's params.
|
23 |
+
* This is for backward compatibility with version < 4.8.0.
|
24 |
*/
|
25 |
$field = RWMB_Helper::find_field( $key, $post_id );
|
26 |
|
27 |
/*
|
28 |
+
* If field is not found, which can caused by registering meta boxes for the backend only or conditional registration.
|
29 |
+
* Then fallback to the old method to retrieve meta (which uses get_post_meta() as the latest fallback).
|
30 |
*/
|
31 |
if ( false === $field ) {
|
32 |
return apply_filters( 'rwmb_meta', RWMB_Helper::meta( $key, $args, $post_id ) );
|
33 |
}
|
34 |
+
$meta = in_array( $field['type'], array( 'oembed', 'map' ), true ) ?
|
35 |
rwmb_the_value( $key, $args, $post_id, false ) :
|
36 |
rwmb_get_value( $key, $args, $post_id );
|
37 |
return apply_filters( 'rwmb_meta', $meta, $key, $args, $post_id );
|
44 |
* This is used to replace old version of rwmb_meta key.
|
45 |
*
|
46 |
* @param string $field_id Field ID. Required.
|
47 |
+
* @param array $args Additional arguments. Rarely used. See specific fields for details.
|
48 |
* @param int|null $post_id Post ID. null for current post. Optional.
|
49 |
*
|
50 |
* @return mixed false if field doesn't exist. Field value otherwise.
|
53 |
$args = wp_parse_args( $args );
|
54 |
$field = RWMB_Helper::find_field( $field_id, $post_id );
|
55 |
|
56 |
+
// Get field value.
|
57 |
$value = $field ? RWMB_Field::call( 'get_value', $field, $args, $post_id ) : false;
|
58 |
|
59 |
/*
|
60 |
+
* Allow developers to change the returned value of field.
|
61 |
+
* For version < 4.8.2, the filter name was 'rwmb_get_field'.
|
62 |
*
|
63 |
+
* @param mixed $value Field value.
|
64 |
+
* @param array $field Field parameters.
|
65 |
+
* @param array $args Additional arguments. Rarely used. See specific fields for details.
|
66 |
* @param int|null $post_id Post ID. null for current post. Optional.
|
67 |
*/
|
68 |
$value = apply_filters( 'rwmb_get_value', $value, $field, $args, $post_id );
|
76 |
* Display the value of a field
|
77 |
*
|
78 |
* @param string $field_id Field ID. Required.
|
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 |
+
* @param bool $echo Display field meta value? Default `true` which works in almost all cases. We use `false` for the [rwmb_meta] shortcode.
|
82 |
*
|
83 |
* @return string
|
84 |
*/
|
93 |
$output = RWMB_Field::call( 'the_value', $field, $args, $post_id );
|
94 |
|
95 |
/*
|
96 |
+
* Allow developers to change the returned value of field.
|
97 |
+
* For version < 4.8.2, the filter name was 'rwmb_get_field'.
|
98 |
*
|
99 |
+
* @param mixed $value Field HTML output.
|
100 |
+
* @param array $field Field parameters.
|
101 |
+
* @param array $args Additional arguments. Rarely used. See specific fields for details.
|
102 |
* @param int|null $post_id Post ID. null for current post. Optional.
|
103 |
*/
|
104 |
$output = apply_filters( 'rwmb_the_value', $output, $field, $args, $post_id );
|
105 |
|
106 |
if ( $echo ) {
|
107 |
+
echo $output; // WPCS: XSS OK.
|
108 |
}
|
109 |
|
110 |
return $output;
|
113 |
|
114 |
if ( ! function_exists( 'rwmb_meta_shortcode' ) ) {
|
115 |
/**
|
116 |
+
* Shortcode to display meta value.
|
117 |
*
|
118 |
+
* @param array $atts Shortcode attributes, same as rwmb_meta() function, but has more "meta_key" parameter.
|
119 |
*
|
120 |
* @return string
|
121 |
*/
|
inc/helper.php
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* The helper class.
|
|
|
|
|
4 |
*/
|
5 |
|
6 |
/**
|
@@ -9,16 +11,16 @@
|
|
9 |
class RWMB_Helper {
|
10 |
|
11 |
/**
|
12 |
-
* Stores all registered fields
|
13 |
*
|
14 |
* @var array
|
15 |
*/
|
16 |
private static $fields = array();
|
17 |
|
18 |
/**
|
19 |
-
* Hash all fields into an indexed array for search
|
20 |
*
|
21 |
-
* @param string $post_type Post type
|
22 |
*/
|
23 |
public static function hash_fields( $post_type ) {
|
24 |
self::$fields[ $post_type ] = array();
|
@@ -26,7 +28,7 @@ class RWMB_Helper {
|
|
26 |
$meta_boxes = RWMB_Core::get_meta_boxes();
|
27 |
foreach ( $meta_boxes as $meta_box ) {
|
28 |
$meta_box = RW_Meta_Box::normalize( $meta_box );
|
29 |
-
if ( ! in_array( $post_type, $meta_box['post_types'] ) ) {
|
30 |
continue;
|
31 |
}
|
32 |
foreach ( $meta_box['fields'] as $field ) {
|
@@ -41,8 +43,8 @@ class RWMB_Helper {
|
|
41 |
* Find field by field ID.
|
42 |
* This function finds field in meta boxes registered by 'rwmb_meta_boxes' filter.
|
43 |
*
|
44 |
-
* @param string $field_id Field ID
|
45 |
-
* @param int $post_id
|
46 |
* @return array|false Field params (array) if success. False otherwise.
|
47 |
*/
|
48 |
public static function find_field( $field_id, $post_id = null ) {
|
@@ -59,11 +61,11 @@ class RWMB_Helper {
|
|
59 |
}
|
60 |
|
61 |
/**
|
62 |
-
* Get post meta
|
63 |
*
|
64 |
* @param string $key Meta key. Required.
|
65 |
-
* @param int|null $post_id Post ID. null for current post. Optional
|
66 |
* @param array $args Array of arguments. Optional.
|
|
|
67 |
*
|
68 |
* @return mixed
|
69 |
*/
|
@@ -74,8 +76,19 @@ class RWMB_Helper {
|
|
74 |
'multiple' => false,
|
75 |
'clone' => false,
|
76 |
) );
|
77 |
-
// Always set 'multiple' true for following field types
|
78 |
-
if ( in_array( $args['type'], array(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
$args['multiple'] = true;
|
80 |
}
|
81 |
|
@@ -93,7 +106,7 @@ class RWMB_Helper {
|
|
93 |
}
|
94 |
$meta = get_post_meta( $post_id, $key, ! $args['multiple'] );
|
95 |
$term_ids = wp_parse_id_list( $meta );
|
96 |
-
// Allow to pass more arguments to "get_terms"
|
97 |
$func_args = wp_parse_args( array(
|
98 |
'include' => $term_ids,
|
99 |
'hide_empty' => false,
|
1 |
<?php
|
2 |
/**
|
3 |
* The helper class.
|
4 |
+
*
|
5 |
+
* @package Meta Box
|
6 |
*/
|
7 |
|
8 |
/**
|
11 |
class RWMB_Helper {
|
12 |
|
13 |
/**
|
14 |
+
* Stores all registered fields.
|
15 |
*
|
16 |
* @var array
|
17 |
*/
|
18 |
private static $fields = array();
|
19 |
|
20 |
/**
|
21 |
+
* Hash all fields into an indexed array for search.
|
22 |
*
|
23 |
+
* @param string $post_type Post type.
|
24 |
*/
|
25 |
public static function hash_fields( $post_type ) {
|
26 |
self::$fields[ $post_type ] = array();
|
28 |
$meta_boxes = RWMB_Core::get_meta_boxes();
|
29 |
foreach ( $meta_boxes as $meta_box ) {
|
30 |
$meta_box = RW_Meta_Box::normalize( $meta_box );
|
31 |
+
if ( ! in_array( $post_type, $meta_box['post_types'], true ) ) {
|
32 |
continue;
|
33 |
}
|
34 |
foreach ( $meta_box['fields'] as $field ) {
|
43 |
* Find field by field ID.
|
44 |
* This function finds field in meta boxes registered by 'rwmb_meta_boxes' filter.
|
45 |
*
|
46 |
+
* @param string $field_id Field ID.
|
47 |
+
* @param int $post_id Post ID.
|
48 |
* @return array|false Field params (array) if success. False otherwise.
|
49 |
*/
|
50 |
public static function find_field( $field_id, $post_id = null ) {
|
61 |
}
|
62 |
|
63 |
/**
|
64 |
+
* Get post meta.
|
65 |
*
|
66 |
* @param string $key Meta key. Required.
|
|
|
67 |
* @param array $args Array of arguments. Optional.
|
68 |
+
* @param int|null $post_id Post ID. null for current post. Optional.
|
69 |
*
|
70 |
* @return mixed
|
71 |
*/
|
76 |
'multiple' => false,
|
77 |
'clone' => false,
|
78 |
) );
|
79 |
+
// Always set 'multiple' true for following field types.
|
80 |
+
if ( in_array( $args['type'], array(
|
81 |
+
'checkbox_list',
|
82 |
+
'autocomplete',
|
83 |
+
'file',
|
84 |
+
'file_advanced',
|
85 |
+
'file_upload',
|
86 |
+
'image',
|
87 |
+
'image_advanced',
|
88 |
+
'image_upload',
|
89 |
+
'plupload_image',
|
90 |
+
'thickbox_image',
|
91 |
+
), true ) ) {
|
92 |
$args['multiple'] = true;
|
93 |
}
|
94 |
|
106 |
}
|
107 |
$meta = get_post_meta( $post_id, $key, ! $args['multiple'] );
|
108 |
$term_ids = wp_parse_id_list( $meta );
|
109 |
+
// Allow to pass more arguments to "get_terms".
|
110 |
$func_args = wp_parse_args( array(
|
111 |
'include' => $term_ids,
|
112 |
'hide_empty' => false,
|
inc/loader.php
CHANGED
@@ -13,22 +13,21 @@
|
|
13 |
* @package Meta Box
|
14 |
*/
|
15 |
class RWMB_Loader {
|
16 |
-
|
17 |
/**
|
18 |
* Define plugin constants.
|
19 |
*/
|
20 |
protected function constants() {
|
21 |
-
// Script version, used to add version for scripts and styles
|
22 |
-
define( 'RWMB_VER', '4.10.
|
23 |
|
24 |
list( $path, $url ) = self::get_path( dirname( dirname( __FILE__ ) ) );
|
25 |
|
26 |
-
// Plugin URLs, for fast enqueuing scripts and styles
|
27 |
define( 'RWMB_URL', $url );
|
28 |
define( 'RWMB_JS_URL', trailingslashit( RWMB_URL . 'js' ) );
|
29 |
define( 'RWMB_CSS_URL', trailingslashit( RWMB_URL . 'css' ) );
|
30 |
|
31 |
-
// Plugin paths, for including files
|
32 |
define( 'RWMB_DIR', $path );
|
33 |
define( 'RWMB_INC_DIR', trailingslashit( RWMB_DIR . 'inc' ) );
|
34 |
}
|
@@ -38,18 +37,18 @@ class RWMB_Loader {
|
|
38 |
* The method is static and can be used in extensions.
|
39 |
*
|
40 |
* @link http://www.deluxeblogtips.com/2013/07/get-url-of-php-file-in-wordpress.html
|
41 |
-
* @param string $path Base folder path
|
42 |
* @return array Path and URL.
|
43 |
*/
|
44 |
public static function get_path( $path = '' ) {
|
45 |
-
// Plugin base path
|
46 |
$path = wp_normalize_path( untrailingslashit( $path ) );
|
47 |
$themes_dir = wp_normalize_path( untrailingslashit( dirname( realpath( get_stylesheet_directory() ) ) ) );
|
48 |
|
49 |
-
// Default URL
|
50 |
$url = plugins_url( '', $path . '/' . basename( $path ) . '.php' );
|
51 |
|
52 |
-
// Included into themes
|
53 |
if (
|
54 |
0 !== strpos( $path, wp_normalize_path( WP_PLUGIN_DIR ) )
|
55 |
&& 0 !== strpos( $path, wp_normalize_path( WPMU_PLUGIN_DIR ) )
|
@@ -71,7 +70,7 @@ class RWMB_Loader {
|
|
71 |
public function init() {
|
72 |
$this->constants();
|
73 |
|
74 |
-
// Register autoload for classes
|
75 |
require_once RWMB_INC_DIR . 'autoloader.php';
|
76 |
$autoloader = new RWMB_Autoloader;
|
77 |
$autoloader->add( RWMB_INC_DIR, 'RW_' );
|
@@ -80,18 +79,18 @@ class RWMB_Loader {
|
|
80 |
$autoloader->add( RWMB_INC_DIR . 'walkers', 'RWMB_Walker_' );
|
81 |
$autoloader->register();
|
82 |
|
83 |
-
// Plugin core
|
84 |
new RWMB_Core;
|
85 |
|
86 |
if ( is_admin() ) {
|
87 |
-
// Validation module
|
88 |
new RWMB_Validation;
|
89 |
|
90 |
$sanitize = new RWMB_Sanitizer;
|
91 |
$sanitize->init();
|
92 |
}
|
93 |
|
94 |
-
// Public functions
|
95 |
require_once RWMB_INC_DIR . 'functions.php';
|
96 |
}
|
97 |
}
|
13 |
* @package Meta Box
|
14 |
*/
|
15 |
class RWMB_Loader {
|
|
|
16 |
/**
|
17 |
* Define plugin constants.
|
18 |
*/
|
19 |
protected function constants() {
|
20 |
+
// Script version, used to add version for scripts and styles.
|
21 |
+
define( 'RWMB_VER', '4.10.2' );
|
22 |
|
23 |
list( $path, $url ) = self::get_path( dirname( dirname( __FILE__ ) ) );
|
24 |
|
25 |
+
// Plugin URLs, for fast enqueuing scripts and styles.
|
26 |
define( 'RWMB_URL', $url );
|
27 |
define( 'RWMB_JS_URL', trailingslashit( RWMB_URL . 'js' ) );
|
28 |
define( 'RWMB_CSS_URL', trailingslashit( RWMB_URL . 'css' ) );
|
29 |
|
30 |
+
// Plugin paths, for including files.
|
31 |
define( 'RWMB_DIR', $path );
|
32 |
define( 'RWMB_INC_DIR', trailingslashit( RWMB_DIR . 'inc' ) );
|
33 |
}
|
37 |
* The method is static and can be used in extensions.
|
38 |
*
|
39 |
* @link http://www.deluxeblogtips.com/2013/07/get-url-of-php-file-in-wordpress.html
|
40 |
+
* @param string $path Base folder path.
|
41 |
* @return array Path and URL.
|
42 |
*/
|
43 |
public static function get_path( $path = '' ) {
|
44 |
+
// Plugin base path.
|
45 |
$path = wp_normalize_path( untrailingslashit( $path ) );
|
46 |
$themes_dir = wp_normalize_path( untrailingslashit( dirname( realpath( get_stylesheet_directory() ) ) ) );
|
47 |
|
48 |
+
// Default URL.
|
49 |
$url = plugins_url( '', $path . '/' . basename( $path ) . '.php' );
|
50 |
|
51 |
+
// Included into themes.
|
52 |
if (
|
53 |
0 !== strpos( $path, wp_normalize_path( WP_PLUGIN_DIR ) )
|
54 |
&& 0 !== strpos( $path, wp_normalize_path( WPMU_PLUGIN_DIR ) )
|
70 |
public function init() {
|
71 |
$this->constants();
|
72 |
|
73 |
+
// Register autoload for classes.
|
74 |
require_once RWMB_INC_DIR . 'autoloader.php';
|
75 |
$autoloader = new RWMB_Autoloader;
|
76 |
$autoloader->add( RWMB_INC_DIR, 'RW_' );
|
79 |
$autoloader->add( RWMB_INC_DIR . 'walkers', 'RWMB_Walker_' );
|
80 |
$autoloader->register();
|
81 |
|
82 |
+
// Plugin core.
|
83 |
new RWMB_Core;
|
84 |
|
85 |
if ( is_admin() ) {
|
86 |
+
// Validation module.
|
87 |
new RWMB_Validation;
|
88 |
|
89 |
$sanitize = new RWMB_Sanitizer;
|
90 |
$sanitize->init();
|
91 |
}
|
92 |
|
93 |
+
// Public functions.
|
94 |
require_once RWMB_INC_DIR . 'functions.php';
|
95 |
}
|
96 |
}
|
inc/meta-box.php
CHANGED
@@ -15,24 +15,31 @@
|
|
15 |
*/
|
16 |
class RW_Meta_Box {
|
17 |
/**
|
18 |
-
*
|
|
|
|
|
19 |
*/
|
20 |
public $meta_box;
|
21 |
|
22 |
/**
|
23 |
-
*
|
|
|
|
|
24 |
*/
|
25 |
public $fields;
|
26 |
|
27 |
/**
|
28 |
-
*
|
|
|
|
|
|
|
29 |
*/
|
30 |
public $saved = false;
|
31 |
|
32 |
/**
|
33 |
-
* Create meta box based on given data
|
34 |
*
|
35 |
-
* @param array $meta_box Meta box definition
|
36 |
*/
|
37 |
public function __construct( $meta_box ) {
|
38 |
$meta_box = self::normalize( $meta_box );
|
@@ -50,8 +57,8 @@ class RW_Meta_Box {
|
|
50 |
/**
|
51 |
* Conditional check for whether initializing meta box.
|
52 |
*
|
53 |
-
* - 1st filter applies to all meta boxes
|
54 |
-
* - 2nd filter applies to only current meta box
|
55 |
*
|
56 |
* @return bool
|
57 |
*/
|
@@ -65,10 +72,10 @@ class RW_Meta_Box {
|
|
65 |
* Add global hooks.
|
66 |
*/
|
67 |
protected function global_hooks() {
|
68 |
-
// Enqueue common styles and scripts
|
69 |
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
|
70 |
|
71 |
-
// Add additional actions for fields
|
72 |
foreach ( $this->fields as $field ) {
|
73 |
RWMB_Field::call( $field, 'add_actions' );
|
74 |
}
|
@@ -79,17 +86,17 @@ class RW_Meta_Box {
|
|
79 |
* This should be extended in sub-classes to support meta fields for terms, user, settings pages, etc.
|
80 |
*/
|
81 |
protected function object_hooks() {
|
82 |
-
// Add meta box
|
83 |
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
|
84 |
|
85 |
-
// Hide meta box if it's set 'default_hidden'
|
86 |
add_filter( 'default_hidden_meta_boxes', array( $this, 'hide' ), 10, 2 );
|
87 |
|
88 |
-
// Save post meta
|
89 |
foreach ( $this->meta_box['post_types'] as $post_type ) {
|
90 |
if ( 'attachment' === $post_type ) {
|
91 |
-
// Attachment uses other hooks
|
92 |
-
// @see wp_update_post(), wp_insert_attachment()
|
93 |
add_action( 'edit_attachment', array( $this, 'save_post' ) );
|
94 |
add_action( 'add_attachment', array( $this, 'save_post' ) );
|
95 |
} else {
|
@@ -111,7 +118,7 @@ class RW_Meta_Box {
|
|
111 |
wp_enqueue_style( 'rwmb-rtl', RWMB_CSS_URL . 'style-rtl.css', array(), RWMB_VER );
|
112 |
}
|
113 |
|
114 |
-
// Load clone script conditionally
|
115 |
foreach ( $this->fields as $field ) {
|
116 |
if ( $field['clone'] ) {
|
117 |
wp_enqueue_script( 'rwmb-clone', RWMB_JS_URL . 'clone.js', array( 'jquery-ui-sortable' ), RWMB_VER, true );
|
@@ -119,12 +126,12 @@ class RW_Meta_Box {
|
|
119 |
}
|
120 |
}
|
121 |
|
122 |
-
// Enqueue scripts and styles for fields
|
123 |
foreach ( $this->fields as $field ) {
|
124 |
RWMB_Field::call( $field, 'admin_enqueue_scripts' );
|
125 |
}
|
126 |
|
127 |
-
// Auto save
|
128 |
if ( $this->meta_box['autosave'] ) {
|
129 |
wp_enqueue_script( 'rwmb-autosave', RWMB_JS_URL . 'autosave.js', array( 'jquery' ), RWMB_VER, true );
|
130 |
}
|
@@ -156,8 +163,8 @@ class RW_Meta_Box {
|
|
156 |
/**
|
157 |
* Hide meta box if it's set 'default_hidden'
|
158 |
*
|
159 |
-
* @param array
|
160 |
-
* @param object $screen Current screen information
|
161 |
*
|
162 |
* @return array
|
163 |
*/
|
@@ -175,7 +182,7 @@ class RW_Meta_Box {
|
|
175 |
public function show() {
|
176 |
$saved = $this->is_saved();
|
177 |
|
178 |
-
// Container
|
179 |
printf(
|
180 |
'<div class="rwmb-meta-box" data-autosave="%s">',
|
181 |
$this->meta_box['autosave'] ? 'true' : 'false'
|
@@ -183,9 +190,9 @@ class RW_Meta_Box {
|
|
183 |
|
184 |
wp_nonce_field( "rwmb-save-{$this->meta_box['id']}", "nonce_{$this->meta_box['id']}" );
|
185 |
|
186 |
-
// Allow users to add custom code before meta box content
|
187 |
-
// 1st action applies to all meta boxes
|
188 |
-
// 2nd action applies to only current meta box
|
189 |
do_action( 'rwmb_before', $this );
|
190 |
do_action( "rwmb_before_{$this->meta_box['id']}", $this );
|
191 |
|
@@ -193,20 +200,20 @@ class RW_Meta_Box {
|
|
193 |
RWMB_Field::call( 'show', $field, $saved );
|
194 |
}
|
195 |
|
196 |
-
// Allow users to add custom code after meta box content
|
197 |
-
// 1st action applies to all meta boxes
|
198 |
-
// 2nd action applies to only current meta box
|
199 |
do_action( 'rwmb_after', $this );
|
200 |
do_action( "rwmb_after_{$this->meta_box['id']}", $this );
|
201 |
|
202 |
-
// End container
|
203 |
echo '</div>';
|
204 |
}
|
205 |
|
206 |
/**
|
207 |
* Save data from meta box
|
208 |
*
|
209 |
-
* @param int $post_id Post ID
|
210 |
*/
|
211 |
public function save_post( $post_id ) {
|
212 |
if ( ! $this->validate() ) {
|
@@ -214,21 +221,23 @@ class RW_Meta_Box {
|
|
214 |
}
|
215 |
$this->saved = true;
|
216 |
|
217 |
-
// Make sure meta is added to the post, not a revision
|
218 |
-
|
|
|
219 |
$post_id = $the_post;
|
220 |
}
|
221 |
|
222 |
-
// Before save action
|
223 |
do_action( 'rwmb_before_save_post', $post_id );
|
224 |
do_action( "rwmb_{$this->meta_box['id']}_before_save_post", $post_id );
|
225 |
|
226 |
foreach ( $this->fields as $field ) {
|
227 |
$single = $field['clone'] || ! $field['multiple'];
|
228 |
$old = RWMB_Field::call( $field, 'raw_meta', $post_id );
|
|
|
229 |
$new = isset( $_POST[ $field['id'] ] ) ? $_POST[ $field['id'] ] : ( $single ? '' : array() );
|
230 |
|
231 |
-
// Allow field class change the value
|
232 |
if ( $field['clone'] ) {
|
233 |
$new = RWMB_Clone::value( $new, $old, $post_id, $field );
|
234 |
} else {
|
@@ -237,11 +246,11 @@ class RW_Meta_Box {
|
|
237 |
}
|
238 |
$new = RWMB_Field::filter( 'value', $new, $field, $old );
|
239 |
|
240 |
-
// Call defined method to save meta value, if there's no methods, call common one
|
241 |
RWMB_Field::call( $field, 'save', $new, $old, $post_id );
|
242 |
}
|
243 |
|
244 |
-
// After save action
|
245 |
do_action( 'rwmb_after_save_post', $post_id );
|
246 |
do_action( "rwmb_{$this->meta_box['id']}_after_save_post", $post_id );
|
247 |
}
|
@@ -266,12 +275,12 @@ class RW_Meta_Box {
|
|
266 |
/**
|
267 |
* Normalize parameters for meta box
|
268 |
*
|
269 |
-
* @param array $meta_box Meta box definition
|
270 |
*
|
271 |
-
* @return array $meta_box Normalized meta box
|
272 |
*/
|
273 |
public static function normalize( $meta_box ) {
|
274 |
-
// Set default values for meta box
|
275 |
$meta_box = wp_parse_args( $meta_box, array(
|
276 |
'id' => sanitize_title( $meta_box['title'] ),
|
277 |
'context' => 'normal',
|
@@ -282,7 +291,7 @@ class RW_Meta_Box {
|
|
282 |
) );
|
283 |
|
284 |
/**
|
285 |
-
* Use 'post_types' for better understanding and fallback to 'pages' for previous versions
|
286 |
*
|
287 |
* @since 4.4.1
|
288 |
*/
|
@@ -299,15 +308,15 @@ class RW_Meta_Box {
|
|
299 |
/**
|
300 |
* Normalize an array of fields
|
301 |
*
|
302 |
-
* @param array $fields Array of fields
|
303 |
*
|
304 |
-
* @return array $fields Normalized fields
|
305 |
*/
|
306 |
public static function normalize_fields( $fields ) {
|
307 |
foreach ( $fields as $k => $field ) {
|
308 |
$field = RWMB_Field::call( 'normalize', $field );
|
309 |
|
310 |
-
// Allow to add default values for fields
|
311 |
$field = apply_filters( 'rwmb_normalize_field', $field );
|
312 |
$field = apply_filters( "rwmb_normalize_{$field['type']}_field", $field );
|
313 |
$field = apply_filters( "rwmb_normalize_{$field['id']}_field", $field );
|
@@ -355,6 +364,6 @@ class RW_Meta_Box {
|
|
355 |
$screen = get_current_screen();
|
356 |
}
|
357 |
|
358 |
-
return 'post'
|
359 |
}
|
360 |
}
|
15 |
*/
|
16 |
class RW_Meta_Box {
|
17 |
/**
|
18 |
+
* Meta box parameters.
|
19 |
+
*
|
20 |
+
* @var array
|
21 |
*/
|
22 |
public $meta_box;
|
23 |
|
24 |
/**
|
25 |
+
* Fields parameters.
|
26 |
+
*
|
27 |
+
* @var array
|
28 |
*/
|
29 |
public $fields;
|
30 |
|
31 |
/**
|
32 |
+
* Detect whether the meta box is saved at least once.
|
33 |
+
* Used to prevent duplicated calls like revisions, manual hook to wp_insert_post, etc.
|
34 |
+
*
|
35 |
+
* @var bool
|
36 |
*/
|
37 |
public $saved = false;
|
38 |
|
39 |
/**
|
40 |
+
* Create meta box based on given data.
|
41 |
*
|
42 |
+
* @param array $meta_box Meta box definition.
|
43 |
*/
|
44 |
public function __construct( $meta_box ) {
|
45 |
$meta_box = self::normalize( $meta_box );
|
57 |
/**
|
58 |
* Conditional check for whether initializing meta box.
|
59 |
*
|
60 |
+
* - 1st filter applies to all meta boxes.
|
61 |
+
* - 2nd filter applies to only current meta box.
|
62 |
*
|
63 |
* @return bool
|
64 |
*/
|
72 |
* Add global hooks.
|
73 |
*/
|
74 |
protected function global_hooks() {
|
75 |
+
// Enqueue common styles and scripts.
|
76 |
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
|
77 |
|
78 |
+
// Add additional actions for fields.
|
79 |
foreach ( $this->fields as $field ) {
|
80 |
RWMB_Field::call( $field, 'add_actions' );
|
81 |
}
|
86 |
* This should be extended in sub-classes to support meta fields for terms, user, settings pages, etc.
|
87 |
*/
|
88 |
protected function object_hooks() {
|
89 |
+
// Add meta box.
|
90 |
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
|
91 |
|
92 |
+
// Hide meta box if it's set 'default_hidden'.
|
93 |
add_filter( 'default_hidden_meta_boxes', array( $this, 'hide' ), 10, 2 );
|
94 |
|
95 |
+
// Save post meta.
|
96 |
foreach ( $this->meta_box['post_types'] as $post_type ) {
|
97 |
if ( 'attachment' === $post_type ) {
|
98 |
+
// Attachment uses other hooks.
|
99 |
+
// @see wp_update_post(), wp_insert_attachment().
|
100 |
add_action( 'edit_attachment', array( $this, 'save_post' ) );
|
101 |
add_action( 'add_attachment', array( $this, 'save_post' ) );
|
102 |
} else {
|
118 |
wp_enqueue_style( 'rwmb-rtl', RWMB_CSS_URL . 'style-rtl.css', array(), RWMB_VER );
|
119 |
}
|
120 |
|
121 |
+
// Load clone script conditionally.
|
122 |
foreach ( $this->fields as $field ) {
|
123 |
if ( $field['clone'] ) {
|
124 |
wp_enqueue_script( 'rwmb-clone', RWMB_JS_URL . 'clone.js', array( 'jquery-ui-sortable' ), RWMB_VER, true );
|
126 |
}
|
127 |
}
|
128 |
|
129 |
+
// Enqueue scripts and styles for fields.
|
130 |
foreach ( $this->fields as $field ) {
|
131 |
RWMB_Field::call( $field, 'admin_enqueue_scripts' );
|
132 |
}
|
133 |
|
134 |
+
// Auto save.
|
135 |
if ( $this->meta_box['autosave'] ) {
|
136 |
wp_enqueue_script( 'rwmb-autosave', RWMB_JS_URL . 'autosave.js', array( 'jquery' ), RWMB_VER, true );
|
137 |
}
|
163 |
/**
|
164 |
* Hide meta box if it's set 'default_hidden'
|
165 |
*
|
166 |
+
* @param array $hidden Array of default hidden meta boxes.
|
167 |
+
* @param object $screen Current screen information.
|
168 |
*
|
169 |
* @return array
|
170 |
*/
|
182 |
public function show() {
|
183 |
$saved = $this->is_saved();
|
184 |
|
185 |
+
// Container.
|
186 |
printf(
|
187 |
'<div class="rwmb-meta-box" data-autosave="%s">',
|
188 |
$this->meta_box['autosave'] ? 'true' : 'false'
|
190 |
|
191 |
wp_nonce_field( "rwmb-save-{$this->meta_box['id']}", "nonce_{$this->meta_box['id']}" );
|
192 |
|
193 |
+
// Allow users to add custom code before meta box content.
|
194 |
+
// 1st action applies to all meta boxes.
|
195 |
+
// 2nd action applies to only current meta box.
|
196 |
do_action( 'rwmb_before', $this );
|
197 |
do_action( "rwmb_before_{$this->meta_box['id']}", $this );
|
198 |
|
200 |
RWMB_Field::call( 'show', $field, $saved );
|
201 |
}
|
202 |
|
203 |
+
// Allow users to add custom code after meta box content.
|
204 |
+
// 1st action applies to all meta boxes.
|
205 |
+
// 2nd action applies to only current meta box.
|
206 |
do_action( 'rwmb_after', $this );
|
207 |
do_action( "rwmb_after_{$this->meta_box['id']}", $this );
|
208 |
|
209 |
+
// End container.
|
210 |
echo '</div>';
|
211 |
}
|
212 |
|
213 |
/**
|
214 |
* Save data from meta box
|
215 |
*
|
216 |
+
* @param int $post_id Post ID.
|
217 |
*/
|
218 |
public function save_post( $post_id ) {
|
219 |
if ( ! $this->validate() ) {
|
221 |
}
|
222 |
$this->saved = true;
|
223 |
|
224 |
+
// Make sure meta is added to the post, not a revision.
|
225 |
+
$the_post = wp_is_post_revision( $post_id );
|
226 |
+
if ( $the_post ) {
|
227 |
$post_id = $the_post;
|
228 |
}
|
229 |
|
230 |
+
// Before save action.
|
231 |
do_action( 'rwmb_before_save_post', $post_id );
|
232 |
do_action( "rwmb_{$this->meta_box['id']}_before_save_post", $post_id );
|
233 |
|
234 |
foreach ( $this->fields as $field ) {
|
235 |
$single = $field['clone'] || ! $field['multiple'];
|
236 |
$old = RWMB_Field::call( $field, 'raw_meta', $post_id );
|
237 |
+
// @codingStandardsIgnoreLine
|
238 |
$new = isset( $_POST[ $field['id'] ] ) ? $_POST[ $field['id'] ] : ( $single ? '' : array() );
|
239 |
|
240 |
+
// Allow field class change the value.
|
241 |
if ( $field['clone'] ) {
|
242 |
$new = RWMB_Clone::value( $new, $old, $post_id, $field );
|
243 |
} else {
|
246 |
}
|
247 |
$new = RWMB_Field::filter( 'value', $new, $field, $old );
|
248 |
|
249 |
+
// Call defined method to save meta value, if there's no methods, call common one.
|
250 |
RWMB_Field::call( $field, 'save', $new, $old, $post_id );
|
251 |
}
|
252 |
|
253 |
+
// After save action.
|
254 |
do_action( 'rwmb_after_save_post', $post_id );
|
255 |
do_action( "rwmb_{$this->meta_box['id']}_after_save_post", $post_id );
|
256 |
}
|
275 |
/**
|
276 |
* Normalize parameters for meta box
|
277 |
*
|
278 |
+
* @param array $meta_box Meta box definition.
|
279 |
*
|
280 |
+
* @return array $meta_box Normalized meta box.
|
281 |
*/
|
282 |
public static function normalize( $meta_box ) {
|
283 |
+
// Set default values for meta box.
|
284 |
$meta_box = wp_parse_args( $meta_box, array(
|
285 |
'id' => sanitize_title( $meta_box['title'] ),
|
286 |
'context' => 'normal',
|
291 |
) );
|
292 |
|
293 |
/**
|
294 |
+
* Use 'post_types' for better understanding and fallback to 'pages' for previous versions.
|
295 |
*
|
296 |
* @since 4.4.1
|
297 |
*/
|
308 |
/**
|
309 |
* Normalize an array of fields
|
310 |
*
|
311 |
+
* @param array $fields Array of fields.
|
312 |
*
|
313 |
+
* @return array $fields Normalized fields.
|
314 |
*/
|
315 |
public static function normalize_fields( $fields ) {
|
316 |
foreach ( $fields as $k => $field ) {
|
317 |
$field = RWMB_Field::call( 'normalize', $field );
|
318 |
|
319 |
+
// Allow to add default values for fields.
|
320 |
$field = apply_filters( 'rwmb_normalize_field', $field );
|
321 |
$field = apply_filters( "rwmb_normalize_{$field['type']}_field", $field );
|
322 |
$field = apply_filters( "rwmb_normalize_{$field['id']}_field", $field );
|
364 |
$screen = get_current_screen();
|
365 |
}
|
366 |
|
367 |
+
return 'post' === $screen->base && in_array( $screen->post_type, $this->meta_box['post_types'], true );
|
368 |
}
|
369 |
}
|
inc/sanitizer.php
CHANGED
@@ -26,12 +26,12 @@ class RWMB_Sanitizer {
|
|
26 |
* Register hook to sanitize field value.
|
27 |
*/
|
28 |
public function init() {
|
29 |
-
// Built-in callback
|
30 |
foreach ( $this->callbacks as $type => $callback ) {
|
31 |
add_filter( "rwmb_{$type}_sanitize", $callback );
|
32 |
}
|
33 |
|
34 |
-
// Custom callback
|
35 |
$types = array_diff( get_class_methods( __CLASS__ ), array( 'init' ) );
|
36 |
foreach ( $types as $type ) {
|
37 |
add_filter( "rwmb_{$type}_sanitize", array( $this, $type ) );
|
@@ -43,7 +43,7 @@ class RWMB_Sanitizer {
|
|
43 |
* This prevents using default value once the checkbox has been unchecked.
|
44 |
*
|
45 |
* @link https://github.com/rilwis/meta-box/issues/6
|
46 |
-
* @param string $value
|
47 |
* @return int
|
48 |
*/
|
49 |
public function checkbox( $value ) {
|
26 |
* Register hook to sanitize field value.
|
27 |
*/
|
28 |
public function init() {
|
29 |
+
// Built-in callback.
|
30 |
foreach ( $this->callbacks as $type => $callback ) {
|
31 |
add_filter( "rwmb_{$type}_sanitize", $callback );
|
32 |
}
|
33 |
|
34 |
+
// Custom callback.
|
35 |
$types = array_diff( get_class_methods( __CLASS__ ), array( 'init' ) );
|
36 |
foreach ( $types as $type ) {
|
37 |
add_filter( "rwmb_{$type}_sanitize", array( $this, $type ) );
|
43 |
* This prevents using default value once the checkbox has been unchecked.
|
44 |
*
|
45 |
* @link https://github.com/rilwis/meta-box/issues/6
|
46 |
+
* @param string $value Checkbox value.
|
47 |
* @return int
|
48 |
*/
|
49 |
public function checkbox( $value ) {
|
inc/templates/media.php
CHANGED
@@ -1,48 +1,48 @@
|
|
1 |
<script id="tmpl-rwmb-media-item" type="text/html">
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
</script>
|
41 |
|
42 |
<script id="tmpl-rwmb-media-status" type="text/html">
|
43 |
<# if ( data.maxFiles > 0 ) { #>
|
44 |
{{{ data.length }}}/{{{ data.maxFiles }}}
|
45 |
-
<# if ( 1 < data.maxFiles ) { #>
|
46 |
<# } #>
|
47 |
</script>
|
48 |
|
1 |
<script id="tmpl-rwmb-media-item" type="text/html">
|
2 |
+
<input type="hidden" name="{{{ data.fieldName }}}" value="{{{ data.id }}}" class="rwmb-media-input">
|
3 |
+
<div class="rwmb-media-preview">
|
4 |
+
<div class="rwmb-media-content">
|
5 |
+
<div class="centered">
|
6 |
+
<# if ( 'image' === data.type && data.sizes ) { #>
|
7 |
+
<# if ( data.sizes.thumbnail ) { #>
|
8 |
+
<img src="{{{ data.sizes.thumbnail.url }}}">
|
9 |
+
<# } else { #>
|
10 |
+
<img src="{{{ data.sizes.full.url }}}">
|
11 |
+
<# } #>
|
12 |
+
<# } else { #>
|
13 |
+
<# if ( data.image && data.image.src && data.image.src !== data.icon ) { #>
|
14 |
+
<img src="{{ data.image.src }}" />
|
15 |
+
<# } else { #>
|
16 |
+
<img src="{{ data.icon }}" />
|
17 |
+
<# } #>
|
18 |
+
<# } #>
|
19 |
+
</div>
|
20 |
+
</div>
|
21 |
+
</div>
|
22 |
+
<div class="rwmb-media-info">
|
23 |
+
<h4>
|
24 |
+
<a href="{{{ data.url }}}" target="_blank" title="{{{ i18nRwmbMedia.view }}}">
|
25 |
+
<# if( data.title ) { #> {{{ data.title }}}
|
26 |
+
<# } else { #> {{{ i18nRwmbMedia.noTitle }}}
|
27 |
+
<# } #>
|
28 |
+
</a>
|
29 |
+
</h4>
|
30 |
+
<p>{{{ data.mime }}}</p>
|
31 |
+
<p>
|
32 |
+
<a class="rwmb-edit-media" title="{{{ i18nRwmbMedia.edit }}}" href="{{{ data.editLink }}}" target="_blank">
|
33 |
+
<span class="dashicons dashicons-edit"></span>{{{ i18nRwmbMedia.edit }}}
|
34 |
+
</a>
|
35 |
+
<a href="#" class="rwmb-remove-media" title="{{{ i18nRwmbMedia.remove }}}">
|
36 |
+
<span class="dashicons dashicons-no-alt"></span>{{{ i18nRwmbMedia.remove }}}
|
37 |
+
</a>
|
38 |
+
</p>
|
39 |
+
</div>
|
40 |
</script>
|
41 |
|
42 |
<script id="tmpl-rwmb-media-status" type="text/html">
|
43 |
<# if ( data.maxFiles > 0 ) { #>
|
44 |
{{{ data.length }}}/{{{ data.maxFiles }}}
|
45 |
+
<# if ( 1 < data.maxFiles ) { #>{{{ i18nRwmbMedia.multiple }}}<# } else {#>{{{ i18nRwmbMedia.single }}}<# } #>
|
46 |
<# } #>
|
47 |
</script>
|
48 |
|
inc/templates/upload.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<script id="tmpl-rwmb-upload-area" type="text/html">
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
</script>
|
1 |
<script id="tmpl-rwmb-upload-area" type="text/html">
|
2 |
+
<div class="rwmb-upload-inside">
|
3 |
+
<h3>{{{ i18nRwmbMedia.uploadInstructions }}}</h3>
|
4 |
+
<p>{{{ i18nRwmbMedia.or }}}</p>
|
5 |
+
<p><a href="#" class="rwmb-browse-button button button-hero" id="{{{ _.uniqueId( 'rwmb-upload-browser-') }}}">{{{ i18nRwmbMedia.select }}}</a></p>
|
6 |
+
</div>
|
7 |
</script>
|
inc/templates/video.php
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
<script id="tmpl-rwmb-video-item" type="text/html">
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
<# if( _.indexOf( i18nRwmbVideo.extensions, data.url.substr( data.url.lastIndexOf('.') + 1 ) ) > -1 ) { #>
|
7 |
<div class="rwmb-video-wrapper">
|
8 |
<video controls="controls" class="rwmb-video-element" preload="metadata"
|
@@ -19,25 +19,25 @@
|
|
19 |
<img src="{{ data.icon }}" />
|
20 |
<# } #>
|
21 |
<# } #>
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
<div class="rwmb-media-info">
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
</script>
|
1 |
<script id="tmpl-rwmb-video-item" type="text/html">
|
2 |
+
<input type="hidden" name="{{{ data.fieldName }}}" value="{{{ data.id }}}" class="rwmb-media-input">
|
3 |
+
<div class="rwmb-media-preview">
|
4 |
+
<div class="rwmb-media-content">
|
5 |
+
<div class="centered">
|
6 |
<# if( _.indexOf( i18nRwmbVideo.extensions, data.url.substr( data.url.lastIndexOf('.') + 1 ) ) > -1 ) { #>
|
7 |
<div class="rwmb-video-wrapper">
|
8 |
<video controls="controls" class="rwmb-video-element" preload="metadata"
|
19 |
<img src="{{ data.icon }}" />
|
20 |
<# } #>
|
21 |
<# } #>
|
22 |
+
</div>
|
23 |
+
</div>
|
24 |
+
</div>
|
25 |
<div class="rwmb-media-info">
|
26 |
+
<h4>
|
27 |
+
<a href="{{{ data.url }}}" target="_blank" title="{{{ i18nRwmbMedia.view }}}">
|
28 |
+
<# if( data.title ) { #> {{{ data.title }}}
|
29 |
+
<# } else { #> {{{ i18nRwmbMedia.noTitle }}}
|
30 |
+
<# } #>
|
31 |
+
</a>
|
32 |
+
</h4>
|
33 |
+
<p>{{{ data.mime }}}</p>
|
34 |
+
<p>
|
35 |
+
<a class="rwmb-edit-media" title="{{{ i18nRwmbMedia.edit }}}" href="{{{ data.editLink }}}" target="_blank">
|
36 |
+
<span class="dashicons dashicons-edit"></span>{{{ i18nRwmbMedia.edit }}}
|
37 |
+
</a>
|
38 |
+
<a href="#" class="rwmb-remove-media" title="{{{ i18nRwmbMedia.remove }}}">
|
39 |
+
<span class="dashicons dashicons-no-alt"></span>{{{ i18nRwmbMedia.remove }}}
|
40 |
+
</a>
|
41 |
+
</p>
|
42 |
+
</div>
|
43 |
</script>
|
inc/validation.php
CHANGED
@@ -22,20 +22,20 @@ class RWMB_Validation {
|
|
22 |
* Output validation rules of each meta box.
|
23 |
* The rules are outputted in [data-rules] attribute of an hidden <script> and will be converted into JSON by JS.
|
24 |
*
|
25 |
-
* @param RW_Meta_Box $object Meta Box object
|
26 |
*/
|
27 |
-
public function rules( $object ) {
|
28 |
if ( ! empty( $object->meta_box['validation'] ) ) {
|
29 |
-
echo '<script type="text/html" class="rwmb-validation-rules" data-rules="' . esc_attr(
|
30 |
}
|
31 |
}
|
32 |
|
33 |
/**
|
34 |
* Enqueue scripts for validation.
|
35 |
*
|
36 |
-
* @param RW_Meta_Box $object Meta Box object
|
37 |
*/
|
38 |
-
public function enqueue( $object ) {
|
39 |
if ( empty( $object->meta_box['validation'] ) ) {
|
40 |
return;
|
41 |
}
|
22 |
* Output validation rules of each meta box.
|
23 |
* The rules are outputted in [data-rules] attribute of an hidden <script> and will be converted into JSON by JS.
|
24 |
*
|
25 |
+
* @param RW_Meta_Box $object Meta Box object.
|
26 |
*/
|
27 |
+
public function rules( RW_Meta_Box $object ) {
|
28 |
if ( ! empty( $object->meta_box['validation'] ) ) {
|
29 |
+
echo '<script type="text/html" class="rwmb-validation-rules" data-rules="' . esc_attr( wp_json_encode( $object->meta_box['validation'] ) ) . '"></script>';
|
30 |
}
|
31 |
}
|
32 |
|
33 |
/**
|
34 |
* Enqueue scripts for validation.
|
35 |
*
|
36 |
+
* @param RW_Meta_Box $object Meta Box object.
|
37 |
*/
|
38 |
+
public function enqueue( RW_Meta_Box $object ) {
|
39 |
if ( empty( $object->meta_box['validation'] ) ) {
|
40 |
return;
|
41 |
}
|
inc/walkers/base.php
CHANGED
@@ -1,10 +1,15 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
* Base
|
4 |
* Walkers must inherit this class and overwrite methods with its own.
|
|
|
|
|
5 |
*/
|
6 |
-
abstract class RWMB_Walker_Base extends Walker {
|
7 |
|
|
|
|
|
|
|
|
|
8 |
/**
|
9 |
* Field data.
|
10 |
*
|
@@ -21,7 +26,14 @@ abstract class RWMB_Walker_Base extends Walker {
|
|
21 |
*/
|
22 |
public $meta = array();
|
23 |
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
$this->db_fields = wp_parse_args( (array) $db_fields, array(
|
26 |
'parent' => '',
|
27 |
'id' => '',
|
1 |
<?php
|
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 |
/**
|
14 |
* Field data.
|
15 |
*
|
26 |
*/
|
27 |
public $meta = array();
|
28 |
|
29 |
+
/**
|
30 |
+
* Constructor.
|
31 |
+
*
|
32 |
+
* @param array $db_fields Database fields.
|
33 |
+
* @param array $field Field parameters.
|
34 |
+
* @param mixed $meta Meta value.
|
35 |
+
*/
|
36 |
+
public function __construct( $db_fields, $field, $meta ) {
|
37 |
$this->db_fields = wp_parse_args( (array) $db_fields, array(
|
38 |
'parent' => '',
|
39 |
'id' => '',
|
inc/walkers/input-list.php
CHANGED
@@ -1,41 +1,44 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
-
*
|
5 |
-
* For checkbox and radio list fields
|
6 |
*/
|
7 |
class RWMB_Walker_Input_List extends RWMB_Walker_Base {
|
8 |
-
|
9 |
/**
|
10 |
-
*
|
11 |
*
|
12 |
* @param string $output Passed by reference. Used to append additional content.
|
13 |
-
* @param int $depth Depth of item.
|
14 |
-
* @param array $args
|
15 |
*/
|
16 |
public function start_lvl( &$output, $depth = 0, $args = array() ) {
|
17 |
$output .= '<ul class="rwmb-input-list">';
|
18 |
}
|
19 |
|
20 |
/**
|
21 |
-
*
|
22 |
*
|
23 |
* @param string $output Passed by reference. Used to append additional content.
|
24 |
-
* @param int $depth Depth of item.
|
25 |
-
* @param array $args
|
26 |
*/
|
27 |
public function end_lvl( &$output, $depth = 0, $args = array() ) {
|
28 |
$output .= '</ul>';
|
29 |
}
|
30 |
|
31 |
/**
|
32 |
-
*
|
33 |
*
|
34 |
* @param string $output Passed by reference. Used to append additional content.
|
35 |
-
* @param object $object
|
36 |
-
* @param int $depth Depth of item.
|
37 |
-
* @param
|
38 |
-
* @param
|
39 |
*/
|
40 |
public function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {
|
41 |
$label = $this->db_fields['label'];
|
@@ -51,14 +54,14 @@ class RWMB_Walker_Input_List extends RWMB_Walker_Base {
|
|
51 |
}
|
52 |
|
53 |
/**
|
54 |
-
*
|
55 |
*
|
56 |
* @param string $output Passed by reference. Used to append additional content.
|
57 |
-
* @param object $
|
58 |
-
* @param int $depth Depth of
|
59 |
-
* @param array $args
|
60 |
*/
|
61 |
-
public function end_el( &$output, $
|
62 |
$output .= '</li>';
|
63 |
}
|
64 |
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* The input list walker for checkbox and radio list fields.
|
4 |
+
*
|
5 |
+
* @package Meta Box
|
6 |
+
*/
|
7 |
|
8 |
/**
|
9 |
+
* The input list walker class.
|
|
|
10 |
*/
|
11 |
class RWMB_Walker_Input_List extends RWMB_Walker_Base {
|
|
|
12 |
/**
|
13 |
+
* Starts the list before the elements are added.
|
14 |
*
|
15 |
* @param string $output Passed by reference. Used to append additional content.
|
16 |
+
* @param int $depth Depth of the item.
|
17 |
+
* @param array $args An array of additional arguments.
|
18 |
*/
|
19 |
public function start_lvl( &$output, $depth = 0, $args = array() ) {
|
20 |
$output .= '<ul class="rwmb-input-list">';
|
21 |
}
|
22 |
|
23 |
/**
|
24 |
+
* Ends the list of after the elements are added.
|
25 |
*
|
26 |
* @param string $output Passed by reference. Used to append additional content.
|
27 |
+
* @param int $depth Depth of the item.
|
28 |
+
* @param array $args An array of additional arguments.
|
29 |
*/
|
30 |
public function end_lvl( &$output, $depth = 0, $args = array() ) {
|
31 |
$output .= '</ul>';
|
32 |
}
|
33 |
|
34 |
/**
|
35 |
+
* Start the element output.
|
36 |
*
|
37 |
* @param string $output Passed by reference. Used to append additional content.
|
38 |
+
* @param object $object The data object.
|
39 |
+
* @param int $depth Depth of the item.
|
40 |
+
* @param array $args An array of additional arguments.
|
41 |
+
* @param int $current_object_id ID of the current item.
|
42 |
*/
|
43 |
public function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {
|
44 |
$label = $this->db_fields['label'];
|
54 |
}
|
55 |
|
56 |
/**
|
57 |
+
* Ends the element output, if needed.
|
58 |
*
|
59 |
* @param string $output Passed by reference. Used to append additional content.
|
60 |
+
* @param object $object The data object.
|
61 |
+
* @param int $depth Depth of the item.
|
62 |
+
* @param array $args An array of additional arguments.
|
63 |
*/
|
64 |
+
public function end_el( &$output, $object, $depth = 0, $args = array() ) {
|
65 |
$output .= '</li>';
|
66 |
}
|
67 |
}
|
inc/walkers/select-tree.php
CHANGED
@@ -1,12 +1,14 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
/**
|
4 |
-
* Select
|
5 |
*
|
6 |
-
* @
|
7 |
*/
|
8 |
-
class RWMB_Walker_Select_Tree {
|
9 |
|
|
|
|
|
|
|
|
|
10 |
/**
|
11 |
* Field data.
|
12 |
*
|
@@ -21,7 +23,14 @@ class RWMB_Walker_Select_Tree {
|
|
21 |
*/
|
22 |
public $meta = array();
|
23 |
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
$this->db_fields = wp_parse_args( (array) $db_fields, array(
|
26 |
'parent' => '',
|
27 |
'id' => '',
|
@@ -31,7 +40,14 @@ class RWMB_Walker_Select_Tree {
|
|
31 |
$this->meta = (array) $meta;
|
32 |
}
|
33 |
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
$parent = $this->db_fields['parent'];
|
36 |
$children = array();
|
37 |
|
@@ -42,7 +58,16 @@ class RWMB_Walker_Select_Tree {
|
|
42 |
return $this->display_level( $children, $top_level, true );
|
43 |
}
|
44 |
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
$id = $this->db_fields['id'];
|
47 |
$field = $this->field;
|
48 |
$walker = new RWMB_Walker_Select( $this->db_fields, $field, $this->meta );
|
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 data.
|
14 |
*
|
23 |
*/
|
24 |
public $meta = array();
|
25 |
|
26 |
+
/**
|
27 |
+
* Constructor.
|
28 |
+
*
|
29 |
+
* @param array $db_fields Database fields.
|
30 |
+
* @param array $field Field parameters.
|
31 |
+
* @param mixed $meta Meta value.
|
32 |
+
*/
|
33 |
+
public function __construct( $db_fields, $field, $meta ) {
|
34 |
$this->db_fields = wp_parse_args( (array) $db_fields, array(
|
35 |
'parent' => '',
|
36 |
'id' => '',
|
40 |
$this->meta = (array) $meta;
|
41 |
}
|
42 |
|
43 |
+
/**
|
44 |
+
* Display array of elements hierarchically.
|
45 |
+
*
|
46 |
+
* @param array $options An array of options.
|
47 |
+
*
|
48 |
+
* @return string
|
49 |
+
*/
|
50 |
+
public function walk( $options ) {
|
51 |
$parent = $this->db_fields['parent'];
|
52 |
$children = array();
|
53 |
|
58 |
return $this->display_level( $children, $top_level, true );
|
59 |
}
|
60 |
|
61 |
+
/**
|
62 |
+
* Display a hierarchy level.
|
63 |
+
*
|
64 |
+
* @param array $options An array of options.
|
65 |
+
* @param int $parent_id Parent item ID.
|
66 |
+
* @param bool $active Whether to show or hide.
|
67 |
+
*
|
68 |
+
* @return string
|
69 |
+
*/
|
70 |
+
public function display_level( $options, $parent_id = 0, $active = false ) {
|
71 |
$id = $this->db_fields['id'];
|
72 |
$field = $this->field;
|
73 |
$walker = new RWMB_Walker_Select( $this->db_fields, $field, $this->meta );
|
inc/walkers/select.php
CHANGED
@@ -1,18 +1,24 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
* Select
|
4 |
-
*
|
|
|
5 |
*/
|
6 |
-
class RWMB_Walker_Select extends RWMB_Walker_Base {
|
7 |
|
|
|
|
|
|
|
|
|
8 |
/**
|
|
|
|
|
9 |
* @see Walker::start_el()
|
10 |
*
|
11 |
* @param string $output Passed by reference. Used to append additional content.
|
12 |
-
* @param object $object
|
13 |
-
* @param int $depth Depth of
|
14 |
-
* @param
|
15 |
-
* @param
|
16 |
*/
|
17 |
public function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {
|
18 |
$label = $this->db_fields['label'];
|
@@ -22,10 +28,10 @@ class RWMB_Walker_Select extends RWMB_Walker_Base {
|
|
22 |
|
23 |
$output .= sprintf(
|
24 |
'<option value="%s" %s>%s%s</option>',
|
25 |
-
$object->$id,
|
26 |
-
selected( in_array( $object->$id, $meta ),
|
27 |
$indent,
|
28 |
-
RWMB_Field::filter( 'choice_label', $object->$label, $this->field, $object )
|
29 |
);
|
30 |
}
|
31 |
}
|
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 |
/**
|
13 |
+
* Start the element output.
|
14 |
+
*
|
15 |
* @see Walker::start_el()
|
16 |
*
|
17 |
* @param string $output Passed by reference. Used to append additional content.
|
18 |
+
* @param object $object The data object.
|
19 |
+
* @param int $depth Depth of the item.
|
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 |
$label = $this->db_fields['label'];
|
28 |
|
29 |
$output .= sprintf(
|
30 |
'<option value="%s" %s>%s%s</option>',
|
31 |
+
esc_attr( $object->$id ),
|
32 |
+
selected( in_array( esc_attr( $object->$id ), $meta, true ), true, false ),
|
33 |
$indent,
|
34 |
+
esc_html( RWMB_Field::filter( 'choice_label', $object->$label, $this->field, $object ) )
|
35 |
);
|
36 |
}
|
37 |
}
|
inc/wpml.php
CHANGED
@@ -1,4 +1,9 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
* WPML compatibility class
|
@@ -15,34 +20,38 @@ class RWMB_WPML {
|
|
15 |
/**
|
16 |
* Translating IDs stored as field values upon WPML post/page duplication.
|
17 |
*
|
18 |
-
* @param $value
|
19 |
-
* @param $target_language
|
20 |
-
* @param $meta_data
|
21 |
* @return mixed
|
22 |
*/
|
23 |
public function wpml_translate_values( $value, $target_language, $meta_data ) {
|
24 |
$fields = RWMB_Core::get_fields();
|
25 |
|
26 |
foreach ( $fields as $field ) {
|
27 |
-
if ( in_array( $field['type'], array( 'post', 'taxonomy_advanced' ) )
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
foreach ( $values as $v ) {
|
40 |
-
$translated_values[] = apply_filters( 'wpml_object_id', $v, $post_type, true, $target_language );
|
41 |
-
}
|
42 |
-
|
43 |
-
$value = implode( ',', $translated_values );
|
44 |
-
}
|
45 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
}
|
47 |
|
48 |
return $value;
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* The WPML compatibility module, allowing all fields are translatable by WPML plugin.
|
4 |
+
*
|
5 |
+
* @package Meta Box
|
6 |
+
*/
|
7 |
|
8 |
/**
|
9 |
* WPML compatibility class
|
20 |
/**
|
21 |
* Translating IDs stored as field values upon WPML post/page duplication.
|
22 |
*
|
23 |
+
* @param mixed $value Meta value.
|
24 |
+
* @param string $target_language Target language.
|
25 |
+
* @param array $meta_data Meta arguments.
|
26 |
* @return mixed
|
27 |
*/
|
28 |
public function wpml_translate_values( $value, $target_language, $meta_data ) {
|
29 |
$fields = RWMB_Core::get_fields();
|
30 |
|
31 |
foreach ( $fields as $field ) {
|
32 |
+
if ( ! in_array( $field['type'], array( 'post', 'taxonomy_advanced' ) ) || $field['id'] !== $meta_data['key'] ) {
|
33 |
+
continue;
|
34 |
+
}
|
35 |
+
|
36 |
+
// Post type needed for WPML filter differs between fields.
|
37 |
+
$post_type = 'taxonomy_advanced' === $field['type'] ? $field['taxonomy'] : $field['post_type'];
|
38 |
+
|
39 |
+
// Translating values, whether are stored as comma separated strings or not.
|
40 |
+
if ( false === strpos( $value, ',' ) ) {
|
41 |
+
$value = apply_filters( 'wpml_object_id', $value, $post_type, true, $target_language );
|
42 |
+
return $value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
}
|
44 |
+
|
45 |
+
// Dealing with IDs stored as comma separated strings.
|
46 |
+
$translated_values = array();
|
47 |
+
$values = explode( ',', $value );
|
48 |
+
|
49 |
+
foreach ( $values as $v ) {
|
50 |
+
$translated_values[] = apply_filters( 'wpml_object_id', $v, $post_type, true, $target_language );
|
51 |
+
}
|
52 |
+
|
53 |
+
$value = implode( ',', $translated_values );
|
54 |
+
return $value;
|
55 |
}
|
56 |
|
57 |
return $value;
|
js/file-upload.js
CHANGED
@@ -46,7 +46,8 @@ jQuery( function ( $ ) {
|
|
46 |
initUploader: function () {
|
47 |
var isIE = navigator.userAgent.indexOf( 'Trident/' ) != - 1 || navigator.userAgent.indexOf( 'MSIE ' ) != - 1,
|
48 |
self = this,
|
49 |
-
extensions = this.getExtensions().join( ',' )
|
|
|
50 |
this.plupload = $.extend( true, {
|
51 |
multipart_params: {},
|
52 |
multipart: true,
|
@@ -56,6 +57,10 @@ jQuery( function ( $ ) {
|
|
56 |
filters: {}
|
57 |
}, wp.Uploader.defaults );
|
58 |
|
|
|
|
|
|
|
|
|
59 |
if ( extensions ) {
|
60 |
this.plupload.filters.mime_types = [{title: i18nRwmbMedia.select, extensions: extensions}];
|
61 |
}
|
46 |
initUploader: function () {
|
47 |
var isIE = navigator.userAgent.indexOf( 'Trident/' ) != - 1 || navigator.userAgent.indexOf( 'MSIE ' ) != - 1,
|
48 |
self = this,
|
49 |
+
extensions = this.getExtensions().join( ',' ),
|
50 |
+
max_file_size;
|
51 |
this.plupload = $.extend( true, {
|
52 |
multipart_params: {},
|
53 |
multipart: true,
|
57 |
filters: {}
|
58 |
}, wp.Uploader.defaults );
|
59 |
|
60 |
+
if( max_file_size = this.controller.get( 'maxFileSize' ) ) {
|
61 |
+
this.plupload.filters.max_file_size = max_file_size;
|
62 |
+
}
|
63 |
+
|
64 |
if ( extensions ) {
|
65 |
this.plupload.filters.mime_types = [{title: i18nRwmbMedia.select, extensions: extensions}];
|
66 |
}
|
js/jquery-validation/additional-methods.min.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
/*! jQuery Validation Plugin - v1.15.0 - 2/24/2016
|
2 |
-
* http://jqueryvalidation.org/
|
3 |
-
* Copyright (c) 2016 Jörn Zaefferer; Licensed MIT */
|
4 |
!function(a){"function"==typeof define&&define.amd?define(["jquery","./jquery.validate.min"],a): "object" == typeof module && module.exports?module.exports=a(require("jquery")):a(jQuery)}(function(a){!function(){function b(a){return a.replace(/<.[^<>]*?>/g," ").replace(/ | /gi," ").replace(/[.(),;:!?%#$'\"_+=\/\-“”’]*/g,"")}a.validator.addMethod("maxWords",function(a,c,d){return this.optional(c) || b(a).match(/\b\w+\b/g).length <= d},a.validator.format("Please enter {0} words or less.")),a.validator.addMethod("minWords",function(a,c,d){return this.optional(c) || b(a).match(/\b\w+\b/g).length >= d},a.validator.format("Please enter at least {0} words.")),a.validator.addMethod("rangeWords",function(a,c,d){var e=b(a),f=/\b\w+\b/g;return this.optional(c)||e.match(f).length>=d[0]&&e.match(f).length<=d[1]},a.validator.format("Please enter between {0} and {1} words."))}(),a.validator.addMethod("accept",function(b,c,d){var e,f,g,h="string"==typeof d?d.replace(/\s/g,""):"image/*",i=this.optional(c);if(i)return i;if("file"===a(c).attr("type")&&(h=h.replace(/[\-\[\]\/\{\}\(\)\+\?\.\\\^\$\|]/g,"\\$&").replace(/,/g,"|").replace("/*","/.*"),c.files&&c.files.length))for(g=new RegExp(".?("+h+")$","i"),e=0;e<c.files.length;e++)if(f=c.files[e],!f.type.match(g))return!1;return!0},a.validator.format("Please enter a value with a valid mimetype.")),a.validator.addMethod("alphanumeric",function(a,b){return this.optional(b)||/^\w+$/i.test(a)},"Letters, numbers, and underscores only please"),a.validator.addMethod("bankaccountNL",function(a,b){if(this.optional(b))return!0;if(!/^[0-9]{9}|([0-9]{2} ){3}[0-9]{3}$/.test(a))return!1;var c,d,e,f=a.replace(/ /g,""),g=0,h=f.length;for(c=0;h>c;c++)d=h-c,e=f.substring(c,c+1),g+=d*e;return g%11===0},"Please specify a valid bank account number"),a.validator.addMethod("bankorgiroaccountNL",function(b,c){return this.optional(c)||a.validator.methods.bankaccountNL.call(this,b,c)||a.validator.methods.giroaccountNL.call(this,b,c)},"Please specify a valid bank or giro account number"),a.validator.addMethod("bic",function(a,b){return this.optional(b)||/^([A-Z]{6}[A-Z2-9][A-NP-Z1-9])(X{3}|[A-WY-Z0-9][A-Z0-9]{2})?$/.test(a.toUpperCase())},"Please specify a valid BIC code"),a.validator.addMethod("cifES",function(a){"use strict";var b,c,d,e,f,g,h=[];if(a=a.toUpperCase(),!a.match("((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)"))return!1;for(d=0;9>d;d++)h[d]=parseInt(a.charAt(d),10);for(c=h[2]+h[4]+h[6],e=1;8>e;e+=2)f=(2*h[e]).toString(),g=f.charAt(1),c+=parseInt(f.charAt(0),10)+(""===g?0:parseInt(g,10));return/^[ABCDEFGHJNPQRSUVW]{1}/.test(a)?(c+="",b=10-parseInt(c.charAt(c.length-1),10),a+=b,h[8].toString()===String.fromCharCode(64+b)||h[8].toString()===a.charAt(a.length-1)):!1},"Please specify a valid CIF number."),a.validator.addMethod("cpfBR",function(a){if(a=a.replace(/([~!@#$%^&*()_+=`{}\[\]\-|\\:;'<>,.\/? ])+/g,""),11!==a.length)return!1;var b,c,d,e,f=0;if(b=parseInt(a.substring(9,10),10),c=parseInt(a.substring(10,11),10),d=function(a,b){var c=10*a%11;return 10!==c&&11!==c||(c=0),c===b},""===a||"00000000000"===a||"11111111111"===a||"22222222222"===a||"33333333333"===a||"44444444444"===a||"55555555555"===a||"66666666666"===a||"77777777777"===a||"88888888888"===a||"99999999999"===a)return!1;for(e=1;9>=e;e++)f+=parseInt(a.substring(e-1,e),10)*(11-e);if(d(f,b)){for(f=0,e=1;10>=e;e++)f+=parseInt(a.substring(e-1,e),10)*(12-e);return d(f,c)}return!1},"Please specify a valid CPF number"),a.validator.addMethod("creditcard",function(a,b){if(this.optional(b))return"dependency-mismatch";if(/[^0-9 \-]+/.test(a))return!1;var c,d,e=0,f=0,g=!1;if(a=a.replace(/\D/g,""),a.length<13||a.length>19)return!1;for(c=a.length-1;c>=0;c--)d=a.charAt(c),f=parseInt(d,10),g&&(f*=2)>9&&(f-=9),e+=f,g=!g;return e%10===0},"Please enter a valid credit card number."),a.validator.addMethod("creditcardtypes",function(a,b,c){if(/[^0-9\-]+/.test(a))return!1;a=a.replace(/\D/g,"");var d=0;return c.mastercard&&(d|=1),c.visa&&(d|=2),c.amex&&(d|=4),c.dinersclub&&(d|=8),c.enroute&&(d|=16),c.discover&&(d|=32),c.jcb&&(d|=64),c.unknown&&(d|=128),c.all&&(d=255),1&d&&/^(5[12345])/.test(a)?16===a.length:2&d&&/^(4)/.test(a)?16===a.length:4&d&&/^(3[47])/.test(a)?15===a.length:8&d&&/^(3(0[012345]|[68]))/.test(a)?14===a.length:16&d&&/^(2(014|149))/.test(a)?15===a.length:32&d&&/^(6011)/.test(a)?16===a.length:64&d&&/^(3)/.test(a)?16===a.length:64&d&&/^(2131|1800)/.test(a)?15===a.length:!!(128&d)},"Please enter a valid credit card number."),a.validator.addMethod("currency",function(a,b,c){var d,e="string"==typeof c,f=e?c:c[0],g=e?!0:c[1];return f=f.replace(/,/g,""),f=g?f+"]":f+"]?",d="^["+f+"([1-9]{1}[0-9]{0,2}(\\,[0-9]{3})*(\\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\\.[0-9]{0,2})?|0(\\.[0-9]{0,2})?|(\\.[0-9]{1,2})?)$",d=new RegExp(d),this.optional(b)||d.test(a)},"Please specify a valid currency"),a.validator.addMethod("dateFA",function(a,b){return this.optional(b)||/^[1-4]\d{3}\/((0?[1-6]\/((3[0-1])|([1-2][0-9])|(0?[1-9])))|((1[0-2]|(0?[7-9]))\/(30|([1-2][0-9])|(0?[1-9]))))$/.test(a)},a.validator.messages.date),a.validator.addMethod("dateITA",function(a,b){var c,d,e,f,g,h=!1,i=/^\d{1,2}\/\d{1,2}\/\d{4}$/;return i.test(a)?(c=a.split("/"),d=parseInt(c[0],10),e=parseInt(c[1],10),f=parseInt(c[2],10),g=new Date(Date.UTC(f,e-1,d,12,0,0,0)),h=g.getUTCFullYear()===f&&g.getUTCMonth()===e-1&&g.getUTCDate()===d):h=!1,this.optional(b)||h},a.validator.messages.date),a.validator.addMethod("dateNL",function(a,b){return this.optional(b)||/^(0?[1-9]|[12]\d|3[01])[\.\/\-](0?[1-9]|1[012])[\.\/\-]([12]\d)?(\d\d)$/.test(a)},a.validator.messages.date),a.validator.addMethod("extension",function(a,b,c){return c="string"==typeof c?c.replace(/,/g,"|"):"png|jpe?g|gif",this.optional(b)||a.match(new RegExp("\\.("+c+")$","i"))},a.validator.format("Please enter a value with a valid extension.")),a.validator.addMethod("giroaccountNL",function(a,b){return this.optional(b)||/^[0-9]{1,7}$/.test(a)},"Please specify a valid giro account number"),a.validator.addMethod("iban",function(a,b){if(this.optional(b))return!0;var c,d,e,f,g,h,i,j,k,l=a.replace(/ /g,"").toUpperCase(),m="",n=!0,o="",p="";if(c=l.substring(0,2),h={AL:"\\d{8}[\\dA-Z]{16}",AD:"\\d{8}[\\dA-Z]{12}",AT:"\\d{16}",AZ:"[\\dA-Z]{4}\\d{20}",BE:"\\d{12}",BH:"[A-Z]{4}[\\dA-Z]{14}",BA:"\\d{16}",BR:"\\d{23}[A-Z][\\dA-Z]",BG:"[A-Z]{4}\\d{6}[\\dA-Z]{8}",CR:"\\d{17}",HR:"\\d{17}",CY:"\\d{8}[\\dA-Z]{16}",CZ:"\\d{20}",DK:"\\d{14}",DO:"[A-Z]{4}\\d{20}",EE:"\\d{16}",FO:"\\d{14}",FI:"\\d{14}",FR:"\\d{10}[\\dA-Z]{11}\\d{2}",GE:"[\\dA-Z]{2}\\d{16}",DE:"\\d{18}",GI:"[A-Z]{4}[\\dA-Z]{15}",GR:"\\d{7}[\\dA-Z]{16}",GL:"\\d{14}",GT:"[\\dA-Z]{4}[\\dA-Z]{20}",HU:"\\d{24}",IS:"\\d{22}",IE:"[\\dA-Z]{4}\\d{14}",IL:"\\d{19}",IT:"[A-Z]\\d{10}[\\dA-Z]{12}",KZ:"\\d{3}[\\dA-Z]{13}",KW:"[A-Z]{4}[\\dA-Z]{22}",LV:"[A-Z]{4}[\\dA-Z]{13}",LB:"\\d{4}[\\dA-Z]{20}",LI:"\\d{5}[\\dA-Z]{12}",LT:"\\d{16}",LU:"\\d{3}[\\dA-Z]{13}",MK:"\\d{3}[\\dA-Z]{10}\\d{2}",MT:"[A-Z]{4}\\d{5}[\\dA-Z]{18}",MR:"\\d{23}",MU:"[A-Z]{4}\\d{19}[A-Z]{3}",MC:"\\d{10}[\\dA-Z]{11}\\d{2}",MD:"[\\dA-Z]{2}\\d{18}",ME:"\\d{18}",NL:"[A-Z]{4}\\d{10}",NO:"\\d{11}",PK:"[\\dA-Z]{4}\\d{16}",PS:"[\\dA-Z]{4}\\d{21}",PL:"\\d{24}",PT:"\\d{21}",RO:"[A-Z]{4}[\\dA-Z]{16}",SM:"[A-Z]\\d{10}[\\dA-Z]{12}",SA:"\\d{2}[\\dA-Z]{18}",RS:"\\d{18}",SK:"\\d{20}",SI:"\\d{15}",ES:"\\d{20}",SE:"\\d{20}",CH:"\\d{5}[\\dA-Z]{12}",TN:"\\d{20}",TR:"\\d{5}[\\dA-Z]{17}",AE:"\\d{3}\\d{16}",GB:"[A-Z]{4}\\d{14}",VG:"[\\dA-Z]{4}\\d{16}"},g=h[c],"undefined"!=typeof g&&(i=new RegExp("^[A-Z]{2}\\d{2}"+g+"$",""),!i.test(l)))return!1;for(d=l.substring(4,l.length)+l.substring(0,4),j=0;j<d.length;j++)e=d.charAt(j),"0"!==e&&(n=!1),n||(m+="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(e));for(k=0;k<m.length;k++)f=m.charAt(k),p=""+o+f,o=p%97;return 1===o},"Please specify a valid IBAN"),a.validator.addMethod("integer",function(a,b){return this.optional(b)||/^-?\d+$/.test(a)},"A positive or negative non-decimal number please"),a.validator.addMethod("ipv4",function(a,b){return this.optional(b)||/^(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)$/i.test(a)},"Please enter a valid IP v4 address."),a.validator.addMethod("ipv6",function(a,b){return this.optional(b)||/^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/i.test(a)},"Please enter a valid IP v6 address."),a.validator.addMethod("lettersonly",function(a,b){return this.optional(b)||/^[a-z]+$/i.test(a)},"Letters only please"),a.validator.addMethod("letterswithbasicpunc",function(a,b){return this.optional(b)||/^[a-z\-.,()'"\s]+$/i.test(a)},"Letters or punctuation only please"),a.validator.addMethod("mobileNL",function(a,b){return this.optional(b)||/^((\+|00(\s|\s?\-\s?)?)31(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)6((\s|\s?\-\s?)?[0-9]){8}$/.test(a)},"Please specify a valid mobile number"),a.validator.addMethod("mobileUK",function(a,b){return a=a.replace(/\(|\)|\s+|-/g,""),this.optional(b)||a.length>9&&a.match(/^(?:(?:(?:00\s?|\+)44\s?|0)7(?:[1345789]\d{2}|624)\s?\d{3}\s?\d{3})$/)},"Please specify a valid mobile number"),a.validator.addMethod("nieES",function(a){"use strict";return a=a.toUpperCase(),a.match("((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)")?/^[T]{1}/.test(a)?a[8]===/^[T]{1}[A-Z0-9]{8}$/.test(a):/^[XYZ]{1}/.test(a)?a[8]==="TRWAGMYFPDXBNJZSQVHLCKE".charAt(a.replace("X","0").replace("Y","1").replace("Z","2").substring(0,8)%23):!1:!1},"Please specify a valid NIE number."),a.validator.addMethod("nifES",function(a){"use strict";return a=a.toUpperCase(),a.match("((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)")?/^[0-9]{8}[A-Z]{1}$/.test(a)?"TRWAGMYFPDXBNJZSQVHLCKE".charAt(a.substring(8,0)%23)===a.charAt(8):/^[KLM]{1}/.test(a)?a[8]===String.fromCharCode(64):!1:!1},"Please specify a valid NIF number."),jQuery.validator.addMethod("notEqualTo",function(b,c,d){return this.optional(c)||!a.validator.methods.equalTo.call(this,b,c,d)},"Please enter a different value, values must not be the same."),a.validator.addMethod("nowhitespace",function(a,b){return this.optional(b)||/^\S+$/i.test(a)},"No white space please"),a.validator.addMethod("pattern",function(a,b,c){return this.optional(b)?!0:("string"==typeof c&&(c=new RegExp("^(?:"+c+")$")),c.test(a))},"Invalid format."),a.validator.addMethod("phoneNL",function(a,b){return this.optional(b)||/^((\+|00(\s|\s?\-\s?)?)31(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)[1-9]((\s|\s?\-\s?)?[0-9]){8}$/.test(a)},"Please specify a valid phone number."),a.validator.addMethod("phoneUK",function(a,b){return a=a.replace(/\(|\)|\s+|-/g,""),this.optional(b)||a.length>9&&a.match(/^(?:(?:(?:00\s?|\+)44\s?)|(?:\(?0))(?:\d{2}\)?\s?\d{4}\s?\d{4}|\d{3}\)?\s?\d{3}\s?\d{3,4}|\d{4}\)?\s?(?:\d{5}|\d{3}\s?\d{3})|\d{5}\)?\s?\d{4,5})$/)},"Please specify a valid phone number"),a.validator.addMethod("phoneUS",function(a,b){return a=a.replace(/\s+/g,""),this.optional(b)||a.length>9&&a.match(/^(\+?1-?)?(\([2-9]([02-9]\d|1[02-9])\)|[2-9]([02-9]\d|1[02-9]))-?[2-9]([02-9]\d|1[02-9])-?\d{4}$/)},"Please specify a valid phone number"),a.validator.addMethod("phonesUK",function(a,b){return a=a.replace(/\(|\)|\s+|-/g,""),this.optional(b)||a.length>9&&a.match(/^(?:(?:(?:00\s?|\+)44\s?|0)(?:1\d{8,9}|[23]\d{9}|7(?:[1345789]\d{8}|624\d{6})))$/)},"Please specify a valid uk phone number"),a.validator.addMethod("postalCodeCA",function(a,b){return this.optional(b)||/^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ] *\d[ABCEGHJKLMNPRSTVWXYZ]\d$/i.test(a)},"Please specify a valid postal code"),a.validator.addMethod("postalcodeBR",function(a,b){return this.optional(b)||/^\d{2}.\d{3}-\d{3}?$|^\d{5}-?\d{3}?$/.test(a)},"Informe um CEP válido."),a.validator.addMethod("postalcodeIT",function(a,b){return this.optional(b)||/^\d{5}$/.test(a)},"Please specify a valid postal code"),a.validator.addMethod("postalcodeNL",function(a,b){return this.optional(b)||/^[1-9][0-9]{3}\s?[a-zA-Z]{2}$/.test(a)},"Please specify a valid postal code"),a.validator.addMethod("postcodeUK",function(a,b){return this.optional(b)||/^((([A-PR-UWYZ][0-9])|([A-PR-UWYZ][0-9][0-9])|([A-PR-UWYZ][A-HK-Y][0-9])|([A-PR-UWYZ][A-HK-Y][0-9][0-9])|([A-PR-UWYZ][0-9][A-HJKSTUW])|([A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRVWXY]))\s?([0-9][ABD-HJLNP-UW-Z]{2})|(GIR)\s?(0AA))$/i.test(a)},"Please specify a valid UK postcode"),a.validator.addMethod("require_from_group",function(b,c,d){var e=a(d[1],c.form),f=e.eq(0),g=f.data("valid_req_grp")?f.data("valid_req_grp"):a.extend({},this),h=e.filter(function(){return g.elementValue(this)}).length>=d[0];return f.data("valid_req_grp",g),a(c).data("being_validated")||(e.data("being_validated",!0),e.each(function(){g.element(this)}),e.data("being_validated",!1)),h},a.validator.format("Please fill at least {0} of these fields.")),a.validator.addMethod("skip_or_fill_minimum",function(b,c,d){var e=a(d[1],c.form),f=e.eq(0),g=f.data("valid_skip")?f.data("valid_skip"):a.extend({},this),h=e.filter(function(){return g.elementValue(this)}).length,i=0===h||h>=d[0];return f.data("valid_skip",g),a(c).data("being_validated")||(e.data("being_validated",!0),e.each(function(){g.element(this)}),e.data("being_validated",!1)),i},a.validator.format("Please either skip these fields or fill at least {0} of them.")),a.validator.addMethod("stateUS",function(a,b,c){var d,e="undefined"==typeof c,f=e||"undefined"==typeof c.caseSensitive?!1:c.caseSensitive,g=e||"undefined"==typeof c.includeTerritories?!1:c.includeTerritories,h=e||"undefined"==typeof c.includeMilitary?!1:c.includeMilitary;return d=g||h?g&&h?"^(A[AEKLPRSZ]|C[AOT]|D[CE]|FL|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEINOPST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])$":g?"^(A[KLRSZ]|C[AOT]|D[CE]|FL|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEINOPST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])$":"^(A[AEKLPRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|PA|RI|S[CD]|T[NX]|UT|V[AT]|W[AIVY])$":"^(A[KLRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|PA|RI|S[CD]|T[NX]|UT|V[AT]|W[AIVY])$",d=f?new RegExp(d):new RegExp(d,"i"),this.optional(b)||d.test(a)},"Please specify a valid state"),a.validator.addMethod("strippedminlength",function(b,c,d){return a(b).text().length>=d},a.validator.format("Please enter at least {0} characters")),a.validator.addMethod("time",function(a,b){return this.optional(b)||/^([01]\d|2[0-3]|[0-9])(:[0-5]\d){1,2}$/.test(a)},"Please enter a valid time, between 00:00 and 23:59"),a.validator.addMethod("time12h",function(a,b){return this.optional(b)||/^((0?[1-9]|1[012])(:[0-5]\d){1,2}(\ ?[AP]M))$/i.test(a)},"Please enter a valid time in 12-hour am/pm format"),a.validator.addMethod("url2",function(a,b){return this.optional(b)||/^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)*(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(a)},a.validator.messages.url),a.validator.addMethod("vinUS",function(a){if(17!==a.length)return!1;var b,c,d,e,f,g,h=["A","B","C","D","E","F","G","H","J","K","L","M","N","P","R","S","T","U","V","W","X","Y","Z"],i=[1,2,3,4,5,6,7,8,1,2,3,4,5,7,9,2,3,4,5,6,7,8,9],j=[8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2],k=0;for(b=0;17>b;b++){if(e=j[b],d=a.slice(b,b+1),8===b&&(g=d),isNaN(d)){for(c=0;c<h.length;c++)if(d.toUpperCase()===h[c]){d=i[c],d*=e,isNaN(g)&&8===c&&(g=h[c]);break}}else d*=e;k+=d}return f=k%11,10===f&&(f="X"),f===g},"The specified vehicle identification number (VIN) is invalid."),a.validator.addMethod("zipcodeUS",function(a,b){return this.optional(b)||/^\d{5}(-\d{4})?$/.test(a)},"The specified US ZIP Code is invalid"),a.validator.addMethod("ziprange",function(a,b){return this.optional(b)||/^90[2-5]\d\{2\}-\d{4}$/.test(a)},"Your ZIP-code must be in the range 902xx-xxxx to 905xx-xxxx")});
|
1 |
+
/*! jQuery Validation Plugin - v1.15.0 - 2/24/2016
|
2 |
+
* http://jqueryvalidation.org/
|
3 |
+
* Copyright (c) 2016 Jörn Zaefferer; Licensed MIT */
|
4 |
!function(a){"function"==typeof define&&define.amd?define(["jquery","./jquery.validate.min"],a): "object" == typeof module && module.exports?module.exports=a(require("jquery")):a(jQuery)}(function(a){!function(){function b(a){return a.replace(/<.[^<>]*?>/g," ").replace(/ | /gi," ").replace(/[.(),;:!?%#$'\"_+=\/\-“”’]*/g,"")}a.validator.addMethod("maxWords",function(a,c,d){return this.optional(c) || b(a).match(/\b\w+\b/g).length <= d},a.validator.format("Please enter {0} words or less.")),a.validator.addMethod("minWords",function(a,c,d){return this.optional(c) || b(a).match(/\b\w+\b/g).length >= d},a.validator.format("Please enter at least {0} words.")),a.validator.addMethod("rangeWords",function(a,c,d){var e=b(a),f=/\b\w+\b/g;return this.optional(c)||e.match(f).length>=d[0]&&e.match(f).length<=d[1]},a.validator.format("Please enter between {0} and {1} words."))}(),a.validator.addMethod("accept",function(b,c,d){var e,f,g,h="string"==typeof d?d.replace(/\s/g,""):"image/*",i=this.optional(c);if(i)return i;if("file"===a(c).attr("type")&&(h=h.replace(/[\-\[\]\/\{\}\(\)\+\?\.\\\^\$\|]/g,"\\$&").replace(/,/g,"|").replace("/*","/.*"),c.files&&c.files.length))for(g=new RegExp(".?("+h+")$","i"),e=0;e<c.files.length;e++)if(f=c.files[e],!f.type.match(g))return!1;return!0},a.validator.format("Please enter a value with a valid mimetype.")),a.validator.addMethod("alphanumeric",function(a,b){return this.optional(b)||/^\w+$/i.test(a)},"Letters, numbers, and underscores only please"),a.validator.addMethod("bankaccountNL",function(a,b){if(this.optional(b))return!0;if(!/^[0-9]{9}|([0-9]{2} ){3}[0-9]{3}$/.test(a))return!1;var c,d,e,f=a.replace(/ /g,""),g=0,h=f.length;for(c=0;h>c;c++)d=h-c,e=f.substring(c,c+1),g+=d*e;return g%11===0},"Please specify a valid bank account number"),a.validator.addMethod("bankorgiroaccountNL",function(b,c){return this.optional(c)||a.validator.methods.bankaccountNL.call(this,b,c)||a.validator.methods.giroaccountNL.call(this,b,c)},"Please specify a valid bank or giro account number"),a.validator.addMethod("bic",function(a,b){return this.optional(b)||/^([A-Z]{6}[A-Z2-9][A-NP-Z1-9])(X{3}|[A-WY-Z0-9][A-Z0-9]{2})?$/.test(a.toUpperCase())},"Please specify a valid BIC code"),a.validator.addMethod("cifES",function(a){"use strict";var b,c,d,e,f,g,h=[];if(a=a.toUpperCase(),!a.match("((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)"))return!1;for(d=0;9>d;d++)h[d]=parseInt(a.charAt(d),10);for(c=h[2]+h[4]+h[6],e=1;8>e;e+=2)f=(2*h[e]).toString(),g=f.charAt(1),c+=parseInt(f.charAt(0),10)+(""===g?0:parseInt(g,10));return/^[ABCDEFGHJNPQRSUVW]{1}/.test(a)?(c+="",b=10-parseInt(c.charAt(c.length-1),10),a+=b,h[8].toString()===String.fromCharCode(64+b)||h[8].toString()===a.charAt(a.length-1)):!1},"Please specify a valid CIF number."),a.validator.addMethod("cpfBR",function(a){if(a=a.replace(/([~!@#$%^&*()_+=`{}\[\]\-|\\:;'<>,.\/? ])+/g,""),11!==a.length)return!1;var b,c,d,e,f=0;if(b=parseInt(a.substring(9,10),10),c=parseInt(a.substring(10,11),10),d=function(a,b){var c=10*a%11;return 10!==c&&11!==c||(c=0),c===b},""===a||"00000000000"===a||"11111111111"===a||"22222222222"===a||"33333333333"===a||"44444444444"===a||"55555555555"===a||"66666666666"===a||"77777777777"===a||"88888888888"===a||"99999999999"===a)return!1;for(e=1;9>=e;e++)f+=parseInt(a.substring(e-1,e),10)*(11-e);if(d(f,b)){for(f=0,e=1;10>=e;e++)f+=parseInt(a.substring(e-1,e),10)*(12-e);return d(f,c)}return!1},"Please specify a valid CPF number"),a.validator.addMethod("creditcard",function(a,b){if(this.optional(b))return"dependency-mismatch";if(/[^0-9 \-]+/.test(a))return!1;var c,d,e=0,f=0,g=!1;if(a=a.replace(/\D/g,""),a.length<13||a.length>19)return!1;for(c=a.length-1;c>=0;c--)d=a.charAt(c),f=parseInt(d,10),g&&(f*=2)>9&&(f-=9),e+=f,g=!g;return e%10===0},"Please enter a valid credit card number."),a.validator.addMethod("creditcardtypes",function(a,b,c){if(/[^0-9\-]+/.test(a))return!1;a=a.replace(/\D/g,"");var d=0;return c.mastercard&&(d|=1),c.visa&&(d|=2),c.amex&&(d|=4),c.dinersclub&&(d|=8),c.enroute&&(d|=16),c.discover&&(d|=32),c.jcb&&(d|=64),c.unknown&&(d|=128),c.all&&(d=255),1&d&&/^(5[12345])/.test(a)?16===a.length:2&d&&/^(4)/.test(a)?16===a.length:4&d&&/^(3[47])/.test(a)?15===a.length:8&d&&/^(3(0[012345]|[68]))/.test(a)?14===a.length:16&d&&/^(2(014|149))/.test(a)?15===a.length:32&d&&/^(6011)/.test(a)?16===a.length:64&d&&/^(3)/.test(a)?16===a.length:64&d&&/^(2131|1800)/.test(a)?15===a.length:!!(128&d)},"Please enter a valid credit card number."),a.validator.addMethod("currency",function(a,b,c){var d,e="string"==typeof c,f=e?c:c[0],g=e?!0:c[1];return f=f.replace(/,/g,""),f=g?f+"]":f+"]?",d="^["+f+"([1-9]{1}[0-9]{0,2}(\\,[0-9]{3})*(\\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\\.[0-9]{0,2})?|0(\\.[0-9]{0,2})?|(\\.[0-9]{1,2})?)$",d=new RegExp(d),this.optional(b)||d.test(a)},"Please specify a valid currency"),a.validator.addMethod("dateFA",function(a,b){return this.optional(b)||/^[1-4]\d{3}\/((0?[1-6]\/((3[0-1])|([1-2][0-9])|(0?[1-9])))|((1[0-2]|(0?[7-9]))\/(30|([1-2][0-9])|(0?[1-9]))))$/.test(a)},a.validator.messages.date),a.validator.addMethod("dateITA",function(a,b){var c,d,e,f,g,h=!1,i=/^\d{1,2}\/\d{1,2}\/\d{4}$/;return i.test(a)?(c=a.split("/"),d=parseInt(c[0],10),e=parseInt(c[1],10),f=parseInt(c[2],10),g=new Date(Date.UTC(f,e-1,d,12,0,0,0)),h=g.getUTCFullYear()===f&&g.getUTCMonth()===e-1&&g.getUTCDate()===d):h=!1,this.optional(b)||h},a.validator.messages.date),a.validator.addMethod("dateNL",function(a,b){return this.optional(b)||/^(0?[1-9]|[12]\d|3[01])[\.\/\-](0?[1-9]|1[012])[\.\/\-]([12]\d)?(\d\d)$/.test(a)},a.validator.messages.date),a.validator.addMethod("extension",function(a,b,c){return c="string"==typeof c?c.replace(/,/g,"|"):"png|jpe?g|gif",this.optional(b)||a.match(new RegExp("\\.("+c+")$","i"))},a.validator.format("Please enter a value with a valid extension.")),a.validator.addMethod("giroaccountNL",function(a,b){return this.optional(b)||/^[0-9]{1,7}$/.test(a)},"Please specify a valid giro account number"),a.validator.addMethod("iban",function(a,b){if(this.optional(b))return!0;var c,d,e,f,g,h,i,j,k,l=a.replace(/ /g,"").toUpperCase(),m="",n=!0,o="",p="";if(c=l.substring(0,2),h={AL:"\\d{8}[\\dA-Z]{16}",AD:"\\d{8}[\\dA-Z]{12}",AT:"\\d{16}",AZ:"[\\dA-Z]{4}\\d{20}",BE:"\\d{12}",BH:"[A-Z]{4}[\\dA-Z]{14}",BA:"\\d{16}",BR:"\\d{23}[A-Z][\\dA-Z]",BG:"[A-Z]{4}\\d{6}[\\dA-Z]{8}",CR:"\\d{17}",HR:"\\d{17}",CY:"\\d{8}[\\dA-Z]{16}",CZ:"\\d{20}",DK:"\\d{14}",DO:"[A-Z]{4}\\d{20}",EE:"\\d{16}",FO:"\\d{14}",FI:"\\d{14}",FR:"\\d{10}[\\dA-Z]{11}\\d{2}",GE:"[\\dA-Z]{2}\\d{16}",DE:"\\d{18}",GI:"[A-Z]{4}[\\dA-Z]{15}",GR:"\\d{7}[\\dA-Z]{16}",GL:"\\d{14}",GT:"[\\dA-Z]{4}[\\dA-Z]{20}",HU:"\\d{24}",IS:"\\d{22}",IE:"[\\dA-Z]{4}\\d{14}",IL:"\\d{19}",IT:"[A-Z]\\d{10}[\\dA-Z]{12}",KZ:"\\d{3}[\\dA-Z]{13}",KW:"[A-Z]{4}[\\dA-Z]{22}",LV:"[A-Z]{4}[\\dA-Z]{13}",LB:"\\d{4}[\\dA-Z]{20}",LI:"\\d{5}[\\dA-Z]{12}",LT:"\\d{16}",LU:"\\d{3}[\\dA-Z]{13}",MK:"\\d{3}[\\dA-Z]{10}\\d{2}",MT:"[A-Z]{4}\\d{5}[\\dA-Z]{18}",MR:"\\d{23}",MU:"[A-Z]{4}\\d{19}[A-Z]{3}",MC:"\\d{10}[\\dA-Z]{11}\\d{2}",MD:"[\\dA-Z]{2}\\d{18}",ME:"\\d{18}",NL:"[A-Z]{4}\\d{10}",NO:"\\d{11}",PK:"[\\dA-Z]{4}\\d{16}",PS:"[\\dA-Z]{4}\\d{21}",PL:"\\d{24}",PT:"\\d{21}",RO:"[A-Z]{4}[\\dA-Z]{16}",SM:"[A-Z]\\d{10}[\\dA-Z]{12}",SA:"\\d{2}[\\dA-Z]{18}",RS:"\\d{18}",SK:"\\d{20}",SI:"\\d{15}",ES:"\\d{20}",SE:"\\d{20}",CH:"\\d{5}[\\dA-Z]{12}",TN:"\\d{20}",TR:"\\d{5}[\\dA-Z]{17}",AE:"\\d{3}\\d{16}",GB:"[A-Z]{4}\\d{14}",VG:"[\\dA-Z]{4}\\d{16}"},g=h[c],"undefined"!=typeof g&&(i=new RegExp("^[A-Z]{2}\\d{2}"+g+"$",""),!i.test(l)))return!1;for(d=l.substring(4,l.length)+l.substring(0,4),j=0;j<d.length;j++)e=d.charAt(j),"0"!==e&&(n=!1),n||(m+="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(e));for(k=0;k<m.length;k++)f=m.charAt(k),p=""+o+f,o=p%97;return 1===o},"Please specify a valid IBAN"),a.validator.addMethod("integer",function(a,b){return this.optional(b)||/^-?\d+$/.test(a)},"A positive or negative non-decimal number please"),a.validator.addMethod("ipv4",function(a,b){return this.optional(b)||/^(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)$/i.test(a)},"Please enter a valid IP v4 address."),a.validator.addMethod("ipv6",function(a,b){return this.optional(b)||/^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/i.test(a)},"Please enter a valid IP v6 address."),a.validator.addMethod("lettersonly",function(a,b){return this.optional(b)||/^[a-z]+$/i.test(a)},"Letters only please"),a.validator.addMethod("letterswithbasicpunc",function(a,b){return this.optional(b)||/^[a-z\-.,()'"\s]+$/i.test(a)},"Letters or punctuation only please"),a.validator.addMethod("mobileNL",function(a,b){return this.optional(b)||/^((\+|00(\s|\s?\-\s?)?)31(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)6((\s|\s?\-\s?)?[0-9]){8}$/.test(a)},"Please specify a valid mobile number"),a.validator.addMethod("mobileUK",function(a,b){return a=a.replace(/\(|\)|\s+|-/g,""),this.optional(b)||a.length>9&&a.match(/^(?:(?:(?:00\s?|\+)44\s?|0)7(?:[1345789]\d{2}|624)\s?\d{3}\s?\d{3})$/)},"Please specify a valid mobile number"),a.validator.addMethod("nieES",function(a){"use strict";return a=a.toUpperCase(),a.match("((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)")?/^[T]{1}/.test(a)?a[8]===/^[T]{1}[A-Z0-9]{8}$/.test(a):/^[XYZ]{1}/.test(a)?a[8]==="TRWAGMYFPDXBNJZSQVHLCKE".charAt(a.replace("X","0").replace("Y","1").replace("Z","2").substring(0,8)%23):!1:!1},"Please specify a valid NIE number."),a.validator.addMethod("nifES",function(a){"use strict";return a=a.toUpperCase(),a.match("((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)")?/^[0-9]{8}[A-Z]{1}$/.test(a)?"TRWAGMYFPDXBNJZSQVHLCKE".charAt(a.substring(8,0)%23)===a.charAt(8):/^[KLM]{1}/.test(a)?a[8]===String.fromCharCode(64):!1:!1},"Please specify a valid NIF number."),jQuery.validator.addMethod("notEqualTo",function(b,c,d){return this.optional(c)||!a.validator.methods.equalTo.call(this,b,c,d)},"Please enter a different value, values must not be the same."),a.validator.addMethod("nowhitespace",function(a,b){return this.optional(b)||/^\S+$/i.test(a)},"No white space please"),a.validator.addMethod("pattern",function(a,b,c){return this.optional(b)?!0:("string"==typeof c&&(c=new RegExp("^(?:"+c+")$")),c.test(a))},"Invalid format."),a.validator.addMethod("phoneNL",function(a,b){return this.optional(b)||/^((\+|00(\s|\s?\-\s?)?)31(\s|\s?\-\s?)?(\(0\)[\-\s]?)?|0)[1-9]((\s|\s?\-\s?)?[0-9]){8}$/.test(a)},"Please specify a valid phone number."),a.validator.addMethod("phoneUK",function(a,b){return a=a.replace(/\(|\)|\s+|-/g,""),this.optional(b)||a.length>9&&a.match(/^(?:(?:(?:00\s?|\+)44\s?)|(?:\(?0))(?:\d{2}\)?\s?\d{4}\s?\d{4}|\d{3}\)?\s?\d{3}\s?\d{3,4}|\d{4}\)?\s?(?:\d{5}|\d{3}\s?\d{3})|\d{5}\)?\s?\d{4,5})$/)},"Please specify a valid phone number"),a.validator.addMethod("phoneUS",function(a,b){return a=a.replace(/\s+/g,""),this.optional(b)||a.length>9&&a.match(/^(\+?1-?)?(\([2-9]([02-9]\d|1[02-9])\)|[2-9]([02-9]\d|1[02-9]))-?[2-9]([02-9]\d|1[02-9])-?\d{4}$/)},"Please specify a valid phone number"),a.validator.addMethod("phonesUK",function(a,b){return a=a.replace(/\(|\)|\s+|-/g,""),this.optional(b)||a.length>9&&a.match(/^(?:(?:(?:00\s?|\+)44\s?|0)(?:1\d{8,9}|[23]\d{9}|7(?:[1345789]\d{8}|624\d{6})))$/)},"Please specify a valid uk phone number"),a.validator.addMethod("postalCodeCA",function(a,b){return this.optional(b)||/^[ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ] *\d[ABCEGHJKLMNPRSTVWXYZ]\d$/i.test(a)},"Please specify a valid postal code"),a.validator.addMethod("postalcodeBR",function(a,b){return this.optional(b)||/^\d{2}.\d{3}-\d{3}?$|^\d{5}-?\d{3}?$/.test(a)},"Informe um CEP válido."),a.validator.addMethod("postalcodeIT",function(a,b){return this.optional(b)||/^\d{5}$/.test(a)},"Please specify a valid postal code"),a.validator.addMethod("postalcodeNL",function(a,b){return this.optional(b)||/^[1-9][0-9]{3}\s?[a-zA-Z]{2}$/.test(a)},"Please specify a valid postal code"),a.validator.addMethod("postcodeUK",function(a,b){return this.optional(b)||/^((([A-PR-UWYZ][0-9])|([A-PR-UWYZ][0-9][0-9])|([A-PR-UWYZ][A-HK-Y][0-9])|([A-PR-UWYZ][A-HK-Y][0-9][0-9])|([A-PR-UWYZ][0-9][A-HJKSTUW])|([A-PR-UWYZ][A-HK-Y][0-9][ABEHMNPRVWXY]))\s?([0-9][ABD-HJLNP-UW-Z]{2})|(GIR)\s?(0AA))$/i.test(a)},"Please specify a valid UK postcode"),a.validator.addMethod("require_from_group",function(b,c,d){var e=a(d[1],c.form),f=e.eq(0),g=f.data("valid_req_grp")?f.data("valid_req_grp"):a.extend({},this),h=e.filter(function(){return g.elementValue(this)}).length>=d[0];return f.data("valid_req_grp",g),a(c).data("being_validated")||(e.data("being_validated",!0),e.each(function(){g.element(this)}),e.data("being_validated",!1)),h},a.validator.format("Please fill at least {0} of these fields.")),a.validator.addMethod("skip_or_fill_minimum",function(b,c,d){var e=a(d[1],c.form),f=e.eq(0),g=f.data("valid_skip")?f.data("valid_skip"):a.extend({},this),h=e.filter(function(){return g.elementValue(this)}).length,i=0===h||h>=d[0];return f.data("valid_skip",g),a(c).data("being_validated")||(e.data("being_validated",!0),e.each(function(){g.element(this)}),e.data("being_validated",!1)),i},a.validator.format("Please either skip these fields or fill at least {0} of them.")),a.validator.addMethod("stateUS",function(a,b,c){var d,e="undefined"==typeof c,f=e||"undefined"==typeof c.caseSensitive?!1:c.caseSensitive,g=e||"undefined"==typeof c.includeTerritories?!1:c.includeTerritories,h=e||"undefined"==typeof c.includeMilitary?!1:c.includeMilitary;return d=g||h?g&&h?"^(A[AEKLPRSZ]|C[AOT]|D[CE]|FL|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEINOPST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])$":g?"^(A[KLRSZ]|C[AOT]|D[CE]|FL|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEINOPST]|N[CDEHJMVY]|O[HKR]|P[AR]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])$":"^(A[AEKLPRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|PA|RI|S[CD]|T[NX]|UT|V[AT]|W[AIVY])$":"^(A[KLRZ]|C[AOT]|D[CE]|FL|GA|HI|I[ADLN]|K[SY]|LA|M[ADEINOST]|N[CDEHJMVY]|O[HKR]|PA|RI|S[CD]|T[NX]|UT|V[AT]|W[AIVY])$",d=f?new RegExp(d):new RegExp(d,"i"),this.optional(b)||d.test(a)},"Please specify a valid state"),a.validator.addMethod("strippedminlength",function(b,c,d){return a(b).text().length>=d},a.validator.format("Please enter at least {0} characters")),a.validator.addMethod("time",function(a,b){return this.optional(b)||/^([01]\d|2[0-3]|[0-9])(:[0-5]\d){1,2}$/.test(a)},"Please enter a valid time, between 00:00 and 23:59"),a.validator.addMethod("time12h",function(a,b){return this.optional(b)||/^((0?[1-9]|1[012])(:[0-5]\d){1,2}(\ ?[AP]M))$/i.test(a)},"Please enter a valid time in 12-hour am/pm format"),a.validator.addMethod("url2",function(a,b){return this.optional(b)||/^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)*(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(a)},a.validator.messages.url),a.validator.addMethod("vinUS",function(a){if(17!==a.length)return!1;var b,c,d,e,f,g,h=["A","B","C","D","E","F","G","H","J","K","L","M","N","P","R","S","T","U","V","W","X","Y","Z"],i=[1,2,3,4,5,6,7,8,1,2,3,4,5,7,9,2,3,4,5,6,7,8,9],j=[8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2],k=0;for(b=0;17>b;b++){if(e=j[b],d=a.slice(b,b+1),8===b&&(g=d),isNaN(d)){for(c=0;c<h.length;c++)if(d.toUpperCase()===h[c]){d=i[c],d*=e,isNaN(g)&&8===c&&(g=h[c]);break}}else d*=e;k+=d}return f=k%11,10===f&&(f="X"),f===g},"The specified vehicle identification number (VIN) is invalid."),a.validator.addMethod("zipcodeUS",function(a,b){return this.optional(b)||/^\d{5}(-\d{4})?$/.test(a)},"The specified US ZIP Code is invalid"),a.validator.addMethod("ziprange",function(a,b){return this.optional(b)||/^90[2-5]\d\{2\}-\d{4}$/.test(a)},"Your ZIP-code must be in the range 902xx-xxxx to 905xx-xxxx")});
|
js/media.js
CHANGED
@@ -121,7 +121,7 @@ jQuery( function ( $ ) {
|
|
121 |
fieldName: this.$input.attr( 'name' ),
|
122 |
ids: this.$input.val().split( ',' )
|
123 |
},
|
124 |
-
this.$el.data()
|
125 |
) );
|
126 |
|
127 |
// Create views
|
121 |
fieldName: this.$input.attr( 'name' ),
|
122 |
ids: this.$input.val().split( ',' )
|
123 |
},
|
124 |
+
this.$el.data( 'options' )
|
125 |
) );
|
126 |
|
127 |
// Create views
|
languages/default.pot
CHANGED
@@ -5,14 +5,14 @@ msgid ""
|
|
5 |
msgstr ""
|
6 |
"Project-Id-Version: Meta Box 4.8.7\n"
|
7 |
"Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/meta-box\n"
|
8 |
-
"POT-Creation-Date:
|
9 |
"MIME-Version: 1.0\n"
|
10 |
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
"Content-Transfer-Encoding: 8bit\n"
|
12 |
"PO-Revision-Date: 2014-MO-DA HO:MI+ZONE\n"
|
13 |
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
14 |
"Language-Team: Meta Box <admin@metabox.io>\n"
|
15 |
-
"X-Generator: Poedit 1.8.
|
16 |
"X-Poedit-KeywordsList: __;_x;_e;_ex;_n;_nx;esc_attr__;esc_attr_e;esc_attr_x;esc_html__;esc_html_e;esc_html_x;_n_noop;_nx_noop\n"
|
17 |
"X-Poedit-Basepath: ..\n"
|
18 |
"X-Poedit-SearchPath-0: .\n"
|
@@ -22,158 +22,158 @@ msgstr ""
|
|
22 |
"X-Poedit-SearchPathExcluded-3: css\n"
|
23 |
"X-Poedit-SearchPathExcluded-4: lang\n"
|
24 |
|
25 |
-
#: inc/
|
26 |
-
msgid "
|
27 |
msgstr ""
|
28 |
|
29 |
-
#: inc/core.php:
|
30 |
-
msgid "
|
31 |
msgstr ""
|
32 |
|
33 |
-
#: inc/
|
34 |
-
msgid "
|
35 |
msgstr ""
|
36 |
|
37 |
-
#: inc/fields/autocomplete.php:
|
38 |
-
#: inc/fields/autocomplete.php:
|
39 |
msgid "Delete"
|
40 |
msgstr ""
|
41 |
|
42 |
-
#: inc/fields/button.php:
|
43 |
msgid "Click me"
|
44 |
msgstr ""
|
45 |
|
46 |
-
#: inc/fields/checkbox.php:
|
47 |
msgid "Yes"
|
48 |
msgstr ""
|
49 |
|
50 |
-
#: inc/fields/checkbox.php:
|
51 |
msgid "No"
|
52 |
msgstr ""
|
53 |
|
54 |
-
#: inc/fields/file-input.php:
|
55 |
msgid "Select File"
|
56 |
msgstr ""
|
57 |
|
58 |
-
#: inc/fields/file-input.php:
|
59 |
msgid "Select"
|
60 |
msgstr ""
|
61 |
|
62 |
-
#: inc/fields/file-input.php:
|
63 |
msgid "Remove"
|
64 |
msgstr ""
|
65 |
|
66 |
-
#: inc/fields/file.php:
|
67 |
#, php-format
|
68 |
msgid "You may only upload maximum %d file"
|
69 |
msgstr ""
|
70 |
|
71 |
-
#: inc/fields/file.php:
|
72 |
#, php-format
|
73 |
msgid "You may only upload maximum %d files"
|
74 |
msgstr ""
|
75 |
|
76 |
-
#: inc/fields/file.php:
|
77 |
msgid "Error: Cannot delete file"
|
78 |
msgstr ""
|
79 |
|
80 |
-
#: inc/fields/file.php:
|
81 |
msgid "Upload Files"
|
82 |
msgstr ""
|
83 |
|
84 |
-
#: inc/fields/file.php:
|
85 |
msgid "+ Add new file"
|
86 |
msgstr ""
|
87 |
|
88 |
-
#: inc/fields/file.php:
|
89 |
msgid "Edit"
|
90 |
msgstr ""
|
91 |
|
92 |
-
#: inc/fields/key-value.php:
|
93 |
msgid "Key"
|
94 |
msgstr ""
|
95 |
|
96 |
-
#: inc/fields/key-value.php:
|
97 |
msgid "Value"
|
98 |
msgstr ""
|
99 |
|
100 |
-
#: inc/fields/map.php:
|
101 |
msgid "Find Address"
|
102 |
msgstr ""
|
103 |
|
104 |
-
#: inc/fields/media.php:
|
105 |
msgid "+ Add Media"
|
106 |
msgstr ""
|
107 |
|
108 |
-
#: inc/fields/media.php:
|
109 |
msgid " file"
|
110 |
msgstr ""
|
111 |
|
112 |
-
#: inc/fields/media.php:
|
113 |
msgid " files"
|
114 |
msgstr ""
|
115 |
|
116 |
-
#: inc/fields/media.php:
|
117 |
msgid "View"
|
118 |
msgstr ""
|
119 |
|
120 |
-
#: inc/fields/media.php:
|
121 |
msgid "No Title"
|
122 |
msgstr ""
|
123 |
|
124 |
-
#: inc/fields/media.php:
|
125 |
msgid "Select Files"
|
126 |
msgstr ""
|
127 |
|
128 |
-
#: inc/fields/media.php:
|
129 |
msgid "or"
|
130 |
msgstr ""
|
131 |
|
132 |
-
#: inc/fields/media.php:
|
133 |
msgid "Drop files here to upload"
|
134 |
msgstr ""
|
135 |
|
136 |
-
#: inc/fields/oembed.php:
|
137 |
msgid "Embed HTML not available."
|
138 |
msgstr ""
|
139 |
|
140 |
-
#: inc/fields/oembed.php:
|
141 |
msgid "Preview"
|
142 |
msgstr ""
|
143 |
|
144 |
-
#: inc/fields/post.php:
|
145 |
msgid "Select a post"
|
146 |
msgstr ""
|
147 |
|
148 |
-
#: inc/fields/post.php:
|
149 |
#, php-format
|
150 |
msgid "Select a %s"
|
151 |
msgstr ""
|
152 |
|
153 |
-
#: inc/fields/select-advanced.php:
|
154 |
msgid "Select an item"
|
155 |
msgstr ""
|
156 |
|
157 |
-
#: inc/fields/select.php:
|
158 |
msgid "All"
|
159 |
msgstr ""
|
160 |
|
161 |
-
#: inc/fields/select.php:
|
162 |
msgid "None"
|
163 |
msgstr ""
|
164 |
|
165 |
-
#: inc/fields/taxonomy.php:
|
166 |
msgid "Select a term"
|
167 |
msgstr ""
|
168 |
|
169 |
-
#: inc/fields/thickbox-image.php:
|
170 |
msgid "Upload Images"
|
171 |
msgstr ""
|
172 |
|
173 |
-
#: inc/fields/user.php:
|
174 |
msgid "Select an user"
|
175 |
msgstr ""
|
176 |
|
177 |
-
#: inc/validation.php:
|
178 |
msgid "Please correct the errors highlighted below and try again."
|
179 |
msgstr ""
|
5 |
msgstr ""
|
6 |
"Project-Id-Version: Meta Box 4.8.7\n"
|
7 |
"Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/meta-box\n"
|
8 |
+
"POT-Creation-Date: 2017-02-03 17:49+0700\n"
|
9 |
"MIME-Version: 1.0\n"
|
10 |
"Content-Type: text/plain; charset=UTF-8\n"
|
11 |
"Content-Transfer-Encoding: 8bit\n"
|
12 |
"PO-Revision-Date: 2014-MO-DA HO:MI+ZONE\n"
|
13 |
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
14 |
"Language-Team: Meta Box <admin@metabox.io>\n"
|
15 |
+
"X-Generator: Poedit 1.8.11\n"
|
16 |
"X-Poedit-KeywordsList: __;_x;_e;_ex;_n;_nx;esc_attr__;esc_attr_e;esc_attr_x;esc_html__;esc_html_e;esc_html_x;_n_noop;_nx_noop\n"
|
17 |
"X-Poedit-Basepath: ..\n"
|
18 |
"X-Poedit-SearchPath-0: .\n"
|
22 |
"X-Poedit-SearchPathExcluded-3: css\n"
|
23 |
"X-Poedit-SearchPathExcluded-4: lang\n"
|
24 |
|
25 |
+
#: inc/clone.php:98
|
26 |
+
msgid "+ Add more"
|
27 |
msgstr ""
|
28 |
|
29 |
+
#: inc/core.php:42
|
30 |
+
msgid "Documentation"
|
31 |
msgstr ""
|
32 |
|
33 |
+
#: inc/core.php:43
|
34 |
+
msgid "Extensions"
|
35 |
msgstr ""
|
36 |
|
37 |
+
#: inc/fields/autocomplete.php:19 inc/fields/autocomplete.php:78
|
38 |
+
#: inc/fields/autocomplete.php:93 inc/fields/file.php:154
|
39 |
msgid "Delete"
|
40 |
msgstr ""
|
41 |
|
42 |
+
#: inc/fields/button.php:32
|
43 |
msgid "Click me"
|
44 |
msgstr ""
|
45 |
|
46 |
+
#: inc/fields/checkbox.php:57
|
47 |
msgid "Yes"
|
48 |
msgstr ""
|
49 |
|
50 |
+
#: inc/fields/checkbox.php:57
|
51 |
msgid "No"
|
52 |
msgstr ""
|
53 |
|
54 |
+
#: inc/fields/file-input.php:21
|
55 |
msgid "Select File"
|
56 |
msgstr ""
|
57 |
|
58 |
+
#: inc/fields/file-input.php:43 inc/fields/select.php:89
|
59 |
msgid "Select"
|
60 |
msgstr ""
|
61 |
|
62 |
+
#: inc/fields/file-input.php:45 inc/fields/media.php:24
|
63 |
msgid "Remove"
|
64 |
msgstr ""
|
65 |
|
66 |
+
#: inc/fields/file.php:20
|
67 |
#, php-format
|
68 |
msgid "You may only upload maximum %d file"
|
69 |
msgstr ""
|
70 |
|
71 |
+
#: inc/fields/file.php:21
|
72 |
#, php-format
|
73 |
msgid "You may only upload maximum %d files"
|
74 |
msgstr ""
|
75 |
|
76 |
+
#: inc/fields/file.php:77
|
77 |
msgid "Error: Cannot delete file"
|
78 |
msgstr ""
|
79 |
|
80 |
+
#: inc/fields/file.php:89
|
81 |
msgid "Upload Files"
|
82 |
msgstr ""
|
83 |
|
84 |
+
#: inc/fields/file.php:90
|
85 |
msgid "+ Add new file"
|
86 |
msgstr ""
|
87 |
|
88 |
+
#: inc/fields/file.php:155 inc/fields/media.php:25
|
89 |
msgid "Edit"
|
90 |
msgstr ""
|
91 |
|
92 |
+
#: inc/fields/key-value.php:116
|
93 |
msgid "Key"
|
94 |
msgstr ""
|
95 |
|
96 |
+
#: inc/fields/key-value.php:117
|
97 |
msgid "Value"
|
98 |
msgstr ""
|
99 |
|
100 |
+
#: inc/fields/map.php:60
|
101 |
msgid "Find Address"
|
102 |
msgstr ""
|
103 |
|
104 |
+
#: inc/fields/media.php:21
|
105 |
msgid "+ Add Media"
|
106 |
msgstr ""
|
107 |
|
108 |
+
#: inc/fields/media.php:22
|
109 |
msgid " file"
|
110 |
msgstr ""
|
111 |
|
112 |
+
#: inc/fields/media.php:23
|
113 |
msgid " files"
|
114 |
msgstr ""
|
115 |
|
116 |
+
#: inc/fields/media.php:26
|
117 |
msgid "View"
|
118 |
msgstr ""
|
119 |
|
120 |
+
#: inc/fields/media.php:27
|
121 |
msgid "No Title"
|
122 |
msgstr ""
|
123 |
|
124 |
+
#: inc/fields/media.php:30
|
125 |
msgid "Select Files"
|
126 |
msgstr ""
|
127 |
|
128 |
+
#: inc/fields/media.php:31
|
129 |
msgid "or"
|
130 |
msgstr ""
|
131 |
|
132 |
+
#: inc/fields/media.php:32
|
133 |
msgid "Drop files here to upload"
|
134 |
msgstr ""
|
135 |
|
136 |
+
#: inc/fields/oembed.php:64
|
137 |
msgid "Embed HTML not available."
|
138 |
msgstr ""
|
139 |
|
140 |
+
#: inc/fields/oembed.php:79
|
141 |
msgid "Preview"
|
142 |
msgstr ""
|
143 |
|
144 |
+
#: inc/fields/post.php:38
|
145 |
msgid "Select a post"
|
146 |
msgstr ""
|
147 |
|
148 |
+
#: inc/fields/post.php:41 inc/fields/taxonomy.php:56
|
149 |
#, php-format
|
150 |
msgid "Select a %s"
|
151 |
msgstr ""
|
152 |
|
153 |
+
#: inc/fields/select-advanced.php:46
|
154 |
msgid "Select an item"
|
155 |
msgstr ""
|
156 |
|
157 |
+
#: inc/fields/select.php:89
|
158 |
msgid "All"
|
159 |
msgstr ""
|
160 |
|
161 |
+
#: inc/fields/select.php:89
|
162 |
msgid "None"
|
163 |
msgstr ""
|
164 |
|
165 |
+
#: inc/fields/taxonomy.php:53
|
166 |
msgid "Select a term"
|
167 |
msgstr ""
|
168 |
|
169 |
+
#: inc/fields/thickbox-image.php:55
|
170 |
msgid "Upload Images"
|
171 |
msgstr ""
|
172 |
|
173 |
+
#: inc/fields/user.php:38
|
174 |
msgid "Select an user"
|
175 |
msgstr ""
|
176 |
|
177 |
+
#: inc/validation.php:47
|
178 |
msgid "Please correct the errors highlighted below and try again."
|
179 |
msgstr ""
|
languages/meta-box-pl_PL.mo
CHANGED
Binary file
|
meta-box.php
CHANGED
@@ -3,12 +3,14 @@
|
|
3 |
* Plugin Name: Meta Box
|
4 |
* Plugin URI: https://metabox.io
|
5 |
* Description: Create custom meta boxes and custom fields in WordPress.
|
6 |
-
* Version: 4.10.
|
7 |
* Author: Rilwis
|
8 |
* Author URI: http://www.deluxeblogtips.com
|
9 |
* License: GPL2+
|
10 |
* Text Domain: meta-box
|
11 |
* Domain Path: /languages/
|
|
|
|
|
12 |
*/
|
13 |
|
14 |
if ( defined( 'ABSPATH' ) && ! defined( 'RWMB_VER' ) ) {
|
3 |
* Plugin Name: Meta Box
|
4 |
* Plugin URI: https://metabox.io
|
5 |
* Description: Create custom meta boxes and custom fields in WordPress.
|
6 |
+
* Version: 4.10.2
|
7 |
* Author: Rilwis
|
8 |
* Author URI: http://www.deluxeblogtips.com
|
9 |
* License: GPL2+
|
10 |
* Text Domain: meta-box
|
11 |
* Domain Path: /languages/
|
12 |
+
*
|
13 |
+
* @package Meta Box
|
14 |
*/
|
15 |
|
16 |
if ( defined( 'ABSPATH' ) && ! defined( 'RWMB_VER' ) ) {
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: metabox, rilwis, fitwp, f-j-kaiser, funkatronic, PerWiklander, rua
|
|
3 |
Donate link: http://paypal.me/anhtnt
|
4 |
Tags: meta-box, custom fields, custom field, meta, meta-boxes, admin, advanced, custom, edit, field, file, image, magic fields, matrix, more fields, Post, repeater, simple fields, text, textarea, type, cms, fields post
|
5 |
Requires at least: 4.1
|
6 |
-
Tested up to: 4.7
|
7 |
-
Stable tag: 4.10
|
8 |
License: GPLv2 or later
|
9 |
|
10 |
Meta Box plugin is a powerful, professional developer toolkit to create custom meta boxes and custom fields for WordPress.
|
@@ -91,10 +91,21 @@ To getting started with the plugin API, please read [this tutorial](https://meta
|
|
91 |
|
92 |
== Changelog ==
|
93 |
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
* Fix: Fix `image_upload` and `plupload_image` field when select images to upload.
|
96 |
|
97 |
-
|
98 |
* Improvement: Add `video` field type which allows users to upload or select video from the Media Library. See [demo](https://github.com/rilwis/meta-box/blob/master/demo/video.php).
|
99 |
* Improvement: Update Turkish. Prop Emre Tuna <tunaemre@windowslive.com>.
|
100 |
* Improvement: Use WP 4.6 date picker localization instead of JS localized file to reduce plugin size.
|
@@ -102,7 +113,7 @@ To getting started with the plugin API, please read [this tutorial](https://meta
|
|
102 |
* Fix: `taxonomy_advanced` field now can be cloned.
|
103 |
* Fix: Make localize_script works with WP 4.1.
|
104 |
|
105 |
-
|
106 |
* Fix: Quick fix for enqueueing validation script
|
107 |
|
108 |
= 4.9.7 =
|
3 |
Donate link: http://paypal.me/anhtnt
|
4 |
Tags: meta-box, custom fields, custom field, meta, meta-boxes, admin, advanced, custom, edit, field, file, image, magic fields, matrix, more fields, Post, repeater, simple fields, text, textarea, type, cms, fields post
|
5 |
Requires at least: 4.1
|
6 |
+
Tested up to: 4.7.2
|
7 |
+
Stable tag: 4.10.2
|
8 |
License: GPLv2 or later
|
9 |
|
10 |
Meta Box plugin is a powerful, professional developer toolkit to create custom meta boxes and custom fields for WordPress.
|
91 |
|
92 |
== Changelog ==
|
93 |
|
94 |
+
= 4.10.2 =
|
95 |
+
* Improvement: Add `max_file_size` to upload fields (`File_Upload`, `Image_Upload`, `Plupload_Image`).
|
96 |
+
* Improvement: Add support for attributes for file input.
|
97 |
+
* Improvement: Update Polish translation.
|
98 |
+
* Improvement: Add translation support for Key and Value strings (@prop saqibsarwar).
|
99 |
+
* Fix: Shorter width of email field vs. other fields (@prop saqibsarwar).
|
100 |
+
* Fix: Fix cloneable datetime field with timestamp=true.
|
101 |
+
* Fix: Remove margin bottom in select_advanced options.
|
102 |
+
* Fix: Showing the correct selected value for select_advanced field when the option value contains '&' character.
|
103 |
+
* Fix: Fix default values not working with taxonomy and taxonomy_advanced fields.
|
104 |
+
|
105 |
+
= 4.10.1 =
|
106 |
* Fix: Fix `image_upload` and `plupload_image` field when select images to upload.
|
107 |
|
108 |
+
= 4.10 =
|
109 |
* Improvement: Add `video` field type which allows users to upload or select video from the Media Library. See [demo](https://github.com/rilwis/meta-box/blob/master/demo/video.php).
|
110 |
* Improvement: Update Turkish. Prop Emre Tuna <tunaemre@windowslive.com>.
|
111 |
* Improvement: Use WP 4.6 date picker localization instead of JS localized file to reduce plugin size.
|
113 |
* Fix: `taxonomy_advanced` field now can be cloned.
|
114 |
* Fix: Make localize_script works with WP 4.1.
|
115 |
|
116 |
+
= 4.9.8 =
|
117 |
* Fix: Quick fix for enqueueing validation script
|
118 |
|
119 |
= 4.9.7 =
|