-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-ft-multiple-select.php
executable file
·78 lines (78 loc) · 2.46 KB
/
class-ft-multiple-select.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
* Multiple Select Control for the Customizer
*
* @version 1.0.0
* @package WordPress
* @subpackage Customizer
*/
if ( class_exists( 'WP_Customize_Control' ) && ! class_exists( 'FT_Multiple_Select_Control' ) ) {
/**
* FT_Multiple_Select_Control Class
*/
class FT_Multiple_Select_Control extends WP_Customize_Control {
/**
* Control Type
*
* @var string
*/
public $type = 'ft-multiple-select';
/**
* Render the control
*
* @since 1.0.0
*
* @return void
*/
public function render_content() {
$selected_values = $this->value();
if ( ! is_array( $selected_values ) ) {
$selected_values = explode( ',', $selected_values );
}
?>
<label>
<?php if ( $this->label ) : ?>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<?php endif; ?>
<?php if ( $this->description ) : ?>
<span class="description customize-control-description"><?php echo esc_html( $this->description ); ?></span>
<?php endif; ?>
<?php if ( empty( $this->choices ) ) : ?>
<?php esc_html_e( 'No choices available.', 'ft-customizer-controls' ); ?>
<?php else : ?>
<select <?php $this->link(); ?> multiple="multiple" style="height: 100px;">
<?php
foreach ( $this->choices as $value => $label ) {
$selected = ( in_array( $value, $selected_values, true ) ) ? selected( 1, 1, false ) : '';
echo '<option value="' . esc_attr( $value ) . '"' . esc_html( $selected ) . '>' . esc_html( $label ) . '</option>';
}
?>
</select>
<?php endif; ?>
</label>
<?php if ( ! empty( $this->choices ) ) : ?>
<div class="ft-multiple-select-buttons" style="text-align: right;">
<button type="buttom" class="button ft-select-all">
<span><?php esc_html_e( 'All', 'ft-customizer-controls' ); ?></span>
</button>
<button type="buttom" class="button ft-deselect-all">
<span><?php esc_html_e( 'None', 'ft-customizer-controls' ); ?></span>
</button>
</div>
<?php endif; ?>
<?php
}
/**
* Loads the scripts/styles.
*
* @since 1.0.0
*
* @return void
*/
public function enqueue() {
$file_path = __DIR__;
$url_path = str_replace( $_SERVER['DOCUMENT_ROOT'], '', $file_path );
wp_enqueue_script( 'ft-multiple-select-control', $url_path . '/js/ft-multiple-select.js', array( 'customize-controls', 'jquery' ), '1.0.0', true );
}
}
}