-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRWMB_Select_advanced_ajax_Field.php
executable file
·51 lines (35 loc) · 1.63 KB
/
RWMB_Select_advanced_ajax_Field.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
if(class_exists('RWMB_Select_Advanced_Field')):
class RWMB_Select_advanced_ajax_Field extends RWMB_Select_Advanced_Field {
public static function html( $meta, $field ) {
$options = self::transform_options( $field['options'] );
$attributes = self::call( 'get_attributes', $field, $meta );
$attributes['data-selected'] = $meta;
$walker = new RWMB_Walker_Select( $field, $meta );
$attributes['class'] .= ' rwmb-select_advanced';
$output = sprintf(
'<select %s>',
self::render_attributes( $attributes )
);
if ( ! $field['multiple'] && $field['placeholder'] ) {
$output .= '<option value="">' . esc_html( $field['placeholder'] ) . '</option>';
}
$output .= $walker->walk( $options, $field['flatten'] ? -1 : 0 );
$output .= '</select>';
$output .= self::get_select_all_html( $field );
$interfaceValue = rwmb_meta($field['id'] .'-interface');
// Hidden field for remember the content of the selector
$output .= '<input
type="hidden"
id="'. $field['id'] .'-interface"
name="'. $field['id'] .'-interface"
value=\''. $interfaceValue .'\' />';
return $output;
}
public static function save( $new, $old, $post_id, $field ) {
// Force saving our hidden field
update_metadata( 'post', $post_id, $field['id'].'-interface', $_POST[$field['id'].'-interface']);
parent::save($new, $old, $post_id, $field);
}
}
endif;