Passed
Push — master ( 6086f2...9dee83 )
by Kiran
09:50 queued 20s
created
includes/class-wpinv-session-handler.php 1 patch
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.
includes/admin/class-getpaid-metaboxes.php 1 patch
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.
ayecode/wp-ayecode-ui/includes/components/class-aui-component-alert.php 1 patch
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.
ayecode/wp-ayecode-ui/includes/components/class-aui-component-helper.php 1 patch
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.
vendor/ayecode/wp-ayecode-ui/includes/inc/bs4-js.php 1 patch
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.
templates/payment-forms/cart-item.php 1 patch
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -26,71 +26,71 @@  discard block
 block discarded – undo
26 26
 
27 27
 				<?php
28 28
 
29
-					// Fires before printing a line item column.
30
-					do_action( "getpaid_form_cart_item_before_$key", $item, $form );
29
+                    // Fires before printing a line item column.
30
+                    do_action( "getpaid_form_cart_item_before_$key", $item, $form );
31 31
 
32
-					// Item name.
33
-					if ( 'name' === $key ) {
32
+                    // Item name.
33
+                    if ( 'name' === $key ) {
34 34
 
35 35
 
36
-						ob_start();
36
+                        ob_start();
37 37
 
38
-						// Add an optional description.
39
-						$description = $item->get_description();
38
+                        // Add an optional description.
39
+                        $description = $item->get_description();
40 40
 
41
-						if ( ! empty( $description ) ) {
42
-							echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post( $description ) . '</small>';
43
-						}
41
+                        if ( ! empty( $description ) ) {
42
+                            echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post( $description ) . '</small>';
43
+                        }
44 44
 
45
-						// Price help text.
46
-						$description = getpaid_item_recurring_price_help_text( $item, $currency );
47
-						if ( $description ) {
48
-							echo "<small class='getpaid-form-item-price-desc form-text text-muted font-italic pr-2 m-0'>" . wp_kses_post( $description ) . '</small>';
49
-						}
45
+                        // Price help text.
46
+                        $description = getpaid_item_recurring_price_help_text( $item, $currency );
47
+                        if ( $description ) {
48
+                            echo "<small class='getpaid-form-item-price-desc form-text text-muted font-italic pr-2 m-0'>" . wp_kses_post( $description ) . '</small>';
49
+                        }
50 50
 
51
-						do_action( 'getpaid_payment_form_cart_item_description', $item, $form );
51
+                        do_action( 'getpaid_payment_form_cart_item_description', $item, $form );
52 52
 
53
-						if ( wpinv_current_user_can_manage_invoicing() ) {
53
+                        if ( wpinv_current_user_can_manage_invoicing() ) {
54 54
 
55
-							edit_post_link(
56
-								__( 'Edit this item.', 'invoicing' ),
57
-								'<small class="form-text text-muted">',
58
-								'</small>',
59
-								$item->get_id(),
60
-								'text-danger'
61
-							);
55
+                            edit_post_link(
56
+                                __( 'Edit this item.', 'invoicing' ),
57
+                                '<small class="form-text text-muted">',
58
+                                '</small>',
59
+                                $item->get_id(),
60
+                                'text-danger'
61
+                            );
62 62
 
63
-						}
63
+                        }
64 64
 
65
-						$description = ob_get_clean();
65
+                        $description = ob_get_clean();
66 66
 
67
-						// Display the name.
68
-						$tootip = empty( $description ) ? '' : '&nbsp;<i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>';
67
+                        // Display the name.
68
+                        $tootip = empty( $description ) ? '' : '&nbsp;<i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>';
69 69
 
70
-						$has_featured_image = has_post_thumbnail( $item->get_id() );
70
+                        $has_featured_image = has_post_thumbnail( $item->get_id() );
71 71
 
72
-						if ( $has_featured_image ) {
73
-							echo '<div class="d-flex align-items-center getpaid-form-item-has-featured-image">';
74
-							echo '<div class="getpaid-form-item-image-container mr-2">';
75
-							echo get_the_post_thumbnail( $item->get_id(), 'thumbnail', array( 'class' => 'getpaid-form-item-image mb-0' ) );
76
-							echo '</div>';
77
-							echo '<div class="getpaid-form-item-name-container">';
78
-						}
72
+                        if ( $has_featured_image ) {
73
+                            echo '<div class="d-flex align-items-center getpaid-form-item-has-featured-image">';
74
+                            echo '<div class="getpaid-form-item-image-container mr-2">';
75
+                            echo get_the_post_thumbnail( $item->get_id(), 'thumbnail', array( 'class' => 'getpaid-form-item-image mb-0' ) );
76
+                            echo '</div>';
77
+                            echo '<div class="getpaid-form-item-name-container">';
78
+                        }
79 79
 
80
-						echo '<div class="mb-1 font-weight-bold">' . esc_html( $item->get_name() ) . wp_kses_post( $tootip ) . '</div>';
80
+                        echo '<div class="mb-1 font-weight-bold">' . esc_html( $item->get_name() ) . wp_kses_post( $tootip ) . '</div>';
81 81
 
82
-						if ( ! empty( $description ) ) {
83
-							printf( '<span class="d-none d-sm-block getpaid-item-desc">%s</span>', wp_kses_post( $description ) );
84
-						}
82
+                        if ( ! empty( $description ) ) {
83
+                            printf( '<span class="d-none d-sm-block getpaid-item-desc">%s</span>', wp_kses_post( $description ) );
84
+                        }
85 85
 
86
-						if ( $item->allows_quantities() ) {
87
-							printf(
88
-								'<small class="d-sm-none text-muted form-text">%s</small>',
89
-								sprintf(
90
-									// translators: %s is the item quantity.
91
-									esc_html__( 'Qty %s', 'invoicing' ),
92
-									sprintf(
93
-										'<input
86
+                        if ( $item->allows_quantities() ) {
87
+                            printf(
88
+                                '<small class="d-sm-none text-muted form-text">%s</small>',
89
+                                sprintf(
90
+                                    // translators: %s is the item quantity.
91
+                                    esc_html__( 'Qty %s', 'invoicing' ),
92
+                                    sprintf(
93
+                                        '<input
94 94
 											type="number"
95 95
 											step="0.01"
96 96
 											style="width: 48px;"
@@ -99,62 +99,62 @@  discard block
 block discarded – undo
99 99
 											min="1"
100 100
 											max="%s"
101 101
 										>',
102
-										(float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(),
103
-										floatval( null !== $max_qty ? $max_qty : 1000000000000 )
104
-									)
105
-								)
106
-							);
107
-						} else {
108
-							printf(
109
-								'<small class="d-sm-none text-muted form-text">%s</small>',
110
-								sprintf(
111
-									// translators: %s is the item quantity.
112
-									esc_html__( 'Qty %s', 'invoicing' ),
113
-									(float) $item->get_quantity()
114
-								)
115
-							);
116
-						}
117
-
118
-						if ( $has_featured_image ) {
119
-							echo '</div>';
120
-							echo '</div>';
121
-						}
122
-					}
123
-
124
-					// Item price.
125
-					if ( 'price' === $key ) {
126
-
127
-					// Set the currency position.
128
-					$position = wpinv_currency_position();
129
-
130
-					if ( 'left_space' === $position ) {
131
-						$position = 'left';
132
-					}
133
-
134
-					if ( 'right_space' === $position ) {
135
-						$position = 'right';
136
-					}
137
-
138
-					if ( $item->user_can_set_their_price() ) {
139
-						$price            = max( (float) $item->get_price(), (float) $item->get_minimum_price() );
140
-						$minimum          = (float) $item->get_minimum_price();
141
-						$validate_minimum = '';
142
-						$class            = '';
143
-						$data_minimum     = '';
144
-
145
-						if ( $minimum > 0 ) {
146
-							$validate_minimum = sprintf(
147
-								// translators: %s is the minimum price.
148
-								esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ),
149
-								wp_strip_all_tags( wpinv_price( $minimum, $currency ) )
150
-							);
151
-
152
-							$class = 'getpaid-validate-minimum-amount';
153
-
154
-							$data_minimum     = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'";
155
-						}
156
-
157
-						?>
102
+                                        (float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(),
103
+                                        floatval( null !== $max_qty ? $max_qty : 1000000000000 )
104
+                                    )
105
+                                )
106
+                            );
107
+                        } else {
108
+                            printf(
109
+                                '<small class="d-sm-none text-muted form-text">%s</small>',
110
+                                sprintf(
111
+                                    // translators: %s is the item quantity.
112
+                                    esc_html__( 'Qty %s', 'invoicing' ),
113
+                                    (float) $item->get_quantity()
114
+                                )
115
+                            );
116
+                        }
117
+
118
+                        if ( $has_featured_image ) {
119
+                            echo '</div>';
120
+                            echo '</div>';
121
+                        }
122
+                    }
123
+
124
+                    // Item price.
125
+                    if ( 'price' === $key ) {
126
+
127
+                    // Set the currency position.
128
+                    $position = wpinv_currency_position();
129
+
130
+                    if ( 'left_space' === $position ) {
131
+                        $position = 'left';
132
+                    }
133
+
134
+                    if ( 'right_space' === $position ) {
135
+                        $position = 'right';
136
+                    }
137
+
138
+                    if ( $item->user_can_set_their_price() ) {
139
+                        $price            = max( (float) $item->get_price(), (float) $item->get_minimum_price() );
140
+                        $minimum          = (float) $item->get_minimum_price();
141
+                        $validate_minimum = '';
142
+                        $class            = '';
143
+                        $data_minimum     = '';
144
+
145
+                        if ( $minimum > 0 ) {
146
+                            $validate_minimum = sprintf(
147
+                                // translators: %s is the minimum price.
148
+                                esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ),
149
+                                wp_strip_all_tags( wpinv_price( $minimum, $currency ) )
150
+                            );
151
+
152
+                            $class = 'getpaid-validate-minimum-amount';
153
+
154
+                            $data_minimum     = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'";
155
+                        }
156
+
157
+                        ?>
158 158
 								<div class="input-group input-group-sm">
159 159
 									<?php if ( 'left' === $position ) : ?>
160 160
 										<?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?>
@@ -195,46 +195,46 @@  discard block
 block discarded – undo
195 195
 
196 196
 							<?php
197 197
 
198
-						} else {
199
-						?>
198
+                        } else {
199
+                        ?>
200 200
 							<span class="getpaid-items-<?php echo (int) $item->get_id(); ?>-view-price">
201 201
 								<?php echo wp_kses_post( wpinv_price( $item->get_price(), $currency ) ); ?>
202 202
 							</span>
203 203
 							<input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr( $item->get_price() ); ?>'>
204 204
 						<?php
205
-						}
205
+                        }
206 206
 
207
-					printf(
207
+                    printf(
208 208
                         '<small class="d-sm-none text-muted form-text getpaid-mobile-item-subtotal">%s</small>',
209
-						// translators: %s is the item subtotal.
209
+                        // translators: %s is the item subtotal.
210 210
                         sprintf( esc_html__( 'Subtotal: %s', 'invoicing' ), wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ) )
211 211
                     );
212
-					}
212
+                    }
213 213
 
