Passed
Push — master ( 345b42...86cae5 )
by Brian
05:49
created
includes/class-wpinv-session-handler.php 2 patches
Indentation   +274 added lines, -274 removed lines patch added patch discarded remove patch
@@ -14,125 +14,125 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class WPInv_Session_Handler extends WPInv_Session {
16 16
 
17
-	/**
18
-	 * Cookie name used for the session.
19
-	 *
20
-	 * @var string cookie name
21
-	 */
22
-	protected $_cookie;
23
-
24
-	/**
25
-	 * Stores session expiry.
26
-	 *
27
-	 * @var int session due to expire timestamp
28
-	 */
29
-	protected $_session_expiring;
30
-
31
-	/**
32
-	 * Stores session due to expire timestamp.
33
-	 *
34
-	 * @var string session expiration timestamp
35
-	 */
36
-	protected $_session_expiration;
37
-
38
-	/**
39
-	 * True when the cookie exists.
40
-	 *
41
-	 * @var bool Based on whether a cookie exists.
42
-	 */
43
-	protected $_has_cookie = false;
44
-
45
-	/**
46
-	 * Table name for session data.
47
-	 *
48
-	 * @var string Custom session table name
49
-	 */
50
-	protected $_table;
51
-
52
-	/**
53
-	 * Constructor for the session class.
54
-	 */
55
-	public function old__construct() {
56
-
57
-	    $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH );
17
+    /**
18
+     * Cookie name used for the session.
19
+     *
20
+     * @var string cookie name
21
+     */
22
+    protected $_cookie;
23
+
24
+    /**
25
+     * Stores session expiry.
26
+     *
27
+     * @var int session due to expire timestamp
28
+     */
29
+    protected $_session_expiring;
30
+
31
+    /**
32
+     * Stores session due to expire timestamp.
33
+     *
34
+     * @var string session expiration timestamp
35
+     */
36
+    protected $_session_expiration;
37
+
38
+    /**
39
+     * True when the cookie exists.
40
+     *
41
+     * @var bool Based on whether a cookie exists.
42
+     */
43
+    protected $_has_cookie = false;
44
+
45
+    /**
46
+     * Table name for session data.
47
+     *
48
+     * @var string Custom session table name
49
+     */
50
+    protected $_table;
51
+
52
+    /**
53
+     * Constructor for the session class.
54
+     */
55
+    public function old__construct() {
56
+
57
+        $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH );
58 58
         add_action( 'init', array( $this, 'init' ), -1 );
59
-		add_action( 'wp_logout', array( $this, 'destroy_session' ) );
60
-		add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 );
61
-		add_action( 'shutdown', array( $this, 'save_data' ), 20 );
62
-
63
-	}
64
-
65
-	/**
66
-	 * Init hooks and session data.
67
-	 *
68
-	 * @since 3.3.0
69
-	 */
70
-	public function init() {
71
-		$this->init_session_cookie();
72
-
73
-		if ( ! is_user_logged_in() ) {
74
-			add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ), 10, 2 );
75
-		}
76
-	}
77
-
78
-	/**
79
-	 * Setup cookie and customer ID.
80
-	 *
81
-	 * @since 3.6.0
82
-	 */
83
-	public function init_session_cookie() {
84
-		$cookie = $this->get_session_cookie();
85
-
86
-		if ( $cookie ) {
87
-			$this->_customer_id        = $cookie[0];
88
-			$this->_session_expiration = $cookie[1];
89
-			$this->_session_expiring   = $cookie[2];
90
-			$this->_has_cookie         = true;
91
-			$this->_data               = $this->get_session_data();
92
-
93
-			// If the user logs in, update session.
94
-			if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) {
95
-				$this->_customer_id = get_current_user_id();
96
-				$this->_dirty       = true;
97
-				$this->save_data();
98
-				$this->set_customer_session_cookie( true );
99
-			}
100
-
101
-			// Update session if its close to expiring.
102
-			if ( time() > $this->_session_expiring ) {
103
-				$this->set_session_expiration();
104
-				$this->update_session_timestamp( $this->_customer_id, $this->_session_expiration );
105
-			}
106
-		} else {
107
-			$this->set_session_expiration();
108
-			$this->_customer_id = $this->generate_customer_id();
109
-			$this->_data        = $this->get_session_data();
110
-		}
111
-	}
112
-
113
-	/**
114
-	 * Sets the session cookie on-demand (usually after adding an item to the cart).
115
-	 *
116
-	 * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set.
117
-	 *
118
-	 * Warning: Cookies will only be set if this is called before the headers are sent.
119
-	 *
120
-	 * @param bool $set Should the session cookie be set.
121
-	 */
122
-	public function set_customer_session_cookie( $set ) {
123
-		if ( $set ) {
124
-			$to_hash           = $this->_customer_id . '|' . $this->_session_expiration;
125
-			$cookie_hash       = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
126
-			$cookie_value      = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash;
127
-			$this->_has_cookie = true;
128
-
129
-			if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) {
130
-				$this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true );
131
-			}
132
-		}
133
-	}
134
-
135
-	public function setcookie( $name, $value, $expire = 0, $secure = false, $httponly = false ) {
59
+        add_action( 'wp_logout', array( $this, 'destroy_session' ) );
60
+        add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 );
61
+        add_action( 'shutdown', array( $this, 'save_data' ), 20 );
62
+
63
+    }
64
+
65
+    /**
66
+     * Init hooks and session data.
67
+     *
68
+     * @since 3.3.0
69
+     */
70
+    public function init() {
71
+        $this->init_session_cookie();
72
+
73
+        if ( ! is_user_logged_in() ) {
74
+            add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ), 10, 2 );
75
+        }
76
+    }
77
+
78
+    /**
79
+     * Setup cookie and customer ID.
80
+     *
81
+     * @since 3.6.0
82
+     */
83
+    public function init_session_cookie() {
84
+        $cookie = $this->get_session_cookie();
85
+
86
+        if ( $cookie ) {
87
+            $this->_customer_id        = $cookie[0];
88
+            $this->_session_expiration = $cookie[1];
89
+            $this->_session_expiring   = $cookie[2];
90
+            $this->_has_cookie         = true;
91
+            $this->_data               = $this->get_session_data();
92
+
93
+            // If the user logs in, update session.
94
+            if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) {
95
+                $this->_customer_id = get_current_user_id();
96
+                $this->_dirty       = true;
97
+                $this->save_data();
98
+                $this->set_customer_session_cookie( true );
99
+            }
100
+
101
+            // Update session if its close to expiring.
102
+            if ( time() > $this->_session_expiring ) {
103
+                $this->set_session_expiration();
104
+                $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration );
105
+            }
106
+        } else {
107
+            $this->set_session_expiration();
108
+            $this->_customer_id = $this->generate_customer_id();
109
+            $this->_data        = $this->get_session_data();
110
+        }
111
+    }
112
+
113
+    /**
114
+     * Sets the session cookie on-demand (usually after adding an item to the cart).
115
+     *
116
+     * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set.
117
+     *
118
+     * Warning: Cookies will only be set if this is called before the headers are sent.
119
+     *
120
+     * @param bool $set Should the session cookie be set.
121
+     */
122
+    public function set_customer_session_cookie( $set ) {
123
+        if ( $set ) {
124
+            $to_hash           = $this->_customer_id . '|' . $this->_session_expiration;
125
+            $cookie_hash       = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
126
+            $cookie_value      = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash;
127
+            $this->_has_cookie = true;
128
+
129
+            if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) {
130
+                $this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true );
131
+            }
132
+        }
133
+    }
134
+
135
+    public function setcookie( $name, $value, $expire = 0, $secure = false, $httponly = false ) {
136 136
         if ( ! headers_sent() ) {
137 137
             setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure ) );
138 138
         } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
@@ -141,86 +141,86 @@  discard block
 block discarded – undo
141 141
         }
142 142
     }
143 143
 
144
-	/**
145
-	 * Should the session cookie be secure?
146
-	 *
147
-	 * @since 3.6.0
148
-	 * @return bool
149
-	 */
150
-	protected function use_secure_cookie() {
144
+    /**
145
+     * Should the session cookie be secure?
146
+     *
147
+     * @since 3.6.0
148
+     * @return bool
149
+     */
150
+    protected function use_secure_cookie() {
151 151
         $is_https = false !== strstr( get_option( 'home' ), 'https:' );
152
-		return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() );
153
-	}
154
-
155
-	/**
156
-	 * Return true if the current user has an active session, i.e. a cookie to retrieve values.
157
-	 *
158
-	 * @return bool
159
-	 */
160
-	public function has_session() {
161
-		return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine.
162
-	}
163
-
164
-	/**
165
-	 * Set session expiration.
166
-	 */
167
-	public function set_session_expiration() {
168
-		$this->_session_expiring   = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours.
169
-		$this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours.
170
-	}
171
-
172
-	/**
173
-	 * Generates session ids.
174
-	 *
175
-	 * @return string
176
-	 */
177
-	public function generate_customer_id() {
178
-		require_once ABSPATH . 'wp-includes/class-phpass.php';
179
-		$hasher      = new PasswordHash( 8, false );
180
-		return md5( $hasher->get_random_bytes( 32 ) );
181
-	}
182
-
183
-	/**
184
-	 * Get the session cookie, if set. Otherwise return false.
185
-	 *
186
-	 * Session cookies without a customer ID are invalid.
187
-	 *
188
-	 * @return bool|array
189
-	 */
190
-	public function get_session_cookie() {
191
-		$cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine.
192
-
193
-		if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) {
194
-			return false;
195
-		}
196
-
197
-		list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value );
198
-
199
-		if ( empty( $customer_id ) ) {
200
-			return false;
201
-		}
202
-
203
-		// Validate hash.
204
-		$to_hash = $customer_id . '|' . $session_expiration;
205
-		$hash    = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
206
-
207
-		if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) {
208
-			return false;
209
-		}
210
-
211
-		return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash );
212
-	}
213
-
214
-	/**
215
-	 * Get session data.
216
-	 *
217
-	 * @return array
218
-	 */
219
-	public function get_session_data() {
220
-		return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array();
221
-	}
222
-
223
-	public function generate_key( $customer_id ) {
152
+        return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() );
153
+    }
154
+
155
+    /**
156
+     * Return true if the current user has an active session, i.e. a cookie to retrieve values.
157
+     *
158
+     * @return bool
159
+     */
160
+    public function has_session() {
161
+        return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine.
162
+    }
163
+
164
+    /**
165
+     * Set session expiration.
166
+     */
167
+    public function set_session_expiration() {
168
+        $this->_session_expiring   = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours.
169
+        $this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours.
170
+    }
171
+
172
+    /**
173
+     * Generates session ids.
174
+     *
175
+     * @return string
176
+     */
177
+    public function generate_customer_id() {
178
+        require_once ABSPATH . 'wp-includes/class-phpass.php';
179
+        $hasher      = new PasswordHash( 8, false );
180
+        return md5( $hasher->get_random_bytes( 32 ) );
181
+    }
182
+
183
+    /**
184
+     * Get the session cookie, if set. Otherwise return false.
185
+     *
186
+     * Session cookies without a customer ID are invalid.
187
+     *
188
+     * @return bool|array
189
+     */
190
+    public function get_session_cookie() {
191
+        $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine.
192
+
193
+        if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) {
194
+            return false;
195
+        }
196
+
197
+        list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value );
198
+
199
+        if ( empty( $customer_id ) ) {
200
+            return false;
201
+        }
202
+
203
+        // Validate hash.
204
+        $to_hash = $customer_id . '|' . $session_expiration;
205
+        $hash    = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
206
+
207
+        if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) {
208
+            return false;
209
+        }
210
+
211
+        return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash );
212
+    }
213
+
214
+    /**
215
+     * Get session data.
216
+     *
217
+     * @return array
218
+     */
219
+    public function get_session_data() {
220
+        return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array();
221
+    }
222
+
223
+    public function generate_key( $customer_id ) {
224 224
         if ( ! $customer_id ) {
225 225
             return;
226 226
         }
@@ -228,68 +228,68 @@  discard block
 block discarded – undo
228 228
         return 'wpi_trans_' . $customer_id;
229 229
     }
230 230
 
231
-	/**
232
-	 * Save data.
233
-	 */
234
-	public function save_data() {
235
-		// Dirty if something changed - prevents saving nothing new.
236
-		if ( $this->_dirty && $this->has_session() ) {
231
+    /**
232
+     * Save data.
233
+     */
234
+    public function save_data() {
235
+        // Dirty if something changed - prevents saving nothing new.
236
+        if ( $this->_dirty && $this->has_session() ) {
237 237
 
238 238
             set_transient( $this->generate_key( $this->_customer_id ), $this->_data, $this->_session_expiration );
239 239
 
240
-			$this->_dirty = false;
241
-		}
242
-	}
243
-
244
-	/**
245
-	 * Destroy all session data.
246
-	 */
247
-	public function destroy_session() {
248
-		$this->delete_session( $this->_customer_id );
249
-		$this->forget_session();
250
-	}
251
-
252
-	/**
253
-	 * Forget all session data without destroying it.
254
-	 */
255
-	public function forget_session() {
256
-		$this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true );
257
-
258
-		wpinv_empty_cart();
259
-
260
-		$this->_data        = array();
261
-		$this->_dirty       = false;
262
-		$this->_customer_id = $this->generate_customer_id();
263
-	}
264
-
265
-	/**
266
-	 * When a user is logged out, ensure they have a unique nonce by using the customer/session ID.
267
-	 *
268
-	 * @param int $uid User ID.
269
-	 * @return string
270
-	 */
271
-	public function nonce_user_logged_out( $uid ) {
272
-
273
-		// Check if one of our nonces.
274
-		if ( substr( $uid, 0, 5 ) === 'wpinv' || substr( $uid, 0, 7 ) === 'getpaid' ) {
275
-			return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid;
276
-		}
277
-
278
-		return $uid;
279
-	}
280
-
281
-	/**
282
-	 * Returns the session.
283
-	 *
284
-	 * @param string $customer_id Customer ID.
285
-	 * @param mixed  $default Default session value.
286
-	 * @return string|array
287
-	 */
288
-	public function get_session( $customer_id, $default = false ) {
289
-
290
-		if ( defined( 'WP_SETUP_CONFIG' ) ) {
291
-			return array();
292
-		}
240
+            $this->_dirty = false;
241
+        }
242
+    }
243
+
244
+    /**
245
+     * Destroy all session data.
246
+     */
247
+    public function destroy_session() {
248
+        $this->delete_session( $this->_customer_id );
249
+        $this->forget_session();
250
+    }
251
+
252
+    /**
253
+     * Forget all session data without destroying it.
254
+     */
255
+    public function forget_session() {
256
+        $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true );
257
+
258
+        wpinv_empty_cart();
259
+
260
+        $this->_data        = array();
261
+        $this->_dirty       = false;
262
+        $this->_customer_id = $this->generate_customer_id();
263
+    }
264
+
265
+    /**
266
+     * When a user is logged out, ensure they have a unique nonce by using the customer/session ID.
267
+     *
268
+     * @param int $uid User ID.
269
+     * @return string
270
+     */
271
+    public function nonce_user_logged_out( $uid ) {
272
+
273
+        // Check if one of our nonces.
274
+        if ( substr( $uid, 0, 5 ) === 'wpinv' || substr( $uid, 0, 7 ) === 'getpaid' ) {
275
+            return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid;
276
+        }
277
+
278
+        return $uid;
279
+    }
280
+
281
+    /**
282
+     * Returns the session.
283
+     *
284
+     * @param string $customer_id Customer ID.
285
+     * @param mixed  $default Default session value.
286
+     * @return string|array
287
+     */
288
+    public function get_session( $customer_id, $default = false ) {
289
+
290
+        if ( defined( 'WP_SETUP_CONFIG' ) ) {
291
+            return array();
292
+        }
293 293
 
294 294
         $key = $this->generate_key( $customer_id );
295 295
         $value = get_transient( $key );
@@ -298,30 +298,30 @@  discard block
 block discarded – undo
298 298
             $value = $default;
299 299
         }
300 300
 
301
-		return maybe_unserialize( $value );
302
-	}
301
+        return maybe_unserialize( $value );
302
+    }
303 303
 
304
-	/**
305
-	 * Delete the session from the cache and database.
306
-	 *
307
-	 * @param int $customer_id Customer ID.
308
-	 */
309
-	public function delete_session( $customer_id ) {
304
+    /**
305
+     * Delete the session from the cache and database.
306
+     *
307
+     * @param int $customer_id Customer ID.
308
+     */
309
+    public function delete_session( $customer_id ) {
310 310
 
311 311
         $key = $this->generate_key( $customer_id );
312 312
 
313
-		delete_transient( $key );
314
-	}
313
+        delete_transient( $key );
314
+    }
315 315
 
316
-	/**
317
-	 * Update the session expiry timestamp.
318
-	 *
319
-	 * @param string $customer_id Customer ID.
320
-	 * @param int    $timestamp Timestamp to expire the cookie.
321
-	 */
322
-	public function update_session_timestamp( $customer_id, $timestamp ) {
316
+    /**
317
+     * Update the session expiry timestamp.
318
+     *
319
+     * @param string $customer_id Customer ID.
320
+     * @param int    $timestamp Timestamp to expire the cookie.
321
+     */
322
+    public function update_session_timestamp( $customer_id, $timestamp ) {
323 323
 
324 324
         set_transient( $this->generate_key( $customer_id ), maybe_serialize( $this->_data ), $timestamp );
325 325
 
326
-	}
326
+    }
327 327
 }
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * Session handler class.
@@ -54,11 +54,11 @@  discard block
 block discarded – undo
54 54
 	 */
55 55
 	public function old__construct() {
56 56
 
57
-	    $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH );
58
-        add_action( 'init', array( $this, 'init' ), -1 );
59
-		add_action( 'wp_logout', array( $this, 'destroy_session' ) );
60
-		add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 );
61
-		add_action( 'shutdown', array( $this, 'save_data' ), 20 );
57
+	    $this->_cookie = apply_filters('wpinv_cookie', 'wpinv_session_' . COOKIEHASH);
58
+        add_action('init', array($this, 'init'), -1);
59
+		add_action('wp_logout', array($this, 'destroy_session'));
60
+		add_action('wp', array($this, 'set_customer_session_cookie'), 10);
61
+		add_action('shutdown', array($this, 'save_data'), 20);
62 62
 
63 63
 	}
64 64
 
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
 	public function init() {
71 71
 		$this->init_session_cookie();
72 72
 
73
-		if ( ! is_user_logged_in() ) {
74
-			add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ), 10, 2 );
73
+		if (!is_user_logged_in()) {
74
+			add_filter('nonce_user_logged_out', array($this, 'nonce_user_logged_out'), 10, 2);
75 75
 		}
76 76
 	}
