@@ -13,97 +13,97 @@ discard block |
||
| 13 | 13 | class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Payment method id. |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 16 | + * Payment method id. |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | 20 | public $id = 'paypal'; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * An array of features that this gateway supports. |
|
| 24 | - * |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 23 | + * An array of features that this gateway supports. |
|
| 24 | + * |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' ); |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Payment method order. |
|
| 31 | - * |
|
| 32 | - * @var int |
|
| 33 | - */ |
|
| 30 | + * Payment method order. |
|
| 31 | + * |
|
| 32 | + * @var int |
|
| 33 | + */ |
|
| 34 | 34 | public $order = 1; |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | - * Stores line items to send to PayPal. |
|
| 38 | - * |
|
| 39 | - * @var array |
|
| 40 | - */ |
|
| 37 | + * Stores line items to send to PayPal. |
|
| 38 | + * |
|
| 39 | + * @var array |
|
| 40 | + */ |
|
| 41 | 41 | protected $line_items = array(); |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | - * Endpoint for requests from PayPal. |
|
| 45 | - * |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 48 | - protected $notify_url; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Endpoint for requests to PayPal. |
|
| 52 | - * |
|
| 53 | - * @var string |
|
| 54 | - */ |
|
| 44 | + * Endpoint for requests from PayPal. |
|
| 45 | + * |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | + protected $notify_url; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Endpoint for requests to PayPal. |
|
| 52 | + * |
|
| 53 | + * @var string |
|
| 54 | + */ |
|
| 55 | 55 | protected $endpoint; |
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | - * Currencies this gateway is allowed for. |
|
| 59 | - * |
|
| 60 | - * @var array |
|
| 61 | - */ |
|
| 62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
| 58 | + * Currencies this gateway is allowed for. |
|
| 59 | + * |
|
| 60 | + * @var array |
|
| 61 | + */ |
|
| 62 | + public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | - * URL to view a transaction. |
|
| 66 | - * |
|
| 67 | - * @var string |
|
| 68 | - */ |
|
| 65 | + * URL to view a transaction. |
|
| 66 | + * |
|
| 67 | + * @var string |
|
| 68 | + */ |
|
| 69 | 69 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | - * URL to view a subscription. |
|
| 73 | - * |
|
| 74 | - * @var string |
|
| 75 | - */ |
|
| 76 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
| 72 | + * URL to view a subscription. |
|
| 73 | + * |
|
| 74 | + * @var string |
|
| 75 | + */ |
|
| 76 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | - * Class constructor. |
|
| 80 | - */ |
|
| 81 | - public function __construct() { |
|
| 79 | + * Class constructor. |
|
| 80 | + */ |
|
| 81 | + public function __construct() { |
|
| 82 | 82 | |
| 83 | 83 | $this->title = __( 'PayPal Standard', 'invoicing' ); |
| 84 | 84 | $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
| 85 | 85 | $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
| 86 | 86 | $this->notify_url = wpinv_get_ipn_url( $this->id ); |
| 87 | 87 | |
| 88 | - add_filter( 'wpinv_subscription_cancel_url', array( $this, 'filter_cancel_subscription_url' ), 10, 2 ); |
|
| 89 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
| 88 | + add_filter( 'wpinv_subscription_cancel_url', array( $this, 'filter_cancel_subscription_url' ), 10, 2 ); |
|
| 89 | + add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
| 90 | 90 | add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
| 91 | - add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
| 92 | - add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
| 93 | - add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) ); |
|
| 94 | - parent::__construct(); |
|
| 91 | + add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
| 92 | + add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
| 93 | + add_action( 'wpinv_paypal_connect', array( $this, 'display_connect_buttons' ) ); |
|
| 94 | + parent::__construct(); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
| 98 | - * Process Payment. |
|
| 99 | - * |
|
| 100 | - * |
|
| 101 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 102 | - * @param array $submission_data Posted checkout fields. |
|
| 103 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 104 | - * @return array |
|
| 105 | - */ |
|
| 106 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 98 | + * Process Payment. |
|
| 99 | + * |
|
| 100 | + * |
|
| 101 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 102 | + * @param array $submission_data Posted checkout fields. |
|
| 103 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 104 | + * @return array |
|
| 105 | + */ |
|
| 106 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 107 | 107 | |
| 108 | 108 | // Get redirect url. |
| 109 | 109 | $paypal_redirect = $this->get_request_url( $invoice ); |
@@ -126,15 +126,15 @@ discard block |
||
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
| 129 | - * Get the PayPal request URL for an invoice. |
|
| 130 | - * |
|
| 131 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 132 | - * @return string |
|
| 133 | - */ |
|
| 134 | - public function get_request_url( $invoice ) { |
|
| 129 | + * Get the PayPal request URL for an invoice. |
|
| 130 | + * |
|
| 131 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 132 | + * @return string |
|
| 133 | + */ |
|
| 134 | + public function get_request_url( $invoice ) { |
|
| 135 | 135 | |
| 136 | 136 | // Endpoint for this request |
| 137 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
| 137 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
| 138 | 138 | |
| 139 | 139 | // Retrieve paypal args. |
| 140 | 140 | $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
@@ -147,45 +147,45 @@ discard block |
||
| 147 | 147 | |
| 148 | 148 | return add_query_arg( $paypal_args, $this->endpoint ); |
| 149 | 149 | |
| 150 | - } |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | 152 | /** |
| 153 | - * Get PayPal Args for passing to PP. |
|
| 154 | - * |
|
| 155 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 156 | - * @return array |
|
| 157 | - */ |
|
| 158 | - protected function get_paypal_args( $invoice ) { |
|
| 153 | + * Get PayPal Args for passing to PP. |
|
| 154 | + * |
|
| 155 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 156 | + * @return array |
|
| 157 | + */ |
|
| 158 | + protected function get_paypal_args( $invoice ) { |
|
| 159 | 159 | |
| 160 | 160 | // Whether or not to send the line items as one item. |
| 161 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
| 162 | - |
|
| 163 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
| 164 | - $force_one_line_item = true; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - $paypal_args = apply_filters( |
|
| 168 | - 'getpaid_paypal_args', |
|
| 169 | - array_merge( |
|
| 170 | - $this->get_transaction_args( $invoice ), |
|
| 171 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
| 172 | - ), |
|
| 173 | - $invoice |
|
| 174 | - ); |
|
| 175 | - |
|
| 176 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
| 161 | + $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
| 162 | + |
|
| 163 | + if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
| 164 | + $force_one_line_item = true; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + $paypal_args = apply_filters( |
|
| 168 | + 'getpaid_paypal_args', |
|
| 169 | + array_merge( |
|
| 170 | + $this->get_transaction_args( $invoice ), |
|
| 171 | + $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
| 172 | + ), |
|
| 173 | + $invoice |
|
| 174 | + ); |
|
| 175 | + |
|
| 176 | + return $this->fix_request_length( $invoice, $paypal_args ); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
| 180 | - * Get transaction args for paypal request. |
|
| 181 | - * |
|
| 182 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 183 | - * @return array |
|
| 184 | - */ |
|
| 185 | - protected function get_transaction_args( $invoice ) { |
|
| 186 | - |
|
| 187 | - $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
| 188 | - return array( |
|
| 180 | + * Get transaction args for paypal request. |
|
| 181 | + * |
|
| 182 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 183 | + * @return array |
|
| 184 | + */ |
|
| 185 | + protected function get_transaction_args( $invoice ) { |
|
| 186 | + |
|
| 187 | + $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
| 188 | + return array( |
|
| 189 | 189 | 'cmd' => '_cart', |
| 190 | 190 | 'business' => $email, |
| 191 | 191 | 'no_shipping' => '1', |
@@ -210,16 +210,16 @@ discard block |
||
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | /** |
| 213 | - * Get line item args for paypal request. |
|
| 214 | - * |
|
| 215 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 216 | - * @param bool $force_one_line_item Create only one item for this invoice. |
|
| 217 | - * @return array |
|
| 218 | - */ |
|
| 219 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
| 213 | + * Get line item args for paypal request. |
|
| 214 | + * |
|
| 215 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 216 | + * @param bool $force_one_line_item Create only one item for this invoice. |
|
| 217 | + * @return array |
|
| 218 | + */ |
|
| 219 | + protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
| 220 | 220 | |
| 221 | 221 | // Maybe send invoice as a single item. |
| 222 | - if ( $force_one_line_item ) { |
|
| 222 | + if ( $force_one_line_item ) { |
|
| 223 | 223 | return $this->get_line_item_args_single_item( $invoice ); |
| 224 | 224 | } |
| 225 | 225 | |
@@ -239,129 +239,129 @@ discard block |
||
| 239 | 239 | $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
| 242 | + return array_merge( $line_item_args, $this->get_line_items() ); |
|
| 243 | 243 | |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
| 247 | - * Get line item args for paypal request as a single line item. |
|
| 248 | - * |
|
| 249 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 250 | - * @return array |
|
| 251 | - */ |
|
| 252 | - protected function get_line_item_args_single_item( $invoice ) { |
|
| 253 | - $this->delete_line_items(); |
|
| 247 | + * Get line item args for paypal request as a single line item. |
|
| 248 | + * |
|
| 249 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 250 | + * @return array |
|
| 251 | + */ |
|
| 252 | + protected function get_line_item_args_single_item( $invoice ) { |
|
| 253 | + $this->delete_line_items(); |
|
| 254 | 254 | |
| 255 | 255 | $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
| 256 | - $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
| 256 | + $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
| 257 | 257 | |
| 258 | - return $this->get_line_items(); |
|
| 258 | + return $this->get_line_items(); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
| 262 | - * Return all line items. |
|
| 263 | - */ |
|
| 264 | - protected function get_line_items() { |
|
| 265 | - return $this->line_items; |
|
| 266 | - } |
|
| 262 | + * Return all line items. |
|
| 263 | + */ |
|
| 264 | + protected function get_line_items() { |
|
| 265 | + return $this->line_items; |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | 268 | /** |
| 269 | - * Remove all line items. |
|
| 270 | - */ |
|
| 271 | - protected function delete_line_items() { |
|
| 272 | - $this->line_items = array(); |
|
| 269 | + * Remove all line items. |
|
| 270 | + */ |
|
| 271 | + protected function delete_line_items() { |
|
| 272 | + $this->line_items = array(); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /** |
| 276 | - * Prepare line items to send to paypal. |
|
| 277 | - * |
|
| 278 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 279 | - */ |
|
| 280 | - protected function prepare_line_items( $invoice ) { |
|
| 281 | - $this->delete_line_items(); |
|
| 282 | - |
|
| 283 | - // Items. |
|
| 284 | - foreach ( $invoice->get_items() as $item ) { |
|
| 285 | - $amount = $item->get_price(); |
|
| 286 | - $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
| 287 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
| 276 | + * Prepare line items to send to paypal. |
|
| 277 | + * |
|
| 278 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 279 | + */ |
|
| 280 | + protected function prepare_line_items( $invoice ) { |
|
| 281 | + $this->delete_line_items(); |
|
| 282 | + |
|
| 283 | + // Items. |
|
| 284 | + foreach ( $invoice->get_items() as $item ) { |
|
| 285 | + $amount = $item->get_price(); |
|
| 286 | + $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
| 287 | + $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | // Fees. |
| 291 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
| 291 | + foreach ( $invoice->get_fees() as $fee => $data ) { |
|
| 292 | 292 | $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | /** |
| 298 | - * Add PayPal Line Item. |
|
| 299 | - * |
|
| 300 | - * @param string $item_name Item name. |
|
| 301 | - * @param float $quantity Item quantity. |
|
| 302 | - * @param float $amount Amount. |
|
| 303 | - * @param string $item_number Item number. |
|
| 304 | - */ |
|
| 305 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
| 306 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
| 307 | - |
|
| 308 | - $item = apply_filters( |
|
| 309 | - 'getpaid_paypal_line_item', |
|
| 310 | - array( |
|
| 311 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
| 312 | - 'quantity' => (float) $quantity, |
|
| 313 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
| 314 | - 'item_number' => $item_number, |
|
| 315 | - ), |
|
| 316 | - $item_name, |
|
| 317 | - $quantity, |
|
| 318 | - $amount, |
|
| 319 | - $item_number |
|
| 320 | - ); |
|
| 321 | - |
|
| 322 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
| 298 | + * Add PayPal Line Item. |
|
| 299 | + * |
|
| 300 | + * @param string $item_name Item name. |
|
| 301 | + * @param float $quantity Item quantity. |
|
| 302 | + * @param float $amount Amount. |
|
| 303 | + * @param string $item_number Item number. |
|
| 304 | + */ |
|
| 305 | + protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
| 306 | + $index = ( count( $this->line_items ) / 4 ) + 1; |
|
| 307 | + |
|
| 308 | + $item = apply_filters( |
|
| 309 | + 'getpaid_paypal_line_item', |
|
| 310 | + array( |
|
| 311 | + 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
| 312 | + 'quantity' => (float) $quantity, |
|
| 313 | + 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
| 314 | + 'item_number' => $item_number, |
|
| 315 | + ), |
|
| 316 | + $item_name, |
|
| 317 | + $quantity, |
|
| 318 | + $amount, |
|
| 319 | + $item_number |
|
| 320 | + ); |
|
| 321 | + |
|
| 322 | + $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
| 323 | 323 | $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
| 324 | 324 | |
| 325 | 325 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
| 326 | - $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
| 327 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
| 326 | + $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
| 327 | + $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
| 331 | - * If the default request with line items is too long, generate a new one with only one line item. |
|
| 332 | - * |
|
| 333 | - * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
| 334 | - * |
|
| 335 | - * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
| 336 | - * @param array $paypal_args Arguments sent to Paypal in the request. |
|
| 337 | - * @return array |
|
| 338 | - */ |
|
| 339 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
| 340 | - $max_paypal_length = 2083; |
|
| 341 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
| 342 | - |
|
| 343 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
| 344 | - return $paypal_args; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - return apply_filters( |
|
| 348 | - 'getpaid_paypal_args', |
|
| 349 | - array_merge( |
|
| 350 | - $this->get_transaction_args( $invoice ), |
|
| 351 | - $this->get_line_item_args( $invoice, true ) |
|
| 352 | - ), |
|
| 353 | - $invoice |
|
| 354 | - ); |
|
| 331 | + * If the default request with line items is too long, generate a new one with only one line item. |
|
| 332 | + * |
|
| 333 | + * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
| 334 | + * |
|
| 335 | + * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
| 336 | + * @param array $paypal_args Arguments sent to Paypal in the request. |
|
| 337 | + * @return array |
|
| 338 | + */ |
|
| 339 | + protected function fix_request_length( $invoice, $paypal_args ) { |
|
| 340 | + $max_paypal_length = 2083; |
|
| 341 | + $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
| 342 | + |
|
| 343 | + if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
| 344 | + return $paypal_args; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + return apply_filters( |
|
| 348 | + 'getpaid_paypal_args', |
|
| 349 | + array_merge( |
|
| 350 | + $this->get_transaction_args( $invoice ), |
|
| 351 | + $this->get_line_item_args( $invoice, true ) |
|
| 352 | + ), |
|
| 353 | + $invoice |
|
| 354 | + ); |
|
| 355 | 355 | |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | /** |
| 359 | - * Processes recurring invoices. |
|
| 360 | - * |
|
| 361 | - * @param array $paypal_args PayPal args. |
|
| 362 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 363 | - */ |
|
| 364 | - public function process_subscription( $paypal_args, $invoice ) { |
|
| 359 | + * Processes recurring invoices. |
|
| 360 | + * |
|
| 361 | + * @param array $paypal_args PayPal args. |
|
| 362 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 363 | + */ |
|
| 364 | + public function process_subscription( $paypal_args, $invoice ) { |
|
| 365 | 365 | |
| 366 | 366 | // Make sure this is a subscription. |
| 367 | 367 | if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) { |
@@ -382,21 +382,21 @@ discard block |
||
| 382 | 382 | $recurring_amount = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 ); |
| 383 | 383 | $subscription_item = $invoice->get_recurring( true ); |
| 384 | 384 | |
| 385 | - // Convert 365 days to 1 year. |
|
| 386 | - if ( 'D' == $period && 365 == $interval ) { |
|
| 387 | - $period = 'Y'; |
|
| 388 | - $interval = 1; |
|
| 389 | - } |
|
| 385 | + // Convert 365 days to 1 year. |
|
| 386 | + if ( 'D' == $period && 365 == $interval ) { |
|
| 387 | + $period = 'Y'; |
|
| 388 | + $interval = 1; |
|
| 389 | + } |
|
| 390 | 390 | |
| 391 | 391 | if ( $subscription_item->has_free_trial() ) { |
| 392 | 392 | |
| 393 | 393 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
| 394 | 394 | |
| 395 | - // Trial period length. |
|
| 396 | - $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
| 395 | + // Trial period length. |
|
| 396 | + $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
| 397 | 397 | |
| 398 | - // Trial period. |
|
| 399 | - $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
| 398 | + // Trial period. |
|
| 399 | + $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
| 400 | 400 | |
| 401 | 401 | } elseif ( $initial_amount != $recurring_amount ) { |
| 402 | 402 | |
@@ -419,40 +419,40 @@ discard block |
||
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | // We have a recurring payment |
| 422 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
| 422 | + if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
| 423 | 423 | |
| 424 | - // Subscription price |
|
| 425 | - $paypal_args['a3'] = $recurring_amount; |
|
| 424 | + // Subscription price |
|
| 425 | + $paypal_args['a3'] = $recurring_amount; |
|
| 426 | 426 | |
| 427 | - // Subscription duration |
|
| 428 | - $paypal_args['p3'] = $interval; |
|
| 427 | + // Subscription duration |
|
| 428 | + $paypal_args['p3'] = $interval; |
|
| 429 | 429 | |
| 430 | - // Subscription period |
|
| 431 | - $paypal_args['t3'] = $period; |
|
| 430 | + // Subscription period |
|
| 431 | + $paypal_args['t3'] = $period; |
|
| 432 | 432 | |
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | // Recurring payments |
| 436 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
| 436 | + if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
| 437 | 437 | |
| 438 | - // Non-recurring payments |
|
| 439 | - $paypal_args['src'] = 0; |
|
| 438 | + // Non-recurring payments |
|
| 439 | + $paypal_args['src'] = 0; |
|
| 440 | 440 | |
| 441 | - } else { |
|
| 441 | + } else { |
|
| 442 | 442 | |
| 443 | - $paypal_args['src'] = 1; |
|
| 443 | + $paypal_args['src'] = 1; |
|
| 444 | 444 | |
| 445 | - if ( $bill_times > 0 ) { |
|
| 445 | + if ( $bill_times > 0 ) { |
|
| 446 | 446 | |
| 447 | - // An initial period is being used to charge a sign-up fee |
|
| 448 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
| 449 | - $bill_times--; |
|
| 450 | - } |
|
| 447 | + // An initial period is being used to charge a sign-up fee |
|
| 448 | + if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
| 449 | + $bill_times--; |
|
| 450 | + } |
|
| 451 | 451 | |
| 452 | 452 | // Make sure it's not over the max of 52 |
| 453 | 453 | $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
| 454 | 454 | |
| 455 | - } |
|
| 455 | + } |
|
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | // Force return URL so that order description & instructions display |
@@ -467,19 +467,19 @@ discard block |
||
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | return apply_filters( |
| 470 | - 'getpaid_paypal_subscription_args', |
|
| 471 | - $paypal_args, |
|
| 472 | - $invoice |
|
| 470 | + 'getpaid_paypal_subscription_args', |
|
| 471 | + $paypal_args, |
|
| 472 | + $invoice |
|
| 473 | 473 | ); |
| 474 | 474 | |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | /** |
| 478 | - * Processes ipns and marks payments as complete. |
|
| 479 | - * |
|
| 480 | - * @return void |
|
| 481 | - */ |
|
| 482 | - public function verify_ipn() { |
|
| 478 | + * Processes ipns and marks payments as complete. |
|
| 479 | + * |
|
| 480 | + * @return void |
|
| 481 | + */ |
|
| 482 | + public function verify_ipn() { |
|
| 483 | 483 | new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
| 484 | 484 | } |
| 485 | 485 | |
@@ -489,19 +489,19 @@ discard block |
||
| 489 | 489 | public function sandbox_notice() { |
| 490 | 490 | |
| 491 | 491 | return sprintf( |
| 492 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
| 493 | - '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
| 494 | - '</a>' |
|
| 495 | - ); |
|
| 492 | + __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %1$sPayPal Sandbox Testing Guide%2$s for more details.', 'invoicing' ), |
|
| 493 | + '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
| 494 | + '</a>' |
|
| 495 | + ); |
|
| 496 | 496 | |
| 497 | 497 | } |
| 498 | 498 | |
| 499 | - /** |
|
| 500 | - * Filters the gateway settings. |
|
| 501 | - * |
|
| 502 | - * @param array $admin_settings |
|
| 503 | - */ |
|
| 504 | - public function admin_settings( $admin_settings ) { |
|
| 499 | + /** |
|
| 500 | + * Filters the gateway settings. |
|
| 501 | + * |
|
| 502 | + * @param array $admin_settings |
|
| 503 | + */ |
|
| 504 | + public function admin_settings( $admin_settings ) { |
|
| 505 | 505 | |
| 506 | 506 | $currencies = sprintf( |
| 507 | 507 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -511,31 +511,31 @@ discard block |
||
| 511 | 511 | $admin_settings['paypal_active']['desc'] .= " ($currencies)"; |
| 512 | 512 | $admin_settings['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
| 513 | 513 | |
| 514 | - // Access tokens. |
|
| 515 | - $live_email = wpinv_get_option( 'paypal_email' ); |
|
| 516 | - $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
| 514 | + // Access tokens. |
|
| 515 | + $live_email = wpinv_get_option( 'paypal_email' ); |
|
| 516 | + $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
| 517 | 517 | |
| 518 | - $admin_settings['paypal_connect'] = array( |
|
| 519 | - 'type' => 'hook', |
|
| 520 | - 'id' => 'paypal_connect', |
|
| 521 | - 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
| 522 | - ); |
|
| 518 | + $admin_settings['paypal_connect'] = array( |
|
| 519 | + 'type' => 'hook', |
|
| 520 | + 'id' => 'paypal_connect', |
|
| 521 | + 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
| 522 | + ); |
|
| 523 | 523 | |
| 524 | 524 | $admin_settings['paypal_email'] = array( |
| 525 | 525 | 'type' => 'text', |
| 526 | - 'class' => 'live-auth-data', |
|
| 526 | + 'class' => 'live-auth-data', |
|
| 527 | 527 | 'id' => 'paypal_email', |
| 528 | 528 | 'name' => __( 'Live Email Address', 'invoicing' ), |
| 529 | 529 | 'desc' => __( 'The email address of your PayPal account.', 'invoicing' ), |
| 530 | 530 | ); |
| 531 | 531 | |
| 532 | - $admin_settings['paypal_sandbox_email'] = array( |
|
| 532 | + $admin_settings['paypal_sandbox_email'] = array( |
|
| 533 | 533 | 'type' => 'text', |
| 534 | - 'class' => 'sandbox-auth-data', |
|
| 534 | + 'class' => 'sandbox-auth-data', |
|
| 535 | 535 | 'id' => 'paypal_sandbox_email', |
| 536 | 536 | 'name' => __( 'Sandbox Email Address', 'invoicing' ), |
| 537 | 537 | 'desc' => __( 'The email address of your sandbox PayPal account.', 'invoicing' ), |
| 538 | - 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
| 538 | + 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
| 539 | 539 | ); |
| 540 | 540 | |
| 541 | 541 | $admin_settings['paypal_ipn_url'] = array( |
@@ -547,57 +547,57 @@ discard block |
||
| 547 | 547 | 'readonly' => true, |
| 548 | 548 | ); |
| 549 | 549 | |
| 550 | - return $admin_settings; |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - /** |
|
| 554 | - * Retrieves the URL to cancel a subscription. |
|
| 555 | - * |
|
| 556 | - * @param string $url |
|
| 557 | - * @param WPInv_Subscription $subscription |
|
| 558 | - */ |
|
| 559 | - public function filter_cancel_subscription_url( $url, $subscription ) { |
|
| 560 | - |
|
| 561 | - if ( $this->id !== $subscription->get_gateway() ) { |
|
| 562 | - return $url; |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - // Get the PayPal profile ID. |
|
| 566 | - $profile_id = $subscription->get_profile_id(); |
|
| 567 | - |
|
| 568 | - // Bail if no profile ID. |
|
| 569 | - if ( empty( $profile_id ) ) { |
|
| 570 | - return $url; |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - $cancel_url = 'https://www.paypal.com/myaccount/autopay/connect/%s/cancel'; |
|
| 574 | - if ( $this->is_sandbox( $subscription->get_parent_payment() ) ) { |
|
| 575 | - $cancel_url = 'https://www.sandbox.paypal.com/myaccount/autopay/connect/%s/cancel'; |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - return sprintf( $cancel_url, $profile_id ); |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * Retrieves the PayPal connect URL when using the setup wizzard. |
|
| 583 | - * |
|
| 584 | - * |
|
| 550 | + return $admin_settings; |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + /** |
|
| 554 | + * Retrieves the URL to cancel a subscription. |
|
| 555 | + * |
|
| 556 | + * @param string $url |
|
| 557 | + * @param WPInv_Subscription $subscription |
|
| 558 | + */ |
|
| 559 | + public function filter_cancel_subscription_url( $url, $subscription ) { |
|
| 560 | + |
|
| 561 | + if ( $this->id !== $subscription->get_gateway() ) { |
|
| 562 | + return $url; |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + // Get the PayPal profile ID. |
|
| 566 | + $profile_id = $subscription->get_profile_id(); |
|
| 567 | + |
|
| 568 | + // Bail if no profile ID. |
|
| 569 | + if ( empty( $profile_id ) ) { |
|
| 570 | + return $url; |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + $cancel_url = 'https://www.paypal.com/myaccount/autopay/connect/%s/cancel'; |
|
| 574 | + if ( $this->is_sandbox( $subscription->get_parent_payment() ) ) { |
|
| 575 | + $cancel_url = 'https://www.sandbox.paypal.com/myaccount/autopay/connect/%s/cancel'; |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + return sprintf( $cancel_url, $profile_id ); |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * Retrieves the PayPal connect URL when using the setup wizzard. |
|
| 583 | + * |
|
| 584 | + * |
|
| 585 | 585 | * @param array $data |
| 586 | 586 | * @return string |
| 587 | - */ |
|
| 588 | - public static function maybe_get_connect_url( $url = '', $data = array() ) { |
|
| 589 | - return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * Retrieves the PayPal connect URL. |
|
| 594 | - * |
|
| 595 | - * |
|
| 587 | + */ |
|
| 588 | + public static function maybe_get_connect_url( $url = '', $data = array() ) { |
|
| 589 | + return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * Retrieves the PayPal connect URL. |
|
| 594 | + * |
|
| 595 | + * |
|
| 596 | 596 | * @param bool $is_sandbox |
| 597 | - * @param string $redirect |
|
| 597 | + * @param string $redirect |
|
| 598 | 598 | * @return string |
| 599 | - */ |
|
| 600 | - public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
| 599 | + */ |
|
| 600 | + public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
| 601 | 601 | |
| 602 | 602 | $redirect_url = add_query_arg( |
| 603 | 603 | array( |
@@ -607,7 +607,7 @@ discard block |
||
| 607 | 607 | 'tab' => 'gateways', |
| 608 | 608 | 'section' => 'paypal', |
| 609 | 609 | 'getpaid-nonce' => wp_create_nonce( 'getpaid-nonce' ), |
| 610 | - 'redirect' => urlencode( $redirect ), |
|
| 610 | + 'redirect' => urlencode( $redirect ), |
|
| 611 | 611 | ), |
| 612 | 612 | admin_url( 'admin.php' ) |
| 613 | 613 | ); |
@@ -622,12 +622,12 @@ discard block |
||
| 622 | 622 | |
| 623 | 623 | } |
| 624 | 624 | |
| 625 | - /** |
|
| 626 | - * Generates settings page js. |
|
| 627 | - * |
|
| 625 | + /** |
|
| 626 | + * Generates settings page js. |
|
| 627 | + * |
|
| 628 | 628 | * @return void |
| 629 | - */ |
|
| 630 | - public static function display_connect_buttons() { |
|
| 629 | + */ |
|
| 630 | + public static function display_connect_buttons() { |
|
| 631 | 631 | |
| 632 | 632 | ?> |
| 633 | 633 | <div class="wpinv-paypal-connect-live"> |
@@ -669,70 +669,70 @@ discard block |
||
| 669 | 669 | <?php |
| 670 | 670 | } |
| 671 | 671 | |
| 672 | - /** |
|
| 673 | - * Connects to PayPal. |
|
| 674 | - * |
|
| 675 | - * @param array $data Connection data. |
|
| 676 | - * @return void |
|
| 677 | - */ |
|
| 678 | - public function connect_paypal( $data ) { |
|
| 679 | - |
|
| 680 | - $sandbox = $this->is_sandbox(); |
|
| 681 | - $data = wp_unslash( $data ); |
|
| 682 | - $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
| 683 | - |
|
| 684 | - if ( isset( $data['live_mode'] ) ) { |
|
| 685 | - $sandbox = empty( $data['live_mode'] ); |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
| 689 | - wpinv_update_option( 'paypal_active', 1 ); |
|
| 690 | - |
|
| 691 | - if ( ! empty( $data['error_description'] ) ) { |
|
| 692 | - getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
| 693 | - } else { |
|
| 694 | - |
|
| 695 | - // Retrieve the user info. |
|
| 696 | - $user_info = wp_remote_get( |
|
| 697 | - ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
| 698 | - array( |
|
| 699 | - |
|
| 700 | - 'headers' => array( |
|
| 701 | - 'Authorization' => 'Bearer ' . $access_token, |
|
| 702 | - 'Content-type' => 'application/json', |
|
| 703 | - ), |
|
| 704 | - |
|
| 705 | - ) |
|
| 706 | - ); |
|
| 707 | - |
|
| 708 | - if ( is_wp_error( $user_info ) ) { |
|
| 709 | - getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
| 710 | - } else { |
|
| 711 | - |
|
| 712 | - // Create application. |
|
| 713 | - $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
| 714 | - |
|
| 715 | - if ( $sandbox ) { |
|
| 716 | - wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
| 717 | - wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
| 718 | - set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
| 719 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
| 720 | - } else { |
|
| 721 | - wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
| 722 | - wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
| 723 | - set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
| 724 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
| 725 | - } |
|
| 672 | + /** |
|
| 673 | + * Connects to PayPal. |
|
| 674 | + * |
|
| 675 | + * @param array $data Connection data. |
|
| 676 | + * @return void |
|
| 677 | + */ |
|
| 678 | + public function connect_paypal( $data ) { |
|
| 679 | + |
|
| 680 | + $sandbox = $this->is_sandbox(); |
|
| 681 | + $data = wp_unslash( $data ); |
|
| 682 | + $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
| 683 | + |
|
| 684 | + if ( isset( $data['live_mode'] ) ) { |
|
| 685 | + $sandbox = empty( $data['live_mode'] ); |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
| 689 | + wpinv_update_option( 'paypal_active', 1 ); |
|
| 690 | + |
|
| 691 | + if ( ! empty( $data['error_description'] ) ) { |
|
| 692 | + getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
| 693 | + } else { |
|
| 694 | + |
|
| 695 | + // Retrieve the user info. |
|
| 696 | + $user_info = wp_remote_get( |
|
| 697 | + ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
| 698 | + array( |
|
| 699 | + |
|
| 700 | + 'headers' => array( |
|
| 701 | + 'Authorization' => 'Bearer ' . $access_token, |
|
| 702 | + 'Content-type' => 'application/json', |
|
| 703 | + ), |
|
| 704 | + |
|
| 705 | + ) |
|
| 706 | + ); |
|
| 707 | + |
|
| 708 | + if ( is_wp_error( $user_info ) ) { |
|
| 709 | + getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
| 710 | + } else { |
|
| 711 | + |
|
| 712 | + // Create application. |
|
| 713 | + $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
| 714 | + |
|
| 715 | + if ( $sandbox ) { |
|
| 716 | + wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
| 717 | + wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
| 718 | + set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
| 719 | + getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
| 720 | + } else { |
|
| 721 | + wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
| 722 | + wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
| 723 | + set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
| 724 | + getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
| 725 | + } |
|
| 726 | 726 | } |
| 727 | 727 | } |
| 728 | 728 | |
| 729 | - $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
| 729 | + $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
| 730 | 730 | |
| 731 | - if ( isset( $data['step'] ) ) { |
|
| 732 | - $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
| 733 | - } |
|
| 734 | - wp_redirect( $redirect ); |
|
| 735 | - exit; |
|
| 736 | - } |
|
| 731 | + if ( isset( $data['step'] ) ) { |
|
| 732 | + $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
| 733 | + } |
|
| 734 | + wp_redirect( $redirect ); |
|
| 735 | + exit; |
|
| 736 | + } |
|
| 737 | 737 | |
| 738 | 738 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
| 7 | - exit; |
|
| 7 | + exit; |
|
| 8 | 8 | } |
| 9 | 9 | add_ThickBox(); |
| 10 | 10 | ?> |
@@ -14,18 +14,18 @@ discard block |
||
| 14 | 14 | <?php if ( $tabs ) { ?> |
| 15 | 15 | <nav class="nav-tab-wrapper wpi-nav-tab-wrapper"> |
| 16 | 16 | <?php |
| 17 | - foreach ( $tabs as $name => $label ) { |
|
| 18 | - echo '<a href="' . esc_url( admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . esc_html( $label ) . '</a>'; |
|
| 19 | - } |
|
| 20 | - do_action( 'wpi_addons_tabs' ); |
|
| 21 | - ?> |
|
| 17 | + foreach ( $tabs as $name => $label ) { |
|
| 18 | + echo '<a href="' . esc_url( admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . esc_html( $label ) . '</a>'; |
|
| 19 | + } |
|
| 20 | + do_action( 'wpi_addons_tabs' ); |
|
| 21 | + ?> |
|
| 22 | 22 | </nav> |
| 23 | 23 | |
| 24 | 24 | <?php |
| 25 | 25 | |
| 26 | - if ( $current_tab == 'membership' ) { |
|
| 26 | + if ( $current_tab == 'membership' ) { |
|
| 27 | 27 | |
| 28 | - ?> |
|
| 28 | + ?> |
|
| 29 | 29 | |
| 30 | 30 | <div class="wpi-membership-tab-conatiner"> |
| 31 | 31 | <div class="membership-content"> |
@@ -36,9 +36,9 @@ discard block |
||
| 36 | 36 | <h2><?php esc_html_e( 'Have a membership key?', 'invoicing' ); ?></h2> |
| 37 | 37 | <p> |
| 38 | 38 | <?php |
| 39 | - $wpeu_admin = new External_Updates_Admin( 'wpinvoicing.com', '1' ); |
|
| 40 | - echo $wpeu_admin->render_licence_actions( 'wpinvoicing.com', 'membership', array( 95, 106, 108, 12351 ) ); |
|
| 41 | - ?> |
|
| 39 | + $wpeu_admin = new External_Updates_Admin( 'wpinvoicing.com', '1' ); |
|
| 40 | + echo $wpeu_admin->render_licence_actions( 'wpinvoicing.com', 'membership', array( 95, 106, 108, 12351 ) ); |
|
| 41 | + ?> |
|
| 42 | 42 | </p> |
| 43 | 43 | <?php } ?> |
| 44 | 44 | |
@@ -48,13 +48,13 @@ discard block |
||
| 48 | 48 | <div class="feature-list"> |
| 49 | 49 | <ul> |
| 50 | 50 | <?php |
| 51 | - $addon_obj = new WPInv_Admin_Addons(); |
|
| 52 | - if ( $addons = $addon_obj->get_section_data( 'addons' ) ) { |
|
| 53 | - foreach ( $addons as $addon ) { |
|
| 54 | - echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html( $addon->info->title ) . '</li>'; |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - ?> |
|
| 51 | + $addon_obj = new WPInv_Admin_Addons(); |
|
| 52 | + if ( $addons = $addon_obj->get_section_data( 'addons' ) ) { |
|
| 53 | + foreach ( $addons as $addon ) { |
|
| 54 | + echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html( $addon->info->title ) . '</li>'; |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + ?> |
|
| 58 | 58 | </ul> |
| 59 | 59 | |
| 60 | 60 | <div class="feature-cta"> |
@@ -65,12 +65,12 @@ discard block |
||
| 65 | 65 | <h3><?php esc_html_e( 'Included Gateways:', 'invoicing' ); ?></h3> |
| 66 | 66 | <ul> |
| 67 | 67 | <?php |
| 68 | - if ( $addons = $addon_obj->get_section_data( 'gateways' ) ) { |
|
| 69 | - foreach ( $addons as $addon ) { |
|
| 70 | - echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html( $addon->info->title ) . '</li>'; |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - ?> |
|
| 68 | + if ( $addons = $addon_obj->get_section_data( 'gateways' ) ) { |
|
| 69 | + foreach ( $addons as $addon ) { |
|
| 70 | + echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html( $addon->info->title ) . '</li>'; |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + ?> |
|
| 74 | 74 | </ul> |
| 75 | 75 | </div> |
| 76 | 76 | |
@@ -81,8 +81,8 @@ discard block |
||
| 81 | 81 | <div class="testimonial-content"> |
| 82 | 82 | <div class="t-image"> |
| 83 | 83 | <?php |
| 84 | - echo '<img src="' . esc_url( plugins_url( 'images/t-image2.png', dirname( __FILE__ ) ) ) . '" > '; |
|
| 85 | - ?> |
|
| 84 | + echo '<img src="' . esc_url( plugins_url( 'images/t-image2.png', dirname( __FILE__ ) ) ) . '" > '; |
|
| 85 | + ?> |
|
| 86 | 86 | </div> |
| 87 | 87 | <div class="t-content"> |
| 88 | 88 | <p> |
@@ -101,8 +101,8 @@ discard block |
||
| 101 | 101 | <div class="testimonial-content"> |
| 102 | 102 | <div class="t-image"> |
| 103 | 103 | <?php |
| 104 | - echo '<img src="' . esc_url( plugins_url( 'images/t-image1.png', dirname( __FILE__ ) ) ) . '" > '; |
|
| 105 | - ?> |
|
| 104 | + echo '<img src="' . esc_url( plugins_url( 'images/t-image1.png', dirname( __FILE__ ) ) ) . '" > '; |
|
| 105 | + ?> |
|
| 106 | 106 | </div> |
| 107 | 107 | <div class="t-content"> |
| 108 | 108 | <p> |
@@ -126,26 +126,26 @@ discard block |
||
| 126 | 126 | </div> |
| 127 | 127 | </div> |
| 128 | 128 | <?php |
| 129 | - } else { |
|
| 130 | - $installed_plugins = get_plugins(); |
|
| 129 | + } else { |
|
| 130 | + $installed_plugins = get_plugins(); |
|
| 131 | 131 | $addon_obj = new WPInv_Admin_Addons(); |
| 132 | - if ( $addons = $addon_obj->get_section_data( $current_tab ) ) : |
|
| 133 | - //print_r($addons); |
|
| 134 | - ?> |
|
| 132 | + if ( $addons = $addon_obj->get_section_data( $current_tab ) ) : |
|
| 133 | + //print_r($addons); |
|
| 134 | + ?> |
|
| 135 | 135 | <ul class="wpi-products"> |
| 136 | 136 | <?php |
| 137 | 137 | foreach ( $addons as $addon ) : |
| 138 | 138 | if ( 965 == $addon->info->id ) { |
| 139 | 139 | continue;}// don't show quote add on |
| 140 | - ?> |
|
| 140 | + ?> |
|
| 141 | 141 | <li class="wpi-product"> |
| 142 | 142 | <div class="wpi-product-title"> |
| 143 | 143 | <h3> |
| 144 | 144 | <?php |
| 145 | - if ( ! empty( $addon->info->excerpt ) ) { |
|
| 146 | - wpi_help_tip( $addon->info->excerpt, false, false, true ); |
|
| 147 | - } |
|
| 148 | - echo esc_html( $addon->info->title ); |
|
| 145 | + if ( ! empty( $addon->info->excerpt ) ) { |
|
| 146 | + wpi_help_tip( $addon->info->excerpt, false, false, true ); |
|
| 147 | + } |
|
| 148 | + echo esc_html( $addon->info->title ); |
|
| 149 | 149 | ?> |
| 150 | 150 | </h3> |
| 151 | 151 | </div> |
@@ -156,32 +156,32 @@ discard block |
||
| 156 | 156 | <?php |
| 157 | 157 | endif; |
| 158 | 158 | |
| 159 | - if ( 'stripe-payment-gateway' == $addon->info->slug ) { |
|
| 160 | - $addon->info->slug = 'getpaid-stripe-payments'; |
|
| 161 | - $addon->info->link = 'https://wordpress.org/plugins/getpaid-stripe-payments/'; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - if ( isset( $addon->info->link ) && substr( $addon->info->link, 0, 21 ) === 'https://wordpress.org' ) { |
|
| 165 | - echo '<a href="' . esc_url( admin_url( '/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug ) ) . '&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
|
| 166 | - echo '<span class="wpi-product-info">' . esc_html__( 'More info', 'invoicing' ) . '</span>'; |
|
| 167 | - echo '</a>'; |
|
| 168 | - } elseif ( isset( $addon->info->link ) && ( substr( $addon->info->link, 0, 23 ) === 'https://wpinvoicing.com' || substr( $addon->info->link, 0, 21 ) === 'https://wpgetpaid.com' ) ) { |
|
| 169 | - if ( defined( 'WP_EASY_UPDATES_ACTIVE' ) ) { |
|
| 170 | - $url = admin_url( '/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug . '&width=770&height=660&item_id=' . $addon->info->id . '&update_url=https://wpgetpaid.com&TB_iframe=true' ); |
|
| 171 | - } else { |
|
| 172 | - // if installed show activation link |
|
| 173 | - if ( isset( $installed_plugins['wp-easy-updates/external-updates.php'] ) ) { |
|
| 174 | - $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
|
| 175 | - } else { |
|
| 176 | - $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - echo '<a href="' . esc_url( $url ) . '" class="thickbox">'; |
|
| 180 | - echo '<span class="wpi-product-info">' . esc_html__( 'More info', 'invoicing' ) . '</span>'; |
|
| 181 | - echo '</a>'; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - ?> |
|
| 159 | + if ( 'stripe-payment-gateway' == $addon->info->slug ) { |
|
| 160 | + $addon->info->slug = 'getpaid-stripe-payments'; |
|
| 161 | + $addon->info->link = 'https://wordpress.org/plugins/getpaid-stripe-payments/'; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + if ( isset( $addon->info->link ) && substr( $addon->info->link, 0, 21 ) === 'https://wordpress.org' ) { |
|
| 165 | + echo '<a href="' . esc_url( admin_url( '/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug ) ) . '&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
|
| 166 | + echo '<span class="wpi-product-info">' . esc_html__( 'More info', 'invoicing' ) . '</span>'; |
|
| 167 | + echo '</a>'; |
|
| 168 | + } elseif ( isset( $addon->info->link ) && ( substr( $addon->info->link, 0, 23 ) === 'https://wpinvoicing.com' || substr( $addon->info->link, 0, 21 ) === 'https://wpgetpaid.com' ) ) { |
|
| 169 | + if ( defined( 'WP_EASY_UPDATES_ACTIVE' ) ) { |
|
| 170 | + $url = admin_url( '/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug . '&width=770&height=660&item_id=' . $addon->info->id . '&update_url=https://wpgetpaid.com&TB_iframe=true' ); |
|
| 171 | + } else { |
|
| 172 | + // if installed show activation link |
|
| 173 | + if ( isset( $installed_plugins['wp-easy-updates/external-updates.php'] ) ) { |
|
| 174 | + $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
|
| 175 | + } else { |
|
| 176 | + $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + echo '<a href="' . esc_url( $url ) . '" class="thickbox">'; |
|
| 180 | + echo '<span class="wpi-product-info">' . esc_html__( 'More info', 'invoicing' ) . '</span>'; |
|
| 181 | + echo '</a>'; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + ?> |
|
| 185 | 185 | |
| 186 | 186 | </span> |
| 187 | 187 | |
@@ -189,15 +189,15 @@ discard block |
||
| 189 | 189 | <span class="wpi-product-button"> |
| 190 | 190 | <?php |
| 191 | 191 | $addon_obj->output_button( $addon ); |
| 192 | - ?> |
|
| 192 | + ?> |
|
| 193 | 193 | </span> |
| 194 | 194 | |
| 195 | 195 | <span class="wpi-price"><?php //print_r($addon); //echo wp_kses_post( $addon->price ); ?></span></li><?php endforeach; ?></ul> |
| 196 | 196 | <?php |
| 197 | 197 | endif; |
| 198 | - } |
|
| 198 | + } |
|
| 199 | 199 | } |
| 200 | - ?> |
|
| 200 | + ?> |
|
| 201 | 201 | |
| 202 | 202 | |
| 203 | 203 | <div class="clearfix" ></div> |
@@ -216,8 +216,8 @@ discard block |
||
| 216 | 216 | <input class="wpeu-licence-key" type="text" placeholder="<?php esc_attr_e( 'Enter your licence key', 'invoicing' ); ?>"> <button class="button-primary wpeu-licence-popup-button" ><?php esc_html_e( 'Install', 'invoicing' ); ?></button> |
| 217 | 217 | <br> |
| 218 | 218 | <?php |
| 219 | - printf( esc_html__( '%1$sFind your licence key here%2$s OR %3$sBuy one here%4$s', 'invoicing' ), '<a href="https://wpinvoicing.com/your-account/" target="_blank">', '</a>', '<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">', '</a>' ); |
|
| 220 | - ?> |
|
| 219 | + printf( esc_html__( '%1$sFind your licence key here%2$s OR %3$sBuy one here%4$s', 'invoicing' ), '<a href="https://wpinvoicing.com/your-account/" target="_blank">', '</a>', '<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">', '</a>' ); |
|
| 220 | + ?> |
|
| 221 | 221 | </span> |
| 222 | 222 | </div> |
| 223 | 223 | |
@@ -993,8 +993,8 @@ |
||
| 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"); |
@@ -1,7 +1,7 @@ discard block |
||
| 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 |
||
| 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">×</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">×</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 |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | - exit; // Exit if accessed directly |
|
| 4 | + exit; // Exit if accessed directly |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | /** |
@@ -11,112 +11,112 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | class AUI_Component_Pagination { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Build the component. |
|
| 16 | - * |
|
| 17 | - * @param array $args |
|
| 18 | - * |
|
| 19 | - * @return string The rendered component. |
|
| 20 | - */ |
|
| 21 | - public static function get( $args = array() ) { |
|
| 22 | - global $wp_query, $aui_bs5; |
|
| 23 | - |
|
| 24 | - $defaults = array( |
|
| 25 | - 'class' => '', |
|
| 26 | - 'mid_size' => 2, |
|
| 27 | - 'prev_text' => '<i class="fas fa-chevron-left"></i>', |
|
| 28 | - 'next_text' => '<i class="fas fa-chevron-right"></i>', |
|
| 29 | - 'screen_reader_text' => __( 'Posts navigation','aui' ), |
|
| 30 | - 'before_paging' => '', |
|
| 31 | - 'after_paging' => '', |
|
| 32 | - 'type' => 'array', |
|
| 33 | - 'total' => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1, |
|
| 34 | - 'links' => array(), // an array of links if using custom links, this includes the a tag. |
|
| 35 | - 'rounded_style' => false, |
|
| 36 | - 'custom_next_text' => '', // Custom next page text |
|
| 37 | - 'custom_prev_text' => '', // Custom prev page text |
|
| 38 | - ); |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 42 | - */ |
|
| 43 | - $args = wp_parse_args( $args, $defaults ); |
|
| 44 | - |
|
| 45 | - $output = ''; |
|
| 46 | - |
|
| 47 | - // Don't print empty markup if there's only one page. |
|
| 48 | - if ( $args['total'] > 1 ) { |
|
| 49 | - // Set up paginated links. |
|
| 50 | - $links = !empty( $args['links'] ) ? $args['links'] : paginate_links( $args ); |
|
| 51 | - |
|
| 52 | - $class = !empty($args['class']) ? $args['class'] : ''; |
|
| 53 | - |
|
| 54 | - $custom_prev_link = ''; |
|
| 55 | - $custom_next_link = ''; |
|
| 56 | - |
|
| 57 | - // make the output bootstrap ready |
|
| 58 | - $links_html = "<ul class='pagination m-0 p-0 $class'>"; |
|
| 59 | - if ( ! empty( $links ) ) { |
|
| 60 | - foreach ( $links as $link ) { |
|
| 61 | - $_link = $link; |
|
| 62 | - |
|
| 63 | - if ( $aui_bs5 ) { |
|
| 64 | - $link_class = $args['rounded_style'] ? 'page-link badge rounded-pill border-0 mx-1 fs-base text-dark link-primary' : 'page-link'; |
|
| 65 | - $link_class_active = $args['rounded_style'] ? ' current active fw-bold badge rounded-pill' : ' current active'; |
|
| 66 | - $links_html .= "<li class='page-item mx-0'>"; |
|
| 67 | - $link = str_replace( array( "page-numbers", " current" ), array( $link_class, $link_class_active ), $link ); |
|
| 68 | - $link = str_replace( 'text-dark link-primary current', 'current', $link ); |
|
| 69 | - $links_html .= $link; |
|
| 70 | - $links_html .= "</li>"; |
|
| 71 | - } else { |
|
| 72 | - $active = strpos( $link, 'current' ) !== false ? 'active' : ''; |
|
| 73 | - $links_html .= "<li class='page-item $active'>"; |
|
| 74 | - $links_html .= str_replace( "page-numbers", "page-link", $link ); |
|
| 75 | - $links_html .= "</li>"; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - if ( strpos( $_link, 'next page-numbers' ) || strpos( $_link, 'prev page-numbers' ) ) { |
|
| 79 | - $link = str_replace( array( "page-numbers", " current" ), array( 'btn btn-outline-primary rounded' . ( $args['rounded_style'] ? '-pill' : '' ) . ' mx-1 fs-base text-dark link-primary', ' current active fw-bold badge rounded-pill' ), $_link ); |
|
| 80 | - $link = str_replace( 'text-dark link-primary current', 'current', $link ); |
|
| 81 | - |
|
| 82 | - if ( strpos( $_link, 'next page-numbers' ) && ! empty( $args['custom_next_text'] ) ) { |
|
| 83 | - $custom_next_link = str_replace( $args['next_text'], $args['custom_next_text'], $link ); |
|
| 84 | - } else if ( strpos( $_link, 'prev page-numbers' ) && ! empty( $args['custom_prev_text'] ) ) { |
|
| 85 | - $custom_prev_link = str_replace( $args['prev_text'], $args['custom_prev_text'], $link ); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - $links_html .= "</ul>"; |
|
| 91 | - |
|
| 92 | - if ( $links ) { |
|
| 93 | - $output .= '<section class="px-0 py-2 w-100">'; |
|
| 94 | - $output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] ); |
|
| 95 | - $output .= '</section>'; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - $output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output ); |
|
| 99 | - $output = str_replace( "nav-links", "aui-nav-links", $output ); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - if ( $output ) { |
|
| 103 | - if ( $custom_next_link || $custom_prev_link ) { |
|
| 104 | - $total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1; |
|
| 105 | - $current = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1; |
|
| 106 | - |
|
| 107 | - $output = '<div class="row d-flex align-items-center justify-content-between"><div class="col text-start">' . $custom_prev_link . '</div><div class="col text-center d-none d-md-block">' . $output . '</div><div class="col text-center d-md-none">' . $current . '/' . $args['total'] . '</div><div class="col text-end">' . $custom_next_link . '</div></div>'; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - if ( ! empty( $args['before_paging'] ) ) { |
|
| 111 | - $output = $args['before_paging'] . $output; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - if ( ! empty( $args['after_paging'] ) ) { |
|
| 115 | - $output = $output . $args['after_paging']; |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - return $output; |
|
| 120 | - } |
|
| 14 | + /** |
|
| 15 | + * Build the component. |
|
| 16 | + * |
|
| 17 | + * @param array $args |
|
| 18 | + * |
|
| 19 | + * @return string The rendered component. |
|
| 20 | + */ |
|
| 21 | + public static function get( $args = array() ) { |
|
| 22 | + global $wp_query, $aui_bs5; |
|
| 23 | + |
|
| 24 | + $defaults = array( |
|
| 25 | + 'class' => '', |
|
| 26 | + 'mid_size' => 2, |
|
| 27 | + 'prev_text' => '<i class="fas fa-chevron-left"></i>', |
|
| 28 | + 'next_text' => '<i class="fas fa-chevron-right"></i>', |
|
| 29 | + 'screen_reader_text' => __( 'Posts navigation','aui' ), |
|
| 30 | + 'before_paging' => '', |
|
| 31 | + 'after_paging' => '', |
|
| 32 | + 'type' => 'array', |
|
| 33 | + 'total' => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1, |
|
| 34 | + 'links' => array(), // an array of links if using custom links, this includes the a tag. |
|
| 35 | + 'rounded_style' => false, |
|
| 36 | + 'custom_next_text' => '', // Custom next page text |
|
| 37 | + 'custom_prev_text' => '', // Custom prev page text |
|
| 38 | + ); |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 42 | + */ |
|
| 43 | + $args = wp_parse_args( $args, $defaults ); |
|
| 44 | + |
|
| 45 | + $output = ''; |
|
| 46 | + |
|
| 47 | + // Don't print empty markup if there's only one page. |
|
| 48 | + if ( $args['total'] > 1 ) { |
|
| 49 | + // Set up paginated links. |
|
| 50 | + $links = !empty( $args['links'] ) ? $args['links'] : paginate_links( $args ); |
|
| 51 | + |
|
| 52 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
| 53 | + |
|
| 54 | + $custom_prev_link = ''; |
|
| 55 | + $custom_next_link = ''; |
|
| 56 | + |
|
| 57 | + // make the output bootstrap ready |
|
| 58 | + $links_html = "<ul class='pagination m-0 p-0 $class'>"; |
|
| 59 | + if ( ! empty( $links ) ) { |
|
| 60 | + foreach ( $links as $link ) { |
|
| 61 | + $_link = $link; |
|
| 62 | + |
|
| 63 | + if ( $aui_bs5 ) { |
|
| 64 | + $link_class = $args['rounded_style'] ? 'page-link badge rounded-pill border-0 mx-1 fs-base text-dark link-primary' : 'page-link'; |
|
| 65 | + $link_class_active = $args['rounded_style'] ? ' current active fw-bold badge rounded-pill' : ' current active'; |
|
| 66 | + $links_html .= "<li class='page-item mx-0'>"; |
|
| 67 | + $link = str_replace( array( "page-numbers", " current" ), array( $link_class, $link_class_active ), $link ); |
|
| 68 | + $link = str_replace( 'text-dark link-primary current', 'current', $link ); |
|
| 69 | + $links_html .= $link; |
|
| 70 | + $links_html .= "</li>"; |
|
| 71 | + } else { |
|
| 72 | + $active = strpos( $link, 'current' ) !== false ? 'active' : ''; |
|
| 73 | + $links_html .= "<li class='page-item $active'>"; |
|
| 74 | + $links_html .= str_replace( "page-numbers", "page-link", $link ); |
|
| 75 | + $links_html .= "</li>"; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + if ( strpos( $_link, 'next page-numbers' ) || strpos( $_link, 'prev page-numbers' ) ) { |
|
| 79 | + $link = str_replace( array( "page-numbers", " current" ), array( 'btn btn-outline-primary rounded' . ( $args['rounded_style'] ? '-pill' : '' ) . ' mx-1 fs-base text-dark link-primary', ' current active fw-bold badge rounded-pill' ), $_link ); |
|
| 80 | + $link = str_replace( 'text-dark link-primary current', 'current', $link ); |
|
| 81 | + |
|
| 82 | + if ( strpos( $_link, 'next page-numbers' ) && ! empty( $args['custom_next_text'] ) ) { |
|
| 83 | + $custom_next_link = str_replace( $args['next_text'], $args['custom_next_text'], $link ); |
|
| 84 | + } else if ( strpos( $_link, 'prev page-numbers' ) && ! empty( $args['custom_prev_text'] ) ) { |
|
| 85 | + $custom_prev_link = str_replace( $args['prev_text'], $args['custom_prev_text'], $link ); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + $links_html .= "</ul>"; |
|
| 91 | + |
|
| 92 | + if ( $links ) { |
|
| 93 | + $output .= '<section class="px-0 py-2 w-100">'; |
|
| 94 | + $output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] ); |
|
| 95 | + $output .= '</section>'; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + $output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output ); |
|
| 99 | + $output = str_replace( "nav-links", "aui-nav-links", $output ); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + if ( $output ) { |
|
| 103 | + if ( $custom_next_link || $custom_prev_link ) { |
|
| 104 | + $total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1; |
|
| 105 | + $current = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1; |
|
| 106 | + |
|
| 107 | + $output = '<div class="row d-flex align-items-center justify-content-between"><div class="col text-start">' . $custom_prev_link . '</div><div class="col text-center d-none d-md-block">' . $output . '</div><div class="col text-center d-md-none">' . $current . '/' . $args['total'] . '</div><div class="col text-end">' . $custom_next_link . '</div></div>'; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + if ( ! empty( $args['before_paging'] ) ) { |
|
| 111 | + $output = $args['before_paging'] . $output; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + if ( ! empty( $args['after_paging'] ) ) { |
|
| 115 | + $output = $output . $args['after_paging']; |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + return $output; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | 122 | } |
| 123 | 123 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
| 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 |
||
| 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", "<\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", "<\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 |
@@ -16,222 +16,222 @@ |
||
| 16 | 16 | |
| 17 | 17 | // If this file is called directly, abort. |
| 18 | 18 | if ( ! defined( 'WPINC' ) ) { |
| 19 | - die; |
|
| 19 | + die; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | class AyeCode_UI_Plugin { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * AUI Plugin constructor. |
|
| 26 | - * |
|
| 27 | - * @since 1.0.0 |
|
| 28 | - */ |
|
| 29 | - public function __construct() { |
|
| 30 | - |
|
| 31 | - // load AUI |
|
| 32 | - require_once( dirname( __FILE__ ) . '/ayecode-ui-loader.php' ); |
|
| 33 | - |
|
| 34 | - // Maybe show example page |
|
| 35 | - add_action( 'template_redirect', array( $this,'maybe_show_examples' ) ); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - public function maybe_show_examples(){ |
|
| 39 | - if ( current_user_can( 'manage_options' ) && isset( $_REQUEST['preview-aui'] ) ) { |
|
| 40 | - echo "<head>"; |
|
| 41 | - wp_head(); |
|
| 42 | - echo "</head>"; |
|
| 43 | - echo "<body class='bsui'>"; |
|
| 44 | - echo $this->get_examples(); |
|
| 45 | - wp_footer(); |
|
| 46 | - echo "</body>"; |
|
| 47 | - exit; |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - public function get_examples(){ |
|
| 52 | - $output = ''; |
|
| 53 | - |
|
| 54 | - // open form |
|
| 55 | - $output .= "<form class='p-5 m-5 border rounded bg-white'>"; |
|
| 56 | - |
|
| 57 | - $output .= aui()->input( |
|
| 58 | - array( |
|
| 59 | - 'type' => 'datepicker', |
|
| 60 | - 'id' => 'date_example_sm', |
|
| 61 | - 'size' => 'sm', |
|
| 62 | - 'name' => 'date_example_sm', |
|
| 63 | - 'label' => 'Date Input Label (small)', |
|
| 64 | - 'help_text' => 'help text', |
|
| 65 | - 'label_type' => 'top', |
|
| 66 | - 'placeholder' => 'YYYY-MM-DD 00:00', |
|
| 67 | - 'value' => '', |
|
| 68 | - 'extra_attributes' => array( |
|
| 69 | - 'data-enable-time' => 'true', |
|
| 70 | - 'data-time_24hr' => 'true', |
|
| 71 | - 'data-allow-input' => 'true', |
|
| 72 | - ), |
|
| 73 | - ) |
|
| 74 | - ); |
|
| 75 | - |
|
| 76 | - $output .= aui()->input( |
|
| 77 | - array( |
|
| 78 | - 'type' => 'datepicker', |
|
| 79 | - 'id' => 'date_example', |
|
| 80 | - //'size' => 'smx', |
|
| 81 | - 'name' => 'date_example', |
|
| 82 | - 'label' => 'Date Input Label', |
|
| 83 | - 'help_text' => 'help text', |
|
| 84 | - 'label_type' => 'top', |
|
| 85 | - 'placeholder' => 'YYYY-MM-DD 00:00', |
|
| 86 | - 'value' => '', |
|
| 87 | - 'extra_attributes' => array( |
|
| 88 | - 'data-enable-time' => 'true', |
|
| 89 | - 'data-time_24hr' => 'true', |
|
| 90 | - 'data-allow-input' => 'true', |
|
| 91 | - ), |
|
| 92 | - ) |
|
| 93 | - ); |
|
| 94 | - |
|
| 95 | - $output .= aui()->input( |
|
| 96 | - array( |
|
| 97 | - 'type' => 'datepicker', |
|
| 98 | - 'id' => 'date_example_lg', |
|
| 99 | - 'size' => 'lg', |
|
| 100 | - 'name' => 'date_example_lg', |
|
| 101 | - 'label' => 'Date Input Label (large)', |
|
| 102 | - 'help_text' => 'help text', |
|
| 103 | - 'label_type' => 'top', |
|
| 104 | - 'placeholder' => 'YYYY-MM-DD 00:00', |
|
| 105 | - 'value' => '', |
|
| 106 | - 'extra_attributes' => array( |
|
| 107 | - 'data-enable-time' => 'true', |
|
| 108 | - 'data-time_24hr' => 'true', |
|
| 109 | - //'data-allow-input' => 'true', |
|
| 110 | - ), |
|
| 111 | - ) |
|
| 112 | - ); |
|
| 113 | - |
|
| 114 | - // input example |
|
| 115 | - $output .= aui()->input( |
|
| 116 | - array( |
|
| 117 | - 'type' => 'text', |
|
| 118 | - 'id' => 'text-example', |
|
| 119 | - 'size' => 'sm', |
|
| 120 | - //'clear_icon' => true, |
|
| 121 | - 'name' => 'text-example', |
|
| 122 | - 'placeholder' => 'text placeholder', |
|
| 123 | - 'title' => 'Text input example', |
|
| 124 | - 'value' => '', |
|
| 125 | - 'required' => false, |
|
| 126 | - 'help_text' => 'help text', |
|
| 127 | - 'label' => 'Text input example label', |
|
| 128 | - 'label_type' => 'top' |
|
| 129 | - ) |
|
| 130 | - ); |
|
| 131 | - |
|
| 132 | - $output .= aui()->input( |
|
| 133 | - array( |
|
| 134 | - 'type' => 'search', |
|
| 135 | - 'id' => 'text-example', |
|
| 136 | - 'size' => 'sm', |
|
| 137 | - //'clear_icon' => true, |
|
| 138 | - 'name' => 'text-example', |
|
| 139 | - 'placeholder' => 'text placeholder', |
|
| 140 | - 'title' => 'Text input example', |
|
| 141 | - 'value' => '', |
|
| 142 | - 'required' => false, |
|
| 143 | - 'help_text' => 'help text', |
|
| 144 | - 'label' => 'Text input example label', |
|
| 145 | - 'label_type' => 'top' |
|
| 146 | - ) |
|
| 147 | - ); |
|
| 148 | - |
|
| 149 | - // input example |
|
| 150 | - $output .= aui()->input( |
|
| 151 | - array( |
|
| 152 | - 'type' => 'url', |
|
| 153 | - 'id' => 'text-example2', |
|
| 154 | - 'name' => 'text-example', |
|
| 155 | - 'placeholder' => 'url placeholder', |
|
| 156 | - 'title' => 'Text input example', |
|
| 157 | - 'value' => '', |
|
| 158 | - 'required' => false, |
|
| 159 | - 'help_text' => 'help text', |
|
| 160 | - 'label' => 'Text input example label' |
|
| 161 | - ) |
|
| 162 | - ); |
|
| 163 | - |
|
| 164 | - // checkbox example |
|
| 165 | - $output .= aui()->input( |
|
| 166 | - array( |
|
| 167 | - 'type' => 'checkbox', |
|
| 168 | - 'id' => 'checkbox-example', |
|
| 169 | - 'name' => 'checkbox-example', |
|
| 170 | - 'placeholder' => 'checkbox-example', |
|
| 171 | - 'title' => 'Checkbox example', |
|
| 172 | - 'value' => '1', |
|
| 173 | - 'checked' => true, |
|
| 174 | - 'required' => false, |
|
| 175 | - 'help_text' => 'help text', |
|
| 176 | - 'label' => 'Checkbox checked' |
|
| 177 | - ) |
|
| 178 | - ); |
|
| 179 | - |
|
| 180 | - // checkbox example |
|
| 181 | - $output .= aui()->input( |
|
| 182 | - array( |
|
| 183 | - 'type' => 'checkbox', |
|
| 184 | - 'id' => 'checkbox-example2', |
|
| 185 | - 'name' => 'checkbox-example2', |
|
| 186 | - 'placeholder' => 'checkbox-example', |
|
| 187 | - 'title' => 'Checkbox example', |
|
| 188 | - 'value' => '1', |
|
| 189 | - 'checked' => false, |
|
| 190 | - 'required' => false, |
|
| 191 | - 'help_text' => 'help text', |
|
| 192 | - 'label' => 'Checkbox un-checked' |
|
| 193 | - ) |
|
| 194 | - ); |
|
| 195 | - |
|
| 196 | - // switch example |
|
| 197 | - $output .= aui()->input( |
|
| 198 | - array( |
|
| 199 | - 'type' => 'checkbox', |
|
| 200 | - 'id' => 'switch-example', |
|
| 201 | - 'name' => 'switch-example', |
|
| 202 | - 'placeholder' => 'checkbox-example', |
|
| 203 | - 'title' => 'Switch example', |
|
| 204 | - 'value' => '1', |
|
| 205 | - 'checked' => true, |
|
| 206 | - 'switch' => true, |
|
| 207 | - 'required' => false, |
|
| 208 | - 'help_text' => 'help text', |
|
| 209 | - 'label' => 'Switch on' |
|
| 210 | - ) |
|
| 211 | - ); |
|
| 212 | - |
|
| 213 | - // switch example |
|
| 214 | - $output .= aui()->input( |
|
| 215 | - array( |
|
| 216 | - 'type' => 'checkbox', |
|
| 217 | - 'id' => 'switch-example2', |
|
| 218 | - 'name' => 'switch-example2', |
|
| 219 | - 'placeholder' => 'checkbox-example', |
|
| 220 | - 'title' => 'Switch example', |
|
| 221 | - 'value' => '1', |
|
| 222 | - 'checked' => false, |
|
| 223 | - 'switch' => true, |
|
| 224 | - 'required' => false, |
|
| 225 | - 'help_text' => 'help text', |
|
| 226 | - 'label' => 'Switch off' |
|
| 227 | - ) |
|
| 228 | - ); |
|
| 229 | - |
|
| 230 | - // close form |
|
| 231 | - $output .= "</form>"; |
|
| 232 | - |
|
| 233 | - return $output; |
|
| 234 | - } |
|
| 24 | + /** |
|
| 25 | + * AUI Plugin constructor. |
|
| 26 | + * |
|
| 27 | + * @since 1.0.0 |
|
| 28 | + */ |
|
| 29 | + public function __construct() { |
|
| 30 | + |
|
| 31 | + // load AUI |
|
| 32 | + require_once( dirname( __FILE__ ) . '/ayecode-ui-loader.php' ); |
|
| 33 | + |
|
| 34 | + // Maybe show example page |
|
| 35 | + add_action( 'template_redirect', array( $this,'maybe_show_examples' ) ); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + public function maybe_show_examples(){ |
|
| 39 | + if ( current_user_can( 'manage_options' ) && isset( $_REQUEST['preview-aui'] ) ) { |
|
| 40 | + echo "<head>"; |
|
| 41 | + wp_head(); |
|
| 42 | + echo "</head>"; |
|
| 43 | + echo "<body class='bsui'>"; |
|
| 44 | + echo $this->get_examples(); |
|
| 45 | + wp_footer(); |
|
| 46 | + echo "</body>"; |
|
| 47 | + exit; |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + public function get_examples(){ |
|
| 52 | + $output = ''; |
|
| 53 | + |
|
| 54 | + // open form |
|
| 55 | + $output .= "<form class='p-5 m-5 border rounded bg-white'>"; |
|
| 56 | + |
|
| 57 | + $output .= aui()->input( |
|
| 58 | + array( |
|
| 59 | + 'type' => 'datepicker', |
|
| 60 | + 'id' => 'date_example_sm', |
|
| 61 | + 'size' => 'sm', |
|
| 62 | + 'name' => 'date_example_sm', |
|
| 63 | + 'label' => 'Date Input Label (small)', |
|
| 64 | + 'help_text' => 'help text', |
|
| 65 | + 'label_type' => 'top', |
|
| 66 | + 'placeholder' => 'YYYY-MM-DD 00:00', |
|
| 67 | + 'value' => '', |
|
| 68 | + 'extra_attributes' => array( |
|
| 69 | + 'data-enable-time' => 'true', |
|
| 70 | + 'data-time_24hr' => 'true', |
|
| 71 | + 'data-allow-input' => 'true', |
|
| 72 | + ), |
|
| 73 | + ) |
|
| 74 | + ); |
|
| 75 | + |
|
| 76 | + $output .= aui()->input( |
|
| 77 | + array( |
|
| 78 | + 'type' => 'datepicker', |
|
| 79 | + 'id' => 'date_example', |
|
| 80 | + //'size' => 'smx', |
|
| 81 | + 'name' => 'date_example', |
|
| 82 | + 'label' => 'Date Input Label', |
|
| 83 | + 'help_text' => 'help text', |
|
| 84 | + 'label_type' => 'top', |
|
| 85 | + 'placeholder' => 'YYYY-MM-DD 00:00', |
|
| 86 | + 'value' => '', |
|
| 87 | + 'extra_attributes' => array( |
|
| 88 | + 'data-enable-time' => 'true', |
|
| 89 | + 'data-time_24hr' => 'true', |
|
| 90 | + 'data-allow-input' => 'true', |
|
| 91 | + ), |
|
| 92 | + ) |
|
| 93 | + ); |
|
| 94 | + |
|
| 95 | + $output .= aui()->input( |
|
| 96 | + array( |
|
| 97 | + 'type' => 'datepicker', |
|
| 98 | + 'id' => 'date_example_lg', |
|
| 99 | + 'size' => 'lg', |
|
| 100 | + 'name' => 'date_example_lg', |
|
| 101 | + 'label' => 'Date Input Label (large)', |
|
| 102 | + 'help_text' => 'help text', |
|
| 103 | + 'label_type' => 'top', |
|
| 104 | + 'placeholder' => 'YYYY-MM-DD 00:00', |
|
| 105 | + 'value' => '', |
|
| 106 | + 'extra_attributes' => array( |
|
| 107 | + 'data-enable-time' => 'true', |
|
| 108 | + 'data-time_24hr' => 'true', |
|
| 109 | + //'data-allow-input' => 'true', |
|
| 110 | + ), |
|
| 111 | + ) |
|
| 112 | + ); |
|
| 113 | + |
|
| 114 | + // input example |
|
| 115 | + $output .= aui()->input( |
|
| 116 | + array( |
|
| 117 | + 'type' => 'text', |
|
| 118 | + 'id' => 'text-example', |
|
| 119 | + 'size' => 'sm', |
|
| 120 | + //'clear_icon' => true, |
|
| 121 | + 'name' => 'text-example', |
|
| 122 | + 'placeholder' => 'text placeholder', |
|
| 123 | + 'title' => 'Text input example', |
|
| 124 | + 'value' => '', |
|
| 125 | + 'required' => false, |
|
| 126 | + 'help_text' => 'help text', |
|
| 127 | + 'label' => 'Text input example label', |
|
| 128 | + 'label_type' => 'top' |
|
| 129 | + ) |
|
| 130 | + ); |
|
| 131 | + |
|
| 132 | + $output .= aui()->input( |
|
| 133 | + array( |
|
| 134 | + 'type' => 'search', |
|
| 135 | + 'id' => 'text-example', |
|
| 136 | + 'size' => 'sm', |
|
| 137 | + //'clear_icon' => true, |
|
| 138 | + 'name' => 'text-example', |
|
| 139 | + 'placeholder' => 'text placeholder', |
|
| 140 | + 'title' => 'Text input example', |
|
| 141 | + 'value' => '', |
|
| 142 | + 'required' => false, |
|
| 143 | + 'help_text' => 'help text', |
|
| 144 | + 'label' => 'Text input example label', |
|
| 145 | + 'label_type' => 'top' |
|
| 146 | + ) |
|
| 147 | + ); |
|
| 148 | + |
|
| 149 | + // input example |
|
| 150 | + $output .= aui()->input( |
|
| 151 | + array( |
|
| 152 | + 'type' => 'url', |
|
| 153 | + 'id' => 'text-example2', |
|
| 154 | + 'name' => 'text-example', |
|
| 155 | + 'placeholder' => 'url placeholder', |
|
| 156 | + 'title' => 'Text input example', |
|
| 157 | + 'value' => '', |
|
| 158 | + 'required' => false, |
|
| 159 | + 'help_text' => 'help text', |
|
| 160 | + 'label' => 'Text input example label' |
|
| 161 | + ) |
|
| 162 | + ); |
|
| 163 | + |
|
| 164 | + // checkbox example |
|
| 165 | + $output .= aui()->input( |
|
| 166 | + array( |
|
| 167 | + 'type' => 'checkbox', |
|
| 168 | + 'id' => 'checkbox-example', |
|
| 169 | + 'name' => 'checkbox-example', |
|
| 170 | + 'placeholder' => 'checkbox-example', |
|
| 171 | + 'title' => 'Checkbox example', |
|
| 172 | + 'value' => '1', |
|
| 173 | + 'checked' => true, |
|
| 174 | + 'required' => false, |
|
| 175 | + 'help_text' => 'help text', |
|
| 176 | + 'label' => 'Checkbox checked' |
|
| 177 | + ) |
|
| 178 | + ); |
|
| 179 | + |
|
| 180 | + // checkbox example |
|
| 181 | + $output .= aui()->input( |
|
| 182 | + array( |
|
| 183 | + 'type' => 'checkbox', |
|
| 184 | + 'id' => 'checkbox-example2', |
|
| 185 | + 'name' => 'checkbox-example2', |
|
| 186 | + 'placeholder' => 'checkbox-example', |
|
| 187 | + 'title' => 'Checkbox example', |
|
| 188 | + 'value' => '1', |
|
| 189 | + 'checked' => false, |
|
| 190 | + 'required' => false, |
|
| 191 | + 'help_text' => 'help text', |
|
| 192 | + 'label' => 'Checkbox un-checked' |
|
| 193 | + ) |
|
| 194 | + ); |
|
| 195 | + |
|
| 196 | + // switch example |
|
| 197 | + $output .= aui()->input( |
|
| 198 | + array( |
|
| 199 | + 'type' => 'checkbox', |
|
| 200 | + 'id' => 'switch-example', |
|
| 201 | + 'name' => 'switch-example', |
|
| 202 | + 'placeholder' => 'checkbox-example', |
|
| 203 | + 'title' => 'Switch example', |
|
| 204 | + 'value' => '1', |
|
| 205 | + 'checked' => true, |
|
| 206 | + 'switch' => true, |
|
| 207 | + 'required' => false, |
|
| 208 | + 'help_text' => 'help text', |
|
| 209 | + 'label' => 'Switch on' |
|
| 210 | + ) |
|
| 211 | + ); |
|
| 212 | + |
|
| 213 | + // switch example |
|
| 214 | + $output .= aui()->input( |
|
| 215 | + array( |
|
| 216 | + 'type' => 'checkbox', |
|
| 217 | + 'id' => 'switch-example2', |
|
| 218 | + 'name' => 'switch-example2', |
|
| 219 | + 'placeholder' => 'checkbox-example', |
|
| 220 | + 'title' => 'Switch example', |
|
| 221 | + 'value' => '1', |
|
| 222 | + 'checked' => false, |
|
| 223 | + 'switch' => true, |
|
| 224 | + 'required' => false, |
|
| 225 | + 'help_text' => 'help text', |
|
| 226 | + 'label' => 'Switch off' |
|
| 227 | + ) |
|
| 228 | + ); |
|
| 229 | + |
|
| 230 | + // close form |
|
| 231 | + $output .= "</form>"; |
|
| 232 | + |
|
| 233 | + return $output; |
|
| 234 | + } |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | new AyeCode_UI_Plugin(); |
| 238 | 238 | \ No newline at end of file |
@@ -993,8 +993,8 @@ |
||
| 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"); |
@@ -12,184 +12,184 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Checkout { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var GetPaid_Payment_Form_Submission |
|
| 17 | - */ |
|
| 18 | - protected $payment_form_submission; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Class constructor. |
|
| 22 | - * |
|
| 23 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 24 | - */ |
|
| 25 | - public function __construct( $submission ) { |
|
| 26 | - $this->payment_form_submission = $submission; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Processes the checkout. |
|
| 31 | - * |
|
| 32 | - */ |
|
| 33 | - public function process_checkout() { |
|
| 34 | - |
|
| 35 | - // Validate the submission. |
|
| 36 | - $this->validate_submission(); |
|
| 37 | - |
|
| 38 | - // Prepare the invoice. |
|
| 39 | - $items = $this->get_submission_items(); |
|
| 40 | - $invoice = $this->get_submission_invoice(); |
|
| 41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
| 42 | - $prepared = $this->prepare_submission_data_for_saving(); |
|
| 43 | - |
|
| 44 | - $this->prepare_billing_info( $invoice ); |
|
| 45 | - |
|
| 46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
| 47 | - |
|
| 48 | - // Save the invoice. |
|
| 49 | - $invoice->set_is_viewed( true ); |
|
| 50 | - $invoice->recalculate_total(); |
|
| 15 | + /** |
|
| 16 | + * @var GetPaid_Payment_Form_Submission |
|
| 17 | + */ |
|
| 18 | + protected $payment_form_submission; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Class constructor. |
|
| 22 | + * |
|
| 23 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 24 | + */ |
|
| 25 | + public function __construct( $submission ) { |
|
| 26 | + $this->payment_form_submission = $submission; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Processes the checkout. |
|
| 31 | + * |
|
| 32 | + */ |
|
| 33 | + public function process_checkout() { |
|
| 34 | + |
|
| 35 | + // Validate the submission. |
|
| 36 | + $this->validate_submission(); |
|
| 37 | + |
|
| 38 | + // Prepare the invoice. |
|
| 39 | + $items = $this->get_submission_items(); |
|
| 40 | + $invoice = $this->get_submission_invoice(); |
|
| 41 | + $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
| 42 | + $prepared = $this->prepare_submission_data_for_saving(); |
|
| 43 | + |
|
| 44 | + $this->prepare_billing_info( $invoice ); |
|
| 45 | + |
|
| 46 | + $shipping = $this->prepare_shipping_info( $invoice ); |
|
| 47 | + |
|
| 48 | + // Save the invoice. |
|
| 49 | + $invoice->set_is_viewed( true ); |
|
| 50 | + $invoice->recalculate_total(); |
|
| 51 | 51 | $invoice->save(); |
| 52 | 52 | |
| 53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
| 53 | + do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
| 54 | 54 | |
| 55 | - // Send to the gateway. |
|
| 56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
| 57 | - } |
|
| 55 | + // Send to the gateway. |
|
| 56 | + $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Validates the submission. |
|
| 61 | - * |
|
| 62 | - */ |
|
| 63 | - protected function validate_submission() { |
|
| 59 | + /** |
|
| 60 | + * Validates the submission. |
|
| 61 | + * |
|
| 62 | + */ |
|
| 63 | + protected function validate_submission() { |
|
| 64 | 64 | |
| 65 | - $submission = $this->payment_form_submission; |
|
| 66 | - $data = $submission->get_data(); |
|
| 65 | + $submission = $this->payment_form_submission; |
|
| 66 | + $data = $submission->get_data(); |
|
| 67 | 67 | |
| 68 | - // Do we have an error? |
|
| 68 | + // Do we have an error? |
|
| 69 | 69 | if ( ! empty( $submission->last_error ) ) { |
| 70 | - wp_send_json_error( $submission->last_error ); |
|
| 70 | + wp_send_json_error( $submission->last_error ); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - // We need a billing email. |
|
| 73 | + // We need a billing email. |
|
| 74 | 74 | if ( ! $submission->has_billing_email() ) { |
| 75 | 75 | wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
| 76 | - } |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - // Non-recurring gateways should not be allowed to process recurring invoices. |
|
| 79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
| 80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
| 81 | - } |
|
| 78 | + // Non-recurring gateways should not be allowed to process recurring invoices. |
|
| 79 | + if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
| 80 | + wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - // Ensure the gateway is active. |
|
| 84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
| 85 | - wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
| 86 | - } |
|
| 83 | + // Ensure the gateway is active. |
|
| 84 | + if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
| 85 | + wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - // Clear any existing errors. |
|
| 89 | - wpinv_clear_errors(); |
|
| 88 | + // Clear any existing errors. |
|
| 89 | + wpinv_clear_errors(); |
|
| 90 | 90 | |
| 91 | - // Allow themes and plugins to hook to errors |
|
| 92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
| 91 | + // Allow themes and plugins to hook to errors |
|
| 92 | + do_action( 'getpaid_checkout_error_checks', $submission ); |
|
| 93 | 93 | |
| 94 | - // Do we have any errors? |
|
| 94 | + // Do we have any errors? |
|
| 95 | 95 | if ( wpinv_get_errors() ) { |
| 96 | 96 | wp_send_json_error( getpaid_get_errors_html() ); |
| 97 | - } |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - } |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Retrieves submission items. |
|
| 103 | - * |
|
| 104 | - * @return GetPaid_Form_Item[] |
|
| 105 | - */ |
|
| 106 | - protected function get_submission_items() { |
|
| 101 | + /** |
|
| 102 | + * Retrieves submission items. |
|
| 103 | + * |
|
| 104 | + * @return GetPaid_Form_Item[] |
|
| 105 | + */ |
|
| 106 | + protected function get_submission_items() { |
|
| 107 | 107 | |
| 108 | - $items = $this->payment_form_submission->get_items(); |
|
| 108 | + $items = $this->payment_form_submission->get_items(); |
|
| 109 | 109 | |
| 110 | 110 | // Ensure that we have items. |
| 111 | 111 | if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
| 112 | 112 | wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
| 113 | - } |
|
| 114 | - |
|
| 115 | - return $items; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Retrieves submission invoice. |
|
| 120 | - * |
|
| 121 | - * @return WPInv_Invoice |
|
| 122 | - */ |
|
| 123 | - protected function get_submission_invoice() { |
|
| 124 | - $submission = $this->payment_form_submission; |
|
| 125 | - |
|
| 126 | - if ( ! $submission->has_invoice() ) { |
|
| 127 | - $invoice = new WPInv_Invoice(); |
|
| 128 | - $invoice->set_created_via( 'payment_form' ); |
|
| 129 | - return $invoice; |
|
| 130 | 113 | } |
| 131 | 114 | |
| 132 | - $invoice = $submission->get_invoice(); |
|
| 115 | + return $items; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Retrieves submission invoice. |
|
| 120 | + * |
|
| 121 | + * @return WPInv_Invoice |
|
| 122 | + */ |
|
| 123 | + protected function get_submission_invoice() { |
|
| 124 | + $submission = $this->payment_form_submission; |
|
| 133 | 125 | |
| 134 | - // Make sure that it is neither paid or refunded. |
|
| 135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
| 137 | - } |
|
| 126 | + if ( ! $submission->has_invoice() ) { |
|
| 127 | + $invoice = new WPInv_Invoice(); |
|
| 128 | + $invoice->set_created_via( 'payment_form' ); |
|
| 129 | + return $invoice; |
|
| 130 | + } |
|
| 138 | 131 | |
| 139 | - return $invoice; |
|
| 140 | - } |
|
| 132 | + $invoice = $submission->get_invoice(); |
|
| 141 | 133 | |
| 142 | - /** |
|
| 143 | - * Processes the submission invoice. |
|
| 144 | - * |
|
| 145 | - * @param WPInv_Invoice $invoice |
|
| 146 | - * @param GetPaid_Form_Item[] $items |
|
| 147 | - * @return WPInv_Invoice |
|
| 148 | - */ |
|
| 149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
| 134 | + // Make sure that it is neither paid or refunded. |
|
| 135 | + if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 136 | + wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
| 137 | + } |
|
| 150 | 138 | |
| 151 | - $submission = $this->payment_form_submission; |
|
| 139 | + return $invoice; |
|
| 140 | + } |
|
| 152 | 141 | |
| 153 | - // Set-up the invoice details. |
|
| 154 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
| 155 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
| 156 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
| 142 | + /** |
|
| 143 | + * Processes the submission invoice. |
|
| 144 | + * |
|
| 145 | + * @param WPInv_Invoice $invoice |
|
| 146 | + * @param GetPaid_Form_Item[] $items |
|
| 147 | + * @return WPInv_Invoice |
|
| 148 | + */ |
|
| 149 | + protected function process_submission_invoice( $invoice, $items ) { |
|
| 150 | + |
|
| 151 | + $submission = $this->payment_form_submission; |
|
| 152 | + |
|
| 153 | + // Set-up the invoice details. |
|
| 154 | + $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
| 155 | + $invoice->set_user_id( $this->get_submission_customer() ); |
|
| 156 | + $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
| 157 | 157 | $invoice->set_items( $items ); |
| 158 | 158 | $invoice->set_fees( $submission->get_fees() ); |
| 159 | 159 | $invoice->set_taxes( $submission->get_taxes() ); |
| 160 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
| 161 | - $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
| 162 | - $invoice->set_currency( $submission->get_currency() ); |
|
| 160 | + $invoice->set_discounts( $submission->get_discounts() ); |
|
| 161 | + $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
| 162 | + $invoice->set_currency( $submission->get_currency() ); |
|
| 163 | 163 | |
| 164 | - if ( $submission->has_shipping() ) { |
|
| 165 | - $invoice->set_shipping( $submission->get_shipping() ); |
|
| 166 | - } |
|
| 164 | + if ( $submission->has_shipping() ) { |
|
| 165 | + $invoice->set_shipping( $submission->get_shipping() ); |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
| 169 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
| 168 | + $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
| 169 | + $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
| 170 | 170 | |
| 171 | - if ( $submission->has_discount_code() ) { |
|
| 171 | + if ( $submission->has_discount_code() ) { |
|
| 172 | 172 | $invoice->set_discount_code( $submission->get_discount_code() ); |
| 173 | - } |
|
| 174 | - |
|
| 175 | - getpaid_maybe_add_default_address( $invoice ); |
|
| 176 | - return $invoice; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Retrieves the submission's customer. |
|
| 181 | - * |
|
| 182 | - * @return int The customer id. |
|
| 183 | - */ |
|
| 184 | - protected function get_submission_customer() { |
|
| 185 | - $submission = $this->payment_form_submission; |
|
| 186 | - |
|
| 187 | - // If this is an existing invoice... |
|
| 188 | - if ( $submission->has_invoice() ) { |
|
| 189 | - return $submission->get_invoice()->get_user_id(); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - // (Maybe) create the user. |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + getpaid_maybe_add_default_address( $invoice ); |
|
| 176 | + return $invoice; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Retrieves the submission's customer. |
|
| 181 | + * |
|
| 182 | + * @return int The customer id. |
|
| 183 | + */ |
|
| 184 | + protected function get_submission_customer() { |
|
| 185 | + $submission = $this->payment_form_submission; |
|
| 186 | + |
|
| 187 | + // If this is an existing invoice... |
|
| 188 | + if ( $submission->has_invoice() ) { |
|
| 189 | + return $submission->get_invoice()->get_user_id(); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + // (Maybe) create the user. |
|
| 193 | 193 | $user = get_current_user_id(); |
| 194 | 194 | |
| 195 | 195 | if ( empty( $user ) ) { |
@@ -197,16 +197,16 @@ discard block |
||
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | if ( empty( $user ) ) { |
| 200 | - $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
| 201 | - $name = implode( '', array_filter( $name ) ); |
|
| 200 | + $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) ); |
|
| 201 | + $name = implode( '', array_filter( $name ) ); |
|
| 202 | 202 | $user = wpinv_create_user( $submission->get_billing_email(), $name ); |
| 203 | 203 | |
| 204 | - // (Maybe) send new user notification. |
|
| 205 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
| 206 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
| 207 | - wp_send_new_user_notifications( $user, 'user' ); |
|
| 208 | - } |
|
| 209 | - } |
|
| 204 | + // (Maybe) send new user notification. |
|
| 205 | + $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
| 206 | + if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
| 207 | + wp_send_new_user_notifications( $user, 'user' ); |
|
| 208 | + } |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | 211 | if ( is_wp_error( $user ) ) { |
| 212 | 212 | wp_send_json_error( $user->get_error_message() ); |
@@ -214,49 +214,49 @@ discard block |
||
| 214 | 214 | |
| 215 | 215 | if ( is_numeric( $user ) ) { |
| 216 | 216 | return $user; |
| 217 | - } |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | - return $user->ID; |
|
| 219 | + return $user->ID; |
|
| 220 | 220 | |
| 221 | - } |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - /** |
|
| 223 | + /** |
|
| 224 | 224 | * Prepares submission data for saving to the database. |
| 225 | 225 | * |
| 226 | - * @return array |
|
| 226 | + * @return array |
|
| 227 | 227 | */ |
| 228 | 228 | public function prepare_submission_data_for_saving() { |
| 229 | 229 | |
| 230 | - $submission = $this->payment_form_submission; |
|
| 230 | + $submission = $this->payment_form_submission; |
|
| 231 | 231 | |
| 232 | - // Prepared submission details. |
|
| 232 | + // Prepared submission details. |
|
| 233 | 233 | $prepared = array( |
| 234 | - 'all' => array(), |
|
| 235 | - 'meta' => array(), |
|
| 236 | - ); |
|
| 234 | + 'all' => array(), |
|
| 235 | + 'meta' => array(), |
|
| 236 | + ); |
|
| 237 | 237 | |
| 238 | 238 | // Raw submission details. |
| 239 | - $data = $submission->get_data(); |
|
| 239 | + $data = $submission->get_data(); |
|
| 240 | 240 | |
| 241 | - // Loop through the submitted details. |
|
| 241 | + // Loop through the submitted details. |
|
| 242 | 242 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
| 243 | 243 | |
| 244 | - // Skip premade fields. |
|
| 244 | + // Skip premade fields. |
|
| 245 | 245 | if ( ! empty( $field['premade'] ) ) { |
| 246 | 246 | continue; |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - // Ensure address is provided. |
|
| 250 | - if ( 'address' === $field['type'] ) { |
|
| 249 | + // Ensure address is provided. |
|
| 250 | + if ( 'address' === $field['type'] ) { |
|
| 251 | 251 | $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
| 252 | 252 | |
| 253 | - foreach ( $field['fields'] as $address_field ) { |
|
| 253 | + foreach ( $field['fields'] as $address_field ) { |
|
| 254 | 254 | |
| 255 | - if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 256 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
| 257 | - } |
|
| 258 | - } |
|
| 259 | - } |
|
| 255 | + if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 256 | + wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
| 257 | + } |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | 261 | // If it is required and not set, abort. |
| 262 | 262 | if ( ! $submission->is_required_field_set( $field ) ) { |
@@ -266,31 +266,31 @@ discard block |
||
| 266 | 266 | // Handle misc fields. |
| 267 | 267 | if ( isset( $data[ $field['id'] ] ) ) { |
| 268 | 268 | |
| 269 | - // Uploads. |
|
| 270 | - if ( 'file_upload' === $field['type'] ) { |
|
| 271 | - $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
| 269 | + // Uploads. |
|
| 270 | + if ( 'file_upload' === $field['type'] ) { |
|
| 271 | + $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
| 272 | 272 | |
| 273 | - if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
| 274 | - wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
| 275 | - } |
|
| 273 | + if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
| 274 | + wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - $value = array(); |
|
| 277 | + $value = array(); |
|
| 278 | 278 | |
| 279 | - foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
| 280 | - $value[] = sprintf( |
|
| 281 | - '<a href="%s" target="_blank">%s</a>', |
|
| 282 | - esc_url_raw( $url ), |
|
| 283 | - esc_html( $name ) |
|
| 284 | - ); |
|
| 285 | - } |
|
| 279 | + foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
| 280 | + $value[] = sprintf( |
|
| 281 | + '<a href="%s" target="_blank">%s</a>', |
|
| 282 | + esc_url_raw( $url ), |
|
| 283 | + esc_html( $name ) |
|
| 284 | + ); |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | - $value = implode( ' | ', $value ); |
|
| 287 | + $value = implode( ' | ', $value ); |
|
| 288 | 288 | |
| 289 | - } elseif ( 'checkbox' === $field['type'] ) { |
|
| 290 | - $value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
| 291 | - } else { |
|
| 292 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
| 293 | - } |
|
| 289 | + } elseif ( 'checkbox' === $field['type'] ) { |
|
| 290 | + $value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
| 291 | + } else { |
|
| 292 | + $value = wp_kses_post( $data[ $field['id'] ] ); |
|
| 293 | + } |
|
| 294 | 294 | |
| 295 | 295 | $label = $field['id']; |
| 296 | 296 | |
@@ -298,192 +298,192 @@ discard block |
||
| 298 | 298 | $label = $field['label']; |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - if ( ! empty( $field['add_meta'] ) ) { |
|
| 302 | - $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
| 303 | - } |
|
| 304 | - $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
| 301 | + if ( ! empty( $field['add_meta'] ) ) { |
|
| 302 | + $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
| 303 | + } |
|
| 304 | + $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
| 305 | 305 | |
| 306 | 306 | } |
| 307 | - } |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | - return $prepared; |
|
| 309 | + return $prepared; |
|
| 310 | 310 | |
| 311 | - } |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - /** |
|
| 313 | + /** |
|
| 314 | 314 | * Retrieves address details. |
| 315 | 315 | * |
| 316 | - * @return array |
|
| 317 | - * @param WPInv_Invoice $invoice |
|
| 318 | - * @param string $type |
|
| 316 | + * @return array |
|
| 317 | + * @param WPInv_Invoice $invoice |
|
| 318 | + * @param string $type |
|
| 319 | 319 | */ |
| 320 | 320 | public function prepare_address_details( $invoice, $type = 'billing' ) { |
| 321 | 321 | |
| 322 | - $data = $this->payment_form_submission->get_data(); |
|
| 323 | - $type = sanitize_key( $type ); |
|
| 324 | - $address = array(); |
|
| 325 | - $prepared = array(); |
|
| 322 | + $data = $this->payment_form_submission->get_data(); |
|
| 323 | + $type = sanitize_key( $type ); |
|
| 324 | + $address = array(); |
|
| 325 | + $prepared = array(); |
|
| 326 | 326 | |
| 327 | - if ( ! empty( $data[ $type ] ) ) { |
|
| 328 | - $address = $data[ $type ]; |
|
| 329 | - } |
|
| 327 | + if ( ! empty( $data[ $type ] ) ) { |
|
| 328 | + $address = $data[ $type ]; |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | - // Clean address details. |
|
| 332 | - foreach ( $address as $key => $value ) { |
|
| 333 | - $key = sanitize_key( $key ); |
|
| 334 | - $key = str_replace( 'wpinv_', '', $key ); |
|
| 335 | - $value = wpinv_clean( $value ); |
|
| 336 | - $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
| 337 | - } |
|
| 331 | + // Clean address details. |
|
| 332 | + foreach ( $address as $key => $value ) { |
|
| 333 | + $key = sanitize_key( $key ); |
|
| 334 | + $key = str_replace( 'wpinv_', '', $key ); |
|
| 335 | + $value = wpinv_clean( $value ); |
|
| 336 | + $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - // Filter address details. |
|
| 340 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
| 339 | + // Filter address details. |
|
| 340 | + $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
| 341 | 341 | |
| 342 | - // Remove non-whitelisted values. |
|
| 343 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
| 342 | + // Remove non-whitelisted values. |
|
| 343 | + return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
| 344 | 344 | |
| 345 | - } |
|
| 345 | + } |
|
| 346 | 346 | |
| 347 | - /** |
|
| 347 | + /** |
|
| 348 | 348 | * Prepares the billing details. |
| 349 | 349 | * |
| 350 | - * @return array |
|
| 351 | - * @param WPInv_Invoice $invoice |
|
| 350 | + * @return array |
|
| 351 | + * @param WPInv_Invoice $invoice |
|
| 352 | 352 | */ |
| 353 | 353 | protected function prepare_billing_info( &$invoice ) { |
| 354 | 354 | |
| 355 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
| 355 | + $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
| 356 | 356 | |
| 357 | - // Update the invoice with the billing details. |
|
| 358 | - $invoice->set_props( $billing_address ); |
|
| 357 | + // Update the invoice with the billing details. |
|
| 358 | + $invoice->set_props( $billing_address ); |
|
| 359 | 359 | |
| 360 | - } |
|
| 360 | + } |
|
| 361 | 361 | |
| 362 | - /** |
|
| 362 | + /** |
|
| 363 | 363 | * Prepares the shipping details. |
| 364 | 364 | * |
| 365 | - * @return array |
|
| 366 | - * @param WPInv_Invoice $invoice |
|
| 365 | + * @return array |
|
| 366 | + * @param WPInv_Invoice $invoice |
|
| 367 | 367 | */ |
| 368 | 368 | protected function prepare_shipping_info( $invoice ) { |
| 369 | 369 | |
| 370 | - $data = $this->payment_form_submission->get_data(); |
|
| 370 | + $data = $this->payment_form_submission->get_data(); |
|
| 371 | 371 | |
| 372 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
| 373 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
| 374 | - } |
|
| 372 | + if ( empty( $data['same-shipping-address'] ) ) { |
|
| 373 | + return $this->prepare_address_details( $invoice, 'shipping' ); |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
| 376 | + return $this->prepare_address_details( $invoice, 'billing' ); |
|
| 377 | 377 | |
| 378 | - } |
|
| 378 | + } |
|
| 379 | 379 | |
| 380 | - /** |
|
| 381 | - * Confirms the submission is valid and send users to the gateway. |
|
| 382 | - * |
|
| 383 | - * @param WPInv_Invoice $invoice |
|
| 384 | - * @param array $prepared_payment_form_data |
|
| 385 | - * @param array $shipping |
|
| 386 | - */ |
|
| 387 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
| 380 | + /** |
|
| 381 | + * Confirms the submission is valid and send users to the gateway. |
|
| 382 | + * |
|
| 383 | + * @param WPInv_Invoice $invoice |
|
| 384 | + * @param array $prepared_payment_form_data |
|
| 385 | + * @param array $shipping |
|
| 386 | + */ |
|
| 387 | + protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
| 388 | 388 | |
| 389 | - // Ensure the invoice exists. |
|
| 389 | + // Ensure the invoice exists. |
|
| 390 | 390 | if ( ! $invoice->exists() ) { |
| 391 | 391 | wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | - // Save payment form data. |
|
| 395 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
| 394 | + // Save payment form data. |
|
| 395 | + $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
| 396 | 396 | delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
| 397 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
| 398 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
| 397 | + delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
| 398 | + if ( ! empty( $prepared_payment_form_data ) ) { |
|
| 399 | 399 | |
| 400 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
| 401 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
| 402 | - } |
|
| 400 | + if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
| 401 | + update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
| 402 | + } |
|
| 403 | 403 | |
| 404 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
| 405 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
| 406 | - } |
|
| 407 | - } |
|
| 404 | + if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
| 405 | + update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | 408 | |
| 409 | - // Save payment form data. |
|
| 410 | - $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
| 409 | + // Save payment form data. |
|
| 410 | + $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
| 411 | 411 | if ( ! empty( $shipping ) ) { |
| 412 | 412 | update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
| 413 | - } |
|
| 413 | + } |
|
| 414 | 414 | |
| 415 | - // Backwards compatibility. |
|
| 415 | + // Backwards compatibility. |
|
| 416 | 416 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
| 417 | 417 | |
| 418 | - try { |
|
| 419 | - $this->process_payment( $invoice ); |
|
| 420 | - } catch ( Exception $e ) { |
|
| 421 | - wpinv_set_error( 'payment_error', $e->getMessage() ); |
|
| 422 | - } |
|
| 418 | + try { |
|
| 419 | + $this->process_payment( $invoice ); |
|
| 420 | + } catch ( Exception $e ) { |
|
| 421 | + wpinv_set_error( 'payment_error', $e->getMessage() ); |
|
| 422 | + } |
|
| 423 | 423 | |
| 424 | 424 | // If we are here, there was an error. |
| 425 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 425 | + wpinv_send_back_to_checkout( $invoice ); |
|
| 426 | 426 | |
| 427 | - } |
|
| 427 | + } |
|
| 428 | 428 | |
| 429 | - /** |
|
| 430 | - * Processes the actual payment. |
|
| 431 | - * |
|
| 432 | - * @param WPInv_Invoice $invoice |
|
| 433 | - */ |
|
| 434 | - protected function process_payment( $invoice ) { |
|
| 429 | + /** |
|
| 430 | + * Processes the actual payment. |
|
| 431 | + * |
|
| 432 | + * @param WPInv_Invoice $invoice |
|
| 433 | + */ |
|
| 434 | + protected function process_payment( $invoice ) { |
|
| 435 | 435 | |
| 436 | - // Clear any checkout errors. |
|
| 437 | - wpinv_clear_errors(); |
|
| 436 | + // Clear any checkout errors. |
|
| 437 | + wpinv_clear_errors(); |
|
| 438 | 438 | |
| 439 | - // No need to send free invoices to the gateway. |
|
| 440 | - if ( $invoice->is_free() ) { |
|
| 441 | - $this->process_free_payment( $invoice ); |
|
| 442 | - } |
|
| 439 | + // No need to send free invoices to the gateway. |
|
| 440 | + if ( $invoice->is_free() ) { |
|
| 441 | + $this->process_free_payment( $invoice ); |
|
| 442 | + } |
|
| 443 | 443 | |
| 444 | - $submission = $this->payment_form_submission; |
|
| 444 | + $submission = $this->payment_form_submission; |
|
| 445 | 445 | |
| 446 | - // Fires before sending to the gateway. |
|
| 447 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
| 446 | + // Fires before sending to the gateway. |
|
| 447 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
| 448 | 448 | |
| 449 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
| 450 | - $submission_data = $submission->get_data(); |
|
| 451 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
| 452 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
| 449 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
| 450 | + $submission_data = $submission->get_data(); |
|
| 451 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
| 452 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
| 453 | 453 | |
| 454 | - // Validate the currency. |
|
| 455 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
| 456 | - wpinv_set_error( 'invalid_currency' ); |
|
| 457 | - } |
|
| 454 | + // Validate the currency. |
|
| 455 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
| 456 | + wpinv_set_error( 'invalid_currency' ); |
|
| 457 | + } |
|
| 458 | 458 | |
| 459 | - // Check to see if we have any errors. |
|
| 460 | - if ( wpinv_get_errors() ) { |
|
| 461 | - wpinv_send_back_to_checkout( $invoice ); |
|
| 462 | - } |
|
| 459 | + // Check to see if we have any errors. |
|
| 460 | + if ( wpinv_get_errors() ) { |
|
| 461 | + wpinv_send_back_to_checkout( $invoice ); |
|
| 462 | + } |
|
| 463 | 463 | |
| 464 | - // Send info to the gateway for payment processing |
|
| 465 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
| 464 | + // Send info to the gateway for payment processing |
|
| 465 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
| 466 | 466 | |
| 467 | - // Backwards compatibility. |
|
| 468 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
| 467 | + // Backwards compatibility. |
|
| 468 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
| 469 | 469 | |
| 470 | - } |
|
| 470 | + } |
|
| 471 | 471 | |
| 472 | - /** |
|
| 473 | - * Marks the invoice as paid in case the checkout is free. |
|
| 474 | - * |
|
| 475 | - * @param WPInv_Invoice $invoice |
|
| 476 | - */ |
|
| 477 | - protected function process_free_payment( $invoice ) { |
|
| 472 | + /** |
|
| 473 | + * Marks the invoice as paid in case the checkout is free. |
|
| 474 | + * |
|
| 475 | + * @param WPInv_Invoice $invoice |
|
| 476 | + */ |
|
| 477 | + protected function process_free_payment( $invoice ) { |
|
| 478 | 478 | |
| 479 | - $invoice->set_gateway( 'none' ); |
|
| 480 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
| 481 | - $invoice->mark_paid(); |
|
| 482 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 479 | + $invoice->set_gateway( 'none' ); |
|
| 480 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
| 481 | + $invoice->mark_paid(); |
|
| 482 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 483 | 483 | |
| 484 | - } |
|
| 484 | + } |
|
| 485 | 485 | |
| 486 | - /** |
|
| 486 | + /** |
|
| 487 | 487 | * Sends a redrect response to payment details. |
| 488 | 488 | * |
| 489 | 489 | */ |