214
-					// Item quantity.
215
-					if ( 'quantity' === $key ) {
214
+                    // Item quantity.
215
+                    if ( 'quantity' === $key ) {
216 216
 
217
-					if ( $item->allows_quantities() ) {
218
-						?>
217
+                    if ( $item->allows_quantities() ) {
218
+                        ?>
219 219
 								<input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' type="number" step="any" style='width: 64px; line-height: 1; min-height: 35px;' class='getpaid-item-quantity-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border' value='<?php echo (float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(); ?>' min='1' <?php echo null !== $max_qty ? 'max="' . (float) $max_qty . '"' : ''; ?> required>
220 220
 						<?php
221
-							} else {
222
-						?>
221
+                            } else {
222
+                        ?>
223 223
 							<span class="getpaid-items-<?php echo (int) $item->get_id(); ?>-view-quantity">
224 224
 								<?php echo (float) $item->get_quantity(); ?>
225 225
 							</span>&nbsp;&nbsp;&nbsp;
226 226
 							<input type='hidden' name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' class='getpaid-item-quantity-input' value='<?php echo (float) $item->get_quantity(); ?>'>
227 227
 						<?php
228
-						}
228
+                        }
229 229
 }
230 230
 
231
-					// Item sub total.
232
-					if ( 'subtotal' === $key ) {
233
-					echo wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) );
234
-					}
231
+                    // Item sub total.
232
+                    if ( 'subtotal' === $key ) {
233
+                    echo wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) );
234
+                    }
235 235
 
