@@ -12,124 +12,124 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class WPInv_Session_Handler extends WPInv_Session { |
14 | 14 | |
15 | - /** |
|
16 | - * Cookie name used for the session. |
|
17 | - * |
|
18 | - * @var string cookie name |
|
19 | - */ |
|
20 | - protected $_cookie; |
|
21 | - |
|
22 | - /** |
|
23 | - * Stores session expiry. |
|
24 | - * |
|
25 | - * @var int session due to expire timestamp |
|
26 | - */ |
|
27 | - protected $_session_expiring; |
|
28 | - |
|
29 | - /** |
|
30 | - * Stores session due to expire timestamp. |
|
31 | - * |
|
32 | - * @var string session expiration timestamp |
|
33 | - */ |
|
34 | - protected $_session_expiration; |
|
35 | - |
|
36 | - /** |
|
37 | - * True when the cookie exists. |
|
38 | - * |
|
39 | - * @var bool Based on whether a cookie exists. |
|
40 | - */ |
|
41 | - protected $_has_cookie = false; |
|
42 | - |
|
43 | - /** |
|
44 | - * Table name for session data. |
|
45 | - * |
|
46 | - * @var string Custom session table name |
|
47 | - */ |
|
48 | - protected $_table; |
|
49 | - |
|
50 | - /** |
|
51 | - * Constructor for the session class. |
|
52 | - */ |
|
53 | - public function __construct() { |
|
54 | - |
|
55 | - $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH ); |
|
15 | + /** |
|
16 | + * Cookie name used for the session. |
|
17 | + * |
|
18 | + * @var string cookie name |
|
19 | + */ |
|
20 | + protected $_cookie; |
|
21 | + |
|
22 | + /** |
|
23 | + * Stores session expiry. |
|
24 | + * |
|
25 | + * @var int session due to expire timestamp |
|
26 | + */ |
|
27 | + protected $_session_expiring; |
|
28 | + |
|
29 | + /** |
|
30 | + * Stores session due to expire timestamp. |
|
31 | + * |
|
32 | + * @var string session expiration timestamp |
|
33 | + */ |
|
34 | + protected $_session_expiration; |
|
35 | + |
|
36 | + /** |
|
37 | + * True when the cookie exists. |
|
38 | + * |
|
39 | + * @var bool Based on whether a cookie exists. |
|
40 | + */ |
|
41 | + protected $_has_cookie = false; |
|
42 | + |
|
43 | + /** |
|
44 | + * Table name for session data. |
|
45 | + * |
|
46 | + * @var string Custom session table name |
|
47 | + */ |
|
48 | + protected $_table; |
|
49 | + |
|
50 | + /** |
|
51 | + * Constructor for the session class. |
|
52 | + */ |
|
53 | + public function __construct() { |
|
54 | + |
|
55 | + $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH ); |
|
56 | 56 | add_action( 'init', array( $this, 'init' ), -1 ); |
57 | - add_action( 'wp_logout', array( $this, 'destroy_session' ) ); |
|
58 | - add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 ); |
|
59 | - add_action( 'shutdown', array( $this, 'save_data' ), 20 ); |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Init hooks and session data. |
|
64 | - * |
|
65 | - * @since 3.3.0 |
|
66 | - */ |
|
67 | - public function init() { |
|
68 | - $this->init_session_cookie(); |
|
69 | - |
|
70 | - if ( ! is_user_logged_in() ) { |
|
71 | - add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) ); |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Setup cookie and customer ID. |
|
77 | - * |
|
78 | - * @since 3.6.0 |
|
79 | - */ |
|
80 | - public function init_session_cookie() { |
|
81 | - $cookie = $this->get_session_cookie(); |
|
82 | - |
|
83 | - if ( $cookie ) { |
|
84 | - $this->_customer_id = $cookie[0]; |
|
85 | - $this->_session_expiration = $cookie[1]; |
|
86 | - $this->_session_expiring = $cookie[2]; |
|
87 | - $this->_has_cookie = true; |
|
88 | - $this->_data = $this->get_session_data(); |
|
89 | - |
|
90 | - // If the user logs in, update session. |
|
91 | - if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) { |
|
92 | - $this->_customer_id = get_current_user_id(); |
|
93 | - $this->_dirty = true; |
|
94 | - $this->save_data(); |
|
95 | - $this->set_customer_session_cookie( true ); |
|
96 | - } |
|
97 | - |
|
98 | - // Update session if its close to expiring. |
|
99 | - if ( time() > $this->_session_expiring ) { |
|
100 | - $this->set_session_expiration(); |
|
101 | - $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration ); |
|
102 | - } |
|
103 | - } else { |
|
104 | - $this->set_session_expiration(); |
|
105 | - $this->_customer_id = $this->generate_customer_id(); |
|
106 | - $this->_data = $this->get_session_data(); |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Sets the session cookie on-demand (usually after adding an item to the cart). |
|
112 | - * |
|
113 | - * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set. |
|
114 | - * |
|
115 | - * Warning: Cookies will only be set if this is called before the headers are sent. |
|
116 | - * |
|
117 | - * @param bool $set Should the session cookie be set. |
|
118 | - */ |
|
119 | - public function set_customer_session_cookie( $set ) { |
|
120 | - if ( $set ) { |
|
121 | - $to_hash = $this->_customer_id . '|' . $this->_session_expiration; |
|
122 | - $cookie_hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
123 | - $cookie_value = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash; |
|
124 | - $this->_has_cookie = true; |
|
125 | - |
|
126 | - if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) { |
|
127 | - $this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true ); |
|
128 | - } |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){ |
|
57 | + add_action( 'wp_logout', array( $this, 'destroy_session' ) ); |
|
58 | + add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 ); |
|
59 | + add_action( 'shutdown', array( $this, 'save_data' ), 20 ); |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Init hooks and session data. |
|
64 | + * |
|
65 | + * @since 3.3.0 |
|
66 | + */ |
|
67 | + public function init() { |
|
68 | + $this->init_session_cookie(); |
|
69 | + |
|
70 | + if ( ! is_user_logged_in() ) { |
|
71 | + add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) ); |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Setup cookie and customer ID. |
|
77 | + * |
|
78 | + * @since 3.6.0 |
|
79 | + */ |
|
80 | + public function init_session_cookie() { |
|
81 | + $cookie = $this->get_session_cookie(); |
|
82 | + |
|
83 | + if ( $cookie ) { |
|
84 | + $this->_customer_id = $cookie[0]; |
|
85 | + $this->_session_expiration = $cookie[1]; |
|
86 | + $this->_session_expiring = $cookie[2]; |
|
87 | + $this->_has_cookie = true; |
|
88 | + $this->_data = $this->get_session_data(); |
|
89 | + |
|
90 | + // If the user logs in, update session. |
|
91 | + if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) { |
|
92 | + $this->_customer_id = get_current_user_id(); |
|
93 | + $this->_dirty = true; |
|
94 | + $this->save_data(); |
|
95 | + $this->set_customer_session_cookie( true ); |
|
96 | + } |
|
97 | + |
|
98 | + // Update session if its close to expiring. |
|
99 | + if ( time() > $this->_session_expiring ) { |
|
100 | + $this->set_session_expiration(); |
|
101 | + $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration ); |
|
102 | + } |
|
103 | + } else { |
|
104 | + $this->set_session_expiration(); |
|
105 | + $this->_customer_id = $this->generate_customer_id(); |
|
106 | + $this->_data = $this->get_session_data(); |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Sets the session cookie on-demand (usually after adding an item to the cart). |
|
112 | + * |
|
113 | + * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set. |
|
114 | + * |
|
115 | + * Warning: Cookies will only be set if this is called before the headers are sent. |
|
116 | + * |
|
117 | + * @param bool $set Should the session cookie be set. |
|
118 | + */ |
|
119 | + public function set_customer_session_cookie( $set ) { |
|
120 | + if ( $set ) { |
|
121 | + $to_hash = $this->_customer_id . '|' . $this->_session_expiration; |
|
122 | + $cookie_hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
123 | + $cookie_value = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash; |
|
124 | + $this->_has_cookie = true; |
|
125 | + |
|
126 | + if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) { |
|
127 | + $this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true ); |
|
128 | + } |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){ |
|
133 | 133 | if ( ! headers_sent() ) { |
134 | 134 | setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure ) ); |
135 | 135 | } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
@@ -138,96 +138,96 @@ discard block |
||
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
141 | - /** |
|
142 | - * Should the session cookie be secure? |
|
143 | - * |
|
144 | - * @since 3.6.0 |
|
145 | - * @return bool |
|
146 | - */ |
|
147 | - protected function use_secure_cookie() { |
|
141 | + /** |
|
142 | + * Should the session cookie be secure? |
|
143 | + * |
|
144 | + * @since 3.6.0 |
|
145 | + * @return bool |
|
146 | + */ |
|
147 | + protected function use_secure_cookie() { |
|
148 | 148 | $is_https = false !== strstr( get_option( 'home' ), 'https:' ); |
149 | - return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() ); |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Return true if the current user has an active session, i.e. a cookie to retrieve values. |
|
154 | - * |
|
155 | - * @return bool |
|
156 | - */ |
|
157 | - public function has_session() { |
|
158 | - return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * Set session expiration. |
|
163 | - */ |
|
164 | - public function set_session_expiration() { |
|
165 | - $this->_session_expiring = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours. |
|
166 | - $this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours. |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Generate a unique customer ID for guests, or return user ID if logged in. |
|
171 | - * |
|
172 | - * Uses Portable PHP password hashing framework to generate a unique cryptographically strong ID. |
|
173 | - * |
|
174 | - * @return string |
|
175 | - */ |
|
176 | - public function generate_customer_id() { |
|
177 | - $customer_id = ''; |
|
178 | - |
|
179 | - if ( is_user_logged_in() ) { |
|
180 | - $customer_id = get_current_user_id(); |
|
181 | - } |
|
182 | - |
|
183 | - if ( empty( $customer_id ) ) { |
|
149 | + return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() ); |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Return true if the current user has an active session, i.e. a cookie to retrieve values. |
|
154 | + * |
|
155 | + * @return bool |
|
156 | + */ |
|
157 | + public function has_session() { |
|
158 | + return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * Set session expiration. |
|
163 | + */ |
|
164 | + public function set_session_expiration() { |
|
165 | + $this->_session_expiring = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours. |
|
166 | + $this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours. |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Generate a unique customer ID for guests, or return user ID if logged in. |
|
171 | + * |
|
172 | + * Uses Portable PHP password hashing framework to generate a unique cryptographically strong ID. |
|
173 | + * |
|
174 | + * @return string |
|
175 | + */ |
|
176 | + public function generate_customer_id() { |
|
177 | + $customer_id = ''; |
|
178 | + |
|
179 | + if ( is_user_logged_in() ) { |
|
180 | + $customer_id = get_current_user_id(); |
|
181 | + } |
|
182 | + |
|
183 | + if ( empty( $customer_id ) ) { |
|
184 | 184 | $customer_id = wp_create_nonce('wpinv-session-customer-id'); |
185 | - } |
|
186 | - |
|
187 | - return $customer_id; |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Get the session cookie, if set. Otherwise return false. |
|
192 | - * |
|
193 | - * Session cookies without a customer ID are invalid. |
|
194 | - * |
|
195 | - * @return bool|array |
|
196 | - */ |
|
197 | - public function get_session_cookie() { |
|
198 | - $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine. |
|
199 | - |
|
200 | - if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) { |
|
201 | - return false; |
|
202 | - } |
|
203 | - |
|
204 | - list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value ); |
|
205 | - |
|
206 | - if ( empty( $customer_id ) ) { |
|
207 | - return false; |
|
208 | - } |
|
209 | - |
|
210 | - // Validate hash. |
|
211 | - $to_hash = $customer_id . '|' . $session_expiration; |
|
212 | - $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
213 | - |
|
214 | - if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) { |
|
215 | - return false; |
|
216 | - } |
|
217 | - |
|
218 | - return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash ); |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Get session data. |
|
223 | - * |
|
224 | - * @return array |
|
225 | - */ |
|
226 | - public function get_session_data() { |
|
227 | - return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array(); |
|
228 | - } |
|
229 | - |
|
230 | - public function generate_key($customer_id){ |
|
185 | + } |
|
186 | + |
|
187 | + return $customer_id; |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Get the session cookie, if set. Otherwise return false. |
|
192 | + * |
|
193 | + * Session cookies without a customer ID are invalid. |
|
194 | + * |
|
195 | + * @return bool|array |
|
196 | + */ |
|
197 | + public function get_session_cookie() { |
|
198 | + $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine. |
|
199 | + |
|
200 | + if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) { |
|
201 | + return false; |
|
202 | + } |
|
203 | + |
|
204 | + list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value ); |
|
205 | + |
|
206 | + if ( empty( $customer_id ) ) { |
|
207 | + return false; |
|
208 | + } |
|
209 | + |
|
210 | + // Validate hash. |
|
211 | + $to_hash = $customer_id . '|' . $session_expiration; |
|
212 | + $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
213 | + |
|
214 | + if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) { |
|
215 | + return false; |
|
216 | + } |
|
217 | + |
|
218 | + return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash ); |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Get session data. |
|
223 | + * |
|
224 | + * @return array |
|
225 | + */ |
|
226 | + public function get_session_data() { |
|
227 | + return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array(); |
|
228 | + } |
|
229 | + |
|
230 | + public function generate_key($customer_id){ |
|
231 | 231 | if(!$customer_id){ |
232 | 232 | return; |
233 | 233 | } |
@@ -235,62 +235,62 @@ discard block |
||
235 | 235 | return 'wpi_trans_'.$customer_id; |
236 | 236 | } |
237 | 237 | |
238 | - /** |
|
239 | - * Save data. |
|
240 | - */ |
|
241 | - public function save_data() { |
|
242 | - // Dirty if something changed - prevents saving nothing new. |
|
243 | - if ( $this->_dirty && $this->has_session() ) { |
|
238 | + /** |
|
239 | + * Save data. |
|
240 | + */ |
|
241 | + public function save_data() { |
|
242 | + // Dirty if something changed - prevents saving nothing new. |
|
243 | + if ( $this->_dirty && $this->has_session() ) { |
|
244 | 244 | |
245 | 245 | set_transient( $this->generate_key($this->_customer_id), $this->_data, $this->_session_expiration); |
246 | 246 | |
247 | - $this->_dirty = false; |
|
248 | - } |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * Destroy all session data. |
|
253 | - */ |
|
254 | - public function destroy_session() { |
|
255 | - $this->delete_session( $this->_customer_id ); |
|
256 | - $this->forget_session(); |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Forget all session data without destroying it. |
|
261 | - */ |
|
262 | - public function forget_session() { |
|
263 | - $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true ); |
|
264 | - |
|
265 | - wpinv_empty_cart(); |
|
266 | - |
|
267 | - $this->_data = array(); |
|
268 | - $this->_dirty = false; |
|
269 | - $this->_customer_id = $this->generate_customer_id(); |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * When a user is logged out, ensure they have a unique nonce by using the customer/session ID. |
|
274 | - * |
|
275 | - * @param int $uid User ID. |
|
276 | - * @return string |
|
277 | - */ |
|
278 | - public function nonce_user_logged_out( $uid ) { |
|
279 | - return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid; |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * Returns the session. |
|
284 | - * |
|
285 | - * @param string $customer_id Customer ID. |
|
286 | - * @param mixed $default Default session value. |
|
287 | - * @return string|array |
|
288 | - */ |
|
289 | - public function get_session( $customer_id, $default = false ) { |
|
290 | - |
|
291 | - if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
292 | - return array(); |
|
293 | - } |
|
247 | + $this->_dirty = false; |
|
248 | + } |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * Destroy all session data. |
|
253 | + */ |
|
254 | + public function destroy_session() { |
|
255 | + $this->delete_session( $this->_customer_id ); |
|
256 | + $this->forget_session(); |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Forget all session data without destroying it. |
|
261 | + */ |
|
262 | + public function forget_session() { |
|
263 | + $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true ); |
|
264 | + |
|
265 | + wpinv_empty_cart(); |
|
266 | + |
|
267 | + $this->_data = array(); |
|
268 | + $this->_dirty = false; |
|
269 | + $this->_customer_id = $this->generate_customer_id(); |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * When a user is logged out, ensure they have a unique nonce by using the customer/session ID. |
|
274 | + * |
|
275 | + * @param int $uid User ID. |
|
276 | + * @return string |
|
277 | + */ |
|
278 | + public function nonce_user_logged_out( $uid ) { |
|
279 | + return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid; |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * Returns the session. |
|
284 | + * |
|
285 | + * @param string $customer_id Customer ID. |
|
286 | + * @param mixed $default Default session value. |
|
287 | + * @return string|array |
|
288 | + */ |
|
289 | + public function get_session( $customer_id, $default = false ) { |
|
290 | + |
|
291 | + if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
292 | + return array(); |
|
293 | + } |
|
294 | 294 | |
295 | 295 | if ( !is_user_logged_in() ) { |
296 | 296 | if(!wp_verify_nonce( $customer_id, 'wpinv-session-customer-id' )){ |
@@ -305,32 +305,32 @@ discard block |
||
305 | 305 | $value = $default; |
306 | 306 | } |
307 | 307 | |
308 | - return maybe_unserialize( $value ); |
|
309 | - } |
|
308 | + return maybe_unserialize( $value ); |
|
309 | + } |
|
310 | 310 | |
311 | - /** |
|
312 | - * Delete the session from the cache and database. |
|
313 | - * |
|
314 | - * @param int $customer_id Customer ID. |
|
315 | - */ |
|
316 | - public function delete_session( $customer_id ) { |
|
311 | + /** |
|
312 | + * Delete the session from the cache and database. |
|
313 | + * |
|
314 | + * @param int $customer_id Customer ID. |
|
315 | + */ |
|
316 | + public function delete_session( $customer_id ) { |
|
317 | 317 | |
318 | 318 | $key = $this->generate_key($customer_id); |
319 | 319 | |
320 | - delete_transient($key); |
|
321 | - } |
|
320 | + delete_transient($key); |
|
321 | + } |
|
322 | 322 | |
323 | - /** |
|
324 | - * Update the session expiry timestamp. |
|
325 | - * |
|
326 | - * @param string $customer_id Customer ID. |
|
327 | - * @param int $timestamp Timestamp to expire the cookie. |
|
328 | - */ |
|
329 | - public function update_session_timestamp( $customer_id, $timestamp ) { |
|
323 | + /** |
|
324 | + * Update the session expiry timestamp. |
|
325 | + * |
|
326 | + * @param string $customer_id Customer ID. |
|
327 | + * @param int $timestamp Timestamp to expire the cookie. |
|
328 | + */ |
|
329 | + public function update_session_timestamp( $customer_id, $timestamp ) { |
|
330 | 330 | |
331 | 331 | set_transient( $this->generate_key($customer_id), maybe_serialize( $this->_data ), $timestamp); |
332 | 332 | |
333 | - } |
|
333 | + } |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | global $wpi_session; |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Session handler class. |
@@ -52,11 +52,11 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public function __construct() { |
54 | 54 | |
55 | - $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH ); |
|
56 | - add_action( 'init', array( $this, 'init' ), -1 ); |
|
57 | - add_action( 'wp_logout', array( $this, 'destroy_session' ) ); |
|
58 | - add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 ); |
|
59 | - add_action( 'shutdown', array( $this, 'save_data' ), 20 ); |
|
55 | + $this->_cookie = apply_filters('wpinv_cookie', 'wpinv_session_' . COOKIEHASH); |
|
56 | + add_action('init', array($this, 'init'), -1); |
|
57 | + add_action('wp_logout', array($this, 'destroy_session')); |
|
58 | + add_action('wp', array($this, 'set_customer_session_cookie'), 10); |
|
59 | + add_action('shutdown', array($this, 'save_data'), 20); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | public function init() { |
68 | 68 | $this->init_session_cookie(); |
69 | 69 | |
70 | - if ( ! is_user_logged_in() ) { |
|
71 | - add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) ); |
|
70 | + if (!is_user_logged_in()) { |
|
71 | + add_filter('nonce_user_logged_out', array($this, 'nonce_user_logged_out')); |
|
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | public function init_session_cookie() { |
81 | 81 | $cookie = $this->get_session_cookie(); |
82 | 82 | |
83 | - if ( $cookie ) { |
|
83 | + if ($cookie) { |
|
84 | 84 | $this->_customer_id = $cookie[0]; |
85 | 85 | $this->_session_expiration = $cookie[1]; |
86 | 86 | $this->_session_expiring = $cookie[2]; |
@@ -88,17 +88,17 @@ discard block |
||
88 | 88 | $this->_data = $this->get_session_data(); |
89 | 89 | |
90 | 90 | // If the user logs in, update session. |
91 | - if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) { |
|
91 | + if (is_user_logged_in() && get_current_user_id() != $this->_customer_id) { |
|
92 | 92 | $this->_customer_id = get_current_user_id(); |
93 | 93 | $this->_dirty = true; |
94 | 94 | $this->save_data(); |
95 | - $this->set_customer_session_cookie( true ); |
|
95 | + $this->set_customer_session_cookie(true); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | // Update session if its close to expiring. |
99 | - if ( time() > $this->_session_expiring ) { |
|
99 | + if (time() > $this->_session_expiring) { |
|
100 | 100 | $this->set_session_expiration(); |
101 | - $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration ); |
|
101 | + $this->update_session_timestamp($this->_customer_id, $this->_session_expiration); |
|
102 | 102 | } |
103 | 103 | } else { |
104 | 104 | $this->set_session_expiration(); |
@@ -116,25 +116,25 @@ discard block |
||
116 | 116 | * |
117 | 117 | * @param bool $set Should the session cookie be set. |
118 | 118 | */ |
119 | - public function set_customer_session_cookie( $set ) { |
|
120 | - if ( $set ) { |
|
119 | + public function set_customer_session_cookie($set) { |
|
120 | + if ($set) { |
|
121 | 121 | $to_hash = $this->_customer_id . '|' . $this->_session_expiration; |
122 | - $cookie_hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
122 | + $cookie_hash = hash_hmac('md5', $to_hash, wp_hash($to_hash)); |
|
123 | 123 | $cookie_value = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash; |
124 | 124 | $this->_has_cookie = true; |
125 | 125 | |
126 | - if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) { |
|
127 | - $this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true ); |
|
126 | + if (!isset($_COOKIE[$this->_cookie]) || $_COOKIE[$this->_cookie] !== $cookie_value) { |
|
127 | + $this->setcookie($this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true); |
|
128 | 128 | } |
129 | 129 | } |
130 | 130 | } |
131 | 131 | |
132 | - public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){ |
|
133 | - if ( ! headers_sent() ) { |
|
134 | - setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure ) ); |
|
135 | - } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
136 | - headers_sent( $file, $line ); |
|
137 | - trigger_error( "{$name} cookie cannot be set - headers already sent by {$file} on line {$line}", E_USER_NOTICE ); // @codingStandardsIgnoreLine |
|
132 | + public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false) { |
|
133 | + if (!headers_sent()) { |
|
134 | + setcookie($name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters('wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure)); |
|
135 | + } elseif (defined('WP_DEBUG') && WP_DEBUG) { |
|
136 | + headers_sent($file, $line); |
|
137 | + trigger_error("{$name} cookie cannot be set - headers already sent by {$file} on line {$line}", E_USER_NOTICE); // @codingStandardsIgnoreLine |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
@@ -145,8 +145,8 @@ discard block |
||
145 | 145 | * @return bool |
146 | 146 | */ |
147 | 147 | protected function use_secure_cookie() { |
148 | - $is_https = false !== strstr( get_option( 'home' ), 'https:' ); |
|
149 | - return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() ); |
|
148 | + $is_https = false !== strstr(get_option('home'), 'https:'); |
|
149 | + return apply_filters('wpinv_session_use_secure_cookie', $is_https && is_ssl()); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
@@ -155,15 +155,15 @@ discard block |
||
155 | 155 | * @return bool |
156 | 156 | */ |
157 | 157 | public function has_session() { |
158 | - return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. |
|
158 | + return isset($_COOKIE[$this->_cookie]) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
162 | 162 | * Set session expiration. |
163 | 163 | */ |
164 | 164 | public function set_session_expiration() { |
165 | - $this->_session_expiring = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours. |
|
166 | - $this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours. |
|
165 | + $this->_session_expiring = time() + intval(apply_filters('wpinv_session_expiring', 60 * 60 * 47)); // 47 Hours. |
|
166 | + $this->_session_expiration = time() + intval(apply_filters('wpinv_session_expiration', 60 * 60 * 48)); // 48 Hours. |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -176,11 +176,11 @@ discard block |
||
176 | 176 | public function generate_customer_id() { |
177 | 177 | $customer_id = ''; |
178 | 178 | |
179 | - if ( is_user_logged_in() ) { |
|
179 | + if (is_user_logged_in()) { |
|
180 | 180 | $customer_id = get_current_user_id(); |
181 | 181 | } |
182 | 182 | |
183 | - if ( empty( $customer_id ) ) { |
|
183 | + if (empty($customer_id)) { |
|
184 | 184 | $customer_id = wp_create_nonce('wpinv-session-customer-id'); |
185 | 185 | } |
186 | 186 | |
@@ -195,27 +195,27 @@ discard block |
||
195 | 195 | * @return bool|array |
196 | 196 | */ |
197 | 197 | public function get_session_cookie() { |
198 | - $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine. |
|
198 | + $cookie_value = isset($_COOKIE[$this->_cookie]) ? wp_unslash($_COOKIE[$this->_cookie]) : false; // @codingStandardsIgnoreLine. |
|
199 | 199 | |
200 | - if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) { |
|
200 | + if (empty($cookie_value) || !is_string($cookie_value)) { |
|
201 | 201 | return false; |
202 | 202 | } |
203 | 203 | |
204 | - list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value ); |
|
204 | + list($customer_id, $session_expiration, $session_expiring, $cookie_hash) = explode('||', $cookie_value); |
|
205 | 205 | |
206 | - if ( empty( $customer_id ) ) { |
|
206 | + if (empty($customer_id)) { |
|
207 | 207 | return false; |
208 | 208 | } |
209 | 209 | |
210 | 210 | // Validate hash. |
211 | 211 | $to_hash = $customer_id . '|' . $session_expiration; |
212 | - $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
212 | + $hash = hash_hmac('md5', $to_hash, wp_hash($to_hash)); |
|
213 | 213 | |
214 | - if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) { |
|
214 | + if (empty($cookie_hash) || !hash_equals($hash, $cookie_hash)) { |
|
215 | 215 | return false; |
216 | 216 | } |
217 | 217 | |
218 | - return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash ); |
|
218 | + return array($customer_id, $session_expiration, $session_expiring, $cookie_hash); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -224,15 +224,15 @@ discard block |
||
224 | 224 | * @return array |
225 | 225 | */ |
226 | 226 | public function get_session_data() { |
227 | - return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array(); |
|
227 | + return $this->has_session() ? (array) $this->get_session($this->_customer_id) : array(); |
|
228 | 228 | } |
229 | 229 | |
230 | - public function generate_key($customer_id){ |
|
231 | - if(!$customer_id){ |
|
230 | + public function generate_key($customer_id) { |
|
231 | + if (!$customer_id) { |
|
232 | 232 | return; |
233 | 233 | } |
234 | 234 | |
235 | - return 'wpi_trans_'.$customer_id; |
|
235 | + return 'wpi_trans_' . $customer_id; |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
@@ -240,9 +240,9 @@ discard block |
||
240 | 240 | */ |
241 | 241 | public function save_data() { |
242 | 242 | // Dirty if something changed - prevents saving nothing new. |
243 | - if ( $this->_dirty && $this->has_session() ) { |
|
243 | + if ($this->_dirty && $this->has_session()) { |
|
244 | 244 | |
245 | - set_transient( $this->generate_key($this->_customer_id), $this->_data, $this->_session_expiration); |
|
245 | + set_transient($this->generate_key($this->_customer_id), $this->_data, $this->_session_expiration); |
|
246 | 246 | |
247 | 247 | $this->_dirty = false; |
248 | 248 | } |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | * Destroy all session data. |
253 | 253 | */ |
254 | 254 | public function destroy_session() { |
255 | - $this->delete_session( $this->_customer_id ); |
|
255 | + $this->delete_session($this->_customer_id); |
|
256 | 256 | $this->forget_session(); |
257 | 257 | } |
258 | 258 | |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | * Forget all session data without destroying it. |
261 | 261 | */ |
262 | 262 | public function forget_session() { |
263 | - $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true ); |
|
263 | + $this->setcookie($this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true); |
|
264 | 264 | |
265 | 265 | wpinv_empty_cart(); |
266 | 266 | |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | * @param int $uid User ID. |
276 | 276 | * @return string |
277 | 277 | */ |
278 | - public function nonce_user_logged_out( $uid ) { |
|
278 | + public function nonce_user_logged_out($uid) { |
|
279 | 279 | return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid; |
280 | 280 | } |
281 | 281 | |
@@ -286,14 +286,14 @@ discard block |
||
286 | 286 | * @param mixed $default Default session value. |
287 | 287 | * @return string|array |
288 | 288 | */ |
289 | - public function get_session( $customer_id, $default = false ) { |
|
289 | + public function get_session($customer_id, $default = false) { |
|
290 | 290 | |
291 | - if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
291 | + if (defined('WP_SETUP_CONFIG')) { |
|
292 | 292 | return array(); |
293 | 293 | } |
294 | 294 | |
295 | - if ( !is_user_logged_in() ) { |
|
296 | - if(!wp_verify_nonce( $customer_id, 'wpinv-session-customer-id' )){ |
|
295 | + if (!is_user_logged_in()) { |
|
296 | + if (!wp_verify_nonce($customer_id, 'wpinv-session-customer-id')) { |
|
297 | 297 | return array(); |
298 | 298 | } |
299 | 299 | } |
@@ -301,11 +301,11 @@ discard block |
||
301 | 301 | $key = $this->generate_key($customer_id); |
302 | 302 | $value = get_transient($key); |
303 | 303 | |
304 | - if ( !$value ) { |
|
304 | + if (!$value) { |
|
305 | 305 | $value = $default; |
306 | 306 | } |
307 | 307 | |
308 | - return maybe_unserialize( $value ); |
|
308 | + return maybe_unserialize($value); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | /** |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | * |
314 | 314 | * @param int $customer_id Customer ID. |
315 | 315 | */ |
316 | - public function delete_session( $customer_id ) { |
|
316 | + public function delete_session($customer_id) { |
|
317 | 317 | |
318 | 318 | $key = $this->generate_key($customer_id); |
319 | 319 | |
@@ -326,9 +326,9 @@ discard block |
||
326 | 326 | * @param string $customer_id Customer ID. |
327 | 327 | * @param int $timestamp Timestamp to expire the cookie. |
328 | 328 | */ |
329 | - public function update_session_timestamp( $customer_id, $timestamp ) { |
|
329 | + public function update_session_timestamp($customer_id, $timestamp) { |
|
330 | 330 | |
331 | - set_transient( $this->generate_key($customer_id), maybe_serialize( $this->_data ), $timestamp); |
|
331 | + set_transient($this->generate_key($customer_id), maybe_serialize($this->_data), $timestamp); |
|
332 | 332 | |
333 | 333 | } |
334 | 334 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | </div> |
127 | 127 | </div> |
128 | 128 | <?php |
129 | - }else{ |
|
129 | + } else{ |
|
130 | 130 | $installed_plugins = get_plugins(); |
131 | 131 | $addon_obj = new WPInv_Admin_Addons(); |
132 | 132 | if ($addons = $addon_obj->get_section_data( $current_tab ) ) : |
@@ -151,14 +151,14 @@ discard block |
||
151 | 151 | echo '<a href="'.admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug).'&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
152 | 152 | echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
153 | 153 | echo '</a>'; |
154 | - }elseif(isset($addon->info->link) && substr( $addon->info->link, 0, 23 ) === "https://wpinvoicing.com"){ |
|
154 | + } elseif(isset($addon->info->link) && substr( $addon->info->link, 0, 23 ) === "https://wpinvoicing.com"){ |
|
155 | 155 | if(defined('WP_EASY_UPDATES_ACTIVE')){ |
156 | 156 | $url = admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug.'&width=770&height=660&item_id='.$addon->info->id.'&update_url=https://wpinvoicing.com&TB_iframe=true'); |
157 | - }else{ |
|
157 | + } else{ |
|
158 | 158 | // if installed show activation link |
159 | 159 | if(isset($installed_plugins['wp-easy-updates/external-updates.php'])){ |
160 | 160 | $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
161 | - }else{ |
|
161 | + } else{ |
|
162 | 162 | $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
163 | 163 | } |
164 | 164 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
7 | - exit; |
|
7 | + exit; |
|
8 | 8 | } |
9 | 9 | add_ThickBox(); |
10 | 10 | ?> |
@@ -14,18 +14,18 @@ discard block |
||
14 | 14 | <?php if ( $tabs ){ ?> |
15 | 15 | <nav class="nav-tab-wrapper wpi-nav-tab-wrapper"> |
16 | 16 | <?php |
17 | - foreach ( $tabs as $name => $label ) { |
|
18 | - echo '<a href="' . admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . $label . '</a>'; |
|
19 | - } |
|
20 | - do_action( 'wpi_addons_tabs' ); |
|
21 | - ?> |
|
17 | + foreach ( $tabs as $name => $label ) { |
|
18 | + echo '<a href="' . admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . $label . '</a>'; |
|
19 | + } |
|
20 | + do_action( 'wpi_addons_tabs' ); |
|
21 | + ?> |
|
22 | 22 | </nav> |
23 | 23 | |
24 | 24 | <?php |
25 | 25 | |
26 | - if($current_tab == 'membership'){ |
|
26 | + if($current_tab == 'membership'){ |
|
27 | 27 | |
28 | - ?> |
|
28 | + ?> |
|
29 | 29 | |
30 | 30 | <div class="wpi-membership-tab-conatiner"> |
31 | 31 | <div class="membership-content"> |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | <h2><?php _e("Have a membership key?","invoicing");?></h2> |
37 | 37 | <p> |
38 | 38 | <?php |
39 | - $wpeu_admin = new External_Updates_Admin('wpinvoicing.com','1'); |
|
40 | - echo $wpeu_admin->render_licence_actions('wpinvoicing.com', 'membership',array(95, 106, 108,12351)); |
|
41 | - ?> |
|
39 | + $wpeu_admin = new External_Updates_Admin('wpinvoicing.com','1'); |
|
40 | + echo $wpeu_admin->render_licence_actions('wpinvoicing.com', 'membership',array(95, 106, 108,12351)); |
|
41 | + ?> |
|
42 | 42 | </p> |
43 | 43 | <?php }?> |
44 | 44 | |
@@ -48,13 +48,13 @@ discard block |
||
48 | 48 | <div class="feature-list"> |
49 | 49 | <ul> |
50 | 50 | <?php |
51 | - $addon_obj = new WPInv_Admin_Addons(); |
|
52 | - if ($addons = $addon_obj->get_section_data( 'addons' ) ) { |
|
53 | - foreach ( $addons as $addon ) { |
|
54 | - echo '<li><i class="far fa-check-circle fa-sm"></i> '.esc_html( $addon->info->title ).'</li>'; |
|
55 | - } |
|
56 | - } |
|
57 | - ?> |
|
51 | + $addon_obj = new WPInv_Admin_Addons(); |
|
52 | + if ($addons = $addon_obj->get_section_data( 'addons' ) ) { |
|
53 | + foreach ( $addons as $addon ) { |
|
54 | + echo '<li><i class="far fa-check-circle fa-sm"></i> '.esc_html( $addon->info->title ).'</li>'; |
|
55 | + } |
|
56 | + } |
|
57 | + ?> |
|
58 | 58 | </ul> |
59 | 59 | |
60 | 60 | <div class="feature-cta"> |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | <h3><?php _e("Included Gateways:","invoicing");?></h3> |
66 | 66 | <ul> |
67 | 67 | <?php |
68 | - if ($addons = $addon_obj->get_section_data( 'gateways' ) ) { |
|
69 | - foreach ( $addons as $addon ) { |
|
70 | - echo '<li><i class="far fa-check-circle fa-sm"></i> '.esc_html( $addon->info->title ).'</li>'; |
|
71 | - } |
|
72 | - } |
|
73 | - ?> |
|
68 | + if ($addons = $addon_obj->get_section_data( 'gateways' ) ) { |
|
69 | + foreach ( $addons as $addon ) { |
|
70 | + echo '<li><i class="far fa-check-circle fa-sm"></i> '.esc_html( $addon->info->title ).'</li>'; |
|
71 | + } |
|
72 | + } |
|
73 | + ?> |
|
74 | 74 | </ul> |
75 | 75 | </div> |
76 | 76 | |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | <div class="testimonial-content"> |
82 | 82 | <div class="t-image"> |
83 | 83 | <?php |
84 | - echo '<img src="' . plugins_url( 'images/t-image2.png', dirname(__FILE__) ) . '" > '; |
|
85 | - ?> |
|
84 | + echo '<img src="' . plugins_url( 'images/t-image2.png', dirname(__FILE__) ) . '" > '; |
|
85 | + ?> |
|
86 | 86 | </div> |
87 | 87 | <div class="t-content"> |
88 | 88 | <p> |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | <div class="testimonial-content"> |
102 | 102 | <div class="t-image"> |
103 | 103 | <?php |
104 | - echo '<img src="' . plugins_url( 'images/t-image1.png', dirname(__FILE__) ) . '" > '; |
|
105 | - ?> |
|
104 | + echo '<img src="' . plugins_url( 'images/t-image1.png', dirname(__FILE__) ) . '" > '; |
|
105 | + ?> |
|
106 | 106 | </div> |
107 | 107 | <div class="t-content"> |
108 | 108 | <p> |
@@ -126,20 +126,20 @@ discard block |
||
126 | 126 | </div> |
127 | 127 | </div> |
128 | 128 | <?php |
129 | - }else{ |
|
130 | - $installed_plugins = get_plugins(); |
|
129 | + }else{ |
|
130 | + $installed_plugins = get_plugins(); |
|
131 | 131 | $addon_obj = new WPInv_Admin_Addons(); |
132 | - if ($addons = $addon_obj->get_section_data( $current_tab ) ) : |
|
133 | - ?> |
|
132 | + if ($addons = $addon_obj->get_section_data( $current_tab ) ) : |
|
133 | + ?> |
|
134 | 134 | <ul class="wpi-products"><?php foreach ( $addons as $addon ) : |
135 | 135 | if(965==$addon->info->id){continue;}// don't show quote add on |
136 | - ?><li class="wpi-product"> |
|
136 | + ?><li class="wpi-product"> |
|
137 | 137 | <div class="wpi-product-title"> |
138 | 138 | <h3><?php |
139 | - if ( ! empty( $addon->info->excerpt) ){ |
|
140 | - echo wpi_help_tip( $addon->info->excerpt ); |
|
141 | - } |
|
142 | - echo esc_html( $addon->info->title ); ?></h3> |
|
139 | + if ( ! empty( $addon->info->excerpt) ){ |
|
140 | + echo wpi_help_tip( $addon->info->excerpt ); |
|
141 | + } |
|
142 | + echo esc_html( $addon->info->title ); ?></h3> |
|
143 | 143 | </div> |
144 | 144 | |
145 | 145 | <span class="wpi-product-image"> |
@@ -147,27 +147,27 @@ discard block |
||
147 | 147 | <img src="<?php echo esc_attr( $addon->info->thumbnail ); ?>"/> |
148 | 148 | <?php endif; |
149 | 149 | |
150 | - if(isset($addon->info->link) && substr( $addon->info->link, 0, 21 ) === "https://wordpress.org"){ |
|
151 | - echo '<a href="'.admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug).'&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
|
152 | - echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
153 | - echo '</a>'; |
|
154 | - }elseif(isset($addon->info->link) && substr( $addon->info->link, 0, 23 ) === "https://wpinvoicing.com"){ |
|
155 | - if(defined('WP_EASY_UPDATES_ACTIVE')){ |
|
156 | - $url = admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug.'&width=770&height=660&item_id='.$addon->info->id.'&update_url=https://wpinvoicing.com&TB_iframe=true'); |
|
157 | - }else{ |
|
158 | - // if installed show activation link |
|
159 | - if(isset($installed_plugins['wp-easy-updates/external-updates.php'])){ |
|
160 | - $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
|
161 | - }else{ |
|
162 | - $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
|
163 | - } |
|
164 | - } |
|
165 | - echo '<a href="'.$url.'" class="thickbox">'; |
|
166 | - echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
167 | - echo '</a>'; |
|
168 | - } |
|
169 | - |
|
170 | - ?> |
|
150 | + if(isset($addon->info->link) && substr( $addon->info->link, 0, 21 ) === "https://wordpress.org"){ |
|
151 | + echo '<a href="'.admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug).'&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
|
152 | + echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
153 | + echo '</a>'; |
|
154 | + }elseif(isset($addon->info->link) && substr( $addon->info->link, 0, 23 ) === "https://wpinvoicing.com"){ |
|
155 | + if(defined('WP_EASY_UPDATES_ACTIVE')){ |
|
156 | + $url = admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug.'&width=770&height=660&item_id='.$addon->info->id.'&update_url=https://wpinvoicing.com&TB_iframe=true'); |
|
157 | + }else{ |
|
158 | + // if installed show activation link |
|
159 | + if(isset($installed_plugins['wp-easy-updates/external-updates.php'])){ |
|
160 | + $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
|
161 | + }else{ |
|
162 | + $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
|
163 | + } |
|
164 | + } |
|
165 | + echo '<a href="'.$url.'" class="thickbox">'; |
|
166 | + echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
167 | + echo '</a>'; |
|
168 | + } |
|
169 | + |
|
170 | + ?> |
|
171 | 171 | |
172 | 172 | </span> |
173 | 173 | |
@@ -175,15 +175,15 @@ discard block |
||
175 | 175 | <span class="wpi-product-button"> |
176 | 176 | <?php |
177 | 177 | $addon_obj->output_button( $addon ); |
178 | - ?> |
|
178 | + ?> |
|
179 | 179 | </span> |
180 | 180 | |
181 | 181 | <span class="wpi-price"><?php //print_r($addon); //echo wp_kses_post( $addon->price ); ?></span></li><?php endforeach; ?></ul> |
182 | 182 | <?php endif; |
183 | - } |
|
183 | + } |
|
184 | 184 | |
185 | - } |
|
186 | - ?> |
|
185 | + } |
|
186 | + ?> |
|
187 | 187 | |
188 | 188 | |
189 | 189 | <div class="clearfix" ></div> |
@@ -202,8 +202,8 @@ discard block |
||
202 | 202 | <input class="wpeu-licence-key" type="text" placeholder="<?php _e("Enter your licence key",'invoicing');?>"> <button class="button-primary wpeu-licence-popup-button" ><?php _e("Install",'invoicing');?></button> |
203 | 203 | <br> |
204 | 204 | <?php |
205 | - echo sprintf( __('%sFind your licence key here%s OR %sBuy one here%s', 'invoicing'), '<a href="https://wpinvoicing.com/your-account/" target="_blank">','</a>','<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">','</a>' ); |
|
206 | - ?> |
|
205 | + echo sprintf( __('%sFind your licence key here%s OR %sBuy one here%s', 'invoicing'), '<a href="https://wpinvoicing.com/your-account/" target="_blank">','</a>','<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">','</a>' ); |
|
206 | + ?> |
|
207 | 207 | </span> |
208 | 208 | </div> |
209 | 209 |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Admin View: Page - Addons |
4 | 4 | * |
5 | 5 | */ |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | add_ThickBox(); |
@@ -11,19 +11,19 @@ discard block |
||
11 | 11 | <div class="wrap wpi_addons_wrap"> |
12 | 12 | <h1><?php echo get_admin_page_title(); ?></h1> |
13 | 13 | |
14 | - <?php if ( $tabs ){ ?> |
|
14 | + <?php if ($tabs) { ?> |
|
15 | 15 | <nav class="nav-tab-wrapper wpi-nav-tab-wrapper"> |
16 | 16 | <?php |
17 | - foreach ( $tabs as $name => $label ) { |
|
18 | - echo '<a href="' . admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . $label . '</a>'; |
|
17 | + foreach ($tabs as $name => $label) { |
|
18 | + echo '<a href="' . admin_url('admin.php?page=wpi-addons&tab=' . $name) . '" class="nav-tab ' . ($current_tab == $name ? 'nav-tab-active' : '') . '">' . $label . '</a>'; |
|
19 | 19 | } |
20 | - do_action( 'wpi_addons_tabs' ); |
|
20 | + do_action('wpi_addons_tabs'); |
|
21 | 21 | ?> |
22 | 22 | </nav> |
23 | 23 | |
24 | 24 | <?php |
25 | 25 | |
26 | - if($current_tab == 'membership'){ |
|
26 | + if ($current_tab == 'membership') { |
|
27 | 27 | |
28 | 28 | ?> |
29 | 29 | |
@@ -32,42 +32,42 @@ discard block |
||
32 | 32 | <!-- |
33 | 33 | <h2>With our WPInvoicing Membership you get access to all our products!</h2> |
34 | 34 | <p><a class="button button-primary" href="https://wpinvoicing.com/downloads/membership/">View Memberships</a></p>--> |
35 | - <?php if(defined('WP_EASY_UPDATES_ACTIVE')){?> |
|
36 | - <h2><?php _e("Have a membership key?","invoicing");?></h2> |
|
35 | + <?php if (defined('WP_EASY_UPDATES_ACTIVE')) {?> |
|
36 | + <h2><?php _e("Have a membership key?", "invoicing"); ?></h2> |
|
37 | 37 | <p> |
38 | 38 | <?php |
39 | - $wpeu_admin = new External_Updates_Admin('wpinvoicing.com','1'); |
|
40 | - echo $wpeu_admin->render_licence_actions('wpinvoicing.com', 'membership',array(95, 106, 108,12351)); |
|
39 | + $wpeu_admin = new External_Updates_Admin('wpinvoicing.com', '1'); |
|
40 | + echo $wpeu_admin->render_licence_actions('wpinvoicing.com', 'membership', array(95, 106, 108, 12351)); |
|
41 | 41 | ?> |
42 | 42 | </p> |
43 | 43 | <?php }?> |
44 | 44 | |
45 | 45 | <div class="membership-cta-contet"> |
46 | 46 | <div class="main-cta"> |
47 | - <h2><?php _e("Membership benefits Include:","invoicing");?></h2> |
|
47 | + <h2><?php _e("Membership benefits Include:", "invoicing"); ?></h2> |
|
48 | 48 | <div class="feature-list"> |
49 | 49 | <ul> |
50 | 50 | <?php |
51 | 51 | $addon_obj = new WPInv_Admin_Addons(); |
52 | - if ($addons = $addon_obj->get_section_data( 'addons' ) ) { |
|
53 | - foreach ( $addons as $addon ) { |
|
54 | - echo '<li><i class="far fa-check-circle fa-sm"></i> '.esc_html( $addon->info->title ).'</li>'; |
|
52 | + if ($addons = $addon_obj->get_section_data('addons')) { |
|
53 | + foreach ($addons as $addon) { |
|
54 | + echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html($addon->info->title) . '</li>'; |
|
55 | 55 | } |
56 | 56 | } |
57 | 57 | ?> |
58 | 58 | </ul> |
59 | 59 | |
60 | 60 | <div class="feature-cta"> |
61 | - <h3><?php _e("Membership Starts from","invoicing");?></h3> |
|
61 | + <h3><?php _e("Membership Starts from", "invoicing"); ?></h3> |
|
62 | 62 | <h4>$99</h4> |
63 | - <a href="https://wpinvoicing.com/downloads/membership/" target="_blank"><?php _e("Buy Membership","invoicing");?></a> |
|
63 | + <a href="https://wpinvoicing.com/downloads/membership/" target="_blank"><?php _e("Buy Membership", "invoicing"); ?></a> |
|
64 | 64 | </div> |
65 | - <h3><?php _e("Included Gateways:","invoicing");?></h3> |
|
65 | + <h3><?php _e("Included Gateways:", "invoicing"); ?></h3> |
|
66 | 66 | <ul> |
67 | 67 | <?php |
68 | - if ($addons = $addon_obj->get_section_data( 'gateways' ) ) { |
|
69 | - foreach ( $addons as $addon ) { |
|
70 | - echo '<li><i class="far fa-check-circle fa-sm"></i> '.esc_html( $addon->info->title ).'</li>'; |
|
68 | + if ($addons = $addon_obj->get_section_data('gateways')) { |
|
69 | + foreach ($addons as $addon) { |
|
70 | + echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html($addon->info->title) . '</li>'; |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | ?> |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | <div class="testimonial-content"> |
82 | 82 | <div class="t-image"> |
83 | 83 | <?php |
84 | - echo '<img src="' . plugins_url( 'images/t-image2.png', dirname(__FILE__) ) . '" > '; |
|
84 | + echo '<img src="' . plugins_url('images/t-image2.png', dirname(__FILE__)) . '" > '; |
|
85 | 85 | ?> |
86 | 86 | </div> |
87 | 87 | <div class="t-content"> |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | <div class="testimonial-content"> |
102 | 102 | <div class="t-image"> |
103 | 103 | <?php |
104 | - echo '<img src="' . plugins_url( 'images/t-image1.png', dirname(__FILE__) ) . '" > '; |
|
104 | + echo '<img src="' . plugins_url('images/t-image1.png', dirname(__FILE__)) . '" > '; |
|
105 | 105 | ?> |
106 | 106 | </div> |
107 | 107 | <div class="t-content"> |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | </div> |
118 | 118 | </div> |
119 | 119 | <div class="member-footer"> |
120 | - <a class="footer-btn" href="https://wpinvoicing.com/downloads/membership/" target="_blank"><?php _e("Buy Membership","invoicing");?></a> |
|
121 | - <a class="footer-link" href="post-new.php?post_type=wpi_invoice"><?php _e("Create Invoice","invoicing");?></a> |
|
120 | + <a class="footer-btn" href="https://wpinvoicing.com/downloads/membership/" target="_blank"><?php _e("Buy Membership", "invoicing"); ?></a> |
|
121 | + <a class="footer-link" href="post-new.php?post_type=wpi_invoice"><?php _e("Create Invoice", "invoicing"); ?></a> |
|
122 | 122 | </div> |
123 | 123 | </div> |
124 | 124 | |
@@ -126,44 +126,44 @@ discard block |
||
126 | 126 | </div> |
127 | 127 | </div> |
128 | 128 | <?php |
129 | - }else{ |
|
129 | + } else { |
|
130 | 130 | $installed_plugins = get_plugins(); |
131 | 131 | $addon_obj = new WPInv_Admin_Addons(); |
132 | - if ($addons = $addon_obj->get_section_data( $current_tab ) ) : |
|
132 | + if ($addons = $addon_obj->get_section_data($current_tab)) : |
|
133 | 133 | ?> |
134 | - <ul class="wpi-products"><?php foreach ( $addons as $addon ) : |
|
135 | - if(965==$addon->info->id){continue;}// don't show quote add on |
|
134 | + <ul class="wpi-products"><?php foreach ($addons as $addon) : |
|
135 | + if (965 == $addon->info->id) {continue; }// don't show quote add on |
|
136 | 136 | ?><li class="wpi-product"> |
137 | 137 | <div class="wpi-product-title"> |
138 | 138 | <h3><?php |
139 | - if ( ! empty( $addon->info->excerpt) ){ |
|
140 | - echo wpi_help_tip( $addon->info->excerpt ); |
|
139 | + if (!empty($addon->info->excerpt)) { |
|
140 | + echo wpi_help_tip($addon->info->excerpt); |
|
141 | 141 | } |
142 | - echo esc_html( $addon->info->title ); ?></h3> |
|
142 | + echo esc_html($addon->info->title); ?></h3> |
|
143 | 143 | </div> |
144 | 144 | |
145 | 145 | <span class="wpi-product-image"> |
146 | - <?php if ( ! empty( $addon->info->thumbnail) ) : ?> |
|
147 | - <img src="<?php echo esc_attr( $addon->info->thumbnail ); ?>"/> |
|
146 | + <?php if (!empty($addon->info->thumbnail)) : ?> |
|
147 | + <img src="<?php echo esc_attr($addon->info->thumbnail); ?>"/> |
|
148 | 148 | <?php endif; |
149 | 149 | |
150 | - if(isset($addon->info->link) && substr( $addon->info->link, 0, 21 ) === "https://wordpress.org"){ |
|
151 | - echo '<a href="'.admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug).'&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
|
152 | - echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
150 | + if (isset($addon->info->link) && substr($addon->info->link, 0, 21) === "https://wordpress.org") { |
|
151 | + echo '<a href="' . admin_url('/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug) . '&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
|
152 | + echo '<span class="wpi-product-info">' . __('More info', 'invoicing') . '</span>'; |
|
153 | 153 | echo '</a>'; |
154 | - }elseif(isset($addon->info->link) && substr( $addon->info->link, 0, 23 ) === "https://wpinvoicing.com"){ |
|
155 | - if(defined('WP_EASY_UPDATES_ACTIVE')){ |
|
156 | - $url = admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug.'&width=770&height=660&item_id='.$addon->info->id.'&update_url=https://wpinvoicing.com&TB_iframe=true'); |
|
157 | - }else{ |
|
154 | + }elseif (isset($addon->info->link) && substr($addon->info->link, 0, 23) === "https://wpinvoicing.com") { |
|
155 | + if (defined('WP_EASY_UPDATES_ACTIVE')) { |
|
156 | + $url = admin_url('/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug . '&width=770&height=660&item_id=' . $addon->info->id . '&update_url=https://wpinvoicing.com&TB_iframe=true'); |
|
157 | + } else { |
|
158 | 158 | // if installed show activation link |
159 | - if(isset($installed_plugins['wp-easy-updates/external-updates.php'])){ |
|
159 | + if (isset($installed_plugins['wp-easy-updates/external-updates.php'])) { |
|
160 | 160 | $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
161 | - }else{ |
|
161 | + } else { |
|
162 | 162 | $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
163 | 163 | } |
164 | 164 | } |
165 | - echo '<a href="'.$url.'" class="thickbox">'; |
|
166 | - echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
165 | + echo '<a href="' . $url . '" class="thickbox">'; |
|
166 | + echo '<span class="wpi-product-info">' . __('More info', 'invoicing') . '</span>'; |
|
167 | 167 | echo '</a>'; |
168 | 168 | } |
169 | 169 | |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | |
175 | 175 | <span class="wpi-product-button"> |
176 | 176 | <?php |
177 | - $addon_obj->output_button( $addon ); |
|
177 | + $addon_obj->output_button($addon); |
|
178 | 178 | ?> |
179 | 179 | </span> |
180 | 180 | |
@@ -188,21 +188,21 @@ discard block |
||
188 | 188 | |
189 | 189 | <div class="clearfix" ></div> |
190 | 190 | |
191 | - <?php if($current_tab =='addons'){ ?> |
|
192 | - <p><?php printf( __( 'All of our Invoicing Addons can be found on WPInvoicing.com here: <a href="%s">Invoicing Addons</a>', 'invoicing' ), 'https://wpinvoicing.com/downloads/category/addons/' ); ?></p> |
|
193 | - <?php } if($current_tab =='gateways'){ ?> |
|
194 | - <p><?php printf( __( 'All of our Invoicing Payment Gateways can be found on WPInvoicing.com here: <a href="%s">Invoicing Payment Gateways</a>', 'invoicing' ), 'https://wpinvoicing.com/downloads/category/gateways/' ); ?></p> |
|
191 | + <?php if ($current_tab == 'addons') { ?> |
|
192 | + <p><?php printf(__('All of our Invoicing Addons can be found on WPInvoicing.com here: <a href="%s">Invoicing Addons</a>', 'invoicing'), 'https://wpinvoicing.com/downloads/category/addons/'); ?></p> |
|
193 | + <?php } if ($current_tab == 'gateways') { ?> |
|
194 | + <p><?php printf(__('All of our Invoicing Payment Gateways can be found on WPInvoicing.com here: <a href="%s">Invoicing Payment Gateways</a>', 'invoicing'), 'https://wpinvoicing.com/downloads/category/gateways/'); ?></p> |
|
195 | 195 | <?php } ?> |
196 | 196 | |
197 | - <div id="wpi-wpeu-required-activation" style="display:none;"><span class="wpi-notification "><?php printf( __("The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s'>activate</a> it now.",'invoicing'),wp_nonce_url(admin_url('plugins.php?action=activate&plugin=wp-easy-updates/external-updates.php'), 'activate-plugin_wp-easy-updates/external-updates.php'));?></span></div> |
|
198 | - <div id="wpi-wpeu-required-for-external" style="display:none;"><span class="wpi-notification "><?php printf( __("The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s' onclick='window.open(\"https://wpeasyupdates.com/wp-easy-updates.zip\", \"_blank\");' >download</a> and install it now.",'invoicing'),admin_url("plugin-install.php?tab=upload&wpeu-install=true"));?></span></div> |
|
197 | + <div id="wpi-wpeu-required-activation" style="display:none;"><span class="wpi-notification "><?php printf(__("The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s'>activate</a> it now.", 'invoicing'), wp_nonce_url(admin_url('plugins.php?action=activate&plugin=wp-easy-updates/external-updates.php'), 'activate-plugin_wp-easy-updates/external-updates.php')); ?></span></div> |
|
198 | + <div id="wpi-wpeu-required-for-external" style="display:none;"><span class="wpi-notification "><?php printf(__("The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s' onclick='window.open(\"https://wpeasyupdates.com/wp-easy-updates.zip\", \"_blank\");' >download</a> and install it now.", 'invoicing'), admin_url("plugin-install.php?tab=upload&wpeu-install=true")); ?></span></div> |
|
199 | 199 | <div id="wpeu-licence-popup" style="display:none;"> |
200 | 200 | <span class="wpi-notification noti-white"> |
201 | - <h3 class="wpeu-licence-title"><?php _e("Licence key",'invoicing');?></h3> |
|
202 | - <input class="wpeu-licence-key" type="text" placeholder="<?php _e("Enter your licence key",'invoicing');?>"> <button class="button-primary wpeu-licence-popup-button" ><?php _e("Install",'invoicing');?></button> |
|
201 | + <h3 class="wpeu-licence-title"><?php _e("Licence key", 'invoicing'); ?></h3> |
|
202 | + <input class="wpeu-licence-key" type="text" placeholder="<?php _e("Enter your licence key", 'invoicing'); ?>"> <button class="button-primary wpeu-licence-popup-button" ><?php _e("Install", 'invoicing'); ?></button> |
|
203 | 203 | <br> |
204 | 204 | <?php |
205 | - echo sprintf( __('%sFind your licence key here%s OR %sBuy one here%s', 'invoicing'), '<a href="https://wpinvoicing.com/your-account/" target="_blank">','</a>','<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">','</a>' ); |
|
205 | + echo sprintf(__('%sFind your licence key here%s OR %sBuy one here%s', 'invoicing'), '<a href="https://wpinvoicing.com/your-account/" target="_blank">', '</a>', '<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">', '</a>'); |
|
206 | 206 | ?> |
207 | 207 | </span> |
208 | 208 | </div> |
@@ -1,261 +1,261 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | if ( ! class_exists( 'WP_Super_Duper' ) ) { |
7 | 7 | |
8 | 8 | |
9 | - /** |
|
10 | - * A Class to be able to create a Widget, Shortcode or Block to be able to output content for WordPress. |
|
11 | - * |
|
12 | - * Should not be called direct but extended instead. |
|
13 | - * |
|
14 | - * Class WP_Super_Duper |
|
15 | - * @since 1.0.3 is_block_content_call() method added. |
|
16 | - * @since 1.0.3 Placeholder text will be shown for widget that return no block content. |
|
17 | - * @since 1.0.4 is_elementor_widget_output() method added. |
|
18 | - * @since 1.0.4 is_elementor_preview() method added. |
|
19 | - * @since 1.0.5 Block checkbox options are set as true by default even when set as false - FIXED |
|
20 | - * @since 1.0.6 Some refactoring for page builders - CHANGED |
|
21 | - * @since 1.0.7 Some refactoring for page builders - CHANGED |
|
22 | - * @since 1.0.8 Some refactoring for page builders ( cornerstone builder now supported ) - CHANGED |
|
23 | - * @since 1.0.9 Numbers saving as strings and not numbers which can cause block render issues on refresh - FIXED |
|
24 | - * @since 1.0.10 Some refactoring for page builders ( Avia builder for Enfold theme now supported ) - CHANGED |
|
25 | - * @since 1.0.11 Some refactoring for page builders - CHANGED |
|
26 | - * @since 1.0.12 A checkbox default value can make a argument true even when unchecked - FIXED |
|
27 | - * @since 1.0.13 Block values can break JS if contains a comma - FIXED |
|
28 | - * @since 1.0.14 Use of additional css class in block editor breaks the block html - FIXED |
|
29 | - * @since 1.0.15 Fix conflicts with GeneratePress sections - FIXED |
|
30 | - * @since 1.0.15 `group` setting option added to be able to group settings - ADDED |
|
31 | - * @since 1.0.15 `block-supports` options array now supported - ADDED |
|
32 | - * @since 1.0.15 `block-icon` now supports Font Awesome class - ADDED |
|
33 | - * @since 1.0.15 Fusion builder (Avada) elements automatically created - ADDED |
|
34 | - * @ver 1.0.15 |
|
35 | - */ |
|
36 | - class WP_Super_Duper extends WP_Widget { |
|
37 | - |
|
38 | - public $version = "1.0.15"; |
|
39 | - public $font_awesome_icon_version = "5.11.2"; |
|
40 | - public $block_code; |
|
41 | - public $options; |
|
42 | - public $base_id; |
|
43 | - public $arguments = array(); |
|
44 | - public $instance = array(); |
|
45 | - private $class_name; |
|
46 | - |
|
47 | - /** |
|
48 | - * The relative url to the current folder. |
|
49 | - * |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - public $url = ''; |
|
53 | - |
|
54 | - /** |
|
55 | - * Take the array options and use them to build. |
|
56 | - */ |
|
57 | - public function __construct( $options ) { |
|
58 | - global $sd_widgets; |
|
59 | - |
|
60 | - $sd_widgets[ $options['base_id'] ] = array( |
|
61 | - 'name' => $options['name'], |
|
62 | - 'class_name' => $options['class_name'] |
|
63 | - ); |
|
64 | - $this->base_id = $options['base_id']; |
|
65 | - // lets filter the options before we do anything |
|
66 | - $options = apply_filters( "wp_super_duper_options", $options ); |
|
67 | - $options = apply_filters( "wp_super_duper_options_{$this->base_id}", $options ); |
|
68 | - $options = $this->add_name_from_key( $options ); |
|
69 | - $this->options = $options; |
|
70 | - |
|
71 | - $this->base_id = $options['base_id']; |
|
72 | - $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array(); |
|
73 | - |
|
74 | - // init parent |
|
75 | - parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] ); |
|
76 | - |
|
77 | - if ( isset( $options['class_name'] ) ) { |
|
78 | - // register widget |
|
79 | - $this->class_name = $options['class_name']; |
|
80 | - |
|
81 | - // register shortcode |
|
82 | - $this->register_shortcode(); |
|
83 | - |
|
84 | - // Fusion Builder (avada) support |
|
85 | - if( function_exists('fusion_builder_map') ){ $this->register_fusion_element(); } |
|
86 | - |
|
87 | - // register block |
|
88 | - add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) ); |
|
89 | - } |
|
90 | - |
|
91 | - // add the CSS and JS we need ONCE |
|
92 | - global $sd_widget_scripts; |
|
93 | - |
|
94 | - if ( ! $sd_widget_scripts ) { |
|
95 | - wp_add_inline_script( 'admin-widgets', $this->widget_js() ); |
|
96 | - wp_add_inline_script( 'customize-controls', $this->widget_js() ); |
|
97 | - wp_add_inline_style( 'widgets', $this->widget_css() ); |
|
98 | - |
|
99 | - $sd_widget_scripts = true; |
|
100 | - |
|
101 | - // add shortcode insert button once |
|
102 | - add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) ); |
|
103 | - // generatepress theme sections compatibility |
|
104 | - if ( function_exists( 'generate_sections_sections_metabox' ) ) { |
|
105 | - add_action( 'generate_sections_metabox', array( $this, 'shortcode_insert_button_script' ) ); |
|
106 | - } |
|
107 | - if ( $this->is_preview() ) { |
|
108 | - add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) ); |
|
109 | - // this makes the insert button work for elementor |
|
110 | - add_action( 'elementor/editor/after_enqueue_scripts', array( |
|
111 | - $this, |
|
112 | - 'shortcode_insert_button_script' |
|
113 | - ) ); // for elementor |
|
114 | - } |
|
115 | - // this makes the insert button work for cornerstone |
|
116 | - add_action('wp_print_footer_scripts',array( __CLASS__, 'maybe_cornerstone_builder' )); |
|
117 | - |
|
118 | - add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) ); |
|
119 | - add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) ); |
|
120 | - |
|
121 | - // add generator text to admin head |
|
122 | - add_action( 'admin_head', array( $this, 'generator' ) ); |
|
123 | - } |
|
124 | - |
|
125 | - do_action( 'wp_super_duper_widget_init', $options, $this ); |
|
126 | - } |
|
127 | - |
|
128 | - public function register_fusion_element(){ |
|
129 | - |
|
130 | - $options = $this->options; |
|
131 | - |
|
132 | - if($this->base_id){ |
|
133 | - |
|
134 | - $params = $this->get_fusion_params(); |
|
135 | - |
|
136 | - $args = array( |
|
137 | - 'name' => $options['name'], |
|
138 | - 'shortcode' => $this->base_id, |
|
139 | - 'icon' => $options['block-icon'] ? $options['block-icon'] : 'far fa-square', |
|
140 | - 'allow_generator' => true, |
|
141 | - ); |
|
142 | - |
|
143 | - if(!empty($params)){ |
|
144 | - $args['params'] = $params; |
|
145 | - } |
|
146 | - |
|
147 | - fusion_builder_map($args); |
|
148 | - } |
|
149 | - |
|
150 | - } |
|
151 | - |
|
152 | - public function get_fusion_params(){ |
|
153 | - $params = array(); |
|
154 | - $arguments = $this->get_arguments(); |
|
155 | - |
|
156 | - if(!empty($arguments)){ |
|
157 | - foreach($arguments as $key => $val){ |
|
158 | - $param = array(); |
|
159 | - // type |
|
160 | - $param['type'] = str_replace( |
|
161 | - array( |
|
162 | - "text", |
|
163 | - "number", |
|
164 | - "email", |
|
165 | - "color", |
|
166 | - "checkbox" |
|
167 | - ), |
|
168 | - array( |
|
169 | - "textfield", |
|
170 | - "textfield", |
|
171 | - "textfield", |
|
172 | - "colorpicker", |
|
173 | - "select", |
|
174 | - |
|
175 | - ), |
|
176 | - $val['type']); |
|
177 | - |
|
178 | - // heading |
|
179 | - $param['heading'] = $val['title']; |
|
180 | - |
|
181 | - // description |
|
182 | - $param['description'] = isset($val['desc']) ? $val['desc'] : ''; |
|
183 | - |
|
184 | - // param_name |
|
185 | - $param['param_name'] = $key; |
|
9 | + /** |
|
10 | + * A Class to be able to create a Widget, Shortcode or Block to be able to output content for WordPress. |
|
11 | + * |
|
12 | + * Should not be called direct but extended instead. |
|
13 | + * |
|
14 | + * Class WP_Super_Duper |
|
15 | + * @since 1.0.3 is_block_content_call() method added. |
|
16 | + * @since 1.0.3 Placeholder text will be shown for widget that return no block content. |
|
17 | + * @since 1.0.4 is_elementor_widget_output() method added. |
|
18 | + * @since 1.0.4 is_elementor_preview() method added. |
|
19 | + * @since 1.0.5 Block checkbox options are set as true by default even when set as false - FIXED |
|
20 | + * @since 1.0.6 Some refactoring for page builders - CHANGED |
|
21 | + * @since 1.0.7 Some refactoring for page builders - CHANGED |
|
22 | + * @since 1.0.8 Some refactoring for page builders ( cornerstone builder now supported ) - CHANGED |
|
23 | + * @since 1.0.9 Numbers saving as strings and not numbers which can cause block render issues on refresh - FIXED |
|
24 | + * @since 1.0.10 Some refactoring for page builders ( Avia builder for Enfold theme now supported ) - CHANGED |
|
25 | + * @since 1.0.11 Some refactoring for page builders - CHANGED |
|
26 | + * @since 1.0.12 A checkbox default value can make a argument true even when unchecked - FIXED |
|
27 | + * @since 1.0.13 Block values can break JS if contains a comma - FIXED |
|
28 | + * @since 1.0.14 Use of additional css class in block editor breaks the block html - FIXED |
|
29 | + * @since 1.0.15 Fix conflicts with GeneratePress sections - FIXED |
|
30 | + * @since 1.0.15 `group` setting option added to be able to group settings - ADDED |
|
31 | + * @since 1.0.15 `block-supports` options array now supported - ADDED |
|
32 | + * @since 1.0.15 `block-icon` now supports Font Awesome class - ADDED |
|
33 | + * @since 1.0.15 Fusion builder (Avada) elements automatically created - ADDED |
|
34 | + * @ver 1.0.15 |
|
35 | + */ |
|
36 | + class WP_Super_Duper extends WP_Widget { |
|
37 | + |
|
38 | + public $version = "1.0.15"; |
|
39 | + public $font_awesome_icon_version = "5.11.2"; |
|
40 | + public $block_code; |
|
41 | + public $options; |
|
42 | + public $base_id; |
|
43 | + public $arguments = array(); |
|
44 | + public $instance = array(); |
|
45 | + private $class_name; |
|
46 | + |
|
47 | + /** |
|
48 | + * The relative url to the current folder. |
|
49 | + * |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + public $url = ''; |
|
53 | + |
|
54 | + /** |
|
55 | + * Take the array options and use them to build. |
|
56 | + */ |
|
57 | + public function __construct( $options ) { |
|
58 | + global $sd_widgets; |
|
59 | + |
|
60 | + $sd_widgets[ $options['base_id'] ] = array( |
|
61 | + 'name' => $options['name'], |
|
62 | + 'class_name' => $options['class_name'] |
|
63 | + ); |
|
64 | + $this->base_id = $options['base_id']; |
|
65 | + // lets filter the options before we do anything |
|
66 | + $options = apply_filters( "wp_super_duper_options", $options ); |
|
67 | + $options = apply_filters( "wp_super_duper_options_{$this->base_id}", $options ); |
|
68 | + $options = $this->add_name_from_key( $options ); |
|
69 | + $this->options = $options; |
|
70 | + |
|
71 | + $this->base_id = $options['base_id']; |
|
72 | + $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array(); |
|
73 | + |
|
74 | + // init parent |
|
75 | + parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] ); |
|
76 | + |
|
77 | + if ( isset( $options['class_name'] ) ) { |
|
78 | + // register widget |
|
79 | + $this->class_name = $options['class_name']; |
|
80 | + |
|
81 | + // register shortcode |
|
82 | + $this->register_shortcode(); |
|
83 | + |
|
84 | + // Fusion Builder (avada) support |
|
85 | + if( function_exists('fusion_builder_map') ){ $this->register_fusion_element(); } |
|
86 | + |
|
87 | + // register block |
|
88 | + add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) ); |
|
89 | + } |
|
90 | + |
|
91 | + // add the CSS and JS we need ONCE |
|
92 | + global $sd_widget_scripts; |
|
93 | + |
|
94 | + if ( ! $sd_widget_scripts ) { |
|
95 | + wp_add_inline_script( 'admin-widgets', $this->widget_js() ); |
|
96 | + wp_add_inline_script( 'customize-controls', $this->widget_js() ); |
|
97 | + wp_add_inline_style( 'widgets', $this->widget_css() ); |
|
98 | + |
|
99 | + $sd_widget_scripts = true; |
|
100 | + |
|
101 | + // add shortcode insert button once |
|
102 | + add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) ); |
|
103 | + // generatepress theme sections compatibility |
|
104 | + if ( function_exists( 'generate_sections_sections_metabox' ) ) { |
|
105 | + add_action( 'generate_sections_metabox', array( $this, 'shortcode_insert_button_script' ) ); |
|
106 | + } |
|
107 | + if ( $this->is_preview() ) { |
|
108 | + add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) ); |
|
109 | + // this makes the insert button work for elementor |
|
110 | + add_action( 'elementor/editor/after_enqueue_scripts', array( |
|
111 | + $this, |
|
112 | + 'shortcode_insert_button_script' |
|
113 | + ) ); // for elementor |
|
114 | + } |
|
115 | + // this makes the insert button work for cornerstone |
|
116 | + add_action('wp_print_footer_scripts',array( __CLASS__, 'maybe_cornerstone_builder' )); |
|
117 | + |
|
118 | + add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) ); |
|
119 | + add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) ); |
|
120 | + |
|
121 | + // add generator text to admin head |
|
122 | + add_action( 'admin_head', array( $this, 'generator' ) ); |
|
123 | + } |
|
124 | + |
|
125 | + do_action( 'wp_super_duper_widget_init', $options, $this ); |
|
126 | + } |
|
127 | + |
|
128 | + public function register_fusion_element(){ |
|
129 | + |
|
130 | + $options = $this->options; |
|
131 | + |
|
132 | + if($this->base_id){ |
|
133 | + |
|
134 | + $params = $this->get_fusion_params(); |
|
135 | + |
|
136 | + $args = array( |
|
137 | + 'name' => $options['name'], |
|
138 | + 'shortcode' => $this->base_id, |
|
139 | + 'icon' => $options['block-icon'] ? $options['block-icon'] : 'far fa-square', |
|
140 | + 'allow_generator' => true, |
|
141 | + ); |
|
142 | + |
|
143 | + if(!empty($params)){ |
|
144 | + $args['params'] = $params; |
|
145 | + } |
|
146 | + |
|
147 | + fusion_builder_map($args); |
|
148 | + } |
|
149 | + |
|
150 | + } |
|
151 | + |
|
152 | + public function get_fusion_params(){ |
|
153 | + $params = array(); |
|
154 | + $arguments = $this->get_arguments(); |
|
155 | + |
|
156 | + if(!empty($arguments)){ |
|
157 | + foreach($arguments as $key => $val){ |
|
158 | + $param = array(); |
|
159 | + // type |
|
160 | + $param['type'] = str_replace( |
|
161 | + array( |
|
162 | + "text", |
|
163 | + "number", |
|
164 | + "email", |
|
165 | + "color", |
|
166 | + "checkbox" |
|
167 | + ), |
|
168 | + array( |
|
169 | + "textfield", |
|
170 | + "textfield", |
|
171 | + "textfield", |
|
172 | + "colorpicker", |
|
173 | + "select", |
|
174 | + |
|
175 | + ), |
|
176 | + $val['type']); |
|
177 | + |
|
178 | + // heading |
|
179 | + $param['heading'] = $val['title']; |
|
180 | + |
|
181 | + // description |
|
182 | + $param['description'] = isset($val['desc']) ? $val['desc'] : ''; |
|
183 | + |
|
184 | + // param_name |
|
185 | + $param['param_name'] = $key; |
|
186 | 186 | |
187 | - // Default |
|
188 | - $param['default'] = isset($val['default']) ? $val['default'] : ''; |
|
189 | - |
|
190 | - // Group |
|
191 | - if(isset($val['group'])){ |
|
192 | - $param['group'] = $val['group']; |
|
193 | - } |
|
194 | - |
|
195 | - // value |
|
196 | - if($val['type'] == 'checkbox'){ |
|
197 | - if(isset($val['default']) && $val['default'] == '0'){ |
|
198 | - unset($param['default']); |
|
199 | - } |
|
200 | - $param['value'] = array(''=>__("No"),'1'=>__("Yes")); |
|
201 | - }elseif($param['type'] == 'select'){ |
|
202 | - $param['value'] = isset($val['options']) ? $val['options'] : array(); |
|
203 | - }else{ |
|
204 | - $param['value'] = isset($val['default']) ? $val['default'] : ''; |
|
205 | - } |
|
206 | - |
|
207 | - // setup the param |
|
208 | - $params[] = $param; |
|
209 | - |
|
210 | - } |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - return $params; |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder |
|
219 | - */ |
|
220 | - public static function maybe_cornerstone_builder(){ |
|
221 | - if(did_action('cornerstone_before_boot_app')){ |
|
222 | - self::shortcode_insert_button_script(); |
|
223 | - } |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * A function to ge the shortcode builder picker html. |
|
228 | - * |
|
229 | - * @param string $editor_id |
|
230 | - * |
|
231 | - * @return string |
|
232 | - */ |
|
233 | - public static function get_picker( $editor_id = '' ) { |
|
234 | - |
|
235 | - ob_start(); |
|
236 | - if ( isset( $_POST['editor_id'] ) ) { |
|
237 | - $editor_id = esc_attr( $_POST['editor_id'] ); |
|
238 | - } elseif ( isset( $_REQUEST['et_fb'] ) ) { |
|
239 | - $editor_id = 'main_content_content_vb_tiny_mce'; |
|
240 | - } |
|
241 | - |
|
242 | - global $sd_widgets; |
|
243 | - ?> |
|
187 | + // Default |
|
188 | + $param['default'] = isset($val['default']) ? $val['default'] : ''; |
|
189 | + |
|
190 | + // Group |
|
191 | + if(isset($val['group'])){ |
|
192 | + $param['group'] = $val['group']; |
|
193 | + } |
|
194 | + |
|
195 | + // value |
|
196 | + if($val['type'] == 'checkbox'){ |
|
197 | + if(isset($val['default']) && $val['default'] == '0'){ |
|
198 | + unset($param['default']); |
|
199 | + } |
|
200 | + $param['value'] = array(''=>__("No"),'1'=>__("Yes")); |
|
201 | + }elseif($param['type'] == 'select'){ |
|
202 | + $param['value'] = isset($val['options']) ? $val['options'] : array(); |
|
203 | + }else{ |
|
204 | + $param['value'] = isset($val['default']) ? $val['default'] : ''; |
|
205 | + } |
|
206 | + |
|
207 | + // setup the param |
|
208 | + $params[] = $param; |
|
209 | + |
|
210 | + } |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + return $params; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder |
|
219 | + */ |
|
220 | + public static function maybe_cornerstone_builder(){ |
|
221 | + if(did_action('cornerstone_before_boot_app')){ |
|
222 | + self::shortcode_insert_button_script(); |
|
223 | + } |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * A function to ge the shortcode builder picker html. |
|
228 | + * |
|
229 | + * @param string $editor_id |
|
230 | + * |
|
231 | + * @return string |
|
232 | + */ |
|
233 | + public static function get_picker( $editor_id = '' ) { |
|
234 | + |
|
235 | + ob_start(); |
|
236 | + if ( isset( $_POST['editor_id'] ) ) { |
|
237 | + $editor_id = esc_attr( $_POST['editor_id'] ); |
|
238 | + } elseif ( isset( $_REQUEST['et_fb'] ) ) { |
|
239 | + $editor_id = 'main_content_content_vb_tiny_mce'; |
|
240 | + } |
|
241 | + |
|
242 | + global $sd_widgets; |
|
243 | + ?> |
|
244 | 244 | |
245 | 245 | <div class="sd-shortcode-left-wrap"> |
246 | 246 | <?php |
247 | - ksort( $sd_widgets ); |
|
247 | + ksort( $sd_widgets ); |
|
248 | 248 | // print_r($sd_widgets);exit; |
249 | - if ( ! empty( $sd_widgets ) ) { |
|
250 | - echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">'; |
|
251 | - echo "<option>" . __( 'Select shortcode' ) . "</option>"; |
|
252 | - foreach ( $sd_widgets as $shortcode => $class ) { |
|
253 | - echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>"; |
|
254 | - } |
|
255 | - echo "</select>"; |
|
256 | - |
|
257 | - } |
|
258 | - ?> |
|
249 | + if ( ! empty( $sd_widgets ) ) { |
|
250 | + echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">'; |
|
251 | + echo "<option>" . __( 'Select shortcode' ) . "</option>"; |
|
252 | + foreach ( $sd_widgets as $shortcode => $class ) { |
|
253 | + echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>"; |
|
254 | + } |
|
255 | + echo "</select>"; |
|
256 | + |
|
257 | + } |
|
258 | + ?> |
|
259 | 259 | <div class="sd-shortcode-settings"></div> |
260 | 260 | |
261 | 261 | </div> |
@@ -266,8 +266,8 @@ discard block |
||
266 | 266 | <?php if ( $editor_id != '' ) { ?> |
267 | 267 | <button class="button sd-insert-shortcode-button" |
268 | 268 | onclick="sd_insert_shortcode(<?php if ( ! empty( $editor_id ) ) { |
269 | - echo "'" . $editor_id . "'"; |
|
270 | - } ?>)"><?php _e( 'Insert shortcode' ); ?></button> |
|
269 | + echo "'" . $editor_id . "'"; |
|
270 | + } ?>)"><?php _e( 'Insert shortcode' ); ?></button> |
|
271 | 271 | <?php } ?> |
272 | 272 | <button class="button" |
273 | 273 | onclick="sd_copy_to_clipboard()"><?php _e( 'Copy shortcode' ); ?></button> |
@@ -275,134 +275,134 @@ discard block |
||
275 | 275 | </div> |
276 | 276 | <?php |
277 | 277 | |
278 | - $html = ob_get_clean(); |
|
279 | - |
|
280 | - if ( wp_doing_ajax() ) { |
|
281 | - echo $html; |
|
282 | - $should_die = true; |
|
283 | - |
|
284 | - // some builder get the editor via ajax so we should not die on those ocasions |
|
285 | - $dont_die = array( |
|
286 | - 'parent_tag',// WP Bakery |
|
287 | - 'avia_request' // enfold |
|
288 | - ); |
|
289 | - |
|
290 | - foreach ( $dont_die as $request ) { |
|
291 | - if ( isset( $_REQUEST[ $request ] ) ) { |
|
292 | - $should_die = false; |
|
293 | - } |
|
294 | - } |
|
295 | - |
|
296 | - if ( $should_die ) { |
|
297 | - wp_die(); |
|
298 | - } |
|
299 | - |
|
300 | - } else { |
|
301 | - return $html; |
|
302 | - } |
|
303 | - |
|
304 | - return ''; |
|
305 | - |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Output the version in the admin header. |
|
310 | - */ |
|
311 | - public function generator() { |
|
312 | - echo '<meta name="generator" content="WP Super Duper v' . $this->version . '" />'; |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * Get widget settings. |
|
317 | - * |
|
318 | - * @since 1.0.0 |
|
319 | - */ |
|
320 | - public static function get_widget_settings() { |
|
321 | - global $sd_widgets; |
|
322 | - |
|
323 | - $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : ''; |
|
324 | - if ( ! $shortcode ) { |
|
325 | - wp_die(); |
|
326 | - } |
|
327 | - $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : ''; |
|
328 | - if ( ! $widget_args ) { |
|
329 | - wp_die(); |
|
330 | - } |
|
331 | - $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
332 | - if ( ! $class_name ) { |
|
333 | - wp_die(); |
|
334 | - } |
|
335 | - |
|
336 | - // invoke an instance method |
|
337 | - $widget = new $class_name; |
|
338 | - |
|
339 | - ob_start(); |
|
340 | - $widget->form( array() ); |
|
341 | - $form = ob_get_clean(); |
|
342 | - echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>"; |
|
343 | - echo "<style>" . $widget->widget_css() . "</style>"; |
|
344 | - echo "<script>" . $widget->widget_js() . "</script>"; |
|
345 | - ?> |
|
278 | + $html = ob_get_clean(); |
|
279 | + |
|
280 | + if ( wp_doing_ajax() ) { |
|
281 | + echo $html; |
|
282 | + $should_die = true; |
|
283 | + |
|
284 | + // some builder get the editor via ajax so we should not die on those ocasions |
|
285 | + $dont_die = array( |
|
286 | + 'parent_tag',// WP Bakery |
|
287 | + 'avia_request' // enfold |
|
288 | + ); |
|
289 | + |
|
290 | + foreach ( $dont_die as $request ) { |
|
291 | + if ( isset( $_REQUEST[ $request ] ) ) { |
|
292 | + $should_die = false; |
|
293 | + } |
|
294 | + } |
|
295 | + |
|
296 | + if ( $should_die ) { |
|
297 | + wp_die(); |
|
298 | + } |
|
299 | + |
|
300 | + } else { |
|
301 | + return $html; |
|
302 | + } |
|
303 | + |
|
304 | + return ''; |
|
305 | + |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Output the version in the admin header. |
|
310 | + */ |
|
311 | + public function generator() { |
|
312 | + echo '<meta name="generator" content="WP Super Duper v' . $this->version . '" />'; |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * Get widget settings. |
|
317 | + * |
|
318 | + * @since 1.0.0 |
|
319 | + */ |
|
320 | + public static function get_widget_settings() { |
|
321 | + global $sd_widgets; |
|
322 | + |
|
323 | + $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : ''; |
|
324 | + if ( ! $shortcode ) { |
|
325 | + wp_die(); |
|
326 | + } |
|
327 | + $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : ''; |
|
328 | + if ( ! $widget_args ) { |
|
329 | + wp_die(); |
|
330 | + } |
|
331 | + $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
332 | + if ( ! $class_name ) { |
|
333 | + wp_die(); |
|
334 | + } |
|
335 | + |
|
336 | + // invoke an instance method |
|
337 | + $widget = new $class_name; |
|
338 | + |
|
339 | + ob_start(); |
|
340 | + $widget->form( array() ); |
|
341 | + $form = ob_get_clean(); |
|
342 | + echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>"; |
|
343 | + echo "<style>" . $widget->widget_css() . "</style>"; |
|
344 | + echo "<script>" . $widget->widget_js() . "</script>"; |
|
345 | + ?> |
|
346 | 346 | <?php |
347 | - wp_die(); |
|
348 | - } |
|
349 | - |
|
350 | - /** |
|
351 | - * Insert shortcode builder button to classic editor (not inside Gutenberg, not needed). |
|
352 | - * |
|
353 | - * @since 1.0.0 |
|
354 | - * |
|
355 | - * @param string $editor_id Optional. Shortcode editor id. Default null. |
|
356 | - * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null. |
|
357 | - */ |
|
358 | - public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) { |
|
359 | - global $sd_widgets, $shortcode_insert_button_once; |
|
360 | - if ( $shortcode_insert_button_once ) { |
|
361 | - return; |
|
362 | - } |
|
363 | - add_thickbox(); |
|
364 | - |
|
365 | - |
|
366 | - /** |
|
367 | - * Cornerstone makes us play dirty tricks :/ |
|
368 | - * All media_buttons are removed via JS unless they are two specific id's so we wrap our content in this ID so it is not removed. |
|
369 | - */ |
|
370 | - if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
371 | - echo '<span id="insert-media-button">'; |
|
372 | - } |
|
373 | - |
|
374 | - echo self::shortcode_button( 'this', 'true' ); |
|
375 | - |
|
376 | - // see opening note |
|
377 | - if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
378 | - echo '</span>'; // end #insert-media-button |
|
379 | - } |
|
380 | - |
|
381 | - // Add separate script for generatepress theme sections |
|
382 | - if ( function_exists( 'generate_sections_sections_metabox' ) && did_action( 'generate_sections_metabox' ) ) { |
|
383 | - } else { |
|
384 | - self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function ); |
|
385 | - } |
|
386 | - |
|
387 | - $shortcode_insert_button_once = true; |
|
388 | - } |
|
389 | - |
|
390 | - /** |
|
391 | - * Gets the shortcode insert button html. |
|
392 | - * |
|
393 | - * @param string $id |
|
394 | - * @param string $search_for_id |
|
395 | - * |
|
396 | - * @return mixed |
|
397 | - */ |
|
398 | - public static function shortcode_button( $id = '', $search_for_id = '' ) { |
|
399 | - ob_start(); |
|
400 | - ?> |
|
347 | + wp_die(); |
|
348 | + } |
|
349 | + |
|
350 | + /** |
|
351 | + * Insert shortcode builder button to classic editor (not inside Gutenberg, not needed). |
|
352 | + * |
|
353 | + * @since 1.0.0 |
|
354 | + * |
|
355 | + * @param string $editor_id Optional. Shortcode editor id. Default null. |
|
356 | + * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null. |
|
357 | + */ |
|
358 | + public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) { |
|
359 | + global $sd_widgets, $shortcode_insert_button_once; |
|
360 | + if ( $shortcode_insert_button_once ) { |
|
361 | + return; |
|
362 | + } |
|
363 | + add_thickbox(); |
|
364 | + |
|
365 | + |
|
366 | + /** |
|
367 | + * Cornerstone makes us play dirty tricks :/ |
|
368 | + * All media_buttons are removed via JS unless they are two specific id's so we wrap our content in this ID so it is not removed. |
|
369 | + */ |
|
370 | + if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
371 | + echo '<span id="insert-media-button">'; |
|
372 | + } |
|
373 | + |
|
374 | + echo self::shortcode_button( 'this', 'true' ); |
|
375 | + |
|
376 | + // see opening note |
|
377 | + if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
378 | + echo '</span>'; // end #insert-media-button |
|
379 | + } |
|
380 | + |
|
381 | + // Add separate script for generatepress theme sections |
|
382 | + if ( function_exists( 'generate_sections_sections_metabox' ) && did_action( 'generate_sections_metabox' ) ) { |
|
383 | + } else { |
|
384 | + self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function ); |
|
385 | + } |
|
386 | + |
|
387 | + $shortcode_insert_button_once = true; |
|
388 | + } |
|
389 | + |
|
390 | + /** |
|
391 | + * Gets the shortcode insert button html. |
|
392 | + * |
|
393 | + * @param string $id |
|
394 | + * @param string $search_for_id |
|
395 | + * |
|
396 | + * @return mixed |
|
397 | + */ |
|
398 | + public static function shortcode_button( $id = '', $search_for_id = '' ) { |
|
399 | + ob_start(); |
|
400 | + ?> |
|
401 | 401 | <span class="sd-lable-shortcode-inserter"> |
402 | 402 | <a onclick="sd_ajax_get_picker(<?php echo $id; |
403 | - if ( $search_for_id ) { |
|
404 | - echo "," . $search_for_id; |
|
405 | - } ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed" |
|
403 | + if ( $search_for_id ) { |
|
404 | + echo "," . $search_for_id; |
|
405 | + } ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed" |
|
406 | 406 | class="thickbox button super-duper-content-open" title="Add Shortcode"> |
407 | 407 | <span style="vertical-align: middle;line-height: 18px;font-size: 20px;" |
408 | 408 | class="dashicons dashicons-screenoptions"></span> |
@@ -413,21 +413,21 @@ discard block |
||
413 | 413 | </span> |
414 | 414 | |
415 | 415 | <?php |
416 | - $html = ob_get_clean(); |
|
417 | - |
|
418 | - // remove line breaks so we can use it in js |
|
419 | - return preg_replace( "/\r|\n/", "", trim( $html ) ); |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * Makes SD work with the siteOrigin page builder. |
|
424 | - * |
|
425 | - * @since 1.0.6 |
|
426 | - * @return mixed |
|
427 | - */ |
|
428 | - public static function siteorigin_js() { |
|
429 | - ob_start(); |
|
430 | - ?> |
|
416 | + $html = ob_get_clean(); |
|
417 | + |
|
418 | + // remove line breaks so we can use it in js |
|
419 | + return preg_replace( "/\r|\n/", "", trim( $html ) ); |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * Makes SD work with the siteOrigin page builder. |
|
424 | + * |
|
425 | + * @since 1.0.6 |
|
426 | + * @return mixed |
|
427 | + */ |
|
428 | + public static function siteorigin_js() { |
|
429 | + ob_start(); |
|
430 | + ?> |
|
431 | 431 | <script> |
432 | 432 | /** |
433 | 433 | * Check a form to see what items shoudl be shown or hidden. |
@@ -505,28 +505,28 @@ discard block |
||
505 | 505 | }); |
506 | 506 | </script> |
507 | 507 | <?php |
508 | - $output = ob_get_clean(); |
|
508 | + $output = ob_get_clean(); |
|
509 | 509 | |
510 | - /* |
|
510 | + /* |
|
511 | 511 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
512 | 512 | */ |
513 | 513 | |
514 | - return str_replace( array( |
|
515 | - '<script>', |
|
516 | - '</script>' |
|
517 | - ), '', $output ); |
|
518 | - } |
|
519 | - |
|
520 | - /** |
|
521 | - * Output the JS and CSS for the shortcode insert button. |
|
522 | - * |
|
523 | - * @since 1.0.6 |
|
524 | - * |
|
525 | - * @param string $editor_id |
|
526 | - * @param string $insert_shortcode_function |
|
527 | - */ |
|
528 | - public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) { |
|
529 | - ?> |
|
514 | + return str_replace( array( |
|
515 | + '<script>', |
|
516 | + '</script>' |
|
517 | + ), '', $output ); |
|
518 | + } |
|
519 | + |
|
520 | + /** |
|
521 | + * Output the JS and CSS for the shortcode insert button. |
|
522 | + * |
|
523 | + * @since 1.0.6 |
|
524 | + * |
|
525 | + * @param string $editor_id |
|
526 | + * @param string $insert_shortcode_function |
|
527 | + */ |
|
528 | + public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) { |
|
529 | + ?> |
|
530 | 530 | <style> |
531 | 531 | .sd-shortcode-left-wrap { |
532 | 532 | float: left; |
@@ -650,35 +650,35 @@ discard block |
||
650 | 650 | <?php } ?> |
651 | 651 | </style> |
652 | 652 | <?php |
653 | - if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
654 | - echo "<script>" . self::siteorigin_js() . "</script>"; |
|
655 | - } |
|
656 | - ?> |
|
653 | + if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
654 | + echo "<script>" . self::siteorigin_js() . "</script>"; |
|
655 | + } |
|
656 | + ?> |
|
657 | 657 | <script> |
658 | 658 | <?php |
659 | - if(! empty( $insert_shortcode_function )){ |
|
660 | - echo $insert_shortcode_function; |
|
661 | - }else{ |
|
662 | - |
|
663 | - /** |
|
664 | - * Function for super duper insert shortcode. |
|
665 | - * |
|
666 | - * @since 1.0.0 |
|
667 | - */ |
|
668 | - ?> |
|
659 | + if(! empty( $insert_shortcode_function )){ |
|
660 | + echo $insert_shortcode_function; |
|
661 | + }else{ |
|
662 | + |
|
663 | + /** |
|
664 | + * Function for super duper insert shortcode. |
|
665 | + * |
|
666 | + * @since 1.0.0 |
|
667 | + */ |
|
668 | + ?> |
|
669 | 669 | function sd_insert_shortcode($editor_id) { |
670 | 670 | $shortcode = jQuery('#TB_ajaxContent #sd-shortcode-output').val(); |
671 | 671 | if ($shortcode) { |
672 | 672 | if (!$editor_id) { |
673 | 673 | <?php |
674 | - if ( isset( $_REQUEST['et_fb'] ) ) { |
|
675 | - echo '$editor_id = "#main_content_content_vb_tiny_mce";'; |
|
676 | - } elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) { |
|
677 | - echo '$editor_id = "#elementor-controls .wp-editor-container textarea";'; |
|
678 | - } else { |
|
679 | - echo '$editor_id = "#wp-content-editor-container textarea";'; |
|
680 | - } |
|
681 | - ?> |
|
674 | + if ( isset( $_REQUEST['et_fb'] ) ) { |
|
675 | + echo '$editor_id = "#main_content_content_vb_tiny_mce";'; |
|
676 | + } elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) { |
|
677 | + echo '$editor_id = "#elementor-controls .wp-editor-container textarea";'; |
|
678 | + } else { |
|
679 | + echo '$editor_id = "#wp-content-editor-container textarea";'; |
|
680 | + } |
|
681 | + ?> |
|
682 | 682 | } else { |
683 | 683 | $editor_id = '#' + $editor_id; |
684 | 684 | } |
@@ -993,16 +993,16 @@ discard block |
||
993 | 993 | |
994 | 994 | </script> |
995 | 995 | <?php |
996 | - } |
|
997 | - |
|
998 | - /** |
|
999 | - * Gets some CSS for the widgets screen. |
|
1000 | - * |
|
1001 | - * @return mixed |
|
1002 | - */ |
|
1003 | - public function widget_css() { |
|
1004 | - ob_start(); |
|
1005 | - ?> |
|
996 | + } |
|
997 | + |
|
998 | + /** |
|
999 | + * Gets some CSS for the widgets screen. |
|
1000 | + * |
|
1001 | + * @return mixed |
|
1002 | + */ |
|
1003 | + public function widget_css() { |
|
1004 | + ob_start(); |
|
1005 | + ?> |
|
1006 | 1006 | <style> |
1007 | 1007 | .sd-advanced-setting { |
1008 | 1008 | display: none; |
@@ -1037,26 +1037,26 @@ discard block |
||
1037 | 1037 | } |
1038 | 1038 | </style> |
1039 | 1039 | <?php |
1040 | - $output = ob_get_clean(); |
|
1040 | + $output = ob_get_clean(); |
|
1041 | 1041 | |
1042 | - /* |
|
1042 | + /* |
|
1043 | 1043 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
1044 | 1044 | */ |
1045 | 1045 | |
1046 | - return str_replace( array( |
|
1047 | - '<style>', |
|
1048 | - '</style>' |
|
1049 | - ), '', $output ); |
|
1050 | - } |
|
1051 | - |
|
1052 | - /** |
|
1053 | - * Gets some JS for the widgets screen. |
|
1054 | - * |
|
1055 | - * @return mixed |
|
1056 | - */ |
|
1057 | - public function widget_js() { |
|
1058 | - ob_start(); |
|
1059 | - ?> |
|
1046 | + return str_replace( array( |
|
1047 | + '<style>', |
|
1048 | + '</style>' |
|
1049 | + ), '', $output ); |
|
1050 | + } |
|
1051 | + |
|
1052 | + /** |
|
1053 | + * Gets some JS for the widgets screen. |
|
1054 | + * |
|
1055 | + * @return mixed |
|
1056 | + */ |
|
1057 | + public function widget_js() { |
|
1058 | + ob_start(); |
|
1059 | + ?> |
|
1060 | 1060 | <script> |
1061 | 1061 | |
1062 | 1062 | /** |
@@ -1211,392 +1211,392 @@ discard block |
||
1211 | 1211 | <?php do_action( 'wp_super_duper_widget_js', $this ); ?> |
1212 | 1212 | </script> |
1213 | 1213 | <?php |
1214 | - $output = ob_get_clean(); |
|
1214 | + $output = ob_get_clean(); |
|
1215 | 1215 | |
1216 | - /* |
|
1216 | + /* |
|
1217 | 1217 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
1218 | 1218 | */ |
1219 | 1219 | |
1220 | - return str_replace( array( |
|
1221 | - '<script>', |
|
1222 | - '</script>' |
|
1223 | - ), '', $output ); |
|
1224 | - } |
|
1225 | - |
|
1226 | - |
|
1227 | - /** |
|
1228 | - * Set the name from the argument key. |
|
1229 | - * |
|
1230 | - * @param $options |
|
1231 | - * |
|
1232 | - * @return mixed |
|
1233 | - */ |
|
1234 | - private function add_name_from_key( $options, $arguments = false ) { |
|
1235 | - if ( ! empty( $options['arguments'] ) ) { |
|
1236 | - foreach ( $options['arguments'] as $key => $val ) { |
|
1237 | - $options['arguments'][ $key ]['name'] = $key; |
|
1238 | - } |
|
1239 | - } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) { |
|
1240 | - foreach ( $options as $key => $val ) { |
|
1241 | - $options[ $key ]['name'] = $key; |
|
1242 | - } |
|
1243 | - } |
|
1244 | - |
|
1245 | - return $options; |
|
1246 | - } |
|
1247 | - |
|
1248 | - /** |
|
1249 | - * Register the parent shortcode. |
|
1250 | - * |
|
1251 | - * @since 1.0.0 |
|
1252 | - */ |
|
1253 | - public function register_shortcode() { |
|
1254 | - add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) ); |
|
1255 | - add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) ); |
|
1256 | - } |
|
1257 | - |
|
1258 | - /** |
|
1259 | - * Render the shortcode via ajax so we can return it to Gutenberg. |
|
1260 | - * |
|
1261 | - * @since 1.0.0 |
|
1262 | - */ |
|
1263 | - public static function render_shortcode() { |
|
1264 | - |
|
1265 | - check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true ); |
|
1266 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
1267 | - wp_die(); |
|
1268 | - } |
|
1269 | - |
|
1270 | - // we might need the $post value here so lets set it. |
|
1271 | - if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) { |
|
1272 | - $post_obj = get_post( absint( $_POST['post_id'] ) ); |
|
1273 | - if ( ! empty( $post_obj ) && empty( $post ) ) { |
|
1274 | - global $post; |
|
1275 | - $post = $post_obj; |
|
1276 | - } |
|
1277 | - } |
|
1278 | - |
|
1279 | - if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) { |
|
1280 | - $shortcode_name = sanitize_title_with_dashes( $_POST['shortcode'] ); |
|
1281 | - $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
1282 | - $attributes = ''; |
|
1283 | - if ( ! empty( $attributes_array ) ) { |
|
1284 | - foreach ( $attributes_array as $key => $value ) { |
|
1285 | - $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' "; |
|
1286 | - } |
|
1287 | - } |
|
1288 | - |
|
1289 | - $shortcode = "[" . $shortcode_name . " " . $attributes . "]"; |
|
1290 | - |
|
1291 | - echo do_shortcode( $shortcode ); |
|
1292 | - |
|
1293 | - } |
|
1294 | - wp_die(); |
|
1295 | - } |
|
1296 | - |
|
1297 | - /** |
|
1298 | - * Output the shortcode. |
|
1299 | - * |
|
1300 | - * @param array $args |
|
1301 | - * @param string $content |
|
1302 | - * |
|
1303 | - * @return string |
|
1304 | - */ |
|
1305 | - public function shortcode_output( $args = array(), $content = '' ) { |
|
1306 | - $args = self::argument_values( $args ); |
|
1307 | - |
|
1308 | - // add extra argument so we know its a output to gutenberg |
|
1309 | - //$args |
|
1310 | - $args = $this->string_to_bool( $args ); |
|
1311 | - |
|
1312 | - |
|
1313 | - $calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : ''; |
|
1314 | - |
|
1315 | - $calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this ); |
|
1316 | - $calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this ); |
|
1317 | - |
|
1318 | - $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this ); |
|
1319 | - $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this ); |
|
1320 | - |
|
1321 | - $shortcode_args = array(); |
|
1322 | - $output = ''; |
|
1323 | - $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false; |
|
1324 | - $main_content = $this->output( $args, $shortcode_args, $content ); |
|
1325 | - if ( $main_content && ! $no_wrap ) { |
|
1326 | - // wrap the shortcode in a dive with the same class as the widget |
|
1327 | - $output .= '<div class="' . $calss . '" ' . $attrs . '>'; |
|
1328 | - if ( ! empty( $args['title'] ) ) { |
|
1329 | - // if its a shortcode and there is a title try to grab the title wrappers |
|
1330 | - $shortcode_args = array( 'before_title' => '', 'after_title' => '' ); |
|
1331 | - if ( empty( $instance ) ) { |
|
1332 | - global $wp_registered_sidebars; |
|
1333 | - if ( ! empty( $wp_registered_sidebars ) ) { |
|
1334 | - foreach ( $wp_registered_sidebars as $sidebar ) { |
|
1335 | - if ( ! empty( $sidebar['before_title'] ) ) { |
|
1336 | - $shortcode_args['before_title'] = $sidebar['before_title']; |
|
1337 | - $shortcode_args['after_title'] = $sidebar['after_title']; |
|
1338 | - break; |
|
1339 | - } |
|
1340 | - } |
|
1341 | - } |
|
1342 | - } |
|
1343 | - $output .= $this->output_title( $shortcode_args, $args ); |
|
1344 | - } |
|
1345 | - $output .= $main_content; |
|
1346 | - $output .= '</div>'; |
|
1347 | - } elseif ( $main_content && $no_wrap ) { |
|
1348 | - $output .= $main_content; |
|
1349 | - } |
|
1350 | - |
|
1351 | - // if preview show a placeholder if empty |
|
1352 | - if ( $this->is_preview() && $output == '' ) { |
|
1353 | - $output = $this->preview_placeholder_text( "[{" . $this->base_id . "}]" ); |
|
1354 | - } |
|
1355 | - |
|
1356 | - return apply_filters( 'wp_super_duper_widget_output', $output, $args, $shortcode_args, $this ); |
|
1357 | - } |
|
1358 | - |
|
1359 | - /** |
|
1360 | - * Placeholder text to show if output is empty and we are on a preview/builder page. |
|
1361 | - * |
|
1362 | - * @param string $name |
|
1363 | - * |
|
1364 | - * @return string |
|
1365 | - */ |
|
1366 | - public function preview_placeholder_text( $name = '' ) { |
|
1367 | - return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>"; |
|
1368 | - } |
|
1369 | - |
|
1370 | - /** |
|
1371 | - * Sometimes booleans values can be turned to strings, so we fix that. |
|
1372 | - * |
|
1373 | - * @param $options |
|
1374 | - * |
|
1375 | - * @return mixed |
|
1376 | - */ |
|
1377 | - public function string_to_bool( $options ) { |
|
1378 | - // convert bool strings to booleans |
|
1379 | - foreach ( $options as $key => $val ) { |
|
1380 | - if ( $val == 'false' ) { |
|
1381 | - $options[ $key ] = false; |
|
1382 | - } elseif ( $val == 'true' ) { |
|
1383 | - $options[ $key ] = true; |
|
1384 | - } |
|
1385 | - } |
|
1386 | - |
|
1387 | - return $options; |
|
1388 | - } |
|
1389 | - |
|
1390 | - /** |
|
1391 | - * Get the argument values that are also filterable. |
|
1392 | - * |
|
1393 | - * @param $instance |
|
1394 | - * |
|
1395 | - * @since 1.0.12 Don't set checkbox default value if the value is empty. |
|
1396 | - * |
|
1397 | - * @return array |
|
1398 | - */ |
|
1399 | - public function argument_values( $instance ) { |
|
1400 | - $argument_values = array(); |
|
1401 | - |
|
1402 | - // set widget instance |
|
1403 | - $this->instance = $instance; |
|
1404 | - |
|
1405 | - if ( empty( $this->arguments ) ) { |
|
1406 | - $this->arguments = $this->get_arguments(); |
|
1407 | - } |
|
1408 | - |
|
1409 | - if ( ! empty( $this->arguments ) ) { |
|
1410 | - foreach ( $this->arguments as $key => $args ) { |
|
1411 | - // set the input name from the key |
|
1412 | - $args['name'] = $key; |
|
1413 | - // |
|
1414 | - $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
|
1415 | - if($args['type']=='checkbox' && $argument_values[ $key ] == ''){ |
|
1416 | - // don't set default for an empty checkbox |
|
1417 | - } |
|
1418 | - elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
1419 | - $argument_values[ $key ] = $args['default']; |
|
1420 | - } |
|
1421 | - } |
|
1422 | - } |
|
1423 | - |
|
1424 | - return $argument_values; |
|
1425 | - } |
|
1426 | - |
|
1427 | - /** |
|
1428 | - * Set arguments in super duper. |
|
1429 | - * |
|
1430 | - * @since 1.0.0 |
|
1431 | - * |
|
1432 | - * @return array Set arguments. |
|
1433 | - */ |
|
1434 | - public function set_arguments() { |
|
1435 | - return $this->arguments; |
|
1436 | - } |
|
1437 | - |
|
1438 | - /** |
|
1439 | - * Get arguments in super duper. |
|
1440 | - * |
|
1441 | - * @since 1.0.0 |
|
1442 | - * |
|
1443 | - * @return array Get arguments. |
|
1444 | - */ |
|
1445 | - public function get_arguments() { |
|
1446 | - if ( empty( $this->arguments ) ) { |
|
1447 | - $this->arguments = $this->set_arguments(); |
|
1448 | - } |
|
1449 | - |
|
1450 | - $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance ); |
|
1451 | - $this->arguments = $this->add_name_from_key( $this->arguments, true ); |
|
1452 | - |
|
1453 | - return $this->arguments; |
|
1454 | - } |
|
1455 | - |
|
1456 | - /** |
|
1457 | - * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class. |
|
1458 | - * |
|
1459 | - * @param array $args |
|
1460 | - * @param array $widget_args |
|
1461 | - * @param string $content |
|
1462 | - */ |
|
1463 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
1464 | - |
|
1465 | - } |
|
1466 | - |
|
1467 | - /** |
|
1468 | - * Add the dynamic block code inline when the wp-block in enqueued. |
|
1469 | - */ |
|
1470 | - public function register_block() { |
|
1471 | - wp_add_inline_script( 'wp-blocks', $this->block() ); |
|
1472 | - if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
1473 | - |
|
1474 | - wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() ); |
|
1475 | - |
|
1476 | - } |
|
1477 | - } |
|
1478 | - |
|
1479 | - /** |
|
1480 | - * Check if we need to show advanced options. |
|
1481 | - * |
|
1482 | - * @return bool |
|
1483 | - */ |
|
1484 | - public function block_show_advanced() { |
|
1485 | - |
|
1486 | - $show = false; |
|
1487 | - $arguments = $this->arguments; |
|
1488 | - |
|
1489 | - if ( empty( $arguments ) ) { |
|
1490 | - $arguments = $this->get_arguments(); |
|
1491 | - } |
|
1492 | - |
|
1493 | - if ( ! empty( $arguments ) ) { |
|
1494 | - foreach ( $arguments as $argument ) { |
|
1495 | - if ( isset( $argument['advanced'] ) && $argument['advanced'] ) { |
|
1496 | - $show = true; |
|
1497 | - break; // no need to continue if we know we have it |
|
1498 | - } |
|
1499 | - } |
|
1500 | - } |
|
1501 | - |
|
1502 | - return $show; |
|
1503 | - } |
|
1504 | - |
|
1505 | - /** |
|
1506 | - * Get the url path to the current folder. |
|
1507 | - * |
|
1508 | - * @return string |
|
1509 | - */ |
|
1510 | - public function get_url() { |
|
1511 | - |
|
1512 | - $url = $this->url; |
|
1513 | - |
|
1514 | - if(!$url){ |
|
1515 | - // check if we are inside a plugin |
|
1516 | - $file_dir = str_replace("/includes","", dirname( __FILE__ )); |
|
1517 | - |
|
1518 | - $dir_parts = explode("/wp-content/",$file_dir); |
|
1519 | - $url_parts = explode("/wp-content/",plugins_url()); |
|
1520 | - |
|
1521 | - if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
|
1522 | - $url = trailingslashit( $url_parts[0]."/wp-content/".$dir_parts[1] ); |
|
1523 | - $this->url = $url; |
|
1524 | - } |
|
1525 | - } |
|
1526 | - |
|
1527 | - |
|
1528 | - return $url; |
|
1529 | - } |
|
1530 | - |
|
1531 | - /** |
|
1532 | - * Generate the block icon. |
|
1533 | - * |
|
1534 | - * Enables the use of Font Awesome icons. |
|
1535 | - * |
|
1536 | - * @note xlink:href is actually deprecated but href is not supported by all so we use both. |
|
1537 | - * @param $icon |
|
1538 | - * @since 1.1.0 |
|
1539 | - * @return string |
|
1540 | - */ |
|
1541 | - public function get_block_icon($icon){ |
|
1542 | - |
|
1543 | - // check if we have a Font Awesome icon |
|
1544 | - $fa_type = ''; |
|
1545 | - if(substr( $icon, 0, 7 ) === "fas fa-"){ |
|
1546 | - $fa_type = 'solid'; |
|
1547 | - }elseif(substr( $icon, 0, 7 ) === "far fa-"){ |
|
1548 | - $fa_type = 'regular'; |
|
1549 | - }elseif(substr( $icon, 0, 7 ) === "fab fa-"){ |
|
1550 | - $fa_type = 'brands'; |
|
1551 | - }else{ |
|
1552 | - $icon = "'".$icon."'"; |
|
1553 | - } |
|
1554 | - |
|
1555 | - // set the icon if we found one |
|
1556 | - if($fa_type){ |
|
1557 | - $fa_icon = str_replace(array("fas fa-","far fa-","fab fa-"),"",$icon); |
|
1558 | - $icon = "el('svg',{width: 20, height: 20, viewBox: '0 0 20 20'},el('use', {'xlink:href': '".$this->get_url()."icons/".$fa_type.".svg#".$fa_icon."','href': '".$this->get_url()."icons/".$fa_type.".svg#".$fa_icon."'}))"; |
|
1559 | - } |
|
1560 | - |
|
1561 | - return $icon; |
|
1562 | - } |
|
1563 | - |
|
1564 | - public function group_arguments($arguments){ |
|
1220 | + return str_replace( array( |
|
1221 | + '<script>', |
|
1222 | + '</script>' |
|
1223 | + ), '', $output ); |
|
1224 | + } |
|
1225 | + |
|
1226 | + |
|
1227 | + /** |
|
1228 | + * Set the name from the argument key. |
|
1229 | + * |
|
1230 | + * @param $options |
|
1231 | + * |
|
1232 | + * @return mixed |
|
1233 | + */ |
|
1234 | + private function add_name_from_key( $options, $arguments = false ) { |
|
1235 | + if ( ! empty( $options['arguments'] ) ) { |
|
1236 | + foreach ( $options['arguments'] as $key => $val ) { |
|
1237 | + $options['arguments'][ $key ]['name'] = $key; |
|
1238 | + } |
|
1239 | + } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) { |
|
1240 | + foreach ( $options as $key => $val ) { |
|
1241 | + $options[ $key ]['name'] = $key; |
|
1242 | + } |
|
1243 | + } |
|
1244 | + |
|
1245 | + return $options; |
|
1246 | + } |
|
1247 | + |
|
1248 | + /** |
|
1249 | + * Register the parent shortcode. |
|
1250 | + * |
|
1251 | + * @since 1.0.0 |
|
1252 | + */ |
|
1253 | + public function register_shortcode() { |
|
1254 | + add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) ); |
|
1255 | + add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) ); |
|
1256 | + } |
|
1257 | + |
|
1258 | + /** |
|
1259 | + * Render the shortcode via ajax so we can return it to Gutenberg. |
|
1260 | + * |
|
1261 | + * @since 1.0.0 |
|
1262 | + */ |
|
1263 | + public static function render_shortcode() { |
|
1264 | + |
|
1265 | + check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true ); |
|
1266 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
1267 | + wp_die(); |
|
1268 | + } |
|
1269 | + |
|
1270 | + // we might need the $post value here so lets set it. |
|
1271 | + if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) { |
|
1272 | + $post_obj = get_post( absint( $_POST['post_id'] ) ); |
|
1273 | + if ( ! empty( $post_obj ) && empty( $post ) ) { |
|
1274 | + global $post; |
|
1275 | + $post = $post_obj; |
|
1276 | + } |
|
1277 | + } |
|
1278 | + |
|
1279 | + if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) { |
|
1280 | + $shortcode_name = sanitize_title_with_dashes( $_POST['shortcode'] ); |
|
1281 | + $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
1282 | + $attributes = ''; |
|
1283 | + if ( ! empty( $attributes_array ) ) { |
|
1284 | + foreach ( $attributes_array as $key => $value ) { |
|
1285 | + $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' "; |
|
1286 | + } |
|
1287 | + } |
|
1288 | + |
|
1289 | + $shortcode = "[" . $shortcode_name . " " . $attributes . "]"; |
|
1290 | + |
|
1291 | + echo do_shortcode( $shortcode ); |
|
1292 | + |
|
1293 | + } |
|
1294 | + wp_die(); |
|
1295 | + } |
|
1296 | + |
|
1297 | + /** |
|
1298 | + * Output the shortcode. |
|
1299 | + * |
|
1300 | + * @param array $args |
|
1301 | + * @param string $content |
|
1302 | + * |
|
1303 | + * @return string |
|
1304 | + */ |
|
1305 | + public function shortcode_output( $args = array(), $content = '' ) { |
|
1306 | + $args = self::argument_values( $args ); |
|
1307 | + |
|
1308 | + // add extra argument so we know its a output to gutenberg |
|
1309 | + //$args |
|
1310 | + $args = $this->string_to_bool( $args ); |
|
1311 | + |
|
1312 | + |
|
1313 | + $calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : ''; |
|
1314 | + |
|
1315 | + $calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this ); |
|
1316 | + $calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this ); |
|
1317 | + |
|
1318 | + $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this ); |
|
1319 | + $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this ); |
|
1320 | + |
|
1321 | + $shortcode_args = array(); |
|
1322 | + $output = ''; |
|
1323 | + $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false; |
|
1324 | + $main_content = $this->output( $args, $shortcode_args, $content ); |
|
1325 | + if ( $main_content && ! $no_wrap ) { |
|
1326 | + // wrap the shortcode in a dive with the same class as the widget |
|
1327 | + $output .= '<div class="' . $calss . '" ' . $attrs . '>'; |
|
1328 | + if ( ! empty( $args['title'] ) ) { |
|
1329 | + // if its a shortcode and there is a title try to grab the title wrappers |
|
1330 | + $shortcode_args = array( 'before_title' => '', 'after_title' => '' ); |
|
1331 | + if ( empty( $instance ) ) { |
|
1332 | + global $wp_registered_sidebars; |
|
1333 | + if ( ! empty( $wp_registered_sidebars ) ) { |
|
1334 | + foreach ( $wp_registered_sidebars as $sidebar ) { |
|
1335 | + if ( ! empty( $sidebar['before_title'] ) ) { |
|
1336 | + $shortcode_args['before_title'] = $sidebar['before_title']; |
|
1337 | + $shortcode_args['after_title'] = $sidebar['after_title']; |
|
1338 | + break; |
|
1339 | + } |
|
1340 | + } |
|
1341 | + } |
|
1342 | + } |
|
1343 | + $output .= $this->output_title( $shortcode_args, $args ); |
|
1344 | + } |
|
1345 | + $output .= $main_content; |
|
1346 | + $output .= '</div>'; |
|
1347 | + } elseif ( $main_content && $no_wrap ) { |
|
1348 | + $output .= $main_content; |
|
1349 | + } |
|
1350 | + |
|
1351 | + // if preview show a placeholder if empty |
|
1352 | + if ( $this->is_preview() && $output == '' ) { |
|
1353 | + $output = $this->preview_placeholder_text( "[{" . $this->base_id . "}]" ); |
|
1354 | + } |
|
1355 | + |
|
1356 | + return apply_filters( 'wp_super_duper_widget_output', $output, $args, $shortcode_args, $this ); |
|
1357 | + } |
|
1358 | + |
|
1359 | + /** |
|
1360 | + * Placeholder text to show if output is empty and we are on a preview/builder page. |
|
1361 | + * |
|
1362 | + * @param string $name |
|
1363 | + * |
|
1364 | + * @return string |
|
1365 | + */ |
|
1366 | + public function preview_placeholder_text( $name = '' ) { |
|
1367 | + return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>"; |
|
1368 | + } |
|
1369 | + |
|
1370 | + /** |
|
1371 | + * Sometimes booleans values can be turned to strings, so we fix that. |
|
1372 | + * |
|
1373 | + * @param $options |
|
1374 | + * |
|
1375 | + * @return mixed |
|
1376 | + */ |
|
1377 | + public function string_to_bool( $options ) { |
|
1378 | + // convert bool strings to booleans |
|
1379 | + foreach ( $options as $key => $val ) { |
|
1380 | + if ( $val == 'false' ) { |
|
1381 | + $options[ $key ] = false; |
|
1382 | + } elseif ( $val == 'true' ) { |
|
1383 | + $options[ $key ] = true; |
|
1384 | + } |
|
1385 | + } |
|
1386 | + |
|
1387 | + return $options; |
|
1388 | + } |
|
1389 | + |
|
1390 | + /** |
|
1391 | + * Get the argument values that are also filterable. |
|
1392 | + * |
|
1393 | + * @param $instance |
|
1394 | + * |
|
1395 | + * @since 1.0.12 Don't set checkbox default value if the value is empty. |
|
1396 | + * |
|
1397 | + * @return array |
|
1398 | + */ |
|
1399 | + public function argument_values( $instance ) { |
|
1400 | + $argument_values = array(); |
|
1401 | + |
|
1402 | + // set widget instance |
|
1403 | + $this->instance = $instance; |
|
1404 | + |
|
1405 | + if ( empty( $this->arguments ) ) { |
|
1406 | + $this->arguments = $this->get_arguments(); |
|
1407 | + } |
|
1408 | + |
|
1409 | + if ( ! empty( $this->arguments ) ) { |
|
1410 | + foreach ( $this->arguments as $key => $args ) { |
|
1411 | + // set the input name from the key |
|
1412 | + $args['name'] = $key; |
|
1413 | + // |
|
1414 | + $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
|
1415 | + if($args['type']=='checkbox' && $argument_values[ $key ] == ''){ |
|
1416 | + // don't set default for an empty checkbox |
|
1417 | + } |
|
1418 | + elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
1419 | + $argument_values[ $key ] = $args['default']; |
|
1420 | + } |
|
1421 | + } |
|
1422 | + } |
|
1423 | + |
|
1424 | + return $argument_values; |
|
1425 | + } |
|
1426 | + |
|
1427 | + /** |
|
1428 | + * Set arguments in super duper. |
|
1429 | + * |
|
1430 | + * @since 1.0.0 |
|
1431 | + * |
|
1432 | + * @return array Set arguments. |
|
1433 | + */ |
|
1434 | + public function set_arguments() { |
|
1435 | + return $this->arguments; |
|
1436 | + } |
|
1437 | + |
|
1438 | + /** |
|
1439 | + * Get arguments in super duper. |
|
1440 | + * |
|
1441 | + * @since 1.0.0 |
|
1442 | + * |
|
1443 | + * @return array Get arguments. |
|
1444 | + */ |
|
1445 | + public function get_arguments() { |
|
1446 | + if ( empty( $this->arguments ) ) { |
|
1447 | + $this->arguments = $this->set_arguments(); |
|
1448 | + } |
|
1449 | + |
|
1450 | + $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance ); |
|
1451 | + $this->arguments = $this->add_name_from_key( $this->arguments, true ); |
|
1452 | + |
|
1453 | + return $this->arguments; |
|
1454 | + } |
|
1455 | + |
|
1456 | + /** |
|
1457 | + * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class. |
|
1458 | + * |
|
1459 | + * @param array $args |
|
1460 | + * @param array $widget_args |
|
1461 | + * @param string $content |
|
1462 | + */ |
|
1463 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
1464 | + |
|
1465 | + } |
|
1466 | + |
|
1467 | + /** |
|
1468 | + * Add the dynamic block code inline when the wp-block in enqueued. |
|
1469 | + */ |
|
1470 | + public function register_block() { |
|
1471 | + wp_add_inline_script( 'wp-blocks', $this->block() ); |
|
1472 | + if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
1473 | + |
|
1474 | + wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() ); |
|
1475 | + |
|
1476 | + } |
|
1477 | + } |
|
1478 | + |
|
1479 | + /** |
|
1480 | + * Check if we need to show advanced options. |
|
1481 | + * |
|
1482 | + * @return bool |
|
1483 | + */ |
|
1484 | + public function block_show_advanced() { |
|
1485 | + |
|
1486 | + $show = false; |
|
1487 | + $arguments = $this->arguments; |
|
1488 | + |
|
1489 | + if ( empty( $arguments ) ) { |
|
1490 | + $arguments = $this->get_arguments(); |
|
1491 | + } |
|
1492 | + |
|
1493 | + if ( ! empty( $arguments ) ) { |
|
1494 | + foreach ( $arguments as $argument ) { |
|
1495 | + if ( isset( $argument['advanced'] ) && $argument['advanced'] ) { |
|
1496 | + $show = true; |
|
1497 | + break; // no need to continue if we know we have it |
|
1498 | + } |
|
1499 | + } |
|
1500 | + } |
|
1501 | + |
|
1502 | + return $show; |
|
1503 | + } |
|
1504 | + |
|
1505 | + /** |
|
1506 | + * Get the url path to the current folder. |
|
1507 | + * |
|
1508 | + * @return string |
|
1509 | + */ |
|
1510 | + public function get_url() { |
|
1511 | + |
|
1512 | + $url = $this->url; |
|
1513 | + |
|
1514 | + if(!$url){ |
|
1515 | + // check if we are inside a plugin |
|
1516 | + $file_dir = str_replace("/includes","", dirname( __FILE__ )); |
|
1517 | + |
|
1518 | + $dir_parts = explode("/wp-content/",$file_dir); |
|
1519 | + $url_parts = explode("/wp-content/",plugins_url()); |
|
1520 | + |
|
1521 | + if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
|
1522 | + $url = trailingslashit( $url_parts[0]."/wp-content/".$dir_parts[1] ); |
|
1523 | + $this->url = $url; |
|
1524 | + } |
|
1525 | + } |
|
1526 | + |
|
1527 | + |
|
1528 | + return $url; |
|
1529 | + } |
|
1530 | + |
|
1531 | + /** |
|
1532 | + * Generate the block icon. |
|
1533 | + * |
|
1534 | + * Enables the use of Font Awesome icons. |
|
1535 | + * |
|
1536 | + * @note xlink:href is actually deprecated but href is not supported by all so we use both. |
|
1537 | + * @param $icon |
|
1538 | + * @since 1.1.0 |
|
1539 | + * @return string |
|
1540 | + */ |
|
1541 | + public function get_block_icon($icon){ |
|
1542 | + |
|
1543 | + // check if we have a Font Awesome icon |
|
1544 | + $fa_type = ''; |
|
1545 | + if(substr( $icon, 0, 7 ) === "fas fa-"){ |
|
1546 | + $fa_type = 'solid'; |
|
1547 | + }elseif(substr( $icon, 0, 7 ) === "far fa-"){ |
|
1548 | + $fa_type = 'regular'; |
|
1549 | + }elseif(substr( $icon, 0, 7 ) === "fab fa-"){ |
|
1550 | + $fa_type = 'brands'; |
|
1551 | + }else{ |
|
1552 | + $icon = "'".$icon."'"; |
|
1553 | + } |
|
1554 | + |
|
1555 | + // set the icon if we found one |
|
1556 | + if($fa_type){ |
|
1557 | + $fa_icon = str_replace(array("fas fa-","far fa-","fab fa-"),"",$icon); |
|
1558 | + $icon = "el('svg',{width: 20, height: 20, viewBox: '0 0 20 20'},el('use', {'xlink:href': '".$this->get_url()."icons/".$fa_type.".svg#".$fa_icon."','href': '".$this->get_url()."icons/".$fa_type.".svg#".$fa_icon."'}))"; |
|
1559 | + } |
|
1560 | + |
|
1561 | + return $icon; |
|
1562 | + } |
|
1563 | + |
|
1564 | + public function group_arguments($arguments){ |
|
1565 | 1565 | // echo '###';print_r($arguments); |
1566 | - if(!empty($arguments)){ |
|
1567 | - $temp_arguments = array(); |
|
1568 | - $general = __("General"); |
|
1569 | - $add_sections = false; |
|
1570 | - foreach($arguments as $key => $args){ |
|
1571 | - if(isset($args['group'])){ |
|
1572 | - $temp_arguments[$args['group']][$key] = $args; |
|
1573 | - $add_sections = true; |
|
1574 | - }else{ |
|
1575 | - $temp_arguments[$general][$key] = $args; |
|
1576 | - } |
|
1577 | - } |
|
1578 | - |
|
1579 | - // only add sections if more than one |
|
1580 | - if($add_sections){ |
|
1581 | - $arguments = $temp_arguments; |
|
1582 | - } |
|
1583 | - } |
|
1566 | + if(!empty($arguments)){ |
|
1567 | + $temp_arguments = array(); |
|
1568 | + $general = __("General"); |
|
1569 | + $add_sections = false; |
|
1570 | + foreach($arguments as $key => $args){ |
|
1571 | + if(isset($args['group'])){ |
|
1572 | + $temp_arguments[$args['group']][$key] = $args; |
|
1573 | + $add_sections = true; |
|
1574 | + }else{ |
|
1575 | + $temp_arguments[$general][$key] = $args; |
|
1576 | + } |
|
1577 | + } |
|
1578 | + |
|
1579 | + // only add sections if more than one |
|
1580 | + if($add_sections){ |
|
1581 | + $arguments = $temp_arguments; |
|
1582 | + } |
|
1583 | + } |
|
1584 | 1584 | // echo '###';print_r($arguments); |
1585 | - return $arguments; |
|
1586 | - } |
|
1587 | - |
|
1588 | - |
|
1589 | - /** |
|
1590 | - * Output the JS for building the dynamic Guntenberg block. |
|
1591 | - * |
|
1592 | - * @since 1.0.4 Added block_wrap property which will set the block wrapping output element ie: div, span, p or empty for no wrap. |
|
1593 | - * @since 1.0.9 Save numbers as numbers and not strings. |
|
1594 | - * @since 1.1.0 Font Awesome classes can be used for icons. |
|
1595 | - * @return mixed |
|
1596 | - */ |
|
1597 | - public function block() { |
|
1598 | - ob_start(); |
|
1599 | - ?> |
|
1585 | + return $arguments; |
|
1586 | + } |
|
1587 | + |
|
1588 | + |
|
1589 | + /** |
|
1590 | + * Output the JS for building the dynamic Guntenberg block. |
|
1591 | + * |
|
1592 | + * @since 1.0.4 Added block_wrap property which will set the block wrapping output element ie: div, span, p or empty for no wrap. |
|
1593 | + * @since 1.0.9 Save numbers as numbers and not strings. |
|
1594 | + * @since 1.1.0 Font Awesome classes can be used for icons. |
|
1595 | + * @return mixed |
|
1596 | + */ |
|
1597 | + public function block() { |
|
1598 | + ob_start(); |
|
1599 | + ?> |
|
1600 | 1600 | <script> |
1601 | 1601 | /** |
1602 | 1602 | * BLOCK: Basic |
@@ -1635,88 +1635,88 @@ discard block |
||
1635 | 1635 | icon: <?php echo $this->get_block_icon($this->options['block-icon']);?>,//'<?php echo isset( $this->options['block-icon'] ) ? esc_attr( $this->options['block-icon'] ) : 'shield-alt';?>', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/. |
1636 | 1636 | supports: { |
1637 | 1637 | <?php |
1638 | - if(isset($this->options['block-supports'])){ |
|
1639 | - echo $this->array_to_attributes( $this->options['block-supports'] ); |
|
1640 | - } |
|
1641 | - ?> |
|
1638 | + if(isset($this->options['block-supports'])){ |
|
1639 | + echo $this->array_to_attributes( $this->options['block-supports'] ); |
|
1640 | + } |
|
1641 | + ?> |
|
1642 | 1642 | }, |
1643 | 1643 | category: '<?php echo isset( $this->options['block-category'] ) ? esc_attr( $this->options['block-category'] ) : 'common';?>', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed. |
1644 | 1644 | <?php if ( isset( $this->options['block-keywords'] ) ) { |
1645 | - echo "keywords : " . $this->options['block-keywords'] . ","; |
|
1646 | - }?> |
|
1645 | + echo "keywords : " . $this->options['block-keywords'] . ","; |
|
1646 | + }?> |
|
1647 | 1647 | |
1648 | 1648 | <?php |
1649 | 1649 | |
1650 | - $show_advanced = $this->block_show_advanced(); |
|
1650 | + $show_advanced = $this->block_show_advanced(); |
|
1651 | 1651 | |
1652 | - $show_alignment = false; |
|
1653 | - // align feature |
|
1654 | - /*echo "supports: {"; |
|
1652 | + $show_alignment = false; |
|
1653 | + // align feature |
|
1654 | + /*echo "supports: {"; |
|
1655 | 1655 | echo " align: true,"; |
1656 | 1656 | echo " html: false"; |
1657 | 1657 | echo "},";*/ |
1658 | 1658 | |
1659 | - if ( ! empty( $this->arguments ) ) { |
|
1660 | - echo "attributes : {"; |
|
1661 | - |
|
1662 | - if ( $show_advanced ) { |
|
1663 | - echo "show_advanced: {"; |
|
1664 | - echo " type: 'boolean',"; |
|
1665 | - echo " default: false,"; |
|
1666 | - echo "},"; |
|
1667 | - } |
|
1668 | - |
|
1669 | - // block wrap element |
|
1670 | - if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this? |
|
1671 | - echo "block_wrap: {"; |
|
1672 | - echo " type: 'string',"; |
|
1673 | - echo " default: '" . esc_attr( $this->options['block-wrap'] ) . "',"; |
|
1674 | - echo "},"; |
|
1675 | - } |
|
1676 | - |
|
1677 | - foreach ( $this->arguments as $key => $args ) { |
|
1678 | - |
|
1679 | - // set if we should show alignment |
|
1680 | - if ( $key == 'alignment' ) { |
|
1681 | - $show_alignment = true; |
|
1682 | - } |
|
1683 | - |
|
1684 | - $extra = ''; |
|
1685 | - |
|
1686 | - if ( $args['type'] == 'checkbox' ) { |
|
1687 | - $type = 'boolean'; |
|
1688 | - $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false'; |
|
1689 | - } elseif ( $args['type'] == 'number' ) { |
|
1690 | - $type = 'number'; |
|
1691 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1692 | - } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) { |
|
1693 | - $type = 'array'; |
|
1694 | - if ( is_array( $args['default'] ) ) { |
|
1695 | - $default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]"; |
|
1696 | - } else { |
|
1697 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1698 | - } |
|
1699 | - } elseif ( $args['type'] == 'multiselect' ) { |
|
1700 | - $type = 'array'; |
|
1701 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1702 | - } else { |
|
1703 | - $type = 'string'; |
|
1704 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1705 | - } |
|
1706 | - echo $key . " : {"; |
|
1707 | - echo "type : '$type',"; |
|
1708 | - echo "default : $default,"; |
|
1709 | - echo "},"; |
|
1710 | - } |
|
1711 | - |
|
1712 | - echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},"; |
|
1713 | - echo "className: { type: 'string', default: '' },"; |
|
1714 | - |
|
1715 | - echo "},"; |
|
1716 | - |
|
1717 | - } |
|
1718 | - |
|
1719 | - ?> |
|
1659 | + if ( ! empty( $this->arguments ) ) { |
|
1660 | + echo "attributes : {"; |
|
1661 | + |
|
1662 | + if ( $show_advanced ) { |
|
1663 | + echo "show_advanced: {"; |
|
1664 | + echo " type: 'boolean',"; |
|
1665 | + echo " default: false,"; |
|
1666 | + echo "},"; |
|
1667 | + } |
|
1668 | + |
|
1669 | + // block wrap element |
|
1670 | + if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this? |
|
1671 | + echo "block_wrap: {"; |
|
1672 | + echo " type: 'string',"; |
|
1673 | + echo " default: '" . esc_attr( $this->options['block-wrap'] ) . "',"; |
|
1674 | + echo "},"; |
|
1675 | + } |
|
1676 | + |
|
1677 | + foreach ( $this->arguments as $key => $args ) { |
|
1678 | + |
|
1679 | + // set if we should show alignment |
|
1680 | + if ( $key == 'alignment' ) { |
|
1681 | + $show_alignment = true; |
|
1682 | + } |
|
1683 | + |
|
1684 | + $extra = ''; |
|
1685 | + |
|
1686 | + if ( $args['type'] == 'checkbox' ) { |
|
1687 | + $type = 'boolean'; |
|
1688 | + $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false'; |
|
1689 | + } elseif ( $args['type'] == 'number' ) { |
|
1690 | + $type = 'number'; |
|
1691 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1692 | + } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) { |
|
1693 | + $type = 'array'; |
|
1694 | + if ( is_array( $args['default'] ) ) { |
|
1695 | + $default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]"; |
|
1696 | + } else { |
|
1697 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1698 | + } |
|
1699 | + } elseif ( $args['type'] == 'multiselect' ) { |
|
1700 | + $type = 'array'; |
|
1701 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1702 | + } else { |
|
1703 | + $type = 'string'; |
|
1704 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1705 | + } |
|
1706 | + echo $key . " : {"; |
|
1707 | + echo "type : '$type',"; |
|
1708 | + echo "default : $default,"; |
|
1709 | + echo "},"; |
|
1710 | + } |
|
1711 | + |
|
1712 | + echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},"; |
|
1713 | + echo "className: { type: 'string', default: '' },"; |
|
1714 | + |
|
1715 | + echo "},"; |
|
1716 | + |
|
1717 | + } |
|
1718 | + |
|
1719 | + ?> |
|
1720 | 1720 | |
1721 | 1721 | // The "edit" property must be a valid function. |
1722 | 1722 | edit: function (props) { |
@@ -1735,8 +1735,8 @@ discard block |
||
1735 | 1735 | 'shortcode': '<?php echo $this->options['base_id'];?>', |
1736 | 1736 | 'attributes': props.attributes, |
1737 | 1737 | 'post_id': <?php global $post; if ( isset( $post->ID ) ) { |
1738 | - echo $post->ID; |
|
1739 | - }?>, |
|
1738 | + echo $post->ID; |
|
1739 | + }?>, |
|
1740 | 1740 | '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>' |
1741 | 1741 | }; |
1742 | 1742 | |
@@ -1783,10 +1783,10 @@ discard block |
||
1783 | 1783 | |
1784 | 1784 | <?php |
1785 | 1785 | |
1786 | - if(! empty( $this->arguments )){ |
|
1786 | + if(! empty( $this->arguments )){ |
|
1787 | 1787 | |
1788 | - if ( $show_advanced ) { |
|
1789 | - ?> |
|
1788 | + if ( $show_advanced ) { |
|
1789 | + ?> |
|
1790 | 1790 | el( |
1791 | 1791 | wp.components.ToggleControl, |
1792 | 1792 | { |
@@ -1799,61 +1799,61 @@ discard block |
||
1799 | 1799 | ), |
1800 | 1800 | <?php |
1801 | 1801 | |
1802 | - } |
|
1802 | + } |
|
1803 | 1803 | |
1804 | - $arguments = $this->group_arguments($this->arguments); |
|
1804 | + $arguments = $this->group_arguments($this->arguments); |
|
1805 | 1805 | |
1806 | - // Do we have sections? |
|
1807 | - $has_sections = $arguments == $this->arguments ? false : true; |
|
1806 | + // Do we have sections? |
|
1807 | + $has_sections = $arguments == $this->arguments ? false : true; |
|
1808 | 1808 | |
1809 | 1809 | |
1810 | - if($has_sections){ |
|
1811 | - $panel_count = 0; |
|
1812 | - foreach($arguments as $key => $args){ |
|
1813 | - ?> |
|
1810 | + if($has_sections){ |
|
1811 | + $panel_count = 0; |
|
1812 | + foreach($arguments as $key => $args){ |
|
1813 | + ?> |
|
1814 | 1814 | el(wp.components.PanelBody, { |
1815 | 1815 | title: '<?php esc_attr_e($key); ?>', |
1816 | 1816 | initialOpen: <?php if($panel_count){echo "false";}else{echo "true";}?> |
1817 | 1817 | }, |
1818 | 1818 | <?php |
1819 | 1819 | |
1820 | - foreach($args as $k => $a){ |
|
1821 | - $this->build_block_arguments($k, $a); |
|
1822 | - } |
|
1823 | - ?> |
|
1820 | + foreach($args as $k => $a){ |
|
1821 | + $this->build_block_arguments($k, $a); |
|
1822 | + } |
|
1823 | + ?> |
|
1824 | 1824 | ), |
1825 | 1825 | <?php |
1826 | - $panel_count++; |
|
1826 | + $panel_count++; |
|
1827 | 1827 | |
1828 | - } |
|
1829 | - }else{ |
|
1830 | - foreach($this->arguments as $key => $args){ |
|
1831 | - $this->build_block_arguments($key, $args); |
|
1832 | - } |
|
1833 | - } |
|
1828 | + } |
|
1829 | + }else{ |
|
1830 | + foreach($this->arguments as $key => $args){ |
|
1831 | + $this->build_block_arguments($key, $args); |
|
1832 | + } |
|
1833 | + } |
|
1834 | 1834 | |
1835 | 1835 | |
1836 | 1836 | |
1837 | - } |
|
1838 | - ?> |
|
1837 | + } |
|
1838 | + ?> |
|
1839 | 1839 | |
1840 | 1840 | ), |
1841 | 1841 | |
1842 | 1842 | <?php |
1843 | - // If the user sets block-output array then build it |
|
1844 | - if ( ! empty( $this->options['block-output'] ) ) { |
|
1845 | - $this->block_element( $this->options['block-output'] ); |
|
1846 | - }else{ |
|
1847 | - // if no block-output is set then we try and get the shortcode html output via ajax. |
|
1848 | - ?> |
|
1843 | + // If the user sets block-output array then build it |
|
1844 | + if ( ! empty( $this->options['block-output'] ) ) { |
|
1845 | + $this->block_element( $this->options['block-output'] ); |
|
1846 | + }else{ |
|
1847 | + // if no block-output is set then we try and get the shortcode html output via ajax. |
|
1848 | + ?> |
|
1849 | 1849 | el('div', { |
1850 | 1850 | dangerouslySetInnerHTML: {__html: onChangeContent()}, |
1851 | 1851 | className: props.className, |
1852 | 1852 | style: {'min-height': '30px'} |
1853 | 1853 | }) |
1854 | 1854 | <?php |
1855 | - } |
|
1856 | - ?> |
|
1855 | + } |
|
1856 | + ?> |
|
1857 | 1857 | ]; // end return |
1858 | 1858 | }, |
1859 | 1859 | |
@@ -1870,17 +1870,17 @@ discard block |
||
1870 | 1870 | var content = "[<?php echo $this->options['base_id'];?>"; |
1871 | 1871 | <?php |
1872 | 1872 | |
1873 | - if(! empty( $this->arguments )){ |
|
1874 | - foreach($this->arguments as $key => $args){ |
|
1875 | - ?> |
|
1873 | + if(! empty( $this->arguments )){ |
|
1874 | + foreach($this->arguments as $key => $args){ |
|
1875 | + ?> |
|
1876 | 1876 | if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) { |
1877 | 1877 | content += " <?php echo esc_attr( $key );?>='" + attr.<?php echo esc_attr( $key );?>+ "' "; |
1878 | 1878 | } |
1879 | 1879 | <?php |
1880 | - } |
|
1881 | - } |
|
1880 | + } |
|
1881 | + } |
|
1882 | 1882 | |
1883 | - ?> |
|
1883 | + ?> |
|
1884 | 1884 | content += "]"; |
1885 | 1885 | |
1886 | 1886 | |
@@ -1909,83 +1909,83 @@ discard block |
||
1909 | 1909 | })(); |
1910 | 1910 | </script> |
1911 | 1911 | <?php |
1912 | - $output = ob_get_clean(); |
|
1912 | + $output = ob_get_clean(); |
|
1913 | 1913 | |
1914 | - /* |
|
1914 | + /* |
|
1915 | 1915 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
1916 | 1916 | */ |
1917 | 1917 | |
1918 | - return str_replace( array( |
|
1919 | - '<script>', |
|
1920 | - '</script>' |
|
1921 | - ), '', $output ); |
|
1922 | - } |
|
1923 | - |
|
1924 | - public function build_block_arguments($key,$args){ |
|
1925 | - $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : ''; |
|
1926 | - $options = ''; |
|
1927 | - $extra = ''; |
|
1928 | - $require = ''; |
|
1929 | - $onchange = "props.setAttributes({ $key: $key } )"; |
|
1930 | - $value = "props.attributes.$key"; |
|
1931 | - $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' ); |
|
1932 | - if ( in_array( $args['type'], $text_type ) ) { |
|
1933 | - $type = 'TextControl'; |
|
1934 | - // Save numbers as numbers and not strings |
|
1935 | - if ( $args['type'] == 'number' ) { |
|
1936 | - $onchange = "props.setAttributes({ $key: Number($key) } )"; |
|
1937 | - } |
|
1938 | - } |
|
1939 | - // elseif ( $args['type'] == 'color' ) { //@todo ColorPicker labels are not shown yet, we use html5 color input for now https://github.com/WordPress/gutenberg/issues/14378 |
|
1940 | - // $type = 'ColorPicker'; |
|
1941 | - // } |
|
1942 | - elseif ( $args['type'] == 'checkbox' ) { |
|
1943 | - $type = 'CheckboxControl'; |
|
1944 | - $extra .= "checked: props.attributes.$key,"; |
|
1945 | - $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )"; |
|
1946 | - } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) { |
|
1947 | - $type = 'SelectControl'; |
|
1948 | - if ( ! empty( $args['options'] ) ) { |
|
1949 | - $options .= "options : ["; |
|
1950 | - foreach ( $args['options'] as $option_val => $option_label ) { |
|
1951 | - $options .= "{ value : '" . esc_attr( $option_val ) . "', label : '" . esc_attr( $option_label ) . "' },"; |
|
1952 | - } |
|
1953 | - $options .= "],"; |
|
1954 | - } |
|
1955 | - if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
1956 | - $extra .= ' multiple: true, '; |
|
1957 | - //$onchange = "props.setAttributes({ $key: ['edit'] } )"; |
|
1958 | - //$value = "['edit', 'delete']"; |
|
1959 | - } |
|
1960 | - } elseif ( $args['type'] == 'alignment' ) { |
|
1961 | - $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example |
|
1962 | - } else { |
|
1963 | - return;// if we have not implemented the control then don't break the JS. |
|
1964 | - } |
|
1965 | - |
|
1966 | - // add show only if advanced |
|
1967 | - if ( ! empty( $args['advanced'] ) ) { |
|
1968 | - echo "props.attributes.show_advanced && "; |
|
1969 | - } |
|
1970 | - // add setting require if defined |
|
1971 | - if ( ! empty( $args['element_require'] ) ) { |
|
1972 | - echo $this->block_props_replace( $args['element_require'], true ) . " && "; |
|
1973 | - } |
|
1974 | - ?> |
|
1918 | + return str_replace( array( |
|
1919 | + '<script>', |
|
1920 | + '</script>' |
|
1921 | + ), '', $output ); |
|
1922 | + } |
|
1923 | + |
|
1924 | + public function build_block_arguments($key,$args){ |
|
1925 | + $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : ''; |
|
1926 | + $options = ''; |
|
1927 | + $extra = ''; |
|
1928 | + $require = ''; |
|
1929 | + $onchange = "props.setAttributes({ $key: $key } )"; |
|
1930 | + $value = "props.attributes.$key"; |
|
1931 | + $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' ); |
|
1932 | + if ( in_array( $args['type'], $text_type ) ) { |
|
1933 | + $type = 'TextControl'; |
|
1934 | + // Save numbers as numbers and not strings |
|
1935 | + if ( $args['type'] == 'number' ) { |
|
1936 | + $onchange = "props.setAttributes({ $key: Number($key) } )"; |
|
1937 | + } |
|
1938 | + } |
|
1939 | + // elseif ( $args['type'] == 'color' ) { //@todo ColorPicker labels are not shown yet, we use html5 color input for now https://github.com/WordPress/gutenberg/issues/14378 |
|
1940 | + // $type = 'ColorPicker'; |
|
1941 | + // } |
|
1942 | + elseif ( $args['type'] == 'checkbox' ) { |
|
1943 | + $type = 'CheckboxControl'; |
|
1944 | + $extra .= "checked: props.attributes.$key,"; |
|
1945 | + $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )"; |
|
1946 | + } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) { |
|
1947 | + $type = 'SelectControl'; |
|
1948 | + if ( ! empty( $args['options'] ) ) { |
|
1949 | + $options .= "options : ["; |
|
1950 | + foreach ( $args['options'] as $option_val => $option_label ) { |
|
1951 | + $options .= "{ value : '" . esc_attr( $option_val ) . "', label : '" . esc_attr( $option_label ) . "' },"; |
|
1952 | + } |
|
1953 | + $options .= "],"; |
|
1954 | + } |
|
1955 | + if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
1956 | + $extra .= ' multiple: true, '; |
|
1957 | + //$onchange = "props.setAttributes({ $key: ['edit'] } )"; |
|
1958 | + //$value = "['edit', 'delete']"; |
|
1959 | + } |
|
1960 | + } elseif ( $args['type'] == 'alignment' ) { |
|
1961 | + $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example |
|
1962 | + } else { |
|
1963 | + return;// if we have not implemented the control then don't break the JS. |
|
1964 | + } |
|
1965 | + |
|
1966 | + // add show only if advanced |
|
1967 | + if ( ! empty( $args['advanced'] ) ) { |
|
1968 | + echo "props.attributes.show_advanced && "; |
|
1969 | + } |
|
1970 | + // add setting require if defined |
|
1971 | + if ( ! empty( $args['element_require'] ) ) { |
|
1972 | + echo $this->block_props_replace( $args['element_require'], true ) . " && "; |
|
1973 | + } |
|
1974 | + ?> |
|
1975 | 1975 | el( |
1976 | 1976 | wp.components.<?php echo esc_attr( $type );?>, |
1977 | 1977 | { |
1978 | 1978 | label: '<?php echo esc_attr( $args['title'] );?>', |
1979 | 1979 | help: '<?php if ( isset( $args['desc'] ) ) { |
1980 | - echo esc_attr( $args['desc'] ); |
|
1981 | - }?>', |
|
1980 | + echo esc_attr( $args['desc'] ); |
|
1981 | + }?>', |
|
1982 | 1982 | value: <?php echo $value;?>, |
1983 | 1983 | <?php if ( $type == 'TextControl' && $args['type'] != 'text' ) { |
1984 | - echo "type: '" . esc_attr( $args['type'] ) . "',"; |
|
1985 | - }?> |
|
1984 | + echo "type: '" . esc_attr( $args['type'] ) . "',"; |
|
1985 | + }?> |
|
1986 | 1986 | <?php if ( ! empty( $args['placeholder'] ) ) { |
1987 | - echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',"; |
|
1988 | - }?> |
|
1987 | + echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',"; |
|
1988 | + }?> |
|
1989 | 1989 | <?php echo $options;?> |
1990 | 1990 | <?php echo $extra;?> |
1991 | 1991 | <?php echo $custom_attributes;?> |
@@ -1995,503 +1995,503 @@ discard block |
||
1995 | 1995 | } |
1996 | 1996 | ), |
1997 | 1997 | <?php |
1998 | - } |
|
1999 | - |
|
2000 | - /** |
|
2001 | - * Convert an array of attributes to block string. |
|
2002 | - * |
|
2003 | - * @todo there is prob a faster way to do this, also we could add some validation here. |
|
2004 | - * |
|
2005 | - * @param $custom_attributes |
|
2006 | - * |
|
2007 | - * @return string |
|
2008 | - */ |
|
2009 | - public function array_to_attributes( $custom_attributes, $html = false ) { |
|
2010 | - $attributes = ''; |
|
2011 | - if ( ! empty( $custom_attributes ) ) { |
|
2012 | - |
|
2013 | - if ( $html ) { |
|
2014 | - foreach ( $custom_attributes as $key => $val ) { |
|
2015 | - $attributes .= " $key='$val' "; |
|
2016 | - } |
|
2017 | - } else { |
|
2018 | - foreach ( $custom_attributes as $key => $val ) { |
|
2019 | - $attributes .= "'$key': '$val',"; |
|
2020 | - } |
|
2021 | - } |
|
2022 | - } |
|
2023 | - |
|
2024 | - return $attributes; |
|
2025 | - } |
|
2026 | - |
|
2027 | - /** |
|
2028 | - * A self looping function to create the output for JS block elements. |
|
2029 | - * |
|
2030 | - * This is what is output in the WP Editor visual view. |
|
2031 | - * |
|
2032 | - * @param $args |
|
2033 | - */ |
|
2034 | - public function block_element( $args ) { |
|
2035 | - |
|
2036 | - |
|
2037 | - if ( ! empty( $args ) ) { |
|
2038 | - foreach ( $args as $element => $new_args ) { |
|
2039 | - |
|
2040 | - if ( is_array( $new_args ) ) { // its an element |
|
2041 | - |
|
2042 | - |
|
2043 | - if ( isset( $new_args['element'] ) ) { |
|
2044 | - |
|
2045 | - if ( isset( $new_args['element_require'] ) ) { |
|
2046 | - echo str_replace( array( |
|
2047 | - "'+", |
|
2048 | - "+'" |
|
2049 | - ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " && "; |
|
2050 | - unset( $new_args['element_require'] ); |
|
2051 | - } |
|
2052 | - |
|
2053 | - echo "\n el( '" . $new_args['element'] . "', {"; |
|
2054 | - |
|
2055 | - // get the attributes |
|
2056 | - foreach ( $new_args as $new_key => $new_value ) { |
|
2057 | - |
|
2058 | - |
|
2059 | - if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) { |
|
2060 | - // do nothing |
|
2061 | - } else { |
|
2062 | - echo $this->block_element( array( $new_key => $new_value ) ); |
|
2063 | - } |
|
2064 | - } |
|
2065 | - |
|
2066 | - echo "},";// end attributes |
|
2067 | - |
|
2068 | - // get the content |
|
2069 | - $first_item = 0; |
|
2070 | - foreach ( $new_args as $new_key => $new_value ) { |
|
2071 | - if ( $new_key === 'content' || is_array( $new_value ) ) { |
|
2072 | - |
|
2073 | - if ( $new_key === 'content' ) { |
|
2074 | - echo "'" . $this->block_props_replace( wp_slash( $new_value ) ) . "'"; |
|
2075 | - } |
|
2076 | - |
|
2077 | - if ( is_array( $new_value ) ) { |
|
2078 | - |
|
2079 | - if ( isset( $new_value['element_require'] ) ) { |
|
2080 | - echo str_replace( array( |
|
2081 | - "'+", |
|
2082 | - "+'" |
|
2083 | - ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " && "; |
|
2084 | - unset( $new_value['element_require'] ); |
|
2085 | - } |
|
2086 | - |
|
2087 | - if ( isset( $new_value['element_repeat'] ) ) { |
|
2088 | - $x = 1; |
|
2089 | - while ( $x <= absint( $new_value['element_repeat'] ) ) { |
|
2090 | - $this->block_element( array( '' => $new_value ) ); |
|
2091 | - $x ++; |
|
2092 | - } |
|
2093 | - } else { |
|
2094 | - $this->block_element( array( '' => $new_value ) ); |
|
2095 | - } |
|
2096 | - } |
|
2097 | - $first_item ++; |
|
2098 | - } |
|
2099 | - } |
|
2100 | - |
|
2101 | - echo ")";// end content |
|
2102 | - |
|
2103 | - echo ", \n"; |
|
2104 | - |
|
2105 | - } |
|
2106 | - } else { |
|
2107 | - |
|
2108 | - if ( substr( $element, 0, 3 ) === "if_" ) { |
|
2109 | - echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ","; |
|
2110 | - } elseif ( $element == 'style' ) { |
|
2111 | - echo $element . ": " . $this->block_props_replace( $new_args ) . ","; |
|
2112 | - } else { |
|
2113 | - echo $element . ": '" . $this->block_props_replace( $new_args ) . "',"; |
|
2114 | - } |
|
2115 | - |
|
2116 | - } |
|
2117 | - } |
|
2118 | - } |
|
2119 | - } |
|
2120 | - |
|
2121 | - /** |
|
2122 | - * Replace block attributes placeholders with the proper naming. |
|
2123 | - * |
|
2124 | - * @param $string |
|
2125 | - * |
|
2126 | - * @return mixed |
|
2127 | - */ |
|
2128 | - public function block_props_replace( $string, $no_wrap = false ) { |
|
2129 | - |
|
2130 | - if ( $no_wrap ) { |
|
2131 | - $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string ); |
|
2132 | - } else { |
|
2133 | - $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string ); |
|
2134 | - } |
|
2135 | - |
|
2136 | - return $string; |
|
2137 | - } |
|
2138 | - |
|
2139 | - /** |
|
2140 | - * Outputs the content of the widget |
|
2141 | - * |
|
2142 | - * @param array $args |
|
2143 | - * @param array $instance |
|
2144 | - */ |
|
2145 | - public function widget( $args, $instance ) { |
|
2146 | - |
|
2147 | - // get the filtered values |
|
2148 | - $argument_values = $this->argument_values( $instance ); |
|
2149 | - $argument_values = $this->string_to_bool( $argument_values ); |
|
2150 | - $output = $this->output( $argument_values, $args ); |
|
2151 | - |
|
2152 | - ob_start(); |
|
2153 | - if ( $output ) { |
|
2154 | - // Before widget |
|
2155 | - $before_widget = $args['before_widget']; |
|
2156 | - $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this ); |
|
2157 | - $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this ); |
|
2158 | - |
|
2159 | - // After widget |
|
2160 | - $after_widget = $args['after_widget']; |
|
2161 | - $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this ); |
|
2162 | - $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this ); |
|
2163 | - |
|
2164 | - echo $before_widget; |
|
2165 | - // elementor strips the widget wrapping div so we check for and add it back if needed |
|
2166 | - if ( $this->is_elementor_widget_output() ) { |
|
2167 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : ''; |
|
2168 | - } |
|
2169 | - echo $this->output_title( $args, $instance ); |
|
2170 | - echo $output; |
|
2171 | - if ( $this->is_elementor_widget_output() ) { |
|
2172 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : ''; |
|
2173 | - } |
|
2174 | - echo $after_widget; |
|
2175 | - } elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty |
|
2176 | - $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" ); |
|
2177 | - echo $output; |
|
2178 | - } |
|
2179 | - $output = ob_get_clean(); |
|
2180 | - |
|
2181 | - $output = apply_filters( 'wp_super_duper_widget_output', $output, $instance, $args, $this ); |
|
2182 | - |
|
2183 | - echo $output; |
|
2184 | - } |
|
2185 | - |
|
2186 | - /** |
|
2187 | - * Tests if the current output is inside a elementor container. |
|
2188 | - * |
|
2189 | - * @since 1.0.4 |
|
2190 | - * @return bool |
|
2191 | - */ |
|
2192 | - public function is_elementor_widget_output() { |
|
2193 | - $result = false; |
|
2194 | - if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) { |
|
2195 | - $result = true; |
|
2196 | - } |
|
2197 | - |
|
2198 | - return $result; |
|
2199 | - } |
|
2200 | - |
|
2201 | - /** |
|
2202 | - * Tests if the current output is inside a elementor preview. |
|
2203 | - * |
|
2204 | - * @since 1.0.4 |
|
2205 | - * @return bool |
|
2206 | - */ |
|
2207 | - public function is_elementor_preview() { |
|
2208 | - $result = false; |
|
2209 | - if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) { |
|
2210 | - $result = true; |
|
2211 | - } |
|
2212 | - |
|
2213 | - return $result; |
|
2214 | - } |
|
2215 | - |
|
2216 | - /** |
|
2217 | - * Tests if the current output is inside a Divi preview. |
|
2218 | - * |
|
2219 | - * @since 1.0.6 |
|
2220 | - * @return bool |
|
2221 | - */ |
|
2222 | - public function is_divi_preview() { |
|
2223 | - $result = false; |
|
2224 | - if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) { |
|
2225 | - $result = true; |
|
2226 | - } |
|
2227 | - |
|
2228 | - return $result; |
|
2229 | - } |
|
2230 | - |
|
2231 | - /** |
|
2232 | - * Tests if the current output is inside a Beaver builder preview. |
|
2233 | - * |
|
2234 | - * @since 1.0.6 |
|
2235 | - * @return bool |
|
2236 | - */ |
|
2237 | - public function is_beaver_preview() { |
|
2238 | - $result = false; |
|
2239 | - if ( isset( $_REQUEST['fl_builder'] ) ) { |
|
2240 | - $result = true; |
|
2241 | - } |
|
2242 | - |
|
2243 | - return $result; |
|
2244 | - } |
|
2245 | - |
|
2246 | - /** |
|
2247 | - * Tests if the current output is inside a siteorigin builder preview. |
|
2248 | - * |
|
2249 | - * @since 1.0.6 |
|
2250 | - * @return bool |
|
2251 | - */ |
|
2252 | - public function is_siteorigin_preview() { |
|
2253 | - $result = false; |
|
2254 | - if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) { |
|
2255 | - $result = true; |
|
2256 | - } |
|
2257 | - |
|
2258 | - return $result; |
|
2259 | - } |
|
2260 | - |
|
2261 | - /** |
|
2262 | - * Tests if the current output is inside a cornerstone builder preview. |
|
2263 | - * |
|
2264 | - * @since 1.0.8 |
|
2265 | - * @return bool |
|
2266 | - */ |
|
2267 | - public function is_cornerstone_preview() { |
|
2268 | - $result = false; |
|
2269 | - if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) { |
|
2270 | - $result = true; |
|
2271 | - } |
|
2272 | - |
|
2273 | - return $result; |
|
2274 | - } |
|
2275 | - |
|
2276 | - /** |
|
2277 | - * Tests if the current output is inside a fusion builder preview. |
|
2278 | - * |
|
2279 | - * @since 1.1.0 |
|
2280 | - * @return bool |
|
2281 | - */ |
|
2282 | - public function is_fusion_preview() { |
|
2283 | - $result = false; |
|
2284 | - if ( ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ) ) { |
|
2285 | - $result = true; |
|
2286 | - } |
|
2287 | - |
|
2288 | - return $result; |
|
2289 | - } |
|
2290 | - |
|
2291 | - /** |
|
2292 | - * General function to check if we are in a preview situation. |
|
2293 | - * |
|
2294 | - * @since 1.0.6 |
|
2295 | - * @return bool |
|
2296 | - */ |
|
2297 | - public function is_preview() { |
|
2298 | - $preview = false; |
|
2299 | - if ( $this->is_divi_preview() ) { |
|
2300 | - $preview = true; |
|
2301 | - } elseif ( $this->is_elementor_preview() ) { |
|
2302 | - $preview = true; |
|
2303 | - } elseif ( $this->is_beaver_preview() ) { |
|
2304 | - $preview = true; |
|
2305 | - } elseif ( $this->is_siteorigin_preview() ) { |
|
2306 | - $preview = true; |
|
2307 | - } elseif ( $this->is_cornerstone_preview() ) { |
|
2308 | - $preview = true; |
|
2309 | - } elseif ( $this->is_fusion_preview() ) { |
|
2310 | - $preview = true; |
|
2311 | - } |
|
2312 | - |
|
2313 | - return $preview; |
|
2314 | - } |
|
2315 | - |
|
2316 | - /** |
|
2317 | - * Output the super title. |
|
2318 | - * |
|
2319 | - * @param $args |
|
2320 | - * @param array $instance |
|
2321 | - * |
|
2322 | - * @return string |
|
2323 | - */ |
|
2324 | - public function output_title( $args, $instance = array() ) { |
|
2325 | - $output = ''; |
|
2326 | - if ( ! empty( $instance['title'] ) ) { |
|
2327 | - /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
|
2328 | - $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
|
2329 | - $output = $args['before_title'] . $title . $args['after_title']; |
|
2330 | - } |
|
2331 | - |
|
2332 | - return $output; |
|
2333 | - } |
|
2334 | - |
|
2335 | - /** |
|
2336 | - * Outputs the options form inputs for the widget. |
|
2337 | - * |
|
2338 | - * @param array $instance The widget options. |
|
2339 | - */ |
|
2340 | - public function form( $instance ) { |
|
2341 | - |
|
2342 | - // set widget instance |
|
2343 | - $this->instance = $instance; |
|
2344 | - |
|
2345 | - // set it as a SD widget |
|
2346 | - echo $this->widget_advanced_toggle(); |
|
2347 | - |
|
2348 | - echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>"; |
|
2349 | - $arguments_raw = $this->get_arguments(); |
|
2350 | - |
|
2351 | - if ( is_array( $arguments_raw ) ) { |
|
2352 | - |
|
2353 | - $arguments = $this->group_arguments($arguments_raw); |
|
2354 | - |
|
2355 | - // Do we have sections? |
|
2356 | - $has_sections = $arguments == $arguments_raw ? false : true; |
|
2357 | - |
|
2358 | - |
|
2359 | - if($has_sections){ |
|
2360 | - $panel_count = 0; |
|
2361 | - foreach($arguments as $key => $args){ |
|
2362 | - |
|
2363 | - ?> |
|
1998 | + } |
|
1999 | + |
|
2000 | + /** |
|
2001 | + * Convert an array of attributes to block string. |
|
2002 | + * |
|
2003 | + * @todo there is prob a faster way to do this, also we could add some validation here. |
|
2004 | + * |
|
2005 | + * @param $custom_attributes |
|
2006 | + * |
|
2007 | + * @return string |
|
2008 | + */ |
|
2009 | + public function array_to_attributes( $custom_attributes, $html = false ) { |
|
2010 | + $attributes = ''; |
|
2011 | + if ( ! empty( $custom_attributes ) ) { |
|
2012 | + |
|
2013 | + if ( $html ) { |
|
2014 | + foreach ( $custom_attributes as $key => $val ) { |
|
2015 | + $attributes .= " $key='$val' "; |
|
2016 | + } |
|
2017 | + } else { |
|
2018 | + foreach ( $custom_attributes as $key => $val ) { |
|
2019 | + $attributes .= "'$key': '$val',"; |
|
2020 | + } |
|
2021 | + } |
|
2022 | + } |
|
2023 | + |
|
2024 | + return $attributes; |
|
2025 | + } |
|
2026 | + |
|
2027 | + /** |
|
2028 | + * A self looping function to create the output for JS block elements. |
|
2029 | + * |
|
2030 | + * This is what is output in the WP Editor visual view. |
|
2031 | + * |
|
2032 | + * @param $args |
|
2033 | + */ |
|
2034 | + public function block_element( $args ) { |
|
2035 | + |
|
2036 | + |
|
2037 | + if ( ! empty( $args ) ) { |
|
2038 | + foreach ( $args as $element => $new_args ) { |
|
2039 | + |
|
2040 | + if ( is_array( $new_args ) ) { // its an element |
|
2041 | + |
|
2042 | + |
|
2043 | + if ( isset( $new_args['element'] ) ) { |
|
2044 | + |
|
2045 | + if ( isset( $new_args['element_require'] ) ) { |
|
2046 | + echo str_replace( array( |
|
2047 | + "'+", |
|
2048 | + "+'" |
|
2049 | + ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " && "; |
|
2050 | + unset( $new_args['element_require'] ); |
|
2051 | + } |
|
2052 | + |
|
2053 | + echo "\n el( '" . $new_args['element'] . "', {"; |
|
2054 | + |
|
2055 | + // get the attributes |
|
2056 | + foreach ( $new_args as $new_key => $new_value ) { |
|
2057 | + |
|
2058 | + |
|
2059 | + if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) { |
|
2060 | + // do nothing |
|
2061 | + } else { |
|
2062 | + echo $this->block_element( array( $new_key => $new_value ) ); |
|
2063 | + } |
|
2064 | + } |
|
2065 | + |
|
2066 | + echo "},";// end attributes |
|
2067 | + |
|
2068 | + // get the content |
|
2069 | + $first_item = 0; |
|
2070 | + foreach ( $new_args as $new_key => $new_value ) { |
|
2071 | + if ( $new_key === 'content' || is_array( $new_value ) ) { |
|
2072 | + |
|
2073 | + if ( $new_key === 'content' ) { |
|
2074 | + echo "'" . $this->block_props_replace( wp_slash( $new_value ) ) . "'"; |
|
2075 | + } |
|
2076 | + |
|
2077 | + if ( is_array( $new_value ) ) { |
|
2078 | + |
|
2079 | + if ( isset( $new_value['element_require'] ) ) { |
|
2080 | + echo str_replace( array( |
|
2081 | + "'+", |
|
2082 | + "+'" |
|
2083 | + ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " && "; |
|
2084 | + unset( $new_value['element_require'] ); |
|
2085 | + } |
|
2086 | + |
|
2087 | + if ( isset( $new_value['element_repeat'] ) ) { |
|
2088 | + $x = 1; |
|
2089 | + while ( $x <= absint( $new_value['element_repeat'] ) ) { |
|
2090 | + $this->block_element( array( '' => $new_value ) ); |
|
2091 | + $x ++; |
|
2092 | + } |
|
2093 | + } else { |
|
2094 | + $this->block_element( array( '' => $new_value ) ); |
|
2095 | + } |
|
2096 | + } |
|
2097 | + $first_item ++; |
|
2098 | + } |
|
2099 | + } |
|
2100 | + |
|
2101 | + echo ")";// end content |
|
2102 | + |
|
2103 | + echo ", \n"; |
|
2104 | + |
|
2105 | + } |
|
2106 | + } else { |
|
2107 | + |
|
2108 | + if ( substr( $element, 0, 3 ) === "if_" ) { |
|
2109 | + echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ","; |
|
2110 | + } elseif ( $element == 'style' ) { |
|
2111 | + echo $element . ": " . $this->block_props_replace( $new_args ) . ","; |
|
2112 | + } else { |
|
2113 | + echo $element . ": '" . $this->block_props_replace( $new_args ) . "',"; |
|
2114 | + } |
|
2115 | + |
|
2116 | + } |
|
2117 | + } |
|
2118 | + } |
|
2119 | + } |
|
2120 | + |
|
2121 | + /** |
|
2122 | + * Replace block attributes placeholders with the proper naming. |
|
2123 | + * |
|
2124 | + * @param $string |
|
2125 | + * |
|
2126 | + * @return mixed |
|
2127 | + */ |
|
2128 | + public function block_props_replace( $string, $no_wrap = false ) { |
|
2129 | + |
|
2130 | + if ( $no_wrap ) { |
|
2131 | + $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string ); |
|
2132 | + } else { |
|
2133 | + $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string ); |
|
2134 | + } |
|
2135 | + |
|
2136 | + return $string; |
|
2137 | + } |
|
2138 | + |
|
2139 | + /** |
|
2140 | + * Outputs the content of the widget |
|
2141 | + * |
|
2142 | + * @param array $args |
|
2143 | + * @param array $instance |
|
2144 | + */ |
|
2145 | + public function widget( $args, $instance ) { |
|
2146 | + |
|
2147 | + // get the filtered values |
|
2148 | + $argument_values = $this->argument_values( $instance ); |
|
2149 | + $argument_values = $this->string_to_bool( $argument_values ); |
|
2150 | + $output = $this->output( $argument_values, $args ); |
|
2151 | + |
|
2152 | + ob_start(); |
|
2153 | + if ( $output ) { |
|
2154 | + // Before widget |
|
2155 | + $before_widget = $args['before_widget']; |
|
2156 | + $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this ); |
|
2157 | + $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this ); |
|
2158 | + |
|
2159 | + // After widget |
|
2160 | + $after_widget = $args['after_widget']; |
|
2161 | + $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this ); |
|
2162 | + $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this ); |
|
2163 | + |
|
2164 | + echo $before_widget; |
|
2165 | + // elementor strips the widget wrapping div so we check for and add it back if needed |
|
2166 | + if ( $this->is_elementor_widget_output() ) { |
|
2167 | + echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : ''; |
|
2168 | + } |
|
2169 | + echo $this->output_title( $args, $instance ); |
|
2170 | + echo $output; |
|
2171 | + if ( $this->is_elementor_widget_output() ) { |
|
2172 | + echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : ''; |
|
2173 | + } |
|
2174 | + echo $after_widget; |
|
2175 | + } elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty |
|
2176 | + $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" ); |
|
2177 | + echo $output; |
|
2178 | + } |
|
2179 | + $output = ob_get_clean(); |
|
2180 | + |
|
2181 | + $output = apply_filters( 'wp_super_duper_widget_output', $output, $instance, $args, $this ); |
|
2182 | + |
|
2183 | + echo $output; |
|
2184 | + } |
|
2185 | + |
|
2186 | + /** |
|
2187 | + * Tests if the current output is inside a elementor container. |
|
2188 | + * |
|
2189 | + * @since 1.0.4 |
|
2190 | + * @return bool |
|
2191 | + */ |
|
2192 | + public function is_elementor_widget_output() { |
|
2193 | + $result = false; |
|
2194 | + if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) { |
|
2195 | + $result = true; |
|
2196 | + } |
|
2197 | + |
|
2198 | + return $result; |
|
2199 | + } |
|
2200 | + |
|
2201 | + /** |
|
2202 | + * Tests if the current output is inside a elementor preview. |
|
2203 | + * |
|
2204 | + * @since 1.0.4 |
|
2205 | + * @return bool |
|
2206 | + */ |
|
2207 | + public function is_elementor_preview() { |
|
2208 | + $result = false; |
|
2209 | + if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) { |
|
2210 | + $result = true; |
|
2211 | + } |
|
2212 | + |
|
2213 | + return $result; |
|
2214 | + } |
|
2215 | + |
|
2216 | + /** |
|
2217 | + * Tests if the current output is inside a Divi preview. |
|
2218 | + * |
|
2219 | + * @since 1.0.6 |
|
2220 | + * @return bool |
|
2221 | + */ |
|
2222 | + public function is_divi_preview() { |
|
2223 | + $result = false; |
|
2224 | + if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) { |
|
2225 | + $result = true; |
|
2226 | + } |
|
2227 | + |
|
2228 | + return $result; |
|
2229 | + } |
|
2230 | + |
|
2231 | + /** |
|
2232 | + * Tests if the current output is inside a Beaver builder preview. |
|
2233 | + * |
|
2234 | + * @since 1.0.6 |
|
2235 | + * @return bool |
|
2236 | + */ |
|
2237 | + public function is_beaver_preview() { |
|
2238 | + $result = false; |
|
2239 | + if ( isset( $_REQUEST['fl_builder'] ) ) { |
|
2240 | + $result = true; |
|
2241 | + } |
|
2242 | + |
|
2243 | + return $result; |
|
2244 | + } |
|
2245 | + |
|
2246 | + /** |
|
2247 | + * Tests if the current output is inside a siteorigin builder preview. |
|
2248 | + * |
|
2249 | + * @since 1.0.6 |
|
2250 | + * @return bool |
|
2251 | + */ |
|
2252 | + public function is_siteorigin_preview() { |
|
2253 | + $result = false; |
|
2254 | + if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) { |
|
2255 | + $result = true; |
|
2256 | + } |
|
2257 | + |
|
2258 | + return $result; |
|
2259 | + } |
|
2260 | + |
|
2261 | + /** |
|
2262 | + * Tests if the current output is inside a cornerstone builder preview. |
|
2263 | + * |
|
2264 | + * @since 1.0.8 |
|
2265 | + * @return bool |
|
2266 | + */ |
|
2267 | + public function is_cornerstone_preview() { |
|
2268 | + $result = false; |
|
2269 | + if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) { |
|
2270 | + $result = true; |
|
2271 | + } |
|
2272 | + |
|
2273 | + return $result; |
|
2274 | + } |
|
2275 | + |
|
2276 | + /** |
|
2277 | + * Tests if the current output is inside a fusion builder preview. |
|
2278 | + * |
|
2279 | + * @since 1.1.0 |
|
2280 | + * @return bool |
|
2281 | + */ |
|
2282 | + public function is_fusion_preview() { |
|
2283 | + $result = false; |
|
2284 | + if ( ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ) ) { |
|
2285 | + $result = true; |
|
2286 | + } |
|
2287 | + |
|
2288 | + return $result; |
|
2289 | + } |
|
2290 | + |
|
2291 | + /** |
|
2292 | + * General function to check if we are in a preview situation. |
|
2293 | + * |
|
2294 | + * @since 1.0.6 |
|
2295 | + * @return bool |
|
2296 | + */ |
|
2297 | + public function is_preview() { |
|
2298 | + $preview = false; |
|
2299 | + if ( $this->is_divi_preview() ) { |
|
2300 | + $preview = true; |
|
2301 | + } elseif ( $this->is_elementor_preview() ) { |
|
2302 | + $preview = true; |
|
2303 | + } elseif ( $this->is_beaver_preview() ) { |
|
2304 | + $preview = true; |
|
2305 | + } elseif ( $this->is_siteorigin_preview() ) { |
|
2306 | + $preview = true; |
|
2307 | + } elseif ( $this->is_cornerstone_preview() ) { |
|
2308 | + $preview = true; |
|
2309 | + } elseif ( $this->is_fusion_preview() ) { |
|
2310 | + $preview = true; |
|
2311 | + } |
|
2312 | + |
|
2313 | + return $preview; |
|
2314 | + } |
|
2315 | + |
|
2316 | + /** |
|
2317 | + * Output the super title. |
|
2318 | + * |
|
2319 | + * @param $args |
|
2320 | + * @param array $instance |
|
2321 | + * |
|
2322 | + * @return string |
|
2323 | + */ |
|
2324 | + public function output_title( $args, $instance = array() ) { |
|
2325 | + $output = ''; |
|
2326 | + if ( ! empty( $instance['title'] ) ) { |
|
2327 | + /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
|
2328 | + $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
|
2329 | + $output = $args['before_title'] . $title . $args['after_title']; |
|
2330 | + } |
|
2331 | + |
|
2332 | + return $output; |
|
2333 | + } |
|
2334 | + |
|
2335 | + /** |
|
2336 | + * Outputs the options form inputs for the widget. |
|
2337 | + * |
|
2338 | + * @param array $instance The widget options. |
|
2339 | + */ |
|
2340 | + public function form( $instance ) { |
|
2341 | + |
|
2342 | + // set widget instance |
|
2343 | + $this->instance = $instance; |
|
2344 | + |
|
2345 | + // set it as a SD widget |
|
2346 | + echo $this->widget_advanced_toggle(); |
|
2347 | + |
|
2348 | + echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>"; |
|
2349 | + $arguments_raw = $this->get_arguments(); |
|
2350 | + |
|
2351 | + if ( is_array( $arguments_raw ) ) { |
|
2352 | + |
|
2353 | + $arguments = $this->group_arguments($arguments_raw); |
|
2354 | + |
|
2355 | + // Do we have sections? |
|
2356 | + $has_sections = $arguments == $arguments_raw ? false : true; |
|
2357 | + |
|
2358 | + |
|
2359 | + if($has_sections){ |
|
2360 | + $panel_count = 0; |
|
2361 | + foreach($arguments as $key => $args){ |
|
2362 | + |
|
2363 | + ?> |
|
2364 | 2364 | <script> |
2365 | 2365 | // jQuery(this).find("i").toggleClass("fas fa-chevron-up fas fa-chevron-down");jQuery(this).next().toggle(); |
2366 | 2366 | </script> |
2367 | 2367 | <?php |
2368 | 2368 | |
2369 | - $hide = $panel_count ? ' style="display:none;" ' : ''; |
|
2370 | - $icon_class = $panel_count ? 'fas fa-chevron-up' : 'fas fa-chevron-down'; |
|
2371 | - echo "<button onclick='jQuery(this).find(\"i\").toggleClass(\"fas fa-chevron-up fas fa-chevron-down\");jQuery(this).next().slideToggle();' type='button' class='sd-toggle-group-button sd-input-group-toggle".sanitize_title_with_dashes($key)."'>".esc_attr($key)." <i style='float:right;' class='".$icon_class."'></i></button>"; |
|
2372 | - echo "<div class='sd-toggle-group sd-input-group-".sanitize_title_with_dashes($key)."' $hide>"; |
|
2373 | - |
|
2374 | - foreach($args as $k => $a){ |
|
2375 | - $this->widget_inputs($a, $instance); |
|
2376 | - } |
|
2377 | - |
|
2378 | - echo "</div>"; |
|
2379 | - |
|
2380 | - $panel_count++; |
|
2381 | - |
|
2382 | - } |
|
2383 | - }else{ |
|
2384 | - foreach ( $arguments as $key => $args ) { |
|
2385 | - $this->widget_inputs( $args, $instance ); |
|
2386 | - } |
|
2387 | - } |
|
2388 | - |
|
2389 | - } |
|
2390 | - } |
|
2391 | - |
|
2392 | - /** |
|
2393 | - * Get the hidden input that when added makes the advanced button show on widget settings. |
|
2394 | - * |
|
2395 | - * @return string |
|
2396 | - */ |
|
2397 | - public function widget_advanced_toggle() { |
|
2398 | - |
|
2399 | - $output = ''; |
|
2400 | - if ( $this->block_show_advanced() ) { |
|
2401 | - $val = 1; |
|
2402 | - } else { |
|
2403 | - $val = 0; |
|
2404 | - } |
|
2405 | - |
|
2406 | - $output .= "<input type='hidden' class='sd-show-advanced' value='$val' />"; |
|
2407 | - |
|
2408 | - return $output; |
|
2409 | - } |
|
2410 | - |
|
2411 | - /** |
|
2412 | - * Convert require element. |
|
2413 | - * |
|
2414 | - * @since 1.0.0 |
|
2415 | - * |
|
2416 | - * @param string $input Input element. |
|
2417 | - * |
|
2418 | - * @return string $output |
|
2419 | - */ |
|
2420 | - public function convert_element_require( $input ) { |
|
2421 | - |
|
2422 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
2423 | - |
|
2424 | - $output = esc_attr( str_replace( array( "[%", "%]" ), array( |
|
2425 | - "jQuery(form).find('[data-argument=\"", |
|
2426 | - "\"]').find('input,select').val()" |
|
2427 | - ), $input ) ); |
|
2428 | - |
|
2429 | - return $output; |
|
2430 | - } |
|
2431 | - |
|
2432 | - /** |
|
2433 | - * Builds the inputs for the widget options. |
|
2434 | - * |
|
2435 | - * @param $args |
|
2436 | - * @param $instance |
|
2437 | - */ |
|
2438 | - public function widget_inputs( $args, $instance ) { |
|
2439 | - |
|
2440 | - $class = ""; |
|
2441 | - $element_require = ""; |
|
2442 | - $custom_attributes = ""; |
|
2443 | - |
|
2444 | - // get value |
|
2445 | - if ( isset( $instance[ $args['name'] ] ) ) { |
|
2446 | - $value = $instance[ $args['name'] ]; |
|
2447 | - } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) { |
|
2448 | - $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] ); |
|
2449 | - } else { |
|
2450 | - $value = ''; |
|
2451 | - } |
|
2452 | - |
|
2453 | - // get placeholder |
|
2454 | - if ( ! empty( $args['placeholder'] ) ) { |
|
2455 | - $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'"; |
|
2456 | - } else { |
|
2457 | - $placeholder = ''; |
|
2458 | - } |
|
2459 | - |
|
2460 | - // get if advanced |
|
2461 | - if ( isset( $args['advanced'] ) && $args['advanced'] ) { |
|
2462 | - $class .= " sd-advanced-setting "; |
|
2463 | - } |
|
2464 | - |
|
2465 | - // element_require |
|
2466 | - if ( isset( $args['element_require'] ) && $args['element_require'] ) { |
|
2467 | - $element_require = $args['element_require']; |
|
2468 | - } |
|
2469 | - |
|
2470 | - // custom_attributes |
|
2471 | - if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) { |
|
2472 | - $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true ); |
|
2473 | - } |
|
2474 | - |
|
2475 | - // before wrapper |
|
2476 | - ?> |
|
2369 | + $hide = $panel_count ? ' style="display:none;" ' : ''; |
|
2370 | + $icon_class = $panel_count ? 'fas fa-chevron-up' : 'fas fa-chevron-down'; |
|
2371 | + echo "<button onclick='jQuery(this).find(\"i\").toggleClass(\"fas fa-chevron-up fas fa-chevron-down\");jQuery(this).next().slideToggle();' type='button' class='sd-toggle-group-button sd-input-group-toggle".sanitize_title_with_dashes($key)."'>".esc_attr($key)." <i style='float:right;' class='".$icon_class."'></i></button>"; |
|
2372 | + echo "<div class='sd-toggle-group sd-input-group-".sanitize_title_with_dashes($key)."' $hide>"; |
|
2373 | + |
|
2374 | + foreach($args as $k => $a){ |
|
2375 | + $this->widget_inputs($a, $instance); |
|
2376 | + } |
|
2377 | + |
|
2378 | + echo "</div>"; |
|
2379 | + |
|
2380 | + $panel_count++; |
|
2381 | + |
|
2382 | + } |
|
2383 | + }else{ |
|
2384 | + foreach ( $arguments as $key => $args ) { |
|
2385 | + $this->widget_inputs( $args, $instance ); |
|
2386 | + } |
|
2387 | + } |
|
2388 | + |
|
2389 | + } |
|
2390 | + } |
|
2391 | + |
|
2392 | + /** |
|
2393 | + * Get the hidden input that when added makes the advanced button show on widget settings. |
|
2394 | + * |
|
2395 | + * @return string |
|
2396 | + */ |
|
2397 | + public function widget_advanced_toggle() { |
|
2398 | + |
|
2399 | + $output = ''; |
|
2400 | + if ( $this->block_show_advanced() ) { |
|
2401 | + $val = 1; |
|
2402 | + } else { |
|
2403 | + $val = 0; |
|
2404 | + } |
|
2405 | + |
|
2406 | + $output .= "<input type='hidden' class='sd-show-advanced' value='$val' />"; |
|
2407 | + |
|
2408 | + return $output; |
|
2409 | + } |
|
2410 | + |
|
2411 | + /** |
|
2412 | + * Convert require element. |
|
2413 | + * |
|
2414 | + * @since 1.0.0 |
|
2415 | + * |
|
2416 | + * @param string $input Input element. |
|
2417 | + * |
|
2418 | + * @return string $output |
|
2419 | + */ |
|
2420 | + public function convert_element_require( $input ) { |
|
2421 | + |
|
2422 | + $input = str_replace( "'", '"', $input );// we only want double quotes |
|
2423 | + |
|
2424 | + $output = esc_attr( str_replace( array( "[%", "%]" ), array( |
|
2425 | + "jQuery(form).find('[data-argument=\"", |
|
2426 | + "\"]').find('input,select').val()" |
|
2427 | + ), $input ) ); |
|
2428 | + |
|
2429 | + return $output; |
|
2430 | + } |
|
2431 | + |
|
2432 | + /** |
|
2433 | + * Builds the inputs for the widget options. |
|
2434 | + * |
|
2435 | + * @param $args |
|
2436 | + * @param $instance |
|
2437 | + */ |
|
2438 | + public function widget_inputs( $args, $instance ) { |
|
2439 | + |
|
2440 | + $class = ""; |
|
2441 | + $element_require = ""; |
|
2442 | + $custom_attributes = ""; |
|
2443 | + |
|
2444 | + // get value |
|
2445 | + if ( isset( $instance[ $args['name'] ] ) ) { |
|
2446 | + $value = $instance[ $args['name'] ]; |
|
2447 | + } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) { |
|
2448 | + $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] ); |
|
2449 | + } else { |
|
2450 | + $value = ''; |
|
2451 | + } |
|
2452 | + |
|
2453 | + // get placeholder |
|
2454 | + if ( ! empty( $args['placeholder'] ) ) { |
|
2455 | + $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'"; |
|
2456 | + } else { |
|
2457 | + $placeholder = ''; |
|
2458 | + } |
|
2459 | + |
|
2460 | + // get if advanced |
|
2461 | + if ( isset( $args['advanced'] ) && $args['advanced'] ) { |
|
2462 | + $class .= " sd-advanced-setting "; |
|
2463 | + } |
|
2464 | + |
|
2465 | + // element_require |
|
2466 | + if ( isset( $args['element_require'] ) && $args['element_require'] ) { |
|
2467 | + $element_require = $args['element_require']; |
|
2468 | + } |
|
2469 | + |
|
2470 | + // custom_attributes |
|
2471 | + if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) { |
|
2472 | + $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true ); |
|
2473 | + } |
|
2474 | + |
|
2475 | + // before wrapper |
|
2476 | + ?> |
|
2477 | 2477 | <p class="sd-argument <?php echo esc_attr( $class ); ?>" |
2478 | 2478 | data-argument='<?php echo esc_attr( $args['name'] ); ?>' |
2479 | 2479 | data-element_require='<?php if ( $element_require ) { |
2480 | - echo $this->convert_element_require( $element_require ); |
|
2481 | - } ?>' |
|
2480 | + echo $this->convert_element_require( $element_require ); |
|
2481 | + } ?>' |
|
2482 | 2482 | > |
2483 | 2483 | <?php |
2484 | 2484 | |
2485 | - switch ( $args['type'] ) { |
|
2486 | - //array('text','password','number','email','tel','url','color') |
|
2487 | - case "text": |
|
2488 | - case "password": |
|
2489 | - case "number": |
|
2490 | - case "email": |
|
2491 | - case "tel": |
|
2492 | - case "url": |
|
2493 | - case "color": |
|
2494 | - ?> |
|
2485 | + switch ( $args['type'] ) { |
|
2486 | + //array('text','password','number','email','tel','url','color') |
|
2487 | + case "text": |
|
2488 | + case "password": |
|
2489 | + case "number": |
|
2490 | + case "email": |
|
2491 | + case "tel": |
|
2492 | + case "url": |
|
2493 | + case "color": |
|
2494 | + ?> |
|
2495 | 2495 | <label |
2496 | 2496 | for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
2497 | 2497 | <input <?php echo $placeholder; ?> class="widefat" |
@@ -2502,47 +2502,47 @@ discard block |
||
2502 | 2502 | value="<?php echo esc_attr( $value ); ?>"> |
2503 | 2503 | <?php |
2504 | 2504 | |
2505 | - break; |
|
2506 | - case "select": |
|
2507 | - $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false; |
|
2508 | - if ( $multiple ) { |
|
2509 | - if ( empty( $value ) ) { |
|
2510 | - $value = array(); |
|
2511 | - } |
|
2512 | - } |
|
2513 | - ?> |
|
2505 | + break; |
|
2506 | + case "select": |
|
2507 | + $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false; |
|
2508 | + if ( $multiple ) { |
|
2509 | + if ( empty( $value ) ) { |
|
2510 | + $value = array(); |
|
2511 | + } |
|
2512 | + } |
|
2513 | + ?> |
|
2514 | 2514 | <label |
2515 | 2515 | for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
2516 | 2516 | <select <?php echo $placeholder; ?> class="widefat" |
2517 | 2517 | <?php echo $custom_attributes; ?> |
2518 | 2518 | id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
2519 | 2519 | name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); |
2520 | - if ( $multiple ) { |
|
2521 | - echo "[]"; |
|
2522 | - } ?>" |
|
2520 | + if ( $multiple ) { |
|
2521 | + echo "[]"; |
|
2522 | + } ?>" |
|
2523 | 2523 | <?php if ( $multiple ) { |
2524 | - echo "multiple"; |
|
2525 | - } //@todo not implemented yet due to gutenberg not supporting it |
|
2526 | - ?> |
|
2524 | + echo "multiple"; |
|
2525 | + } //@todo not implemented yet due to gutenberg not supporting it |
|
2526 | + ?> |
|
2527 | 2527 | > |
2528 | 2528 | <?php |
2529 | 2529 | |
2530 | - if ( ! empty( $args['options'] ) ) { |
|
2531 | - foreach ( $args['options'] as $val => $label ) { |
|
2532 | - if ( $multiple ) { |
|
2533 | - $selected = in_array( $val, $value ) ? 'selected="selected"' : ''; |
|
2534 | - } else { |
|
2535 | - $selected = selected( $value, $val, false ); |
|
2536 | - } |
|
2537 | - echo "<option value='$val' " . $selected . ">$label</option>"; |
|
2538 | - } |
|
2539 | - } |
|
2540 | - ?> |
|
2530 | + if ( ! empty( $args['options'] ) ) { |
|
2531 | + foreach ( $args['options'] as $val => $label ) { |
|
2532 | + if ( $multiple ) { |
|
2533 | + $selected = in_array( $val, $value ) ? 'selected="selected"' : ''; |
|
2534 | + } else { |
|
2535 | + $selected = selected( $value, $val, false ); |
|
2536 | + } |
|
2537 | + echo "<option value='$val' " . $selected . ">$label</option>"; |
|
2538 | + } |
|
2539 | + } |
|
2540 | + ?> |
|
2541 | 2541 | </select> |
2542 | 2542 | <?php |
2543 | - break; |
|
2544 | - case "checkbox": |
|
2545 | - ?> |
|
2543 | + break; |
|
2544 | + case "checkbox": |
|
2545 | + ?> |
|
2546 | 2546 | <input <?php echo $placeholder; ?> |
2547 | 2547 | <?php checked( 1, $value, true ) ?> |
2548 | 2548 | <?php echo $custom_attributes; ?> |
@@ -2552,136 +2552,136 @@ discard block |
||
2552 | 2552 | <label |
2553 | 2553 | for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
2554 | 2554 | <?php |
2555 | - break; |
|
2556 | - case "hidden": |
|
2557 | - ?> |
|
2555 | + break; |
|
2556 | + case "hidden": |
|
2557 | + ?> |
|
2558 | 2558 | <input id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
2559 | 2559 | name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="hidden" |
2560 | 2560 | value="<?php echo esc_attr( $value ); ?>"> |
2561 | 2561 | <?php |
2562 | - break; |
|
2563 | - default: |
|
2564 | - echo "No input type found!"; // @todo we need to add more input types. |
|
2565 | - } |
|
2562 | + break; |
|
2563 | + default: |
|
2564 | + echo "No input type found!"; // @todo we need to add more input types. |
|
2565 | + } |
|
2566 | 2566 | |
2567 | - // after wrapper |
|
2568 | - ?> |
|
2567 | + // after wrapper |
|
2568 | + ?> |
|
2569 | 2569 | </p> |
2570 | 2570 | <?php |
2571 | 2571 | |
2572 | - } |
|
2573 | - |
|
2574 | - /** |
|
2575 | - * Get the widget input description html. |
|
2576 | - * |
|
2577 | - * @param $args |
|
2578 | - * |
|
2579 | - * @return string |
|
2580 | - * @todo, need to make its own tooltip script |
|
2581 | - */ |
|
2582 | - public function widget_field_desc( $args ) { |
|
2583 | - |
|
2584 | - $description = ''; |
|
2585 | - if ( isset( $args['desc'] ) && $args['desc'] ) { |
|
2586 | - if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) { |
|
2587 | - $description = $this->desc_tip( $args['desc'] ); |
|
2588 | - } else { |
|
2589 | - $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>'; |
|
2590 | - } |
|
2591 | - } |
|
2592 | - |
|
2593 | - return $description; |
|
2594 | - } |
|
2595 | - |
|
2596 | - /** |
|
2597 | - * Get the tool tip html. |
|
2598 | - * |
|
2599 | - * @param $tip |
|
2600 | - * @param bool $allow_html |
|
2601 | - * |
|
2602 | - * @return string |
|
2603 | - */ |
|
2604 | - function desc_tip( $tip, $allow_html = false ) { |
|
2605 | - if ( $allow_html ) { |
|
2606 | - $tip = $this->sanitize_tooltip( $tip ); |
|
2607 | - } else { |
|
2608 | - $tip = esc_attr( $tip ); |
|
2609 | - } |
|
2610 | - |
|
2611 | - return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
|
2612 | - } |
|
2613 | - |
|
2614 | - /** |
|
2615 | - * Sanitize a string destined to be a tooltip. |
|
2616 | - * |
|
2617 | - * @param string $var |
|
2618 | - * |
|
2619 | - * @return string |
|
2620 | - */ |
|
2621 | - public function sanitize_tooltip( $var ) { |
|
2622 | - return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
2623 | - 'br' => array(), |
|
2624 | - 'em' => array(), |
|
2625 | - 'strong' => array(), |
|
2626 | - 'small' => array(), |
|
2627 | - 'span' => array(), |
|
2628 | - 'ul' => array(), |
|
2629 | - 'li' => array(), |
|
2630 | - 'ol' => array(), |
|
2631 | - 'p' => array(), |
|
2632 | - ) ) ); |
|
2633 | - } |
|
2634 | - |
|
2635 | - /** |
|
2636 | - * Processing widget options on save |
|
2637 | - * |
|
2638 | - * @param array $new_instance The new options |
|
2639 | - * @param array $old_instance The previous options |
|
2640 | - * |
|
2641 | - * @return array |
|
2642 | - * @todo we should add some sanitation here. |
|
2643 | - */ |
|
2644 | - public function update( $new_instance, $old_instance ) { |
|
2645 | - |
|
2646 | - //save the widget |
|
2647 | - $instance = array_merge( (array) $old_instance, (array) $new_instance ); |
|
2648 | - |
|
2649 | - // set widget instance |
|
2650 | - $this->instance = $instance; |
|
2651 | - |
|
2652 | - if ( empty( $this->arguments ) ) { |
|
2653 | - $this->get_arguments(); |
|
2654 | - } |
|
2655 | - |
|
2656 | - // check for checkboxes |
|
2657 | - if ( ! empty( $this->arguments ) ) { |
|
2658 | - foreach ( $this->arguments as $argument ) { |
|
2659 | - if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) { |
|
2660 | - $instance[ $argument['name'] ] = '0'; |
|
2661 | - } |
|
2662 | - } |
|
2663 | - } |
|
2664 | - |
|
2665 | - return $instance; |
|
2666 | - } |
|
2667 | - |
|
2668 | - /** |
|
2669 | - * Checks if the current call is a ajax call to get the block content. |
|
2670 | - * |
|
2671 | - * This can be used in your widget to return different content as the block content. |
|
2672 | - * |
|
2673 | - * @since 1.0.3 |
|
2674 | - * @return bool |
|
2675 | - */ |
|
2676 | - public function is_block_content_call() { |
|
2677 | - $result = false; |
|
2678 | - if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) { |
|
2679 | - $result = true; |
|
2680 | - } |
|
2681 | - |
|
2682 | - return $result; |
|
2683 | - } |
|
2684 | - |
|
2685 | - } |
|
2572 | + } |
|
2573 | + |
|
2574 | + /** |
|
2575 | + * Get the widget input description html. |
|
2576 | + * |
|
2577 | + * @param $args |
|
2578 | + * |
|
2579 | + * @return string |
|
2580 | + * @todo, need to make its own tooltip script |
|
2581 | + */ |
|
2582 | + public function widget_field_desc( $args ) { |
|
2583 | + |
|
2584 | + $description = ''; |
|
2585 | + if ( isset( $args['desc'] ) && $args['desc'] ) { |
|
2586 | + if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) { |
|
2587 | + $description = $this->desc_tip( $args['desc'] ); |
|
2588 | + } else { |
|
2589 | + $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>'; |
|
2590 | + } |
|
2591 | + } |
|
2592 | + |
|
2593 | + return $description; |
|
2594 | + } |
|
2595 | + |
|
2596 | + /** |
|
2597 | + * Get the tool tip html. |
|
2598 | + * |
|
2599 | + * @param $tip |
|
2600 | + * @param bool $allow_html |
|
2601 | + * |
|
2602 | + * @return string |
|
2603 | + */ |
|
2604 | + function desc_tip( $tip, $allow_html = false ) { |
|
2605 | + if ( $allow_html ) { |
|
2606 | + $tip = $this->sanitize_tooltip( $tip ); |
|
2607 | + } else { |
|
2608 | + $tip = esc_attr( $tip ); |
|
2609 | + } |
|
2610 | + |
|
2611 | + return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
|
2612 | + } |
|
2613 | + |
|
2614 | + /** |
|
2615 | + * Sanitize a string destined to be a tooltip. |
|
2616 | + * |
|
2617 | + * @param string $var |
|
2618 | + * |
|
2619 | + * @return string |
|
2620 | + */ |
|
2621 | + public function sanitize_tooltip( $var ) { |
|
2622 | + return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
2623 | + 'br' => array(), |
|
2624 | + 'em' => array(), |
|
2625 | + 'strong' => array(), |
|
2626 | + 'small' => array(), |
|
2627 | + 'span' => array(), |
|
2628 | + 'ul' => array(), |
|
2629 | + 'li' => array(), |
|
2630 | + 'ol' => array(), |
|
2631 | + 'p' => array(), |
|
2632 | + ) ) ); |
|
2633 | + } |
|
2634 | + |
|
2635 | + /** |
|
2636 | + * Processing widget options on save |
|
2637 | + * |
|
2638 | + * @param array $new_instance The new options |
|
2639 | + * @param array $old_instance The previous options |
|
2640 | + * |
|
2641 | + * @return array |
|
2642 | + * @todo we should add some sanitation here. |
|
2643 | + */ |
|
2644 | + public function update( $new_instance, $old_instance ) { |
|
2645 | + |
|
2646 | + //save the widget |
|
2647 | + $instance = array_merge( (array) $old_instance, (array) $new_instance ); |
|
2648 | + |
|
2649 | + // set widget instance |
|
2650 | + $this->instance = $instance; |
|
2651 | + |
|
2652 | + if ( empty( $this->arguments ) ) { |
|
2653 | + $this->get_arguments(); |
|
2654 | + } |
|
2655 | + |
|
2656 | + // check for checkboxes |
|
2657 | + if ( ! empty( $this->arguments ) ) { |
|
2658 | + foreach ( $this->arguments as $argument ) { |
|
2659 | + if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) { |
|
2660 | + $instance[ $argument['name'] ] = '0'; |
|
2661 | + } |
|
2662 | + } |
|
2663 | + } |
|
2664 | + |
|
2665 | + return $instance; |
|
2666 | + } |
|
2667 | + |
|
2668 | + /** |
|
2669 | + * Checks if the current call is a ajax call to get the block content. |
|
2670 | + * |
|
2671 | + * This can be used in your widget to return different content as the block content. |
|
2672 | + * |
|
2673 | + * @since 1.0.3 |
|
2674 | + * @return bool |
|
2675 | + */ |
|
2676 | + public function is_block_content_call() { |
|
2677 | + $result = false; |
|
2678 | + if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) { |
|
2679 | + $result = true; |
|
2680 | + } |
|
2681 | + |
|
2682 | + return $result; |
|
2683 | + } |
|
2684 | + |
|
2685 | + } |
|
2686 | 2686 | |
2687 | 2687 | } |
2688 | 2688 | \ No newline at end of file |
@@ -198,9 +198,9 @@ discard block |
||
198 | 198 | unset($param['default']); |
199 | 199 | } |
200 | 200 | $param['value'] = array(''=>__("No"),'1'=>__("Yes")); |
201 | - }elseif($param['type'] == 'select'){ |
|
201 | + } elseif($param['type'] == 'select'){ |
|
202 | 202 | $param['value'] = isset($val['options']) ? $val['options'] : array(); |
203 | - }else{ |
|
203 | + } else{ |
|
204 | 204 | $param['value'] = isset($val['default']) ? $val['default'] : ''; |
205 | 205 | } |
206 | 206 | |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | <?php |
659 | 659 | if(! empty( $insert_shortcode_function )){ |
660 | 660 | echo $insert_shortcode_function; |
661 | - }else{ |
|
661 | + } else{ |
|
662 | 662 | |
663 | 663 | /** |
664 | 664 | * Function for super duper insert shortcode. |
@@ -1414,8 +1414,7 @@ discard block |
||
1414 | 1414 | $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
1415 | 1415 | if($args['type']=='checkbox' && $argument_values[ $key ] == ''){ |
1416 | 1416 | // don't set default for an empty checkbox |
1417 | - } |
|
1418 | - elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
1417 | + } elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
1419 | 1418 | $argument_values[ $key ] = $args['default']; |
1420 | 1419 | } |
1421 | 1420 | } |
@@ -1544,11 +1543,11 @@ discard block |
||
1544 | 1543 | $fa_type = ''; |
1545 | 1544 | if(substr( $icon, 0, 7 ) === "fas fa-"){ |
1546 | 1545 | $fa_type = 'solid'; |
1547 | - }elseif(substr( $icon, 0, 7 ) === "far fa-"){ |
|
1546 | + } elseif(substr( $icon, 0, 7 ) === "far fa-"){ |
|
1548 | 1547 | $fa_type = 'regular'; |
1549 | - }elseif(substr( $icon, 0, 7 ) === "fab fa-"){ |
|
1548 | + } elseif(substr( $icon, 0, 7 ) === "fab fa-"){ |
|
1550 | 1549 | $fa_type = 'brands'; |
1551 | - }else{ |
|
1550 | + } else{ |
|
1552 | 1551 | $icon = "'".$icon."'"; |
1553 | 1552 | } |
1554 | 1553 | |
@@ -1571,7 +1570,7 @@ discard block |
||
1571 | 1570 | if(isset($args['group'])){ |
1572 | 1571 | $temp_arguments[$args['group']][$key] = $args; |
1573 | 1572 | $add_sections = true; |
1574 | - }else{ |
|
1573 | + } else{ |
|
1575 | 1574 | $temp_arguments[$general][$key] = $args; |
1576 | 1575 | } |
1577 | 1576 | } |
@@ -1813,7 +1812,7 @@ discard block |
||
1813 | 1812 | ?> |
1814 | 1813 | el(wp.components.PanelBody, { |
1815 | 1814 | title: '<?php esc_attr_e($key); ?>', |
1816 | - initialOpen: <?php if($panel_count){echo "false";}else{echo "true";}?> |
|
1815 | + initialOpen: <?php if($panel_count){echo "false";} else{echo "true";}?> |
|
1817 | 1816 | }, |
1818 | 1817 | <?php |
1819 | 1818 | |
@@ -1826,7 +1825,7 @@ discard block |
||
1826 | 1825 | $panel_count++; |
1827 | 1826 | |
1828 | 1827 | } |
1829 | - }else{ |
|
1828 | + } else{ |
|
1830 | 1829 | foreach($this->arguments as $key => $args){ |
1831 | 1830 | $this->build_block_arguments($key, $args); |
1832 | 1831 | } |
@@ -1843,7 +1842,7 @@ discard block |
||
1843 | 1842 | // If the user sets block-output array then build it |
1844 | 1843 | if ( ! empty( $this->options['block-output'] ) ) { |
1845 | 1844 | $this->block_element( $this->options['block-output'] ); |
1846 | - }else{ |
|
1845 | + } else{ |
|
1847 | 1846 | // if no block-output is set then we try and get the shortcode html output via ajax. |
1848 | 1847 | ?> |
1849 | 1848 | el('div', { |
@@ -2380,7 +2379,7 @@ discard block |
||
2380 | 2379 | $panel_count++; |
2381 | 2380 | |
2382 | 2381 | } |
2383 | - }else{ |
|
2382 | + } else{ |
|
2384 | 2383 | foreach ( $arguments as $key => $args ) { |
2385 | 2384 | $this->widget_inputs( $args, $instance ); |
2386 | 2385 | } |
@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
6 | -if ( ! class_exists( 'WP_Super_Duper' ) ) { |
|
6 | +if (!class_exists('WP_Super_Duper')) { |
|
7 | 7 | |
8 | 8 | |
9 | 9 | /** |
@@ -54,27 +54,27 @@ discard block |
||
54 | 54 | /** |
55 | 55 | * Take the array options and use them to build. |
56 | 56 | */ |
57 | - public function __construct( $options ) { |
|
57 | + public function __construct($options) { |
|
58 | 58 | global $sd_widgets; |
59 | 59 | |
60 | - $sd_widgets[ $options['base_id'] ] = array( |
|
60 | + $sd_widgets[$options['base_id']] = array( |
|
61 | 61 | 'name' => $options['name'], |
62 | 62 | 'class_name' => $options['class_name'] |
63 | 63 | ); |
64 | - $this->base_id = $options['base_id']; |
|
64 | + $this->base_id = $options['base_id']; |
|
65 | 65 | // lets filter the options before we do anything |
66 | - $options = apply_filters( "wp_super_duper_options", $options ); |
|
67 | - $options = apply_filters( "wp_super_duper_options_{$this->base_id}", $options ); |
|
68 | - $options = $this->add_name_from_key( $options ); |
|
66 | + $options = apply_filters("wp_super_duper_options", $options); |
|
67 | + $options = apply_filters("wp_super_duper_options_{$this->base_id}", $options); |
|
68 | + $options = $this->add_name_from_key($options); |
|
69 | 69 | $this->options = $options; |
70 | 70 | |
71 | 71 | $this->base_id = $options['base_id']; |
72 | - $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array(); |
|
72 | + $this->arguments = isset($options['arguments']) ? $options['arguments'] : array(); |
|
73 | 73 | |
74 | 74 | // init parent |
75 | - parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] ); |
|
75 | + parent::__construct($options['base_id'], $options['name'], $options['widget_ops']); |
|
76 | 76 | |
77 | - if ( isset( $options['class_name'] ) ) { |
|
77 | + if (isset($options['class_name'])) { |
|
78 | 78 | // register widget |
79 | 79 | $this->class_name = $options['class_name']; |
80 | 80 | |
@@ -82,54 +82,54 @@ discard block |
||
82 | 82 | $this->register_shortcode(); |
83 | 83 | |
84 | 84 | // Fusion Builder (avada) support |
85 | - if( function_exists('fusion_builder_map') ){ $this->register_fusion_element(); } |
|
85 | + if (function_exists('fusion_builder_map')) { $this->register_fusion_element(); } |
|
86 | 86 | |
87 | 87 | // register block |
88 | - add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) ); |
|
88 | + add_action('admin_enqueue_scripts', array($this, 'register_block')); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | // add the CSS and JS we need ONCE |
92 | 92 | global $sd_widget_scripts; |
93 | 93 | |
94 | - if ( ! $sd_widget_scripts ) { |
|
95 | - wp_add_inline_script( 'admin-widgets', $this->widget_js() ); |
|
96 | - wp_add_inline_script( 'customize-controls', $this->widget_js() ); |
|
97 | - wp_add_inline_style( 'widgets', $this->widget_css() ); |
|
94 | + if (!$sd_widget_scripts) { |
|
95 | + wp_add_inline_script('admin-widgets', $this->widget_js()); |
|
96 | + wp_add_inline_script('customize-controls', $this->widget_js()); |
|
97 | + wp_add_inline_style('widgets', $this->widget_css()); |
|
98 | 98 | |
99 | 99 | $sd_widget_scripts = true; |
100 | 100 | |
101 | 101 | // add shortcode insert button once |
102 | - add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) ); |
|
102 | + add_action('media_buttons', array($this, 'shortcode_insert_button')); |
|
103 | 103 | // generatepress theme sections compatibility |
104 | - if ( function_exists( 'generate_sections_sections_metabox' ) ) { |
|
105 | - add_action( 'generate_sections_metabox', array( $this, 'shortcode_insert_button_script' ) ); |
|
104 | + if (function_exists('generate_sections_sections_metabox')) { |
|
105 | + add_action('generate_sections_metabox', array($this, 'shortcode_insert_button_script')); |
|
106 | 106 | } |
107 | - if ( $this->is_preview() ) { |
|
108 | - add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) ); |
|
107 | + if ($this->is_preview()) { |
|
108 | + add_action('wp_footer', array($this, 'shortcode_insert_button_script')); |
|
109 | 109 | // this makes the insert button work for elementor |
110 | - add_action( 'elementor/editor/after_enqueue_scripts', array( |
|
110 | + add_action('elementor/editor/after_enqueue_scripts', array( |
|
111 | 111 | $this, |
112 | 112 | 'shortcode_insert_button_script' |
113 | - ) ); // for elementor |
|
113 | + )); // for elementor |
|
114 | 114 | } |
115 | 115 | // this makes the insert button work for cornerstone |
116 | - add_action('wp_print_footer_scripts',array( __CLASS__, 'maybe_cornerstone_builder' )); |
|
116 | + add_action('wp_print_footer_scripts', array(__CLASS__, 'maybe_cornerstone_builder')); |
|
117 | 117 | |
118 | - add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) ); |
|
119 | - add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) ); |
|
118 | + add_action('wp_ajax_super_duper_get_widget_settings', array(__CLASS__, 'get_widget_settings')); |
|
119 | + add_action('wp_ajax_super_duper_get_picker', array(__CLASS__, 'get_picker')); |
|
120 | 120 | |
121 | 121 | // add generator text to admin head |
122 | - add_action( 'admin_head', array( $this, 'generator' ) ); |
|
122 | + add_action('admin_head', array($this, 'generator')); |
|
123 | 123 | } |
124 | 124 | |
125 | - do_action( 'wp_super_duper_widget_init', $options, $this ); |
|
125 | + do_action('wp_super_duper_widget_init', $options, $this); |
|
126 | 126 | } |
127 | 127 | |
128 | - public function register_fusion_element(){ |
|
128 | + public function register_fusion_element() { |
|
129 | 129 | |
130 | 130 | $options = $this->options; |
131 | 131 | |
132 | - if($this->base_id){ |
|
132 | + if ($this->base_id) { |
|
133 | 133 | |
134 | 134 | $params = $this->get_fusion_params(); |
135 | 135 | |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | 'allow_generator' => true, |
141 | 141 | ); |
142 | 142 | |
143 | - if(!empty($params)){ |
|
143 | + if (!empty($params)) { |
|
144 | 144 | $args['params'] = $params; |
145 | 145 | } |
146 | 146 | |
@@ -149,12 +149,12 @@ discard block |
||
149 | 149 | |
150 | 150 | } |
151 | 151 | |
152 | - public function get_fusion_params(){ |
|
152 | + public function get_fusion_params() { |
|
153 | 153 | $params = array(); |
154 | 154 | $arguments = $this->get_arguments(); |
155 | 155 | |
156 | - if(!empty($arguments)){ |
|
157 | - foreach($arguments as $key => $val){ |
|
156 | + if (!empty($arguments)) { |
|
157 | + foreach ($arguments as $key => $val) { |
|
158 | 158 | $param = array(); |
159 | 159 | // type |
160 | 160 | $param['type'] = str_replace( |
@@ -188,19 +188,19 @@ discard block |
||
188 | 188 | $param['default'] = isset($val['default']) ? $val['default'] : ''; |
189 | 189 | |
190 | 190 | // Group |
191 | - if(isset($val['group'])){ |
|
191 | + if (isset($val['group'])) { |
|
192 | 192 | $param['group'] = $val['group']; |
193 | 193 | } |
194 | 194 | |
195 | 195 | // value |
196 | - if($val['type'] == 'checkbox'){ |
|
197 | - if(isset($val['default']) && $val['default'] == '0'){ |
|
196 | + if ($val['type'] == 'checkbox') { |
|
197 | + if (isset($val['default']) && $val['default'] == '0') { |
|
198 | 198 | unset($param['default']); |
199 | 199 | } |
200 | - $param['value'] = array(''=>__("No"),'1'=>__("Yes")); |
|
201 | - }elseif($param['type'] == 'select'){ |
|
200 | + $param['value'] = array(''=>__("No"), '1'=>__("Yes")); |
|
201 | + }elseif ($param['type'] == 'select') { |
|
202 | 202 | $param['value'] = isset($val['options']) ? $val['options'] : array(); |
203 | - }else{ |
|
203 | + } else { |
|
204 | 204 | $param['value'] = isset($val['default']) ? $val['default'] : ''; |
205 | 205 | } |
206 | 206 | |
@@ -217,8 +217,8 @@ discard block |
||
217 | 217 | /** |
218 | 218 | * Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder |
219 | 219 | */ |
220 | - public static function maybe_cornerstone_builder(){ |
|
221 | - if(did_action('cornerstone_before_boot_app')){ |
|
220 | + public static function maybe_cornerstone_builder() { |
|
221 | + if (did_action('cornerstone_before_boot_app')) { |
|
222 | 222 | self::shortcode_insert_button_script(); |
223 | 223 | } |
224 | 224 | } |
@@ -230,12 +230,12 @@ discard block |
||
230 | 230 | * |
231 | 231 | * @return string |
232 | 232 | */ |
233 | - public static function get_picker( $editor_id = '' ) { |
|
233 | + public static function get_picker($editor_id = '') { |
|
234 | 234 | |
235 | 235 | ob_start(); |
236 | - if ( isset( $_POST['editor_id'] ) ) { |
|
237 | - $editor_id = esc_attr( $_POST['editor_id'] ); |
|
238 | - } elseif ( isset( $_REQUEST['et_fb'] ) ) { |
|
236 | + if (isset($_POST['editor_id'])) { |
|
237 | + $editor_id = esc_attr($_POST['editor_id']); |
|
238 | + } elseif (isset($_REQUEST['et_fb'])) { |
|
239 | 239 | $editor_id = 'main_content_content_vb_tiny_mce'; |
240 | 240 | } |
241 | 241 | |
@@ -244,13 +244,13 @@ discard block |
||
244 | 244 | |
245 | 245 | <div class="sd-shortcode-left-wrap"> |
246 | 246 | <?php |
247 | - ksort( $sd_widgets ); |
|
247 | + ksort($sd_widgets); |
|
248 | 248 | // print_r($sd_widgets);exit; |
249 | - if ( ! empty( $sd_widgets ) ) { |
|
249 | + if (!empty($sd_widgets)) { |
|
250 | 250 | echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">'; |
251 | - echo "<option>" . __( 'Select shortcode' ) . "</option>"; |
|
252 | - foreach ( $sd_widgets as $shortcode => $class ) { |
|
253 | - echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>"; |
|
251 | + echo "<option>" . __('Select shortcode') . "</option>"; |
|
252 | + foreach ($sd_widgets as $shortcode => $class) { |
|
253 | + echo "<option value='" . esc_attr($shortcode) . "'>" . esc_attr($shortcode) . " (" . esc_attr($class['name']) . ")</option>"; |
|
254 | 254 | } |
255 | 255 | echo "</select>"; |
256 | 256 | |
@@ -263,37 +263,37 @@ discard block |
||
263 | 263 | <div class="sd-shortcode-right-wrap"> |
264 | 264 | <textarea id='sd-shortcode-output' disabled></textarea> |
265 | 265 | <div id='sd-shortcode-output-actions'> |
266 | - <?php if ( $editor_id != '' ) { ?> |
|
266 | + <?php if ($editor_id != '') { ?> |
|
267 | 267 | <button class="button sd-insert-shortcode-button" |
268 | - onclick="sd_insert_shortcode(<?php if ( ! empty( $editor_id ) ) { |
|
268 | + onclick="sd_insert_shortcode(<?php if (!empty($editor_id)) { |
|
269 | 269 | echo "'" . $editor_id . "'"; |
270 | - } ?>)"><?php _e( 'Insert shortcode' ); ?></button> |
|
270 | + } ?>)"><?php _e('Insert shortcode'); ?></button> |
|
271 | 271 | <?php } ?> |
272 | 272 | <button class="button" |
273 | - onclick="sd_copy_to_clipboard()"><?php _e( 'Copy shortcode' ); ?></button> |
|
273 | + onclick="sd_copy_to_clipboard()"><?php _e('Copy shortcode'); ?></button> |
|
274 | 274 | </div> |
275 | 275 | </div> |
276 | 276 | <?php |
277 | 277 | |
278 | 278 | $html = ob_get_clean(); |
279 | 279 | |
280 | - if ( wp_doing_ajax() ) { |
|
280 | + if (wp_doing_ajax()) { |
|
281 | 281 | echo $html; |
282 | 282 | $should_die = true; |
283 | 283 | |
284 | 284 | // some builder get the editor via ajax so we should not die on those ocasions |
285 | 285 | $dont_die = array( |
286 | - 'parent_tag',// WP Bakery |
|
286 | + 'parent_tag', // WP Bakery |
|
287 | 287 | 'avia_request' // enfold |
288 | 288 | ); |
289 | 289 | |
290 | - foreach ( $dont_die as $request ) { |
|
291 | - if ( isset( $_REQUEST[ $request ] ) ) { |
|
290 | + foreach ($dont_die as $request) { |
|
291 | + if (isset($_REQUEST[$request])) { |
|
292 | 292 | $should_die = false; |
293 | 293 | } |
294 | 294 | } |
295 | 295 | |
296 | - if ( $should_die ) { |
|
296 | + if ($should_die) { |
|
297 | 297 | wp_die(); |
298 | 298 | } |
299 | 299 | |
@@ -320,16 +320,16 @@ discard block |
||
320 | 320 | public static function get_widget_settings() { |
321 | 321 | global $sd_widgets; |
322 | 322 | |
323 | - $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : ''; |
|
324 | - if ( ! $shortcode ) { |
|
323 | + $shortcode = isset($_REQUEST['shortcode']) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes($_REQUEST['shortcode']) : ''; |
|
324 | + if (!$shortcode) { |
|
325 | 325 | wp_die(); |
326 | 326 | } |
327 | - $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : ''; |
|
328 | - if ( ! $widget_args ) { |
|
327 | + $widget_args = isset($sd_widgets[$shortcode]) ? $sd_widgets[$shortcode] : ''; |
|
328 | + if (!$widget_args) { |
|
329 | 329 | wp_die(); |
330 | 330 | } |
331 | - $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
332 | - if ( ! $class_name ) { |
|
331 | + $class_name = isset($widget_args['class_name']) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
332 | + if (!$class_name) { |
|
333 | 333 | wp_die(); |
334 | 334 | } |
335 | 335 | |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | $widget = new $class_name; |
338 | 338 | |
339 | 339 | ob_start(); |
340 | - $widget->form( array() ); |
|
340 | + $widget->form(array()); |
|
341 | 341 | $form = ob_get_clean(); |
342 | 342 | echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>"; |
343 | 343 | echo "<style>" . $widget->widget_css() . "</style>"; |
@@ -355,9 +355,9 @@ discard block |
||
355 | 355 | * @param string $editor_id Optional. Shortcode editor id. Default null. |
356 | 356 | * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null. |
357 | 357 | */ |
358 | - public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) { |
|
358 | + public static function shortcode_insert_button($editor_id = '', $insert_shortcode_function = '') { |
|
359 | 359 | global $sd_widgets, $shortcode_insert_button_once; |
360 | - if ( $shortcode_insert_button_once ) { |
|
360 | + if ($shortcode_insert_button_once) { |
|
361 | 361 | return; |
362 | 362 | } |
363 | 363 | add_thickbox(); |
@@ -367,21 +367,21 @@ discard block |
||
367 | 367 | * Cornerstone makes us play dirty tricks :/ |
368 | 368 | * All media_buttons are removed via JS unless they are two specific id's so we wrap our content in this ID so it is not removed. |
369 | 369 | */ |
370 | - if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
370 | + if (function_exists('cornerstone_plugin_init') && !is_admin()) { |
|
371 | 371 | echo '<span id="insert-media-button">'; |
372 | 372 | } |
373 | 373 | |
374 | - echo self::shortcode_button( 'this', 'true' ); |
|
374 | + echo self::shortcode_button('this', 'true'); |
|
375 | 375 | |
376 | 376 | // see opening note |
377 | - if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
377 | + if (function_exists('cornerstone_plugin_init') && !is_admin()) { |
|
378 | 378 | echo '</span>'; // end #insert-media-button |
379 | 379 | } |
380 | 380 | |
381 | 381 | // Add separate script for generatepress theme sections |
382 | - if ( function_exists( 'generate_sections_sections_metabox' ) && did_action( 'generate_sections_metabox' ) ) { |
|
382 | + if (function_exists('generate_sections_sections_metabox') && did_action('generate_sections_metabox')) { |
|
383 | 383 | } else { |
384 | - self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function ); |
|
384 | + self::shortcode_insert_button_script($editor_id, $insert_shortcode_function); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | $shortcode_insert_button_once = true; |
@@ -395,12 +395,12 @@ discard block |
||
395 | 395 | * |
396 | 396 | * @return mixed |
397 | 397 | */ |
398 | - public static function shortcode_button( $id = '', $search_for_id = '' ) { |
|
398 | + public static function shortcode_button($id = '', $search_for_id = '') { |
|
399 | 399 | ob_start(); |
400 | 400 | ?> |
401 | 401 | <span class="sd-lable-shortcode-inserter"> |
402 | 402 | <a onclick="sd_ajax_get_picker(<?php echo $id; |
403 | - if ( $search_for_id ) { |
|
403 | + if ($search_for_id) { |
|
404 | 404 | echo "," . $search_for_id; |
405 | 405 | } ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed" |
406 | 406 | class="thickbox button super-duper-content-open" title="Add Shortcode"> |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | $html = ob_get_clean(); |
417 | 417 | |
418 | 418 | // remove line breaks so we can use it in js |
419 | - return preg_replace( "/\r|\n/", "", trim( $html ) ); |
|
419 | + return preg_replace("/\r|\n/", "", trim($html)); |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | /** |
@@ -474,7 +474,7 @@ discard block |
||
474 | 474 | jQuery($this).data('sd-widget-enabled', true); |
475 | 475 | } |
476 | 476 | |
477 | - var $button = '<button title="<?php _e( 'Advanced Settings' );?>" class="button button-primary right sd-advanced-button" onclick="sd_so_toggle_advanced(this);return false;"><i class="fas fa-sliders-h" aria-hidden="true"></i></button>'; |
|
477 | + var $button = '<button title="<?php _e('Advanced Settings'); ?>" class="button button-primary right sd-advanced-button" onclick="sd_so_toggle_advanced(this);return false;"><i class="fas fa-sliders-h" aria-hidden="true"></i></button>'; |
|
478 | 478 | var form = jQuery($this).parents('' + $selector + ''); |
479 | 479 | |
480 | 480 | if (jQuery($this).val() == '1' && jQuery(form).find('.sd-advanced-button').length == 0) { |
@@ -511,10 +511,10 @@ discard block |
||
511 | 511 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
512 | 512 | */ |
513 | 513 | |
514 | - return str_replace( array( |
|
514 | + return str_replace(array( |
|
515 | 515 | '<script>', |
516 | 516 | '</script>' |
517 | - ), '', $output ); |
|
517 | + ), '', $output); |
|
518 | 518 | } |
519 | 519 | |
520 | 520 | /** |
@@ -525,7 +525,7 @@ discard block |
||
525 | 525 | * @param string $editor_id |
526 | 526 | * @param string $insert_shortcode_function |
527 | 527 | */ |
528 | - public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) { |
|
528 | + public static function shortcode_insert_button_script($editor_id = '', $insert_shortcode_function = '') { |
|
529 | 529 | ?> |
530 | 530 | <style> |
531 | 531 | .sd-shortcode-left-wrap { |
@@ -643,22 +643,22 @@ discard block |
||
643 | 643 | height: 250px; |
644 | 644 | width: 100%; |
645 | 645 | } |
646 | - <?php if ( function_exists( 'generate_sections_sections_metabox' ) ) { ?> |
|
646 | + <?php if (function_exists('generate_sections_sections_metabox')) { ?> |
|
647 | 647 | .generate-sections-modal #custom-media-buttons > .sd-lable-shortcode-inserter { |
648 | 648 | display: inline; |
649 | 649 | } |
650 | 650 | <?php } ?> |
651 | 651 | </style> |
652 | 652 | <?php |
653 | - if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
653 | + if (class_exists('SiteOrigin_Panels')) { |
|
654 | 654 | echo "<script>" . self::siteorigin_js() . "</script>"; |
655 | 655 | } |
656 | 656 | ?> |
657 | 657 | <script> |
658 | 658 | <?php |
659 | - if(! empty( $insert_shortcode_function )){ |
|
659 | + if (!empty($insert_shortcode_function)) { |
|
660 | 660 | echo $insert_shortcode_function; |
661 | - }else{ |
|
661 | + } else { |
|
662 | 662 | |
663 | 663 | /** |
664 | 664 | * Function for super duper insert shortcode. |
@@ -671,9 +671,9 @@ discard block |
||
671 | 671 | if ($shortcode) { |
672 | 672 | if (!$editor_id) { |
673 | 673 | <?php |
674 | - if ( isset( $_REQUEST['et_fb'] ) ) { |
|
674 | + if (isset($_REQUEST['et_fb'])) { |
|
675 | 675 | echo '$editor_id = "#main_content_content_vb_tiny_mce";'; |
676 | - } elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) { |
|
676 | + } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor') { |
|
677 | 677 | echo '$editor_id = "#elementor-controls .wp-editor-container textarea";'; |
678 | 678 | } else { |
679 | 679 | echo '$editor_id = "#wp-content-editor-container textarea";'; |
@@ -758,11 +758,11 @@ discard block |
||
758 | 758 | 'shortcode': $short_code, |
759 | 759 | 'attributes': 123, |
760 | 760 | 'post_id': 321, |
761 | - '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>' |
|
761 | + '_ajax_nonce': '<?php echo wp_create_nonce('super_duper_output_shortcode'); ?>' |
|
762 | 762 | }; |
763 | 763 | |
764 | 764 | if (typeof ajaxurl === 'undefined') { |
765 | - var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' );?>"; |
|
765 | + var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>"; |
|
766 | 766 | } |
767 | 767 | |
768 | 768 | jQuery.post(ajaxurl, data, function (response) { |
@@ -960,11 +960,11 @@ discard block |
||
960 | 960 | var data = { |
961 | 961 | 'action': 'super_duper_get_picker', |
962 | 962 | 'editor_id': $id, |
963 | - '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_picker' );?>' |
|
963 | + '_ajax_nonce': '<?php echo wp_create_nonce('super_duper_picker'); ?>' |
|
964 | 964 | }; |
965 | 965 | |
966 | 966 | if (!ajaxurl) { |
967 | - var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' ); ?>"; |
|
967 | + var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>"; |
|
968 | 968 | } |
969 | 969 | |
970 | 970 | jQuery.post(ajaxurl, data, function (response) { |
@@ -985,9 +985,9 @@ discard block |
||
985 | 985 | */ |
986 | 986 | function sd_shortcode_button($id) { |
987 | 987 | if ($id) { |
988 | - return '<?php echo self::shortcode_button( "\\''+\$id+'\\'" );?>'; |
|
988 | + return '<?php echo self::shortcode_button("\\''+\$id+'\\'"); ?>'; |
|
989 | 989 | } else { |
990 | - return '<?php echo self::shortcode_button();?>'; |
|
990 | + return '<?php echo self::shortcode_button(); ?>'; |
|
991 | 991 | } |
992 | 992 | } |
993 | 993 | |
@@ -1043,10 +1043,10 @@ discard block |
||
1043 | 1043 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
1044 | 1044 | */ |
1045 | 1045 | |
1046 | - return str_replace( array( |
|
1046 | + return str_replace(array( |
|
1047 | 1047 | '<style>', |
1048 | 1048 | '</style>' |
1049 | - ), '', $output ); |
|
1049 | + ), '', $output); |
|
1050 | 1050 | } |
1051 | 1051 | |
1052 | 1052 | /** |
@@ -1116,7 +1116,7 @@ discard block |
||
1116 | 1116 | jQuery($this).data('sd-widget-enabled', true); |
1117 | 1117 | } |
1118 | 1118 | |
1119 | - var $button = '<button title="<?php _e( 'Advanced Settings' );?>" class="button button-primary right sd-advanced-button" onclick="sd_toggle_advanced(this);return false;"><span class="dashicons dashicons-admin-settings" style="width: 28px;font-size: 28px;"></span></button>'; |
|
1119 | + var $button = '<button title="<?php _e('Advanced Settings'); ?>" class="button button-primary right sd-advanced-button" onclick="sd_toggle_advanced(this);return false;"><span class="dashicons dashicons-admin-settings" style="width: 28px;font-size: 28px;"></span></button>'; |
|
1120 | 1120 | var form = jQuery($this).parents('' + $selector + ''); |
1121 | 1121 | |
1122 | 1122 | if (jQuery($this).val() == '1' && jQuery(form).find('.sd-advanced-button').length == 0) { |
@@ -1208,7 +1208,7 @@ discard block |
||
1208 | 1208 | }); |
1209 | 1209 | |
1210 | 1210 | } |
1211 | - <?php do_action( 'wp_super_duper_widget_js', $this ); ?> |
|
1211 | + <?php do_action('wp_super_duper_widget_js', $this); ?> |
|
1212 | 1212 | </script> |
1213 | 1213 | <?php |
1214 | 1214 | $output = ob_get_clean(); |
@@ -1217,10 +1217,10 @@ discard block |
||
1217 | 1217 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
1218 | 1218 | */ |
1219 | 1219 | |
1220 | - return str_replace( array( |
|
1220 | + return str_replace(array( |
|
1221 | 1221 | '<script>', |
1222 | 1222 | '</script>' |
1223 | - ), '', $output ); |
|
1223 | + ), '', $output); |
|
1224 | 1224 | } |
1225 | 1225 | |
1226 | 1226 | |
@@ -1231,14 +1231,14 @@ discard block |
||
1231 | 1231 | * |
1232 | 1232 | * @return mixed |
1233 | 1233 | */ |
1234 | - private function add_name_from_key( $options, $arguments = false ) { |
|
1235 | - if ( ! empty( $options['arguments'] ) ) { |
|
1236 | - foreach ( $options['arguments'] as $key => $val ) { |
|
1237 | - $options['arguments'][ $key ]['name'] = $key; |
|
1234 | + private function add_name_from_key($options, $arguments = false) { |
|
1235 | + if (!empty($options['arguments'])) { |
|
1236 | + foreach ($options['arguments'] as $key => $val) { |
|
1237 | + $options['arguments'][$key]['name'] = $key; |
|
1238 | 1238 | } |
1239 | - } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) { |
|
1240 | - foreach ( $options as $key => $val ) { |
|
1241 | - $options[ $key ]['name'] = $key; |
|
1239 | + } elseif ($arguments && is_array($options) && !empty($options)) { |
|
1240 | + foreach ($options as $key => $val) { |
|
1241 | + $options[$key]['name'] = $key; |
|
1242 | 1242 | } |
1243 | 1243 | } |
1244 | 1244 | |
@@ -1251,8 +1251,8 @@ discard block |
||
1251 | 1251 | * @since 1.0.0 |
1252 | 1252 | */ |
1253 | 1253 | public function register_shortcode() { |
1254 | - add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) ); |
|
1255 | - add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) ); |
|
1254 | + add_shortcode($this->base_id, array($this, 'shortcode_output')); |
|
1255 | + add_action('wp_ajax_super_duper_output_shortcode', array(__CLASS__, 'render_shortcode')); |
|
1256 | 1256 | } |
1257 | 1257 | |
1258 | 1258 | /** |
@@ -1262,33 +1262,33 @@ discard block |
||
1262 | 1262 | */ |
1263 | 1263 | public static function render_shortcode() { |
1264 | 1264 | |
1265 | - check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true ); |
|
1266 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
1265 | + check_ajax_referer('super_duper_output_shortcode', '_ajax_nonce', true); |
|
1266 | + if (!current_user_can('manage_options')) { |
|
1267 | 1267 | wp_die(); |
1268 | 1268 | } |
1269 | 1269 | |
1270 | 1270 | // we might need the $post value here so lets set it. |
1271 | - if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) { |
|
1272 | - $post_obj = get_post( absint( $_POST['post_id'] ) ); |
|
1273 | - if ( ! empty( $post_obj ) && empty( $post ) ) { |
|
1271 | + if (isset($_POST['post_id']) && $_POST['post_id']) { |
|
1272 | + $post_obj = get_post(absint($_POST['post_id'])); |
|
1273 | + if (!empty($post_obj) && empty($post)) { |
|
1274 | 1274 | global $post; |
1275 | 1275 | $post = $post_obj; |
1276 | 1276 | } |
1277 | 1277 | } |
1278 | 1278 | |
1279 | - if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) { |
|
1280 | - $shortcode_name = sanitize_title_with_dashes( $_POST['shortcode'] ); |
|
1281 | - $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
1279 | + if (isset($_POST['shortcode']) && $_POST['shortcode']) { |
|
1280 | + $shortcode_name = sanitize_title_with_dashes($_POST['shortcode']); |
|
1281 | + $attributes_array = isset($_POST['attributes']) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
1282 | 1282 | $attributes = ''; |
1283 | - if ( ! empty( $attributes_array ) ) { |
|
1284 | - foreach ( $attributes_array as $key => $value ) { |
|
1285 | - $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' "; |
|
1283 | + if (!empty($attributes_array)) { |
|
1284 | + foreach ($attributes_array as $key => $value) { |
|
1285 | + $attributes .= " " . sanitize_title_with_dashes($key) . "='" . wp_slash($value) . "' "; |
|
1286 | 1286 | } |
1287 | 1287 | } |
1288 | 1288 | |
1289 | 1289 | $shortcode = "[" . $shortcode_name . " " . $attributes . "]"; |
1290 | 1290 | |
1291 | - echo do_shortcode( $shortcode ); |
|
1291 | + echo do_shortcode($shortcode); |
|
1292 | 1292 | |
1293 | 1293 | } |
1294 | 1294 | wp_die(); |
@@ -1302,37 +1302,37 @@ discard block |
||
1302 | 1302 | * |
1303 | 1303 | * @return string |
1304 | 1304 | */ |
1305 | - public function shortcode_output( $args = array(), $content = '' ) { |
|
1306 | - $args = self::argument_values( $args ); |
|
1305 | + public function shortcode_output($args = array(), $content = '') { |
|
1306 | + $args = self::argument_values($args); |
|
1307 | 1307 | |
1308 | 1308 | // add extra argument so we know its a output to gutenberg |
1309 | 1309 | //$args |
1310 | - $args = $this->string_to_bool( $args ); |
|
1310 | + $args = $this->string_to_bool($args); |
|
1311 | 1311 | |
1312 | 1312 | |
1313 | - $calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : ''; |
|
1313 | + $calss = isset($this->options['widget_ops']['classname']) ? esc_attr($this->options['widget_ops']['classname']) : ''; |
|
1314 | 1314 | |
1315 | - $calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this ); |
|
1316 | - $calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this ); |
|
1315 | + $calss = apply_filters('wp_super_duper_div_classname', $calss, $args, $this); |
|
1316 | + $calss = apply_filters('wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this); |
|
1317 | 1317 | |
1318 | - $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this ); |
|
1319 | - $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this ); |
|
1318 | + $attrs = apply_filters('wp_super_duper_div_attrs', '', $args, $this); |
|
1319 | + $attrs = apply_filters('wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this); |
|
1320 | 1320 | |
1321 | 1321 | $shortcode_args = array(); |
1322 | 1322 | $output = ''; |
1323 | - $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false; |
|
1324 | - $main_content = $this->output( $args, $shortcode_args, $content ); |
|
1325 | - if ( $main_content && ! $no_wrap ) { |
|
1323 | + $no_wrap = isset($this->options['no_wrap']) && $this->options['no_wrap'] ? true : false; |
|
1324 | + $main_content = $this->output($args, $shortcode_args, $content); |
|
1325 | + if ($main_content && !$no_wrap) { |
|
1326 | 1326 | // wrap the shortcode in a dive with the same class as the widget |
1327 | 1327 | $output .= '<div class="' . $calss . '" ' . $attrs . '>'; |
1328 | - if ( ! empty( $args['title'] ) ) { |
|
1328 | + if (!empty($args['title'])) { |
|
1329 | 1329 | // if its a shortcode and there is a title try to grab the title wrappers |
1330 | - $shortcode_args = array( 'before_title' => '', 'after_title' => '' ); |
|
1331 | - if ( empty( $instance ) ) { |
|
1330 | + $shortcode_args = array('before_title' => '', 'after_title' => ''); |
|
1331 | + if (empty($instance)) { |
|
1332 | 1332 | global $wp_registered_sidebars; |
1333 | - if ( ! empty( $wp_registered_sidebars ) ) { |
|
1334 | - foreach ( $wp_registered_sidebars as $sidebar ) { |
|
1335 | - if ( ! empty( $sidebar['before_title'] ) ) { |
|
1333 | + if (!empty($wp_registered_sidebars)) { |
|
1334 | + foreach ($wp_registered_sidebars as $sidebar) { |
|
1335 | + if (!empty($sidebar['before_title'])) { |
|
1336 | 1336 | $shortcode_args['before_title'] = $sidebar['before_title']; |
1337 | 1337 | $shortcode_args['after_title'] = $sidebar['after_title']; |
1338 | 1338 | break; |
@@ -1340,20 +1340,20 @@ discard block |
||
1340 | 1340 | } |
1341 | 1341 | } |
1342 | 1342 | } |
1343 | - $output .= $this->output_title( $shortcode_args, $args ); |
|
1343 | + $output .= $this->output_title($shortcode_args, $args); |
|
1344 | 1344 | } |
1345 | 1345 | $output .= $main_content; |
1346 | 1346 | $output .= '</div>'; |
1347 | - } elseif ( $main_content && $no_wrap ) { |
|
1347 | + } elseif ($main_content && $no_wrap) { |
|
1348 | 1348 | $output .= $main_content; |
1349 | 1349 | } |
1350 | 1350 | |
1351 | 1351 | // if preview show a placeholder if empty |
1352 | - if ( $this->is_preview() && $output == '' ) { |
|
1353 | - $output = $this->preview_placeholder_text( "[{" . $this->base_id . "}]" ); |
|
1352 | + if ($this->is_preview() && $output == '') { |
|
1353 | + $output = $this->preview_placeholder_text("[{" . $this->base_id . "}]"); |
|
1354 | 1354 | } |
1355 | 1355 | |
1356 | - return apply_filters( 'wp_super_duper_widget_output', $output, $args, $shortcode_args, $this ); |
|
1356 | + return apply_filters('wp_super_duper_widget_output', $output, $args, $shortcode_args, $this); |
|
1357 | 1357 | } |
1358 | 1358 | |
1359 | 1359 | /** |
@@ -1363,8 +1363,8 @@ discard block |
||
1363 | 1363 | * |
1364 | 1364 | * @return string |
1365 | 1365 | */ |
1366 | - public function preview_placeholder_text( $name = '' ) { |
|
1367 | - return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>"; |
|
1366 | + public function preview_placeholder_text($name = '') { |
|
1367 | + return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf(__('Placeholder for: %s'), $name) . "</div>"; |
|
1368 | 1368 | } |
1369 | 1369 | |
1370 | 1370 | /** |
@@ -1374,13 +1374,13 @@ discard block |
||
1374 | 1374 | * |
1375 | 1375 | * @return mixed |
1376 | 1376 | */ |
1377 | - public function string_to_bool( $options ) { |
|
1377 | + public function string_to_bool($options) { |
|
1378 | 1378 | // convert bool strings to booleans |
1379 | - foreach ( $options as $key => $val ) { |
|
1380 | - if ( $val == 'false' ) { |
|
1381 | - $options[ $key ] = false; |
|
1382 | - } elseif ( $val == 'true' ) { |
|
1383 | - $options[ $key ] = true; |
|
1379 | + foreach ($options as $key => $val) { |
|
1380 | + if ($val == 'false') { |
|
1381 | + $options[$key] = false; |
|
1382 | + } elseif ($val == 'true') { |
|
1383 | + $options[$key] = true; |
|
1384 | 1384 | } |
1385 | 1385 | } |
1386 | 1386 | |
@@ -1396,27 +1396,27 @@ discard block |
||
1396 | 1396 | * |
1397 | 1397 | * @return array |
1398 | 1398 | */ |
1399 | - public function argument_values( $instance ) { |
|
1399 | + public function argument_values($instance) { |
|
1400 | 1400 | $argument_values = array(); |
1401 | 1401 | |
1402 | 1402 | // set widget instance |
1403 | 1403 | $this->instance = $instance; |
1404 | 1404 | |
1405 | - if ( empty( $this->arguments ) ) { |
|
1405 | + if (empty($this->arguments)) { |
|
1406 | 1406 | $this->arguments = $this->get_arguments(); |
1407 | 1407 | } |
1408 | 1408 | |
1409 | - if ( ! empty( $this->arguments ) ) { |
|
1410 | - foreach ( $this->arguments as $key => $args ) { |
|
1409 | + if (!empty($this->arguments)) { |
|
1410 | + foreach ($this->arguments as $key => $args) { |
|
1411 | 1411 | // set the input name from the key |
1412 | 1412 | $args['name'] = $key; |
1413 | 1413 | // |
1414 | - $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
|
1415 | - if($args['type']=='checkbox' && $argument_values[ $key ] == ''){ |
|
1414 | + $argument_values[$key] = isset($instance[$key]) ? $instance[$key] : ''; |
|
1415 | + if ($args['type'] == 'checkbox' && $argument_values[$key] == '') { |
|
1416 | 1416 | // don't set default for an empty checkbox |
1417 | 1417 | } |
1418 | - elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
1419 | - $argument_values[ $key ] = $args['default']; |
|
1418 | + elseif ($argument_values[$key] == '' && isset($args['default'])) { |
|
1419 | + $argument_values[$key] = $args['default']; |
|
1420 | 1420 | } |
1421 | 1421 | } |
1422 | 1422 | } |
@@ -1443,12 +1443,12 @@ discard block |
||
1443 | 1443 | * @return array Get arguments. |
1444 | 1444 | */ |
1445 | 1445 | public function get_arguments() { |
1446 | - if ( empty( $this->arguments ) ) { |
|
1446 | + if (empty($this->arguments)) { |
|
1447 | 1447 | $this->arguments = $this->set_arguments(); |
1448 | 1448 | } |
1449 | 1449 | |
1450 | - $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance ); |
|
1451 | - $this->arguments = $this->add_name_from_key( $this->arguments, true ); |
|
1450 | + $this->arguments = apply_filters('wp_super_duper_arguments', $this->arguments, $this->options, $this->instance); |
|
1451 | + $this->arguments = $this->add_name_from_key($this->arguments, true); |
|
1452 | 1452 | |
1453 | 1453 | return $this->arguments; |
1454 | 1454 | } |
@@ -1460,7 +1460,7 @@ discard block |
||
1460 | 1460 | * @param array $widget_args |
1461 | 1461 | * @param string $content |
1462 | 1462 | */ |
1463 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
1463 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
1464 | 1464 | |
1465 | 1465 | } |
1466 | 1466 | |
@@ -1468,10 +1468,10 @@ discard block |
||
1468 | 1468 | * Add the dynamic block code inline when the wp-block in enqueued. |
1469 | 1469 | */ |
1470 | 1470 | public function register_block() { |
1471 | - wp_add_inline_script( 'wp-blocks', $this->block() ); |
|
1472 | - if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
1471 | + wp_add_inline_script('wp-blocks', $this->block()); |
|
1472 | + if (class_exists('SiteOrigin_Panels')) { |
|
1473 | 1473 | |
1474 | - wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() ); |
|
1474 | + wp_add_inline_script('wp-blocks', $this->siteorigin_js()); |
|
1475 | 1475 | |
1476 | 1476 | } |
1477 | 1477 | } |
@@ -1486,13 +1486,13 @@ discard block |
||
1486 | 1486 | $show = false; |
1487 | 1487 | $arguments = $this->arguments; |
1488 | 1488 | |
1489 | - if ( empty( $arguments ) ) { |
|
1489 | + if (empty($arguments)) { |
|
1490 | 1490 | $arguments = $this->get_arguments(); |
1491 | 1491 | } |
1492 | 1492 | |
1493 | - if ( ! empty( $arguments ) ) { |
|
1494 | - foreach ( $arguments as $argument ) { |
|
1495 | - if ( isset( $argument['advanced'] ) && $argument['advanced'] ) { |
|
1493 | + if (!empty($arguments)) { |
|
1494 | + foreach ($arguments as $argument) { |
|
1495 | + if (isset($argument['advanced']) && $argument['advanced']) { |
|
1496 | 1496 | $show = true; |
1497 | 1497 | break; // no need to continue if we know we have it |
1498 | 1498 | } |
@@ -1511,15 +1511,15 @@ discard block |
||
1511 | 1511 | |
1512 | 1512 | $url = $this->url; |
1513 | 1513 | |
1514 | - if(!$url){ |
|
1514 | + if (!$url) { |
|
1515 | 1515 | // check if we are inside a plugin |
1516 | - $file_dir = str_replace("/includes","", dirname( __FILE__ )); |
|
1516 | + $file_dir = str_replace("/includes", "", dirname(__FILE__)); |
|
1517 | 1517 | |
1518 | - $dir_parts = explode("/wp-content/",$file_dir); |
|
1519 | - $url_parts = explode("/wp-content/",plugins_url()); |
|
1518 | + $dir_parts = explode("/wp-content/", $file_dir); |
|
1519 | + $url_parts = explode("/wp-content/", plugins_url()); |
|
1520 | 1520 | |
1521 | - if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
|
1522 | - $url = trailingslashit( $url_parts[0]."/wp-content/".$dir_parts[1] ); |
|
1521 | + if (!empty($url_parts[0]) && !empty($dir_parts[1])) { |
|
1522 | + $url = trailingslashit($url_parts[0] . "/wp-content/" . $dir_parts[1]); |
|
1523 | 1523 | $this->url = $url; |
1524 | 1524 | } |
1525 | 1525 | } |
@@ -1538,46 +1538,46 @@ discard block |
||
1538 | 1538 | * @since 1.1.0 |
1539 | 1539 | * @return string |
1540 | 1540 | */ |
1541 | - public function get_block_icon($icon){ |
|
1541 | + public function get_block_icon($icon) { |
|
1542 | 1542 | |
1543 | 1543 | // check if we have a Font Awesome icon |
1544 | 1544 | $fa_type = ''; |
1545 | - if(substr( $icon, 0, 7 ) === "fas fa-"){ |
|
1545 | + if (substr($icon, 0, 7) === "fas fa-") { |
|
1546 | 1546 | $fa_type = 'solid'; |
1547 | - }elseif(substr( $icon, 0, 7 ) === "far fa-"){ |
|
1547 | + }elseif (substr($icon, 0, 7) === "far fa-") { |
|
1548 | 1548 | $fa_type = 'regular'; |
1549 | - }elseif(substr( $icon, 0, 7 ) === "fab fa-"){ |
|
1549 | + }elseif (substr($icon, 0, 7) === "fab fa-") { |
|
1550 | 1550 | $fa_type = 'brands'; |
1551 | - }else{ |
|
1552 | - $icon = "'".$icon."'"; |
|
1551 | + } else { |
|
1552 | + $icon = "'" . $icon . "'"; |
|
1553 | 1553 | } |
1554 | 1554 | |
1555 | 1555 | // set the icon if we found one |
1556 | - if($fa_type){ |
|
1557 | - $fa_icon = str_replace(array("fas fa-","far fa-","fab fa-"),"",$icon); |
|
1558 | - $icon = "el('svg',{width: 20, height: 20, viewBox: '0 0 20 20'},el('use', {'xlink:href': '".$this->get_url()."icons/".$fa_type.".svg#".$fa_icon."','href': '".$this->get_url()."icons/".$fa_type.".svg#".$fa_icon."'}))"; |
|
1556 | + if ($fa_type) { |
|
1557 | + $fa_icon = str_replace(array("fas fa-", "far fa-", "fab fa-"), "", $icon); |
|
1558 | + $icon = "el('svg',{width: 20, height: 20, viewBox: '0 0 20 20'},el('use', {'xlink:href': '" . $this->get_url() . "icons/" . $fa_type . ".svg#" . $fa_icon . "','href': '" . $this->get_url() . "icons/" . $fa_type . ".svg#" . $fa_icon . "'}))"; |
|
1559 | 1559 | } |
1560 | 1560 | |
1561 | 1561 | return $icon; |
1562 | 1562 | } |
1563 | 1563 | |
1564 | - public function group_arguments($arguments){ |
|
1564 | + public function group_arguments($arguments) { |
|
1565 | 1565 | // echo '###';print_r($arguments); |
1566 | - if(!empty($arguments)){ |
|
1566 | + if (!empty($arguments)) { |
|
1567 | 1567 | $temp_arguments = array(); |
1568 | 1568 | $general = __("General"); |
1569 | 1569 | $add_sections = false; |
1570 | - foreach($arguments as $key => $args){ |
|
1571 | - if(isset($args['group'])){ |
|
1570 | + foreach ($arguments as $key => $args) { |
|
1571 | + if (isset($args['group'])) { |
|
1572 | 1572 | $temp_arguments[$args['group']][$key] = $args; |
1573 | 1573 | $add_sections = true; |
1574 | - }else{ |
|
1574 | + } else { |
|
1575 | 1575 | $temp_arguments[$general][$key] = $args; |
1576 | 1576 | } |
1577 | 1577 | } |
1578 | 1578 | |
1579 | 1579 | // only add sections if more than one |
1580 | - if($add_sections){ |
|
1580 | + if ($add_sections) { |
|
1581 | 1581 | $arguments = $temp_arguments; |
1582 | 1582 | } |
1583 | 1583 | } |
@@ -1629,19 +1629,19 @@ discard block |
||
1629 | 1629 | * @return {?WPBlock} The block, if it has been successfully |
1630 | 1630 | * registered; otherwise `undefined`. |
1631 | 1631 | */ |
1632 | - registerBlockType('<?php echo str_replace( "_", "-", sanitize_title_with_dashes( $this->options['textdomain'] ) . '/' . sanitize_title_with_dashes( $this->options['class_name'] ) ); ?>', { // Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block. |
|
1633 | - title: '<?php echo $this->options['name'];?>', // Block title. |
|
1634 | - description: '<?php echo esc_attr( $this->options['widget_ops']['description'] )?>', // Block title. |
|
1635 | - icon: <?php echo $this->get_block_icon($this->options['block-icon']);?>,//'<?php echo isset( $this->options['block-icon'] ) ? esc_attr( $this->options['block-icon'] ) : 'shield-alt';?>', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/. |
|
1632 | + registerBlockType('<?php echo str_replace("_", "-", sanitize_title_with_dashes($this->options['textdomain']) . '/' . sanitize_title_with_dashes($this->options['class_name'])); ?>', { // Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block. |
|
1633 | + title: '<?php echo $this->options['name']; ?>', // Block title. |
|
1634 | + description: '<?php echo esc_attr($this->options['widget_ops']['description'])?>', // Block title. |
|
1635 | + icon: <?php echo $this->get_block_icon($this->options['block-icon']); ?>,//'<?php echo isset($this->options['block-icon']) ? esc_attr($this->options['block-icon']) : 'shield-alt'; ?>', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/. |
|
1636 | 1636 | supports: { |
1637 | 1637 | <?php |
1638 | - if(isset($this->options['block-supports'])){ |
|
1639 | - echo $this->array_to_attributes( $this->options['block-supports'] ); |
|
1638 | + if (isset($this->options['block-supports'])) { |
|
1639 | + echo $this->array_to_attributes($this->options['block-supports']); |
|
1640 | 1640 | } |
1641 | 1641 | ?> |
1642 | 1642 | }, |
1643 | - category: '<?php echo isset( $this->options['block-category'] ) ? esc_attr( $this->options['block-category'] ) : 'common';?>', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed. |
|
1644 | - <?php if ( isset( $this->options['block-keywords'] ) ) { |
|
1643 | + category: '<?php echo isset($this->options['block-category']) ? esc_attr($this->options['block-category']) : 'common'; ?>', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed. |
|
1644 | + <?php if (isset($this->options['block-keywords'])) { |
|
1645 | 1645 | echo "keywords : " . $this->options['block-keywords'] . ","; |
1646 | 1646 | }?> |
1647 | 1647 | |
@@ -1656,10 +1656,10 @@ discard block |
||
1656 | 1656 | echo " html: false"; |
1657 | 1657 | echo "},";*/ |
1658 | 1658 | |
1659 | - if ( ! empty( $this->arguments ) ) { |
|
1659 | + if (!empty($this->arguments)) { |
|
1660 | 1660 | echo "attributes : {"; |
1661 | 1661 | |
1662 | - if ( $show_advanced ) { |
|
1662 | + if ($show_advanced) { |
|
1663 | 1663 | echo "show_advanced: {"; |
1664 | 1664 | echo " type: 'boolean',"; |
1665 | 1665 | echo " default: false,"; |
@@ -1667,41 +1667,41 @@ discard block |
||
1667 | 1667 | } |
1668 | 1668 | |
1669 | 1669 | // block wrap element |
1670 | - if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this? |
|
1670 | + if (isset($this->options['block-wrap'])) { //@todo we should validate this? |
|
1671 | 1671 | echo "block_wrap: {"; |
1672 | 1672 | echo " type: 'string',"; |
1673 | - echo " default: '" . esc_attr( $this->options['block-wrap'] ) . "',"; |
|
1673 | + echo " default: '" . esc_attr($this->options['block-wrap']) . "',"; |
|
1674 | 1674 | echo "},"; |
1675 | 1675 | } |
1676 | 1676 | |
1677 | - foreach ( $this->arguments as $key => $args ) { |
|
1677 | + foreach ($this->arguments as $key => $args) { |
|
1678 | 1678 | |
1679 | 1679 | // set if we should show alignment |
1680 | - if ( $key == 'alignment' ) { |
|
1680 | + if ($key == 'alignment') { |
|
1681 | 1681 | $show_alignment = true; |
1682 | 1682 | } |
1683 | 1683 | |
1684 | 1684 | $extra = ''; |
1685 | 1685 | |
1686 | - if ( $args['type'] == 'checkbox' ) { |
|
1686 | + if ($args['type'] == 'checkbox') { |
|
1687 | 1687 | $type = 'boolean'; |
1688 | - $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false'; |
|
1689 | - } elseif ( $args['type'] == 'number' ) { |
|
1688 | + $default = isset($args['default']) && $args['default'] ? 'true' : 'false'; |
|
1689 | + } elseif ($args['type'] == 'number') { |
|
1690 | 1690 | $type = 'number'; |
1691 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1692 | - } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) { |
|
1691 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
1692 | + } elseif ($args['type'] == 'select' && !empty($args['multiple'])) { |
|
1693 | 1693 | $type = 'array'; |
1694 | - if ( is_array( $args['default'] ) ) { |
|
1695 | - $default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]"; |
|
1694 | + if (is_array($args['default'])) { |
|
1695 | + $default = isset($args['default']) ? "['" . implode("','", $args['default']) . "']" : "[]"; |
|
1696 | 1696 | } else { |
1697 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1697 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
1698 | 1698 | } |
1699 | - } elseif ( $args['type'] == 'multiselect' ) { |
|
1699 | + } elseif ($args['type'] == 'multiselect') { |
|
1700 | 1700 | $type = 'array'; |
1701 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1701 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
1702 | 1702 | } else { |
1703 | 1703 | $type = 'string'; |
1704 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1704 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
1705 | 1705 | } |
1706 | 1706 | echo $key . " : {"; |
1707 | 1707 | echo "type : '$type',"; |
@@ -1732,12 +1732,12 @@ discard block |
||
1732 | 1732 | is_fetching = true; |
1733 | 1733 | var data = { |
1734 | 1734 | 'action': 'super_duper_output_shortcode', |
1735 | - 'shortcode': '<?php echo $this->options['base_id'];?>', |
|
1735 | + 'shortcode': '<?php echo $this->options['base_id']; ?>', |
|
1736 | 1736 | 'attributes': props.attributes, |
1737 | - 'post_id': <?php global $post; if ( isset( $post->ID ) ) { |
|
1737 | + 'post_id': <?php global $post; if (isset($post->ID)) { |
|
1738 | 1738 | echo $post->ID; |
1739 | 1739 | }?>, |
1740 | - '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>' |
|
1740 | + '_ajax_nonce': '<?php echo wp_create_nonce('super_duper_output_shortcode'); ?>' |
|
1741 | 1741 | }; |
1742 | 1742 | |
1743 | 1743 | jQuery.post(ajaxurl, data, function (response) { |
@@ -1746,7 +1746,7 @@ discard block |
||
1746 | 1746 | |
1747 | 1747 | // if the content is empty then we place some placeholder text |
1748 | 1748 | if (env == '') { |
1749 | - env = "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" + "<?php _e( 'Placeholder for: ' );?>" + props.name + "</div>"; |
|
1749 | + env = "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" + "<?php _e('Placeholder for: '); ?>" + props.name + "</div>"; |
|
1750 | 1750 | } |
1751 | 1751 | |
1752 | 1752 | props.setAttributes({content: env}); |
@@ -1765,7 +1765,7 @@ discard block |
||
1765 | 1765 | |
1766 | 1766 | el(wp.editor.BlockControls, {key: 'controls'}, |
1767 | 1767 | |
1768 | - <?php if($show_alignment){?> |
|
1768 | + <?php if ($show_alignment) {?> |
|
1769 | 1769 | el( |
1770 | 1770 | wp.editor.AlignmentToolbar, |
1771 | 1771 | { |
@@ -1783,9 +1783,9 @@ discard block |
||
1783 | 1783 | |
1784 | 1784 | <?php |
1785 | 1785 | |
1786 | - if(! empty( $this->arguments )){ |
|
1786 | + if (!empty($this->arguments)) { |
|
1787 | 1787 | |
1788 | - if ( $show_advanced ) { |
|
1788 | + if ($show_advanced) { |
|
1789 | 1789 | ?> |
1790 | 1790 | el( |
1791 | 1791 | wp.components.ToggleControl, |
@@ -1807,17 +1807,17 @@ discard block |
||
1807 | 1807 | $has_sections = $arguments == $this->arguments ? false : true; |
1808 | 1808 | |
1809 | 1809 | |
1810 | - if($has_sections){ |
|
1810 | + if ($has_sections) { |
|
1811 | 1811 | $panel_count = 0; |
1812 | - foreach($arguments as $key => $args){ |
|
1812 | + foreach ($arguments as $key => $args) { |
|
1813 | 1813 | ?> |
1814 | 1814 | el(wp.components.PanelBody, { |
1815 | 1815 | title: '<?php esc_attr_e($key); ?>', |
1816 | - initialOpen: <?php if($panel_count){echo "false";}else{echo "true";}?> |
|
1816 | + initialOpen: <?php if ($panel_count) {echo "false"; } else {echo "true"; }?> |
|
1817 | 1817 | }, |
1818 | 1818 | <?php |
1819 | 1819 | |
1820 | - foreach($args as $k => $a){ |
|
1820 | + foreach ($args as $k => $a) { |
|
1821 | 1821 | $this->build_block_arguments($k, $a); |
1822 | 1822 | } |
1823 | 1823 | ?> |
@@ -1826,8 +1826,8 @@ discard block |
||
1826 | 1826 | $panel_count++; |
1827 | 1827 | |
1828 | 1828 | } |
1829 | - }else{ |
|
1830 | - foreach($this->arguments as $key => $args){ |
|
1829 | + } else { |
|
1830 | + foreach ($this->arguments as $key => $args) { |
|
1831 | 1831 | $this->build_block_arguments($key, $args); |
1832 | 1832 | } |
1833 | 1833 | } |
@@ -1841,9 +1841,9 @@ discard block |
||
1841 | 1841 | |
1842 | 1842 | <?php |
1843 | 1843 | // If the user sets block-output array then build it |
1844 | - if ( ! empty( $this->options['block-output'] ) ) { |
|
1845 | - $this->block_element( $this->options['block-output'] ); |
|
1846 | - }else{ |
|
1844 | + if (!empty($this->options['block-output'])) { |
|
1845 | + $this->block_element($this->options['block-output']); |
|
1846 | + } else { |
|
1847 | 1847 | // if no block-output is set then we try and get the shortcode html output via ajax. |
1848 | 1848 | ?> |
1849 | 1849 | el('div', { |
@@ -1867,14 +1867,14 @@ discard block |
||
1867 | 1867 | var align = ''; |
1868 | 1868 | |
1869 | 1869 | // build the shortcode. |
1870 | - var content = "[<?php echo $this->options['base_id'];?>"; |
|
1870 | + var content = "[<?php echo $this->options['base_id']; ?>"; |
|
1871 | 1871 | <?php |
1872 | 1872 | |
1873 | - if(! empty( $this->arguments )){ |
|
1874 | - foreach($this->arguments as $key => $args){ |
|
1873 | + if (!empty($this->arguments)) { |
|
1874 | + foreach ($this->arguments as $key => $args) { |
|
1875 | 1875 | ?> |
1876 | - if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) { |
|
1877 | - content += " <?php echo esc_attr( $key );?>='" + attr.<?php echo esc_attr( $key );?>+ "' "; |
|
1876 | + if (attr.hasOwnProperty("<?php echo esc_attr($key); ?>")) { |
|
1877 | + content += " <?php echo esc_attr($key); ?>='" + attr.<?php echo esc_attr($key); ?>+ "' "; |
|
1878 | 1878 | } |
1879 | 1879 | <?php |
1880 | 1880 | } |
@@ -1915,82 +1915,82 @@ discard block |
||
1915 | 1915 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
1916 | 1916 | */ |
1917 | 1917 | |
1918 | - return str_replace( array( |
|
1918 | + return str_replace(array( |
|
1919 | 1919 | '<script>', |
1920 | 1920 | '</script>' |
1921 | - ), '', $output ); |
|
1921 | + ), '', $output); |
|
1922 | 1922 | } |
1923 | 1923 | |
1924 | - public function build_block_arguments($key,$args){ |
|
1925 | - $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : ''; |
|
1924 | + public function build_block_arguments($key, $args) { |
|
1925 | + $custom_attributes = !empty($args['custom_attributes']) ? $this->array_to_attributes($args['custom_attributes']) : ''; |
|
1926 | 1926 | $options = ''; |
1927 | 1927 | $extra = ''; |
1928 | 1928 | $require = ''; |
1929 | 1929 | $onchange = "props.setAttributes({ $key: $key } )"; |
1930 | 1930 | $value = "props.attributes.$key"; |
1931 | - $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' ); |
|
1932 | - if ( in_array( $args['type'], $text_type ) ) { |
|
1931 | + $text_type = array('text', 'password', 'number', 'email', 'tel', 'url', 'color'); |
|
1932 | + if (in_array($args['type'], $text_type)) { |
|
1933 | 1933 | $type = 'TextControl'; |
1934 | 1934 | // Save numbers as numbers and not strings |
1935 | - if ( $args['type'] == 'number' ) { |
|
1935 | + if ($args['type'] == 'number') { |
|
1936 | 1936 | $onchange = "props.setAttributes({ $key: Number($key) } )"; |
1937 | 1937 | } |
1938 | 1938 | } |
1939 | 1939 | // elseif ( $args['type'] == 'color' ) { //@todo ColorPicker labels are not shown yet, we use html5 color input for now https://github.com/WordPress/gutenberg/issues/14378 |
1940 | 1940 | // $type = 'ColorPicker'; |
1941 | 1941 | // } |
1942 | - elseif ( $args['type'] == 'checkbox' ) { |
|
1942 | + elseif ($args['type'] == 'checkbox') { |
|
1943 | 1943 | $type = 'CheckboxControl'; |
1944 | 1944 | $extra .= "checked: props.attributes.$key,"; |
1945 | 1945 | $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )"; |
1946 | - } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) { |
|
1946 | + } elseif ($args['type'] == 'select' || $args['type'] == 'multiselect') { |
|
1947 | 1947 | $type = 'SelectControl'; |
1948 | - if ( ! empty( $args['options'] ) ) { |
|
1948 | + if (!empty($args['options'])) { |
|
1949 | 1949 | $options .= "options : ["; |
1950 | - foreach ( $args['options'] as $option_val => $option_label ) { |
|
1951 | - $options .= "{ value : '" . esc_attr( $option_val ) . "', label : '" . esc_attr( $option_label ) . "' },"; |
|
1950 | + foreach ($args['options'] as $option_val => $option_label) { |
|
1951 | + $options .= "{ value : '" . esc_attr($option_val) . "', label : '" . esc_attr($option_label) . "' },"; |
|
1952 | 1952 | } |
1953 | 1953 | $options .= "],"; |
1954 | 1954 | } |
1955 | - if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
1955 | + if (isset($args['multiple']) && $args['multiple']) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
1956 | 1956 | $extra .= ' multiple: true, '; |
1957 | 1957 | //$onchange = "props.setAttributes({ $key: ['edit'] } )"; |
1958 | 1958 | //$value = "['edit', 'delete']"; |
1959 | 1959 | } |
1960 | - } elseif ( $args['type'] == 'alignment' ) { |
|
1960 | + } elseif ($args['type'] == 'alignment') { |
|
1961 | 1961 | $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example |
1962 | 1962 | } else { |
1963 | - return;// if we have not implemented the control then don't break the JS. |
|
1963 | + return; // if we have not implemented the control then don't break the JS. |
|
1964 | 1964 | } |
1965 | 1965 | |
1966 | 1966 | // add show only if advanced |
1967 | - if ( ! empty( $args['advanced'] ) ) { |
|
1967 | + if (!empty($args['advanced'])) { |
|
1968 | 1968 | echo "props.attributes.show_advanced && "; |
1969 | 1969 | } |
1970 | 1970 | // add setting require if defined |
1971 | - if ( ! empty( $args['element_require'] ) ) { |
|
1972 | - echo $this->block_props_replace( $args['element_require'], true ) . " && "; |
|
1971 | + if (!empty($args['element_require'])) { |
|
1972 | + echo $this->block_props_replace($args['element_require'], true) . " && "; |
|
1973 | 1973 | } |
1974 | 1974 | ?> |
1975 | 1975 | el( |
1976 | - wp.components.<?php echo esc_attr( $type );?>, |
|
1976 | + wp.components.<?php echo esc_attr($type); ?>, |
|
1977 | 1977 | { |
1978 | - label: '<?php echo esc_attr( $args['title'] );?>', |
|
1979 | - help: '<?php if ( isset( $args['desc'] ) ) { |
|
1980 | - echo esc_attr( $args['desc'] ); |
|
1978 | + label: '<?php echo esc_attr($args['title']); ?>', |
|
1979 | + help: '<?php if (isset($args['desc'])) { |
|
1980 | + echo esc_attr($args['desc']); |
|
1981 | 1981 | }?>', |
1982 | - value: <?php echo $value;?>, |
|
1983 | - <?php if ( $type == 'TextControl' && $args['type'] != 'text' ) { |
|
1984 | - echo "type: '" . esc_attr( $args['type'] ) . "',"; |
|
1982 | + value: <?php echo $value; ?>, |
|
1983 | + <?php if ($type == 'TextControl' && $args['type'] != 'text') { |
|
1984 | + echo "type: '" . esc_attr($args['type']) . "',"; |
|
1985 | 1985 | }?> |
1986 | - <?php if ( ! empty( $args['placeholder'] ) ) { |
|
1987 | - echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',"; |
|
1986 | + <?php if (!empty($args['placeholder'])) { |
|
1987 | + echo "placeholder: '" . esc_attr($args['placeholder']) . "',"; |
|
1988 | 1988 | }?> |
1989 | - <?php echo $options;?> |
|
1990 | - <?php echo $extra;?> |
|
1991 | - <?php echo $custom_attributes;?> |
|
1992 | - onChange: function ( <?php echo $key;?> ) { |
|
1993 | - <?php echo $onchange;?> |
|
1989 | + <?php echo $options; ?> |
|
1990 | + <?php echo $extra; ?> |
|
1991 | + <?php echo $custom_attributes; ?> |
|
1992 | + onChange: function ( <?php echo $key; ?> ) { |
|
1993 | + <?php echo $onchange; ?> |
|
1994 | 1994 | } |
1995 | 1995 | } |
1996 | 1996 | ), |
@@ -2006,16 +2006,16 @@ discard block |
||
2006 | 2006 | * |
2007 | 2007 | * @return string |
2008 | 2008 | */ |
2009 | - public function array_to_attributes( $custom_attributes, $html = false ) { |
|
2009 | + public function array_to_attributes($custom_attributes, $html = false) { |
|
2010 | 2010 | $attributes = ''; |
2011 | - if ( ! empty( $custom_attributes ) ) { |
|
2011 | + if (!empty($custom_attributes)) { |
|
2012 | 2012 | |
2013 | - if ( $html ) { |
|
2014 | - foreach ( $custom_attributes as $key => $val ) { |
|
2013 | + if ($html) { |
|
2014 | + foreach ($custom_attributes as $key => $val) { |
|
2015 | 2015 | $attributes .= " $key='$val' "; |
2016 | 2016 | } |
2017 | 2017 | } else { |
2018 | - foreach ( $custom_attributes as $key => $val ) { |
|
2018 | + foreach ($custom_attributes as $key => $val) { |
|
2019 | 2019 | $attributes .= "'$key': '$val',"; |
2020 | 2020 | } |
2021 | 2021 | } |
@@ -2031,86 +2031,86 @@ discard block |
||
2031 | 2031 | * |
2032 | 2032 | * @param $args |
2033 | 2033 | */ |
2034 | - public function block_element( $args ) { |
|
2034 | + public function block_element($args) { |
|
2035 | 2035 | |
2036 | 2036 | |
2037 | - if ( ! empty( $args ) ) { |
|
2038 | - foreach ( $args as $element => $new_args ) { |
|
2037 | + if (!empty($args)) { |
|
2038 | + foreach ($args as $element => $new_args) { |
|
2039 | 2039 | |
2040 | - if ( is_array( $new_args ) ) { // its an element |
|
2040 | + if (is_array($new_args)) { // its an element |
|
2041 | 2041 | |
2042 | 2042 | |
2043 | - if ( isset( $new_args['element'] ) ) { |
|
2043 | + if (isset($new_args['element'])) { |
|
2044 | 2044 | |
2045 | - if ( isset( $new_args['element_require'] ) ) { |
|
2046 | - echo str_replace( array( |
|
2045 | + if (isset($new_args['element_require'])) { |
|
2046 | + echo str_replace(array( |
|
2047 | 2047 | "'+", |
2048 | 2048 | "+'" |
2049 | - ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " && "; |
|
2050 | - unset( $new_args['element_require'] ); |
|
2049 | + ), '', $this->block_props_replace($new_args['element_require'])) . " && "; |
|
2050 | + unset($new_args['element_require']); |
|
2051 | 2051 | } |
2052 | 2052 | |
2053 | 2053 | echo "\n el( '" . $new_args['element'] . "', {"; |
2054 | 2054 | |
2055 | 2055 | // get the attributes |
2056 | - foreach ( $new_args as $new_key => $new_value ) { |
|
2056 | + foreach ($new_args as $new_key => $new_value) { |
|
2057 | 2057 | |
2058 | 2058 | |
2059 | - if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) { |
|
2059 | + if ($new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array($new_value)) { |
|
2060 | 2060 | // do nothing |
2061 | 2061 | } else { |
2062 | - echo $this->block_element( array( $new_key => $new_value ) ); |
|
2062 | + echo $this->block_element(array($new_key => $new_value)); |
|
2063 | 2063 | } |
2064 | 2064 | } |
2065 | 2065 | |
2066 | - echo "},";// end attributes |
|
2066 | + echo "},"; // end attributes |
|
2067 | 2067 | |
2068 | 2068 | // get the content |
2069 | 2069 | $first_item = 0; |
2070 | - foreach ( $new_args as $new_key => $new_value ) { |
|
2071 | - if ( $new_key === 'content' || is_array( $new_value ) ) { |
|
2070 | + foreach ($new_args as $new_key => $new_value) { |
|
2071 | + if ($new_key === 'content' || is_array($new_value)) { |
|
2072 | 2072 | |
2073 | - if ( $new_key === 'content' ) { |
|
2074 | - echo "'" . $this->block_props_replace( wp_slash( $new_value ) ) . "'"; |
|
2073 | + if ($new_key === 'content') { |
|
2074 | + echo "'" . $this->block_props_replace(wp_slash($new_value)) . "'"; |
|
2075 | 2075 | } |
2076 | 2076 | |
2077 | - if ( is_array( $new_value ) ) { |
|
2077 | + if (is_array($new_value)) { |
|
2078 | 2078 | |
2079 | - if ( isset( $new_value['element_require'] ) ) { |
|
2080 | - echo str_replace( array( |
|
2079 | + if (isset($new_value['element_require'])) { |
|
2080 | + echo str_replace(array( |
|
2081 | 2081 | "'+", |
2082 | 2082 | "+'" |
2083 | - ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " && "; |
|
2084 | - unset( $new_value['element_require'] ); |
|
2083 | + ), '', $this->block_props_replace($new_value['element_require'])) . " && "; |
|
2084 | + unset($new_value['element_require']); |
|
2085 | 2085 | } |
2086 | 2086 | |
2087 | - if ( isset( $new_value['element_repeat'] ) ) { |
|
2087 | + if (isset($new_value['element_repeat'])) { |
|
2088 | 2088 | $x = 1; |
2089 | - while ( $x <= absint( $new_value['element_repeat'] ) ) { |
|
2090 | - $this->block_element( array( '' => $new_value ) ); |
|
2091 | - $x ++; |
|
2089 | + while ($x <= absint($new_value['element_repeat'])) { |
|
2090 | + $this->block_element(array('' => $new_value)); |
|
2091 | + $x++; |
|
2092 | 2092 | } |
2093 | 2093 | } else { |
2094 | - $this->block_element( array( '' => $new_value ) ); |
|
2094 | + $this->block_element(array('' => $new_value)); |
|
2095 | 2095 | } |
2096 | 2096 | } |
2097 | - $first_item ++; |
|
2097 | + $first_item++; |
|
2098 | 2098 | } |
2099 | 2099 | } |
2100 | 2100 | |
2101 | - echo ")";// end content |
|
2101 | + echo ")"; // end content |
|
2102 | 2102 | |
2103 | 2103 | echo ", \n"; |
2104 | 2104 | |
2105 | 2105 | } |
2106 | 2106 | } else { |
2107 | 2107 | |
2108 | - if ( substr( $element, 0, 3 ) === "if_" ) { |
|
2109 | - echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ","; |
|
2110 | - } elseif ( $element == 'style' ) { |
|
2111 | - echo $element . ": " . $this->block_props_replace( $new_args ) . ","; |
|
2108 | + if (substr($element, 0, 3) === "if_") { |
|
2109 | + echo str_replace("if_", "", $element) . ": " . $this->block_props_replace($new_args, true) . ","; |
|
2110 | + } elseif ($element == 'style') { |
|
2111 | + echo $element . ": " . $this->block_props_replace($new_args) . ","; |
|
2112 | 2112 | } else { |
2113 | - echo $element . ": '" . $this->block_props_replace( $new_args ) . "',"; |
|
2113 | + echo $element . ": '" . $this->block_props_replace($new_args) . "',"; |
|
2114 | 2114 | } |
2115 | 2115 | |
2116 | 2116 | } |
@@ -2125,12 +2125,12 @@ discard block |
||
2125 | 2125 | * |
2126 | 2126 | * @return mixed |
2127 | 2127 | */ |
2128 | - public function block_props_replace( $string, $no_wrap = false ) { |
|
2128 | + public function block_props_replace($string, $no_wrap = false) { |
|
2129 | 2129 | |
2130 | - if ( $no_wrap ) { |
|
2131 | - $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string ); |
|
2130 | + if ($no_wrap) { |
|
2131 | + $string = str_replace(array("[%", "%]"), array("props.attributes.", ""), $string); |
|
2132 | 2132 | } else { |
2133 | - $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string ); |
|
2133 | + $string = str_replace(array("[%", "%]"), array("'+props.attributes.", "+'"), $string); |
|
2134 | 2134 | } |
2135 | 2135 | |
2136 | 2136 | return $string; |
@@ -2142,43 +2142,43 @@ discard block |
||
2142 | 2142 | * @param array $args |
2143 | 2143 | * @param array $instance |
2144 | 2144 | */ |
2145 | - public function widget( $args, $instance ) { |
|
2145 | + public function widget($args, $instance) { |
|
2146 | 2146 | |
2147 | 2147 | // get the filtered values |
2148 | - $argument_values = $this->argument_values( $instance ); |
|
2149 | - $argument_values = $this->string_to_bool( $argument_values ); |
|
2150 | - $output = $this->output( $argument_values, $args ); |
|
2148 | + $argument_values = $this->argument_values($instance); |
|
2149 | + $argument_values = $this->string_to_bool($argument_values); |
|
2150 | + $output = $this->output($argument_values, $args); |
|
2151 | 2151 | |
2152 | 2152 | ob_start(); |
2153 | - if ( $output ) { |
|
2153 | + if ($output) { |
|
2154 | 2154 | // Before widget |
2155 | 2155 | $before_widget = $args['before_widget']; |
2156 | - $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this ); |
|
2157 | - $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this ); |
|
2156 | + $before_widget = apply_filters('wp_super_duper_before_widget', $before_widget, $args, $instance, $this); |
|
2157 | + $before_widget = apply_filters('wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this); |
|
2158 | 2158 | |
2159 | 2159 | // After widget |
2160 | 2160 | $after_widget = $args['after_widget']; |
2161 | - $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this ); |
|
2162 | - $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this ); |
|
2161 | + $after_widget = apply_filters('wp_super_duper_after_widget', $after_widget, $args, $instance, $this); |
|
2162 | + $after_widget = apply_filters('wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this); |
|
2163 | 2163 | |
2164 | 2164 | echo $before_widget; |
2165 | 2165 | // elementor strips the widget wrapping div so we check for and add it back if needed |
2166 | - if ( $this->is_elementor_widget_output() ) { |
|
2167 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : ''; |
|
2166 | + if ($this->is_elementor_widget_output()) { |
|
2167 | + echo !empty($this->options['widget_ops']['classname']) ? "<span class='" . esc_attr($this->options['widget_ops']['classname']) . "'>" : ''; |
|
2168 | 2168 | } |
2169 | - echo $this->output_title( $args, $instance ); |
|
2169 | + echo $this->output_title($args, $instance); |
|
2170 | 2170 | echo $output; |
2171 | - if ( $this->is_elementor_widget_output() ) { |
|
2172 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : ''; |
|
2171 | + if ($this->is_elementor_widget_output()) { |
|
2172 | + echo !empty($this->options['widget_ops']['classname']) ? "</span>" : ''; |
|
2173 | 2173 | } |
2174 | 2174 | echo $after_widget; |
2175 | - } elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty |
|
2176 | - $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" ); |
|
2175 | + } elseif ($this->is_preview() && $output == '') {// if preview show a placeholder if empty |
|
2176 | + $output = $this->preview_placeholder_text("{{" . $this->base_id . "}}"); |
|
2177 | 2177 | echo $output; |
2178 | 2178 | } |
2179 | 2179 | $output = ob_get_clean(); |
2180 | 2180 | |
2181 | - $output = apply_filters( 'wp_super_duper_widget_output', $output, $instance, $args, $this ); |
|
2181 | + $output = apply_filters('wp_super_duper_widget_output', $output, $instance, $args, $this); |
|
2182 | 2182 | |
2183 | 2183 | echo $output; |
2184 | 2184 | } |
@@ -2191,7 +2191,7 @@ discard block |
||
2191 | 2191 | */ |
2192 | 2192 | public function is_elementor_widget_output() { |
2193 | 2193 | $result = false; |
2194 | - if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) { |
|
2194 | + if (defined('ELEMENTOR_VERSION') && isset($this->number) && $this->number == 'REPLACE_TO_ID') { |
|
2195 | 2195 | $result = true; |
2196 | 2196 | } |
2197 | 2197 | |
@@ -2206,7 +2206,7 @@ discard block |
||
2206 | 2206 | */ |
2207 | 2207 | public function is_elementor_preview() { |
2208 | 2208 | $result = false; |
2209 | - if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) { |
|
2209 | + if (isset($_REQUEST['elementor-preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor') || (isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor_ajax')) { |
|
2210 | 2210 | $result = true; |
2211 | 2211 | } |
2212 | 2212 | |
@@ -2221,7 +2221,7 @@ discard block |
||
2221 | 2221 | */ |
2222 | 2222 | public function is_divi_preview() { |
2223 | 2223 | $result = false; |
2224 | - if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) { |
|
2224 | + if (isset($_REQUEST['et_fb']) || isset($_REQUEST['et_pb_preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor')) { |
|
2225 | 2225 | $result = true; |
2226 | 2226 | } |
2227 | 2227 | |
@@ -2236,7 +2236,7 @@ discard block |
||
2236 | 2236 | */ |
2237 | 2237 | public function is_beaver_preview() { |
2238 | 2238 | $result = false; |
2239 | - if ( isset( $_REQUEST['fl_builder'] ) ) { |
|
2239 | + if (isset($_REQUEST['fl_builder'])) { |
|
2240 | 2240 | $result = true; |
2241 | 2241 | } |
2242 | 2242 | |
@@ -2251,7 +2251,7 @@ discard block |
||
2251 | 2251 | */ |
2252 | 2252 | public function is_siteorigin_preview() { |
2253 | 2253 | $result = false; |
2254 | - if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) { |
|
2254 | + if (!empty($_REQUEST['siteorigin_panels_live_editor'])) { |
|
2255 | 2255 | $result = true; |
2256 | 2256 | } |
2257 | 2257 | |
@@ -2266,7 +2266,7 @@ discard block |
||
2266 | 2266 | */ |
2267 | 2267 | public function is_cornerstone_preview() { |
2268 | 2268 | $result = false; |
2269 | - if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) { |
|
2269 | + if (!empty($_REQUEST['cornerstone_preview']) || basename($_SERVER['REQUEST_URI']) == 'cornerstone-endpoint') { |
|
2270 | 2270 | $result = true; |
2271 | 2271 | } |
2272 | 2272 | |
@@ -2281,7 +2281,7 @@ discard block |
||
2281 | 2281 | */ |
2282 | 2282 | public function is_fusion_preview() { |
2283 | 2283 | $result = false; |
2284 | - if ( ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ) ) { |
|
2284 | + if (!empty($_REQUEST['fb-edit']) || !empty($_REQUEST['fusion_load_nonce'])) { |
|
2285 | 2285 | $result = true; |
2286 | 2286 | } |
2287 | 2287 | |
@@ -2296,17 +2296,17 @@ discard block |
||
2296 | 2296 | */ |
2297 | 2297 | public function is_preview() { |
2298 | 2298 | $preview = false; |
2299 | - if ( $this->is_divi_preview() ) { |
|
2299 | + if ($this->is_divi_preview()) { |
|
2300 | 2300 | $preview = true; |
2301 | - } elseif ( $this->is_elementor_preview() ) { |
|
2301 | + } elseif ($this->is_elementor_preview()) { |
|
2302 | 2302 | $preview = true; |
2303 | - } elseif ( $this->is_beaver_preview() ) { |
|
2303 | + } elseif ($this->is_beaver_preview()) { |
|
2304 | 2304 | $preview = true; |
2305 | - } elseif ( $this->is_siteorigin_preview() ) { |
|
2305 | + } elseif ($this->is_siteorigin_preview()) { |
|
2306 | 2306 | $preview = true; |
2307 | - } elseif ( $this->is_cornerstone_preview() ) { |
|
2307 | + } elseif ($this->is_cornerstone_preview()) { |
|
2308 | 2308 | $preview = true; |
2309 | - } elseif ( $this->is_fusion_preview() ) { |
|
2309 | + } elseif ($this->is_fusion_preview()) { |
|
2310 | 2310 | $preview = true; |
2311 | 2311 | } |
2312 | 2312 | |
@@ -2321,11 +2321,11 @@ discard block |
||
2321 | 2321 | * |
2322 | 2322 | * @return string |
2323 | 2323 | */ |
2324 | - public function output_title( $args, $instance = array() ) { |
|
2324 | + public function output_title($args, $instance = array()) { |
|
2325 | 2325 | $output = ''; |
2326 | - if ( ! empty( $instance['title'] ) ) { |
|
2326 | + if (!empty($instance['title'])) { |
|
2327 | 2327 | /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
2328 | - $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
|
2328 | + $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); |
|
2329 | 2329 | $output = $args['before_title'] . $title . $args['after_title']; |
2330 | 2330 | } |
2331 | 2331 | |
@@ -2337,7 +2337,7 @@ discard block |
||
2337 | 2337 | * |
2338 | 2338 | * @param array $instance The widget options. |
2339 | 2339 | */ |
2340 | - public function form( $instance ) { |
|
2340 | + public function form($instance) { |
|
2341 | 2341 | |
2342 | 2342 | // set widget instance |
2343 | 2343 | $this->instance = $instance; |
@@ -2345,10 +2345,10 @@ discard block |
||
2345 | 2345 | // set it as a SD widget |
2346 | 2346 | echo $this->widget_advanced_toggle(); |
2347 | 2347 | |
2348 | - echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>"; |
|
2348 | + echo "<p>" . esc_attr($this->options['widget_ops']['description']) . "</p>"; |
|
2349 | 2349 | $arguments_raw = $this->get_arguments(); |
2350 | 2350 | |
2351 | - if ( is_array( $arguments_raw ) ) { |
|
2351 | + if (is_array($arguments_raw)) { |
|
2352 | 2352 | |
2353 | 2353 | $arguments = $this->group_arguments($arguments_raw); |
2354 | 2354 | |
@@ -2356,9 +2356,9 @@ discard block |
||
2356 | 2356 | $has_sections = $arguments == $arguments_raw ? false : true; |
2357 | 2357 | |
2358 | 2358 | |
2359 | - if($has_sections){ |
|
2359 | + if ($has_sections) { |
|
2360 | 2360 | $panel_count = 0; |
2361 | - foreach($arguments as $key => $args){ |
|
2361 | + foreach ($arguments as $key => $args) { |
|
2362 | 2362 | |
2363 | 2363 | ?> |
2364 | 2364 | <script> |
@@ -2368,10 +2368,10 @@ discard block |
||
2368 | 2368 | |
2369 | 2369 | $hide = $panel_count ? ' style="display:none;" ' : ''; |
2370 | 2370 | $icon_class = $panel_count ? 'fas fa-chevron-up' : 'fas fa-chevron-down'; |
2371 | - echo "<button onclick='jQuery(this).find(\"i\").toggleClass(\"fas fa-chevron-up fas fa-chevron-down\");jQuery(this).next().slideToggle();' type='button' class='sd-toggle-group-button sd-input-group-toggle".sanitize_title_with_dashes($key)."'>".esc_attr($key)." <i style='float:right;' class='".$icon_class."'></i></button>"; |
|
2372 | - echo "<div class='sd-toggle-group sd-input-group-".sanitize_title_with_dashes($key)."' $hide>"; |
|
2371 | + echo "<button onclick='jQuery(this).find(\"i\").toggleClass(\"fas fa-chevron-up fas fa-chevron-down\");jQuery(this).next().slideToggle();' type='button' class='sd-toggle-group-button sd-input-group-toggle" . sanitize_title_with_dashes($key) . "'>" . esc_attr($key) . " <i style='float:right;' class='" . $icon_class . "'></i></button>"; |
|
2372 | + echo "<div class='sd-toggle-group sd-input-group-" . sanitize_title_with_dashes($key) . "' $hide>"; |
|
2373 | 2373 | |
2374 | - foreach($args as $k => $a){ |
|
2374 | + foreach ($args as $k => $a) { |
|
2375 | 2375 | $this->widget_inputs($a, $instance); |
2376 | 2376 | } |
2377 | 2377 | |
@@ -2380,9 +2380,9 @@ discard block |
||
2380 | 2380 | $panel_count++; |
2381 | 2381 | |
2382 | 2382 | } |
2383 | - }else{ |
|
2384 | - foreach ( $arguments as $key => $args ) { |
|
2385 | - $this->widget_inputs( $args, $instance ); |
|
2383 | + } else { |
|
2384 | + foreach ($arguments as $key => $args) { |
|
2385 | + $this->widget_inputs($args, $instance); |
|
2386 | 2386 | } |
2387 | 2387 | } |
2388 | 2388 | |
@@ -2397,7 +2397,7 @@ discard block |
||
2397 | 2397 | public function widget_advanced_toggle() { |
2398 | 2398 | |
2399 | 2399 | $output = ''; |
2400 | - if ( $this->block_show_advanced() ) { |
|
2400 | + if ($this->block_show_advanced()) { |
|
2401 | 2401 | $val = 1; |
2402 | 2402 | } else { |
2403 | 2403 | $val = 0; |
@@ -2417,14 +2417,14 @@ discard block |
||
2417 | 2417 | * |
2418 | 2418 | * @return string $output |
2419 | 2419 | */ |
2420 | - public function convert_element_require( $input ) { |
|
2420 | + public function convert_element_require($input) { |
|
2421 | 2421 | |
2422 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
2422 | + $input = str_replace("'", '"', $input); // we only want double quotes |
|
2423 | 2423 | |
2424 | - $output = esc_attr( str_replace( array( "[%", "%]" ), array( |
|
2424 | + $output = esc_attr(str_replace(array("[%", "%]"), array( |
|
2425 | 2425 | "jQuery(form).find('[data-argument=\"", |
2426 | 2426 | "\"]').find('input,select').val()" |
2427 | - ), $input ) ); |
|
2427 | + ), $input)); |
|
2428 | 2428 | |
2429 | 2429 | return $output; |
2430 | 2430 | } |
@@ -2435,54 +2435,54 @@ discard block |
||
2435 | 2435 | * @param $args |
2436 | 2436 | * @param $instance |
2437 | 2437 | */ |
2438 | - public function widget_inputs( $args, $instance ) { |
|
2438 | + public function widget_inputs($args, $instance) { |
|
2439 | 2439 | |
2440 | 2440 | $class = ""; |
2441 | 2441 | $element_require = ""; |
2442 | 2442 | $custom_attributes = ""; |
2443 | 2443 | |
2444 | 2444 | // get value |
2445 | - if ( isset( $instance[ $args['name'] ] ) ) { |
|
2446 | - $value = $instance[ $args['name'] ]; |
|
2447 | - } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) { |
|
2448 | - $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] ); |
|
2445 | + if (isset($instance[$args['name']])) { |
|
2446 | + $value = $instance[$args['name']]; |
|
2447 | + } elseif (!isset($instance[$args['name']]) && !empty($args['default'])) { |
|
2448 | + $value = is_array($args['default']) ? array_map("esc_html", $args['default']) : esc_html($args['default']); |
|
2449 | 2449 | } else { |
2450 | 2450 | $value = ''; |
2451 | 2451 | } |
2452 | 2452 | |
2453 | 2453 | // get placeholder |
2454 | - if ( ! empty( $args['placeholder'] ) ) { |
|
2455 | - $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'"; |
|
2454 | + if (!empty($args['placeholder'])) { |
|
2455 | + $placeholder = "placeholder='" . esc_html($args['placeholder']) . "'"; |
|
2456 | 2456 | } else { |
2457 | 2457 | $placeholder = ''; |
2458 | 2458 | } |
2459 | 2459 | |
2460 | 2460 | // get if advanced |
2461 | - if ( isset( $args['advanced'] ) && $args['advanced'] ) { |
|
2461 | + if (isset($args['advanced']) && $args['advanced']) { |
|
2462 | 2462 | $class .= " sd-advanced-setting "; |
2463 | 2463 | } |
2464 | 2464 | |
2465 | 2465 | // element_require |
2466 | - if ( isset( $args['element_require'] ) && $args['element_require'] ) { |
|
2466 | + if (isset($args['element_require']) && $args['element_require']) { |
|
2467 | 2467 | $element_require = $args['element_require']; |
2468 | 2468 | } |
2469 | 2469 | |
2470 | 2470 | // custom_attributes |
2471 | - if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) { |
|
2472 | - $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true ); |
|
2471 | + if (isset($args['custom_attributes']) && $args['custom_attributes']) { |
|
2472 | + $custom_attributes = $this->array_to_attributes($args['custom_attributes'], true); |
|
2473 | 2473 | } |
2474 | 2474 | |
2475 | 2475 | // before wrapper |
2476 | 2476 | ?> |
2477 | - <p class="sd-argument <?php echo esc_attr( $class ); ?>" |
|
2478 | - data-argument='<?php echo esc_attr( $args['name'] ); ?>' |
|
2479 | - data-element_require='<?php if ( $element_require ) { |
|
2480 | - echo $this->convert_element_require( $element_require ); |
|
2477 | + <p class="sd-argument <?php echo esc_attr($class); ?>" |
|
2478 | + data-argument='<?php echo esc_attr($args['name']); ?>' |
|
2479 | + data-element_require='<?php if ($element_require) { |
|
2480 | + echo $this->convert_element_require($element_require); |
|
2481 | 2481 | } ?>' |
2482 | 2482 | > |
2483 | 2483 | <?php |
2484 | 2484 | |
2485 | - switch ( $args['type'] ) { |
|
2485 | + switch ($args['type']) { |
|
2486 | 2486 | //array('text','password','number','email','tel','url','color') |
2487 | 2487 | case "text": |
2488 | 2488 | case "password": |
@@ -2493,46 +2493,46 @@ discard block |
||
2493 | 2493 | case "color": |
2494 | 2494 | ?> |
2495 | 2495 | <label |
2496 | - for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
|
2496 | + for="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"><?php echo esc_attr($args['title']); ?><?php echo $this->widget_field_desc($args); ?></label> |
|
2497 | 2497 | <input <?php echo $placeholder; ?> class="widefat" |
2498 | 2498 | <?php echo $custom_attributes; ?> |
2499 | - id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
2500 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" |
|
2501 | - type="<?php echo esc_attr( $args['type'] ); ?>" |
|
2502 | - value="<?php echo esc_attr( $value ); ?>"> |
|
2499 | + id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
2500 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" |
|
2501 | + type="<?php echo esc_attr($args['type']); ?>" |
|
2502 | + value="<?php echo esc_attr($value); ?>"> |
|
2503 | 2503 | <?php |
2504 | 2504 | |
2505 | 2505 | break; |
2506 | 2506 | case "select": |
2507 | - $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false; |
|
2508 | - if ( $multiple ) { |
|
2509 | - if ( empty( $value ) ) { |
|
2507 | + $multiple = isset($args['multiple']) && $args['multiple'] ? true : false; |
|
2508 | + if ($multiple) { |
|
2509 | + if (empty($value)) { |
|
2510 | 2510 | $value = array(); |
2511 | 2511 | } |
2512 | 2512 | } |
2513 | 2513 | ?> |
2514 | 2514 | <label |
2515 | - for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
|
2515 | + for="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"><?php echo esc_attr($args['title']); ?><?php echo $this->widget_field_desc($args); ?></label> |
|
2516 | 2516 | <select <?php echo $placeholder; ?> class="widefat" |
2517 | 2517 | <?php echo $custom_attributes; ?> |
2518 | - id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
2519 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); |
|
2520 | - if ( $multiple ) { |
|
2518 | + id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
2519 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); |
|
2520 | + if ($multiple) { |
|
2521 | 2521 | echo "[]"; |
2522 | 2522 | } ?>" |
2523 | - <?php if ( $multiple ) { |
|
2523 | + <?php if ($multiple) { |
|
2524 | 2524 | echo "multiple"; |
2525 | 2525 | } //@todo not implemented yet due to gutenberg not supporting it |
2526 | 2526 | ?> |
2527 | 2527 | > |
2528 | 2528 | <?php |
2529 | 2529 | |
2530 | - if ( ! empty( $args['options'] ) ) { |
|
2531 | - foreach ( $args['options'] as $val => $label ) { |
|
2532 | - if ( $multiple ) { |
|
2533 | - $selected = in_array( $val, $value ) ? 'selected="selected"' : ''; |
|
2530 | + if (!empty($args['options'])) { |
|
2531 | + foreach ($args['options'] as $val => $label) { |
|
2532 | + if ($multiple) { |
|
2533 | + $selected = in_array($val, $value) ? 'selected="selected"' : ''; |
|
2534 | 2534 | } else { |
2535 | - $selected = selected( $value, $val, false ); |
|
2535 | + $selected = selected($value, $val, false); |
|
2536 | 2536 | } |
2537 | 2537 | echo "<option value='$val' " . $selected . ">$label</option>"; |
2538 | 2538 | } |
@@ -2544,20 +2544,20 @@ discard block |
||
2544 | 2544 | case "checkbox": |
2545 | 2545 | ?> |
2546 | 2546 | <input <?php echo $placeholder; ?> |
2547 | - <?php checked( 1, $value, true ) ?> |
|
2547 | + <?php checked(1, $value, true) ?> |
|
2548 | 2548 | <?php echo $custom_attributes; ?> |
2549 | - class="widefat" id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
2550 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="checkbox" |
|
2549 | + class="widefat" id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
2550 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" type="checkbox" |
|
2551 | 2551 | value="1"> |
2552 | 2552 | <label |
2553 | - for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
|
2553 | + for="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"><?php echo esc_attr($args['title']); ?><?php echo $this->widget_field_desc($args); ?></label> |
|
2554 | 2554 | <?php |
2555 | 2555 | break; |
2556 | 2556 | case "hidden": |
2557 | 2557 | ?> |
2558 | - <input id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
2559 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="hidden" |
|
2560 | - value="<?php echo esc_attr( $value ); ?>"> |
|
2558 | + <input id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
2559 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" type="hidden" |
|
2560 | + value="<?php echo esc_attr($value); ?>"> |
|
2561 | 2561 | <?php |
2562 | 2562 | break; |
2563 | 2563 | default: |
@@ -2579,14 +2579,14 @@ discard block |
||
2579 | 2579 | * @return string |
2580 | 2580 | * @todo, need to make its own tooltip script |
2581 | 2581 | */ |
2582 | - public function widget_field_desc( $args ) { |
|
2582 | + public function widget_field_desc($args) { |
|
2583 | 2583 | |
2584 | 2584 | $description = ''; |
2585 | - if ( isset( $args['desc'] ) && $args['desc'] ) { |
|
2586 | - if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) { |
|
2587 | - $description = $this->desc_tip( $args['desc'] ); |
|
2585 | + if (isset($args['desc']) && $args['desc']) { |
|
2586 | + if (isset($args['desc_tip']) && $args['desc_tip']) { |
|
2587 | + $description = $this->desc_tip($args['desc']); |
|
2588 | 2588 | } else { |
2589 | - $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>'; |
|
2589 | + $description = '<span class="description">' . wp_kses_post($args['desc']) . '</span>'; |
|
2590 | 2590 | } |
2591 | 2591 | } |
2592 | 2592 | |
@@ -2601,11 +2601,11 @@ discard block |
||
2601 | 2601 | * |
2602 | 2602 | * @return string |
2603 | 2603 | */ |
2604 | - function desc_tip( $tip, $allow_html = false ) { |
|
2605 | - if ( $allow_html ) { |
|
2606 | - $tip = $this->sanitize_tooltip( $tip ); |
|
2604 | + function desc_tip($tip, $allow_html = false) { |
|
2605 | + if ($allow_html) { |
|
2606 | + $tip = $this->sanitize_tooltip($tip); |
|
2607 | 2607 | } else { |
2608 | - $tip = esc_attr( $tip ); |
|
2608 | + $tip = esc_attr($tip); |
|
2609 | 2609 | } |
2610 | 2610 | |
2611 | 2611 | return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
@@ -2618,8 +2618,8 @@ discard block |
||
2618 | 2618 | * |
2619 | 2619 | * @return string |
2620 | 2620 | */ |
2621 | - public function sanitize_tooltip( $var ) { |
|
2622 | - return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
2621 | + public function sanitize_tooltip($var) { |
|
2622 | + return htmlspecialchars(wp_kses(html_entity_decode($var), array( |
|
2623 | 2623 | 'br' => array(), |
2624 | 2624 | 'em' => array(), |
2625 | 2625 | 'strong' => array(), |
@@ -2629,7 +2629,7 @@ discard block |
||
2629 | 2629 | 'li' => array(), |
2630 | 2630 | 'ol' => array(), |
2631 | 2631 | 'p' => array(), |
2632 | - ) ) ); |
|
2632 | + ))); |
|
2633 | 2633 | } |
2634 | 2634 | |
2635 | 2635 | /** |
@@ -2641,23 +2641,23 @@ discard block |
||
2641 | 2641 | * @return array |
2642 | 2642 | * @todo we should add some sanitation here. |
2643 | 2643 | */ |
2644 | - public function update( $new_instance, $old_instance ) { |
|
2644 | + public function update($new_instance, $old_instance) { |
|
2645 | 2645 | |
2646 | 2646 | //save the widget |
2647 | - $instance = array_merge( (array) $old_instance, (array) $new_instance ); |
|
2647 | + $instance = array_merge((array) $old_instance, (array) $new_instance); |
|
2648 | 2648 | |
2649 | 2649 | // set widget instance |
2650 | 2650 | $this->instance = $instance; |
2651 | 2651 | |
2652 | - if ( empty( $this->arguments ) ) { |
|
2652 | + if (empty($this->arguments)) { |
|
2653 | 2653 | $this->get_arguments(); |
2654 | 2654 | } |
2655 | 2655 | |
2656 | 2656 | // check for checkboxes |
2657 | - if ( ! empty( $this->arguments ) ) { |
|
2658 | - foreach ( $this->arguments as $argument ) { |
|
2659 | - if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) { |
|
2660 | - $instance[ $argument['name'] ] = '0'; |
|
2657 | + if (!empty($this->arguments)) { |
|
2658 | + foreach ($this->arguments as $argument) { |
|
2659 | + if (isset($argument['type']) && $argument['type'] == 'checkbox' && !isset($new_instance[$argument['name']])) { |
|
2660 | + $instance[$argument['name']] = '0'; |
|
2661 | 2661 | } |
2662 | 2662 | } |
2663 | 2663 | } |
@@ -2675,7 +2675,7 @@ discard block |
||
2675 | 2675 | */ |
2676 | 2676 | public function is_block_content_call() { |
2677 | 2677 | $result = false; |
2678 | - if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) { |
|
2678 | + if (wp_doing_ajax() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'super_duper_output_shortcode') { |
|
2679 | 2679 | $result = true; |
2680 | 2680 | } |
2681 | 2681 |
@@ -12,19 +12,19 @@ |
||
12 | 12 | */ |
13 | 13 | |
14 | 14 | // MUST have WordPress. |
15 | -if ( !defined( 'WPINC' ) ) { |
|
16 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
15 | +if (!defined('WPINC')) { |
|
16 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
17 | 17 | } |
18 | 18 | |
19 | -if ( !defined( 'WPINV_VERSION' ) ) { |
|
20 | - define( 'WPINV_VERSION', '1.0.12' ); |
|
19 | +if (!defined('WPINV_VERSION')) { |
|
20 | + define('WPINV_VERSION', '1.0.12'); |
|
21 | 21 | } |
22 | 22 | |
23 | -if ( !defined( 'WPINV_PLUGIN_FILE' ) ) { |
|
24 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
23 | +if (!defined('WPINV_PLUGIN_FILE')) { |
|
24 | + define('WPINV_PLUGIN_FILE', __FILE__); |
|
25 | 25 | } |
26 | 26 | |
27 | -require plugin_dir_path( __FILE__ ) . 'includes/class-wpinv.php'; |
|
27 | +require plugin_dir_path(__FILE__) . 'includes/class-wpinv.php'; |
|
28 | 28 | |
29 | 29 | function wpinv_run() { |
30 | 30 | global $invoicing; |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
10 | +if (!defined('WPINC')) { |
|
11 | 11 | exit; |
12 | 12 | } |
13 | 13 | |
@@ -24,40 +24,40 @@ discard block |
||
24 | 24 | * @param Array $assoc_args Key value arguments stored in associated array format. |
25 | 25 | * @since 1.0.13 |
26 | 26 | */ |
27 | - public function insert_invoice( $args, $assoc_args ) { |
|
27 | + public function insert_invoice($args, $assoc_args) { |
|
28 | 28 | |
29 | 29 | // Fetch invoice data from the args |
30 | - $invoice_data = wp_unslash( $assoc_args ); |
|
30 | + $invoice_data = wp_unslash($assoc_args); |
|
31 | 31 | |
32 | 32 | // Abort if no invoice data is provided |
33 | - if( empty( $invoice_data ) ) { |
|
34 | - return WP_CLI::error( __( 'Invoice data not provided', 'invoicing' ) ); |
|
33 | + if (empty($invoice_data)) { |
|
34 | + return WP_CLI::error(__('Invoice data not provided', 'invoicing')); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | //Cart details |
38 | - if( !empty( $invoice_data['cart_details'] ) ) { |
|
39 | - $invoice_data['cart_details'] = json_decode( $invoice_data['cart_details'], true ); |
|
38 | + if (!empty($invoice_data['cart_details'])) { |
|
39 | + $invoice_data['cart_details'] = json_decode($invoice_data['cart_details'], true); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | //User details |
43 | - if( !empty( $invoice_data['user_info'] ) ) { |
|
44 | - $invoice_data['user_info'] = json_decode( $invoice_data['user_info'], true ); |
|
43 | + if (!empty($invoice_data['user_info'])) { |
|
44 | + $invoice_data['user_info'] = json_decode($invoice_data['user_info'], true); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | //Payment info |
48 | - if( !empty( $invoice_data['payment_details'] ) ) { |
|
49 | - $invoice_data['payment_details'] = json_decode( $invoice_data['payment_details'], true ); |
|
48 | + if (!empty($invoice_data['payment_details'])) { |
|
49 | + $invoice_data['payment_details'] = json_decode($invoice_data['payment_details'], true); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | // Try creating the invoice |
53 | - $invoice = wpinv_insert_invoice( $invoice_data, true ); |
|
53 | + $invoice = wpinv_insert_invoice($invoice_data, true); |
|
54 | 54 | |
55 | - if ( is_wp_error( $invoice ) ) { |
|
56 | - return WP_CLI::error( $invoice->get_error_message() ); |
|
55 | + if (is_wp_error($invoice)) { |
|
56 | + return WP_CLI::error($invoice->get_error_message()); |
|
57 | 57 | } |
58 | 58 | |
59 | - $message = sprintf( __( 'Invoice %s created', 'invoicing' ), $invoice->ID ); |
|
60 | - WP_CLI::success( $message ); |
|
59 | + $message = sprintf(__('Invoice %s created', 'invoicing'), $invoice->ID); |
|
60 | + WP_CLI::success($message); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 |
@@ -46,25 +46,25 @@ |
||
46 | 46 | parent::__construct( $options ); |
47 | 47 | } |
48 | 48 | |
49 | - /** |
|
50 | - * The Super block output function. |
|
51 | - * |
|
52 | - * @param array $args |
|
53 | - * @param array $widget_args |
|
54 | - * @param string $content |
|
55 | - * |
|
56 | - * @return mixed|string|bool |
|
57 | - */ |
|
49 | + /** |
|
50 | + * The Super block output function. |
|
51 | + * |
|
52 | + * @param array $args |
|
53 | + * @param array $widget_args |
|
54 | + * @param string $content |
|
55 | + * |
|
56 | + * @return mixed|string|bool |
|
57 | + */ |
|
58 | 58 | public function output( $args = array(), $widget_args = array(), $content = '' ) { |
59 | 59 | |
60 | - ob_start(); |
|
60 | + ob_start(); |
|
61 | 61 | |
62 | - do_action( 'wpinv_before_user_invoice_history' ); |
|
63 | - wpinv_get_template_part( 'wpinv-invoice-history' ); |
|
64 | - do_action( 'wpinv_after_user_invoice_history' ); |
|
62 | + do_action( 'wpinv_before_user_invoice_history' ); |
|
63 | + wpinv_get_template_part( 'wpinv-invoice-history' ); |
|
64 | + do_action( 'wpinv_after_user_invoice_history' ); |
|
65 | 65 | |
66 | - $output = ob_get_clean(); |
|
67 | - return trim($output); |
|
66 | + $output = ob_get_clean(); |
|
67 | + return trim($output); |
|
68 | 68 | |
69 | 69 | } |
70 | 70 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -24,15 +24,15 @@ discard block |
||
24 | 24 | 'block-keywords'=> "['invoicing','history']", |
25 | 25 | 'class_name' => __CLASS__, |
26 | 26 | 'base_id' => 'wpinv_history', |
27 | - 'name' => __('Invoicing > Invoice History','invoicing'), |
|
27 | + 'name' => __('Invoicing > Invoice History', 'invoicing'), |
|
28 | 28 | 'widget_ops' => array( |
29 | 29 | 'classname' => 'wpinv-history-class', |
30 | - 'description' => esc_html__('Displays invoice history.','invoicing'), |
|
30 | + 'description' => esc_html__('Displays invoice history.', 'invoicing'), |
|
31 | 31 | ), |
32 | 32 | 'arguments' => array( |
33 | 33 | 'title' => array( |
34 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
35 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
34 | + 'title' => __('Widget title', 'invoicing'), |
|
35 | + 'desc' => __('Enter widget title.', 'invoicing'), |
|
36 | 36 | 'type' => 'text', |
37 | 37 | 'desc_tip' => true, |
38 | 38 | 'default' => '', |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | ); |
44 | 44 | |
45 | 45 | |
46 | - parent::__construct( $options ); |
|
46 | + parent::__construct($options); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -55,13 +55,13 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @return mixed|string|bool |
57 | 57 | */ |
58 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
58 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
59 | 59 | |
60 | 60 | ob_start(); |
61 | 61 | |
62 | - do_action( 'wpinv_before_user_invoice_history' ); |
|
63 | - wpinv_get_template_part( 'wpinv-invoice-history' ); |
|
64 | - do_action( 'wpinv_after_user_invoice_history' ); |
|
62 | + do_action('wpinv_before_user_invoice_history'); |
|
63 | + wpinv_get_template_part('wpinv-invoice-history'); |
|
64 | + do_action('wpinv_after_user_invoice_history'); |
|
65 | 65 | |
66 | 66 | $output = ob_get_clean(); |
67 | 67 | return trim($output); |
@@ -44,22 +44,22 @@ |
||
44 | 44 | parent::__construct( $options ); |
45 | 45 | } |
46 | 46 | |
47 | - /** |
|
48 | - * The Super block output function. |
|
49 | - * |
|
50 | - * @param array $args |
|
51 | - * @param array $widget_args |
|
52 | - * @param string $content |
|
53 | - * |
|
54 | - * @return mixed|string|bool |
|
55 | - */ |
|
47 | + /** |
|
48 | + * The Super block output function. |
|
49 | + * |
|
50 | + * @param array $args |
|
51 | + * @param array $widget_args |
|
52 | + * @param string $content |
|
53 | + * |
|
54 | + * @return mixed|string|bool |
|
55 | + */ |
|
56 | 56 | public function output( $args = array(), $widget_args = array(), $content = '' ) { |
57 | 57 | |
58 | - ob_start(); |
|
58 | + ob_start(); |
|
59 | 59 | |
60 | - wpinv_print_errors(); |
|
60 | + wpinv_print_errors(); |
|
61 | 61 | |
62 | - return '<div class="wpinv">' . ob_get_clean() . '</div>'; |
|
62 | + return '<div class="wpinv">' . ob_get_clean() . '</div>'; |
|
63 | 63 | |
64 | 64 | } |
65 | 65 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -22,15 +22,15 @@ discard block |
||
22 | 22 | 'block-keywords'=> "['invoicing','history']", |
23 | 23 | 'class_name' => __CLASS__, |
24 | 24 | 'base_id' => 'wpinv_messages', |
25 | - 'name' => __('Invoicing > Invoice Messages','invoicing'), |
|
25 | + 'name' => __('Invoicing > Invoice Messages', 'invoicing'), |
|
26 | 26 | 'widget_ops' => array( |
27 | 27 | 'classname' => 'wpinv-messages-class', |
28 | - 'description' => esc_html__('Displays invoice error and warning messages on checkout page.','invoicing'), |
|
28 | + 'description' => esc_html__('Displays invoice error and warning messages on checkout page.', 'invoicing'), |
|
29 | 29 | ), |
30 | 30 | 'arguments' => array( |
31 | 31 | 'title' => array( |
32 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
33 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
32 | + 'title' => __('Widget title', 'invoicing'), |
|
33 | + 'desc' => __('Enter widget title.', 'invoicing'), |
|
34 | 34 | 'type' => 'text', |
35 | 35 | 'desc_tip' => true, |
36 | 36 | 'default' => '', |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | ); |
42 | 42 | |
43 | 43 | |
44 | - parent::__construct( $options ); |
|
44 | + parent::__construct($options); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @return mixed|string|bool |
55 | 55 | */ |
56 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
56 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
57 | 57 | |
58 | 58 | ob_start(); |
59 | 59 |
@@ -46,18 +46,18 @@ |
||
46 | 46 | parent::__construct( $options ); |
47 | 47 | } |
48 | 48 | |
49 | - /** |
|
50 | - * The Super block output function. |
|
51 | - * |
|
52 | - * @param array $args |
|
53 | - * @param array $widget_args |
|
54 | - * @param string $content |
|
55 | - * |
|
56 | - * @return mixed|string|bool |
|
57 | - */ |
|
49 | + /** |
|
50 | + * The Super block output function. |
|
51 | + * |
|
52 | + * @param array $args |
|
53 | + * @param array $widget_args |
|
54 | + * @param string $content |
|
55 | + * |
|
56 | + * @return mixed|string|bool |
|
57 | + */ |
|
58 | 58 | public function output( $args = array(), $widget_args = array(), $content = '' ) { |
59 | 59 | |
60 | - return wpinv_checkout_form(); |
|
60 | + return wpinv_checkout_form(); |
|
61 | 61 | |
62 | 62 | } |
63 | 63 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -24,15 +24,15 @@ discard block |
||
24 | 24 | 'block-keywords'=> "['invoicing','checkout']", |
25 | 25 | 'class_name' => __CLASS__, |
26 | 26 | 'base_id' => 'wpinv_checkout', |
27 | - 'name' => __('Invoicing > Checkout','invoicing'), |
|
27 | + 'name' => __('Invoicing > Checkout', 'invoicing'), |
|
28 | 28 | 'widget_ops' => array( |
29 | 29 | 'classname' => 'wpinv-checkout-class', |
30 | - 'description' => esc_html__('Displays checkout form.','invoicing'), |
|
30 | + 'description' => esc_html__('Displays checkout form.', 'invoicing'), |
|
31 | 31 | ), |
32 | 32 | 'arguments' => array( |
33 | 33 | 'title' => array( |
34 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
35 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
34 | + 'title' => __('Widget title', 'invoicing'), |
|
35 | + 'desc' => __('Enter widget title.', 'invoicing'), |
|
36 | 36 | 'type' => 'text', |
37 | 37 | 'desc_tip' => true, |
38 | 38 | 'default' => '', |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | ); |
44 | 44 | |
45 | 45 | |
46 | - parent::__construct( $options ); |
|
46 | + parent::__construct($options); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @return mixed|string|bool |
57 | 57 | */ |
58 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
58 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
59 | 59 | |
60 | 60 | return wpinv_checkout_form(); |
61 | 61 |
@@ -46,25 +46,25 @@ |
||
46 | 46 | parent::__construct( $options ); |
47 | 47 | } |
48 | 48 | |
49 | - /** |
|
50 | - * The Super block output function. |
|
51 | - * |
|
52 | - * @param array $args |
|
53 | - * @param array $widget_args |
|
54 | - * @param string $content |
|
55 | - * |
|
56 | - * @return mixed|string|bool |
|
57 | - */ |
|
49 | + /** |
|
50 | + * The Super block output function. |
|
51 | + * |
|
52 | + * @param array $args |
|
53 | + * @param array $widget_args |
|
54 | + * @param string $content |
|
55 | + * |
|
56 | + * @return mixed|string|bool |
|
57 | + */ |
|
58 | 58 | public function output( $args = array(), $widget_args = array(), $content = '' ) { |
59 | 59 | |
60 | - ob_start(); |
|
60 | + ob_start(); |
|
61 | 61 | |
62 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
63 | - wpinv_get_template_part( 'wpinv-subscriptions-history' ); |
|
64 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
62 | + do_action( 'wpinv_before_user_subscriptions' ); |
|
63 | + wpinv_get_template_part( 'wpinv-subscriptions-history' ); |
|
64 | + do_action( 'wpinv_after_user_subscriptions' ); |
|
65 | 65 | |
66 | - $output = ob_get_clean(); |
|
67 | - return trim($output); |
|
66 | + $output = ob_get_clean(); |
|
67 | + return trim($output); |
|
68 | 68 | |
69 | 69 | } |
70 | 70 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -24,15 +24,15 @@ discard block |
||
24 | 24 | 'block-keywords'=> "['invoicing','subscriptions']", |
25 | 25 | 'class_name' => __CLASS__, |
26 | 26 | 'base_id' => 'wpinv_subscriptions', |
27 | - 'name' => __('Invoicing > Subscriptions History','invoicing'), |
|
27 | + 'name' => __('Invoicing > Subscriptions History', 'invoicing'), |
|
28 | 28 | 'widget_ops' => array( |
29 | 29 | 'classname' => 'wpinv-checkout-class', |
30 | - 'description' => esc_html__('Displays subscriptions history.','invoicing'), |
|
30 | + 'description' => esc_html__('Displays subscriptions history.', 'invoicing'), |
|
31 | 31 | ), |
32 | 32 | 'arguments' => array( |
33 | 33 | 'title' => array( |
34 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
35 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
34 | + 'title' => __('Widget title', 'invoicing'), |
|
35 | + 'desc' => __('Enter widget title.', 'invoicing'), |
|
36 | 36 | 'type' => 'text', |
37 | 37 | 'desc_tip' => true, |
38 | 38 | 'default' => '', |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | ); |
44 | 44 | |
45 | 45 | |
46 | - parent::__construct( $options ); |
|
46 | + parent::__construct($options); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -55,13 +55,13 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @return mixed|string|bool |
57 | 57 | */ |
58 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
58 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
59 | 59 | |
60 | 60 | ob_start(); |
61 | 61 | |
62 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
63 | - wpinv_get_template_part( 'wpinv-subscriptions-history' ); |
|
64 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
62 | + do_action('wpinv_before_user_subscriptions'); |
|
63 | + wpinv_get_template_part('wpinv-subscriptions-history'); |
|
64 | + do_action('wpinv_after_user_subscriptions'); |
|
65 | 65 | |
66 | 66 | $output = ob_get_clean(); |
67 | 67 | return trim($output); |