77 77
 
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	public function init_session_cookie() {
84 84
 		$cookie = $this->get_session_cookie();
85 85
 
86
-		if ( $cookie ) {
86
+		if ($cookie) {
87 87
 			$this->_customer_id        = $cookie[0];
88 88
 			$this->_session_expiration = $cookie[1];
89 89
 			$this->_session_expiring   = $cookie[2];
@@ -91,17 +91,17 @@  discard block
 block discarded – undo
91 91
 			$this->_data               = $this->get_session_data();
92 92
 
93 93
 			// If the user logs in, update session.
94
-			if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) {
94
+			if (is_user_logged_in() && get_current_user_id() != $this->_customer_id) {
95 95
 				$this->_customer_id = get_current_user_id();
96 96
 				$this->_dirty       = true;
97 97
 				$this->save_data();
98
-				$this->set_customer_session_cookie( true );
98
+				$this->set_customer_session_cookie(true);
99 99
 			}
100 100
 
101 101
 			// Update session if its close to expiring.
102
-			if ( time() > $this->_session_expiring ) {
102
+			if (time() > $this->_session_expiring) {
103 103
 				$this->set_session_expiration();
104
-				$this->update_session_timestamp( $this->_customer_id, $this->_session_expiration );
104
+				$this->update_session_timestamp($this->_customer_id, $this->_session_expiration);
105 105
 			}
106 106
 		} else {
107 107
 			$this->set_session_expiration();
@@ -119,25 +119,25 @@  discard block
 block discarded – undo
119 119
 	 *
120 120
 	 * @param bool $set Should the session cookie be set.
121 121
 	 */
122
-	public function set_customer_session_cookie( $set ) {
123
-		if ( $set ) {
122
+	public function set_customer_session_cookie($set) {
123
+		if ($set) {
124 124
 			$to_hash           = $this->_customer_id . '|' . $this->_session_expiration;
125
-			$cookie_hash       = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
125
+			$cookie_hash       = hash_hmac('md5', $to_hash, wp_hash($to_hash));
126 126
 			$cookie_value      = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash;
127 127
 			$this->_has_cookie = true;
128 128
 
129
-			if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) {
130
-				$this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true );
129
+			if (!isset($_COOKIE[$this->_cookie]) || $_COOKIE[$this->_cookie] !== $cookie_value) {
130
+				$this->setcookie($this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true);
131 131
 			}
132 132
 		}
133 133
 	}
134 134
 
135
-	public function setcookie( $name, $value, $expire = 0, $secure = false, $httponly = false ) {
136
-        if ( ! headers_sent() ) {
137
-            setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure ) );
138
-        } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
139
-            headers_sent( $file, $line );
140
-            trigger_error( "{$name} cookie cannot be set - headers already sent by {$file} on line {$line}", E_USER_NOTICE ); // @codingStandardsIgnoreLine
135
+	public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false) {
136
+        if (!headers_sent()) {
137
+            setcookie($name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters('wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure));
138
+        } elseif (defined('WP_DEBUG') && WP_DEBUG) {
139
+            headers_sent($file, $line);
140
+            trigger_error("{$name} cookie cannot be set - headers already sent by {$file} on line {$line}", E_USER_NOTICE); // @codingStandardsIgnoreLine
141 141
         }
142 142
     }
143 143
 
@@ -148,8 +148,8 @@  discard block
 block discarded – undo
148 148
 	 * @return bool
149 149
 	 */
150 150
 	protected function use_secure_cookie() {
151
-        $is_https = false !== strstr( get_option( 'home' ), 'https:' );
152
-		return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() );
151
+        $is_https = false !== strstr(get_option('home'), 'https:');
152
+		return apply_filters('wpinv_session_use_secure_cookie', $is_https && is_ssl());
153 153
 	}
154 154
 
155 155
 	/**
@@ -158,15 +158,15 @@  discard block
 block discarded – undo
158 158
 	 * @return bool
159 159
 	 */
160 160
 	public function has_session() {
161
-		return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine.
161
+		return isset($_COOKIE[$this->_cookie]) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine.
162 162
 	}
163 163
 
164 164
 	/**
165 165
 	 * Set session expiration.
166 166
 	 */
167 167
 	public function set_session_expiration() {
168
-		$this->_session_expiring   = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours.
169
-		$this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours.
168
+		$this->_session_expiring   = time() + intval(apply_filters('wpinv_session_expiring', 60 * 60 * 47)); // 47 Hours.
169
+		$this->_session_expiration = time() + intval(apply_filters('wpinv_session_expiration', 60 * 60 * 48)); // 48 Hours.
170 170
 	}
171 171
 
172 172
 	/**
@@ -176,8 +176,8 @@  discard block
 block discarded – undo
176 176
 	 */
177 177
 	public function generate_customer_id() {
178 178
 		require_once ABSPATH . 'wp-includes/class-phpass.php';
179
-		$hasher      = new PasswordHash( 8, false );
180
-		return md5( $hasher->get_random_bytes( 32 ) );
179
+		$hasher = new PasswordHash(8, false);
180
+		return md5($hasher->get_random_bytes(32));
181 181
 	}
182 182
 
183 183
 	/**
@@ -188,27 +188,27 @@  discard block
 block discarded – undo
188 188
 	 * @return bool|array
189 189
 	 */
190 190
 	public function get_session_cookie() {
191
-		$cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine.
191
+		$cookie_value = isset($_COOKIE[$this->_cookie]) ? wp_unslash($_COOKIE[$this->_cookie]) : false; // @codingStandardsIgnoreLine.
192 192
 
193
-		if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) {
193
+		if (empty($cookie_value) || !is_string($cookie_value)) {
194 194
 			return false;
195 195
 		}
196 196
 
197
-		list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value );
197
+		list($customer_id, $session_expiration, $session_expiring, $cookie_hash) = explode('||', $cookie_value);
198 198
 
199
-		if ( empty( $customer_id ) ) {
199
+		if (empty($customer_id)) {
200 200
 			return false;
201 201
 		}
202 202
 
203 203
 		// Validate hash.
204 204
 		$to_hash = $customer_id . '|' . $session_expiration;
205
-		$hash    = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
205
+		$hash    = hash_hmac('md5', $to_hash, wp_hash($to_hash));
206 206
 
207
-		if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) {
207
+		if (empty($cookie_hash) || !hash_equals($hash, $cookie_hash)) {
208 208
 			return false;
209 209
 		}
210 210
 
211
-		return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash );
211
+		return array($customer_id, $session_expiration, $session_expiring, $cookie_hash);
212 212
 	}
213 213
 
214 214
 	/**
@@ -217,11 +217,11 @@  discard block
 block discarded – undo
217 217
 	 * @return array
218 218
 	 */
219 219
 	public function get_session_data() {
220
-		return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array();
220
+		return $this->has_session() ? (array) $this->get_session($this->_customer_id) : array();
221 221
 	}
222 222
 
223
-	public function generate_key( $customer_id ) {
224
-        if ( ! $customer_id ) {
223
+	public function generate_key($customer_id) {
224
+        if (!$customer_id) {
225 225
             return;
226 226
         }
227 227
 
@@ -233,9 +233,9 @@  discard block
 block discarded – undo
233 233
 	 */
234 234
 	public function save_data() {
235 235
 		// Dirty if something changed - prevents saving nothing new.
236
-		if ( $this->_dirty && $this->has_session() ) {
236
+		if ($this->_dirty && $this->has_session()) {
237 237
 
238
-            set_transient( $this->generate_key( $this->_customer_id ), $this->_data, $this->_session_expiration );
238
+            set_transient($this->generate_key($this->_customer_id), $this->_data, $this->_session_expiration);
239 239
 
240 240
 			$this->_dirty = false;
241 241
 		}
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 	 * Destroy all session data.
246 246
 	 */
247 247
 	public function destroy_session() {
248
-		$this->delete_session( $this->_customer_id );
248
+		$this->delete_session($this->_customer_id);
249 249
 		$this->forget_session();
250 250
 	}
251 251
 
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 	 * Forget all session data without destroying it.
254 254
 	 */
255 255
 	public function forget_session() {
256
-		$this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true );
256
+		$this->setcookie($this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true);
257 257
 
258 258
 		wpinv_empty_cart();
259 259
 
@@ -268,10 +268,10 @@  discard block
 block discarded – undo
268 268
 	 * @param int $uid User ID.
269 269
 	 * @return string
270 270
 	 */
271
-	public function nonce_user_logged_out( $uid ) {
271
+	public function nonce_user_logged_out($uid) {
272 272
 
273 273
 		// Check if one of our nonces.
274
-		if ( substr( $uid, 0, 5 ) === 'wpinv' || substr( $uid, 0, 7 ) === 'getpaid' ) {
274
+		if (substr($uid, 0, 5) === 'wpinv' || substr($uid, 0, 7) === 'getpaid') {
275 275
 			return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid;
276 276
 		}
277 277
 
@@ -285,20 +285,20 @@  discard block
 block discarded – undo
285 285
 	 * @param mixed  $default Default session value.
286 286
 	 * @return string|array
287 287
 	 */
288
-	public function get_session( $customer_id, $default = false ) {
288
+	public function get_session($customer_id, $default = false) {
289 289
 
290
-		if ( defined( 'WP_SETUP_CONFIG' ) ) {
290
+		if (defined('WP_SETUP_CONFIG')) {
291 291
 			return array();
292 292
 		}
293 293
 
294
-        $key = $this->generate_key( $customer_id );
295
-        $value = get_transient( $key );
294
+        $key = $this->generate_key($customer_id);
295
+        $value = get_transient($key);
296 296
 
297
-        if ( ! $value ) {
297
+        if (!$value) {
298 298
             $value = $default;
299 299
         }
300 300
 
301
-		return maybe_unserialize( $value );
301
+		return maybe_unserialize($value);
302 302
 	}
303 303
 
304 304
 	/**
@@ -306,11 +306,11 @@  discard block
 block discarded – undo
306 306
 	 *
307 307
 	 * @param int $customer_id Customer ID.
308 308
 	 */
309
-	public function delete_session( $customer_id ) {
309
+	public function delete_session($customer_id) {
310 310
 
311
-        $key = $this->generate_key( $customer_id );
311
+        $key = $this->generate_key($customer_id);
312 312
 
313
-		delete_transient( $key );
313
+		delete_transient($key);
314 314
 	}
315 315
 
316 316
 	/**
@@ -319,9 +319,9 @@  discard block
 block discarded – undo
319 319
 	 * @param string $customer_id Customer ID.
320 320
 	 * @param int    $timestamp Timestamp to expire the cookie.
321 321
 	 */
322
-	public function update_session_timestamp( $customer_id, $timestamp ) {
322
+	public function update_session_timestamp($customer_id, $timestamp) {
323 323
 
324
-        set_transient( $this->generate_key( $customer_id ), maybe_serialize( $this->_data ), $timestamp );
324
+        set_transient($this->generate_key($customer_id), maybe_serialize($this->_data), $timestamp);
325 325
 
326 326
 	}
327 327
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-metaboxes.php 2 patches
Indentation   +243 added lines, -243 removed lines patch added patch discarded remove patch
@@ -12,280 +12,280 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Metaboxes {
14 14
 
15
-	/**
16
-	 * Only save metaboxes once.
17
-	 *
18
-	 * @var boolean
19
-	 */
20
-	private static $saved_meta_boxes = false;
15
+    /**
16
+     * Only save metaboxes once.
17
+     *
18
+     * @var boolean
19
+     */
20
+    private static $saved_meta_boxes = false;
21 21
 
22 22
     /**
23
-	 * Hook in methods.
24
-	 */
25
-	public static function init() {
23
+     * Hook in methods.
24
+     */
25
+    public static function init() {
26 26
 
27
-		// Register metaboxes.
28
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 50, 2 );
27
+        // Register metaboxes.
28
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 50, 2 );
29 29
 
30
-		// Remove metaboxes.
31
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
30
+        // Remove metaboxes.
31
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
32 32
 
33
-		// Rename metaboxes.
34
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
33
+        // Rename metaboxes.
34
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
35 35
 
36
-		// Save metaboxes.
37
-		add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
-	}
36
+        // Save metaboxes.
37
+        add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
+    }
39 39
 
40
-	/**
41
-	 * Register core metaboxes.
42
-	 */
43
-	public static function add_meta_boxes( $post_type, $post ) {
40
+    /**
41
+     * Register core metaboxes.
42
+     */
43
+    public static function add_meta_boxes( $post_type, $post ) {
44 44
 
45
-		// For invoices.
46
-		self::add_invoice_meta_boxes( $post_type, $post );
45
+        // For invoices.
46
+        self::add_invoice_meta_boxes( $post_type, $post );
47 47
 
48
-		// For payment forms.
49
-		self::add_payment_form_meta_boxes( $post_type, $post );
48
+        // For payment forms.
49
+        self::add_payment_form_meta_boxes( $post_type, $post );
50 50
 
51
-		// For invoice items.
52
-		self::add_item_meta_boxes( $post_type );
51
+        // For invoice items.
52
+        self::add_item_meta_boxes( $post_type );
53 53
 
54
-		// For invoice discounts.
55
-		if ( 'wpi_discount' === $post_type ) {
56
-			add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
57
-		}
54
+        // For invoice discounts.
55
+        if ( 'wpi_discount' === $post_type ) {
56
+            add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
57
+        }
58 58
 
59
-	}
59
+    }
60 60
 
61
-	/**
62
-	 * Register core metaboxes.
63
-	 */
64
-	protected static function add_payment_form_meta_boxes( $post_type, $post ) {
61
+    /**
62
+     * Register core metaboxes.
63
+     */
64
+    protected static function add_payment_form_meta_boxes( $post_type, $post ) {
65 65
 
66
-		// For payment forms.
67
-		if ( 'wpi_payment_form' === $post_type ) {
66
+        // For payment forms.
67
+        if ( 'wpi_payment_form' === $post_type ) {
68 68
 
69
-			// Design payment form.
70
-			add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
69
+            // Design payment form.
70
+            add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
71 71
 
72
-			// Payment form information.
73
-			if ( wpinv_get_default_payment_form() !== $post->ID ) {
74
-				add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
75
-			}
72
+            // Payment form information.
73
+            if ( wpinv_get_default_payment_form() !== $post->ID ) {
74
+                add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
75
+            }
76 76
 }
77 77
 
78
-	}
79
-
80
-	/**
81
-	 * Register core metaboxes.
82
-	 */
83
-	protected static function add_item_meta_boxes( $post_type ) {
78
+    }
84 79
 
85
-		if ( 'wpi_item' === $post_type ) {
86
-
87
-			// Item details.
88
-			add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
89
-
90
-			// If taxes are enabled, register the tax metabox.
91
-			if ( wpinv_use_taxes() ) {
92
-				add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
93
-			}
80
+    /**
81
+     * Register core metaboxes.
82
+     */
83
+    protected static function add_item_meta_boxes( $post_type ) {
94 84
 
95
-			// Item info.
96
-			add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
85
+        if ( 'wpi_item' === $post_type ) {
97 86
 
98
-			// Item description.
99
-			add_meta_box( 'postexcerpt', __( 'Item Description', 'invoicing' ), 'GetPaid_Meta_Box_Description::output', 'wpi_item', 'normal' );
100
-		}
87
+            // Item details.
88
+            add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
101 89
 
102
-	}
90
+            // If taxes are enabled, register the tax metabox.
91
+            if ( wpinv_use_taxes() ) {
92
+                add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
93
+            }
103 94
 
104
-	/**
105
-	 * Register invoice metaboxes.
106
-	 */
107
-	protected static function add_invoice_meta_boxes( $post_type, $post ) {
95
+            // Item info.
96
+            add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
108 97
 
109
-		// For invoices...
110
-		if ( getpaid_is_invoice_post_type( $post_type ) ) {
111
-			$invoice = new WPInv_Invoice( $post );
98
+            // Item description.
99
+            add_meta_box( 'postexcerpt', __( 'Item Description', 'invoicing' ), 'GetPaid_Meta_Box_Description::output', 'wpi_item', 'normal' );
100
+        }
112 101
 
113
-			// Resend invoice.
114
-			if ( ! $invoice->is_draft() ) {
102
+    }
115 103
 
116
-				add_meta_box(
117
-					'wpinv-mb-resend-invoice',
118
-					sprintf(
119
-						// translators: %s is the invoice type.
120
-						__( 'Resend %s', 'invoicing' ),
121
-						ucfirst( $invoice->get_invoice_quote_type() )
122
-					),
123
-					'GetPaid_Meta_Box_Resend_Invoice::output',
124
-					$post_type,
125
-					'side',
126
-					'low'
127
-				);
104
+    /**
105
+     * Register invoice metaboxes.
106
+     */
107
+    protected static function add_invoice_meta_boxes( $post_type, $post ) {
108
+
109
+        // For invoices...
110
+        if ( getpaid_is_invoice_post_type( $post_type ) ) {
111
+            $invoice = new WPInv_Invoice( $post );
112
+
113
+            // Resend invoice.
114
+            if ( ! $invoice->is_draft() ) {
115
+
116
+                add_meta_box(
117
+                    'wpinv-mb-resend-invoice',
118
+                    sprintf(
119
+                        // translators: %s is the invoice type.
120
+                        __( 'Resend %s', 'invoicing' ),
121
+                        ucfirst( $invoice->get_invoice_quote_type() )
122
+                    ),
123
+                    'GetPaid_Meta_Box_Resend_Invoice::output',
124
+                    $post_type,
125
+                    'side',
126
+                    'low'
127
+                );
128
+
129
+            }
130
+
131
+            // Subscriptions.
132
+            $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
133
+            if ( ! empty( $subscriptions ) ) {
134
+
135
+                if ( is_array( $subscriptions ) ) {
136
+                    add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' );
137
+                } else {
138
+                    add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
139
+                }
140
+
141
+                if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) {
142
+                    add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
143
+                }
144
+}
128 145
 
129
-			}
146
+            // Invoice details.
147
+            add_meta_box(
148
+                'wpinv-details',
149
+                sprintf(
150
+                    // translators: %s is the invoice type.
151
+                    __( '%s Details', 'invoicing' ),
152
+                    ucfirst( $invoice->get_invoice_quote_type() )
153
+                ),
154
+                'GetPaid_Meta_Box_Invoice_Details::output',
155
+                $post_type,
156
+                'side'
157
+            );
158
+
159
+            // Payment details.
160
+            add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
161
+
162
+            // Billing details.
163
+            add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
164
+
165
+            // Invoice items.
166
+            add_meta_box(
167
+                'wpinv-items',
168
+                sprintf(
169
+                    // translators: %s is the invoice type.
170
+                    __( '%s Items', 'invoicing' ),
171
+                    ucfirst( $invoice->get_invoice_quote_type() )
172
+                ),
173
+                'GetPaid_Meta_Box_Invoice_Items::output',
174
+                $post_type,
175
+                'normal',
176
+                'high'
177
+            );
178
+
179
+            // Invoice notes.
180
+            add_meta_box(
181
+                'wpinv-notes',
182
+                sprintf(
183
+                    // translators: %s is the invoice type.
184
+                    __( '%s Notes', 'invoicing' ),
185
+                    ucfirst( $invoice->get_invoice_quote_type() )
186
+                ),
187
+                'WPInv_Meta_Box_Notes::output',
188
+                $post_type,
189
+                'side',
190
+                'low'
191
+            );
192
+
193
+            // Shipping Address.
194
+            if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) {
195
+                add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
196
+            }
197
+
198
+            // Payment form information.
199
+            if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) {
200
+                add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
201
+            }
202
+}
130 203
 
131
-			// Subscriptions.
132
-			$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
133
-			if ( ! empty( $subscriptions ) ) {
204
+    }
134 205
 
135
-				if ( is_array( $subscriptions ) ) {
136
-					add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' );
137
-				} else {
138
-					add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
139
-				}
206
+    /**
207
+     * Remove some metaboxes.
208
+     */
209
+    public static function remove_meta_boxes() {
210
+        remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
211
+        remove_meta_box( 'postexcerpt', 'wpi_item', 'normal' );
212
+    }
140 213
 
141
-				if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) {
142
-					add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
143
-				}
144
-}
214
+    /**
215
+     * Rename other metaboxes.
216
+     */
217
+    public static function rename_meta_boxes() {
145 218
 
146
-			// Invoice details.
147
-			add_meta_box(
148
-				'wpinv-details',
149
-				sprintf(
150
-					// translators: %s is the invoice type.
151
-					__( '%s Details', 'invoicing' ),
152
-					ucfirst( $invoice->get_invoice_quote_type() )
153
-				),
154
-				'GetPaid_Meta_Box_Invoice_Details::output',
155
-				$post_type,
156
-				'side'
157
-			);
158
-
159
-			// Payment details.
160
-			add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
161
-
162
-			// Billing details.
163
-			add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
164
-
165
-			// Invoice items.
166
-			add_meta_box(
167
-				'wpinv-items',
168
-				sprintf(
169
-					// translators: %s is the invoice type.
170
-					__( '%s Items', 'invoicing' ),
171
-					ucfirst( $invoice->get_invoice_quote_type() )
172
-				),
173
-				'GetPaid_Meta_Box_Invoice_Items::output',
174
-				$post_type,
175
-				'normal',
176
-				'high'
177
-			);
178
-
179
-			// Invoice notes.
180
-			add_meta_box(
181
-				'wpinv-notes',
182
-				sprintf(
183
-					// translators: %s is the invoice type.
184
-					__( '%s Notes', 'invoicing' ),
185
-					ucfirst( $invoice->get_invoice_quote_type() )
186
-				),
187
-				'WPInv_Meta_Box_Notes::output',
188
-				$post_type,
189
-				'side',
190
-				'low'
191
-			);
192
-
193
-			// Shipping Address.
194
-			if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) {
195
-				add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
196
-			}
197
-
198
-			// Payment form information.
199
-			if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) {
200
-				add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
201
-			}
202
-}
219
+    }
203 220
 
204
-	}
205
-
206
-	/**
207
-	 * Remove some metaboxes.
208
-	 */
209
-	public static function remove_meta_boxes() {
210
-		remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
211
-		remove_meta_box( 'postexcerpt', 'wpi_item', 'normal' );
212
-	}
213
-
214
-	/**
215
-	 * Rename other metaboxes.
216
-	 */
217
-	public static function rename_meta_boxes() {
218
-
219
-	}
220
-
221
-	/**
222
-	 * Check if we're saving, then trigger an action based on the post type.
223
-	 *
224
-	 * @param  int    $post_id Post ID.
225
-	 * @param  object $post Post object.
226
-	 */
227
-	public static function save_meta_boxes( $post_id, $post ) {
228
-		$post_id = absint( $post_id );
229
-		$data    = wp_kses_post_deep( wp_unslash( $_POST ) );
230
-
231
-		// Do not save for ajax requests.
232
-		if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
233
-			return;
234
-		}
235
-
236
-		// $post_id and $post are required
237
-		if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
238
-			return;
239
-		}
240
-
241
-		// Dont' save meta boxes for revisions or autosaves.
242
-		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
243
-			return;
244
-		}
245
-
246
-		// Check the nonce.
247
-		if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
248
-			return;
249
-		}
250
-
251
-		// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
252
-		if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
253
-			return;
254
-		}
255
-
256
-		// Check user has permission to edit.
257
-		if ( ! current_user_can( 'edit_post', $post_id ) ) {
258
-			return;
259
-		}
260
-
261
-		if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
262
-
263
-			// We need this save event to run once to avoid potential endless loops.
264
-			self::$saved_meta_boxes = true;
265
-
266
-			return GetPaid_Meta_Box_Invoice_Address::save( $post_id, wp_kses_post_deep( $_POST ) );
267
-
268
-		}
269
-
270
-		// Ensure this is our post type.
271
-		$post_types_map = array(
272
-			'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
273
-			'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
274
-			'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
275
-		);
276
-
277
-		// Is this our post type?
278
-		if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
279
-			return;
280
-		}
281
-
282
-		// We need this save event to run once to avoid potential endless loops.
283
-		self::$saved_meta_boxes = true;
284
-
285
-		// Save the post.
286
-		$class = $post_types_map[ $post->post_type ];
287
-		$class::save( $post_id, wp_kses_post_deep( $_POST ), $post );
288
-
289
-	}
221
+    /**
222
+     * Check if we're saving, then trigger an action based on the post type.
223
+     *
224
+     * @param  int    $post_id Post ID.
225
+     * @param  object $post Post object.
226
+     */
227
+    public static function save_meta_boxes( $post_id, $post ) {
228
+        $post_id = absint( $post_id );
229
+        $data    = wp_kses_post_deep( wp_unslash( $_POST ) );
230
+
231
+        // Do not save for ajax requests.
232
+        if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
233
+            return;
234
+        }
235
+
236
+        // $post_id and $post are required
237
+        if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
238
+            return;
239
+        }
240
+
241
+        // Dont' save meta boxes for revisions or autosaves.
242
+        if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
243
+            return;
244
+        }
245
+
246
+        // Check the nonce.
247
+        if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
248
+            return;
249
+        }
250
+
251
+        // Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
252
+        if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
253
+            return;
254
+        }
255
+
256
+        // Check user has permission to edit.
257
+        if ( ! current_user_can( 'edit_post', $post_id ) ) {
258
+            return;
259
+        }
260
+
261
+        if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
262
+
263
+            // We need this save event to run once to avoid potential endless loops.
264
+            self::$saved_meta_boxes = true;
265
+
266
+            return GetPaid_Meta_Box_Invoice_Address::save( $post_id, wp_kses_post_deep( $_POST ) );
267
+
268
+        }
269
+
270
+        // Ensure this is our post type.
271
+        $post_types_map = array(
272
+            'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
273
+            'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
274
+            'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
275
+        );
276
+
277
+        // Is this our post type?
278
+        if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
279
+            return;
280
+        }
281
+
282
+        // We need this save event to run once to avoid potential endless loops.
283
+        self::$saved_meta_boxes = true;
284
+
285
+        // Save the post.
286
+        $class = $post_types_map[ $post->post_type ];
287
+        $class::save( $post_id, wp_kses_post_deep( $_POST ), $post );
288
+
289
+    }
290 290
 
291 291
 }
Please login to merge, or discard this patch.
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Metaboxes Admin Class
@@ -25,35 +25,35 @@  discard block
 block discarded – undo
25 25
 	public static function init() {
26 26
 
27 27
 		// Register metaboxes.
28
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 50, 2 );
28
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 50, 2);
29 29
 
30 30
 		// Remove metaboxes.
31
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
31
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30);
32 32
 
33 33
 		// Rename metaboxes.
34
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
34
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45);
35 35
 
36 36
 		// Save metaboxes.
37
-		add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
37
+		add_action('save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2);
38 38
 	}
39 39
 
40 40
 	/**
41 41
 	 * Register core metaboxes.
42 42
 	 */
