@@ -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"); |
@@ -13,741 +13,741 @@ discard block |
||
| 13 | 13 | class GetPaid_Post_Types_Admin { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Hook in methods. |
|
| 17 | - */ |
|
| 18 | - public static function init() { |
|
| 19 | - |
|
| 20 | - // Init metaboxes. |
|
| 21 | - GetPaid_Metaboxes::init(); |
|
| 22 | - |
|
| 23 | - // Filter the post updated messages. |
|
| 24 | - add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
| 25 | - |
|
| 26 | - // Filter post actions. |
|
| 27 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
| 28 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 ); |
|
| 29 | - |
|
| 30 | - // Invoice table columns. |
|
| 31 | - add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
| 32 | - add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
| 33 | - add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) ); |
|
| 34 | - add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 ); |
|
| 35 | - |
|
| 36 | - // Items table columns. |
|
| 37 | - add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
| 38 | - add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
| 39 | - add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
| 40 | - add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
| 41 | - add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
| 42 | - add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
| 43 | - |
|
| 44 | - // Payment forms columns. |
|
| 45 | - add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
| 46 | - add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
| 47 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
| 48 | - |
|
| 49 | - // Discount table columns. |
|
| 50 | - add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
| 51 | - add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
| 52 | - |
|
| 53 | - // Deleting posts. |
|
| 54 | - add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
| 55 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
| 56 | - |
|
| 57 | - add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 ); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Post updated messages. |
|
| 62 | - */ |
|
| 63 | - public static function post_updated_messages( $messages ) { |
|
| 64 | - global $post; |
|
| 65 | - |
|
| 66 | - $messages['wpi_discount'] = array( |
|
| 67 | - 0 => '', |
|
| 68 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
| 69 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 70 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 71 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
| 72 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 73 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
| 74 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
| 75 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
| 76 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 77 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
| 78 | - ); |
|
| 79 | - |
|
| 80 | - $messages['wpi_payment_form'] = array( |
|
| 81 | - 0 => '', |
|
| 82 | - 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 83 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 84 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 85 | - 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 86 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 87 | - 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 88 | - 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
| 89 | - 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
| 90 | - 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 91 | - 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
| 92 | - ); |
|
| 93 | - |
|
| 94 | - return $messages; |
|
| 95 | - |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Post row actions. |
|
| 100 | - */ |
|
| 101 | - public static function post_row_actions( $actions, $post ) { |
|
| 102 | - |
|
| 103 | - $post = get_post( $post ); |
|
| 104 | - |
|
| 105 | - // We do not want to edit the default payment form. |
|
| 106 | - if ( 'wpi_payment_form' == $post->post_type ) { |
|
| 107 | - |
|
| 108 | - if ( wpinv_get_default_payment_form() === $post->ID ) { |
|
| 109 | - unset( $actions['trash'] ); |
|
| 110 | - unset( $actions['inline hide-if-no-js'] ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $actions['duplicate'] = sprintf( |
|
| 114 | - '<a href="%1$s">%2$s</a>', |
|
| 115 | - esc_url( |
|
| 116 | - wp_nonce_url( |
|
| 117 | - add_query_arg( |
|
| 118 | - array( |
|
| 119 | - 'getpaid-admin-action' => 'duplicate_form', |
|
| 120 | - 'form_id' => $post->ID, |
|
| 121 | - ) |
|
| 122 | - ), |
|
| 123 | - 'getpaid-nonce', |
|
| 124 | - 'getpaid-nonce' |
|
| 125 | - ) |
|
| 126 | - ), |
|
| 127 | - esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
| 128 | - ); |
|
| 129 | - |
|
| 130 | - $actions['reset'] = sprintf( |
|
| 131 | - '<a href="%1$s" style="color: #800">%2$s</a>', |
|
| 132 | - esc_url( |
|
| 133 | - wp_nonce_url( |
|
| 134 | - add_query_arg( |
|
| 135 | - array( |
|
| 136 | - 'getpaid-admin-action' => 'reset_form_stats', |
|
| 137 | - 'form_id' => $post->ID, |
|
| 138 | - ) |
|
| 139 | - ), |
|
| 140 | - 'getpaid-nonce', |
|
| 141 | - 'getpaid-nonce' |
|
| 142 | - ) |
|
| 143 | - ), |
|
| 144 | - esc_html( __( 'Reset Stats', 'invoicing' ) ) |
|
| 145 | - ); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - // Link to item payment form. |
|
| 149 | - if ( 'wpi_item' == $post->post_type ) { |
|
| 150 | - |
|
| 151 | - if ( in_array( get_post_meta( $post->ID, '_wpinv_type', true ), array( '', 'fee', 'custom' ), true ) ) { |
|
| 152 | - |
|
| 153 | - $actions['buy'] = sprintf( |
|
| 154 | - '<a href="%1$s">%2$s</a>', |
|
| 155 | - esc_url( getpaid_embed_url( false, $post->ID . '|0' ) ), |
|
| 156 | - esc_html( __( 'Buy', 'invoicing' ) ) |
|
| 157 | - ); |
|
| 158 | - |
|
| 159 | - } |
|
| 16 | + * Hook in methods. |
|
| 17 | + */ |
|
| 18 | + public static function init() { |
|
| 19 | + |
|
| 20 | + // Init metaboxes. |
|
| 21 | + GetPaid_Metaboxes::init(); |
|
| 22 | + |
|
| 23 | + // Filter the post updated messages. |
|
| 24 | + add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
| 25 | + |
|
| 26 | + // Filter post actions. |
|
| 27 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
| 28 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 ); |
|
| 29 | + |
|
| 30 | + // Invoice table columns. |
|
| 31 | + add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
| 32 | + add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
| 33 | + add_filter( 'bulk_actions-edit-wpi_invoice', array( __CLASS__, 'invoice_bulk_actions' ) ); |
|
| 34 | + add_filter( 'handle_bulk_actions-edit-wpi_invoice', array( __CLASS__, 'handle_invoice_bulk_actions' ), 10, 3 ); |
|
| 35 | + |
|
| 36 | + // Items table columns. |
|
| 37 | + add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
| 38 | + add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
| 39 | + add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
| 40 | + add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
| 41 | + add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
| 42 | + add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
| 43 | + |
|
| 44 | + // Payment forms columns. |
|
| 45 | + add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
| 46 | + add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
| 47 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
| 48 | + |
|
| 49 | + // Discount table columns. |
|
| 50 | + add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
| 51 | + add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
| 52 | + |
|
| 53 | + // Deleting posts. |
|
| 54 | + add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
| 55 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
| 56 | + |
|
| 57 | + add_filter( 'display_post_states', array( __CLASS__, 'add_display_post_states' ), 10, 2 ); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Post updated messages. |
|
| 62 | + */ |
|
| 63 | + public static function post_updated_messages( $messages ) { |
|
| 64 | + global $post; |
|
| 65 | + |
|
| 66 | + $messages['wpi_discount'] = array( |
|
| 67 | + 0 => '', |
|
| 68 | + 1 => __( 'Discount updated.', 'invoicing' ), |
|
| 69 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 70 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 71 | + 4 => __( 'Discount updated.', 'invoicing' ), |
|
| 72 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 73 | + 6 => __( 'Discount updated.', 'invoicing' ), |
|
| 74 | + 7 => __( 'Discount saved.', 'invoicing' ), |
|
| 75 | + 8 => __( 'Discount submitted.', 'invoicing' ), |
|
| 76 | + 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 77 | + 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
| 78 | + ); |
|
| 79 | + |
|
| 80 | + $messages['wpi_payment_form'] = array( |
|
| 81 | + 0 => '', |
|
| 82 | + 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 83 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 84 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 85 | + 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 86 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 87 | + 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
| 88 | + 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
| 89 | + 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
| 90 | + 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 91 | + 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
| 92 | + ); |
|
| 93 | + |
|
| 94 | + return $messages; |
|
| 95 | + |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Post row actions. |
|
| 100 | + */ |
|
| 101 | + public static function post_row_actions( $actions, $post ) { |
|
| 102 | + |
|
| 103 | + $post = get_post( $post ); |
|
| 104 | + |
|
| 105 | + // We do not want to edit the default payment form. |
|
| 106 | + if ( 'wpi_payment_form' == $post->post_type ) { |
|
| 107 | + |
|
| 108 | + if ( wpinv_get_default_payment_form() === $post->ID ) { |
|
| 109 | + unset( $actions['trash'] ); |
|
| 110 | + unset( $actions['inline hide-if-no-js'] ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $actions['duplicate'] = sprintf( |
|
| 114 | + '<a href="%1$s">%2$s</a>', |
|
| 115 | + esc_url( |
|
| 116 | + wp_nonce_url( |
|
| 117 | + add_query_arg( |
|
| 118 | + array( |
|
| 119 | + 'getpaid-admin-action' => 'duplicate_form', |
|
| 120 | + 'form_id' => $post->ID, |
|
| 121 | + ) |
|
| 122 | + ), |
|
| 123 | + 'getpaid-nonce', |
|
| 124 | + 'getpaid-nonce' |
|
| 125 | + ) |
|
| 126 | + ), |
|
| 127 | + esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
| 128 | + ); |
|
| 129 | + |
|
| 130 | + $actions['reset'] = sprintf( |
|
| 131 | + '<a href="%1$s" style="color: #800">%2$s</a>', |
|
| 132 | + esc_url( |
|
| 133 | + wp_nonce_url( |
|
| 134 | + add_query_arg( |
|
| 135 | + array( |
|
| 136 | + 'getpaid-admin-action' => 'reset_form_stats', |
|
| 137 | + 'form_id' => $post->ID, |
|
| 138 | + ) |
|
| 139 | + ), |
|
| 140 | + 'getpaid-nonce', |
|
| 141 | + 'getpaid-nonce' |
|
| 142 | + ) |
|
| 143 | + ), |
|
| 144 | + esc_html( __( 'Reset Stats', 'invoicing' ) ) |
|
| 145 | + ); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + // Link to item payment form. |
|
| 149 | + if ( 'wpi_item' == $post->post_type ) { |
|
| 150 | + |
|
| 151 | + if ( in_array( get_post_meta( $post->ID, '_wpinv_type', true ), array( '', 'fee', 'custom' ), true ) ) { |
|
| 152 | + |
|
| 153 | + $actions['buy'] = sprintf( |
|
| 154 | + '<a href="%1$s">%2$s</a>', |
|
| 155 | + esc_url( getpaid_embed_url( false, $post->ID . '|0' ) ), |
|
| 156 | + esc_html( __( 'Buy', 'invoicing' ) ) |
|
| 157 | + ); |
|
| 158 | + |
|
| 159 | + } |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - return $actions; |
|
| 163 | - } |
|
| 162 | + return $actions; |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - /** |
|
| 165 | + /** |
|
| 166 | 166 | * Remove bulk edit option from admin side quote listing |
| 167 | 167 | * |
| 168 | 168 | * @since 1.0.0 |
| 169 | 169 | * @param array $actions post actions |
| 170 | - * @param WP_Post $post |
|
| 170 | + * @param WP_Post $post |
|
| 171 | 171 | * @return array $actions actions without edit option |
| 172 | 172 | */ |
| 173 | 173 | public static function filter_invoice_row_actions( $actions, $post ) { |
| 174 | 174 | |
| 175 | 175 | if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
| 176 | 176 | |
| 177 | - $actions = array(); |
|
| 178 | - $invoice = new WPInv_Invoice( $post ); |
|
| 179 | - |
|
| 180 | - $actions['edit'] = sprintf( |
|
| 181 | - '<a href="%1$s">%2$s</a>', |
|
| 182 | - esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
| 183 | - esc_html( __( 'Edit', 'invoicing' ) ) |
|
| 184 | - ); |
|
| 185 | - |
|
| 186 | - if ( ! $invoice->is_draft() ) { |
|
| 187 | - |
|
| 188 | - $actions['view'] = sprintf( |
|
| 189 | - '<a href="%1$s">%2$s</a>', |
|
| 190 | - esc_url( $invoice->get_view_url() ), |
|
| 191 | - sprintf( |
|
| 192 | - // translators: %s is the invoice type |
|
| 193 | - esc_html__( 'View %s', 'invoicing' ), |
|
| 194 | - getpaid_get_post_type_label( $invoice->get_post_type(), false ) |
|
| 195 | - ) |
|
| 196 | - ); |
|
| 197 | - |
|
| 198 | - $actions['send'] = sprintf( |
|
| 199 | - '<a href="%1$s">%2$s</a>', |
|
| 200 | - esc_url( |
|
| 201 | - wp_nonce_url( |
|
| 202 | - add_query_arg( |
|
| 203 | - array( |
|
| 204 | - 'getpaid-admin-action' => 'send_invoice', |
|
| 205 | - 'invoice_id' => $invoice->get_id(), |
|
| 206 | - ) |
|
| 207 | - ), |
|
| 208 | - 'getpaid-nonce', |
|
| 209 | - 'getpaid-nonce' |
|
| 210 | - ) |
|
| 211 | - ), |
|
| 212 | - esc_html( __( 'Send to Customer', 'invoicing' ) ) |
|
| 213 | - ); |
|
| 214 | - |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - $actions['duplicate'] = sprintf( |
|
| 218 | - '<a href="%1$s">%2$s</a>', |
|
| 219 | - esc_url( |
|
| 220 | - wp_nonce_url( |
|
| 221 | - add_query_arg( |
|
| 222 | - array( |
|
| 223 | - 'getpaid-admin-action' => 'duplicate_invoice', |
|
| 224 | - 'invoice_id' => $post->ID, |
|
| 225 | - ) |
|
| 226 | - ), |
|
| 227 | - 'getpaid-nonce', |
|
| 228 | - 'getpaid-nonce' |
|
| 229 | - ) |
|
| 230 | - ), |
|
| 231 | - esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
| 232 | - ); |
|
| 177 | + $actions = array(); |
|
| 178 | + $invoice = new WPInv_Invoice( $post ); |
|
| 179 | + |
|
| 180 | + $actions['edit'] = sprintf( |
|
| 181 | + '<a href="%1$s">%2$s</a>', |
|
| 182 | + esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
| 183 | + esc_html( __( 'Edit', 'invoicing' ) ) |
|
| 184 | + ); |
|
| 185 | + |
|
| 186 | + if ( ! $invoice->is_draft() ) { |
|
| 187 | + |
|
| 188 | + $actions['view'] = sprintf( |
|
| 189 | + '<a href="%1$s">%2$s</a>', |
|
| 190 | + esc_url( $invoice->get_view_url() ), |
|
| 191 | + sprintf( |
|
| 192 | + // translators: %s is the invoice type |
|
| 193 | + esc_html__( 'View %s', 'invoicing' ), |
|
| 194 | + getpaid_get_post_type_label( $invoice->get_post_type(), false ) |
|
| 195 | + ) |
|
| 196 | + ); |
|
| 197 | + |
|
| 198 | + $actions['send'] = sprintf( |
|
| 199 | + '<a href="%1$s">%2$s</a>', |
|
| 200 | + esc_url( |
|
| 201 | + wp_nonce_url( |
|
| 202 | + add_query_arg( |
|
| 203 | + array( |
|
| 204 | + 'getpaid-admin-action' => 'send_invoice', |
|
| 205 | + 'invoice_id' => $invoice->get_id(), |
|
| 206 | + ) |
|
| 207 | + ), |
|
| 208 | + 'getpaid-nonce', |
|
| 209 | + 'getpaid-nonce' |
|
| 210 | + ) |
|
| 211 | + ), |
|
| 212 | + esc_html( __( 'Send to Customer', 'invoicing' ) ) |
|
| 213 | + ); |
|
| 214 | + |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + $actions['duplicate'] = sprintf( |
|
| 218 | + '<a href="%1$s">%2$s</a>', |
|
| 219 | + esc_url( |
|
| 220 | + wp_nonce_url( |
|
| 221 | + add_query_arg( |
|
| 222 | + array( |
|
| 223 | + 'getpaid-admin-action' => 'duplicate_invoice', |
|
| 224 | + 'invoice_id' => $post->ID, |
|
| 225 | + ) |
|
| 226 | + ), |
|
| 227 | + 'getpaid-nonce', |
|
| 228 | + 'getpaid-nonce' |
|
| 229 | + ) |
|
| 230 | + ), |
|
| 231 | + esc_html( __( 'Duplicate', 'invoicing' ) ) |
|
| 232 | + ); |
|
| 233 | 233 | |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | return $actions; |
| 237 | - } |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * Returns an array of invoice table columns. |
|
| 241 | - */ |
|
| 242 | - public static function invoice_columns( $columns ) { |
|
| 243 | - |
|
| 244 | - $columns = array( |
|
| 245 | - 'cb' => $columns['cb'], |
|
| 246 | - 'number' => __( 'Invoice', 'invoicing' ), |
|
| 247 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
| 248 | - 'invoice_date' => __( 'Created', 'invoicing' ), |
|
| 249 | - 'payment_date' => __( 'Completed', 'invoicing' ), |
|
| 250 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 251 | - 'recurring' => __( 'Recurring', 'invoicing' ), |
|
| 252 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 253 | - ); |
|
| 254 | - |
|
| 255 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * Displays invoice table columns. |
|
| 260 | - */ |
|
| 261 | - public static function display_invoice_columns( $column_name, $post_id ) { |
|
| 262 | - |
|
| 263 | - $invoice = new WPInv_Invoice( $post_id ); |
|
| 264 | - |
|
| 265 | - switch ( $column_name ) { |
|
| 266 | - |
|
| 267 | - case 'invoice_date': |
|
| 268 | - $date_time = esc_attr( $invoice->get_created_date() ); |
|
| 269 | - $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
| 270 | - echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
| 271 | - break; |
|
| 272 | - |
|
| 273 | - case 'payment_date': |
|
| 274 | - if ( $invoice->is_paid() ) { |
|
| 275 | - $date_time = esc_attr( $invoice->get_completed_date() ); |
|
| 276 | - $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
| 277 | - echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
| 278 | - } else { |
|
| 279 | - echo '—'; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - break; |
|
| 283 | - |
|
| 284 | - case 'amount': |
|
| 285 | - $amount = $invoice->get_total(); |
|
| 286 | - $formated_amount = wp_kses_post( wpinv_price( $amount, $invoice->get_currency() ) ); |
|
| 287 | - |
|
| 288 | - if ( $invoice->is_refunded() ) { |
|
| 289 | - $refunded_amount = wpinv_price( 0, $invoice->get_currency() ); |
|
| 290 | - echo wp_kses_post( "<del>$formated_amount</del> <ins>$refunded_amount</ins>" ); |
|
| 291 | - } else { |
|
| 292 | - |
|
| 293 | - $discount = $invoice->get_total_discount(); |
|
| 294 | - |
|
| 295 | - if ( ! empty( $discount ) ) { |
|
| 296 | - $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() ); |
|
| 297 | - echo wp_kses_post( "<del>$new_amount</del> <ins>$formated_amount</ins>" ); |
|
| 298 | - } else { |
|
| 299 | - echo wp_kses_post( $formated_amount ); |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - break; |
|
| 304 | - |
|
| 305 | - case 'status': |
|
| 306 | - $status = esc_html( $invoice->get_status() ); |
|
| 307 | - $status_label = esc_html( $invoice->get_status_nicename() ); |
|
| 308 | - |
|
| 309 | - // If it is paid, show the gateway title. |
|
| 310 | - if ( $invoice->is_paid() ) { |
|
| 311 | - $gateway = esc_html( $invoice->get_gateway_title() ); |
|
| 312 | - $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), esc_html( $gateway ) ); |
|
| 313 | - |
|
| 314 | - echo wp_kses_post( "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>" ); |
|
| 315 | - } else { |
|
| 316 | - echo wp_kses_post( "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>" ); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - // If it is not paid, display the overdue and view status. |
|
| 320 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
| 321 | - |
|
| 322 | - // Invoice view status. |
|
| 323 | - if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
| 324 | - echo ' <i class="fa fa-eye wpi-help-tip" title="' . esc_attr__( 'Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
| 325 | - } else { |
|
| 326 | - echo ' <i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__( 'Not Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - // Display the overview status. |
|
| 330 | - if ( wpinv_get_option( 'overdue_active' ) ) { |
|
| 331 | - $due_date = $invoice->get_due_date(); |
|
| 332 | - $fomatted = getpaid_format_date( $due_date ); |
|
| 333 | - |
|
| 334 | - if ( ! empty( $fomatted ) ) { |
|
| 335 | - $date = wp_sprintf( |
|
| 336 | - // translators: %s is the due date. |
|
| 337 | - __( 'Due %s', 'invoicing' ), |
|
| 338 | - $fomatted |
|
| 339 | - ); |
|
| 340 | - echo wp_kses_post( "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>" ); |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - break; |
|
| 346 | - |
|
| 347 | - case 'recurring': |
|
| 348 | - if ( $invoice->is_recurring() ) { |
|
| 349 | - echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
| 350 | - } else { |
|
| 351 | - echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
| 352 | - } |
|
| 353 | - break; |
|
| 354 | - |
|
| 355 | - case 'number': |
|
| 356 | - $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
| 357 | - $invoice_number = esc_html( $invoice->get_number() ); |
|
| 358 | - $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
| 359 | - |
|
| 360 | - echo wp_kses_post( "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>" ); |
|
| 361 | - |
|
| 362 | - do_action( 'getpaid_admin_table_invoice_number_column', $invoice ); |
|
| 363 | - break; |
|
| 364 | - |
|
| 365 | - case 'customer': |
|
| 366 | - $customer_name = $invoice->get_user_full_name(); |
|
| 367 | - |
|
| 368 | - if ( empty( $customer_name ) ) { |
|
| 369 | - $customer_name = $invoice->get_email(); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - if ( ! empty( $customer_name ) ) { |
|
| 373 | - $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
| 374 | - $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
| 375 | - echo wp_kses_post( "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>" ); |
|
| 376 | - } else { |
|
| 377 | - echo '<div>—</div>'; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - break; |
|
| 381 | - |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * Displays invoice bulk actions. |
|
| 388 | - */ |
|
| 389 | - public static function invoice_bulk_actions( $actions ) { |
|
| 390 | - $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' ); |
|
| 391 | - return $actions; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * Processes invoice bulk actions. |
|
| 396 | - */ |
|
| 397 | - public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) { |
|
| 398 | - |
|
| 399 | - if ( 'resend-invoice' === $action ) { |
|
| 400 | - foreach ( $post_ids as $post_id ) { |
|
| 401 | - getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true ); |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - return $redirect_url; |
|
| 406 | - |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * Returns an array of payment forms table columns. |
|
| 411 | - */ |
|
| 412 | - public static function payment_form_columns( $columns ) { |
|
| 413 | - |
|
| 414 | - $columns = array( |
|
| 415 | - 'cb' => $columns['cb'], |
|
| 416 | - 'title' => __( 'Name', 'invoicing' ), |
|
| 417 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 418 | - 'earnings' => __( 'Revenue', 'invoicing' ), |
|
| 419 | - 'refunds' => __( 'Refunded', 'invoicing' ), |
|
| 420 | - 'items' => __( 'Items', 'invoicing' ), |
|
| 421 | - 'date' => __( 'Date', 'invoicing' ), |
|
| 422 | - ); |
|
| 423 | - |
|
| 424 | - return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
| 425 | - |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - /** |
|
| 429 | - * Displays payment form table columns. |
|
| 430 | - */ |
|
| 431 | - public static function display_payment_form_columns( $column_name, $post_id ) { |
|
| 432 | - |
|
| 433 | - // Retrieve the payment form. |
|
| 434 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
| 435 | - |
|
| 436 | - switch ( $column_name ) { |
|
| 437 | - |
|
| 438 | - case 'earnings': |
|
| 439 | - echo wp_kses_post( wpinv_price( $form->get_earned() ) ); |
|
| 440 | - break; |
|
| 441 | - |
|
| 442 | - case 'refunds': |
|
| 443 | - echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
| 444 | - break; |
|
| 445 | - |
|
| 446 | - case 'refunds': |
|
| 447 | - echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
| 448 | - break; |
|
| 449 | - |
|
| 450 | - case 'shortcode': |
|
| 451 | - if ( $form->is_default() ) { |
|
| 452 | - echo '—'; |
|
| 453 | - } else { |
|
| 454 | - echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - break; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * Returns an array of invoice table columns. |
|
| 241 | + */ |
|
| 242 | + public static function invoice_columns( $columns ) { |
|
| 243 | + |
|
| 244 | + $columns = array( |
|
| 245 | + 'cb' => $columns['cb'], |
|
| 246 | + 'number' => __( 'Invoice', 'invoicing' ), |
|
| 247 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
| 248 | + 'invoice_date' => __( 'Created', 'invoicing' ), |
|
| 249 | + 'payment_date' => __( 'Completed', 'invoicing' ), |
|
| 250 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 251 | + 'recurring' => __( 'Recurring', 'invoicing' ), |
|
| 252 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 253 | + ); |
|
| 254 | + |
|
| 255 | + return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * Displays invoice table columns. |
|
| 260 | + */ |
|
| 261 | + public static function display_invoice_columns( $column_name, $post_id ) { |
|
| 262 | + |
|
| 263 | + $invoice = new WPInv_Invoice( $post_id ); |
|
| 264 | + |
|
| 265 | + switch ( $column_name ) { |
|
| 266 | + |
|
| 267 | + case 'invoice_date': |
|
| 268 | + $date_time = esc_attr( $invoice->get_created_date() ); |
|
| 269 | + $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
| 270 | + echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
| 271 | + break; |
|
| 272 | + |
|
| 273 | + case 'payment_date': |
|
| 274 | + if ( $invoice->is_paid() ) { |
|
| 275 | + $date_time = esc_attr( $invoice->get_completed_date() ); |
|
| 276 | + $date = esc_html( getpaid_format_date_value( $date_time, '—', true ) ); |
|
| 277 | + echo wp_kses_post( "<span title='$date_time'>$date</span>" ); |
|
| 278 | + } else { |
|
| 279 | + echo '—'; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + break; |
|
| 283 | + |
|
| 284 | + case 'amount': |
|
| 285 | + $amount = $invoice->get_total(); |
|
| 286 | + $formated_amount = wp_kses_post( wpinv_price( $amount, $invoice->get_currency() ) ); |
|
| 287 | + |
|
| 288 | + if ( $invoice->is_refunded() ) { |
|
| 289 | + $refunded_amount = wpinv_price( 0, $invoice->get_currency() ); |
|
| 290 | + echo wp_kses_post( "<del>$formated_amount</del> <ins>$refunded_amount</ins>" ); |
|
| 291 | + } else { |
|
| 292 | + |
|
| 293 | + $discount = $invoice->get_total_discount(); |
|
| 294 | + |
|
| 295 | + if ( ! empty( $discount ) ) { |
|
| 296 | + $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() ); |
|
| 297 | + echo wp_kses_post( "<del>$new_amount</del> <ins>$formated_amount</ins>" ); |
|
| 298 | + } else { |
|
| 299 | + echo wp_kses_post( $formated_amount ); |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + break; |
|
| 304 | + |
|
| 305 | + case 'status': |
|
| 306 | + $status = esc_html( $invoice->get_status() ); |
|
| 307 | + $status_label = esc_html( $invoice->get_status_nicename() ); |
|
| 308 | + |
|
| 309 | + // If it is paid, show the gateway title. |
|
| 310 | + if ( $invoice->is_paid() ) { |
|
| 311 | + $gateway = esc_html( $invoice->get_gateway_title() ); |
|
| 312 | + $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), esc_html( $gateway ) ); |
|
| 313 | + |
|
| 314 | + echo wp_kses_post( "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>" ); |
|
| 315 | + } else { |
|
| 316 | + echo wp_kses_post( "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>" ); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + // If it is not paid, display the overdue and view status. |
|
| 320 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
| 321 | + |
|
| 322 | + // Invoice view status. |
|
| 323 | + if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
| 324 | + echo ' <i class="fa fa-eye wpi-help-tip" title="' . esc_attr__( 'Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
| 325 | + } else { |
|
| 326 | + echo ' <i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__( 'Not Viewed by Customer', 'invoicing' ) . '"></i>'; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + // Display the overview status. |
|
| 330 | + if ( wpinv_get_option( 'overdue_active' ) ) { |
|
| 331 | + $due_date = $invoice->get_due_date(); |
|
| 332 | + $fomatted = getpaid_format_date( $due_date ); |
|
| 333 | + |
|
| 334 | + if ( ! empty( $fomatted ) ) { |
|
| 335 | + $date = wp_sprintf( |
|
| 336 | + // translators: %s is the due date. |
|
| 337 | + __( 'Due %s', 'invoicing' ), |
|
| 338 | + $fomatted |
|
| 339 | + ); |
|
| 340 | + echo wp_kses_post( "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>" ); |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + break; |
|
| 346 | + |
|
| 347 | + case 'recurring': |
|
| 348 | + if ( $invoice->is_recurring() ) { |
|
| 349 | + echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
| 350 | + } else { |
|
| 351 | + echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
| 352 | + } |
|
| 353 | + break; |
|
| 354 | + |
|
| 355 | + case 'number': |
|
| 356 | + $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
| 357 | + $invoice_number = esc_html( $invoice->get_number() ); |
|
| 358 | + $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
| 359 | + |
|
| 360 | + echo wp_kses_post( "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>" ); |
|
| 361 | + |
|
| 362 | + do_action( 'getpaid_admin_table_invoice_number_column', $invoice ); |
|
| 363 | + break; |
|
| 364 | + |
|
| 365 | + case 'customer': |
|
| 366 | + $customer_name = $invoice->get_user_full_name(); |
|
| 367 | + |
|
| 368 | + if ( empty( $customer_name ) ) { |
|
| 369 | + $customer_name = $invoice->get_email(); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + if ( ! empty( $customer_name ) ) { |
|
| 373 | + $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
| 374 | + $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
| 375 | + echo wp_kses_post( "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>" ); |
|
| 376 | + } else { |
|
| 377 | + echo '<div>—</div>'; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + break; |
|
| 458 | 381 | |
| 459 | - case 'items': |
|
| 460 | - $items = $form->get_items(); |
|
| 461 | - |
|
| 462 | - if ( $form->is_default() || empty( $items ) ) { |
|
| 463 | - echo '—'; |
|
| 464 | - return; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - $_items = array(); |
|
| 468 | - |
|
| 469 | - foreach ( $items as $item ) { |
|
| 470 | - $url = $item->get_edit_url(); |
|
| 471 | - |
|
| 472 | - if ( empty( $url ) ) { |
|
| 473 | - $_items[] = esc_html( $item->get_name() ); |
|
| 474 | - } else { |
|
| 475 | - $_items[] = sprintf( |
|
| 476 | - '<a href="%s">%s</a>', |
|
| 477 | - esc_url( $url ), |
|
| 478 | - esc_html( $item->get_name() ) |
|
| 479 | - ); |
|
| 480 | - } |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * Displays invoice bulk actions. |
|
| 388 | + */ |
|
| 389 | + public static function invoice_bulk_actions( $actions ) { |
|
| 390 | + $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' ); |
|
| 391 | + return $actions; |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * Processes invoice bulk actions. |
|
| 396 | + */ |
|
| 397 | + public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) { |
|
| 398 | + |
|
| 399 | + if ( 'resend-invoice' === $action ) { |
|
| 400 | + foreach ( $post_ids as $post_id ) { |
|
| 401 | + getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true ); |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + return $redirect_url; |
|
| 406 | + |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * Returns an array of payment forms table columns. |
|
| 411 | + */ |
|
| 412 | + public static function payment_form_columns( $columns ) { |
|
| 413 | + |
|
| 414 | + $columns = array( |
|
| 415 | + 'cb' => $columns['cb'], |
|
| 416 | + 'title' => __( 'Name', 'invoicing' ), |
|
| 417 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 418 | + 'earnings' => __( 'Revenue', 'invoicing' ), |
|
| 419 | + 'refunds' => __( 'Refunded', 'invoicing' ), |
|
| 420 | + 'items' => __( 'Items', 'invoicing' ), |
|
| 421 | + 'date' => __( 'Date', 'invoicing' ), |
|
| 422 | + ); |
|
| 423 | + |
|
| 424 | + return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
| 425 | + |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + /** |
|
| 429 | + * Displays payment form table columns. |
|
| 430 | + */ |
|
| 431 | + public static function display_payment_form_columns( $column_name, $post_id ) { |
|
| 432 | + |
|
| 433 | + // Retrieve the payment form. |
|
| 434 | + $form = new GetPaid_Payment_Form( $post_id ); |
|
| 435 | + |
|
| 436 | + switch ( $column_name ) { |
|
| 437 | + |
|
| 438 | + case 'earnings': |
|
| 439 | + echo wp_kses_post( wpinv_price( $form->get_earned() ) ); |
|
| 440 | + break; |
|
| 441 | + |
|
| 442 | + case 'refunds': |
|
| 443 | + echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
| 444 | + break; |
|
| 445 | + |
|
| 446 | + case 'refunds': |
|
| 447 | + echo wp_kses_post( wpinv_price( $form->get_refunded() ) ); |
|
| 448 | + break; |
|
| 449 | + |
|
| 450 | + case 'shortcode': |
|
| 451 | + if ( $form->is_default() ) { |
|
| 452 | + echo '—'; |
|
| 453 | + } else { |
|
| 454 | + echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + break; |
|
| 458 | + |
|
| 459 | + case 'items': |
|
| 460 | + $items = $form->get_items(); |
|
| 461 | + |
|
| 462 | + if ( $form->is_default() || empty( $items ) ) { |
|
| 463 | + echo '—'; |
|
| 464 | + return; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + $_items = array(); |
|
| 468 | + |
|
| 469 | + foreach ( $items as $item ) { |
|
| 470 | + $url = $item->get_edit_url(); |
|
| 471 | + |
|
| 472 | + if ( empty( $url ) ) { |
|
| 473 | + $_items[] = esc_html( $item->get_name() ); |
|
| 474 | + } else { |
|
| 475 | + $_items[] = sprintf( |
|
| 476 | + '<a href="%s">%s</a>', |
|
| 477 | + esc_url( $url ), |
|
| 478 | + esc_html( $item->get_name() ) |
|
| 479 | + ); |
|
| 480 | + } |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | - echo wp_kses_post( implode( '<br>', $_items ) ); |
|
| 483 | + echo wp_kses_post( implode( '<br>', $_items ) ); |
|
| 484 | + |
|
| 485 | + break; |
|
| 486 | + |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * Filters post states. |
|
| 493 | + */ |
|
| 494 | + public static function filter_payment_form_state( $post_states, $post ) { |
|
| 495 | + |
|
| 496 | + if ( 'wpi_payment_form' === $post->post_type && wpinv_get_default_payment_form() === $post->ID ) { |
|
| 497 | + $post_states['default_form'] = __( 'Default Payment Form', 'invoicing' ); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + return $post_states; |
|
| 501 | + |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + /** |
|
| 505 | + * Returns an array of coupon table columns. |
|
| 506 | + */ |
|
| 507 | + public static function discount_columns( $columns ) { |
|
| 508 | + |
|
| 509 | + $columns = array( |
|
| 510 | + 'cb' => $columns['cb'], |
|
| 511 | + 'title' => __( 'Name', 'invoicing' ), |
|
| 512 | + 'code' => __( 'Code', 'invoicing' ), |
|
| 513 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 514 | + 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
| 515 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 516 | + 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
| 517 | + ); |
|
| 518 | + |
|
| 519 | + return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
| 520 | + } |
|
| 484 | 521 | |
| 485 | - break; |
|
| 522 | + /** |
|
| 523 | + * Filters post states. |
|
| 524 | + */ |
|
| 525 | + public static function filter_discount_state( $post_states, $post ) { |
|
| 486 | 526 | |
| 487 | - } |
|
| 527 | + if ( 'wpi_discount' === $post->post_type ) { |
|
| 488 | 528 | |
| 489 | - } |
|
| 529 | + $discount = new WPInv_Discount( $post ); |
|
| 490 | 530 | |
| 491 | - /** |
|
| 492 | - * Filters post states. |
|
| 493 | - */ |
|
| 494 | - public static function filter_payment_form_state( $post_states, $post ) { |
|
| 531 | + $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
| 495 | 532 | |
| 496 | - if ( 'wpi_payment_form' === $post->post_type && wpinv_get_default_payment_form() === $post->ID ) { |
|
| 497 | - $post_states['default_form'] = __( 'Default Payment Form', 'invoicing' ); |
|
| 498 | - } |
|
| 533 | + if ( 'publish' !== $status ) { |
|
| 534 | + return array( |
|
| 535 | + 'discount_status' => wpinv_discount_status( $status ), |
|
| 536 | + ); |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + return array(); |
|
| 540 | + |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + return $post_states; |
|
| 499 | 544 | |
| 500 | - return $post_states; |
|
| 545 | + } |
|
| 501 | 546 | |
| 502 | - } |
|
| 547 | + /** |
|
| 548 | + * Returns an array of items table columns. |
|
| 549 | + */ |
|
| 550 | + public static function item_columns( $columns ) { |
|
| 551 | + |
|
| 552 | + $columns = array( |
|
| 553 | + 'cb' => $columns['cb'], |
|
| 554 | + 'title' => __( 'Name', 'invoicing' ), |
|
| 555 | + 'price' => __( 'Price', 'invoicing' ), |
|
| 556 | + 'vat_rule' => __( 'Tax Rule', 'invoicing' ), |
|
| 557 | + 'vat_class' => __( 'Tax Class', 'invoicing' ), |
|
| 558 | + 'type' => __( 'Type', 'invoicing' ), |
|
| 559 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 560 | + ); |
|
| 561 | + |
|
| 562 | + if ( ! wpinv_use_taxes() ) { |
|
| 563 | + unset( $columns['vat_rule'] ); |
|
| 564 | + unset( $columns['vat_class'] ); |
|
| 565 | + } |
|
| 503 | 566 | |
| 504 | - /** |
|
| 505 | - * Returns an array of coupon table columns. |
|
| 506 | - */ |
|
| 507 | - public static function discount_columns( $columns ) { |
|
| 567 | + return apply_filters( 'wpi_item_table_columns', $columns ); |
|
| 568 | + } |
|
| 508 | 569 | |
| 509 | - $columns = array( |
|
| 510 | - 'cb' => $columns['cb'], |
|
| 511 | - 'title' => __( 'Name', 'invoicing' ), |
|
| 512 | - 'code' => __( 'Code', 'invoicing' ), |
|
| 513 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 514 | - 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
| 515 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 516 | - 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
| 517 | - ); |
|
| 570 | + /** |
|
| 571 | + * Returns an array of sortable items table columns. |
|
| 572 | + */ |
|
| 573 | + public static function sortable_item_columns( $columns ) { |
|
| 574 | + |
|
| 575 | + return array_merge( |
|
| 576 | + $columns, |
|
| 577 | + array( |
|
| 578 | + 'price' => 'price', |
|
| 579 | + 'vat_rule' => 'vat_rule', |
|
| 580 | + 'vat_class' => 'vat_class', |
|
| 581 | + 'type' => 'type', |
|
| 582 | + ) |
|
| 583 | + ); |
|
| 518 | 584 | |
| 519 | - return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
| 520 | - } |
|
| 585 | + } |
|
| 521 | 586 | |
| 522 | - /** |
|
| 523 | - * Filters post states. |
|
| 524 | - */ |
|
| 525 | - public static function filter_discount_state( $post_states, $post ) { |
|
| 587 | + /** |
|
| 588 | + * Displays items table columns. |
|
| 589 | + */ |
|
| 590 | + public static function display_item_columns( $column_name, $post_id ) { |
|
| 526 | 591 | |
| 527 | - if ( 'wpi_discount' === $post->post_type ) { |
|
| 592 | + $item = new WPInv_Item( $post_id ); |
|
| 528 | 593 | |
| 529 | - $discount = new WPInv_Discount( $post ); |
|
| 594 | + switch ( $column_name ) { |
|
| 530 | 595 | |
| 531 | - $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
| 596 | + case 'price': |
|
| 597 | + if ( ! $item->is_recurring() ) { |
|
| 598 | + echo wp_kses_post( $item->get_the_price() ); |
|
| 599 | + break; |
|
| 600 | + } |
|
| 532 | 601 | |
| 533 | - if ( 'publish' !== $status ) { |
|
| 534 | - return array( |
|
| 535 | - 'discount_status' => wpinv_discount_status( $status ), |
|
| 536 | - ); |
|
| 537 | - } |
|
| 602 | + $price = wp_sprintf( |
|
| 603 | + __( '%1$s / %2$s', 'invoicing' ), |
|
| 604 | + $item->get_the_price(), |
|
| 605 | + getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
| 606 | + ); |
|
| 538 | 607 | |
| 539 | - return array(); |
|
| 608 | + if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
| 609 | + echo wp_kses_post( $price ); |
|
| 610 | + break; |
|
| 611 | + } |
|
| 540 | 612 | |
| 541 | - } |
|
| 613 | + echo wp_kses_post( $item->get_the_initial_price() ); |
|
| 542 | 614 | |
| 543 | - return $post_states; |
|
| 615 | + echo '<span class="meta">' . wp_sprintf( esc_html__( 'then %s', 'invoicing' ), wp_kses_post( $price ) ) . '</span>'; |
|
| 616 | + break; |
|
| 544 | 617 | |
| 545 | - } |
|
| 618 | + case 'vat_rule': |
|
| 619 | + echo wp_kses_post( getpaid_get_tax_rule_label( $item->get_vat_rule() ) ); |
|
| 620 | + break; |
|
| 546 | 621 | |
| 547 | - /** |
|
| 548 | - * Returns an array of items table columns. |
|
| 549 | - */ |
|
| 550 | - public static function item_columns( $columns ) { |
|
| 622 | + case 'vat_class': |
|
| 623 | + echo wp_kses_post( getpaid_get_tax_class_label( $item->get_vat_class() ) ); |
|
| 624 | + break; |
|
| 551 | 625 | |
| 552 | - $columns = array( |
|
| 553 | - 'cb' => $columns['cb'], |
|
| 554 | - 'title' => __( 'Name', 'invoicing' ), |
|
| 555 | - 'price' => __( 'Price', 'invoicing' ), |
|
| 556 | - 'vat_rule' => __( 'Tax Rule', 'invoicing' ), |
|
| 557 | - 'vat_class' => __( 'Tax Class', 'invoicing' ), |
|
| 558 | - 'type' => __( 'Type', 'invoicing' ), |
|
| 559 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
| 560 | - ); |
|
| 626 | + case 'shortcode': |
|
| 627 | + if ( $item->is_type( array( '', 'fee', 'custom' ) ) ) { |
|
| 628 | + echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
| 629 | + } else { |
|
| 630 | + echo '—'; |
|
| 631 | + } |
|
| 561 | 632 | |
| 562 | - if ( ! wpinv_use_taxes() ) { |
|
| 563 | - unset( $columns['vat_rule'] ); |
|
| 564 | - unset( $columns['vat_class'] ); |
|
| 565 | - } |
|
| 633 | + break; |
|
| 566 | 634 | |
| 567 | - return apply_filters( 'wpi_item_table_columns', $columns ); |
|
| 568 | - } |
|
| 635 | + case 'type': |
|
| 636 | + echo wp_kses_post( wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>' ); |
|
| 637 | + break; |
|
| 569 | 638 | |
| 570 | - /** |
|
| 571 | - * Returns an array of sortable items table columns. |
|
| 572 | - */ |
|
| 573 | - public static function sortable_item_columns( $columns ) { |
|
| 574 | - |
|
| 575 | - return array_merge( |
|
| 576 | - $columns, |
|
| 577 | - array( |
|
| 578 | - 'price' => 'price', |
|
| 579 | - 'vat_rule' => 'vat_rule', |
|
| 580 | - 'vat_class' => 'vat_class', |
|
| 581 | - 'type' => 'type', |
|
| 582 | - ) |
|
| 583 | - ); |
|
| 584 | - |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * Displays items table columns. |
|
| 589 | - */ |
|
| 590 | - public static function display_item_columns( $column_name, $post_id ) { |
|
| 591 | - |
|
| 592 | - $item = new WPInv_Item( $post_id ); |
|
| 593 | - |
|
| 594 | - switch ( $column_name ) { |
|
| 595 | - |
|
| 596 | - case 'price': |
|
| 597 | - if ( ! $item->is_recurring() ) { |
|
| 598 | - echo wp_kses_post( $item->get_the_price() ); |
|
| 599 | - break; |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - $price = wp_sprintf( |
|
| 603 | - __( '%1$s / %2$s', 'invoicing' ), |
|
| 604 | - $item->get_the_price(), |
|
| 605 | - getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
| 606 | - ); |
|
| 607 | - |
|
| 608 | - if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
| 609 | - echo wp_kses_post( $price ); |
|
| 610 | - break; |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - echo wp_kses_post( $item->get_the_initial_price() ); |
|
| 614 | - |
|
| 615 | - echo '<span class="meta">' . wp_sprintf( esc_html__( 'then %s', 'invoicing' ), wp_kses_post( $price ) ) . '</span>'; |
|
| 616 | - break; |
|
| 617 | - |
|
| 618 | - case 'vat_rule': |
|
| 619 | - echo wp_kses_post( getpaid_get_tax_rule_label( $item->get_vat_rule() ) ); |
|
| 620 | - break; |
|
| 621 | - |
|
| 622 | - case 'vat_class': |
|
| 623 | - echo wp_kses_post( getpaid_get_tax_class_label( $item->get_vat_class() ) ); |
|
| 624 | - break; |
|
| 625 | - |
|
| 626 | - case 'shortcode': |
|
| 627 | - if ( $item->is_type( array( '', 'fee', 'custom' ) ) ) { |
|
| 628 | - echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
| 629 | - } else { |
|
| 630 | - echo '—'; |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - break; |
|
| 634 | - |
|
| 635 | - case 'type': |
|
| 636 | - echo wp_kses_post( wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>' ); |
|
| 637 | - break; |
|
| 638 | - |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - /** |
|
| 644 | - * Lets users filter items using taxes. |
|
| 645 | - */ |
|
| 646 | - public static function add_item_filters( $post_type ) { |
|
| 647 | - |
|
| 648 | - // Abort if we're not dealing with items. |
|
| 649 | - if ( 'wpi_item' !== $post_type ) { |
|
| 650 | - return; |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - // Filter by vat rules. |
|
| 654 | - if ( wpinv_use_taxes() ) { |
|
| 655 | - |
|
| 656 | - // Sanitize selected vat rule. |
|
| 657 | - $vat_rule = ''; |
|
| 658 | - $vat_rules = getpaid_get_tax_rules(); |
|
| 659 | - if ( isset( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 660 | - $vat_rule = sanitize_text_field( $_GET['vat_rule'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - // Filter by VAT rule. |
|
| 664 | - wpinv_html_select( |
|
| 665 | - array( |
|
| 666 | - 'options' => array_merge( |
|
| 667 | - array( |
|
| 668 | - '' => __( 'All Tax Rules', 'invoicing' ), |
|
| 669 | - ), |
|
| 670 | - $vat_rules |
|
| 671 | - ), |
|
| 672 | - 'name' => 'vat_rule', |
|
| 673 | - 'id' => 'vat_rule', |
|
| 674 | - 'selected' => in_array( $vat_rule, array_keys( $vat_rules ), true ) ? $vat_rule : '', |
|
| 675 | - 'show_option_all' => false, |
|
| 676 | - 'show_option_none' => false, |
|
| 677 | - ) |
|
| 678 | - ); |
|
| 679 | - |
|
| 680 | - // Filter by VAT class. |
|
| 681 | - |
|
| 682 | - // Sanitize selected vat rule. |
|
| 683 | - $vat_class = ''; |
|
| 684 | - $vat_classes = getpaid_get_tax_classes(); |
|
| 685 | - if ( isset( $_GET['vat_class'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 686 | - $vat_class = sanitize_text_field( $_GET['vat_class'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - wpinv_html_select( |
|
| 690 | - array( |
|
| 691 | - 'options' => array_merge( |
|
| 692 | - array( |
|
| 693 | - '' => __( 'All Tax Classes', 'invoicing' ), |
|
| 694 | - ), |
|
| 695 | - $vat_classes |
|
| 696 | - ), |
|
| 697 | - 'name' => 'vat_class', |
|
| 698 | - 'id' => 'vat_class', |
|
| 699 | - 'selected' => in_array( $vat_class, array_keys( $vat_classes ), true ) ? $vat_class : '', |
|
| 700 | - 'show_option_all' => false, |
|
| 701 | - 'show_option_none' => false, |
|
| 702 | - ) |
|
| 703 | - ); |
|
| 704 | - |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - // Filter by item type. |
|
| 708 | - $type = ''; |
|
| 709 | - if ( isset( $_GET['type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 710 | - $type = sanitize_text_field( $_GET['type'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - wpinv_html_select( |
|
| 714 | - array( |
|
| 715 | - 'options' => array_merge( |
|
| 716 | - array( |
|
| 717 | - '' => __( 'All item types', 'invoicing' ), |
|
| 718 | - ), |
|
| 719 | - wpinv_get_item_types() |
|
| 720 | - ), |
|
| 721 | - 'name' => 'type', |
|
| 722 | - 'id' => 'type', |
|
| 723 | - 'selected' => in_array( $type, wpinv_item_types(), true ) ? $type : '', |
|
| 724 | - 'show_option_all' => false, |
|
| 725 | - 'show_option_none' => false, |
|
| 726 | - ) |
|
| 727 | - ); |
|
| 728 | - |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - /** |
|
| 732 | - * Filters the item query. |
|
| 733 | - */ |
|
| 734 | - public static function filter_item_query( $query ) { |
|
| 735 | - |
|
| 736 | - // modify the query only if it admin and main query. |
|
| 737 | - if ( ! ( is_admin() && $query->is_main_query() ) ) { |
|
| 738 | - return $query; |
|
| 739 | - } |
|
| 740 | - |
|
| 741 | - // we want to modify the query for our items. |
|
| 742 | - if ( empty( $query->query['post_type'] ) || 'wpi_item' !== $query->query['post_type'] ) { |
|
| 743 | - return $query; |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - if ( empty( $query->query_vars['meta_query'] ) ) { |
|
| 747 | - $query->query_vars['meta_query'] = array(); |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - // Filter vat rule type |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + /** |
|
| 644 | + * Lets users filter items using taxes. |
|
| 645 | + */ |
|
| 646 | + public static function add_item_filters( $post_type ) { |
|
| 647 | + |
|
| 648 | + // Abort if we're not dealing with items. |
|
| 649 | + if ( 'wpi_item' !== $post_type ) { |
|
| 650 | + return; |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + // Filter by vat rules. |
|
| 654 | + if ( wpinv_use_taxes() ) { |
|
| 655 | + |
|
| 656 | + // Sanitize selected vat rule. |
|
| 657 | + $vat_rule = ''; |
|
| 658 | + $vat_rules = getpaid_get_tax_rules(); |
|
| 659 | + if ( isset( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 660 | + $vat_rule = sanitize_text_field( $_GET['vat_rule'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + // Filter by VAT rule. |
|
| 664 | + wpinv_html_select( |
|
| 665 | + array( |
|
| 666 | + 'options' => array_merge( |
|
| 667 | + array( |
|
| 668 | + '' => __( 'All Tax Rules', 'invoicing' ), |
|
| 669 | + ), |
|
| 670 | + $vat_rules |
|
| 671 | + ), |
|
| 672 | + 'name' => 'vat_rule', |
|
| 673 | + 'id' => 'vat_rule', |
|
| 674 | + 'selected' => in_array( $vat_rule, array_keys( $vat_rules ), true ) ? $vat_rule : '', |
|
| 675 | + 'show_option_all' => false, |
|
| 676 | + 'show_option_none' => false, |
|
| 677 | + ) |
|
| 678 | + ); |
|
| 679 | + |
|
| 680 | + // Filter by VAT class. |
|
| 681 | + |
|
| 682 | + // Sanitize selected vat rule. |
|
| 683 | + $vat_class = ''; |
|
| 684 | + $vat_classes = getpaid_get_tax_classes(); |
|
| 685 | + if ( isset( $_GET['vat_class'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 686 | + $vat_class = sanitize_text_field( $_GET['vat_class'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + wpinv_html_select( |
|
| 690 | + array( |
|
| 691 | + 'options' => array_merge( |
|
| 692 | + array( |
|
| 693 | + '' => __( 'All Tax Classes', 'invoicing' ), |
|
| 694 | + ), |
|
| 695 | + $vat_classes |
|
| 696 | + ), |
|
| 697 | + 'name' => 'vat_class', |
|
| 698 | + 'id' => 'vat_class', |
|
| 699 | + 'selected' => in_array( $vat_class, array_keys( $vat_classes ), true ) ? $vat_class : '', |
|
| 700 | + 'show_option_all' => false, |
|
| 701 | + 'show_option_none' => false, |
|
| 702 | + ) |
|
| 703 | + ); |
|
| 704 | + |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + // Filter by item type. |
|
| 708 | + $type = ''; |
|
| 709 | + if ( isset( $_GET['type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 710 | + $type = sanitize_text_field( $_GET['type'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + wpinv_html_select( |
|
| 714 | + array( |
|
| 715 | + 'options' => array_merge( |
|
| 716 | + array( |
|
| 717 | + '' => __( 'All item types', 'invoicing' ), |
|
| 718 | + ), |
|
| 719 | + wpinv_get_item_types() |
|
| 720 | + ), |
|
| 721 | + 'name' => 'type', |
|
| 722 | + 'id' => 'type', |
|
| 723 | + 'selected' => in_array( $type, wpinv_item_types(), true ) ? $type : '', |
|
| 724 | + 'show_option_all' => false, |
|
| 725 | + 'show_option_none' => false, |
|
| 726 | + ) |
|
| 727 | + ); |
|
| 728 | + |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + /** |
|
| 732 | + * Filters the item query. |
|
| 733 | + */ |
|
| 734 | + public static function filter_item_query( $query ) { |
|
| 735 | + |
|
| 736 | + // modify the query only if it admin and main query. |
|
| 737 | + if ( ! ( is_admin() && $query->is_main_query() ) ) { |
|
| 738 | + return $query; |
|
| 739 | + } |
|
| 740 | + |
|
| 741 | + // we want to modify the query for our items. |
|
| 742 | + if ( empty( $query->query['post_type'] ) || 'wpi_item' !== $query->query['post_type'] ) { |
|
| 743 | + return $query; |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + if ( empty( $query->query_vars['meta_query'] ) ) { |
|
| 747 | + $query->query_vars['meta_query'] = array(); |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + // Filter vat rule type |
|
| 751 | 751 | if ( ! empty( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 752 | 752 | $query->query_vars['meta_query'][] = array( |
| 753 | 753 | 'key' => '_wpinv_vat_rule', |
@@ -772,97 +772,97 @@ discard block |
||
| 772 | 772 | 'value' => sanitize_text_field( $_GET['type'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended |
| 773 | 773 | 'compare' => '=', |
| 774 | 774 | ); |
| 775 | - } |
|
| 776 | - |
|
| 777 | - } |
|
| 778 | - |
|
| 779 | - /** |
|
| 780 | - * Reorders items. |
|
| 781 | - */ |
|
| 782 | - public static function reorder_items( $vars ) { |
|
| 783 | - global $typenow; |
|
| 784 | - |
|
| 785 | - if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
| 786 | - return $vars; |
|
| 787 | - } |
|
| 788 | - |
|
| 789 | - // By item type. |
|
| 790 | - if ( 'type' === $vars['orderby'] ) { |
|
| 791 | - return array_merge( |
|
| 792 | - $vars, |
|
| 793 | - array( |
|
| 794 | - 'meta_key' => '_wpinv_type', |
|
| 795 | - 'orderby' => 'meta_value', |
|
| 796 | - ) |
|
| 797 | - ); |
|
| 798 | - } |
|
| 799 | - |
|
| 800 | - // By vat class. |
|
| 801 | - if ( 'vat_class' === $vars['orderby'] ) { |
|
| 802 | - return array_merge( |
|
| 803 | - $vars, |
|
| 804 | - array( |
|
| 805 | - 'meta_key' => '_wpinv_vat_class', |
|
| 806 | - 'orderby' => 'meta_value', |
|
| 807 | - ) |
|
| 808 | - ); |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - // By vat rule. |
|
| 812 | - if ( 'vat_rule' === $vars['orderby'] ) { |
|
| 813 | - return array_merge( |
|
| 814 | - $vars, |
|
| 815 | - array( |
|
| 816 | - 'meta_key' => '_wpinv_vat_rule', |
|
| 817 | - 'orderby' => 'meta_value', |
|
| 818 | - ) |
|
| 819 | - ); |
|
| 820 | - } |
|
| 821 | - |
|
| 822 | - // By price. |
|
| 823 | - if ( 'price' === $vars['orderby'] ) { |
|
| 824 | - return array_merge( |
|
| 825 | - $vars, |
|
| 826 | - array( |
|
| 827 | - 'meta_key' => '_wpinv_price', |
|
| 828 | - 'orderby' => 'meta_value_num', |
|
| 829 | - ) |
|
| 830 | - ); |
|
| 831 | - } |
|
| 832 | - |
|
| 833 | - return $vars; |
|
| 834 | - |
|
| 835 | - } |
|
| 836 | - |
|
| 837 | - /** |
|
| 838 | - * Fired when deleting a post. |
|
| 839 | - */ |
|
| 840 | - public static function delete_post( $post_id ) { |
|
| 841 | - |
|
| 842 | - switch ( get_post_type( $post_id ) ) { |
|
| 843 | - |
|
| 844 | - case 'wpi_item': |
|
| 845 | - do_action( 'getpaid_before_delete_item', new WPInv_Item( $post_id ) ); |
|
| 846 | - break; |
|
| 847 | - |
|
| 848 | - case 'wpi_payment_form': |
|
| 849 | - do_action( 'getpaid_before_delete_payment_form', new GetPaid_Payment_Form( $post_id ) ); |
|
| 850 | - break; |
|
| 851 | - |
|
| 852 | - case 'wpi_discount': |
|
| 853 | - do_action( 'getpaid_before_delete_discount', new WPInv_Discount( $post_id ) ); |
|
| 854 | - break; |
|
| 855 | - |
|
| 856 | - case 'wpi_invoice': |
|
| 857 | - $invoice = new WPInv_Invoice( $post_id ); |
|
| 858 | - do_action( 'getpaid_before_delete_invoice', $invoice ); |
|
| 859 | - $invoice->get_data_store()->delete_items( $invoice ); |
|
| 860 | - $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
| 861 | - break; |
|
| 862 | - } |
|
| 863 | - } |
|
| 864 | - |
|
| 865 | - /** |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + } |
|
| 778 | + |
|
| 779 | + /** |
|
| 780 | + * Reorders items. |
|
| 781 | + */ |
|
| 782 | + public static function reorder_items( $vars ) { |
|
| 783 | + global $typenow; |
|
| 784 | + |
|
| 785 | + if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
| 786 | + return $vars; |
|
| 787 | + } |
|
| 788 | + |
|
| 789 | + // By item type. |
|
| 790 | + if ( 'type' === $vars['orderby'] ) { |
|
| 791 | + return array_merge( |
|
| 792 | + $vars, |
|
| 793 | + array( |
|
| 794 | + 'meta_key' => '_wpinv_type', |
|
| 795 | + 'orderby' => 'meta_value', |
|
| 796 | + ) |
|
| 797 | + ); |
|
| 798 | + } |
|
| 799 | + |
|
| 800 | + // By vat class. |
|
| 801 | + if ( 'vat_class' === $vars['orderby'] ) { |
|
| 802 | + return array_merge( |
|
| 803 | + $vars, |
|
| 804 | + array( |
|
| 805 | + 'meta_key' => '_wpinv_vat_class', |
|
| 806 | + 'orderby' => 'meta_value', |
|
| 807 | + ) |
|
| 808 | + ); |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + // By vat rule. |
|
| 812 | + if ( 'vat_rule' === $vars['orderby'] ) { |
|
| 813 | + return array_merge( |
|
| 814 | + $vars, |
|
| 815 | + array( |
|
| 816 | + 'meta_key' => '_wpinv_vat_rule', |
|
| 817 | + 'orderby' => 'meta_value', |
|
| 818 | + ) |
|
| 819 | + ); |
|
| 820 | + } |
|
| 821 | + |
|
| 822 | + // By price. |
|
| 823 | + if ( 'price' === $vars['orderby'] ) { |
|
| 824 | + return array_merge( |
|
| 825 | + $vars, |
|
| 826 | + array( |
|
| 827 | + 'meta_key' => '_wpinv_price', |
|
| 828 | + 'orderby' => 'meta_value_num', |
|
| 829 | + ) |
|
| 830 | + ); |
|
| 831 | + } |
|
| 832 | + |
|
| 833 | + return $vars; |
|
| 834 | + |
|
| 835 | + } |
|
| 836 | + |
|
| 837 | + /** |
|
| 838 | + * Fired when deleting a post. |
|
| 839 | + */ |
|
| 840 | + public static function delete_post( $post_id ) { |
|
| 841 | + |
|
| 842 | + switch ( get_post_type( $post_id ) ) { |
|
| 843 | + |
|
| 844 | + case 'wpi_item': |
|
| 845 | + do_action( 'getpaid_before_delete_item', new WPInv_Item( $post_id ) ); |
|
| 846 | + break; |
|
| 847 | + |
|
| 848 | + case 'wpi_payment_form': |
|
| 849 | + do_action( 'getpaid_before_delete_payment_form', new GetPaid_Payment_Form( $post_id ) ); |
|
| 850 | + break; |
|
| 851 | + |
|
| 852 | + case 'wpi_discount': |
|
| 853 | + do_action( 'getpaid_before_delete_discount', new WPInv_Discount( $post_id ) ); |
|
| 854 | + break; |
|
| 855 | + |
|
| 856 | + case 'wpi_invoice': |
|
| 857 | + $invoice = new WPInv_Invoice( $post_id ); |
|
| 858 | + do_action( 'getpaid_before_delete_invoice', $invoice ); |
|
| 859 | + $invoice->get_data_store()->delete_items( $invoice ); |
|
| 860 | + $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
| 861 | + break; |
|
| 862 | + } |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + /** |
|
| 866 | 866 | * Add a post display state for special GetPaid pages in the page list table. |
| 867 | 867 | * |
| 868 | 868 | * @param array $post_states An array of post display states. |
@@ -876,21 +876,21 @@ discard block |
||
| 876 | 876 | $post_states['getpaid_success_page'] = __( 'GetPaid Receipt Page', 'invoicing' ); |
| 877 | 877 | } |
| 878 | 878 | |
| 879 | - foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) { |
|
| 879 | + foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) { |
|
| 880 | 880 | |
| 881 | - if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) { |
|
| 882 | - $post_states[ "getpaid_{$post_type}_history_page" ] = sprintf( |
|
| 883 | - __( 'GetPaid %s History Page', 'invoicing' ), |
|
| 884 | - $label |
|
| 885 | - ); |
|
| 886 | - } |
|
| 881 | + if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) { |
|
| 882 | + $post_states[ "getpaid_{$post_type}_history_page" ] = sprintf( |
|
| 883 | + __( 'GetPaid %s History Page', 'invoicing' ), |
|
| 884 | + $label |
|
| 885 | + ); |
|
| 886 | + } |
|
| 887 | 887 | } |
| 888 | 888 | |
| 889 | - if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) { |
|
| 889 | + if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) { |
|
| 890 | 890 | $post_states['getpaid_invoice_subscription_page'] = __( 'GetPaid Subscription Page', 'invoicing' ); |
| 891 | 891 | } |
| 892 | 892 | |
| 893 | - if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) { |
|
| 893 | + if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) { |
|
| 894 | 894 | $post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' ); |
| 895 | 895 | } |
| 896 | 896 | |