236
-					do_action( "getpaid_payment_form_cart_item_$key", $item, $form );
237
-				?>
236
+                    do_action( "getpaid_payment_form_cart_item_$key", $item, $form );
237
+                ?>
238 238
 
239 239
 			</div>
240 240
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-items.php 1 patch
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -12,51 +12,51 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Items {
14 14
 
15
-	/**
16
-	 * Submission items.
17
-	 * @var GetPaid_Form_Item[]
18
-	 */
19
-	public $items = array();
15
+    /**
16
+     * Submission items.
17
+     * @var GetPaid_Form_Item[]
18
+     */
19
+    public $items = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$data         = $submission->get_data();
29
-		$payment_form = $submission->get_payment_form();
30
-		$invoice      = $submission->get_invoice();
31
-		$force_prices = array();
32
-
33
-		// Prepare the selected items.
34
-		$selected_items = array();
35
-		if ( ! empty( $data['getpaid-items'] ) ) {
36
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
37
-
38
-			if ( ! empty( $invoice ) && $submission->is_initial_fetch() ) {
39
-				foreach ( $invoice->get_items() as $invoice_item ) {
40
-					if ( isset( $selected_items[ $invoice_item->get_id() ] ) ) {
41
-						$selected_items[ $invoice_item->get_id() ]['quantity'] = $invoice_item->get_quantity();
42
-						$selected_items[ $invoice_item->get_id() ]['price']    = $invoice_item->get_price();
43
-
44
-						$force_prices[ $invoice_item->get_id() ] = $invoice_item->get_price();
45
-					}
46
-				}
47
-			}
48
-		}
49
-
50
-		// (Maybe) set form items.
51
-		if ( isset( $data['getpaid-form-items'] ) ) {
52
-
53
-			// Confirm items key.
54
-			$form_items = wpinv_clean( $data['getpaid-form-items'] );
55
-			if ( ! isset( $data['getpaid-form-items-key'] ) || md5( NONCE_KEY . AUTH_KEY . $form_items ) !== $data['getpaid-form-items-key'] ) {
56
-				throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) );
57
-			}
58
-
59
-			$items    = array();
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $data         = $submission->get_data();
29
+        $payment_form = $submission->get_payment_form();
30
+        $invoice      = $submission->get_invoice();
31
+        $force_prices = array();
32
+
33
+        // Prepare the selected items.
34
+        $selected_items = array();
35
+        if ( ! empty( $data['getpaid-items'] ) ) {
36
+            $selected_items = wpinv_clean( $data['getpaid-items'] );
37
+
38
+            if ( ! empty( $invoice ) && $submission->is_initial_fetch() ) {
39
+                foreach ( $invoice->get_items() as $invoice_item ) {
40
+                    if ( isset( $selected_items[ $invoice_item->get_id() ] ) ) {
41
+                        $selected_items[ $invoice_item->get_id() ]['quantity'] = $invoice_item->get_quantity();
42
+                        $selected_items[ $invoice_item->get_id() ]['price']    = $invoice_item->get_price();
43
+
44
+                        $force_prices[ $invoice_item->get_id() ] = $invoice_item->get_price();
45
+                    }
46
+                }
47
+            }
48
+        }
49
+
50
+        // (Maybe) set form items.
51
+        if ( isset( $data['getpaid-form-items'] ) ) {
52
+
53
+            // Confirm items key.
54
+            $form_items = wpinv_clean( $data['getpaid-form-items'] );
55
+            if ( ! isset( $data['getpaid-form-items-key'] ) || md5( NONCE_KEY . AUTH_KEY . $form_items ) !== $data['getpaid-form-items-key'] ) {
56
+                throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) );
57
+            }
58
+
59
+            $items    = array();
60 60
             $item_ids = array();
61 61
 
