@@ -29,7 +29,7 @@ |
||
29 | 29 | add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high' ); |
30 | 30 | add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' ); |
31 | 31 | |
32 | - remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal'); |
|
32 | + remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal'); |
|
33 | 33 | } |
34 | 34 | add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 ); |
35 | 35 |
@@ -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; |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | case 'status' : |
102 | 102 | $value = $wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' ); |
103 | 103 | $is_viewed = wpinv_is_invoice_viewed( $wpi_invoice->ID ); |
104 | - $gateway_title = wpinv_get_gateway_admin_label( $wpi_invoice->get_gateway() ); |
|
105 | - $offline_gateways = apply_filters('wpinv_offline_payments', array('bank_transfer', 'cheque', 'cod')); |
|
106 | - $is_offline_payment = in_array($wpi_invoice->get_gateway(), $offline_gateways) ? true : false; |
|
104 | + $gateway_title = wpinv_get_gateway_admin_label( $wpi_invoice->get_gateway() ); |
|
105 | + $offline_gateways = apply_filters('wpinv_offline_payments', array('bank_transfer', 'cheque', 'cod')); |
|
106 | + $is_offline_payment = in_array($wpi_invoice->get_gateway(), $offline_gateways) ? true : false; |
|
107 | 107 | |
108 | 108 | if ( 1 == $is_viewed ) { |
109 | 109 | $value .= ' <i class="fa fa-eye" title="'.__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
@@ -174,69 +174,69 @@ discard block |
||
174 | 174 | } |
175 | 175 | |
176 | 176 | function wpinv_admin_messages() { |
177 | - global $wpinv_options, $pagenow, $post; |
|
177 | + global $wpinv_options, $pagenow, $post; |
|
178 | 178 | |
179 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
180 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' ); |
|
181 | - } |
|
179 | + if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
180 | + add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' ); |
|
181 | + } |
|
182 | 182 | |
183 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
184 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' ); |
|
185 | - } |
|
183 | + if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
184 | + add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' ); |
|
185 | + } |
|
186 | 186 | |
187 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
188 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' ); |
|
189 | - } |
|
187 | + if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
188 | + add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' ); |
|
189 | + } |
|
190 | 190 | |
191 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
192 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' ); |
|
193 | - } |
|
191 | + if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
192 | + add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' ); |
|
193 | + } |
|
194 | 194 | |
195 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
196 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' ); |
|
197 | - } |
|
195 | + if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
196 | + add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' ); |
|
197 | + } |
|
198 | 198 | |
199 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
200 | - add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' ); |
|
201 | - } |
|
199 | + if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
200 | + add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' ); |
|
201 | + } |
|
202 | 202 | |
203 | - if ( isset( $_GET['wpinv-message'] ) && 'email_disabled' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
204 | - add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Email notification is disabled. Please check settings.', 'invoicing' ), 'error' ); |
|
205 | - } |
|
203 | + if ( isset( $_GET['wpinv-message'] ) && 'email_disabled' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
204 | + add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Email notification is disabled. Please check settings.', 'invoicing' ), 'error' ); |
|
205 | + } |
|
206 | 206 | |
207 | - if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
208 | - add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' ); |
|
207 | + if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
208 | + add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' ); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
212 | - add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' ); |
|
212 | + add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' ); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
216 | 216 | add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' ); |
217 | 217 | } |
218 | 218 | |
219 | - if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
220 | - add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' ); |
|
221 | - } |
|
219 | + if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
220 | + add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' ); |
|
221 | + } |
|
222 | 222 | |
223 | - if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
224 | - add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' ); |
|
225 | - } |
|
223 | + if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
224 | + add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' ); |
|
225 | + } |
|
226 | 226 | |
227 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
228 | - add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' ); |
|
229 | - } |
|
227 | + if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
228 | + add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' ); |
|
229 | + } |
|
230 | 230 | |
231 | - if ( $pagenow == 'post.php' && !empty( $post->post_type ) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable( $post ) ) { |
|
232 | - $message = apply_filters( 'wpinv_item_non_editable_message', __( 'This item in not editable.', 'invoicing' ), $post->ID ); |
|
231 | + if ( $pagenow == 'post.php' && !empty( $post->post_type ) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable( $post ) ) { |
|
232 | + $message = apply_filters( 'wpinv_item_non_editable_message', __( 'This item in not editable.', 'invoicing' ), $post->ID ); |
|
233 | 233 | |
234 | - if ( !empty( $message ) ) { |
|
235 | - add_settings_error( 'wpinv-notices', 'wpinv-edit-n', $message, 'updated' ); |
|
236 | - } |
|
237 | - } |
|
234 | + if ( !empty( $message ) ) { |
|
235 | + add_settings_error( 'wpinv-notices', 'wpinv-edit-n', $message, 'updated' ); |
|
236 | + } |
|
237 | + } |
|
238 | 238 | |
239 | - settings_errors( 'wpinv-notices' ); |
|
239 | + settings_errors( 'wpinv-notices' ); |
|
240 | 240 | } |
241 | 241 | add_action( 'admin_notices', 'wpinv_admin_messages' ); |
242 | 242 | |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | break; |
327 | 327 | case 'id' : |
328 | 328 | echo $post->ID; |
329 | - echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '"> |
|
329 | + echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '"> |
|
330 | 330 | <div class="price">' . wpinv_get_item_price( $post->ID ) . '</div>'; |
331 | 331 | if ( $wpinv_euvat->allow_vat_rules() ) { |
332 | 332 | echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule( $post->ID ) . '</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 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * |
7 | 7 | */ |
8 | 8 | if ( ! defined( 'ABSPATH' ) ) { |
9 | - exit; |
|
9 | + exit; |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | /** |
@@ -15,71 +15,71 @@ discard block |
||
15 | 15 | class WPInv_Admin_Addons extends Ayecode_Addons { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * Get the extensions page tabs. |
|
20 | - * |
|
21 | - * @return array of tabs. |
|
22 | - */ |
|
23 | - public function get_tabs(){ |
|
24 | - $tabs = array( |
|
25 | - 'addons' => __("Addons", "invoicing"), |
|
18 | + /** |
|
19 | + * Get the extensions page tabs. |
|
20 | + * |
|
21 | + * @return array of tabs. |
|
22 | + */ |
|
23 | + public function get_tabs(){ |
|
24 | + $tabs = array( |
|
25 | + 'addons' => __("Addons", "invoicing"), |
|
26 | 26 | 'gateways' => __("Payment Gateways", "invoicing"), |
27 | 27 | 'recommended_plugins' => __("Recommended plugins", "invoicing"), |
28 | 28 | 'membership' => __("Membership", "invoicing"), |
29 | - ); |
|
30 | - |
|
31 | - return $tabs; |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * Get section content for the addons screen. |
|
36 | - * |
|
37 | - * @param string $section_id |
|
38 | - * |
|
39 | - * @return array |
|
40 | - */ |
|
41 | - public function get_section_data( $section_id ) { |
|
42 | - $section = self::get_tab( $section_id ); |
|
43 | - $api_url = "https://wpinvoicing.com/edd-api/v2/products/"; |
|
44 | - $section_data = new stdClass(); |
|
45 | - |
|
46 | - if($section_id=='recommended_plugins'){ |
|
47 | - $section_data->products = self::get_recommend_wp_plugins_edd_formatted(); |
|
48 | - } |
|
49 | - elseif ( ! empty( $section ) ) { |
|
50 | - if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing |
|
51 | - //if ( 1==1) { |
|
52 | - |
|
53 | - $query_args = array( 'category' => $section_id, 'number' => 100); |
|
54 | - $query_args = apply_filters('wpeu_edd_api_query_args',$query_args,$api_url,$section_id); |
|
55 | - |
|
56 | - $raw_section = wp_safe_remote_get( esc_url_raw( add_query_arg($query_args ,$api_url) ), array( 'user-agent' => 'Invoicing Addons Page','timeout' => 15, ) ); |
|
57 | - |
|
58 | - if ( ! is_wp_error( $raw_section ) ) { |
|
59 | - $section_data = json_decode( wp_remote_retrieve_body( $raw_section ) ); |
|
60 | - |
|
61 | - if ( ! empty( $section_data->products ) ) { |
|
62 | - set_transient( 'wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS ); |
|
63 | - } |
|
64 | - } |
|
65 | - } |
|
66 | - } |
|
67 | - |
|
68 | - $products = isset($section_data->products) ? $section_data->products : ''; |
|
69 | - |
|
70 | - return apply_filters( 'wpi_addons_section_data', $products, $section_id ); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Outputs a button. |
|
75 | - *ccc |
|
76 | - * @param string $url |
|
77 | - * @param string $text |
|
78 | - * @param string $theme |
|
79 | - * @param string $plugin |
|
80 | - */ |
|
81 | - public function output_button( $addon ) { |
|
82 | - $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
29 | + ); |
|
30 | + |
|
31 | + return $tabs; |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * Get section content for the addons screen. |
|
36 | + * |
|
37 | + * @param string $section_id |
|
38 | + * |
|
39 | + * @return array |
|
40 | + */ |
|
41 | + public function get_section_data( $section_id ) { |
|
42 | + $section = self::get_tab( $section_id ); |
|
43 | + $api_url = "https://wpinvoicing.com/edd-api/v2/products/"; |
|
44 | + $section_data = new stdClass(); |
|
45 | + |
|
46 | + if($section_id=='recommended_plugins'){ |
|
47 | + $section_data->products = self::get_recommend_wp_plugins_edd_formatted(); |
|
48 | + } |
|
49 | + elseif ( ! empty( $section ) ) { |
|
50 | + if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing |
|
51 | + //if ( 1==1) { |
|
52 | + |
|
53 | + $query_args = array( 'category' => $section_id, 'number' => 100); |
|
54 | + $query_args = apply_filters('wpeu_edd_api_query_args',$query_args,$api_url,$section_id); |
|
55 | + |
|
56 | + $raw_section = wp_safe_remote_get( esc_url_raw( add_query_arg($query_args ,$api_url) ), array( 'user-agent' => 'Invoicing Addons Page','timeout' => 15, ) ); |
|
57 | + |
|
58 | + if ( ! is_wp_error( $raw_section ) ) { |
|
59 | + $section_data = json_decode( wp_remote_retrieve_body( $raw_section ) ); |
|
60 | + |
|
61 | + if ( ! empty( $section_data->products ) ) { |
|
62 | + set_transient( 'wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS ); |
|
63 | + } |
|
64 | + } |
|
65 | + } |
|
66 | + } |
|
67 | + |
|
68 | + $products = isset($section_data->products) ? $section_data->products : ''; |
|
69 | + |
|
70 | + return apply_filters( 'wpi_addons_section_data', $products, $section_id ); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Outputs a button. |
|
75 | + *ccc |
|
76 | + * @param string $url |
|
77 | + * @param string $text |
|
78 | + * @param string $theme |
|
79 | + * @param string $plugin |
|
80 | + */ |
|
81 | + public function output_button( $addon ) { |
|
82 | + $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
83 | 83 | // $button_text = __('Free','invoicing'); |
84 | 84 | // $licensing = false; |
85 | 85 | // $installed = false; |
@@ -91,123 +91,123 @@ discard block |
||
91 | 91 | // $install_status = 'get'; |
92 | 92 | // $onclick = ''; |
93 | 93 | |
94 | - $wp_org_themes = array('supreme-directory','directory-starter'); |
|
95 | - |
|
96 | - $button_args = array( |
|
97 | - 'type' => ($current_tab == 'addons' || $current_tab =='gateways') ? 'addons' : $current_tab, |
|
98 | - 'id' => isset($addon->info->id) ? absint($addon->info->id) : '', |
|
99 | - 'title' => isset($addon->info->title) ? $addon->info->title : '', |
|
100 | - 'button_text' => __('Free','invoicing'), |
|
101 | - 'price_text' => __('Free','invoicing'), |
|
102 | - 'link' => isset($addon->info->link) ? $addon->info->link : '', // link to product |
|
103 | - 'url' => isset($addon->info->link) ? $addon->info->link : '', // button url |
|
104 | - 'class' => 'button-primary', |
|
105 | - 'install_status' => 'get', |
|
106 | - 'installed' => false, |
|
107 | - 'price' => '', |
|
108 | - 'licensing' => isset($addon->licensing->enabled) && $addon->licensing->enabled ? true : false, |
|
109 | - 'license' => isset($addon->licensing->license) && $addon->licensing->license ? $addon->licensing->license : '', |
|
110 | - 'onclick' => '', |
|
111 | - 'slug' => isset($addon->info->slug) ? $addon->info->slug : '', |
|
112 | - 'active' => false, |
|
113 | - 'file' => '', |
|
114 | - 'update_url' => '', |
|
115 | - ); |
|
116 | - |
|
117 | - if( ($current_tab == 'addons' || $current_tab =='gateways') && isset($addon->info->id) && $addon->info->id){ |
|
118 | - include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
|
119 | - if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
|
120 | - $status = self::install_plugin_install_status($addon); |
|
121 | - $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
|
122 | - if(isset($status['status'])){$button_args['install_status'] = $status['status'];} |
|
123 | - $button_args['update_url'] = "https://wpinvoicing.com"; |
|
124 | - }elseif($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) { |
|
125 | - if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
|
126 | - $button_args['installed'] = self::is_theme_installed($addon); |
|
127 | - if(!in_array($button_args['slug'],$wp_org_themes)){ |
|
128 | - $button_args['update_url'] = "https://wpinvoicing.com"; |
|
129 | - } |
|
130 | - }elseif($current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug){ |
|
131 | - include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
|
132 | - $status = install_plugin_install_status(array("slug"=>$button_args['slug'],"version"=>"")); |
|
133 | - $button_args['install_status'] = isset($status['status']) ? $status['status'] : 'install'; |
|
134 | - $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
|
135 | - } |
|
136 | - |
|
137 | - // set price |
|
138 | - if(isset($addon->pricing) && !empty($addon->pricing)){ |
|
139 | - if(is_object($addon->pricing)){ |
|
140 | - $prices = (Array)$addon->pricing; |
|
141 | - $button_args['price'] = reset($prices); |
|
142 | - }elseif(isset($addon->pricing)){ |
|
143 | - $button_args['price'] = $addon->pricing; |
|
144 | - } |
|
145 | - } |
|
146 | - |
|
147 | - // set price text |
|
148 | - if( $button_args['price'] && $button_args['price'] != '0.00' ){ |
|
149 | - $button_args['price_text'] = sprintf( __('From: $%d', 'invoicing'), $button_args['price']); |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - // set if installed |
|
154 | - if(in_array($button_args['install_status'], array('installed','latest_installed','update_available','newer_installed'))){ |
|
155 | - $button_args['installed'] = true; |
|
156 | - } |
|
94 | + $wp_org_themes = array('supreme-directory','directory-starter'); |
|
95 | + |
|
96 | + $button_args = array( |
|
97 | + 'type' => ($current_tab == 'addons' || $current_tab =='gateways') ? 'addons' : $current_tab, |
|
98 | + 'id' => isset($addon->info->id) ? absint($addon->info->id) : '', |
|
99 | + 'title' => isset($addon->info->title) ? $addon->info->title : '', |
|
100 | + 'button_text' => __('Free','invoicing'), |
|
101 | + 'price_text' => __('Free','invoicing'), |
|
102 | + 'link' => isset($addon->info->link) ? $addon->info->link : '', // link to product |
|
103 | + 'url' => isset($addon->info->link) ? $addon->info->link : '', // button url |
|
104 | + 'class' => 'button-primary', |
|
105 | + 'install_status' => 'get', |
|
106 | + 'installed' => false, |
|
107 | + 'price' => '', |
|
108 | + 'licensing' => isset($addon->licensing->enabled) && $addon->licensing->enabled ? true : false, |
|
109 | + 'license' => isset($addon->licensing->license) && $addon->licensing->license ? $addon->licensing->license : '', |
|
110 | + 'onclick' => '', |
|
111 | + 'slug' => isset($addon->info->slug) ? $addon->info->slug : '', |
|
112 | + 'active' => false, |
|
113 | + 'file' => '', |
|
114 | + 'update_url' => '', |
|
115 | + ); |
|
116 | + |
|
117 | + if( ($current_tab == 'addons' || $current_tab =='gateways') && isset($addon->info->id) && $addon->info->id){ |
|
118 | + include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
|
119 | + if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
|
120 | + $status = self::install_plugin_install_status($addon); |
|
121 | + $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
|
122 | + if(isset($status['status'])){$button_args['install_status'] = $status['status'];} |
|
123 | + $button_args['update_url'] = "https://wpinvoicing.com"; |
|
124 | + }elseif($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) { |
|
125 | + if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
|
126 | + $button_args['installed'] = self::is_theme_installed($addon); |
|
127 | + if(!in_array($button_args['slug'],$wp_org_themes)){ |
|
128 | + $button_args['update_url'] = "https://wpinvoicing.com"; |
|
129 | + } |
|
130 | + }elseif($current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug){ |
|
131 | + include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
|
132 | + $status = install_plugin_install_status(array("slug"=>$button_args['slug'],"version"=>"")); |
|
133 | + $button_args['install_status'] = isset($status['status']) ? $status['status'] : 'install'; |
|
134 | + $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
|
135 | + } |
|
136 | + |
|
137 | + // set price |
|
138 | + if(isset($addon->pricing) && !empty($addon->pricing)){ |
|
139 | + if(is_object($addon->pricing)){ |
|
140 | + $prices = (Array)$addon->pricing; |
|
141 | + $button_args['price'] = reset($prices); |
|
142 | + }elseif(isset($addon->pricing)){ |
|
143 | + $button_args['price'] = $addon->pricing; |
|
144 | + } |
|
145 | + } |
|
146 | + |
|
147 | + // set price text |
|
148 | + if( $button_args['price'] && $button_args['price'] != '0.00' ){ |
|
149 | + $button_args['price_text'] = sprintf( __('From: $%d', 'invoicing'), $button_args['price']); |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + // set if installed |
|
154 | + if(in_array($button_args['install_status'], array('installed','latest_installed','update_available','newer_installed'))){ |
|
155 | + $button_args['installed'] = true; |
|
156 | + } |
|
157 | 157 | |
158 | 158 | // print_r($button_args); |
159 | - // set if active |
|
160 | - if($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')){ |
|
161 | - if($button_args['type'] != 'themes'){ |
|
162 | - $button_args['active'] = is_plugin_active($button_args['file']); |
|
163 | - }else{ |
|
164 | - $button_args['active'] = self::is_theme_active($addon); |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - // set button text and class |
|
169 | - if($button_args['active']){ |
|
170 | - $button_args['button_text'] = __('Active','invoicing'); |
|
171 | - $button_args['class'] = ' button-secondary disabled '; |
|
172 | - }elseif($button_args['installed']){ |
|
173 | - $button_args['button_text'] = __('Activate','invoicing'); |
|
174 | - |
|
175 | - if($button_args['type'] != 'themes'){ |
|
176 | - if ( current_user_can( 'manage_options' ) ) { |
|
177 | - $button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin='.$button_args['file']), 'activate-plugin_' . $button_args['file']); |
|
178 | - }else{ |
|
179 | - $button_args['url'] = '#'; |
|
180 | - } |
|
181 | - }else{ |
|
182 | - if ( current_user_can( 'switch_themes' ) ) { |
|
183 | - $button_args['url'] = self::get_theme_activation_url($addon); |
|
184 | - }else{ |
|
185 | - $button_args['url'] = '#'; |
|
186 | - } |
|
187 | - } |
|
188 | - |
|
189 | - }else{ |
|
190 | - if($button_args['type'] == 'recommended_plugins'){ |
|
191 | - $button_args['button_text'] = __('Install','invoicing'); |
|
192 | - }else{ |
|
193 | - $button_args['button_text'] = __('Get it','invoicing'); |
|
194 | - |
|
195 | - /*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){ |
|
159 | + // set if active |
|
160 | + if($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')){ |
|
161 | + if($button_args['type'] != 'themes'){ |
|
162 | + $button_args['active'] = is_plugin_active($button_args['file']); |
|
163 | + }else{ |
|
164 | + $button_args['active'] = self::is_theme_active($addon); |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + // set button text and class |
|
169 | + if($button_args['active']){ |
|
170 | + $button_args['button_text'] = __('Active','invoicing'); |
|
171 | + $button_args['class'] = ' button-secondary disabled '; |
|
172 | + }elseif($button_args['installed']){ |
|
173 | + $button_args['button_text'] = __('Activate','invoicing'); |
|
174 | + |
|
175 | + if($button_args['type'] != 'themes'){ |
|
176 | + if ( current_user_can( 'manage_options' ) ) { |
|
177 | + $button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin='.$button_args['file']), 'activate-plugin_' . $button_args['file']); |
|
178 | + }else{ |
|
179 | + $button_args['url'] = '#'; |
|
180 | + } |
|
181 | + }else{ |
|
182 | + if ( current_user_can( 'switch_themes' ) ) { |
|
183 | + $button_args['url'] = self::get_theme_activation_url($addon); |
|
184 | + }else{ |
|
185 | + $button_args['url'] = '#'; |
|
186 | + } |
|
187 | + } |
|
188 | + |
|
189 | + }else{ |
|
190 | + if($button_args['type'] == 'recommended_plugins'){ |
|
191 | + $button_args['button_text'] = __('Install','invoicing'); |
|
192 | + }else{ |
|
193 | + $button_args['button_text'] = __('Get it','invoicing'); |
|
194 | + |
|
195 | + /*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){ |
|
196 | 196 | $button_args['button_text'] = __('Install','invoicing'); |
197 | 197 | $button_args['url'] = self::get_theme_install_url($button_args['slug']); |
198 | 198 | $button_args['onclick'] = 'gd_set_button_installing(this);'; |
199 | 199 | }*/ |
200 | 200 | |
201 | - } |
|
202 | - } |
|
201 | + } |
|
202 | + } |
|
203 | 203 | |
204 | 204 | |
205 | - // filter the button arguments |
|
206 | - $button_args = apply_filters('edd_api_button_args',$button_args); |
|
205 | + // filter the button arguments |
|
206 | + $button_args = apply_filters('edd_api_button_args',$button_args); |
|
207 | 207 | // print_r($button_args); |
208 | - // set price text |
|
209 | - if(isset($button_args['price_text'])){ |
|
210 | - ?> |
|
208 | + // set price text |
|
209 | + if(isset($button_args['price_text'])){ |
|
210 | + ?> |
|
211 | 211 | <a |
212 | 212 | target="_blank" |
213 | 213 | class="addons-price-text" |
@@ -215,15 +215,15 @@ discard block |
||
215 | 215 | <?php echo esc_html( $button_args['price_text'] ); ?> |
216 | 216 | </a> |
217 | 217 | <?php |
218 | - } |
|
218 | + } |
|
219 | 219 | |
220 | 220 | |
221 | - $target = ''; |
|
222 | - if ( ! empty( $button_args['url'] ) ) { |
|
223 | - $target = strpos($button_args['url'], get_site_url()) !== false ? '' : ' target="_blank" '; |
|
224 | - } |
|
221 | + $target = ''; |
|
222 | + if ( ! empty( $button_args['url'] ) ) { |
|
223 | + $target = strpos($button_args['url'], get_site_url()) !== false ? '' : ' target="_blank" '; |
|
224 | + } |
|
225 | 225 | |
226 | - ?> |
|
226 | + ?> |
|
227 | 227 | <a |
228 | 228 | data-licence="<?php echo esc_attr($button_args['license']);?>" |
229 | 229 | data-licensing="<?php echo $button_args['licensing'] ? 1 : 0;?>" |
@@ -246,28 +246,28 @@ discard block |
||
246 | 246 | <?php |
247 | 247 | |
248 | 248 | |
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * Handles output of the addons page in admin. |
|
254 | - */ |
|
255 | - public function output() { |
|
256 | - $tabs = self::get_tabs(); |
|
257 | - $sections = self::get_sections(); |
|
258 | - $theme = wp_get_theme(); |
|
259 | - $section_keys = array_keys( $sections ); |
|
260 | - $current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys ); |
|
261 | - $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
262 | - include_once( WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php' ); |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * A list of recommended wp.org plugins. |
|
267 | - * @return array |
|
268 | - */ |
|
269 | - public function get_recommend_wp_plugins(){ |
|
270 | - $plugins = array( |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * Handles output of the addons page in admin. |
|
254 | + */ |
|
255 | + public function output() { |
|
256 | + $tabs = self::get_tabs(); |
|
257 | + $sections = self::get_sections(); |
|
258 | + $theme = wp_get_theme(); |
|
259 | + $section_keys = array_keys( $sections ); |
|
260 | + $current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys ); |
|
261 | + $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
262 | + include_once( WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php' ); |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * A list of recommended wp.org plugins. |
|
267 | + * @return array |
|
268 | + */ |
|
269 | + public function get_recommend_wp_plugins(){ |
|
270 | + $plugins = array( |
|
271 | 271 | 'invoicing-quotes' => array( |
272 | 272 | 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
273 | 273 | 'slug' => 'invoicing-quotes', |
@@ -286,8 +286,8 @@ discard block |
||
286 | 286 | 'name' => 'UsersWP', |
287 | 287 | 'desc' => __('Allow frontend user login and registration as well as have slick profile pages.','invoicing'), |
288 | 288 | ), |
289 | - ); |
|
289 | + ); |
|
290 | 290 | |
291 | - return $plugins; |
|
292 | - } |
|
291 | + return $plugins; |
|
292 | + } |
|
293 | 293 | } |
@@ -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 |
@@ -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 |
@@ -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 |
@@ -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 |