@@ -12,51 +12,51 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Items { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Submission items. |
|
| 17 | - * @var GetPaid_Form_Item[] |
|
| 18 | - */ |
|
| 19 | - public $items = array(); |
|
| 15 | + /** |
|
| 16 | + * Submission items. |
|
| 17 | + * @var GetPaid_Form_Item[] |
|
| 18 | + */ |
|
| 19 | + public $items = array(); |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | - * Class constructor |
|
| 23 | - * |
|
| 24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | - */ |
|
| 26 | - public function __construct( $submission ) { |
|
| 27 | - |
|
| 28 | - $data = $submission->get_data(); |
|
| 29 | - $payment_form = $submission->get_payment_form(); |
|
| 30 | - $invoice = $submission->get_invoice(); |
|
| 31 | - $force_prices = array(); |
|
| 32 | - |
|
| 33 | - // Prepare the selected items. |
|
| 34 | - $selected_items = array(); |
|
| 35 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
| 36 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
| 37 | - |
|
| 38 | - if ( ! empty( $invoice ) && $submission->is_initial_fetch() ) { |
|
| 39 | - foreach ( $invoice->get_items() as $invoice_item ) { |
|
| 40 | - if ( isset( $selected_items[ $invoice_item->get_id() ] ) ) { |
|
| 41 | - $selected_items[ $invoice_item->get_id() ]['quantity'] = $invoice_item->get_quantity(); |
|
| 42 | - $selected_items[ $invoice_item->get_id() ]['price'] = $invoice_item->get_price(); |
|
| 43 | - |
|
| 44 | - $force_prices[ $invoice_item->get_id() ] = $invoice_item->get_price(); |
|
| 45 | - } |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - // (Maybe) set form items. |
|
| 51 | - if ( isset( $data['getpaid-form-items'] ) ) { |
|
| 52 | - |
|
| 53 | - // Confirm items key. |
|
| 54 | - $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
| 55 | - if ( ! isset( $data['getpaid-form-items-key'] ) || md5( NONCE_KEY . AUTH_KEY . $form_items ) !== $data['getpaid-form-items-key'] ) { |
|
| 56 | - throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) ); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - $items = array(); |
|
| 22 | + * Class constructor |
|
| 23 | + * |
|
| 24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | + */ |
|
| 26 | + public function __construct( $submission ) { |
|
| 27 | + |
|
| 28 | + $data = $submission->get_data(); |
|
| 29 | + $payment_form = $submission->get_payment_form(); |
|
| 30 | + $invoice = $submission->get_invoice(); |
|
| 31 | + $force_prices = array(); |
|
| 32 | + |
|
| 33 | + // Prepare the selected items. |
|
| 34 | + $selected_items = array(); |
|
| 35 | + if ( ! empty( $data['getpaid-items'] ) ) { |
|
| 36 | + $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
| 37 | + |
|
| 38 | + if ( ! empty( $invoice ) && $submission->is_initial_fetch() ) { |
|
| 39 | + foreach ( $invoice->get_items() as $invoice_item ) { |
|
| 40 | + if ( isset( $selected_items[ $invoice_item->get_id() ] ) ) { |
|
| 41 | + $selected_items[ $invoice_item->get_id() ]['quantity'] = $invoice_item->get_quantity(); |
|
| 42 | + $selected_items[ $invoice_item->get_id() ]['price'] = $invoice_item->get_price(); |
|
| 43 | + |
|
| 44 | + $force_prices[ $invoice_item->get_id() ] = $invoice_item->get_price(); |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + // (Maybe) set form items. |
|
| 51 | + if ( isset( $data['getpaid-form-items'] ) ) { |
|
| 52 | + |
|
| 53 | + // Confirm items key. |
|
| 54 | + $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
| 55 | + if ( ! isset( $data['getpaid-form-items-key'] ) || md5( NONCE_KEY . AUTH_KEY . $form_items ) !== $data['getpaid-form-items-key'] ) { |
|
| 56 | + throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) ); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + $items = array(); |
|
| 60 | 60 | $item_ids = array(); |
| 61 | 61 | |
| 62 | 62 | foreach ( getpaid_convert_items_to_array( $form_items ) as $item_id => $qty ) { |
@@ -69,10 +69,10 @@ discard block |
||
| 69 | 69 | $item->set_is_required( false ); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - if ( ! $item->user_can_set_their_price() && isset( $force_prices[ $item_id ] ) ) { |
|
| 73 | - $item->set_is_dynamic_pricing( true ); |
|
| 74 | - $item->set_minimum_price( 0 ); |
|
| 75 | - } |
|
| 72 | + if ( ! $item->user_can_set_their_price() && isset( $force_prices[ $item_id ] ) ) { |
|
| 73 | + $item->set_is_dynamic_pricing( true ); |
|
| 74 | + $item->set_minimum_price( 0 ); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | 77 | $item_ids[] = $item->get_id(); |
| 78 | 78 | $items[] = $item; |
@@ -87,61 +87,61 @@ discard block |
||
| 87 | 87 | $items[] = $item; |
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | - } |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | 92 | $payment_form->set_items( $items ); |
| 93 | 93 | |
| 94 | - } |
|
| 95 | - |
|
| 96 | - // Process each individual item. |
|
| 97 | - foreach ( $payment_form->get_items() as $item ) { |
|
| 98 | - $this->process_item( $item, $selected_items, $submission ); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Process a single item. |
|
| 105 | - * |
|
| 106 | - * @param GetPaid_Form_Item $item |
|
| 107 | - * @param array $selected_items |
|
| 108 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 109 | - */ |
|
| 110 | - public function process_item( $item, $selected_items, $submission ) { |
|
| 94 | + } |
|
| 111 | 95 | |
| 112 | - // Abort if this is an optional item and it has not been selected. |
|
| 113 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 114 | - return; |
|
| 115 | - } |
|
| 96 | + // Process each individual item. |
|
| 97 | + foreach ( $payment_form->get_items() as $item ) { |
|
| 98 | + $this->process_item( $item, $selected_items, $submission ); |
|
| 99 | + } |
|
| 116 | 100 | |
| 117 | - // (maybe) let customers change the quantities and prices. |
|
| 118 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 101 | + } |
|
| 119 | 102 | |
| 120 | - // Maybe change the quantities. |
|
| 121 | - if ( $item->allows_quantities() ) { |
|
| 122 | - $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
| 123 | - } |
|
| 103 | + /** |
|
| 104 | + * Process a single item. |
|
| 105 | + * |
|
| 106 | + * @param GetPaid_Form_Item $item |
|
| 107 | + * @param array $selected_items |
|
| 108 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 109 | + */ |
|
| 110 | + public function process_item( $item, $selected_items, $submission ) { |
|
| 111 | + |
|
| 112 | + // Abort if this is an optional item and it has not been selected. |
|
| 113 | + if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 114 | + return; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + // (maybe) let customers change the quantities and prices. |
|
| 118 | + if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
| 119 | + |
|
| 120 | + // Maybe change the quantities. |
|
| 121 | + if ( $item->allows_quantities() ) { |
|
| 122 | + $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - // Maybe change the price. |
|
| 126 | - if ( $item->user_can_set_their_price() ) { |
|
| 127 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
| 125 | + // Maybe change the price. |
|
| 126 | + if ( $item->user_can_set_their_price() ) { |
|
| 127 | + $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
| 128 | 128 | |
| 129 | - if ( $item->get_minimum_price() > $price ) { |
|
| 130 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) ); |
|
| 131 | - } |
|
| 129 | + if ( $item->get_minimum_price() > $price ) { |
|
| 130 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) ); |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - $item->set_price( $price ); |
|
| 133 | + $item->set_price( $price ); |
|
| 134 | 134 | |
| 135 | - } |
|
| 136 | - } |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | - if ( 0 == $item->get_quantity() ) { |
|
| 139 | - return; |
|
| 140 | - } |
|
| 138 | + if ( 0 == $item->get_quantity() ) { |
|
| 139 | + return; |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - // Save the item. |
|
| 143 | - $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission ); |
|
| 142 | + // Save the item. |
|
| 143 | + $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission ); |
|
| 144 | 144 | |
| 145 | - } |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | 147 | } |
@@ -12,305 +12,305 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Payment_Form_Submission_Refresh_Prices { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Contains the response for refreshing prices. |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - public $response = array(); |
|
| 15 | + /** |
|
| 16 | + * Contains the response for refreshing prices. |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + public $response = array(); |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | - * Class constructor |
|
| 23 | - * |
|
| 24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | - */ |
|
| 26 | - public function __construct( $submission ) { |
|
| 27 | - |
|
| 28 | - $this->response = array( |
|
| 29 | - 'submission_id' => $submission->id, |
|
| 22 | + * Class constructor |
|
| 23 | + * |
|
| 24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 25 | + */ |
|
| 26 | + public function __construct( $submission ) { |
|
| 27 | + |
|
| 28 | + $this->response = array( |
|
| 29 | + 'submission_id' => $submission->id, |
|
| 30 | 30 | 'has_recurring' => $submission->has_recurring, |
| 31 | - 'has_subscription_group' => $submission->has_subscription_group(), |
|
| 32 | - 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
|
| 31 | + 'has_subscription_group' => $submission->has_subscription_group(), |
|
| 32 | + 'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(), |
|
| 33 | 33 | 'is_free' => ! $submission->should_collect_payment_details(), |
| 34 | - ); |
|
| 35 | - |
|
| 36 | - $payment_form = $submission->get_payment_form(); |
|
| 37 | - if ( ! empty( $payment_form->invoice ) ) { |
|
| 38 | - $this->response['invoice'] = $payment_form->invoice->get_id(); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - $this->add_totals( $submission ); |
|
| 42 | - $this->add_texts( $submission ); |
|
| 43 | - $this->add_items( $submission ); |
|
| 44 | - $this->add_fees( $submission ); |
|
| 45 | - $this->add_discounts( $submission ); |
|
| 46 | - $this->add_taxes( $submission ); |
|
| 47 | - $this->add_gateways( $submission ); |
|
| 48 | - $this->add_data( $submission ); |
|
| 49 | - |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Adds totals to a response for submission refresh prices. |
|
| 54 | - * |
|
| 55 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 56 | - */ |
|
| 57 | - public function add_totals( $submission ) { |
|
| 58 | - |
|
| 59 | - $this->response = array_merge( |
|
| 60 | - $this->response, |
|
| 61 | - array( |
|
| 62 | - |
|
| 63 | - 'totals' => array( |
|
| 64 | - 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
| 65 | - 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
| 66 | - 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
| 67 | - 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
| 68 | - 'total' => $submission->format_amount( $submission->get_total() ), |
|
| 69 | - 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
| 70 | - ), |
|
| 71 | - |
|
| 72 | - 'recurring' => array( |
|
| 73 | - 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
| 74 | - 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
| 75 | - 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
| 76 | - 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
| 77 | - 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
| 78 | - ), |
|
| 79 | - |
|
| 80 | - 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
| 81 | - 'currency' => $submission->get_currency(), |
|
| 82 | - |
|
| 83 | - ) |
|
| 84 | - ); |
|
| 85 | - |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Adds texts to a response for submission refresh prices. |
|
| 90 | - * |
|
| 91 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 92 | - */ |
|
| 93 | - public function add_texts( $submission ) { |
|
| 94 | - |
|
| 95 | - $payable = $submission->format_amount( $submission->get_total() ); |
|
| 96 | - $groups = getpaid_get_subscription_groups( $submission ); |
|
| 97 | - |
|
| 98 | - if ( $submission->has_recurring && 2 > count( $groups ) ) { |
|
| 99 | - |
|
| 100 | - $recurring = new WPInv_Item( $submission->has_recurring ); |
|
| 101 | - $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
| 102 | - $main_item = reset( $groups ); |
|
| 103 | - |
|
| 104 | - if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
| 105 | - $payable = "$payable / $period"; |
|
| 106 | - } elseif ( $main_item ) { |
|
| 107 | - |
|
| 108 | - $main_item = reset( $main_item ); |
|
| 109 | - |
|
| 110 | - // Calculate the next renewal date. |
|
| 111 | - $_period = $main_item->get_recurring_period( true ); |
|
| 112 | - $_interval = $main_item->get_recurring_interval(); |
|
| 113 | - |
|
| 114 | - // If the subscription item has a trial period... |
|
| 115 | - if ( $main_item->has_free_trial() ) { |
|
| 116 | - $_period = $main_item->get_trial_period( true ); |
|
| 117 | - $_interval = $main_item->get_trial_interval(); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - $payable = sprintf( |
|
| 121 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 122 | - $submission->format_amount( $submission->get_total() ), |
|
| 123 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
| 124 | - $period |
|
| 125 | - ); |
|
| 126 | - |
|
| 127 | - $payable .= sprintf( |
|
| 128 | - '<small class="text-muted form-text">%s</small>', |
|
| 129 | - sprintf( |
|
| 130 | - __( 'First renewal on %s', 'invoicing' ), |
|
| 131 | - getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) ) |
|
| 132 | - ) |
|
| 133 | - ); |
|
| 134 | - |
|
| 135 | - } else { |
|
| 136 | - $payable = sprintf( |
|
| 137 | - __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 138 | - $submission->format_amount( $submission->get_total() ), |
|
| 139 | - $submission->format_amount( $submission->get_recurring_total() ), |
|
| 140 | - $period |
|
| 141 | - ); |
|
| 142 | - } |
|
| 143 | -} |
|
| 34 | + ); |
|
| 35 | + |
|
| 36 | + $payment_form = $submission->get_payment_form(); |
|
| 37 | + if ( ! empty( $payment_form->invoice ) ) { |
|
| 38 | + $this->response['invoice'] = $payment_form->invoice->get_id(); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + $this->add_totals( $submission ); |
|
| 42 | + $this->add_texts( $submission ); |
|
| 43 | + $this->add_items( $submission ); |
|
| 44 | + $this->add_fees( $submission ); |
|
| 45 | + $this->add_discounts( $submission ); |
|
| 46 | + $this->add_taxes( $submission ); |
|
| 47 | + $this->add_gateways( $submission ); |
|
| 48 | + $this->add_data( $submission ); |
|
| 144 | 49 | |
| 145 | - $texts = array( |
|
| 146 | - '.getpaid-checkout-total-payable' => $payable, |
|
| 147 | - ); |
|
| 50 | + } |
|
| 148 | 51 | |
| 149 | - foreach ( $submission->get_items() as $item ) { |
|
| 150 | - $item_id = $item->get_id(); |
|
| 151 | - $initial_price = $submission->format_amount( $item->get_sub_total() - $item->item_discount ); |
|
| 152 | - $recurring_price = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount ); |
|
| 153 | - $texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
| 154 | - $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) ); |
|
| 52 | + /** |
|
| 53 | + * Adds totals to a response for submission refresh prices. |
|
| 54 | + * |
|
| 55 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 56 | + */ |
|
| 57 | + public function add_totals( $submission ) { |
|
| 58 | + |
|
| 59 | + $this->response = array_merge( |
|
| 60 | + $this->response, |
|
| 61 | + array( |
|
| 62 | + |
|
| 63 | + 'totals' => array( |
|
| 64 | + 'subtotal' => $submission->format_amount( $submission->get_subtotal() ), |
|
| 65 | + 'discount' => $submission->format_amount( $submission->get_discount() ), |
|
| 66 | + 'fees' => $submission->format_amount( $submission->get_fee() ), |
|
| 67 | + 'tax' => $submission->format_amount( $submission->get_tax() ), |
|
| 68 | + 'total' => $submission->format_amount( $submission->get_total() ), |
|
| 69 | + 'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ), |
|
| 70 | + ), |
|
| 71 | + |
|
| 72 | + 'recurring' => array( |
|
| 73 | + 'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ), |
|
| 74 | + 'discount' => $submission->format_amount( $submission->get_recurring_discount() ), |
|
| 75 | + 'fees' => $submission->format_amount( $submission->get_recurring_fee() ), |
|
| 76 | + 'tax' => $submission->format_amount( $submission->get_recurring_tax() ), |
|
| 77 | + 'total' => $submission->format_amount( $submission->get_recurring_total() ), |
|
| 78 | + ), |
|
| 79 | + |
|
| 80 | + 'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ), |
|
| 81 | + 'currency' => $submission->get_currency(), |
|
| 82 | + |
|
| 83 | + ) |
|
| 84 | + ); |
|
| 85 | + |
|
| 86 | + } |
|
| 155 | 87 | |
| 156 | - if ( $item->get_quantity() == 1 ) { |
|
| 157 | - $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = ''; |
|
| 158 | - } |
|
| 88 | + /** |
|
| 89 | + * Adds texts to a response for submission refresh prices. |
|
| 90 | + * |
|
| 91 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 92 | + */ |
|
| 93 | + public function add_texts( $submission ) { |
|
| 94 | + |
|
| 95 | + $payable = $submission->format_amount( $submission->get_total() ); |
|
| 96 | + $groups = getpaid_get_subscription_groups( $submission ); |
|
| 97 | + |
|
| 98 | + if ( $submission->has_recurring && 2 > count( $groups ) ) { |
|
| 99 | + |
|
| 100 | + $recurring = new WPInv_Item( $submission->has_recurring ); |
|
| 101 | + $period = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' ); |
|
| 102 | + $main_item = reset( $groups ); |
|
| 103 | + |
|
| 104 | + if ( $submission->get_total() == $submission->get_recurring_total() ) { |
|
| 105 | + $payable = "$payable / $period"; |
|
| 106 | + } elseif ( $main_item ) { |
|
| 107 | + |
|
| 108 | + $main_item = reset( $main_item ); |
|
| 109 | + |
|
| 110 | + // Calculate the next renewal date. |
|
| 111 | + $_period = $main_item->get_recurring_period( true ); |
|
| 112 | + $_interval = $main_item->get_recurring_interval(); |
|
| 113 | + |
|
| 114 | + // If the subscription item has a trial period... |
|
| 115 | + if ( $main_item->has_free_trial() ) { |
|
| 116 | + $_period = $main_item->get_trial_period( true ); |
|
| 117 | + $_interval = $main_item->get_trial_interval(); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + $payable = sprintf( |
|
| 121 | + __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 122 | + $submission->format_amount( $submission->get_total() ), |
|
| 123 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
| 124 | + $period |
|
| 125 | + ); |
|
| 126 | + |
|
| 127 | + $payable .= sprintf( |
|
| 128 | + '<small class="text-muted form-text">%s</small>', |
|
| 129 | + sprintf( |
|
| 130 | + __( 'First renewal on %s', 'invoicing' ), |
|
| 131 | + getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) ) |
|
| 132 | + ) |
|
| 133 | + ); |
|
| 134 | + |
|
| 135 | + } else { |
|
| 136 | + $payable = sprintf( |
|
| 137 | + __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ), |
|
| 138 | + $submission->format_amount( $submission->get_total() ), |
|
| 139 | + $submission->format_amount( $submission->get_recurring_total() ), |
|
| 140 | + $period |
|
| 141 | + ); |
|
| 142 | + } |
|
| 159 | 143 | } |
| 160 | 144 | |
| 161 | - $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
| 145 | + $texts = array( |
|
| 146 | + '.getpaid-checkout-total-payable' => $payable, |
|
| 147 | + ); |
|
| 162 | 148 | |
| 163 | - } |
|
| 149 | + foreach ( $submission->get_items() as $item ) { |
|
| 150 | + $item_id = $item->get_id(); |
|
| 151 | + $initial_price = $submission->format_amount( $item->get_sub_total() - $item->item_discount ); |
|
| 152 | + $recurring_price = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount ); |
|
| 153 | + $texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price ); |
|
| 154 | + $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) ); |
|
| 155 | + |
|
| 156 | + if ( $item->get_quantity() == 1 ) { |
|
| 157 | + $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = ''; |
|
| 158 | + } |
|
| 159 | +} |
|
| 164 | 160 | |
| 165 | - /** |
|
| 166 | - * Adds items to a response for submission refresh prices. |
|
| 167 | - * |
|
| 168 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 169 | - */ |
|
| 170 | - public function add_items( $submission ) { |
|
| 161 | + $this->response = array_merge( $this->response, array( 'texts' => $texts ) ); |
|
| 171 | 162 | |
| 172 | - // Add items. |
|
| 173 | - $items = array(); |
|
| 174 | - $selected_items = array(); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Adds items to a response for submission refresh prices. |
|
| 167 | + * |
|
| 168 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 169 | + */ |
|
| 170 | + public function add_items( $submission ) { |
|
| 171 | + |
|
| 172 | + // Add items. |
|
| 173 | + $items = array(); |
|
| 174 | + $selected_items = array(); |
|
| 175 | 175 | |
| 176 | 176 | foreach ( $submission->get_items() as $item ) { |
| 177 | - $item_id = $item->get_id(); |
|
| 178 | - $items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() ); |
|
| 179 | - |
|
| 180 | - $selected_items[ "$item_id" ] = array( |
|
| 181 | - 'quantity' => $item->get_quantity(), |
|
| 182 | - 'price' => $item->get_price(), |
|
| 183 | - 'price_fmt' => $submission->format_amount( $item->get_price() ), |
|
| 184 | - ); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - $this->response = array_merge( |
|
| 188 | - $this->response, |
|
| 189 | - array( |
|
| 190 | - 'items' => $items, |
|
| 191 | - 'selected_items' => $selected_items, |
|
| 192 | - ) |
|
| 193 | - ); |
|
| 194 | - |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Adds fees to a response for submission refresh prices. |
|
| 199 | - * |
|
| 200 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 201 | - */ |
|
| 202 | - public function add_fees( $submission ) { |
|
| 203 | - |
|
| 204 | - $fees = array(); |
|
| 177 | + $item_id = $item->get_id(); |
|
| 178 | + $items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() ); |
|
| 179 | + |
|
| 180 | + $selected_items[ "$item_id" ] = array( |
|
| 181 | + 'quantity' => $item->get_quantity(), |
|
| 182 | + 'price' => $item->get_price(), |
|
| 183 | + 'price_fmt' => $submission->format_amount( $item->get_price() ), |
|
| 184 | + ); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + $this->response = array_merge( |
|
| 188 | + $this->response, |
|
| 189 | + array( |
|
| 190 | + 'items' => $items, |
|
| 191 | + 'selected_items' => $selected_items, |
|
| 192 | + ) |
|
| 193 | + ); |
|
| 194 | + |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Adds fees to a response for submission refresh prices. |
|
| 199 | + * |
|
| 200 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 201 | + */ |
|
| 202 | + public function add_fees( $submission ) { |
|
| 203 | + |
|
| 204 | + $fees = array(); |
|
| 205 | 205 | |
| 206 | 206 | foreach ( $submission->get_fees() as $name => $data ) { |
| 207 | - $fees[ $name ] = $submission->format_amount( $data['initial_fee'] ); |
|
| 208 | - } |
|
| 207 | + $fees[ $name ] = $submission->format_amount( $data['initial_fee'] ); |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - $this->response = array_merge( |
|
| 211 | - $this->response, |
|
| 212 | - array( 'fees' => $fees ) |
|
| 213 | - ); |
|
| 210 | + $this->response = array_merge( |
|
| 211 | + $this->response, |
|
| 212 | + array( 'fees' => $fees ) |
|
| 213 | + ); |
|
| 214 | 214 | |
| 215 | - } |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | - /** |
|
| 218 | - * Adds discounts to a response for submission refresh prices. |
|
| 219 | - * |
|
| 220 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 221 | - */ |
|
| 222 | - public function add_discounts( $submission ) { |
|
| 217 | + /** |
|
| 218 | + * Adds discounts to a response for submission refresh prices. |
|
| 219 | + * |
|
| 220 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 221 | + */ |
|
| 222 | + public function add_discounts( $submission ) { |
|
| 223 | 223 | |
| 224 | - $discounts = array(); |
|
| 224 | + $discounts = array(); |
|
| 225 | 225 | |
| 226 | 226 | foreach ( $submission->get_discounts() as $name => $data ) { |
| 227 | - $discounts[ $name ] = $submission->format_amount( $data['initial_discount'] ); |
|
| 228 | - } |
|
| 227 | + $discounts[ $name ] = $submission->format_amount( $data['initial_discount'] ); |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - $this->response = array_merge( |
|
| 231 | - $this->response, |
|
| 232 | - array( 'discounts' => $discounts ) |
|
| 233 | - ); |
|
| 230 | + $this->response = array_merge( |
|
| 231 | + $this->response, |
|
| 232 | + array( 'discounts' => $discounts ) |
|
| 233 | + ); |
|
| 234 | 234 | |
| 235 | - } |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | - /** |
|
| 238 | - * Adds taxes to a response for submission refresh prices. |
|
| 239 | - * |
|
| 240 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 241 | - */ |
|
| 242 | - public function add_taxes( $submission ) { |
|
| 243 | - |
|
| 244 | - $taxes = array(); |
|
| 245 | - $markup = ''; |
|
| 237 | + /** |
|
| 238 | + * Adds taxes to a response for submission refresh prices. |
|
| 239 | + * |
|
| 240 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 241 | + */ |
|
| 242 | + public function add_taxes( $submission ) { |
|
| 243 | + |
|
| 244 | + $taxes = array(); |
|
| 245 | + $markup = ''; |
|
| 246 | 246 | foreach ( $submission->get_taxes() as $name => $data ) { |
| 247 | - $name = sanitize_text_field( $name ); |
|
| 248 | - $amount = $submission->format_amount( $data['initial_tax'] ); |
|
| 249 | - $taxes[ $name ] = $amount; |
|
| 250 | - $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
| 254 | - $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - $this->response = array_merge( |
|
| 258 | - $this->response, |
|
| 259 | - array( 'taxes' => $taxes ) |
|
| 260 | - ); |
|
| 261 | - |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Adds gateways to a response for submission refresh prices. |
|
| 266 | - * |
|
| 267 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 268 | - */ |
|
| 269 | - public function add_gateways( $submission ) { |
|
| 270 | - |
|
| 271 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 272 | - |
|
| 273 | - if ( $this->response['has_recurring'] ) { |
|
| 274 | - |
|
| 275 | - foreach ( $gateways as $i => $gateway ) { |
|
| 276 | - |
|
| 277 | - if ( |
|
| 278 | - ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
| 279 | - || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
| 280 | - || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
| 281 | - unset( $gateways[ $i ] ); |
|
| 282 | - } |
|
| 247 | + $name = sanitize_text_field( $name ); |
|
| 248 | + $amount = $submission->format_amount( $data['initial_tax'] ); |
|
| 249 | + $taxes[ $name ] = $amount; |
|
| 250 | + $markup .= "<small class='form-text'>$name : $amount</small>"; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) { |
|
| 254 | + $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + $this->response = array_merge( |
|
| 258 | + $this->response, |
|
| 259 | + array( 'taxes' => $taxes ) |
|
| 260 | + ); |
|
| 261 | + |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Adds gateways to a response for submission refresh prices. |
|
| 266 | + * |
|
| 267 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 268 | + */ |
|
| 269 | + public function add_gateways( $submission ) { |
|
| 270 | + |
|
| 271 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 272 | + |
|
| 273 | + if ( $this->response['has_recurring'] ) { |
|
| 274 | + |
|
| 275 | + foreach ( $gateways as $i => $gateway ) { |
|
| 276 | + |
|
| 277 | + if ( |
|
| 278 | + ! getpaid_payment_gateway_supports( $gateway, 'subscription' ) |
|
| 279 | + || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) ) |
|
| 280 | + || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) { |
|
| 281 | + unset( $gateways[ $i ] ); |
|
| 282 | + } |
|
| 283 | 283 | } |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
| 287 | - $this->response = array_merge( |
|
| 288 | - $this->response, |
|
| 289 | - array( 'gateways' => $gateways ) |
|
| 290 | - ); |
|
| 291 | - |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * Adds data to a response for submission refresh prices. |
|
| 296 | - * |
|
| 297 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 298 | - */ |
|
| 299 | - public function add_data( $submission ) { |
|
| 300 | - |
|
| 301 | - $this->response = array_merge( |
|
| 302 | - $this->response, |
|
| 303 | - array( |
|
| 304 | - 'js_data' => apply_filters( |
|
| 305 | - 'getpaid_submission_js_data', |
|
| 306 | - array( |
|
| 307 | - 'is_recurring' => $this->response['has_recurring'], |
|
| 308 | - ), |
|
| 309 | - $submission |
|
| 310 | - ), |
|
| 311 | - ) |
|
| 312 | - ); |
|
| 313 | - |
|
| 314 | - } |
|
| 286 | + $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission ); |
|
| 287 | + $this->response = array_merge( |
|
| 288 | + $this->response, |
|
| 289 | + array( 'gateways' => $gateways ) |
|
| 290 | + ); |
|
| 291 | + |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * Adds data to a response for submission refresh prices. |
|
| 296 | + * |
|
| 297 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 298 | + */ |
|
| 299 | + public function add_data( $submission ) { |
|
| 300 | + |
|
| 301 | + $this->response = array_merge( |
|
| 302 | + $this->response, |
|
| 303 | + array( |
|
| 304 | + 'js_data' => apply_filters( |
|
| 305 | + 'getpaid_submission_js_data', |
|
| 306 | + array( |
|
| 307 | + 'is_recurring' => $this->response['has_recurring'], |
|
| 308 | + ), |
|
| 309 | + $submission |
|
| 310 | + ), |
|
| 311 | + ) |
|
| 312 | + ); |
|
| 313 | + |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | 316 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | - exit; |
|
| 3 | + exit; |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | /** |
@@ -10,67 +10,67 @@ discard block |
||
| 10 | 10 | class GetPaid_Form_Item extends WPInv_Item { |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * Stores a custom description for the item. |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - protected $custom_description = null; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Stores the item quantity. |
|
| 21 | - * |
|
| 22 | - * @var float |
|
| 23 | - */ |
|
| 24 | - protected $quantity = 1; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Stores the item meta. |
|
| 28 | - * |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $meta = array(); |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Is this item required? |
|
| 35 | - * |
|
| 36 | - * @var int |
|
| 37 | - */ |
|
| 38 | - protected $is_required = true; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Are quantities allowed? |
|
| 42 | - * |
|
| 43 | - * @var int |
|
| 44 | - */ |
|
| 45 | - protected $allow_quantities = false; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Associated invoice. |
|
| 49 | - * |
|
| 50 | - * @var int |
|
| 51 | - */ |
|
| 52 | - public $invoice_id = 0; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Item discount. |
|
| 56 | - * |
|
| 57 | - * @var float |
|
| 58 | - */ |
|
| 59 | - public $item_discount = 0; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Recurring item discount. |
|
| 63 | - * |
|
| 64 | - * @var float |
|
| 65 | - */ |
|
| 66 | - public $recurring_item_discount = 0; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Item tax. |
|
| 70 | - * |
|
| 71 | - * @var float |
|
| 72 | - */ |
|
| 73 | - public $item_tax = 0; |
|
| 13 | + * Stores a custom description for the item. |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + protected $custom_description = null; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Stores the item quantity. |
|
| 21 | + * |
|
| 22 | + * @var float |
|
| 23 | + */ |
|
| 24 | + protected $quantity = 1; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Stores the item meta. |
|
| 28 | + * |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $meta = array(); |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Is this item required? |
|
| 35 | + * |
|
| 36 | + * @var int |
|
| 37 | + */ |
|
| 38 | + protected $is_required = true; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Are quantities allowed? |
|
| 42 | + * |
|
| 43 | + * @var int |
|
| 44 | + */ |
|
| 45 | + protected $allow_quantities = false; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Associated invoice. |
|
| 49 | + * |
|
| 50 | + * @var int |
|
| 51 | + */ |
|
| 52 | + public $invoice_id = 0; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Item discount. |
|
| 56 | + * |
|
| 57 | + * @var float |
|
| 58 | + */ |
|
| 59 | + public $item_discount = 0; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Recurring item discount. |
|
| 63 | + * |
|
| 64 | + * @var float |
|
| 65 | + */ |
|
| 66 | + public $recurring_item_discount = 0; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Item tax. |
|
| 70 | + * |
|
| 71 | + * @var float |
|
| 72 | + */ |
|
| 73 | + public $item_tax = 0; |
|
| 74 | 74 | |
| 75 | 75 | /* |
| 76 | 76 | |-------------------------------------------------------------------------- |
@@ -88,230 +88,230 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | |
| 90 | 90 | /** |
| 91 | - * Get the item name. |
|
| 92 | - * |
|
| 93 | - * @since 1.0.19 |
|
| 94 | - * @param string $context View or edit context. |
|
| 95 | - * @return string |
|
| 96 | - */ |
|
| 97 | - public function get_name( $context = 'view' ) { |
|
| 98 | - $name = parent::get_name( $context ); |
|
| 99 | - return $name . wpinv_get_item_suffix( $this ); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Get the item name without a suffix. |
|
| 104 | - * |
|
| 105 | - * @since 1.0.19 |
|
| 106 | - * @param string $context View or edit context. |
|
| 107 | - * @return string |
|
| 108 | - */ |
|
| 109 | - public function get_raw_name( $context = 'view' ) { |
|
| 110 | - return parent::get_name( $context ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Get the item description. |
|
| 115 | - * |
|
| 116 | - * @since 1.0.19 |
|
| 117 | - * @param string $context View or edit context. |
|
| 118 | - * @return string |
|
| 119 | - */ |
|
| 120 | - public function get_description( $context = 'view' ) { |
|
| 121 | - |
|
| 122 | - if ( isset( $this->custom_description ) ) { |
|
| 123 | - return $this->custom_description; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - return parent::get_description( $context ); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Returns the sub total. |
|
| 131 | - * |
|
| 132 | - * @since 1.0.19 |
|
| 133 | - * @param string $context View or edit context. |
|
| 134 | - * @return float |
|
| 135 | - */ |
|
| 136 | - public function get_sub_total( $context = 'view' ) { |
|
| 137 | - return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Returns the recurring sub total. |
|
| 142 | - * |
|
| 143 | - * @since 1.0.19 |
|
| 144 | - * @param string $context View or edit context. |
|
| 145 | - * @return float |
|
| 146 | - */ |
|
| 147 | - public function get_recurring_sub_total( $context = 'view' ) { |
|
| 148 | - |
|
| 149 | - if ( $this->is_recurring() ) { |
|
| 150 | - return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - return 0; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * @deprecated |
|
| 158 | - */ |
|
| 159 | - public function get_qantity( $context = 'view' ) { |
|
| 160 | - return $this->get_quantity( $context ); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Get the item quantity. |
|
| 165 | - * |
|
| 166 | - * @since 1.0.19 |
|
| 167 | - * @param string $context View or edit context. |
|
| 168 | - * @return float |
|
| 169 | - */ |
|
| 170 | - public function get_quantity( $context = 'view' ) { |
|
| 171 | - $quantity = (float) $this->quantity; |
|
| 172 | - |
|
| 173 | - if ( 'view' === $context ) { |
|
| 174 | - return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - return $quantity; |
|
| 178 | - |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Get the item meta data. |
|
| 183 | - * |
|
| 184 | - * @since 1.0.19 |
|
| 185 | - * @param string $context View or edit context. |
|
| 186 | - * @return meta |
|
| 187 | - */ |
|
| 188 | - public function get_item_meta( $context = 'view' ) { |
|
| 189 | - $meta = $this->meta; |
|
| 190 | - |
|
| 191 | - if ( 'view' === $context ) { |
|
| 192 | - return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - return $meta; |
|
| 196 | - |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Returns whether or not customers can update the item quantity. |
|
| 201 | - * |
|
| 202 | - * @since 1.0.19 |
|
| 203 | - * @param string $context View or edit context. |
|
| 204 | - * @return bool |
|
| 205 | - */ |
|
| 206 | - public function get_allow_quantities( $context = 'view' ) { |
|
| 207 | - $allow_quantities = (bool) $this->allow_quantities; |
|
| 208 | - |
|
| 209 | - if ( 'view' === $context ) { |
|
| 210 | - return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - return $allow_quantities; |
|
| 214 | - |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Returns whether or not the item is required. |
|
| 219 | - * |
|
| 220 | - * @since 1.0.19 |
|
| 221 | - * @param string $context View or edit context. |
|
| 222 | - * @return bool |
|
| 223 | - */ |
|
| 224 | - public function get_is_required( $context = 'view' ) { |
|
| 225 | - $is_required = (bool) $this->is_required; |
|
| 226 | - |
|
| 227 | - if ( 'view' === $context ) { |
|
| 228 | - return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - return $is_required; |
|
| 232 | - |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * Prepares form data for use. |
|
| 237 | - * |
|
| 238 | - * @since 1.0.19 |
|
| 239 | - * @return array |
|
| 240 | - */ |
|
| 241 | - public function prepare_data_for_use( $required = null ) { |
|
| 242 | - |
|
| 243 | - $required = is_null( $required ) ? $this->is_required() : $required; |
|
| 244 | - return array( |
|
| 245 | - 'title' => wp_strip_all_tags( $this->get_name() ), |
|
| 246 | - 'id' => $this->get_id(), |
|
| 247 | - 'price' => $this->get_price(), |
|
| 248 | - 'recurring' => $this->is_recurring(), |
|
| 249 | - 'description' => $this->get_description(), |
|
| 250 | - 'allow_quantities' => $this->allows_quantities(), |
|
| 251 | - 'required' => $required, |
|
| 252 | - ); |
|
| 253 | - |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * Prepares form data for ajax use. |
|
| 258 | - * |
|
| 259 | - * @since 1.0.19 |
|
| 260 | - * @return array |
|
| 261 | - */ |
|
| 262 | - public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) { |
|
| 263 | - |
|
| 264 | - $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
| 265 | - |
|
| 266 | - if ( $description ) { |
|
| 267 | - $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - $price = ! $is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
| 271 | - $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
| 272 | - return array( |
|
| 273 | - 'id' => $this->get_id(), |
|
| 274 | - 'texts' => array( |
|
| 275 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
| 276 | - 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
| 277 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
| 278 | - 'item-price' => wpinv_price( $price, $currency ), |
|
| 279 | - 'item-total' => wpinv_price( $subtotal, $currency ), |
|
| 280 | - ), |
|
| 281 | - 'inputs' => array( |
|
| 282 | - 'item-id' => $this->get_id(), |
|
| 283 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
| 284 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
| 285 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
| 286 | - 'item-price' => $price, |
|
| 287 | - ), |
|
| 288 | - ); |
|
| 289 | - |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * Prepares form data for saving (cart_details). |
|
| 294 | - * |
|
| 295 | - * @since 1.0.19 |
|
| 296 | - * @return array |
|
| 297 | - */ |
|
| 298 | - public function prepare_data_for_saving() { |
|
| 299 | - |
|
| 300 | - return array( |
|
| 301 | - 'post_id' => $this->invoice_id, |
|
| 302 | - 'item_id' => $this->get_id(), |
|
| 303 | - 'item_name' => sanitize_text_field( $this->get_raw_name( 'edit' ) ), |
|
| 304 | - 'item_description' => $this->get_description( 'edit' ), |
|
| 305 | - 'tax' => $this->item_tax, |
|
| 306 | - 'item_price' => $this->get_price( 'edit' ), |
|
| 307 | - 'quantity' => (float) $this->get_quantity( 'edit' ), |
|
| 308 | - 'discount' => $this->item_discount, |
|
| 309 | - 'subtotal' => $this->get_sub_total( 'edit' ), |
|
| 310 | - 'price' => $this->get_sub_total( 'edit' ) + $this->item_tax - $this->item_discount, |
|
| 311 | - 'meta' => $this->get_item_meta( 'edit' ), |
|
| 312 | - ); |
|
| 313 | - |
|
| 314 | - } |
|
| 91 | + * Get the item name. |
|
| 92 | + * |
|
| 93 | + * @since 1.0.19 |
|
| 94 | + * @param string $context View or edit context. |
|
| 95 | + * @return string |
|
| 96 | + */ |
|
| 97 | + public function get_name( $context = 'view' ) { |
|
| 98 | + $name = parent::get_name( $context ); |
|
| 99 | + return $name . wpinv_get_item_suffix( $this ); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Get the item name without a suffix. |
|
| 104 | + * |
|
| 105 | + * @since 1.0.19 |
|
| 106 | + * @param string $context View or edit context. |
|
| 107 | + * @return string |
|
| 108 | + */ |
|
| 109 | + public function get_raw_name( $context = 'view' ) { |
|
| 110 | + return parent::get_name( $context ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Get the item description. |
|
| 115 | + * |
|
| 116 | + * @since 1.0.19 |
|
| 117 | + * @param string $context View or edit context. |
|
| 118 | + * @return string |
|
| 119 | + */ |
|
| 120 | + public function get_description( $context = 'view' ) { |
|
| 121 | + |
|
| 122 | + if ( isset( $this->custom_description ) ) { |
|
| 123 | + return $this->custom_description; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + return parent::get_description( $context ); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Returns the sub total. |
|
| 131 | + * |
|
| 132 | + * @since 1.0.19 |
|
| 133 | + * @param string $context View or edit context. |
|
| 134 | + * @return float |
|
| 135 | + */ |
|
| 136 | + public function get_sub_total( $context = 'view' ) { |
|
| 137 | + return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Returns the recurring sub total. |
|
| 142 | + * |
|
| 143 | + * @since 1.0.19 |
|
| 144 | + * @param string $context View or edit context. |
|
| 145 | + * @return float |
|
| 146 | + */ |
|
| 147 | + public function get_recurring_sub_total( $context = 'view' ) { |
|
| 148 | + |
|
| 149 | + if ( $this->is_recurring() ) { |
|
| 150 | + return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + return 0; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * @deprecated |
|
| 158 | + */ |
|
| 159 | + public function get_qantity( $context = 'view' ) { |
|
| 160 | + return $this->get_quantity( $context ); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Get the item quantity. |
|
| 165 | + * |
|
| 166 | + * @since 1.0.19 |
|
| 167 | + * @param string $context View or edit context. |
|
| 168 | + * @return float |
|
| 169 | + */ |
|
| 170 | + public function get_quantity( $context = 'view' ) { |
|
| 171 | + $quantity = (float) $this->quantity; |
|
| 172 | + |
|
| 173 | + if ( 'view' === $context ) { |
|
| 174 | + return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + return $quantity; |
|
| 178 | + |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Get the item meta data. |
|
| 183 | + * |
|
| 184 | + * @since 1.0.19 |
|
| 185 | + * @param string $context View or edit context. |
|
| 186 | + * @return meta |
|
| 187 | + */ |
|
| 188 | + public function get_item_meta( $context = 'view' ) { |
|
| 189 | + $meta = $this->meta; |
|
| 190 | + |
|
| 191 | + if ( 'view' === $context ) { |
|
| 192 | + return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + return $meta; |
|
| 196 | + |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Returns whether or not customers can update the item quantity. |
|
| 201 | + * |
|
| 202 | + * @since 1.0.19 |
|
| 203 | + * @param string $context View or edit context. |
|
| 204 | + * @return bool |
|
| 205 | + */ |
|
| 206 | + public function get_allow_quantities( $context = 'view' ) { |
|
| 207 | + $allow_quantities = (bool) $this->allow_quantities; |
|
| 208 | + |
|
| 209 | + if ( 'view' === $context ) { |
|
| 210 | + return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + return $allow_quantities; |
|
| 214 | + |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Returns whether or not the item is required. |
|
| 219 | + * |
|
| 220 | + * @since 1.0.19 |
|
| 221 | + * @param string $context View or edit context. |
|
| 222 | + * @return bool |
|
| 223 | + */ |
|
| 224 | + public function get_is_required( $context = 'view' ) { |
|
| 225 | + $is_required = (bool) $this->is_required; |
|
| 226 | + |
|
| 227 | + if ( 'view' === $context ) { |
|
| 228 | + return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + return $is_required; |
|
| 232 | + |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * Prepares form data for use. |
|
| 237 | + * |
|
| 238 | + * @since 1.0.19 |
|
| 239 | + * @return array |
|
| 240 | + */ |
|
| 241 | + public function prepare_data_for_use( $required = null ) { |
|
| 242 | + |
|
| 243 | + $required = is_null( $required ) ? $this->is_required() : $required; |
|
| 244 | + return array( |
|
| 245 | + 'title' => wp_strip_all_tags( $this->get_name() ), |
|
| 246 | + 'id' => $this->get_id(), |
|
| 247 | + 'price' => $this->get_price(), |
|
| 248 | + 'recurring' => $this->is_recurring(), |
|
| 249 | + 'description' => $this->get_description(), |
|
| 250 | + 'allow_quantities' => $this->allows_quantities(), |
|
| 251 | + 'required' => $required, |
|
| 252 | + ); |
|
| 253 | + |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * Prepares form data for ajax use. |
|
| 258 | + * |
|
| 259 | + * @since 1.0.19 |
|
| 260 | + * @return array |
|
| 261 | + */ |
|
| 262 | + public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) { |
|
| 263 | + |
|
| 264 | + $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
| 265 | + |
|
| 266 | + if ( $description ) { |
|
| 267 | + $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + $price = ! $is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
| 271 | + $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
| 272 | + return array( |
|
| 273 | + 'id' => $this->get_id(), |
|
| 274 | + 'texts' => array( |
|
| 275 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
| 276 | + 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
| 277 | + 'item-quantity' => floatval( $this->get_quantity() ), |
|
| 278 | + 'item-price' => wpinv_price( $price, $currency ), |
|
| 279 | + 'item-total' => wpinv_price( $subtotal, $currency ), |
|
| 280 | + ), |
|
| 281 | + 'inputs' => array( |
|
| 282 | + 'item-id' => $this->get_id(), |
|
| 283 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
| 284 | + 'item-description' => wp_kses_post( $this->get_description() ), |
|
| 285 | + 'item-quantity' => floatval( $this->get_quantity() ), |
|
| 286 | + 'item-price' => $price, |
|
| 287 | + ), |
|
| 288 | + ); |
|
| 289 | + |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * Prepares form data for saving (cart_details). |
|
| 294 | + * |
|
| 295 | + * @since 1.0.19 |
|
| 296 | + * @return array |
|
| 297 | + */ |
|
| 298 | + public function prepare_data_for_saving() { |
|
| 299 | + |
|
| 300 | + return array( |
|
| 301 | + 'post_id' => $this->invoice_id, |
|
| 302 | + 'item_id' => $this->get_id(), |
|
| 303 | + 'item_name' => sanitize_text_field( $this->get_raw_name( 'edit' ) ), |
|
| 304 | + 'item_description' => $this->get_description( 'edit' ), |
|
| 305 | + 'tax' => $this->item_tax, |
|
| 306 | + 'item_price' => $this->get_price( 'edit' ), |
|
| 307 | + 'quantity' => (float) $this->get_quantity( 'edit' ), |
|
| 308 | + 'discount' => $this->item_discount, |
|
| 309 | + 'subtotal' => $this->get_sub_total( 'edit' ), |
|
| 310 | + 'price' => $this->get_sub_total( 'edit' ) + $this->item_tax - $this->item_discount, |
|
| 311 | + 'meta' => $this->get_item_meta( 'edit' ), |
|
| 312 | + ); |
|
| 313 | + |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | 316 | /* |
| 317 | 317 | |-------------------------------------------------------------------------- |
@@ -323,70 +323,70 @@ discard block |
||
| 323 | 323 | | object. |
| 324 | 324 | */ |
| 325 | 325 | |
| 326 | - /** |
|
| 327 | - * Set the item qantity. |
|
| 328 | - * |
|
| 329 | - * @since 1.0.19 |
|
| 330 | - * @param float $quantity The item quantity. |
|
| 331 | - */ |
|
| 332 | - public function set_quantity( $quantity ) { |
|
| 333 | - |
|
| 334 | - if ( ! is_numeric( $quantity ) ) { |
|
| 335 | - $quantity = 1; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - $this->quantity = (float) $quantity; |
|
| 339 | - |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * Set the item meta data. |
|
| 344 | - * |
|
| 345 | - * @since 1.0.19 |
|
| 346 | - * @param array $meta The item meta data. |
|
| 347 | - */ |
|
| 348 | - public function set_item_meta( $meta ) { |
|
| 349 | - $this->meta = maybe_unserialize( $meta ); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Set whether or not the quantities are allowed. |
|
| 354 | - * |
|
| 355 | - * @since 1.0.19 |
|
| 356 | - * @param bool $allow_quantities |
|
| 357 | - */ |
|
| 358 | - public function set_allow_quantities( $allow_quantities ) { |
|
| 359 | - $this->allow_quantities = (bool) $allow_quantities; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * Set whether or not the item is required. |
|
| 364 | - * |
|
| 365 | - * @since 1.0.19 |
|
| 366 | - * @param bool $is_required |
|
| 367 | - */ |
|
| 368 | - public function set_is_required( $is_required ) { |
|
| 369 | - $this->is_required = (bool) $is_required; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * Sets the custom item description. |
|
| 374 | - * |
|
| 375 | - * @since 1.0.19 |
|
| 376 | - * @param string $description |
|
| 377 | - */ |
|
| 378 | - public function set_custom_description( $description ) { |
|
| 379 | - $this->custom_description = $description; |
|
| 380 | - } |
|
| 326 | + /** |
|
| 327 | + * Set the item qantity. |
|
| 328 | + * |
|
| 329 | + * @since 1.0.19 |
|
| 330 | + * @param float $quantity The item quantity. |
|
| 331 | + */ |
|
| 332 | + public function set_quantity( $quantity ) { |
|
| 333 | + |
|
| 334 | + if ( ! is_numeric( $quantity ) ) { |
|
| 335 | + $quantity = 1; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + $this->quantity = (float) $quantity; |
|
| 339 | + |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * Set the item meta data. |
|
| 344 | + * |
|
| 345 | + * @since 1.0.19 |
|
| 346 | + * @param array $meta The item meta data. |
|
| 347 | + */ |
|
| 348 | + public function set_item_meta( $meta ) { |
|
| 349 | + $this->meta = maybe_unserialize( $meta ); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Set whether or not the quantities are allowed. |
|
| 354 | + * |
|
| 355 | + * @since 1.0.19 |
|
| 356 | + * @param bool $allow_quantities |
|
| 357 | + */ |
|
| 358 | + public function set_allow_quantities( $allow_quantities ) { |
|
| 359 | + $this->allow_quantities = (bool) $allow_quantities; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * Set whether or not the item is required. |
|
| 364 | + * |
|
| 365 | + * @since 1.0.19 |
|
| 366 | + * @param bool $is_required |
|
| 367 | + */ |
|
| 368 | + public function set_is_required( $is_required ) { |
|
| 369 | + $this->is_required = (bool) $is_required; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * Sets the custom item description. |
|
| 374 | + * |
|
| 375 | + * @since 1.0.19 |
|
| 376 | + * @param string $description |
|
| 377 | + */ |
|
| 378 | + public function set_custom_description( $description ) { |
|
| 379 | + $this->custom_description = $description; |
|
| 380 | + } |
|
| 381 | 381 | |
| 382 | 382 | /** |
| 383 | 383 | * We do not want to save items to the database. |
| 384 | 384 | * |
| 385 | - * @return int item id |
|
| 385 | + * @return int item id |
|
| 386 | 386 | */ |
| 387 | 387 | public function save( $data = array() ) { |
| 388 | 388 | return $this->get_id(); |
| 389 | - } |
|
| 389 | + } |
|
| 390 | 390 | |
| 391 | 391 | /* |
| 392 | 392 | |-------------------------------------------------------------------------- |
@@ -398,23 +398,23 @@ discard block |
||
| 398 | 398 | */ |
| 399 | 399 | |
| 400 | 400 | /** |
| 401 | - * Checks whether the item has enabled dynamic pricing. |
|
| 402 | - * |
|
| 403 | - * @since 1.0.19 |
|
| 404 | - * @return bool |
|
| 405 | - */ |
|
| 406 | - public function is_required() { |
|
| 401 | + * Checks whether the item has enabled dynamic pricing. |
|
| 402 | + * |
|
| 403 | + * @since 1.0.19 |
|
| 404 | + * @return bool |
|
| 405 | + */ |
|
| 406 | + public function is_required() { |
|
| 407 | 407 | return (bool) $this->get_is_required(); |
| 408 | - } |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * Checks whether users can edit the quantities. |
|
| 412 | - * |
|
| 413 | - * @since 1.0.19 |
|
| 414 | - * @return bool |
|
| 415 | - */ |
|
| 416 | - public function allows_quantities() { |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * Checks whether users can edit the quantities. |
|
| 412 | + * |
|
| 413 | + * @since 1.0.19 |
|
| 414 | + * @return bool |
|
| 415 | + */ |
|
| 416 | + public function allows_quantities() { |
|
| 417 | 417 | return (bool) $this->get_allow_quantities(); |
| 418 | - } |
|
| 418 | + } |
|
| 419 | 419 | |
| 420 | 420 | } |
@@ -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,1283 +11,1283 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | class AUI_Component_Input { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Build the component. |
|
| 16 | - * |
|
| 17 | - * @param array $args |
|
| 18 | - * |
|
| 19 | - * @return string The rendered component. |
|
| 20 | - */ |
|
| 21 | - public static function input( $args = array() ) { |
|
| 22 | - global $aui_bs5; |
|
| 23 | - |
|
| 24 | - $defaults = array( |
|
| 25 | - 'type' => 'text', |
|
| 26 | - 'name' => '', |
|
| 27 | - 'class' => '', |
|
| 28 | - 'wrap_class' => '', |
|
| 29 | - 'id' => '', |
|
| 30 | - 'placeholder' => '', |
|
| 31 | - 'title' => '', |
|
| 32 | - 'value' => '', |
|
| 33 | - 'required' => false, |
|
| 34 | - 'size' => '', // sm, lg, small, large |
|
| 35 | - 'clear_icon' => '', // true will show a clear icon, can't be used with input_group_right |
|
| 36 | - 'with_hidden' => false, // Append hidden field for single checkbox. |
|
| 37 | - 'label' => '', |
|
| 38 | - 'label_after' => false, |
|
| 39 | - 'label_class' => '', |
|
| 40 | - 'label_col' => '2', |
|
| 41 | - 'label_type' => '', // top, horizontal, empty = hidden |
|
| 42 | - 'label_force_left' => false, // used to force checkbox label left when using horizontal |
|
| 43 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 44 | - 'help_text' => '', |
|
| 45 | - 'validation_text' => '', |
|
| 46 | - 'validation_pattern' => '', |
|
| 47 | - 'no_wrap' => false, |
|
| 48 | - 'input_group_right' => '', |
|
| 49 | - 'input_group_left' => '', |
|
| 50 | - 'input_group_right_inside' => false, |
|
| 51 | - // forces the input group inside the input |
|
| 52 | - 'input_group_left_inside' => false, |
|
| 53 | - // forces the input group inside the input |
|
| 54 | - 'form_group_class' => '', |
|
| 55 | - 'step' => '', |
|
| 56 | - 'switch' => false, |
|
| 57 | - // to show checkbox as a switch |
|
| 58 | - 'checked' => false, |
|
| 59 | - // set a checkbox or radio as selected |
|
| 60 | - 'password_toggle' => true, |
|
| 61 | - // toggle view/hide password |
|
| 62 | - 'element_require' => '', |
|
| 63 | - // [%element_id%] == "1" |
|
| 64 | - 'extra_attributes' => array(), |
|
| 65 | - // an array of extra attributes |
|
| 66 | - 'wrap_attributes' => array() |
|
| 67 | - ); |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 71 | - */ |
|
| 72 | - $args = wp_parse_args( $args, $defaults ); |
|
| 73 | - $output = ''; |
|
| 74 | - if ( ! empty( $args['type'] ) ) { |
|
| 75 | - // hidden label option needs to be empty |
|
| 76 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
| 77 | - |
|
| 78 | - $type = sanitize_html_class( $args['type'] ); |
|
| 79 | - |
|
| 80 | - $help_text = ''; |
|
| 81 | - $label = ''; |
|
| 82 | - $label_after = $args['label_after']; |
|
| 83 | - $label_args = array( |
|
| 84 | - 'title' => $args['label'], |
|
| 85 | - 'for' => $args['id'], |
|
| 86 | - 'class' => $args['label_class'] . " ", |
|
| 87 | - 'label_type' => $args['label_type'], |
|
| 88 | - 'label_col' => $args['label_col'] |
|
| 89 | - ); |
|
| 90 | - |
|
| 91 | - // floating labels need label after |
|
| 92 | - if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
| 93 | - $label_after = true; |
|
| 94 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // size |
|
| 98 | - $size = ''; |
|
| 99 | - if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
|
| 100 | - $size = 'lg'; |
|
| 101 | - $args['class'] .= ' form-control-lg'; |
|
| 102 | - }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
| 103 | - $size = 'sm'; |
|
| 104 | - $args['class'] .= ' form-control-sm'; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - // clear function |
|
| 108 | - $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');'; |
|
| 109 | - |
|
| 110 | - // Some special sauce for files |
|
| 111 | - if ( $type == 'file' ) { |
|
| 112 | - $label_after = true; // if type file we need the label after |
|
| 113 | - $args['class'] .= ' custom-file-input '; |
|
| 114 | - } elseif ( $type == 'checkbox' ) { |
|
| 115 | - $label_after = true; // if type file we need the label after |
|
| 116 | - $args['class'] .= $aui_bs5 ? ' form-check-input' : ' custom-control-input '; |
|
| 117 | - } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
| 118 | - $orig_type = $type; |
|
| 119 | - $type = 'text'; |
|
| 120 | - $args['class'] .= ' bg-initial '; // @todo not sure why we have this? |
|
| 121 | - $clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');"; |
|
| 122 | - |
|
| 123 | - $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
| 124 | - |
|
| 125 | - // Disable native datetime inputs. |
|
| 126 | - if ( ( $orig_type == 'timepicker' || ! empty( $args['extra_attributes']['data-enable-time'] ) ) && ! isset( $args['extra_attributes']['data-disable-mobile'] ) ) { |
|
| 127 | - $args['extra_attributes']['data-disable-mobile'] = 'true'; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - // set a way to clear field if empty |
|
| 131 | - if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) { |
|
| 132 | - $args['input_group_right_inside'] = true; |
|
| 133 | - $args['clear_icon'] = true; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - // enqueue the script |
|
| 137 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
| 138 | - $aui_settings->enqueue_flatpickr(); |
|
| 139 | - } elseif ( $type == 'iconpicker' ) { |
|
| 140 | - $type = 'text'; |
|
| 141 | - //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
| 14 | + /** |
|
| 15 | + * Build the component. |
|
| 16 | + * |
|
| 17 | + * @param array $args |
|
| 18 | + * |
|
| 19 | + * @return string The rendered component. |
|
| 20 | + */ |
|
| 21 | + public static function input( $args = array() ) { |
|
| 22 | + global $aui_bs5; |
|
| 23 | + |
|
| 24 | + $defaults = array( |
|
| 25 | + 'type' => 'text', |
|
| 26 | + 'name' => '', |
|
| 27 | + 'class' => '', |
|
| 28 | + 'wrap_class' => '', |
|
| 29 | + 'id' => '', |
|
| 30 | + 'placeholder' => '', |
|
| 31 | + 'title' => '', |
|
| 32 | + 'value' => '', |
|
| 33 | + 'required' => false, |
|
| 34 | + 'size' => '', // sm, lg, small, large |
|
| 35 | + 'clear_icon' => '', // true will show a clear icon, can't be used with input_group_right |
|
| 36 | + 'with_hidden' => false, // Append hidden field for single checkbox. |
|
| 37 | + 'label' => '', |
|
| 38 | + 'label_after' => false, |
|
| 39 | + 'label_class' => '', |
|
| 40 | + 'label_col' => '2', |
|
| 41 | + 'label_type' => '', // top, horizontal, empty = hidden |
|
| 42 | + 'label_force_left' => false, // used to force checkbox label left when using horizontal |
|
| 43 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 44 | + 'help_text' => '', |
|
| 45 | + 'validation_text' => '', |
|
| 46 | + 'validation_pattern' => '', |
|
| 47 | + 'no_wrap' => false, |
|
| 48 | + 'input_group_right' => '', |
|
| 49 | + 'input_group_left' => '', |
|
| 50 | + 'input_group_right_inside' => false, |
|
| 51 | + // forces the input group inside the input |
|
| 52 | + 'input_group_left_inside' => false, |
|
| 53 | + // forces the input group inside the input |
|
| 54 | + 'form_group_class' => '', |
|
| 55 | + 'step' => '', |
|
| 56 | + 'switch' => false, |
|
| 57 | + // to show checkbox as a switch |
|
| 58 | + 'checked' => false, |
|
| 59 | + // set a checkbox or radio as selected |
|
| 60 | + 'password_toggle' => true, |
|
| 61 | + // toggle view/hide password |
|
| 62 | + 'element_require' => '', |
|
| 63 | + // [%element_id%] == "1" |
|
| 64 | + 'extra_attributes' => array(), |
|
| 65 | + // an array of extra attributes |
|
| 66 | + 'wrap_attributes' => array() |
|
| 67 | + ); |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 71 | + */ |
|
| 72 | + $args = wp_parse_args( $args, $defaults ); |
|
| 73 | + $output = ''; |
|
| 74 | + if ( ! empty( $args['type'] ) ) { |
|
| 75 | + // hidden label option needs to be empty |
|
| 76 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
| 77 | + |
|
| 78 | + $type = sanitize_html_class( $args['type'] ); |
|
| 79 | + |
|
| 80 | + $help_text = ''; |
|
| 81 | + $label = ''; |
|
| 82 | + $label_after = $args['label_after']; |
|
| 83 | + $label_args = array( |
|
| 84 | + 'title' => $args['label'], |
|
| 85 | + 'for' => $args['id'], |
|
| 86 | + 'class' => $args['label_class'] . " ", |
|
| 87 | + 'label_type' => $args['label_type'], |
|
| 88 | + 'label_col' => $args['label_col'] |
|
| 89 | + ); |
|
| 90 | + |
|
| 91 | + // floating labels need label after |
|
| 92 | + if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
| 93 | + $label_after = true; |
|
| 94 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // size |
|
| 98 | + $size = ''; |
|
| 99 | + if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
|
| 100 | + $size = 'lg'; |
|
| 101 | + $args['class'] .= ' form-control-lg'; |
|
| 102 | + }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
| 103 | + $size = 'sm'; |
|
| 104 | + $args['class'] .= ' form-control-sm'; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + // clear function |
|
| 108 | + $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');'; |
|
| 109 | + |
|
| 110 | + // Some special sauce for files |
|
| 111 | + if ( $type == 'file' ) { |
|
| 112 | + $label_after = true; // if type file we need the label after |
|
| 113 | + $args['class'] .= ' custom-file-input '; |
|
| 114 | + } elseif ( $type == 'checkbox' ) { |
|
| 115 | + $label_after = true; // if type file we need the label after |
|
| 116 | + $args['class'] .= $aui_bs5 ? ' form-check-input' : ' custom-control-input '; |
|
| 117 | + } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
| 118 | + $orig_type = $type; |
|
| 119 | + $type = 'text'; |
|
| 120 | + $args['class'] .= ' bg-initial '; // @todo not sure why we have this? |
|
| 121 | + $clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');"; |
|
| 122 | + |
|
| 123 | + $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
| 124 | + |
|
| 125 | + // Disable native datetime inputs. |
|
| 126 | + if ( ( $orig_type == 'timepicker' || ! empty( $args['extra_attributes']['data-enable-time'] ) ) && ! isset( $args['extra_attributes']['data-disable-mobile'] ) ) { |
|
| 127 | + $args['extra_attributes']['data-disable-mobile'] = 'true'; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + // set a way to clear field if empty |
|
| 131 | + if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) { |
|
| 132 | + $args['input_group_right_inside'] = true; |
|
| 133 | + $args['clear_icon'] = true; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + // enqueue the script |
|
| 137 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
| 138 | + $aui_settings->enqueue_flatpickr(); |
|
| 139 | + } elseif ( $type == 'iconpicker' ) { |
|
| 140 | + $type = 'text'; |
|
| 141 | + //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
| 142 | 142 | // $args['class'] .= ' bg-initial '; |
| 143 | 143 | |
| 144 | - $args['extra_attributes']['data-aui-init'] = 'iconpicker'; |
|
| 145 | - $args['extra_attributes']['data-placement'] = 'bottomRight'; |
|
| 144 | + $args['extra_attributes']['data-aui-init'] = 'iconpicker'; |
|
| 145 | + $args['extra_attributes']['data-placement'] = 'bottomRight'; |
|
| 146 | 146 | |
| 147 | - $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>'; |
|
| 147 | + $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>'; |
|
| 148 | 148 | // $args['input_group_right_inside'] = true; |
| 149 | - // enqueue the script |
|
| 150 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
| 151 | - $aui_settings->enqueue_iconpicker(); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - if ( $type == 'checkbox' && ( ( ! empty( $args['name'] ) && strpos( $args['name'], '[' ) === false ) || ! empty( $args['with_hidden'] ) ) ) { |
|
| 155 | - $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - // allow clear icon |
|
| 159 | - if ( $args['input_group_right'] === '' && $args['clear_icon'] ) { |
|
| 160 | - $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' ); |
|
| 161 | - $args['input_group_right_inside'] = true; |
|
| 162 | - $align_class = $aui_bs5 ? ' h-100 py-0' : ''; |
|
| 163 | - $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none ' . $align_class . '" onclick="' . $clear_function . '"><span style="font-size: ' . $font_size . 'rem" aria-hidden="true" class="' . ( $aui_bs5 ? 'btn-close' : 'close' ) . '">' . ( $aui_bs5 ? '' : '×' ) . '</span></span>'; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - // open/type |
|
| 167 | - $output .= '<input type="' . $type . '" '; |
|
| 168 | - |
|
| 169 | - // name |
|
| 170 | - if ( ! empty( $args['name'] ) ) { |
|
| 171 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - // id |
|
| 175 | - if ( ! empty( $args['id'] ) ) { |
|
| 176 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - // placeholder |
|
| 180 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
| 181 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - // title |
|
| 185 | - if ( ! empty( $args['title'] ) ) { |
|
| 186 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - // value |
|
| 190 | - if ( ! empty( $args['value'] ) ) { |
|
| 191 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - // checked, for radio and checkboxes |
|
| 195 | - if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
| 196 | - $output .= ' checked '; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - // validation text |
|
| 200 | - if ( ! empty( $args['validation_text'] ) ) { |
|
| 201 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
| 202 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - // validation_pattern |
|
| 206 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
| 207 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - // step (for numbers) |
|
| 211 | - if ( ! empty( $args['step'] ) ) { |
|
| 212 | - $output .= ' step="' . $args['step'] . '" '; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - // required |
|
| 216 | - if ( ! empty( $args['required'] ) ) { |
|
| 217 | - $output .= ' required '; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - // class |
|
| 221 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
| 222 | - $output .= $aui_bs5 && $type == 'checkbox' ? ' class="' . $class . '" ' : ' class="form-control ' . $class . '" '; |
|
| 223 | - |
|
| 224 | - // data-attributes |
|
| 225 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
| 226 | - |
|
| 227 | - // extra attributes |
|
| 228 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
| 229 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - // close |
|
| 233 | - $output .= ' >'; |
|
| 234 | - |
|
| 235 | - // help text |
|
| 236 | - if ( ! empty( $args['help_text'] ) ) { |
|
| 237 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - // label |
|
| 241 | - if ( ! empty( $args['label'] ) ) { |
|
| 242 | - $label_base_class = ''; |
|
| 243 | - if ( $type == 'file' ) { |
|
| 244 | - $label_base_class = ' custom-file-label'; |
|
| 245 | - } elseif ( $type == 'checkbox' ) { |
|
| 246 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
| 247 | - $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
| 248 | - $help_text = ''; |
|
| 249 | - //$label_args['class'] .= ' d-inline '; |
|
| 250 | - $args['wrap_class'] .= ' align-items-center '; |
|
| 251 | - }else{ |
|
| 252 | - |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - $label_base_class = $aui_bs5 ? ' form-check-label' : ' custom-control-label'; |
|
| 256 | - } |
|
| 257 | - $label_args['class'] .= $label_base_class; |
|
| 258 | - $temp_label_args = $label_args; |
|
| 259 | - if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
| 260 | - $label = self::label( $temp_label_args, $type ); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - // set help text in the correct position |
|
| 267 | - if ( $label_after ) { |
|
| 268 | - $output .= $label . $help_text; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - // some input types need a separate wrap |
|
| 272 | - if ( $type == 'file' ) { |
|
| 273 | - $output = self::wrap( array( |
|
| 274 | - 'content' => $output, |
|
| 275 | - 'class' => $aui_bs5 ? 'mb-3 custom-file' : 'form-group custom-file' |
|
| 276 | - ) ); |
|
| 277 | - } elseif ( $type == 'checkbox' ) { |
|
| 278 | - |
|
| 279 | - $label_args['title'] = $args['label']; |
|
| 280 | - $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
| 281 | - $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
| 282 | - $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
| 283 | - if ( $aui_bs5 ) { |
|
| 284 | - $wrap_class = $args['switch'] ? 'form-check form-switch' . $switch_size_class : 'form-check'; |
|
| 285 | - }else{ |
|
| 286 | - $wrap_class = $args['switch'] ? 'custom-switch' . $switch_size_class : 'custom-checkbox' ; |
|
| 287 | - } |
|
| 288 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
| 289 | - $wrap_class .= $aui_bs5 ? '' : ' d-flex align-content-center'; |
|
| 290 | - $label = str_replace(array("form-check-label","custom-control-label"),"", self::label( $label_args, 'cb' ) ); |
|
| 291 | - } |
|
| 292 | - $output = self::wrap( array( |
|
| 293 | - 'content' => $output, |
|
| 294 | - 'class' => $aui_bs5 ? $wrap_class : 'custom-control ' . $wrap_class |
|
| 295 | - ) ); |
|
| 296 | - |
|
| 297 | - if ( $args['label_type'] == 'horizontal' ) { |
|
| 298 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
| 299 | - $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
|
| 300 | - } |
|
| 301 | - } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - // allow password field to toggle view |
|
| 305 | - $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
| 149 | + // enqueue the script |
|
| 150 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
| 151 | + $aui_settings->enqueue_iconpicker(); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + if ( $type == 'checkbox' && ( ( ! empty( $args['name'] ) && strpos( $args['name'], '[' ) === false ) || ! empty( $args['with_hidden'] ) ) ) { |
|
| 155 | + $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + // allow clear icon |
|
| 159 | + if ( $args['input_group_right'] === '' && $args['clear_icon'] ) { |
|
| 160 | + $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' ); |
|
| 161 | + $args['input_group_right_inside'] = true; |
|
| 162 | + $align_class = $aui_bs5 ? ' h-100 py-0' : ''; |
|
| 163 | + $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none ' . $align_class . '" onclick="' . $clear_function . '"><span style="font-size: ' . $font_size . 'rem" aria-hidden="true" class="' . ( $aui_bs5 ? 'btn-close' : 'close' ) . '">' . ( $aui_bs5 ? '' : '×' ) . '</span></span>'; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + // open/type |
|
| 167 | + $output .= '<input type="' . $type . '" '; |
|
| 168 | + |
|
| 169 | + // name |
|
| 170 | + if ( ! empty( $args['name'] ) ) { |
|
| 171 | + $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + // id |
|
| 175 | + if ( ! empty( $args['id'] ) ) { |
|
| 176 | + $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + // placeholder |
|
| 180 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
| 181 | + $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + // title |
|
| 185 | + if ( ! empty( $args['title'] ) ) { |
|
| 186 | + $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + // value |
|
| 190 | + if ( ! empty( $args['value'] ) ) { |
|
| 191 | + $output .= AUI_Component_Helper::value( $args['value'] ); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + // checked, for radio and checkboxes |
|
| 195 | + if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
| 196 | + $output .= ' checked '; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + // validation text |
|
| 200 | + if ( ! empty( $args['validation_text'] ) ) { |
|
| 201 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
| 202 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + // validation_pattern |
|
| 206 | + if ( ! empty( $args['validation_pattern'] ) ) { |
|
| 207 | + $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + // step (for numbers) |
|
| 211 | + if ( ! empty( $args['step'] ) ) { |
|
| 212 | + $output .= ' step="' . $args['step'] . '" '; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + // required |
|
| 216 | + if ( ! empty( $args['required'] ) ) { |
|
| 217 | + $output .= ' required '; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + // class |
|
| 221 | + $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
| 222 | + $output .= $aui_bs5 && $type == 'checkbox' ? ' class="' . $class . '" ' : ' class="form-control ' . $class . '" '; |
|
| 223 | + |
|
| 224 | + // data-attributes |
|
| 225 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
| 226 | + |
|
| 227 | + // extra attributes |
|
| 228 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
| 229 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + // close |
|
| 233 | + $output .= ' >'; |
|
| 234 | + |
|
| 235 | + // help text |
|
| 236 | + if ( ! empty( $args['help_text'] ) ) { |
|
| 237 | + $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + // label |
|
| 241 | + if ( ! empty( $args['label'] ) ) { |
|
| 242 | + $label_base_class = ''; |
|
| 243 | + if ( $type == 'file' ) { |
|
| 244 | + $label_base_class = ' custom-file-label'; |
|
| 245 | + } elseif ( $type == 'checkbox' ) { |
|
| 246 | + if ( ! empty( $args['label_force_left'] ) ) { |
|
| 247 | + $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
| 248 | + $help_text = ''; |
|
| 249 | + //$label_args['class'] .= ' d-inline '; |
|
| 250 | + $args['wrap_class'] .= ' align-items-center '; |
|
| 251 | + }else{ |
|
| 252 | + |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + $label_base_class = $aui_bs5 ? ' form-check-label' : ' custom-control-label'; |
|
| 256 | + } |
|
| 257 | + $label_args['class'] .= $label_base_class; |
|
| 258 | + $temp_label_args = $label_args; |
|
| 259 | + if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
| 260 | + $label = self::label( $temp_label_args, $type ); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + // set help text in the correct position |
|
| 267 | + if ( $label_after ) { |
|
| 268 | + $output .= $label . $help_text; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + // some input types need a separate wrap |
|
| 272 | + if ( $type == 'file' ) { |
|
| 273 | + $output = self::wrap( array( |
|
| 274 | + 'content' => $output, |
|
| 275 | + 'class' => $aui_bs5 ? 'mb-3 custom-file' : 'form-group custom-file' |
|
| 276 | + ) ); |
|
| 277 | + } elseif ( $type == 'checkbox' ) { |
|
| 278 | + |
|
| 279 | + $label_args['title'] = $args['label']; |
|
| 280 | + $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
| 281 | + $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
| 282 | + $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
| 283 | + if ( $aui_bs5 ) { |
|
| 284 | + $wrap_class = $args['switch'] ? 'form-check form-switch' . $switch_size_class : 'form-check'; |
|
| 285 | + }else{ |
|
| 286 | + $wrap_class = $args['switch'] ? 'custom-switch' . $switch_size_class : 'custom-checkbox' ; |
|
| 287 | + } |
|
| 288 | + if ( ! empty( $args['label_force_left'] ) ) { |
|
| 289 | + $wrap_class .= $aui_bs5 ? '' : ' d-flex align-content-center'; |
|
| 290 | + $label = str_replace(array("form-check-label","custom-control-label"),"", self::label( $label_args, 'cb' ) ); |
|
| 291 | + } |
|
| 292 | + $output = self::wrap( array( |
|
| 293 | + 'content' => $output, |
|
| 294 | + 'class' => $aui_bs5 ? $wrap_class : 'custom-control ' . $wrap_class |
|
| 295 | + ) ); |
|
| 296 | + |
|
| 297 | + if ( $args['label_type'] == 'horizontal' ) { |
|
| 298 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
| 299 | + $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
|
| 300 | + } |
|
| 301 | + } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + // allow password field to toggle view |
|
| 305 | + $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
| 306 | 306 | onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\'); |
| 307 | 307 | var $eli = jQuery(this).parent().parent().find(\'input\'); |
| 308 | 308 | if($el.hasClass(\'fa-eye\')) |
| 309 | 309 | {$eli.attr(\'type\',\'text\');} |
| 310 | 310 | else{$eli.attr(\'type\',\'password\');}" |
| 311 | 311 | ><i class="far fa-fw fa-eye-slash"></i></span>'; |
| 312 | - } |
|
| 313 | - |
|
| 314 | - // input group wraps |
|
| 315 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
| 316 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
| 317 | - $group_size = $size == 'lg' ? ' input-group-lg' : ''; |
|
| 318 | - $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size; |
|
| 319 | - |
|
| 320 | - if ( $args['input_group_left'] ) { |
|
| 321 | - $output = self::wrap( array( |
|
| 322 | - 'content' => $output, |
|
| 323 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
| 324 | - 'input_group_left' => $args['input_group_left'], |
|
| 325 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
| 326 | - ) ); |
|
| 327 | - } |
|
| 328 | - if ( $args['input_group_right'] ) { |
|
| 329 | - $output = self::wrap( array( |
|
| 330 | - 'content' => $output, |
|
| 331 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
| 332 | - 'input_group_right' => $args['input_group_right'], |
|
| 333 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
| 334 | - ) ); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - if ( ! $label_after ) { |
|
| 340 | - $output .= $help_text; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - |
|
| 344 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
| 345 | - $output = self::wrap( array( |
|
| 346 | - 'content' => $output, |
|
| 347 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
| 348 | - ) ); |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - if ( ! $label_after ) { |
|
| 352 | - $output = $label . $output; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - // wrap |
|
| 356 | - if ( ! $args['no_wrap'] ) { |
|
| 357 | - if ( ! empty( $args['form_group_class'] ) ) { |
|
| 358 | - $fg_class = esc_attr( $args['form_group_class'] ); |
|
| 359 | - }else{ |
|
| 360 | - $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
| 361 | - } |
|
| 362 | - $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : $fg_class; |
|
| 363 | - $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
| 364 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 365 | - $output = self::wrap( array( |
|
| 366 | - 'content' => $output, |
|
| 367 | - 'class' => $wrap_class, |
|
| 368 | - 'element_require' => $args['element_require'], |
|
| 369 | - 'argument_id' => $args['id'], |
|
| 370 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
| 371 | - ) ); |
|
| 372 | - } |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - return $output; |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - public static function label( $args = array(), $type = '' ) { |
|
| 379 | - global $aui_bs5; |
|
| 380 | - //<label for="exampleInputEmail1">Email address</label> |
|
| 381 | - $defaults = array( |
|
| 382 | - 'title' => 'div', |
|
| 383 | - 'for' => '', |
|
| 384 | - 'class' => '', |
|
| 385 | - 'label_type' => '', // empty = hidden, top, horizontal |
|
| 386 | - 'label_col' => '', |
|
| 387 | - ); |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 391 | - */ |
|
| 392 | - $args = wp_parse_args( $args, $defaults ); |
|
| 393 | - $output = ''; |
|
| 394 | - |
|
| 395 | - if ( $args['title'] ) { |
|
| 396 | - |
|
| 397 | - // maybe hide labels //@todo set a global option for visibility class |
|
| 398 | - if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
| 399 | - $class = $args['class']; |
|
| 400 | - } else { |
|
| 401 | - $class = 'sr-only ' . $args['class']; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - // maybe horizontal |
|
| 405 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
| 406 | - $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label '.$type; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - if( $aui_bs5 ){ $class .= ' form-label'; } |
|
| 410 | - |
|
| 411 | - // open |
|
| 412 | - $output .= '<label '; |
|
| 413 | - |
|
| 414 | - // for |
|
| 415 | - if ( ! empty( $args['for'] ) ) { |
|
| 416 | - $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - // class |
|
| 420 | - $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
| 421 | - $output .= ' class="' . $class . '" '; |
|
| 422 | - |
|
| 423 | - // close |
|
| 424 | - $output .= '>'; |
|
| 425 | - |
|
| 426 | - |
|
| 427 | - // title, don't escape fully as can contain html |
|
| 428 | - if ( ! empty( $args['title'] ) ) { |
|
| 429 | - $output .= wp_kses_post( $args['title'] ); |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - // close wrap |
|
| 433 | - $output .= '</label>'; |
|
| 434 | - |
|
| 435 | - |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - |
|
| 439 | - return $output; |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * Wrap some content in a HTML wrapper. |
|
| 444 | - * |
|
| 445 | - * @param array $args |
|
| 446 | - * |
|
| 447 | - * @return string |
|
| 448 | - */ |
|
| 449 | - public static function wrap( $args = array() ) { |
|
| 450 | - global $aui_bs5; |
|
| 451 | - $defaults = array( |
|
| 452 | - 'type' => 'div', |
|
| 453 | - 'class' => $aui_bs5 ? 'mb-3' : 'form-group', |
|
| 454 | - 'content' => '', |
|
| 455 | - 'input_group_left' => '', |
|
| 456 | - 'input_group_right' => '', |
|
| 457 | - 'input_group_left_inside' => false, |
|
| 458 | - 'input_group_right_inside' => false, |
|
| 459 | - 'element_require' => '', |
|
| 460 | - 'argument_id' => '', |
|
| 461 | - 'wrap_attributes' => array() |
|
| 462 | - ); |
|
| 463 | - |
|
| 464 | - /** |
|
| 465 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 466 | - */ |
|
| 467 | - $args = wp_parse_args( $args, $defaults ); |
|
| 468 | - $output = ''; |
|
| 469 | - if ( $args['type'] ) { |
|
| 470 | - |
|
| 471 | - // open |
|
| 472 | - $output .= '<' . sanitize_html_class( $args['type'] ); |
|
| 473 | - |
|
| 474 | - // element require |
|
| 475 | - if ( ! empty( $args['element_require'] ) ) { |
|
| 476 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
| 477 | - $args['class'] .= " aui-conditional-field"; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - // argument_id |
|
| 481 | - if ( ! empty( $args['argument_id'] ) ) { |
|
| 482 | - $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - // class |
|
| 486 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
| 487 | - $output .= ' class="' . $class . '" '; |
|
| 488 | - |
|
| 489 | - // Attributes |
|
| 490 | - if ( ! empty( $args['wrap_attributes'] ) ) { |
|
| 491 | - $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - // close wrap |
|
| 495 | - $output .= ' >'; |
|
| 496 | - |
|
| 497 | - |
|
| 498 | - // Input group left |
|
| 499 | - if ( ! empty( $args['input_group_left'] ) ) { |
|
| 500 | - $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
| 501 | - $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
| 502 | - $output .= $aui_bs5 ? $input_group_left : '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + // input group wraps |
|
| 315 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
| 316 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
| 317 | + $group_size = $size == 'lg' ? ' input-group-lg' : ''; |
|
| 318 | + $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size; |
|
| 319 | + |
|
| 320 | + if ( $args['input_group_left'] ) { |
|
| 321 | + $output = self::wrap( array( |
|
| 322 | + 'content' => $output, |
|
| 323 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
| 324 | + 'input_group_left' => $args['input_group_left'], |
|
| 325 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
| 326 | + ) ); |
|
| 327 | + } |
|
| 328 | + if ( $args['input_group_right'] ) { |
|
| 329 | + $output = self::wrap( array( |
|
| 330 | + 'content' => $output, |
|
| 331 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
| 332 | + 'input_group_right' => $args['input_group_right'], |
|
| 333 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
| 334 | + ) ); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + if ( ! $label_after ) { |
|
| 340 | + $output .= $help_text; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + |
|
| 344 | + if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
| 345 | + $output = self::wrap( array( |
|
| 346 | + 'content' => $output, |
|
| 347 | + 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
| 348 | + ) ); |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + if ( ! $label_after ) { |
|
| 352 | + $output = $label . $output; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + // wrap |
|
| 356 | + if ( ! $args['no_wrap'] ) { |
|
| 357 | + if ( ! empty( $args['form_group_class'] ) ) { |
|
| 358 | + $fg_class = esc_attr( $args['form_group_class'] ); |
|
| 359 | + }else{ |
|
| 360 | + $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
| 361 | + } |
|
| 362 | + $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : $fg_class; |
|
| 363 | + $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
| 364 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 365 | + $output = self::wrap( array( |
|
| 366 | + 'content' => $output, |
|
| 367 | + 'class' => $wrap_class, |
|
| 368 | + 'element_require' => $args['element_require'], |
|
| 369 | + 'argument_id' => $args['id'], |
|
| 370 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
| 371 | + ) ); |
|
| 372 | + } |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + return $output; |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + public static function label( $args = array(), $type = '' ) { |
|
| 379 | + global $aui_bs5; |
|
| 380 | + //<label for="exampleInputEmail1">Email address</label> |
|
| 381 | + $defaults = array( |
|
| 382 | + 'title' => 'div', |
|
| 383 | + 'for' => '', |
|
| 384 | + 'class' => '', |
|
| 385 | + 'label_type' => '', // empty = hidden, top, horizontal |
|
| 386 | + 'label_col' => '', |
|
| 387 | + ); |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 391 | + */ |
|
| 392 | + $args = wp_parse_args( $args, $defaults ); |
|
| 393 | + $output = ''; |
|
| 394 | + |
|
| 395 | + if ( $args['title'] ) { |
|
| 396 | + |
|
| 397 | + // maybe hide labels //@todo set a global option for visibility class |
|
| 398 | + if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
| 399 | + $class = $args['class']; |
|
| 400 | + } else { |
|
| 401 | + $class = 'sr-only ' . $args['class']; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + // maybe horizontal |
|
| 405 | + if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
| 406 | + $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label '.$type; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + if( $aui_bs5 ){ $class .= ' form-label'; } |
|
| 410 | + |
|
| 411 | + // open |
|
| 412 | + $output .= '<label '; |
|
| 413 | + |
|
| 414 | + // for |
|
| 415 | + if ( ! empty( $args['for'] ) ) { |
|
| 416 | + $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + // class |
|
| 420 | + $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
| 421 | + $output .= ' class="' . $class . '" '; |
|
| 422 | + |
|
| 423 | + // close |
|
| 424 | + $output .= '>'; |
|
| 425 | + |
|
| 426 | + |
|
| 427 | + // title, don't escape fully as can contain html |
|
| 428 | + if ( ! empty( $args['title'] ) ) { |
|
| 429 | + $output .= wp_kses_post( $args['title'] ); |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + // close wrap |
|
| 433 | + $output .= '</label>'; |
|
| 434 | + |
|
| 435 | + |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + |
|
| 439 | + return $output; |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * Wrap some content in a HTML wrapper. |
|
| 444 | + * |
|
| 445 | + * @param array $args |
|
| 446 | + * |
|
| 447 | + * @return string |
|
| 448 | + */ |
|
| 449 | + public static function wrap( $args = array() ) { |
|
| 450 | + global $aui_bs5; |
|
| 451 | + $defaults = array( |
|
| 452 | + 'type' => 'div', |
|
| 453 | + 'class' => $aui_bs5 ? 'mb-3' : 'form-group', |
|
| 454 | + 'content' => '', |
|
| 455 | + 'input_group_left' => '', |
|
| 456 | + 'input_group_right' => '', |
|
| 457 | + 'input_group_left_inside' => false, |
|
| 458 | + 'input_group_right_inside' => false, |
|
| 459 | + 'element_require' => '', |
|
| 460 | + 'argument_id' => '', |
|
| 461 | + 'wrap_attributes' => array() |
|
| 462 | + ); |
|
| 463 | + |
|
| 464 | + /** |
|
| 465 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 466 | + */ |
|
| 467 | + $args = wp_parse_args( $args, $defaults ); |
|
| 468 | + $output = ''; |
|
| 469 | + if ( $args['type'] ) { |
|
| 470 | + |
|
| 471 | + // open |
|
| 472 | + $output .= '<' . sanitize_html_class( $args['type'] ); |
|
| 473 | + |
|
| 474 | + // element require |
|
| 475 | + if ( ! empty( $args['element_require'] ) ) { |
|
| 476 | + $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
| 477 | + $args['class'] .= " aui-conditional-field"; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + // argument_id |
|
| 481 | + if ( ! empty( $args['argument_id'] ) ) { |
|
| 482 | + $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + // class |
|
| 486 | + $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
| 487 | + $output .= ' class="' . $class . '" '; |
|
| 488 | + |
|
| 489 | + // Attributes |
|
| 490 | + if ( ! empty( $args['wrap_attributes'] ) ) { |
|
| 491 | + $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + // close wrap |
|
| 495 | + $output .= ' >'; |
|
| 496 | + |
|
| 497 | + |
|
| 498 | + // Input group left |
|
| 499 | + if ( ! empty( $args['input_group_left'] ) ) { |
|
| 500 | + $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
| 501 | + $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
| 502 | + $output .= $aui_bs5 ? $input_group_left : '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
| 503 | 503 | // $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
| 504 | - } |
|
| 504 | + } |
|
| 505 | 505 | |
| 506 | - // content |
|
| 507 | - $output .= $args['content']; |
|
| 506 | + // content |
|
| 507 | + $output .= $args['content']; |
|
| 508 | 508 | |
| 509 | - // Input group right |
|
| 510 | - if ( ! empty( $args['input_group_right'] ) ) { |
|
| 511 | - $position_class = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : ''; |
|
| 512 | - $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
| 513 | - $output .= $aui_bs5 ? str_replace( 'input-group-text','input-group-text top-0 end-0', $input_group_right ) : '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
|
| 509 | + // Input group right |
|
| 510 | + if ( ! empty( $args['input_group_right'] ) ) { |
|
| 511 | + $position_class = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : ''; |
|
| 512 | + $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
| 513 | + $output .= $aui_bs5 ? str_replace( 'input-group-text','input-group-text top-0 end-0', $input_group_right ) : '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
|
| 514 | 514 | // $output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
| 515 | - } |
|
| 516 | - |
|
| 517 | - |
|
| 518 | - // close wrap |
|
| 519 | - $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
| 520 | - |
|
| 521 | - |
|
| 522 | - } else { |
|
| 523 | - $output = $args['content']; |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - return $output; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - /** |
|
| 530 | - * Build the component. |
|
| 531 | - * |
|
| 532 | - * @param array $args |
|
| 533 | - * |
|
| 534 | - * @return string The rendered component. |
|
| 535 | - */ |
|
| 536 | - public static function textarea( $args = array() ) { |
|
| 537 | - global $aui_bs5; |
|
| 538 | - |
|
| 539 | - $defaults = array( |
|
| 540 | - 'name' => '', |
|
| 541 | - 'class' => '', |
|
| 542 | - 'wrap_class' => '', |
|
| 543 | - 'id' => '', |
|
| 544 | - 'placeholder' => '', |
|
| 545 | - 'title' => '', |
|
| 546 | - 'value' => '', |
|
| 547 | - 'required' => false, |
|
| 548 | - 'label' => '', |
|
| 549 | - 'label_after' => false, |
|
| 550 | - 'label_class' => '', |
|
| 551 | - 'label_type' => '', |
|
| 552 | - 'label_col' => '', |
|
| 553 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 554 | - 'input_group_right' => '', |
|
| 555 | - 'input_group_left' => '', |
|
| 556 | - 'input_group_right_inside' => false, |
|
| 557 | - 'form_group_class' => '', |
|
| 558 | - 'help_text' => '', |
|
| 559 | - 'validation_text' => '', |
|
| 560 | - 'validation_pattern' => '', |
|
| 561 | - 'no_wrap' => false, |
|
| 562 | - 'rows' => '', |
|
| 563 | - 'wysiwyg' => false, |
|
| 564 | - 'allow_tags' => false, |
|
| 565 | - // Allow HTML tags |
|
| 566 | - 'element_require' => '', |
|
| 567 | - // [%element_id%] == "1" |
|
| 568 | - 'extra_attributes' => array(), |
|
| 569 | - // an array of extra attributes |
|
| 570 | - 'wrap_attributes' => array(), |
|
| 571 | - ); |
|
| 572 | - |
|
| 573 | - /** |
|
| 574 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 575 | - */ |
|
| 576 | - $args = wp_parse_args( $args, $defaults ); |
|
| 577 | - $output = ''; |
|
| 578 | - $label = ''; |
|
| 579 | - |
|
| 580 | - // hidden label option needs to be empty |
|
| 581 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
| 582 | - |
|
| 583 | - // floating labels don't work with wysiwyg so set it as top |
|
| 584 | - if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
| 585 | - $args['label_type'] = 'top'; |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - $label_after = $args['label_after']; |
|
| 589 | - |
|
| 590 | - // floating labels need label after |
|
| 591 | - if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
| 592 | - $label_after = true; |
|
| 593 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - // label |
|
| 597 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
| 598 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
| 599 | - $label_args = array( |
|
| 600 | - 'title' => $args['label'], |
|
| 601 | - 'for' => $args['id'], |
|
| 602 | - 'class' => $args['label_class'] . " ", |
|
| 603 | - 'label_type' => $args['label_type'], |
|
| 604 | - 'label_col' => $args['label_col'] |
|
| 605 | - ); |
|
| 606 | - $label .= self::label( $label_args ); |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - // maybe horizontal label |
|
| 610 | - if ( $args['label_type'] == 'horizontal' ) { |
|
| 611 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
| 612 | - $label .= '<div class="' . $input_col . '">'; |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - if ( ! empty( $args['wysiwyg'] ) ) { |
|
| 616 | - ob_start(); |
|
| 617 | - $content = $args['value']; |
|
| 618 | - $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
| 619 | - $settings = array( |
|
| 620 | - 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
| 621 | - 'quicktags' => false, |
|
| 622 | - 'media_buttons' => false, |
|
| 623 | - 'editor_class' => 'form-control', |
|
| 624 | - 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
| 625 | - 'teeny' => true, |
|
| 626 | - ); |
|
| 627 | - |
|
| 628 | - // maybe set settings if array |
|
| 629 | - if ( is_array( $args['wysiwyg'] ) ) { |
|
| 630 | - $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - wp_editor( $content, $editor_id, $settings ); |
|
| 634 | - $output .= ob_get_clean(); |
|
| 635 | - } else { |
|
| 636 | - |
|
| 637 | - // open |
|
| 638 | - $output .= '<textarea '; |
|
| 639 | - |
|
| 640 | - // name |
|
| 641 | - if ( ! empty( $args['name'] ) ) { |
|
| 642 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - // id |
|
| 646 | - if ( ! empty( $args['id'] ) ) { |
|
| 647 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - // placeholder |
|
| 651 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
| 652 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - // title |
|
| 656 | - if ( ! empty( $args['title'] ) ) { |
|
| 657 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - // validation text |
|
| 661 | - if ( ! empty( $args['validation_text'] ) ) { |
|
| 662 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
| 663 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - // validation_pattern |
|
| 667 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
| 668 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - // required |
|
| 672 | - if ( ! empty( $args['required'] ) ) { |
|
| 673 | - $output .= ' required '; |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - // rows |
|
| 677 | - if ( ! empty( $args['rows'] ) ) { |
|
| 678 | - $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - |
|
| 682 | - // class |
|
| 683 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
| 684 | - $output .= ' class="form-control ' . $class . '" '; |
|
| 685 | - |
|
| 686 | - // extra attributes |
|
| 687 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
| 688 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - // close tag |
|
| 692 | - $output .= ' >'; |
|
| 693 | - |
|
| 694 | - // value |
|
| 695 | - if ( ! empty( $args['value'] ) ) { |
|
| 696 | - if ( ! empty( $args['allow_tags'] ) ) { |
|
| 697 | - $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
| 698 | - } else { |
|
| 699 | - $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] ); |
|
| 700 | - } |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - // closing tag |
|
| 704 | - $output .= '</textarea>'; |
|
| 705 | - |
|
| 706 | - |
|
| 707 | - // input group wraps |
|
| 708 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
| 709 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
| 710 | - if ( $args['input_group_left'] ) { |
|
| 711 | - $output = self::wrap( array( |
|
| 712 | - 'content' => $output, |
|
| 713 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 714 | - 'input_group_left' => $args['input_group_left'], |
|
| 715 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
| 716 | - ) ); |
|
| 717 | - } |
|
| 718 | - if ( $args['input_group_right'] ) { |
|
| 719 | - $output = self::wrap( array( |
|
| 720 | - 'content' => $output, |
|
| 721 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 722 | - 'input_group_right' => $args['input_group_right'], |
|
| 723 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
| 724 | - ) ); |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - if ( ! empty( $args['label'] ) && $label_after ) { |
|
| 733 | - $label_args = array( |
|
| 734 | - 'title' => $args['label'], |
|
| 735 | - 'for' => $args['id'], |
|
| 736 | - 'class' => $args['label_class'] . " ", |
|
| 737 | - 'label_type' => $args['label_type'], |
|
| 738 | - 'label_col' => $args['label_col'] |
|
| 739 | - ); |
|
| 740 | - $output .= self::label( $label_args ); |
|
| 741 | - } |
|
| 742 | - |
|
| 743 | - // help text |
|
| 744 | - if ( ! empty( $args['help_text'] ) ) { |
|
| 745 | - $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - if ( ! $label_after ) { |
|
| 749 | - $output = $label . $output; |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - // maybe horizontal label |
|
| 753 | - if ( $args['label_type'] == 'horizontal' ) { |
|
| 754 | - $output .= '</div>'; |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - |
|
| 758 | - // wrap |
|
| 759 | - if ( ! $args['no_wrap'] ) { |
|
| 760 | - if ( ! empty( $args['form_group_class'] ) ) { |
|
| 761 | - $fg_class = esc_attr( $args['form_group_class'] ); |
|
| 762 | - }else{ |
|
| 763 | - $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
| 764 | - } |
|
| 765 | - $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : $fg_class; |
|
| 766 | - $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
| 767 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 768 | - $output = self::wrap( array( |
|
| 769 | - 'content' => $output, |
|
| 770 | - 'class' => $wrap_class, |
|
| 771 | - 'element_require' => $args['element_require'], |
|
| 772 | - 'argument_id' => $args['id'], |
|
| 773 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
| 774 | - ) ); |
|
| 775 | - } |
|
| 776 | - |
|
| 777 | - |
|
| 778 | - return $output; |
|
| 779 | - } |
|
| 780 | - |
|
| 781 | - /** |
|
| 782 | - * Build the component. |
|
| 783 | - * |
|
| 784 | - * @param array $args |
|
| 785 | - * |
|
| 786 | - * @return string The rendered component. |
|
| 787 | - */ |
|
| 788 | - public static function select( $args = array() ) { |
|
| 789 | - global $aui_bs5; |
|
| 790 | - $defaults = array( |
|
| 791 | - 'class' => '', |
|
| 792 | - 'wrap_class' => '', |
|
| 793 | - 'id' => '', |
|
| 794 | - 'title' => '', |
|
| 795 | - 'value' => '', |
|
| 796 | - // can be an array or a string |
|
| 797 | - 'required' => false, |
|
| 798 | - 'label' => '', |
|
| 799 | - 'label_after' => false, |
|
| 800 | - 'label_type' => '', |
|
| 801 | - 'label_col' => '', |
|
| 802 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 803 | - 'label_class' => '', |
|
| 804 | - 'help_text' => '', |
|
| 805 | - 'placeholder' => '', |
|
| 806 | - 'options' => array(), |
|
| 807 | - // array or string |
|
| 808 | - 'icon' => '', |
|
| 809 | - 'multiple' => false, |
|
| 810 | - 'select2' => false, |
|
| 811 | - 'no_wrap' => false, |
|
| 812 | - 'input_group_right' => '', |
|
| 813 | - 'input_group_left' => '', |
|
| 814 | - 'input_group_right_inside' => false, // forces the input group inside the input |
|
| 815 | - 'input_group_left_inside' => false, // forces the input group inside the input |
|
| 816 | - 'form_group_class' => '', |
|
| 817 | - 'element_require' => '', |
|
| 818 | - // [%element_id%] == "1" |
|
| 819 | - 'extra_attributes' => array(), |
|
| 820 | - // an array of extra attributes |
|
| 821 | - 'wrap_attributes' => array(), |
|
| 822 | - ); |
|
| 823 | - |
|
| 824 | - /** |
|
| 825 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 826 | - */ |
|
| 827 | - $args = wp_parse_args( $args, $defaults ); |
|
| 828 | - $output = ''; |
|
| 829 | - |
|
| 830 | - // for now lets hide floating labels |
|
| 831 | - if ( $args['label_type'] == 'floating' ) { |
|
| 832 | - $args['label_type'] = 'hidden'; |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - // hidden label option needs to be empty |
|
| 836 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
| 837 | - |
|
| 838 | - |
|
| 839 | - $label_after = $args['label_after']; |
|
| 840 | - |
|
| 841 | - // floating labels need label after |
|
| 842 | - if ( $args['label_type'] == 'floating' ) { |
|
| 843 | - $label_after = true; |
|
| 844 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - // Maybe setup select2 |
|
| 848 | - $is_select2 = false; |
|
| 849 | - if ( ! empty( $args['select2'] ) ) { |
|
| 850 | - $args['class'] .= ' aui-select2'; |
|
| 851 | - $is_select2 = true; |
|
| 852 | - } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
| 853 | - $is_select2 = true; |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - // select2 tags |
|
| 857 | - if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
| 858 | - $args['data-tags'] = 'true'; |
|
| 859 | - $args['data-token-separators'] = "[',']"; |
|
| 860 | - $args['multiple'] = true; |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - // select2 placeholder |
|
| 864 | - if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
| 865 | - $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
| 866 | - $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
| 867 | - } |
|
| 868 | - |
|
| 869 | - // Set hidden input to save empty value for multiselect. |
|
| 870 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
| 871 | - $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>'; |
|
| 872 | - } |
|
| 873 | - |
|
| 874 | - // open/type |
|
| 875 | - $output .= '<select '; |
|
| 876 | - |
|
| 877 | - // style |
|
| 878 | - if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
| 879 | - $output .= " style='width:100%;' "; |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - // element require |
|
| 883 | - if ( ! empty( $args['element_require'] ) ) { |
|
| 884 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
| 885 | - $args['class'] .= " aui-conditional-field"; |
|
| 886 | - } |
|
| 887 | - |
|
| 888 | - // class |
|
| 889 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
| 890 | - $select_class = $aui_bs5 ? 'form-select ' : 'custom-select '; |
|
| 891 | - $output .= AUI_Component_Helper::class_attr( $select_class . $class ); |
|
| 892 | - |
|
| 893 | - // name |
|
| 894 | - if ( ! empty( $args['name'] ) ) { |
|
| 895 | - $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
| 896 | - } |
|
| 897 | - |
|
| 898 | - // id |
|
| 899 | - if ( ! empty( $args['id'] ) ) { |
|
| 900 | - $output .= AUI_Component_Helper::id( $args['id'] ); |
|
| 901 | - } |
|
| 902 | - |
|
| 903 | - // title |
|
| 904 | - if ( ! empty( $args['title'] ) ) { |
|
| 905 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - // data-attributes |
|
| 909 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
| 910 | - |
|
| 911 | - // aria-attributes |
|
| 912 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
| 913 | - |
|
| 914 | - // extra attributes |
|
| 915 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
| 916 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - // required |
|
| 920 | - if ( ! empty( $args['required'] ) ) { |
|
| 921 | - $output .= ' required '; |
|
| 922 | - } |
|
| 923 | - |
|
| 924 | - // multiple |
|
| 925 | - if ( ! empty( $args['multiple'] ) ) { |
|
| 926 | - $output .= ' multiple '; |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - // close opening tag |
|
| 930 | - $output .= ' >'; |
|
| 931 | - |
|
| 932 | - // placeholder |
|
| 933 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
| 934 | - $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
| 935 | - } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
| 936 | - $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
| 937 | - } |
|
| 938 | - |
|
| 939 | - // Options |
|
| 940 | - if ( ! empty( $args['options'] ) ) { |
|
| 941 | - |
|
| 942 | - if ( ! is_array( $args['options'] ) ) { |
|
| 943 | - $output .= $args['options']; // not the preferred way but an option |
|
| 944 | - } else { |
|
| 945 | - foreach ( $args['options'] as $val => $name ) { |
|
| 946 | - $selected = ''; |
|
| 947 | - if ( is_array( $name ) ) { |
|
| 948 | - if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
| 949 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
| 950 | - |
|
| 951 | - $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
| 952 | - } else { |
|
| 953 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
| 954 | - $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
| 955 | - $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
| 956 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
| 957 | - $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
| 958 | - } elseif ( ! empty( $args['value'] ) ) { |
|
| 959 | - $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
| 960 | - } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) { |
|
| 961 | - $selected = selected( $option_value, $args['value'], false ); |
|
| 962 | - } |
|
| 963 | - |
|
| 964 | - $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
| 965 | - } |
|
| 966 | - } else { |
|
| 967 | - if ( ! empty( $args['value'] ) ) { |
|
| 968 | - if ( is_array( $args['value'] ) ) { |
|
| 969 | - $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
| 970 | - } elseif ( ! empty( $args['value'] ) ) { |
|
| 971 | - $selected = selected( $args['value'], $val, false ); |
|
| 972 | - } |
|
| 973 | - } elseif ( $args['value'] === $val ) { |
|
| 974 | - $selected = selected( $args['value'], $val, false ); |
|
| 975 | - } |
|
| 976 | - $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
| 977 | - } |
|
| 978 | - } |
|
| 979 | - } |
|
| 980 | - |
|
| 981 | - } |
|
| 982 | - |
|
| 983 | - // closing tag |
|
| 984 | - $output .= '</select>'; |
|
| 985 | - |
|
| 986 | - $label = ''; |
|
| 987 | - $help_text = ''; |
|
| 988 | - // label |
|
| 989 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
| 990 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
| 991 | - $label_args = array( |
|
| 992 | - 'title' => $args['label'], |
|
| 993 | - 'for' => $args['id'], |
|
| 994 | - 'class' => $args['label_class'] . " ", |
|
| 995 | - 'label_type' => $args['label_type'], |
|
| 996 | - 'label_col' => $args['label_col'] |
|
| 997 | - ); |
|
| 998 | - $label = self::label( $label_args ); |
|
| 999 | - } |
|
| 1000 | - |
|
| 1001 | - // help text |
|
| 1002 | - if ( ! empty( $args['help_text'] ) ) { |
|
| 1003 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
| 1004 | - } |
|
| 1005 | - |
|
| 1006 | - // input group wraps |
|
| 1007 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
| 1008 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
| 1009 | - if ( $args['input_group_left'] ) { |
|
| 1010 | - $output = self::wrap( array( |
|
| 1011 | - 'content' => $output, |
|
| 1012 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 1013 | - 'input_group_left' => $args['input_group_left'], |
|
| 1014 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
| 1015 | - ) ); |
|
| 1016 | - } |
|
| 1017 | - if ( $args['input_group_right'] ) { |
|
| 1018 | - $output = self::wrap( array( |
|
| 1019 | - 'content' => $output, |
|
| 1020 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 1021 | - 'input_group_right' => $args['input_group_right'], |
|
| 1022 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
| 1023 | - ) ); |
|
| 1024 | - } |
|
| 1025 | - |
|
| 1026 | - } |
|
| 1027 | - |
|
| 1028 | - if ( ! $label_after ) { |
|
| 1029 | - $output .= $help_text; |
|
| 1030 | - } |
|
| 1031 | - |
|
| 1032 | - |
|
| 1033 | - if ( $args['label_type'] == 'horizontal' ) { |
|
| 1034 | - $output = self::wrap( array( |
|
| 1035 | - 'content' => $output, |
|
| 1036 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
| 1037 | - ) ); |
|
| 1038 | - } |
|
| 1039 | - |
|
| 1040 | - if ( ! $label_after ) { |
|
| 1041 | - $output = $label . $output; |
|
| 1042 | - } |
|
| 1043 | - |
|
| 1044 | - // maybe horizontal label |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + |
|
| 518 | + // close wrap |
|
| 519 | + $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
| 520 | + |
|
| 521 | + |
|
| 522 | + } else { |
|
| 523 | + $output = $args['content']; |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + return $output; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + /** |
|
| 530 | + * Build the component. |
|
| 531 | + * |
|
| 532 | + * @param array $args |
|
| 533 | + * |
|
| 534 | + * @return string The rendered component. |
|
| 535 | + */ |
|
| 536 | + public static function textarea( $args = array() ) { |
|
| 537 | + global $aui_bs5; |
|
| 538 | + |
|
| 539 | + $defaults = array( |
|
| 540 | + 'name' => '', |
|
| 541 | + 'class' => '', |
|
| 542 | + 'wrap_class' => '', |
|
| 543 | + 'id' => '', |
|
| 544 | + 'placeholder' => '', |
|
| 545 | + 'title' => '', |
|
| 546 | + 'value' => '', |
|
| 547 | + 'required' => false, |
|
| 548 | + 'label' => '', |
|
| 549 | + 'label_after' => false, |
|
| 550 | + 'label_class' => '', |
|
| 551 | + 'label_type' => '', |
|
| 552 | + 'label_col' => '', |
|
| 553 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 554 | + 'input_group_right' => '', |
|
| 555 | + 'input_group_left' => '', |
|
| 556 | + 'input_group_right_inside' => false, |
|
| 557 | + 'form_group_class' => '', |
|
| 558 | + 'help_text' => '', |
|
| 559 | + 'validation_text' => '', |
|
| 560 | + 'validation_pattern' => '', |
|
| 561 | + 'no_wrap' => false, |
|
| 562 | + 'rows' => '', |
|
| 563 | + 'wysiwyg' => false, |
|
| 564 | + 'allow_tags' => false, |
|
| 565 | + // Allow HTML tags |
|
| 566 | + 'element_require' => '', |
|
| 567 | + // [%element_id%] == "1" |
|
| 568 | + 'extra_attributes' => array(), |
|
| 569 | + // an array of extra attributes |
|
| 570 | + 'wrap_attributes' => array(), |
|
| 571 | + ); |
|
| 572 | + |
|
| 573 | + /** |
|
| 574 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 575 | + */ |
|
| 576 | + $args = wp_parse_args( $args, $defaults ); |
|
| 577 | + $output = ''; |
|
| 578 | + $label = ''; |
|
| 579 | + |
|
| 580 | + // hidden label option needs to be empty |
|
| 581 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
| 582 | + |
|
| 583 | + // floating labels don't work with wysiwyg so set it as top |
|
| 584 | + if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
| 585 | + $args['label_type'] = 'top'; |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + $label_after = $args['label_after']; |
|
| 589 | + |
|
| 590 | + // floating labels need label after |
|
| 591 | + if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
| 592 | + $label_after = true; |
|
| 593 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + // label |
|
| 597 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
| 598 | + } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
| 599 | + $label_args = array( |
|
| 600 | + 'title' => $args['label'], |
|
| 601 | + 'for' => $args['id'], |
|
| 602 | + 'class' => $args['label_class'] . " ", |
|
| 603 | + 'label_type' => $args['label_type'], |
|
| 604 | + 'label_col' => $args['label_col'] |
|
| 605 | + ); |
|
| 606 | + $label .= self::label( $label_args ); |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + // maybe horizontal label |
|
| 610 | + if ( $args['label_type'] == 'horizontal' ) { |
|
| 611 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
| 612 | + $label .= '<div class="' . $input_col . '">'; |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + if ( ! empty( $args['wysiwyg'] ) ) { |
|
| 616 | + ob_start(); |
|
| 617 | + $content = $args['value']; |
|
| 618 | + $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
| 619 | + $settings = array( |
|
| 620 | + 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
| 621 | + 'quicktags' => false, |
|
| 622 | + 'media_buttons' => false, |
|
| 623 | + 'editor_class' => 'form-control', |
|
| 624 | + 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
| 625 | + 'teeny' => true, |
|
| 626 | + ); |
|
| 627 | + |
|
| 628 | + // maybe set settings if array |
|
| 629 | + if ( is_array( $args['wysiwyg'] ) ) { |
|
| 630 | + $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + wp_editor( $content, $editor_id, $settings ); |
|
| 634 | + $output .= ob_get_clean(); |
|
| 635 | + } else { |
|
| 636 | + |
|
| 637 | + // open |
|
| 638 | + $output .= '<textarea '; |
|
| 639 | + |
|
| 640 | + // name |
|
| 641 | + if ( ! empty( $args['name'] ) ) { |
|
| 642 | + $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + // id |
|
| 646 | + if ( ! empty( $args['id'] ) ) { |
|
| 647 | + $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + // placeholder |
|
| 651 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
| 652 | + $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + // title |
|
| 656 | + if ( ! empty( $args['title'] ) ) { |
|
| 657 | + $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + // validation text |
|
| 661 | + if ( ! empty( $args['validation_text'] ) ) { |
|
| 662 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
| 663 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + // validation_pattern |
|
| 667 | + if ( ! empty( $args['validation_pattern'] ) ) { |
|
| 668 | + $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + // required |
|
| 672 | + if ( ! empty( $args['required'] ) ) { |
|
| 673 | + $output .= ' required '; |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + // rows |
|
| 677 | + if ( ! empty( $args['rows'] ) ) { |
|
| 678 | + $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + |
|
| 682 | + // class |
|
| 683 | + $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
| 684 | + $output .= ' class="form-control ' . $class . '" '; |
|
| 685 | + |
|
| 686 | + // extra attributes |
|
| 687 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
| 688 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + // close tag |
|
| 692 | + $output .= ' >'; |
|
| 693 | + |
|
| 694 | + // value |
|
| 695 | + if ( ! empty( $args['value'] ) ) { |
|
| 696 | + if ( ! empty( $args['allow_tags'] ) ) { |
|
| 697 | + $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
| 698 | + } else { |
|
| 699 | + $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] ); |
|
| 700 | + } |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + // closing tag |
|
| 704 | + $output .= '</textarea>'; |
|
| 705 | + |
|
| 706 | + |
|
| 707 | + // input group wraps |
|
| 708 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
| 709 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
| 710 | + if ( $args['input_group_left'] ) { |
|
| 711 | + $output = self::wrap( array( |
|
| 712 | + 'content' => $output, |
|
| 713 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 714 | + 'input_group_left' => $args['input_group_left'], |
|
| 715 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
| 716 | + ) ); |
|
| 717 | + } |
|
| 718 | + if ( $args['input_group_right'] ) { |
|
| 719 | + $output = self::wrap( array( |
|
| 720 | + 'content' => $output, |
|
| 721 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 722 | + 'input_group_right' => $args['input_group_right'], |
|
| 723 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
| 724 | + ) ); |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + if ( ! empty( $args['label'] ) && $label_after ) { |
|
| 733 | + $label_args = array( |
|
| 734 | + 'title' => $args['label'], |
|
| 735 | + 'for' => $args['id'], |
|
| 736 | + 'class' => $args['label_class'] . " ", |
|
| 737 | + 'label_type' => $args['label_type'], |
|
| 738 | + 'label_col' => $args['label_col'] |
|
| 739 | + ); |
|
| 740 | + $output .= self::label( $label_args ); |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + // help text |
|
| 744 | + if ( ! empty( $args['help_text'] ) ) { |
|
| 745 | + $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + if ( ! $label_after ) { |
|
| 749 | + $output = $label . $output; |
|
| 750 | + } |
|
| 751 | + |
|
| 752 | + // maybe horizontal label |
|
| 753 | + if ( $args['label_type'] == 'horizontal' ) { |
|
| 754 | + $output .= '</div>'; |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + |
|
| 758 | + // wrap |
|
| 759 | + if ( ! $args['no_wrap'] ) { |
|
| 760 | + if ( ! empty( $args['form_group_class'] ) ) { |
|
| 761 | + $fg_class = esc_attr( $args['form_group_class'] ); |
|
| 762 | + }else{ |
|
| 763 | + $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
| 764 | + } |
|
| 765 | + $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : $fg_class; |
|
| 766 | + $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
| 767 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 768 | + $output = self::wrap( array( |
|
| 769 | + 'content' => $output, |
|
| 770 | + 'class' => $wrap_class, |
|
| 771 | + 'element_require' => $args['element_require'], |
|
| 772 | + 'argument_id' => $args['id'], |
|
| 773 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
| 774 | + ) ); |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + |
|
| 778 | + return $output; |
|
| 779 | + } |
|
| 780 | + |
|
| 781 | + /** |
|
| 782 | + * Build the component. |
|
| 783 | + * |
|
| 784 | + * @param array $args |
|
| 785 | + * |
|
| 786 | + * @return string The rendered component. |
|
| 787 | + */ |
|
| 788 | + public static function select( $args = array() ) { |
|
| 789 | + global $aui_bs5; |
|
| 790 | + $defaults = array( |
|
| 791 | + 'class' => '', |
|
| 792 | + 'wrap_class' => '', |
|
| 793 | + 'id' => '', |
|
| 794 | + 'title' => '', |
|
| 795 | + 'value' => '', |
|
| 796 | + // can be an array or a string |
|
| 797 | + 'required' => false, |
|
| 798 | + 'label' => '', |
|
| 799 | + 'label_after' => false, |
|
| 800 | + 'label_type' => '', |
|
| 801 | + 'label_col' => '', |
|
| 802 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 803 | + 'label_class' => '', |
|
| 804 | + 'help_text' => '', |
|
| 805 | + 'placeholder' => '', |
|
| 806 | + 'options' => array(), |
|
| 807 | + // array or string |
|
| 808 | + 'icon' => '', |
|
| 809 | + 'multiple' => false, |
|
| 810 | + 'select2' => false, |
|
| 811 | + 'no_wrap' => false, |
|
| 812 | + 'input_group_right' => '', |
|
| 813 | + 'input_group_left' => '', |
|
| 814 | + 'input_group_right_inside' => false, // forces the input group inside the input |
|
| 815 | + 'input_group_left_inside' => false, // forces the input group inside the input |
|
| 816 | + 'form_group_class' => '', |
|
| 817 | + 'element_require' => '', |
|
| 818 | + // [%element_id%] == "1" |
|
| 819 | + 'extra_attributes' => array(), |
|
| 820 | + // an array of extra attributes |
|
| 821 | + 'wrap_attributes' => array(), |
|
| 822 | + ); |
|
| 823 | + |
|
| 824 | + /** |
|
| 825 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 826 | + */ |
|
| 827 | + $args = wp_parse_args( $args, $defaults ); |
|
| 828 | + $output = ''; |
|
| 829 | + |
|
| 830 | + // for now lets hide floating labels |
|
| 831 | + if ( $args['label_type'] == 'floating' ) { |
|
| 832 | + $args['label_type'] = 'hidden'; |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + // hidden label option needs to be empty |
|
| 836 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
| 837 | + |
|
| 838 | + |
|
| 839 | + $label_after = $args['label_after']; |
|
| 840 | + |
|
| 841 | + // floating labels need label after |
|
| 842 | + if ( $args['label_type'] == 'floating' ) { |
|
| 843 | + $label_after = true; |
|
| 844 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + // Maybe setup select2 |
|
| 848 | + $is_select2 = false; |
|
| 849 | + if ( ! empty( $args['select2'] ) ) { |
|
| 850 | + $args['class'] .= ' aui-select2'; |
|
| 851 | + $is_select2 = true; |
|
| 852 | + } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
| 853 | + $is_select2 = true; |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + // select2 tags |
|
| 857 | + if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
| 858 | + $args['data-tags'] = 'true'; |
|
| 859 | + $args['data-token-separators'] = "[',']"; |
|
| 860 | + $args['multiple'] = true; |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + // select2 placeholder |
|
| 864 | + if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
| 865 | + $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
| 866 | + $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + // Set hidden input to save empty value for multiselect. |
|
| 870 | + if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
| 871 | + $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>'; |
|
| 872 | + } |
|
| 873 | + |
|
| 874 | + // open/type |
|
| 875 | + $output .= '<select '; |
|
| 876 | + |
|
| 877 | + // style |
|
| 878 | + if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
| 879 | + $output .= " style='width:100%;' "; |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + // element require |
|
| 883 | + if ( ! empty( $args['element_require'] ) ) { |
|
| 884 | + $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
| 885 | + $args['class'] .= " aui-conditional-field"; |
|
| 886 | + } |
|
| 887 | + |
|
| 888 | + // class |
|
| 889 | + $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
| 890 | + $select_class = $aui_bs5 ? 'form-select ' : 'custom-select '; |
|
| 891 | + $output .= AUI_Component_Helper::class_attr( $select_class . $class ); |
|
| 892 | + |
|
| 893 | + // name |
|
| 894 | + if ( ! empty( $args['name'] ) ) { |
|
| 895 | + $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
| 896 | + } |
|
| 897 | + |
|
| 898 | + // id |
|
| 899 | + if ( ! empty( $args['id'] ) ) { |
|
| 900 | + $output .= AUI_Component_Helper::id( $args['id'] ); |
|
| 901 | + } |
|
| 902 | + |
|
| 903 | + // title |
|
| 904 | + if ( ! empty( $args['title'] ) ) { |
|
| 905 | + $output .= AUI_Component_Helper::title( $args['title'] ); |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + // data-attributes |
|
| 909 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
| 910 | + |
|
| 911 | + // aria-attributes |
|
| 912 | + $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
| 913 | + |
|
| 914 | + // extra attributes |
|
| 915 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
| 916 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + // required |
|
| 920 | + if ( ! empty( $args['required'] ) ) { |
|
| 921 | + $output .= ' required '; |
|
| 922 | + } |
|
| 923 | + |
|
| 924 | + // multiple |
|
| 925 | + if ( ! empty( $args['multiple'] ) ) { |
|
| 926 | + $output .= ' multiple '; |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + // close opening tag |
|
| 930 | + $output .= ' >'; |
|
| 931 | + |
|
| 932 | + // placeholder |
|
| 933 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
| 934 | + $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
| 935 | + } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
| 936 | + $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
| 937 | + } |
|
| 938 | + |
|
| 939 | + // Options |
|
| 940 | + if ( ! empty( $args['options'] ) ) { |
|
| 941 | + |
|
| 942 | + if ( ! is_array( $args['options'] ) ) { |
|
| 943 | + $output .= $args['options']; // not the preferred way but an option |
|
| 944 | + } else { |
|
| 945 | + foreach ( $args['options'] as $val => $name ) { |
|
| 946 | + $selected = ''; |
|
| 947 | + if ( is_array( $name ) ) { |
|
| 948 | + if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
| 949 | + $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
| 950 | + |
|
| 951 | + $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
| 952 | + } else { |
|
| 953 | + $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
| 954 | + $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
| 955 | + $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
| 956 | + if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
| 957 | + $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
| 958 | + } elseif ( ! empty( $args['value'] ) ) { |
|
| 959 | + $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
| 960 | + } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) { |
|
| 961 | + $selected = selected( $option_value, $args['value'], false ); |
|
| 962 | + } |
|
| 963 | + |
|
| 964 | + $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
| 965 | + } |
|
| 966 | + } else { |
|
| 967 | + if ( ! empty( $args['value'] ) ) { |
|
| 968 | + if ( is_array( $args['value'] ) ) { |
|
| 969 | + $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
| 970 | + } elseif ( ! empty( $args['value'] ) ) { |
|
| 971 | + $selected = selected( $args['value'], $val, false ); |
|
| 972 | + } |
|
| 973 | + } elseif ( $args['value'] === $val ) { |
|
| 974 | + $selected = selected( $args['value'], $val, false ); |
|
| 975 | + } |
|
| 976 | + $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
| 977 | + } |
|
| 978 | + } |
|
| 979 | + } |
|
| 980 | + |
|
| 981 | + } |
|
| 982 | + |
|
| 983 | + // closing tag |
|
| 984 | + $output .= '</select>'; |
|
| 985 | + |
|
| 986 | + $label = ''; |
|
| 987 | + $help_text = ''; |
|
| 988 | + // label |
|
| 989 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
| 990 | + } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
| 991 | + $label_args = array( |
|
| 992 | + 'title' => $args['label'], |
|
| 993 | + 'for' => $args['id'], |
|
| 994 | + 'class' => $args['label_class'] . " ", |
|
| 995 | + 'label_type' => $args['label_type'], |
|
| 996 | + 'label_col' => $args['label_col'] |
|
| 997 | + ); |
|
| 998 | + $label = self::label( $label_args ); |
|
| 999 | + } |
|
| 1000 | + |
|
| 1001 | + // help text |
|
| 1002 | + if ( ! empty( $args['help_text'] ) ) { |
|
| 1003 | + $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
| 1004 | + } |
|
| 1005 | + |
|
| 1006 | + // input group wraps |
|
| 1007 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
| 1008 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
| 1009 | + if ( $args['input_group_left'] ) { |
|
| 1010 | + $output = self::wrap( array( |
|
| 1011 | + 'content' => $output, |
|
| 1012 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 1013 | + 'input_group_left' => $args['input_group_left'], |
|
| 1014 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
| 1015 | + ) ); |
|
| 1016 | + } |
|
| 1017 | + if ( $args['input_group_right'] ) { |
|
| 1018 | + $output = self::wrap( array( |
|
| 1019 | + 'content' => $output, |
|
| 1020 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
| 1021 | + 'input_group_right' => $args['input_group_right'], |
|
| 1022 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
| 1023 | + ) ); |
|
| 1024 | + } |
|
| 1025 | + |
|
| 1026 | + } |
|
| 1027 | + |
|
| 1028 | + if ( ! $label_after ) { |
|
| 1029 | + $output .= $help_text; |
|
| 1030 | + } |
|
| 1031 | + |
|
| 1032 | + |
|
| 1033 | + if ( $args['label_type'] == 'horizontal' ) { |
|
| 1034 | + $output = self::wrap( array( |
|
| 1035 | + 'content' => $output, |
|
| 1036 | + 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
| 1037 | + ) ); |
|
| 1038 | + } |
|
| 1039 | + |
|
| 1040 | + if ( ! $label_after ) { |
|
| 1041 | + $output = $label . $output; |
|
| 1042 | + } |
|
| 1043 | + |
|
| 1044 | + // maybe horizontal label |
|
| 1045 | 1045 | // if ( $args['label_type'] == 'horizontal' ) { |
| 1046 | 1046 | // $output .= '</div>'; |
| 1047 | 1047 | // } |
| 1048 | 1048 | |
| 1049 | 1049 | |
| 1050 | - // wrap |
|
| 1051 | - if ( ! $args['no_wrap'] ) { |
|
| 1052 | - if ( ! empty( $args['form_group_class'] ) ) { |
|
| 1053 | - $fg_class = esc_attr( $args['form_group_class'] ); |
|
| 1054 | - }else{ |
|
| 1055 | - $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
| 1056 | - } |
|
| 1057 | - $wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class; |
|
| 1058 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 1059 | - $output = self::wrap( array( |
|
| 1060 | - 'content' => $output, |
|
| 1061 | - 'class' => $wrap_class, |
|
| 1062 | - 'element_require' => $args['element_require'], |
|
| 1063 | - 'argument_id' => $args['id'], |
|
| 1064 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
| 1065 | - ) ); |
|
| 1066 | - } |
|
| 1067 | - |
|
| 1068 | - |
|
| 1069 | - return $output; |
|
| 1070 | - } |
|
| 1071 | - |
|
| 1072 | - /** |
|
| 1073 | - * Build the component. |
|
| 1074 | - * |
|
| 1075 | - * @param array $args |
|
| 1076 | - * |
|
| 1077 | - * @return string The rendered component. |
|
| 1078 | - */ |
|
| 1079 | - public static function radio( $args = array() ) { |
|
| 1080 | - global $aui_bs5; |
|
| 1081 | - |
|
| 1082 | - $defaults = array( |
|
| 1083 | - 'class' => '', |
|
| 1084 | - 'wrap_class' => '', |
|
| 1085 | - 'id' => '', |
|
| 1086 | - 'title' => '', |
|
| 1087 | - 'horizontal' => false, |
|
| 1088 | - // sets the lable horizontal |
|
| 1089 | - 'value' => '', |
|
| 1090 | - 'label' => '', |
|
| 1091 | - 'label_class' => '', |
|
| 1092 | - 'label_type' => '', |
|
| 1093 | - 'label_col' => '', |
|
| 1094 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 1095 | - 'help_text' => '', |
|
| 1096 | - 'inline' => true, |
|
| 1097 | - 'required' => false, |
|
| 1098 | - 'options' => array(), |
|
| 1099 | - 'icon' => '', |
|
| 1100 | - 'no_wrap' => false, |
|
| 1101 | - 'element_require' => '', |
|
| 1102 | - // [%element_id%] == "1" |
|
| 1103 | - 'extra_attributes' => array(), |
|
| 1104 | - // an array of extra attributes |
|
| 1105 | - 'wrap_attributes' => array() |
|
| 1106 | - ); |
|
| 1107 | - |
|
| 1108 | - /** |
|
| 1109 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 1110 | - */ |
|
| 1111 | - $args = wp_parse_args( $args, $defaults ); |
|
| 1112 | - |
|
| 1113 | - // for now lets use horizontal for floating |
|
| 1114 | - if ( $args['label_type'] == 'floating' ) { |
|
| 1115 | - $args['label_type'] = 'horizontal'; |
|
| 1116 | - } |
|
| 1117 | - |
|
| 1118 | - $label_args = array( |
|
| 1119 | - 'title' => $args['label'], |
|
| 1120 | - 'class' => $args['label_class'] . " pt-0 ", |
|
| 1121 | - 'label_type' => $args['label_type'], |
|
| 1122 | - 'label_col' => $args['label_col'] |
|
| 1123 | - ); |
|
| 1124 | - |
|
| 1125 | - $output = ''; |
|
| 1126 | - |
|
| 1127 | - |
|
| 1128 | - // label before |
|
| 1129 | - if ( ! empty( $args['label'] ) ) { |
|
| 1130 | - $output .= self::label( $label_args, 'radio' ); |
|
| 1131 | - } |
|
| 1132 | - |
|
| 1133 | - // maybe horizontal label |
|
| 1134 | - if ( $args['label_type'] == 'horizontal' ) { |
|
| 1135 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
| 1136 | - $output .= '<div class="' . $input_col . '">'; |
|
| 1137 | - } |
|
| 1138 | - |
|
| 1139 | - if ( ! empty( $args['options'] ) ) { |
|
| 1140 | - $count = 0; |
|
| 1141 | - foreach ( $args['options'] as $value => $label ) { |
|
| 1142 | - $option_args = $args; |
|
| 1143 | - $option_args['value'] = $value; |
|
| 1144 | - $option_args['label'] = $label; |
|
| 1145 | - $option_args['checked'] = $value == $args['value'] ? true : false; |
|
| 1146 | - $output .= self::radio_option( $option_args, $count ); |
|
| 1147 | - $count ++; |
|
| 1148 | - } |
|
| 1149 | - } |
|
| 1150 | - |
|
| 1151 | - // help text |
|
| 1152 | - $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
| 1153 | - $output .= $help_text; |
|
| 1154 | - |
|
| 1155 | - // maybe horizontal label |
|
| 1156 | - if ( $args['label_type'] == 'horizontal' ) { |
|
| 1157 | - $output .= '</div>'; |
|
| 1158 | - } |
|
| 1159 | - |
|
| 1160 | - // wrap |
|
| 1161 | - $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
| 1162 | - $wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class; |
|
| 1163 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 1164 | - $output = self::wrap( array( |
|
| 1165 | - 'content' => $output, |
|
| 1166 | - 'class' => $wrap_class, |
|
| 1167 | - 'element_require' => $args['element_require'], |
|
| 1168 | - 'argument_id' => $args['id'], |
|
| 1169 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
| 1170 | - ) ); |
|
| 1171 | - |
|
| 1172 | - |
|
| 1173 | - return $output; |
|
| 1174 | - } |
|
| 1175 | - |
|
| 1176 | - /** |
|
| 1177 | - * Build the component. |
|
| 1178 | - * |
|
| 1179 | - * @param array $args |
|
| 1180 | - * |
|
| 1181 | - * @return string The rendered component. |
|
| 1182 | - */ |
|
| 1183 | - public static function radio_option( $args = array(), $count = '' ) { |
|
| 1184 | - $defaults = array( |
|
| 1185 | - 'class' => '', |
|
| 1186 | - 'id' => '', |
|
| 1187 | - 'title' => '', |
|
| 1188 | - 'value' => '', |
|
| 1189 | - 'required' => false, |
|
| 1190 | - 'inline' => true, |
|
| 1191 | - 'label' => '', |
|
| 1192 | - 'options' => array(), |
|
| 1193 | - 'icon' => '', |
|
| 1194 | - 'no_wrap' => false, |
|
| 1195 | - 'extra_attributes' => array() // an array of extra attributes |
|
| 1196 | - ); |
|
| 1197 | - |
|
| 1198 | - /** |
|
| 1199 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 1200 | - */ |
|
| 1201 | - $args = wp_parse_args( $args, $defaults ); |
|
| 1202 | - |
|
| 1203 | - $output = ''; |
|
| 1204 | - |
|
| 1205 | - // open/type |
|
| 1206 | - $output .= '<input type="radio"'; |
|
| 1207 | - |
|
| 1208 | - // class |
|
| 1209 | - $output .= ' class="form-check-input" '; |
|
| 1210 | - |
|
| 1211 | - // name |
|
| 1212 | - if ( ! empty( $args['name'] ) ) { |
|
| 1213 | - $output .= AUI_Component_Helper::name( $args['name'] ); |
|
| 1214 | - } |
|
| 1215 | - |
|
| 1216 | - // id |
|
| 1217 | - if ( ! empty( $args['id'] ) ) { |
|
| 1218 | - $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
| 1219 | - } |
|
| 1220 | - |
|
| 1221 | - // title |
|
| 1222 | - if ( ! empty( $args['title'] ) ) { |
|
| 1223 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
| 1224 | - } |
|
| 1225 | - |
|
| 1226 | - // value |
|
| 1227 | - if ( isset( $args['value'] ) ) { |
|
| 1228 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
| 1229 | - } |
|
| 1230 | - |
|
| 1231 | - // checked, for radio and checkboxes |
|
| 1232 | - if ( $args['checked'] ) { |
|
| 1233 | - $output .= ' checked '; |
|
| 1234 | - } |
|
| 1235 | - |
|
| 1236 | - // data-attributes |
|
| 1237 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
| 1238 | - |
|
| 1239 | - // aria-attributes |
|
| 1240 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
| 1241 | - |
|
| 1242 | - // extra attributes |
|
| 1243 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
| 1244 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
| 1245 | - } |
|
| 1246 | - |
|
| 1247 | - // required |
|
| 1248 | - if ( ! empty( $args['required'] ) ) { |
|
| 1249 | - $output .= ' required '; |
|
| 1250 | - } |
|
| 1251 | - |
|
| 1252 | - // close opening tag |
|
| 1253 | - $output .= ' >'; |
|
| 1254 | - |
|
| 1255 | - // label |
|
| 1256 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
| 1257 | - } elseif ( ! empty( $args['label'] ) ) { |
|
| 1258 | - $output .= self::label( array( |
|
| 1259 | - 'title' => $args['label'], |
|
| 1260 | - 'for' => $args['id'] . $count, |
|
| 1261 | - 'class' => 'form-check-label' |
|
| 1262 | - ), 'radio' ); |
|
| 1263 | - } |
|
| 1264 | - |
|
| 1265 | - // wrap |
|
| 1266 | - if ( ! $args['no_wrap'] ) { |
|
| 1267 | - $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
| 1268 | - |
|
| 1269 | - // Unique wrap class |
|
| 1270 | - $uniq_class = 'fwrap'; |
|
| 1271 | - if ( ! empty( $args['name'] ) ) { |
|
| 1272 | - $uniq_class .= '-' . $args['name']; |
|
| 1273 | - } else if ( ! empty( $args['id'] ) ) { |
|
| 1274 | - $uniq_class .= '-' . $args['id']; |
|
| 1275 | - } |
|
| 1276 | - |
|
| 1277 | - if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
| 1278 | - $uniq_class .= '-' . $args['value']; |
|
| 1279 | - } else { |
|
| 1280 | - $uniq_class .= '-' . $count; |
|
| 1281 | - } |
|
| 1282 | - $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
| 1283 | - |
|
| 1284 | - $output = self::wrap( array( |
|
| 1285 | - 'content' => $output, |
|
| 1286 | - 'class' => $wrap_class |
|
| 1287 | - ) ); |
|
| 1288 | - } |
|
| 1289 | - |
|
| 1290 | - return $output; |
|
| 1291 | - } |
|
| 1050 | + // wrap |
|
| 1051 | + if ( ! $args['no_wrap'] ) { |
|
| 1052 | + if ( ! empty( $args['form_group_class'] ) ) { |
|
| 1053 | + $fg_class = esc_attr( $args['form_group_class'] ); |
|
| 1054 | + }else{ |
|
| 1055 | + $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
| 1056 | + } |
|
| 1057 | + $wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class; |
|
| 1058 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 1059 | + $output = self::wrap( array( |
|
| 1060 | + 'content' => $output, |
|
| 1061 | + 'class' => $wrap_class, |
|
| 1062 | + 'element_require' => $args['element_require'], |
|
| 1063 | + 'argument_id' => $args['id'], |
|
| 1064 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
| 1065 | + ) ); |
|
| 1066 | + } |
|
| 1067 | + |
|
| 1068 | + |
|
| 1069 | + return $output; |
|
| 1070 | + } |
|
| 1071 | + |
|
| 1072 | + /** |
|
| 1073 | + * Build the component. |
|
| 1074 | + * |
|
| 1075 | + * @param array $args |
|
| 1076 | + * |
|
| 1077 | + * @return string The rendered component. |
|
| 1078 | + */ |
|
| 1079 | + public static function radio( $args = array() ) { |
|
| 1080 | + global $aui_bs5; |
|
| 1081 | + |
|
| 1082 | + $defaults = array( |
|
| 1083 | + 'class' => '', |
|
| 1084 | + 'wrap_class' => '', |
|
| 1085 | + 'id' => '', |
|
| 1086 | + 'title' => '', |
|
| 1087 | + 'horizontal' => false, |
|
| 1088 | + // sets the lable horizontal |
|
| 1089 | + 'value' => '', |
|
| 1090 | + 'label' => '', |
|
| 1091 | + 'label_class' => '', |
|
| 1092 | + 'label_type' => '', |
|
| 1093 | + 'label_col' => '', |
|
| 1094 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
| 1095 | + 'help_text' => '', |
|
| 1096 | + 'inline' => true, |
|
| 1097 | + 'required' => false, |
|
| 1098 | + 'options' => array(), |
|
| 1099 | + 'icon' => '', |
|
| 1100 | + 'no_wrap' => false, |
|
| 1101 | + 'element_require' => '', |
|
| 1102 | + // [%element_id%] == "1" |
|
| 1103 | + 'extra_attributes' => array(), |
|
| 1104 | + // an array of extra attributes |
|
| 1105 | + 'wrap_attributes' => array() |
|
| 1106 | + ); |
|
| 1107 | + |
|
| 1108 | + /** |
|
| 1109 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 1110 | + */ |
|
| 1111 | + $args = wp_parse_args( $args, $defaults ); |
|
| 1112 | + |
|
| 1113 | + // for now lets use horizontal for floating |
|
| 1114 | + if ( $args['label_type'] == 'floating' ) { |
|
| 1115 | + $args['label_type'] = 'horizontal'; |
|
| 1116 | + } |
|
| 1117 | + |
|
| 1118 | + $label_args = array( |
|
| 1119 | + 'title' => $args['label'], |
|
| 1120 | + 'class' => $args['label_class'] . " pt-0 ", |
|
| 1121 | + 'label_type' => $args['label_type'], |
|
| 1122 | + 'label_col' => $args['label_col'] |
|
| 1123 | + ); |
|
| 1124 | + |
|
| 1125 | + $output = ''; |
|
| 1126 | + |
|
| 1127 | + |
|
| 1128 | + // label before |
|
| 1129 | + if ( ! empty( $args['label'] ) ) { |
|
| 1130 | + $output .= self::label( $label_args, 'radio' ); |
|
| 1131 | + } |
|
| 1132 | + |
|
| 1133 | + // maybe horizontal label |
|
| 1134 | + if ( $args['label_type'] == 'horizontal' ) { |
|
| 1135 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
| 1136 | + $output .= '<div class="' . $input_col . '">'; |
|
| 1137 | + } |
|
| 1138 | + |
|
| 1139 | + if ( ! empty( $args['options'] ) ) { |
|
| 1140 | + $count = 0; |
|
| 1141 | + foreach ( $args['options'] as $value => $label ) { |
|
| 1142 | + $option_args = $args; |
|
| 1143 | + $option_args['value'] = $value; |
|
| 1144 | + $option_args['label'] = $label; |
|
| 1145 | + $option_args['checked'] = $value == $args['value'] ? true : false; |
|
| 1146 | + $output .= self::radio_option( $option_args, $count ); |
|
| 1147 | + $count ++; |
|
| 1148 | + } |
|
| 1149 | + } |
|
| 1150 | + |
|
| 1151 | + // help text |
|
| 1152 | + $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
| 1153 | + $output .= $help_text; |
|
| 1154 | + |
|
| 1155 | + // maybe horizontal label |
|
| 1156 | + if ( $args['label_type'] == 'horizontal' ) { |
|
| 1157 | + $output .= '</div>'; |
|
| 1158 | + } |
|
| 1159 | + |
|
| 1160 | + // wrap |
|
| 1161 | + $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
| 1162 | + $wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class; |
|
| 1163 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
| 1164 | + $output = self::wrap( array( |
|
| 1165 | + 'content' => $output, |
|
| 1166 | + 'class' => $wrap_class, |
|
| 1167 | + 'element_require' => $args['element_require'], |
|
| 1168 | + 'argument_id' => $args['id'], |
|
| 1169 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
| 1170 | + ) ); |
|
| 1171 | + |
|
| 1172 | + |
|
| 1173 | + return $output; |
|
| 1174 | + } |
|
| 1175 | + |
|
| 1176 | + /** |
|
| 1177 | + * Build the component. |
|
| 1178 | + * |
|
| 1179 | + * @param array $args |
|
| 1180 | + * |
|
| 1181 | + * @return string The rendered component. |
|
| 1182 | + */ |
|
| 1183 | + public static function radio_option( $args = array(), $count = '' ) { |
|
| 1184 | + $defaults = array( |
|
| 1185 | + 'class' => '', |
|
| 1186 | + 'id' => '', |
|
| 1187 | + 'title' => '', |
|
| 1188 | + 'value' => '', |
|
| 1189 | + 'required' => false, |
|
| 1190 | + 'inline' => true, |
|
| 1191 | + 'label' => '', |
|
| 1192 | + 'options' => array(), |
|
| 1193 | + 'icon' => '', |
|
| 1194 | + 'no_wrap' => false, |
|
| 1195 | + 'extra_attributes' => array() // an array of extra attributes |
|
| 1196 | + ); |
|
| 1197 | + |
|
| 1198 | + /** |
|
| 1199 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 1200 | + */ |
|
| 1201 | + $args = wp_parse_args( $args, $defaults ); |
|
| 1202 | + |
|
| 1203 | + $output = ''; |
|
| 1204 | + |
|
| 1205 | + // open/type |
|
| 1206 | + $output .= '<input type="radio"'; |
|
| 1207 | + |
|
| 1208 | + // class |
|
| 1209 | + $output .= ' class="form-check-input" '; |
|
| 1210 | + |
|
| 1211 | + // name |
|
| 1212 | + if ( ! empty( $args['name'] ) ) { |
|
| 1213 | + $output .= AUI_Component_Helper::name( $args['name'] ); |
|
| 1214 | + } |
|
| 1215 | + |
|
| 1216 | + // id |
|
| 1217 | + if ( ! empty( $args['id'] ) ) { |
|
| 1218 | + $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
| 1219 | + } |
|
| 1220 | + |
|
| 1221 | + // title |
|
| 1222 | + if ( ! empty( $args['title'] ) ) { |
|
| 1223 | + $output .= AUI_Component_Helper::title( $args['title'] ); |
|
| 1224 | + } |
|
| 1225 | + |
|
| 1226 | + // value |
|
| 1227 | + if ( isset( $args['value'] ) ) { |
|
| 1228 | + $output .= AUI_Component_Helper::value( $args['value'] ); |
|
| 1229 | + } |
|
| 1230 | + |
|
| 1231 | + // checked, for radio and checkboxes |
|
| 1232 | + if ( $args['checked'] ) { |
|
| 1233 | + $output .= ' checked '; |
|
| 1234 | + } |
|
| 1235 | + |
|
| 1236 | + // data-attributes |
|
| 1237 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
| 1238 | + |
|
| 1239 | + // aria-attributes |
|
| 1240 | + $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
| 1241 | + |
|
| 1242 | + // extra attributes |
|
| 1243 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
| 1244 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
| 1245 | + } |
|
| 1246 | + |
|
| 1247 | + // required |
|
| 1248 | + if ( ! empty( $args['required'] ) ) { |
|
| 1249 | + $output .= ' required '; |
|
| 1250 | + } |
|
| 1251 | + |
|
| 1252 | + // close opening tag |
|
| 1253 | + $output .= ' >'; |
|
| 1254 | + |
|
| 1255 | + // label |
|
| 1256 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
| 1257 | + } elseif ( ! empty( $args['label'] ) ) { |
|
| 1258 | + $output .= self::label( array( |
|
| 1259 | + 'title' => $args['label'], |
|
| 1260 | + 'for' => $args['id'] . $count, |
|
| 1261 | + 'class' => 'form-check-label' |
|
| 1262 | + ), 'radio' ); |
|
| 1263 | + } |
|
| 1264 | + |
|
| 1265 | + // wrap |
|
| 1266 | + if ( ! $args['no_wrap'] ) { |
|
| 1267 | + $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
| 1268 | + |
|
| 1269 | + // Unique wrap class |
|
| 1270 | + $uniq_class = 'fwrap'; |
|
| 1271 | + if ( ! empty( $args['name'] ) ) { |
|
| 1272 | + $uniq_class .= '-' . $args['name']; |
|
| 1273 | + } else if ( ! empty( $args['id'] ) ) { |
|
| 1274 | + $uniq_class .= '-' . $args['id']; |
|
| 1275 | + } |
|
| 1276 | + |
|
| 1277 | + if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
| 1278 | + $uniq_class .= '-' . $args['value']; |
|
| 1279 | + } else { |
|
| 1280 | + $uniq_class .= '-' . $count; |
|
| 1281 | + } |
|
| 1282 | + $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
| 1283 | + |
|
| 1284 | + $output = self::wrap( array( |
|
| 1285 | + 'content' => $output, |
|
| 1286 | + 'class' => $wrap_class |
|
| 1287 | + ) ); |
|
| 1288 | + } |
|
| 1289 | + |
|
| 1290 | + return $output; |
|
| 1291 | + } |
|
| 1292 | 1292 | |
| 1293 | 1293 | } |
| 1294 | 1294 | \ No newline at end of file |
@@ -13,464 +13,464 @@ discard block |
||
| 13 | 13 | */ |
| 14 | 14 | abstract class GetPaid_Payment_Gateway { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Set if the place checkout button should be renamed on selection. |
|
| 18 | - * |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - public $checkout_button_text; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * Boolean whether the method is enabled. |
|
| 25 | - * |
|
| 26 | - * @var bool |
|
| 27 | - */ |
|
| 28 | - public $enabled = true; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Payment method id. |
|
| 32 | - * |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 35 | - public $id; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Payment method order. |
|
| 39 | - * |
|
| 40 | - * @var int |
|
| 41 | - */ |
|
| 42 | - public $order = 10; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Payment method title for the frontend. |
|
| 46 | - * |
|
| 47 | - * @var string |
|
| 48 | - */ |
|
| 49 | - public $title; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Payment method description for the frontend. |
|
| 53 | - * |
|
| 54 | - * @var string |
|
| 55 | - */ |
|
| 56 | - public $description; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Gateway title. |
|
| 60 | - * |
|
| 61 | - * @var string |
|
| 62 | - */ |
|
| 63 | - public $method_title = ''; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Gateway description. |
|
| 67 | - * |
|
| 68 | - * @var string |
|
| 69 | - */ |
|
| 70 | - public $method_description = ''; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Countries this gateway is allowed for. |
|
| 74 | - * |
|
| 75 | - * @var array |
|
| 76 | - */ |
|
| 77 | - public $countries; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Currencies this gateway is allowed for. |
|
| 81 | - * |
|
| 82 | - * @var array |
|
| 83 | - */ |
|
| 84 | - public $currencies; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Currencies this gateway is not allowed for. |
|
| 88 | - * |
|
| 89 | - * @var array |
|
| 90 | - */ |
|
| 91 | - public $exclude_currencies; |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Maximum transaction amount, zero does not define a maximum. |
|
| 95 | - * |
|
| 96 | - * @var int |
|
| 97 | - */ |
|
| 98 | - public $max_amount = 0; |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Optional URL to view a transaction. |
|
| 102 | - * |
|
| 103 | - * @var string |
|
| 104 | - */ |
|
| 105 | - public $view_transaction_url = ''; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Optional URL to view a subscription. |
|
| 109 | - * |
|
| 110 | - * @var string |
|
| 111 | - */ |
|
| 112 | - public $view_subscription_url = ''; |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Optional label to show for "new payment method" in the payment |
|
| 116 | - * method/token selection radio selection. |
|
| 117 | - * |
|
| 118 | - * @var string |
|
| 119 | - */ |
|
| 120 | - public $new_method_label = ''; |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Contains a user's saved tokens for this gateway. |
|
| 124 | - * |
|
| 125 | - * @var array |
|
| 126 | - */ |
|
| 127 | - protected $tokens = array(); |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * An array of features that this gateway supports. |
|
| 131 | - * |
|
| 132 | - * @var array |
|
| 133 | - */ |
|
| 134 | - protected $supports = array(); |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Class constructor. |
|
| 138 | - */ |
|
| 139 | - public function __construct() { |
|
| 140 | - |
|
| 141 | - do_action( 'getpaid_before_init_payment_gateway_' . $this->id, $this ); |
|
| 142 | - |
|
| 143 | - // Register gateway. |
|
| 144 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
| 145 | - |
|
| 146 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
| 147 | - |
|
| 148 | - // Add support for various features. |
|
| 149 | - foreach ( $this->supports as $feature ) { |
|
| 150 | - add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' ); |
|
| 151 | - add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' ); |
|
| 152 | - add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - // Invoice addons. |
|
| 156 | - if ( $this->supports( 'addons' ) ) { |
|
| 157 | - add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - // Gateway settings. |
|
| 161 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
| 162 | - |
|
| 163 | - // Gateway checkout fiellds. |
|
| 164 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
| 165 | - |
|
| 166 | - // Process payment. |
|
| 167 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
| 168 | - |
|
| 169 | - // Change the checkout button text. |
|
| 170 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
| 171 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - // Check if a gateway is valid for a given currency. |
|
| 175 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
| 176 | - |
|
| 177 | - // Generate the transaction url. |
|
| 178 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
| 179 | - |
|
| 180 | - // Generate the subscription url. |
|
| 181 | - add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
| 182 | - |
|
| 183 | - // Confirm payments. |
|
| 184 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
| 185 | - |
|
| 186 | - // Verify IPNs. |
|
| 187 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
| 188 | - |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Checks if this gateway is a given gateway. |
|
| 193 | - * |
|
| 194 | - * @since 1.0.19 |
|
| 195 | - * @return bool |
|
| 196 | - */ |
|
| 197 | - public function is( $gateway ) { |
|
| 198 | - return $gateway == $this->id; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Returns a users saved tokens for this gateway. |
|
| 203 | - * |
|
| 204 | - * @since 1.0.19 |
|
| 205 | - * @return array |
|
| 206 | - */ |
|
| 207 | - public function get_tokens( $sandbox = null ) { |
|
| 208 | - |
|
| 209 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
| 210 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
| 211 | - |
|
| 212 | - if ( is_array( $tokens ) ) { |
|
| 213 | - $this->tokens = $tokens; |
|
| 214 | - } |
|
| 16 | + /** |
|
| 17 | + * Set if the place checkout button should be renamed on selection. |
|
| 18 | + * |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + public $checkout_button_text; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * Boolean whether the method is enabled. |
|
| 25 | + * |
|
| 26 | + * @var bool |
|
| 27 | + */ |
|
| 28 | + public $enabled = true; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Payment method id. |
|
| 32 | + * |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | + public $id; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Payment method order. |
|
| 39 | + * |
|
| 40 | + * @var int |
|
| 41 | + */ |
|
| 42 | + public $order = 10; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Payment method title for the frontend. |
|
| 46 | + * |
|
| 47 | + * @var string |
|
| 48 | + */ |
|
| 49 | + public $title; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Payment method description for the frontend. |
|
| 53 | + * |
|
| 54 | + * @var string |
|
| 55 | + */ |
|
| 56 | + public $description; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Gateway title. |
|
| 60 | + * |
|
| 61 | + * @var string |
|
| 62 | + */ |
|
| 63 | + public $method_title = ''; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Gateway description. |
|
| 67 | + * |
|
| 68 | + * @var string |
|
| 69 | + */ |
|
| 70 | + public $method_description = ''; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Countries this gateway is allowed for. |
|
| 74 | + * |
|
| 75 | + * @var array |
|
| 76 | + */ |
|
| 77 | + public $countries; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Currencies this gateway is allowed for. |
|
| 81 | + * |
|
| 82 | + * @var array |
|
| 83 | + */ |
|
| 84 | + public $currencies; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Currencies this gateway is not allowed for. |
|
| 88 | + * |
|
| 89 | + * @var array |
|
| 90 | + */ |
|
| 91 | + public $exclude_currencies; |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Maximum transaction amount, zero does not define a maximum. |
|
| 95 | + * |
|
| 96 | + * @var int |
|
| 97 | + */ |
|
| 98 | + public $max_amount = 0; |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Optional URL to view a transaction. |
|
| 102 | + * |
|
| 103 | + * @var string |
|
| 104 | + */ |
|
| 105 | + public $view_transaction_url = ''; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Optional URL to view a subscription. |
|
| 109 | + * |
|
| 110 | + * @var string |
|
| 111 | + */ |
|
| 112 | + public $view_subscription_url = ''; |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Optional label to show for "new payment method" in the payment |
|
| 116 | + * method/token selection radio selection. |
|
| 117 | + * |
|
| 118 | + * @var string |
|
| 119 | + */ |
|
| 120 | + public $new_method_label = ''; |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Contains a user's saved tokens for this gateway. |
|
| 124 | + * |
|
| 125 | + * @var array |
|
| 126 | + */ |
|
| 127 | + protected $tokens = array(); |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * An array of features that this gateway supports. |
|
| 131 | + * |
|
| 132 | + * @var array |
|
| 133 | + */ |
|
| 134 | + protected $supports = array(); |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Class constructor. |
|
| 138 | + */ |
|
| 139 | + public function __construct() { |
|
| 140 | + |
|
| 141 | + do_action( 'getpaid_before_init_payment_gateway_' . $this->id, $this ); |
|
| 142 | + |
|
| 143 | + // Register gateway. |
|
| 144 | + add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
| 145 | + |
|
| 146 | + $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
| 147 | + |
|
| 148 | + // Add support for various features. |
|
| 149 | + foreach ( $this->supports as $feature ) { |
|
| 150 | + add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' ); |
|
| 151 | + add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' ); |
|
| 152 | + add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + // Invoice addons. |
|
| 156 | + if ( $this->supports( 'addons' ) ) { |
|
| 157 | + add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + // Gateway settings. |
|
| 161 | + add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
| 162 | + |
|
| 163 | + // Gateway checkout fiellds. |
|
| 164 | + add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
| 165 | + |
|
| 166 | + // Process payment. |
|
| 167 | + add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
| 168 | + |
|
| 169 | + // Change the checkout button text. |
|
| 170 | + if ( ! empty( $this->checkout_button_text ) ) { |
|
| 171 | + add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + // Check if a gateway is valid for a given currency. |
|
| 175 | + add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
| 176 | + |
|
| 177 | + // Generate the transaction url. |
|
| 178 | + add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
| 179 | + |
|
| 180 | + // Generate the subscription url. |
|
| 181 | + add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
| 182 | + |
|
| 183 | + // Confirm payments. |
|
| 184 | + add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
| 185 | + |
|
| 186 | + // Verify IPNs. |
|
| 187 | + add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
| 188 | + |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Checks if this gateway is a given gateway. |
|
| 193 | + * |
|
| 194 | + * @since 1.0.19 |
|
| 195 | + * @return bool |
|
| 196 | + */ |
|
| 197 | + public function is( $gateway ) { |
|
| 198 | + return $gateway == $this->id; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Returns a users saved tokens for this gateway. |
|
| 203 | + * |
|
| 204 | + * @since 1.0.19 |
|
| 205 | + * @return array |
|
| 206 | + */ |
|
| 207 | + public function get_tokens( $sandbox = null ) { |
|
| 208 | + |
|
| 209 | + if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
| 210 | + $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
| 211 | + |
|
| 212 | + if ( is_array( $tokens ) ) { |
|
| 213 | + $this->tokens = $tokens; |
|
| 214 | + } |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - if ( ! is_bool( $sandbox ) ) { |
|
| 218 | - return $this->tokens; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - // Filter tokens. |
|
| 222 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
| 223 | - return wp_list_filter( $this->tokens, $args ); |
|
| 224 | - |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Saves a token for this gateway. |
|
| 229 | - * |
|
| 230 | - * @since 1.0.19 |
|
| 231 | - */ |
|
| 232 | - public function save_token( $token ) { |
|
| 233 | - |
|
| 234 | - $tokens = $this->get_tokens(); |
|
| 235 | - $tokens[] = $token; |
|
| 236 | - |
|
| 237 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
| 238 | - |
|
| 239 | - $this->tokens = $tokens; |
|
| 240 | - |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Return the title for admin screens. |
|
| 245 | - * |
|
| 246 | - * @return string |
|
| 247 | - */ |
|
| 248 | - public function get_method_title() { |
|
| 249 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Return the description for admin screens. |
|
| 254 | - * |
|
| 255 | - * @return string |
|
| 256 | - */ |
|
| 257 | - public function get_method_description() { |
|
| 258 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Get the success url. |
|
| 263 | - * |
|
| 264 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 265 | - * @return string |
|
| 266 | - */ |
|
| 267 | - public function get_return_url( $invoice ) { |
|
| 268 | - |
|
| 269 | - // Payment success url |
|
| 270 | - $return_url = add_query_arg( |
|
| 271 | - array( |
|
| 272 | - 'payment-confirm' => $this->id, |
|
| 273 | - 'invoice_key' => $invoice->get_key(), |
|
| 274 | - 'utm_nooverride' => 1, |
|
| 275 | - ), |
|
| 276 | - wpinv_get_success_page_uri() |
|
| 277 | - ); |
|
| 278 | - |
|
| 279 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * Confirms payments when rendering the success page. |
|
| 284 | - * |
|
| 285 | - * @param string $content Success page content. |
|
| 286 | - * @return string |
|
| 287 | - */ |
|
| 288 | - public function confirm_payment( $content ) { |
|
| 289 | - |
|
| 290 | - // Retrieve the invoice. |
|
| 291 | - $invoice_id = getpaid_get_current_invoice_id(); |
|
| 292 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 293 | - |
|
| 294 | - // Ensure that it exists and that it is pending payment. |
|
| 295 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
| 296 | - return $content; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - // Can the user view this invoice?? |
|
| 300 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
| 301 | - return $content; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - // Show payment processing indicator. |
|
| 305 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * Processes ipns and marks payments as complete. |
|
| 310 | - * |
|
| 311 | - * @return void |
|
| 312 | - */ |
|
| 313 | - public function verify_ipn() {} |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Processes invoice addons. |
|
| 317 | - * |
|
| 318 | - * @param WPInv_Invoice $invoice |
|
| 319 | - * @param GetPaid_Form_Item[] $items |
|
| 320 | - * @return WPInv_Invoice |
|
| 321 | - */ |
|
| 322 | - public function process_addons( $invoice, $items ) { |
|
| 323 | - |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
| 328 | - * |
|
| 329 | - * @param string $transaction_url transaction url. |
|
| 330 | - * @param WPInv_Invoice $invoice Invoice object. |
|
| 331 | - * @return string transaction URL, or empty string. |
|
| 332 | - */ |
|
| 333 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
| 334 | - |
|
| 335 | - $transaction_id = $invoice->get_transaction_id(); |
|
| 336 | - |
|
| 337 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
| 338 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
| 339 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
| 340 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - return $transaction_url; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
| 348 | - * |
|
| 349 | - * @param string $subscription_url transaction url. |
|
| 350 | - * @param WPInv_Subscription $subscription Subscription objectt. |
|
| 351 | - * @return string subscription URL, or empty string. |
|
| 352 | - */ |
|
| 353 | - public function generate_subscription_url( $subscription_url, $subscription ) { |
|
| 354 | - |
|
| 355 | - $profile_id = $subscription->get_profile_id(); |
|
| 356 | - |
|
| 357 | - if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
| 358 | - |
|
| 359 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
| 360 | - $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
| 361 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
| 362 | - |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - return $subscription_url; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - /** |
|
| 369 | - * Check if the gateway is available for use. |
|
| 370 | - * |
|
| 371 | - * @return bool |
|
| 372 | - */ |
|
| 373 | - public function is_available() { |
|
| 374 | - return ! empty( $this->enabled ); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * Return the gateway's title. |
|
| 379 | - * |
|
| 380 | - * @return string |
|
| 381 | - */ |
|
| 382 | - public function get_title() { |
|
| 383 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * Return the gateway's description. |
|
| 388 | - * |
|
| 389 | - * @return string |
|
| 390 | - */ |
|
| 391 | - public function get_description() { |
|
| 392 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * Process Payment. |
|
| 397 | - * |
|
| 398 | - * |
|
| 399 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 400 | - * @param array $submission_data Posted checkout fields. |
|
| 401 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 402 | - * @return void |
|
| 403 | - */ |
|
| 404 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 405 | - // Process the payment then either redirect to the success page or the gateway. |
|
| 406 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * Process refund. |
|
| 411 | - * |
|
| 412 | - * If the gateway declares 'refunds' support, this will allow it to refund. |
|
| 413 | - * a passed in amount. |
|
| 414 | - * |
|
| 415 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 416 | - * @param float $amount Refund amount. |
|
| 417 | - * @param string $reason Refund reason. |
|
| 418 | - * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
| 419 | - */ |
|
| 420 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
| 421 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Displays the payment fields, credit cards etc. |
|
| 426 | - * |
|
| 427 | - * @param int $invoice_id 0 or invoice id. |
|
| 428 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
| 429 | - */ |
|
| 430 | - public function payment_fields( $invoice_id, $form ) { |
|
| 431 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * Filters the gateway settings. |
|
| 436 | - * |
|
| 437 | - * @param array $admin_settings |
|
| 438 | - */ |
|
| 439 | - public function admin_settings( $admin_settings ) { |
|
| 440 | - return $admin_settings; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * Retrieves the value of a gateway setting. |
|
| 445 | - * |
|
| 446 | - * @param string $option |
|
| 447 | - */ |
|
| 448 | - public function get_option( $option, $default = false ) { |
|
| 449 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * Check if a gateway supports a given feature. |
|
| 454 | - * |
|
| 455 | - * Gateways should override this to declare support (or lack of support) for a feature. |
|
| 456 | - * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
| 457 | - * |
|
| 458 | - * @param string $feature string The name of a feature to test support for. |
|
| 459 | - * @return bool True if the gateway supports the feature, false otherwise. |
|
| 460 | - * @since 1.0.19 |
|
| 461 | - */ |
|
| 462 | - public function supports( $feature ) { |
|
| 463 | - return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * Returns the credit card form html. |
|
| 468 | - * |
|
| 469 | - * @param bool $save whether or not to display the save button. |
|
| 470 | - */ |
|
| 217 | + if ( ! is_bool( $sandbox ) ) { |
|
| 218 | + return $this->tokens; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + // Filter tokens. |
|
| 222 | + $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
| 223 | + return wp_list_filter( $this->tokens, $args ); |
|
| 224 | + |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Saves a token for this gateway. |
|
| 229 | + * |
|
| 230 | + * @since 1.0.19 |
|
| 231 | + */ |
|
| 232 | + public function save_token( $token ) { |
|
| 233 | + |
|
| 234 | + $tokens = $this->get_tokens(); |
|
| 235 | + $tokens[] = $token; |
|
| 236 | + |
|
| 237 | + update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
| 238 | + |
|
| 239 | + $this->tokens = $tokens; |
|
| 240 | + |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Return the title for admin screens. |
|
| 245 | + * |
|
| 246 | + * @return string |
|
| 247 | + */ |
|
| 248 | + public function get_method_title() { |
|
| 249 | + return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Return the description for admin screens. |
|
| 254 | + * |
|
| 255 | + * @return string |
|
| 256 | + */ |
|
| 257 | + public function get_method_description() { |
|
| 258 | + return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Get the success url. |
|
| 263 | + * |
|
| 264 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 265 | + * @return string |
|
| 266 | + */ |
|
| 267 | + public function get_return_url( $invoice ) { |
|
| 268 | + |
|
| 269 | + // Payment success url |
|
| 270 | + $return_url = add_query_arg( |
|
| 271 | + array( |
|
| 272 | + 'payment-confirm' => $this->id, |
|
| 273 | + 'invoice_key' => $invoice->get_key(), |
|
| 274 | + 'utm_nooverride' => 1, |
|
| 275 | + ), |
|
| 276 | + wpinv_get_success_page_uri() |
|
| 277 | + ); |
|
| 278 | + |
|
| 279 | + return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * Confirms payments when rendering the success page. |
|
| 284 | + * |
|
| 285 | + * @param string $content Success page content. |
|
| 286 | + * @return string |
|
| 287 | + */ |
|
| 288 | + public function confirm_payment( $content ) { |
|
| 289 | + |
|
| 290 | + // Retrieve the invoice. |
|
| 291 | + $invoice_id = getpaid_get_current_invoice_id(); |
|
| 292 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 293 | + |
|
| 294 | + // Ensure that it exists and that it is pending payment. |
|
| 295 | + if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
| 296 | + return $content; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + // Can the user view this invoice?? |
|
| 300 | + if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
| 301 | + return $content; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + // Show payment processing indicator. |
|
| 305 | + return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * Processes ipns and marks payments as complete. |
|
| 310 | + * |
|
| 311 | + * @return void |
|
| 312 | + */ |
|
| 313 | + public function verify_ipn() {} |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Processes invoice addons. |
|
| 317 | + * |
|
| 318 | + * @param WPInv_Invoice $invoice |
|
| 319 | + * @param GetPaid_Form_Item[] $items |
|
| 320 | + * @return WPInv_Invoice |
|
| 321 | + */ |
|
| 322 | + public function process_addons( $invoice, $items ) { |
|
| 323 | + |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
| 328 | + * |
|
| 329 | + * @param string $transaction_url transaction url. |
|
| 330 | + * @param WPInv_Invoice $invoice Invoice object. |
|
| 331 | + * @return string transaction URL, or empty string. |
|
| 332 | + */ |
|
| 333 | + public function filter_transaction_url( $transaction_url, $invoice ) { |
|
| 334 | + |
|
| 335 | + $transaction_id = $invoice->get_transaction_id(); |
|
| 336 | + |
|
| 337 | + if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
| 338 | + $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
| 339 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
| 340 | + $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + return $transaction_url; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
| 348 | + * |
|
| 349 | + * @param string $subscription_url transaction url. |
|
| 350 | + * @param WPInv_Subscription $subscription Subscription objectt. |
|
| 351 | + * @return string subscription URL, or empty string. |
|
| 352 | + */ |
|
| 353 | + public function generate_subscription_url( $subscription_url, $subscription ) { |
|
| 354 | + |
|
| 355 | + $profile_id = $subscription->get_profile_id(); |
|
| 356 | + |
|
| 357 | + if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
| 358 | + |
|
| 359 | + $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
| 360 | + $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
| 361 | + $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
| 362 | + |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + return $subscription_url; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * Check if the gateway is available for use. |
|
| 370 | + * |
|
| 371 | + * @return bool |
|
| 372 | + */ |
|
| 373 | + public function is_available() { |
|
| 374 | + return ! empty( $this->enabled ); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * Return the gateway's title. |
|
| 379 | + * |
|
| 380 | + * @return string |
|
| 381 | + */ |
|
| 382 | + public function get_title() { |
|
| 383 | + return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * Return the gateway's description. |
|
| 388 | + * |
|
| 389 | + * @return string |
|
| 390 | + */ |
|
| 391 | + public function get_description() { |
|
| 392 | + return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * Process Payment. |
|
| 397 | + * |
|
| 398 | + * |
|
| 399 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 400 | + * @param array $submission_data Posted checkout fields. |
|
| 401 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 402 | + * @return void |
|
| 403 | + */ |
|
| 404 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 405 | + // Process the payment then either redirect to the success page or the gateway. |
|
| 406 | + do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * Process refund. |
|
| 411 | + * |
|
| 412 | + * If the gateway declares 'refunds' support, this will allow it to refund. |
|
| 413 | + * a passed in amount. |
|
| 414 | + * |
|
| 415 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 416 | + * @param float $amount Refund amount. |
|
| 417 | + * @param string $reason Refund reason. |
|
| 418 | + * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
| 419 | + */ |
|
| 420 | + public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
| 421 | + return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Displays the payment fields, credit cards etc. |
|
| 426 | + * |
|
| 427 | + * @param int $invoice_id 0 or invoice id. |
|
| 428 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
| 429 | + */ |
|
| 430 | + public function payment_fields( $invoice_id, $form ) { |
|
| 431 | + do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * Filters the gateway settings. |
|
| 436 | + * |
|
| 437 | + * @param array $admin_settings |
|
| 438 | + */ |
|
| 439 | + public function admin_settings( $admin_settings ) { |
|
| 440 | + return $admin_settings; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * Retrieves the value of a gateway setting. |
|
| 445 | + * |
|
| 446 | + * @param string $option |
|
| 447 | + */ |
|
| 448 | + public function get_option( $option, $default = false ) { |
|
| 449 | + return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * Check if a gateway supports a given feature. |
|
| 454 | + * |
|
| 455 | + * Gateways should override this to declare support (or lack of support) for a feature. |
|
| 456 | + * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
| 457 | + * |
|
| 458 | + * @param string $feature string The name of a feature to test support for. |
|
| 459 | + * @return bool True if the gateway supports the feature, false otherwise. |
|
| 460 | + * @since 1.0.19 |
|
| 461 | + */ |
|
| 462 | + public function supports( $feature ) { |
|
| 463 | + return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * Returns the credit card form html. |
|
| 468 | + * |
|
| 469 | + * @param bool $save whether or not to display the save button. |
|
| 470 | + */ |
|
| 471 | 471 | public function get_cc_form( $save = false ) { |
| 472 | 472 | |
| 473 | - ob_start(); |
|
| 473 | + ob_start(); |
|
| 474 | 474 | |
| 475 | 475 | $id_prefix = esc_attr( uniqid( $this->id ) ); |
| 476 | 476 | |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | '11' => __( 'November', 'invoicing' ), |
| 489 | 489 | '12' => __( 'December', 'invoicing' ), |
| 490 | 490 | ); |
| 491 | - $months = apply_filters( 'getpaid_cc_months', $months, $this ); |
|
| 491 | + $months = apply_filters( 'getpaid_cc_months', $months, $this ); |
|
| 492 | 492 | |
| 493 | 493 | $year = (int) current_time( 'Y' ); |
| 494 | 494 | $years = array(); |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | $years[ $year + $i ] = $year + $i; |
| 498 | 498 | } |
| 499 | 499 | |
| 500 | - $years = apply_filters( 'getpaid_cc_years', $years, $this ); |
|
| 500 | + $years = apply_filters( 'getpaid_cc_years', $years, $this ); |
|
| 501 | 501 | |
| 502 | 502 | ?> |
| 503 | 503 | <div class="<?php echo esc_attr( $this->id ); ?>-cc-form getpaid-cc-form mt-1"> |
@@ -539,7 +539,7 @@ discard block |
||
| 539 | 539 | |
| 540 | 540 | <?php |
| 541 | 541 | foreach ( $months as $key => $month ) { |
| 542 | - echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $month ) . '</option>'; |
|
| 542 | + echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $month ) . '</option>'; |
|
| 543 | 543 | } |
| 544 | 544 | ?> |
| 545 | 545 | |
@@ -552,7 +552,7 @@ discard block |
||
| 552 | 552 | |
| 553 | 553 | <?php |
| 554 | 554 | foreach ( $years as $key => $year ) { |
| 555 | - echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $year ) . '</option>'; |
|
| 555 | + echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $year ) . '</option>'; |
|
| 556 | 556 | } |
| 557 | 557 | ?> |
| 558 | 558 | |
@@ -570,13 +570,13 @@ discard block |
||
| 570 | 570 | 'name' => $this->id . '[cc_cvv2]', |
| 571 | 571 | 'id' => "$id_prefix-cc-cvv2", |
| 572 | 572 | 'label' => __( 'CCV', 'invoicing' ), |
| 573 | - 'label_type' => 'vertical', |
|
| 574 | - 'class' => 'form-control-sm', |
|
| 575 | - 'extra_attributes' => array( |
|
| 576 | - 'autocomplete' => 'cc-csc', |
|
| 577 | - ), |
|
| 573 | + 'label_type' => 'vertical', |
|
| 574 | + 'class' => 'form-control-sm', |
|
| 575 | + 'extra_attributes' => array( |
|
| 576 | + 'autocomplete' => 'cc-csc', |
|
| 577 | + ), |
|
| 578 | 578 | ), |
| 579 | - true |
|
| 579 | + true |
|
| 580 | 580 | ); |
| 581 | 581 | ?> |
| 582 | 582 | </div> |
@@ -585,192 +585,192 @@ discard block |
||
| 585 | 585 | |
| 586 | 586 | <?php |
| 587 | 587 | |
| 588 | - if ( $save ) { |
|
| 589 | - $this->save_payment_method_checkbox(); |
|
| 590 | - } |
|
| 588 | + if ( $save ) { |
|
| 589 | + $this->save_payment_method_checkbox(); |
|
| 590 | + } |
|
| 591 | 591 | |
| 592 | - ?> |
|
| 592 | + ?> |
|
| 593 | 593 | </div> |
| 594 | 594 | |
| 595 | 595 | </div> |
| 596 | 596 | <?php |
| 597 | 597 | |
| 598 | - return ob_get_clean(); |
|
| 598 | + return ob_get_clean(); |
|
| 599 | + |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + /** |
|
| 603 | + * Displays a new payment method entry form. |
|
| 604 | + * |
|
| 605 | + * @since 1.0.19 |
|
| 606 | + */ |
|
| 607 | + public function new_payment_method_entry( $form ) { |
|
| 608 | + echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses( $form, getpaid_allowed_html() ) . '</div>'; |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + /** |
|
| 612 | + * Grab and display our saved payment methods. |
|
| 613 | + * |
|
| 614 | + * @since 1.0.19 |
|
| 615 | + */ |
|
| 616 | + public function saved_payment_methods() { |
|
| 617 | + echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
| 618 | + |
|
| 619 | + foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
| 620 | + $this->get_saved_payment_method_option_html( $token ); |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + $this->get_new_payment_method_option_html(); |
|
| 624 | + echo '</ul>'; |
|
| 599 | 625 | |
| 600 | 626 | } |
| 601 | 627 | |
| 602 | - /** |
|
| 603 | - * Displays a new payment method entry form. |
|
| 604 | - * |
|
| 605 | - * @since 1.0.19 |
|
| 606 | - */ |
|
| 607 | - public function new_payment_method_entry( $form ) { |
|
| 608 | - echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses( $form, getpaid_allowed_html() ) . '</div>'; |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - /** |
|
| 612 | - * Grab and display our saved payment methods. |
|
| 613 | - * |
|
| 614 | - * @since 1.0.19 |
|
| 615 | - */ |
|
| 616 | - public function saved_payment_methods() { |
|
| 617 | - echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
| 618 | - |
|
| 619 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
| 620 | - $this->get_saved_payment_method_option_html( $token ); |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - $this->get_new_payment_method_option_html(); |
|
| 624 | - echo '</ul>'; |
|
| 625 | - |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - /** |
|
| 629 | - * Gets saved payment method HTML from a token. |
|
| 630 | - * |
|
| 631 | - * @since 1.0.19 |
|
| 632 | - * @param array $token Payment Token. |
|
| 633 | - * @return string Generated payment method HTML |
|
| 634 | - */ |
|
| 635 | - public function get_saved_payment_method_option_html( $token ) { |
|
| 636 | - |
|
| 637 | - printf( |
|
| 638 | - '<li class="getpaid-payment-method form-group mb-3"> |
|
| 628 | + /** |
|
| 629 | + * Gets saved payment method HTML from a token. |
|
| 630 | + * |
|
| 631 | + * @since 1.0.19 |
|
| 632 | + * @param array $token Payment Token. |
|
| 633 | + * @return string Generated payment method HTML |
|
| 634 | + */ |
|
| 635 | + public function get_saved_payment_method_option_html( $token ) { |
|
| 636 | + |
|
| 637 | + printf( |
|
| 638 | + '<li class="getpaid-payment-method form-group mb-3"> |
|
| 639 | 639 | <label> |
| 640 | 640 | <input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" data-currency="%5$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s /> |
| 641 | 641 | <span>%3$s</span> |
| 642 | 642 | </label> |
| 643 | 643 | </li>', |
| 644 | - esc_attr( $this->id ), |
|
| 645 | - esc_attr( $token['id'] ), |
|
| 646 | - esc_html( $token['name'] ), |
|
| 647 | - checked( empty( $token['default'] ), false, false ), |
|
| 648 | - empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] ) |
|
| 649 | - ); |
|
| 650 | - |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - /** |
|
| 654 | - * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
| 655 | - * |
|
| 656 | - * @since 1.0.19 |
|
| 657 | - */ |
|
| 658 | - public function get_new_payment_method_option_html() { |
|
| 659 | - |
|
| 660 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
| 661 | - |
|
| 662 | - printf( |
|
| 663 | - '<li class="getpaid-new-payment-method"> |
|
| 644 | + esc_attr( $this->id ), |
|
| 645 | + esc_attr( $token['id'] ), |
|
| 646 | + esc_html( $token['name'] ), |
|
| 647 | + checked( empty( $token['default'] ), false, false ), |
|
| 648 | + empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] ) |
|
| 649 | + ); |
|
| 650 | + |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + /** |
|
| 654 | + * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
| 655 | + * |
|
| 656 | + * @since 1.0.19 |
|
| 657 | + */ |
|
| 658 | + public function get_new_payment_method_option_html() { |
|
| 659 | + |
|
| 660 | + $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
| 661 | + |
|
| 662 | + printf( |
|
| 663 | + '<li class="getpaid-new-payment-method"> |
|
| 664 | 664 | <label> |
| 665 | 665 | <input name="getpaid-%1$s-payment-method" type="radio" data-currency="none" value="new" style="width:auto;" /> |
| 666 | 666 | <span>%2$s</span> |
| 667 | 667 | </label> |
| 668 | 668 | </li>', |
| 669 | - esc_attr( $this->id ), |
|
| 670 | - esc_html( $label ) |
|
| 671 | - ); |
|
| 672 | - |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - /** |
|
| 676 | - * Outputs a checkbox for saving a new payment method to the database. |
|
| 677 | - * |
|
| 678 | - * @since 1.0.19 |
|
| 679 | - */ |
|
| 680 | - public function save_payment_method_checkbox() { |
|
| 681 | - |
|
| 682 | - aui()->input( |
|
| 683 | - array( |
|
| 684 | - 'type' => 'checkbox', |
|
| 685 | - 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
| 686 | - 'id' => esc_attr( uniqid( $this->id ) ), |
|
| 687 | - 'required' => false, |
|
| 688 | - 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
| 689 | - 'value' => 'true', |
|
| 690 | - 'checked' => true, |
|
| 691 | - 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
| 692 | - ), |
|
| 693 | - true |
|
| 694 | - ); |
|
| 695 | - |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - /** |
|
| 699 | - * Registers the gateway. |
|
| 700 | - * |
|
| 701 | - * @return array |
|
| 702 | - */ |
|
| 703 | - public function register_gateway( $gateways ) { |
|
| 704 | - |
|
| 705 | - $gateways[ $this->id ] = array( |
|
| 706 | - |
|
| 707 | - 'admin_label' => $this->method_title, |
|
| 669 | + esc_attr( $this->id ), |
|
| 670 | + esc_html( $label ) |
|
| 671 | + ); |
|
| 672 | + |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + /** |
|
| 676 | + * Outputs a checkbox for saving a new payment method to the database. |
|
| 677 | + * |
|
| 678 | + * @since 1.0.19 |
|
| 679 | + */ |
|
| 680 | + public function save_payment_method_checkbox() { |
|
| 681 | + |
|
| 682 | + aui()->input( |
|
| 683 | + array( |
|
| 684 | + 'type' => 'checkbox', |
|
| 685 | + 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
| 686 | + 'id' => esc_attr( uniqid( $this->id ) ), |
|
| 687 | + 'required' => false, |
|
| 688 | + 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
| 689 | + 'value' => 'true', |
|
| 690 | + 'checked' => true, |
|
| 691 | + 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
| 692 | + ), |
|
| 693 | + true |
|
| 694 | + ); |
|
| 695 | + |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + /** |
|
| 699 | + * Registers the gateway. |
|
| 700 | + * |
|
| 701 | + * @return array |
|
| 702 | + */ |
|
| 703 | + public function register_gateway( $gateways ) { |
|
| 704 | + |
|
| 705 | + $gateways[ $this->id ] = array( |
|
| 706 | + |
|
| 707 | + 'admin_label' => $this->method_title, |
|
| 708 | 708 | 'checkout_label' => $this->title, |
| 709 | - 'ordering' => $this->order, |
|
| 709 | + 'ordering' => $this->order, |
|
| 710 | 710 | |
| 711 | - ); |
|
| 711 | + ); |
|
| 712 | 712 | |
| 713 | - return $gateways; |
|
| 713 | + return $gateways; |
|
| 714 | 714 | |
| 715 | - } |
|
| 715 | + } |
|
| 716 | 716 | |
| 717 | - /** |
|
| 718 | - * Checks whether or not this is a sandbox request. |
|
| 719 | - * |
|
| 720 | - * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
| 721 | - * @return bool |
|
| 722 | - */ |
|
| 723 | - public function is_sandbox( $invoice = null ) { |
|
| 717 | + /** |
|
| 718 | + * Checks whether or not this is a sandbox request. |
|
| 719 | + * |
|
| 720 | + * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
| 721 | + * @return bool |
|
| 722 | + */ |
|
| 723 | + public function is_sandbox( $invoice = null ) { |
|
| 724 | 724 | |
| 725 | - if ( is_a( $invoice, 'WPInv_Invoice' ) && ! $invoice->needs_payment() ) { |
|
| 726 | - return $invoice->get_mode() === 'test'; |
|
| 727 | - } |
|
| 725 | + if ( is_a( $invoice, 'WPInv_Invoice' ) && ! $invoice->needs_payment() ) { |
|
| 726 | + return $invoice->get_mode() === 'test'; |
|
| 727 | + } |
|
| 728 | 728 | |
| 729 | - return wpinv_is_test_mode( $this->id ); |
|
| 729 | + return wpinv_is_test_mode( $this->id ); |
|
| 730 | 730 | |
| 731 | - } |
|
| 731 | + } |
|
| 732 | 732 | |
| 733 | - /** |
|
| 734 | - * Renames the checkout button |
|
| 735 | - * |
|
| 736 | - * @return string |
|
| 737 | - */ |
|
| 738 | - public function rename_checkout_button() { |
|
| 739 | - return $this->checkout_button_text; |
|
| 740 | - } |
|
| 733 | + /** |
|
| 734 | + * Renames the checkout button |
|
| 735 | + * |
|
| 736 | + * @return string |
|
| 737 | + */ |
|
| 738 | + public function rename_checkout_button() { |
|
| 739 | + return $this->checkout_button_text; |
|
| 740 | + } |
|
| 741 | 741 | |
| 742 | - /** |
|
| 743 | - * Validate gateway currency |
|
| 744 | - * |
|
| 745 | - * @return bool |
|
| 746 | - */ |
|
| 747 | - public function validate_currency( $validation, $currency ) { |
|
| 742 | + /** |
|
| 743 | + * Validate gateway currency |
|
| 744 | + * |
|
| 745 | + * @return bool |
|
| 746 | + */ |
|
| 747 | + public function validate_currency( $validation, $currency ) { |
|
| 748 | 748 | |
| 749 | - // Required currencies. |
|
| 750 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
| 751 | - return false; |
|
| 752 | - } |
|
| 749 | + // Required currencies. |
|
| 750 | + if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
| 751 | + return false; |
|
| 752 | + } |
|
| 753 | 753 | |
| 754 | - // Excluded currencies. |
|
| 755 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
| 756 | - return false; |
|
| 757 | - } |
|
| 754 | + // Excluded currencies. |
|
| 755 | + if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
| 756 | + return false; |
|
| 757 | + } |
|
| 758 | 758 | |
| 759 | - return $validation; |
|
| 760 | - } |
|
| 759 | + return $validation; |
|
| 760 | + } |
|
| 761 | 761 | |
| 762 | - /** |
|
| 763 | - * Displays an error |
|
| 764 | - * |
|
| 765 | - */ |
|
| 766 | - public function show_error( $code, $message, $type ) { |
|
| 762 | + /** |
|
| 763 | + * Displays an error |
|
| 764 | + * |
|
| 765 | + */ |
|
| 766 | + public function show_error( $code, $message, $type ) { |
|
| 767 | 767 | |
| 768 | - if ( is_admin() ) { |
|
| 769 | - getpaid_admin()->{"show_$type"}( $message ); |
|
| 770 | - } |
|
| 768 | + if ( is_admin() ) { |
|
| 769 | + getpaid_admin()->{"show_$type"}( $message ); |
|
| 770 | + } |
|
| 771 | 771 | |
| 772 | - wpinv_set_error( $code, $message, $type ); |
|
| 772 | + wpinv_set_error( $code, $message, $type ); |
|
| 773 | 773 | |
| 774 | - } |
|
| 774 | + } |
|
| 775 | 775 | |
| 776 | 776 | } |
@@ -25,8 +25,8 @@ discard block |
||
| 25 | 25 | $defaults[ $key ] = $setting['std']; |
| 26 | 26 | } |
| 27 | 27 | } |
| 28 | - } |
|
| 29 | - } |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | 31 | return $defaults; |
| 32 | 32 | |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * |
| 145 | 145 | */ |
| 146 | 146 | function wpinv_register_settings() { |
| 147 | - do_action( 'getpaid_before_register_settings' ); |
|
| 147 | + do_action( 'getpaid_before_register_settings' ); |
|
| 148 | 148 | |
| 149 | 149 | // Loop through all tabs. |
| 150 | 150 | foreach ( wpinv_get_registered_settings() as $tab => $sections ) { |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | $settings = $sections; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - do_action( "getpaid_register_{$tab}_{$section}" ); |
|
| 162 | + do_action( "getpaid_register_{$tab}_{$section}" ); |
|
| 163 | 163 | |
| 164 | 164 | // Register the setting section. |
| 165 | 165 | add_settings_section( |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | // Creates our settings in the options table. |
| 181 | 181 | register_setting( 'wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize' ); |
| 182 | 182 | |
| 183 | - do_action( 'getpaid_after_register_settings' ); |
|
| 183 | + do_action( 'getpaid_after_register_settings' ); |
|
| 184 | 184 | } |
| 185 | 185 | add_action( 'admin_init', 'wpinv_register_settings' ); |
| 186 | 186 | |
@@ -197,13 +197,13 @@ discard block |
||
| 197 | 197 | $name = isset( $option['name'] ) ? $option['name'] : ''; |
| 198 | 198 | $cb = "wpinv_{$option['type']}_callback"; |
| 199 | 199 | $section = "wpinv_settings_{$tab}_$section"; |
| 200 | - $is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page']; |
|
| 200 | + $is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page']; |
|
| 201 | 201 | |
| 202 | - if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) { |
|
| 203 | - $tip = wpinv_clean( $option['desc'] ); |
|
| 204 | - $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
|
| 205 | - unset( $option['desc'] ); |
|
| 206 | - } |
|
| 202 | + if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) { |
|
| 203 | + $tip = wpinv_clean( $option['desc'] ); |
|
| 204 | + $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
|
| 205 | + unset( $option['desc'] ); |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | 208 | // Loop through all tabs. |
| 209 | 209 | add_settings_field( |
@@ -230,9 +230,9 @@ discard block |
||
| 230 | 230 | 'faux' => isset( $option['faux'] ) ? $option['faux'] : false, |
| 231 | 231 | 'onchange' => isset( $option['onchange'] ) ? $option['onchange'] : '', |
| 232 | 232 | 'custom' => isset( $option['custom'] ) ? $option['custom'] : '', |
| 233 | - 'default_content' => isset( $option['default_content'] ) ? $option['default_content'] : '', |
|
| 234 | - 'class' => isset( $option['class'] ) ? $option['class'] : '', |
|
| 235 | - 'style' => isset( $option['style'] ) ? $option['style'] : '', |
|
| 233 | + 'default_content' => isset( $option['default_content'] ) ? $option['default_content'] : '', |
|
| 234 | + 'class' => isset( $option['class'] ) ? $option['class'] : '', |
|
| 235 | + 'style' => isset( $option['style'] ) ? $option['style'] : '', |
|
| 236 | 236 | 'cols' => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50, |
| 237 | 237 | 'rows' => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5, |
| 238 | 238 | ) |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | * @return array |
| 247 | 247 | */ |
| 248 | 248 | function wpinv_get_registered_settings() { |
| 249 | - return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) ); |
|
| 249 | + return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) ); |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | /** |
@@ -265,18 +265,18 @@ discard block |
||
| 265 | 265 | */ |
| 266 | 266 | function wpinv_settings_sanitize( $input = array() ) { |
| 267 | 267 | |
| 268 | - $wpinv_options = wpinv_get_options(); |
|
| 269 | - $raw_referrer = wp_get_raw_referer(); |
|
| 268 | + $wpinv_options = wpinv_get_options(); |
|
| 269 | + $raw_referrer = wp_get_raw_referer(); |
|
| 270 | 270 | |
| 271 | 271 | if ( empty( $raw_referrer ) ) { |
| 272 | - return array_merge( $wpinv_options, $input ); |
|
| 272 | + return array_merge( $wpinv_options, $input ); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | wp_parse_str( $raw_referrer, $referrer ); |
| 276 | 276 | |
| 277 | - if ( in_array( 'gp-setup', $referrer ) ) { |
|
| 278 | - return array_merge( $wpinv_options, $input ); |
|
| 279 | - } |
|
| 277 | + if ( in_array( 'gp-setup', $referrer ) ) { |
|
| 278 | + return array_merge( $wpinv_options, $input ); |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | 281 | $settings = wpinv_get_registered_settings(); |
| 282 | 282 | $tab = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general'; |
@@ -298,10 +298,10 @@ discard block |
||
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | // General filter |
| 301 | - $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
| 301 | + $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
| 302 | 302 | |
| 303 | - // Key specific filter. |
|
| 304 | - $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] ); |
|
| 303 | + // Key specific filter. |
|
| 304 | + $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] ); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | // Loop through the whitelist and unset any that are empty for the tab being saved |
@@ -344,14 +344,14 @@ discard block |
||
| 344 | 344 | |
| 345 | 345 | foreach ( $new_rates as $rate ) { |
| 346 | 346 | |
| 347 | - $rate['rate'] = wpinv_sanitize_amount( $rate['rate'] ); |
|
| 348 | - $rate['name'] = sanitize_text_field( $rate['name'] ); |
|
| 349 | - $rate['state'] = sanitize_text_field( $rate['state'] ); |
|
| 350 | - $rate['country'] = sanitize_text_field( $rate['country'] ); |
|
| 351 | - $rate['global'] = empty( $rate['state'] ); |
|
| 352 | - $tax_rates[] = $rate; |
|
| 347 | + $rate['rate'] = wpinv_sanitize_amount( $rate['rate'] ); |
|
| 348 | + $rate['name'] = sanitize_text_field( $rate['name'] ); |
|
| 349 | + $rate['state'] = sanitize_text_field( $rate['state'] ); |
|
| 350 | + $rate['country'] = sanitize_text_field( $rate['country'] ); |
|
| 351 | + $rate['global'] = empty( $rate['state'] ); |
|
| 352 | + $tax_rates[] = $rate; |
|
| 353 | 353 | |
| 354 | - } |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | 356 | update_option( 'wpinv_tax_rates', $tax_rates ); |
| 357 | 357 | |
@@ -364,21 +364,21 @@ discard block |
||
| 364 | 364 | return $input; |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | - if ( empty( $_POST['wpinv_tax_rules_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_tax_rules_nonce'], 'wpinv_tax_rules' ) ) { |
|
| 368 | - return $input; |
|
| 369 | - } |
|
| 367 | + if ( empty( $_POST['wpinv_tax_rules_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_tax_rules_nonce'], 'wpinv_tax_rules' ) ) { |
|
| 368 | + return $input; |
|
| 369 | + } |
|
| 370 | 370 | |
| 371 | 371 | $new_rules = ! empty( $_POST['tax_rules'] ) ? wp_kses_post_deep( array_values( $_POST['tax_rules'] ) ) : array(); |
| 372 | 372 | $tax_rules = array(); |
| 373 | 373 | |
| 374 | 374 | foreach ( $new_rules as $rule ) { |
| 375 | 375 | |
| 376 | - $rule['key'] = sanitize_title_with_dashes( $rule['key'] ); |
|
| 377 | - $rule['label'] = sanitize_text_field( $rule['label'] ); |
|
| 378 | - $rule['tax_base'] = sanitize_text_field( $rule['tax_base'] ); |
|
| 379 | - $tax_rules[] = $rule; |
|
| 376 | + $rule['key'] = sanitize_title_with_dashes( $rule['key'] ); |
|
| 377 | + $rule['label'] = sanitize_text_field( $rule['label'] ); |
|
| 378 | + $rule['tax_base'] = sanitize_text_field( $rule['tax_base'] ); |
|
| 379 | + $tax_rules[] = $rule; |
|
| 380 | 380 | |
| 381 | - } |
|
| 381 | + } |
|
| 382 | 382 | |
| 383 | 383 | update_option( 'wpinv_tax_rules', $tax_rules ); |
| 384 | 384 | |
@@ -391,11 +391,11 @@ discard block |
||
| 391 | 391 | $tabs['general'] = __( 'General', 'invoicing' ); |
| 392 | 392 | $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' ); |
| 393 | 393 | $tabs['taxes'] = __( 'Taxes', 'invoicing' ); |
| 394 | - $tabs['emails'] = __( 'Emails', 'invoicing' ); |
|
| 394 | + $tabs['emails'] = __( 'Emails', 'invoicing' ); |
|
| 395 | 395 | |
| 396 | - if ( count( getpaid_get_integration_settings() ) > 0 ) { |
|
| 397 | - $tabs['integrations'] = __( 'Integrations', 'invoicing' ); |
|
| 398 | - } |
|
| 396 | + if ( count( getpaid_get_integration_settings() ) > 0 ) { |
|
| 397 | + $tabs['integrations'] = __( 'Integrations', 'invoicing' ); |
|
| 398 | + } |
|
| 399 | 399 | |
| 400 | 400 | $tabs['privacy'] = __( 'Privacy', 'invoicing' ); |
| 401 | 401 | $tabs['misc'] = __( 'Misc', 'invoicing' ); |
@@ -426,53 +426,53 @@ discard block |
||
| 426 | 426 | 'general' => apply_filters( |
| 427 | 427 | 'wpinv_settings_sections_general', |
| 428 | 428 | array( |
| 429 | - 'main' => __( 'General Settings', 'invoicing' ), |
|
| 430 | - 'page_section' => __( 'Page Settings', 'invoicing' ), |
|
| 431 | - 'currency_section' => __( 'Currency Settings', 'invoicing' ), |
|
| 432 | - 'labels' => __( 'Label Texts', 'invoicing' ), |
|
| 429 | + 'main' => __( 'General Settings', 'invoicing' ), |
|
| 430 | + 'page_section' => __( 'Page Settings', 'invoicing' ), |
|
| 431 | + 'currency_section' => __( 'Currency Settings', 'invoicing' ), |
|
| 432 | + 'labels' => __( 'Label Texts', 'invoicing' ), |
|
| 433 | 433 | ) |
| 434 | 434 | ), |
| 435 | 435 | 'gateways' => apply_filters( |
| 436 | 436 | 'wpinv_settings_sections_gateways', |
| 437 | 437 | array( |
| 438 | - 'main' => __( 'Gateway Settings', 'invoicing' ), |
|
| 438 | + 'main' => __( 'Gateway Settings', 'invoicing' ), |
|
| 439 | 439 | ) |
| 440 | 440 | ), |
| 441 | 441 | 'taxes' => apply_filters( |
| 442 | 442 | 'wpinv_settings_sections_taxes', |
| 443 | 443 | array( |
| 444 | - 'main' => __( 'Tax Settings', 'invoicing' ), |
|
| 445 | - 'rules' => __( 'Tax Rules', 'invoicing' ), |
|
| 446 | - 'rates' => __( 'Tax Rates', 'invoicing' ), |
|
| 447 | - 'vat' => __( 'EU VAT Settings', 'invoicing' ), |
|
| 444 | + 'main' => __( 'Tax Settings', 'invoicing' ), |
|
| 445 | + 'rules' => __( 'Tax Rules', 'invoicing' ), |
|
| 446 | + 'rates' => __( 'Tax Rates', 'invoicing' ), |
|
| 447 | + 'vat' => __( 'EU VAT Settings', 'invoicing' ), |
|
| 448 | 448 | ) |
| 449 | 449 | ), |
| 450 | 450 | 'emails' => apply_filters( |
| 451 | 451 | 'wpinv_settings_sections_emails', |
| 452 | 452 | array( |
| 453 | - 'main' => __( 'Email Settings', 'invoicing' ), |
|
| 453 | + 'main' => __( 'Email Settings', 'invoicing' ), |
|
| 454 | 454 | ) |
| 455 | 455 | ), |
| 456 | 456 | |
| 457 | - 'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ), |
|
| 457 | + 'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ), |
|
| 458 | 458 | |
| 459 | 459 | 'privacy' => apply_filters( |
| 460 | 460 | 'wpinv_settings_sections_privacy', |
| 461 | 461 | array( |
| 462 | - 'main' => __( 'Privacy policy', 'invoicing' ), |
|
| 462 | + 'main' => __( 'Privacy policy', 'invoicing' ), |
|
| 463 | 463 | ) |
| 464 | 464 | ), |
| 465 | 465 | 'misc' => apply_filters( |
| 466 | 466 | 'wpinv_settings_sections_misc', |
| 467 | 467 | array( |
| 468 | - 'main' => __( 'Miscellaneous', 'invoicing' ), |
|
| 469 | - 'custom-css' => __( 'Custom CSS', 'invoicing' ), |
|
| 468 | + 'main' => __( 'Miscellaneous', 'invoicing' ), |
|
| 469 | + 'custom-css' => __( 'Custom CSS', 'invoicing' ), |
|
| 470 | 470 | ) |
| 471 | 471 | ), |
| 472 | 472 | 'tools' => apply_filters( |
| 473 | 473 | 'wpinv_settings_sections_tools', |
| 474 | 474 | array( |
| 475 | - 'main' => __( 'Diagnostic Tools', 'invoicing' ), |
|
| 475 | + 'main' => __( 'Diagnostic Tools', 'invoicing' ), |
|
| 476 | 476 | ) |
| 477 | 477 | ), |
| 478 | 478 | ); |
@@ -483,46 +483,46 @@ discard block |
||
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | function wpinv_get_pages( $with_slug = false, $default_label = null ) { |
| 486 | - $pages_options = array(); |
|
| 486 | + $pages_options = array(); |
|
| 487 | 487 | |
| 488 | - if ( $default_label !== null && $default_label !== false ) { |
|
| 489 | - $pages_options = array( '' => $default_label ); // Blank option |
|
| 490 | - } |
|
| 488 | + if ( $default_label !== null && $default_label !== false ) { |
|
| 489 | + $pages_options = array( '' => $default_label ); // Blank option |
|
| 490 | + } |
|
| 491 | 491 | |
| 492 | - $pages = get_pages(); |
|
| 493 | - if ( $pages ) { |
|
| 494 | - foreach ( $pages as $page ) { |
|
| 495 | - $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
| 492 | + $pages = get_pages(); |
|
| 493 | + if ( $pages ) { |
|
| 494 | + foreach ( $pages as $page ) { |
|
| 495 | + $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
|
| 496 | 496 | $pages_options[ $page->ID ] = $title; |
| 497 | - } |
|
| 498 | - } |
|
| 497 | + } |
|
| 498 | + } |
|
| 499 | 499 | |
| 500 | - return $pages_options; |
|
| 500 | + return $pages_options; |
|
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | function wpinv_header_callback( $args ) { |
| 504 | - if ( ! empty( $args['desc'] ) ) { |
|
| 504 | + if ( ! empty( $args['desc'] ) ) { |
|
| 505 | 505 | echo wp_kses_post( $args['desc'] ); |
| 506 | 506 | } |
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | function wpinv_hidden_callback( $args ) { |
| 510 | 510 | |
| 511 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 512 | - $value = wpinv_get_option( $args['id'], $std ); |
|
| 511 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 512 | + $value = wpinv_get_option( $args['id'], $std ); |
|
| 513 | 513 | |
| 514 | - if ( isset( $args['set_value'] ) ) { |
|
| 515 | - $value = $args['set_value']; |
|
| 516 | - } |
|
| 514 | + if ( isset( $args['set_value'] ) ) { |
|
| 515 | + $value = $args['set_value']; |
|
| 516 | + } |
|
| 517 | 517 | |
| 518 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
| 519 | - $args['readonly'] = true; |
|
| 520 | - $name = ''; |
|
| 521 | - } else { |
|
| 522 | - $name = 'wpinv_settings[' . esc_attr( $args['id'] ) . ']'; |
|
| 523 | - } |
|
| 518 | + if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
| 519 | + $args['readonly'] = true; |
|
| 520 | + $name = ''; |
|
| 521 | + } else { |
|
| 522 | + $name = 'wpinv_settings[' . esc_attr( $args['id'] ) . ']'; |
|
| 523 | + } |
|
| 524 | 524 | |
| 525 | - echo '<input type="hidden" id="wpinv_settings[' . esc_attr( $args['id'] ) . ']" name="' . esc_attr( $name ) . '" value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
| 525 | + echo '<input type="hidden" id="wpinv_settings[' . esc_attr( $args['id'] ) . ']" name="' . esc_attr( $name ) . '" value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
| 526 | 526 | |
| 527 | 527 | } |
| 528 | 528 | |
@@ -531,12 +531,12 @@ discard block |
||
| 531 | 531 | */ |
| 532 | 532 | function wpinv_checkbox_callback( $args ) { |
| 533 | 533 | |
| 534 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 535 | - $std = wpinv_get_option( $args['id'], $std ); |
|
| 536 | - $id = esc_attr( $args['id'] ); |
|
| 534 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 535 | + $std = wpinv_get_option( $args['id'], $std ); |
|
| 536 | + $id = esc_attr( $args['id'] ); |
|
| 537 | 537 | |
| 538 | - getpaid_hidden_field( "wpinv_settings[$id]", '0' ); |
|
| 539 | - ?> |
|
| 538 | + getpaid_hidden_field( "wpinv_settings[$id]", '0' ); |
|
| 539 | + ?> |
|
| 540 | 540 | <label> |
| 541 | 541 | <input id="wpinv-settings-<?php echo esc_attr( $id ); ?>" name="wpinv_settings[<?php echo esc_attr( $id ); ?>]" <?php checked( empty( $std ), false ); ?> value="1" type="checkbox" /> |
| 542 | 542 | <?php echo wp_kses_post( $args['desc'] ); ?> |
@@ -546,75 +546,75 @@ discard block |
||
| 546 | 546 | |
| 547 | 547 | function wpinv_multicheck_callback( $args ) { |
| 548 | 548 | |
| 549 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 550 | - $class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
| 549 | + $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
| 550 | + $class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
| 551 | 551 | |
| 552 | - if ( ! empty( $args['options'] ) ) { |
|
| 552 | + if ( ! empty( $args['options'] ) ) { |
|
| 553 | 553 | |
| 554 | - $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
| 555 | - $value = wpinv_get_option( $args['id'], $std ); |
|
| 554 | + $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
| 555 | + $value = wpinv_get_option( $args['id'], $std ); |
|
| 556 | 556 | |
| 557 | - echo '<div class="wpi-mcheck-rows wpi-mcheck-' . esc_attr( $sanitize_id . $class ) . '">'; |
|
| 557 | + echo '<div class="wpi-mcheck-rows wpi-mcheck-' . esc_attr( $sanitize_id . $class ) . '">'; |
|
| 558 | 558 | foreach ( $args['options'] as $key => $option ) : |
| 559 | - $sanitize_key = esc_attr( wpinv_sanitize_key( $key ) ); |
|
| 560 | - if ( in_array( $sanitize_key, $value ) ) { |
|
| 561 | - $enabled = $sanitize_key; |
|
| 562 | - } else { |
|
| 563 | - $enabled = null; |
|
| 564 | - } |
|
| 565 | - echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
| 566 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
| 567 | - endforeach; |
|
| 568 | - echo '</div>'; |
|
| 569 | - echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
| 570 | - } |
|
| 559 | + $sanitize_key = esc_attr( wpinv_sanitize_key( $key ) ); |
|
| 560 | + if ( in_array( $sanitize_key, $value ) ) { |
|
| 561 | + $enabled = $sanitize_key; |
|
| 562 | + } else { |
|
| 563 | + $enabled = null; |
|
| 564 | + } |
|
| 565 | + echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
| 566 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
| 567 | + endforeach; |
|
| 568 | + echo '</div>'; |
|
| 569 | + echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
| 570 | + } |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | function wpinv_payment_icons_callback( $args ) { |
| 574 | 574 | |
| 575 | 575 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 576 | - $value = wpinv_get_option( $args['id'], false ); |
|
| 576 | + $value = wpinv_get_option( $args['id'], false ); |
|
| 577 | 577 | |
| 578 | - if ( ! empty( $args['options'] ) ) { |
|
| 579 | - foreach ( $args['options'] as $key => $option ) { |
|
| 578 | + if ( ! empty( $args['options'] ) ) { |
|
| 579 | + foreach ( $args['options'] as $key => $option ) { |
|
| 580 | 580 | $sanitize_key = wpinv_sanitize_key( $key ); |
| 581 | 581 | |
| 582 | - if ( empty( $value ) ) { |
|
| 583 | - $enabled = $option; |
|
| 584 | - } else { |
|
| 585 | - $enabled = null; |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
| 589 | - |
|
| 590 | - echo '<input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
| 591 | - |
|
| 592 | - if ( wpinv_string_is_image_url( $key ) ) { |
|
| 593 | - echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
| 594 | - } else { |
|
| 595 | - $card = strtolower( str_replace( ' ', '', $option ) ); |
|
| 596 | - |
|
| 597 | - if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
| 598 | - $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
| 599 | - } else { |
|
| 600 | - $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
| 601 | - $content_dir = WP_CONTENT_DIR; |
|
| 602 | - |
|
| 603 | - if ( function_exists( 'wp_normalize_path' ) ) { |
|
| 604 | - // Replaces backslashes with forward slashes for Windows systems |
|
| 605 | - $image = wp_normalize_path( $image ); |
|
| 606 | - $content_dir = wp_normalize_path( $content_dir ); |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - $image = str_replace( $content_dir, content_url(), $image ); |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
| 613 | - } |
|
| 614 | - echo wp_kses_post( $option ) . '</label>'; |
|
| 615 | - } |
|
| 616 | - echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
| 617 | - } |
|
| 582 | + if ( empty( $value ) ) { |
|
| 583 | + $enabled = $option; |
|
| 584 | + } else { |
|
| 585 | + $enabled = null; |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
|
| 589 | + |
|
| 590 | + echo '<input name="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" id="wpinv_settings[' . esc_attr( $sanitize_id ) . '][' . esc_attr( $sanitize_key ) . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
| 591 | + |
|
| 592 | + if ( wpinv_string_is_image_url( $key ) ) { |
|
| 593 | + echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
| 594 | + } else { |
|
| 595 | + $card = strtolower( str_replace( ' ', '', $option ) ); |
|
| 596 | + |
|
| 597 | + if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
| 598 | + $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
| 599 | + } else { |
|
| 600 | + $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
| 601 | + $content_dir = WP_CONTENT_DIR; |
|
| 602 | + |
|
| 603 | + if ( function_exists( 'wp_normalize_path' ) ) { |
|
| 604 | + // Replaces backslashes with forward slashes for Windows systems |
|
| 605 | + $image = wp_normalize_path( $image ); |
|
| 606 | + $content_dir = wp_normalize_path( $content_dir ); |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + $image = str_replace( $content_dir, content_url(), $image ); |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
| 613 | + } |
|
| 614 | + echo wp_kses_post( $option ) . '</label>'; |
|
| 615 | + } |
|
| 616 | + echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
| 617 | + } |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | /** |
@@ -622,9 +622,9 @@ discard block |
||
| 622 | 622 | */ |
| 623 | 623 | function wpinv_radio_callback( $args ) { |
| 624 | 624 | |
| 625 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 626 | - $std = wpinv_get_option( $args['id'], $std ); |
|
| 627 | - ?> |
|
| 625 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 626 | + $std = wpinv_get_option( $args['id'], $std ); |
|
| 627 | + ?> |
|
| 628 | 628 | <fieldset> |
| 629 | 629 | <ul id="wpinv-settings-<?php echo esc_attr( $args['id'] ); ?>" style="margin-top: 0;"> |
| 630 | 630 | <?php foreach ( $args['options'] as $key => $option ) : ?> |
@@ -638,7 +638,7 @@ discard block |
||
| 638 | 638 | </ul> |
| 639 | 639 | </fieldset> |
| 640 | 640 | <?php |
| 641 | - getpaid_settings_description_callback( $args ); |
|
| 641 | + getpaid_settings_description_callback( $args ); |
|
| 642 | 642 | } |
| 643 | 643 | |
| 644 | 644 | /** |
@@ -646,10 +646,10 @@ discard block |
||
| 646 | 646 | */ |
| 647 | 647 | function getpaid_settings_description_callback( $args ) { |
| 648 | 648 | |
| 649 | - if ( ! empty( $args['desc'] ) ) { |
|
| 650 | - $description = $args['desc']; |
|
| 651 | - echo wp_kses_post( "<p class='description'>$description</p>" ); |
|
| 652 | - } |
|
| 649 | + if ( ! empty( $args['desc'] ) ) { |
|
| 650 | + $description = $args['desc']; |
|
| 651 | + echo wp_kses_post( "<p class='description'>$description</p>" ); |
|
| 652 | + } |
|
| 653 | 653 | |
| 654 | 654 | } |
| 655 | 655 | |
@@ -658,7 +658,7 @@ discard block |
||
| 658 | 658 | */ |
| 659 | 659 | function wpinv_gateways_callback() { |
| 660 | 660 | |
| 661 | - ?> |
|
| 661 | + ?> |
|
| 662 | 662 | </td> |
| 663 | 663 | </tr> |
| 664 | 664 | <tr class="bsui"> |
@@ -672,26 +672,26 @@ discard block |
||
| 672 | 672 | |
| 673 | 673 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 674 | 674 | $class = ! empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
| 675 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 676 | - $value = wpinv_get_option( $args['id'], $std ); |
|
| 675 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 676 | + $value = wpinv_get_option( $args['id'], $std ); |
|
| 677 | 677 | |
| 678 | - echo '<select name="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" class="' . esc_attr( $class ) . '" >'; |
|
| 678 | + echo '<select name="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" class="' . esc_attr( $class ) . '" >'; |
|
| 679 | 679 | |
| 680 | - foreach ( $args['options'] as $key => $option ) : |
|
| 680 | + foreach ( $args['options'] as $key => $option ) : |
|
| 681 | 681 | |
| 682 | - echo '<option value="' . esc_attr( $key ) . '" '; |
|
| 682 | + echo '<option value="' . esc_attr( $key ) . '" '; |
|
| 683 | 683 | |
| 684 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
| 684 | + if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
| 685 | 685 | selected( $key, $args['selected'] ); |
| 686 | 686 | } else { |
| 687 | 687 | selected( $key, $value ); |
| 688 | 688 | } |
| 689 | 689 | |
| 690 | - echo '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
| 691 | - endforeach; |
|
| 690 | + echo '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
| 691 | + endforeach; |
|
| 692 | 692 | |
| 693 | - echo '</select>'; |
|
| 694 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 693 | + echo '</select>'; |
|
| 694 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | /** |
@@ -702,38 +702,38 @@ discard block |
||
| 702 | 702 | */ |
| 703 | 703 | function wpinv_settings_attrs_helper( $args ) { |
| 704 | 704 | |
| 705 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 706 | - $id = esc_attr( $args['id'] ); |
|
| 707 | - $value = is_scalar( $value ) ? $value : ''; |
|
| 708 | - |
|
| 709 | - $attrs = array( |
|
| 710 | - 'name' => ! empty( $args['faux'] ) ? false : "wpinv_settings[$id]", |
|
| 711 | - 'readonly' => ! empty( $args['faux'] ), |
|
| 712 | - 'value' => ! empty( $args['faux'] ) ? $value : wpinv_get_option( $args['id'], $value ), |
|
| 713 | - 'id' => 'wpinv-settings-' . $args['id'], |
|
| 714 | - 'style' => $args['style'], |
|
| 715 | - 'class' => $args['class'], |
|
| 716 | - 'placeholder' => $args['placeholder'], |
|
| 717 | - 'data-placeholder' => $args['placeholder'], |
|
| 718 | - ); |
|
| 705 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 706 | + $id = esc_attr( $args['id'] ); |
|
| 707 | + $value = is_scalar( $value ) ? $value : ''; |
|
| 708 | + |
|
| 709 | + $attrs = array( |
|
| 710 | + 'name' => ! empty( $args['faux'] ) ? false : "wpinv_settings[$id]", |
|
| 711 | + 'readonly' => ! empty( $args['faux'] ), |
|
| 712 | + 'value' => ! empty( $args['faux'] ) ? $value : wpinv_get_option( $args['id'], $value ), |
|
| 713 | + 'id' => 'wpinv-settings-' . $args['id'], |
|
| 714 | + 'style' => $args['style'], |
|
| 715 | + 'class' => $args['class'], |
|
| 716 | + 'placeholder' => $args['placeholder'], |
|
| 717 | + 'data-placeholder' => $args['placeholder'], |
|
| 718 | + ); |
|
| 719 | 719 | |
| 720 | - if ( ! empty( $args['onchange'] ) ) { |
|
| 721 | - $attrs['onchange'] = $args['onchange']; |
|
| 722 | - } |
|
| 720 | + if ( ! empty( $args['onchange'] ) ) { |
|
| 721 | + $attrs['onchange'] = $args['onchange']; |
|
| 722 | + } |
|
| 723 | 723 | |
| 724 | - foreach ( $attrs as $key => $value ) { |
|
| 724 | + foreach ( $attrs as $key => $value ) { |
|
| 725 | 725 | |
| 726 | - if ( false === $value ) { |
|
| 727 | - continue; |
|
| 728 | - } |
|
| 726 | + if ( false === $value ) { |
|
| 727 | + continue; |
|
| 728 | + } |
|
| 729 | 729 | |
| 730 | - if ( true === $value ) { |
|
| 731 | - echo ' ' . esc_attr( $key ); |
|
| 732 | - } else { |
|
| 733 | - echo ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
| 734 | - } |
|
| 730 | + if ( true === $value ) { |
|
| 731 | + echo ' ' . esc_attr( $key ); |
|
| 732 | + } else { |
|
| 733 | + echo ' ' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
| 734 | + } |
|
| 735 | 735 | |
| 736 | - } |
|
| 736 | + } |
|
| 737 | 737 | |
| 738 | 738 | } |
| 739 | 739 | |
@@ -742,7 +742,7 @@ discard block |
||
| 742 | 742 | */ |
| 743 | 743 | function wpinv_text_callback( $args ) { |
| 744 | 744 | |
| 745 | - ?> |
|
| 745 | + ?> |
|
| 746 | 746 | <label style="width: 100%;"> |
| 747 | 747 | <input type="text" <?php wpinv_settings_attrs_helper( $args ); ?>> |
| 748 | 748 | <?php getpaid_settings_description_callback( $args ); ?> |
@@ -756,7 +756,7 @@ discard block |
||
| 756 | 756 | */ |
| 757 | 757 | function wpinv_number_callback( $args ) { |
| 758 | 758 | |
| 759 | - ?> |
|
| 759 | + ?> |
|
| 760 | 760 | <label style="width: 100%;"> |
| 761 | 761 | <input type="number" step="<?php echo esc_attr( $args['step'] ); ?>" max="<?php echo intval( $args['max'] ); ?>" min="<?php echo intval( $args['min'] ); ?>" <?php wpinv_settings_attrs_helper( $args ); ?>> |
| 762 | 762 | <?php getpaid_settings_description_callback( $args ); ?> |
@@ -768,34 +768,34 @@ discard block |
||
| 768 | 768 | function wpinv_textarea_callback( $args ) { |
| 769 | 769 | |
| 770 | 770 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 771 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 772 | - $value = wpinv_get_option( $args['id'], $std ); |
|
| 771 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 772 | + $value = wpinv_get_option( $args['id'], $std ); |
|
| 773 | 773 | |
| 774 | 774 | $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
| 775 | 775 | $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text'; |
| 776 | 776 | |
| 777 | - echo '<textarea class="' . esc_attr( $class ) . ' txtarea-' . esc_attr( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . esc_attr( $args['cols'] ) . '" rows="' . esc_attr( $args['rows'] ) . '" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
| 778 | - echo '<br /><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 777 | + echo '<textarea class="' . esc_attr( $class ) . ' txtarea-' . esc_attr( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . esc_attr( $args['cols'] ) . '" rows="' . esc_attr( $args['rows'] ) . '" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
| 778 | + echo '<br /><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 779 | 779 | |
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | function wpinv_password_callback( $args ) { |
| 783 | 783 | |
| 784 | 784 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 785 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 786 | - $value = wpinv_get_option( $args['id'], $std ); |
|
| 785 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 786 | + $value = wpinv_get_option( $args['id'], $std ); |
|
| 787 | 787 | |
| 788 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 789 | - echo '<input type="password" class="' . esc_attr( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
| 790 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 788 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 789 | + echo '<input type="password" class="' . esc_attr( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
| 790 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 791 | 791 | |
| 792 | 792 | } |
| 793 | 793 | |
| 794 | 794 | function wpinv_missing_callback( $args ) { |
| 795 | - printf( |
|
| 796 | - esc_html__( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
| 797 | - '<strong>' . esc_html( $args['id'] ) . '</strong>' |
|
| 798 | - ); |
|
| 795 | + printf( |
|
| 796 | + esc_html__( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
| 797 | + '<strong>' . esc_html( $args['id'] ) . '</strong>' |
|
| 798 | + ); |
|
| 799 | 799 | } |
| 800 | 800 | |
| 801 | 801 | /** |
@@ -803,13 +803,13 @@ discard block |
||
| 803 | 803 | */ |
| 804 | 804 | function wpinv_select_callback( $args ) { |
| 805 | 805 | |
| 806 | - $desc = wp_kses_post( $args['desc'] ); |
|
| 807 | - $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
| 808 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 809 | - $value = wpinv_get_option( $args['id'], $value ); |
|
| 810 | - $rand = uniqid( 'random_id' ); |
|
| 806 | + $desc = wp_kses_post( $args['desc'] ); |
|
| 807 | + $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>"; |
|
| 808 | + $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 809 | + $value = wpinv_get_option( $args['id'], $value ); |
|
| 810 | + $rand = uniqid( 'random_id' ); |
|
| 811 | 811 | |
| 812 | - ?> |
|
| 812 | + ?> |
|
| 813 | 813 | <label style="width: 100%;"> |
| 814 | 814 | <select <?php wpinv_settings_attrs_helper( $args ); ?> data-allow-clear="true"> |
| 815 | 815 | <?php foreach ( $args['options'] as $option => $name ) : ?> |
@@ -842,50 +842,50 @@ discard block |
||
| 842 | 842 | function wpinv_color_select_callback( $args ) { |
| 843 | 843 | |
| 844 | 844 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 845 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 846 | - $value = wpinv_get_option( $args['id'], $std ); |
|
| 845 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 846 | + $value = wpinv_get_option( $args['id'], $std ); |
|
| 847 | 847 | |
| 848 | - echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
| 848 | + echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
| 849 | 849 | |
| 850 | - foreach ( $args['options'] as $option => $color ) { |
|
| 851 | - echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $color['label'] ) . '</option>'; |
|
| 852 | - } |
|
| 850 | + foreach ( $args['options'] as $option => $color ) { |
|
| 851 | + echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $color['label'] ) . '</option>'; |
|
| 852 | + } |
|
| 853 | 853 | |
| 854 | - echo '</select>'; |
|
| 855 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 854 | + echo '</select>'; |
|
| 855 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 856 | 856 | |
| 857 | 857 | } |
| 858 | 858 | |
| 859 | 859 | function wpinv_rich_editor_callback( $args ) { |
| 860 | - global $wp_version; |
|
| 860 | + global $wp_version; |
|
| 861 | 861 | |
| 862 | 862 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 863 | 863 | |
| 864 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 865 | - $value = wpinv_get_option( $args['id'], $std ); |
|
| 864 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 865 | + $value = wpinv_get_option( $args['id'], $std ); |
|
| 866 | 866 | |
| 867 | - if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
| 868 | - $value = $std; |
|
| 869 | - } |
|
| 867 | + if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
| 868 | + $value = $std; |
|
| 869 | + } |
|
| 870 | 870 | |
| 871 | - $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
| 871 | + $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
| 872 | 872 | |
| 873 | - echo '<div class="getpaid-settings-editor-input">'; |
|
| 874 | - if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
| 875 | - wp_editor( |
|
| 873 | + echo '<div class="getpaid-settings-editor-input">'; |
|
| 874 | + if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
| 875 | + wp_editor( |
|
| 876 | 876 | stripslashes( $value ), |
| 877 | 877 | 'wpinv_settings_' . esc_attr( $args['id'] ), |
| 878 | 878 | array( |
| 879 | - 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', |
|
| 880 | - 'textarea_rows' => absint( $rows ), |
|
| 881 | - 'media_buttons' => false, |
|
| 879 | + 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', |
|
| 880 | + 'textarea_rows' => absint( $rows ), |
|
| 881 | + 'media_buttons' => false, |
|
| 882 | 882 | ) |
| 883 | 883 | ); |
| 884 | - } else { |
|
| 885 | - echo '<textarea class="large-text" rows="10" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
| 886 | - } |
|
| 884 | + } else { |
|
| 885 | + echo '<textarea class="large-text" rows="10" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
| 886 | + } |
|
| 887 | 887 | |
| 888 | - echo '</div><br/><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 888 | + echo '</div><br/><label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 889 | 889 | |
| 890 | 890 | } |
| 891 | 891 | |
@@ -893,51 +893,51 @@ discard block |
||
| 893 | 893 | |
| 894 | 894 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 895 | 895 | |
| 896 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 897 | - $value = wpinv_get_option( $args['id'], $std ); |
|
| 896 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 897 | + $value = wpinv_get_option( $args['id'], $std ); |
|
| 898 | 898 | |
| 899 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 900 | - echo '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
| 901 | - echo '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . esc_attr__( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
| 902 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 899 | + $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 900 | + echo '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
| 901 | + echo '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . esc_attr__( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
| 902 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 903 | 903 | |
| 904 | 904 | } |
| 905 | 905 | |
| 906 | 906 | function wpinv_color_callback( $args ) { |
| 907 | 907 | |
| 908 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 909 | - $value = wpinv_get_option( $args['id'], $std ); |
|
| 908 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 909 | + $value = wpinv_get_option( $args['id'], $std ); |
|
| 910 | 910 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 911 | 911 | |
| 912 | - echo '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $std ) . '" />'; |
|
| 913 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 912 | + echo '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $std ) . '" />'; |
|
| 913 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 914 | 914 | |
| 915 | 915 | } |
| 916 | 916 | |
| 917 | 917 | function wpinv_country_states_callback( $args ) { |
| 918 | 918 | |
| 919 | - $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 920 | - $value = wpinv_get_option( $args['id'], $std ); |
|
| 919 | + $std = isset( $args['std'] ) ? $args['std'] : ''; |
|
| 920 | + $value = wpinv_get_option( $args['id'], $std ); |
|
| 921 | 921 | |
| 922 | 922 | $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
| 923 | 923 | |
| 924 | - if ( isset( $args['placeholder'] ) ) { |
|
| 925 | - $placeholder = $args['placeholder']; |
|
| 926 | - } else { |
|
| 927 | - $placeholder = ''; |
|
| 928 | - } |
|
| 924 | + if ( isset( $args['placeholder'] ) ) { |
|
| 925 | + $placeholder = $args['placeholder']; |
|
| 926 | + } else { |
|
| 927 | + $placeholder = ''; |
|
| 928 | + } |
|
| 929 | 929 | |
| 930 | - $states = wpinv_get_country_states(); |
|
| 930 | + $states = wpinv_get_country_states(); |
|
| 931 | 931 | |
| 932 | - $class = empty( $states ) ? 'wpinv-no-states' : 'wpi_select2'; |
|
| 933 | - echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="' . esc_attr( $class ) . '" data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
| 932 | + $class = empty( $states ) ? 'wpinv-no-states' : 'wpi_select2'; |
|
| 933 | + echo '<select id="wpinv_settings[' . esc_attr( $sanitize_id ) . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="' . esc_attr( $class ) . '" data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
| 934 | 934 | |
| 935 | - foreach ( $states as $option => $name ) { |
|
| 936 | - echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $name ) . '</option>'; |
|
| 937 | - } |
|
| 935 | + foreach ( $states as $option => $name ) { |
|
| 936 | + echo '<option value="' . esc_attr( $option ) . '" ' . selected( $option, $value ) . '>' . esc_html( $name ) . '</option>'; |
|
| 937 | + } |
|
| 938 | 938 | |
| 939 | - echo '</select>'; |
|
| 940 | - echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 939 | + echo '</select>'; |
|
| 940 | + echo '<label for="wpinv_settings[' . esc_attr( $sanitize_id ) . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
| 941 | 941 | |
| 942 | 942 | } |
| 943 | 943 | |
@@ -946,7 +946,7 @@ discard block |
||
| 946 | 946 | */ |
| 947 | 947 | function wpinv_tax_rates_callback() { |
| 948 | 948 | |
| 949 | - ?> |
|
| 949 | + ?> |
|
| 950 | 950 | </td> |
| 951 | 951 | </tr> |
| 952 | 952 | <tr class="bsui"> |
@@ -962,9 +962,9 @@ discard block |
||
| 962 | 962 | */ |
| 963 | 963 | function wpinv_tax_rate_callback( $tax_rate, $key ) { |
| 964 | 964 | |
| 965 | - $key = sanitize_key( $key ); |
|
| 966 | - $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate']; |
|
| 967 | - include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php'; |
|
| 965 | + $key = sanitize_key( $key ); |
|
| 966 | + $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate']; |
|
| 967 | + include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php'; |
|
| 968 | 968 | |
| 969 | 969 | } |
| 970 | 970 | |
@@ -973,7 +973,7 @@ discard block |
||
| 973 | 973 | */ |
| 974 | 974 | function wpinv_tax_rules_callback() { |
| 975 | 975 | |
| 976 | - ?> |
|
| 976 | + ?> |
|
| 977 | 977 | </td> |
| 978 | 978 | </tr> |
| 979 | 979 | <tr class="bsui"> |
@@ -1011,14 +1011,14 @@ discard block |
||
| 1011 | 1011 | <td> |
| 1012 | 1012 | <a href=" |
| 1013 | 1013 | <?php |
| 1014 | - echo esc_url( |
|
| 1015 | - wp_nonce_url( |
|
| 1016 | - add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
| 1017 | - 'getpaid-nonce', |
|
| 1018 | - 'getpaid-nonce' |
|
| 1019 | - ) |
|
| 1020 | - ); |
|
| 1021 | - ?> |
|
| 1014 | + echo esc_url( |
|
| 1015 | + wp_nonce_url( |
|
| 1016 | + add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ), |
|
| 1017 | + 'getpaid-nonce', |
|
| 1018 | + 'getpaid-nonce' |
|
| 1019 | + ) |
|
| 1020 | + ); |
|
| 1021 | + ?> |
|
| 1022 | 1022 | " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a> |
| 1023 | 1023 | </td> |
| 1024 | 1024 | </tr> |
@@ -1030,14 +1030,14 @@ discard block |
||
| 1030 | 1030 | <td> |
| 1031 | 1031 | <a href=" |
| 1032 | 1032 | <?php |
| 1033 | - echo esc_url( |
|
| 1034 | - wp_nonce_url( |
|
| 1035 | - add_query_arg( 'getpaid-admin-action', 'refresh_permalinks' ), |
|
| 1036 | - 'getpaid-nonce', |
|
| 1037 | - 'getpaid-nonce' |
|
| 1038 | - ) |
|
| 1039 | - ); |
|
| 1040 | - ?> |
|
| 1033 | + echo esc_url( |
|
| 1034 | + wp_nonce_url( |
|
| 1035 | + add_query_arg( 'getpaid-admin-action', 'refresh_permalinks' ), |
|
| 1036 | + 'getpaid-nonce', |
|
| 1037 | + 'getpaid-nonce' |
|
| 1038 | + ) |
|
| 1039 | + ); |
|
| 1040 | + ?> |
|
| 1041 | 1041 | " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a> |
| 1042 | 1042 | </td> |
| 1043 | 1043 | </tr> |
@@ -1049,14 +1049,14 @@ discard block |
||
| 1049 | 1049 | <td> |
| 1050 | 1050 | <a href=" |
| 1051 | 1051 | <?php |
| 1052 | - echo esc_url( |
|
| 1053 | - wp_nonce_url( |
|
| 1054 | - add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ), |
|
| 1055 | - 'getpaid-nonce', |
|
| 1056 | - 'getpaid-nonce' |
|
| 1057 | - ) |
|
| 1058 | - ); |
|
| 1059 | - ?> |
|
| 1052 | + echo esc_url( |
|
| 1053 | + wp_nonce_url( |
|
| 1054 | + add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ), |
|
| 1055 | + 'getpaid-nonce', |
|
| 1056 | + 'getpaid-nonce' |
|
| 1057 | + ) |
|
| 1058 | + ); |
|
| 1059 | + ?> |
|
| 1060 | 1060 | " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a> |
| 1061 | 1061 | </td> |
| 1062 | 1062 | </tr> |
@@ -1068,14 +1068,14 @@ discard block |
||
| 1068 | 1068 | <td> |
| 1069 | 1069 | <a href=" |
| 1070 | 1070 | <?php |
| 1071 | - echo esc_url( |
|
| 1072 | - wp_nonce_url( |
|
| 1073 | - add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ), |
|
| 1074 | - 'getpaid-nonce', |
|
| 1075 | - 'getpaid-nonce' |
|
| 1076 | - ) |
|
| 1077 | - ); |
|
| 1078 | - ?> |
|
| 1071 | + echo esc_url( |
|
| 1072 | + wp_nonce_url( |
|
| 1073 | + add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ), |
|
| 1074 | + 'getpaid-nonce', |
|
| 1075 | + 'getpaid-nonce' |
|
| 1076 | + ) |
|
| 1077 | + ); |
|
| 1078 | + ?> |
|
| 1079 | 1079 | " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a> |
| 1080 | 1080 | </td> |
| 1081 | 1081 | </tr> |
@@ -1088,14 +1088,14 @@ discard block |
||
| 1088 | 1088 | <td> |
| 1089 | 1089 | <a href=" |
| 1090 | 1090 | <?php |
| 1091 | - echo esc_url( |
|
| 1092 | - wp_nonce_url( |
|
| 1093 | - add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ), |
|
| 1094 | - 'getpaid-nonce', |
|
| 1095 | - 'getpaid-nonce' |
|
| 1096 | - ) |
|
| 1097 | - ); |
|
| 1098 | - ?> |
|
| 1091 | + echo esc_url( |
|
| 1092 | + wp_nonce_url( |
|
| 1093 | + add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ), |
|
| 1094 | + 'getpaid-nonce', |
|
| 1095 | + 'getpaid-nonce' |
|
| 1096 | + ) |
|
| 1097 | + ); |
|
| 1098 | + ?> |
|
| 1099 | 1099 | " class="button button-primary"><?php esc_html_e( 'Run', 'invoicing' ); ?></a> |
| 1100 | 1100 | </td> |
| 1101 | 1101 | </tr> |
@@ -1108,8 +1108,8 @@ discard block |
||
| 1108 | 1108 | <td> |
| 1109 | 1109 | <a href=" |
| 1110 | 1110 | <?php |
| 1111 | - echo esc_url( admin_url( 'index.php?page=gp-setup' ) ); |
|
| 1112 | - ?> |
|
| 1111 | + echo esc_url( admin_url( 'index.php?page=gp-setup' ) ); |
|
| 1112 | + ?> |
|
| 1113 | 1113 | " class="button button-primary"><?php esc_html_e( 'Launch', 'invoicing' ); ?></a> |
| 1114 | 1114 | </td> |
| 1115 | 1115 | </tr> |
@@ -1123,19 +1123,19 @@ discard block |
||
| 1123 | 1123 | |
| 1124 | 1124 | |
| 1125 | 1125 | function wpinv_descriptive_text_callback( $args ) { |
| 1126 | - echo wp_kses_post( $args['desc'] ); |
|
| 1126 | + echo wp_kses_post( $args['desc'] ); |
|
| 1127 | 1127 | } |
| 1128 | 1128 | |
| 1129 | 1129 | function wpinv_raw_html_callback( $args ) { |
| 1130 | - echo wp_kses( $args['desc'], getpaid_allowed_html() ); |
|
| 1130 | + echo wp_kses( $args['desc'], getpaid_allowed_html() ); |
|
| 1131 | 1131 | } |
| 1132 | 1132 | |
| 1133 | 1133 | function wpinv_hook_callback( $args ) { |
| 1134 | - do_action( 'wpinv_' . $args['id'], $args ); |
|
| 1134 | + do_action( 'wpinv_' . $args['id'], $args ); |
|
| 1135 | 1135 | } |
| 1136 | 1136 | |
| 1137 | 1137 | function wpinv_set_settings_cap() { |
| 1138 | - return wpinv_get_capability(); |
|
| 1138 | + return wpinv_get_capability(); |
|
| 1139 | 1139 | } |
| 1140 | 1140 | add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' ); |
| 1141 | 1141 | |
@@ -1159,15 +1159,15 @@ discard block |
||
| 1159 | 1159 | */ |
| 1160 | 1160 | function wpinv_get_merge_tags_help_text( $subscription = false ) { |
| 1161 | 1161 | |
| 1162 | - $url = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f'; |
|
| 1163 | - $link = sprintf( |
|
| 1164 | - '<strong><a href="%s" target="_blank">%s</a></strong>', |
|
| 1165 | - $url, |
|
| 1166 | - esc_html__( 'View available merge tags.', 'invoicing' ) |
|
| 1167 | - ); |
|
| 1162 | + $url = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f'; |
|
| 1163 | + $link = sprintf( |
|
| 1164 | + '<strong><a href="%s" target="_blank">%s</a></strong>', |
|
| 1165 | + $url, |
|
| 1166 | + esc_html__( 'View available merge tags.', 'invoicing' ) |
|
| 1167 | + ); |
|
| 1168 | 1168 | |
| 1169 | - $description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' ); |
|
| 1169 | + $description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' ); |
|
| 1170 | 1170 | |
| 1171 | - return "$description $link"; |
|
| 1171 | + return "$description $link"; |
|
| 1172 | 1172 | |
| 1173 | 1173 | } |
@@ -1,196 +1,196 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | function wpinv_is_subscription_payment( $invoice = '' ) { |
| 3 | - if ( empty( $invoice ) ) { |
|
| 4 | - return false; |
|
| 5 | - } |
|
| 3 | + if ( empty( $invoice ) ) { |
|
| 4 | + return false; |
|
| 5 | + } |
|
| 6 | 6 | |
| 7 | - if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
| 8 | - $invoice = wpinv_get_invoice( $invoice ); |
|
| 9 | - } |
|
| 7 | + if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
| 8 | + $invoice = wpinv_get_invoice( $invoice ); |
|
| 9 | + } |
|
| 10 | 10 | |
| 11 | - if ( empty( $invoice ) ) { |
|
| 12 | - return false; |
|
| 13 | - } |
|
| 11 | + if ( empty( $invoice ) ) { |
|
| 12 | + return false; |
|
| 13 | + } |
|
| 14 | 14 | |
| 15 | - if ( $invoice->is_renewal() ) { |
|
| 16 | - return true; |
|
| 17 | - } |
|
| 15 | + if ( $invoice->is_renewal() ) { |
|
| 16 | + return true; |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - return false; |
|
| 19 | + return false; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | function wpinv_payment_link_transaction_id( $invoice = '' ) { |
| 23 | - if ( empty( $invoice ) ) { |
|
| 24 | - return false; |
|
| 25 | - } |
|
| 23 | + if ( empty( $invoice ) ) { |
|
| 24 | + return false; |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
| 28 | - $invoice = wpinv_get_invoice( $invoice ); |
|
| 29 | - } |
|
| 27 | + if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
| 28 | + $invoice = wpinv_get_invoice( $invoice ); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - if ( empty( $invoice ) ) { |
|
| 32 | - return false; |
|
| 33 | - } |
|
| 31 | + if ( empty( $invoice ) ) { |
|
| 32 | + return false; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice ); |
|
| 35 | + return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice ); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) { |
| 39 | - $interval = (int)$interval > 0 ? (int)$interval : 1; |
|
| 40 | - |
|
| 41 | - if ( $trial_interval > 0 && ! empty( $trial_period ) ) { |
|
| 42 | - $amount = __( 'Free', 'invoicing' ); |
|
| 43 | - $interval = $trial_interval; |
|
| 44 | - $period = $trial_period; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - $description = ''; |
|
| 48 | - switch ( $period ) { |
|
| 49 | - case 'D': |
|
| 50 | - case 'day': |
|
| 51 | - $description = wp_sprintf( _n( '%s for the first day.', '%1$s for the first %2$d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
| 52 | - break; |
|
| 53 | - case 'W': |
|
| 54 | - case 'week': |
|
| 55 | - $description = wp_sprintf( _n( '%s for the first week.', '%1$s for the first %2$d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
| 56 | - break; |
|
| 57 | - case 'M': |
|
| 58 | - case 'month': |
|
| 59 | - $description = wp_sprintf( _n( '%s for the first month.', '%1$s for the first %2$d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
| 60 | - break; |
|
| 61 | - case 'Y': |
|
| 62 | - case 'year': |
|
| 63 | - $description = wp_sprintf( _n( '%s for the first year.', '%1$s for the first %2$d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
| 64 | - break; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval ); |
|
| 39 | + $interval = (int)$interval > 0 ? (int)$interval : 1; |
|
| 40 | + |
|
| 41 | + if ( $trial_interval > 0 && ! empty( $trial_period ) ) { |
|
| 42 | + $amount = __( 'Free', 'invoicing' ); |
|
| 43 | + $interval = $trial_interval; |
|
| 44 | + $period = $trial_period; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + $description = ''; |
|
| 48 | + switch ( $period ) { |
|
| 49 | + case 'D': |
|
| 50 | + case 'day': |
|
| 51 | + $description = wp_sprintf( _n( '%s for the first day.', '%1$s for the first %2$d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
| 52 | + break; |
|
| 53 | + case 'W': |
|
| 54 | + case 'week': |
|
| 55 | + $description = wp_sprintf( _n( '%s for the first week.', '%1$s for the first %2$d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
| 56 | + break; |
|
| 57 | + case 'M': |
|
| 58 | + case 'month': |
|
| 59 | + $description = wp_sprintf( _n( '%s for the first month.', '%1$s for the first %2$d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
| 60 | + break; |
|
| 61 | + case 'Y': |
|
| 62 | + case 'year': |
|
| 63 | + $description = wp_sprintf( _n( '%s for the first year.', '%1$s for the first %2$d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
| 64 | + break; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval ); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) { |
| 71 | - $interval = (int)$interval > 0 ? (int)$interval : 1; |
|
| 72 | - $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0; |
|
| 73 | - |
|
| 74 | - $description = ''; |
|
| 75 | - switch ( $period ) { |
|
| 76 | - case 'D': |
|
| 77 | - case 'day': |
|
| 78 | - if ( (int)$bill_times > 0 ) { |
|
| 79 | - if ( $interval > 1 ) { |
|
| 80 | - if ( $bill_times > 1 ) { |
|
| 81 | - $description = wp_sprintf( __( '%1$s for each %2$d days, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
| 82 | - } else { |
|
| 83 | - $description = wp_sprintf( __( '%1$s for %2$d days.', 'invoicing' ), $amount, $interval ); |
|
| 84 | - } |
|
| 85 | - } else { |
|
| 86 | - $description = wp_sprintf( _n( '%s for one day.', '%1$s for each day, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
| 87 | - } |
|
| 88 | - } else { |
|
| 89 | - $description = wp_sprintf( _n( '%s for each day.', '%1$s for each %2$d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
| 90 | - } |
|
| 91 | - break; |
|
| 92 | - case 'W': |
|
| 93 | - case 'week': |
|
| 94 | - if ( (int)$bill_times > 0 ) { |
|
| 95 | - if ( $interval > 1 ) { |
|
| 96 | - if ( $bill_times > 1 ) { |
|
| 97 | - $description = wp_sprintf( __( '%1$s for each %2$d weeks, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
| 98 | - } else { |
|
| 99 | - $description = wp_sprintf( __( '%1$s for %2$d weeks.', 'invoicing' ), $amount, $interval ); |
|
| 100 | - } |
|
| 101 | - } else { |
|
| 102 | - $description = wp_sprintf( _n( '%s for one week.', '%1$s for each week, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
| 103 | - } |
|
| 104 | - } else { |
|
| 105 | - $description = wp_sprintf( _n( '%s for each week.', '%1$s for each %2$d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
| 106 | - } |
|
| 107 | - break; |
|
| 108 | - case 'M': |
|
| 109 | - case 'month': |
|
| 110 | - if ( (int)$bill_times > 0 ) { |
|
| 111 | - if ( $interval > 1 ) { |
|
| 112 | - if ( $bill_times > 1 ) { |
|
| 113 | - $description = wp_sprintf( __( '%1$s for each %2$d months, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
| 114 | - } else { |
|
| 115 | - $description = wp_sprintf( __( '%1$s for %2$d months.', 'invoicing' ), $amount, $interval ); |
|
| 116 | - } |
|
| 117 | - } else { |
|
| 118 | - $description = wp_sprintf( _n( '%s for one month.', '%1$s for each month, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
| 119 | - } |
|
| 120 | - } else { |
|
| 121 | - $description = wp_sprintf( _n( '%s for each month.', '%1$s for each %2$d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
| 122 | - } |
|
| 123 | - break; |
|
| 124 | - case 'Y': |
|
| 125 | - case 'year': |
|
| 126 | - if ( (int)$bill_times > 0 ) { |
|
| 127 | - if ( $interval > 1 ) { |
|
| 128 | - if ( $bill_times > 1 ) { |
|
| 129 | - $description = wp_sprintf( __( '%1$s for each %2$d years, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
| 130 | - } else { |
|
| 131 | - $description = wp_sprintf( __( '%1$s for %2$d years.', 'invoicing' ), $amount, $interval ); |
|
| 132 | - } |
|
| 133 | - } else { |
|
| 134 | - $description = wp_sprintf( _n( '%s for one year.', '%1$s for each year, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
| 135 | - } |
|
| 136 | - } else { |
|
| 137 | - $description = wp_sprintf( _n( '%s for each year.', '%1$s for each %2$d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
| 138 | - } |
|
| 139 | - break; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
| 71 | + $interval = (int)$interval > 0 ? (int)$interval : 1; |
|
| 72 | + $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0; |
|
| 73 | + |
|
| 74 | + $description = ''; |
|
| 75 | + switch ( $period ) { |
|
| 76 | + case 'D': |
|
| 77 | + case 'day': |
|
| 78 | + if ( (int)$bill_times > 0 ) { |
|
| 79 | + if ( $interval > 1 ) { |
|
| 80 | + if ( $bill_times > 1 ) { |
|
| 81 | + $description = wp_sprintf( __( '%1$s for each %2$d days, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
| 82 | + } else { |
|
| 83 | + $description = wp_sprintf( __( '%1$s for %2$d days.', 'invoicing' ), $amount, $interval ); |
|
| 84 | + } |
|
| 85 | + } else { |
|
| 86 | + $description = wp_sprintf( _n( '%s for one day.', '%1$s for each day, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
| 87 | + } |
|
| 88 | + } else { |
|
| 89 | + $description = wp_sprintf( _n( '%s for each day.', '%1$s for each %2$d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
| 90 | + } |
|
| 91 | + break; |
|
| 92 | + case 'W': |
|
| 93 | + case 'week': |
|
| 94 | + if ( (int)$bill_times > 0 ) { |
|
| 95 | + if ( $interval > 1 ) { |
|
| 96 | + if ( $bill_times > 1 ) { |
|
| 97 | + $description = wp_sprintf( __( '%1$s for each %2$d weeks, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
| 98 | + } else { |
|
| 99 | + $description = wp_sprintf( __( '%1$s for %2$d weeks.', 'invoicing' ), $amount, $interval ); |
|
| 100 | + } |
|
| 101 | + } else { |
|
| 102 | + $description = wp_sprintf( _n( '%s for one week.', '%1$s for each week, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
| 103 | + } |
|
| 104 | + } else { |
|
| 105 | + $description = wp_sprintf( _n( '%s for each week.', '%1$s for each %2$d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
| 106 | + } |
|
| 107 | + break; |
|
| 108 | + case 'M': |
|
| 109 | + case 'month': |
|
| 110 | + if ( (int)$bill_times > 0 ) { |
|
| 111 | + if ( $interval > 1 ) { |
|
| 112 | + if ( $bill_times > 1 ) { |
|
| 113 | + $description = wp_sprintf( __( '%1$s for each %2$d months, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
| 114 | + } else { |
|
| 115 | + $description = wp_sprintf( __( '%1$s for %2$d months.', 'invoicing' ), $amount, $interval ); |
|
| 116 | + } |
|
| 117 | + } else { |
|
| 118 | + $description = wp_sprintf( _n( '%s for one month.', '%1$s for each month, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
| 119 | + } |
|
| 120 | + } else { |
|
| 121 | + $description = wp_sprintf( _n( '%s for each month.', '%1$s for each %2$d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
| 122 | + } |
|
| 123 | + break; |
|
| 124 | + case 'Y': |
|
| 125 | + case 'year': |
|
| 126 | + if ( (int)$bill_times > 0 ) { |
|
| 127 | + if ( $interval > 1 ) { |
|
| 128 | + if ( $bill_times > 1 ) { |
|
| 129 | + $description = wp_sprintf( __( '%1$s for each %2$d years, for %3$d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
| 130 | + } else { |
|
| 131 | + $description = wp_sprintf( __( '%1$s for %2$d years.', 'invoicing' ), $amount, $interval ); |
|
| 132 | + } |
|
| 133 | + } else { |
|
| 134 | + $description = wp_sprintf( _n( '%s for one year.', '%1$s for each year, for %2$d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
| 135 | + } |
|
| 136 | + } else { |
|
| 137 | + $description = wp_sprintf( _n( '%s for each year.', '%1$s for each %2$d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
| 138 | + } |
|
| 139 | + break; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | function wpinv_subscription_payment_desc( $invoice ) { |
| 146 | - if ( empty( $invoice ) ) { |
|
| 147 | - return null; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - $description = ''; |
|
| 151 | - if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) { |
|
| 152 | - if ( $item->has_free_trial() ) { |
|
| 153 | - $trial_period = $item->get_trial_period(); |
|
| 154 | - $trial_interval = $item->get_trial_interval(); |
|
| 155 | - } else { |
|
| 156 | - $trial_period = ''; |
|
| 157 | - $trial_interval = 0; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() ); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice ); |
|
| 146 | + if ( empty( $invoice ) ) { |
|
| 147 | + return null; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + $description = ''; |
|
| 151 | + if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) { |
|
| 152 | + if ( $item->has_free_trial() ) { |
|
| 153 | + $trial_period = $item->get_trial_period(); |
|
| 154 | + $trial_interval = $item->get_trial_interval(); |
|
| 155 | + } else { |
|
| 156 | + $trial_period = ''; |
|
| 157 | + $trial_interval = 0; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() ); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice ); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) { |
| 167 | - $initial_total = wpinv_round_amount( $initial ); |
|
| 168 | - $recurring_total = wpinv_round_amount( $recurring ); |
|
| 167 | + $initial_total = wpinv_round_amount( $initial ); |
|
| 168 | + $recurring_total = wpinv_round_amount( $recurring ); |
|
| 169 | 169 | |
| 170 | - if ( $trial_interval > 0 && ! empty( $trial_period ) ) { |
|
| 171 | - // Free trial |
|
| 172 | - } else { |
|
| 173 | - if ( $bill_times == 1 ) { |
|
| 174 | - $recurring_total = $initial_total; |
|
| 175 | - } elseif ( $bill_times > 1 && $initial_total != $recurring_total ) { |
|
| 176 | - $bill_times--; |
|
| 177 | - } |
|
| 178 | - } |
|
| 170 | + if ( $trial_interval > 0 && ! empty( $trial_period ) ) { |
|
| 171 | + // Free trial |
|
| 172 | + } else { |
|
| 173 | + if ( $bill_times == 1 ) { |
|
| 174 | + $recurring_total = $initial_total; |
|
| 175 | + } elseif ( $bill_times > 1 && $initial_total != $recurring_total ) { |
|
| 176 | + $bill_times--; |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - $initial_amount = wpinv_price( $initial_total, $currency ); |
|
| 181 | - $recurring_amount = wpinv_price( $recurring_total, $currency ); |
|
| 180 | + $initial_amount = wpinv_price( $initial_total, $currency ); |
|
| 181 | + $recurring_amount = wpinv_price( $recurring_total, $currency ); |
|
| 182 | 182 | |
| 183 | - $recurring = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
| 183 | + $recurring = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
| 184 | 184 | |
| 185 | - if ( $initial_total != $recurring_total ) { |
|
| 186 | - $initial = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval ); |
|
| 185 | + if ( $initial_total != $recurring_total ) { |
|
| 186 | + $initial = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval ); |
|
| 187 | 187 | |
| 188 | - $description = wp_sprintf( __( '%1$s Then %2$s', 'invoicing' ), $initial, $recurring ); |
|
| 189 | - } else { |
|
| 190 | - $description = $recurring; |
|
| 191 | - } |
|
| 188 | + $description = wp_sprintf( __( '%1$s Then %2$s', 'invoicing' ), $initial, $recurring ); |
|
| 189 | + } else { |
|
| 190 | + $description = $recurring; |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency ); |
|
| 193 | + return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency ); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
@@ -202,25 +202,25 @@ discard block |
||
| 202 | 202 | */ |
| 203 | 203 | function getpaid_get_card_name( $card_number ) { |
| 204 | 204 | |
| 205 | - // Known regexes. |
|
| 206 | - $regexes = array( |
|
| 207 | - '/^4/' => __( 'Visa', 'invoicing' ), |
|
| 208 | - '/^5[1-5]/' => __( 'Mastercard', 'invoicing' ), |
|
| 209 | - '/^3[47]/' => __( 'Amex', 'invoicing' ), |
|
| 210 | - '/^3(?:0[0-5]|[68])/' => __( 'Diners Club', 'invoicing' ), |
|
| 211 | - '/^6(?:011|5)/' => __( 'Discover', 'invoicing' ), |
|
| 212 | - '/^(?:2131|1800|35\d{3})/' => __( 'JCB', 'invoicing' ), |
|
| 213 | - ); |
|
| 214 | - |
|
| 215 | - // Confirm if one matches. |
|
| 216 | - foreach ( $regexes as $regex => $card ) { |
|
| 217 | - if ( preg_match( $regex, $card_number ) >= 1 ) { |
|
| 218 | - return $card; |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - // None matched. |
|
| 223 | - return __( 'Card', 'invoicing' ); |
|
| 205 | + // Known regexes. |
|
| 206 | + $regexes = array( |
|
| 207 | + '/^4/' => __( 'Visa', 'invoicing' ), |
|
| 208 | + '/^5[1-5]/' => __( 'Mastercard', 'invoicing' ), |
|
| 209 | + '/^3[47]/' => __( 'Amex', 'invoicing' ), |
|
| 210 | + '/^3(?:0[0-5]|[68])/' => __( 'Diners Club', 'invoicing' ), |
|
| 211 | + '/^6(?:011|5)/' => __( 'Discover', 'invoicing' ), |
|
| 212 | + '/^(?:2131|1800|35\d{3})/' => __( 'JCB', 'invoicing' ), |
|
| 213 | + ); |
|
| 214 | + |
|
| 215 | + // Confirm if one matches. |
|
| 216 | + foreach ( $regexes as $regex => $card ) { |
|
| 217 | + if ( preg_match( $regex, $card_number ) >= 1 ) { |
|
| 218 | + return $card; |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + // None matched. |
|
| 223 | + return __( 'Card', 'invoicing' ); |
|
| 224 | 224 | |
| 225 | 225 | } |
| 226 | 226 | |
@@ -230,24 +230,24 @@ discard block |
||
| 230 | 230 | * @param WPInv_Invoice|int|null $invoice |
| 231 | 231 | */ |
| 232 | 232 | function wpinv_send_back_to_checkout( $invoice = null ) { |
| 233 | - $response = array( 'success' => false ); |
|
| 234 | - $invoice = wpinv_get_invoice( $invoice ); |
|
| 235 | - |
|
| 236 | - // Was an invoice created? |
|
| 237 | - if ( ! empty( $invoice ) ) { |
|
| 238 | - $invoice = is_scalar( $invoice ) ? new WPInv_Invoice( $invoice ) : $invoice; |
|
| 239 | - $response['invoice'] = $invoice->get_id(); |
|
| 240 | - do_action( 'getpaid_checkout_invoice_exception', $invoice ); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - // Do we have any errors? |
|
| 244 | - if ( wpinv_get_errors() ) { |
|
| 245 | - $response['data'] = getpaid_get_errors_html( true, false ); |
|
| 246 | - } else { |
|
| 247 | - $response['data'] = __( 'An error occured while processing your payment. Please try again.', 'invoicing' ); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - wp_send_json( $response ); |
|
| 233 | + $response = array( 'success' => false ); |
|
| 234 | + $invoice = wpinv_get_invoice( $invoice ); |
|
| 235 | + |
|
| 236 | + // Was an invoice created? |
|
| 237 | + if ( ! empty( $invoice ) ) { |
|
| 238 | + $invoice = is_scalar( $invoice ) ? new WPInv_Invoice( $invoice ) : $invoice; |
|
| 239 | + $response['invoice'] = $invoice->get_id(); |
|
| 240 | + do_action( 'getpaid_checkout_invoice_exception', $invoice ); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + // Do we have any errors? |
|
| 244 | + if ( wpinv_get_errors() ) { |
|
| 245 | + $response['data'] = getpaid_get_errors_html( true, false ); |
|
| 246 | + } else { |
|
| 247 | + $response['data'] = __( 'An error occured while processing your payment. Please try again.', 'invoicing' ); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + wp_send_json( $response ); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | * @return string |
| 257 | 257 | */ |
| 258 | 258 | function getpaid_get_recaptcha_site_key() { |
| 259 | - return apply_filters( 'getpaid_recaptcha_site_key', wpinv_get_option( 'recaptcha_site_key', '' ) ); |
|
| 259 | + return apply_filters( 'getpaid_recaptcha_site_key', wpinv_get_option( 'recaptcha_site_key', '' ) ); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | * @return string |
| 266 | 266 | */ |
| 267 | 267 | function getpaid_get_recaptcha_secret_key() { |
| 268 | - return apply_filters( 'getpaid_recaptcha_secret_key', wpinv_get_option( 'recaptcha_secret_key', '' ) ); |
|
| 268 | + return apply_filters( 'getpaid_recaptcha_secret_key', wpinv_get_option( 'recaptcha_secret_key', '' ) ); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | /** |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | * @return bool |
| 275 | 275 | */ |
| 276 | 276 | function getpaid_is_recaptcha_enabled() { |
| 277 | - return wpinv_get_option( 'enable_recaptcha', false ) && getpaid_get_recaptcha_site_key() && getpaid_get_recaptcha_secret_key(); |
|
| 277 | + return wpinv_get_option( 'enable_recaptcha', false ) && getpaid_get_recaptcha_site_key() && getpaid_get_recaptcha_secret_key(); |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | /** |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | * @return string |
| 284 | 284 | */ |
| 285 | 285 | function getpaid_get_recaptcha_version() { |
| 286 | - return apply_filters( 'getpaid_recaptcha_version', wpinv_get_option( 'recaptcha_version', 'v2' ) ); |
|
| 286 | + return apply_filters( 'getpaid_recaptcha_version', wpinv_get_option( 'recaptcha_version', 'v2' ) ); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | /** |
@@ -292,42 +292,42 @@ discard block |
||
| 292 | 292 | * @return array |
| 293 | 293 | */ |
| 294 | 294 | function getpaid_get_recaptcha_settings() { |
| 295 | - $settings = array( |
|
| 296 | - 'enabled' => getpaid_is_recaptcha_enabled(), |
|
| 297 | - 'version' => getpaid_get_recaptcha_version(), |
|
| 298 | - ); |
|
| 299 | - |
|
| 300 | - if ( ! getpaid_is_recaptcha_enabled() ) { |
|
| 301 | - return $settings; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - $settings['sitekey'] = getpaid_get_recaptcha_site_key(); |
|
| 305 | - |
|
| 306 | - // Version 2 render params. |
|
| 307 | - if ( 'v2' === getpaid_get_recaptcha_version() ) { |
|
| 308 | - $settings['render_params'] = array( |
|
| 309 | - 'sitekey' => getpaid_get_recaptcha_site_key(), |
|
| 310 | - 'theme' => 'light', |
|
| 311 | - 'size' => 'normal', |
|
| 312 | - 'tabindex' => 0, |
|
| 313 | - ); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - return apply_filters( 'getpaid_recaptcha_settings', $settings ); |
|
| 295 | + $settings = array( |
|
| 296 | + 'enabled' => getpaid_is_recaptcha_enabled(), |
|
| 297 | + 'version' => getpaid_get_recaptcha_version(), |
|
| 298 | + ); |
|
| 299 | + |
|
| 300 | + if ( ! getpaid_is_recaptcha_enabled() ) { |
|
| 301 | + return $settings; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + $settings['sitekey'] = getpaid_get_recaptcha_site_key(); |
|
| 305 | + |
|
| 306 | + // Version 2 render params. |
|
| 307 | + if ( 'v2' === getpaid_get_recaptcha_version() ) { |
|
| 308 | + $settings['render_params'] = array( |
|
| 309 | + 'sitekey' => getpaid_get_recaptcha_site_key(), |
|
| 310 | + 'theme' => 'light', |
|
| 311 | + 'size' => 'normal', |
|
| 312 | + 'tabindex' => 0, |
|
| 313 | + ); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + return apply_filters( 'getpaid_recaptcha_settings', $settings ); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | /** |
| 320 | 320 | * Displays reCAPTCHA before payment button. |
| 321 | 321 | */ |
| 322 | 322 | function getpaid_display_recaptcha_before_payment_button() { |
| 323 | - if ( ! getpaid_is_recaptcha_enabled() || 'v2' !== getpaid_get_recaptcha_version() ) { |
|
| 324 | - return; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - printf( |
|
| 328 | - '<div class="getpaid-recaptcha-wrapper"><div class="g-recaptcha mw-100 overflow-hidden my-2" id="getpaid-recaptcha-%s"></div></div>', |
|
| 329 | - esc_attr( wp_unique_id() ) |
|
| 330 | - ); |
|
| 323 | + if ( ! getpaid_is_recaptcha_enabled() || 'v2' !== getpaid_get_recaptcha_version() ) { |
|
| 324 | + return; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + printf( |
|
| 328 | + '<div class="getpaid-recaptcha-wrapper"><div class="g-recaptcha mw-100 overflow-hidden my-2" id="getpaid-recaptcha-%s"></div></div>', |
|
| 329 | + esc_attr( wp_unique_id() ) |
|
| 330 | + ); |
|
| 331 | 331 | } |
| 332 | 332 | add_action( 'getpaid_before_payment_form_pay_button', 'getpaid_display_recaptcha_before_payment_button' ); |
| 333 | 333 | |
@@ -338,43 +338,43 @@ discard block |
||
| 338 | 338 | */ |
| 339 | 339 | function getpaid_validate_recaptcha_response( $submission ) { |
| 340 | 340 | |
| 341 | - // Check if reCAPTCHA is enabled. |
|
| 342 | - if ( ! getpaid_is_recaptcha_enabled() ) { |
|
| 343 | - return; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - $token = $submission->get_field( 'g-recaptcha-response' ); |
|
| 347 | - |
|
| 348 | - // Abort if no token was provided. |
|
| 349 | - if ( empty( $token ) ) { |
|
| 350 | - wp_send_json_error( 'v2' === getpaid_get_recaptcha_version() ? __( 'Please confirm that you are not a robot.', 'invoicing' ) : __( "Unable to verify that you're not a robot. Please try again.", 'invoicing' ) ); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - $result = wp_remote_post( |
|
| 354 | - 'https://www.google.com/recaptcha/api/siteverify', |
|
| 355 | - array( |
|
| 356 | - 'body' => array( |
|
| 357 | - 'secret' => getpaid_get_recaptcha_secret_key(), |
|
| 358 | - 'response' => $token, |
|
| 359 | - ), |
|
| 360 | - ) |
|
| 361 | - ); |
|
| 362 | - |
|
| 363 | - // Site not reachable, give benefit of doubt. |
|
| 364 | - if ( is_wp_error( $result ) ) { |
|
| 365 | - return; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - $result = json_decode( wp_remote_retrieve_body( $result ), true ); |
|
| 369 | - |
|
| 370 | - if ( empty( $result['success'] ) && ! in_array( 'missing-input-secret', $result['error-codes'], true ) && ! in_array( 'invalid-input-secret', $result['error-codes'], true ) ) { |
|
| 371 | - wp_send_json_error( __( "Unable to verify that you're not a robot. Please try again.", 'invoicing' ) ); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - // For v3, check the score. |
|
| 375 | - $minimum_score = apply_filters( 'getpaid_recaptcha_minimum_score', 0.4 ); |
|
| 376 | - if ( 'v3' === getpaid_get_recaptcha_version() && ( empty( $result['score'] ) || $result['score'] < $minimum_score ) ) { |
|
| 377 | - wp_send_json_error( __( "Unable to verify that you're not a robot. Please try again.", 'invoicing' ) ); |
|
| 378 | - } |
|
| 341 | + // Check if reCAPTCHA is enabled. |
|
| 342 | + if ( ! getpaid_is_recaptcha_enabled() ) { |
|
| 343 | + return; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + $token = $submission->get_field( 'g-recaptcha-response' ); |
|
| 347 | + |
|
| 348 | + // Abort if no token was provided. |
|
| 349 | + if ( empty( $token ) ) { |
|
| 350 | + wp_send_json_error( 'v2' === getpaid_get_recaptcha_version() ? __( 'Please confirm that you are not a robot.', 'invoicing' ) : __( "Unable to verify that you're not a robot. Please try again.", 'invoicing' ) ); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + $result = wp_remote_post( |
|
| 354 | + 'https://www.google.com/recaptcha/api/siteverify', |
|
| 355 | + array( |
|
| 356 | + 'body' => array( |
|
| 357 | + 'secret' => getpaid_get_recaptcha_secret_key(), |
|
| 358 | + 'response' => $token, |
|
| 359 | + ), |
|
| 360 | + ) |
|
| 361 | + ); |
|
| 362 | + |
|
| 363 | + // Site not reachable, give benefit of doubt. |
|
| 364 | + if ( is_wp_error( $result ) ) { |
|
| 365 | + return; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + $result = json_decode( wp_remote_retrieve_body( $result ), true ); |
|
| 369 | + |
|
| 370 | + if ( empty( $result['success'] ) && ! in_array( 'missing-input-secret', $result['error-codes'], true ) && ! in_array( 'invalid-input-secret', $result['error-codes'], true ) ) { |
|
| 371 | + wp_send_json_error( __( "Unable to verify that you're not a robot. Please try again.", 'invoicing' ) ); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + // For v3, check the score. |
|
| 375 | + $minimum_score = apply_filters( 'getpaid_recaptcha_minimum_score', 0.4 ); |
|
| 376 | + if ( 'v3' === getpaid_get_recaptcha_version() && ( empty( $result['score'] ) || $result['score'] < $minimum_score ) ) { |
|
| 377 | + wp_send_json_error( __( "Unable to verify that you're not a robot. Please try again.", 'invoicing' ) ); |
|
| 378 | + } |
|
| 379 | 379 | } |
| 380 | 380 | add_action( 'getpaid_checkout_error_checks', 'getpaid_validate_recaptcha_response' ); |
@@ -1,103 +1,103 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | - exit; |
|
| 4 | + exit; |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | if ( ! class_exists( 'AyeCode_Deactivation_Survey' ) ) { |
| 8 | 8 | |
| 9 | - class AyeCode_Deactivation_Survey { |
|
| 9 | + class AyeCode_Deactivation_Survey { |
|
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * AyeCode_Deactivation_Survey instance. |
|
| 13 | - * |
|
| 14 | - * @access private |
|
| 15 | - * @since 1.0.0 |
|
| 16 | - * @var AyeCode_Deactivation_Survey There can be only one! |
|
| 17 | - */ |
|
| 18 | - private static $instance = null; |
|
| 11 | + /** |
|
| 12 | + * AyeCode_Deactivation_Survey instance. |
|
| 13 | + * |
|
| 14 | + * @access private |
|
| 15 | + * @since 1.0.0 |
|
| 16 | + * @var AyeCode_Deactivation_Survey There can be only one! |
|
| 17 | + */ |
|
| 18 | + private static $instance = null; |
|
| 19 | 19 | |
| 20 | - public static $plugins; |
|
| 20 | + public static $plugins; |
|
| 21 | 21 | |
| 22 | - public $version = "1.0.6"; |
|
| 22 | + public $version = "1.0.6"; |
|
| 23 | 23 | |
| 24 | - public static function instance( $plugin = array() ) { |
|
| 25 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_Deactivation_Survey ) ) { |
|
| 26 | - self::$instance = new AyeCode_Deactivation_Survey; |
|
| 27 | - self::$plugins = array(); |
|
| 24 | + public static function instance( $plugin = array() ) { |
|
| 25 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_Deactivation_Survey ) ) { |
|
| 26 | + self::$instance = new AyeCode_Deactivation_Survey; |
|
| 27 | + self::$plugins = array(); |
|
| 28 | 28 | |
| 29 | - add_action( 'admin_enqueue_scripts', array( self::$instance, 'scripts' ) ); |
|
| 29 | + add_action( 'admin_enqueue_scripts', array( self::$instance, 'scripts' ) ); |
|
| 30 | 30 | |
| 31 | - do_action( 'ayecode_deactivation_survey_loaded' ); |
|
| 32 | - } |
|
| 31 | + do_action( 'ayecode_deactivation_survey_loaded' ); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - if(!empty($plugin)){ |
|
| 35 | - self::$plugins[] = (object)$plugin; |
|
| 36 | - } |
|
| 34 | + if(!empty($plugin)){ |
|
| 35 | + self::$plugins[] = (object)$plugin; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - return self::$instance; |
|
| 39 | - } |
|
| 38 | + return self::$instance; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - public function scripts() { |
|
| 42 | - global $pagenow; |
|
| 41 | + public function scripts() { |
|
| 42 | + global $pagenow; |
|
| 43 | 43 | |
| 44 | - // Bail if we are not on the plugins page |
|
| 45 | - if ( $pagenow != "plugins.php" ) { |
|
| 46 | - return; |
|
| 47 | - } |
|
| 44 | + // Bail if we are not on the plugins page |
|
| 45 | + if ( $pagenow != "plugins.php" ) { |
|
| 46 | + return; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - // Enqueue scripts |
|
| 50 | - add_thickbox(); |
|
| 51 | - wp_enqueue_script('ayecode-deactivation-survey', plugin_dir_url(__FILE__) . 'ayecode-ds.js'); |
|
| 49 | + // Enqueue scripts |
|
| 50 | + add_thickbox(); |
|
| 51 | + wp_enqueue_script('ayecode-deactivation-survey', plugin_dir_url(__FILE__) . 'ayecode-ds.js'); |
|
| 52 | 52 | |
| 53 | - /* |
|
| 53 | + /* |
|
| 54 | 54 | * Localized strings. Strings can be localised by plugins using this class. |
| 55 | 55 | * We deliberately don't add textdomains here so that double textdomain warning is not given in theme review. |
| 56 | 56 | */ |
| 57 | - wp_localize_script('ayecode-deactivation-survey', 'ayecodeds_deactivate_feedback_form_strings', array( |
|
| 58 | - 'quick_feedback' => 'Quick Feedback', |
|
| 59 | - 'foreword' => 'If you would be kind enough, please tell us why you\'re deactivating?', |
|
| 60 | - 'better_plugins_name' => 'Please tell us which plugin?', |
|
| 61 | - 'please_tell_us' => 'Please tell us the reason so we can improve the plugin', |
|
| 62 | - 'do_not_attach_email' => 'Do not send my e-mail address with this feedback', |
|
| 63 | - 'brief_description' => 'Please give us any feedback that could help us improve', |
|
| 64 | - 'cancel' => 'Cancel', |
|
| 65 | - 'skip_and_deactivate' => 'Skip & Deactivate', |
|
| 66 | - 'submit_and_deactivate' => 'Submit & Deactivate', |
|
| 67 | - 'please_wait' => 'Please wait', |
|
| 68 | - 'get_support' => 'Get Support', |
|
| 69 | - 'documentation' => 'Documentation', |
|
| 70 | - 'thank_you' => 'Thank you!', |
|
| 71 | - )); |
|
| 72 | - |
|
| 73 | - // Plugins |
|
| 74 | - $plugins = apply_filters('ayecode_deactivation_survey_plugins', self::$plugins); |
|
| 75 | - |
|
| 76 | - // Reasons |
|
| 77 | - $defaultReasons = array( |
|
| 78 | - 'suddenly-stopped-working' => 'The plugin suddenly stopped working', |
|
| 79 | - 'plugin-broke-site' => 'The plugin broke my site', |
|
| 80 | - 'plugin-setup-difficult' => 'Too difficult to setup', |
|
| 81 | - 'plugin-design-difficult' => 'Too difficult to get the design i want', |
|
| 82 | - 'no-longer-needed' => 'I don\'t need this plugin any more', |
|
| 83 | - 'found-better-plugin' => 'I found a better plugin', |
|
| 84 | - 'temporary-deactivation' => 'It\'s a temporary deactivation, I\'m troubleshooting', |
|
| 85 | - 'other' => 'Other', |
|
| 86 | - ); |
|
| 87 | - |
|
| 88 | - foreach($plugins as $plugin) |
|
| 89 | - { |
|
| 90 | - $plugin->reasons = apply_filters('ayecode_deactivation_survey_reasons', $defaultReasons, $plugin); |
|
| 91 | - $plugin->url = home_url(); |
|
| 92 | - $plugin->activated = 0; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - // Send plugin data |
|
| 96 | - wp_localize_script('ayecode-deactivation-survey', 'ayecodeds_deactivate_feedback_form_plugins', $plugins); |
|
| 97 | - |
|
| 98 | - } |
|
| 57 | + wp_localize_script('ayecode-deactivation-survey', 'ayecodeds_deactivate_feedback_form_strings', array( |
|
| 58 | + 'quick_feedback' => 'Quick Feedback', |
|
| 59 | + 'foreword' => 'If you would be kind enough, please tell us why you\'re deactivating?', |
|
| 60 | + 'better_plugins_name' => 'Please tell us which plugin?', |
|
| 61 | + 'please_tell_us' => 'Please tell us the reason so we can improve the plugin', |
|
| 62 | + 'do_not_attach_email' => 'Do not send my e-mail address with this feedback', |
|
| 63 | + 'brief_description' => 'Please give us any feedback that could help us improve', |
|
| 64 | + 'cancel' => 'Cancel', |
|
| 65 | + 'skip_and_deactivate' => 'Skip & Deactivate', |
|
| 66 | + 'submit_and_deactivate' => 'Submit & Deactivate', |
|
| 67 | + 'please_wait' => 'Please wait', |
|
| 68 | + 'get_support' => 'Get Support', |
|
| 69 | + 'documentation' => 'Documentation', |
|
| 70 | + 'thank_you' => 'Thank you!', |
|
| 71 | + )); |
|
| 72 | + |
|
| 73 | + // Plugins |
|
| 74 | + $plugins = apply_filters('ayecode_deactivation_survey_plugins', self::$plugins); |
|
| 75 | + |
|
| 76 | + // Reasons |
|
| 77 | + $defaultReasons = array( |
|
| 78 | + 'suddenly-stopped-working' => 'The plugin suddenly stopped working', |
|
| 79 | + 'plugin-broke-site' => 'The plugin broke my site', |
|
| 80 | + 'plugin-setup-difficult' => 'Too difficult to setup', |
|
| 81 | + 'plugin-design-difficult' => 'Too difficult to get the design i want', |
|
| 82 | + 'no-longer-needed' => 'I don\'t need this plugin any more', |
|
| 83 | + 'found-better-plugin' => 'I found a better plugin', |
|
| 84 | + 'temporary-deactivation' => 'It\'s a temporary deactivation, I\'m troubleshooting', |
|
| 85 | + 'other' => 'Other', |
|
| 86 | + ); |
|
| 87 | + |
|
| 88 | + foreach($plugins as $plugin) |
|
| 89 | + { |
|
| 90 | + $plugin->reasons = apply_filters('ayecode_deactivation_survey_reasons', $defaultReasons, $plugin); |
|
| 91 | + $plugin->url = home_url(); |
|
| 92 | + $plugin->activated = 0; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + // Send plugin data |
|
| 96 | + wp_localize_script('ayecode-deactivation-survey', 'ayecodeds_deactivate_feedback_form_plugins', $plugins); |
|
| 97 | + |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | 100 | |
| 101 | - } |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | 103 | } |
| 104 | 104 | \ No newline at end of file |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | |
| 58 | 58 | // And the optional invoice id. |
| 59 | 59 | if ( ! empty( $form->invoice ) ) { |
| 60 | - getpaid_hidden_field( 'invoice_id', $form->invoice->get_id() ); |
|
| 60 | + getpaid_hidden_field( 'invoice_id', $form->invoice->get_id() ); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | // We also want to include the form id. |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | <?php |
| 77 | 77 | |
| 78 | 78 | foreach ( $form->get_elements() as $element ) { |
| 79 | - if ( isset( $element['type'] ) ) { |
|
| 79 | + if ( isset( $element['type'] ) ) { |
|
| 80 | 80 | $grid_class = getpaid_get_form_element_grid_class( $element ); |
| 81 | 81 | do_action( 'getpaid_payment_form_element_before', $element, $form ); |
| 82 | 82 | do_action( "getpaid_payment_form_element_before_{$element['type']}_template", $element, $form ); |