62 62
             foreach ( getpaid_convert_items_to_array( $form_items ) as $item_id => $qty ) {
@@ -69,10 +69,10 @@  discard block
 block discarded – undo
69 69
                         $item->set_is_required( false );
70 70
                     }
71 71
 
72
-					if ( ! $item->user_can_set_their_price() && isset( $force_prices[ $item_id ] ) ) {
73
-						$item->set_is_dynamic_pricing( true );
74
-						$item->set_minimum_price( 0 );
75
-					}
72
+                    if ( ! $item->user_can_set_their_price() && isset( $force_prices[ $item_id ] ) ) {
73
+                        $item->set_is_dynamic_pricing( true );
74
+                        $item->set_minimum_price( 0 );
75
+                    }
76 76
 
77 77
                     $item_ids[] = $item->get_id();
78 78
                     $items[]    = $item;
@@ -87,61 +87,61 @@  discard block
 block discarded – undo
87 87
                         $items[]    = $item;
88 88
                     }
89 89
                 }
90
-			}
90
+            }
91 91
 
92 92
             $payment_form->set_items( $items );
93 93
 
94
-		}
95
-
96
-		// Process each individual item.
97
-		foreach ( $payment_form->get_items() as $item ) {
98
-			$this->process_item( $item, $selected_items, $submission );
99
-		}
100
-
101
-	}
102
-
103
-	/**
104
-	 * Process a single item.
105
-	 *
106
-	 * @param GetPaid_Form_Item $item
107
-	 * @param array $selected_items
108
-	 * @param GetPaid_Payment_Form_Submission $submission
109
-	 */
110
-	public function process_item( $item, $selected_items, $submission ) {
94
+        }
111 95
 
112
-		// Abort if this is an optional item and it has not been selected.
113
-		if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
114
-			return;
115
-		}
96
+        // Process each individual item.
97
+        foreach ( $payment_form->get_items() as $item ) {
98
+            $this->process_item( $item, $selected_items, $submission );
99
+        }
116 100
 
117
-		// (maybe) let customers change the quantities and prices.
118
-		if ( isset( $selected_items[ $item->get_id() ] ) ) {
101
+    }
119 102
 
120
-			// Maybe change the quantities.
121
-			if ( $item->allows_quantities() ) {
122
-				$item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] );
123
-			}
103
+    /**
104
+     * Process a single item.
105
+     *
106
+     * @param GetPaid_Form_Item $item
107
+     * @param array $selected_items
108
+     * @param GetPaid_Payment_Form_Submission $submission
109
+     */
110
+    public function process_item( $item, $selected_items, $submission ) {
111
+
112
+        // Abort if this is an optional item and it has not been selected.
113
+        if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
114
+            return;
115
+        }
116
+
117
+        // (maybe) let customers change the quantities and prices.
118
+        if ( isset( $selected_items[ $item->get_id() ] ) ) {
119
+
120
+            // Maybe change the quantities.
121
+            if ( $item->allows_quantities() ) {
122
+                $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] );
123
+            }
124 124
 
125
-			// Maybe change the price.
126
-			if ( $item->user_can_set_their_price() ) {
127
-				$price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
125
+            // Maybe change the price.
126
+            if ( $item->user_can_set_their_price() ) {
127
+                $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
128 128
 
129
-				if ( $item->get_minimum_price() > $price ) {
130
-					throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) );
131
-				}
129
+                if ( $item->get_minimum_price() > $price ) {
130
+                    throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) );
131
+                }
132 132
 
133
-				$item->set_price( $price );
133
+                $item->set_price( $price );
134 134
 
135
-			}
136
-		}
135
+            }
136
+        }
137 137
 
138
-		if ( 0 == $item->get_quantity() ) {
139
-			return;
140
-		}
138
+        if ( 0 == $item->get_quantity() ) {
139
+            return;
140
+        }
141 141
 
142
-		// Save the item.
143
-		$this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission );
142
+        // Save the item.
143
+        $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission );
144 144
 
145
-	}
145
+    }
146 146
 
