@@ -10,13 +10,13 @@ |
||
10 | 10 | */ |
11 | 11 | interface RWMB_Storage_Interface { |
12 | 12 | |
13 | - /** |
|
14 | - * Get value from storage. |
|
15 | - * |
|
16 | - * @param int $object_id Object id. |
|
17 | - * @param string $name Field name. |
|
18 | - * @param array $args Custom arguments.. |
|
19 | - * @return mixed |
|
20 | - */ |
|
21 | - public function get( $object_id, $name, $args = array() ); |
|
13 | + /** |
|
14 | + * Get value from storage. |
|
15 | + * |
|
16 | + * @param int $object_id Object id. |
|
17 | + * @param string $name Field name. |
|
18 | + * @param array $args Custom arguments.. |
|
19 | + * @return mixed |
|
20 | + */ |
|
21 | + public function get( $object_id, $name, $args = array() ); |
|
22 | 22 | } |
@@ -18,5 +18,5 @@ |
||
18 | 18 | * @param array $args Custom arguments.. |
19 | 19 | * @return mixed |
20 | 20 | */ |
21 | - public function get( $object_id, $name, $args = array() ); |
|
21 | + public function get($object_id, $name, $args = array()); |
|
22 | 22 | } |
@@ -10,24 +10,24 @@ |
||
10 | 10 | */ |
11 | 11 | class RWMB_Storage_Registry { |
12 | 12 | |
13 | - /** |
|
14 | - * List storage instances. |
|
15 | - * |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - protected $storages = array(); |
|
13 | + /** |
|
14 | + * List storage instances. |
|
15 | + * |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + protected $storages = array(); |
|
19 | 19 | |
20 | - /** |
|
21 | - * Get storage instance. |
|
22 | - * |
|
23 | - * @param string $class_name Storage class name. |
|
24 | - * @return RWMB_Storage_Interface |
|
25 | - */ |
|
26 | - public function get( $class_name ) { |
|
27 | - if ( empty( $this->storages[ $class_name ] ) ) { |
|
28 | - $this->storages[ $class_name ] = new $class_name(); |
|
29 | - } |
|
20 | + /** |
|
21 | + * Get storage instance. |
|
22 | + * |
|
23 | + * @param string $class_name Storage class name. |
|
24 | + * @return RWMB_Storage_Interface |
|
25 | + */ |
|
26 | + public function get( $class_name ) { |
|
27 | + if ( empty( $this->storages[ $class_name ] ) ) { |
|
28 | + $this->storages[ $class_name ] = new $class_name(); |
|
29 | + } |
|
30 | 30 | |
31 | - return $this->storages[ $class_name ]; |
|
32 | - } |
|
31 | + return $this->storages[ $class_name ]; |
|
32 | + } |
|
33 | 33 | } |
@@ -23,11 +23,11 @@ |
||
23 | 23 | * @param string $class_name Storage class name. |
24 | 24 | * @return RWMB_Storage_Interface |
25 | 25 | */ |
26 | - public function get( $class_name ) { |
|
27 | - if ( empty( $this->storages[ $class_name ] ) ) { |
|
28 | - $this->storages[ $class_name ] = new $class_name(); |
|
26 | + public function get($class_name) { |
|
27 | + if (empty($this->storages[$class_name])) { |
|
28 | + $this->storages[$class_name] = new $class_name(); |
|
29 | 29 | } |
30 | 30 | |
31 | - return $this->storages[ $class_name ]; |
|
31 | + return $this->storages[$class_name]; |
|
32 | 32 | } |
33 | 33 | } |
@@ -10,75 +10,75 @@ |
||
10 | 10 | * Meta box registry class. |
11 | 11 | */ |
12 | 12 | class RWMB_Meta_Box_Registry { |
13 | - /** |
|
14 | - * Internal data storage. |
|
15 | - * |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - private $data = array(); |
|
13 | + /** |
|
14 | + * Internal data storage. |
|
15 | + * |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + private $data = array(); |
|
19 | 19 | |
20 | - /** |
|
21 | - * Create a meta box object. |
|
22 | - * |
|
23 | - * @param array $settings Meta box settings. |
|
24 | - * @return \RW_Meta_Box |
|
25 | - */ |
|
26 | - public function make( $settings ) { |
|
27 | - $class_name = apply_filters( 'rwmb_meta_box_class_name', 'RW_Meta_Box', $settings ); |
|
20 | + /** |
|
21 | + * Create a meta box object. |
|
22 | + * |
|
23 | + * @param array $settings Meta box settings. |
|
24 | + * @return \RW_Meta_Box |
|
25 | + */ |
|
26 | + public function make( $settings ) { |
|
27 | + $class_name = apply_filters( 'rwmb_meta_box_class_name', 'RW_Meta_Box', $settings ); |
|
28 | 28 | |
29 | - $meta_box = new $class_name( $settings ); |
|
30 | - $this->add( $meta_box ); |
|
31 | - return $meta_box; |
|
32 | - } |
|
29 | + $meta_box = new $class_name( $settings ); |
|
30 | + $this->add( $meta_box ); |
|
31 | + return $meta_box; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Add a meta box to the registry. |
|
36 | - * |
|
37 | - * @param RW_Meta_Box $meta_box Meta box instance. |
|
38 | - */ |
|
39 | - public function add( RW_Meta_Box $meta_box ) { |
|
40 | - $this->data[ $meta_box->id ] = $meta_box; |
|
41 | - } |
|
34 | + /** |
|
35 | + * Add a meta box to the registry. |
|
36 | + * |
|
37 | + * @param RW_Meta_Box $meta_box Meta box instance. |
|
38 | + */ |
|
39 | + public function add( RW_Meta_Box $meta_box ) { |
|
40 | + $this->data[ $meta_box->id ] = $meta_box; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Retrieve a meta box by id. |
|
45 | - * |
|
46 | - * @param string $id Meta box id. |
|
47 | - * |
|
48 | - * @return RW_Meta_Box|bool False or meta box object. |
|
49 | - */ |
|
50 | - public function get( $id ) { |
|
51 | - return isset( $this->data[ $id ] ) ? $this->data[ $id ] : false; |
|
52 | - } |
|
43 | + /** |
|
44 | + * Retrieve a meta box by id. |
|
45 | + * |
|
46 | + * @param string $id Meta box id. |
|
47 | + * |
|
48 | + * @return RW_Meta_Box|bool False or meta box object. |
|
49 | + */ |
|
50 | + public function get( $id ) { |
|
51 | + return isset( $this->data[ $id ] ) ? $this->data[ $id ] : false; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Get meta boxes under some conditions. |
|
56 | - * |
|
57 | - * @param array $args Custom argument to get meta boxes by. |
|
58 | - * |
|
59 | - * @return array |
|
60 | - */ |
|
61 | - public function get_by( $args ) { |
|
62 | - $meta_boxes = $this->data; |
|
63 | - foreach ( $meta_boxes as $index => $meta_box ) { |
|
64 | - foreach ( $args as $key => $value ) { |
|
65 | - $meta_box_key = 'object_type' === $key ? $meta_box->get_object_type() : $meta_box->$key; |
|
66 | - if ( $meta_box_key !== $value ) { |
|
67 | - unset( $meta_boxes[ $index ] ); |
|
68 | - continue 2; // Skip the meta box loop. |
|
69 | - } |
|
70 | - } |
|
71 | - } |
|
54 | + /** |
|
55 | + * Get meta boxes under some conditions. |
|
56 | + * |
|
57 | + * @param array $args Custom argument to get meta boxes by. |
|
58 | + * |
|
59 | + * @return array |
|
60 | + */ |
|
61 | + public function get_by( $args ) { |
|
62 | + $meta_boxes = $this->data; |
|
63 | + foreach ( $meta_boxes as $index => $meta_box ) { |
|
64 | + foreach ( $args as $key => $value ) { |
|
65 | + $meta_box_key = 'object_type' === $key ? $meta_box->get_object_type() : $meta_box->$key; |
|
66 | + if ( $meta_box_key !== $value ) { |
|
67 | + unset( $meta_boxes[ $index ] ); |
|
68 | + continue 2; // Skip the meta box loop. |
|
69 | + } |
|
70 | + } |
|
71 | + } |
|
72 | 72 | |
73 | - return $meta_boxes; |
|
74 | - } |
|
73 | + return $meta_boxes; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Retrieve all meta boxes. |
|
78 | - * |
|
79 | - * @return array |
|
80 | - */ |
|
81 | - public function all() { |
|
82 | - return $this->data; |
|
83 | - } |
|
76 | + /** |
|
77 | + * Retrieve all meta boxes. |
|
78 | + * |
|
79 | + * @return array |
|
80 | + */ |
|
81 | + public function all() { |
|
82 | + return $this->data; |
|
83 | + } |
|
84 | 84 | } |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | * @param array $settings Meta box settings. |
24 | 24 | * @return \RW_Meta_Box |
25 | 25 | */ |
26 | - public function make( $settings ) { |
|
27 | - $class_name = apply_filters( 'rwmb_meta_box_class_name', 'RW_Meta_Box', $settings ); |
|
26 | + public function make($settings) { |
|
27 | + $class_name = apply_filters('rwmb_meta_box_class_name', 'RW_Meta_Box', $settings); |
|
28 | 28 | |
29 | - $meta_box = new $class_name( $settings ); |
|
30 | - $this->add( $meta_box ); |
|
29 | + $meta_box = new $class_name($settings); |
|
30 | + $this->add($meta_box); |
|
31 | 31 | return $meta_box; |
32 | 32 | } |
33 | 33 | |
@@ -36,8 +36,8 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @param RW_Meta_Box $meta_box Meta box instance. |
38 | 38 | */ |
39 | - public function add( RW_Meta_Box $meta_box ) { |
|
40 | - $this->data[ $meta_box->id ] = $meta_box; |
|
39 | + public function add(RW_Meta_Box $meta_box) { |
|
40 | + $this->data[$meta_box->id] = $meta_box; |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @return RW_Meta_Box|bool False or meta box object. |
49 | 49 | */ |
50 | - public function get( $id ) { |
|
51 | - return isset( $this->data[ $id ] ) ? $this->data[ $id ] : false; |
|
50 | + public function get($id) { |
|
51 | + return isset($this->data[$id]) ? $this->data[$id] : false; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -58,13 +58,13 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @return array |
60 | 60 | */ |
61 | - public function get_by( $args ) { |
|
61 | + public function get_by($args) { |
|
62 | 62 | $meta_boxes = $this->data; |
63 | - foreach ( $meta_boxes as $index => $meta_box ) { |
|
64 | - foreach ( $args as $key => $value ) { |
|
63 | + foreach ($meta_boxes as $index => $meta_box) { |
|
64 | + foreach ($args as $key => $value) { |
|
65 | 65 | $meta_box_key = 'object_type' === $key ? $meta_box->get_object_type() : $meta_box->$key; |
66 | - if ( $meta_box_key !== $value ) { |
|
67 | - unset( $meta_boxes[ $index ] ); |
|
66 | + if ($meta_box_key !== $value) { |
|
67 | + unset($meta_boxes[$index]); |
|
68 | 68 | continue 2; // Skip the meta box loop. |
69 | 69 | } |
70 | 70 | } |
@@ -11,614 +11,614 @@ |
||
11 | 11 | * The field base class. |
12 | 12 | */ |
13 | 13 | abstract class RWMB_Field { |
14 | - /** |
|
15 | - * Add actions. |
|
16 | - */ |
|
17 | - public static function add_actions() { |
|
18 | - } |
|
19 | - |
|
20 | - /** |
|
21 | - * Enqueue scripts and styles. |
|
22 | - */ |
|
23 | - public static function admin_enqueue_scripts() { |
|
24 | - } |
|
25 | - |
|
26 | - /** |
|
27 | - * Show field HTML |
|
28 | - * Filters are put inside this method, not inside methods such as "meta", "html", "begin_html", etc. |
|
29 | - * That ensures the returned value are always been applied filters. |
|
30 | - * This method is not meant to be overwritten in specific fields. |
|
31 | - * |
|
32 | - * @param array $field Field parameters. |
|
33 | - * @param bool $saved Whether the meta box is saved at least once. |
|
34 | - * @param int $post_id Post ID. |
|
35 | - */ |
|
36 | - public static function show( $field, $saved, $post_id = 0 ) { |
|
37 | - $meta = self::call( $field, 'meta', $post_id, $saved ); |
|
38 | - $meta = self::filter( 'field_meta', $meta, $field, $saved ); |
|
39 | - |
|
40 | - $begin = self::call( $field, 'begin_html', $meta ); |
|
41 | - $begin = self::filter( 'begin_html', $begin, $field, $meta ); |
|
42 | - |
|
43 | - // Separate code for cloneable and non-cloneable fields to make easy to maintain. |
|
44 | - if ( $field['clone'] ) { |
|
45 | - $field_html = RWMB_Clone::html( $meta, $field ); |
|
46 | - } else { |
|
47 | - // Call separated methods for displaying each type of field. |
|
48 | - $field_html = self::call( $field, 'html', $meta ); |
|
49 | - $field_html = self::filter( 'html', $field_html, $field, $meta ); |
|
50 | - } |
|
51 | - |
|
52 | - $end = self::call( $field, 'end_html', $meta ); |
|
53 | - $end = self::filter( 'end_html', $end, $field, $meta ); |
|
54 | - |
|
55 | - $html = self::filter( 'wrapper_html', "$begin$field_html$end", $field, $meta ); |
|
56 | - |
|
57 | - // Display label and input in DIV and allow user-defined classes to be appended. |
|
58 | - $classes = "rwmb-field rwmb-{$field['type']}-wrapper " . $field['class']; |
|
59 | - if ( ! empty( $field['required'] ) ) { |
|
60 | - $classes .= ' required'; |
|
61 | - } |
|
62 | - |
|
63 | - $outer_html = sprintf( |
|
64 | - $field['before'] . '<div class="%s">%s</div>' . $field['after'], |
|
65 | - esc_attr( trim( $classes ) ), |
|
66 | - $html |
|
67 | - ); |
|
68 | - $outer_html = self::filter( 'outer_html', $outer_html, $field, $meta ); |
|
69 | - |
|
70 | - echo $outer_html; // WPCS: XSS OK. |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Get field HTML. |
|
75 | - * |
|
76 | - * @param mixed $meta Meta value. |
|
77 | - * @param array $field Field parameters. |
|
78 | - * |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public static function html( $meta, $field ) { |
|
82 | - return ''; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Show begin HTML markup for fields. |
|
87 | - * |
|
88 | - * @param mixed $meta Meta value. |
|
89 | - * @param array $field Field parameters. |
|
90 | - * |
|
91 | - * @return string |
|
92 | - */ |
|
93 | - public static function begin_html( $meta, $field ) { |
|
94 | - $field_label = ''; |
|
95 | - if ( $field['name'] ) { |
|
96 | - // Change "for" attribute in label |
|
97 | - $field_label = sprintf( |
|
98 | - '<div class="rwmb-label"> |
|
14 | + /** |
|
15 | + * Add actions. |
|
16 | + */ |
|
17 | + public static function add_actions() { |
|
18 | + } |
|
19 | + |
|
20 | + /** |
|
21 | + * Enqueue scripts and styles. |
|
22 | + */ |
|
23 | + public static function admin_enqueue_scripts() { |
|
24 | + } |
|
25 | + |
|
26 | + /** |
|
27 | + * Show field HTML |
|
28 | + * Filters are put inside this method, not inside methods such as "meta", "html", "begin_html", etc. |
|
29 | + * That ensures the returned value are always been applied filters. |
|
30 | + * This method is not meant to be overwritten in specific fields. |
|
31 | + * |
|
32 | + * @param array $field Field parameters. |
|
33 | + * @param bool $saved Whether the meta box is saved at least once. |
|
34 | + * @param int $post_id Post ID. |
|
35 | + */ |
|
36 | + public static function show( $field, $saved, $post_id = 0 ) { |
|
37 | + $meta = self::call( $field, 'meta', $post_id, $saved ); |
|
38 | + $meta = self::filter( 'field_meta', $meta, $field, $saved ); |
|
39 | + |
|
40 | + $begin = self::call( $field, 'begin_html', $meta ); |
|
41 | + $begin = self::filter( 'begin_html', $begin, $field, $meta ); |
|
42 | + |
|
43 | + // Separate code for cloneable and non-cloneable fields to make easy to maintain. |
|
44 | + if ( $field['clone'] ) { |
|
45 | + $field_html = RWMB_Clone::html( $meta, $field ); |
|
46 | + } else { |
|
47 | + // Call separated methods for displaying each type of field. |
|
48 | + $field_html = self::call( $field, 'html', $meta ); |
|
49 | + $field_html = self::filter( 'html', $field_html, $field, $meta ); |
|
50 | + } |
|
51 | + |
|
52 | + $end = self::call( $field, 'end_html', $meta ); |
|
53 | + $end = self::filter( 'end_html', $end, $field, $meta ); |
|
54 | + |
|
55 | + $html = self::filter( 'wrapper_html', "$begin$field_html$end", $field, $meta ); |
|
56 | + |
|
57 | + // Display label and input in DIV and allow user-defined classes to be appended. |
|
58 | + $classes = "rwmb-field rwmb-{$field['type']}-wrapper " . $field['class']; |
|
59 | + if ( ! empty( $field['required'] ) ) { |
|
60 | + $classes .= ' required'; |
|
61 | + } |
|
62 | + |
|
63 | + $outer_html = sprintf( |
|
64 | + $field['before'] . '<div class="%s">%s</div>' . $field['after'], |
|
65 | + esc_attr( trim( $classes ) ), |
|
66 | + $html |
|
67 | + ); |
|
68 | + $outer_html = self::filter( 'outer_html', $outer_html, $field, $meta ); |
|
69 | + |
|
70 | + echo $outer_html; // WPCS: XSS OK. |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Get field HTML. |
|
75 | + * |
|
76 | + * @param mixed $meta Meta value. |
|
77 | + * @param array $field Field parameters. |
|
78 | + * |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public static function html( $meta, $field ) { |
|
82 | + return ''; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Show begin HTML markup for fields. |
|
87 | + * |
|
88 | + * @param mixed $meta Meta value. |
|
89 | + * @param array $field Field parameters. |
|
90 | + * |
|
91 | + * @return string |
|
92 | + */ |
|
93 | + public static function begin_html( $meta, $field ) { |
|
94 | + $field_label = ''; |
|
95 | + if ( $field['name'] ) { |
|
96 | + // Change "for" attribute in label |
|
97 | + $field_label = sprintf( |
|
98 | + '<div class="rwmb-label"> |
|
99 | 99 | <label for="%s">%s%s</label> |
100 | 100 | %s |
101 | 101 | </div>', |
102 | - ( isset( $field['attributes']['id'] ) ) ? esc_attr( $field['attributes']['id'] ) : esc_attr( $field['id'] ), |
|
103 | - $field['name'], |
|
104 | - $field['required'] || ! empty( $field['attributes']['required'] ) ? '<span class="rwmb-required">*</span>' : '', |
|
105 | - self::label_description( $field ) |
|
106 | - ); |
|
107 | - } |
|
108 | - |
|
109 | - $data_min_clone = is_numeric( $field['min_clone'] ) && $field['min_clone'] > 1 ? ' data-min-clone=' . $field['min_clone'] : ''; |
|
110 | - $data_max_clone = is_numeric( $field['max_clone'] ) && $field['max_clone'] > 1 ? ' data-max-clone=' . $field['max_clone'] : ''; |
|
111 | - |
|
112 | - $input_open = sprintf( |
|
113 | - '<div class="rwmb-input" %s %s>', |
|
114 | - $data_min_clone, |
|
115 | - $data_max_clone |
|
116 | - ); |
|
117 | - |
|
118 | - return $field_label . $input_open; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Show end HTML markup for fields. |
|
123 | - * |
|
124 | - * @param mixed $meta Meta value. |
|
125 | - * @param array $field Field parameters. |
|
126 | - * |
|
127 | - * @return string |
|
128 | - */ |
|
129 | - public static function end_html( $meta, $field ) { |
|
130 | - return RWMB_Clone::add_clone_button( $field ) . self::call( 'input_description', $field ) . '</div>'; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Display field label description. |
|
135 | - * |
|
136 | - * @param array $field Field parameters. |
|
137 | - * @return string |
|
138 | - */ |
|
139 | - protected static function label_description( $field ) { |
|
140 | - $id = $field['id'] ? ' id="' . esc_attr( $field['id'] ) . '-label-description"' : ''; |
|
141 | - return $field['label_description'] ? "<p{$id} class='description'>{$field['label_description']}</p>" : ''; |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Display field description. |
|
146 | - * |
|
147 | - * @param array $field Field parameters. |
|
148 | - * @return string |
|
149 | - */ |
|
150 | - protected static function input_description( $field ) { |
|
151 | - $id = $field['id'] ? ' id="' . esc_attr( $field['id'] ) . '-description"' : ''; |
|
152 | - return $field['desc'] ? "<p{$id} class='description'>{$field['desc']}</p>" : ''; |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Get raw meta value. |
|
157 | - * |
|
158 | - * @param int $object_id Object ID. |
|
159 | - * @param array $field Field parameters. |
|
160 | - * @param array $args Arguments of {@see rwmb_meta()} helper. |
|
161 | - * |
|
162 | - * @return mixed |
|
163 | - */ |
|
164 | - public static function raw_meta( $object_id, $field, $args = array() ) { |
|
165 | - if ( empty( $field['id'] ) ) { |
|
166 | - return ''; |
|
167 | - } |
|
168 | - |
|
169 | - if ( isset( $field['storage'] ) ) { |
|
170 | - $storage = $field['storage']; |
|
171 | - } elseif ( isset( $args['object_type'] ) ) { |
|
172 | - $storage = rwmb_get_storage( $args['object_type'] ); |
|
173 | - } else { |
|
174 | - $storage = rwmb_get_storage( 'post' ); |
|
175 | - } |
|
176 | - |
|
177 | - if ( ! isset( $args['single'] ) ) { |
|
178 | - $args['single'] = $field['clone'] || ! $field['multiple']; |
|
179 | - } |
|
180 | - |
|
181 | - if ( $field['clone'] && $field['clone_as_multiple'] ) { |
|
182 | - $args['single'] = false; |
|
183 | - } |
|
184 | - |
|
185 | - $value = $storage->get( $object_id, $field['id'], $args ); |
|
186 | - $value = self::filter( 'raw_meta', $value, $field, $object_id, $args ); |
|
187 | - return $value; |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Get meta value. |
|
192 | - * |
|
193 | - * @param int $post_id Post ID. |
|
194 | - * @param bool $saved Whether the meta box is saved at least once. |
|
195 | - * @param array $field Field parameters. |
|
196 | - * |
|
197 | - * @return mixed |
|
198 | - */ |
|
199 | - public static function meta( $post_id, $saved, $field ) { |
|
200 | - /** |
|
201 | - * For special fields like 'divider', 'heading' which don't have ID, just return empty string |
|
202 | - * to prevent notice error when displaying fields. |
|
203 | - */ |
|
204 | - if ( empty( $field['id'] ) ) { |
|
205 | - return ''; |
|
206 | - } |
|
207 | - |
|
208 | - // Get raw meta. |
|
209 | - $meta = self::call( $field, 'raw_meta', $post_id ); |
|
210 | - |
|
211 | - // Use $field['std'] only when the meta box hasn't been saved (i.e. the first time we run). |
|
212 | - $meta = ! $saved || ! $field['save_field'] ? $field['std'] : $meta; |
|
213 | - |
|
214 | - if ( $field['clone'] ) { |
|
215 | - $meta = RWMB_Helpers_Array::ensure( $meta ); |
|
216 | - |
|
217 | - // Ensure $meta is an array with values so that the foreach loop in self::show() runs properly. |
|
218 | - if ( empty( $meta ) ) { |
|
219 | - $meta = array( '' ); |
|
220 | - } |
|
221 | - |
|
222 | - if ( $field['multiple'] ) { |
|
223 | - $first = reset( $meta ); |
|
224 | - |
|
225 | - // If users set std for a cloneable checkbox list field in the Builder, they can only set [value1, value2]. We need to transform it to [[value1, value2]]. |
|
226 | - // In other cases, make sure each value is an array. |
|
227 | - $meta = is_array( $first ) ? array_map( 'RWMB_Helpers_Array::ensure', $meta ) : array( $meta ); |
|
228 | - } |
|
229 | - } elseif ( $field['multiple'] ) { |
|
230 | - $meta = RWMB_Helpers_Array::ensure( $meta ); |
|
231 | - } |
|
232 | - |
|
233 | - return $meta; |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Process the submitted value before saving into the database. |
|
238 | - * |
|
239 | - * @param mixed $value The submitted value. |
|
240 | - * @param int $object_id The object ID. |
|
241 | - * @param array $field The field settings. |
|
242 | - */ |
|
243 | - public static function process_value( $value, $object_id, $field ) { |
|
244 | - $old_value = self::call( $field, 'raw_meta', $object_id ); |
|
245 | - |
|
246 | - // Allow field class change the value. |
|
247 | - if ( $field['clone'] ) { |
|
248 | - $value = RWMB_Clone::value( $value, $old_value, $object_id, $field ); |
|
249 | - } else { |
|
250 | - $value = self::call( $field, 'value', $value, $old_value, $object_id ); |
|
251 | - $value = self::filter( 'sanitize', $value, $field, $old_value, $object_id ); |
|
252 | - } |
|
253 | - $value = self::filter( 'value', $value, $field, $old_value, $object_id ); |
|
254 | - |
|
255 | - return $value; |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Set value of meta before saving into database. |
|
260 | - * |
|
261 | - * @param mixed $new The submitted meta value. |
|
262 | - * @param mixed $old The existing meta value. |
|
263 | - * @param int $post_id The post ID. |
|
264 | - * @param array $field The field parameters. |
|
265 | - * |
|
266 | - * @return mixed |
|
267 | - */ |
|
268 | - public static function value( $new, $old, $post_id, $field ) { |
|
269 | - return $new; |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Save meta value. |
|
274 | - * |
|
275 | - * @param mixed $new The submitted meta value. |
|
276 | - * @param mixed $old The existing meta value. |
|
277 | - * @param int $post_id The post ID. |
|
278 | - * @param array $field The field parameters. |
|
279 | - */ |
|
280 | - public static function save( $new, $old, $post_id, $field ) { |
|
281 | - if ( empty( $field['id'] ) || ! $field['save_field'] ) { |
|
282 | - return; |
|
283 | - } |
|
284 | - $name = $field['id']; |
|
285 | - $storage = $field['storage']; |
|
286 | - |
|
287 | - // Remove post meta if it's empty. |
|
288 | - if ( ! RWMB_Helpers_Value::is_valid_for_field( $new ) ) { |
|
289 | - $storage->delete( $post_id, $name ); |
|
290 | - return; |
|
291 | - } |
|
292 | - |
|
293 | - // If field is cloneable AND not force to save as multiple rows, value is saved as a single row in the database. |
|
294 | - if ( $field['clone'] && ! $field['clone_as_multiple'] ) { |
|
295 | - $storage->update( $post_id, $name, $new ); |
|
296 | - return; |
|
297 | - } |
|
298 | - |
|
299 | - // Save cloned fields as multiple values instead serialized array. |
|
300 | - if ( ( $field['clone'] && $field['clone_as_multiple'] ) || $field['multiple'] ) { |
|
301 | - $storage->delete( $post_id, $name ); |
|
302 | - $new = (array) $new; |
|
303 | - foreach ( $new as $new_value ) { |
|
304 | - $storage->add( $post_id, $name, $new_value, false ); |
|
305 | - } |
|
306 | - return; |
|
307 | - } |
|
308 | - |
|
309 | - // Default: just update post meta. |
|
310 | - $storage->update( $post_id, $name, $new ); |
|
311 | - } |
|
312 | - |
|
313 | - /** |
|
314 | - * Normalize parameters for field. |
|
315 | - * |
|
316 | - * @param array|string $field Field settings. |
|
317 | - * @return array |
|
318 | - */ |
|
319 | - public static function normalize( $field ) { |
|
320 | - // Quick define text fields with "name" attribute only. |
|
321 | - if ( is_string( $field ) ) { |
|
322 | - $field = array( |
|
323 | - 'name' => $field, |
|
324 | - 'id' => sanitize_key( $field ), |
|
325 | - ); |
|
326 | - } |
|
327 | - $field = wp_parse_args( |
|
328 | - $field, |
|
329 | - array( |
|
330 | - 'id' => '', |
|
331 | - 'name' => '', |
|
332 | - 'type' => 'text', |
|
333 | - 'label_description' => '', |
|
334 | - 'multiple' => false, |
|
335 | - 'std' => '', |
|
336 | - 'desc' => '', |
|
337 | - 'format' => '', |
|
338 | - 'before' => '', |
|
339 | - 'after' => '', |
|
340 | - 'field_name' => isset( $field['id'] ) ? $field['id'] : '', |
|
341 | - 'placeholder' => '', |
|
342 | - 'save_field' => true, |
|
343 | - |
|
344 | - 'clone' => false, |
|
345 | - 'min_clone' => 0, |
|
346 | - 'max_clone' => 0, |
|
347 | - 'sort_clone' => false, |
|
348 | - 'add_button' => __( '+ Add more', 'meta-box' ), |
|
349 | - 'clone_default' => false, |
|
350 | - 'clone_as_multiple' => false, |
|
351 | - |
|
352 | - 'class' => '', |
|
353 | - 'disabled' => false, |
|
354 | - 'required' => false, |
|
355 | - 'autofocus' => false, |
|
356 | - 'attributes' => array(), |
|
357 | - |
|
358 | - 'sanitize_callback' => null, |
|
359 | - ) |
|
360 | - ); |
|
361 | - |
|
362 | - // Store the original ID to run correct filters for the clonable field. |
|
363 | - if ( $field['clone'] ) { |
|
364 | - $field['_original_id'] = $field['id']; |
|
365 | - } |
|
366 | - |
|
367 | - if ( $field['clone_default'] ) { |
|
368 | - $field['attributes'] = wp_parse_args( |
|
369 | - $field['attributes'], |
|
370 | - array( |
|
371 | - 'data-default' => $field['std'], |
|
372 | - 'data-clone-default' => 'true', |
|
373 | - ) |
|
374 | - ); |
|
375 | - } |
|
376 | - |
|
377 | - if ( 1 === $field['max_clone'] ) { |
|
378 | - $field['clone'] = false; |
|
379 | - } |
|
380 | - |
|
381 | - return $field; |
|
382 | - } |
|
383 | - |
|
384 | - /** |
|
385 | - * Get the attributes for a field. |
|
386 | - * |
|
387 | - * @param array $field Field parameters. |
|
388 | - * @param mixed $value Meta value. |
|
389 | - * |
|
390 | - * @return array |
|
391 | - */ |
|
392 | - public static function get_attributes( $field, $value = null ) { |
|
393 | - $attributes = wp_parse_args( |
|
394 | - $field['attributes'], |
|
395 | - array( |
|
396 | - 'disabled' => $field['disabled'], |
|
397 | - 'autofocus' => $field['autofocus'], |
|
398 | - 'required' => $field['required'], |
|
399 | - 'id' => $field['id'], |
|
400 | - 'class' => '', |
|
401 | - 'name' => $field['field_name'], |
|
402 | - ) |
|
403 | - ); |
|
404 | - |
|
405 | - $attributes['class'] = trim( implode( ' ', array_merge( array( "rwmb-{$field['type']}" ), (array) $attributes['class'] ) ) ); |
|
406 | - |
|
407 | - return $attributes; |
|
408 | - } |
|
409 | - |
|
410 | - /** |
|
411 | - * Renders an attribute array into an html attributes string. |
|
412 | - * |
|
413 | - * @param array $attributes HTML attributes. |
|
414 | - * |
|
415 | - * @return string |
|
416 | - */ |
|
417 | - public static function render_attributes( $attributes ) { |
|
418 | - $output = ''; |
|
419 | - |
|
420 | - $attributes = array_filter( $attributes, 'RWMB_Helpers_Value::is_valid_for_attribute' ); |
|
421 | - foreach ( $attributes as $key => $value ) { |
|
422 | - if ( is_array( $value ) ) { |
|
423 | - $value = wp_json_encode( $value ); |
|
424 | - } |
|
425 | - |
|
426 | - $output .= sprintf( ' %s="%s"', $key, esc_attr( $value ) ); |
|
427 | - } |
|
428 | - |
|
429 | - return $output; |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * Get the field value. |
|
434 | - * The difference between this function and 'meta' function is 'meta' function always returns the escaped value |
|
435 | - * of the field saved in the database, while this function returns more meaningful value of the field, for ex.: |
|
436 | - * for file/image: return array of file/image information instead of file/image IDs. |
|
437 | - * |
|
438 | - * Each field can extend this function and add more data to the returned value. |
|
439 | - * See specific field classes for details. |
|
440 | - * |
|
441 | - * @param array $field Field parameters. |
|
442 | - * @param array $args Additional arguments. Rarely used. See specific fields for details. |
|
443 | - * @param int|null $post_id Post ID. null for current post. Optional. |
|
444 | - * |
|
445 | - * @return mixed Field value |
|
446 | - */ |
|
447 | - public static function get_value( $field, $args = array(), $post_id = null ) { |
|
448 | - // Some fields does not have ID like heading, custom HTML, etc. |
|
449 | - if ( empty( $field['id'] ) ) { |
|
450 | - return ''; |
|
451 | - } |
|
452 | - |
|
453 | - if ( ! $post_id ) { |
|
454 | - $post_id = get_the_ID(); |
|
455 | - } |
|
456 | - |
|
457 | - // Get raw meta value in the database, no escape. |
|
458 | - $value = self::call( $field, 'raw_meta', $post_id, $args ); |
|
459 | - |
|
460 | - // Make sure meta value is an array for cloneable and multiple fields. |
|
461 | - if ( $field['clone'] || $field['multiple'] ) { |
|
462 | - $value = is_array( $value ) && $value ? $value : array(); |
|
463 | - } |
|
464 | - |
|
465 | - return $value; |
|
466 | - } |
|
467 | - |
|
468 | - /** |
|
469 | - * Output the field value. |
|
470 | - * Depends on field value and field types, each field can extend this method to output its value in its own way |
|
471 | - * See specific field classes for details. |
|
472 | - * |
|
473 | - * Note: we don't echo the field value directly. We return the output HTML of field, which will be used in |
|
474 | - * rwmb_the_field function later. |
|
475 | - * |
|
476 | - * @use self::get_value() |
|
477 | - * @see rwmb_the_value() |
|
478 | - * |
|
479 | - * @param array $field Field parameters. |
|
480 | - * @param array $args Additional arguments. Rarely used. See specific fields for details. |
|
481 | - * @param int|null $post_id Post ID. null for current post. Optional. |
|
482 | - * |
|
483 | - * @return string HTML output of the field |
|
484 | - */ |
|
485 | - public static function the_value( $field, $args = array(), $post_id = null ) { |
|
486 | - $value = self::call( 'get_value', $field, $args, $post_id ); |
|
487 | - |
|
488 | - if ( false === $value ) { |
|
489 | - return ''; |
|
490 | - } |
|
491 | - |
|
492 | - return self::call( 'format_value', $field, $value, $args, $post_id ); |
|
493 | - } |
|
494 | - |
|
495 | - /** |
|
496 | - * Format value for the helper functions. |
|
497 | - * |
|
498 | - * @param array $field Field parameters. |
|
499 | - * @param string|array $value The field meta value. |
|
500 | - * @param array $args Additional arguments. Rarely used. See specific fields for details. |
|
501 | - * @param int|null $post_id Post ID. null for current post. Optional. |
|
502 | - * |
|
503 | - * @return string |
|
504 | - */ |
|
505 | - public static function format_value( $field, $value, $args, $post_id ) { |
|
506 | - if ( ! $field['clone'] ) { |
|
507 | - return self::call( 'format_clone_value', $field, $value, $args, $post_id ); |
|
508 | - } |
|
509 | - $output = '<ul>'; |
|
510 | - foreach ( $value as $clone ) { |
|
511 | - $output .= '<li>' . self::call( 'format_clone_value', $field, $clone, $args, $post_id ) . '</li>'; |
|
512 | - } |
|
513 | - $output .= '</ul>'; |
|
514 | - return $output; |
|
515 | - } |
|
516 | - |
|
517 | - /** |
|
518 | - * Format value for a clone. |
|
519 | - * |
|
520 | - * @param array $field Field parameters. |
|
521 | - * @param string|array $value The field meta value. |
|
522 | - * @param array $args Additional arguments. Rarely used. See specific fields for details. |
|
523 | - * @param int|null $post_id Post ID. null for current post. Optional. |
|
524 | - * |
|
525 | - * @return string |
|
526 | - */ |
|
527 | - public static function format_clone_value( $field, $value, $args, $post_id ) { |
|
528 | - if ( ! $field['multiple'] ) { |
|
529 | - return self::call( 'format_single_value', $field, $value, $args, $post_id ); |
|
530 | - } |
|
531 | - $output = '<ul>'; |
|
532 | - foreach ( $value as $single ) { |
|
533 | - $output .= '<li>' . self::call( 'format_single_value', $field, $single, $args, $post_id ) . '</li>'; |
|
534 | - } |
|
535 | - $output .= '</ul>'; |
|
536 | - return $output; |
|
537 | - } |
|
538 | - |
|
539 | - /** |
|
540 | - * Format a single value for the helper functions. Sub-fields should overwrite this method if necessary. |
|
541 | - * |
|
542 | - * @param array $field Field parameters. |
|
543 | - * @param string $value The value. |
|
544 | - * @param array $args Additional arguments. Rarely used. See specific fields for details. |
|
545 | - * @param int|null $post_id Post ID. null for current post. Optional. |
|
546 | - * |
|
547 | - * @return string |
|
548 | - */ |
|
549 | - public static function format_single_value( $field, $value, $args, $post_id ) { |
|
550 | - return $value; |
|
551 | - } |
|
552 | - |
|
553 | - /** |
|
554 | - * Call a method of a field. |
|
555 | - */ |
|
556 | - public static function call() { |
|
557 | - $args = func_get_args(); |
|
558 | - |
|
559 | - $check = reset( $args ); |
|
560 | - |
|
561 | - // Params: method name, field, other params. |
|
562 | - if ( is_string( $check ) ) { |
|
563 | - $method = array_shift( $args ); |
|
564 | - $field = reset( $args ); // Keep field as 1st param. |
|
565 | - } |
|
566 | - // Params: field, method name, other params. |
|
567 | - else { |
|
568 | - $field = array_shift( $args ); |
|
569 | - $method = array_shift( $args ); |
|
570 | - |
|
571 | - if ( 'raw_meta' === $method ) { |
|
572 | - // Add field param after object id. |
|
573 | - array_splice( $args, 1, 0, array( $field ) ); |
|
574 | - } else { |
|
575 | - $args[] = $field; // Add field as last param. |
|
576 | - } |
|
577 | - } |
|
578 | - |
|
579 | - $class = RWMB_Helpers_Field::get_class( $field ); |
|
580 | - if ( method_exists( $class, $method ) ) { |
|
581 | - return call_user_func_array( array( $class, $method ), $args ); |
|
582 | - } else { |
|
583 | - _deprecated_function( "$class::$method", '5.4.8' ); |
|
584 | - } |
|
585 | - } |
|
586 | - |
|
587 | - /** |
|
588 | - * Apply various filters based on field type, id. |
|
589 | - * Filters: |
|
590 | - * - rwmb_{$name} |
|
591 | - * - rwmb_{$field['type']}_{$name} |
|
592 | - * - rwmb_{$field['id']}_{$name} |
|
593 | - * |
|
594 | - * @return mixed |
|
595 | - */ |
|
596 | - public static function filter() { |
|
597 | - $args = func_get_args(); |
|
598 | - |
|
599 | - // 3 first params must be: filter name, value, field. Other params will be used for filters. |
|
600 | - $name = array_shift( $args ); |
|
601 | - $value = array_shift( $args ); |
|
602 | - $field = array_shift( $args ); |
|
603 | - |
|
604 | - // List of filters. |
|
605 | - $filters = array( |
|
606 | - 'rwmb_' . $name, |
|
607 | - 'rwmb_' . $field['type'] . '_' . $name, |
|
608 | - ); |
|
609 | - if ( $field['id'] ) { |
|
610 | - $field_id = $field['clone'] ? $field['_original_id'] : $field['id']; |
|
611 | - $filters[] = 'rwmb_' . $field_id . '_' . $name; |
|
612 | - } |
|
613 | - |
|
614 | - // Filter params: value, field, other params. Note: value is changed after each run. |
|
615 | - array_unshift( $args, $field ); |
|
616 | - foreach ( $filters as $filter ) { |
|
617 | - $filter_args = $args; |
|
618 | - array_unshift( $filter_args, $value ); |
|
619 | - $value = apply_filters_ref_array( $filter, $filter_args ); |
|
620 | - } |
|
621 | - |
|
622 | - return $value; |
|
623 | - } |
|
102 | + ( isset( $field['attributes']['id'] ) ) ? esc_attr( $field['attributes']['id'] ) : esc_attr( $field['id'] ), |
|
103 | + $field['name'], |
|
104 | + $field['required'] || ! empty( $field['attributes']['required'] ) ? '<span class="rwmb-required">*</span>' : '', |
|
105 | + self::label_description( $field ) |
|
106 | + ); |
|
107 | + } |
|
108 | + |
|
109 | + $data_min_clone = is_numeric( $field['min_clone'] ) && $field['min_clone'] > 1 ? ' data-min-clone=' . $field['min_clone'] : ''; |
|
110 | + $data_max_clone = is_numeric( $field['max_clone'] ) && $field['max_clone'] > 1 ? ' data-max-clone=' . $field['max_clone'] : ''; |
|
111 | + |
|
112 | + $input_open = sprintf( |
|
113 | + '<div class="rwmb-input" %s %s>', |
|
114 | + $data_min_clone, |
|
115 | + $data_max_clone |
|
116 | + ); |
|
117 | + |
|
118 | + return $field_label . $input_open; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Show end HTML markup for fields. |
|
123 | + * |
|
124 | + * @param mixed $meta Meta value. |
|
125 | + * @param array $field Field parameters. |
|
126 | + * |
|
127 | + * @return string |
|
128 | + */ |
|
129 | + public static function end_html( $meta, $field ) { |
|
130 | + return RWMB_Clone::add_clone_button( $field ) . self::call( 'input_description', $field ) . '</div>'; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Display field label description. |
|
135 | + * |
|
136 | + * @param array $field Field parameters. |
|
137 | + * @return string |
|
138 | + */ |
|
139 | + protected static function label_description( $field ) { |
|
140 | + $id = $field['id'] ? ' id="' . esc_attr( $field['id'] ) . '-label-description"' : ''; |
|
141 | + return $field['label_description'] ? "<p{$id} class='description'>{$field['label_description']}</p>" : ''; |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Display field description. |
|
146 | + * |
|
147 | + * @param array $field Field parameters. |
|
148 | + * @return string |
|
149 | + */ |
|
150 | + protected static function input_description( $field ) { |
|
151 | + $id = $field['id'] ? ' id="' . esc_attr( $field['id'] ) . '-description"' : ''; |
|
152 | + return $field['desc'] ? "<p{$id} class='description'>{$field['desc']}</p>" : ''; |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Get raw meta value. |
|
157 | + * |
|
158 | + * @param int $object_id Object ID. |
|
159 | + * @param array $field Field parameters. |
|
160 | + * @param array $args Arguments of {@see rwmb_meta()} helper. |
|
161 | + * |
|
162 | + * @return mixed |
|
163 | + */ |
|
164 | + public static function raw_meta( $object_id, $field, $args = array() ) { |
|
165 | + if ( empty( $field['id'] ) ) { |
|
166 | + return ''; |
|
167 | + } |
|
168 | + |
|
169 | + if ( isset( $field['storage'] ) ) { |
|
170 | + $storage = $field['storage']; |
|
171 | + } elseif ( isset( $args['object_type'] ) ) { |
|
172 | + $storage = rwmb_get_storage( $args['object_type'] ); |
|
173 | + } else { |
|
174 | + $storage = rwmb_get_storage( 'post' ); |
|
175 | + } |
|
176 | + |
|
177 | + if ( ! isset( $args['single'] ) ) { |
|
178 | + $args['single'] = $field['clone'] || ! $field['multiple']; |
|
179 | + } |
|
180 | + |
|
181 | + if ( $field['clone'] && $field['clone_as_multiple'] ) { |
|
182 | + $args['single'] = false; |
|
183 | + } |
|
184 | + |
|
185 | + $value = $storage->get( $object_id, $field['id'], $args ); |
|
186 | + $value = self::filter( 'raw_meta', $value, $field, $object_id, $args ); |
|
187 | + return $value; |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Get meta value. |
|
192 | + * |
|
193 | + * @param int $post_id Post ID. |
|
194 | + * @param bool $saved Whether the meta box is saved at least once. |
|
195 | + * @param array $field Field parameters. |
|
196 | + * |
|
197 | + * @return mixed |
|
198 | + */ |
|
199 | + public static function meta( $post_id, $saved, $field ) { |
|
200 | + /** |
|
201 | + * For special fields like 'divider', 'heading' which don't have ID, just return empty string |
|
202 | + * to prevent notice error when displaying fields. |
|
203 | + */ |
|
204 | + if ( empty( $field['id'] ) ) { |
|
205 | + return ''; |
|
206 | + } |
|
207 | + |
|
208 | + // Get raw meta. |
|
209 | + $meta = self::call( $field, 'raw_meta', $post_id ); |
|
210 | + |
|
211 | + // Use $field['std'] only when the meta box hasn't been saved (i.e. the first time we run). |
|
212 | + $meta = ! $saved || ! $field['save_field'] ? $field['std'] : $meta; |
|
213 | + |
|
214 | + if ( $field['clone'] ) { |
|
215 | + $meta = RWMB_Helpers_Array::ensure( $meta ); |
|
216 | + |
|
217 | + // Ensure $meta is an array with values so that the foreach loop in self::show() runs properly. |
|
218 | + if ( empty( $meta ) ) { |
|
219 | + $meta = array( '' ); |
|
220 | + } |
|
221 | + |
|
222 | + if ( $field['multiple'] ) { |
|
223 | + $first = reset( $meta ); |
|
224 | + |
|
225 | + // If users set std for a cloneable checkbox list field in the Builder, they can only set [value1, value2]. We need to transform it to [[value1, value2]]. |
|
226 | + // In other cases, make sure each value is an array. |
|
227 | + $meta = is_array( $first ) ? array_map( 'RWMB_Helpers_Array::ensure', $meta ) : array( $meta ); |
|
228 | + } |
|
229 | + } elseif ( $field['multiple'] ) { |
|
230 | + $meta = RWMB_Helpers_Array::ensure( $meta ); |
|
231 | + } |
|
232 | + |
|
233 | + return $meta; |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Process the submitted value before saving into the database. |
|
238 | + * |
|
239 | + * @param mixed $value The submitted value. |
|
240 | + * @param int $object_id The object ID. |
|
241 | + * @param array $field The field settings. |
|
242 | + */ |
|
243 | + public static function process_value( $value, $object_id, $field ) { |
|
244 | + $old_value = self::call( $field, 'raw_meta', $object_id ); |
|
245 | + |
|
246 | + // Allow field class change the value. |
|
247 | + if ( $field['clone'] ) { |
|
248 | + $value = RWMB_Clone::value( $value, $old_value, $object_id, $field ); |
|
249 | + } else { |
|
250 | + $value = self::call( $field, 'value', $value, $old_value, $object_id ); |
|
251 | + $value = self::filter( 'sanitize', $value, $field, $old_value, $object_id ); |
|
252 | + } |
|
253 | + $value = self::filter( 'value', $value, $field, $old_value, $object_id ); |
|
254 | + |
|
255 | + return $value; |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Set value of meta before saving into database. |
|
260 | + * |
|
261 | + * @param mixed $new The submitted meta value. |
|
262 | + * @param mixed $old The existing meta value. |
|
263 | + * @param int $post_id The post ID. |
|
264 | + * @param array $field The field parameters. |
|
265 | + * |
|
266 | + * @return mixed |
|
267 | + */ |
|
268 | + public static function value( $new, $old, $post_id, $field ) { |
|
269 | + return $new; |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Save meta value. |
|
274 | + * |
|
275 | + * @param mixed $new The submitted meta value. |
|
276 | + * @param mixed $old The existing meta value. |
|
277 | + * @param int $post_id The post ID. |
|
278 | + * @param array $field The field parameters. |
|
279 | + */ |
|
280 | + public static function save( $new, $old, $post_id, $field ) { |
|
281 | + if ( empty( $field['id'] ) || ! $field['save_field'] ) { |
|
282 | + return; |
|
283 | + } |
|
284 | + $name = $field['id']; |
|
285 | + $storage = $field['storage']; |
|
286 | + |
|
287 | + // Remove post meta if it's empty. |
|
288 | + if ( ! RWMB_Helpers_Value::is_valid_for_field( $new ) ) { |
|
289 | + $storage->delete( $post_id, $name ); |
|
290 | + return; |
|
291 | + } |
|
292 | + |
|
293 | + // If field is cloneable AND not force to save as multiple rows, value is saved as a single row in the database. |
|
294 | + if ( $field['clone'] && ! $field['clone_as_multiple'] ) { |
|
295 | + $storage->update( $post_id, $name, $new ); |
|
296 | + return; |
|
297 | + } |
|
298 | + |
|
299 | + // Save cloned fields as multiple values instead serialized array. |
|
300 | + if ( ( $field['clone'] && $field['clone_as_multiple'] ) || $field['multiple'] ) { |
|
301 | + $storage->delete( $post_id, $name ); |
|
302 | + $new = (array) $new; |
|
303 | + foreach ( $new as $new_value ) { |
|
304 | + $storage->add( $post_id, $name, $new_value, false ); |
|
305 | + } |
|
306 | + return; |
|
307 | + } |
|
308 | + |
|
309 | + // Default: just update post meta. |
|
310 | + $storage->update( $post_id, $name, $new ); |
|
311 | + } |
|
312 | + |
|
313 | + /** |
|
314 | + * Normalize parameters for field. |
|
315 | + * |
|
316 | + * @param array|string $field Field settings. |
|
317 | + * @return array |
|
318 | + */ |
|
319 | + public static function normalize( $field ) { |
|
320 | + // Quick define text fields with "name" attribute only. |
|
321 | + if ( is_string( $field ) ) { |
|
322 | + $field = array( |
|
323 | + 'name' => $field, |
|
324 | + 'id' => sanitize_key( $field ), |
|
325 | + ); |
|
326 | + } |
|
327 | + $field = wp_parse_args( |
|
328 | + $field, |
|
329 | + array( |
|
330 | + 'id' => '', |
|
331 | + 'name' => '', |
|
332 | + 'type' => 'text', |
|
333 | + 'label_description' => '', |
|
334 | + 'multiple' => false, |
|
335 | + 'std' => '', |
|
336 | + 'desc' => '', |
|
337 | + 'format' => '', |
|
338 | + 'before' => '', |
|
339 | + 'after' => '', |
|
340 | + 'field_name' => isset( $field['id'] ) ? $field['id'] : '', |
|
341 | + 'placeholder' => '', |
|
342 | + 'save_field' => true, |
|
343 | + |
|
344 | + 'clone' => false, |
|
345 | + 'min_clone' => 0, |
|
346 | + 'max_clone' => 0, |
|
347 | + 'sort_clone' => false, |
|
348 | + 'add_button' => __( '+ Add more', 'meta-box' ), |
|
349 | + 'clone_default' => false, |
|
350 | + 'clone_as_multiple' => false, |
|
351 | + |
|
352 | + 'class' => '', |
|
353 | + 'disabled' => false, |
|
354 | + 'required' => false, |
|
355 | + 'autofocus' => false, |
|
356 | + 'attributes' => array(), |
|
357 | + |
|
358 | + 'sanitize_callback' => null, |
|
359 | + ) |
|
360 | + ); |
|
361 | + |
|
362 | + // Store the original ID to run correct filters for the clonable field. |
|
363 | + if ( $field['clone'] ) { |
|
364 | + $field['_original_id'] = $field['id']; |
|
365 | + } |
|
366 | + |
|
367 | + if ( $field['clone_default'] ) { |
|
368 | + $field['attributes'] = wp_parse_args( |
|
369 | + $field['attributes'], |
|
370 | + array( |
|
371 | + 'data-default' => $field['std'], |
|
372 | + 'data-clone-default' => 'true', |
|
373 | + ) |
|
374 | + ); |
|
375 | + } |
|
376 | + |
|
377 | + if ( 1 === $field['max_clone'] ) { |
|
378 | + $field['clone'] = false; |
|
379 | + } |
|
380 | + |
|
381 | + return $field; |
|
382 | + } |
|
383 | + |
|
384 | + /** |
|
385 | + * Get the attributes for a field. |
|
386 | + * |
|
387 | + * @param array $field Field parameters. |
|
388 | + * @param mixed $value Meta value. |
|
389 | + * |
|
390 | + * @return array |
|
391 | + */ |
|
392 | + public static function get_attributes( $field, $value = null ) { |
|
393 | + $attributes = wp_parse_args( |
|
394 | + $field['attributes'], |
|
395 | + array( |
|
396 | + 'disabled' => $field['disabled'], |
|
397 | + 'autofocus' => $field['autofocus'], |
|
398 | + 'required' => $field['required'], |
|
399 | + 'id' => $field['id'], |
|
400 | + 'class' => '', |
|
401 | + 'name' => $field['field_name'], |
|
402 | + ) |
|
403 | + ); |
|
404 | + |
|
405 | + $attributes['class'] = trim( implode( ' ', array_merge( array( "rwmb-{$field['type']}" ), (array) $attributes['class'] ) ) ); |
|
406 | + |
|
407 | + return $attributes; |
|
408 | + } |
|
409 | + |
|
410 | + /** |
|
411 | + * Renders an attribute array into an html attributes string. |
|
412 | + * |
|
413 | + * @param array $attributes HTML attributes. |
|
414 | + * |
|
415 | + * @return string |
|
416 | + */ |
|
417 | + public static function render_attributes( $attributes ) { |
|
418 | + $output = ''; |
|
419 | + |
|
420 | + $attributes = array_filter( $attributes, 'RWMB_Helpers_Value::is_valid_for_attribute' ); |
|
421 | + foreach ( $attributes as $key => $value ) { |
|
422 | + if ( is_array( $value ) ) { |
|
423 | + $value = wp_json_encode( $value ); |
|
424 | + } |
|
425 | + |
|
426 | + $output .= sprintf( ' %s="%s"', $key, esc_attr( $value ) ); |
|
427 | + } |
|
428 | + |
|
429 | + return $output; |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Get the field value. |
|
434 | + * The difference between this function and 'meta' function is 'meta' function always returns the escaped value |
|
435 | + * of the field saved in the database, while this function returns more meaningful value of the field, for ex.: |
|
436 | + * for file/image: return array of file/image information instead of file/image IDs. |
|
437 | + * |
|
438 | + * Each field can extend this function and add more data to the returned value. |
|
439 | + * See specific field classes for details. |
|
440 | + * |
|
441 | + * @param array $field Field parameters. |
|
442 | + * @param array $args Additional arguments. Rarely used. See specific fields for details. |
|
443 | + * @param int|null $post_id Post ID. null for current post. Optional. |
|
444 | + * |
|
445 | + * @return mixed Field value |
|
446 | + */ |
|
447 | + public static function get_value( $field, $args = array(), $post_id = null ) { |
|
448 | + // Some fields does not have ID like heading, custom HTML, etc. |
|
449 | + if ( empty( $field['id'] ) ) { |
|
450 | + return ''; |
|
451 | + } |
|
452 | + |
|
453 | + if ( ! $post_id ) { |
|
454 | + $post_id = get_the_ID(); |
|
455 | + } |
|
456 | + |
|
457 | + // Get raw meta value in the database, no escape. |
|
458 | + $value = self::call( $field, 'raw_meta', $post_id, $args ); |
|
459 | + |
|
460 | + // Make sure meta value is an array for cloneable and multiple fields. |
|
461 | + if ( $field['clone'] || $field['multiple'] ) { |
|
462 | + $value = is_array( $value ) && $value ? $value : array(); |
|
463 | + } |
|
464 | + |
|
465 | + return $value; |
|
466 | + } |
|
467 | + |
|
468 | + /** |
|
469 | + * Output the field value. |
|
470 | + * Depends on field value and field types, each field can extend this method to output its value in its own way |
|
471 | + * See specific field classes for details. |
|
472 | + * |
|
473 | + * Note: we don't echo the field value directly. We return the output HTML of field, which will be used in |
|
474 | + * rwmb_the_field function later. |
|
475 | + * |
|
476 | + * @use self::get_value() |
|
477 | + * @see rwmb_the_value() |
|
478 | + * |
|
479 | + * @param array $field Field parameters. |
|
480 | + * @param array $args Additional arguments. Rarely used. See specific fields for details. |
|
481 | + * @param int|null $post_id Post ID. null for current post. Optional. |
|
482 | + * |
|
483 | + * @return string HTML output of the field |
|
484 | + */ |
|
485 | + public static function the_value( $field, $args = array(), $post_id = null ) { |
|
486 | + $value = self::call( 'get_value', $field, $args, $post_id ); |
|
487 | + |
|
488 | + if ( false === $value ) { |
|
489 | + return ''; |
|
490 | + } |
|
491 | + |
|
492 | + return self::call( 'format_value', $field, $value, $args, $post_id ); |
|
493 | + } |
|
494 | + |
|
495 | + /** |
|
496 | + * Format value for the helper functions. |
|
497 | + * |
|
498 | + * @param array $field Field parameters. |
|
499 | + * @param string|array $value The field meta value. |
|
500 | + * @param array $args Additional arguments. Rarely used. See specific fields for details. |
|
501 | + * @param int|null $post_id Post ID. null for current post. Optional. |
|
502 | + * |
|
503 | + * @return string |
|
504 | + */ |
|
505 | + public static function format_value( $field, $value, $args, $post_id ) { |
|
506 | + if ( ! $field['clone'] ) { |
|
507 | + return self::call( 'format_clone_value', $field, $value, $args, $post_id ); |
|
508 | + } |
|
509 | + $output = '<ul>'; |
|
510 | + foreach ( $value as $clone ) { |
|
511 | + $output .= '<li>' . self::call( 'format_clone_value', $field, $clone, $args, $post_id ) . '</li>'; |
|
512 | + } |
|
513 | + $output .= '</ul>'; |
|
514 | + return $output; |
|
515 | + } |
|
516 | + |
|
517 | + /** |
|
518 | + * Format value for a clone. |
|
519 | + * |
|
520 | + * @param array $field Field parameters. |
|
521 | + * @param string|array $value The field meta value. |
|
522 | + * @param array $args Additional arguments. Rarely used. See specific fields for details. |
|
523 | + * @param int|null $post_id Post ID. null for current post. Optional. |
|
524 | + * |
|
525 | + * @return string |
|
526 | + */ |
|
527 | + public static function format_clone_value( $field, $value, $args, $post_id ) { |
|
528 | + if ( ! $field['multiple'] ) { |
|
529 | + return self::call( 'format_single_value', $field, $value, $args, $post_id ); |
|
530 | + } |
|
531 | + $output = '<ul>'; |
|
532 | + foreach ( $value as $single ) { |
|
533 | + $output .= '<li>' . self::call( 'format_single_value', $field, $single, $args, $post_id ) . '</li>'; |
|
534 | + } |
|
535 | + $output .= '</ul>'; |
|
536 | + return $output; |
|
537 | + } |
|
538 | + |
|
539 | + /** |
|
540 | + * Format a single value for the helper functions. Sub-fields should overwrite this method if necessary. |
|
541 | + * |
|
542 | + * @param array $field Field parameters. |
|
543 | + * @param string $value The value. |
|
544 | + * @param array $args Additional arguments. Rarely used. See specific fields for details. |
|
545 | + * @param int|null $post_id Post ID. null for current post. Optional. |
|
546 | + * |
|
547 | + * @return string |
|
548 | + */ |
|
549 | + public static function format_single_value( $field, $value, $args, $post_id ) { |
|
550 | + return $value; |
|
551 | + } |
|
552 | + |
|
553 | + /** |
|
554 | + * Call a method of a field. |
|
555 | + */ |
|
556 | + public static function call() { |
|
557 | + $args = func_get_args(); |
|
558 | + |
|
559 | + $check = reset( $args ); |
|
560 | + |
|
561 | + // Params: method name, field, other params. |
|
562 | + if ( is_string( $check ) ) { |
|
563 | + $method = array_shift( $args ); |
|
564 | + $field = reset( $args ); // Keep field as 1st param. |
|
565 | + } |
|
566 | + // Params: field, method name, other params. |
|
567 | + else { |
|
568 | + $field = array_shift( $args ); |
|
569 | + $method = array_shift( $args ); |
|
570 | + |
|
571 | + if ( 'raw_meta' === $method ) { |
|
572 | + // Add field param after object id. |
|
573 | + array_splice( $args, 1, 0, array( $field ) ); |
|
574 | + } else { |
|
575 | + $args[] = $field; // Add field as last param. |
|
576 | + } |
|
577 | + } |
|
578 | + |
|
579 | + $class = RWMB_Helpers_Field::get_class( $field ); |
|
580 | + if ( method_exists( $class, $method ) ) { |
|
581 | + return call_user_func_array( array( $class, $method ), $args ); |
|
582 | + } else { |
|
583 | + _deprecated_function( "$class::$method", '5.4.8' ); |
|
584 | + } |
|
585 | + } |
|
586 | + |
|
587 | + /** |
|
588 | + * Apply various filters based on field type, id. |
|
589 | + * Filters: |
|
590 | + * - rwmb_{$name} |
|
591 | + * - rwmb_{$field['type']}_{$name} |
|
592 | + * - rwmb_{$field['id']}_{$name} |
|
593 | + * |
|
594 | + * @return mixed |
|
595 | + */ |
|
596 | + public static function filter() { |
|
597 | + $args = func_get_args(); |
|
598 | + |
|
599 | + // 3 first params must be: filter name, value, field. Other params will be used for filters. |
|
600 | + $name = array_shift( $args ); |
|
601 | + $value = array_shift( $args ); |
|
602 | + $field = array_shift( $args ); |
|
603 | + |
|
604 | + // List of filters. |
|
605 | + $filters = array( |
|
606 | + 'rwmb_' . $name, |
|
607 | + 'rwmb_' . $field['type'] . '_' . $name, |
|
608 | + ); |
|
609 | + if ( $field['id'] ) { |
|
610 | + $field_id = $field['clone'] ? $field['_original_id'] : $field['id']; |
|
611 | + $filters[] = 'rwmb_' . $field_id . '_' . $name; |
|
612 | + } |
|
613 | + |
|
614 | + // Filter params: value, field, other params. Note: value is changed after each run. |
|
615 | + array_unshift( $args, $field ); |
|
616 | + foreach ( $filters as $filter ) { |
|
617 | + $filter_args = $args; |
|
618 | + array_unshift( $filter_args, $value ); |
|
619 | + $value = apply_filters_ref_array( $filter, $filter_args ); |
|
620 | + } |
|
621 | + |
|
622 | + return $value; |
|
623 | + } |
|
624 | 624 | } |
@@ -33,39 +33,39 @@ discard block |
||
33 | 33 | * @param bool $saved Whether the meta box is saved at least once. |
34 | 34 | * @param int $post_id Post ID. |
35 | 35 | */ |
36 | - public static function show( $field, $saved, $post_id = 0 ) { |
|
37 | - $meta = self::call( $field, 'meta', $post_id, $saved ); |
|
38 | - $meta = self::filter( 'field_meta', $meta, $field, $saved ); |
|
36 | + public static function show($field, $saved, $post_id = 0) { |
|
37 | + $meta = self::call($field, 'meta', $post_id, $saved); |
|
38 | + $meta = self::filter('field_meta', $meta, $field, $saved); |
|
39 | 39 | |
40 | - $begin = self::call( $field, 'begin_html', $meta ); |
|
41 | - $begin = self::filter( 'begin_html', $begin, $field, $meta ); |
|
40 | + $begin = self::call($field, 'begin_html', $meta); |
|
41 | + $begin = self::filter('begin_html', $begin, $field, $meta); |
|
42 | 42 | |
43 | 43 | // Separate code for cloneable and non-cloneable fields to make easy to maintain. |
44 | - if ( $field['clone'] ) { |
|
45 | - $field_html = RWMB_Clone::html( $meta, $field ); |
|
44 | + if ($field['clone']) { |
|
45 | + $field_html = RWMB_Clone::html($meta, $field); |
|
46 | 46 | } else { |
47 | 47 | // Call separated methods for displaying each type of field. |
48 | - $field_html = self::call( $field, 'html', $meta ); |
|
49 | - $field_html = self::filter( 'html', $field_html, $field, $meta ); |
|
48 | + $field_html = self::call($field, 'html', $meta); |
|
49 | + $field_html = self::filter('html', $field_html, $field, $meta); |
|
50 | 50 | } |
51 | 51 | |
52 | - $end = self::call( $field, 'end_html', $meta ); |
|
53 | - $end = self::filter( 'end_html', $end, $field, $meta ); |
|
52 | + $end = self::call($field, 'end_html', $meta); |
|
53 | + $end = self::filter('end_html', $end, $field, $meta); |
|
54 | 54 | |
55 | - $html = self::filter( 'wrapper_html', "$begin$field_html$end", $field, $meta ); |
|
55 | + $html = self::filter('wrapper_html', "$begin$field_html$end", $field, $meta); |
|
56 | 56 | |
57 | 57 | // Display label and input in DIV and allow user-defined classes to be appended. |
58 | 58 | $classes = "rwmb-field rwmb-{$field['type']}-wrapper " . $field['class']; |
59 | - if ( ! empty( $field['required'] ) ) { |
|
59 | + if (!empty($field['required'])) { |
|
60 | 60 | $classes .= ' required'; |
61 | 61 | } |
62 | 62 | |
63 | 63 | $outer_html = sprintf( |
64 | 64 | $field['before'] . '<div class="%s">%s</div>' . $field['after'], |
65 | - esc_attr( trim( $classes ) ), |
|
65 | + esc_attr(trim($classes)), |
|
66 | 66 | $html |
67 | 67 | ); |
68 | - $outer_html = self::filter( 'outer_html', $outer_html, $field, $meta ); |
|
68 | + $outer_html = self::filter('outer_html', $outer_html, $field, $meta); |
|
69 | 69 | |
70 | 70 | echo $outer_html; // WPCS: XSS OK. |
71 | 71 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @return string |
80 | 80 | */ |
81 | - public static function html( $meta, $field ) { |
|
81 | + public static function html($meta, $field) { |
|
82 | 82 | return ''; |
83 | 83 | } |
84 | 84 | |
@@ -90,24 +90,24 @@ discard block |
||
90 | 90 | * |
91 | 91 | * @return string |
92 | 92 | */ |
93 | - public static function begin_html( $meta, $field ) { |
|
93 | + public static function begin_html($meta, $field) { |
|
94 | 94 | $field_label = ''; |
95 | - if ( $field['name'] ) { |
|
95 | + if ($field['name']) { |
|
96 | 96 | // Change "for" attribute in label |
97 | 97 | $field_label = sprintf( |
98 | 98 | '<div class="rwmb-label"> |
99 | 99 | <label for="%s">%s%s</label> |
100 | 100 | %s |
101 | 101 | </div>', |
102 | - ( isset( $field['attributes']['id'] ) ) ? esc_attr( $field['attributes']['id'] ) : esc_attr( $field['id'] ), |
|
102 | + (isset($field['attributes']['id'])) ? esc_attr($field['attributes']['id']) : esc_attr($field['id']), |
|
103 | 103 | $field['name'], |
104 | - $field['required'] || ! empty( $field['attributes']['required'] ) ? '<span class="rwmb-required">*</span>' : '', |
|
105 | - self::label_description( $field ) |
|
104 | + $field['required'] || !empty($field['attributes']['required']) ? '<span class="rwmb-required">*</span>' : '', |
|
105 | + self::label_description($field) |
|
106 | 106 | ); |
107 | 107 | } |
108 | 108 | |
109 | - $data_min_clone = is_numeric( $field['min_clone'] ) && $field['min_clone'] > 1 ? ' data-min-clone=' . $field['min_clone'] : ''; |
|
110 | - $data_max_clone = is_numeric( $field['max_clone'] ) && $field['max_clone'] > 1 ? ' data-max-clone=' . $field['max_clone'] : ''; |
|
109 | + $data_min_clone = is_numeric($field['min_clone']) && $field['min_clone'] > 1 ? ' data-min-clone=' . $field['min_clone'] : ''; |
|
110 | + $data_max_clone = is_numeric($field['max_clone']) && $field['max_clone'] > 1 ? ' data-max-clone=' . $field['max_clone'] : ''; |
|
111 | 111 | |
112 | 112 | $input_open = sprintf( |
113 | 113 | '<div class="rwmb-input" %s %s>', |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | * |
127 | 127 | * @return string |
128 | 128 | */ |
129 | - public static function end_html( $meta, $field ) { |
|
130 | - return RWMB_Clone::add_clone_button( $field ) . self::call( 'input_description', $field ) . '</div>'; |
|
129 | + public static function end_html($meta, $field) { |
|
130 | + return RWMB_Clone::add_clone_button($field) . self::call('input_description', $field) . '</div>'; |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | * @param array $field Field parameters. |
137 | 137 | * @return string |
138 | 138 | */ |
139 | - protected static function label_description( $field ) { |
|
140 | - $id = $field['id'] ? ' id="' . esc_attr( $field['id'] ) . '-label-description"' : ''; |
|
139 | + protected static function label_description($field) { |
|
140 | + $id = $field['id'] ? ' id="' . esc_attr($field['id']) . '-label-description"' : ''; |
|
141 | 141 | return $field['label_description'] ? "<p{$id} class='description'>{$field['label_description']}</p>" : ''; |
142 | 142 | } |
143 | 143 | |
@@ -147,8 +147,8 @@ discard block |
||
147 | 147 | * @param array $field Field parameters. |
148 | 148 | * @return string |
149 | 149 | */ |
150 | - protected static function input_description( $field ) { |
|
151 | - $id = $field['id'] ? ' id="' . esc_attr( $field['id'] ) . '-description"' : ''; |
|
150 | + protected static function input_description($field) { |
|
151 | + $id = $field['id'] ? ' id="' . esc_attr($field['id']) . '-description"' : ''; |
|
152 | 152 | return $field['desc'] ? "<p{$id} class='description'>{$field['desc']}</p>" : ''; |
153 | 153 | } |
154 | 154 | |
@@ -161,29 +161,29 @@ discard block |
||
161 | 161 | * |
162 | 162 | * @return mixed |
163 | 163 | */ |
164 | - public static function raw_meta( $object_id, $field, $args = array() ) { |
|
165 | - if ( empty( $field['id'] ) ) { |
|
164 | + public static function raw_meta($object_id, $field, $args = array()) { |
|
165 | + if (empty($field['id'])) { |
|
166 | 166 | return ''; |
167 | 167 | } |
168 | 168 | |
169 | - if ( isset( $field['storage'] ) ) { |
|
169 | + if (isset($field['storage'])) { |
|
170 | 170 | $storage = $field['storage']; |
171 | - } elseif ( isset( $args['object_type'] ) ) { |
|
172 | - $storage = rwmb_get_storage( $args['object_type'] ); |
|
171 | + } elseif (isset($args['object_type'])) { |
|
172 | + $storage = rwmb_get_storage($args['object_type']); |
|
173 | 173 | } else { |
174 | - $storage = rwmb_get_storage( 'post' ); |
|
174 | + $storage = rwmb_get_storage('post'); |
|
175 | 175 | } |
176 | 176 | |
177 | - if ( ! isset( $args['single'] ) ) { |
|
178 | - $args['single'] = $field['clone'] || ! $field['multiple']; |
|
177 | + if (!isset($args['single'])) { |
|
178 | + $args['single'] = $field['clone'] || !$field['multiple']; |
|
179 | 179 | } |
180 | 180 | |
181 | - if ( $field['clone'] && $field['clone_as_multiple'] ) { |
|
181 | + if ($field['clone'] && $field['clone_as_multiple']) { |
|
182 | 182 | $args['single'] = false; |
183 | 183 | } |
184 | 184 | |
185 | - $value = $storage->get( $object_id, $field['id'], $args ); |
|
186 | - $value = self::filter( 'raw_meta', $value, $field, $object_id, $args ); |
|
185 | + $value = $storage->get($object_id, $field['id'], $args); |
|
186 | + $value = self::filter('raw_meta', $value, $field, $object_id, $args); |
|
187 | 187 | return $value; |
188 | 188 | } |
189 | 189 | |
@@ -196,38 +196,38 @@ discard block |
||
196 | 196 | * |
197 | 197 | * @return mixed |
198 | 198 | */ |
199 | - public static function meta( $post_id, $saved, $field ) { |
|
199 | + public static function meta($post_id, $saved, $field) { |
|
200 | 200 | /** |
201 | 201 | * For special fields like 'divider', 'heading' which don't have ID, just return empty string |
202 | 202 | * to prevent notice error when displaying fields. |
203 | 203 | */ |
204 | - if ( empty( $field['id'] ) ) { |
|
204 | + if (empty($field['id'])) { |
|
205 | 205 | return ''; |
206 | 206 | } |
207 | 207 | |
208 | 208 | // Get raw meta. |
209 | - $meta = self::call( $field, 'raw_meta', $post_id ); |
|
209 | + $meta = self::call($field, 'raw_meta', $post_id); |
|
210 | 210 | |
211 | 211 | // Use $field['std'] only when the meta box hasn't been saved (i.e. the first time we run). |
212 | - $meta = ! $saved || ! $field['save_field'] ? $field['std'] : $meta; |
|
212 | + $meta = !$saved || !$field['save_field'] ? $field['std'] : $meta; |
|
213 | 213 | |
214 | - if ( $field['clone'] ) { |
|
215 | - $meta = RWMB_Helpers_Array::ensure( $meta ); |
|
214 | + if ($field['clone']) { |
|
215 | + $meta = RWMB_Helpers_Array::ensure($meta); |
|
216 | 216 | |
217 | 217 | // Ensure $meta is an array with values so that the foreach loop in self::show() runs properly. |
218 | - if ( empty( $meta ) ) { |
|
219 | - $meta = array( '' ); |
|
218 | + if (empty($meta)) { |
|
219 | + $meta = array(''); |
|
220 | 220 | } |
221 | 221 | |
222 | - if ( $field['multiple'] ) { |
|
223 | - $first = reset( $meta ); |
|
222 | + if ($field['multiple']) { |
|
223 | + $first = reset($meta); |
|
224 | 224 | |
225 | 225 | // If users set std for a cloneable checkbox list field in the Builder, they can only set [value1, value2]. We need to transform it to [[value1, value2]]. |
226 | 226 | // In other cases, make sure each value is an array. |
227 | - $meta = is_array( $first ) ? array_map( 'RWMB_Helpers_Array::ensure', $meta ) : array( $meta ); |
|
227 | + $meta = is_array($first) ? array_map('RWMB_Helpers_Array::ensure', $meta) : array($meta); |
|
228 | 228 | } |
229 | - } elseif ( $field['multiple'] ) { |
|
230 | - $meta = RWMB_Helpers_Array::ensure( $meta ); |
|
229 | + } elseif ($field['multiple']) { |
|
230 | + $meta = RWMB_Helpers_Array::ensure($meta); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | return $meta; |
@@ -240,17 +240,17 @@ discard block |
||
240 | 240 | * @param int $object_id The object ID. |
241 | 241 | * @param array $field The field settings. |
242 | 242 | */ |
243 | - public static function process_value( $value, $object_id, $field ) { |
|
244 | - $old_value = self::call( $field, 'raw_meta', $object_id ); |
|
243 | + public static function process_value($value, $object_id, $field) { |
|
244 | + $old_value = self::call($field, 'raw_meta', $object_id); |
|
245 | 245 | |
246 | 246 | // Allow field class change the value. |
247 | - if ( $field['clone'] ) { |
|
248 | - $value = RWMB_Clone::value( $value, $old_value, $object_id, $field ); |
|
247 | + if ($field['clone']) { |
|
248 | + $value = RWMB_Clone::value($value, $old_value, $object_id, $field); |
|
249 | 249 | } else { |
250 | - $value = self::call( $field, 'value', $value, $old_value, $object_id ); |
|
251 | - $value = self::filter( 'sanitize', $value, $field, $old_value, $object_id ); |
|
250 | + $value = self::call($field, 'value', $value, $old_value, $object_id); |
|
251 | + $value = self::filter('sanitize', $value, $field, $old_value, $object_id); |
|
252 | 252 | } |
253 | - $value = self::filter( 'value', $value, $field, $old_value, $object_id ); |
|
253 | + $value = self::filter('value', $value, $field, $old_value, $object_id); |
|
254 | 254 | |
255 | 255 | return $value; |
256 | 256 | } |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | * |
266 | 266 | * @return mixed |
267 | 267 | */ |
268 | - public static function value( $new, $old, $post_id, $field ) { |
|
268 | + public static function value($new, $old, $post_id, $field) { |
|
269 | 269 | return $new; |
270 | 270 | } |
271 | 271 | |
@@ -277,37 +277,37 @@ discard block |
||
277 | 277 | * @param int $post_id The post ID. |
278 | 278 | * @param array $field The field parameters. |
279 | 279 | */ |
280 | - public static function save( $new, $old, $post_id, $field ) { |
|
281 | - if ( empty( $field['id'] ) || ! $field['save_field'] ) { |
|
280 | + public static function save($new, $old, $post_id, $field) { |
|
281 | + if (empty($field['id']) || !$field['save_field']) { |
|
282 | 282 | return; |
283 | 283 | } |
284 | 284 | $name = $field['id']; |
285 | 285 | $storage = $field['storage']; |
286 | 286 | |
287 | 287 | // Remove post meta if it's empty. |
288 | - if ( ! RWMB_Helpers_Value::is_valid_for_field( $new ) ) { |
|
289 | - $storage->delete( $post_id, $name ); |
|
288 | + if (!RWMB_Helpers_Value::is_valid_for_field($new)) { |
|
289 | + $storage->delete($post_id, $name); |
|
290 | 290 | return; |
291 | 291 | } |
292 | 292 | |
293 | 293 | // If field is cloneable AND not force to save as multiple rows, value is saved as a single row in the database. |
294 | - if ( $field['clone'] && ! $field['clone_as_multiple'] ) { |
|
295 | - $storage->update( $post_id, $name, $new ); |
|
294 | + if ($field['clone'] && !$field['clone_as_multiple']) { |
|
295 | + $storage->update($post_id, $name, $new); |
|
296 | 296 | return; |
297 | 297 | } |
298 | 298 | |
299 | 299 | // Save cloned fields as multiple values instead serialized array. |
300 | - if ( ( $field['clone'] && $field['clone_as_multiple'] ) || $field['multiple'] ) { |
|
301 | - $storage->delete( $post_id, $name ); |
|
300 | + if (($field['clone'] && $field['clone_as_multiple']) || $field['multiple']) { |
|
301 | + $storage->delete($post_id, $name); |
|
302 | 302 | $new = (array) $new; |
303 | - foreach ( $new as $new_value ) { |
|
304 | - $storage->add( $post_id, $name, $new_value, false ); |
|
303 | + foreach ($new as $new_value) { |
|
304 | + $storage->add($post_id, $name, $new_value, false); |
|
305 | 305 | } |
306 | 306 | return; |
307 | 307 | } |
308 | 308 | |
309 | 309 | // Default: just update post meta. |
310 | - $storage->update( $post_id, $name, $new ); |
|
310 | + $storage->update($post_id, $name, $new); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | /** |
@@ -316,12 +316,12 @@ discard block |
||
316 | 316 | * @param array|string $field Field settings. |
317 | 317 | * @return array |
318 | 318 | */ |
319 | - public static function normalize( $field ) { |
|
319 | + public static function normalize($field) { |
|
320 | 320 | // Quick define text fields with "name" attribute only. |
321 | - if ( is_string( $field ) ) { |
|
321 | + if (is_string($field)) { |
|
322 | 322 | $field = array( |
323 | 323 | 'name' => $field, |
324 | - 'id' => sanitize_key( $field ), |
|
324 | + 'id' => sanitize_key($field), |
|
325 | 325 | ); |
326 | 326 | } |
327 | 327 | $field = wp_parse_args( |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | 'format' => '', |
338 | 338 | 'before' => '', |
339 | 339 | 'after' => '', |
340 | - 'field_name' => isset( $field['id'] ) ? $field['id'] : '', |
|
340 | + 'field_name' => isset($field['id']) ? $field['id'] : '', |
|
341 | 341 | 'placeholder' => '', |
342 | 342 | 'save_field' => true, |
343 | 343 | |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | 'min_clone' => 0, |
346 | 346 | 'max_clone' => 0, |
347 | 347 | 'sort_clone' => false, |
348 | - 'add_button' => __( '+ Add more', 'meta-box' ), |
|
348 | + 'add_button' => __('+ Add more', 'meta-box'), |
|
349 | 349 | 'clone_default' => false, |
350 | 350 | 'clone_as_multiple' => false, |
351 | 351 | |
@@ -360,11 +360,11 @@ discard block |
||
360 | 360 | ); |
361 | 361 | |
362 | 362 | // Store the original ID to run correct filters for the clonable field. |
363 | - if ( $field['clone'] ) { |
|
363 | + if ($field['clone']) { |
|
364 | 364 | $field['_original_id'] = $field['id']; |
365 | 365 | } |
366 | 366 | |
367 | - if ( $field['clone_default'] ) { |
|
367 | + if ($field['clone_default']) { |
|
368 | 368 | $field['attributes'] = wp_parse_args( |
369 | 369 | $field['attributes'], |
370 | 370 | array( |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | ); |
375 | 375 | } |
376 | 376 | |
377 | - if ( 1 === $field['max_clone'] ) { |
|
377 | + if (1 === $field['max_clone']) { |
|
378 | 378 | $field['clone'] = false; |
379 | 379 | } |
380 | 380 | |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | * |
390 | 390 | * @return array |
391 | 391 | */ |
392 | - public static function get_attributes( $field, $value = null ) { |
|
392 | + public static function get_attributes($field, $value = null) { |
|
393 | 393 | $attributes = wp_parse_args( |
394 | 394 | $field['attributes'], |
395 | 395 | array( |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | ) |
403 | 403 | ); |
404 | 404 | |
405 | - $attributes['class'] = trim( implode( ' ', array_merge( array( "rwmb-{$field['type']}" ), (array) $attributes['class'] ) ) ); |
|
405 | + $attributes['class'] = trim(implode(' ', array_merge(array("rwmb-{$field['type']}"), (array) $attributes['class']))); |
|
406 | 406 | |
407 | 407 | return $attributes; |
408 | 408 | } |
@@ -414,16 +414,16 @@ discard block |
||
414 | 414 | * |
415 | 415 | * @return string |
416 | 416 | */ |
417 | - public static function render_attributes( $attributes ) { |
|
417 | + public static function render_attributes($attributes) { |
|
418 | 418 | $output = ''; |
419 | 419 | |
420 | - $attributes = array_filter( $attributes, 'RWMB_Helpers_Value::is_valid_for_attribute' ); |
|
421 | - foreach ( $attributes as $key => $value ) { |
|
422 | - if ( is_array( $value ) ) { |
|
423 | - $value = wp_json_encode( $value ); |
|
420 | + $attributes = array_filter($attributes, 'RWMB_Helpers_Value::is_valid_for_attribute'); |
|
421 | + foreach ($attributes as $key => $value) { |
|
422 | + if (is_array($value)) { |
|
423 | + $value = wp_json_encode($value); |
|
424 | 424 | } |
425 | 425 | |
426 | - $output .= sprintf( ' %s="%s"', $key, esc_attr( $value ) ); |
|
426 | + $output .= sprintf(' %s="%s"', $key, esc_attr($value)); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | return $output; |
@@ -444,22 +444,22 @@ discard block |
||
444 | 444 | * |
445 | 445 | * @return mixed Field value |
446 | 446 | */ |
447 | - public static function get_value( $field, $args = array(), $post_id = null ) { |
|
447 | + public static function get_value($field, $args = array(), $post_id = null) { |
|
448 | 448 | // Some fields does not have ID like heading, custom HTML, etc. |
449 | - if ( empty( $field['id'] ) ) { |
|
449 | + if (empty($field['id'])) { |
|
450 | 450 | return ''; |
451 | 451 | } |
452 | 452 | |
453 | - if ( ! $post_id ) { |
|
453 | + if (!$post_id) { |
|
454 | 454 | $post_id = get_the_ID(); |
455 | 455 | } |
456 | 456 | |
457 | 457 | // Get raw meta value in the database, no escape. |
458 | - $value = self::call( $field, 'raw_meta', $post_id, $args ); |
|
458 | + $value = self::call($field, 'raw_meta', $post_id, $args); |
|
459 | 459 | |
460 | 460 | // Make sure meta value is an array for cloneable and multiple fields. |
461 | - if ( $field['clone'] || $field['multiple'] ) { |
|
462 | - $value = is_array( $value ) && $value ? $value : array(); |
|
461 | + if ($field['clone'] || $field['multiple']) { |
|
462 | + $value = is_array($value) && $value ? $value : array(); |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | return $value; |
@@ -482,14 +482,14 @@ discard block |
||
482 | 482 | * |
483 | 483 | * @return string HTML output of the field |
484 | 484 | */ |
485 | - public static function the_value( $field, $args = array(), $post_id = null ) { |
|
486 | - $value = self::call( 'get_value', $field, $args, $post_id ); |
|
485 | + public static function the_value($field, $args = array(), $post_id = null) { |
|
486 | + $value = self::call('get_value', $field, $args, $post_id); |
|
487 | 487 | |
488 | - if ( false === $value ) { |
|
488 | + if (false === $value) { |
|
489 | 489 | return ''; |
490 | 490 | } |
491 | 491 | |
492 | - return self::call( 'format_value', $field, $value, $args, $post_id ); |
|
492 | + return self::call('format_value', $field, $value, $args, $post_id); |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | /** |
@@ -502,13 +502,13 @@ discard block |
||
502 | 502 | * |
503 | 503 | * @return string |
504 | 504 | */ |
505 | - public static function format_value( $field, $value, $args, $post_id ) { |
|
506 | - if ( ! $field['clone'] ) { |
|
507 | - return self::call( 'format_clone_value', $field, $value, $args, $post_id ); |
|
505 | + public static function format_value($field, $value, $args, $post_id) { |
|
506 | + if (!$field['clone']) { |
|
507 | + return self::call('format_clone_value', $field, $value, $args, $post_id); |
|
508 | 508 | } |
509 | 509 | $output = '<ul>'; |
510 | - foreach ( $value as $clone ) { |
|
511 | - $output .= '<li>' . self::call( 'format_clone_value', $field, $clone, $args, $post_id ) . '</li>'; |
|
510 | + foreach ($value as $clone) { |
|
511 | + $output .= '<li>' . self::call('format_clone_value', $field, $clone, $args, $post_id) . '</li>'; |
|
512 | 512 | } |
513 | 513 | $output .= '</ul>'; |
514 | 514 | return $output; |
@@ -524,13 +524,13 @@ discard block |
||
524 | 524 | * |
525 | 525 | * @return string |
526 | 526 | */ |
527 | - public static function format_clone_value( $field, $value, $args, $post_id ) { |
|
528 | - if ( ! $field['multiple'] ) { |
|
529 | - return self::call( 'format_single_value', $field, $value, $args, $post_id ); |
|
527 | + public static function format_clone_value($field, $value, $args, $post_id) { |
|
528 | + if (!$field['multiple']) { |
|
529 | + return self::call('format_single_value', $field, $value, $args, $post_id); |
|
530 | 530 | } |
531 | 531 | $output = '<ul>'; |
532 | - foreach ( $value as $single ) { |
|
533 | - $output .= '<li>' . self::call( 'format_single_value', $field, $single, $args, $post_id ) . '</li>'; |
|
532 | + foreach ($value as $single) { |
|
533 | + $output .= '<li>' . self::call('format_single_value', $field, $single, $args, $post_id) . '</li>'; |
|
534 | 534 | } |
535 | 535 | $output .= '</ul>'; |
536 | 536 | return $output; |
@@ -546,7 +546,7 @@ discard block |
||
546 | 546 | * |
547 | 547 | * @return string |
548 | 548 | */ |
549 | - public static function format_single_value( $field, $value, $args, $post_id ) { |
|
549 | + public static function format_single_value($field, $value, $args, $post_id) { |
|
550 | 550 | return $value; |
551 | 551 | } |
552 | 552 | |
@@ -556,31 +556,31 @@ discard block |
||
556 | 556 | public static function call() { |
557 | 557 | $args = func_get_args(); |
558 | 558 | |
559 | - $check = reset( $args ); |
|
559 | + $check = reset($args); |
|
560 | 560 | |
561 | 561 | // Params: method name, field, other params. |
562 | - if ( is_string( $check ) ) { |
|
563 | - $method = array_shift( $args ); |
|
564 | - $field = reset( $args ); // Keep field as 1st param. |
|
562 | + if (is_string($check)) { |
|
563 | + $method = array_shift($args); |
|
564 | + $field = reset($args); // Keep field as 1st param. |
|
565 | 565 | } |
566 | 566 | // Params: field, method name, other params. |
567 | 567 | else { |
568 | - $field = array_shift( $args ); |
|
569 | - $method = array_shift( $args ); |
|
568 | + $field = array_shift($args); |
|
569 | + $method = array_shift($args); |
|
570 | 570 | |
571 | - if ( 'raw_meta' === $method ) { |
|
571 | + if ('raw_meta' === $method) { |
|
572 | 572 | // Add field param after object id. |
573 | - array_splice( $args, 1, 0, array( $field ) ); |
|
573 | + array_splice($args, 1, 0, array($field)); |
|
574 | 574 | } else { |
575 | 575 | $args[] = $field; // Add field as last param. |
576 | 576 | } |
577 | 577 | } |
578 | 578 | |
579 | - $class = RWMB_Helpers_Field::get_class( $field ); |
|
580 | - if ( method_exists( $class, $method ) ) { |
|
581 | - return call_user_func_array( array( $class, $method ), $args ); |
|
579 | + $class = RWMB_Helpers_Field::get_class($field); |
|
580 | + if (method_exists($class, $method)) { |
|
581 | + return call_user_func_array(array($class, $method), $args); |
|
582 | 582 | } else { |
583 | - _deprecated_function( "$class::$method", '5.4.8' ); |
|
583 | + _deprecated_function("$class::$method", '5.4.8'); |
|
584 | 584 | } |
585 | 585 | } |
586 | 586 | |
@@ -597,26 +597,26 @@ discard block |
||
597 | 597 | $args = func_get_args(); |
598 | 598 | |
599 | 599 | // 3 first params must be: filter name, value, field. Other params will be used for filters. |
600 | - $name = array_shift( $args ); |
|
601 | - $value = array_shift( $args ); |
|
602 | - $field = array_shift( $args ); |
|
600 | + $name = array_shift($args); |
|
601 | + $value = array_shift($args); |
|
602 | + $field = array_shift($args); |
|
603 | 603 | |
604 | 604 | // List of filters. |
605 | 605 | $filters = array( |
606 | 606 | 'rwmb_' . $name, |
607 | 607 | 'rwmb_' . $field['type'] . '_' . $name, |
608 | 608 | ); |
609 | - if ( $field['id'] ) { |
|
609 | + if ($field['id']) { |
|
610 | 610 | $field_id = $field['clone'] ? $field['_original_id'] : $field['id']; |
611 | 611 | $filters[] = 'rwmb_' . $field_id . '_' . $name; |
612 | 612 | } |
613 | 613 | |
614 | 614 | // Filter params: value, field, other params. Note: value is changed after each run. |
615 | - array_unshift( $args, $field ); |
|
616 | - foreach ( $filters as $filter ) { |
|
615 | + array_unshift($args, $field); |
|
616 | + foreach ($filters as $filter) { |
|
617 | 617 | $filter_args = $args; |
618 | - array_unshift( $filter_args, $value ); |
|
619 | - $value = apply_filters_ref_array( $filter, $filter_args ); |
|
618 | + array_unshift($filter_args, $value); |
|
619 | + $value = apply_filters_ref_array($filter, $filter_args); |
|
620 | 620 | } |
621 | 621 | |
622 | 622 | return $value; |
@@ -11,105 +11,105 @@ |
||
11 | 11 | * @package Meta Box |
12 | 12 | */ |
13 | 13 | class RWMB_Core { |
14 | - /** |
|
15 | - * Initialization. |
|
16 | - */ |
|
17 | - public function init() { |
|
18 | - load_plugin_textdomain( 'meta-box', false, plugin_basename( RWMB_DIR ) . '/languages/' ); |
|
14 | + /** |
|
15 | + * Initialization. |
|
16 | + */ |
|
17 | + public function init() { |
|
18 | + load_plugin_textdomain( 'meta-box', false, plugin_basename( RWMB_DIR ) . '/languages/' ); |
|
19 | 19 | |
20 | - add_filter( 'plugin_action_links_meta-box/meta-box.php', array( $this, 'plugin_links' ), 20 ); |
|
20 | + add_filter( 'plugin_action_links_meta-box/meta-box.php', array( $this, 'plugin_links' ), 20 ); |
|
21 | 21 | |
22 | - // Uses priority 20 to support custom port types registered using the default priority. |
|
23 | - add_action( 'init', array( $this, 'register_meta_boxes' ), 20 ); |
|
24 | - add_action( 'edit_page_form', array( $this, 'fix_page_template' ) ); |
|
25 | - $this->add_context_hooks(); |
|
26 | - } |
|
22 | + // Uses priority 20 to support custom port types registered using the default priority. |
|
23 | + add_action( 'init', array( $this, 'register_meta_boxes' ), 20 ); |
|
24 | + add_action( 'edit_page_form', array( $this, 'fix_page_template' ) ); |
|
25 | + $this->add_context_hooks(); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * Add links to Documentation and Extensions in plugin's list of action links. |
|
30 | - * |
|
31 | - * @since 4.3.11 |
|
32 | - * |
|
33 | - * @param array $links Array of plugin links. |
|
34 | - * |
|
35 | - * @return array |
|
36 | - */ |
|
37 | - public function plugin_links( $links ) { |
|
38 | - $links[] = '<a href="https://docs.metabox.io">' . esc_html__( 'Docs', 'meta-box' ) . '</a>'; |
|
39 | - return $links; |
|
40 | - } |
|
28 | + /** |
|
29 | + * Add links to Documentation and Extensions in plugin's list of action links. |
|
30 | + * |
|
31 | + * @since 4.3.11 |
|
32 | + * |
|
33 | + * @param array $links Array of plugin links. |
|
34 | + * |
|
35 | + * @return array |
|
36 | + */ |
|
37 | + public function plugin_links( $links ) { |
|
38 | + $links[] = '<a href="https://docs.metabox.io">' . esc_html__( 'Docs', 'meta-box' ) . '</a>'; |
|
39 | + return $links; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Register meta boxes. |
|
44 | - * Advantages: |
|
45 | - * - prevents incorrect hook. |
|
46 | - * - no need to check for class existences. |
|
47 | - */ |
|
48 | - public function register_meta_boxes() { |
|
49 | - $configs = apply_filters( 'rwmb_meta_boxes', array() ); |
|
50 | - $registry = rwmb_get_registry( 'meta_box' ); |
|
42 | + /** |
|
43 | + * Register meta boxes. |
|
44 | + * Advantages: |
|
45 | + * - prevents incorrect hook. |
|
46 | + * - no need to check for class existences. |
|
47 | + */ |
|
48 | + public function register_meta_boxes() { |
|
49 | + $configs = apply_filters( 'rwmb_meta_boxes', array() ); |
|
50 | + $registry = rwmb_get_registry( 'meta_box' ); |
|
51 | 51 | |
52 | - foreach ( $configs as $config ) { |
|
53 | - $meta_box = $registry->make( $config ); |
|
54 | - $meta_box->register_fields(); |
|
55 | - } |
|
56 | - } |
|
52 | + foreach ( $configs as $config ) { |
|
53 | + $meta_box = $registry->make( $config ); |
|
54 | + $meta_box->register_fields(); |
|
55 | + } |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * WordPress will prevent post data saving if a page template has been selected that does not exist. |
|
60 | - * This is especially a problem when switching to our theme, and old page templates are in the post data. |
|
61 | - * Unset the page template if the page does not exist to allow the post to save. |
|
62 | - * |
|
63 | - * @param WP_Post $post Post object. |
|
64 | - * |
|
65 | - * @since 4.3.10 |
|
66 | - */ |
|
67 | - public function fix_page_template( WP_Post $post ) { |
|
68 | - $template = get_post_meta( $post->ID, '_wp_page_template', true ); |
|
69 | - $page_templates = wp_get_theme()->get_page_templates(); |
|
58 | + /** |
|
59 | + * WordPress will prevent post data saving if a page template has been selected that does not exist. |
|
60 | + * This is especially a problem when switching to our theme, and old page templates are in the post data. |
|
61 | + * Unset the page template if the page does not exist to allow the post to save. |
|
62 | + * |
|
63 | + * @param WP_Post $post Post object. |
|
64 | + * |
|
65 | + * @since 4.3.10 |
|
66 | + */ |
|
67 | + public function fix_page_template( WP_Post $post ) { |
|
68 | + $template = get_post_meta( $post->ID, '_wp_page_template', true ); |
|
69 | + $page_templates = wp_get_theme()->get_page_templates(); |
|
70 | 70 | |
71 | - // If the template doesn't exists, remove the data to allow WordPress to save. |
|
72 | - if ( ! isset( $page_templates[ $template ] ) ) { |
|
73 | - delete_post_meta( $post->ID, '_wp_page_template' ); |
|
74 | - } |
|
75 | - } |
|
71 | + // If the template doesn't exists, remove the data to allow WordPress to save. |
|
72 | + if ( ! isset( $page_templates[ $template ] ) ) { |
|
73 | + delete_post_meta( $post->ID, '_wp_page_template' ); |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Get registered meta boxes via a filter. |
|
79 | - * |
|
80 | - * @deprecated No longer used. Keep for backward-compatibility with extensions. |
|
81 | - * |
|
82 | - * @return array |
|
83 | - */ |
|
84 | - public static function get_meta_boxes() { |
|
85 | - $meta_boxes = rwmb_get_registry( 'meta_box' )->all(); |
|
86 | - return wp_list_pluck( $meta_boxes, 'meta_box' ); |
|
87 | - } |
|
77 | + /** |
|
78 | + * Get registered meta boxes via a filter. |
|
79 | + * |
|
80 | + * @deprecated No longer used. Keep for backward-compatibility with extensions. |
|
81 | + * |
|
82 | + * @return array |
|
83 | + */ |
|
84 | + public static function get_meta_boxes() { |
|
85 | + $meta_boxes = rwmb_get_registry( 'meta_box' )->all(); |
|
86 | + return wp_list_pluck( $meta_boxes, 'meta_box' ); |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Add hooks for extra contexts. |
|
91 | - */ |
|
92 | - public function add_context_hooks() { |
|
93 | - $hooks = array( |
|
94 | - 'edit_form_top', |
|
95 | - 'edit_form_after_title', |
|
96 | - 'edit_form_after_editor', |
|
97 | - 'edit_form_before_permalink', |
|
98 | - ); |
|
89 | + /** |
|
90 | + * Add hooks for extra contexts. |
|
91 | + */ |
|
92 | + public function add_context_hooks() { |
|
93 | + $hooks = array( |
|
94 | + 'edit_form_top', |
|
95 | + 'edit_form_after_title', |
|
96 | + 'edit_form_after_editor', |
|
97 | + 'edit_form_before_permalink', |
|
98 | + ); |
|
99 | 99 | |
100 | - foreach ( $hooks as $hook ) { |
|
101 | - add_action( $hook, array( $this, 'add_context' ) ); |
|
102 | - } |
|
103 | - } |
|
100 | + foreach ( $hooks as $hook ) { |
|
101 | + add_action( $hook, array( $this, 'add_context' ) ); |
|
102 | + } |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Add new meta box context. |
|
107 | - * |
|
108 | - * @param WP_Post $post The current post object. |
|
109 | - */ |
|
110 | - public function add_context( $post ) { |
|
111 | - $hook = current_filter(); |
|
112 | - $context = 'edit_form_top' === $hook ? 'form_top' : substr( $hook, 10 ); |
|
113 | - do_meta_boxes( null, $context, $post ); |
|
114 | - } |
|
105 | + /** |
|
106 | + * Add new meta box context. |
|
107 | + * |
|
108 | + * @param WP_Post $post The current post object. |
|
109 | + */ |
|
110 | + public function add_context( $post ) { |
|
111 | + $hook = current_filter(); |
|
112 | + $context = 'edit_form_top' === $hook ? 'form_top' : substr( $hook, 10 ); |
|
113 | + do_meta_boxes( null, $context, $post ); |
|
114 | + } |
|
115 | 115 | } |
@@ -15,13 +15,13 @@ discard block |
||
15 | 15 | * Initialization. |
16 | 16 | */ |
17 | 17 | public function init() { |
18 | - load_plugin_textdomain( 'meta-box', false, plugin_basename( RWMB_DIR ) . '/languages/' ); |
|
18 | + load_plugin_textdomain('meta-box', false, plugin_basename(RWMB_DIR) . '/languages/'); |
|
19 | 19 | |
20 | - add_filter( 'plugin_action_links_meta-box/meta-box.php', array( $this, 'plugin_links' ), 20 ); |
|
20 | + add_filter('plugin_action_links_meta-box/meta-box.php', array($this, 'plugin_links'), 20); |
|
21 | 21 | |
22 | 22 | // Uses priority 20 to support custom port types registered using the default priority. |
23 | - add_action( 'init', array( $this, 'register_meta_boxes' ), 20 ); |
|
24 | - add_action( 'edit_page_form', array( $this, 'fix_page_template' ) ); |
|
23 | + add_action('init', array($this, 'register_meta_boxes'), 20); |
|
24 | + add_action('edit_page_form', array($this, 'fix_page_template')); |
|
25 | 25 | $this->add_context_hooks(); |
26 | 26 | } |
27 | 27 | |
@@ -34,8 +34,8 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @return array |
36 | 36 | */ |
37 | - public function plugin_links( $links ) { |
|
38 | - $links[] = '<a href="https://docs.metabox.io">' . esc_html__( 'Docs', 'meta-box' ) . '</a>'; |
|
37 | + public function plugin_links($links) { |
|
38 | + $links[] = '<a href="https://docs.metabox.io">' . esc_html__('Docs', 'meta-box') . '</a>'; |
|
39 | 39 | return $links; |
40 | 40 | } |
41 | 41 | |
@@ -46,11 +46,11 @@ discard block |
||
46 | 46 | * - no need to check for class existences. |
47 | 47 | */ |
48 | 48 | public function register_meta_boxes() { |
49 | - $configs = apply_filters( 'rwmb_meta_boxes', array() ); |
|
50 | - $registry = rwmb_get_registry( 'meta_box' ); |
|
49 | + $configs = apply_filters('rwmb_meta_boxes', array()); |
|
50 | + $registry = rwmb_get_registry('meta_box'); |
|
51 | 51 | |
52 | - foreach ( $configs as $config ) { |
|
53 | - $meta_box = $registry->make( $config ); |
|
52 | + foreach ($configs as $config) { |
|
53 | + $meta_box = $registry->make($config); |
|
54 | 54 | $meta_box->register_fields(); |
55 | 55 | } |
56 | 56 | } |
@@ -64,13 +64,13 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @since 4.3.10 |
66 | 66 | */ |
67 | - public function fix_page_template( WP_Post $post ) { |
|
68 | - $template = get_post_meta( $post->ID, '_wp_page_template', true ); |
|
67 | + public function fix_page_template(WP_Post $post) { |
|
68 | + $template = get_post_meta($post->ID, '_wp_page_template', true); |
|
69 | 69 | $page_templates = wp_get_theme()->get_page_templates(); |
70 | 70 | |
71 | 71 | // If the template doesn't exists, remove the data to allow WordPress to save. |
72 | - if ( ! isset( $page_templates[ $template ] ) ) { |
|
73 | - delete_post_meta( $post->ID, '_wp_page_template' ); |
|
72 | + if (!isset($page_templates[$template])) { |
|
73 | + delete_post_meta($post->ID, '_wp_page_template'); |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | * @return array |
83 | 83 | */ |
84 | 84 | public static function get_meta_boxes() { |
85 | - $meta_boxes = rwmb_get_registry( 'meta_box' )->all(); |
|
86 | - return wp_list_pluck( $meta_boxes, 'meta_box' ); |
|
85 | + $meta_boxes = rwmb_get_registry('meta_box')->all(); |
|
86 | + return wp_list_pluck($meta_boxes, 'meta_box'); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | 'edit_form_before_permalink', |
98 | 98 | ); |
99 | 99 | |
100 | - foreach ( $hooks as $hook ) { |
|
101 | - add_action( $hook, array( $this, 'add_context' ) ); |
|
100 | + foreach ($hooks as $hook) { |
|
101 | + add_action($hook, array($this, 'add_context')); |
|
102 | 102 | } |
103 | 103 | } |
104 | 104 | |
@@ -107,9 +107,9 @@ discard block |
||
107 | 107 | * |
108 | 108 | * @param WP_Post $post The current post object. |
109 | 109 | */ |
110 | - public function add_context( $post ) { |
|
110 | + public function add_context($post) { |
|
111 | 111 | $hook = current_filter(); |
112 | - $context = 'edit_form_top' === $hook ? 'form_top' : substr( $hook, 10 ); |
|
113 | - do_meta_boxes( null, $context, $post ); |
|
112 | + $context = 'edit_form_top' === $hook ? 'form_top' : substr($hook, 10); |
|
113 | + do_meta_boxes(null, $context, $post); |
|
114 | 114 | } |
115 | 115 | } |
@@ -9,118 +9,118 @@ |
||
9 | 9 | * WPML compatibility class |
10 | 10 | */ |
11 | 11 | class RWMB_WPML { |
12 | - /** |
|
13 | - * List of fields that need to translate values (because they're saved as IDs). |
|
14 | - * |
|
15 | - * @var array |
|
16 | - */ |
|
17 | - protected $field_types = array( 'post', 'taxonomy_advanced' ); |
|
18 | - |
|
19 | - /** |
|
20 | - * Initialize. |
|
21 | - */ |
|
22 | - public function init() { |
|
23 | - /** |
|
24 | - * Run before meta boxes are registered so it can modify fields. |
|
25 | - * |
|
26 | - * @see modify_field() |
|
27 | - */ |
|
28 | - add_action( 'init', array( $this, 'register_hooks' ), 9 ); |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
32 | - * Register hooks. |
|
33 | - */ |
|
34 | - public function register_hooks() { |
|
35 | - if ( ! defined( 'ICL_SITEPRESS_VERSION' ) ) { |
|
36 | - return; |
|
37 | - } |
|
38 | - add_filter( 'wpml_duplicate_generic_string', array( $this, 'translate_ids' ), 10, 3 ); |
|
39 | - add_filter( 'rwmb_normalize_field', array( $this, 'modify_field' ) ); |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Translating IDs stored as field values upon WPML post/page duplication. |
|
44 | - * |
|
45 | - * @param mixed $value Meta value. |
|
46 | - * @param string $target_language Target language. |
|
47 | - * @param array $meta_data Meta arguments. |
|
48 | - * @return mixed |
|
49 | - */ |
|
50 | - public function translate_ids( $value, $target_language, $meta_data ) { |
|
51 | - if ( 'custom_field' !== $meta_data['context'] ) { |
|
52 | - return $value; |
|
53 | - } |
|
54 | - |
|
55 | - $field = rwmb_get_registry( 'field' )->get( $meta_data['key'], get_post_type( $meta_data['master_post_id'] ) ); |
|
56 | - if ( false === $field || ! in_array( $field['type'], $this->field_types, true ) ) { |
|
57 | - return $value; |
|
58 | - } |
|
59 | - |
|
60 | - // Object type needed for WPML filter differs between fields. |
|
61 | - $object_type = 'taxonomy_advanced' === $field['type'] ? $field['taxonomy'] : $field['post_type']; |
|
62 | - |
|
63 | - // Translating values, whether are stored as comma separated strings or not. |
|
64 | - if ( false === strpos( $value, ',' ) ) { |
|
65 | - $value = apply_filters( 'wpml_object_id', $value, $object_type, true, $target_language ); |
|
66 | - return $value; |
|
67 | - } |
|
68 | - |
|
69 | - // Dealing with IDs stored as comma separated strings. |
|
70 | - $translated_values = array(); |
|
71 | - $values = explode( ',', $value ); |
|
72 | - |
|
73 | - foreach ( $values as $v ) { |
|
74 | - $translated_values[] = apply_filters( 'wpml_object_id', $v, $object_type, true, $target_language ); |
|
75 | - } |
|
76 | - |
|
77 | - $value = implode( ',', $translated_values ); |
|
78 | - return $value; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Modified field depends on its translation status. |
|
83 | - * If the post is a translated version of another post and the field is set to: |
|
84 | - * - Do not translate: hide the field. |
|
85 | - * - Copy: make it disabled so users cannot edit. |
|
86 | - * - Translate: do nothing. |
|
87 | - * |
|
88 | - * @param array $field Field parameters. |
|
89 | - * |
|
90 | - * @return mixed |
|
91 | - */ |
|
92 | - public function modify_field( $field ) { |
|
93 | - global $wpml_post_translations; |
|
94 | - |
|
95 | - if ( empty( $field['id'] ) ) { |
|
96 | - return $field; |
|
97 | - } |
|
98 | - |
|
99 | - // Get post ID. |
|
100 | - $request = rwmb_request(); |
|
101 | - $post_id = $request->filter_get( 'post', FILTER_SANITIZE_NUMBER_INT ); |
|
102 | - if ( ! $post_id ) { |
|
103 | - $post_id = $request->filter_post( 'post_ID', FILTER_SANITIZE_NUMBER_INT ); |
|
104 | - } |
|
105 | - |
|
106 | - // If the post is the original one: do nothing. |
|
107 | - if ( ! method_exists( $wpml_post_translations, 'get_source_lang_code' ) || ! $wpml_post_translations->get_source_lang_code( $post_id ) ) { |
|
108 | - return $field; |
|
109 | - } |
|
110 | - |
|
111 | - // Get setting for the custom field translation. |
|
112 | - $custom_fields_translation = apply_filters( 'wpml_sub_setting', false, 'translation-management', 'custom_fields_translation' ); |
|
113 | - if ( ! isset( $custom_fields_translation[ $field['id'] ] ) ) { |
|
114 | - return $field; |
|
115 | - } |
|
116 | - |
|
117 | - $setting = intval( $custom_fields_translation[ $field['id'] ] ); |
|
118 | - if ( 0 === $setting ) { // Do not translate: hide it. |
|
119 | - $field['class'] .= ' hidden'; |
|
120 | - } elseif ( 1 === $setting ) { // Copy: disable editing. |
|
121 | - $field['disabled'] = true; |
|
122 | - } |
|
123 | - |
|
124 | - return $field; |
|
125 | - } |
|
12 | + /** |
|
13 | + * List of fields that need to translate values (because they're saved as IDs). |
|
14 | + * |
|
15 | + * @var array |
|
16 | + */ |
|
17 | + protected $field_types = array( 'post', 'taxonomy_advanced' ); |
|
18 | + |
|
19 | + /** |
|
20 | + * Initialize. |
|
21 | + */ |
|
22 | + public function init() { |
|
23 | + /** |
|
24 | + * Run before meta boxes are registered so it can modify fields. |
|
25 | + * |
|
26 | + * @see modify_field() |
|
27 | + */ |
|
28 | + add_action( 'init', array( $this, 'register_hooks' ), 9 ); |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | + * Register hooks. |
|
33 | + */ |
|
34 | + public function register_hooks() { |
|
35 | + if ( ! defined( 'ICL_SITEPRESS_VERSION' ) ) { |
|
36 | + return; |
|
37 | + } |
|
38 | + add_filter( 'wpml_duplicate_generic_string', array( $this, 'translate_ids' ), 10, 3 ); |
|
39 | + add_filter( 'rwmb_normalize_field', array( $this, 'modify_field' ) ); |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Translating IDs stored as field values upon WPML post/page duplication. |
|
44 | + * |
|
45 | + * @param mixed $value Meta value. |
|
46 | + * @param string $target_language Target language. |
|
47 | + * @param array $meta_data Meta arguments. |
|
48 | + * @return mixed |
|
49 | + */ |
|
50 | + public function translate_ids( $value, $target_language, $meta_data ) { |
|
51 | + if ( 'custom_field' !== $meta_data['context'] ) { |
|
52 | + return $value; |
|
53 | + } |
|
54 | + |
|
55 | + $field = rwmb_get_registry( 'field' )->get( $meta_data['key'], get_post_type( $meta_data['master_post_id'] ) ); |
|
56 | + if ( false === $field || ! in_array( $field['type'], $this->field_types, true ) ) { |
|
57 | + return $value; |
|
58 | + } |
|
59 | + |
|
60 | + // Object type needed for WPML filter differs between fields. |
|
61 | + $object_type = 'taxonomy_advanced' === $field['type'] ? $field['taxonomy'] : $field['post_type']; |
|
62 | + |
|
63 | + // Translating values, whether are stored as comma separated strings or not. |
|
64 | + if ( false === strpos( $value, ',' ) ) { |
|
65 | + $value = apply_filters( 'wpml_object_id', $value, $object_type, true, $target_language ); |
|
66 | + return $value; |
|
67 | + } |
|
68 | + |
|
69 | + // Dealing with IDs stored as comma separated strings. |
|
70 | + $translated_values = array(); |
|
71 | + $values = explode( ',', $value ); |
|
72 | + |
|
73 | + foreach ( $values as $v ) { |
|
74 | + $translated_values[] = apply_filters( 'wpml_object_id', $v, $object_type, true, $target_language ); |
|
75 | + } |
|
76 | + |
|
77 | + $value = implode( ',', $translated_values ); |
|
78 | + return $value; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Modified field depends on its translation status. |
|
83 | + * If the post is a translated version of another post and the field is set to: |
|
84 | + * - Do not translate: hide the field. |
|
85 | + * - Copy: make it disabled so users cannot edit. |
|
86 | + * - Translate: do nothing. |
|
87 | + * |
|
88 | + * @param array $field Field parameters. |
|
89 | + * |
|
90 | + * @return mixed |
|
91 | + */ |
|
92 | + public function modify_field( $field ) { |
|
93 | + global $wpml_post_translations; |
|
94 | + |
|
95 | + if ( empty( $field['id'] ) ) { |
|
96 | + return $field; |
|
97 | + } |
|
98 | + |
|
99 | + // Get post ID. |
|
100 | + $request = rwmb_request(); |
|
101 | + $post_id = $request->filter_get( 'post', FILTER_SANITIZE_NUMBER_INT ); |
|
102 | + if ( ! $post_id ) { |
|
103 | + $post_id = $request->filter_post( 'post_ID', FILTER_SANITIZE_NUMBER_INT ); |
|
104 | + } |
|
105 | + |
|
106 | + // If the post is the original one: do nothing. |
|
107 | + if ( ! method_exists( $wpml_post_translations, 'get_source_lang_code' ) || ! $wpml_post_translations->get_source_lang_code( $post_id ) ) { |
|
108 | + return $field; |
|
109 | + } |
|
110 | + |
|
111 | + // Get setting for the custom field translation. |
|
112 | + $custom_fields_translation = apply_filters( 'wpml_sub_setting', false, 'translation-management', 'custom_fields_translation' ); |
|
113 | + if ( ! isset( $custom_fields_translation[ $field['id'] ] ) ) { |
|
114 | + return $field; |
|
115 | + } |
|
116 | + |
|
117 | + $setting = intval( $custom_fields_translation[ $field['id'] ] ); |
|
118 | + if ( 0 === $setting ) { // Do not translate: hide it. |
|
119 | + $field['class'] .= ' hidden'; |
|
120 | + } elseif ( 1 === $setting ) { // Copy: disable editing. |
|
121 | + $field['disabled'] = true; |
|
122 | + } |
|
123 | + |
|
124 | + return $field; |
|
125 | + } |
|
126 | 126 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | * |
15 | 15 | * @var array |
16 | 16 | */ |
17 | - protected $field_types = array( 'post', 'taxonomy_advanced' ); |
|
17 | + protected $field_types = array('post', 'taxonomy_advanced'); |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Initialize. |
@@ -25,18 +25,18 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @see modify_field() |
27 | 27 | */ |
28 | - add_action( 'init', array( $this, 'register_hooks' ), 9 ); |
|
28 | + add_action('init', array($this, 'register_hooks'), 9); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Register hooks. |
33 | 33 | */ |
34 | 34 | public function register_hooks() { |
35 | - if ( ! defined( 'ICL_SITEPRESS_VERSION' ) ) { |
|
35 | + if (!defined('ICL_SITEPRESS_VERSION')) { |
|
36 | 36 | return; |
37 | 37 | } |
38 | - add_filter( 'wpml_duplicate_generic_string', array( $this, 'translate_ids' ), 10, 3 ); |
|
39 | - add_filter( 'rwmb_normalize_field', array( $this, 'modify_field' ) ); |
|
38 | + add_filter('wpml_duplicate_generic_string', array($this, 'translate_ids'), 10, 3); |
|
39 | + add_filter('rwmb_normalize_field', array($this, 'modify_field')); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -47,13 +47,13 @@ discard block |
||
47 | 47 | * @param array $meta_data Meta arguments. |
48 | 48 | * @return mixed |
49 | 49 | */ |
50 | - public function translate_ids( $value, $target_language, $meta_data ) { |
|
51 | - if ( 'custom_field' !== $meta_data['context'] ) { |
|
50 | + public function translate_ids($value, $target_language, $meta_data) { |
|
51 | + if ('custom_field' !== $meta_data['context']) { |
|
52 | 52 | return $value; |
53 | 53 | } |
54 | 54 | |
55 | - $field = rwmb_get_registry( 'field' )->get( $meta_data['key'], get_post_type( $meta_data['master_post_id'] ) ); |
|
56 | - if ( false === $field || ! in_array( $field['type'], $this->field_types, true ) ) { |
|
55 | + $field = rwmb_get_registry('field')->get($meta_data['key'], get_post_type($meta_data['master_post_id'])); |
|
56 | + if (false === $field || !in_array($field['type'], $this->field_types, true)) { |
|
57 | 57 | return $value; |
58 | 58 | } |
59 | 59 | |
@@ -61,20 +61,20 @@ discard block |
||
61 | 61 | $object_type = 'taxonomy_advanced' === $field['type'] ? $field['taxonomy'] : $field['post_type']; |
62 | 62 | |
63 | 63 | // Translating values, whether are stored as comma separated strings or not. |
64 | - if ( false === strpos( $value, ',' ) ) { |
|
65 | - $value = apply_filters( 'wpml_object_id', $value, $object_type, true, $target_language ); |
|
64 | + if (false === strpos($value, ',')) { |
|
65 | + $value = apply_filters('wpml_object_id', $value, $object_type, true, $target_language); |
|
66 | 66 | return $value; |
67 | 67 | } |
68 | 68 | |
69 | 69 | // Dealing with IDs stored as comma separated strings. |
70 | 70 | $translated_values = array(); |
71 | - $values = explode( ',', $value ); |
|
71 | + $values = explode(',', $value); |
|
72 | 72 | |
73 | - foreach ( $values as $v ) { |
|
74 | - $translated_values[] = apply_filters( 'wpml_object_id', $v, $object_type, true, $target_language ); |
|
73 | + foreach ($values as $v) { |
|
74 | + $translated_values[] = apply_filters('wpml_object_id', $v, $object_type, true, $target_language); |
|
75 | 75 | } |
76 | 76 | |
77 | - $value = implode( ',', $translated_values ); |
|
77 | + $value = implode(',', $translated_values); |
|
78 | 78 | return $value; |
79 | 79 | } |
80 | 80 | |
@@ -89,35 +89,35 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @return mixed |
91 | 91 | */ |
92 | - public function modify_field( $field ) { |
|
92 | + public function modify_field($field) { |
|
93 | 93 | global $wpml_post_translations; |
94 | 94 | |
95 | - if ( empty( $field['id'] ) ) { |
|
95 | + if (empty($field['id'])) { |
|
96 | 96 | return $field; |
97 | 97 | } |
98 | 98 | |
99 | 99 | // Get post ID. |
100 | 100 | $request = rwmb_request(); |
101 | - $post_id = $request->filter_get( 'post', FILTER_SANITIZE_NUMBER_INT ); |
|
102 | - if ( ! $post_id ) { |
|
103 | - $post_id = $request->filter_post( 'post_ID', FILTER_SANITIZE_NUMBER_INT ); |
|
101 | + $post_id = $request->filter_get('post', FILTER_SANITIZE_NUMBER_INT); |
|
102 | + if (!$post_id) { |
|
103 | + $post_id = $request->filter_post('post_ID', FILTER_SANITIZE_NUMBER_INT); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | // If the post is the original one: do nothing. |
107 | - if ( ! method_exists( $wpml_post_translations, 'get_source_lang_code' ) || ! $wpml_post_translations->get_source_lang_code( $post_id ) ) { |
|
107 | + if (!method_exists($wpml_post_translations, 'get_source_lang_code') || !$wpml_post_translations->get_source_lang_code($post_id)) { |
|
108 | 108 | return $field; |
109 | 109 | } |
110 | 110 | |
111 | 111 | // Get setting for the custom field translation. |
112 | - $custom_fields_translation = apply_filters( 'wpml_sub_setting', false, 'translation-management', 'custom_fields_translation' ); |
|
113 | - if ( ! isset( $custom_fields_translation[ $field['id'] ] ) ) { |
|
112 | + $custom_fields_translation = apply_filters('wpml_sub_setting', false, 'translation-management', 'custom_fields_translation'); |
|
113 | + if (!isset($custom_fields_translation[$field['id']])) { |
|
114 | 114 | return $field; |
115 | 115 | } |
116 | 116 | |
117 | - $setting = intval( $custom_fields_translation[ $field['id'] ] ); |
|
118 | - if ( 0 === $setting ) { // Do not translate: hide it. |
|
117 | + $setting = intval($custom_fields_translation[$field['id']]); |
|
118 | + if (0 === $setting) { // Do not translate: hide it. |
|
119 | 119 | $field['class'] .= ' hidden'; |
120 | - } elseif ( 1 === $setting ) { // Copy: disable editing. |
|
120 | + } elseif (1 === $setting) { // Copy: disable editing. |
|
121 | 121 | $field['disabled'] = true; |
122 | 122 | } |
123 | 123 |
@@ -6,154 +6,154 @@ discard block |
||
6 | 6 | */ |
7 | 7 | |
8 | 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 | - $field = rwmb_get_field_settings( $key, $args, $post_id ); |
|
21 | - |
|
22 | - /* |
|
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 | + $field = rwmb_get_field_settings( $key, $args, $post_id ); |
|
21 | + |
|
22 | + /* |
|
23 | 23 | * If field is not found, which can caused by registering meta boxes for the backend only or conditional registration. |
24 | 24 | * Then fallback to the old method to retrieve meta (which uses get_post_meta() as the latest fallback). |
25 | 25 | */ |
26 | - if ( false === $field ) { |
|
27 | - return apply_filters( 'rwmb_meta', rwmb_meta_legacy( $key, $args, $post_id ) ); |
|
28 | - } |
|
29 | - $meta = in_array( $field['type'], array( 'oembed', 'map', 'osm' ), true ) ? |
|
30 | - rwmb_the_value( $key, $args, $post_id, false ) : |
|
31 | - rwmb_get_value( $key, $args, $post_id ); |
|
32 | - return apply_filters( 'rwmb_meta', $meta, $key, $args, $post_id ); |
|
33 | - } |
|
26 | + if ( false === $field ) { |
|
27 | + return apply_filters( 'rwmb_meta', rwmb_meta_legacy( $key, $args, $post_id ) ); |
|
28 | + } |
|
29 | + $meta = in_array( $field['type'], array( 'oembed', 'map', 'osm' ), true ) ? |
|
30 | + rwmb_the_value( $key, $args, $post_id, false ) : |
|
31 | + rwmb_get_value( $key, $args, $post_id ); |
|
32 | + return apply_filters( 'rwmb_meta', $meta, $key, $args, $post_id ); |
|
33 | + } |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | if ( ! function_exists( 'rwmb_set_meta' ) ) { |
37 | - /** |
|
38 | - * Set meta value. |
|
39 | - * |
|
40 | - * @param int $object_id Object ID. Required. |
|
41 | - * @param string $key Meta key. Required. |
|
42 | - * @param string $value Meta value. Required. |
|
43 | - * @param array $args Array of arguments. Optional. |
|
44 | - */ |
|
45 | - function rwmb_set_meta( $object_id, $key, $value, $args = array() ) { |
|
46 | - $args = wp_parse_args( $args ); |
|
47 | - $field = rwmb_get_field_settings( $key, $args, $object_id ); |
|
48 | - |
|
49 | - if ( false === $field ) { |
|
50 | - return; |
|
51 | - } |
|
52 | - |
|
53 | - $old = RWMB_Field::call( $field, 'raw_meta', $object_id ); |
|
54 | - $new = RWMB_Field::process_value( $value, $object_id, $field ); |
|
55 | - RWMB_Field::call( $field, 'save', $new, $old, $object_id ); |
|
56 | - } |
|
37 | + /** |
|
38 | + * Set meta value. |
|
39 | + * |
|
40 | + * @param int $object_id Object ID. Required. |
|
41 | + * @param string $key Meta key. Required. |
|
42 | + * @param string $value Meta value. Required. |
|
43 | + * @param array $args Array of arguments. Optional. |
|
44 | + */ |
|
45 | + function rwmb_set_meta( $object_id, $key, $value, $args = array() ) { |
|
46 | + $args = wp_parse_args( $args ); |
|
47 | + $field = rwmb_get_field_settings( $key, $args, $object_id ); |
|
48 | + |
|
49 | + if ( false === $field ) { |
|
50 | + return; |
|
51 | + } |
|
52 | + |
|
53 | + $old = RWMB_Field::call( $field, 'raw_meta', $object_id ); |
|
54 | + $new = RWMB_Field::process_value( $value, $object_id, $field ); |
|
55 | + RWMB_Field::call( $field, 'save', $new, $old, $object_id ); |
|
56 | + } |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | if ( ! function_exists( 'rwmb_get_field_settings' ) ) { |
60 | - /** |
|
61 | - * Get field settings. |
|
62 | - * |
|
63 | - * @param string $key Meta key. Required. |
|
64 | - * @param array $args Array of arguments. Optional. |
|
65 | - * @param int|null $object_id Object ID. null for current post. Optional. |
|
66 | - * |
|
67 | - * @return array |
|
68 | - */ |
|
69 | - function rwmb_get_field_settings( $key, $args = array(), $object_id = null ) { |
|
70 | - $args = wp_parse_args( |
|
71 | - $args, |
|
72 | - array( |
|
73 | - 'object_type' => 'post', |
|
74 | - 'type' => '', |
|
75 | - ) |
|
76 | - ); |
|
77 | - |
|
78 | - /** |
|
79 | - * Filter meta type from object type and object id. |
|
80 | - * |
|
81 | - * @var string Meta type, default is post type name. |
|
82 | - * @var string Object type. |
|
83 | - * @var string|int Object id. |
|
84 | - */ |
|
85 | - $type = apply_filters( 'rwmb_meta_type', $args['type'], $args['object_type'], $object_id ); |
|
86 | - if ( ! $type ) { |
|
87 | - $type = get_post_type( $object_id ); |
|
88 | - } |
|
89 | - |
|
90 | - return rwmb_get_registry( 'field' )->get( $key, $type, $args['object_type'] ); |
|
91 | - } |
|
60 | + /** |
|
61 | + * Get field settings. |
|
62 | + * |
|
63 | + * @param string $key Meta key. Required. |
|
64 | + * @param array $args Array of arguments. Optional. |
|
65 | + * @param int|null $object_id Object ID. null for current post. Optional. |
|
66 | + * |
|
67 | + * @return array |
|
68 | + */ |
|
69 | + function rwmb_get_field_settings( $key, $args = array(), $object_id = null ) { |
|
70 | + $args = wp_parse_args( |
|
71 | + $args, |
|
72 | + array( |
|
73 | + 'object_type' => 'post', |
|
74 | + 'type' => '', |
|
75 | + ) |
|
76 | + ); |
|
77 | + |
|
78 | + /** |
|
79 | + * Filter meta type from object type and object id. |
|
80 | + * |
|
81 | + * @var string Meta type, default is post type name. |
|
82 | + * @var string Object type. |
|
83 | + * @var string|int Object id. |
|
84 | + */ |
|
85 | + $type = apply_filters( 'rwmb_meta_type', $args['type'], $args['object_type'], $object_id ); |
|
86 | + if ( ! $type ) { |
|
87 | + $type = get_post_type( $object_id ); |
|
88 | + } |
|
89 | + |
|
90 | + return rwmb_get_registry( 'field' )->get( $key, $type, $args['object_type'] ); |
|
91 | + } |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | if ( ! function_exists( 'rwmb_meta_legacy' ) ) { |
95 | - /** |
|
96 | - * Get post meta. |
|
97 | - * |
|
98 | - * @param string $key Meta key. Required. |
|
99 | - * @param array $args Array of arguments. Optional. |
|
100 | - * @param int|null $post_id Post ID. null for current post. Optional. |
|
101 | - * |
|
102 | - * @return mixed |
|
103 | - */ |
|
104 | - function rwmb_meta_legacy( $key, $args = array(), $post_id = null ) { |
|
105 | - $args = wp_parse_args( |
|
106 | - $args, |
|
107 | - array( |
|
108 | - 'type' => 'text', |
|
109 | - 'multiple' => false, |
|
110 | - 'clone' => false, |
|
111 | - ) |
|
112 | - ); |
|
113 | - $field = array( |
|
114 | - 'id' => $key, |
|
115 | - 'type' => $args['type'], |
|
116 | - 'clone' => $args['clone'], |
|
117 | - 'multiple' => $args['multiple'], |
|
118 | - ); |
|
119 | - |
|
120 | - $method = 'get_value'; |
|
121 | - switch ( $args['type'] ) { |
|
122 | - case 'taxonomy': |
|
123 | - case 'taxonomy_advanced': |
|
124 | - $field['taxonomy'] = $args['taxonomy']; |
|
125 | - break; |
|
126 | - case 'map': |
|
127 | - case 'osm': |
|
128 | - case 'oembed': |
|
129 | - $method = 'the_value'; |
|
130 | - break; |
|
131 | - } |
|
132 | - $field = RWMB_Field::call( 'normalize', $field ); |
|
133 | - |
|
134 | - return RWMB_Field::call( $method, $field, $args, $post_id ); |
|
135 | - } |
|
95 | + /** |
|
96 | + * Get post meta. |
|
97 | + * |
|
98 | + * @param string $key Meta key. Required. |
|
99 | + * @param array $args Array of arguments. Optional. |
|
100 | + * @param int|null $post_id Post ID. null for current post. Optional. |
|
101 | + * |
|
102 | + * @return mixed |
|
103 | + */ |
|
104 | + function rwmb_meta_legacy( $key, $args = array(), $post_id = null ) { |
|
105 | + $args = wp_parse_args( |
|
106 | + $args, |
|
107 | + array( |
|
108 | + 'type' => 'text', |
|
109 | + 'multiple' => false, |
|
110 | + 'clone' => false, |
|
111 | + ) |
|
112 | + ); |
|
113 | + $field = array( |
|
114 | + 'id' => $key, |
|
115 | + 'type' => $args['type'], |
|
116 | + 'clone' => $args['clone'], |
|
117 | + 'multiple' => $args['multiple'], |
|
118 | + ); |
|
119 | + |
|
120 | + $method = 'get_value'; |
|
121 | + switch ( $args['type'] ) { |
|
122 | + case 'taxonomy': |
|
123 | + case 'taxonomy_advanced': |
|
124 | + $field['taxonomy'] = $args['taxonomy']; |
|
125 | + break; |
|
126 | + case 'map': |
|
127 | + case 'osm': |
|
128 | + case 'oembed': |
|
129 | + $method = 'the_value'; |
|
130 | + break; |
|
131 | + } |
|
132 | + $field = RWMB_Field::call( 'normalize', $field ); |
|
133 | + |
|
134 | + return RWMB_Field::call( $method, $field, $args, $post_id ); |
|
135 | + } |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | if ( ! function_exists( 'rwmb_get_value' ) ) { |
139 | - /** |
|
140 | - * Get value of custom field. |
|
141 | - * This is used to replace old version of rwmb_meta key. |
|
142 | - * |
|
143 | - * @param string $field_id Field ID. Required. |
|
144 | - * @param array $args Additional arguments. Rarely used. See specific fields for details. |
|
145 | - * @param int|null $post_id Post ID. null for current post. Optional. |
|
146 | - * |
|
147 | - * @return mixed false if field doesn't exist. Field value otherwise. |
|
148 | - */ |
|
149 | - function rwmb_get_value( $field_id, $args = array(), $post_id = null ) { |
|
150 | - $args = wp_parse_args( $args ); |
|
151 | - $field = rwmb_get_field_settings( $field_id, $args, $post_id ); |
|
152 | - |
|
153 | - // Get field value. |
|
154 | - $value = $field ? RWMB_Field::call( 'get_value', $field, $args, $post_id ) : false; |
|
155 | - |
|
156 | - /* |
|
139 | + /** |
|
140 | + * Get value of custom field. |
|
141 | + * This is used to replace old version of rwmb_meta key. |
|
142 | + * |
|
143 | + * @param string $field_id Field ID. Required. |
|
144 | + * @param array $args Additional arguments. Rarely used. See specific fields for details. |
|
145 | + * @param int|null $post_id Post ID. null for current post. Optional. |
|
146 | + * |
|
147 | + * @return mixed false if field doesn't exist. Field value otherwise. |
|
148 | + */ |
|
149 | + function rwmb_get_value( $field_id, $args = array(), $post_id = null ) { |
|
150 | + $args = wp_parse_args( $args ); |
|
151 | + $field = rwmb_get_field_settings( $field_id, $args, $post_id ); |
|
152 | + |
|
153 | + // Get field value. |
|
154 | + $value = $field ? RWMB_Field::call( 'get_value', $field, $args, $post_id ) : false; |
|
155 | + |
|
156 | + /* |
|
157 | 157 | * Allow developers to change the returned value of field. |
158 | 158 | * For version < 4.8.2, the filter name was 'rwmb_get_field'. |
159 | 159 | * |
@@ -162,34 +162,34 @@ discard block |
||
162 | 162 | * @param array $args Additional arguments. Rarely used. See specific fields for details. |
163 | 163 | * @param int|null $post_id Post ID. null for current post. Optional. |
164 | 164 | */ |
165 | - $value = apply_filters( 'rwmb_get_value', $value, $field, $args, $post_id ); |
|
165 | + $value = apply_filters( 'rwmb_get_value', $value, $field, $args, $post_id ); |
|
166 | 166 | |
167 | - return $value; |
|
168 | - } |
|
167 | + return $value; |
|
168 | + } |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | if ( ! function_exists( 'rwmb_the_value' ) ) { |
172 | - /** |
|
173 | - * Display the value of a field |
|
174 | - * |
|
175 | - * @param string $field_id Field ID. Required. |
|
176 | - * @param array $args Additional arguments. Rarely used. See specific fields for details. |
|
177 | - * @param int|null $post_id Post ID. null for current post. Optional. |
|
178 | - * @param bool $echo Display field meta value? Default `true` which works in almost all cases. We use `false` for the [rwmb_meta] shortcode. |
|
179 | - * |
|
180 | - * @return string |
|
181 | - */ |
|
182 | - function rwmb_the_value( $field_id, $args = array(), $post_id = null, $echo = true ) { |
|
183 | - $args = wp_parse_args( $args ); |
|
184 | - $field = rwmb_get_field_settings( $field_id, $args, $post_id ); |
|
185 | - |
|
186 | - if ( ! $field ) { |
|
187 | - return ''; |
|
188 | - } |
|
189 | - |
|
190 | - $output = RWMB_Field::call( 'the_value', $field, $args, $post_id ); |
|
191 | - |
|
192 | - /* |
|
172 | + /** |
|
173 | + * Display the value of a field |
|
174 | + * |
|
175 | + * @param string $field_id Field ID. Required. |
|
176 | + * @param array $args Additional arguments. Rarely used. See specific fields for details. |
|
177 | + * @param int|null $post_id Post ID. null for current post. Optional. |
|
178 | + * @param bool $echo Display field meta value? Default `true` which works in almost all cases. We use `false` for the [rwmb_meta] shortcode. |
|
179 | + * |
|
180 | + * @return string |
|
181 | + */ |
|
182 | + function rwmb_the_value( $field_id, $args = array(), $post_id = null, $echo = true ) { |
|
183 | + $args = wp_parse_args( $args ); |
|
184 | + $field = rwmb_get_field_settings( $field_id, $args, $post_id ); |
|
185 | + |
|
186 | + if ( ! $field ) { |
|
187 | + return ''; |
|
188 | + } |
|
189 | + |
|
190 | + $output = RWMB_Field::call( 'the_value', $field, $args, $post_id ); |
|
191 | + |
|
192 | + /* |
|
193 | 193 | * Allow developers to change the returned value of field. |
194 | 194 | * For version < 4.8.2, the filter name was 'rwmb_get_field'. |
195 | 195 | * |
@@ -198,135 +198,135 @@ discard block |
||
198 | 198 | * @param array $args Additional arguments. Rarely used. See specific fields for details. |
199 | 199 | * @param int|null $post_id Post ID. null for current post. Optional. |
200 | 200 | */ |
201 | - $output = apply_filters( 'rwmb_the_value', $output, $field, $args, $post_id ); |
|
201 | + $output = apply_filters( 'rwmb_the_value', $output, $field, $args, $post_id ); |
|
202 | 202 | |
203 | - if ( $echo ) { |
|
204 | - echo $output; // WPCS: XSS OK. |
|
205 | - } |
|
203 | + if ( $echo ) { |
|
204 | + echo $output; // WPCS: XSS OK. |
|
205 | + } |
|
206 | 206 | |
207 | - return $output; |
|
208 | - } |
|
207 | + return $output; |
|
208 | + } |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | if ( ! function_exists( 'rwmb_get_object_fields' ) ) { |
212 | - /** |
|
213 | - * Get defined meta fields for object. |
|
214 | - * |
|
215 | - * @param int|string $type_or_id Object ID or post type / taxonomy (for terms) / user (for users). |
|
216 | - * @param string $object_type Object type. Use post, term. |
|
217 | - * |
|
218 | - * @return array |
|
219 | - */ |
|
220 | - function rwmb_get_object_fields( $type_or_id, $object_type = 'post' ) { |
|
221 | - $meta_boxes = rwmb_get_registry( 'meta_box' )->get_by( array( 'object_type' => $object_type ) ); |
|
222 | - array_walk( $meta_boxes, 'rwmb_check_meta_box_supports', array( $object_type, $type_or_id ) ); |
|
223 | - $meta_boxes = array_filter( $meta_boxes ); |
|
224 | - |
|
225 | - $fields = array(); |
|
226 | - foreach ( $meta_boxes as $meta_box ) { |
|
227 | - foreach ( $meta_box->fields as $field ) { |
|
228 | - $fields[ $field['id'] ] = $field; |
|
229 | - } |
|
230 | - } |
|
231 | - |
|
232 | - return $fields; |
|
233 | - } |
|
212 | + /** |
|
213 | + * Get defined meta fields for object. |
|
214 | + * |
|
215 | + * @param int|string $type_or_id Object ID or post type / taxonomy (for terms) / user (for users). |
|
216 | + * @param string $object_type Object type. Use post, term. |
|
217 | + * |
|
218 | + * @return array |
|
219 | + */ |
|
220 | + function rwmb_get_object_fields( $type_or_id, $object_type = 'post' ) { |
|
221 | + $meta_boxes = rwmb_get_registry( 'meta_box' )->get_by( array( 'object_type' => $object_type ) ); |
|
222 | + array_walk( $meta_boxes, 'rwmb_check_meta_box_supports', array( $object_type, $type_or_id ) ); |
|
223 | + $meta_boxes = array_filter( $meta_boxes ); |
|
224 | + |
|
225 | + $fields = array(); |
|
226 | + foreach ( $meta_boxes as $meta_box ) { |
|
227 | + foreach ( $meta_box->fields as $field ) { |
|
228 | + $fields[ $field['id'] ] = $field; |
|
229 | + } |
|
230 | + } |
|
231 | + |
|
232 | + return $fields; |
|
233 | + } |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | if ( ! function_exists( 'rwmb_check_meta_box_supports' ) ) { |
237 | - /** |
|
238 | - * Check if a meta box supports an object. |
|
239 | - * |
|
240 | - * @param object $meta_box Meta Box object. |
|
241 | - * @param int $key Not used. |
|
242 | - * @param array $object_data Object data (type and ID). |
|
243 | - */ |
|
244 | - function rwmb_check_meta_box_supports( &$meta_box, $key, $object_data ) { |
|
245 | - list( $object_type, $type_or_id ) = $object_data; |
|
246 | - |
|
247 | - $type = null; |
|
248 | - $prop = null; |
|
249 | - switch ( $object_type ) { |
|
250 | - case 'post': |
|
251 | - $type = is_numeric( $type_or_id ) ? get_post_type( $type_or_id ) : $type_or_id; |
|
252 | - $prop = 'post_types'; |
|
253 | - break; |
|
254 | - case 'term': |
|
255 | - $type = $type_or_id; |
|
256 | - if ( is_numeric( $type_or_id ) ) { |
|
257 | - $term = get_term( $type_or_id ); |
|
258 | - $type = is_array( $term ) ? $term->taxonomy : null; |
|
259 | - } |
|
260 | - $prop = 'taxonomies'; |
|
261 | - break; |
|
262 | - case 'user': |
|
263 | - $type = 'user'; |
|
264 | - $prop = 'user'; |
|
265 | - break; |
|
266 | - case 'setting': |
|
267 | - $type = $type_or_id; |
|
268 | - $prop = 'settings_pages'; |
|
269 | - break; |
|
270 | - } |
|
271 | - if ( ! $type ) { |
|
272 | - $meta_box = false; |
|
273 | - return; |
|
274 | - } |
|
275 | - if ( isset( $meta_box->meta_box[ $prop ] ) && ! in_array( $type, $meta_box->meta_box[ $prop ], true ) ) { |
|
276 | - $meta_box = false; |
|
277 | - } |
|
278 | - } |
|
237 | + /** |
|
238 | + * Check if a meta box supports an object. |
|
239 | + * |
|
240 | + * @param object $meta_box Meta Box object. |
|
241 | + * @param int $key Not used. |
|
242 | + * @param array $object_data Object data (type and ID). |
|
243 | + */ |
|
244 | + function rwmb_check_meta_box_supports( &$meta_box, $key, $object_data ) { |
|
245 | + list( $object_type, $type_or_id ) = $object_data; |
|
246 | + |
|
247 | + $type = null; |
|
248 | + $prop = null; |
|
249 | + switch ( $object_type ) { |
|
250 | + case 'post': |
|
251 | + $type = is_numeric( $type_or_id ) ? get_post_type( $type_or_id ) : $type_or_id; |
|
252 | + $prop = 'post_types'; |
|
253 | + break; |
|
254 | + case 'term': |
|
255 | + $type = $type_or_id; |
|
256 | + if ( is_numeric( $type_or_id ) ) { |
|
257 | + $term = get_term( $type_or_id ); |
|
258 | + $type = is_array( $term ) ? $term->taxonomy : null; |
|
259 | + } |
|
260 | + $prop = 'taxonomies'; |
|
261 | + break; |
|
262 | + case 'user': |
|
263 | + $type = 'user'; |
|
264 | + $prop = 'user'; |
|
265 | + break; |
|
266 | + case 'setting': |
|
267 | + $type = $type_or_id; |
|
268 | + $prop = 'settings_pages'; |
|
269 | + break; |
|
270 | + } |
|
271 | + if ( ! $type ) { |
|
272 | + $meta_box = false; |
|
273 | + return; |
|
274 | + } |
|
275 | + if ( isset( $meta_box->meta_box[ $prop ] ) && ! in_array( $type, $meta_box->meta_box[ $prop ], true ) ) { |
|
276 | + $meta_box = false; |
|
277 | + } |
|
278 | + } |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | if ( ! function_exists( 'rwmb_get_registry' ) ) { |
282 | - /** |
|
283 | - * Get the registry by type. |
|
284 | - * Always return the same instance of the registry. |
|
285 | - * |
|
286 | - * @param string $type Registry type. |
|
287 | - * |
|
288 | - * @return object |
|
289 | - */ |
|
290 | - function rwmb_get_registry( $type ) { |
|
291 | - static $data = array(); |
|
292 | - |
|
293 | - $class = 'RWMB_' . RWMB_Helpers_String::title_case( $type ) . '_Registry'; |
|
294 | - if ( ! isset( $data[ $type ] ) ) { |
|
295 | - $data[ $type ] = new $class(); |
|
296 | - } |
|
297 | - |
|
298 | - return $data[ $type ]; |
|
299 | - } |
|
282 | + /** |
|
283 | + * Get the registry by type. |
|
284 | + * Always return the same instance of the registry. |
|
285 | + * |
|
286 | + * @param string $type Registry type. |
|
287 | + * |
|
288 | + * @return object |
|
289 | + */ |
|
290 | + function rwmb_get_registry( $type ) { |
|
291 | + static $data = array(); |
|
292 | + |
|
293 | + $class = 'RWMB_' . RWMB_Helpers_String::title_case( $type ) . '_Registry'; |
|
294 | + if ( ! isset( $data[ $type ] ) ) { |
|
295 | + $data[ $type ] = new $class(); |
|
296 | + } |
|
297 | + |
|
298 | + return $data[ $type ]; |
|
299 | + } |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | if ( ! function_exists( 'rwmb_get_storage' ) ) { |
303 | - /** |
|
304 | - * Get storage instance. |
|
305 | - * |
|
306 | - * @param string $object_type Object type. Use post or term. |
|
307 | - * @param RW_Meta_Box $meta_box Meta box object. Optional. |
|
308 | - * @return RWMB_Storage_Interface |
|
309 | - */ |
|
310 | - function rwmb_get_storage( $object_type, $meta_box = null ) { |
|
311 | - $class = 'RWMB_' . RWMB_Helpers_String::title_case( $object_type ) . '_Storage'; |
|
312 | - $class = class_exists( $class ) ? $class : 'RWMB_Post_Storage'; |
|
313 | - $storage = rwmb_get_registry( 'storage' )->get( $class ); |
|
314 | - |
|
315 | - return apply_filters( 'rwmb_get_storage', $storage, $object_type, $meta_box ); |
|
316 | - } |
|
303 | + /** |
|
304 | + * Get storage instance. |
|
305 | + * |
|
306 | + * @param string $object_type Object type. Use post or term. |
|
307 | + * @param RW_Meta_Box $meta_box Meta box object. Optional. |
|
308 | + * @return RWMB_Storage_Interface |
|
309 | + */ |
|
310 | + function rwmb_get_storage( $object_type, $meta_box = null ) { |
|
311 | + $class = 'RWMB_' . RWMB_Helpers_String::title_case( $object_type ) . '_Storage'; |
|
312 | + $class = class_exists( $class ) ? $class : 'RWMB_Post_Storage'; |
|
313 | + $storage = rwmb_get_registry( 'storage' )->get( $class ); |
|
314 | + |
|
315 | + return apply_filters( 'rwmb_get_storage', $storage, $object_type, $meta_box ); |
|
316 | + } |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | if ( ! function_exists( 'rwmb_request' ) ) { |
320 | - /** |
|
321 | - * Get request object. |
|
322 | - * |
|
323 | - * @return RWMB_Request |
|
324 | - */ |
|
325 | - function rwmb_request() { |
|
326 | - static $request; |
|
327 | - if ( ! $request ) { |
|
328 | - $request = new RWMB_Request(); |
|
329 | - } |
|
330 | - return $request; |
|
331 | - } |
|
320 | + /** |
|
321 | + * Get request object. |
|
322 | + * |
|
323 | + * @return RWMB_Request |
|
324 | + */ |
|
325 | + function rwmb_request() { |
|
326 | + static $request; |
|
327 | + if ( ! $request ) { |
|
328 | + $request = new RWMB_Request(); |
|
329 | + } |
|
330 | + return $request; |
|
331 | + } |
|
332 | 332 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * @package Meta Box |
6 | 6 | */ |
7 | 7 | |
8 | -if ( ! function_exists( 'rwmb_meta' ) ) { |
|
8 | +if (!function_exists('rwmb_meta')) { |
|
9 | 9 | /** |
10 | 10 | * Get post meta. |
11 | 11 | * |
@@ -15,25 +15,24 @@ discard block |
||
15 | 15 | * |
16 | 16 | * @return mixed |
17 | 17 | */ |
18 | - function rwmb_meta( $key, $args = array(), $post_id = null ) { |
|
19 | - $args = wp_parse_args( $args ); |
|
20 | - $field = rwmb_get_field_settings( $key, $args, $post_id ); |
|
18 | + function rwmb_meta($key, $args = array(), $post_id = null) { |
|
19 | + $args = wp_parse_args($args); |
|
20 | + $field = rwmb_get_field_settings($key, $args, $post_id); |
|
21 | 21 | |
22 | 22 | /* |
23 | 23 | * If field is not found, which can caused by registering meta boxes for the backend only or conditional registration. |
24 | 24 | * Then fallback to the old method to retrieve meta (which uses get_post_meta() as the latest fallback). |
25 | 25 | */ |
26 | - if ( false === $field ) { |
|
27 | - return apply_filters( 'rwmb_meta', rwmb_meta_legacy( $key, $args, $post_id ) ); |
|
26 | + if (false === $field) { |
|
27 | + return apply_filters('rwmb_meta', rwmb_meta_legacy($key, $args, $post_id)); |
|
28 | 28 | } |
29 | - $meta = in_array( $field['type'], array( 'oembed', 'map', 'osm' ), true ) ? |
|
30 | - rwmb_the_value( $key, $args, $post_id, false ) : |
|
31 | - rwmb_get_value( $key, $args, $post_id ); |
|
32 | - return apply_filters( 'rwmb_meta', $meta, $key, $args, $post_id ); |
|
29 | + $meta = in_array($field['type'], array('oembed', 'map', 'osm'), true) ? |
|
30 | + rwmb_the_value($key, $args, $post_id, false) : rwmb_get_value($key, $args, $post_id); |
|
31 | + return apply_filters('rwmb_meta', $meta, $key, $args, $post_id); |
|
33 | 32 | } |
34 | 33 | } |
35 | 34 | |
36 | -if ( ! function_exists( 'rwmb_set_meta' ) ) { |
|
35 | +if (!function_exists('rwmb_set_meta')) { |
|
37 | 36 | /** |
38 | 37 | * Set meta value. |
39 | 38 | * |
@@ -42,21 +41,21 @@ discard block |
||
42 | 41 | * @param string $value Meta value. Required. |
43 | 42 | * @param array $args Array of arguments. Optional. |
44 | 43 | */ |
45 | - function rwmb_set_meta( $object_id, $key, $value, $args = array() ) { |
|
46 | - $args = wp_parse_args( $args ); |
|
47 | - $field = rwmb_get_field_settings( $key, $args, $object_id ); |
|
44 | + function rwmb_set_meta($object_id, $key, $value, $args = array()) { |
|
45 | + $args = wp_parse_args($args); |
|
46 | + $field = rwmb_get_field_settings($key, $args, $object_id); |
|
48 | 47 | |
49 | - if ( false === $field ) { |
|
48 | + if (false === $field) { |
|
50 | 49 | return; |
51 | 50 | } |
52 | 51 | |
53 | - $old = RWMB_Field::call( $field, 'raw_meta', $object_id ); |
|
54 | - $new = RWMB_Field::process_value( $value, $object_id, $field ); |
|
55 | - RWMB_Field::call( $field, 'save', $new, $old, $object_id ); |
|
52 | + $old = RWMB_Field::call($field, 'raw_meta', $object_id); |
|
53 | + $new = RWMB_Field::process_value($value, $object_id, $field); |
|
54 | + RWMB_Field::call($field, 'save', $new, $old, $object_id); |
|
56 | 55 | } |
57 | 56 | } |
58 | 57 | |
59 | -if ( ! function_exists( 'rwmb_get_field_settings' ) ) { |
|
58 | +if (!function_exists('rwmb_get_field_settings')) { |
|
60 | 59 | /** |
61 | 60 | * Get field settings. |
62 | 61 | * |
@@ -66,7 +65,7 @@ discard block |
||
66 | 65 | * |
67 | 66 | * @return array |
68 | 67 | */ |
69 | - function rwmb_get_field_settings( $key, $args = array(), $object_id = null ) { |
|
68 | + function rwmb_get_field_settings($key, $args = array(), $object_id = null) { |
|
70 | 69 | $args = wp_parse_args( |
71 | 70 | $args, |
72 | 71 | array( |
@@ -82,16 +81,16 @@ discard block |
||
82 | 81 | * @var string Object type. |
83 | 82 | * @var string|int Object id. |
84 | 83 | */ |
85 | - $type = apply_filters( 'rwmb_meta_type', $args['type'], $args['object_type'], $object_id ); |
|
86 | - if ( ! $type ) { |
|
87 | - $type = get_post_type( $object_id ); |
|
84 | + $type = apply_filters('rwmb_meta_type', $args['type'], $args['object_type'], $object_id); |
|
85 | + if (!$type) { |
|
86 | + $type = get_post_type($object_id); |
|
88 | 87 | } |
89 | 88 | |
90 | - return rwmb_get_registry( 'field' )->get( $key, $type, $args['object_type'] ); |
|
89 | + return rwmb_get_registry('field')->get($key, $type, $args['object_type']); |
|
91 | 90 | } |
92 | 91 | } |
93 | 92 | |
94 | -if ( ! function_exists( 'rwmb_meta_legacy' ) ) { |
|
93 | +if (!function_exists('rwmb_meta_legacy')) { |
|
95 | 94 | /** |
96 | 95 | * Get post meta. |
97 | 96 | * |
@@ -101,8 +100,8 @@ discard block |
||
101 | 100 | * |
102 | 101 | * @return mixed |
103 | 102 | */ |
104 | - function rwmb_meta_legacy( $key, $args = array(), $post_id = null ) { |
|
105 | - $args = wp_parse_args( |
|
103 | + function rwmb_meta_legacy($key, $args = array(), $post_id = null) { |
|
104 | + $args = wp_parse_args( |
|
106 | 105 | $args, |
107 | 106 | array( |
108 | 107 | 'type' => 'text', |
@@ -118,7 +117,7 @@ discard block |
||
118 | 117 | ); |
119 | 118 | |
120 | 119 | $method = 'get_value'; |
121 | - switch ( $args['type'] ) { |
|
120 | + switch ($args['type']) { |
|
122 | 121 | case 'taxonomy': |
123 | 122 | case 'taxonomy_advanced': |
124 | 123 | $field['taxonomy'] = $args['taxonomy']; |
@@ -129,13 +128,13 @@ discard block |
||
129 | 128 | $method = 'the_value'; |
130 | 129 | break; |
131 | 130 | } |
132 | - $field = RWMB_Field::call( 'normalize', $field ); |
|
131 | + $field = RWMB_Field::call('normalize', $field); |
|
133 | 132 | |
134 | - return RWMB_Field::call( $method, $field, $args, $post_id ); |
|
133 | + return RWMB_Field::call($method, $field, $args, $post_id); |
|
135 | 134 | } |
136 | 135 | } |
137 | 136 | |
138 | -if ( ! function_exists( 'rwmb_get_value' ) ) { |
|
137 | +if (!function_exists('rwmb_get_value')) { |
|
139 | 138 | /** |
140 | 139 | * Get value of custom field. |
141 | 140 | * This is used to replace old version of rwmb_meta key. |
@@ -146,12 +145,12 @@ discard block |
||
146 | 145 | * |
147 | 146 | * @return mixed false if field doesn't exist. Field value otherwise. |
148 | 147 | */ |
149 | - function rwmb_get_value( $field_id, $args = array(), $post_id = null ) { |
|
150 | - $args = wp_parse_args( $args ); |
|
151 | - $field = rwmb_get_field_settings( $field_id, $args, $post_id ); |
|
148 | + function rwmb_get_value($field_id, $args = array(), $post_id = null) { |
|
149 | + $args = wp_parse_args($args); |
|
150 | + $field = rwmb_get_field_settings($field_id, $args, $post_id); |
|
152 | 151 | |
153 | 152 | // Get field value. |
154 | - $value = $field ? RWMB_Field::call( 'get_value', $field, $args, $post_id ) : false; |
|
153 | + $value = $field ? RWMB_Field::call('get_value', $field, $args, $post_id) : false; |
|
155 | 154 | |
156 | 155 | /* |
157 | 156 | * Allow developers to change the returned value of field. |
@@ -162,13 +161,13 @@ discard block |
||
162 | 161 | * @param array $args Additional arguments. Rarely used. See specific fields for details. |
163 | 162 | * @param int|null $post_id Post ID. null for current post. Optional. |
164 | 163 | */ |
165 | - $value = apply_filters( 'rwmb_get_value', $value, $field, $args, $post_id ); |
|
164 | + $value = apply_filters('rwmb_get_value', $value, $field, $args, $post_id); |
|
166 | 165 | |
167 | 166 | return $value; |
168 | 167 | } |
169 | 168 | } |
170 | 169 | |
171 | -if ( ! function_exists( 'rwmb_the_value' ) ) { |
|
170 | +if (!function_exists('rwmb_the_value')) { |
|
172 | 171 | /** |
173 | 172 | * Display the value of a field |
174 | 173 | * |
@@ -179,15 +178,15 @@ discard block |
||
179 | 178 | * |
180 | 179 | * @return string |
181 | 180 | */ |
182 | - function rwmb_the_value( $field_id, $args = array(), $post_id = null, $echo = true ) { |
|
183 | - $args = wp_parse_args( $args ); |
|
184 | - $field = rwmb_get_field_settings( $field_id, $args, $post_id ); |
|
181 | + function rwmb_the_value($field_id, $args = array(), $post_id = null, $echo = true) { |
|
182 | + $args = wp_parse_args($args); |
|
183 | + $field = rwmb_get_field_settings($field_id, $args, $post_id); |
|
185 | 184 | |
186 | - if ( ! $field ) { |
|
185 | + if (!$field) { |
|
187 | 186 | return ''; |
188 | 187 | } |
189 | 188 | |
190 | - $output = RWMB_Field::call( 'the_value', $field, $args, $post_id ); |
|
189 | + $output = RWMB_Field::call('the_value', $field, $args, $post_id); |
|
191 | 190 | |
192 | 191 | /* |
193 | 192 | * Allow developers to change the returned value of field. |
@@ -198,9 +197,9 @@ discard block |
||
198 | 197 | * @param array $args Additional arguments. Rarely used. See specific fields for details. |
199 | 198 | * @param int|null $post_id Post ID. null for current post. Optional. |
200 | 199 | */ |
201 | - $output = apply_filters( 'rwmb_the_value', $output, $field, $args, $post_id ); |
|
200 | + $output = apply_filters('rwmb_the_value', $output, $field, $args, $post_id); |
|
202 | 201 | |
203 | - if ( $echo ) { |
|
202 | + if ($echo) { |
|
204 | 203 | echo $output; // WPCS: XSS OK. |
205 | 204 | } |
206 | 205 | |
@@ -208,7 +207,7 @@ discard block |
||
208 | 207 | } |
209 | 208 | } |
210 | 209 | |
211 | -if ( ! function_exists( 'rwmb_get_object_fields' ) ) { |
|
210 | +if (!function_exists('rwmb_get_object_fields')) { |
|
212 | 211 | /** |
213 | 212 | * Get defined meta fields for object. |
214 | 213 | * |
@@ -217,15 +216,15 @@ discard block |
||
217 | 216 | * |
218 | 217 | * @return array |
219 | 218 | */ |
220 | - function rwmb_get_object_fields( $type_or_id, $object_type = 'post' ) { |
|
221 | - $meta_boxes = rwmb_get_registry( 'meta_box' )->get_by( array( 'object_type' => $object_type ) ); |
|
222 | - array_walk( $meta_boxes, 'rwmb_check_meta_box_supports', array( $object_type, $type_or_id ) ); |
|
223 | - $meta_boxes = array_filter( $meta_boxes ); |
|
219 | + function rwmb_get_object_fields($type_or_id, $object_type = 'post') { |
|
220 | + $meta_boxes = rwmb_get_registry('meta_box')->get_by(array('object_type' => $object_type)); |
|
221 | + array_walk($meta_boxes, 'rwmb_check_meta_box_supports', array($object_type, $type_or_id)); |
|
222 | + $meta_boxes = array_filter($meta_boxes); |
|
224 | 223 | |
225 | 224 | $fields = array(); |
226 | - foreach ( $meta_boxes as $meta_box ) { |
|
227 | - foreach ( $meta_box->fields as $field ) { |
|
228 | - $fields[ $field['id'] ] = $field; |
|
225 | + foreach ($meta_boxes as $meta_box) { |
|
226 | + foreach ($meta_box->fields as $field) { |
|
227 | + $fields[$field['id']] = $field; |
|
229 | 228 | } |
230 | 229 | } |
231 | 230 | |
@@ -233,7 +232,7 @@ discard block |
||
233 | 232 | } |
234 | 233 | } |
235 | 234 | |
236 | -if ( ! function_exists( 'rwmb_check_meta_box_supports' ) ) { |
|
235 | +if (!function_exists('rwmb_check_meta_box_supports')) { |
|
237 | 236 | /** |
238 | 237 | * Check if a meta box supports an object. |
239 | 238 | * |
@@ -241,21 +240,21 @@ discard block |
||
241 | 240 | * @param int $key Not used. |
242 | 241 | * @param array $object_data Object data (type and ID). |
243 | 242 | */ |
244 | - function rwmb_check_meta_box_supports( &$meta_box, $key, $object_data ) { |
|
245 | - list( $object_type, $type_or_id ) = $object_data; |
|
243 | + function rwmb_check_meta_box_supports(&$meta_box, $key, $object_data) { |
|
244 | + list($object_type, $type_or_id) = $object_data; |
|
246 | 245 | |
247 | 246 | $type = null; |
248 | 247 | $prop = null; |
249 | - switch ( $object_type ) { |
|
248 | + switch ($object_type) { |
|
250 | 249 | case 'post': |
251 | - $type = is_numeric( $type_or_id ) ? get_post_type( $type_or_id ) : $type_or_id; |
|
250 | + $type = is_numeric($type_or_id) ? get_post_type($type_or_id) : $type_or_id; |
|
252 | 251 | $prop = 'post_types'; |
253 | 252 | break; |
254 | 253 | case 'term': |
255 | 254 | $type = $type_or_id; |
256 | - if ( is_numeric( $type_or_id ) ) { |
|
257 | - $term = get_term( $type_or_id ); |
|
258 | - $type = is_array( $term ) ? $term->taxonomy : null; |
|
255 | + if (is_numeric($type_or_id)) { |
|
256 | + $term = get_term($type_or_id); |
|
257 | + $type = is_array($term) ? $term->taxonomy : null; |
|
259 | 258 | } |
260 | 259 | $prop = 'taxonomies'; |
261 | 260 | break; |
@@ -268,17 +267,17 @@ discard block |
||
268 | 267 | $prop = 'settings_pages'; |
269 | 268 | break; |
270 | 269 | } |
271 | - if ( ! $type ) { |
|
270 | + if (!$type) { |
|
272 | 271 | $meta_box = false; |
273 | 272 | return; |
274 | 273 | } |
275 | - if ( isset( $meta_box->meta_box[ $prop ] ) && ! in_array( $type, $meta_box->meta_box[ $prop ], true ) ) { |
|
274 | + if (isset($meta_box->meta_box[$prop]) && !in_array($type, $meta_box->meta_box[$prop], true)) { |
|
276 | 275 | $meta_box = false; |
277 | 276 | } |
278 | 277 | } |
279 | 278 | } |
280 | 279 | |
281 | -if ( ! function_exists( 'rwmb_get_registry' ) ) { |
|
280 | +if (!function_exists('rwmb_get_registry')) { |
|
282 | 281 | /** |
283 | 282 | * Get the registry by type. |
284 | 283 | * Always return the same instance of the registry. |
@@ -287,19 +286,19 @@ discard block |
||
287 | 286 | * |
288 | 287 | * @return object |
289 | 288 | */ |
290 | - function rwmb_get_registry( $type ) { |
|
289 | + function rwmb_get_registry($type) { |
|
291 | 290 | static $data = array(); |
292 | 291 | |
293 | - $class = 'RWMB_' . RWMB_Helpers_String::title_case( $type ) . '_Registry'; |
|
294 | - if ( ! isset( $data[ $type ] ) ) { |
|
295 | - $data[ $type ] = new $class(); |
|
292 | + $class = 'RWMB_' . RWMB_Helpers_String::title_case($type) . '_Registry'; |
|
293 | + if (!isset($data[$type])) { |
|
294 | + $data[$type] = new $class(); |
|
296 | 295 | } |
297 | 296 | |
298 | - return $data[ $type ]; |
|
297 | + return $data[$type]; |
|
299 | 298 | } |
300 | 299 | } |
301 | 300 | |
302 | -if ( ! function_exists( 'rwmb_get_storage' ) ) { |
|
301 | +if (!function_exists('rwmb_get_storage')) { |
|
303 | 302 | /** |
304 | 303 | * Get storage instance. |
305 | 304 | * |
@@ -307,16 +306,16 @@ discard block |
||
307 | 306 | * @param RW_Meta_Box $meta_box Meta box object. Optional. |
308 | 307 | * @return RWMB_Storage_Interface |
309 | 308 | */ |
310 | - function rwmb_get_storage( $object_type, $meta_box = null ) { |
|
311 | - $class = 'RWMB_' . RWMB_Helpers_String::title_case( $object_type ) . '_Storage'; |
|
312 | - $class = class_exists( $class ) ? $class : 'RWMB_Post_Storage'; |
|
313 | - $storage = rwmb_get_registry( 'storage' )->get( $class ); |
|
309 | + function rwmb_get_storage($object_type, $meta_box = null) { |
|
310 | + $class = 'RWMB_' . RWMB_Helpers_String::title_case($object_type) . '_Storage'; |
|
311 | + $class = class_exists($class) ? $class : 'RWMB_Post_Storage'; |
|
312 | + $storage = rwmb_get_registry('storage')->get($class); |
|
314 | 313 | |
315 | - return apply_filters( 'rwmb_get_storage', $storage, $object_type, $meta_box ); |
|
314 | + return apply_filters('rwmb_get_storage', $storage, $object_type, $meta_box); |
|
316 | 315 | } |
317 | 316 | } |
318 | 317 | |
319 | -if ( ! function_exists( 'rwmb_request' ) ) { |
|
318 | +if (!function_exists('rwmb_request')) { |
|
320 | 319 | /** |
321 | 320 | * Get request object. |
322 | 321 | * |
@@ -324,7 +323,7 @@ discard block |
||
324 | 323 | */ |
325 | 324 | function rwmb_request() { |
326 | 325 | static $request; |
327 | - if ( ! $request ) { |
|
326 | + if (!$request) { |
|
328 | 327 | $request = new RWMB_Request(); |
329 | 328 | } |
330 | 329 | return $request; |
@@ -9,272 +9,272 @@ |
||
9 | 9 | * Sanitize class. |
10 | 10 | */ |
11 | 11 | class RWMB_Sanitizer { |
12 | - /** |
|
13 | - * Register hook to sanitize field value. |
|
14 | - */ |
|
15 | - public function init() { |
|
16 | - add_filter( 'rwmb_sanitize', array( $this, 'sanitize' ), 10, 4 ); |
|
17 | - } |
|
12 | + /** |
|
13 | + * Register hook to sanitize field value. |
|
14 | + */ |
|
15 | + public function init() { |
|
16 | + add_filter( 'rwmb_sanitize', array( $this, 'sanitize' ), 10, 4 ); |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * Sanitize a field value. |
|
21 | - * |
|
22 | - * @param mixed $value The submitted new value. |
|
23 | - * @param array $field The field settings. |
|
24 | - * @param mixed $old_value The old field value in the database. |
|
25 | - * @param int $object_id The object ID. |
|
26 | - */ |
|
27 | - public function sanitize( $value, $field, $old_value = null, $object_id = null ) { |
|
28 | - // Allow developers to bypass the sanitization. |
|
29 | - if ( 'none' === $field['sanitize_callback'] ) { |
|
30 | - return $value; |
|
31 | - } |
|
19 | + /** |
|
20 | + * Sanitize a field value. |
|
21 | + * |
|
22 | + * @param mixed $value The submitted new value. |
|
23 | + * @param array $field The field settings. |
|
24 | + * @param mixed $old_value The old field value in the database. |
|
25 | + * @param int $object_id The object ID. |
|
26 | + */ |
|
27 | + public function sanitize( $value, $field, $old_value = null, $object_id = null ) { |
|
28 | + // Allow developers to bypass the sanitization. |
|
29 | + if ( 'none' === $field['sanitize_callback'] ) { |
|
30 | + return $value; |
|
31 | + } |
|
32 | 32 | |
33 | - $callback = $this->get_callback( $field ); |
|
33 | + $callback = $this->get_callback( $field ); |
|
34 | 34 | |
35 | - return is_callable( $callback ) ? call_user_func( $callback, $value, $field, $old_value, $object_id ) : $value; |
|
36 | - } |
|
35 | + return is_callable( $callback ) ? call_user_func( $callback, $value, $field, $old_value, $object_id ) : $value; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Get sanitize callback for a field. |
|
40 | - * |
|
41 | - * @param array $field Field settings. |
|
42 | - * @return callable |
|
43 | - */ |
|
44 | - private function get_callback( $field ) { |
|
45 | - // User-defined callback. |
|
46 | - if ( is_callable( $field['sanitize_callback'] ) ) { |
|
47 | - return $field['sanitize_callback']; |
|
48 | - } |
|
38 | + /** |
|
39 | + * Get sanitize callback for a field. |
|
40 | + * |
|
41 | + * @param array $field Field settings. |
|
42 | + * @return callable |
|
43 | + */ |
|
44 | + private function get_callback( $field ) { |
|
45 | + // User-defined callback. |
|
46 | + if ( is_callable( $field['sanitize_callback'] ) ) { |
|
47 | + return $field['sanitize_callback']; |
|
48 | + } |
|
49 | 49 | |
50 | - $callbacks = array( |
|
51 | - 'autocomplete' => array( $this, 'sanitize_choice' ), |
|
52 | - 'background' => array( $this, 'sanitize_background' ), |
|
53 | - 'button_group' => array( $this, 'sanitize_choice' ), |
|
54 | - 'checkbox' => array( $this, 'sanitize_checkbox' ), |
|
55 | - 'checkbox_list' => array( $this, 'sanitize_choice' ), |
|
56 | - 'color' => array( $this, 'sanitize_color' ), |
|
57 | - 'date' => array( $this, 'sanitize_datetime' ), |
|
58 | - 'datetime' => array( $this, 'sanitize_datetime' ), |
|
59 | - 'email' => 'sanitize_email', |
|
60 | - 'fieldset_text' => array( $this, 'sanitize_text' ), |
|
61 | - 'file' => array( $this, 'sanitize_file' ), |
|
62 | - 'file_advanced' => array( $this, 'sanitize_object' ), |
|
63 | - 'file_input' => array( $this, 'sanitize_url' ), |
|
64 | - 'file_upload' => array( $this, 'sanitize_object' ), |
|
65 | - 'hidden' => 'sanitize_text_field', |
|
66 | - 'image' => array( $this, 'sanitize_file' ), |
|
67 | - 'image_advanced' => array( $this, 'sanitize_object' ), |
|
68 | - 'image_select' => array( $this, 'sanitize_choice' ), |
|
69 | - 'image_upload' => array( $this, 'sanitize_object' ), |
|
70 | - 'key_value' => array( $this, 'sanitize_text' ), |
|
71 | - 'map' => array( $this, 'sanitize_map' ), |
|
72 | - 'number' => array( $this, 'sanitize_number' ), |
|
73 | - 'oembed' => array( $this, 'sanitize_url' ), |
|
74 | - 'osm' => array( $this, 'sanitize_map' ), |
|
75 | - 'password' => 'sanitize_text_field', |
|
76 | - 'post' => array( $this, 'sanitize_object' ), |
|
77 | - 'radio' => array( $this, 'sanitize_choice' ), |
|
78 | - 'range' => array( $this, 'sanitize_number' ), |
|
79 | - 'select' => array( $this, 'sanitize_choice' ), |
|
80 | - 'select_advanced' => array( $this, 'sanitize_choice' ), |
|
81 | - 'sidebar' => array( $this, 'sanitize_text' ), |
|
82 | - 'single_image' => 'absint', |
|
83 | - 'slider' => array( $this, 'sanitize_slider' ), |
|
84 | - 'switch' => array( $this, 'sanitize_checkbox' ), |
|
85 | - 'taxonomy' => array( $this, 'sanitize_object' ), |
|
86 | - 'taxonomy_advanced' => array( $this, 'sanitize_taxonomy_advanced' ), |
|
87 | - 'text' => 'sanitize_text_field', |
|
88 | - 'text_list' => array( $this, 'sanitize_text' ), |
|
89 | - 'textarea' => 'wp_kses_post', |
|
90 | - 'time' => 'sanitize_text_field', |
|
91 | - 'url' => array( $this, 'sanitize_url' ), |
|
92 | - 'user' => array( $this, 'sanitize_object' ), |
|
93 | - 'video' => array( $this, 'sanitize_object' ), |
|
94 | - 'wysiwyg' => 'wp_kses_post', |
|
95 | - ); |
|
50 | + $callbacks = array( |
|
51 | + 'autocomplete' => array( $this, 'sanitize_choice' ), |
|
52 | + 'background' => array( $this, 'sanitize_background' ), |
|
53 | + 'button_group' => array( $this, 'sanitize_choice' ), |
|
54 | + 'checkbox' => array( $this, 'sanitize_checkbox' ), |
|
55 | + 'checkbox_list' => array( $this, 'sanitize_choice' ), |
|
56 | + 'color' => array( $this, 'sanitize_color' ), |
|
57 | + 'date' => array( $this, 'sanitize_datetime' ), |
|
58 | + 'datetime' => array( $this, 'sanitize_datetime' ), |
|
59 | + 'email' => 'sanitize_email', |
|
60 | + 'fieldset_text' => array( $this, 'sanitize_text' ), |
|
61 | + 'file' => array( $this, 'sanitize_file' ), |
|
62 | + 'file_advanced' => array( $this, 'sanitize_object' ), |
|
63 | + 'file_input' => array( $this, 'sanitize_url' ), |
|
64 | + 'file_upload' => array( $this, 'sanitize_object' ), |
|
65 | + 'hidden' => 'sanitize_text_field', |
|
66 | + 'image' => array( $this, 'sanitize_file' ), |
|
67 | + 'image_advanced' => array( $this, 'sanitize_object' ), |
|
68 | + 'image_select' => array( $this, 'sanitize_choice' ), |
|
69 | + 'image_upload' => array( $this, 'sanitize_object' ), |
|
70 | + 'key_value' => array( $this, 'sanitize_text' ), |
|
71 | + 'map' => array( $this, 'sanitize_map' ), |
|
72 | + 'number' => array( $this, 'sanitize_number' ), |
|
73 | + 'oembed' => array( $this, 'sanitize_url' ), |
|
74 | + 'osm' => array( $this, 'sanitize_map' ), |
|
75 | + 'password' => 'sanitize_text_field', |
|
76 | + 'post' => array( $this, 'sanitize_object' ), |
|
77 | + 'radio' => array( $this, 'sanitize_choice' ), |
|
78 | + 'range' => array( $this, 'sanitize_number' ), |
|
79 | + 'select' => array( $this, 'sanitize_choice' ), |
|
80 | + 'select_advanced' => array( $this, 'sanitize_choice' ), |
|
81 | + 'sidebar' => array( $this, 'sanitize_text' ), |
|
82 | + 'single_image' => 'absint', |
|
83 | + 'slider' => array( $this, 'sanitize_slider' ), |
|
84 | + 'switch' => array( $this, 'sanitize_checkbox' ), |
|
85 | + 'taxonomy' => array( $this, 'sanitize_object' ), |
|
86 | + 'taxonomy_advanced' => array( $this, 'sanitize_taxonomy_advanced' ), |
|
87 | + 'text' => 'sanitize_text_field', |
|
88 | + 'text_list' => array( $this, 'sanitize_text' ), |
|
89 | + 'textarea' => 'wp_kses_post', |
|
90 | + 'time' => 'sanitize_text_field', |
|
91 | + 'url' => array( $this, 'sanitize_url' ), |
|
92 | + 'user' => array( $this, 'sanitize_object' ), |
|
93 | + 'video' => array( $this, 'sanitize_object' ), |
|
94 | + 'wysiwyg' => 'wp_kses_post', |
|
95 | + ); |
|
96 | 96 | |
97 | - $type = $field['type']; |
|
97 | + $type = $field['type']; |
|
98 | 98 | |
99 | - return isset( $callbacks[ $type ] ) ? $callbacks[ $type ] : null; |
|
100 | - } |
|
99 | + return isset( $callbacks[ $type ] ) ? $callbacks[ $type ] : null; |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Set the value of checkbox to 1 or 0 instead of 'checked' and empty string. |
|
104 | - * This prevents using default value once the checkbox has been unchecked. |
|
105 | - * |
|
106 | - * @link https://github.com/rilwis/meta-box/issues/6 |
|
107 | - * @param string $value Checkbox value. |
|
108 | - * @return int |
|
109 | - */ |
|
110 | - private function sanitize_checkbox( $value ) { |
|
111 | - return (int) ! empty( $value ); |
|
112 | - } |
|
102 | + /** |
|
103 | + * Set the value of checkbox to 1 or 0 instead of 'checked' and empty string. |
|
104 | + * This prevents using default value once the checkbox has been unchecked. |
|
105 | + * |
|
106 | + * @link https://github.com/rilwis/meta-box/issues/6 |
|
107 | + * @param string $value Checkbox value. |
|
108 | + * @return int |
|
109 | + */ |
|
110 | + private function sanitize_checkbox( $value ) { |
|
111 | + return (int) ! empty( $value ); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Sanitize numeric value. |
|
116 | - * |
|
117 | - * @param string $value The number value. |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - private function sanitize_number( $value ) { |
|
121 | - return is_numeric( $value ) ? $value : ''; |
|
122 | - } |
|
114 | + /** |
|
115 | + * Sanitize numeric value. |
|
116 | + * |
|
117 | + * @param string $value The number value. |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + private function sanitize_number( $value ) { |
|
121 | + return is_numeric( $value ) ? $value : ''; |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * Sanitize color value. |
|
126 | - * |
|
127 | - * @param string $value The color value. |
|
128 | - * @return string |
|
129 | - */ |
|
130 | - private function sanitize_color( $value ) { |
|
131 | - if ( false === strpos( $value, 'rgba' ) ) { |
|
132 | - return sanitize_hex_color( $value ); |
|
133 | - } |
|
124 | + /** |
|
125 | + * Sanitize color value. |
|
126 | + * |
|
127 | + * @param string $value The color value. |
|
128 | + * @return string |
|
129 | + */ |
|
130 | + private function sanitize_color( $value ) { |
|
131 | + if ( false === strpos( $value, 'rgba' ) ) { |
|
132 | + return sanitize_hex_color( $value ); |
|
133 | + } |
|
134 | 134 | |
135 | - // rgba value. |
|
136 | - $red = ''; |
|
137 | - $green = ''; |
|
138 | - $blue = ''; |
|
139 | - $alpha = ''; |
|
140 | - sscanf( $value, 'rgba(%d,%d,%d,%f)', $red, $green, $blue, $alpha ); |
|
135 | + // rgba value. |
|
136 | + $red = ''; |
|
137 | + $green = ''; |
|
138 | + $blue = ''; |
|
139 | + $alpha = ''; |
|
140 | + sscanf( $value, 'rgba(%d,%d,%d,%f)', $red, $green, $blue, $alpha ); |
|
141 | 141 | |
142 | - return 'rgba(' . $red . ',' . $green . ',' . $blue . ',' . $alpha . ')'; |
|
143 | - } |
|
142 | + return 'rgba(' . $red . ',' . $green . ',' . $blue . ',' . $alpha . ')'; |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * Sanitize value for a choice field. |
|
147 | - * |
|
148 | - * @param string|array $value The submitted value. |
|
149 | - * @param array $field The field settings. |
|
150 | - * @return string|array |
|
151 | - */ |
|
152 | - private function sanitize_choice( $value, $field ) { |
|
153 | - $options = RWMB_Choice_Field::transform_options( $field['options'] ); |
|
154 | - $options = wp_list_pluck( $options, 'value' ); |
|
155 | - $value = wp_unslash( $value ); |
|
156 | - return is_array( $value ) ? array_intersect( $value, $options ) : ( in_array( $value, $options ) ? $value : '' ); |
|
157 | - } |
|
145 | + /** |
|
146 | + * Sanitize value for a choice field. |
|
147 | + * |
|
148 | + * @param string|array $value The submitted value. |
|
149 | + * @param array $field The field settings. |
|
150 | + * @return string|array |
|
151 | + */ |
|
152 | + private function sanitize_choice( $value, $field ) { |
|
153 | + $options = RWMB_Choice_Field::transform_options( $field['options'] ); |
|
154 | + $options = wp_list_pluck( $options, 'value' ); |
|
155 | + $value = wp_unslash( $value ); |
|
156 | + return is_array( $value ) ? array_intersect( $value, $options ) : ( in_array( $value, $options ) ? $value : '' ); |
|
157 | + } |
|
158 | 158 | |
159 | - /** |
|
160 | - * Sanitize object & media field. |
|
161 | - * |
|
162 | - * @param int|array $value The submitted value. |
|
163 | - * @return int|array |
|
164 | - */ |
|
165 | - private function sanitize_object( $value ) { |
|
166 | - return is_array( $value ) ? array_filter( array_map( 'absint', $value ) ) : ( $value ? absint( $value ) : '' ); |
|
167 | - } |
|
159 | + /** |
|
160 | + * Sanitize object & media field. |
|
161 | + * |
|
162 | + * @param int|array $value The submitted value. |
|
163 | + * @return int|array |
|
164 | + */ |
|
165 | + private function sanitize_object( $value ) { |
|
166 | + return is_array( $value ) ? array_filter( array_map( 'absint', $value ) ) : ( $value ? absint( $value ) : '' ); |
|
167 | + } |
|
168 | 168 | |
169 | - /** |
|
170 | - * Sanitize background field. |
|
171 | - * |
|
172 | - * @param array $value The submitted value. |
|
173 | - * @return array |
|
174 | - */ |
|
175 | - private function sanitize_background( $value ) { |
|
176 | - $value = wp_parse_args( |
|
177 | - $value, |
|
178 | - array( |
|
179 | - 'color' => '', |
|
180 | - 'image' => '', |
|
181 | - 'repeat' => '', |
|
182 | - 'attachment' => '', |
|
183 | - 'position' => '', |
|
184 | - 'size' => '', |
|
185 | - ) |
|
186 | - ); |
|
187 | - $value['color'] = $this->sanitize_color( $value['color'] ); |
|
188 | - $value['image'] = esc_url_raw( $value['image'] ); |
|
169 | + /** |
|
170 | + * Sanitize background field. |
|
171 | + * |
|
172 | + * @param array $value The submitted value. |
|
173 | + * @return array |
|
174 | + */ |
|
175 | + private function sanitize_background( $value ) { |
|
176 | + $value = wp_parse_args( |
|
177 | + $value, |
|
178 | + array( |
|
179 | + 'color' => '', |
|
180 | + 'image' => '', |
|
181 | + 'repeat' => '', |
|
182 | + 'attachment' => '', |
|
183 | + 'position' => '', |
|
184 | + 'size' => '', |
|
185 | + ) |
|
186 | + ); |
|
187 | + $value['color'] = $this->sanitize_color( $value['color'] ); |
|
188 | + $value['image'] = esc_url_raw( $value['image'] ); |
|
189 | 189 | |
190 | - $value['repeat'] = in_array( $value['repeat'], array( 'no-repeat', 'repeat', 'repeat-x', 'repeat-y', 'inherit' ), true ) ? $value['repeat'] : ''; |
|
191 | - $value['position'] = in_array( $value['position'], array( 'top left', 'top center', 'top right', 'center left', 'center center', 'center right', 'bottom left', 'bottom center', 'bottom right' ), true ) ? $value['position'] : ''; |
|
192 | - $value['attachment'] = in_array( $value['attachment'], array( 'fixed', 'scroll', 'inherit' ), true ) ? $value['attachment'] : ''; |
|
193 | - $value['size'] = in_array( $value['size'], array( 'inherit', 'cover', 'contain' ), true ) ? $value['size'] : ''; |
|
190 | + $value['repeat'] = in_array( $value['repeat'], array( 'no-repeat', 'repeat', 'repeat-x', 'repeat-y', 'inherit' ), true ) ? $value['repeat'] : ''; |
|
191 | + $value['position'] = in_array( $value['position'], array( 'top left', 'top center', 'top right', 'center left', 'center center', 'center right', 'bottom left', 'bottom center', 'bottom right' ), true ) ? $value['position'] : ''; |
|
192 | + $value['attachment'] = in_array( $value['attachment'], array( 'fixed', 'scroll', 'inherit' ), true ) ? $value['attachment'] : ''; |
|
193 | + $value['size'] = in_array( $value['size'], array( 'inherit', 'cover', 'contain' ), true ) ? $value['size'] : ''; |
|
194 | 194 | |
195 | - return $value; |
|
196 | - } |
|
195 | + return $value; |
|
196 | + } |
|
197 | 197 | |
198 | - /** |
|
199 | - * Sanitize text field. |
|
200 | - * |
|
201 | - * @param string|array $value The submitted value. |
|
202 | - * @return string|array |
|
203 | - */ |
|
204 | - private function sanitize_text( $value ) { |
|
205 | - return is_array( $value ) ? array_map( __METHOD__, $value ) : sanitize_text_field( $value ); |
|
206 | - } |
|
198 | + /** |
|
199 | + * Sanitize text field. |
|
200 | + * |
|
201 | + * @param string|array $value The submitted value. |
|
202 | + * @return string|array |
|
203 | + */ |
|
204 | + private function sanitize_text( $value ) { |
|
205 | + return is_array( $value ) ? array_map( __METHOD__, $value ) : sanitize_text_field( $value ); |
|
206 | + } |
|
207 | 207 | |
208 | - /** |
|
209 | - * Sanitize file, image field. |
|
210 | - * |
|
211 | - * @param array $value The submitted value. |
|
212 | - * @param array $field The field settings. |
|
213 | - * @return array |
|
214 | - */ |
|
215 | - private function sanitize_file( $value, $field ) { |
|
216 | - return $field['upload_dir'] ? array_map( 'esc_url_raw', $value ) : $this->sanitize_object( $value ); |
|
217 | - } |
|
208 | + /** |
|
209 | + * Sanitize file, image field. |
|
210 | + * |
|
211 | + * @param array $value The submitted value. |
|
212 | + * @param array $field The field settings. |
|
213 | + * @return array |
|
214 | + */ |
|
215 | + private function sanitize_file( $value, $field ) { |
|
216 | + return $field['upload_dir'] ? array_map( 'esc_url_raw', $value ) : $this->sanitize_object( $value ); |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * Sanitize slider field. |
|
221 | - * |
|
222 | - * @param mixed $value The submitted value. |
|
223 | - * @param array $field The field settings. |
|
224 | - * @return string|int|float |
|
225 | - */ |
|
226 | - private function sanitize_slider( $value, $field ) { |
|
227 | - return true === $field['js_options']['range'] ? sanitize_text_field( $value ) : $this->sanitize_number( $value ); |
|
228 | - } |
|
219 | + /** |
|
220 | + * Sanitize slider field. |
|
221 | + * |
|
222 | + * @param mixed $value The submitted value. |
|
223 | + * @param array $field The field settings. |
|
224 | + * @return string|int|float |
|
225 | + */ |
|
226 | + private function sanitize_slider( $value, $field ) { |
|
227 | + return true === $field['js_options']['range'] ? sanitize_text_field( $value ) : $this->sanitize_number( $value ); |
|
228 | + } |
|
229 | 229 | |
230 | - /** |
|
231 | - * Sanitize datetime field. |
|
232 | - * |
|
233 | - * @param mixed $value The submitted value. |
|
234 | - * @param array $field The field settings. |
|
235 | - * @return float|string |
|
236 | - */ |
|
237 | - private function sanitize_datetime( $value, $field ) { |
|
238 | - return $field['timestamp'] ? floor( abs( (float) $value ) ) : sanitize_text_field( $value ); |
|
239 | - } |
|
230 | + /** |
|
231 | + * Sanitize datetime field. |
|
232 | + * |
|
233 | + * @param mixed $value The submitted value. |
|
234 | + * @param array $field The field settings. |
|
235 | + * @return float|string |
|
236 | + */ |
|
237 | + private function sanitize_datetime( $value, $field ) { |
|
238 | + return $field['timestamp'] ? floor( abs( (float) $value ) ) : sanitize_text_field( $value ); |
|
239 | + } |
|
240 | 240 | |
241 | - /** |
|
242 | - * Sanitize map field. |
|
243 | - * |
|
244 | - * @param mixed $value The submitted value. |
|
245 | - * @return string |
|
246 | - */ |
|
247 | - private function sanitize_map( $value ) { |
|
248 | - $value = sanitize_text_field( $value ); |
|
249 | - list( $latitude, $longitude, $zoom ) = explode( ',', $value . ',,' ); |
|
241 | + /** |
|
242 | + * Sanitize map field. |
|
243 | + * |
|
244 | + * @param mixed $value The submitted value. |
|
245 | + * @return string |
|
246 | + */ |
|
247 | + private function sanitize_map( $value ) { |
|
248 | + $value = sanitize_text_field( $value ); |
|
249 | + list( $latitude, $longitude, $zoom ) = explode( ',', $value . ',,' ); |
|
250 | 250 | |
251 | - $latitude = (float) $latitude; |
|
252 | - $longitude = (float) $longitude; |
|
253 | - $zoom = (int) $zoom; |
|
251 | + $latitude = (float) $latitude; |
|
252 | + $longitude = (float) $longitude; |
|
253 | + $zoom = (int) $zoom; |
|
254 | 254 | |
255 | - return "$latitude,$longitude,$zoom"; |
|
256 | - } |
|
255 | + return "$latitude,$longitude,$zoom"; |
|
256 | + } |
|
257 | 257 | |
258 | - /** |
|
259 | - * Sanitize taxonomy advanced field. |
|
260 | - * |
|
261 | - * @param mixed $value The submitted value. |
|
262 | - * @return string |
|
263 | - */ |
|
264 | - private function sanitize_taxonomy_advanced( $value ) { |
|
265 | - $value = RWMB_Helpers_Array::from_csv( $value ); |
|
266 | - $value = array_filter( array_map( 'absint', $value ) ); |
|
258 | + /** |
|
259 | + * Sanitize taxonomy advanced field. |
|
260 | + * |
|
261 | + * @param mixed $value The submitted value. |
|
262 | + * @return string |
|
263 | + */ |
|
264 | + private function sanitize_taxonomy_advanced( $value ) { |
|
265 | + $value = RWMB_Helpers_Array::from_csv( $value ); |
|
266 | + $value = array_filter( array_map( 'absint', $value ) ); |
|
267 | 267 | |
268 | - return implode( ',', $value ); |
|
269 | - } |
|
268 | + return implode( ',', $value ); |
|
269 | + } |
|
270 | 270 | |
271 | - /** |
|
272 | - * Sanitize URL field. |
|
273 | - * |
|
274 | - * @param string $value The submitted value. |
|
275 | - * @return string |
|
276 | - */ |
|
277 | - private function sanitize_url( $value ) { |
|
278 | - return esc_url_raw( $value ); |
|
279 | - } |
|
271 | + /** |
|
272 | + * Sanitize URL field. |
|
273 | + * |
|
274 | + * @param string $value The submitted value. |
|
275 | + * @return string |
|
276 | + */ |
|
277 | + private function sanitize_url( $value ) { |
|
278 | + return esc_url_raw( $value ); |
|
279 | + } |
|
280 | 280 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * Register hook to sanitize field value. |
14 | 14 | */ |
15 | 15 | public function init() { |
16 | - add_filter( 'rwmb_sanitize', array( $this, 'sanitize' ), 10, 4 ); |
|
16 | + add_filter('rwmb_sanitize', array($this, 'sanitize'), 10, 4); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -24,15 +24,15 @@ discard block |
||
24 | 24 | * @param mixed $old_value The old field value in the database. |
25 | 25 | * @param int $object_id The object ID. |
26 | 26 | */ |
27 | - public function sanitize( $value, $field, $old_value = null, $object_id = null ) { |
|
27 | + public function sanitize($value, $field, $old_value = null, $object_id = null) { |
|
28 | 28 | // Allow developers to bypass the sanitization. |
29 | - if ( 'none' === $field['sanitize_callback'] ) { |
|
29 | + if ('none' === $field['sanitize_callback']) { |
|
30 | 30 | return $value; |
31 | 31 | } |
32 | 32 | |
33 | - $callback = $this->get_callback( $field ); |
|
33 | + $callback = $this->get_callback($field); |
|
34 | 34 | |
35 | - return is_callable( $callback ) ? call_user_func( $callback, $value, $field, $old_value, $object_id ) : $value; |
|
35 | + return is_callable($callback) ? call_user_func($callback, $value, $field, $old_value, $object_id) : $value; |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -41,62 +41,62 @@ discard block |
||
41 | 41 | * @param array $field Field settings. |
42 | 42 | * @return callable |
43 | 43 | */ |
44 | - private function get_callback( $field ) { |
|
44 | + private function get_callback($field) { |
|
45 | 45 | // User-defined callback. |
46 | - if ( is_callable( $field['sanitize_callback'] ) ) { |
|
46 | + if (is_callable($field['sanitize_callback'])) { |
|
47 | 47 | return $field['sanitize_callback']; |
48 | 48 | } |
49 | 49 | |
50 | 50 | $callbacks = array( |
51 | - 'autocomplete' => array( $this, 'sanitize_choice' ), |
|
52 | - 'background' => array( $this, 'sanitize_background' ), |
|
53 | - 'button_group' => array( $this, 'sanitize_choice' ), |
|
54 | - 'checkbox' => array( $this, 'sanitize_checkbox' ), |
|
55 | - 'checkbox_list' => array( $this, 'sanitize_choice' ), |
|
56 | - 'color' => array( $this, 'sanitize_color' ), |
|
57 | - 'date' => array( $this, 'sanitize_datetime' ), |
|
58 | - 'datetime' => array( $this, 'sanitize_datetime' ), |
|
51 | + 'autocomplete' => array($this, 'sanitize_choice'), |
|
52 | + 'background' => array($this, 'sanitize_background'), |
|
53 | + 'button_group' => array($this, 'sanitize_choice'), |
|
54 | + 'checkbox' => array($this, 'sanitize_checkbox'), |
|
55 | + 'checkbox_list' => array($this, 'sanitize_choice'), |
|
56 | + 'color' => array($this, 'sanitize_color'), |
|
57 | + 'date' => array($this, 'sanitize_datetime'), |
|
58 | + 'datetime' => array($this, 'sanitize_datetime'), |
|
59 | 59 | 'email' => 'sanitize_email', |
60 | - 'fieldset_text' => array( $this, 'sanitize_text' ), |
|
61 | - 'file' => array( $this, 'sanitize_file' ), |
|
62 | - 'file_advanced' => array( $this, 'sanitize_object' ), |
|
63 | - 'file_input' => array( $this, 'sanitize_url' ), |
|
64 | - 'file_upload' => array( $this, 'sanitize_object' ), |
|
60 | + 'fieldset_text' => array($this, 'sanitize_text'), |
|
61 | + 'file' => array($this, 'sanitize_file'), |
|
62 | + 'file_advanced' => array($this, 'sanitize_object'), |
|
63 | + 'file_input' => array($this, 'sanitize_url'), |
|
64 | + 'file_upload' => array($this, 'sanitize_object'), |
|
65 | 65 | 'hidden' => 'sanitize_text_field', |
66 | - 'image' => array( $this, 'sanitize_file' ), |
|
67 | - 'image_advanced' => array( $this, 'sanitize_object' ), |
|
68 | - 'image_select' => array( $this, 'sanitize_choice' ), |
|
69 | - 'image_upload' => array( $this, 'sanitize_object' ), |
|
70 | - 'key_value' => array( $this, 'sanitize_text' ), |
|
71 | - 'map' => array( $this, 'sanitize_map' ), |
|
72 | - 'number' => array( $this, 'sanitize_number' ), |
|
73 | - 'oembed' => array( $this, 'sanitize_url' ), |
|
74 | - 'osm' => array( $this, 'sanitize_map' ), |
|
66 | + 'image' => array($this, 'sanitize_file'), |
|
67 | + 'image_advanced' => array($this, 'sanitize_object'), |
|
68 | + 'image_select' => array($this, 'sanitize_choice'), |
|
69 | + 'image_upload' => array($this, 'sanitize_object'), |
|
70 | + 'key_value' => array($this, 'sanitize_text'), |
|
71 | + 'map' => array($this, 'sanitize_map'), |
|
72 | + 'number' => array($this, 'sanitize_number'), |
|
73 | + 'oembed' => array($this, 'sanitize_url'), |
|
74 | + 'osm' => array($this, 'sanitize_map'), |
|
75 | 75 | 'password' => 'sanitize_text_field', |
76 | - 'post' => array( $this, 'sanitize_object' ), |
|
77 | - 'radio' => array( $this, 'sanitize_choice' ), |
|
78 | - 'range' => array( $this, 'sanitize_number' ), |
|
79 | - 'select' => array( $this, 'sanitize_choice' ), |
|
80 | - 'select_advanced' => array( $this, 'sanitize_choice' ), |
|
81 | - 'sidebar' => array( $this, 'sanitize_text' ), |
|
76 | + 'post' => array($this, 'sanitize_object'), |
|
77 | + 'radio' => array($this, 'sanitize_choice'), |
|
78 | + 'range' => array($this, 'sanitize_number'), |
|
79 | + 'select' => array($this, 'sanitize_choice'), |
|
80 | + 'select_advanced' => array($this, 'sanitize_choice'), |
|
81 | + 'sidebar' => array($this, 'sanitize_text'), |
|
82 | 82 | 'single_image' => 'absint', |
83 | - 'slider' => array( $this, 'sanitize_slider' ), |
|
84 | - 'switch' => array( $this, 'sanitize_checkbox' ), |
|
85 | - 'taxonomy' => array( $this, 'sanitize_object' ), |
|
86 | - 'taxonomy_advanced' => array( $this, 'sanitize_taxonomy_advanced' ), |
|
83 | + 'slider' => array($this, 'sanitize_slider'), |
|
84 | + 'switch' => array($this, 'sanitize_checkbox'), |
|
85 | + 'taxonomy' => array($this, 'sanitize_object'), |
|
86 | + 'taxonomy_advanced' => array($this, 'sanitize_taxonomy_advanced'), |
|
87 | 87 | 'text' => 'sanitize_text_field', |
88 | - 'text_list' => array( $this, 'sanitize_text' ), |
|
88 | + 'text_list' => array($this, 'sanitize_text'), |
|
89 | 89 | 'textarea' => 'wp_kses_post', |
90 | 90 | 'time' => 'sanitize_text_field', |
91 | - 'url' => array( $this, 'sanitize_url' ), |
|
92 | - 'user' => array( $this, 'sanitize_object' ), |
|
93 | - 'video' => array( $this, 'sanitize_object' ), |
|
91 | + 'url' => array($this, 'sanitize_url'), |
|
92 | + 'user' => array($this, 'sanitize_object'), |
|
93 | + 'video' => array($this, 'sanitize_object'), |
|
94 | 94 | 'wysiwyg' => 'wp_kses_post', |
95 | 95 | ); |
96 | 96 | |
97 | 97 | $type = $field['type']; |
98 | 98 | |
99 | - return isset( $callbacks[ $type ] ) ? $callbacks[ $type ] : null; |
|
99 | + return isset($callbacks[$type]) ? $callbacks[$type] : null; |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | * @param string $value Checkbox value. |
108 | 108 | * @return int |
109 | 109 | */ |
110 | - private function sanitize_checkbox( $value ) { |
|
111 | - return (int) ! empty( $value ); |
|
110 | + private function sanitize_checkbox($value) { |
|
111 | + return (int) !empty($value); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | * @param string $value The number value. |
118 | 118 | * @return string |
119 | 119 | */ |
120 | - private function sanitize_number( $value ) { |
|
121 | - return is_numeric( $value ) ? $value : ''; |
|
120 | + private function sanitize_number($value) { |
|
121 | + return is_numeric($value) ? $value : ''; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | * @param string $value The color value. |
128 | 128 | * @return string |
129 | 129 | */ |
130 | - private function sanitize_color( $value ) { |
|
131 | - if ( false === strpos( $value, 'rgba' ) ) { |
|
132 | - return sanitize_hex_color( $value ); |
|
130 | + private function sanitize_color($value) { |
|
131 | + if (false === strpos($value, 'rgba')) { |
|
132 | + return sanitize_hex_color($value); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | // rgba value. |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | $green = ''; |
138 | 138 | $blue = ''; |
139 | 139 | $alpha = ''; |
140 | - sscanf( $value, 'rgba(%d,%d,%d,%f)', $red, $green, $blue, $alpha ); |
|
140 | + sscanf($value, 'rgba(%d,%d,%d,%f)', $red, $green, $blue, $alpha); |
|
141 | 141 | |
142 | 142 | return 'rgba(' . $red . ',' . $green . ',' . $blue . ',' . $alpha . ')'; |
143 | 143 | } |
@@ -149,11 +149,11 @@ discard block |
||
149 | 149 | * @param array $field The field settings. |
150 | 150 | * @return string|array |
151 | 151 | */ |
152 | - private function sanitize_choice( $value, $field ) { |
|
153 | - $options = RWMB_Choice_Field::transform_options( $field['options'] ); |
|
154 | - $options = wp_list_pluck( $options, 'value' ); |
|
155 | - $value = wp_unslash( $value ); |
|
156 | - return is_array( $value ) ? array_intersect( $value, $options ) : ( in_array( $value, $options ) ? $value : '' ); |
|
152 | + private function sanitize_choice($value, $field) { |
|
153 | + $options = RWMB_Choice_Field::transform_options($field['options']); |
|
154 | + $options = wp_list_pluck($options, 'value'); |
|
155 | + $value = wp_unslash($value); |
|
156 | + return is_array($value) ? array_intersect($value, $options) : (in_array($value, $options) ? $value : ''); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | /** |
@@ -162,8 +162,8 @@ discard block |
||
162 | 162 | * @param int|array $value The submitted value. |
163 | 163 | * @return int|array |
164 | 164 | */ |
165 | - private function sanitize_object( $value ) { |
|
166 | - return is_array( $value ) ? array_filter( array_map( 'absint', $value ) ) : ( $value ? absint( $value ) : '' ); |
|
165 | + private function sanitize_object($value) { |
|
166 | + return is_array($value) ? array_filter(array_map('absint', $value)) : ($value ? absint($value) : ''); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -172,8 +172,8 @@ discard block |
||
172 | 172 | * @param array $value The submitted value. |
173 | 173 | * @return array |
174 | 174 | */ |
175 | - private function sanitize_background( $value ) { |
|
176 | - $value = wp_parse_args( |
|
175 | + private function sanitize_background($value) { |
|
176 | + $value = wp_parse_args( |
|
177 | 177 | $value, |
178 | 178 | array( |
179 | 179 | 'color' => '', |
@@ -184,13 +184,13 @@ discard block |
||
184 | 184 | 'size' => '', |
185 | 185 | ) |
186 | 186 | ); |
187 | - $value['color'] = $this->sanitize_color( $value['color'] ); |
|
188 | - $value['image'] = esc_url_raw( $value['image'] ); |
|
187 | + $value['color'] = $this->sanitize_color($value['color']); |
|
188 | + $value['image'] = esc_url_raw($value['image']); |
|
189 | 189 | |
190 | - $value['repeat'] = in_array( $value['repeat'], array( 'no-repeat', 'repeat', 'repeat-x', 'repeat-y', 'inherit' ), true ) ? $value['repeat'] : ''; |
|
191 | - $value['position'] = in_array( $value['position'], array( 'top left', 'top center', 'top right', 'center left', 'center center', 'center right', 'bottom left', 'bottom center', 'bottom right' ), true ) ? $value['position'] : ''; |
|
192 | - $value['attachment'] = in_array( $value['attachment'], array( 'fixed', 'scroll', 'inherit' ), true ) ? $value['attachment'] : ''; |
|
193 | - $value['size'] = in_array( $value['size'], array( 'inherit', 'cover', 'contain' ), true ) ? $value['size'] : ''; |
|
190 | + $value['repeat'] = in_array($value['repeat'], array('no-repeat', 'repeat', 'repeat-x', 'repeat-y', 'inherit'), true) ? $value['repeat'] : ''; |
|
191 | + $value['position'] = in_array($value['position'], array('top left', 'top center', 'top right', 'center left', 'center center', 'center right', 'bottom left', 'bottom center', 'bottom right'), true) ? $value['position'] : ''; |
|
192 | + $value['attachment'] = in_array($value['attachment'], array('fixed', 'scroll', 'inherit'), true) ? $value['attachment'] : ''; |
|
193 | + $value['size'] = in_array($value['size'], array('inherit', 'cover', 'contain'), true) ? $value['size'] : ''; |
|
194 | 194 | |
195 | 195 | return $value; |
196 | 196 | } |
@@ -201,8 +201,8 @@ discard block |
||
201 | 201 | * @param string|array $value The submitted value. |
202 | 202 | * @return string|array |
203 | 203 | */ |
204 | - private function sanitize_text( $value ) { |
|
205 | - return is_array( $value ) ? array_map( __METHOD__, $value ) : sanitize_text_field( $value ); |
|
204 | + private function sanitize_text($value) { |
|
205 | + return is_array($value) ? array_map(__METHOD__, $value) : sanitize_text_field($value); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -212,8 +212,8 @@ discard block |
||
212 | 212 | * @param array $field The field settings. |
213 | 213 | * @return array |
214 | 214 | */ |
215 | - private function sanitize_file( $value, $field ) { |
|
216 | - return $field['upload_dir'] ? array_map( 'esc_url_raw', $value ) : $this->sanitize_object( $value ); |
|
215 | + private function sanitize_file($value, $field) { |
|
216 | + return $field['upload_dir'] ? array_map('esc_url_raw', $value) : $this->sanitize_object($value); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -223,8 +223,8 @@ discard block |
||
223 | 223 | * @param array $field The field settings. |
224 | 224 | * @return string|int|float |
225 | 225 | */ |
226 | - private function sanitize_slider( $value, $field ) { |
|
227 | - return true === $field['js_options']['range'] ? sanitize_text_field( $value ) : $this->sanitize_number( $value ); |
|
226 | + private function sanitize_slider($value, $field) { |
|
227 | + return true === $field['js_options']['range'] ? sanitize_text_field($value) : $this->sanitize_number($value); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
@@ -234,8 +234,8 @@ discard block |
||
234 | 234 | * @param array $field The field settings. |
235 | 235 | * @return float|string |
236 | 236 | */ |
237 | - private function sanitize_datetime( $value, $field ) { |
|
238 | - return $field['timestamp'] ? floor( abs( (float) $value ) ) : sanitize_text_field( $value ); |
|
237 | + private function sanitize_datetime($value, $field) { |
|
238 | + return $field['timestamp'] ? floor(abs((float) $value)) : sanitize_text_field($value); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | /** |
@@ -244,9 +244,9 @@ discard block |
||
244 | 244 | * @param mixed $value The submitted value. |
245 | 245 | * @return string |
246 | 246 | */ |
247 | - private function sanitize_map( $value ) { |
|
248 | - $value = sanitize_text_field( $value ); |
|
249 | - list( $latitude, $longitude, $zoom ) = explode( ',', $value . ',,' ); |
|
247 | + private function sanitize_map($value) { |
|
248 | + $value = sanitize_text_field($value); |
|
249 | + list($latitude, $longitude, $zoom) = explode(',', $value . ',,'); |
|
250 | 250 | |
251 | 251 | $latitude = (float) $latitude; |
252 | 252 | $longitude = (float) $longitude; |
@@ -261,11 +261,11 @@ discard block |
||
261 | 261 | * @param mixed $value The submitted value. |
262 | 262 | * @return string |
263 | 263 | */ |
264 | - private function sanitize_taxonomy_advanced( $value ) { |
|
265 | - $value = RWMB_Helpers_Array::from_csv( $value ); |
|
266 | - $value = array_filter( array_map( 'absint', $value ) ); |
|
264 | + private function sanitize_taxonomy_advanced($value) { |
|
265 | + $value = RWMB_Helpers_Array::from_csv($value); |
|
266 | + $value = array_filter(array_map('absint', $value)); |
|
267 | 267 | |
268 | - return implode( ',', $value ); |
|
268 | + return implode(',', $value); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | * @param string $value The submitted value. |
275 | 275 | * @return string |
276 | 276 | */ |
277 | - private function sanitize_url( $value ) { |
|
278 | - return esc_url_raw( $value ); |
|
277 | + private function sanitize_url($value) { |
|
278 | + return esc_url_raw($value); |
|
279 | 279 | } |
280 | 280 | } |
@@ -9,26 +9,26 @@ |
||
9 | 9 | * The select walker class. |
10 | 10 | */ |
11 | 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 | - $indent = str_repeat( ' ', $depth * 4 ); |
|
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 | + $indent = str_repeat( ' ', $depth * 4 ); |
|
25 | 25 | |
26 | - $output .= sprintf( |
|
27 | - '<option value="%s" %s>%s%s</option>', |
|
28 | - esc_attr( $object->value ), |
|
29 | - selected( in_array( $object->value, $this->meta ), true, false ), |
|
30 | - $indent, |
|
31 | - esc_html( $object->label ) |
|
32 | - ); |
|
33 | - } |
|
26 | + $output .= sprintf( |
|
27 | + '<option value="%s" %s>%s%s</option>', |
|
28 | + esc_attr( $object->value ), |
|
29 | + selected( in_array( $object->value, $this->meta ), true, false ), |
|
30 | + $indent, |
|
31 | + esc_html( $object->label ) |
|
32 | + ); |
|
33 | + } |
|
34 | 34 | } |
@@ -20,15 +20,15 @@ |
||
20 | 20 | * @param array $args An array of additional arguments. |
21 | 21 | * @param int $current_object_id ID of the current item. |
22 | 22 | */ |
23 | - public function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) { |
|
24 | - $indent = str_repeat( ' ', $depth * 4 ); |
|
23 | + public function start_el(&$output, $object, $depth = 0, $args = array(), $current_object_id = 0) { |
|
24 | + $indent = str_repeat(' ', $depth * 4); |
|
25 | 25 | |
26 | 26 | $output .= sprintf( |
27 | 27 | '<option value="%s" %s>%s%s</option>', |
28 | - esc_attr( $object->value ), |
|
29 | - selected( in_array( $object->value, $this->meta ), true, false ), |
|
28 | + esc_attr($object->value), |
|
29 | + selected(in_array($object->value, $this->meta), true, false), |
|
30 | 30 | $indent, |
31 | - esc_html( $object->label ) |
|
31 | + esc_html($object->label) |
|
32 | 32 | ); |
33 | 33 | } |
34 | 34 | } |