43
-	public static function add_meta_boxes( $post_type, $post ) {
43
+	public static function add_meta_boxes($post_type, $post) {
44 44
 
45 45
 		// For invoices.
46
-		self::add_invoice_meta_boxes( $post_type, $post );
46
+		self::add_invoice_meta_boxes($post_type, $post);
47 47
 
48 48
 		// For payment forms.
49
-		self::add_payment_form_meta_boxes( $post_type, $post );
49
+		self::add_payment_form_meta_boxes($post_type, $post);
50 50
 
51 51
 		// For invoice items.
52
-		self::add_item_meta_boxes( $post_type );
52
+		self::add_item_meta_boxes($post_type);
53 53
 
54 54
 		// For invoice discounts.
55
-		if ( 'wpi_discount' === $post_type ) {
56
-			add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
55
+		if ('wpi_discount' === $post_type) {
56
+			add_meta_box('wpinv_discount_details', __('Discount Details', 'invoicing'), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high');
57 57
 		}
58 58
 
59 59
 	}
@@ -61,17 +61,17 @@  discard block
 block discarded – undo
61 61
 	/**
62 62
 	 * Register core metaboxes.
63 63
 	 */
64
-	protected static function add_payment_form_meta_boxes( $post_type, $post ) {
64
+	protected static function add_payment_form_meta_boxes($post_type, $post) {
65 65
 
66 66
 		// For payment forms.
67
-		if ( 'wpi_payment_form' === $post_type ) {
67
+		if ('wpi_payment_form' === $post_type) {
68 68
 
69 69
 			// Design payment form.
70
-			add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
70
+			add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal');
71 71
 
72 72
 			// Payment form information.
73
-			if ( wpinv_get_default_payment_form() !== $post->ID ) {
74
-				add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
73
+			if (wpinv_get_default_payment_form() !== $post->ID) {
74
+				add_meta_box('wpinv-payment-form-info', __('Details', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side');
75 75
 			}
76 76
 }
77 77
 
@@ -80,23 +80,23 @@  discard block
 block discarded – undo
80 80
 	/**
81 81
 	 * Register core metaboxes.
82 82
 	 */
83
-	protected static function add_item_meta_boxes( $post_type ) {
83
+	protected static function add_item_meta_boxes($post_type) {
84 84
 
85
-		if ( 'wpi_item' === $post_type ) {
85
+		if ('wpi_item' === $post_type) {
86 86
 
87 87
 			// Item details.
88
-			add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
88
+			add_meta_box('wpinv_item_details', __('Item Details', 'invoicing'), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high');
89 89
 
90 90
 			// If taxes are enabled, register the tax metabox.
91
-			if ( wpinv_use_taxes() ) {
92
-				add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
91
+			if (wpinv_use_taxes()) {
92
+				add_meta_box('wpinv_item_vat', __('Tax', 'invoicing'), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high');
93 93
 			}
94 94
 
95 95
 			// Item info.
96
-			add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
96
+			add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core');
97 97
 
98 98
 			// Item description.
99
-			add_meta_box( 'postexcerpt', __( 'Item Description', 'invoicing' ), 'GetPaid_Meta_Box_Description::output', 'wpi_item', 'normal' );
99
+			add_meta_box('postexcerpt', __('Item Description', 'invoicing'), 'GetPaid_Meta_Box_Description::output', 'wpi_item', 'normal');
100 100
 		}
101 101
 
102 102
 	}
@@ -104,21 +104,21 @@  discard block
 block discarded – undo
104 104
 	/**
105 105
 	 * Register invoice metaboxes.
106 106
 	 */
107
-	protected static function add_invoice_meta_boxes( $post_type, $post ) {
107
+	protected static function add_invoice_meta_boxes($post_type, $post) {
108 108
 
109 109
 		// For invoices...
110
-		if ( getpaid_is_invoice_post_type( $post_type ) ) {
111
-			$invoice = new WPInv_Invoice( $post );
110
+		if (getpaid_is_invoice_post_type($post_type)) {
111
+			$invoice = new WPInv_Invoice($post);
112 112
 
113 113
 			// Resend invoice.
114
-			if ( ! $invoice->is_draft() ) {
114
+			if (!$invoice->is_draft()) {
115 115
 
116 116
 				add_meta_box(
117 117
 					'wpinv-mb-resend-invoice',
118 118
 					sprintf(
119 119
 						// translators: %s is the invoice type.
120
-						__( 'Resend %s', 'invoicing' ),
121
-						ucfirst( $invoice->get_invoice_quote_type() )
120
+						__('Resend %s', 'invoicing'),
121
+						ucfirst($invoice->get_invoice_quote_type())
122 122
 					),
123 123
 					'GetPaid_Meta_Box_Resend_Invoice::output',
124 124
 					$post_type,
@@ -129,17 +129,17 @@  discard block
 block discarded – undo
129 129
 			}
130 130
 
131 131
 			// Subscriptions.
132
-			$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
133
-			if ( ! empty( $subscriptions ) ) {
132
+			$subscriptions = getpaid_get_invoice_subscriptions($invoice);
133
+			if (!empty($subscriptions)) {
134 134
 
135
-				if ( is_array( $subscriptions ) ) {
136
-					add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' );
135
+				if (is_array($subscriptions)) {
136
+					add_meta_box('wpinv-mb-subscriptions', __('Related Subscriptions', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced');
137 137
 				} else {
138
-					add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
138
+					add_meta_box('wpinv-mb-subscriptions', __('Subscription Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced');
139 139
 				}
140 140
 
141
-				if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) {
142
-					add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
141
+				if (getpaid_count_subscription_invoices($invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id()) > 1) {
142
+					add_meta_box('wpinv-mb-subscription-invoices', __('Related Payments', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced');
143 143
 				}
144 144
 }
145 145
 
@@ -148,8 +148,8 @@  discard block
 block discarded – undo
148 148
 				'wpinv-details',
149 149
 				sprintf(
150 150
 					// translators: %s is the invoice type.
151
-					__( '%s Details', 'invoicing' ),
152
-					ucfirst( $invoice->get_invoice_quote_type() )
151
+					__('%s Details', 'invoicing'),
152
+					ucfirst($invoice->get_invoice_quote_type())
153 153
 				),
154 154
 				'GetPaid_Meta_Box_Invoice_Details::output',
155 155
 				$post_type,
@@ -157,18 +157,18 @@  discard block
 block discarded – undo
157 157
 			);
158 158
 
159 159
 			// Payment details.
160
-			add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
160
+			add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default');
161 161
 
162 162
 			// Billing details.
163
-			add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
163
+			add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high');
164 164
 
165 165
 			// Invoice items.
166 166
 			add_meta_box(
167 167
 				'wpinv-items',
168 168
 				sprintf(
169 169
 					// translators: %s is the invoice type.
170
-					__( '%s Items', 'invoicing' ),
171
-					ucfirst( $invoice->get_invoice_quote_type() )
170
+					__('%s Items', 'invoicing'),
171
+					ucfirst($invoice->get_invoice_quote_type())
172 172
 				),
173 173
 				'GetPaid_Meta_Box_Invoice_Items::output',
174 174
 				$post_type,
@@ -181,8 +181,8 @@  discard block
 block discarded – undo
181 181
 				'wpinv-notes',
182 182
 				sprintf(
183 183
 					// translators: %s is the invoice type.
184
-					__( '%s Notes', 'invoicing' ),
185
-					ucfirst( $invoice->get_invoice_quote_type() )
184
+					__('%s Notes', 'invoicing'),
185
+					ucfirst($invoice->get_invoice_quote_type())
186 186
 				),
187 187
 				'WPInv_Meta_Box_Notes::output',
188 188
 				$post_type,
@@ -191,13 +191,13 @@  discard block
 block discarded – undo
191 191
 			);
192 192
 
193 193
 			// Shipping Address.
194
-			if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) {
195
-				add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
194
+			if (get_post_meta($invoice->get_id(), 'shipping_address', true)) {
195
+				add_meta_box('wpinv-invoice-shipping-details', __('Shipping Address', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high');
196 196
 			}
197 197
 
198 198
 			// Payment form information.
199
-			if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) {
200
-				add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
199
+			if (get_post_meta($invoice->get_id(), 'payment_form_data', true)) {
200
+				add_meta_box('wpinv-invoice-payment-form-details', __('Payment Form Details', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high');
201 201
 			}
202 202
 }
203 203
 
@@ -207,8 +207,8 @@  discard block
 block discarded – undo
207 207
 	 * Remove some metaboxes.
208 208
 	 */
209 209
 	public static function remove_meta_boxes() {
210
-		remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
211
-		remove_meta_box( 'postexcerpt', 'wpi_item', 'normal' );
210
+		remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal');
211
+		remove_meta_box('postexcerpt', 'wpi_item', 'normal');
212 212
 	}
213 213
 
214 214
 	/**
@@ -224,46 +224,46 @@  discard block
 block discarded – undo
224 224
 	 * @param  int    $post_id Post ID.
225 225
 	 * @param  object $post Post object.
226 226
 	 */
227
-	public static function save_meta_boxes( $post_id, $post ) {
228
-		$post_id = absint( $post_id );
229
-		$data    = wp_kses_post_deep( wp_unslash( $_POST ) );
227
+	public static function save_meta_boxes($post_id, $post) {
228
+		$post_id = absint($post_id);
229
+		$data    = wp_kses_post_deep(wp_unslash($_POST));
230 230
 
231 231
 		// Do not save for ajax requests.
232
-		if ( ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
232
+		if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
233 233
 			return;
234 234
 		}
235 235
 
236 236
 		// $post_id and $post are required
237
-		if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
237
+		if (empty($post_id) || empty($post) || self::$saved_meta_boxes) {
238 238
 			return;
239 239
 		}
240 240
 
241 241
 		// Dont' save meta boxes for revisions or autosaves.
242
-		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
242
+		if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
243 243
 			return;
244 244
 		}
245 245
 
246 246
 		// Check the nonce.
247
-		if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
247
+		if (empty($data['getpaid_meta_nonce']) || !wp_verify_nonce($data['getpaid_meta_nonce'], 'getpaid_meta_nonce')) {
248 248
 			return;
249 249
 		}
250 250
 
251 251
 		// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
252
-		if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
252
+		if (empty($data['post_ID']) || absint($data['post_ID']) !== $post_id) {
253 253
 			return;
254 254
 		}
255 255
 
256 256
 		// Check user has permission to edit.
257
-		if ( ! current_user_can( 'edit_post', $post_id ) ) {
257
+		if (!current_user_can('edit_post', $post_id)) {
258 258
 			return;
259 259
 		}
260 260
 
261
-		if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
261
+		if (getpaid_is_invoice_post_type($post->post_type)) {
262 262
 
263 263
 			// We need this save event to run once to avoid potential endless loops.
264 264
 			self::$saved_meta_boxes = true;
265 265
 
266
-			return GetPaid_Meta_Box_Invoice_Address::save( $post_id, wp_kses_post_deep( $_POST ) );
266
+			return GetPaid_Meta_Box_Invoice_Address::save($post_id, wp_kses_post_deep($_POST));
267 267
 
268 268
 		}
269 269
 
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 		);
276 276
 
277 277
 		// Is this our post type?
278
-		if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
278
+		if (!isset($post_types_map[$post->post_type])) {
279 279
 			return;
280 280
 		}
281 281
 
@@ -283,8 +283,8 @@  discard block
 block discarded – undo
283 283
 		self::$saved_meta_boxes = true;
284 284
 
285 285
 		// Save the post.
286
-		$class = $post_types_map[ $post->post_type ];
287
-		$class::save( $post_id, wp_kses_post_deep( $_POST ), $post );
286
+		$class = $post_types_map[$post->post_type];
287
+		$class::save($post_id, wp_kses_post_deep($_POST), $post);
288 288
 
289 289
 	}
290 290
 
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-paypal-gateway.php 2 patches
Indentation   +366 added lines, -366 removed lines patch added patch discarded remove patch
@@ -13,97 +13,97 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'paypal';
21 21
 
22 22
     /**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27 27
     protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34 34
     public $order = 1;
35 35
 
36 36
     /**
37
-	 * Stores line items to send to PayPal.
38
-	 *
39
-	 * @var array
40
-	 */
37
+     * Stores line items to send to PayPal.
38
+     *
39
+     * @var array
40
+     */
41 41
     protected $line_items = array();
42 42
 
43 43
     /**
44
-	 * Endpoint for requests from PayPal.
45
-	 *
46
-	 * @var string
47
-	 */
48
-	protected $notify_url;
49
-
50
-	/**
51
-	 * Endpoint for requests to PayPal.
52
-	 *
53
-	 * @var string
54
-	 */
44
+     * Endpoint for requests from PayPal.
45
+     *
46
+     * @var string
47
+     */
48
+    protected $notify_url;
49
+
50
+    /**
51
+     * Endpoint for requests to PayPal.
52
+     *
53
+     * @var string
54
+     */
55 55
     protected $endpoint;
56 56
 
57 57
     /**
58
-	 * Currencies this gateway is allowed for.
59
-	 *
60
-	 * @var array
61
-	 */
62
-	public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
58
+     * Currencies this gateway is allowed for.
59
+     *
60
+     * @var array
61
+     */
62
+    public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
63 63
 
64 64
     /**
65
-	 * URL to view a transaction.
66
-	 *
67
-	 * @var string
68
-	 */
65
+     * URL to view a transaction.
66
+     *
67
+     * @var string
68
+     */
69 69
     public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s';
70 70
 
71 71
     /**
72
-	 * URL to view a subscription.
73
-	 *
74
-	 * @var string
75
-	 */
76
-	public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
72
+     * URL to view a subscription.
73
+     *
74
+     * @var string
75
+     */
76
+    public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
77 77
 
78 78
     /**
79
-	 * Class constructor.
80
-	 */
81
-	public function __construct() {
79
+     * Class constructor.
80
+     */
81
+    public function __construct() {
82 82
 
83 83
         $this->title                = __( 'PayPal Standard', 'invoicing' );
84 84
         $this->method_title         = __( 'PayPal Standard', 'invoicing' );
85 85
         $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' );
86 86
         $this->notify_url           = wpinv_get_ipn_url( $this->id );
87 87
 
88
-		add_filter( 'wpinv_subscription_cancel_url', array( $this, 'filter_cancel_subscription_url' ), 10, 2 );
89
-		add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
88
+        add_filter( 'wpinv_subscription_cancel_url', array( $this, 'filter_cancel_subscription_url' ), 10, 2 );
89
+        add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
90 90
         add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) );
91
-		add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
92
-		add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
93
-		add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) );
94
-		parent::__construct();
91
+        add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
92
+        add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
93
+        add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) );
94
+        parent::__construct();
95 95
     }
96 96
 
97 97
     /**
98
-	 * Process Payment.
99
-	 *
100
-	 *
101
-	 * @param WPInv_Invoice $invoice Invoice.
102
-	 * @param array $submission_data Posted checkout fields.
103
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
104
-	 * @return array
105
-	 */
106
-	public function process_payment( $invoice, $submission_data, $submission ) {
98
+     * Process Payment.
99
+     *
100
+     *
101
+     * @param WPInv_Invoice $invoice Invoice.
102
+     * @param array $submission_data Posted checkout fields.
103
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
104
+     * @return array
105
+     */
106
+    public function process_payment( $invoice, $submission_data, $submission ) {
107 107
 
108 108
         // Get redirect url.
109 109
         $paypal_redirect = $this->get_request_url( $invoice );
@@ -126,15 +126,15 @@  discard block
 block discarded – undo
126 126
     }
127 127
 
128 128
     /**
129
-	 * Get the PayPal request URL for an invoice.
130
-	 *
131
-	 * @param  WPInv_Invoice $invoice Invoice object.
132
-	 * @return string
133
-	 */
134
-	public function get_request_url( $invoice ) {
129
+     * Get the PayPal request URL for an invoice.
130
+     *
131
+     * @param  WPInv_Invoice $invoice Invoice object.
132
+     * @return string
133
+     */
134
+    public function get_request_url( $invoice ) {
135 135
 
136 136
         // Endpoint for this request
137
-		$this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
137
+        $this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
138 138
 
139 139
         // Retrieve paypal args.
140 140
         $paypal_args       = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' );
@@ -147,45 +147,45 @@  discard block
 block discarded – undo
147 147
 
148 148
         return add_query_arg( $paypal_args, $this->endpoint );
149 149
 
150
-	}
150
+    }
151 151
 
152 152
     /**
153
-	 * Get PayPal Args for passing to PP.
154
-	 *
155
-	 * @param  WPInv_Invoice $invoice Invoice object.
156
-	 * @return array
157
-	 */
158
-	protected function get_paypal_args( $invoice ) {
153
+     * Get PayPal Args for passing to PP.
154
+     *
155
+     * @param  WPInv_Invoice $invoice Invoice object.
156
+     * @return array
157
+     */
158
+    protected function get_paypal_args( $invoice ) {
159 159
 
160 160
         // Whether or not to send the line items as one item.
161
-		$force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
162
-
163
-		if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
164
-			$force_one_line_item = true;
165
-		}
166
-
167
-		$paypal_args = apply_filters(
168
-			'getpaid_paypal_args',
169
-			array_merge(
170
-				$this->get_transaction_args( $invoice ),
171
-				$this->get_line_item_args( $invoice, $force_one_line_item )
172
-			),
173
-			$invoice
174
-		);
175
-
176
-		return $this->fix_request_length( $invoice, $paypal_args );
161
+        $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
162
+
163
+        if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
164
+            $force_one_line_item = true;
165
+        }
166
+
167
+        $paypal_args = apply_filters(
168
+            'getpaid_paypal_args',
169
+            array_merge(
170
+                $this->get_transaction_args( $invoice ),
171
+                $this->get_line_item_args( $invoice, $force_one_line_item )
172
+            ),
173
+            $invoice
174
+        );
175
+
176
+        return $this->fix_request_length( $invoice, $paypal_args );
177 177
     }
178 178
 
179 179
     /**
180
-	 * Get transaction args for paypal request.
181
-	 *
182
-	 * @param WPInv_Invoice $invoice Invoice object.
183
-	 * @return array
184
-	 */
185
-	protected function get_transaction_args( $invoice ) {
186
-
187
-		$email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' );
188
-		return array(
180
+     * Get transaction args for paypal request.
181
+     *
182
+     * @param WPInv_Invoice $invoice Invoice object.
183
+     * @return array
184
+     */
185
+    protected function get_transaction_args( $invoice ) {
186
+
187
+        $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' );
188
+        return array(
189 189
             'cmd'           => '_cart',
190 190
             'business'      => $email,
191 191
             'no_shipping'   => '1',
@@ -210,16 +210,16 @@  discard block
 block discarded – undo
210 210
     }
211 211
 
212 212
     /**
213
-	 * Get line item args for paypal request.
214
-	 *
215
-	 * @param  WPInv_Invoice $invoice Invoice object.
216
-	 * @param  bool     $force_one_line_item Create only one item for this invoice.
217
-	 * @return array
218
-	 */
219
-	protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
213
+     * Get line item args for paypal request.
214
+     *
215
+     * @param  WPInv_Invoice $invoice Invoice object.
216
+     * @param  bool     $force_one_line_item Create only one item for this invoice.
217
+     * @return array
218
+     */
219
+    protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
220 220
 
221 221
         // Maybe send invoice as a single item.
222
-		if ( $force_one_line_item ) {
222
+        if ( $force_one_line_item ) {
223 223
             return $this->get_line_item_args_single_item( $invoice );
224 224
         }
225 225
 
@@ -239,129 +239,129 @@  discard block
 block discarded – undo
239 239
             $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 );
240 240
         }
241 241
 
242
-		return array_merge( $line_item_args, $this->get_line_items() );
242
+        return array_merge( $line_item_args, $this->get_line_items() );
243 243
 
244 244
     }
245 245
 
246 246
     /**
247
-	 * Get line item args for paypal request as a single line item.
248
-	 *
249
-	 * @param  WPInv_Invoice $invoice Invoice object.
250
-	 * @return array
251
-	 */
252
-	protected function get_line_item_args_single_item( $invoice ) {
253
-		$this->delete_line_items();
247
+     * Get line item args for paypal request as a single line item.
248
+     *
249
+     * @param  WPInv_Invoice $invoice Invoice object.
250
+     * @return array
251
+     */
252
+    protected function get_line_item_args_single_item( $invoice ) {
253
+        $this->delete_line_items();
254 254
 
255 255
         $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
256
-		$this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
256
+        $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
257 257
 
258
-		return $this->get_line_items();
258
+        return $this->get_line_items();
259 259
     }
260 260
 
261 261
     /**
262
-	 * Return all line items.
263
-	 */
264
-	protected function get_line_items() {
265
-		return $this->line_items;
266
-	}
262
+     * Return all line items.
263
+     */
264
+    protected function get_line_items() {
265
+        return $this->line_items;
266
+    }
267 267
 
268 268
     /**
269
-	 * Remove all line items.
270
-	 */
271
-	protected function delete_line_items() {
272
-		$this->line_items = array();
269
+     * Remove all line items.
270
+     */
271
+    protected function delete_line_items() {
272
+        $this->line_items = array();
273 273
     }
274 274
 
275 275
     /**
276
-	 * Prepare line items to send to paypal.
277
-	 *
278
-	 * @param  WPInv_Invoice $invoice Invoice object.
279
-	 */
280
-	protected function prepare_line_items( $invoice ) {
281
-		$this->delete_line_items();
282
-
283
-		// Items.
284
-		foreach ( $invoice->get_items() as $item ) {
285
-			$amount   = $item->get_price();
286
-			$quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
287
-			$this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
276
+     * Prepare line items to send to paypal.
277
+     *
278
+     * @param  WPInv_Invoice $invoice Invoice object.
279
+     */
280
+    protected function prepare_line_items( $invoice ) {
281
+        $this->delete_line_items();
282
+
283
+        // Items.
284
+        foreach ( $invoice->get_items() as $item ) {
285
+            $amount   = $item->get_price();
286
+            $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
287
+            $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
288 288
         }
289 289
 
290 290
         // Fees.
291
-		foreach ( $invoice->get_fees() as $fee => $data ) {
291
+        foreach ( $invoice->get_fees() as $fee => $data ) {
292 292
             $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) );
293 293
         }
294 294
 
295 295
     }
296 296
 
297 297
     /**
298
-	 * Add PayPal Line Item.
299
-	 *
300
-	 * @param  string $item_name Item name.
301
-	 * @param  float    $quantity Item quantity.
302
-	 * @param  float  $amount Amount.
303
-	 * @param  string $item_number Item number.
304
-	 */
305
-	protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
306
-		$index = ( count( $this->line_items ) / 4 ) + 1;
307
-
308
-		$item = apply_filters(
309
-			'getpaid_paypal_line_item',
310
-			array(
311
-				'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
312
-				'quantity'    => (float) $quantity,
313
-				'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
314
-				'item_number' => $item_number,
315
-			),
316
-			$item_name,
317
-			$quantity,
318
-			$amount,
319
-			$item_number
320
-		);
321
-
322
-		$this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
298
+     * Add PayPal Line Item.
299
+     *
300
+     * @param  string $item_name Item name.
301
+     * @param  float    $quantity Item quantity.
302
+     * @param  float  $amount Amount.
303
+     * @param  string $item_number Item number.
304
+     */
305
+    protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
306
+        $index = ( count( $this->line_items ) / 4 ) + 1;
307
+
308
+        $item = apply_filters(
309
+            'getpaid_paypal_line_item',
310
+            array(
311
+                'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
312
+                'quantity'    => (float) $quantity,
313
+                'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
314
+                'item_number' => $item_number,
315
+            ),
316
+            $item_name,
317
+            $quantity,
318
+            $amount,
319
+            $item_number
320
+        );
321
+
322
+        $this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
323 323
         $this->line_items[ 'quantity_' . $index ]    = $item['quantity'];
324 324
 
325 325
         // The price or amount of the product, service, or contribution, not including shipping, handling, or tax.
326
-		$this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
327
-		$this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
326
+        $this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
327
+        $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
328 328
     }
329 329
 
330 330
     /**
331
-	 * If the default request with line items is too long, generate a new one with only one line item.
332
-	 *
333
-	 * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
334
-	 *
335
-	 * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
336
-	 * @param array    $paypal_args Arguments sent to Paypal in the request.
337
-	 * @return array
338
-	 */
339
-	protected function fix_request_length( $invoice, $paypal_args ) {
340
-		$max_paypal_length = 2083;
341
-		$query_candidate   = http_build_query( $paypal_args, '', '&' );
342
-
343
-		if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
344
-			return $paypal_args;
345
-		}
346
-
347
-		return apply_filters(
348
-			'getpaid_paypal_args',
349
-			array_merge(
350
-				$this->get_transaction_args( $invoice ),
351
-				$this->get_line_item_args( $invoice, true )
352
-			),
353
-			$invoice
354
-		);
331
+     * If the default request with line items is too long, generate a new one with only one line item.
332
+     *
333
+     * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
334
+     *
335
+     * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
336
+     * @param array    $paypal_args Arguments sent to Paypal in the request.
337
+     * @return array
338
+     */
339
+    protected function fix_request_length( $invoice, $paypal_args ) {
340
+        $max_paypal_length = 2083;
341
+        $query_candidate   = http_build_query( $paypal_args, '', '&' );
342
+
343
+        if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
344
+            return $paypal_args;
345
+        }
346
+
347
+        return apply_filters(
348
+            'getpaid_paypal_args',
349
+            array_merge(
350
+                $this->get_transaction_args( $invoice ),
351
+                $this->get_line_item_args( $invoice, true )
352
+            ),
353
+            $invoice
354
+        );
355 355
 
356 356
     }
357 357
 
358 358
     /**
359
-	 * Processes recurring invoices.
360
-	 *
361
-	 * @param  array $paypal_args PayPal args.
362
-	 * @param  WPInv_Invoice    $invoice Invoice object.
363
-	 */
364
-	public function process_subscription( $paypal_args, $invoice ) {
359
+     * Processes recurring invoices.
360
+     *
361
+     * @param  array $paypal_args PayPal args.
362
+     * @param  WPInv_Invoice    $invoice Invoice object.
363
+     */
364
+    public function process_subscription( $paypal_args, $invoice ) {
365 365
 
366 366
         // Make sure this is a subscription.
367 367
         if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) {
@@ -382,21 +382,21 @@  discard block
 block discarded – undo
382 382
         $recurring_amount       = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 );
383 383
         $subscription_item      = $invoice->get_recurring( true );
384 384
 
385
-		// Convert 365 days to 1 year.
386
-		if ( 'D' == $period && 365 == $interval ) {
387
-			$period = 'Y';
388
-			$interval = 1;
389
-		}
385
+        // Convert 365 days to 1 year.
386
+        if ( 'D' == $period && 365 == $interval ) {
387
+            $period = 'Y';
388
+            $interval = 1;
389
+        }
390 390
 
391 391
         if ( $subscription_item->has_free_trial() ) {
392 392
 
393 393
             $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount;
394 394
 
395
-			// Trial period length.
396
-			$paypal_args['p1'] = $subscription_item->get_trial_interval();
395
+            // Trial period length.
396
+            $paypal_args['p1'] = $subscription_item->get_trial_interval();
397 397
 
398
-			// Trial period.
399
-			$paypal_args['t1'] = $subscription_item->get_trial_period();
398
+            // Trial period.
399
+            $paypal_args['t1'] = $subscription_item->get_trial_period();
400 400
 
401 401
         } elseif ( $initial_amount != $recurring_amount ) {
402 402
 
@@ -419,40 +419,40 @@  discard block
 block discarded – undo
419 419
         }
420 420
 
421 421
         // We have a recurring payment
422
-		if ( ! isset( $param_number ) || 1 == $param_number ) {
422
+        if ( ! isset( $param_number ) || 1 == $param_number ) {
423 423
 
424
-			// Subscription price
425
-			$paypal_args['a3'] = $recurring_amount;
424
+            // Subscription price
425
+            $paypal_args['a3'] = $recurring_amount;
426 426
 
427
-			// Subscription duration
428
-			$paypal_args['p3'] = $interval;
427
+            // Subscription duration
428
+            $paypal_args['p3'] = $interval;
429 429
 
430
-			// Subscription period
431
-			$paypal_args['t3'] = $period;
430
+            // Subscription period
431
+            $paypal_args['t3'] = $period;
432 432
 
433 433
         }
434 434
 
435 435
         // Recurring payments
436
-		if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
436
+        if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
437 437
 
438
-			// Non-recurring payments
439
-			$paypal_args['src'] = 0;
438
+            // Non-recurring payments
439
+            $paypal_args['src'] = 0;
440 440
 
441
-		} else {
441
+        } else {
442 442
 
443
-			$paypal_args['src'] = 1;
443
+            $paypal_args['src'] = 1;
444 444
 
445
-			if ( $bill_times > 0 ) {
445
+            if ( $bill_times > 0 ) {
446 446
 
447
-				// An initial period is being used to charge a sign-up fee
448
-				if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
449
-					$bill_times--;
450
-				}
447
+                // An initial period is being used to charge a sign-up fee
448
+                if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
449
+                    $bill_times--;
450
+                }
451 451
 
452 452
                 // Make sure it's not over the max of 52
453 453
                 $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
454 454
 
455
-			}
455
+            }
456 456
         }
457 457
 
458 458
         // Force return URL so that order description & instructions display
@@ -467,19 +467,19 @@  discard block
 block discarded – undo
467 467
 }
468 468
 
469 469
         return apply_filters(
470
-			'getpaid_paypal_subscription_args',
471
-			$paypal_args,
472
-			$invoice
470
+            'getpaid_paypal_subscription_args',
471
+            $paypal_args,
472
+            $invoice
473 473
         );
474 474
 
475 475
     }
476 476
 
477 477
     /**
478
-	 * Processes ipns and marks payments as complete.
479
-	 *
480
-	 * @return void
481
-	 */
482
-	public function verify_ipn() {
478
+     * Processes ipns and marks payments as complete.
479
+     *
480
+     * @return void
481
+     */
482
+    public function verify_ipn() {
483 483
         new GetPaid_Paypal_Gateway_IPN_Handler( $this );
484 484
     }
485 485
 
@@ -489,19 +489,19 @@  discard block
 block discarded – undo
489 489
     public function sandbox_notice() {
490 490
 
491 491
         return sprintf(
492
-			__( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ),
493
-			'<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
494
-			'</a>'
495
-		);
492
+            __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ),
493
+            '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
494
+            '</a>'
495
+        );
496 496
 
497 497
     }
498 498
 
499
-	/**
500
-	 * Filters the gateway settings.
501
-	 *
502
-	 * @param array $admin_settings
503
-	 */
504
-	public function admin_settings( $admin_settings ) {
499
+    /**
500
+     * Filters the gateway settings.
501
+     *
502
+     * @param array $admin_settings
503
+     */
504
+    public function admin_settings( $admin_settings ) {
505 505
 
506 506
         $currencies = sprintf(
507 507
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -511,31 +511,31 @@  discard block
 block discarded – undo
511 511
         $admin_settings['paypal_active']['desc'] .= " ($currencies)";
512 512
         $admin_settings['paypal_desc']['std']     = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
513 513
 
514
-		// Access tokens.
515
-		$live_email      = wpinv_get_option( 'paypal_email' );
516
-		$sandbox_email   = wpinv_get_option( 'paypal_sandbox_email' );
514
+        // Access tokens.
515
+        $live_email      = wpinv_get_option( 'paypal_email' );
516
+        $sandbox_email   = wpinv_get_option( 'paypal_sandbox_email' );
517 517
 
518
-		$admin_settings['paypal_connect'] = array(
519
-			'type' => 'hook',
520
-			'id'   => 'paypal_connect',
521
-			'name' => __( 'Connect to PayPal', 'invoicing' ),
522
-		);
518
+        $admin_settings['paypal_connect'] = array(
519
+            'type' => 'hook',
520
+            'id'   => 'paypal_connect',
521
+            'name' => __( 'Connect to PayPal', 'invoicing' ),
522
+        );
523 523
 
524 524
         $admin_settings['paypal_email'] = array(
525 525
             'type'  => 'text',
526
-			'class' => 'live-auth-data',
526
+            'class' => 'live-auth-data',
527 527
             'id'    => 'paypal_email',
528 528
             'name'  => __( 'Live Email Address', 'invoicing' ),
529 529
             'desc'  => __( 'The email address of your PayPal account.', 'invoicing' ),
530 530
         );
531 531
 
532
-		$admin_settings['paypal_sandbox_email'] = array(
532
+        $admin_settings['paypal_sandbox_email'] = array(
533 533
             'type'  => 'text',
534
-			'class' => 'sandbox-auth-data',
534
+            'class' => 'sandbox-auth-data',
535 535
             'id'    => 'paypal_sandbox_email',
536 536
             'name'  => __( 'Sandbox Email Address', 'invoicing' ),
537 537
             'desc'  => __( 'The email address of your sandbox PayPal account.', 'invoicing' ),
538
-			'std'   => wpinv_get_option( 'paypal_email', '' ),
538
+            'std'   => wpinv_get_option( 'paypal_email', '' ),
539 539
         );
540 540
 
541 541
         $admin_settings['paypal_ipn_url'] = array(
@@ -547,57 +547,57 @@  discard block
 block discarded – undo
547 547
             'readonly' => true,
548 548
         );
549 549
 
550
-		return $admin_settings;
551
-	}
552
-
553
-	/**
554
-	 * Retrieves the URL to cancel a subscription.
555
-	 *
556
-	 * @param string $url
557
-	 * @param WPInv_Subscription $subscription
558
-	 */
559
-	public function filter_cancel_subscription_url( $url, $subscription ) {
560
-
561
-		if ( $this->id !== $subscription->get_gateway() ) {
562
-			return $url;
563
-		}
564
-
565
-		// Get the PayPal profile ID.
566
-		$profile_id = $subscription->get_profile_id();
567
-
568
-		// Bail if no profile ID.
569
-		if ( empty( $profile_id ) ) {
570
-			return $url;
571
-		}
572
-
573
-		$cancel_url = 'https://www.paypal.com/myaccount/autopay/connect/%s/cancel';
574
-		if ( $this->is_sandbox( $subscription->get_parent_payment() ) ) {
575
-			$cancel_url = 'https://www.sandbox.paypal.com/myaccount/autopay/connect/%s/cancel';
576
-		}
577
-
578
-		return sprintf( $cancel_url, $profile_id );
579
-	}
580
-
581
-	/**
582
-	 * Retrieves the PayPal connect URL when using the setup wizzard.
583
-	 *
584
-	 *
550
+        return $admin_settings;
551
+    }
552
+
553
+    /**
554
+     * Retrieves the URL to cancel a subscription.
555
+     *
556
+     * @param string $url
557
+     * @param WPInv_Subscription $subscription
558
+     */
559
+    public function filter_cancel_subscription_url( $url, $subscription ) {
560
+
561
+        if ( $this->id !== $subscription->get_gateway() ) {
562
+            return $url;
563
+        }
564
+
565
+        // Get the PayPal profile ID.
566
+        $profile_id = $subscription->get_profile_id();
567
+
568
+        // Bail if no profile ID.
569
+        if ( empty( $profile_id ) ) {
570
+            return $url;
571
+        }
572
+
573
+        $cancel_url = 'https://www.paypal.com/myaccount/autopay/connect/%s/cancel';
574
+        if ( $this->is_sandbox( $subscription->get_parent_payment() ) ) {
575
+            $cancel_url = 'https://www.sandbox.paypal.com/myaccount/autopay/connect/%s/cancel';
576
+        }
577
+
578
+        return sprintf( $cancel_url, $profile_id );
579
+    }
580
+
581
+    /**
582
+     * Retrieves the PayPal connect URL when using the setup wizzard.
583
+     *
584
+     *
585 585
      * @param array $data
586 586
      * @return string
587
-	 */
588
-	public static function maybe_get_connect_url( $url = '', $data = array() ) {
589
-		return self::get_connect_url( false, urldecode( $data['redirect'] ) );
590
-	}
591
-
592
-	/**
593
-	 * Retrieves the PayPal connect URL.
594
-	 *
595
-	 *
587
+     */
588
+    public static function maybe_get_connect_url( $url = '', $data = array() ) {
589
+        return self::get_connect_url( false, urldecode( $data['redirect'] ) );
590
+    }
591
+
592
+    /**
593
+     * Retrieves the PayPal connect URL.
594
+     *
595
+     *
596 596
      * @param bool $is_sandbox
597
-	 * @param string $redirect
597
+     * @param string $redirect
598 598
      * @return string
599
-	 */
600
-	public static function get_connect_url( $is_sandbox, $redirect = '' ) {
599
+     */
600
+    public static function get_connect_url( $is_sandbox, $redirect = '' ) {
601 601
 
602 602
         $redirect_url = add_query_arg(
603 603
             array(
@@ -607,7 +607,7 @@  discard block
 block discarded – undo
607 607
                 'tab'                  => 'gateways',
608 608
                 'section'              => 'paypal',
609 609
                 'getpaid-nonce'        => wp_create_nonce( 'getpaid-nonce' ),
610
-				'redirect'             => urlencode( $redirect ),
610
+                'redirect'             => urlencode( $redirect ),
611 611
             ),
612 612
             admin_url( 'admin.php' )
613 613
         );
@@ -622,12 +622,12 @@  discard block
 block discarded – undo
622 622
 
623 623
     }
624 624
 
625
-	/**
626
-	 * Generates settings page js.
627
-	 *
625
+    /**
626
+     * Generates settings page js.
627
+     *
628 628
      * @return void
629
-	 */
630
-	public static function display_connect_buttons() {
629
+     */
630
+    public static function display_connect_buttons() {
631 631
 
632 632
         ?>
633 633
 			<div class="wpinv-paypal-connect-live">
@@ -669,70 +669,70 @@  discard block
 block discarded – undo
669 669
         <?php
670 670
     }
671 671
 
672
-	/**
673
-	 * Connects to PayPal.
674
-	 *
675
-	 * @param array $data Connection data.
676
-	 * @return void
677
-	 */
678
-	public function connect_paypal( $data ) {
679
-
680
-		$sandbox      = $this->is_sandbox();
681
-		$data         = wp_unslash( $data );
682
-		$access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
683
-
684
-		if ( isset( $data['live_mode'] ) ) {
685
-			$sandbox = empty( $data['live_mode'] );
686
-		}
687
-
688
-		wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
689
-		wpinv_update_option( 'paypal_active', 1 );
690
-
691
-		if ( ! empty( $data['error_description'] ) ) {
692
-			getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
693
-		} else {
694
-
695
-			// Retrieve the user info.
696
-			$user_info = wp_remote_get(
697
-				! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
698
-				array(
699
-
700
-					'headers' => array(
701
-						'Authorization' => 'Bearer ' . $access_token,
702
-						'Content-type'  => 'application/json',
703
-					),
704
-
705
-				)
706
-			);
707
-
708
-			if ( is_wp_error( $user_info ) ) {
709
-				getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
710
-			} else {
711
-
712
-				// Create application.
713
-				$user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
714
-
715
-				if ( $sandbox ) {
716
-					wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
717
-					wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
718
-					set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
719
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
720
-				} else {
721
-					wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
722
-					wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
723
-					set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
724
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
725
-				}
672
+    /**
673
+     * Connects to PayPal.
674
+     *
675
+     * @param array $data Connection data.
676
+     * @return void
677
+     */
678
+    public function connect_paypal( $data ) {
679
+
680
+        $sandbox      = $this->is_sandbox();
681
+        $data         = wp_unslash( $data );
682
+        $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
683
+
684
+        if ( isset( $data['live_mode'] ) ) {
685
+            $sandbox = empty( $data['live_mode'] );
686
+        }
687
+
688
+        wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
689
+        wpinv_update_option( 'paypal_active', 1 );
690
+
691
+        if ( ! empty( $data['error_description'] ) ) {
692
+            getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
693
+        } else {
694
+
695
+            // Retrieve the user info.
696
+            $user_info = wp_remote_get(
697
+                ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
698
+                array(
699
+
700
+                    'headers' => array(
701
+                        'Authorization' => 'Bearer ' . $access_token,
702
+                        'Content-type'  => 'application/json',
703
+                    ),
704
+
705
+                )
706
+            );
707
+
708
+            if ( is_wp_error( $user_info ) ) {
709
+                getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
710
+            } else {
711
+
712
+                // Create application.
713
+                $user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
714
+
715
+                if ( $sandbox ) {
716
+                    wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
717
+                    wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
718
+                    set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
719
+                    getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
720
+                } else {
721
+                    wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
722
+                    wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
723
+                    set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
724
+                    getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
725
+                }
726 726
 }
727 727
 }
728 728
 
729
-		$redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
729
+        $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
730 730
 
731
-		if ( isset( $data['step'] ) ) {
732
-			$redirect = add_query_arg( 'step', $data['step'], $redirect );
733
-		}
734
-		wp_redirect( $redirect );
735
-		exit;
736
-	}
731
+        if ( isset( $data['step'] ) ) {
732
+            $redirect = add_query_arg( 'step', $data['step'], $redirect );
733
+        }
734
+        wp_redirect( $redirect );
735
+        exit;
736
+    }
737 737
 
738 738
 }
Please login to merge, or discard this patch.
Spacing   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Paypal Payment Gateway class.
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @var array
26 26
 	 */
27
-    protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' );
27
+    protected $supports = array('subscription', 'sandbox', 'single_subscription_group');
28 28
 
29 29
     /**
30 30
 	 * Payment method order.
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	 *
60 60
 	 * @var array
61 61
 	 */
62
-	public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
62
+	public $currencies = array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR');
63 63
 
64 64
     /**
65 65
 	 * URL to view a transaction.
@@ -80,17 +80,17 @@  discard block
 block discarded – undo
80 80
 	 */
81 81
 	public function __construct() {
82 82
 
83
-        $this->title                = __( 'PayPal Standard', 'invoicing' );
84
-        $this->method_title         = __( 'PayPal Standard', 'invoicing' );
85
-        $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' );
86
-        $this->notify_url           = wpinv_get_ipn_url( $this->id );
87
-
88
-		add_filter( 'wpinv_subscription_cancel_url', array( $this, 'filter_cancel_subscription_url' ), 10, 2 );
89
-		add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 );
90
-        add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) );
91
-		add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 );
92
-		add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) );
93
-		add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) );
83
+        $this->title                = __('PayPal Standard', 'invoicing');
84
+        $this->method_title         = __('PayPal Standard', 'invoicing');
85
+        $this->checkout_button_text = __('Proceed to PayPal', 'invoicing');
86
+        $this->notify_url           = wpinv_get_ipn_url($this->id);
87
+
88
+		add_filter('wpinv_subscription_cancel_url', array($this, 'filter_cancel_subscription_url'), 10, 2);
89
+		add_filter('getpaid_paypal_args', array($this, 'process_subscription'), 10, 2);
90
+        add_filter('getpaid_paypal_sandbox_notice', array($this, 'sandbox_notice'));
91
+		add_filter('getpaid_get_paypal_connect_url', array($this, 'maybe_get_connect_url'), 10, 2);
92
+		add_action('getpaid_authenticated_admin_action_connect_paypal', array($this, 'connect_paypal'));
93
+		add_action('wpinv_paypal_connect', array($this, 'display_connect_buttons'));
94 94
 		parent::__construct();
95 95
     }
96 96
 
@@ -103,16 +103,16 @@  discard block
 block discarded – undo
103 103
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
104 104
 	 * @return array
105 105
 	 */
106
-	public function process_payment( $invoice, $submission_data, $submission ) {
106
+	public function process_payment($invoice, $submission_data, $submission) {
107 107
 
108 108
         // Get redirect url.
109
-        $paypal_redirect = $this->get_request_url( $invoice );
109
+        $paypal_redirect = $this->get_request_url($invoice);
110 110
 
111 111
         // Add a note about the request url.
112 112
         $invoice->add_note(
113 113
             sprintf(
114
-                __( 'Redirecting to PayPal: %s', 'invoicing' ),
115
-                esc_url( $paypal_redirect )
114
+                __('Redirecting to PayPal: %s', 'invoicing'),
115
+                esc_url($paypal_redirect)
116 116
             ),
117 117
             false,
118 118
             false,
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
         );
121 121
 
122 122
         // Redirect to PayPal
123
-        wp_redirect( $paypal_redirect );
123
+        wp_redirect($paypal_redirect);
124 124
         exit;
125 125
 
126 126
     }
@@ -131,21 +131,21 @@  discard block
 block discarded – undo
131 131
 	 * @param  WPInv_Invoice $invoice Invoice object.
132 132
 	 * @return string
133 133
 	 */
134
-	public function get_request_url( $invoice ) {
134
+	public function get_request_url($invoice) {
135 135
 
136 136
         // Endpoint for this request
137
-		$this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
137
+		$this->endpoint = $this->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
138 138
 
139 139
         // Retrieve paypal args.
140
-        $paypal_args       = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' );
140
+        $paypal_args = map_deep($this->get_paypal_args($invoice), 'urlencode');
141 141
 
142
-        if ( $invoice->is_recurring() ) {
142
+        if ($invoice->is_recurring()) {
143 143
             $paypal_args['bn'] = 'GetPaid_Subscribe_WPS_US';
144 144
         } else {
145 145
             $paypal_args['bn'] = 'GetPaid_ShoppingCart_WPS_US';
146 146
         }
147 147
 
148
-        return add_query_arg( $paypal_args, $this->endpoint );
148
+        return add_query_arg($paypal_args, $this->endpoint);
149 149
 
150 150
 	}
151 151
 
@@ -155,25 +155,25 @@  discard block
 block discarded – undo
155 155
 	 * @param  WPInv_Invoice $invoice Invoice object.
156 156
 	 * @return array
157 157
 	 */
158
-	protected function get_paypal_args( $invoice ) {
158
+	protected function get_paypal_args($invoice) {
159 159
 
160 160
         // Whether or not to send the line items as one item.
161
-		$force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice );
161
+		$force_one_line_item = apply_filters('getpaid_paypal_force_one_line_item', true, $invoice);
162 162
 
163
-		if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
163
+		if ($invoice->is_recurring() || (wpinv_use_taxes() && wpinv_prices_include_tax())) {
164 164
 			$force_one_line_item = true;
165 165
 		}
166 166
 
167 167
 		$paypal_args = apply_filters(
168 168
 			'getpaid_paypal_args',
169 169
 			array_merge(
170
-				$this->get_transaction_args( $invoice ),
171
-				$this->get_line_item_args( $invoice, $force_one_line_item )
170
+				$this->get_transaction_args($invoice),
171
+				$this->get_line_item_args($invoice, $force_one_line_item)
172 172
 			),
173 173
 			$invoice
174 174
 		);
175 175
 
176
-		return $this->fix_request_length( $invoice, $paypal_args );
176
+		return $this->fix_request_length($invoice, $paypal_args);
177 177
     }
178 178
 
179 179
     /**
@@ -182,9 +182,9 @@  discard block
 block discarded – undo
182 182
 	 * @param WPInv_Invoice $invoice Invoice object.
183 183
 	 * @return array
184 184
 	 */
185
-	protected function get_transaction_args( $invoice ) {
185
+	protected function get_transaction_args($invoice) {
186 186
 
187
-		$email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' );
187
+		$email = $this->is_sandbox($invoice) ? wpinv_get_option('paypal_sandbox_email', wpinv_get_option('paypal_email', '')) : wpinv_get_option('paypal_email', '');
188 188
 		return array(
189 189
             'cmd'           => '_cart',
190 190
             'business'      => $email,
@@ -195,16 +195,16 @@  discard block
 block discarded – undo
195 195
             'rm'            => is_ssl() ? 2 : 1,
196 196
             'upload'        => 1,
197 197
             'currency_code' => $invoice->get_currency(), // https://developer.paypal.com/docs/nvp-soap-api/currency-codes/#paypal
198
-            'return'        => esc_url_raw( $this->get_return_url( $invoice ) ),
199
-            'cancel_return' => esc_url_raw( $invoice->get_checkout_payment_url() ),
200
-            'notify_url'    => getpaid_limit_length( $this->notify_url, 255 ),
201
-            'invoice'       => getpaid_limit_length( $invoice->get_number(), 127 ),
198
+            'return'        => esc_url_raw($this->get_return_url($invoice)),
199
+            'cancel_return' => esc_url_raw($invoice->get_checkout_payment_url()),
200
+            'notify_url'    => getpaid_limit_length($this->notify_url, 255),
201
+            'invoice'       => getpaid_limit_length($invoice->get_number(), 127),
202 202
             'custom'        => $invoice->get_id(),
203
-            'first_name'    => getpaid_limit_length( $invoice->get_first_name(), 32 ),
204
-            'last_name'     => getpaid_limit_length( $invoice->get_last_name(), 64 ),
205
-            'country'       => getpaid_limit_length( $invoice->get_country(), 2 ),
206
-            'email'         => getpaid_limit_length( $invoice->get_email(), 127 ),
207
-            'cbt'           => get_bloginfo( 'name' ),
203
+            'first_name'    => getpaid_limit_length($invoice->get_first_name(), 32),
204
+            'last_name'     => getpaid_limit_length($invoice->get_last_name(), 64),
205
+            'country'       => getpaid_limit_length($invoice->get_country(), 2),
206
+            'email'         => getpaid_limit_length($invoice->get_email(), 127),
207
+            'cbt'           => get_bloginfo('name'),
208 208
         );
209 209
 
210 210
     }
@@ -216,30 +216,30 @@  discard block
 block discarded – undo
216 216
 	 * @param  bool     $force_one_line_item Create only one item for this invoice.
217 217
 	 * @return array
218 218
 	 */
219
-	protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
219
+	protected function get_line_item_args($invoice, $force_one_line_item = false) {
220 220
 
221 221
         // Maybe send invoice as a single item.
222
-		if ( $force_one_line_item ) {
223
-            return $this->get_line_item_args_single_item( $invoice );
222
+		if ($force_one_line_item) {
223
+            return $this->get_line_item_args_single_item($invoice);
224 224
         }
225 225
 
226 226
         // Send each line item individually.
227 227
         $line_item_args = array();
228 228
 
229 229
         // Prepare line items.
230
-        $this->prepare_line_items( $invoice );
230
+        $this->prepare_line_items($invoice);
231 231
 
232 232
         // Add taxes to the cart
233
-        if ( wpinv_use_taxes() && $invoice->is_taxable() ) {
234
-            $line_item_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_tax(), 2 );
233
+        if (wpinv_use_taxes() && $invoice->is_taxable()) {
234
+            $line_item_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_tax(), 2);
235 235
         }
236 236
 
237 237
         // Add discount.
238
-        if ( $invoice->get_total_discount() > 0 ) {
239
-            $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 );
238
+        if ($invoice->get_total_discount() > 0) {
239
+            $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_discount(), 2);
240 240
         }
241 241
 
242
-		return array_merge( $line_item_args, $this->get_line_items() );
242
+		return array_merge($line_item_args, $this->get_line_items());
243 243
 
244 244
     }
245 245
 
@@ -249,11 +249,11 @@  discard block
 block discarded – undo
249 249
 	 * @param  WPInv_Invoice $invoice Invoice object.
250 250
 	 * @return array
251 251
 	 */
252
-	protected function get_line_item_args_single_item( $invoice ) {
252
+	protected function get_line_item_args_single_item($invoice) {
253 253
 		$this->delete_line_items();
254 254
 
255
-        $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
256
-		$this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() );
255
+        $item_name = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number());
256
+		$this->add_line_item($item_name, 1, wpinv_round_amount((float) $invoice->get_total(), 2, true), $invoice->get_id());
257 257
 
258 258
 		return $this->get_line_items();
259 259
     }
@@ -277,19 +277,19 @@  discard block
 block discarded – undo
277 277
 	 *
278 278
 	 * @param  WPInv_Invoice $invoice Invoice object.
279 279
 	 */
280
-	protected function prepare_line_items( $invoice ) {
280
+	protected function prepare_line_items($invoice) {
281 281
 		$this->delete_line_items();
282 282
 
283 283
 		// Items.
284
-		foreach ( $invoice->get_items() as $item ) {
284
+		foreach ($invoice->get_items() as $item) {
285 285
 			$amount   = $item->get_price();
286 286
 			$quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
287
-			$this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
287
+			$this->add_line_item($item->get_raw_name(), $quantity, $amount, $item->get_id());
288 288
         }
289 289
 
290 290
         // Fees.
291
-		foreach ( $invoice->get_fees() as $fee => $data ) {
292
-            $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) );
291
+		foreach ($invoice->get_fees() as $fee => $data) {
292
+            $this->add_line_item($fee, 1, wpinv_sanitize_amount($data['initial_fee']));
293 293
         }
294 294
 
295 295
     }
@@ -302,15 +302,15 @@  discard block
 block discarded – undo
302 302
 	 * @param  float  $amount Amount.
303 303
 	 * @param  string $item_number Item number.
304 304
 	 */
305
-	protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
306
-		$index = ( count( $this->line_items ) / 4 ) + 1;
305
+	protected function add_line_item($item_name, $quantity = 1, $amount = 0.0, $item_number = '') {
306
+		$index = (count($this->line_items) / 4) + 1;
307 307
 
308 308
 		$item = apply_filters(
309 309
 			'getpaid_paypal_line_item',
310 310
 			array(
311
-				'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
311
+				'item_name'   => html_entity_decode(getpaid_limit_length($item_name ? wp_strip_all_tags($item_name) : __('Item', 'invoicing'), 127), ENT_NOQUOTES, 'UTF-8'),
312 312
 				'quantity'    => (float) $quantity,
313
-				'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
313
+				'amount'      => wpinv_sanitize_amount((float) $amount, 2),
314 314
 				'item_number' => $item_number,
315 315
 			),
316 316
 			$item_name,
@@ -319,12 +319,12 @@  discard block
 block discarded – undo
319 319
 			$item_number
320 320
 		);
321 321
 
322
-		$this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
323
-        $this->line_items[ 'quantity_' . $index ]    = $item['quantity'];
322
+		$this->line_items['item_name_' . $index] = getpaid_limit_length($item['item_name'], 127);
323
+        $this->line_items['quantity_' . $index] = $item['quantity'];
324 324
 
325 325
         // The price or amount of the product, service, or contribution, not including shipping, handling, or tax.
326
-		$this->line_items[ 'amount_' . $index ]      = $item['amount'] * $item['quantity'];
327
-		$this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
326
+		$this->line_items['amount_' . $index]      = $item['amount'] * $item['quantity'];
327
+		$this->line_items['item_number_' . $index] = getpaid_limit_length($item['item_number'], 127);
328 328
     }
329 329
 
330 330
     /**
@@ -336,19 +336,19 @@  discard block
 block discarded – undo
336 336
 	 * @param array    $paypal_args Arguments sent to Paypal in the request.
337 337
 	 * @return array
338 338
 	 */
339
-	protected function fix_request_length( $invoice, $paypal_args ) {
339
+	protected function fix_request_length($invoice, $paypal_args) {
340 340
 		$max_paypal_length = 2083;
341
-		$query_candidate   = http_build_query( $paypal_args, '', '&' );
341
+		$query_candidate   = http_build_query($paypal_args, '', '&');
342 342
 
343
-		if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
343
+		if (strlen($this->endpoint . $query_candidate) <= $max_paypal_length) {
344 344
 			return $paypal_args;
345 345
 		}
346 346
 
347 347
 		return apply_filters(
348 348
 			'getpaid_paypal_args',
349 349
 			array_merge(
350
-				$this->get_transaction_args( $invoice ),
351
-				$this->get_line_item_args( $invoice, true )
350
+				$this->get_transaction_args($invoice),
351
+				$this->get_line_item_args($invoice, true)
352 352
 			),
353 353
 			$invoice
354 354
 		);
@@ -361,10 +361,10 @@  discard block
 block discarded – undo
361 361
 	 * @param  array $paypal_args PayPal args.
362 362
 	 * @param  WPInv_Invoice    $invoice Invoice object.
363 363
 	 */
364
-	public function process_subscription( $paypal_args, $invoice ) {
364
+	public function process_subscription($paypal_args, $invoice) {
365 365
 
366 366
         // Make sure this is a subscription.
367
-        if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) {
367
+        if (!$invoice->is_recurring() || !$subscription = getpaid_get_invoice_subscription($invoice)) {
368 368
             return $paypal_args;
369 369
         }
370 370
 
@@ -372,23 +372,23 @@  discard block
 block discarded – undo
372 372
         $paypal_args['cmd'] = '_xclick-subscriptions';
373 373
 
374 374
         // Subscription name.
375
-        $paypal_args['item_name'] = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
375
+        $paypal_args['item_name'] = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number());
376 376
 
377 377
         // Get subscription args.
378
-        $period                 = strtoupper( substr( $subscription->get_period(), 0, 1 ) );
378
+        $period                 = strtoupper(substr($subscription->get_period(), 0, 1));
379 379
         $interval               = (int) $subscription->get_frequency();
380 380
         $bill_times             = (int) $subscription->get_bill_times();
381
-        $initial_amount         = (float) wpinv_sanitize_amount( $invoice->get_initial_total(), 2 );
382
-        $recurring_amount       = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 );
383
-        $subscription_item      = $invoice->get_recurring( true );
381
+        $initial_amount         = (float) wpinv_sanitize_amount($invoice->get_initial_total(), 2);
382
+        $recurring_amount       = (float) wpinv_sanitize_amount($invoice->get_recurring_total(), 2);
383
+        $subscription_item      = $invoice->get_recurring(true);
384 384
 
385 385
 		// Convert 365 days to 1 year.
386
-		if ( 'D' == $period && 365 == $interval ) {
386
+		if ('D' == $period && 365 == $interval) {
387 387
 			$period = 'Y';
388 388
 			$interval = 1;
389 389
 		}
390 390
 
391
-        if ( $subscription_item->has_free_trial() ) {
391
+        if ($subscription_item->has_free_trial()) {
392 392
 
393 393
             $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount;
394 394
 
@@ -398,28 +398,28 @@  discard block
 block discarded – undo
398 398
 			// Trial period.
399 399
 			$paypal_args['t1'] = $subscription_item->get_trial_period();
400 400
 
401
-        } elseif ( $initial_amount != $recurring_amount ) {
401
+        } elseif ($initial_amount != $recurring_amount) {
402 402
 
403 403
             // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period.
404 404
 
405
-            if ( 1 == $bill_times ) {
405
+            if (1 == $bill_times) {
406 406
                 $param_number = 3;
407 407
             } else {
408 408
                 $param_number = 1;
409 409
             }
410 410
 
411
-            $paypal_args[ 'a' . $param_number ] = $initial_amount ? $initial_amount : 0;
411
+            $paypal_args['a' . $param_number] = $initial_amount ? $initial_amount : 0;
412 412
 
413 413
             // Sign Up interval
414
-            $paypal_args[ 'p' . $param_number ] = $interval;
414
+            $paypal_args['p' . $param_number] = $interval;
415 415
 
416 416
             // Sign Up unit of duration
417
-            $paypal_args[ 't' . $param_number ] = $period;
417
+            $paypal_args['t' . $param_number] = $period;
418 418
 
419 419
         }
420 420
 
421 421
         // We have a recurring payment
422
-		if ( ! isset( $param_number ) || 1 == $param_number ) {
422
+		if (!isset($param_number) || 1 == $param_number) {
423 423
 
424 424
 			// Subscription price
425 425
 			$paypal_args['a3'] = $recurring_amount;
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
         }
434 434
 
435 435
         // Recurring payments
436
-		if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
436
+		if (1 == $bill_times || ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial() && 2 == $bill_times)) {
437 437
 
438 438
 			// Non-recurring payments
439 439
 			$paypal_args['src'] = 0;
@@ -442,15 +442,15 @@  discard block
 block discarded – undo
442 442
 
443 443
 			$paypal_args['src'] = 1;
444 444
 
445
-			if ( $bill_times > 0 ) {
445
+			if ($bill_times > 0) {
446 446
 
447 447
 				// An initial period is being used to charge a sign-up fee
448
-				if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
448
+				if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) {
449 449
 					$bill_times--;
450 450
 				}
451 451
 
452 452
                 // Make sure it's not over the max of 52
453
-                $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
453
+                $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52);
454 454
 
455 455
 			}
456 456
         }
@@ -459,10 +459,10 @@  discard block
 block discarded – undo
459 459
         $paypal_args['rm'] = 2;
460 460
 
461 461
         // Get rid of redudant items.
462
-        foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) {
462
+        foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) {
463 463
 
464
-            if ( isset( $paypal_args[ $arg ] ) ) {
465
-                unset( $paypal_args[ $arg ] );
464
+            if (isset($paypal_args[$arg])) {
465
+                unset($paypal_args[$arg]);
466 466
             }
467 467
 }
468 468
 
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 	 * @return void
481 481
 	 */
482 482
 	public function verify_ipn() {
483
-        new GetPaid_Paypal_Gateway_IPN_Handler( $this );
483
+        new GetPaid_Paypal_Gateway_IPN_Handler($this);
484 484
     }
485 485
 
486 486
     /**
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
     public function sandbox_notice() {
490 490
 
491 491
         return sprintf(
492
-			__( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ),
492
+			__('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing'),
493 493
 			'<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
494 494
 			'</a>'
495 495
 		);
@@ -501,49 +501,49 @@  discard block
 block discarded – undo
501 501
 	 *
502 502
 	 * @param array $admin_settings
503 503
 	 */
504
-	public function admin_settings( $admin_settings ) {
504
+	public function admin_settings($admin_settings) {
505 505
 
506 506
         $currencies = sprintf(
507
-            __( 'Supported Currencies: %s', 'invoicing' ),
508
-            implode( ', ', $this->currencies )
507
+            __('Supported Currencies: %s', 'invoicing'),
508
+            implode(', ', $this->currencies)
509 509
         );
510 510
 
511 511
         $admin_settings['paypal_active']['desc'] .= " ($currencies)";
512
-        $admin_settings['paypal_desc']['std']     = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
512
+        $admin_settings['paypal_desc']['std']     = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing');
513 513
 
514 514
 		// Access tokens.
515
-		$live_email      = wpinv_get_option( 'paypal_email' );
516
-		$sandbox_email   = wpinv_get_option( 'paypal_sandbox_email' );
515
+		$live_email      = wpinv_get_option('paypal_email');
516
+		$sandbox_email   = wpinv_get_option('paypal_sandbox_email');
517 517
 
518 518
 		$admin_settings['paypal_connect'] = array(
519 519
 			'type' => 'hook',
520 520
 			'id'   => 'paypal_connect',
521
-			'name' => __( 'Connect to PayPal', 'invoicing' ),
521
+			'name' => __('Connect to PayPal', 'invoicing'),
522 522
 		);
523 523
 
524 524
         $admin_settings['paypal_email'] = array(
525 525
             'type'  => 'text',
526 526
 			'class' => 'live-auth-data',
527 527
             'id'    => 'paypal_email',
528
-            'name'  => __( 'Live Email Address', 'invoicing' ),
529
-            'desc'  => __( 'The email address of your PayPal account.', 'invoicing' ),
528
+            'name'  => __('Live Email Address', 'invoicing'),
529
+            'desc'  => __('The email address of your PayPal account.', 'invoicing'),
530 530
         );
531 531
 
532 532
 		$admin_settings['paypal_sandbox_email'] = array(
533 533
             'type'  => 'text',
534 534
 			'class' => 'sandbox-auth-data',
535 535
             'id'    => 'paypal_sandbox_email',
536
-            'name'  => __( 'Sandbox Email Address', 'invoicing' ),
537
-            'desc'  => __( 'The email address of your sandbox PayPal account.', 'invoicing' ),
538
-			'std'   => wpinv_get_option( 'paypal_email', '' ),
536
+            'name'  => __('Sandbox Email Address', 'invoicing'),
537
+            'desc'  => __('The email address of your sandbox PayPal account.', 'invoicing'),
538
+			'std'   => wpinv_get_option('paypal_email', ''),
539 539
         );
540 540
 
541 541
         $admin_settings['paypal_ipn_url'] = array(
542 542
             'type'     => 'ipn_url',
543 543
             'id'       => 'paypal_ipn_url',
544
-            'name'     => __( 'IPN Url', 'invoicing' ),
544
+            'name'     => __('IPN Url', 'invoicing'),
545 545
             'std'      => $this->notify_url,
546
-            'desc'     => __( "If you've not enabled IPNs in your paypal account, use the above URL to enable them.", 'invoicing' ) . ' <a href="https://developer.paypal.com/docs/api-basics/notifications/ipn/"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
546
+            'desc'     => __("If you've not enabled IPNs in your paypal account, use the above URL to enable them.", 'invoicing') . ' <a href="https://developer.paypal.com/docs/api-basics/notifications/ipn/"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
547 547
             'readonly' => true,
548 548
         );
549 549
 
@@ -556,9 +556,9 @@  discard block
 block discarded – undo
556 556
 	 * @param string $url
557 557
 	 * @param WPInv_Subscription $subscription
558 558
 	 */
559
-	public function filter_cancel_subscription_url( $url, $subscription ) {
559
+	public function filter_cancel_subscription_url($url, $subscription) {
560 560
 
561
-		if ( $this->id !== $subscription->get_gateway() ) {
561
+		if ($this->id !== $subscription->get_gateway()) {
562 562
 			return $url;
563 563
 		}
564 564
 
@@ -566,16 +566,16 @@  discard block
 block discarded – undo
566 566
 		$profile_id = $subscription->get_profile_id();
567 567
 
568 568
 		// Bail if no profile ID.
569
-		if ( empty( $profile_id ) ) {
569
+		if (empty($profile_id)) {
570 570
 			return $url;
571 571
 		}
572 572
 
573 573
 		$cancel_url = 'https://www.paypal.com/myaccount/autopay/connect/%s/cancel';
574
-		if ( $this->is_sandbox( $subscription->get_parent_payment() ) ) {
574
+		if ($this->is_sandbox($subscription->get_parent_payment())) {
575 575
 			$cancel_url = 'https://www.sandbox.paypal.com/myaccount/autopay/connect/%s/cancel';
576 576
 		}
577 577
 
578
-		return sprintf( $cancel_url, $profile_id );
578
+		return sprintf($cancel_url, $profile_id);
579 579
 	}
580 580
 
581 581
 	/**
@@ -585,8 +585,8 @@  discard block
 block discarded – undo
585 585
      * @param array $data
586 586
      * @return string
587 587
 	 */
588
-	public static function maybe_get_connect_url( $url = '', $data = array() ) {
589
-		return self::get_connect_url( false, urldecode( $data['redirect'] ) );
588
+	public static function maybe_get_connect_url($url = '', $data = array()) {
589
+		return self::get_connect_url(false, urldecode($data['redirect']));
590 590
 	}
591 591
 
592 592
 	/**
@@ -597,25 +597,25 @@  discard block
 block discarded – undo
597 597
 	 * @param string $redirect
598 598
      * @return string
599 599
 	 */
600
-	public static function get_connect_url( $is_sandbox, $redirect = '' ) {
600
+	public static function get_connect_url($is_sandbox, $redirect = '') {
601 601
 
602 602
         $redirect_url = add_query_arg(
603 603
             array(
604 604
                 'getpaid-admin-action' => 'connect_paypal',
605 605
                 'page'                 => 'wpinv-settings',
606
-                'live_mode'            => (int) empty( $is_sandbox ),
606
+                'live_mode'            => (int) empty($is_sandbox),
607 607
                 'tab'                  => 'gateways',
608 608
                 'section'              => 'paypal',
609
-                'getpaid-nonce'        => wp_create_nonce( 'getpaid-nonce' ),
610
-				'redirect'             => urlencode( $redirect ),
609
+                'getpaid-nonce'        => wp_create_nonce('getpaid-nonce'),
610
+				'redirect'             => urlencode($redirect),
611 611
             ),
612
-            admin_url( 'admin.php' )
612
+            admin_url('admin.php')
613 613
         );
614 614
 
615 615
         return add_query_arg(
616 616
             array(
617
-                'live_mode'    => (int) empty( $is_sandbox ),
618
-                'redirect_url' => urlencode( str_replace( '&amp;', '&', $redirect_url ) ),
617
+                'live_mode'    => (int) empty($is_sandbox),
618
+                'redirect_url' => urlencode(str_replace('&amp;', '&', $redirect_url)),
619 619
             ),
620 620
             'https://ayecode.io/oauth/paypal'
621 621
         );
@@ -631,10 +631,10 @@  discard block
 block discarded – undo
631 631
 
632 632
         ?>
633 633
 			<div class="wpinv-paypal-connect-live">
634
-				<a class="button button-primary" href="<?php echo esc_url( self::get_connect_url( false ) ); ?>"><?php esc_html_e( 'Connect to PayPal', 'invoicing' ); ?></a>
634
+				<a class="button button-primary" href="<?php echo esc_url(self::get_connect_url(false)); ?>"><?php esc_html_e('Connect to PayPal', 'invoicing'); ?></a>
635 635
 			</div>
636 636
 			<div class="wpinv-paypal-connect-sandbox">
637
-				<a class="button button-primary" href="<?php echo esc_url( self::get_connect_url( true ) ); ?>"><?php esc_html_e( 'Connect to PayPal Sandbox', 'invoicing' ); ?></a>
637
+				<a class="button button-primary" href="<?php echo esc_url(self::get_connect_url(true)); ?>"><?php esc_html_e('Connect to PayPal Sandbox', 'invoicing'); ?></a>
638 638
 			</div>
639 639
 
640 640
             <script>
@@ -675,26 +675,26 @@  discard block
 block discarded – undo
675 675
 	 * @param array $data Connection data.
676 676
 	 * @return void
677 677
 	 */
678
-	public function connect_paypal( $data ) {
678
+	public function connect_paypal($data) {
679 679
 
680 680
 		$sandbox      = $this->is_sandbox();
681
-		$data         = wp_unslash( $data );
682
-		$access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] );
681
+		$data         = wp_unslash($data);
682
+		$access_token = empty($data['access_token']) ? '' : sanitize_text_field($data['access_token']);
683 683
 
684
-		if ( isset( $data['live_mode'] ) ) {
685
-			$sandbox = empty( $data['live_mode'] );
684
+		if (isset($data['live_mode'])) {
685
+			$sandbox = empty($data['live_mode']);
686 686
 		}
687 687
 
688
-		wpinv_update_option( 'paypal_sandbox', (int) $sandbox );
689
-		wpinv_update_option( 'paypal_active', 1 );
688
+		wpinv_update_option('paypal_sandbox', (int) $sandbox);
689
+		wpinv_update_option('paypal_active', 1);
690 690
 
691
-		if ( ! empty( $data['error_description'] ) ) {
692
-			getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) );
691
+		if (!empty($data['error_description'])) {
692
+			getpaid_admin()->show_error(wp_kses_post(urldecode($data['error_description'])));
693 693
 		} else {
694 694
 
695 695
 			// Retrieve the user info.
696 696
 			$user_info = wp_remote_get(
697
-				! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
697
+				!$sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1',
698 698
 				array(
699 699
 
700 700
 					'headers' => array(
@@ -705,33 +705,33 @@  discard block
 block discarded – undo
705 705
 				)
706 706
 			);
707 707
 
708
-			if ( is_wp_error( $user_info ) ) {
709
-				getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) );
708
+			if (is_wp_error($user_info)) {
709
+				getpaid_admin()->show_error(wp_kses_post($user_info->get_error_message()));
710 710
 			} else {
711 711
 
712 712
 				// Create application.
713
-				$user_info = json_decode( wp_remote_retrieve_body( $user_info ) );
713
+				$user_info = json_decode(wp_remote_retrieve_body($user_info));
714 714
 
715
-				if ( $sandbox ) {
716
-					wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) );
717
-					wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
718
-					set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
719
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) );
715
+				if ($sandbox) {
716
+					wpinv_update_option('paypal_sandbox_email', sanitize_email($user_info->emails[0]->value));
717
+					wpinv_update_option('paypal_sandbox_refresh_token', sanitize_text_field(urldecode($data['refresh_token'])));
718
+					set_transient('getpaid_paypal_sandbox_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']);
719
+					getpaid_admin()->show_success(__('Successfully connected your PayPal sandbox account', 'invoicing'));
720 720
 				} else {
721
-					wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) );
722
-					wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) );
723
-					set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] );
724
-					getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) );
721
+					wpinv_update_option('paypal_email', sanitize_email($user_info->emails[0]->value));
722
+					wpinv_update_option('paypal_refresh_token', sanitize_text_field(urldecode($data['refresh_token'])));
723
+					set_transient('getpaid_paypal_access_token', sanitize_text_field(urldecode($data['access_token'])), (int) $data['expires_in']);
724
+					getpaid_admin()->show_success(__('Successfully connected your PayPal account', 'invoicing'));
725 725
 				}
726 726
 }
727 727
 }
728 728
 
729
-		$redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways&section=paypal' ) : urldecode( $data['redirect'] );
729
+		$redirect = empty($data['redirect']) ? admin_url('admin.php?page=wpinv-settings&tab=gateways&section=paypal') : urldecode($data['redirect']);
730 730
 
731
-		if ( isset( $data['step'] ) ) {
732
-			$redirect = add_query_arg( 'step', $data['step'], $redirect );
731
+		if (isset($data['step'])) {
732
+			$redirect = add_query_arg('step', $data['step'], $redirect);
733 733
 		}
734
-		wp_redirect( $redirect );
734
+		wp_redirect($redirect);
735 735
 		exit;
736 736
 	}
737 737
 
Please login to merge, or discard this patch.
includes/admin/html-admin-page-addons.php 2 patches
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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="' . esc_url( admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . esc_html( $label ) . '</a>';
19
-			}
20
-			do_action( 'wpi_addons_tabs' );
21
-			?>
17
+            foreach ( $tabs as $name => $label ) {
18
+                echo '<a href="' . esc_url( admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . esc_html( $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
 block discarded – undo
36 36
 					<h2><?php esc_html_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
 block discarded – undo
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
 block discarded – undo
65 65
 									<h3><?php esc_html_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
 block discarded – undo
81 81
 						<div class="testimonial-content">
82 82
 							<div class="t-image">
83 83
 								<?php
84
-									echo '<img src="' . esc_url( plugins_url( 'images/t-image2.png', dirname( __FILE__ ) ) ) . '" > ';
85
-								?>
84
+                                    echo '<img src="' . esc_url( 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
 block discarded – undo
101 101
 						<div class="testimonial-content">
102 102
 							<div class="t-image">
103 103
 								<?php
104
-									echo '<img src="' . esc_url( plugins_url( 'images/t-image1.png', dirname( __FILE__ ) ) ) . '" > ';
105
-								?>
104
+                                    echo '<img src="' . esc_url( plugins_url( 'images/t-image1.png', dirname( __FILE__ ) ) ) . '" > ';
105
+                                ?>
106 106
 							</div>
107 107
 							<div class="t-content">
108 108
 								<p>
@@ -126,26 +126,26 @@  discard block
 block discarded – undo
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
-				//print_r($addons);
134
-				?>
132
+            if ( $addons = $addon_obj->get_section_data( $current_tab ) ) :
133
+                //print_r($addons);
134
+                ?>
135 135
 				<ul class="wpi-products">
136 136
                 <?php
137 137
                 foreach ( $addons as $addon ) :
138 138
                         if ( 965 == $addon->info->id ) {
139 139
 continue;}// don't show quote add on
140
-						?>
140
+                        ?>
141 141
                         <li class="wpi-product">
142 142
 								<div class="wpi-product-title">
143 143
 									<h3>
144 144
                                     <?php
145
-										if ( ! empty( $addon->info->excerpt ) ) {
146
-										wpi_help_tip( $addon->info->excerpt, false, false, true );
147
-										}
148
-										echo esc_html( $addon->info->title );
145
+                                        if ( ! empty( $addon->info->excerpt ) ) {
146
+                                        wpi_help_tip( $addon->info->excerpt, false, false, true );
147
+                                        }
148
+                                        echo esc_html( $addon->info->title );
149 149
                                         ?>
150 150
                                         </h3>
151 151
 								</div>
@@ -156,32 +156,32 @@  discard block
 block discarded – undo
156 156
 									<?php
157 157
                                     endif;
158 158
 
159
-									if ( 'stripe-payment-gateway' == $addon->info->slug ) {
160
-										$addon->info->slug = 'getpaid-stripe-payments';
161
-										$addon->info->link = 'https://wordpress.org/plugins/getpaid-stripe-payments/';
162
-									}
163
-
164
-									if ( isset( $addon->info->link ) && substr( $addon->info->link, 0, 21 ) === 'https://wordpress.org' ) {
165
-										echo '<a href="' . esc_url( admin_url( '/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug ) ) . '&width=770&height=660&TB_iframe=true" class="thickbox" >';
166
-										echo '<span class="wpi-product-info">' . esc_html__( 'More info', 'invoicing' ) . '</span>';
167
-										echo '</a>';
168
-									} elseif ( isset( $addon->info->link ) && ( substr( $addon->info->link, 0, 23 ) === 'https://wpinvoicing.com' || substr( $addon->info->link, 0, 21 ) === 'https://wpgetpaid.com' ) ) {
169
-										if ( defined( 'WP_EASY_UPDATES_ACTIVE' ) ) {
170
-											$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://wpgetpaid.com&TB_iframe=true' );
171
-										} else {
172
-											// if installed show activation link
173
-											if ( isset( $installed_plugins['wp-easy-updates/external-updates.php'] ) ) {
174
-												$url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation';
175
-											} else {
176
-												$url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external';
177
-											}
178
-										}
179
-										echo '<a href="' . esc_url( $url ) . '" class="thickbox">';
180
-										echo '<span class="wpi-product-info">' . esc_html__( 'More info', 'invoicing' ) . '</span>';
181
-										echo '</a>';
182
-									}
183
-
184
-									?>
159
+                                    if ( 'stripe-payment-gateway' == $addon->info->slug ) {
160
+                                        $addon->info->slug = 'getpaid-stripe-payments';
161
+                                        $addon->info->link = 'https://wordpress.org/plugins/getpaid-stripe-payments/';
162
+                                    }
163
+
164
+                                    if ( isset( $addon->info->link ) && substr( $addon->info->link, 0, 21 ) === 'https://wordpress.org' ) {
165
+                                        echo '<a href="' . esc_url( admin_url( '/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug ) ) . '&width=770&height=660&TB_iframe=true" class="thickbox" >';
166
+                                        echo '<span class="wpi-product-info">' . esc_html__( 'More info', 'invoicing' ) . '</span>';
167
+                                        echo '</a>';
168
+                                    } elseif ( isset( $addon->info->link ) && ( substr( $addon->info->link, 0, 23 ) === 'https://wpinvoicing.com' || substr( $addon->info->link, 0, 21 ) === 'https://wpgetpaid.com' ) ) {
169
+                                        if ( defined( 'WP_EASY_UPDATES_ACTIVE' ) ) {
170
+                                            $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://wpgetpaid.com&TB_iframe=true' );
171
+                                        } else {
172
+                                            // if installed show activation link
173
+                                            if ( isset( $installed_plugins['wp-easy-updates/external-updates.php'] ) ) {
174
+                                                $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation';
175
+                                            } else {
176
+                                                $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external';
177
+                                            }
178
+                                        }
179
+                                        echo '<a href="' . esc_url( $url ) . '" class="thickbox">';
180
+                                        echo '<span class="wpi-product-info">' . esc_html__( 'More info', 'invoicing' ) . '</span>';
181
+                                        echo '</a>';
182
+                                    }
183
+
184
+                                    ?>
185 185
 
186 186
 								</span>
187 187
 
@@ -189,15 +189,15 @@  discard block
 block discarded – undo
189 189
 								<span class="wpi-product-button">
190 190
 									<?php
191 191
                                     $addon_obj->output_button( $addon );
192
-									?>
192
+                                    ?>
193 193
 								</span>
194 194
 
195 195
 								<span class="wpi-price"><?php //print_r($addon); //echo wp_kses_post( $addon->price ); ?></span></li><?php endforeach; ?></ul>
196 196
 			<?php
197 197
             endif;
198
-		}
198
+        }
199 199
 }
200
-	?>
200
+    ?>
201 201
 
202 202
 
203 203
 	<div class="clearfix" ></div>
@@ -216,8 +216,8 @@  discard block
 block discarded – undo
216 216
 			<input class="wpeu-licence-key" type="text" placeholder="<?php esc_attr_e( 'Enter your licence key', 'invoicing' ); ?>"> <button class="button-primary wpeu-licence-popup-button" ><?php esc_html_e( 'Install', 'invoicing' ); ?></button>
217 217
 			<br>
218 218
 			<?php
219
-			printf( esc_html__( '%1$sFind your licence key here%2$s OR %3$sBuy one here%4$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>' );
220
-			?>
219
+            printf( esc_html__( '%1$sFind your licence key here%2$s OR %3$sBuy one here%4$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>' );
220
+            ?>
221 221
 		</span>
222 222
 	</div>
223 223
 
Please login to merge, or discard this patch.
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -3,27 +3,27 @@  discard block
 block discarded – undo
3 3
  * Admin View: Page - Addons
4 4
  *
5 5
  */
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
 	exit;
8 8
 }
9 9
 add_ThickBox();
10 10
 ?>
11 11
 <div class="wrap wpi_addons_wrap">
12
-	<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
12
+	<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
13 13
 
14
-	<?php if ( $tabs ) { ?>
14
+	<?php if ($tabs) { ?>
15 15
 		<nav class="nav-tab-wrapper wpi-nav-tab-wrapper">
16 16
 			<?php
17
-			foreach ( $tabs as $name => $label ) {
18
-				echo '<a href="' . esc_url( admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . esc_html( $label ) . '</a>';
17
+			foreach ($tabs as $name => $label) {
18
+				echo '<a href="' . esc_url(admin_url('admin.php?page=wpi-addons&tab=' . $name)) . '" class="nav-tab ' . ($current_tab == $name ? 'nav-tab-active' : '') . '">' . esc_html($label) . '</a>';
19 19
 			}
20
-			do_action( 'wpi_addons_tabs' );
20
+			do_action('wpi_addons_tabs');
21 21
 			?>
22 22
 		</nav>
23 23
 
24 24
 		<?php
25 25
 
26
-		if ( $current_tab == 'membership' ) {
26
+		if ($current_tab == 'membership') {
27 27
 
28 28
 			?>
29 29
 
@@ -32,42 +32,42 @@  discard block
 block discarded – undo
32 32
 <!--
33 33
 				<h2>With our WPInvoicing Membership you get access to all our products!</h2>
34 34
 				<p><a class="button button-primary" href="https://wpinvoicing.com/downloads/membership/">View Memberships</a></p>-->
35
-				<?php if ( defined( 'WP_EASY_UPDATES_ACTIVE' ) ) { ?>
36
-					<h2><?php esc_html_e( 'Have a membership key?', 'invoicing' ); ?></h2>
35
+				<?php if (defined('WP_EASY_UPDATES_ACTIVE')) { ?>
36
+					<h2><?php esc_html_e('Have a membership key?', 'invoicing'); ?></h2>
37 37
 					<p>
38 38
 						<?php
39
-						$wpeu_admin = new External_Updates_Admin( 'wpinvoicing.com', '1' );
40
-						echo $wpeu_admin->render_licence_actions( 'wpinvoicing.com', 'membership', array( 95, 106, 108, 12351 ) );
39
+						$wpeu_admin = new External_Updates_Admin('wpinvoicing.com', '1');
40
+						echo $wpeu_admin->render_licence_actions('wpinvoicing.com', 'membership', array(95, 106, 108, 12351));
41 41
 						?>
42 42
 					</p>
43 43
 				<?php } ?>
44 44
 
45 45
 				<div class="membership-cta-contet">
46 46
 					<div class="main-cta">
47
-							<h2><?php esc_html_e( 'Membership benefits Include:', 'invoicing' ); ?></h2>
47
+							<h2><?php esc_html_e('Membership benefits Include:', 'invoicing'); ?></h2>
48 48
 							<div class="feature-list">
49 49
 								<ul>
50 50
 									<?php
51 51
 									$addon_obj = new WPInv_Admin_Addons();
52
-									if ( $addons = $addon_obj->get_section_data( 'addons' ) ) {
53
-										foreach ( $addons as $addon ) {
54
-											echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html( $addon->info->title ) . '</li>';
52
+									if ($addons = $addon_obj->get_section_data('addons')) {
53
+										foreach ($addons as $addon) {
54
+											echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html($addon->info->title) . '</li>';
55 55
 										}
56 56
 									}
57 57
 									?>
58 58
 									</ul>
59 59
 
60 60
 									<div class="feature-cta">
61
-										<h3><?php esc_html_e( 'Membership Starts from', 'invoicing' ); ?></h3>
61
+										<h3><?php esc_html_e('Membership Starts from', 'invoicing'); ?></h3>
62 62
 										<h4>$99</h4>
63
-										<a href="https://wpinvoicing.com/downloads/membership/" target="_blank"><?php esc_attr_e( 'Buy Membership', 'invoicing' ); ?></a>
63
+										<a href="https://wpinvoicing.com/downloads/membership/" target="_blank"><?php esc_attr_e('Buy Membership', 'invoicing'); ?></a>
64 64
 									</div>
65
-									<h3><?php esc_html_e( 'Included Gateways:', 'invoicing' ); ?></h3>
65
+									<h3><?php esc_html_e('Included Gateways:', 'invoicing'); ?></h3>
66 66
 									<ul>
67 67
 										<?php
68
-										if ( $addons = $addon_obj->get_section_data( 'gateways' ) ) {
69
-											foreach ( $addons as $addon ) {
70
-												echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html( $addon->info->title ) . '</li>';
68
+										if ($addons = $addon_obj->get_section_data('gateways')) {
69
+											foreach ($addons as $addon) {
70
+												echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html($addon->info->title) . '</li>';
71 71
 											}
72 72
 										}
73 73
 										?>
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
 						<div class="testimonial-content">
82 82
 							<div class="t-image">
83 83
 								<?php
84
-									echo '<img src="' . esc_url( plugins_url( 'images/t-image2.png', dirname( __FILE__ ) ) ) . '" > ';
84
+									echo '<img src="' . esc_url(plugins_url('images/t-image2.png', dirname(__FILE__))) . '" > ';
85 85
 								?>
86 86
 							</div>
87 87
 							<div class="t-content">
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 						<div class="testimonial-content">
102 102
 							<div class="t-image">
103 103
 								<?php
104
-									echo '<img src="' . esc_url( plugins_url( 'images/t-image1.png', dirname( __FILE__ ) ) ) . '" > ';
104
+									echo '<img src="' . esc_url(plugins_url('images/t-image1.png', dirname(__FILE__))) . '" > ';
105 105
 								?>
106 106
 							</div>
107 107
 							<div class="t-content">
@@ -117,8 +117,8 @@  discard block
 block discarded – undo
117 117
 						</div>
118 118
 					</div>
119 119
 					<div class="member-footer">
120
-						<a class="footer-btn" href="https://wpinvoicing.com/downloads/membership/" target="_blank"><?php esc_html_e( 'Buy Membership', 'invoicing' ); ?></a>
121
-						<a class="footer-link" href="post-new.php?post_type=wpi_invoice"><?php esc_html_e( 'Create Invoice', 'invoicing' ); ?></a>
120
+						<a class="footer-btn" href="https://wpinvoicing.com/downloads/membership/" target="_blank"><?php esc_html_e('Buy Membership', 'invoicing'); ?></a>
121
+						<a class="footer-link" href="post-new.php?post_type=wpi_invoice"><?php esc_html_e('Create Invoice', 'invoicing'); ?></a>
122 122
 					</div>
123 123
 				</div>
124 124
 
@@ -129,55 +129,55 @@  discard block
 block discarded – undo
129 129
 		} else {
130 130
 			$installed_plugins = get_plugins();
131 131
             $addon_obj = new WPInv_Admin_Addons();
132
-			if ( $addons = $addon_obj->get_section_data( $current_tab ) ) :
132
+			if ($addons = $addon_obj->get_section_data($current_tab)) :
133 133
 				//print_r($addons);
134 134
 				?>
135 135
 				<ul class="wpi-products">
136 136
                 <?php
137
-                foreach ( $addons as $addon ) :
138
-                        if ( 965 == $addon->info->id ) {
139
-continue;}// don't show quote add on
137
+                foreach ($addons as $addon) :
138
+                        if (965 == $addon->info->id) {
139
+continue; }// don't show quote add on
140 140
 						?>
141 141
                         <li class="wpi-product">
142 142
 								<div class="wpi-product-title">
143 143
 									<h3>
144 144
                                     <?php
145
-										if ( ! empty( $addon->info->excerpt ) ) {
146
-										wpi_help_tip( $addon->info->excerpt, false, false, true );
145
+										if (!empty($addon->info->excerpt)) {
146
+										wpi_help_tip($addon->info->excerpt, false, false, true);
147 147
 										}
148
-										echo esc_html( $addon->info->title );
148
+										echo esc_html($addon->info->title);
149 149
                                         ?>
150 150
                                         </h3>
151 151
 								</div>
152 152
 
153 153
 								<span class="wpi-product-image">
154
-									<?php if ( ! empty( $addon->info->thumbnail ) ) : ?>
155
-										<img src="<?php echo esc_attr( $addon->info->thumbnail ); ?>"/>
154
+									<?php if (!empty($addon->info->thumbnail)) : ?>
155
+										<img src="<?php echo esc_attr($addon->info->thumbnail); ?>"/>
156 156
 									<?php
157 157
                                     endif;
158 158
 
159
-									if ( 'stripe-payment-gateway' == $addon->info->slug ) {
159
+									if ('stripe-payment-gateway' == $addon->info->slug) {
160 160
 										$addon->info->slug = 'getpaid-stripe-payments';
161 161
 										$addon->info->link = 'https://wordpress.org/plugins/getpaid-stripe-payments/';
162 162
 									}
163 163
 
164
-									if ( isset( $addon->info->link ) && substr( $addon->info->link, 0, 21 ) === 'https://wordpress.org' ) {
165
-										echo '<a href="' . esc_url( admin_url( '/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug ) ) . '&width=770&height=660&TB_iframe=true" class="thickbox" >';
166
-										echo '<span class="wpi-product-info">' . esc_html__( 'More info', 'invoicing' ) . '</span>';
164
+									if (isset($addon->info->link) && substr($addon->info->link, 0, 21) === 'https://wordpress.org') {
165
+										echo '<a href="' . esc_url(admin_url('/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug)) . '&width=770&height=660&TB_iframe=true" class="thickbox" >';
166
+										echo '<span class="wpi-product-info">' . esc_html__('More info', 'invoicing') . '</span>';
167 167
 										echo '</a>';
168
-									} elseif ( isset( $addon->info->link ) && ( substr( $addon->info->link, 0, 23 ) === 'https://wpinvoicing.com' || substr( $addon->info->link, 0, 21 ) === 'https://wpgetpaid.com' ) ) {
169
-										if ( defined( 'WP_EASY_UPDATES_ACTIVE' ) ) {
170
-											$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://wpgetpaid.com&TB_iframe=true' );
168
+									} elseif (isset($addon->info->link) && (substr($addon->info->link, 0, 23) === 'https://wpinvoicing.com' || substr($addon->info->link, 0, 21) === 'https://wpgetpaid.com')) {
169
+										if (defined('WP_EASY_UPDATES_ACTIVE')) {
170
+											$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://wpgetpaid.com&TB_iframe=true');
171 171
 										} else {
172 172
 											// if installed show activation link
173
-											if ( isset( $installed_plugins['wp-easy-updates/external-updates.php'] ) ) {
173
+											if (isset($installed_plugins['wp-easy-updates/external-updates.php'])) {
174 174
 												$url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation';
175 175
 											} else {
176 176
 												$url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external';
177 177
 											}
178 178
 										}
179
-										echo '<a href="' . esc_url( $url ) . '" class="thickbox">';
180
-										echo '<span class="wpi-product-info">' . esc_html__( 'More info', 'invoicing' ) . '</span>';
179
+										echo '<a href="' . esc_url($url) . '" class="thickbox">';
180
+										echo '<span class="wpi-product-info">' . esc_html__('More info', 'invoicing') . '</span>';
181 181
 										echo '</a>';
182 182
 									}
183 183
 
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 
189 189
 								<span class="wpi-product-button">
190 190
 									<?php
191
-                                    $addon_obj->output_button( $addon );
191
+                                    $addon_obj->output_button($addon);
192 192
 									?>
193 193
 								</span>
194 194
 
@@ -202,21 +202,21 @@  discard block
 block discarded – undo
202 202
 
203 203
 	<div class="clearfix" ></div>
204 204
 
205
-	<?php if ( $current_tab == 'addons' ) { ?>
206
-	<p><?php printf(  esc_attr__( 'All of our Addons can be found on wpGetPaid.com here: %sInvoicing Addons%s', 'invoicing' ), '<a href="https://wpinvoicing.com/downloads/category/addons/">','</a>' ); ?></p>
207
-	<?php } if ( $current_tab == 'gateways' ) { ?>
208
-    <p><?php printf( esc_attr__( 'All of our Payment Gateways can be found on wpGetPaid.com here: %sGetPaid Payment Gateways %s', 'invoicing' ), '<a href="https://wpinvoicing.com/downloads/category/gateways/">','</a>'  ); ?></p>
205
+	<?php if ($current_tab == 'addons') { ?>
206
+	<p><?php printf(esc_attr__('All of our Addons can be found on wpGetPaid.com here: %sInvoicing Addons%s', 'invoicing'), '<a href="https://wpinvoicing.com/downloads/category/addons/">', '</a>'); ?></p>
207
+	<?php } if ($current_tab == 'gateways') { ?>
208
+    <p><?php printf(esc_attr__('All of our Payment Gateways can be found on wpGetPaid.com here: %sGetPaid Payment Gateways %s', 'invoicing'), '<a href="https://wpinvoicing.com/downloads/category/gateways/">', '</a>'); ?></p>
209 209
     <?php } ?>
210 210
 
211
-	<div id="wpi-wpeu-required-activation" style="display:none;"><span class="wpi-notification "><?php echo wp_kses_post(  sprintf( __( "The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s'>activate</a> it now.", 'invoicing' ), wp_nonce_url( admin_url( 'plugins.php?action=activate&plugin=wp-easy-updates/external-updates.php' ), 'activate-plugin_wp-easy-updates/external-updates.php' ) ) ); ?></span></div>
212
-	<div id="wpi-wpeu-required-for-external" style="display:none;"><span class="wpi-notification "><?php echo wp_kses_post( sprintf( __( "The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s' onclick='window.open(\"https://wpeasyupdates.com/wp-easy-updates.zip\", \"_blank\");' >download</a> and install it now.", 'invoicing' ), admin_url( 'plugin-install.php?tab=upload&wpeu-install=true' ) ) ); ?></span></div>
211
+	<div id="wpi-wpeu-required-activation" style="display:none;"><span class="wpi-notification "><?php echo wp_kses_post(sprintf(__("The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s'>activate</a> it now.", 'invoicing'), wp_nonce_url(admin_url('plugins.php?action=activate&plugin=wp-easy-updates/external-updates.php'), 'activate-plugin_wp-easy-updates/external-updates.php'))); ?></span></div>
212
+	<div id="wpi-wpeu-required-for-external" style="display:none;"><span class="wpi-notification "><?php echo wp_kses_post(sprintf(__("The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s' onclick='window.open(\"https://wpeasyupdates.com/wp-easy-updates.zip\", \"_blank\");' >download</a> and install it now.", 'invoicing'), admin_url('plugin-install.php?tab=upload&wpeu-install=true'))); ?></span></div>
213 213
 	<div id="wpeu-licence-popup" style="display:none;">
214 214
 		<span class="wpi-notification noti-white">
215
-			<h3 class="wpeu-licence-title"><?php esc_html_e( 'Licence key', 'invoicing' ); ?></h3>
216
-			<input class="wpeu-licence-key" type="text" placeholder="<?php esc_attr_e( 'Enter your licence key', 'invoicing' ); ?>"> <button class="button-primary wpeu-licence-popup-button" ><?php esc_html_e( 'Install', 'invoicing' ); ?></button>
215
+			<h3 class="wpeu-licence-title"><?php esc_html_e('Licence key', 'invoicing'); ?></h3>
216
+			<input class="wpeu-licence-key" type="text" placeholder="<?php esc_attr_e('Enter your licence key', 'invoicing'); ?>"> <button class="button-primary wpeu-licence-popup-button" ><?php esc_html_e('Install', 'invoicing'); ?></button>
217 217
 			<br>
218 218
 			<?php
219
-			printf( esc_html__( '%1$sFind your licence key here%2$s OR %3$sBuy one here%4$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>' );
219
+			printf(esc_html__('%1$sFind your licence key here%2$s OR %3$sBuy one here%4$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>');
220 220
 			?>
221 221
 		</span>
222 222
 	</div>
Please login to merge, or discard this patch.
vendor/ayecode/wp-ayecode-ui/includes/inc/bs5-js.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -993,8 +993,8 @@
 block discarded – undo
993 993
     aui_flip_color_scheme_on_scroll();
994 994
 
995 995
 	<?php
996
-	// FSE tweaks.
997
-	if(!empty($_REQUEST['postType']) && $_REQUEST['postType']=='wp_template'){ ?>
996
+    // FSE tweaks.
997
+    if(!empty($_REQUEST['postType']) && $_REQUEST['postType']=='wp_template'){ ?>
998 998
     function aui_fse_set_data_scroll() {
999 999
         console.log('init scroll');
1000 1000
         let Iframe = document.getElementsByClassName("edit-site-visual-editor__editor-canvas");
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
     function aui_init_flatpickr(){
248 248
         if ( typeof jQuery.fn.flatpickr === "function" && !$aui_doing_init_flatpickr) {
249 249
             $aui_doing_init_flatpickr = true;
250
-			<?php if ( ! empty( $flatpickr_locale ) ) { ?>try{flatpickr.localize(<?php echo $flatpickr_locale; ?>);}catch(err){console.log(err.message);}<?php } ?>
250
+			<?php if (!empty($flatpickr_locale)) { ?>try{flatpickr.localize(<?php echo $flatpickr_locale; ?>);}catch(err){console.log(err.message);}<?php } ?>
251 251
             jQuery('input[data-aui-init="flatpickr"]:not(.flatpickr-input)').flatpickr();
252 252
         }
253 253
         $aui_doing_init_flatpickr = false;
@@ -994,7 +994,7 @@  discard block
 block discarded – undo
994 994
 
995 995
 	<?php
996 996
 	// FSE tweaks.
997
-	if(!empty($_REQUEST['postType']) && $_REQUEST['postType']=='wp_template'){ ?>
997
+	if (!empty($_REQUEST['postType']) && $_REQUEST['postType'] == 'wp_template') { ?>
998 998
     function aui_fse_set_data_scroll() {
999 999
         console.log('init scroll');
1000 1000
         let Iframe = document.getElementsByClassName("edit-site-visual-editor__editor-canvas");
Please login to merge, or discard this patch.
vendor/ayecode/wp-ayecode-ui/includes/inc/bs-conversion.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -13,10 +13,10 @@  discard block
 block discarded – undo
13 13
  *
14 14
  * @return array|mixed|string|string[]
15 15
  */
16
-function aui_bs_convert_sd_output( $output, $instance = '', $args = '', $sd = '' ) {
16
+function aui_bs_convert_sd_output($output, $instance = '', $args = '', $sd = '') {
17 17
 	global $aui_bs5;
18 18
 
19
-	if ( $aui_bs5 ) {
19
+	if ($aui_bs5) {
20 20
 
21 21
 		$convert = array(
22 22
 			'ml-'                   => 'ms-',
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
 			'class="close"' => 'class="btn-close"',
58 58
 			'<span aria-hidden="true">&times;</span>' => '',
59 59
 		);
60
-		$output  = str_replace(
61
-			array_keys( $convert ),
62
-			array_values( $convert ),
60
+		$output = str_replace(
61
+			array_keys($convert),
62
+			array_values($convert),
63 63
 			$output
64 64
 		);
65 65
 	}
@@ -67,4 +67,4 @@  discard block
 block discarded – undo
67 67
 	return $output;
68 68
 }
69 69
 
70
-add_filter( 'wp_super_duper_widget_output', 'aui_bs_convert_sd_output', 10, 4 ); //$output, $instance, $args, $this
70
+add_filter('wp_super_duper_widget_output', 'aui_bs_convert_sd_output', 10, 4); //$output, $instance, $args, $this
Please login to merge, or discard this patch.
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -14,64 +14,64 @@
 block discarded – undo
14 14
  * @return array|mixed|string|string[]
15 15
  */
16 16
 function aui_bs_convert_sd_output( $output, $instance = '', $args = '', $sd = '' ) {
17
-	global $aui_bs5;
17
+    global $aui_bs5;
18 18
 
19
-	if ( $aui_bs5 ) {
19
+    if ( $aui_bs5 ) {
20 20
 
21
-		$convert = array(
22
-			'ml-'                   => 'ms-',
23
-			'mr-'                   => 'me-',
24
-			'pl-'                   => 'ps-',
25
-			'pr-'                   => 'pe-',
26
-			' form-row'              => ' row',
27
-			' embed-responsive-item' => '',
28
-			' embed-responsive' => ' ratio',
29
-			'-1by1'    => '-1x1',
30
-			'-4by3'    => '-4x3',
31
-			'-16by9'    => '-16x9',
32
-			'-21by9'    => '-21x9',
33
-			'geodir-lightbox-image' => 'aui-lightbox-image',
34
-			' badge-'   => ' text-bg-',
35
-			'form-group'   => 'mb-3',
36
-			'custom-select'   => 'form-select',
37
-			'float-left'   => 'float-start',
38
-			'float-right'   => 'float-end',
39
-			'text-left'    => 'text-start',
40
-			'text-sm-left'    => 'text-sm-start',
41
-			'text-md-left'    => 'text-md-start',
42
-			'text-lg-left'    => 'text-lg-start',
43
-			'text-right'    => 'text-end',
44
-			'text-sm-right'    => 'text-sm-end',
45
-			'text-md-right'    => 'text-md-end',
46
-			'text-lg-right'    => 'text-lg-end',
47
-			'border-right'    => 'border-end',
48
-			'border-left'    => 'border-start',
49
-			'font-weight-'  => 'fw-',
50
-			'btn-block'     => 'w-100',
51
-			'rounded-left'  => 'rounded-start',
52
-			'rounded-right'  => 'rounded-end',
53
-			'font-italic' => 'fst-italic',
21
+        $convert = array(
22
+            'ml-'                   => 'ms-',
23
+            'mr-'                   => 'me-',
24
+            'pl-'                   => 'ps-',
25
+            'pr-'                   => 'pe-',
26
+            ' form-row'              => ' row',
27
+            ' embed-responsive-item' => '',
28
+            ' embed-responsive' => ' ratio',
29
+            '-1by1'    => '-1x1',
30
+            '-4by3'    => '-4x3',
31
+            '-16by9'    => '-16x9',
32
+            '-21by9'    => '-21x9',
33
+            'geodir-lightbox-image' => 'aui-lightbox-image',
34
+            ' badge-'   => ' text-bg-',
35
+            'form-group'   => 'mb-3',
36
+            'custom-select'   => 'form-select',
37
+            'float-left'   => 'float-start',
38
+            'float-right'   => 'float-end',
39
+            'text-left'    => 'text-start',
40
+            'text-sm-left'    => 'text-sm-start',
41
+            'text-md-left'    => 'text-md-start',
42
+            'text-lg-left'    => 'text-lg-start',
43
+            'text-right'    => 'text-end',
44
+            'text-sm-right'    => 'text-sm-end',
45
+            'text-md-right'    => 'text-md-end',
46
+            'text-lg-right'    => 'text-lg-end',
47
+            'border-right'    => 'border-end',
48
+            'border-left'    => 'border-start',
49
+            'font-weight-'  => 'fw-',
50
+            'btn-block'     => 'w-100',
51
+            'rounded-left'  => 'rounded-start',
52
+            'rounded-right'  => 'rounded-end',
53
+            'font-italic' => 'fst-italic',
54 54
 
55 55
 //			'custom-control custom-checkbox'    => 'form-check',
56
-			// data
57
-			' data-toggle=' => ' data-bs-toggle=',
58
-			'data-ride=' => 'data-bs-ride=',
59
-			'data-controlnav=' => 'data-bs-controlnav=',
60
-			'data-slide='   => 'data-bs-slide=',
61
-			'data-slide-to=' => 'data-bs-slide-to=',
62
-			'data-target='  => 'data-bs-target=',
63
-			'data-dismiss="modal"'  => 'data-bs-dismiss="modal"',
64
-			'class="close"' => 'class="btn-close"',
65
-			'<span aria-hidden="true">&times;</span>' => '',
66
-		);
67
-		$output  = str_replace(
68
-			array_keys( $convert ),
69
-			array_values( $convert ),
70
-			$output
71
-		);
72
-	}
56
+            // data
57
+            ' data-toggle=' => ' data-bs-toggle=',
58
+            'data-ride=' => 'data-bs-ride=',
59
+            'data-controlnav=' => 'data-bs-controlnav=',
60
+            'data-slide='   => 'data-bs-slide=',
61
+            'data-slide-to=' => 'data-bs-slide-to=',
62
+            'data-target='  => 'data-bs-target=',
63
+            'data-dismiss="modal"'  => 'data-bs-dismiss="modal"',
64
+            'class="close"' => 'class="btn-close"',
65
+            '<span aria-hidden="true">&times;</span>' => '',
66
+        );
67
+        $output  = str_replace(
68
+            array_keys( $convert ),
69
+            array_values( $convert ),
70
+            $output
71
+        );
72
+    }
73 73
 
74
-	return $output;
74
+    return $output;
75 75
 }
76 76
 
77 77
 add_filter( 'wp_super_duper_widget_output', 'aui_bs_convert_sd_output', 10, 4 ); //$output, $instance, $args, $this
Please login to merge, or discard this patch.
ayecode/wp-ayecode-ui/includes/components/class-aui-component-alert.php 3 patches
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if ( ! defined( 'ABSPATH' ) ) {
4
-	exit; // Exit if accessed directly
4
+    exit; // Exit if accessed directly
5 5
 }
6 6
 
7 7
 /**
@@ -11,87 +11,87 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class AUI_Component_Alert {
13 13
 
14
-	/**
15
-	 * Build the component.
16
-	 * 
17
-	 * @param array $args
18
-	 *
19
-	 * @return string The rendered component.
20
-	 */
21
-	public static function get($args = array()){
22
-		global $aui_bs5;
23
-		$defaults = array(
24
-			'type'       => 'info',
25
-			'class'      => '',
26
-			'icon' => '',
27
-			'heading'    => '',
28
-			'content'    => '',
29
-			'footer'     => '',
30
-			'dismissible'=> false,
31
-			'data'       => '',
32
-		);
33
-
34
-		/**
35
-		 * Parse incoming $args into an array and merge it with $defaults
36
-		 */
37
-		$args   = wp_parse_args( $args, $defaults );
38
-		$output = '';
39
-		if ( ! empty( $args['content'] ) ) {
40
-			$type = sanitize_html_class( $args['type'] );
41
-			if($type=='error'){$type='danger';}
42
-			$icon = !empty($args['icon']) ? "<i class='".esc_attr($args['icon'])."'></i>" : '';
43
-
44
-			// set default icon
45
-			if(!$icon && $args['icon']!==false && $type){
46
-				if($type=='danger'){$icon = '<i class="fas fa-exclamation-circle"></i>';}
47
-				elseif($type=='warning'){$icon = '<i class="fas fa-exclamation-triangle"></i>';}
48
-				elseif($type=='success'){$icon = '<i class="fas fa-check-circle"></i>';}
49
-				elseif($type=='info'){$icon = '<i class="fas fa-info-circle"></i>';}
50
-			}
51
-
52
-			$data = '';
53
-			$class = !empty($args['class']) ? esc_attr($args['class']) : '';
54
-			if($args['dismissible']){$class .= " alert-dismissible fade show";}
55
-
56
-			// open
57
-			$output .= '<div class="alert alert-' . $type . ' '.$class.'" role="alert" '.$data.'>';
58
-
59
-			// heading
60
-			if ( ! empty( $args['heading'] ) ) {
61
-				$output .= '<h4 class="alert-heading">' . $args['heading'] . '</h4>';
62
-			}
63
-
64
-			// icon
65
-			if ( ! empty( $icon) ) {
66
-				$output .= $icon." ";
67
-			}
68
-
69
-			// content
70
-			$output .= $args['content'];
71
-
72
-			// dismissible
73
-			if($args['dismissible']){
74
-
75
-				if ( $aui_bs5 ) {
76
-					$output .= '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>';
77
-				}else{
78
-					$output .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close">';
79
-					$output .= '<span aria-hidden="true">&times;</span>';
80
-					$output .= '</button>';
81
-				}
82
-			}
83
-
84
-			// footer
85
-			if ( ! empty( $args['footer'] ) ) {
86
-				$output .= '<hr>';
87
-				$output .= '<p class="mb-0">' . $args['footer'] . '</p>';
88
-			}
89
-
90
-			// close
91
-			$output .= '</div>';
92
-		}
93
-
94
-		return $output;
95
-	}
14
+    /**
15
+     * Build the component.
16
+     * 
17
+     * @param array $args
18
+     *
19
+     * @return string The rendered component.
20
+     */
21
+    public static function get($args = array()){
22
+        global $aui_bs5;
23
+        $defaults = array(
24
+            'type'       => 'info',
25
+            'class'      => '',
26
+            'icon' => '',
27
+            'heading'    => '',
28
+            'content'    => '',
29
+            'footer'     => '',
30
+            'dismissible'=> false,
31
+            'data'       => '',
32
+        );
33
+
34
+        /**
35
+         * Parse incoming $args into an array and merge it with $defaults
36
+         */
37
+        $args   = wp_parse_args( $args, $defaults );
38
+        $output = '';
39
+        if ( ! empty( $args['content'] ) ) {
40
+            $type = sanitize_html_class( $args['type'] );
41
+            if($type=='error'){$type='danger';}
42
+            $icon = !empty($args['icon']) ? "<i class='".esc_attr($args['icon'])."'></i>" : '';
43
+
44
+            // set default icon
45
+            if(!$icon && $args['icon']!==false && $type){
46
+                if($type=='danger'){$icon = '<i class="fas fa-exclamation-circle"></i>';}
47
+                elseif($type=='warning'){$icon = '<i class="fas fa-exclamation-triangle"></i>';}
48
+                elseif($type=='success'){$icon = '<i class="fas fa-check-circle"></i>';}
49
+                elseif($type=='info'){$icon = '<i class="fas fa-info-circle"></i>';}
50
+            }
51
+
52
+            $data = '';
53
+            $class = !empty($args['class']) ? esc_attr($args['class']) : '';
54
+            if($args['dismissible']){$class .= " alert-dismissible fade show";}
55
+
56
+            // open
57
+            $output .= '<div class="alert alert-' . $type . ' '.$class.'" role="alert" '.$data.'>';
58
+
59
+            // heading
60
+            if ( ! empty( $args['heading'] ) ) {
61
+                $output .= '<h4 class="alert-heading">' . $args['heading'] . '</h4>';
62
+            }
63
+
64
+            // icon
65
+            if ( ! empty( $icon) ) {
66
+                $output .= $icon." ";
67
+            }
68
+
69
+            // content
70
+            $output .= $args['content'];
71
+
72
+            // dismissible
73
+            if($args['dismissible']){
74
+
75
+                if ( $aui_bs5 ) {
76
+                    $output .= '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>';
77
+                }else{
78
+                    $output .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close">';
79
+                    $output .= '<span aria-hidden="true">&times;</span>';
80
+                    $output .= '</button>';
81
+                }
82
+            }
83
+
84
+            // footer
85
+            if ( ! empty( $args['footer'] ) ) {
86
+                $output .= '<hr>';
87
+                $output .= '<p class="mb-0">' . $args['footer'] . '</p>';
88
+            }
89
+
90
+            // close
91
+            $output .= '</div>';
92
+        }
93
+
94
+        return $output;
95
+    }
96 96
 
97 97
 }
98 98
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) {
3
+if (!defined('ABSPATH')) {
4 4
 	exit; // Exit if accessed directly
5 5
 }
6 6
 
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 	 *
19 19
 	 * @return string The rendered component.
20 20
 	 */
21
-	public static function get($args = array()){
21
+	public static function get($args = array()) {
22 22
 		global $aui_bs5;
23 23
 		$defaults = array(
24 24
 			'type'       => 'info',
@@ -34,47 +34,47 @@  discard block
 block discarded – undo
34 34
 		/**
35 35
 		 * Parse incoming $args into an array and merge it with $defaults
36 36
 		 */
37
-		$args   = wp_parse_args( $args, $defaults );
37
+		$args   = wp_parse_args($args, $defaults);
38 38
 		$output = '';
39
-		if ( ! empty( $args['content'] ) ) {
40
-			$type = sanitize_html_class( $args['type'] );
41
-			if($type=='error'){$type='danger';}
42
-			$icon = !empty($args['icon']) ? "<i class='".esc_attr($args['icon'])."'></i>" : '';
39
+		if (!empty($args['content'])) {
40
+			$type = sanitize_html_class($args['type']);
41
+			if ($type == 'error') {$type = 'danger'; }
42
+			$icon = !empty($args['icon']) ? "<i class='" . esc_attr($args['icon']) . "'></i>" : '';
43 43
 
44 44
 			// set default icon
45
-			if(!$icon && $args['icon']!==false && $type){
46
-				if($type=='danger'){$icon = '<i class="fas fa-exclamation-circle"></i>';}
47
-				elseif($type=='warning'){$icon = '<i class="fas fa-exclamation-triangle"></i>';}
48
-				elseif($type=='success'){$icon = '<i class="fas fa-check-circle"></i>';}
49
-				elseif($type=='info'){$icon = '<i class="fas fa-info-circle"></i>';}
45
+			if (!$icon && $args['icon'] !== false && $type) {
46
+				if ($type == 'danger') {$icon = '<i class="fas fa-exclamation-circle"></i>'; }
47
+				elseif ($type == 'warning') {$icon = '<i class="fas fa-exclamation-triangle"></i>'; }
48
+				elseif ($type == 'success') {$icon = '<i class="fas fa-check-circle"></i>'; }
49
+				elseif ($type == 'info') {$icon = '<i class="fas fa-info-circle"></i>'; }
50 50
 			}
51 51
 
52 52
 			$data = '';
53 53
 			$class = !empty($args['class']) ? esc_attr($args['class']) : '';
54
-			if($args['dismissible']){$class .= " alert-dismissible fade show";}
54
+			if ($args['dismissible']) {$class .= " alert-dismissible fade show"; }
55 55
 
56 56
 			// open
57
-			$output .= '<div class="alert alert-' . $type . ' '.$class.'" role="alert" '.$data.'>';
57
+			$output .= '<div class="alert alert-' . $type . ' ' . $class . '" role="alert" ' . $data . '>';
58 58
 
59 59
 			// heading
60
-			if ( ! empty( $args['heading'] ) ) {
60
+			if (!empty($args['heading'])) {
61 61
 				$output .= '<h4 class="alert-heading">' . $args['heading'] . '</h4>';
62 62
 			}
63 63
 
64 64
 			// icon
65
-			if ( ! empty( $icon) ) {
66
-				$output .= $icon." ";
65
+			if (!empty($icon)) {
66
+				$output .= $icon . " ";
67 67
 			}
68 68
 
69 69
 			// content
70 70
 			$output .= $args['content'];
71 71
 
72 72
 			// dismissible
73
-			if($args['dismissible']){
73
+			if ($args['dismissible']) {
74 74
 
75
-				if ( $aui_bs5 ) {
75
+				if ($aui_bs5) {
76 76
 					$output .= '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>';
77
-				}else{
77
+				} else {
78 78
 					$output .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close">';
79 79
 					$output .= '<span aria-hidden="true">&times;</span>';
80 80
 					$output .= '</button>';
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 			}
83 83
 
84 84
 			// footer
85
-			if ( ! empty( $args['footer'] ) ) {
85
+			if (!empty($args['footer'])) {
86 86
 				$output .= '<hr>';
87 87
 				$output .= '<p class="mb-0">' . $args['footer'] . '</p>';
88 88
 			}
Please login to merge, or discard this patch.
Braces   +2 added lines, -5 removed lines patch added patch discarded remove patch
@@ -43,10 +43,7 @@  discard block
 block discarded – undo
43 43
 
44 44
 			// set default icon
45 45
 			if(!$icon && $args['icon']!==false && $type){
46
-				if($type=='danger'){$icon = '<i class="fas fa-exclamation-circle"></i>';}
47
-				elseif($type=='warning'){$icon = '<i class="fas fa-exclamation-triangle"></i>';}
48
-				elseif($type=='success'){$icon = '<i class="fas fa-check-circle"></i>';}
49
-				elseif($type=='info'){$icon = '<i class="fas fa-info-circle"></i>';}
46
+				if($type=='danger'){$icon = '<i class="fas fa-exclamation-circle"></i>';} elseif($type=='warning'){$icon = '<i class="fas fa-exclamation-triangle"></i>';} elseif($type=='success'){$icon = '<i class="fas fa-check-circle"></i>';} elseif($type=='info'){$icon = '<i class="fas fa-info-circle"></i>';}
50 47
 			}
51 48
 
52 49
 			$data = '';
@@ -74,7 +71,7 @@  discard block
 block discarded – undo
74 71
 
75 72
 				if ( $aui_bs5 ) {
76 73
 					$output .= '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>';
77
-				}else{
74
+				} else{
78 75
 					$output .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close">';
79 76
 					$output .= '<span aria-hidden="true">&times;</span>';
80 77
 					$output .= '</button>';
Please login to merge, or discard this patch.
wp-ayecode-ui/includes/components/class-aui-component-pagination.php 2 patches
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if ( ! defined( 'ABSPATH' ) ) {
4
-	exit; // Exit if accessed directly
4
+    exit; // Exit if accessed directly
5 5
 }
6 6
 
7 7
 /**
@@ -11,112 +11,112 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class AUI_Component_Pagination {
13 13
 
14
-	/**
15
-	 * Build the component.
16
-	 *
17
-	 * @param array $args
18
-	 *
19
-	 * @return string The rendered component.
20
-	 */
21
-	public static function get( $args = array() ) {
22
-		global $wp_query, $aui_bs5;
23
-
24
-		$defaults = array(
25
-			'class'              => '',
26
-			'mid_size'           => 2,
27
-			'prev_text'          => '<i class="fas fa-chevron-left"></i>',
28
-			'next_text'          => '<i class="fas fa-chevron-right"></i>',
29
-			'screen_reader_text' => __( 'Posts navigation','aui' ),
30
-			'before_paging'      => '',
31
-			'after_paging'       => '',
32
-			'type'               => 'array',
33
-			'total'              => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1,
34
-			'links'              => array(), // an array of links if using custom links, this includes the a tag.
35
-			'rounded_style'      => false,
36
-			'custom_next_text'   => '', // Custom next page text
37
-			'custom_prev_text'   => '', // Custom prev page text
38
-		);
39
-
40
-		/**
41
-		 * Parse incoming $args into an array and merge it with $defaults
42
-		 */
43
-		$args = wp_parse_args( $args, $defaults );
44
-
45
-		$output = '';
46
-
47
-		// Don't print empty markup if there's only one page.
48
-		if ( $args['total'] > 1 ) {
49
-			// Set up paginated links.
50
-			$links = !empty(  $args['links'] ) ? $args['links'] :  paginate_links( $args );
51
-
52
-			$class = !empty($args['class']) ? $args['class'] : '';
53
-
54
-			$custom_prev_link = '';
55
-			$custom_next_link = '';
56
-
57
-			// make the output bootstrap ready
58
-			$links_html = "<ul class='pagination m-0 p-0 $class'>";
59
-			if ( ! empty( $links ) ) {
60
-				foreach ( $links as $link ) {
61
-					$_link = $link;
62
-
63
-					if ( $aui_bs5 ) {
64
-						$link_class = $args['rounded_style'] ? 'page-link badge rounded-pill border-0 mx-1 fs-base text-dark link-primary' : 'page-link';
65
-						$link_class_active = $args['rounded_style'] ? ' current active fw-bold badge rounded-pill' : ' current active';
66
-						$links_html .= "<li class='page-item mx-0'>";
67
-						$link = str_replace( array( "page-numbers", " current" ), array( $link_class, $link_class_active ), $link );
68
-						$link = str_replace( 'text-dark link-primary current', 'current', $link );
69
-						$links_html .=  $link;
70
-						$links_html .= "</li>";
71
-					} else {
72
-						$active = strpos( $link, 'current' ) !== false ? 'active' : '';
73
-						$links_html .= "<li class='page-item $active'>";
74
-						$links_html .= str_replace( "page-numbers", "page-link", $link );
75
-						$links_html .= "</li>";
76
-					}
77
-
78
-					if ( strpos( $_link, 'next page-numbers' ) || strpos( $_link, 'prev page-numbers' ) ) {
79
-						$link = str_replace( array( "page-numbers", " current" ), array( 'btn btn-outline-primary rounded' . ( $args['rounded_style'] ? '-pill' : '' ) . ' mx-1 fs-base text-dark link-primary', ' current active fw-bold badge rounded-pill' ), $_link );
80
-						$link = str_replace( 'text-dark link-primary current', 'current', $link );
81
-
82
-						if ( strpos( $_link, 'next page-numbers' ) && ! empty( $args['custom_next_text'] ) ) {
83
-							$custom_next_link = str_replace( $args['next_text'], $args['custom_next_text'], $link );
84
-						} else if ( strpos( $_link, 'prev page-numbers' ) && ! empty( $args['custom_prev_text'] ) ) {
85
-							$custom_prev_link = str_replace( $args['prev_text'], $args['custom_prev_text'], $link );
86
-						}
87
-					}
88
-				}
89
-			}
90
-			$links_html .= "</ul>";
91
-
92
-			if ( $links ) {
93
-				$output .= '<section class="px-0 py-2 w-100">';
94
-				$output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] );
95
-				$output .= '</section>';
96
-			}
97
-
98
-			$output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output );
99
-			$output = str_replace( "nav-links", "aui-nav-links", $output );
100
-		}
101
-
102
-		if ( $output ) {
103
-			if ( $custom_next_link || $custom_prev_link ) {
104
-				$total   = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1;
105
-				$current = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1;
106
-
107
-				$output = '<div class="row d-flex align-items-center justify-content-between"><div class="col text-start">' . $custom_prev_link . '</div><div class="col text-center d-none d-md-block">' . $output . '</div><div class="col text-center d-md-none">' . $current . '/' . $args['total'] . '</div><div class="col text-end">' . $custom_next_link . '</div></div>';
108
-			}
109
-
110
-			if ( ! empty( $args['before_paging'] ) ) {
111
-				$output = $args['before_paging'] . $output;
112
-			}
113
-
114
-			if ( ! empty( $args['after_paging'] ) ) {
115
-				$output = $output . $args['after_paging'];
116
-			}
117
-		}
118
-
119
-		return $output;
120
-	}
14
+    /**
15
+     * Build the component.
16
+     *
17
+     * @param array $args
18
+     *
19
+     * @return string The rendered component.
20
+     */
21
+    public static function get( $args = array() ) {
22
+        global $wp_query, $aui_bs5;
23
+
24
+        $defaults = array(
25
+            'class'              => '',
26
+            'mid_size'           => 2,
27
+            'prev_text'          => '<i class="fas fa-chevron-left"></i>',
28
+            'next_text'          => '<i class="fas fa-chevron-right"></i>',
29
+            'screen_reader_text' => __( 'Posts navigation','aui' ),
30
+            'before_paging'      => '',
31
+            'after_paging'       => '',
32
+            'type'               => 'array',
33
+            'total'              => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1,
34
+            'links'              => array(), // an array of links if using custom links, this includes the a tag.
35
+            'rounded_style'      => false,
36
+            'custom_next_text'   => '', // Custom next page text
37
+            'custom_prev_text'   => '', // Custom prev page text
38
+        );
39
+
40
+        /**
41
+         * Parse incoming $args into an array and merge it with $defaults
42
+         */
43
+        $args = wp_parse_args( $args, $defaults );
44
+
45
+        $output = '';
46
+
47
+        // Don't print empty markup if there's only one page.
48
+        if ( $args['total'] > 1 ) {
49
+            // Set up paginated links.
50
+            $links = !empty(  $args['links'] ) ? $args['links'] :  paginate_links( $args );
51
+
52
+            $class = !empty($args['class']) ? $args['class'] : '';
53
+
54
+            $custom_prev_link = '';
55
+            $custom_next_link = '';
56
+
57
+            // make the output bootstrap ready
58
+            $links_html = "<ul class='pagination m-0 p-0 $class'>";
59
+            if ( ! empty( $links ) ) {
60
+                foreach ( $links as $link ) {
61
+                    $_link = $link;
62
+
63
+                    if ( $aui_bs5 ) {
64
+                        $link_class = $args['rounded_style'] ? 'page-link badge rounded-pill border-0 mx-1 fs-base text-dark link-primary' : 'page-link';
65
+                        $link_class_active = $args['rounded_style'] ? ' current active fw-bold badge rounded-pill' : ' current active';
66
+                        $links_html .= "<li class='page-item mx-0'>";
67
+                        $link = str_replace( array( "page-numbers", " current" ), array( $link_class, $link_class_active ), $link );
68
+                        $link = str_replace( 'text-dark link-primary current', 'current', $link );
69
+                        $links_html .=  $link;
70
+                        $links_html .= "</li>";
71
+                    } else {
72
+                        $active = strpos( $link, 'current' ) !== false ? 'active' : '';
73
+                        $links_html .= "<li class='page-item $active'>";
74
+                        $links_html .= str_replace( "page-numbers", "page-link", $link );
75
+                        $links_html .= "</li>";
76
+                    }
77
+
78
+                    if ( strpos( $_link, 'next page-numbers' ) || strpos( $_link, 'prev page-numbers' ) ) {
79
+                        $link = str_replace( array( "page-numbers", " current" ), array( 'btn btn-outline-primary rounded' . ( $args['rounded_style'] ? '-pill' : '' ) . ' mx-1 fs-base text-dark link-primary', ' current active fw-bold badge rounded-pill' ), $_link );
80
+                        $link = str_replace( 'text-dark link-primary current', 'current', $link );
81
+
82
+                        if ( strpos( $_link, 'next page-numbers' ) && ! empty( $args['custom_next_text'] ) ) {
83
+                            $custom_next_link = str_replace( $args['next_text'], $args['custom_next_text'], $link );
84
+                        } else if ( strpos( $_link, 'prev page-numbers' ) && ! empty( $args['custom_prev_text'] ) ) {
85
+                            $custom_prev_link = str_replace( $args['prev_text'], $args['custom_prev_text'], $link );
86
+                        }
87
+                    }
88
+                }
89
+            }
90
+            $links_html .= "</ul>";
91
+
92
+            if ( $links ) {
93
+                $output .= '<section class="px-0 py-2 w-100">';
94
+                $output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] );
95
+                $output .= '</section>';
96
+            }
97
+
98
+            $output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output );
99
+            $output = str_replace( "nav-links", "aui-nav-links", $output );
100
+        }
101
+
102
+        if ( $output ) {
103
+            if ( $custom_next_link || $custom_prev_link ) {
104
+                $total   = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1;
105
+                $current = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1;
106
+
107
+                $output = '<div class="row d-flex align-items-center justify-content-between"><div class="col text-start">' . $custom_prev_link . '</div><div class="col text-center d-none d-md-block">' . $output . '</div><div class="col text-center d-md-none">' . $current . '/' . $args['total'] . '</div><div class="col text-end">' . $custom_next_link . '</div></div>';
108
+            }
109
+
110
+            if ( ! empty( $args['before_paging'] ) ) {
111
+                $output = $args['before_paging'] . $output;
112
+            }
113
+
114
+            if ( ! empty( $args['after_paging'] ) ) {
115
+                $output = $output . $args['after_paging'];
116
+            }
117
+        }
118
+
119
+        return $output;
120
+    }
121 121
 
122 122
 }
123 123
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) {
3
+if (!defined('ABSPATH')) {
4 4
 	exit; // Exit if accessed directly
5 5
 }
6 6
 
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 	 *
19 19
 	 * @return string The rendered component.
20 20
 	 */
21
-	public static function get( $args = array() ) {
21
+	public static function get($args = array()) {
22 22
 		global $wp_query, $aui_bs5;
23 23
 
24 24
 		$defaults = array(
@@ -26,11 +26,11 @@  discard block
 block discarded – undo
26 26
 			'mid_size'           => 2,
27 27
 			'prev_text'          => '<i class="fas fa-chevron-left"></i>',
28 28
 			'next_text'          => '<i class="fas fa-chevron-right"></i>',
29
-			'screen_reader_text' => __( 'Posts navigation','aui' ),
29
+			'screen_reader_text' => __('Posts navigation', 'aui'),
30 30
 			'before_paging'      => '',
31 31
 			'after_paging'       => '',
32 32
 			'type'               => 'array',
33
-			'total'              => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1,
33
+			'total'              => isset($wp_query->max_num_pages) ? $wp_query->max_num_pages : 1,
34 34
 			'links'              => array(), // an array of links if using custom links, this includes the a tag.
35 35
 			'rounded_style'      => false,
36 36
 			'custom_next_text'   => '', // Custom next page text
@@ -40,14 +40,14 @@  discard block
 block discarded – undo
40 40
 		/**
41 41
 		 * Parse incoming $args into an array and merge it with $defaults
42 42
 		 */
43
-		$args = wp_parse_args( $args, $defaults );
43
+		$args = wp_parse_args($args, $defaults);
44 44
 
45 45
 		$output = '';
46 46
 
47 47
 		// Don't print empty markup if there's only one page.
48
-		if ( $args['total'] > 1 ) {
48
+		if ($args['total'] > 1) {
49 49
 			// Set up paginated links.
50
-			$links = !empty(  $args['links'] ) ? $args['links'] :  paginate_links( $args );
50
+			$links = !empty($args['links']) ? $args['links'] : paginate_links($args);
51 51
 
52 52
 			$class = !empty($args['class']) ? $args['class'] : '';
53 53
 
@@ -56,62 +56,62 @@  discard block
 block discarded – undo
56 56
 
57 57
 			// make the output bootstrap ready
58 58
 			$links_html = "<ul class='pagination m-0 p-0 $class'>";
59
-			if ( ! empty( $links ) ) {
60
-				foreach ( $links as $link ) {
59
+			if (!empty($links)) {
60
+				foreach ($links as $link) {
61 61
 					$_link = $link;
62 62
 
63
-					if ( $aui_bs5 ) {
63
+					if ($aui_bs5) {
64 64
 						$link_class = $args['rounded_style'] ? 'page-link badge rounded-pill border-0 mx-1 fs-base text-dark link-primary' : 'page-link';
65 65
 						$link_class_active = $args['rounded_style'] ? ' current active fw-bold badge rounded-pill' : ' current active';
66 66
 						$links_html .= "<li class='page-item mx-0'>";
67
-						$link = str_replace( array( "page-numbers", " current" ), array( $link_class, $link_class_active ), $link );
68
-						$link = str_replace( 'text-dark link-primary current', 'current', $link );
69
-						$links_html .=  $link;
67
+						$link = str_replace(array("page-numbers", " current"), array($link_class, $link_class_active), $link);
68
+						$link = str_replace('text-dark link-primary current', 'current', $link);
69
+						$links_html .= $link;
70 70
 						$links_html .= "</li>";
71 71
 					} else {
72
-						$active = strpos( $link, 'current' ) !== false ? 'active' : '';
72
+						$active = strpos($link, 'current') !== false ? 'active' : '';
73 73
 						$links_html .= "<li class='page-item $active'>";
74
-						$links_html .= str_replace( "page-numbers", "page-link", $link );
74
+						$links_html .= str_replace("page-numbers", "page-link", $link);
75 75
 						$links_html .= "</li>";
76 76
 					}
77 77
 
78
-					if ( strpos( $_link, 'next page-numbers' ) || strpos( $_link, 'prev page-numbers' ) ) {
79
-						$link = str_replace( array( "page-numbers", " current" ), array( 'btn btn-outline-primary rounded' . ( $args['rounded_style'] ? '-pill' : '' ) . ' mx-1 fs-base text-dark link-primary', ' current active fw-bold badge rounded-pill' ), $_link );
80
-						$link = str_replace( 'text-dark link-primary current', 'current', $link );
78
+					if (strpos($_link, 'next page-numbers') || strpos($_link, 'prev page-numbers')) {
79
+						$link = str_replace(array("page-numbers", " current"), array('btn btn-outline-primary rounded' . ($args['rounded_style'] ? '-pill' : '') . ' mx-1 fs-base text-dark link-primary', ' current active fw-bold badge rounded-pill'), $_link);
80
+						$link = str_replace('text-dark link-primary current', 'current', $link);
81 81
 
82
-						if ( strpos( $_link, 'next page-numbers' ) && ! empty( $args['custom_next_text'] ) ) {
83
-							$custom_next_link = str_replace( $args['next_text'], $args['custom_next_text'], $link );
84
-						} else if ( strpos( $_link, 'prev page-numbers' ) && ! empty( $args['custom_prev_text'] ) ) {
85
-							$custom_prev_link = str_replace( $args['prev_text'], $args['custom_prev_text'], $link );
82
+						if (strpos($_link, 'next page-numbers') && !empty($args['custom_next_text'])) {
83
+							$custom_next_link = str_replace($args['next_text'], $args['custom_next_text'], $link);
84
+						} else if (strpos($_link, 'prev page-numbers') && !empty($args['custom_prev_text'])) {
85
+							$custom_prev_link = str_replace($args['prev_text'], $args['custom_prev_text'], $link);
86 86
 						}
87 87
 					}
88 88
 				}
89 89
 			}
90 90
 			$links_html .= "</ul>";
91 91
 
92
-			if ( $links ) {
92
+			if ($links) {
93 93
 				$output .= '<section class="px-0 py-2 w-100">';
94
-				$output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] );
94
+				$output .= _navigation_markup($links_html, 'aui-pagination', $args['screen_reader_text']);
95 95
 				$output .= '</section>';
96 96
 			}
97 97
 
98
-			$output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output );
99
-			$output = str_replace( "nav-links", "aui-nav-links", $output );
98
+			$output = str_replace("screen-reader-text", "screen-reader-text sr-only", $output);
99
+			$output = str_replace("nav-links", "aui-nav-links", $output);
100 100
 		}
101 101
 
102
-		if ( $output ) {
103
-			if ( $custom_next_link || $custom_prev_link ) {
104
-				$total   = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1;
105
-				$current = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1;
102
+		if ($output) {
103
+			if ($custom_next_link || $custom_prev_link) {
104
+				$total   = isset($wp_query->max_num_pages) ? $wp_query->max_num_pages : 1;
105
+				$current = get_query_var('paged') ? (int) get_query_var('paged') : 1;
106 106
 
107 107
 				$output = '<div class="row d-flex align-items-center justify-content-between"><div class="col text-start">' . $custom_prev_link . '</div><div class="col text-center d-none d-md-block">' . $output . '</div><div class="col text-center d-md-none">' . $current . '/' . $args['total'] . '</div><div class="col text-end">' . $custom_next_link . '</div></div>';
108 108
 			}
109 109
 
110
-			if ( ! empty( $args['before_paging'] ) ) {
110
+			if (!empty($args['before_paging'])) {
111 111
 				$output = $args['before_paging'] . $output;
112 112
 			}
113 113
 
114
-			if ( ! empty( $args['after_paging'] ) ) {
114
+			if (!empty($args['after_paging'])) {
115 115
 				$output = $output . $args['after_paging'];
116 116
 			}
117 117
 		}
Please login to merge, or discard this patch.
ayecode/wp-ayecode-ui/includes/components/class-aui-component-helper.php 2 patches
Indentation   +467 added lines, -467 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if ( ! defined( 'ABSPATH' ) ) {
4
-	exit; // Exit if accessed directly
4
+    exit; // Exit if accessed directly
5 5
 }
6 6
 
7 7
 /**
@@ -11,470 +11,470 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class AUI_Component_Helper {
13 13
 
14
-	/**
15
-	 * A component helper for generating a input name.
16
-	 *
17
-	 * @param $text
18
-	 * @param $multiple bool If the name is set to be multiple but no brackets found then we add some.
19
-	 *
20
-	 * @return string
21
-	 */
22
-	public static function name( $text, $multiple = false ) {
23
-		$output = '';
24
-
25
-		if ( $text ) {
26
-			$is_multiple = strpos( $text, '[' ) === false && $multiple ? '[]' : '';
27
-			$output      = ' name="' . esc_attr( $text ) . $is_multiple . '" ';
28
-		}
29
-
30
-		return $output;
31
-	}
32
-
33
-	/**
34
-	 * A component helper for generating a item id.
35
-	 *
36
-	 * @param $text string The text to be used as the value.
37
-	 *
38
-	 * @return string The sanitized item.
39
-	 */
40
-	public static function id( $text ) {
41
-		$output = '';
42
-
43
-		if ( $text ) {
44
-			$output = ' id="' . sanitize_html_class( $text ) . '" ';
45
-		}
46
-
47
-		return $output;
48
-	}
49
-
50
-	/**
51
-	 * A component helper for generating a item title.
52
-	 *
53
-	 * @param $text string The text to be used as the value.
54
-	 *
55
-	 * @return string The sanitized item.
56
-	 */
57
-	public static function title( $text ) {
58
-		$output = '';
59
-
60
-		if ( $text ) {
61
-			$output = ' title="' . esc_attr( $text ) . '" ';
62
-		}
63
-
64
-		return $output;
65
-	}
66
-
67
-	/**
68
-	 * A component helper for generating a item value.
69
-	 *
70
-	 * @param $text string The text to be used as the value.
71
-	 *
72
-	 * @return string The sanitized item.
73
-	 */
74
-	public static function value( $text ) {
75
-		$output = '';
76
-
77
-		if ( $text !== null && $text !== false ) {
78
-			$output = ' value="' . esc_attr( wp_unslash( $text ) ) . '" ';
79
-		}
80
-
81
-		return $output;
82
-	}
83
-
84
-	/**
85
-	 * A component helper for generating a item class attribute.
86
-	 *
87
-	 * @param $text string The text to be used as the value.
88
-	 *
89
-	 * @return string The sanitized item.
90
-	 */
91
-	public static function class_attr( $text ) {
92
-		$output = '';
93
-
94
-		if ( $text ) {
95
-			$classes = self::esc_classes( $text );
96
-			if ( ! empty( $classes ) ) {
97
-				$output = ' class="' . $classes . '" ';
98
-			}
99
-		}
100
-
101
-		return $output;
102
-	}
103
-
104
-	/**
105
-	 * Escape a string of classes.
106
-	 *
107
-	 * @param $text
108
-	 *
109
-	 * @return string
110
-	 */
111
-	public static function esc_classes( $text ) {
112
-		$output = '';
113
-
114
-		if ( $text ) {
115
-			$classes = explode( " ", $text );
116
-			$classes = array_map( "trim", $classes );
117
-			$classes = array_map( "sanitize_html_class", $classes );
118
-			if ( ! empty( $classes ) ) {
119
-				$output = implode( " ", $classes );
120
-			}
121
-		}
122
-
123
-		return $output;
124
-
125
-	}
126
-
127
-	/**
128
-	 * @param $args
129
-	 *
130
-	 * @return string
131
-	 */
132
-	public static function data_attributes( $args ) {
133
-		$output = '';
134
-
135
-		if ( ! empty( $args ) ) {
136
-
137
-			foreach ( $args as $key => $val ) {
138
-				if ( substr( $key, 0, 5 ) === "data-" ) {
139
-					$output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" ';
140
-				}
141
-			}
142
-		}
143
-
144
-		return $output;
145
-	}
146
-
147
-	/**
148
-	 * @param $args
149
-	 *
150
-	 * @return string
151
-	 */
152
-	public static function aria_attributes( $args ) {
153
-		$output = '';
154
-
155
-		if ( ! empty( $args ) ) {
156
-
157
-			foreach ( $args as $key => $val ) {
158
-				if ( substr( $key, 0, 5 ) === "aria-" ) {
159
-					$output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" ';
160
-				}
161
-			}
162
-		}
163
-
164
-		return $output;
165
-	}
166
-
167
-	/**
168
-	 * Build a font awesome icon from a class.
169
-	 *
170
-	 * @param $class
171
-	 * @param bool $space_after
172
-	 * @param array $extra_attributes An array of extra attributes.
173
-	 *
174
-	 * @return string
175
-	 */
176
-	public static function icon( $class, $space_after = false, $extra_attributes = array() ) {
177
-		$output = '';
178
-
179
-		if ( $class ) {
180
-			$classes = self::esc_classes( $class );
181
-			if ( ! empty( $classes ) ) {
182
-				$output = '<i class="' . $classes . '" ';
183
-				// extra attributes
184
-				if ( ! empty( $extra_attributes ) ) {
185
-					$output .= AUI_Component_Helper::extra_attributes( $extra_attributes );
186
-				}
187
-				$output .= '></i>';
188
-				if ( $space_after ) {
189
-					$output .= " ";
190
-				}
191
-			}
192
-		}
193
-
194
-		return $output;
195
-	}
196
-
197
-	/**
198
-	 * @param $args
199
-	 *
200
-	 * @return string
201
-	 */
202
-	public static function extra_attributes( $args ) {
203
-		$output = '';
204
-
205
-		if ( ! empty( $args ) ) {
206
-
207
-			if ( is_array( $args ) ) {
208
-				foreach ( $args as $key => $val ) {
209
-					$output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" ';
210
-				}
211
-			} else {
212
-				$output .= ' ' . $args . ' ';
213
-			}
214
-
215
-		}
216
-
217
-		return $output;
218
-	}
219
-
220
-	/**
221
-	 * @param $args
222
-	 *
223
-	 * @return string
224
-	 */
225
-	public static function help_text( $text ) {
226
-		$output = '';
227
-
228
-		if ( $text ) {
229
-			$output .= '<small class="form-text text-muted d-block">' . wp_kses_post( $text ) . '</small>';
230
-		}
231
-
232
-
233
-		return $output;
234
-	}
235
-
236
-	/**
237
-	 * Replace element require context with JS.
238
-	 *
239
-	 * @param $input
240
-	 *
241
-	 * @return string|void
242
-	 */
243
-	public static function element_require( $input ) {
244
-
245
-		$input = str_replace( "'", '"', $input );// we only want double quotes
246
-
247
-		$output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array(
248
-			"jQuery(form).find('[data-argument=\"",
249
-			"\"]').find('input,select,textarea').val()",
250
-			"\"]').find('input:checked').val()",
251
-		), $input ) );
252
-
253
-		if ( $output ) {
254
-			$output = ' data-element-require="' . $output . '" ';
255
-		}
256
-
257
-		return $output;
258
-	}
259
-
260
-	/**
261
-	 * Navigates through an array, object, or scalar, and removes slashes from the values.
262
-	 *
263
-	 * @since 0.1.41
264
-	 *
265
-	 * @param mixed $value The value to be stripped.
266
-	 * @param array $input Input Field.
267
-	 *
268
-	 * @return mixed Stripped value.
269
-	 */
270
-	public static function sanitize_html_field( $value, $input = array() ) {
271
-		$original = $value;
272
-
273
-		if ( is_array( $value ) ) {
274
-			foreach ( $value as $index => $item ) {
275
-				$value[ $index ] = self::_sanitize_html_field( $value, $input );
276
-			}
277
-		} elseif ( is_object( $value ) ) {
278
-			$object_vars = get_object_vars( $value );
279
-
280
-			foreach ( $object_vars as $property_name => $property_value ) {
281
-				$value->$property_name = self::_sanitize_html_field( $property_value, $input );
282
-			}
283
-		} else {
284
-			$value = self::_sanitize_html_field( $value, $input );
285
-		}
286
-
287
-		/**
288
-		 * Filters content and keeps only allowable HTML elements.
289
-		 *
290
-		 * @since 0.1.41
291
-		 *
292
-		 * @param string|array $value Content to filter through kses.
293
-		 * @param string|array $value Original content without filter.
294
-		 * @param array $input Input Field.
295
-		 */
296
-		return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input );
297
-	}
298
-
299
-	/**
300
-	 * Filters content and keeps only allowable HTML elements.
301
-	 *
302
-	 * This function makes sure that only the allowed HTML element names, attribute
303
-	 * names and attribute values plus only sane HTML entities will occur in
304
-	 * $string. You have to remove any slashes from PHP's magic quotes before you
305
-	 * call this function.
306
-	 *
307
-	 * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news',
308
-	 * 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This
309
-	 * covers all common link protocols, except for 'javascript' which should not
310
-	 * be allowed for untrusted users.
311
-	 *
312
-	 * @since 0.1.41
313
-	 *
314
-	 * @param string|array $value Content to filter through kses.
315
-	 * @param array $input Input Field.
316
-	 *
317
-	 * @return string Filtered content with only allowed HTML elements.
318
-	 */
319
-	public static function _sanitize_html_field( $value, $input = array() ) {
320
-		if ( $value === '' ) {
321
-			return $value;
322
-		}
323
-
324
-		$allowed_html = self::kses_allowed_html( 'post', $input );
325
-
326
-		if ( ! is_array( $allowed_html ) ) {
327
-			$allowed_html = wp_kses_allowed_html( 'post' );
328
-		}
329
-
330
-		$filtered = trim( wp_unslash( $value ) );
331
-		$filtered = wp_kses( $filtered, $allowed_html );
332
-		$filtered = balanceTags( $filtered ); // Balances tags
333
-
334
-		return $filtered;
335
-	}
336
-
337
-	/**
338
-	 * Returns an array of allowed HTML tags and attributes for a given context.
339
-	 *
340
-	 * @since 0.1.41
341
-	 *
342
-	 * @param string|array $context The context for which to retrieve tags. Allowed values are 'post',
343
-	 *                              'strip', 'data', 'entities', or the name of a field filter such as
344
-	 *                              'pre_user_description'.
345
-	 * @param array $input Input.
346
-	 *
347
-	 * @return array Array of allowed HTML tags and their allowed attributes.
348
-	 */
349
-	public static function kses_allowed_html( $context = 'post', $input = array() ) {
350
-		$allowed_html = wp_kses_allowed_html( $context );
351
-
352
-		if ( is_array( $allowed_html ) ) {
353
-			// <iframe>
354
-			if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) {
355
-				$allowed_html['iframe'] = array(
356
-					'class'           => true,
357
-					'id'              => true,
358
-					'src'             => true,
359
-					'width'           => true,
360
-					'height'          => true,
361
-					'frameborder'     => true,
362
-					'marginwidth'     => true,
363
-					'marginheight'    => true,
364
-					'scrolling'       => true,
365
-					'style'           => true,
366
-					'title'           => true,
367
-					'allow'           => true,
368
-					'allowfullscreen' => true,
369
-					'data-*'          => true,
370
-				);
371
-			}
372
-		}
373
-
374
-		/**
375
-		 * Filters the allowed html tags.
376
-		 *
377
-		 * @since 0.1.41
378
-		 *
379
-		 * @param array[]|string $allowed_html Allowed html tags.
380
-		 * @param @param string|array $context The context for which to retrieve tags.
381
-		 * @param array $input Input field.
382
-		 */
383
-		return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input );
384
-	}
385
-
386
-	public static function get_column_class( $label_number = 2, $type = 'label' ) {
387
-
388
-		$class = '';
389
-
390
-		// set default if empty
391
-		if( $label_number === '' ){
392
-			$label_number = 2;
393
-		}
394
-
395
-		if ( $label_number && $label_number < 12 && $label_number > 0 ) {
396
-			if ( $type == 'label' ) {
397
-				$class = 'col-sm-' . absint( $label_number );
398
-			} elseif ( $type == 'input' ) {
399
-				$class = 'col-sm-' . ( 12 - absint( $label_number ) );
400
-			}
401
-		}
402
-
403
-		return $class;
404
-	}
405
-
406
-	/**
407
-	 * Sanitizes a multiline string from user input or from the database.
408
-	 *
409
-	 * Emulate the WP native sanitize_textarea_field function in a %%variable%% safe way.
410
-	 *
411
-	 * @see   https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php for the original
412
-	 *
413
-	 * @since 0.1.66
414
-	 *
415
-	 * @param string $str String to sanitize.
416
-	 * @return string Sanitized string.
417
-	 */
418
-	public static function sanitize_textarea_field( $str ) {
419
-		$filtered = self::_sanitize_text_fields( $str, true );
420
-
421
-		/**
422
-		 * Filters a sanitized textarea field string.
423
-		 *
424
-		 * @see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php
425
-		 *
426
-		 * @param string $filtered The sanitized string.
427
-		 * @param string $str      The string prior to being sanitized.
428
-		 */
429
-		return apply_filters( 'sanitize_textarea_field', $filtered, $str );
430
-	}
431
-
432
-	/**
433
-	 * Internal helper function to sanitize a string from user input or from the db.
434
-	 *
435
-	 * @since 0.1.66
436
-	 * @access private
437
-	 *
438
-	 * @param string $str           String to sanitize.
439
-	 * @param bool   $keep_newlines Optional. Whether to keep newlines. Default: false.
440
-	 * @return string Sanitized string.
441
-	 */
442
-	public static function _sanitize_text_fields( $str, $keep_newlines = false ) {
443
-		if ( is_object( $str ) || is_array( $str ) ) {
444
-			return '';
445
-		}
446
-
447
-		$str = (string) $str;
448
-
449
-		$filtered = wp_check_invalid_utf8( $str );
450
-
451
-		if ( strpos( $filtered, '<' ) !== false ) {
452
-			$filtered = wp_pre_kses_less_than( $filtered );
453
-			// This will strip extra whitespace for us.
454
-			$filtered = wp_strip_all_tags( $filtered, false );
455
-
456
-			// Use HTML entities in a special case to make sure no later
457
-			// newline stripping stage could lead to a functional tag.
458
-			$filtered = str_replace( "<\n", "&lt;\n", $filtered );
459
-		}
460
-
461
-		if ( ! $keep_newlines ) {
462
-			$filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered );
463
-		}
464
-		$filtered = trim( $filtered );
465
-
466
-		$found = false;
467
-		while ( preg_match( '`[^%](%[a-f0-9]{2})`i', $filtered, $match ) ) {
468
-			$filtered = str_replace( $match[1], '', $filtered );
469
-			$found = true;
470
-		}
471
-		unset( $match );
472
-
473
-		if ( $found ) {
474
-			// Strip out the whitespace that may now exist after removing the octets.
475
-			$filtered = trim( preg_replace( '` +`', ' ', $filtered ) );
476
-		}
477
-
478
-		return $filtered;
479
-	}
14
+    /**
15
+     * A component helper for generating a input name.
16
+     *
17
+     * @param $text
18
+     * @param $multiple bool If the name is set to be multiple but no brackets found then we add some.
19
+     *
20
+     * @return string
21
+     */
22
+    public static function name( $text, $multiple = false ) {
23
+        $output = '';
24
+
25
+        if ( $text ) {
26
+            $is_multiple = strpos( $text, '[' ) === false && $multiple ? '[]' : '';
27
+            $output      = ' name="' . esc_attr( $text ) . $is_multiple . '" ';
28
+        }
29
+
30
+        return $output;
31
+    }
32
+
33
+    /**
34
+     * A component helper for generating a item id.
35
+     *
36
+     * @param $text string The text to be used as the value.
37
+     *
38
+     * @return string The sanitized item.
39
+     */
40
+    public static function id( $text ) {
41
+        $output = '';
42
+
43
+        if ( $text ) {
44
+            $output = ' id="' . sanitize_html_class( $text ) . '" ';
45
+        }
46
+
47
+        return $output;
48
+    }
49
+
50
+    /**
51
+     * A component helper for generating a item title.
52
+     *
53
+     * @param $text string The text to be used as the value.
54
+     *
55
+     * @return string The sanitized item.
56
+     */
57
+    public static function title( $text ) {
58
+        $output = '';
59
+
60
+        if ( $text ) {
61
+            $output = ' title="' . esc_attr( $text ) . '" ';
62
+        }
63
+
64
+        return $output;
65
+    }
66
+
67
+    /**
68
+     * A component helper for generating a item value.
69
+     *
70
+     * @param $text string The text to be used as the value.
71
+     *
72
+     * @return string The sanitized item.
73
+     */
74
+    public static function value( $text ) {
75
+        $output = '';
76
+
77
+        if ( $text !== null && $text !== false ) {
78
+            $output = ' value="' . esc_attr( wp_unslash( $text ) ) . '" ';
79
+        }
80
+
81
+        return $output;
82
+    }
83
+
84
+    /**
85
+     * A component helper for generating a item class attribute.
86
+     *
87
+     * @param $text string The text to be used as the value.
88
+     *
89
+     * @return string The sanitized item.
90
+     */
91
+    public static function class_attr( $text ) {
92
+        $output = '';
93
+
94
+        if ( $text ) {
95
+            $classes = self::esc_classes( $text );
96
+            if ( ! empty( $classes ) ) {
97
+                $output = ' class="' . $classes . '" ';
98
+            }
99
+        }
100
+
101
+        return $output;
102
+    }
103
+
104
+    /**
105
+     * Escape a string of classes.
106
+     *
107
+     * @param $text
108
+     *
109
+     * @return string
110
+     */
111
+    public static function esc_classes( $text ) {
112
+        $output = '';
113
+
114
+        if ( $text ) {
115
+            $classes = explode( " ", $text );
116
+            $classes = array_map( "trim", $classes );
117
+            $classes = array_map( "sanitize_html_class", $classes );
118
+            if ( ! empty( $classes ) ) {
119
+                $output = implode( " ", $classes );
120
+            }
121
+        }
122
+
123
+        return $output;
124
+
125
+    }
126
+
127
+    /**
128
+     * @param $args
129
+     *
130
+     * @return string
131
+     */
132
+    public static function data_attributes( $args ) {
133
+        $output = '';
134
+
135
+        if ( ! empty( $args ) ) {
136
+
137
+            foreach ( $args as $key => $val ) {
138
+                if ( substr( $key, 0, 5 ) === "data-" ) {
139
+                    $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" ';
140
+                }
141
+            }
142
+        }
143
+
144
+        return $output;
145
+    }
146
+
147
+    /**
148
+     * @param $args
149
+     *
150
+     * @return string
151
+     */
152
+    public static function aria_attributes( $args ) {
153
+        $output = '';
154
+
155
+        if ( ! empty( $args ) ) {
156
+
157
+            foreach ( $args as $key => $val ) {
158
+                if ( substr( $key, 0, 5 ) === "aria-" ) {
159
+                    $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" ';
160
+                }
161
+            }
162
+        }
163
+
164
+        return $output;
165
+    }
166
+
167
+    /**
168
+     * Build a font awesome icon from a class.
169
+     *
170
+     * @param $class
171
+     * @param bool $space_after
172
+     * @param array $extra_attributes An array of extra attributes.
173
+     *
174
+     * @return string
175
+     */
176
+    public static function icon( $class, $space_after = false, $extra_attributes = array() ) {
177
+        $output = '';
178
+
179
+        if ( $class ) {
180
+            $classes = self::esc_classes( $class );
181
+            if ( ! empty( $classes ) ) {
182
+                $output = '<i class="' . $classes . '" ';
183
+                // extra attributes
184
+                if ( ! empty( $extra_attributes ) ) {
185
+                    $output .= AUI_Component_Helper::extra_attributes( $extra_attributes );
186
+                }
187
+                $output .= '></i>';
188
+                if ( $space_after ) {
189
+                    $output .= " ";
190
+                }
191
+            }
192
+        }
193
+
194
+        return $output;
195
+    }
196
+
197
+    /**
198
+     * @param $args
199
+     *
200
+     * @return string
201
+     */
202
+    public static function extra_attributes( $args ) {
203
+        $output = '';
204
+
205
+        if ( ! empty( $args ) ) {
206
+
207
+            if ( is_array( $args ) ) {
208
+                foreach ( $args as $key => $val ) {
209
+                    $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" ';
210
+                }
211
+            } else {
212
+                $output .= ' ' . $args . ' ';
213
+            }
214
+
215
+        }
216
+
217
+        return $output;
218
+    }
219
+
220
+    /**
221
+     * @param $args
222
+     *
223
+     * @return string
224
+     */
225
+    public static function help_text( $text ) {
226
+        $output = '';
227
+
228
+        if ( $text ) {
229
+            $output .= '<small class="form-text text-muted d-block">' . wp_kses_post( $text ) . '</small>';
230
+        }
231
+
232
+
233
+        return $output;
234
+    }
235
+
236
+    /**
237
+     * Replace element require context with JS.
238
+     *
239
+     * @param $input
240
+     *
241
+     * @return string|void
242
+     */
243
+    public static function element_require( $input ) {
244
+
245
+        $input = str_replace( "'", '"', $input );// we only want double quotes
246
+
247
+        $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array(
248
+            "jQuery(form).find('[data-argument=\"",
249
+            "\"]').find('input,select,textarea').val()",
250
+            "\"]').find('input:checked').val()",
251
+        ), $input ) );
252
+
253
+        if ( $output ) {
254
+            $output = ' data-element-require="' . $output . '" ';
255
+        }
256
+
257
+        return $output;
258
+    }
259
+
260
+    /**
261
+     * Navigates through an array, object, or scalar, and removes slashes from the values.
262
+     *
263
+     * @since 0.1.41
264
+     *
265
+     * @param mixed $value The value to be stripped.
266
+     * @param array $input Input Field.
267
+     *
268
+     * @return mixed Stripped value.
269
+     */
270
+    public static function sanitize_html_field( $value, $input = array() ) {
271
+        $original = $value;
272
+
273
+        if ( is_array( $value ) ) {
274
+            foreach ( $value as $index => $item ) {
275
+                $value[ $index ] = self::_sanitize_html_field( $value, $input );
276
+            }
277
+        } elseif ( is_object( $value ) ) {
278
+            $object_vars = get_object_vars( $value );
279
+
280
+            foreach ( $object_vars as $property_name => $property_value ) {
281
+                $value->$property_name = self::_sanitize_html_field( $property_value, $input );
282
+            }
283
+        } else {
284
+            $value = self::_sanitize_html_field( $value, $input );
285
+        }
286
+
287
+        /**
288
+         * Filters content and keeps only allowable HTML elements.
289
+         *
290
+         * @since 0.1.41
291
+         *
292
+         * @param string|array $value Content to filter through kses.
293
+         * @param string|array $value Original content without filter.
294
+         * @param array $input Input Field.
295
+         */
296
+        return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input );
297
+    }
298
+
299
+    /**
300
+     * Filters content and keeps only allowable HTML elements.
301
+     *
302
+     * This function makes sure that only the allowed HTML element names, attribute
303
+     * names and attribute values plus only sane HTML entities will occur in
304
+     * $string. You have to remove any slashes from PHP's magic quotes before you
305
+     * call this function.
306
+     *
307
+     * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news',
308
+     * 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This
309
+     * covers all common link protocols, except for 'javascript' which should not
310
+     * be allowed for untrusted users.
311
+     *
312
+     * @since 0.1.41
313
+     *
314
+     * @param string|array $value Content to filter through kses.
315
+     * @param array $input Input Field.
316
+     *
317
+     * @return string Filtered content with only allowed HTML elements.
318
+     */
319
+    public static function _sanitize_html_field( $value, $input = array() ) {
320
+        if ( $value === '' ) {
321
+            return $value;
322
+        }
323
+
324
+        $allowed_html = self::kses_allowed_html( 'post', $input );
325
+
326
+        if ( ! is_array( $allowed_html ) ) {
327
+            $allowed_html = wp_kses_allowed_html( 'post' );
328
+        }
329
+
330
+        $filtered = trim( wp_unslash( $value ) );
331
+        $filtered = wp_kses( $filtered, $allowed_html );
332
+        $filtered = balanceTags( $filtered ); // Balances tags
333
+
334
+        return $filtered;
335
+    }
336
+
337
+    /**
338
+     * Returns an array of allowed HTML tags and attributes for a given context.
339
+     *
340
+     * @since 0.1.41
341
+     *
342
+     * @param string|array $context The context for which to retrieve tags. Allowed values are 'post',
343
+     *                              'strip', 'data', 'entities', or the name of a field filter such as
344
+     *                              'pre_user_description'.
345
+     * @param array $input Input.
346
+     *
347
+     * @return array Array of allowed HTML tags and their allowed attributes.
348
+     */
349
+    public static function kses_allowed_html( $context = 'post', $input = array() ) {
350
+        $allowed_html = wp_kses_allowed_html( $context );
351
+
352
+        if ( is_array( $allowed_html ) ) {
353
+            // <iframe>
354
+            if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) {
355
+                $allowed_html['iframe'] = array(
356
+                    'class'           => true,
357
+                    'id'              => true,
358
+                    'src'             => true,
359
+                    'width'           => true,
360
+                    'height'          => true,
361
+                    'frameborder'     => true,
362
+                    'marginwidth'     => true,
363
+                    'marginheight'    => true,
364
+                    'scrolling'       => true,
365
+                    'style'           => true,
366
+                    'title'           => true,
367
+                    'allow'           => true,
368
+                    'allowfullscreen' => true,
369
+                    'data-*'          => true,
370
+                );
371
+            }
372
+        }
373
+
374
+        /**
375
+         * Filters the allowed html tags.
376
+         *
377
+         * @since 0.1.41
378
+         *
379
+         * @param array[]|string $allowed_html Allowed html tags.
380
+         * @param @param string|array $context The context for which to retrieve tags.
381
+         * @param array $input Input field.
382
+         */
383
+        return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input );
384
+    }
385
+
386
+    public static function get_column_class( $label_number = 2, $type = 'label' ) {
387
+
388
+        $class = '';
389
+
390
+        // set default if empty
391
+        if( $label_number === '' ){
392
+            $label_number = 2;
393
+        }
394
+
395
+        if ( $label_number && $label_number < 12 && $label_number > 0 ) {
396
+            if ( $type == 'label' ) {
397
+                $class = 'col-sm-' . absint( $label_number );
398
+            } elseif ( $type == 'input' ) {
399
+                $class = 'col-sm-' . ( 12 - absint( $label_number ) );
400
+            }
401
+        }
402
+
403
+        return $class;
404
+    }
405
+
406
+    /**
407
+     * Sanitizes a multiline string from user input or from the database.
408
+     *
409
+     * Emulate the WP native sanitize_textarea_field function in a %%variable%% safe way.
410
+     *
411
+     * @see   https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php for the original
412
+     *
413
+     * @since 0.1.66
414
+     *
415
+     * @param string $str String to sanitize.
416
+     * @return string Sanitized string.
417
+     */
418
+    public static function sanitize_textarea_field( $str ) {
419
+        $filtered = self::_sanitize_text_fields( $str, true );
420
+
421
+        /**
422
+         * Filters a sanitized textarea field string.
423
+         *
424
+         * @see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php
425
+         *
426
+         * @param string $filtered The sanitized string.
427
+         * @param string $str      The string prior to being sanitized.
428
+         */
429
+        return apply_filters( 'sanitize_textarea_field', $filtered, $str );
430
+    }
431
+
432
+    /**
433
+     * Internal helper function to sanitize a string from user input or from the db.
434
+     *
435
+     * @since 0.1.66
436
+     * @access private
437
+     *
438
+     * @param string $str           String to sanitize.
439
+     * @param bool   $keep_newlines Optional. Whether to keep newlines. Default: false.
440
+     * @return string Sanitized string.
441
+     */
442
+    public static function _sanitize_text_fields( $str, $keep_newlines = false ) {
443
+        if ( is_object( $str ) || is_array( $str ) ) {
444
+            return '';
445
+        }
446
+
447
+        $str = (string) $str;
448
+
449
+        $filtered = wp_check_invalid_utf8( $str );
450
+
451
+        if ( strpos( $filtered, '<' ) !== false ) {
452
+            $filtered = wp_pre_kses_less_than( $filtered );
453
+            // This will strip extra whitespace for us.
454
+            $filtered = wp_strip_all_tags( $filtered, false );
455
+
456
+            // Use HTML entities in a special case to make sure no later
457
+            // newline stripping stage could lead to a functional tag.
458
+            $filtered = str_replace( "<\n", "&lt;\n", $filtered );
459
+        }
460
+
461
+        if ( ! $keep_newlines ) {
462
+            $filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered );
463
+        }
464
+        $filtered = trim( $filtered );
465
+
466
+        $found = false;
467
+        while ( preg_match( '`[^%](%[a-f0-9]{2})`i', $filtered, $match ) ) {
468
+            $filtered = str_replace( $match[1], '', $filtered );
469
+            $found = true;
470
+        }
471
+        unset( $match );
472
+
473
+        if ( $found ) {
474
+            // Strip out the whitespace that may now exist after removing the octets.
475
+            $filtered = trim( preg_replace( '` +`', ' ', $filtered ) );
476
+        }
477
+
478
+        return $filtered;
479
+    }
480 480
 }
481 481
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) {
3
+if (!defined('ABSPATH')) {
4 4
 	exit; // Exit if accessed directly
5 5
 }
6 6
 
@@ -19,12 +19,12 @@  discard block
 block discarded – undo
19 19
 	 *
20 20
 	 * @return string
21 21
 	 */
22
-	public static function name( $text, $multiple = false ) {
22
+	public static function name($text, $multiple = false) {
23 23
 		$output = '';
24 24
 
25
-		if ( $text ) {
26
-			$is_multiple = strpos( $text, '[' ) === false && $multiple ? '[]' : '';
27
-			$output      = ' name="' . esc_attr( $text ) . $is_multiple . '" ';
25
+		if ($text) {
26
+			$is_multiple = strpos($text, '[') === false && $multiple ? '[]' : '';
27
+			$output      = ' name="' . esc_attr($text) . $is_multiple . '" ';
28 28
 		}
29 29
 
30 30
 		return $output;
@@ -37,11 +37,11 @@  discard block
 block discarded – undo
37 37
 	 *
38 38
 	 * @return string The sanitized item.
39 39
 	 */
40
-	public static function id( $text ) {
40
+	public static function id($text) {
41 41
 		$output = '';
42 42
 
43
-		if ( $text ) {
44
-			$output = ' id="' . sanitize_html_class( $text ) . '" ';
43
+		if ($text) {
44
+			$output = ' id="' . sanitize_html_class($text) . '" ';
45 45
 		}
46 46
 
47 47
 		return $output;
@@ -54,11 +54,11 @@  discard block
 block discarded – undo
54 54
 	 *
55 55
 	 * @return string The sanitized item.
56 56
 	 */
57
-	public static function title( $text ) {
57
+	public static function title($text) {
58 58
 		$output = '';
59 59
 
60
-		if ( $text ) {
61
-			$output = ' title="' . esc_attr( $text ) . '" ';
60
+		if ($text) {
61
+			$output = ' title="' . esc_attr($text) . '" ';
62 62
 		}
63 63
 
64 64
 		return $output;
@@ -71,11 +71,11 @@  discard block
 block discarded – undo
71 71
 	 *
72 72
 	 * @return string The sanitized item.
73 73
 	 */
74
-	public static function value( $text ) {
74
+	public static function value($text) {
75 75
 		$output = '';
76 76
 
77
-		if ( $text !== null && $text !== false ) {
78
-			$output = ' value="' . esc_attr( wp_unslash( $text ) ) . '" ';
77
+		if ($text !== null && $text !== false) {
78
+			$output = ' value="' . esc_attr(wp_unslash($text)) . '" ';
79 79
 		}
80 80
 
81 81
 		return $output;
@@ -88,12 +88,12 @@  discard block
 block discarded – undo
88 88
 	 *
89 89
 	 * @return string The sanitized item.
90 90
 	 */
91
-	public static function class_attr( $text ) {
91
+	public static function class_attr($text) {
92 92
 		$output = '';
93 93
 
94
-		if ( $text ) {
95
-			$classes = self::esc_classes( $text );
96
-			if ( ! empty( $classes ) ) {
94
+		if ($text) {
95
+			$classes = self::esc_classes($text);
96
+			if (!empty($classes)) {
97 97
 				$output = ' class="' . $classes . '" ';
98 98
 			}
99 99
 		}
@@ -108,15 +108,15 @@  discard block
 block discarded – undo
108 108
 	 *
109 109
 	 * @return string
110 110
 	 */
111
-	public static function esc_classes( $text ) {
111
+	public static function esc_classes($text) {
112 112
 		$output = '';
113 113
 
114
-		if ( $text ) {
115
-			$classes = explode( " ", $text );
116
-			$classes = array_map( "trim", $classes );
117
-			$classes = array_map( "sanitize_html_class", $classes );
118
-			if ( ! empty( $classes ) ) {
119
-				$output = implode( " ", $classes );
114
+		if ($text) {
115
+			$classes = explode(" ", $text);
116
+			$classes = array_map("trim", $classes);
117
+			$classes = array_map("sanitize_html_class", $classes);
118
+			if (!empty($classes)) {
119
+				$output = implode(" ", $classes);
120 120
 			}
121 121
 		}
122 122
 
@@ -129,14 +129,14 @@  discard block
 block discarded – undo
129 129
 	 *
130 130
 	 * @return string
131 131
 	 */
132
-	public static function data_attributes( $args ) {
132
+	public static function data_attributes($args) {
133 133
 		$output = '';
134 134
 
135
-		if ( ! empty( $args ) ) {
135
+		if (!empty($args)) {
136 136
 
137
-			foreach ( $args as $key => $val ) {
138
-				if ( substr( $key, 0, 5 ) === "data-" ) {
139
-					$output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" ';
137
+			foreach ($args as $key => $val) {
138
+				if (substr($key, 0, 5) === "data-") {
139
+					$output .= ' ' . sanitize_html_class($key) . '="' . esc_attr($val) . '" ';
140 140
 				}
141 141
 			}
142 142
 		}
@@ -149,14 +149,14 @@  discard block
 block discarded – undo
149 149
 	 *
150 150
 	 * @return string
151 151
 	 */
152
-	public static function aria_attributes( $args ) {
152
+	public static function aria_attributes($args) {
153 153
 		$output = '';
154 154
 
155
-		if ( ! empty( $args ) ) {
155
+		if (!empty($args)) {
156 156
 
157
-			foreach ( $args as $key => $val ) {
158
-				if ( substr( $key, 0, 5 ) === "aria-" ) {
159
-					$output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" ';
157
+			foreach ($args as $key => $val) {
158
+				if (substr($key, 0, 5) === "aria-") {
159
+					$output .= ' ' . sanitize_html_class($key) . '="' . esc_attr($val) . '" ';
160 160
 				}
161 161
 			}
162 162
 		}
@@ -173,19 +173,19 @@  discard block
 block discarded – undo
173 173
 	 *
174 174
 	 * @return string
175 175
 	 */
176
-	public static function icon( $class, $space_after = false, $extra_attributes = array() ) {
176
+	public static function icon($class, $space_after = false, $extra_attributes = array()) {
177 177
 		$output = '';
178 178
 
179
-		if ( $class ) {
180
-			$classes = self::esc_classes( $class );
181
-			if ( ! empty( $classes ) ) {
179
+		if ($class) {
180
+			$classes = self::esc_classes($class);
181
+			if (!empty($classes)) {
182 182
 				$output = '<i class="' . $classes . '" ';
183 183
 				// extra attributes
184
-				if ( ! empty( $extra_attributes ) ) {
185
-					$output .= AUI_Component_Helper::extra_attributes( $extra_attributes );
184
+				if (!empty($extra_attributes)) {
185
+					$output .= AUI_Component_Helper::extra_attributes($extra_attributes);
186 186
 				}
187 187
 				$output .= '></i>';
188
-				if ( $space_after ) {
188
+				if ($space_after) {
189 189
 					$output .= " ";
190 190
 				}
191 191
 			}
@@ -199,14 +199,14 @@  discard block
 block discarded – undo
199 199
 	 *
200 200
 	 * @return string
201 201
 	 */
202
-	public static function extra_attributes( $args ) {
202
+	public static function extra_attributes($args) {
203 203
 		$output = '';
204 204
 
205
-		if ( ! empty( $args ) ) {
205
+		if (!empty($args)) {
206 206
 
207
-			if ( is_array( $args ) ) {
208
-				foreach ( $args as $key => $val ) {
209
-					$output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" ';
207
+			if (is_array($args)) {
208
+				foreach ($args as $key => $val) {
209
+					$output .= ' ' . sanitize_html_class($key) . '="' . esc_attr($val) . '" ';
210 210
 				}
211 211
 			} else {
212 212
 				$output .= ' ' . $args . ' ';
@@ -222,11 +222,11 @@  discard block
 block discarded – undo
222 222
 	 *
223 223
 	 * @return string
224 224
 	 */
225
-	public static function help_text( $text ) {
225
+	public static function help_text($text) {
226 226
 		$output = '';
227 227
 
228
-		if ( $text ) {
229
-			$output .= '<small class="form-text text-muted d-block">' . wp_kses_post( $text ) . '</small>';
228
+		if ($text) {
229
+			$output .= '<small class="form-text text-muted d-block">' . wp_kses_post($text) . '</small>';
230 230
 		}
231 231
 
232 232
 
@@ -240,17 +240,17 @@  discard block
 block discarded – undo
240 240
 	 *
241 241
 	 * @return string|void
242 242
 	 */
243
-	public static function element_require( $input ) {
243
+	public static function element_require($input) {
244 244
 
245
-		$input = str_replace( "'", '"', $input );// we only want double quotes
245
+		$input = str_replace("'", '"', $input); // we only want double quotes
246 246
 
247
-		$output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array(
247
+		$output = esc_attr(str_replace(array("[%", "%]", "%:checked]"), array(
248 248
 			"jQuery(form).find('[data-argument=\"",
249 249
 			"\"]').find('input,select,textarea').val()",
250 250
 			"\"]').find('input:checked').val()",
251
-		), $input ) );
251
+		), $input));
252 252
 
253
-		if ( $output ) {
253
+		if ($output) {
254 254
 			$output = ' data-element-require="' . $output . '" ';
255 255
 		}
256 256
 
@@ -267,21 +267,21 @@  discard block
 block discarded – undo
267 267
 	 *
268 268
 	 * @return mixed Stripped value.
269 269
 	 */
270
-	public static function sanitize_html_field( $value, $input = array() ) {
270
+	public static function sanitize_html_field($value, $input = array()) {
271 271
 		$original = $value;
272 272
 
273
-		if ( is_array( $value ) ) {
274
-			foreach ( $value as $index => $item ) {
275
-				$value[ $index ] = self::_sanitize_html_field( $value, $input );
273
+		if (is_array($value)) {
274
+			foreach ($value as $index => $item) {
275
+				$value[$index] = self::_sanitize_html_field($value, $input);
276 276
 			}
277
-		} elseif ( is_object( $value ) ) {
278
-			$object_vars = get_object_vars( $value );
277
+		} elseif (is_object($value)) {
278
+			$object_vars = get_object_vars($value);
279 279
 
280
-			foreach ( $object_vars as $property_name => $property_value ) {
281
-				$value->$property_name = self::_sanitize_html_field( $property_value, $input );
280
+			foreach ($object_vars as $property_name => $property_value) {
281
+				$value->$property_name = self::_sanitize_html_field($property_value, $input);
282 282
 			}
283 283
 		} else {
284
-			$value = self::_sanitize_html_field( $value, $input );
284
+			$value = self::_sanitize_html_field($value, $input);
285 285
 		}
286 286
 
287 287
 		/**
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
 		 * @param string|array $value Original content without filter.
294 294
 		 * @param array $input Input Field.
295 295
 		 */
296
-		return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input );
296
+		return apply_filters('ayecode_ui_sanitize_html_field', $value, $original, $input);
297 297
 	}
298 298
 
299 299
 	/**
@@ -316,20 +316,20 @@  discard block
 block discarded – undo
316 316
 	 *
317 317
 	 * @return string Filtered content with only allowed HTML elements.
318 318
 	 */
319
-	public static function _sanitize_html_field( $value, $input = array() ) {
320
-		if ( $value === '' ) {
319
+	public static function _sanitize_html_field($value, $input = array()) {
320
+		if ($value === '') {
321 321
 			return $value;
322 322
 		}
323 323
 
324
-		$allowed_html = self::kses_allowed_html( 'post', $input );
324
+		$allowed_html = self::kses_allowed_html('post', $input);
325 325
 
326
-		if ( ! is_array( $allowed_html ) ) {
327
-			$allowed_html = wp_kses_allowed_html( 'post' );
326
+		if (!is_array($allowed_html)) {
327
+			$allowed_html = wp_kses_allowed_html('post');
328 328
 		}
329 329
 
330
-		$filtered = trim( wp_unslash( $value ) );
331
-		$filtered = wp_kses( $filtered, $allowed_html );
332
-		$filtered = balanceTags( $filtered ); // Balances tags
330
+		$filtered = trim(wp_unslash($value));
331
+		$filtered = wp_kses($filtered, $allowed_html);
332
+		$filtered = balanceTags($filtered); // Balances tags
333 333
 
334 334
 		return $filtered;
335 335
 	}
@@ -346,12 +346,12 @@  discard block
 block discarded – undo
346 346
 	 *
347 347
 	 * @return array Array of allowed HTML tags and their allowed attributes.
348 348
 	 */
349
-	public static function kses_allowed_html( $context = 'post', $input = array() ) {
350
-		$allowed_html = wp_kses_allowed_html( $context );
349
+	public static function kses_allowed_html($context = 'post', $input = array()) {
350
+		$allowed_html = wp_kses_allowed_html($context);
351 351
 
352
-		if ( is_array( $allowed_html ) ) {
352
+		if (is_array($allowed_html)) {
353 353
 			// <iframe>
354
-			if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) {
354
+			if (!isset($allowed_html['iframe']) && $context == 'post') {
355 355
 				$allowed_html['iframe'] = array(
356 356
 					'class'           => true,
357 357
 					'id'              => true,
@@ -380,23 +380,23 @@  discard block
 block discarded – undo
380 380
 		 * @param @param string|array $context The context for which to retrieve tags.
381 381
 		 * @param array $input Input field.
382 382
 		 */
383
-		return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input );
383
+		return apply_filters('ayecode_ui_kses_allowed_html', $allowed_html, $context, $input);
384 384
 	}
385 385
 
386
-	public static function get_column_class( $label_number = 2, $type = 'label' ) {
386
+	public static function get_column_class($label_number = 2, $type = 'label') {
387 387
 
388 388
 		$class = '';
389 389
 
390 390
 		// set default if empty
391
-		if( $label_number === '' ){
391
+		if ($label_number === '') {
392 392
 			$label_number = 2;
393 393
 		}
394 394
 
395
-		if ( $label_number && $label_number < 12 && $label_number > 0 ) {
396
-			if ( $type == 'label' ) {
397
-				$class = 'col-sm-' . absint( $label_number );
398
-			} elseif ( $type == 'input' ) {
399
-				$class = 'col-sm-' . ( 12 - absint( $label_number ) );
395
+		if ($label_number && $label_number < 12 && $label_number > 0) {
396
+			if ($type == 'label') {
397
+				$class = 'col-sm-' . absint($label_number);
398
+			} elseif ($type == 'input') {
399
+				$class = 'col-sm-' . (12 - absint($label_number));
400 400
 			}
401 401
 		}
402 402
 
@@ -415,8 +415,8 @@  discard block
 block discarded – undo
415 415
 	 * @param string $str String to sanitize.
416 416
 	 * @return string Sanitized string.
417 417
 	 */
418
-	public static function sanitize_textarea_field( $str ) {
419
-		$filtered = self::_sanitize_text_fields( $str, true );
418
+	public static function sanitize_textarea_field($str) {
419
+		$filtered = self::_sanitize_text_fields($str, true);
420 420
 
421 421
 		/**
422 422
 		 * Filters a sanitized textarea field string.
@@ -426,7 +426,7 @@  discard block
 block discarded – undo
426 426
 		 * @param string $filtered The sanitized string.
427 427
 		 * @param string $str      The string prior to being sanitized.
428 428
 		 */
429
-		return apply_filters( 'sanitize_textarea_field', $filtered, $str );
429
+		return apply_filters('sanitize_textarea_field', $filtered, $str);
430 430
 	}
431 431
 
432 432
 	/**
@@ -439,40 +439,40 @@  discard block
 block discarded – undo
439 439
 	 * @param bool   $keep_newlines Optional. Whether to keep newlines. Default: false.
440 440
 	 * @return string Sanitized string.
441 441
 	 */
442
-	public static function _sanitize_text_fields( $str, $keep_newlines = false ) {
443
-		if ( is_object( $str ) || is_array( $str ) ) {
442
+	public static function _sanitize_text_fields($str, $keep_newlines = false) {
443
+		if (is_object($str) || is_array($str)) {
444 444
 			return '';
445 445
 		}
446 446
 
447 447
 		$str = (string) $str;
448 448
 
449
-		$filtered = wp_check_invalid_utf8( $str );
449
+		$filtered = wp_check_invalid_utf8($str);
450 450
 
451
-		if ( strpos( $filtered, '<' ) !== false ) {
452
-			$filtered = wp_pre_kses_less_than( $filtered );
451
+		if (strpos($filtered, '<') !== false) {
452
+			$filtered = wp_pre_kses_less_than($filtered);
453 453
 			// This will strip extra whitespace for us.
454
-			$filtered = wp_strip_all_tags( $filtered, false );
454
+			$filtered = wp_strip_all_tags($filtered, false);
455 455
 
456 456
 			// Use HTML entities in a special case to make sure no later
457 457
 			// newline stripping stage could lead to a functional tag.
458
-			$filtered = str_replace( "<\n", "&lt;\n", $filtered );
458
+			$filtered = str_replace("<\n", "&lt;\n", $filtered);
459 459
 		}
460 460
 
461
-		if ( ! $keep_newlines ) {
462
-			$filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered );
461
+		if (!$keep_newlines) {
462
+			$filtered = preg_replace('/[\r\n\t ]+/', ' ', $filtered);
463 463
 		}
464
-		$filtered = trim( $filtered );
464
+		$filtered = trim($filtered);
465 465
 
466 466
 		$found = false;
467
-		while ( preg_match( '`[^%](%[a-f0-9]{2})`i', $filtered, $match ) ) {
468
-			$filtered = str_replace( $match[1], '', $filtered );
467
+		while (preg_match('`[^%](%[a-f0-9]{2})`i', $filtered, $match)) {
468
+			$filtered = str_replace($match[1], '', $filtered);
469 469
 			$found = true;
470 470
 		}
471
-		unset( $match );
471
+		unset($match);
472 472
 
473
-		if ( $found ) {
473
+		if ($found) {
474 474
 			// Strip out the whitespace that may now exist after removing the octets.
475
-			$filtered = trim( preg_replace( '` +`', ' ', $filtered ) );
475
+			$filtered = trim(preg_replace('` +`', ' ', $filtered));
476 476
 		}
477 477
 
478 478
 		return $filtered;
Please login to merge, or discard this patch.