147 147
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-form-item.php 1 patch
Indentation   +359 added lines, -359 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,67 +10,67 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Form_Item  extends WPInv_Item {
11 11
 
12 12
     /**
13
-	 * Stores a custom description for the item.
14
-	 *
15
-	 * @var string
16
-	 */
17
-	protected $custom_description = null;
18
-
19
-	/**
20
-	 * Stores the item quantity.
21
-	 *
22
-	 * @var float
23
-	 */
24
-	protected $quantity = 1;
25
-
26
-	/**
27
-	 * Stores the item meta.
28
-	 *
29
-	 * @var array
30
-	 */
31
-	protected $meta = array();
32
-
33
-	/**
34
-	 * Is this item required?
35
-	 *
36
-	 * @var int
37
-	 */
38
-	protected $is_required = true;
39
-
40
-	/**
41
-	 * Are quantities allowed?
42
-	 *
43
-	 * @var int
44
-	 */
45
-	protected $allow_quantities = false;
46
-
47
-	/**
48
-	 * Associated invoice.
49
-	 *
50
-	 * @var int
51
-	 */
52
-	public $invoice_id = 0;
53
-
54
-	/**
55
-	 * Item discount.
56
-	 *
57
-	 * @var float
58
-	 */
59
-	public $item_discount = 0;
60
-
61
-	/**
62
-	 * Recurring item discount.
63
-	 *
64
-	 * @var float
65
-	 */
66
-	public $recurring_item_discount = 0;
67
-
68
-	/**
69
-	 * Item tax.
70
-	 *
71
-	 * @var float
72
-	 */
73
-	public $item_tax = 0;
13
+     * Stores a custom description for the item.
14
+     *
15
+     * @var string
16
+     */
17
+    protected $custom_description = null;
18
+
19
+    /**
20
+     * Stores the item quantity.
21
+     *
22
+     * @var float
23
+     */
24
+    protected $quantity = 1;
25
+
26
+    /**
27
+     * Stores the item meta.
28
+     *
29
+     * @var array
30
+     */
31
+    protected $meta = array();
32
+
33
+    /**
34
+     * Is this item required?
35
+     *
36
+     * @var int
37
+     */
38
+    protected $is_required = true;
39
+
40
+    /**
41
+     * Are quantities allowed?
42
+     *
43
+     * @var int
44
+     */
45
+    protected $allow_quantities = false;
46
+
47
+    /**
48
+     * Associated invoice.
49
+     *
50
+     * @var int
51
+     */
52
+    public $invoice_id = 0;
53
+
54
+    /**
55
+     * Item discount.
56
+     *
57
+     * @var float
58
+     */
59
+    public $item_discount = 0;
60
+
61
+    /**
62
+     * Recurring item discount.
63
+     *
64
+     * @var float
65
+     */
66
+    public $recurring_item_discount = 0;
67
+
68
+    /**
69
+     * Item tax.
70
+     *
71
+     * @var float
72
+     */
73
+    public $item_tax = 0;
74 74
 
75 75
     /*
76 76
 	|--------------------------------------------------------------------------
@@ -88,230 +88,230 @@  discard block
 block discarded – undo
88 88
     */
89 89
 
90 90
     /**
91
-	 * Get the item name.
92
-	 *
93
-	 * @since 1.0.19
94
-	 * @param  string $context View or edit context.
95
-	 * @return string
96
-	 */
97
-	public function get_name( $context = 'view' ) {
98
-		$name = parent::get_name( $context );
99
-		return $name . wpinv_get_item_suffix( $this );
100
-	}
101
-
102
-	/**
103
-	 * Get the item name without a suffix.
104
-	 *
105
-	 * @since 1.0.19
106
-	 * @param  string $context View or edit context.
107
-	 * @return string
108
-	 */
109
-	public function get_raw_name( $context = 'view' ) {
110
-		return parent::get_name( $context );
111
-	}
112
-
113
-	/**
114
-	 * Get the item description.
115
-	 *
116
-	 * @since 1.0.19
117
-	 * @param  string $context View or edit context.
118
-	 * @return string
119
-	 */
120
-	public function get_description( $context = 'view' ) {
121
-
122
-		if ( isset( $this->custom_description ) ) {
123
-			return $this->custom_description;
124
-		}
125
-
126
-		return parent::get_description( $context );
127
-	}
128
-
129
-	/**
130
-	 * Returns the sub total.
131
-	 *
132
-	 * @since 1.0.19
133
-	 * @param  string $context View or edit context.
134
-	 * @return float
135
-	 */
136
-	public function get_sub_total( $context = 'view' ) {
137
-		return $this->get_quantity( $context ) * $this->get_initial_price( $context );
138
-	}
139
-
140
-	/**
141
-	 * Returns the recurring sub total.
142
-	 *
143
-	 * @since 1.0.19
144
-	 * @param  string $context View or edit context.
145
-	 * @return float
146
-	 */
147
-	public function get_recurring_sub_total( $context = 'view' ) {
148
-
149
-		if ( $this->is_recurring() ) {
150
-			return $this->get_quantity( $context ) * $this->get_price( $context );
151
-		}
152
-
153
-		return 0;
154
-	}
155
-
156
-	/**
157
-	 * @deprecated
158
-	 */
159
-	public function get_qantity( $context = 'view' ) {
160
-		return $this->get_quantity( $context );
161
-	}
162
-
163
-	/**
164
-	 * Get the item quantity.
165
-	 *
166
-	 * @since 1.0.19
167
-	 * @param  string $context View or edit context.
168
-	 * @return float
169
-	 */
170
-	public function get_quantity( $context = 'view' ) {
171
-		$quantity = (float) $this->quantity;
172
-
173
-		if ( 'view' === $context ) {
174
-			return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this );
175
-		}
176
-
177
-		return $quantity;
178
-
179
-	}
180
-
181
-	/**
182
-	 * Get the item meta data.
183
-	 *
184
-	 * @since 1.0.19
185
-	 * @param  string $context View or edit context.
186
-	 * @return meta
187
-	 */
188
-	public function get_item_meta( $context = 'view' ) {
189
-		$meta = $this->meta;
190
-
191
-		if ( 'view' === $context ) {
192
-			return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this );
193
-		}
194
-
195
-		return $meta;
196
-
197
-	}
198
-
199
-	/**
200
-	 * Returns whether or not customers can update the item quantity.
201
-	 *
202
-	 * @since 1.0.19
203
-	 * @param  string $context View or edit context.
204
-	 * @return bool
205
-	 */
206
-	public function get_allow_quantities( $context = 'view' ) {
207
-		$allow_quantities = (bool) $this->allow_quantities;
208
-
209
-		if ( 'view' === $context ) {
210
-			return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this );
211
-		}
212
-
213
-		return $allow_quantities;
214
-
215
-	}
216
-
217
-	/**
218
-	 * Returns whether or not the item is required.
219
-	 *
220
-	 * @since 1.0.19
221
-	 * @param  string $context View or edit context.
222
-	 * @return bool
223
-	 */
224
-	public function get_is_required( $context = 'view' ) {
225
-		$is_required = (bool) $this->is_required;
226
-
227
-		if ( 'view' === $context ) {
228
-			return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this );
229
-		}
230
-
231
-		return $is_required;
232
-
233
-	}
234
-
235
-	/**
236
-	 * Prepares form data for use.
237
-	 *
238
-	 * @since 1.0.19
239
-	 * @return array
240
-	 */
241
-	public function prepare_data_for_use( $required = null ) {
242
-
243
-		$required = is_null( $required ) ? $this->is_required() : $required;
244
-		return array(
245
-			'title'            => wp_strip_all_tags( $this->get_name() ),
246
-			'id'               => $this->get_id(),
247
-			'price'            => $this->get_price(),
248
-			'recurring'        => $this->is_recurring(),
249
-			'description'      => $this->get_description(),
250
-			'allow_quantities' => $this->allows_quantities(),
251
-			'required'         => $required,
252
-		);
253
-
254
-	}
255
-
256
-	/**
257
-	 * Prepares form data for ajax use.
258
-	 *
259
-	 * @since 1.0.19
260
-	 * @return array
261
-	 */
262
-	public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) {
263
-
264
-		$description = getpaid_item_recurring_price_help_text( $this, $currency );
265
-
266
-		if ( $description ) {
267
-			$description = "<div class='getpaid-subscription-help-text'>$description</div>";
268
-		}
269
-
270
-		$price    = ! $is_renewal ? $this->get_price() : $this->get_recurring_price();
271
-		$subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total();
272
-		return array(
273
-			'id'     => $this->get_id(),
274
-			'texts'  => array(
275
-				'item-name'        => sanitize_text_field( $this->get_name() ),
276
-				'item-description' => wp_kses_post( $this->get_description() ) . $description,
277
-				'item-quantity'    => floatval( $this->get_quantity() ),
278
-				'item-price'       => wpinv_price( $price, $currency ),
279
-				'item-total'       => wpinv_price( $subtotal, $currency ),
280
-			),
281
-			'inputs' => array(
282
-				'item-id'          => $this->get_id(),
283
-				'item-name'        => sanitize_text_field( $this->get_name() ),
284
-				'item-description' => wp_kses_post( $this->get_description() ),
285
-				'item-quantity'    => floatval( $this->get_quantity() ),
286
-				'item-price'       => $price,
287
-			),
288
-		);
289
-
290
-	}
291
-
292
-	/**
293
-	 * Prepares form data for saving (cart_details).
294
-	 *
295
-	 * @since 1.0.19
296
-	 * @return array
297
-	 */
298
-	public function prepare_data_for_saving() {
299
-
300
-		return array(
301
-			'post_id'          => $this->invoice_id,
302
-			'item_id'          => $this->get_id(),
303
-			'item_name'        => sanitize_text_field( $this->get_raw_name( 'edit' ) ),
304
-			'item_description' => $this->get_description( 'edit' ),
305
-			'tax'              => $this->item_tax,
306
-			'item_price'       => $this->get_price( 'edit' ),
307
-			'quantity'         => (float) $this->get_quantity( 'edit' ),
308
-			'discount'         => $this->item_discount,
309
-			'subtotal'         => $this->get_sub_total( 'edit' ),
310
-			'price'            => $this->get_sub_total( 'edit' ) + $this->item_tax - $this->item_discount,
311
-			'meta'             => $this->get_item_meta( 'edit' ),
312
-		);
313
-
314
-	}
91
+     * Get the item name.
92
+     *
93
+     * @since 1.0.19
94
+     * @param  string $context View or edit context.
95
+     * @return string
96
+     */
97
+    public function get_name( $context = 'view' ) {
98
+        $name = parent::get_name( $context );
99
+        return $name . wpinv_get_item_suffix( $this );
100
+    }
101
+
102
+    /**
103
+     * Get the item name without a suffix.
104
+     *
105
+     * @since 1.0.19
106
+     * @param  string $context View or edit context.
107
+     * @return string
108
+     */
109
+    public function get_raw_name( $context = 'view' ) {
110
+        return parent::get_name( $context );
111
+    }
112
+
113
+    /**
114
+     * Get the item description.
115
+     *
116
+     * @since 1.0.19
117
+     * @param  string $context View or edit context.
118
+     * @return string
119
+     */
120
+    public function get_description( $context = 'view' ) {
121
+
122
+        if ( isset( $this->custom_description ) ) {
123
+            return $this->custom_description;
124
+        }
125
+
126
+        return parent::get_description( $context );
127
+    }
128
+
129
+    /**
130
+     * Returns the sub total.
131
+     *
132
+     * @since 1.0.19
133
+     * @param  string $context View or edit context.
134
+     * @return float
135
+     */
136
+    public function get_sub_total( $context = 'view' ) {
137
+        return $this->get_quantity( $context ) * $this->get_initial_price( $context );
138
+    }
139
+
140
+    /**
141
+     * Returns the recurring sub total.
142
+     *
143
+     * @since 1.0.19
144
+     * @param  string $context View or edit context.
145
+     * @return float
146
+     */
147
+    public function get_recurring_sub_total( $context = 'view' ) {
148
+
149
+        if ( $this->is_recurring() ) {
150
+            return $this->get_quantity( $context ) * $this->get_price( $context );
151
+        }
152
+
153
+        return 0;
154
+    }
155
+
156
+    /**
157
+     * @deprecated
158
+     */
159
+    public function get_qantity( $context = 'view' ) {
160
+        return $this->get_quantity( $context );
161
+    }
162
+
163
+    /**
164
+     * Get the item quantity.
165
+     *
166
+     * @since 1.0.19
167
+     * @param  string $context View or edit context.
168
+     * @return float
169
+     */
170
+    public function get_quantity( $context = 'view' ) {
171
+        $quantity = (float) $this->quantity;
172
+
173
+        if ( 'view' === $context ) {
174
+            return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this );
175
+        }
176
+
177
+        return $quantity;
178
+
179
+    }
180
+
181
+    /**
182
+     * Get the item meta data.
183
+     *
184
+     * @since 1.0.19
185
+     * @param  string $context View or edit context.
186
+     * @return meta
187
+     */
188
+    public function get_item_meta( $context = 'view' ) {
189
+        $meta = $this->meta;
190
+
191
+        if ( 'view' === $context ) {
192
+            return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this );
193
+        }
194
+
195
+        return $meta;
196
+
197
+    }
198
+
199
+    /**
200
+     * Returns whether or not customers can update the item quantity.
201
+     *
202
+     * @since 1.0.19
203
+     * @param  string $context View or edit context.
204
+     * @return bool
205
+     */
206
+    public function get_allow_quantities( $context = 'view' ) {
207
+        $allow_quantities = (bool) $this->allow_quantities;
208
+
209
+        if ( 'view' === $context ) {
210
+            return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this );
211
+        }
212
+
213
+        return $allow_quantities;
214
+
215
+    }
216
+
217
+    /**
218
+     * Returns whether or not the item is required.
219
+     *
220
+     * @since 1.0.19
221
+     * @param  string $context View or edit context.
222
+     * @return bool
223
+     */
224
+    public function get_is_required( $context = 'view' ) {
225
+        $is_required = (bool) $this->is_required;
226
+
227
+        if ( 'view' === $context ) {
228
+            return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this );
229
+        }
230
+
231
+        return $is_required;
232
+
233
+    }
234
+
235
+    /**
236
+     * Prepares form data for use.
237
+     *
238
+     * @since 1.0.19
239
+     * @return array
240
+     */
241
+    public function prepare_data_for_use( $required = null ) {
242
+
243
+        $required = is_null( $required ) ? $this->is_required() : $required;
244
+        return array(
245
+            'title'            => wp_strip_all_tags( $this->get_name() ),
246
+            'id'               => $this->get_id(),
247
+            'price'            => $this->get_price(),
248
+            'recurring'        => $this->is_recurring(),
249
+            'description'      => $this->get_description(),
250
+            'allow_quantities' => $this->allows_quantities(),
251
+            'required'         => $required,
252
+        );
253
+
254
+    }
255
+
256
+    /**
257
+     * Prepares form data for ajax use.
258
+     *
259
+     * @since 1.0.19
260
+     * @return array
261
+     */
262
+    public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) {
263
+
264
+        $description = getpaid_item_recurring_price_help_text( $this, $currency );
265
+
266
+        if ( $description ) {
267
+            $description = "<div class='getpaid-subscription-help-text'>$description</div>";
268
+        }
269
+
270
+        $price    = ! $is_renewal ? $this->get_price() : $this->get_recurring_price();
271
+        $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total();
272
+        return array(
273
+            'id'     => $this->get_id(),
274
+            'texts'  => array(
275
+                'item-name'        => sanitize_text_field( $this->get_name() ),
276
+                'item-description' => wp_kses_post( $this->get_description() ) . $description,
277
+                'item-quantity'    => floatval( $this->get_quantity() ),
278
+                'item-price'       => wpinv_price( $price, $currency ),
279
+                'item-total'       => wpinv_price( $subtotal, $currency ),
280
+            ),
281
+            'inputs' => array(
282
+                'item-id'          => $this->get_id(),
283
+                'item-name'        => sanitize_text_field( $this->get_name() ),
284
+                'item-description' => wp_kses_post( $this->get_description() ),
285
+                'item-quantity'    => floatval( $this->get_quantity() ),
286
+                'item-price'       => $price,
287
+            ),
288
+        );
289
+
290
+    }
291
+
292
+    /**
293
+     * Prepares form data for saving (cart_details).
294
+     *
295
+     * @since 1.0.19
296
+     * @return array
297
+     */
298
+    public function prepare_data_for_saving() {
299
+
300
+        return array(
301
+            'post_id'          => $this->invoice_id,
302
+            'item_id'          => $this->get_id(),
303
+            'item_name'        => sanitize_text_field( $this->get_raw_name( 'edit' ) ),
304
+            'item_description' => $this->get_description( 'edit' ),
305
+            'tax'              => $this->item_tax,
306
+            'item_price'       => $this->get_price( 'edit' ),
307
+            'quantity'         => (float) $this->get_quantity( 'edit' ),
308
+            'discount'         => $this->item_discount,
309
+            'subtotal'         => $this->get_sub_total( 'edit' ),
310
+            'price'            => $this->get_sub_total( 'edit' ) + $this->item_tax - $this->item_discount,
311
+            'meta'             => $this->get_item_meta( 'edit' ),
312
+        );
313
+
314
+    }
315 315
 
