|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* GMB_Shortcode_Generator class. |
|
5
|
|
|
* |
|
6
|
|
|
* @description: Adds a TinyMCE button that's clickable |
|
7
|
|
|
* |
|
8
|
|
|
* @since 2.0 |
|
9
|
|
|
*/ |
|
10
|
|
|
class GMB_Shortcode_Generator extends Google_Maps_Builder_Core_Shortcode_Generator { |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Constructor |
|
14
|
|
|
*/ |
|
15
|
|
|
public function __construct() { |
|
16
|
|
|
parent::__construct(); |
|
17
|
|
|
add_action( 'gmb_after_shortcode_form', array( $this, 'form_upsell') ); |
|
18
|
|
|
add_action( 'gmb_shortcode_iframe_style', array( $this, 'upsell_css' ) ); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Renders an HTML Dropdown |
|
25
|
|
|
* |
|
26
|
|
|
* @since 2.0 |
|
27
|
|
|
* |
|
28
|
|
|
* @param array $args |
|
29
|
|
|
* |
|
30
|
|
|
* @return string |
|
31
|
|
|
*/ |
|
32
|
|
|
public static function select( $args = array() ) { |
|
33
|
|
|
|
|
34
|
|
|
$defaults = array( |
|
35
|
|
|
'options' => array(), |
|
36
|
|
|
'name' => null, |
|
37
|
|
|
'class' => '', |
|
38
|
|
|
'id' => '', |
|
39
|
|
|
'selected' => 0, |
|
40
|
|
|
'chosen' => false, |
|
41
|
|
|
'placeholder' => null, |
|
42
|
|
|
'multiple' => false, |
|
43
|
|
|
'show_option_all' => _x( 'All', 'all dropdown items', 'google-maps-builder' ), |
|
44
|
|
|
'show_option_none' => _x( 'None', 'no dropdown items', 'google-maps-builder' ) |
|
45
|
|
|
); |
|
46
|
|
|
|
|
47
|
|
|
$args = wp_parse_args( $args, $defaults ); |
|
48
|
|
|
|
|
49
|
|
|
if ( $args['multiple'] ) { |
|
50
|
|
|
$multiple = ' MULTIPLE'; |
|
51
|
|
|
} else { |
|
52
|
|
|
$multiple = ''; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
if ( $args['chosen'] ) { |
|
56
|
|
|
$args['class'] .= 'gmb-select-chosen'; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
if ( $args['placeholder'] ) { |
|
60
|
|
|
$placeholder = $args['placeholder']; |
|
61
|
|
|
} else { |
|
62
|
|
|
$placeholder = ''; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( sanitize_key( str_replace( '-', '_', $args['id'] ) ) ) . '" class="gmb-select ' . esc_attr( $args['class'] ) . '"' . $multiple . ' data-placeholder="' . $placeholder . '">'; |
|
66
|
|
|
|
|
67
|
|
|
if ( $args['show_option_all'] ) { |
|
68
|
|
|
if ( $args['multiple'] ) { |
|
69
|
|
|
$selected = selected( true, in_array( 0, $args['selected'] ), false ); |
|
70
|
|
|
} else { |
|
71
|
|
|
$selected = selected( $args['selected'], 0, false ); |
|
72
|
|
|
} |
|
73
|
|
|
$output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
if ( ! empty( $args['options'] ) ) { |
|
77
|
|
|
|
|
78
|
|
|
if ( $args['show_option_none'] ) { |
|
79
|
|
|
if ( $args['multiple'] ) { |
|
80
|
|
|
$selected = selected( true, in_array( - 1, $args['selected'] ), false ); |
|
81
|
|
|
} else { |
|
82
|
|
|
$selected = selected( $args['selected'], - 1, false ); |
|
83
|
|
|
} |
|
84
|
|
|
$output .= '<option value="-1"' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
foreach ( $args['options'] as $key => $option ) { |
|
88
|
|
|
|
|
89
|
|
|
if ( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
90
|
|
|
$selected = selected( true, in_array( $key, $args['selected'] ), false ); |
|
91
|
|
|
} else { |
|
92
|
|
|
$selected = selected( $args['selected'], $key, false ); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
$output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
$output .= '</select>'; |
|
100
|
|
|
|
|
101
|
|
|
return $output; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Add upsell markup to shortcode form |
|
106
|
|
|
* |
|
107
|
|
|
* @since 2.1.0 |
|
108
|
|
|
* |
|
109
|
|
|
* @uses "gmb_after_shortcode_form" |
|
110
|
|
|
*/ |
|
111
|
|
|
public function form_upsell(){?> |
|
112
|
|
|
<a href="https://wordimpress.com/plugins/maps-builder-pro?utm_source=MBF&utm_medium=BANNER&utm_content=SHORTCODE&utm_campaign=MBF%20Shortcode" class="button button-small shortcode-upsell" target="_blank"> |
|
113
|
|
|
<?php _e( 'Go Pro', 'google-maps-builder' ); ?> |
|
114
|
|
|
<span class="dashicons dashicons-external"></span> |
|
115
|
|
|
</a> |
|
116
|
|
|
<?php |
|
117
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Add extra css for upsell |
|
122
|
|
|
* |
|
123
|
|
|
* @since 2.1.0 |
|
124
|
|
|
* |
|
125
|
|
|
* @uses "gmb_shortcode_iframe_style" action |
|
126
|
|
|
*/ |
|
127
|
|
|
public function upsell_css(){ ?> |
|
128
|
|
|
.shortcode-upsell { |
|
129
|
|
|
position: absolute; |
|
130
|
|
|
bottom: 10px; |
|
131
|
|
|
right: 10px; |
|
132
|
|
|
padding: 5px 10px !important; |
|
133
|
|
|
font-size: 13px !important; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
.shortcode-upsell span.dashicons { |
|
137
|
|
|
font-size: 12px; |
|
138
|
|
|
height: 14px; |
|
139
|
|
|
position: relative; |
|
140
|
|
|
top: 3px; |
|
141
|
|
|
opacity: 0.8; |
|
142
|
|
|
width: 12px; |
|
143
|
|
|
} |
|
144
|
|
|
<?php |
|
145
|
|
|
|
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
new GMB_Shortcode_Generator(); |
|
151
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.