316 316
     /*
317 317
 	|--------------------------------------------------------------------------
@@ -323,70 +323,70 @@  discard block
 block discarded – undo
323 323
 	| object.
324 324
     */
325 325
 
326
-	/**
327
-	 * Set the item qantity.
328
-	 *
329
-	 * @since 1.0.19
330
-	 * @param  float $quantity The item quantity.
331
-	 */
332
-	public function set_quantity( $quantity ) {
333
-
334
-		if ( ! is_numeric( $quantity ) ) {
335
-			$quantity = 1;
336
-		}
337
-
338
-		$this->quantity = (float) $quantity;
339
-
340
-	}
341
-
342
-	/**
343
-	 * Set the item meta data.
344
-	 *
345
-	 * @since 1.0.19
346
-	 * @param  array $meta The item meta data.
347
-	 */
348
-	public function set_item_meta( $meta ) {
349
-		$this->meta = maybe_unserialize( $meta );
350
-	}
351
-
352
-	/**
353
-	 * Set whether or not the quantities are allowed.
354
-	 *
355
-	 * @since 1.0.19
356
-	 * @param  bool $allow_quantities
357
-	 */
358
-	public function set_allow_quantities( $allow_quantities ) {
359
-		$this->allow_quantities = (bool) $allow_quantities;
360
-	}
361
-
362
-	/**
363
-	 * Set whether or not the item is required.
364
-	 *
365
-	 * @since 1.0.19
366
-	 * @param  bool $is_required
367
-	 */
368
-	public function set_is_required( $is_required ) {
369
-		$this->is_required = (bool) $is_required;
370
-	}
371
-
372
-	/**
373
-	 * Sets the custom item description.
374
-	 *
375
-	 * @since 1.0.19
376
-	 * @param  string $description
377
-	 */
378
-	public function set_custom_description( $description ) {
379
-		$this->custom_description = $description;
380
-	}
326
+    /**
327
+     * Set the item qantity.
328
+     *
329
+     * @since 1.0.19
330
+     * @param  float $quantity The item quantity.
331
+     */
332
+    public function set_quantity( $quantity ) {
333
+
334
+        if ( ! is_numeric( $quantity ) ) {
335
+            $quantity = 1;
336
+        }
337
+
338
+        $this->quantity = (float) $quantity;
339
+
340
+    }
341
+
342
+    /**
343
+     * Set the item meta data.
344
+     *
345
+     * @since 1.0.19
346
+     * @param  array $meta The item meta data.
347
+     */
348
+    public function set_item_meta( $meta ) {
349
+        $this->meta = maybe_unserialize( $meta );
350
+    }
351
+
352
+    /**
353
+     * Set whether or not the quantities are allowed.
354
+     *
355
+     * @since 1.0.19
356
+     * @param  bool $allow_quantities
357
+     */
358
+    public function set_allow_quantities( $allow_quantities ) {
359
+        $this->allow_quantities = (bool) $allow_quantities;
360
+    }
361
+
362
+    /**
363
+     * Set whether or not the item is required.
364
+     *
365
+     * @since 1.0.19
366
+     * @param  bool $is_required
367
+     */
368
+    public function set_is_required( $is_required ) {
369
+        $this->is_required = (bool) $is_required;
370
+    }
371
+
372
+    /**
373
+     * Sets the custom item description.
374
+     *
375
+     * @since 1.0.19
376
+     * @param  string $description
377
+     */
378
+    public function set_custom_description( $description ) {
379
+        $this->custom_description = $description;
380
+    }
381 381
 
382 382
     /**
383 383
      * We do not want to save items to the database.
384 384
      *
385
-	 * @return int item id
385
+     * @return int item id
386 386
      */
387 387
     public function save( $data = array() ) {
388 388
         return $this->get_id();
389
-	}
389
+    }
390 390
 
391 391
     /*
392 392
 	|--------------------------------------------------------------------------
@@ -398,23 +398,23 @@  discard block
 block discarded – undo
398 398
 	*/
399 399
 
400 400
     /**
401
-	 * Checks whether the item has enabled dynamic pricing.
402
-	 *
403
-	 * @since 1.0.19
404
-	 * @return bool
405
-	 */
406
-	public function is_required() {
401
+     * Checks whether the item has enabled dynamic pricing.
402
+     *
403
+     * @since 1.0.19
404
+     * @return bool
405
+     */
406
+    public function is_required() {
407 407
         return (bool) $this->get_is_required();
408
-	}
409
-
410
-	/**
411
-	 * Checks whether users can edit the quantities.
412
-	 *
413
-	 * @since 1.0.19
414
-	 * @return bool
415
-	 */
416
-	public function allows_quantities() {
408
+    }
409
+
410
+    /**
411
+     * Checks whether users can edit the quantities.
412
+     *
413
+     * @since 1.0.19
414
+     * @return bool
415
+     */
416
+    public function allows_quantities() {
417 417
         return (bool) $this->get_allow_quantities();
418
-	}
418
+    }
419 419
 
420 420
 }
Please login to merge, or discard this patch.
templates/payment-forms/form.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 
58 58
         // And the optional invoice id.
59 59
         if ( ! empty( $form->invoice ) ) {
60
-		    getpaid_hidden_field( 'invoice_id', $form->invoice->get_id() );
60
+            getpaid_hidden_field( 'invoice_id', $form->invoice->get_id() );
61 61
         }
62 62
 
63 63
         // We also want to include the form id.
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
                 <?php
77 77
 
78 78
                     foreach ( $form->get_elements() as $element ) {
79
-					    if ( isset( $element['type'] ) ) {
79
+                        if ( isset( $element['type'] ) ) {
80 80
                             $grid_class = getpaid_get_form_element_grid_class( $element );
81 81
                             do_action( 'getpaid_payment_form_element_before', $element, $form );
82 82
                             do_action( "getpaid_payment_form_element_before_{$element['type']}_template", $element, $form );
Please login to merge, or discard this patch.