@@ -12,170 +12,170 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class GetPaid_Checkout { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var GetPaid_Payment_Form_Submission |
|
| 17 | - */ |
|
| 18 | - protected $payment_form_submission; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Class constructor. |
|
| 22 | - * |
|
| 23 | - * @param GetPaid_Payment_Form_Submission $submission |
|
| 24 | - */ |
|
| 25 | - public function __construct( $submission ) { |
|
| 26 | - $this->payment_form_submission = $submission; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Processes the checkout. |
|
| 31 | - * |
|
| 32 | - */ |
|
| 33 | - public function process_checkout() { |
|
| 34 | - |
|
| 35 | - // Validate the submission. |
|
| 36 | - $this->validate_submission(); |
|
| 37 | - |
|
| 38 | - // Prepare the invoice. |
|
| 39 | - $items = $this->get_submission_items(); |
|
| 40 | - $invoice = $this->get_submission_invoice(); |
|
| 41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
| 42 | - $prepared = $this->prepare_submission_data_for_saving( $invoice ); |
|
| 43 | - |
|
| 44 | - // Save the invoice. |
|
| 45 | - $invoice->recalculate_total(); |
|
| 15 | + /** |
|
| 16 | + * @var GetPaid_Payment_Form_Submission |
|
| 17 | + */ |
|
| 18 | + protected $payment_form_submission; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Class constructor. |
|
| 22 | + * |
|
| 23 | + * @param GetPaid_Payment_Form_Submission $submission |
|
| 24 | + */ |
|
| 25 | + public function __construct( $submission ) { |
|
| 26 | + $this->payment_form_submission = $submission; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Processes the checkout. |
|
| 31 | + * |
|
| 32 | + */ |
|
| 33 | + public function process_checkout() { |
|
| 34 | + |
|
| 35 | + // Validate the submission. |
|
| 36 | + $this->validate_submission(); |
|
| 37 | + |
|
| 38 | + // Prepare the invoice. |
|
| 39 | + $items = $this->get_submission_items(); |
|
| 40 | + $invoice = $this->get_submission_invoice(); |
|
| 41 | + $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
| 42 | + $prepared = $this->prepare_submission_data_for_saving( $invoice ); |
|
| 43 | + |
|
| 44 | + // Save the invoice. |
|
| 45 | + $invoice->recalculate_total(); |
|
| 46 | 46 | $invoice->save(); |
| 47 | 47 | |
| 48 | - // Send to the gateway. |
|
| 49 | - $this->post_process_submission( $invoice, $prepared ); |
|
| 50 | - } |
|
| 48 | + // Send to the gateway. |
|
| 49 | + $this->post_process_submission( $invoice, $prepared ); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Validates the submission. |
|
| 54 | - * |
|
| 55 | - */ |
|
| 56 | - protected function validate_submission() { |
|
| 52 | + /** |
|
| 53 | + * Validates the submission. |
|
| 54 | + * |
|
| 55 | + */ |
|
| 56 | + protected function validate_submission() { |
|
| 57 | 57 | |
| 58 | - $submission = $this->payment_form_submission; |
|
| 59 | - $data = $submission->get_data(); |
|
| 58 | + $submission = $this->payment_form_submission; |
|
| 59 | + $data = $submission->get_data(); |
|
| 60 | 60 | |
| 61 | - // Do we have an error? |
|
| 61 | + // Do we have an error? |
|
| 62 | 62 | if ( ! empty( $submission->last_error ) ) { |
| 63 | - wp_send_json_error( $submission->last_error ); |
|
| 63 | + wp_send_json_error( $submission->last_error ); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - // We need a billing email. |
|
| 66 | + // We need a billing email. |
|
| 67 | 67 | if ( ! $submission->has_billing_email() ) { |
| 68 | 68 | wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
| 69 | - } |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - // Non-recurring gateways should not be allowed to process recurring invoices. |
|
| 72 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
| 73 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
| 74 | - } |
|
| 71 | + // Non-recurring gateways should not be allowed to process recurring invoices. |
|
| 72 | + if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
| 73 | + wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - // Ensure the gateway is active. |
|
| 77 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
| 78 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
| 79 | - } |
|
| 76 | + // Ensure the gateway is active. |
|
| 77 | + if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
| 78 | + wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - // Clear any existing errors. |
|
| 82 | - wpinv_clear_errors(); |
|
| 81 | + // Clear any existing errors. |
|
| 82 | + wpinv_clear_errors(); |
|
| 83 | 83 | |
| 84 | - // Allow themes and plugins to hook to errors |
|
| 85 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
| 84 | + // Allow themes and plugins to hook to errors |
|
| 85 | + do_action( 'getpaid_checkout_error_checks', $submission ); |
|
| 86 | 86 | |
| 87 | - // Do we have any errors? |
|
| 87 | + // Do we have any errors? |
|
| 88 | 88 | if ( wpinv_get_errors() ) { |
| 89 | 89 | wp_send_json_error( getpaid_get_errors_html() ); |
| 90 | - } |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Retrieves submission items. |
|
| 96 | - * |
|
| 97 | - * @return GetPaid_Form_Item[] |
|
| 98 | - */ |
|
| 99 | - protected function get_submission_items() { |
|
| 94 | + /** |
|
| 95 | + * Retrieves submission items. |
|
| 96 | + * |
|
| 97 | + * @return GetPaid_Form_Item[] |
|
| 98 | + */ |
|
| 99 | + protected function get_submission_items() { |
|
| 100 | 100 | |
| 101 | - $items = $this->payment_form_submission->get_items(); |
|
| 101 | + $items = $this->payment_form_submission->get_items(); |
|
| 102 | 102 | |
| 103 | 103 | // Ensure that we have items. |
| 104 | 104 | if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
| 105 | 105 | wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
| 106 | - } |
|
| 107 | - |
|
| 108 | - return $items; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Retrieves submission invoice. |
|
| 113 | - * |
|
| 114 | - * @return WPInv_Invoice |
|
| 115 | - */ |
|
| 116 | - protected function get_submission_invoice() { |
|
| 117 | - $submission = $this->payment_form_submission; |
|
| 118 | - |
|
| 119 | - if ( ! $submission->has_invoice() ) { |
|
| 120 | - $invoice = new WPInv_Invoice(); |
|
| 121 | - $invoice->created_via( 'payment_form' ); |
|
| 122 | - return $invoice; |
|
| 123 | 106 | } |
| 124 | 107 | |
| 125 | - $invoice = $submission->get_invoice(); |
|
| 108 | + return $items; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Retrieves submission invoice. |
|
| 113 | + * |
|
| 114 | + * @return WPInv_Invoice |
|
| 115 | + */ |
|
| 116 | + protected function get_submission_invoice() { |
|
| 117 | + $submission = $this->payment_form_submission; |
|
| 126 | 118 | |
| 127 | - // Make sure that it is neither paid or refunded. |
|
| 128 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 129 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
| 130 | - } |
|
| 119 | + if ( ! $submission->has_invoice() ) { |
|
| 120 | + $invoice = new WPInv_Invoice(); |
|
| 121 | + $invoice->created_via( 'payment_form' ); |
|
| 122 | + return $invoice; |
|
| 123 | + } |
|
| 131 | 124 | |
| 132 | - return $invoice; |
|
| 133 | - } |
|
| 125 | + $invoice = $submission->get_invoice(); |
|
| 134 | 126 | |
| 135 | - /** |
|
| 136 | - * Processes the submission invoice. |
|
| 137 | - * |
|
| 138 | - * @param WPInv_Invoice $invoice |
|
| 139 | - * @param GetPaid_Form_Item[] $items |
|
| 140 | - * @return WPInv_Invoice |
|
| 141 | - */ |
|
| 142 | - protected function process_submission_invoice( $invoice, $items ) { |
|
| 127 | + // Make sure that it is neither paid or refunded. |
|
| 128 | + if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 129 | + wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
| 130 | + } |
|
| 143 | 131 | |
| 144 | - $submission = $this->payment_form_submission; |
|
| 145 | - $data = $submission->get_data(); |
|
| 132 | + return $invoice; |
|
| 133 | + } |
|
| 146 | 134 | |
| 147 | - // Set-up the invoice details. |
|
| 148 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
| 149 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
| 150 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
| 135 | + /** |
|
| 136 | + * Processes the submission invoice. |
|
| 137 | + * |
|
| 138 | + * @param WPInv_Invoice $invoice |
|
| 139 | + * @param GetPaid_Form_Item[] $items |
|
| 140 | + * @return WPInv_Invoice |
|
| 141 | + */ |
|
| 142 | + protected function process_submission_invoice( $invoice, $items ) { |
|
| 143 | + |
|
| 144 | + $submission = $this->payment_form_submission; |
|
| 145 | + $data = $submission->get_data(); |
|
| 146 | + |
|
| 147 | + // Set-up the invoice details. |
|
| 148 | + $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
| 149 | + $invoice->set_user_id( $this->get_submission_customer() ); |
|
| 150 | + $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
| 151 | 151 | $invoice->set_items( $items ); |
| 152 | 152 | $invoice->set_fees( $submission->get_fees() ); |
| 153 | 153 | $invoice->set_taxes( $submission->get_taxes() ); |
| 154 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
| 155 | - $invoice->set_gateway( $data['wpi-gateway'] ); |
|
| 154 | + $invoice->set_discounts( $submission->get_discounts() ); |
|
| 155 | + $invoice->set_gateway( $data['wpi-gateway'] ); |
|
| 156 | 156 | |
| 157 | - if ( $submission->has_discount_code() ) { |
|
| 157 | + if ( $submission->has_discount_code() ) { |
|
| 158 | 158 | $invoice->set_discount_code( $submission->get_discount_code() ); |
| 159 | - } |
|
| 160 | - |
|
| 161 | - getpaid_maybe_add_default_address( $invoice ); |
|
| 162 | - return $invoice; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Retrieves the submission's customer. |
|
| 167 | - * |
|
| 168 | - * @return int The customer id. |
|
| 169 | - */ |
|
| 170 | - protected function get_submission_customer() { |
|
| 171 | - $submission = $this->payment_form_submission; |
|
| 172 | - |
|
| 173 | - // If this is an existing invoice... |
|
| 174 | - if ( $submission->has_invoice() ) { |
|
| 175 | - return $submission->get_invoice()->get_user_id(); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - // (Maybe) create the user. |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + getpaid_maybe_add_default_address( $invoice ); |
|
| 162 | + return $invoice; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Retrieves the submission's customer. |
|
| 167 | + * |
|
| 168 | + * @return int The customer id. |
|
| 169 | + */ |
|
| 170 | + protected function get_submission_customer() { |
|
| 171 | + $submission = $this->payment_form_submission; |
|
| 172 | + |
|
| 173 | + // If this is an existing invoice... |
|
| 174 | + if ( $submission->has_invoice() ) { |
|
| 175 | + return $submission->get_invoice()->get_user_id(); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + // (Maybe) create the user. |
|
| 179 | 179 | $user = get_current_user_id(); |
| 180 | 180 | |
| 181 | 181 | if ( empty( $user ) ) { |
@@ -192,31 +192,31 @@ discard block |
||
| 192 | 192 | |
| 193 | 193 | if ( is_numeric( $user ) ) { |
| 194 | 194 | return $user; |
| 195 | - } |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - return $user->ID; |
|
| 197 | + return $user->ID; |
|
| 198 | 198 | |
| 199 | - } |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - /** |
|
| 201 | + /** |
|
| 202 | 202 | * Prepares submission data for saving to the database. |
| 203 | 203 | * |
| 204 | - * @param WPInv_Invoice $invoice |
|
| 204 | + * @param WPInv_Invoice $invoice |
|
| 205 | 205 | */ |
| 206 | 206 | public function prepare_submission_data_for_saving( &$invoice ) { |
| 207 | 207 | |
| 208 | - $submission = $this->payment_form_submission; |
|
| 208 | + $submission = $this->payment_form_submission; |
|
| 209 | 209 | |
| 210 | - // Prepared submission details. |
|
| 210 | + // Prepared submission details. |
|
| 211 | 211 | $prepared = array(); |
| 212 | 212 | |
| 213 | 213 | // Raw submission details. |
| 214 | - $data = $submission->get_data(); |
|
| 214 | + $data = $submission->get_data(); |
|
| 215 | 215 | |
| 216 | - // Loop throught the submitted details. |
|
| 216 | + // Loop throught the submitted details. |
|
| 217 | 217 | foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
| 218 | 218 | |
| 219 | - // Skip premade fields. |
|
| 219 | + // Skip premade fields. |
|
| 220 | 220 | if ( ! empty( $field['premade'] ) ) { |
| 221 | 221 | continue; |
| 222 | 222 | } |
@@ -259,21 +259,21 @@ discard block |
||
| 259 | 259 | $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] ); |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - } |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - return $prepared; |
|
| 264 | + return $prepared; |
|
| 265 | 265 | |
| 266 | - } |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - /** |
|
| 269 | - * Confirms the submission is valid and send users to the gateway. |
|
| 270 | - * |
|
| 271 | - * @param WPInv_Invoice $invoice |
|
| 272 | - * @param array $prepared_payment_form_data |
|
| 273 | - */ |
|
| 274 | - protected function post_process_submission( $invoice, $prepared_payment_form_data ) { |
|
| 268 | + /** |
|
| 269 | + * Confirms the submission is valid and send users to the gateway. |
|
| 270 | + * |
|
| 271 | + * @param WPInv_Invoice $invoice |
|
| 272 | + * @param array $prepared_payment_form_data |
|
| 273 | + */ |
|
| 274 | + protected function post_process_submission( $invoice, $prepared_payment_form_data ) { |
|
| 275 | 275 | |
| 276 | - // Ensure the invoice exists. |
|
| 276 | + // Ensure the invoice exists. |
|
| 277 | 277 | if ( ! $invoice->exists() ) { |
| 278 | 278 | wp_send_json_error( __( 'An error occured while saving your invoice.', 'invoicing' ) ); |
| 279 | 279 | } |
@@ -281,65 +281,65 @@ discard block |
||
| 281 | 281 | // Save payment form data. |
| 282 | 282 | if ( ! empty( $prepared_payment_form_data ) ) { |
| 283 | 283 | update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data ); |
| 284 | - } |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | - // Backwards compatibility. |
|
| 286 | + // Backwards compatibility. |
|
| 287 | 287 | add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
| 288 | 288 | |
| 289 | - $this->process_payment( $invoice ); |
|
| 289 | + $this->process_payment( $invoice ); |
|
| 290 | 290 | |
| 291 | 291 | // If we are here, there was an error. |
| 292 | - wpinv_send_back_to_checkout(); |
|
| 292 | + wpinv_send_back_to_checkout(); |
|
| 293 | 293 | |
| 294 | - } |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | - /** |
|
| 297 | - * Processes the actual payment. |
|
| 298 | - * |
|
| 299 | - * @param WPInv_Invoice $invoice |
|
| 300 | - */ |
|
| 301 | - protected function process_payment( $invoice ) { |
|
| 296 | + /** |
|
| 297 | + * Processes the actual payment. |
|
| 298 | + * |
|
| 299 | + * @param WPInv_Invoice $invoice |
|
| 300 | + */ |
|
| 301 | + protected function process_payment( $invoice ) { |
|
| 302 | 302 | |
| 303 | - $submission = $this->payment_form_submission; |
|
| 303 | + $submission = $this->payment_form_submission; |
|
| 304 | 304 | |
| 305 | - // No need to send free invoices to the gateway. |
|
| 306 | - if ( $invoice->is_free() ) { |
|
| 307 | - $invoice->set_gateway( 'none' ); |
|
| 308 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
| 309 | - $invoice->mark_paid(); |
|
| 310 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 311 | - } |
|
| 305 | + // No need to send free invoices to the gateway. |
|
| 306 | + if ( $invoice->is_free() ) { |
|
| 307 | + $invoice->set_gateway( 'none' ); |
|
| 308 | + $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
| 309 | + $invoice->mark_paid(); |
|
| 310 | + wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - // Clear any checkout errors. |
|
| 314 | - wpinv_clear_errors(); |
|
| 313 | + // Clear any checkout errors. |
|
| 314 | + wpinv_clear_errors(); |
|
| 315 | 315 | |
| 316 | - // Fires before sending to the gateway. |
|
| 317 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
| 316 | + // Fires before sending to the gateway. |
|
| 317 | + do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
| 318 | 318 | |
| 319 | - // Allow the sumission data to be modified before it is sent to the gateway. |
|
| 320 | - $submission_data = $submission->get_data(); |
|
| 321 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
| 322 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
| 319 | + // Allow the sumission data to be modified before it is sent to the gateway. |
|
| 320 | + $submission_data = $submission->get_data(); |
|
| 321 | + $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
| 322 | + $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
| 323 | 323 | |
| 324 | - // Validate the currency. |
|
| 325 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
| 326 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) ); |
|
| 327 | - } |
|
| 324 | + // Validate the currency. |
|
| 325 | + if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
| 326 | + wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) ); |
|
| 327 | + } |
|
| 328 | 328 | |
| 329 | - // Check to see if we have any errors. |
|
| 330 | - if ( wpinv_get_errors() ) { |
|
| 331 | - wpinv_send_back_to_checkout(); |
|
| 332 | - } |
|
| 329 | + // Check to see if we have any errors. |
|
| 330 | + if ( wpinv_get_errors() ) { |
|
| 331 | + wpinv_send_back_to_checkout(); |
|
| 332 | + } |
|
| 333 | 333 | |
| 334 | - // Send info to the gateway for payment processing |
|
| 335 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
| 334 | + // Send info to the gateway for payment processing |
|
| 335 | + do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
| 336 | 336 | |
| 337 | - // Backwards compatibility. |
|
| 338 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
| 337 | + // Backwards compatibility. |
|
| 338 | + wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
| 339 | 339 | |
| 340 | - } |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | - /** |
|
| 342 | + /** |
|
| 343 | 343 | * Sends a redrect response to payment details. |
| 344 | 344 | * |
| 345 | 345 | */ |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Main Checkout Class. |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * |
| 23 | 23 | * @param GetPaid_Payment_Form_Submission $submission |
| 24 | 24 | */ |
| 25 | - public function __construct( $submission ) { |
|
| 25 | + public function __construct($submission) { |
|
| 26 | 26 | $this->payment_form_submission = $submission; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -38,15 +38,15 @@ discard block |
||
| 38 | 38 | // Prepare the invoice. |
| 39 | 39 | $items = $this->get_submission_items(); |
| 40 | 40 | $invoice = $this->get_submission_invoice(); |
| 41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
| 42 | - $prepared = $this->prepare_submission_data_for_saving( $invoice ); |
|
| 41 | + $invoice = $this->process_submission_invoice($invoice, $items); |
|
| 42 | + $prepared = $this->prepare_submission_data_for_saving($invoice); |
|
| 43 | 43 | |
| 44 | 44 | // Save the invoice. |
| 45 | 45 | $invoice->recalculate_total(); |
| 46 | 46 | $invoice->save(); |
| 47 | 47 | |
| 48 | 48 | // Send to the gateway. |
| 49 | - $this->post_process_submission( $invoice, $prepared ); |
|
| 49 | + $this->post_process_submission($invoice, $prepared); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -59,34 +59,34 @@ discard block |
||
| 59 | 59 | $data = $submission->get_data(); |
| 60 | 60 | |
| 61 | 61 | // Do we have an error? |
| 62 | - if ( ! empty( $submission->last_error ) ) { |
|
| 63 | - wp_send_json_error( $submission->last_error ); |
|
| 62 | + if (!empty($submission->last_error)) { |
|
| 63 | + wp_send_json_error($submission->last_error); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | // We need a billing email. |
| 67 | - if ( ! $submission->has_billing_email() ) { |
|
| 68 | - wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
|
| 67 | + if (!$submission->has_billing_email()) { |
|
| 68 | + wp_send_json_error(__('Provide a valid billing email.', 'invoicing')); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | // Non-recurring gateways should not be allowed to process recurring invoices. |
| 72 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
| 73 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
| 72 | + if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) { |
|
| 73 | + wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing')); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | // Ensure the gateway is active. |
| 77 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
| 78 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
| 77 | + if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) { |
|
| 78 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not active', 'invoicing')); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | // Clear any existing errors. |
| 82 | 82 | wpinv_clear_errors(); |
| 83 | 83 | |
| 84 | 84 | // Allow themes and plugins to hook to errors |
| 85 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
| 85 | + do_action('getpaid_checkout_error_checks', $submission); |
|
| 86 | 86 | |
| 87 | 87 | // Do we have any errors? |
| 88 | - if ( wpinv_get_errors() ) { |
|
| 89 | - wp_send_json_error( getpaid_get_errors_html() ); |
|
| 88 | + if (wpinv_get_errors()) { |
|
| 89 | + wp_send_json_error(getpaid_get_errors_html()); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | } |
@@ -101,8 +101,8 @@ discard block |
||
| 101 | 101 | $items = $this->payment_form_submission->get_items(); |
| 102 | 102 | |
| 103 | 103 | // Ensure that we have items. |
| 104 | - if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
|
| 105 | - wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
|
| 104 | + if (empty($items) && !$this->payment_form_submission->has_fees()) { |
|
| 105 | + wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing')); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | return $items; |
@@ -116,17 +116,17 @@ discard block |
||
| 116 | 116 | protected function get_submission_invoice() { |
| 117 | 117 | $submission = $this->payment_form_submission; |
| 118 | 118 | |
| 119 | - if ( ! $submission->has_invoice() ) { |
|
| 119 | + if (!$submission->has_invoice()) { |
|
| 120 | 120 | $invoice = new WPInv_Invoice(); |
| 121 | - $invoice->created_via( 'payment_form' ); |
|
| 121 | + $invoice->created_via('payment_form'); |
|
| 122 | 122 | return $invoice; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | $invoice = $submission->get_invoice(); |
| 126 | 126 | |
| 127 | 127 | // Make sure that it is neither paid or refunded. |
| 128 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 129 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
| 128 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
| 129 | + wp_send_json_error(__('This invoice has already been paid for.', 'invoicing')); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | return $invoice; |
@@ -139,26 +139,26 @@ discard block |
||
| 139 | 139 | * @param GetPaid_Form_Item[] $items |
| 140 | 140 | * @return WPInv_Invoice |
| 141 | 141 | */ |
| 142 | - protected function process_submission_invoice( $invoice, $items ) { |
|
| 142 | + protected function process_submission_invoice($invoice, $items) { |
|
| 143 | 143 | |
| 144 | 144 | $submission = $this->payment_form_submission; |
| 145 | 145 | $data = $submission->get_data(); |
| 146 | 146 | |
| 147 | 147 | // Set-up the invoice details. |
| 148 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
| 149 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
| 150 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
| 151 | - $invoice->set_items( $items ); |
|
| 152 | - $invoice->set_fees( $submission->get_fees() ); |
|
| 153 | - $invoice->set_taxes( $submission->get_taxes() ); |
|
| 154 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
| 155 | - $invoice->set_gateway( $data['wpi-gateway'] ); |
|
| 156 | - |
|
| 157 | - if ( $submission->has_discount_code() ) { |
|
| 158 | - $invoice->set_discount_code( $submission->get_discount_code() ); |
|
| 148 | + $invoice->set_email(sanitize_email($submission->get_billing_email())); |
|
| 149 | + $invoice->set_user_id($this->get_submission_customer()); |
|
| 150 | + $invoice->set_payment_form(absint($submission->get_payment_form()->get_id())); |
|
| 151 | + $invoice->set_items($items); |
|
| 152 | + $invoice->set_fees($submission->get_fees()); |
|
| 153 | + $invoice->set_taxes($submission->get_taxes()); |
|
| 154 | + $invoice->set_discounts($submission->get_discounts()); |
|
| 155 | + $invoice->set_gateway($data['wpi-gateway']); |
|
| 156 | + |
|
| 157 | + if ($submission->has_discount_code()) { |
|
| 158 | + $invoice->set_discount_code($submission->get_discount_code()); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - getpaid_maybe_add_default_address( $invoice ); |
|
| 161 | + getpaid_maybe_add_default_address($invoice); |
|
| 162 | 162 | return $invoice; |
| 163 | 163 | } |
| 164 | 164 | |
@@ -171,26 +171,26 @@ discard block |
||
| 171 | 171 | $submission = $this->payment_form_submission; |
| 172 | 172 | |
| 173 | 173 | // If this is an existing invoice... |
| 174 | - if ( $submission->has_invoice() ) { |
|
| 174 | + if ($submission->has_invoice()) { |
|
| 175 | 175 | return $submission->get_invoice()->get_user_id(); |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | // (Maybe) create the user. |
| 179 | 179 | $user = get_current_user_id(); |
| 180 | 180 | |
| 181 | - if ( empty( $user ) ) { |
|
| 182 | - $user = get_user_by( 'email', $submission->get_billing_email() ); |
|
| 181 | + if (empty($user)) { |
|
| 182 | + $user = get_user_by('email', $submission->get_billing_email()); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - if ( empty( $user ) ) { |
|
| 186 | - $user = wpinv_create_user( $submission->get_billing_email() ); |
|
| 185 | + if (empty($user)) { |
|
| 186 | + $user = wpinv_create_user($submission->get_billing_email()); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - if ( is_wp_error( $user ) ) { |
|
| 190 | - wp_send_json_error( $user->get_error_message() ); |
|
| 189 | + if (is_wp_error($user)) { |
|
| 190 | + wp_send_json_error($user->get_error_message()); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - if ( is_numeric( $user ) ) { |
|
| 193 | + if (is_numeric($user)) { |
|
| 194 | 194 | return $user; |
| 195 | 195 | } |
| 196 | 196 | |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | * |
| 204 | 204 | * @param WPInv_Invoice $invoice |
| 205 | 205 | */ |
| 206 | - public function prepare_submission_data_for_saving( &$invoice ) { |
|
| 206 | + public function prepare_submission_data_for_saving(&$invoice) { |
|
| 207 | 207 | |
| 208 | 208 | $submission = $this->payment_form_submission; |
| 209 | 209 | |
@@ -214,49 +214,49 @@ discard block |
||
| 214 | 214 | $data = $submission->get_data(); |
| 215 | 215 | |
| 216 | 216 | // Loop throught the submitted details. |
| 217 | - foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
|
| 217 | + foreach ($submission->get_payment_form()->get_elements() as $field) { |
|
| 218 | 218 | |
| 219 | 219 | // Skip premade fields. |
| 220 | - if ( ! empty( $field['premade'] ) ) { |
|
| 220 | + if (!empty($field['premade'])) { |
|
| 221 | 221 | continue; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | // If it is required and not set, abort. |
| 225 | - if ( ! $submission->is_required_field_set( $field ) ) { |
|
| 226 | - wp_send_json_error( __( 'Some required fields are not set.', 'invoicing' ) ); |
|
| 225 | + if (!$submission->is_required_field_set($field)) { |
|
| 226 | + wp_send_json_error(__('Some required fields are not set.', 'invoicing')); |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | // Handle address fields. |
| 230 | - if ( $field['type'] == 'address' ) { |
|
| 230 | + if ($field['type'] == 'address') { |
|
| 231 | 231 | |
| 232 | - foreach ( $field['fields'] as $address_field ) { |
|
| 232 | + foreach ($field['fields'] as $address_field) { |
|
| 233 | 233 | |
| 234 | 234 | // skip if it is not visible. |
| 235 | - if ( empty( $address_field['visible'] ) ) { |
|
| 235 | + if (empty($address_field['visible'])) { |
|
| 236 | 236 | continue; |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | // If it is required and not set, abort |
| 240 | - if ( ! empty( $address_field['required'] ) && empty( $data[ $address_field['name'] ] ) ) { |
|
| 241 | - wp_send_json_error( __( 'Some required fields are not set.', 'invoicing' ) ); |
|
| 240 | + if (!empty($address_field['required']) && empty($data[$address_field['name']])) { |
|
| 241 | + wp_send_json_error(__('Some required fields are not set.', 'invoicing')); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | - if ( isset( $data[ $address_field['name'] ] ) ) { |
|
| 245 | - $name = str_replace( 'wpinv_', '', $address_field['name'] ); |
|
| 244 | + if (isset($data[$address_field['name']])) { |
|
| 245 | + $name = str_replace('wpinv_', '', $address_field['name']); |
|
| 246 | 246 | $method = "set_$name"; |
| 247 | - $invoice->$method( wpinv_clean( $data[ $address_field['name'] ] ) ); |
|
| 247 | + $invoice->$method(wpinv_clean($data[$address_field['name']])); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - } else if ( isset( $data[ $field['id'] ] ) ) { |
|
| 252 | + } else if (isset($data[$field['id']])) { |
|
| 253 | 253 | $label = $field['id']; |
| 254 | 254 | |
| 255 | - if ( isset( $field['label'] ) ) { |
|
| 255 | + if (isset($field['label'])) { |
|
| 256 | 256 | $label = $field['label']; |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] ); |
|
| 259 | + $prepared[wpinv_clean($label)] = wpinv_clean($data[$field['id']]); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | } |
@@ -271,22 +271,22 @@ discard block |
||
| 271 | 271 | * @param WPInv_Invoice $invoice |
| 272 | 272 | * @param array $prepared_payment_form_data |
| 273 | 273 | */ |
| 274 | - protected function post_process_submission( $invoice, $prepared_payment_form_data ) { |
|
| 274 | + protected function post_process_submission($invoice, $prepared_payment_form_data) { |
|
| 275 | 275 | |
| 276 | 276 | // Ensure the invoice exists. |
| 277 | - if ( ! $invoice->exists() ) { |
|
| 278 | - wp_send_json_error( __( 'An error occured while saving your invoice.', 'invoicing' ) ); |
|
| 277 | + if (!$invoice->exists()) { |
|
| 278 | + wp_send_json_error(__('An error occured while saving your invoice.', 'invoicing')); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | // Save payment form data. |
| 282 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
| 283 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data ); |
|
| 282 | + if (!empty($prepared_payment_form_data)) { |
|
| 283 | + update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | // Backwards compatibility. |
| 287 | - add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
|
| 287 | + add_filter('wp_redirect', array($this, 'send_redirect_response')); |
|
| 288 | 288 | |
| 289 | - $this->process_payment( $invoice ); |
|
| 289 | + $this->process_payment($invoice); |
|
| 290 | 290 | |
| 291 | 291 | // If we are here, there was an error. |
| 292 | 292 | wpinv_send_back_to_checkout(); |
@@ -298,44 +298,44 @@ discard block |
||
| 298 | 298 | * |
| 299 | 299 | * @param WPInv_Invoice $invoice |
| 300 | 300 | */ |
| 301 | - protected function process_payment( $invoice ) { |
|
| 301 | + protected function process_payment($invoice) { |
|
| 302 | 302 | |
| 303 | 303 | $submission = $this->payment_form_submission; |
| 304 | 304 | |
| 305 | 305 | // No need to send free invoices to the gateway. |
| 306 | - if ( $invoice->is_free() ) { |
|
| 307 | - $invoice->set_gateway( 'none' ); |
|
| 308 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
| 306 | + if ($invoice->is_free()) { |
|
| 307 | + $invoice->set_gateway('none'); |
|
| 308 | + $invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true); |
|
| 309 | 309 | $invoice->mark_paid(); |
| 310 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 310 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | // Clear any checkout errors. |
| 314 | 314 | wpinv_clear_errors(); |
| 315 | 315 | |
| 316 | 316 | // Fires before sending to the gateway. |
| 317 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
| 317 | + do_action('getpaid_checkout_before_gateway', $invoice, $submission); |
|
| 318 | 318 | |
| 319 | 319 | // Allow the sumission data to be modified before it is sent to the gateway. |
| 320 | 320 | $submission_data = $submission->get_data(); |
| 321 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
| 322 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
| 321 | + $submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice); |
|
| 322 | + $submission_data = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice); |
|
| 323 | 323 | |
| 324 | 324 | // Validate the currency. |
| 325 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
| 326 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support the invoice currency', 'invoicing' ) ); |
|
| 325 | + if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) { |
|
| 326 | + wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support the invoice currency', 'invoicing')); |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | // Check to see if we have any errors. |
| 330 | - if ( wpinv_get_errors() ) { |
|
| 330 | + if (wpinv_get_errors()) { |
|
| 331 | 331 | wpinv_send_back_to_checkout(); |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | // Send info to the gateway for payment processing |
| 335 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
| 335 | + do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission); |
|
| 336 | 336 | |
| 337 | 337 | // Backwards compatibility. |
| 338 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
| 338 | + wpinv_send_to_gateway($submission_gateway, $invoice); |
|
| 339 | 339 | |
| 340 | 340 | } |
| 341 | 341 | |
@@ -343,9 +343,9 @@ discard block |
||
| 343 | 343 | * Sends a redrect response to payment details. |
| 344 | 344 | * |
| 345 | 345 | */ |
| 346 | - public function send_redirect_response( $url ) { |
|
| 347 | - $url = urlencode( $url ); |
|
| 348 | - wp_send_json_success( $url ); |
|
| 346 | + public function send_redirect_response($url) { |
|
| 347 | + $url = urlencode($url); |
|
| 348 | + wp_send_json_success($url); |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | } |
@@ -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,187 +10,187 @@ discard block |
||
| 10 | 10 | class GetPaid_Payment_Form_Submission { |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * Submission ID |
|
| 14 | - * |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - public $id = null; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * The raw submission data. |
|
| 21 | - * |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - protected $data = null; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Submission totals |
|
| 28 | - * |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $totals = array( |
|
| 32 | - |
|
| 33 | - 'subtotal' => array( |
|
| 34 | - 'initial' => 0, |
|
| 35 | - 'recurring' => 0, |
|
| 36 | - ), |
|
| 37 | - |
|
| 38 | - 'discount' => array( |
|
| 39 | - 'initial' => 0, |
|
| 40 | - 'recurring' => 0, |
|
| 41 | - ), |
|
| 42 | - |
|
| 43 | - 'fees' => array( |
|
| 44 | - 'initial' => 0, |
|
| 45 | - 'recurring' => 0, |
|
| 46 | - ), |
|
| 47 | - |
|
| 48 | - 'taxes' => array( |
|
| 49 | - 'initial' => 0, |
|
| 50 | - 'recurring' => 0, |
|
| 51 | - ), |
|
| 52 | - |
|
| 53 | - ); |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Sets the associated payment form. |
|
| 57 | - * |
|
| 58 | - * @var GetPaid_Payment_Form |
|
| 59 | - */ |
|
| 13 | + * Submission ID |
|
| 14 | + * |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + public $id = null; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * The raw submission data. |
|
| 21 | + * |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + protected $data = null; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Submission totals |
|
| 28 | + * |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $totals = array( |
|
| 32 | + |
|
| 33 | + 'subtotal' => array( |
|
| 34 | + 'initial' => 0, |
|
| 35 | + 'recurring' => 0, |
|
| 36 | + ), |
|
| 37 | + |
|
| 38 | + 'discount' => array( |
|
| 39 | + 'initial' => 0, |
|
| 40 | + 'recurring' => 0, |
|
| 41 | + ), |
|
| 42 | + |
|
| 43 | + 'fees' => array( |
|
| 44 | + 'initial' => 0, |
|
| 45 | + 'recurring' => 0, |
|
| 46 | + ), |
|
| 47 | + |
|
| 48 | + 'taxes' => array( |
|
| 49 | + 'initial' => 0, |
|
| 50 | + 'recurring' => 0, |
|
| 51 | + ), |
|
| 52 | + |
|
| 53 | + ); |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Sets the associated payment form. |
|
| 57 | + * |
|
| 58 | + * @var GetPaid_Payment_Form |
|
| 59 | + */ |
|
| 60 | 60 | protected $payment_form = null; |
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | - * The country for the submission. |
|
| 64 | - * |
|
| 65 | - * @var string |
|
| 66 | - */ |
|
| 67 | - public $country = null; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * The state for the submission. |
|
| 71 | - * |
|
| 72 | - * @since 1.0.19 |
|
| 73 | - * @var string |
|
| 74 | - */ |
|
| 75 | - public $state = null; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * The invoice associated with the submission. |
|
| 79 | - * |
|
| 80 | - * @var WPInv_Invoice |
|
| 81 | - */ |
|
| 82 | - protected $invoice = null; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * The recurring item for the submission. |
|
| 86 | - * |
|
| 87 | - * @var int |
|
| 88 | - */ |
|
| 89 | - public $has_recurring = 0; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * An array of fees for the submission. |
|
| 93 | - * |
|
| 94 | - * @var array |
|
| 95 | - */ |
|
| 96 | - protected $fees = array(); |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * An array of discounts for the submission. |
|
| 100 | - * |
|
| 101 | - * @var array |
|
| 102 | - */ |
|
| 103 | - protected $discounts = array(); |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * An array of taxes for the submission. |
|
| 107 | - * |
|
| 108 | - * @var array |
|
| 109 | - */ |
|
| 110 | - protected $taxes = array(); |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * An array of items for the submission. |
|
| 114 | - * |
|
| 115 | - * @var GetPaid_Form_Item[] |
|
| 116 | - */ |
|
| 117 | - protected $items = array(); |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * The last error. |
|
| 121 | - * |
|
| 122 | - * @var string |
|
| 123 | - */ |
|
| 124 | - public $last_error = null; |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Class constructor. |
|
| 128 | - * |
|
| 129 | - */ |
|
| 130 | - public function __construct() { |
|
| 131 | - |
|
| 132 | - // Set the state and country to the default state and country. |
|
| 133 | - $this->country = wpinv_default_billing_country(); |
|
| 134 | - $this->state = wpinv_get_default_state(); |
|
| 135 | - |
|
| 136 | - // Do we have an actual submission? |
|
| 137 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 138 | - $this->load_data( $_POST ); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Loads submission data. |
|
| 145 | - * |
|
| 146 | - * @param array $data |
|
| 147 | - */ |
|
| 148 | - public function load_data( $data ) { |
|
| 149 | - |
|
| 150 | - // Remove slashes from the submitted data... |
|
| 151 | - $data = wp_unslash( $data ); |
|
| 152 | - |
|
| 153 | - // Allow plugins to filter the data. |
|
| 154 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 155 | - |
|
| 156 | - // Cache it... |
|
| 157 | - $this->data = $data; |
|
| 158 | - |
|
| 159 | - // Then generate a unique id from the data. |
|
| 160 | - $this->id = md5( wp_json_encode( $data ) ); |
|
| 161 | - |
|
| 162 | - // Finally, process the submission. |
|
| 163 | - try { |
|
| 164 | - |
|
| 165 | - // Each process is passed an instance of the class (with reference) |
|
| 166 | - // and should throw an Exception whenever it encounters one. |
|
| 167 | - $processors = apply_filters( |
|
| 168 | - 'getpaid_payment_form_submission_processors', |
|
| 169 | - array( |
|
| 170 | - array( $this, 'process_payment_form' ), |
|
| 171 | - array( $this, 'process_invoice' ), |
|
| 172 | - array( $this, 'process_fees' ), |
|
| 173 | - array( $this, 'process_items' ), |
|
| 174 | - array( $this, 'process_taxes' ), |
|
| 175 | - array( $this, 'process_discount' ), |
|
| 176 | - ), |
|
| 177 | - $this |
|
| 178 | - ); |
|
| 179 | - |
|
| 180 | - foreach ( $processors as $processor ) { |
|
| 181 | - call_user_func_array( $processor, array( &$this ) ); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - } catch ( Exception $e ) { |
|
| 185 | - $this->last_error = $e->getMessage(); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - // Fired when we are done processing a submission. |
|
| 189 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 190 | - |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /* |
|
| 63 | + * The country for the submission. |
|
| 64 | + * |
|
| 65 | + * @var string |
|
| 66 | + */ |
|
| 67 | + public $country = null; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * The state for the submission. |
|
| 71 | + * |
|
| 72 | + * @since 1.0.19 |
|
| 73 | + * @var string |
|
| 74 | + */ |
|
| 75 | + public $state = null; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * The invoice associated with the submission. |
|
| 79 | + * |
|
| 80 | + * @var WPInv_Invoice |
|
| 81 | + */ |
|
| 82 | + protected $invoice = null; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * The recurring item for the submission. |
|
| 86 | + * |
|
| 87 | + * @var int |
|
| 88 | + */ |
|
| 89 | + public $has_recurring = 0; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * An array of fees for the submission. |
|
| 93 | + * |
|
| 94 | + * @var array |
|
| 95 | + */ |
|
| 96 | + protected $fees = array(); |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * An array of discounts for the submission. |
|
| 100 | + * |
|
| 101 | + * @var array |
|
| 102 | + */ |
|
| 103 | + protected $discounts = array(); |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * An array of taxes for the submission. |
|
| 107 | + * |
|
| 108 | + * @var array |
|
| 109 | + */ |
|
| 110 | + protected $taxes = array(); |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * An array of items for the submission. |
|
| 114 | + * |
|
| 115 | + * @var GetPaid_Form_Item[] |
|
| 116 | + */ |
|
| 117 | + protected $items = array(); |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * The last error. |
|
| 121 | + * |
|
| 122 | + * @var string |
|
| 123 | + */ |
|
| 124 | + public $last_error = null; |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Class constructor. |
|
| 128 | + * |
|
| 129 | + */ |
|
| 130 | + public function __construct() { |
|
| 131 | + |
|
| 132 | + // Set the state and country to the default state and country. |
|
| 133 | + $this->country = wpinv_default_billing_country(); |
|
| 134 | + $this->state = wpinv_get_default_state(); |
|
| 135 | + |
|
| 136 | + // Do we have an actual submission? |
|
| 137 | + if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 138 | + $this->load_data( $_POST ); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Loads submission data. |
|
| 145 | + * |
|
| 146 | + * @param array $data |
|
| 147 | + */ |
|
| 148 | + public function load_data( $data ) { |
|
| 149 | + |
|
| 150 | + // Remove slashes from the submitted data... |
|
| 151 | + $data = wp_unslash( $data ); |
|
| 152 | + |
|
| 153 | + // Allow plugins to filter the data. |
|
| 154 | + $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 155 | + |
|
| 156 | + // Cache it... |
|
| 157 | + $this->data = $data; |
|
| 158 | + |
|
| 159 | + // Then generate a unique id from the data. |
|
| 160 | + $this->id = md5( wp_json_encode( $data ) ); |
|
| 161 | + |
|
| 162 | + // Finally, process the submission. |
|
| 163 | + try { |
|
| 164 | + |
|
| 165 | + // Each process is passed an instance of the class (with reference) |
|
| 166 | + // and should throw an Exception whenever it encounters one. |
|
| 167 | + $processors = apply_filters( |
|
| 168 | + 'getpaid_payment_form_submission_processors', |
|
| 169 | + array( |
|
| 170 | + array( $this, 'process_payment_form' ), |
|
| 171 | + array( $this, 'process_invoice' ), |
|
| 172 | + array( $this, 'process_fees' ), |
|
| 173 | + array( $this, 'process_items' ), |
|
| 174 | + array( $this, 'process_taxes' ), |
|
| 175 | + array( $this, 'process_discount' ), |
|
| 176 | + ), |
|
| 177 | + $this |
|
| 178 | + ); |
|
| 179 | + |
|
| 180 | + foreach ( $processors as $processor ) { |
|
| 181 | + call_user_func_array( $processor, array( &$this ) ); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + } catch ( Exception $e ) { |
|
| 185 | + $this->last_error = $e->getMessage(); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + // Fired when we are done processing a submission. |
|
| 189 | + do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 190 | + |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /* |
|
| 194 | 194 | |-------------------------------------------------------------------------- |
| 195 | 195 | | Payment Forms. |
| 196 | 196 | |-------------------------------------------------------------------------- |
@@ -199,39 +199,39 @@ discard block |
||
| 199 | 199 | | submission has an active payment form etc. |
| 200 | 200 | */ |
| 201 | 201 | |
| 202 | - /** |
|
| 203 | - * Prepares the submission's payment form. |
|
| 204 | - * |
|
| 205 | - * @since 1.0.19 |
|
| 206 | - */ |
|
| 207 | - public function process_payment_form() { |
|
| 202 | + /** |
|
| 203 | + * Prepares the submission's payment form. |
|
| 204 | + * |
|
| 205 | + * @since 1.0.19 |
|
| 206 | + */ |
|
| 207 | + public function process_payment_form() { |
|
| 208 | 208 | |
| 209 | - // Every submission needs an active payment form. |
|
| 210 | - if ( empty( $this->data['form_id'] ) ) { |
|
| 211 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 212 | - } |
|
| 209 | + // Every submission needs an active payment form. |
|
| 210 | + if ( empty( $this->data['form_id'] ) ) { |
|
| 211 | + throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - // Fetch the payment form. |
|
| 215 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 214 | + // Fetch the payment form. |
|
| 215 | + $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 216 | 216 | |
| 217 | - if ( ! $this->payment_form->is_active() ) { |
|
| 218 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 219 | - } |
|
| 217 | + if ( ! $this->payment_form->is_active() ) { |
|
| 218 | + throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 222 | - } |
|
| 221 | + do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | 224 | /** |
| 225 | - * Returns the payment form. |
|
| 226 | - * |
|
| 227 | - * @since 1.0.19 |
|
| 228 | - * @return GetPaid_Payment_Form |
|
| 229 | - */ |
|
| 230 | - public function get_payment_form() { |
|
| 231 | - return $this->payment_form; |
|
| 232 | - } |
|
| 225 | + * Returns the payment form. |
|
| 226 | + * |
|
| 227 | + * @since 1.0.19 |
|
| 228 | + * @return GetPaid_Payment_Form |
|
| 229 | + */ |
|
| 230 | + public function get_payment_form() { |
|
| 231 | + return $this->payment_form; |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - /* |
|
| 234 | + /* |
|
| 235 | 235 | |-------------------------------------------------------------------------- |
| 236 | 236 | | Invoices. |
| 237 | 237 | |-------------------------------------------------------------------------- |
@@ -240,61 +240,61 @@ discard block |
||
| 240 | 240 | | might be for an existing invoice. |
| 241 | 241 | */ |
| 242 | 242 | |
| 243 | - /** |
|
| 244 | - * Prepares the submission's invoice. |
|
| 245 | - * |
|
| 246 | - * @since 1.0.19 |
|
| 247 | - */ |
|
| 248 | - public function process_invoice() { |
|
| 243 | + /** |
|
| 244 | + * Prepares the submission's invoice. |
|
| 245 | + * |
|
| 246 | + * @since 1.0.19 |
|
| 247 | + */ |
|
| 248 | + public function process_invoice() { |
|
| 249 | 249 | |
| 250 | - // Abort if there is no invoice. |
|
| 251 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
| 252 | - return; |
|
| 253 | - } |
|
| 250 | + // Abort if there is no invoice. |
|
| 251 | + if ( empty( $this->data['invoice_id'] ) ) { |
|
| 252 | + return; |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - // If the submission is for an existing invoice, ensure that it exists |
|
| 256 | - // and that it is not paid for. |
|
| 257 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 255 | + // If the submission is for an existing invoice, ensure that it exists |
|
| 256 | + // and that it is not paid for. |
|
| 257 | + $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 258 | 258 | |
| 259 | 259 | if ( empty( $invoice ) ) { |
| 260 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - if ( $invoice->is_paid() ) { |
|
| 264 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
| 268 | - $this->payment_form->invoice = $invoice; |
|
| 269 | - |
|
| 270 | - $this->country = $invoice->get_country(); |
|
| 271 | - $this->state = $invoice->get_state(); |
|
| 272 | - $this->invoice = $invoice; |
|
| 273 | - |
|
| 274 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * Returns the associated invoice. |
|
| 279 | - * |
|
| 280 | - * @since 1.0.19 |
|
| 281 | - * @return WPInv_Invoice |
|
| 282 | - */ |
|
| 283 | - public function get_invoice() { |
|
| 284 | - return $this->invoice; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * Checks whether there is an invoice associated with this submission. |
|
| 289 | - * |
|
| 290 | - * @since 1.0.19 |
|
| 291 | - * @return bool |
|
| 292 | - */ |
|
| 293 | - public function has_invoice() { |
|
| 294 | - return ! empty( $this->invoice ); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /* |
|
| 260 | + throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + if ( $invoice->is_paid() ) { |
|
| 264 | + throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + $this->payment_form->set_items( $invoice->get_items() ); |
|
| 268 | + $this->payment_form->invoice = $invoice; |
|
| 269 | + |
|
| 270 | + $this->country = $invoice->get_country(); |
|
| 271 | + $this->state = $invoice->get_state(); |
|
| 272 | + $this->invoice = $invoice; |
|
| 273 | + |
|
| 274 | + do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * Returns the associated invoice. |
|
| 279 | + * |
|
| 280 | + * @since 1.0.19 |
|
| 281 | + * @return WPInv_Invoice |
|
| 282 | + */ |
|
| 283 | + public function get_invoice() { |
|
| 284 | + return $this->invoice; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * Checks whether there is an invoice associated with this submission. |
|
| 289 | + * |
|
| 290 | + * @since 1.0.19 |
|
| 291 | + * @return bool |
|
| 292 | + */ |
|
| 293 | + public function has_invoice() { |
|
| 294 | + return ! empty( $this->invoice ); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /* |
|
| 298 | 298 | |-------------------------------------------------------------------------- |
| 299 | 299 | | Items. |
| 300 | 300 | |-------------------------------------------------------------------------- |
@@ -303,105 +303,105 @@ discard block |
||
| 303 | 303 | | recurring item. But can have an unlimited number of non-recurring items. |
| 304 | 304 | */ |
| 305 | 305 | |
| 306 | - /** |
|
| 307 | - * Prepares the submission's items. |
|
| 308 | - * |
|
| 309 | - * @since 1.0.19 |
|
| 310 | - */ |
|
| 311 | - public function process_items() { |
|
| 312 | - |
|
| 313 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 314 | - |
|
| 315 | - foreach ( $processor->items as $item ) { |
|
| 316 | - $this->add_item( $item ); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * Adds an item to the submission. |
|
| 324 | - * |
|
| 325 | - * @since 1.0.19 |
|
| 326 | - * @param GetPaid_Form_Item $item |
|
| 327 | - */ |
|
| 328 | - public function add_item( $item ) { |
|
| 329 | - |
|
| 330 | - // Make sure that it is available for purchase. |
|
| 331 | - if ( ! $item->can_purchase() ) { |
|
| 332 | - return; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - // Each submission can only contain one recurring item. |
|
| 336 | - if ( $item->is_recurring() ) { |
|
| 337 | - |
|
| 338 | - if ( $this->has_recurring != 0 ) { |
|
| 339 | - throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) ); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - $this->has_recurring = $item->get_id(); |
|
| 343 | - |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - // Update the items and totals. |
|
| 347 | - $this->items[ $item->get_id() ] = $item; |
|
| 348 | - $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
| 349 | - $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
| 350 | - |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * Removes a specific item. |
|
| 355 | - * |
|
| 356 | - * You should not call this method after the discounts and taxes |
|
| 357 | - * have been calculated. |
|
| 358 | - * |
|
| 359 | - * @since 1.0.19 |
|
| 360 | - */ |
|
| 361 | - public function remove_item( $item_id ) { |
|
| 362 | - |
|
| 363 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
| 364 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 365 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 366 | - |
|
| 367 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 368 | - $this->has_recurring = 0; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - unset( $this->items[ $item_id ] ); |
|
| 372 | - } |
|
| 306 | + /** |
|
| 307 | + * Prepares the submission's items. |
|
| 308 | + * |
|
| 309 | + * @since 1.0.19 |
|
| 310 | + */ |
|
| 311 | + public function process_items() { |
|
| 312 | + |
|
| 313 | + $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 314 | + |
|
| 315 | + foreach ( $processor->items as $item ) { |
|
| 316 | + $this->add_item( $item ); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * Adds an item to the submission. |
|
| 324 | + * |
|
| 325 | + * @since 1.0.19 |
|
| 326 | + * @param GetPaid_Form_Item $item |
|
| 327 | + */ |
|
| 328 | + public function add_item( $item ) { |
|
| 329 | + |
|
| 330 | + // Make sure that it is available for purchase. |
|
| 331 | + if ( ! $item->can_purchase() ) { |
|
| 332 | + return; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + // Each submission can only contain one recurring item. |
|
| 336 | + if ( $item->is_recurring() ) { |
|
| 337 | + |
|
| 338 | + if ( $this->has_recurring != 0 ) { |
|
| 339 | + throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) ); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + $this->has_recurring = $item->get_id(); |
|
| 343 | + |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + // Update the items and totals. |
|
| 347 | + $this->items[ $item->get_id() ] = $item; |
|
| 348 | + $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
|
| 349 | + $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
|
| 350 | + |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * Removes a specific item. |
|
| 355 | + * |
|
| 356 | + * You should not call this method after the discounts and taxes |
|
| 357 | + * have been calculated. |
|
| 358 | + * |
|
| 359 | + * @since 1.0.19 |
|
| 360 | + */ |
|
| 361 | + public function remove_item( $item_id ) { |
|
| 362 | + |
|
| 363 | + if ( isset( $this->items[ $item_id ] ) ) { |
|
| 364 | + $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 365 | + $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 366 | + |
|
| 367 | + if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 368 | + $this->has_recurring = 0; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + unset( $this->items[ $item_id ] ); |
|
| 372 | + } |
|
| 373 | 373 | |
| 374 | - } |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * Returns the subtotal. |
|
| 378 | - * |
|
| 379 | - * @since 1.0.19 |
|
| 380 | - */ |
|
| 381 | - public function get_subtotal() { |
|
| 382 | - return $this->totals['subtotal']['initial']; |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Returns the recurring subtotal. |
|
| 387 | - * |
|
| 388 | - * @since 1.0.19 |
|
| 389 | - */ |
|
| 390 | - public function get_recurring_subtotal() { |
|
| 391 | - return $this->totals['subtotal']['recurring']; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * Returns all items. |
|
| 396 | - * |
|
| 397 | - * @since 1.0.19 |
|
| 398 | - * @return GetPaid_Form_Item[] |
|
| 399 | - */ |
|
| 400 | - public function get_items() { |
|
| 401 | - return $this->items; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - /* |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * Returns the subtotal. |
|
| 378 | + * |
|
| 379 | + * @since 1.0.19 |
|
| 380 | + */ |
|
| 381 | + public function get_subtotal() { |
|
| 382 | + return $this->totals['subtotal']['initial']; |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Returns the recurring subtotal. |
|
| 387 | + * |
|
| 388 | + * @since 1.0.19 |
|
| 389 | + */ |
|
| 390 | + public function get_recurring_subtotal() { |
|
| 391 | + return $this->totals['subtotal']['recurring']; |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * Returns all items. |
|
| 396 | + * |
|
| 397 | + * @since 1.0.19 |
|
| 398 | + * @return GetPaid_Form_Item[] |
|
| 399 | + */ |
|
| 400 | + public function get_items() { |
|
| 401 | + return $this->items; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + /* |
|
| 405 | 405 | |-------------------------------------------------------------------------- |
| 406 | 406 | | Taxes |
| 407 | 407 | |-------------------------------------------------------------------------- |
@@ -410,108 +410,108 @@ discard block |
||
| 410 | 410 | | or only one-time. |
| 411 | 411 | */ |
| 412 | 412 | |
| 413 | - /** |
|
| 414 | - * Prepares the submission's taxes. |
|
| 415 | - * |
|
| 416 | - * @since 1.0.19 |
|
| 417 | - */ |
|
| 418 | - public function process_taxes() { |
|
| 419 | - |
|
| 420 | - // Abort if we're not using taxes. |
|
| 421 | - if ( ! $this->use_taxes() ) { |
|
| 422 | - return; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - // If a custom country && state has been passed in, use it to calculate taxes. |
|
| 426 | - if ( ! empty( $this->data['wpinv_country'] ) ) { |
|
| 427 | - $this->country = $this->data['wpinv_country']; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - if ( ! empty( $this->data['wpinv_state'] ) ) { |
|
| 431 | - $this->country = $this->data['wpinv_state']; |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 435 | - |
|
| 436 | - foreach ( $processor->taxes as $tax ) { |
|
| 437 | - $this->add_tax( $tax ); |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * Adds a tax to the submission. |
|
| 445 | - * |
|
| 446 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
| 447 | - * @since 1.0.19 |
|
| 448 | - */ |
|
| 449 | - public function add_tax( $tax ) { |
|
| 450 | - $this->taxes[ $tax['name'] ] = $tax; |
|
| 451 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 452 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * Removes a specific tax. |
|
| 457 | - * |
|
| 458 | - * @since 1.0.19 |
|
| 459 | - */ |
|
| 460 | - public function remove_tax( $tax_name ) { |
|
| 461 | - |
|
| 462 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 463 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 464 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 465 | - unset( $this->taxes[ $tax_name ] ); |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * Whether or not we'll use taxes for the submission. |
|
| 472 | - * |
|
| 473 | - * @since 1.0.19 |
|
| 474 | - */ |
|
| 475 | - public function use_taxes() { |
|
| 476 | - |
|
| 477 | - $use_taxes = wpinv_use_taxes(); |
|
| 478 | - |
|
| 479 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 480 | - $use_taxes = false; |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 484 | - |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * Returns the tax. |
|
| 489 | - * |
|
| 490 | - * @since 1.0.19 |
|
| 491 | - */ |
|
| 492 | - public function get_tax() { |
|
| 493 | - return $this->totals['taxes']['initial']; |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - /** |
|
| 497 | - * Returns the recurring tax. |
|
| 498 | - * |
|
| 499 | - * @since 1.0.19 |
|
| 500 | - */ |
|
| 501 | - public function get_recurring_tax() { |
|
| 502 | - return $this->totals['taxes']['recurring']; |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * Returns all taxes. |
|
| 507 | - * |
|
| 508 | - * @since 1.0.19 |
|
| 509 | - */ |
|
| 510 | - public function get_taxes() { |
|
| 511 | - return $this->taxes; |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - /* |
|
| 413 | + /** |
|
| 414 | + * Prepares the submission's taxes. |
|
| 415 | + * |
|
| 416 | + * @since 1.0.19 |
|
| 417 | + */ |
|
| 418 | + public function process_taxes() { |
|
| 419 | + |
|
| 420 | + // Abort if we're not using taxes. |
|
| 421 | + if ( ! $this->use_taxes() ) { |
|
| 422 | + return; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + // If a custom country && state has been passed in, use it to calculate taxes. |
|
| 426 | + if ( ! empty( $this->data['wpinv_country'] ) ) { |
|
| 427 | + $this->country = $this->data['wpinv_country']; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + if ( ! empty( $this->data['wpinv_state'] ) ) { |
|
| 431 | + $this->country = $this->data['wpinv_state']; |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 435 | + |
|
| 436 | + foreach ( $processor->taxes as $tax ) { |
|
| 437 | + $this->add_tax( $tax ); |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * Adds a tax to the submission. |
|
| 445 | + * |
|
| 446 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
| 447 | + * @since 1.0.19 |
|
| 448 | + */ |
|
| 449 | + public function add_tax( $tax ) { |
|
| 450 | + $this->taxes[ $tax['name'] ] = $tax; |
|
| 451 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 452 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * Removes a specific tax. |
|
| 457 | + * |
|
| 458 | + * @since 1.0.19 |
|
| 459 | + */ |
|
| 460 | + public function remove_tax( $tax_name ) { |
|
| 461 | + |
|
| 462 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 463 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 464 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 465 | + unset( $this->taxes[ $tax_name ] ); |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * Whether or not we'll use taxes for the submission. |
|
| 472 | + * |
|
| 473 | + * @since 1.0.19 |
|
| 474 | + */ |
|
| 475 | + public function use_taxes() { |
|
| 476 | + |
|
| 477 | + $use_taxes = wpinv_use_taxes(); |
|
| 478 | + |
|
| 479 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 480 | + $use_taxes = false; |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 484 | + |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * Returns the tax. |
|
| 489 | + * |
|
| 490 | + * @since 1.0.19 |
|
| 491 | + */ |
|
| 492 | + public function get_tax() { |
|
| 493 | + return $this->totals['taxes']['initial']; |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + /** |
|
| 497 | + * Returns the recurring tax. |
|
| 498 | + * |
|
| 499 | + * @since 1.0.19 |
|
| 500 | + */ |
|
| 501 | + public function get_recurring_tax() { |
|
| 502 | + return $this->totals['taxes']['recurring']; |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * Returns all taxes. |
|
| 507 | + * |
|
| 508 | + * @since 1.0.19 |
|
| 509 | + */ |
|
| 510 | + public function get_taxes() { |
|
| 511 | + return $this->taxes; |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + /* |
|
| 515 | 515 | |-------------------------------------------------------------------------- |
| 516 | 516 | | Discounts |
| 517 | 517 | |-------------------------------------------------------------------------- |
@@ -520,99 +520,99 @@ discard block |
||
| 520 | 520 | | or only one-time. They also do not have to come from a discount code. |
| 521 | 521 | */ |
| 522 | 522 | |
| 523 | - /** |
|
| 524 | - * Prepares the submission's discount. |
|
| 525 | - * |
|
| 526 | - * @since 1.0.19 |
|
| 527 | - */ |
|
| 528 | - public function process_discount() { |
|
| 529 | - |
|
| 530 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
| 531 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
| 532 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 533 | - |
|
| 534 | - foreach ( $processor->discounts as $discount ) { |
|
| 535 | - $this->add_discount( $discount ); |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * Adds a discount to the submission. |
|
| 543 | - * |
|
| 544 | - * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
| 545 | - * @since 1.0.19 |
|
| 546 | - */ |
|
| 547 | - public function add_discount( $discount ) { |
|
| 548 | - $this->discounts[ $discount['name'] ] = $discount; |
|
| 549 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 550 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - /** |
|
| 554 | - * Removes a discount from the submission. |
|
| 555 | - * |
|
| 556 | - * @since 1.0.19 |
|
| 557 | - */ |
|
| 558 | - public function remove_discount( $name ) { |
|
| 559 | - |
|
| 560 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
| 561 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 562 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 563 | - unset( $this->discounts[ $name ] ); |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - /** |
|
| 569 | - * Checks whether there is a discount code associated with this submission. |
|
| 570 | - * |
|
| 571 | - * @since 1.0.19 |
|
| 572 | - * @return bool |
|
| 573 | - */ |
|
| 574 | - public function has_discount_code() { |
|
| 575 | - return ! empty( $this->discounts['discount_code'] ); |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - /** |
|
| 579 | - * Returns the discount code. |
|
| 580 | - * |
|
| 581 | - * @since 1.0.19 |
|
| 582 | - * @return string |
|
| 583 | - */ |
|
| 584 | - public function get_discount_code() { |
|
| 585 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * Returns the discount. |
|
| 590 | - * |
|
| 591 | - * @since 1.0.19 |
|
| 592 | - */ |
|
| 593 | - public function get_discount() { |
|
| 594 | - return $this->totals['discount']['initial']; |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - /** |
|
| 598 | - * Returns the recurring discount. |
|
| 599 | - * |
|
| 600 | - * @since 1.0.19 |
|
| 601 | - */ |
|
| 602 | - public function get_recurring_discount() { |
|
| 603 | - return $this->totals['discount']['recurring']; |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - /** |
|
| 607 | - * Returns all discounts. |
|
| 608 | - * |
|
| 609 | - * @since 1.0.19 |
|
| 610 | - */ |
|
| 611 | - public function get_discounts() { |
|
| 612 | - return $this->discounts; |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - /* |
|
| 523 | + /** |
|
| 524 | + * Prepares the submission's discount. |
|
| 525 | + * |
|
| 526 | + * @since 1.0.19 |
|
| 527 | + */ |
|
| 528 | + public function process_discount() { |
|
| 529 | + |
|
| 530 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
| 531 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
| 532 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 533 | + |
|
| 534 | + foreach ( $processor->discounts as $discount ) { |
|
| 535 | + $this->add_discount( $discount ); |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * Adds a discount to the submission. |
|
| 543 | + * |
|
| 544 | + * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
|
| 545 | + * @since 1.0.19 |
|
| 546 | + */ |
|
| 547 | + public function add_discount( $discount ) { |
|
| 548 | + $this->discounts[ $discount['name'] ] = $discount; |
|
| 549 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 550 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + /** |
|
| 554 | + * Removes a discount from the submission. |
|
| 555 | + * |
|
| 556 | + * @since 1.0.19 |
|
| 557 | + */ |
|
| 558 | + public function remove_discount( $name ) { |
|
| 559 | + |
|
| 560 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
| 561 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 562 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 563 | + unset( $this->discounts[ $name ] ); |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + /** |
|
| 569 | + * Checks whether there is a discount code associated with this submission. |
|
| 570 | + * |
|
| 571 | + * @since 1.0.19 |
|
| 572 | + * @return bool |
|
| 573 | + */ |
|
| 574 | + public function has_discount_code() { |
|
| 575 | + return ! empty( $this->discounts['discount_code'] ); |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + /** |
|
| 579 | + * Returns the discount code. |
|
| 580 | + * |
|
| 581 | + * @since 1.0.19 |
|
| 582 | + * @return string |
|
| 583 | + */ |
|
| 584 | + public function get_discount_code() { |
|
| 585 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * Returns the discount. |
|
| 590 | + * |
|
| 591 | + * @since 1.0.19 |
|
| 592 | + */ |
|
| 593 | + public function get_discount() { |
|
| 594 | + return $this->totals['discount']['initial']; |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + /** |
|
| 598 | + * Returns the recurring discount. |
|
| 599 | + * |
|
| 600 | + * @since 1.0.19 |
|
| 601 | + */ |
|
| 602 | + public function get_recurring_discount() { |
|
| 603 | + return $this->totals['discount']['recurring']; |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + /** |
|
| 607 | + * Returns all discounts. |
|
| 608 | + * |
|
| 609 | + * @since 1.0.19 |
|
| 610 | + */ |
|
| 611 | + public function get_discounts() { |
|
| 612 | + return $this->discounts; |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + /* |
|
| 616 | 616 | |-------------------------------------------------------------------------- |
| 617 | 617 | | Fees |
| 618 | 618 | |-------------------------------------------------------------------------- |
@@ -622,89 +622,89 @@ discard block |
||
| 622 | 622 | | fees. |
| 623 | 623 | */ |
| 624 | 624 | |
| 625 | - /** |
|
| 626 | - * Prepares the submission's fees. |
|
| 627 | - * |
|
| 628 | - * @since 1.0.19 |
|
| 629 | - */ |
|
| 630 | - public function process_fees() { |
|
| 631 | - |
|
| 632 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 633 | - |
|
| 634 | - foreach ( $fees_processor->fees as $fee ) { |
|
| 635 | - $this->add_fee( $fee ); |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - /** |
|
| 642 | - * Adds a fee to the submission. |
|
| 643 | - * |
|
| 644 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 645 | - * @since 1.0.19 |
|
| 646 | - */ |
|
| 647 | - public function add_fee( $fee ) { |
|
| 648 | - |
|
| 649 | - $this->fees[ $fee['name'] ] = $fee; |
|
| 650 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 651 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 652 | - |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - /** |
|
| 656 | - * Removes a fee from the submission. |
|
| 657 | - * |
|
| 658 | - * @since 1.0.19 |
|
| 659 | - */ |
|
| 660 | - public function remove_fee( $name ) { |
|
| 661 | - |
|
| 662 | - if ( isset( $this->fees[ $name ] ) ) { |
|
| 663 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 664 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 665 | - unset( $this->fees[ $name ] ); |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - /** |
|
| 671 | - * Returns the fees. |
|
| 672 | - * |
|
| 673 | - * @since 1.0.19 |
|
| 674 | - */ |
|
| 675 | - public function get_fee() { |
|
| 676 | - return $this->totals['fees']['initial']; |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - /** |
|
| 680 | - * Returns the recurring fees. |
|
| 681 | - * |
|
| 682 | - * @since 1.0.19 |
|
| 683 | - */ |
|
| 684 | - public function get_recurring_fee() { |
|
| 685 | - return $this->totals['fees']['recurring']; |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - * Returns all fees. |
|
| 690 | - * |
|
| 691 | - * @since 1.0.19 |
|
| 692 | - */ |
|
| 693 | - public function get_fees() { |
|
| 694 | - return $this->fees; |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - /** |
|
| 698 | - * Checks if there are any fees for the form. |
|
| 699 | - * |
|
| 700 | - * @return bool |
|
| 701 | - * @since 1.0.19 |
|
| 702 | - */ |
|
| 703 | - public function has_fees() { |
|
| 704 | - return count( $this->fees ) !== 0; |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - /* |
|
| 625 | + /** |
|
| 626 | + * Prepares the submission's fees. |
|
| 627 | + * |
|
| 628 | + * @since 1.0.19 |
|
| 629 | + */ |
|
| 630 | + public function process_fees() { |
|
| 631 | + |
|
| 632 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 633 | + |
|
| 634 | + foreach ( $fees_processor->fees as $fee ) { |
|
| 635 | + $this->add_fee( $fee ); |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + /** |
|
| 642 | + * Adds a fee to the submission. |
|
| 643 | + * |
|
| 644 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
| 645 | + * @since 1.0.19 |
|
| 646 | + */ |
|
| 647 | + public function add_fee( $fee ) { |
|
| 648 | + |
|
| 649 | + $this->fees[ $fee['name'] ] = $fee; |
|
| 650 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 651 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 652 | + |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + /** |
|
| 656 | + * Removes a fee from the submission. |
|
| 657 | + * |
|
| 658 | + * @since 1.0.19 |
|
| 659 | + */ |
|
| 660 | + public function remove_fee( $name ) { |
|
| 661 | + |
|
| 662 | + if ( isset( $this->fees[ $name ] ) ) { |
|
| 663 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 664 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 665 | + unset( $this->fees[ $name ] ); |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + /** |
|
| 671 | + * Returns the fees. |
|
| 672 | + * |
|
| 673 | + * @since 1.0.19 |
|
| 674 | + */ |
|
| 675 | + public function get_fee() { |
|
| 676 | + return $this->totals['fees']['initial']; |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + /** |
|
| 680 | + * Returns the recurring fees. |
|
| 681 | + * |
|
| 682 | + * @since 1.0.19 |
|
| 683 | + */ |
|
| 684 | + public function get_recurring_fee() { |
|
| 685 | + return $this->totals['fees']['recurring']; |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + * Returns all fees. |
|
| 690 | + * |
|
| 691 | + * @since 1.0.19 |
|
| 692 | + */ |
|
| 693 | + public function get_fees() { |
|
| 694 | + return $this->fees; |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + /** |
|
| 698 | + * Checks if there are any fees for the form. |
|
| 699 | + * |
|
| 700 | + * @return bool |
|
| 701 | + * @since 1.0.19 |
|
| 702 | + */ |
|
| 703 | + public function has_fees() { |
|
| 704 | + return count( $this->fees ) !== 0; |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + /* |
|
| 708 | 708 | |-------------------------------------------------------------------------- |
| 709 | 709 | | MISC |
| 710 | 710 | |-------------------------------------------------------------------------- |
@@ -712,109 +712,109 @@ discard block |
||
| 712 | 712 | | Extra submission functions. |
| 713 | 713 | */ |
| 714 | 714 | |
| 715 | - /** |
|
| 716 | - * Returns the total amount to collect for this submission. |
|
| 717 | - * |
|
| 718 | - * @since 1.0.19 |
|
| 719 | - */ |
|
| 720 | - public function get_total() { |
|
| 721 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
| 722 | - return max( $total, 0 ); |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - /** |
|
| 726 | - * Returns the recurring total amount to collect for this submission. |
|
| 727 | - * |
|
| 728 | - * @since 1.0.19 |
|
| 729 | - */ |
|
| 730 | - public function get_recurring_total() { |
|
| 731 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
| 732 | - return max( $total, 0 ); |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - /** |
|
| 736 | - * Whether payment details should be collected for this submission. |
|
| 737 | - * |
|
| 738 | - * @since 1.0.19 |
|
| 739 | - */ |
|
| 740 | - public function should_collect_payment_details() { |
|
| 741 | - $initial = $this->get_total(); |
|
| 742 | - $recurring = $this->get_recurring_total(); |
|
| 743 | - |
|
| 744 | - if ( $this->has_recurring == 0 ) { |
|
| 745 | - $recurring = 0; |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - $collect = $initial > 0 || $recurring > 0; |
|
| 749 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - /** |
|
| 753 | - * Returns the billing email of the user. |
|
| 754 | - * |
|
| 755 | - * @since 1.0.19 |
|
| 756 | - */ |
|
| 757 | - public function get_billing_email() { |
|
| 758 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - /** |
|
| 762 | - * Checks if the submitter has a billing email. |
|
| 763 | - * |
|
| 764 | - * @since 1.0.19 |
|
| 765 | - */ |
|
| 766 | - public function has_billing_email() { |
|
| 767 | - $billing_email = $this->get_billing_email(); |
|
| 768 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 769 | - } |
|
| 770 | - |
|
| 771 | - /** |
|
| 772 | - * Returns the appropriate currency for the submission. |
|
| 773 | - * |
|
| 774 | - * @since 1.0.19 |
|
| 775 | - * @return string |
|
| 776 | - */ |
|
| 777 | - public function get_currency() { |
|
| 778 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
| 779 | - } |
|
| 780 | - |
|
| 781 | - /** |
|
| 782 | - * Returns the raw submission data. |
|
| 783 | - * |
|
| 784 | - * @since 1.0.19 |
|
| 785 | - * @return array |
|
| 786 | - */ |
|
| 787 | - public function get_data() { |
|
| 788 | - return $this->data; |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - /** |
|
| 792 | - * Returns a field from the submission data |
|
| 793 | - * |
|
| 794 | - * @param string $field |
|
| 795 | - * @since 1.0.19 |
|
| 796 | - * @return mixed |
|
| 797 | - */ |
|
| 798 | - public function get_field( $field ) { |
|
| 799 | - return isset( $this->data[ $field ] ) ? $this->data[ $field ] : ''; |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - /** |
|
| 803 | - * Checks if a required field is set. |
|
| 804 | - * |
|
| 805 | - * @since 1.0.19 |
|
| 806 | - */ |
|
| 807 | - public function is_required_field_set( $field ) { |
|
| 808 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - /** |
|
| 812 | - * Formats an amount |
|
| 813 | - * |
|
| 814 | - * @since 1.0.19 |
|
| 815 | - */ |
|
| 816 | - public function format_amount( $amount ) { |
|
| 817 | - return wpinv_price( $amount, $this->get_currency() ); |
|
| 818 | - } |
|
| 715 | + /** |
|
| 716 | + * Returns the total amount to collect for this submission. |
|
| 717 | + * |
|
| 718 | + * @since 1.0.19 |
|
| 719 | + */ |
|
| 720 | + public function get_total() { |
|
| 721 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
| 722 | + return max( $total, 0 ); |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + /** |
|
| 726 | + * Returns the recurring total amount to collect for this submission. |
|
| 727 | + * |
|
| 728 | + * @since 1.0.19 |
|
| 729 | + */ |
|
| 730 | + public function get_recurring_total() { |
|
| 731 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
| 732 | + return max( $total, 0 ); |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + /** |
|
| 736 | + * Whether payment details should be collected for this submission. |
|
| 737 | + * |
|
| 738 | + * @since 1.0.19 |
|
| 739 | + */ |
|
| 740 | + public function should_collect_payment_details() { |
|
| 741 | + $initial = $this->get_total(); |
|
| 742 | + $recurring = $this->get_recurring_total(); |
|
| 743 | + |
|
| 744 | + if ( $this->has_recurring == 0 ) { |
|
| 745 | + $recurring = 0; |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + $collect = $initial > 0 || $recurring > 0; |
|
| 749 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 750 | + } |
|
| 751 | + |
|
| 752 | + /** |
|
| 753 | + * Returns the billing email of the user. |
|
| 754 | + * |
|
| 755 | + * @since 1.0.19 |
|
| 756 | + */ |
|
| 757 | + public function get_billing_email() { |
|
| 758 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + /** |
|
| 762 | + * Checks if the submitter has a billing email. |
|
| 763 | + * |
|
| 764 | + * @since 1.0.19 |
|
| 765 | + */ |
|
| 766 | + public function has_billing_email() { |
|
| 767 | + $billing_email = $this->get_billing_email(); |
|
| 768 | + return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 769 | + } |
|
| 770 | + |
|
| 771 | + /** |
|
| 772 | + * Returns the appropriate currency for the submission. |
|
| 773 | + * |
|
| 774 | + * @since 1.0.19 |
|
| 775 | + * @return string |
|
| 776 | + */ |
|
| 777 | + public function get_currency() { |
|
| 778 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
| 779 | + } |
|
| 780 | + |
|
| 781 | + /** |
|
| 782 | + * Returns the raw submission data. |
|
| 783 | + * |
|
| 784 | + * @since 1.0.19 |
|
| 785 | + * @return array |
|
| 786 | + */ |
|
| 787 | + public function get_data() { |
|
| 788 | + return $this->data; |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + /** |
|
| 792 | + * Returns a field from the submission data |
|
| 793 | + * |
|
| 794 | + * @param string $field |
|
| 795 | + * @since 1.0.19 |
|
| 796 | + * @return mixed |
|
| 797 | + */ |
|
| 798 | + public function get_field( $field ) { |
|
| 799 | + return isset( $this->data[ $field ] ) ? $this->data[ $field ] : ''; |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + /** |
|
| 803 | + * Checks if a required field is set. |
|
| 804 | + * |
|
| 805 | + * @since 1.0.19 |
|
| 806 | + */ |
|
| 807 | + public function is_required_field_set( $field ) { |
|
| 808 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + /** |
|
| 812 | + * Formats an amount |
|
| 813 | + * |
|
| 814 | + * @since 1.0.19 |
|
| 815 | + */ |
|
| 816 | + public function format_amount( $amount ) { |
|
| 817 | + return wpinv_price( $amount, $this->get_currency() ); |
|
| 818 | + } |
|
| 819 | 819 | |
| 820 | 820 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -134,8 +134,8 @@ discard block |
||
| 134 | 134 | $this->state = wpinv_get_default_state(); |
| 135 | 135 | |
| 136 | 136 | // Do we have an actual submission? |
| 137 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
| 138 | - $this->load_data( $_POST ); |
|
| 137 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
| 138 | + $this->load_data($_POST); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | } |
@@ -145,19 +145,19 @@ discard block |
||
| 145 | 145 | * |
| 146 | 146 | * @param array $data |
| 147 | 147 | */ |
| 148 | - public function load_data( $data ) { |
|
| 148 | + public function load_data($data) { |
|
| 149 | 149 | |
| 150 | 150 | // Remove slashes from the submitted data... |
| 151 | - $data = wp_unslash( $data ); |
|
| 151 | + $data = wp_unslash($data); |
|
| 152 | 152 | |
| 153 | 153 | // Allow plugins to filter the data. |
| 154 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
| 154 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
| 155 | 155 | |
| 156 | 156 | // Cache it... |
| 157 | 157 | $this->data = $data; |
| 158 | 158 | |
| 159 | 159 | // Then generate a unique id from the data. |
| 160 | - $this->id = md5( wp_json_encode( $data ) ); |
|
| 160 | + $this->id = md5(wp_json_encode($data)); |
|
| 161 | 161 | |
| 162 | 162 | // Finally, process the submission. |
| 163 | 163 | try { |
@@ -167,26 +167,26 @@ discard block |
||
| 167 | 167 | $processors = apply_filters( |
| 168 | 168 | 'getpaid_payment_form_submission_processors', |
| 169 | 169 | array( |
| 170 | - array( $this, 'process_payment_form' ), |
|
| 171 | - array( $this, 'process_invoice' ), |
|
| 172 | - array( $this, 'process_fees' ), |
|
| 173 | - array( $this, 'process_items' ), |
|
| 174 | - array( $this, 'process_taxes' ), |
|
| 175 | - array( $this, 'process_discount' ), |
|
| 170 | + array($this, 'process_payment_form'), |
|
| 171 | + array($this, 'process_invoice'), |
|
| 172 | + array($this, 'process_fees'), |
|
| 173 | + array($this, 'process_items'), |
|
| 174 | + array($this, 'process_taxes'), |
|
| 175 | + array($this, 'process_discount'), |
|
| 176 | 176 | ), |
| 177 | 177 | $this |
| 178 | 178 | ); |
| 179 | 179 | |
| 180 | - foreach ( $processors as $processor ) { |
|
| 181 | - call_user_func_array( $processor, array( &$this ) ); |
|
| 180 | + foreach ($processors as $processor) { |
|
| 181 | + call_user_func_array($processor, array(&$this)); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - } catch ( Exception $e ) { |
|
| 184 | + } catch (Exception $e) { |
|
| 185 | 185 | $this->last_error = $e->getMessage(); |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | // Fired when we are done processing a submission. |
| 189 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
| 189 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
| 190 | 190 | |
| 191 | 191 | } |
| 192 | 192 | |
@@ -207,18 +207,18 @@ discard block |
||
| 207 | 207 | public function process_payment_form() { |
| 208 | 208 | |
| 209 | 209 | // Every submission needs an active payment form. |
| 210 | - if ( empty( $this->data['form_id'] ) ) { |
|
| 211 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
| 210 | + if (empty($this->data['form_id'])) { |
|
| 211 | + throw new Exception(__('Missing payment form', 'invoicing')); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | // Fetch the payment form. |
| 215 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
| 215 | + $this->payment_form = new GetPaid_Payment_Form($this->data['form_id']); |
|
| 216 | 216 | |
| 217 | - if ( ! $this->payment_form->is_active() ) { |
|
| 218 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
| 217 | + if (!$this->payment_form->is_active()) { |
|
| 218 | + throw new Exception(__('Payment form not active', 'invoicing')); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
| 221 | + do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this)); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | /** |
@@ -248,30 +248,30 @@ discard block |
||
| 248 | 248 | public function process_invoice() { |
| 249 | 249 | |
| 250 | 250 | // Abort if there is no invoice. |
| 251 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
| 251 | + if (empty($this->data['invoice_id'])) { |
|
| 252 | 252 | return; |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | // If the submission is for an existing invoice, ensure that it exists |
| 256 | 256 | // and that it is not paid for. |
| 257 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
| 257 | + $invoice = wpinv_get_invoice($this->data['invoice_id']); |
|
| 258 | 258 | |
| 259 | - if ( empty( $invoice ) ) { |
|
| 260 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
| 259 | + if (empty($invoice)) { |
|
| 260 | + throw new Exception(__('Invalid invoice', 'invoicing')); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - if ( $invoice->is_paid() ) { |
|
| 264 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
| 263 | + if ($invoice->is_paid()) { |
|
| 264 | + throw new Exception(__('This invoice is already paid for.', 'invoicing')); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
| 267 | + $this->payment_form->set_items($invoice->get_items()); |
|
| 268 | 268 | $this->payment_form->invoice = $invoice; |
| 269 | 269 | |
| 270 | 270 | $this->country = $invoice->get_country(); |
| 271 | 271 | $this->state = $invoice->get_state(); |
| 272 | 272 | $this->invoice = $invoice; |
| 273 | 273 | |
| 274 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
| 274 | + do_action_ref_array('getpaid_submissions_process_invoice', array(&$this)); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | * @return bool |
| 292 | 292 | */ |
| 293 | 293 | public function has_invoice() { |
| 294 | - return ! empty( $this->invoice ); |
|
| 294 | + return !empty($this->invoice); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | /* |
@@ -310,13 +310,13 @@ discard block |
||
| 310 | 310 | */ |
| 311 | 311 | public function process_items() { |
| 312 | 312 | |
| 313 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
| 313 | + $processor = new GetPaid_Payment_Form_Submission_Items($this); |
|
| 314 | 314 | |
| 315 | - foreach ( $processor->items as $item ) { |
|
| 316 | - $this->add_item( $item ); |
|
| 315 | + foreach ($processor->items as $item) { |
|
| 316 | + $this->add_item($item); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
| 319 | + do_action_ref_array('getpaid_submissions_process_items', array(&$this)); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | /** |
@@ -325,18 +325,18 @@ discard block |
||
| 325 | 325 | * @since 1.0.19 |
| 326 | 326 | * @param GetPaid_Form_Item $item |
| 327 | 327 | */ |
| 328 | - public function add_item( $item ) { |
|
| 328 | + public function add_item($item) { |
|
| 329 | 329 | |
| 330 | 330 | // Make sure that it is available for purchase. |
| 331 | - if ( ! $item->can_purchase() ) { |
|
| 331 | + if (!$item->can_purchase()) { |
|
| 332 | 332 | return; |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | // Each submission can only contain one recurring item. |
| 336 | - if ( $item->is_recurring() ) { |
|
| 336 | + if ($item->is_recurring()) { |
|
| 337 | 337 | |
| 338 | - if ( $this->has_recurring != 0 ) { |
|
| 339 | - throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) ); |
|
| 338 | + if ($this->has_recurring != 0) { |
|
| 339 | + throw new Exception(__('You can only buy one recurring item at a time.', 'invoicing')); |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | $this->has_recurring = $item->get_id(); |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | // Update the items and totals. |
| 347 | - $this->items[ $item->get_id() ] = $item; |
|
| 347 | + $this->items[$item->get_id()] = $item; |
|
| 348 | 348 | $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
| 349 | 349 | $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
| 350 | 350 | |
@@ -358,17 +358,17 @@ discard block |
||
| 358 | 358 | * |
| 359 | 359 | * @since 1.0.19 |
| 360 | 360 | */ |
| 361 | - public function remove_item( $item_id ) { |
|
| 361 | + public function remove_item($item_id) { |
|
| 362 | 362 | |
| 363 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
| 364 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
| 365 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
| 363 | + if (isset($this->items[$item_id])) { |
|
| 364 | + $this->totals['subtotal']['initial'] -= $this->items[$item_id]->get_sub_total(); |
|
| 365 | + $this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total(); |
|
| 366 | 366 | |
| 367 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
| 367 | + if ($this->items[$item_id]->is_recurring()) { |
|
| 368 | 368 | $this->has_recurring = 0; |
| 369 | 369 | } |
| 370 | 370 | |
| 371 | - unset( $this->items[ $item_id ] ); |
|
| 371 | + unset($this->items[$item_id]); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | } |
@@ -418,26 +418,26 @@ discard block |
||
| 418 | 418 | public function process_taxes() { |
| 419 | 419 | |
| 420 | 420 | // Abort if we're not using taxes. |
| 421 | - if ( ! $this->use_taxes() ) { |
|
| 421 | + if (!$this->use_taxes()) { |
|
| 422 | 422 | return; |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | // If a custom country && state has been passed in, use it to calculate taxes. |
| 426 | - if ( ! empty( $this->data['wpinv_country'] ) ) { |
|
| 426 | + if (!empty($this->data['wpinv_country'])) { |
|
| 427 | 427 | $this->country = $this->data['wpinv_country']; |
| 428 | 428 | } |
| 429 | 429 | |
| 430 | - if ( ! empty( $this->data['wpinv_state'] ) ) { |
|
| 430 | + if (!empty($this->data['wpinv_state'])) { |
|
| 431 | 431 | $this->country = $this->data['wpinv_state']; |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
| 434 | + $processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
| 435 | 435 | |
| 436 | - foreach ( $processor->taxes as $tax ) { |
|
| 437 | - $this->add_tax( $tax ); |
|
| 436 | + foreach ($processor->taxes as $tax) { |
|
| 437 | + $this->add_tax($tax); |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
| 440 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | /** |
@@ -446,10 +446,10 @@ discard block |
||
| 446 | 446 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
| 447 | 447 | * @since 1.0.19 |
| 448 | 448 | */ |
| 449 | - public function add_tax( $tax ) { |
|
| 450 | - $this->taxes[ $tax['name'] ] = $tax; |
|
| 451 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
| 452 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
| 449 | + public function add_tax($tax) { |
|
| 450 | + $this->taxes[$tax['name']] = $tax; |
|
| 451 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount($tax['initial_tax']); |
|
| 452 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']); |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | /** |
@@ -457,12 +457,12 @@ discard block |
||
| 457 | 457 | * |
| 458 | 458 | * @since 1.0.19 |
| 459 | 459 | */ |
| 460 | - public function remove_tax( $tax_name ) { |
|
| 460 | + public function remove_tax($tax_name) { |
|
| 461 | 461 | |
| 462 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
| 463 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
| 464 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
| 465 | - unset( $this->taxes[ $tax_name ] ); |
|
| 462 | + if (isset($this->taxes[$tax_name])) { |
|
| 463 | + $this->totals['taxes']['initial'] -= $this->taxes[$tax_name]['initial_tax']; |
|
| 464 | + $this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax']; |
|
| 465 | + unset($this->taxes[$tax_name]); |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | } |
@@ -476,11 +476,11 @@ discard block |
||
| 476 | 476 | |
| 477 | 477 | $use_taxes = wpinv_use_taxes(); |
| 478 | 478 | |
| 479 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
| 479 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
| 480 | 480 | $use_taxes = false; |
| 481 | 481 | } |
| 482 | 482 | |
| 483 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
| 483 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
| 484 | 484 | |
| 485 | 485 | } |
| 486 | 486 | |
@@ -529,13 +529,13 @@ discard block |
||
| 529 | 529 | |
| 530 | 530 | $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
| 531 | 531 | $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
| 532 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
| 532 | + $processor = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total); |
|
| 533 | 533 | |
| 534 | - foreach ( $processor->discounts as $discount ) { |
|
| 535 | - $this->add_discount( $discount ); |
|
| 534 | + foreach ($processor->discounts as $discount) { |
|
| 535 | + $this->add_discount($discount); |
|
| 536 | 536 | } |
| 537 | 537 | |
| 538 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
| 538 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | /** |
@@ -544,10 +544,10 @@ discard block |
||
| 544 | 544 | * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code. |
| 545 | 545 | * @since 1.0.19 |
| 546 | 546 | */ |
| 547 | - public function add_discount( $discount ) { |
|
| 548 | - $this->discounts[ $discount['name'] ] = $discount; |
|
| 549 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
| 550 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
| 547 | + public function add_discount($discount) { |
|
| 548 | + $this->discounts[$discount['name']] = $discount; |
|
| 549 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount($discount['initial_discount']); |
|
| 550 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']); |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | /** |
@@ -555,12 +555,12 @@ discard block |
||
| 555 | 555 | * |
| 556 | 556 | * @since 1.0.19 |
| 557 | 557 | */ |
| 558 | - public function remove_discount( $name ) { |
|
| 558 | + public function remove_discount($name) { |
|
| 559 | 559 | |
| 560 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
| 561 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
| 562 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
| 563 | - unset( $this->discounts[ $name ] ); |
|
| 560 | + if (isset($this->discounts[$name])) { |
|
| 561 | + $this->totals['discount']['initial'] -= $this->discounts[$name]['initial_discount']; |
|
| 562 | + $this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount']; |
|
| 563 | + unset($this->discounts[$name]); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | } |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | * @return bool |
| 573 | 573 | */ |
| 574 | 574 | public function has_discount_code() { |
| 575 | - return ! empty( $this->discounts['discount_code'] ); |
|
| 575 | + return !empty($this->discounts['discount_code']); |
|
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | /** |
@@ -629,13 +629,13 @@ discard block |
||
| 629 | 629 | */ |
| 630 | 630 | public function process_fees() { |
| 631 | 631 | |
| 632 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
| 632 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
| 633 | 633 | |
| 634 | - foreach ( $fees_processor->fees as $fee ) { |
|
| 635 | - $this->add_fee( $fee ); |
|
| 634 | + foreach ($fees_processor->fees as $fee) { |
|
| 635 | + $this->add_fee($fee); |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
| 638 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | /** |
@@ -644,11 +644,11 @@ discard block |
||
| 644 | 644 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
| 645 | 645 | * @since 1.0.19 |
| 646 | 646 | */ |
| 647 | - public function add_fee( $fee ) { |
|
| 647 | + public function add_fee($fee) { |
|
| 648 | 648 | |
| 649 | - $this->fees[ $fee['name'] ] = $fee; |
|
| 650 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
| 651 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
| 649 | + $this->fees[$fee['name']] = $fee; |
|
| 650 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
| 651 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
| 652 | 652 | |
| 653 | 653 | } |
| 654 | 654 | |
@@ -657,12 +657,12 @@ discard block |
||
| 657 | 657 | * |
| 658 | 658 | * @since 1.0.19 |
| 659 | 659 | */ |
| 660 | - public function remove_fee( $name ) { |
|
| 660 | + public function remove_fee($name) { |
|
| 661 | 661 | |
| 662 | - if ( isset( $this->fees[ $name ] ) ) { |
|
| 663 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
| 664 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
| 665 | - unset( $this->fees[ $name ] ); |
|
| 662 | + if (isset($this->fees[$name])) { |
|
| 663 | + $this->totals['fees']['initial'] -= $this->fees[$name]['initial_fee']; |
|
| 664 | + $this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee']; |
|
| 665 | + unset($this->fees[$name]); |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | } |
@@ -701,7 +701,7 @@ discard block |
||
| 701 | 701 | * @since 1.0.19 |
| 702 | 702 | */ |
| 703 | 703 | public function has_fees() { |
| 704 | - return count( $this->fees ) !== 0; |
|
| 704 | + return count($this->fees) !== 0; |
|
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | /* |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | */ |
| 720 | 720 | public function get_total() { |
| 721 | 721 | $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
| 722 | - return max( $total, 0 ); |
|
| 722 | + return max($total, 0); |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | /** |
@@ -729,7 +729,7 @@ discard block |
||
| 729 | 729 | */ |
| 730 | 730 | public function get_recurring_total() { |
| 731 | 731 | $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
| 732 | - return max( $total, 0 ); |
|
| 732 | + return max($total, 0); |
|
| 733 | 733 | } |
| 734 | 734 | |
| 735 | 735 | /** |
@@ -741,12 +741,12 @@ discard block |
||
| 741 | 741 | $initial = $this->get_total(); |
| 742 | 742 | $recurring = $this->get_recurring_total(); |
| 743 | 743 | |
| 744 | - if ( $this->has_recurring == 0 ) { |
|
| 744 | + if ($this->has_recurring == 0) { |
|
| 745 | 745 | $recurring = 0; |
| 746 | 746 | } |
| 747 | 747 | |
| 748 | 748 | $collect = $initial > 0 || $recurring > 0; |
| 749 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
| 749 | + return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this); |
|
| 750 | 750 | } |
| 751 | 751 | |
| 752 | 752 | /** |
@@ -755,7 +755,7 @@ discard block |
||
| 755 | 755 | * @since 1.0.19 |
| 756 | 756 | */ |
| 757 | 757 | public function get_billing_email() { |
| 758 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
| 758 | + return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this); |
|
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | /** |
@@ -765,7 +765,7 @@ discard block |
||
| 765 | 765 | */ |
| 766 | 766 | public function has_billing_email() { |
| 767 | 767 | $billing_email = $this->get_billing_email(); |
| 768 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
| 768 | + return !empty($billing_email) && is_email($billing_email); |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | /** |
@@ -795,8 +795,8 @@ discard block |
||
| 795 | 795 | * @since 1.0.19 |
| 796 | 796 | * @return mixed |
| 797 | 797 | */ |
| 798 | - public function get_field( $field ) { |
|
| 799 | - return isset( $this->data[ $field ] ) ? $this->data[ $field ] : ''; |
|
| 798 | + public function get_field($field) { |
|
| 799 | + return isset($this->data[$field]) ? $this->data[$field] : ''; |
|
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | /** |
@@ -804,8 +804,8 @@ discard block |
||
| 804 | 804 | * |
| 805 | 805 | * @since 1.0.19 |
| 806 | 806 | */ |
| 807 | - public function is_required_field_set( $field ) { |
|
| 808 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
| 807 | + public function is_required_field_set($field) { |
|
| 808 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
| 809 | 809 | } |
| 810 | 810 | |
| 811 | 811 | /** |
@@ -813,8 +813,8 @@ discard block |
||
| 813 | 813 | * |
| 814 | 814 | * @since 1.0.19 |
| 815 | 815 | */ |
| 816 | - public function format_amount( $amount ) { |
|
| 817 | - return wpinv_price( $amount, $this->get_currency() ); |
|
| 816 | + public function format_amount($amount) { |
|
| 817 | + return wpinv_price($amount, $this->get_currency()); |
|
| 818 | 818 | } |
| 819 | 819 | |
| 820 | 820 | } |
@@ -1,262 +1,262 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | - exit; |
|
| 3 | + exit; |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | if ( ! class_exists( 'WP_Super_Duper' ) ) { |
| 7 | 7 | |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * A Class to be able to create a Widget, Shortcode or Block to be able to output content for WordPress. |
|
| 11 | - * |
|
| 12 | - * Should not be called direct but extended instead. |
|
| 13 | - * |
|
| 14 | - * Class WP_Super_Duper |
|
| 15 | - * @since 1.0.16 change log moved to file change-log.txt - CHANGED |
|
| 16 | - * @ver 1.0.19 |
|
| 17 | - */ |
|
| 18 | - class WP_Super_Duper extends WP_Widget { |
|
| 19 | - |
|
| 20 | - public $version = "1.0.22"; |
|
| 21 | - public $font_awesome_icon_version = "5.11.2"; |
|
| 22 | - public $block_code; |
|
| 23 | - public $options; |
|
| 24 | - public $base_id; |
|
| 25 | - public $settings_hash; |
|
| 26 | - public $arguments = array(); |
|
| 27 | - public $instance = array(); |
|
| 28 | - private $class_name; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * The relative url to the current folder. |
|
| 32 | - * |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 35 | - public $url = ''; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Take the array options and use them to build. |
|
| 39 | - */ |
|
| 40 | - public function __construct( $options ) { |
|
| 41 | - global $sd_widgets; |
|
| 42 | - |
|
| 43 | - $sd_widgets[ $options['base_id'] ] = array( |
|
| 44 | - 'name' => $options['name'], |
|
| 45 | - 'class_name' => $options['class_name'] |
|
| 46 | - ); |
|
| 47 | - $this->base_id = $options['base_id']; |
|
| 48 | - // lets filter the options before we do anything |
|
| 49 | - $options = apply_filters( "wp_super_duper_options", $options ); |
|
| 50 | - $options = apply_filters( "wp_super_duper_options_{$this->base_id}", $options ); |
|
| 51 | - $options = $this->add_name_from_key( $options ); |
|
| 52 | - $this->options = $options; |
|
| 53 | - |
|
| 54 | - $this->base_id = $options['base_id']; |
|
| 55 | - $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array(); |
|
| 56 | - |
|
| 57 | - // init parent |
|
| 58 | - parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] ); |
|
| 59 | - |
|
| 60 | - if ( isset( $options['class_name'] ) ) { |
|
| 61 | - // register widget |
|
| 62 | - $this->class_name = $options['class_name']; |
|
| 63 | - |
|
| 64 | - // register shortcode |
|
| 65 | - $this->register_shortcode(); |
|
| 66 | - |
|
| 67 | - // Fusion Builder (avada) support |
|
| 68 | - if ( function_exists( 'fusion_builder_map' ) ) { |
|
| 69 | - add_action( 'init', array( $this, 'register_fusion_element' ) ); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - // register block |
|
| 73 | - add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) ); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - // add the CSS and JS we need ONCE |
|
| 77 | - global $sd_widget_scripts; |
|
| 78 | - |
|
| 79 | - if ( ! $sd_widget_scripts ) { |
|
| 80 | - wp_add_inline_script( 'admin-widgets', $this->widget_js() ); |
|
| 81 | - wp_add_inline_script( 'customize-controls', $this->widget_js() ); |
|
| 82 | - wp_add_inline_style( 'widgets', $this->widget_css() ); |
|
| 83 | - |
|
| 84 | - // maybe add elementor editor styles |
|
| 85 | - add_action( 'elementor/editor/after_enqueue_styles', array( $this, 'elementor_editor_styles' ) ); |
|
| 86 | - |
|
| 87 | - $sd_widget_scripts = true; |
|
| 88 | - |
|
| 89 | - // add shortcode insert button once |
|
| 90 | - add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) ); |
|
| 91 | - // generatepress theme sections compatibility |
|
| 92 | - if ( function_exists( 'generate_sections_sections_metabox' ) ) { |
|
| 93 | - add_action( 'generate_sections_metabox', array( $this, 'shortcode_insert_button_script' ) ); |
|
| 94 | - } |
|
| 95 | - if ( $this->is_preview() ) { |
|
| 96 | - add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) ); |
|
| 97 | - // this makes the insert button work for elementor |
|
| 98 | - add_action( 'elementor/editor/after_enqueue_scripts', array( |
|
| 99 | - $this, |
|
| 100 | - 'shortcode_insert_button_script' |
|
| 101 | - ) ); // for elementor |
|
| 102 | - } |
|
| 103 | - // this makes the insert button work for cornerstone |
|
| 104 | - add_action( 'wp_print_footer_scripts', array( __CLASS__, 'maybe_cornerstone_builder' ) ); |
|
| 105 | - |
|
| 106 | - add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) ); |
|
| 107 | - add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) ); |
|
| 108 | - |
|
| 109 | - // add generator text to admin head |
|
| 110 | - add_action( 'admin_head', array( $this, 'generator' ) ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - do_action( 'wp_super_duper_widget_init', $options, $this ); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Add our widget CSS to elementor editor. |
|
| 118 | - */ |
|
| 119 | - public function elementor_editor_styles() { |
|
| 120 | - wp_add_inline_style( 'elementor-editor', $this->widget_css( false ) ); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - public function register_fusion_element() { |
|
| 124 | - |
|
| 125 | - $options = $this->options; |
|
| 126 | - |
|
| 127 | - if ( $this->base_id ) { |
|
| 128 | - |
|
| 129 | - $params = $this->get_fusion_params(); |
|
| 130 | - |
|
| 131 | - $args = array( |
|
| 132 | - 'name' => $options['name'], |
|
| 133 | - 'shortcode' => $this->base_id, |
|
| 134 | - 'icon' => $options['block-icon'] ? $options['block-icon'] : 'far fa-square', |
|
| 135 | - 'allow_generator' => true, |
|
| 136 | - ); |
|
| 137 | - |
|
| 138 | - if ( ! empty( $params ) ) { |
|
| 139 | - $args['params'] = $params; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - fusion_builder_map( $args ); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - public function get_fusion_params() { |
|
| 148 | - $params = array(); |
|
| 149 | - $arguments = $this->get_arguments(); |
|
| 150 | - |
|
| 151 | - if ( ! empty( $arguments ) ) { |
|
| 152 | - foreach ( $arguments as $key => $val ) { |
|
| 153 | - $param = array(); |
|
| 154 | - // type |
|
| 155 | - $param['type'] = str_replace( |
|
| 156 | - array( |
|
| 157 | - "text", |
|
| 158 | - "number", |
|
| 159 | - "email", |
|
| 160 | - "color", |
|
| 161 | - "checkbox" |
|
| 162 | - ), |
|
| 163 | - array( |
|
| 164 | - "textfield", |
|
| 165 | - "textfield", |
|
| 166 | - "textfield", |
|
| 167 | - "colorpicker", |
|
| 168 | - "select", |
|
| 169 | - |
|
| 170 | - ), |
|
| 171 | - $val['type'] ); |
|
| 172 | - |
|
| 173 | - // multiselect |
|
| 174 | - if ( $val['type'] == 'multiselect' || ( ( $param['type'] == 'select' || $val['type'] == 'select' ) && ! empty( $val['multiple'] ) ) ) { |
|
| 175 | - $param['type'] = 'multiple_select'; |
|
| 176 | - $param['multiple'] = true; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - // heading |
|
| 180 | - $param['heading'] = $val['title']; |
|
| 181 | - |
|
| 182 | - // description |
|
| 183 | - $param['description'] = isset( $val['desc'] ) ? $val['desc'] : ''; |
|
| 184 | - |
|
| 185 | - // param_name |
|
| 186 | - $param['param_name'] = $key; |
|
| 187 | - |
|
| 188 | - // Default |
|
| 189 | - $param['default'] = isset( $val['default'] ) ? $val['default'] : ''; |
|
| 190 | - |
|
| 191 | - // Group |
|
| 192 | - if ( isset( $val['group'] ) ) { |
|
| 193 | - $param['group'] = $val['group']; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - // value |
|
| 197 | - if ( $val['type'] == 'checkbox' ) { |
|
| 198 | - if ( isset( $val['default'] ) && $val['default'] == '0' ) { |
|
| 199 | - unset( $param['default'] ); |
|
| 200 | - } |
|
| 201 | - $param['value'] = array( '' => __( "No" ), '1' => __( "Yes" ) ); |
|
| 202 | - } elseif ( $param['type'] == 'select' || $param['type'] == 'multiple_select' ) { |
|
| 203 | - $param['value'] = isset( $val['options'] ) ? $val['options'] : array(); |
|
| 204 | - } else { |
|
| 205 | - $param['value'] = isset( $val['default'] ) ? $val['default'] : ''; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - // setup the param |
|
| 209 | - $params[] = $param; |
|
| 210 | - |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - return $params; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder |
|
| 220 | - */ |
|
| 221 | - public static function maybe_cornerstone_builder() { |
|
| 222 | - if ( did_action( 'cornerstone_before_boot_app' ) ) { |
|
| 223 | - self::shortcode_insert_button_script(); |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * A function to ge the shortcode builder picker html. |
|
| 229 | - * |
|
| 230 | - * @param string $editor_id |
|
| 231 | - * |
|
| 232 | - * @return string |
|
| 233 | - */ |
|
| 234 | - public static function get_picker( $editor_id = '' ) { |
|
| 235 | - |
|
| 236 | - ob_start(); |
|
| 237 | - if ( isset( $_POST['editor_id'] ) ) { |
|
| 238 | - $editor_id = esc_attr( $_POST['editor_id'] ); |
|
| 239 | - } elseif ( isset( $_REQUEST['et_fb'] ) ) { |
|
| 240 | - $editor_id = 'main_content_content_vb_tiny_mce'; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - global $sd_widgets; |
|
| 244 | - ?> |
|
| 9 | + /** |
|
| 10 | + * A Class to be able to create a Widget, Shortcode or Block to be able to output content for WordPress. |
|
| 11 | + * |
|
| 12 | + * Should not be called direct but extended instead. |
|
| 13 | + * |
|
| 14 | + * Class WP_Super_Duper |
|
| 15 | + * @since 1.0.16 change log moved to file change-log.txt - CHANGED |
|
| 16 | + * @ver 1.0.19 |
|
| 17 | + */ |
|
| 18 | + class WP_Super_Duper extends WP_Widget { |
|
| 19 | + |
|
| 20 | + public $version = "1.0.22"; |
|
| 21 | + public $font_awesome_icon_version = "5.11.2"; |
|
| 22 | + public $block_code; |
|
| 23 | + public $options; |
|
| 24 | + public $base_id; |
|
| 25 | + public $settings_hash; |
|
| 26 | + public $arguments = array(); |
|
| 27 | + public $instance = array(); |
|
| 28 | + private $class_name; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * The relative url to the current folder. |
|
| 32 | + * |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | + public $url = ''; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Take the array options and use them to build. |
|
| 39 | + */ |
|
| 40 | + public function __construct( $options ) { |
|
| 41 | + global $sd_widgets; |
|
| 42 | + |
|
| 43 | + $sd_widgets[ $options['base_id'] ] = array( |
|
| 44 | + 'name' => $options['name'], |
|
| 45 | + 'class_name' => $options['class_name'] |
|
| 46 | + ); |
|
| 47 | + $this->base_id = $options['base_id']; |
|
| 48 | + // lets filter the options before we do anything |
|
| 49 | + $options = apply_filters( "wp_super_duper_options", $options ); |
|
| 50 | + $options = apply_filters( "wp_super_duper_options_{$this->base_id}", $options ); |
|
| 51 | + $options = $this->add_name_from_key( $options ); |
|
| 52 | + $this->options = $options; |
|
| 53 | + |
|
| 54 | + $this->base_id = $options['base_id']; |
|
| 55 | + $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array(); |
|
| 56 | + |
|
| 57 | + // init parent |
|
| 58 | + parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] ); |
|
| 59 | + |
|
| 60 | + if ( isset( $options['class_name'] ) ) { |
|
| 61 | + // register widget |
|
| 62 | + $this->class_name = $options['class_name']; |
|
| 63 | + |
|
| 64 | + // register shortcode |
|
| 65 | + $this->register_shortcode(); |
|
| 66 | + |
|
| 67 | + // Fusion Builder (avada) support |
|
| 68 | + if ( function_exists( 'fusion_builder_map' ) ) { |
|
| 69 | + add_action( 'init', array( $this, 'register_fusion_element' ) ); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + // register block |
|
| 73 | + add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) ); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + // add the CSS and JS we need ONCE |
|
| 77 | + global $sd_widget_scripts; |
|
| 78 | + |
|
| 79 | + if ( ! $sd_widget_scripts ) { |
|
| 80 | + wp_add_inline_script( 'admin-widgets', $this->widget_js() ); |
|
| 81 | + wp_add_inline_script( 'customize-controls', $this->widget_js() ); |
|
| 82 | + wp_add_inline_style( 'widgets', $this->widget_css() ); |
|
| 83 | + |
|
| 84 | + // maybe add elementor editor styles |
|
| 85 | + add_action( 'elementor/editor/after_enqueue_styles', array( $this, 'elementor_editor_styles' ) ); |
|
| 86 | + |
|
| 87 | + $sd_widget_scripts = true; |
|
| 88 | + |
|
| 89 | + // add shortcode insert button once |
|
| 90 | + add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) ); |
|
| 91 | + // generatepress theme sections compatibility |
|
| 92 | + if ( function_exists( 'generate_sections_sections_metabox' ) ) { |
|
| 93 | + add_action( 'generate_sections_metabox', array( $this, 'shortcode_insert_button_script' ) ); |
|
| 94 | + } |
|
| 95 | + if ( $this->is_preview() ) { |
|
| 96 | + add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) ); |
|
| 97 | + // this makes the insert button work for elementor |
|
| 98 | + add_action( 'elementor/editor/after_enqueue_scripts', array( |
|
| 99 | + $this, |
|
| 100 | + 'shortcode_insert_button_script' |
|
| 101 | + ) ); // for elementor |
|
| 102 | + } |
|
| 103 | + // this makes the insert button work for cornerstone |
|
| 104 | + add_action( 'wp_print_footer_scripts', array( __CLASS__, 'maybe_cornerstone_builder' ) ); |
|
| 105 | + |
|
| 106 | + add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) ); |
|
| 107 | + add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) ); |
|
| 108 | + |
|
| 109 | + // add generator text to admin head |
|
| 110 | + add_action( 'admin_head', array( $this, 'generator' ) ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + do_action( 'wp_super_duper_widget_init', $options, $this ); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Add our widget CSS to elementor editor. |
|
| 118 | + */ |
|
| 119 | + public function elementor_editor_styles() { |
|
| 120 | + wp_add_inline_style( 'elementor-editor', $this->widget_css( false ) ); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + public function register_fusion_element() { |
|
| 124 | + |
|
| 125 | + $options = $this->options; |
|
| 126 | + |
|
| 127 | + if ( $this->base_id ) { |
|
| 128 | + |
|
| 129 | + $params = $this->get_fusion_params(); |
|
| 130 | + |
|
| 131 | + $args = array( |
|
| 132 | + 'name' => $options['name'], |
|
| 133 | + 'shortcode' => $this->base_id, |
|
| 134 | + 'icon' => $options['block-icon'] ? $options['block-icon'] : 'far fa-square', |
|
| 135 | + 'allow_generator' => true, |
|
| 136 | + ); |
|
| 137 | + |
|
| 138 | + if ( ! empty( $params ) ) { |
|
| 139 | + $args['params'] = $params; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + fusion_builder_map( $args ); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + public function get_fusion_params() { |
|
| 148 | + $params = array(); |
|
| 149 | + $arguments = $this->get_arguments(); |
|
| 150 | + |
|
| 151 | + if ( ! empty( $arguments ) ) { |
|
| 152 | + foreach ( $arguments as $key => $val ) { |
|
| 153 | + $param = array(); |
|
| 154 | + // type |
|
| 155 | + $param['type'] = str_replace( |
|
| 156 | + array( |
|
| 157 | + "text", |
|
| 158 | + "number", |
|
| 159 | + "email", |
|
| 160 | + "color", |
|
| 161 | + "checkbox" |
|
| 162 | + ), |
|
| 163 | + array( |
|
| 164 | + "textfield", |
|
| 165 | + "textfield", |
|
| 166 | + "textfield", |
|
| 167 | + "colorpicker", |
|
| 168 | + "select", |
|
| 169 | + |
|
| 170 | + ), |
|
| 171 | + $val['type'] ); |
|
| 172 | + |
|
| 173 | + // multiselect |
|
| 174 | + if ( $val['type'] == 'multiselect' || ( ( $param['type'] == 'select' || $val['type'] == 'select' ) && ! empty( $val['multiple'] ) ) ) { |
|
| 175 | + $param['type'] = 'multiple_select'; |
|
| 176 | + $param['multiple'] = true; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + // heading |
|
| 180 | + $param['heading'] = $val['title']; |
|
| 181 | + |
|
| 182 | + // description |
|
| 183 | + $param['description'] = isset( $val['desc'] ) ? $val['desc'] : ''; |
|
| 184 | + |
|
| 185 | + // param_name |
|
| 186 | + $param['param_name'] = $key; |
|
| 187 | + |
|
| 188 | + // Default |
|
| 189 | + $param['default'] = isset( $val['default'] ) ? $val['default'] : ''; |
|
| 190 | + |
|
| 191 | + // Group |
|
| 192 | + if ( isset( $val['group'] ) ) { |
|
| 193 | + $param['group'] = $val['group']; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + // value |
|
| 197 | + if ( $val['type'] == 'checkbox' ) { |
|
| 198 | + if ( isset( $val['default'] ) && $val['default'] == '0' ) { |
|
| 199 | + unset( $param['default'] ); |
|
| 200 | + } |
|
| 201 | + $param['value'] = array( '' => __( "No" ), '1' => __( "Yes" ) ); |
|
| 202 | + } elseif ( $param['type'] == 'select' || $param['type'] == 'multiple_select' ) { |
|
| 203 | + $param['value'] = isset( $val['options'] ) ? $val['options'] : array(); |
|
| 204 | + } else { |
|
| 205 | + $param['value'] = isset( $val['default'] ) ? $val['default'] : ''; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + // setup the param |
|
| 209 | + $params[] = $param; |
|
| 210 | + |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + return $params; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder |
|
| 220 | + */ |
|
| 221 | + public static function maybe_cornerstone_builder() { |
|
| 222 | + if ( did_action( 'cornerstone_before_boot_app' ) ) { |
|
| 223 | + self::shortcode_insert_button_script(); |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * A function to ge the shortcode builder picker html. |
|
| 229 | + * |
|
| 230 | + * @param string $editor_id |
|
| 231 | + * |
|
| 232 | + * @return string |
|
| 233 | + */ |
|
| 234 | + public static function get_picker( $editor_id = '' ) { |
|
| 235 | + |
|
| 236 | + ob_start(); |
|
| 237 | + if ( isset( $_POST['editor_id'] ) ) { |
|
| 238 | + $editor_id = esc_attr( $_POST['editor_id'] ); |
|
| 239 | + } elseif ( isset( $_REQUEST['et_fb'] ) ) { |
|
| 240 | + $editor_id = 'main_content_content_vb_tiny_mce'; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + global $sd_widgets; |
|
| 244 | + ?> |
|
| 245 | 245 | |
| 246 | 246 | <div class="sd-shortcode-left-wrap"> |
| 247 | 247 | <?php |
| 248 | - ksort( $sd_widgets ); |
|
| 249 | - // print_r($sd_widgets);exit; |
|
| 250 | - if ( ! empty( $sd_widgets ) ) { |
|
| 251 | - echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">'; |
|
| 252 | - echo "<option>" . __( 'Select shortcode' ) . "</option>"; |
|
| 253 | - foreach ( $sd_widgets as $shortcode => $class ) { |
|
| 254 | - echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>"; |
|
| 255 | - } |
|
| 256 | - echo "</select>"; |
|
| 257 | - |
|
| 258 | - } |
|
| 259 | - ?> |
|
| 248 | + ksort( $sd_widgets ); |
|
| 249 | + // print_r($sd_widgets);exit; |
|
| 250 | + if ( ! empty( $sd_widgets ) ) { |
|
| 251 | + echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">'; |
|
| 252 | + echo "<option>" . __( 'Select shortcode' ) . "</option>"; |
|
| 253 | + foreach ( $sd_widgets as $shortcode => $class ) { |
|
| 254 | + echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>"; |
|
| 255 | + } |
|
| 256 | + echo "</select>"; |
|
| 257 | + |
|
| 258 | + } |
|
| 259 | + ?> |
|
| 260 | 260 | <div class="sd-shortcode-settings"></div> |
| 261 | 261 | |
| 262 | 262 | </div> |
@@ -267,8 +267,8 @@ discard block |
||
| 267 | 267 | <?php if ( $editor_id != '' ) { ?> |
| 268 | 268 | <button class="button sd-insert-shortcode-button" |
| 269 | 269 | onclick="sd_insert_shortcode(<?php if ( ! empty( $editor_id ) ) { |
| 270 | - echo "'" . $editor_id . "'"; |
|
| 271 | - } ?>)"><?php _e( 'Insert shortcode' ); ?></button> |
|
| 270 | + echo "'" . $editor_id . "'"; |
|
| 271 | + } ?>)"><?php _e( 'Insert shortcode' ); ?></button> |
|
| 272 | 272 | <?php } ?> |
| 273 | 273 | <button class="button" |
| 274 | 274 | onclick="sd_copy_to_clipboard()"><?php _e( 'Copy shortcode' ); ?></button> |
@@ -276,134 +276,134 @@ discard block |
||
| 276 | 276 | </div> |
| 277 | 277 | <?php |
| 278 | 278 | |
| 279 | - $html = ob_get_clean(); |
|
| 280 | - |
|
| 281 | - if ( wp_doing_ajax() ) { |
|
| 282 | - echo $html; |
|
| 283 | - $should_die = true; |
|
| 284 | - |
|
| 285 | - // some builder get the editor via ajax so we should not die on those ocasions |
|
| 286 | - $dont_die = array( |
|
| 287 | - 'parent_tag',// WP Bakery |
|
| 288 | - 'avia_request' // enfold |
|
| 289 | - ); |
|
| 290 | - |
|
| 291 | - foreach ( $dont_die as $request ) { |
|
| 292 | - if ( isset( $_REQUEST[ $request ] ) ) { |
|
| 293 | - $should_die = false; |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - if ( $should_die ) { |
|
| 298 | - wp_die(); |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - } else { |
|
| 302 | - return $html; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - return ''; |
|
| 306 | - |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * Output the version in the admin header. |
|
| 311 | - */ |
|
| 312 | - public function generator() { |
|
| 313 | - echo '<meta name="generator" content="WP Super Duper v' . $this->version . '" />'; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * Get widget settings. |
|
| 318 | - * |
|
| 319 | - * @since 1.0.0 |
|
| 320 | - */ |
|
| 321 | - public static function get_widget_settings() { |
|
| 322 | - global $sd_widgets; |
|
| 323 | - |
|
| 324 | - $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : ''; |
|
| 325 | - if ( ! $shortcode ) { |
|
| 326 | - wp_die(); |
|
| 327 | - } |
|
| 328 | - $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : ''; |
|
| 329 | - if ( ! $widget_args ) { |
|
| 330 | - wp_die(); |
|
| 331 | - } |
|
| 332 | - $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
| 333 | - if ( ! $class_name ) { |
|
| 334 | - wp_die(); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - // invoke an instance method |
|
| 338 | - $widget = new $class_name; |
|
| 339 | - |
|
| 340 | - ob_start(); |
|
| 341 | - $widget->form( array() ); |
|
| 342 | - $form = ob_get_clean(); |
|
| 343 | - echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>"; |
|
| 344 | - echo "<style>" . $widget->widget_css() . "</style>"; |
|
| 345 | - echo "<script>" . $widget->widget_js() . "</script>"; |
|
| 346 | - ?> |
|
| 279 | + $html = ob_get_clean(); |
|
| 280 | + |
|
| 281 | + if ( wp_doing_ajax() ) { |
|
| 282 | + echo $html; |
|
| 283 | + $should_die = true; |
|
| 284 | + |
|
| 285 | + // some builder get the editor via ajax so we should not die on those ocasions |
|
| 286 | + $dont_die = array( |
|
| 287 | + 'parent_tag',// WP Bakery |
|
| 288 | + 'avia_request' // enfold |
|
| 289 | + ); |
|
| 290 | + |
|
| 291 | + foreach ( $dont_die as $request ) { |
|
| 292 | + if ( isset( $_REQUEST[ $request ] ) ) { |
|
| 293 | + $should_die = false; |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + if ( $should_die ) { |
|
| 298 | + wp_die(); |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + } else { |
|
| 302 | + return $html; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + return ''; |
|
| 306 | + |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * Output the version in the admin header. |
|
| 311 | + */ |
|
| 312 | + public function generator() { |
|
| 313 | + echo '<meta name="generator" content="WP Super Duper v' . $this->version . '" />'; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * Get widget settings. |
|
| 318 | + * |
|
| 319 | + * @since 1.0.0 |
|
| 320 | + */ |
|
| 321 | + public static function get_widget_settings() { |
|
| 322 | + global $sd_widgets; |
|
| 323 | + |
|
| 324 | + $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : ''; |
|
| 325 | + if ( ! $shortcode ) { |
|
| 326 | + wp_die(); |
|
| 327 | + } |
|
| 328 | + $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : ''; |
|
| 329 | + if ( ! $widget_args ) { |
|
| 330 | + wp_die(); |
|
| 331 | + } |
|
| 332 | + $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
| 333 | + if ( ! $class_name ) { |
|
| 334 | + wp_die(); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + // invoke an instance method |
|
| 338 | + $widget = new $class_name; |
|
| 339 | + |
|
| 340 | + ob_start(); |
|
| 341 | + $widget->form( array() ); |
|
| 342 | + $form = ob_get_clean(); |
|
| 343 | + echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>"; |
|
| 344 | + echo "<style>" . $widget->widget_css() . "</style>"; |
|
| 345 | + echo "<script>" . $widget->widget_js() . "</script>"; |
|
| 346 | + ?> |
|
| 347 | 347 | <?php |
| 348 | - wp_die(); |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * Insert shortcode builder button to classic editor (not inside Gutenberg, not needed). |
|
| 353 | - * |
|
| 354 | - * @since 1.0.0 |
|
| 355 | - * |
|
| 356 | - * @param string $editor_id Optional. Shortcode editor id. Default null. |
|
| 357 | - * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null. |
|
| 358 | - */ |
|
| 359 | - public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) { |
|
| 360 | - global $sd_widgets, $shortcode_insert_button_once; |
|
| 361 | - if ( $shortcode_insert_button_once ) { |
|
| 362 | - return; |
|
| 363 | - } |
|
| 364 | - add_thickbox(); |
|
| 365 | - |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * Cornerstone makes us play dirty tricks :/ |
|
| 369 | - * All media_buttons are removed via JS unless they are two specific id's so we wrap our content in this ID so it is not removed. |
|
| 370 | - */ |
|
| 371 | - if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
| 372 | - echo '<span id="insert-media-button">'; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - echo self::shortcode_button( 'this', 'true' ); |
|
| 376 | - |
|
| 377 | - // see opening note |
|
| 378 | - if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
| 379 | - echo '</span>'; // end #insert-media-button |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - // Add separate script for generatepress theme sections |
|
| 383 | - if ( function_exists( 'generate_sections_sections_metabox' ) && did_action( 'generate_sections_metabox' ) ) { |
|
| 384 | - } else { |
|
| 385 | - self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function ); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - $shortcode_insert_button_once = true; |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * Gets the shortcode insert button html. |
|
| 393 | - * |
|
| 394 | - * @param string $id |
|
| 395 | - * @param string $search_for_id |
|
| 396 | - * |
|
| 397 | - * @return mixed |
|
| 398 | - */ |
|
| 399 | - public static function shortcode_button( $id = '', $search_for_id = '' ) { |
|
| 400 | - ob_start(); |
|
| 401 | - ?> |
|
| 348 | + wp_die(); |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * Insert shortcode builder button to classic editor (not inside Gutenberg, not needed). |
|
| 353 | + * |
|
| 354 | + * @since 1.0.0 |
|
| 355 | + * |
|
| 356 | + * @param string $editor_id Optional. Shortcode editor id. Default null. |
|
| 357 | + * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null. |
|
| 358 | + */ |
|
| 359 | + public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) { |
|
| 360 | + global $sd_widgets, $shortcode_insert_button_once; |
|
| 361 | + if ( $shortcode_insert_button_once ) { |
|
| 362 | + return; |
|
| 363 | + } |
|
| 364 | + add_thickbox(); |
|
| 365 | + |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * Cornerstone makes us play dirty tricks :/ |
|
| 369 | + * All media_buttons are removed via JS unless they are two specific id's so we wrap our content in this ID so it is not removed. |
|
| 370 | + */ |
|
| 371 | + if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
| 372 | + echo '<span id="insert-media-button">'; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + echo self::shortcode_button( 'this', 'true' ); |
|
| 376 | + |
|
| 377 | + // see opening note |
|
| 378 | + if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
| 379 | + echo '</span>'; // end #insert-media-button |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + // Add separate script for generatepress theme sections |
|
| 383 | + if ( function_exists( 'generate_sections_sections_metabox' ) && did_action( 'generate_sections_metabox' ) ) { |
|
| 384 | + } else { |
|
| 385 | + self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function ); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + $shortcode_insert_button_once = true; |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * Gets the shortcode insert button html. |
|
| 393 | + * |
|
| 394 | + * @param string $id |
|
| 395 | + * @param string $search_for_id |
|
| 396 | + * |
|
| 397 | + * @return mixed |
|
| 398 | + */ |
|
| 399 | + public static function shortcode_button( $id = '', $search_for_id = '' ) { |
|
| 400 | + ob_start(); |
|
| 401 | + ?> |
|
| 402 | 402 | <span class="sd-lable-shortcode-inserter"> |
| 403 | 403 | <a onclick="sd_ajax_get_picker(<?php echo $id; |
| 404 | - if ( $search_for_id ) { |
|
| 405 | - echo "," . $search_for_id; |
|
| 406 | - } ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed" |
|
| 404 | + if ( $search_for_id ) { |
|
| 405 | + echo "," . $search_for_id; |
|
| 406 | + } ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed" |
|
| 407 | 407 | class="thickbox button super-duper-content-open" title="Add Shortcode"> |
| 408 | 408 | <span style="vertical-align: middle;line-height: 18px;font-size: 20px;" |
| 409 | 409 | class="dashicons dashicons-screenoptions"></span> |
@@ -414,21 +414,21 @@ discard block |
||
| 414 | 414 | </span> |
| 415 | 415 | |
| 416 | 416 | <?php |
| 417 | - $html = ob_get_clean(); |
|
| 418 | - |
|
| 419 | - // remove line breaks so we can use it in js |
|
| 420 | - return preg_replace( "/\r|\n/", "", trim( $html ) ); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * Makes SD work with the siteOrigin page builder. |
|
| 425 | - * |
|
| 426 | - * @since 1.0.6 |
|
| 427 | - * @return mixed |
|
| 428 | - */ |
|
| 429 | - public static function siteorigin_js() { |
|
| 430 | - ob_start(); |
|
| 431 | - ?> |
|
| 417 | + $html = ob_get_clean(); |
|
| 418 | + |
|
| 419 | + // remove line breaks so we can use it in js |
|
| 420 | + return preg_replace( "/\r|\n/", "", trim( $html ) ); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * Makes SD work with the siteOrigin page builder. |
|
| 425 | + * |
|
| 426 | + * @since 1.0.6 |
|
| 427 | + * @return mixed |
|
| 428 | + */ |
|
| 429 | + public static function siteorigin_js() { |
|
| 430 | + ob_start(); |
|
| 431 | + ?> |
|
| 432 | 432 | <script> |
| 433 | 433 | /** |
| 434 | 434 | * Check a form to see what items shoudl be shown or hidden. |
@@ -506,28 +506,28 @@ discard block |
||
| 506 | 506 | }); |
| 507 | 507 | </script> |
| 508 | 508 | <?php |
| 509 | - $output = ob_get_clean(); |
|
| 509 | + $output = ob_get_clean(); |
|
| 510 | 510 | |
| 511 | - /* |
|
| 511 | + /* |
|
| 512 | 512 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 513 | 513 | */ |
| 514 | 514 | |
| 515 | - return str_replace( array( |
|
| 516 | - '<script>', |
|
| 517 | - '</script>' |
|
| 518 | - ), '', $output ); |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * Output the JS and CSS for the shortcode insert button. |
|
| 523 | - * |
|
| 524 | - * @since 1.0.6 |
|
| 525 | - * |
|
| 526 | - * @param string $editor_id |
|
| 527 | - * @param string $insert_shortcode_function |
|
| 528 | - */ |
|
| 529 | - public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) { |
|
| 530 | - ?> |
|
| 515 | + return str_replace( array( |
|
| 516 | + '<script>', |
|
| 517 | + '</script>' |
|
| 518 | + ), '', $output ); |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * Output the JS and CSS for the shortcode insert button. |
|
| 523 | + * |
|
| 524 | + * @since 1.0.6 |
|
| 525 | + * |
|
| 526 | + * @param string $editor_id |
|
| 527 | + * @param string $insert_shortcode_function |
|
| 528 | + */ |
|
| 529 | + public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) { |
|
| 530 | + ?> |
|
| 531 | 531 | <style> |
| 532 | 532 | .sd-shortcode-left-wrap { |
| 533 | 533 | float: left; |
@@ -653,35 +653,35 @@ discard block |
||
| 653 | 653 | <?php } ?> |
| 654 | 654 | </style> |
| 655 | 655 | <?php |
| 656 | - if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
| 657 | - echo "<script>" . self::siteorigin_js() . "</script>"; |
|
| 658 | - } |
|
| 659 | - ?> |
|
| 656 | + if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
| 657 | + echo "<script>" . self::siteorigin_js() . "</script>"; |
|
| 658 | + } |
|
| 659 | + ?> |
|
| 660 | 660 | <script> |
| 661 | 661 | <?php |
| 662 | - if(! empty( $insert_shortcode_function )){ |
|
| 663 | - echo $insert_shortcode_function; |
|
| 664 | - }else{ |
|
| 665 | - |
|
| 666 | - /** |
|
| 667 | - * Function for super duper insert shortcode. |
|
| 668 | - * |
|
| 669 | - * @since 1.0.0 |
|
| 670 | - */ |
|
| 671 | - ?> |
|
| 662 | + if(! empty( $insert_shortcode_function )){ |
|
| 663 | + echo $insert_shortcode_function; |
|
| 664 | + }else{ |
|
| 665 | + |
|
| 666 | + /** |
|
| 667 | + * Function for super duper insert shortcode. |
|
| 668 | + * |
|
| 669 | + * @since 1.0.0 |
|
| 670 | + */ |
|
| 671 | + ?> |
|
| 672 | 672 | function sd_insert_shortcode($editor_id) { |
| 673 | 673 | $shortcode = jQuery('#TB_ajaxContent #sd-shortcode-output').val(); |
| 674 | 674 | if ($shortcode) { |
| 675 | 675 | if (!$editor_id) { |
| 676 | 676 | <?php |
| 677 | - if ( isset( $_REQUEST['et_fb'] ) ) { |
|
| 678 | - echo '$editor_id = "#main_content_content_vb_tiny_mce";'; |
|
| 679 | - } elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) { |
|
| 680 | - echo '$editor_id = "#elementor-controls .wp-editor-container textarea";'; |
|
| 681 | - } else { |
|
| 682 | - echo '$editor_id = "#wp-content-editor-container textarea";'; |
|
| 683 | - } |
|
| 684 | - ?> |
|
| 677 | + if ( isset( $_REQUEST['et_fb'] ) ) { |
|
| 678 | + echo '$editor_id = "#main_content_content_vb_tiny_mce";'; |
|
| 679 | + } elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) { |
|
| 680 | + echo '$editor_id = "#elementor-controls .wp-editor-container textarea";'; |
|
| 681 | + } else { |
|
| 682 | + echo '$editor_id = "#wp-content-editor-container textarea";'; |
|
| 683 | + } |
|
| 684 | + ?> |
|
| 685 | 685 | } else { |
| 686 | 686 | $editor_id = '#' + $editor_id; |
| 687 | 687 | } |
@@ -1007,18 +1007,18 @@ discard block |
||
| 1007 | 1007 | |
| 1008 | 1008 | </script> |
| 1009 | 1009 | <?php |
| 1010 | - } |
|
| 1011 | - |
|
| 1012 | - /** |
|
| 1013 | - * Gets some CSS for the widgets screen. |
|
| 1014 | - * |
|
| 1015 | - * @param bool $advanced If we should include advanced CSS. |
|
| 1016 | - * |
|
| 1017 | - * @return mixed |
|
| 1018 | - */ |
|
| 1019 | - public function widget_css( $advanced = true ) { |
|
| 1020 | - ob_start(); |
|
| 1021 | - ?> |
|
| 1010 | + } |
|
| 1011 | + |
|
| 1012 | + /** |
|
| 1013 | + * Gets some CSS for the widgets screen. |
|
| 1014 | + * |
|
| 1015 | + * @param bool $advanced If we should include advanced CSS. |
|
| 1016 | + * |
|
| 1017 | + * @return mixed |
|
| 1018 | + */ |
|
| 1019 | + public function widget_css( $advanced = true ) { |
|
| 1020 | + ob_start(); |
|
| 1021 | + ?> |
|
| 1022 | 1022 | <style> |
| 1023 | 1023 | <?php if( $advanced ){ ?> |
| 1024 | 1024 | .sd-advanced-setting { |
@@ -1056,26 +1056,26 @@ discard block |
||
| 1056 | 1056 | } |
| 1057 | 1057 | </style> |
| 1058 | 1058 | <?php |
| 1059 | - $output = ob_get_clean(); |
|
| 1059 | + $output = ob_get_clean(); |
|
| 1060 | 1060 | |
| 1061 | - /* |
|
| 1061 | + /* |
|
| 1062 | 1062 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 1063 | 1063 | */ |
| 1064 | 1064 | |
| 1065 | - return str_replace( array( |
|
| 1066 | - '<style>', |
|
| 1067 | - '</style>' |
|
| 1068 | - ), '', $output ); |
|
| 1069 | - } |
|
| 1070 | - |
|
| 1071 | - /** |
|
| 1072 | - * Gets some JS for the widgets screen. |
|
| 1073 | - * |
|
| 1074 | - * @return mixed |
|
| 1075 | - */ |
|
| 1076 | - public function widget_js() { |
|
| 1077 | - ob_start(); |
|
| 1078 | - ?> |
|
| 1065 | + return str_replace( array( |
|
| 1066 | + '<style>', |
|
| 1067 | + '</style>' |
|
| 1068 | + ), '', $output ); |
|
| 1069 | + } |
|
| 1070 | + |
|
| 1071 | + /** |
|
| 1072 | + * Gets some JS for the widgets screen. |
|
| 1073 | + * |
|
| 1074 | + * @return mixed |
|
| 1075 | + */ |
|
| 1076 | + public function widget_js() { |
|
| 1077 | + ob_start(); |
|
| 1078 | + ?> |
|
| 1079 | 1079 | <script> |
| 1080 | 1080 | |
| 1081 | 1081 | /** |
@@ -1230,402 +1230,402 @@ discard block |
||
| 1230 | 1230 | <?php do_action( 'wp_super_duper_widget_js', $this ); ?> |
| 1231 | 1231 | </script> |
| 1232 | 1232 | <?php |
| 1233 | - $output = ob_get_clean(); |
|
| 1233 | + $output = ob_get_clean(); |
|
| 1234 | 1234 | |
| 1235 | - /* |
|
| 1235 | + /* |
|
| 1236 | 1236 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 1237 | 1237 | */ |
| 1238 | 1238 | |
| 1239 | - return str_replace( array( |
|
| 1240 | - '<script>', |
|
| 1241 | - '</script>' |
|
| 1242 | - ), '', $output ); |
|
| 1243 | - } |
|
| 1244 | - |
|
| 1245 | - |
|
| 1246 | - /** |
|
| 1247 | - * Set the name from the argument key. |
|
| 1248 | - * |
|
| 1249 | - * @param $options |
|
| 1250 | - * |
|
| 1251 | - * @return mixed |
|
| 1252 | - */ |
|
| 1253 | - private function add_name_from_key( $options, $arguments = false ) { |
|
| 1254 | - if ( ! empty( $options['arguments'] ) ) { |
|
| 1255 | - foreach ( $options['arguments'] as $key => $val ) { |
|
| 1256 | - $options['arguments'][ $key ]['name'] = $key; |
|
| 1257 | - } |
|
| 1258 | - } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) { |
|
| 1259 | - foreach ( $options as $key => $val ) { |
|
| 1260 | - $options[ $key ]['name'] = $key; |
|
| 1261 | - } |
|
| 1262 | - } |
|
| 1263 | - |
|
| 1264 | - return $options; |
|
| 1265 | - } |
|
| 1266 | - |
|
| 1267 | - /** |
|
| 1268 | - * Register the parent shortcode. |
|
| 1269 | - * |
|
| 1270 | - * @since 1.0.0 |
|
| 1271 | - */ |
|
| 1272 | - public function register_shortcode() { |
|
| 1273 | - add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) ); |
|
| 1274 | - add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) ); |
|
| 1275 | - } |
|
| 1276 | - |
|
| 1277 | - /** |
|
| 1278 | - * Render the shortcode via ajax so we can return it to Gutenberg. |
|
| 1279 | - * |
|
| 1280 | - * @since 1.0.0 |
|
| 1281 | - */ |
|
| 1282 | - public static function render_shortcode() { |
|
| 1283 | - |
|
| 1284 | - check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true ); |
|
| 1285 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 1286 | - wp_die(); |
|
| 1287 | - } |
|
| 1288 | - |
|
| 1289 | - // we might need the $post value here so lets set it. |
|
| 1290 | - if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) { |
|
| 1291 | - $post_obj = get_post( absint( $_POST['post_id'] ) ); |
|
| 1292 | - if ( ! empty( $post_obj ) && empty( $post ) ) { |
|
| 1293 | - global $post; |
|
| 1294 | - $post = $post_obj; |
|
| 1295 | - } |
|
| 1296 | - } |
|
| 1297 | - |
|
| 1298 | - if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) { |
|
| 1299 | - $shortcode_name = sanitize_title_with_dashes( $_POST['shortcode'] ); |
|
| 1300 | - $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
| 1301 | - $attributes = ''; |
|
| 1302 | - if ( ! empty( $attributes_array ) ) { |
|
| 1303 | - foreach ( $attributes_array as $key => $value ) { |
|
| 1304 | - $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' "; |
|
| 1305 | - } |
|
| 1306 | - } |
|
| 1307 | - |
|
| 1308 | - $shortcode = "[" . $shortcode_name . " " . $attributes . "]"; |
|
| 1309 | - |
|
| 1310 | - echo do_shortcode( $shortcode ); |
|
| 1311 | - |
|
| 1312 | - } |
|
| 1313 | - wp_die(); |
|
| 1314 | - } |
|
| 1315 | - |
|
| 1316 | - /** |
|
| 1317 | - * Output the shortcode. |
|
| 1318 | - * |
|
| 1319 | - * @param array $args |
|
| 1320 | - * @param string $content |
|
| 1321 | - * |
|
| 1322 | - * @return string |
|
| 1323 | - */ |
|
| 1324 | - public function shortcode_output( $args = array(), $content = '' ) { |
|
| 1325 | - $args = $this->argument_values( $args ); |
|
| 1326 | - |
|
| 1327 | - // add extra argument so we know its a output to gutenberg |
|
| 1328 | - //$args |
|
| 1329 | - $args = $this->string_to_bool( $args ); |
|
| 1330 | - |
|
| 1331 | - // if we have a enclosed shortcode we add it to the special `html` argument |
|
| 1332 | - if ( ! empty( $content ) ) { |
|
| 1333 | - $args['html'] = $content; |
|
| 1334 | - } |
|
| 1335 | - |
|
| 1336 | - $class = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : ''; |
|
| 1337 | - $class .= " sdel-".$this->get_instance_hash(); |
|
| 1338 | - |
|
| 1339 | - $class = apply_filters( 'wp_super_duper_div_classname', $class, $args, $this ); |
|
| 1340 | - $class = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $class, $args, $this ); |
|
| 1341 | - |
|
| 1342 | - $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this ); |
|
| 1343 | - $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this ); //@todo this does not seem right @kiran? |
|
| 1344 | - |
|
| 1345 | - $shortcode_args = array(); |
|
| 1346 | - $output = ''; |
|
| 1347 | - $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false; |
|
| 1348 | - if ( isset( $args['no_wrap'] ) && $args['no_wrap'] ) { |
|
| 1349 | - $no_wrap = true; |
|
| 1350 | - } |
|
| 1351 | - $main_content = $this->output( $args, $shortcode_args, $content ); |
|
| 1352 | - if ( $main_content && ! $no_wrap ) { |
|
| 1353 | - // wrap the shortcode in a div with the same class as the widget |
|
| 1354 | - $output .= '<div class="' . $class . '" ' . $attrs . '>'; |
|
| 1355 | - if ( ! empty( $args['title'] ) ) { |
|
| 1356 | - // if its a shortcode and there is a title try to grab the title wrappers |
|
| 1357 | - $shortcode_args = array( 'before_title' => '', 'after_title' => '' ); |
|
| 1358 | - if ( empty( $instance ) ) { |
|
| 1359 | - global $wp_registered_sidebars; |
|
| 1360 | - if ( ! empty( $wp_registered_sidebars ) ) { |
|
| 1361 | - foreach ( $wp_registered_sidebars as $sidebar ) { |
|
| 1362 | - if ( ! empty( $sidebar['before_title'] ) ) { |
|
| 1363 | - $shortcode_args['before_title'] = $sidebar['before_title']; |
|
| 1364 | - $shortcode_args['after_title'] = $sidebar['after_title']; |
|
| 1365 | - break; |
|
| 1366 | - } |
|
| 1367 | - } |
|
| 1368 | - } |
|
| 1369 | - } |
|
| 1370 | - $output .= $this->output_title( $shortcode_args, $args ); |
|
| 1371 | - } |
|
| 1372 | - $output .= $main_content; |
|
| 1373 | - $output .= '</div>'; |
|
| 1374 | - } elseif ( $main_content && $no_wrap ) { |
|
| 1375 | - $output .= $main_content; |
|
| 1376 | - } |
|
| 1377 | - |
|
| 1378 | - // if preview show a placeholder if empty |
|
| 1379 | - if ( $this->is_preview() && $output == '' ) { |
|
| 1380 | - $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" ); |
|
| 1381 | - } |
|
| 1382 | - |
|
| 1383 | - return apply_filters( 'wp_super_duper_widget_output', $output, $args, $shortcode_args, $this ); |
|
| 1384 | - } |
|
| 1385 | - |
|
| 1386 | - /** |
|
| 1387 | - * Placeholder text to show if output is empty and we are on a preview/builder page. |
|
| 1388 | - * |
|
| 1389 | - * @param string $name |
|
| 1390 | - * |
|
| 1391 | - * @return string |
|
| 1392 | - */ |
|
| 1393 | - public function preview_placeholder_text( $name = '' ) { |
|
| 1394 | - return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>"; |
|
| 1395 | - } |
|
| 1396 | - |
|
| 1397 | - /** |
|
| 1398 | - * Sometimes booleans values can be turned to strings, so we fix that. |
|
| 1399 | - * |
|
| 1400 | - * @param $options |
|
| 1401 | - * |
|
| 1402 | - * @return mixed |
|
| 1403 | - */ |
|
| 1404 | - public function string_to_bool( $options ) { |
|
| 1405 | - // convert bool strings to booleans |
|
| 1406 | - foreach ( $options as $key => $val ) { |
|
| 1407 | - if ( $val == 'false' ) { |
|
| 1408 | - $options[ $key ] = false; |
|
| 1409 | - } elseif ( $val == 'true' ) { |
|
| 1410 | - $options[ $key ] = true; |
|
| 1411 | - } |
|
| 1412 | - } |
|
| 1413 | - |
|
| 1414 | - return $options; |
|
| 1415 | - } |
|
| 1416 | - |
|
| 1417 | - /** |
|
| 1418 | - * Get the argument values that are also filterable. |
|
| 1419 | - * |
|
| 1420 | - * @param $instance |
|
| 1421 | - * |
|
| 1422 | - * @since 1.0.12 Don't set checkbox default value if the value is empty. |
|
| 1423 | - * |
|
| 1424 | - * @return array |
|
| 1425 | - */ |
|
| 1426 | - public function argument_values( $instance ) { |
|
| 1427 | - $argument_values = array(); |
|
| 1428 | - |
|
| 1429 | - // set widget instance |
|
| 1430 | - $this->instance = $instance; |
|
| 1431 | - |
|
| 1432 | - if ( empty( $this->arguments ) ) { |
|
| 1433 | - $this->arguments = $this->get_arguments(); |
|
| 1434 | - } |
|
| 1435 | - |
|
| 1436 | - if ( ! empty( $this->arguments ) ) { |
|
| 1437 | - foreach ( $this->arguments as $key => $args ) { |
|
| 1438 | - // set the input name from the key |
|
| 1439 | - $args['name'] = $key; |
|
| 1440 | - // |
|
| 1441 | - $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
|
| 1442 | - if ( $args['type'] == 'checkbox' && $argument_values[ $key ] == '' ) { |
|
| 1443 | - // don't set default for an empty checkbox |
|
| 1444 | - } elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
| 1445 | - $argument_values[ $key ] = $args['default']; |
|
| 1446 | - } |
|
| 1447 | - } |
|
| 1448 | - } |
|
| 1449 | - |
|
| 1450 | - return $argument_values; |
|
| 1451 | - } |
|
| 1452 | - |
|
| 1453 | - /** |
|
| 1454 | - * Set arguments in super duper. |
|
| 1455 | - * |
|
| 1456 | - * @since 1.0.0 |
|
| 1457 | - * |
|
| 1458 | - * @return array Set arguments. |
|
| 1459 | - */ |
|
| 1460 | - public function set_arguments() { |
|
| 1461 | - return $this->arguments; |
|
| 1462 | - } |
|
| 1463 | - |
|
| 1464 | - /** |
|
| 1465 | - * Get arguments in super duper. |
|
| 1466 | - * |
|
| 1467 | - * @since 1.0.0 |
|
| 1468 | - * |
|
| 1469 | - * @return array Get arguments. |
|
| 1470 | - */ |
|
| 1471 | - public function get_arguments() { |
|
| 1472 | - if ( empty( $this->arguments ) ) { |
|
| 1473 | - $this->arguments = $this->set_arguments(); |
|
| 1474 | - } |
|
| 1475 | - |
|
| 1476 | - $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance ); |
|
| 1477 | - $this->arguments = $this->add_name_from_key( $this->arguments, true ); |
|
| 1478 | - |
|
| 1479 | - return $this->arguments; |
|
| 1480 | - } |
|
| 1481 | - |
|
| 1482 | - /** |
|
| 1483 | - * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class. |
|
| 1484 | - * |
|
| 1485 | - * @param array $args |
|
| 1486 | - * @param array $widget_args |
|
| 1487 | - * @param string $content |
|
| 1488 | - */ |
|
| 1489 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 1490 | - |
|
| 1491 | - } |
|
| 1492 | - |
|
| 1493 | - /** |
|
| 1494 | - * Add the dynamic block code inline when the wp-block in enqueued. |
|
| 1495 | - */ |
|
| 1496 | - public function register_block() { |
|
| 1497 | - wp_add_inline_script( 'wp-blocks', $this->block() ); |
|
| 1498 | - if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
| 1499 | - wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() ); |
|
| 1500 | - } |
|
| 1501 | - } |
|
| 1502 | - |
|
| 1503 | - /** |
|
| 1504 | - * Check if we need to show advanced options. |
|
| 1505 | - * |
|
| 1506 | - * @return bool |
|
| 1507 | - */ |
|
| 1508 | - public function block_show_advanced() { |
|
| 1509 | - |
|
| 1510 | - $show = false; |
|
| 1511 | - $arguments = $this->arguments; |
|
| 1512 | - |
|
| 1513 | - if ( empty( $arguments ) ) { |
|
| 1514 | - $arguments = $this->get_arguments(); |
|
| 1515 | - } |
|
| 1516 | - |
|
| 1517 | - if ( ! empty( $arguments ) ) { |
|
| 1518 | - foreach ( $arguments as $argument ) { |
|
| 1519 | - if ( isset( $argument['advanced'] ) && $argument['advanced'] ) { |
|
| 1520 | - $show = true; |
|
| 1521 | - break; // no need to continue if we know we have it |
|
| 1522 | - } |
|
| 1523 | - } |
|
| 1524 | - } |
|
| 1525 | - |
|
| 1526 | - return $show; |
|
| 1527 | - } |
|
| 1528 | - |
|
| 1529 | - /** |
|
| 1530 | - * Get the url path to the current folder. |
|
| 1531 | - * |
|
| 1532 | - * @return string |
|
| 1533 | - */ |
|
| 1534 | - public function get_url() { |
|
| 1535 | - |
|
| 1536 | - $url = $this->url; |
|
| 1537 | - |
|
| 1538 | - if ( ! $url ) { |
|
| 1539 | - // check if we are inside a plugin |
|
| 1540 | - $file_dir = str_replace( "/includes", "", dirname( __FILE__ ) ); |
|
| 1541 | - |
|
| 1542 | - $dir_parts = explode( "/wp-content/", $file_dir ); |
|
| 1543 | - $url_parts = explode( "/wp-content/", plugins_url() ); |
|
| 1544 | - |
|
| 1545 | - if ( ! empty( $url_parts[0] ) && ! empty( $dir_parts[1] ) ) { |
|
| 1546 | - $url = trailingslashit( $url_parts[0] . "/wp-content/" . $dir_parts[1] ); |
|
| 1547 | - $this->url = $url; |
|
| 1548 | - } |
|
| 1549 | - } |
|
| 1550 | - |
|
| 1551 | - |
|
| 1552 | - return $url; |
|
| 1553 | - } |
|
| 1554 | - |
|
| 1555 | - /** |
|
| 1556 | - * Generate the block icon. |
|
| 1557 | - * |
|
| 1558 | - * Enables the use of Font Awesome icons. |
|
| 1559 | - * |
|
| 1560 | - * @note xlink:href is actually deprecated but href is not supported by all so we use both. |
|
| 1561 | - * |
|
| 1562 | - * @param $icon |
|
| 1563 | - * |
|
| 1564 | - * @since 1.1.0 |
|
| 1565 | - * @return string |
|
| 1566 | - */ |
|
| 1567 | - public function get_block_icon( $icon ) { |
|
| 1568 | - |
|
| 1569 | - // check if we have a Font Awesome icon |
|
| 1570 | - $fa_type = ''; |
|
| 1571 | - if ( substr( $icon, 0, 7 ) === "fas fa-" ) { |
|
| 1572 | - $fa_type = 'solid'; |
|
| 1573 | - } elseif ( substr( $icon, 0, 7 ) === "far fa-" ) { |
|
| 1574 | - $fa_type = 'regular'; |
|
| 1575 | - } elseif ( substr( $icon, 0, 7 ) === "fab fa-" ) { |
|
| 1576 | - $fa_type = 'brands'; |
|
| 1577 | - } else { |
|
| 1578 | - $icon = "'" . $icon . "'"; |
|
| 1579 | - } |
|
| 1580 | - |
|
| 1581 | - // set the icon if we found one |
|
| 1582 | - if ( $fa_type ) { |
|
| 1583 | - $fa_icon = str_replace( array( "fas fa-", "far fa-", "fab fa-" ), "", $icon ); |
|
| 1584 | - $icon = "el('svg',{width: 20, height: 20, viewBox: '0 0 20 20'},el('use', {'xlink:href': '" . $this->get_url() . "icons/" . $fa_type . ".svg#" . $fa_icon . "','href': '" . $this->get_url() . "icons/" . $fa_type . ".svg#" . $fa_icon . "'}))"; |
|
| 1585 | - } |
|
| 1586 | - |
|
| 1587 | - return $icon; |
|
| 1588 | - } |
|
| 1589 | - |
|
| 1590 | - public function group_arguments( $arguments ) { |
|
| 1239 | + return str_replace( array( |
|
| 1240 | + '<script>', |
|
| 1241 | + '</script>' |
|
| 1242 | + ), '', $output ); |
|
| 1243 | + } |
|
| 1244 | + |
|
| 1245 | + |
|
| 1246 | + /** |
|
| 1247 | + * Set the name from the argument key. |
|
| 1248 | + * |
|
| 1249 | + * @param $options |
|
| 1250 | + * |
|
| 1251 | + * @return mixed |
|
| 1252 | + */ |
|
| 1253 | + private function add_name_from_key( $options, $arguments = false ) { |
|
| 1254 | + if ( ! empty( $options['arguments'] ) ) { |
|
| 1255 | + foreach ( $options['arguments'] as $key => $val ) { |
|
| 1256 | + $options['arguments'][ $key ]['name'] = $key; |
|
| 1257 | + } |
|
| 1258 | + } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) { |
|
| 1259 | + foreach ( $options as $key => $val ) { |
|
| 1260 | + $options[ $key ]['name'] = $key; |
|
| 1261 | + } |
|
| 1262 | + } |
|
| 1263 | + |
|
| 1264 | + return $options; |
|
| 1265 | + } |
|
| 1266 | + |
|
| 1267 | + /** |
|
| 1268 | + * Register the parent shortcode. |
|
| 1269 | + * |
|
| 1270 | + * @since 1.0.0 |
|
| 1271 | + */ |
|
| 1272 | + public function register_shortcode() { |
|
| 1273 | + add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) ); |
|
| 1274 | + add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) ); |
|
| 1275 | + } |
|
| 1276 | + |
|
| 1277 | + /** |
|
| 1278 | + * Render the shortcode via ajax so we can return it to Gutenberg. |
|
| 1279 | + * |
|
| 1280 | + * @since 1.0.0 |
|
| 1281 | + */ |
|
| 1282 | + public static function render_shortcode() { |
|
| 1283 | + |
|
| 1284 | + check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true ); |
|
| 1285 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
| 1286 | + wp_die(); |
|
| 1287 | + } |
|
| 1288 | + |
|
| 1289 | + // we might need the $post value here so lets set it. |
|
| 1290 | + if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) { |
|
| 1291 | + $post_obj = get_post( absint( $_POST['post_id'] ) ); |
|
| 1292 | + if ( ! empty( $post_obj ) && empty( $post ) ) { |
|
| 1293 | + global $post; |
|
| 1294 | + $post = $post_obj; |
|
| 1295 | + } |
|
| 1296 | + } |
|
| 1297 | + |
|
| 1298 | + if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) { |
|
| 1299 | + $shortcode_name = sanitize_title_with_dashes( $_POST['shortcode'] ); |
|
| 1300 | + $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
| 1301 | + $attributes = ''; |
|
| 1302 | + if ( ! empty( $attributes_array ) ) { |
|
| 1303 | + foreach ( $attributes_array as $key => $value ) { |
|
| 1304 | + $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' "; |
|
| 1305 | + } |
|
| 1306 | + } |
|
| 1307 | + |
|
| 1308 | + $shortcode = "[" . $shortcode_name . " " . $attributes . "]"; |
|
| 1309 | + |
|
| 1310 | + echo do_shortcode( $shortcode ); |
|
| 1311 | + |
|
| 1312 | + } |
|
| 1313 | + wp_die(); |
|
| 1314 | + } |
|
| 1315 | + |
|
| 1316 | + /** |
|
| 1317 | + * Output the shortcode. |
|
| 1318 | + * |
|
| 1319 | + * @param array $args |
|
| 1320 | + * @param string $content |
|
| 1321 | + * |
|
| 1322 | + * @return string |
|
| 1323 | + */ |
|
| 1324 | + public function shortcode_output( $args = array(), $content = '' ) { |
|
| 1325 | + $args = $this->argument_values( $args ); |
|
| 1326 | + |
|
| 1327 | + // add extra argument so we know its a output to gutenberg |
|
| 1328 | + //$args |
|
| 1329 | + $args = $this->string_to_bool( $args ); |
|
| 1330 | + |
|
| 1331 | + // if we have a enclosed shortcode we add it to the special `html` argument |
|
| 1332 | + if ( ! empty( $content ) ) { |
|
| 1333 | + $args['html'] = $content; |
|
| 1334 | + } |
|
| 1335 | + |
|
| 1336 | + $class = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : ''; |
|
| 1337 | + $class .= " sdel-".$this->get_instance_hash(); |
|
| 1338 | + |
|
| 1339 | + $class = apply_filters( 'wp_super_duper_div_classname', $class, $args, $this ); |
|
| 1340 | + $class = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $class, $args, $this ); |
|
| 1341 | + |
|
| 1342 | + $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this ); |
|
| 1343 | + $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this ); //@todo this does not seem right @kiran? |
|
| 1344 | + |
|
| 1345 | + $shortcode_args = array(); |
|
| 1346 | + $output = ''; |
|
| 1347 | + $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false; |
|
| 1348 | + if ( isset( $args['no_wrap'] ) && $args['no_wrap'] ) { |
|
| 1349 | + $no_wrap = true; |
|
| 1350 | + } |
|
| 1351 | + $main_content = $this->output( $args, $shortcode_args, $content ); |
|
| 1352 | + if ( $main_content && ! $no_wrap ) { |
|
| 1353 | + // wrap the shortcode in a div with the same class as the widget |
|
| 1354 | + $output .= '<div class="' . $class . '" ' . $attrs . '>'; |
|
| 1355 | + if ( ! empty( $args['title'] ) ) { |
|
| 1356 | + // if its a shortcode and there is a title try to grab the title wrappers |
|
| 1357 | + $shortcode_args = array( 'before_title' => '', 'after_title' => '' ); |
|
| 1358 | + if ( empty( $instance ) ) { |
|
| 1359 | + global $wp_registered_sidebars; |
|
| 1360 | + if ( ! empty( $wp_registered_sidebars ) ) { |
|
| 1361 | + foreach ( $wp_registered_sidebars as $sidebar ) { |
|
| 1362 | + if ( ! empty( $sidebar['before_title'] ) ) { |
|
| 1363 | + $shortcode_args['before_title'] = $sidebar['before_title']; |
|
| 1364 | + $shortcode_args['after_title'] = $sidebar['after_title']; |
|
| 1365 | + break; |
|
| 1366 | + } |
|
| 1367 | + } |
|
| 1368 | + } |
|
| 1369 | + } |
|
| 1370 | + $output .= $this->output_title( $shortcode_args, $args ); |
|
| 1371 | + } |
|
| 1372 | + $output .= $main_content; |
|
| 1373 | + $output .= '</div>'; |
|
| 1374 | + } elseif ( $main_content && $no_wrap ) { |
|
| 1375 | + $output .= $main_content; |
|
| 1376 | + } |
|
| 1377 | + |
|
| 1378 | + // if preview show a placeholder if empty |
|
| 1379 | + if ( $this->is_preview() && $output == '' ) { |
|
| 1380 | + $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" ); |
|
| 1381 | + } |
|
| 1382 | + |
|
| 1383 | + return apply_filters( 'wp_super_duper_widget_output', $output, $args, $shortcode_args, $this ); |
|
| 1384 | + } |
|
| 1385 | + |
|
| 1386 | + /** |
|
| 1387 | + * Placeholder text to show if output is empty and we are on a preview/builder page. |
|
| 1388 | + * |
|
| 1389 | + * @param string $name |
|
| 1390 | + * |
|
| 1391 | + * @return string |
|
| 1392 | + */ |
|
| 1393 | + public function preview_placeholder_text( $name = '' ) { |
|
| 1394 | + return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>"; |
|
| 1395 | + } |
|
| 1396 | + |
|
| 1397 | + /** |
|
| 1398 | + * Sometimes booleans values can be turned to strings, so we fix that. |
|
| 1399 | + * |
|
| 1400 | + * @param $options |
|
| 1401 | + * |
|
| 1402 | + * @return mixed |
|
| 1403 | + */ |
|
| 1404 | + public function string_to_bool( $options ) { |
|
| 1405 | + // convert bool strings to booleans |
|
| 1406 | + foreach ( $options as $key => $val ) { |
|
| 1407 | + if ( $val == 'false' ) { |
|
| 1408 | + $options[ $key ] = false; |
|
| 1409 | + } elseif ( $val == 'true' ) { |
|
| 1410 | + $options[ $key ] = true; |
|
| 1411 | + } |
|
| 1412 | + } |
|
| 1413 | + |
|
| 1414 | + return $options; |
|
| 1415 | + } |
|
| 1416 | + |
|
| 1417 | + /** |
|
| 1418 | + * Get the argument values that are also filterable. |
|
| 1419 | + * |
|
| 1420 | + * @param $instance |
|
| 1421 | + * |
|
| 1422 | + * @since 1.0.12 Don't set checkbox default value if the value is empty. |
|
| 1423 | + * |
|
| 1424 | + * @return array |
|
| 1425 | + */ |
|
| 1426 | + public function argument_values( $instance ) { |
|
| 1427 | + $argument_values = array(); |
|
| 1428 | + |
|
| 1429 | + // set widget instance |
|
| 1430 | + $this->instance = $instance; |
|
| 1431 | + |
|
| 1432 | + if ( empty( $this->arguments ) ) { |
|
| 1433 | + $this->arguments = $this->get_arguments(); |
|
| 1434 | + } |
|
| 1435 | + |
|
| 1436 | + if ( ! empty( $this->arguments ) ) { |
|
| 1437 | + foreach ( $this->arguments as $key => $args ) { |
|
| 1438 | + // set the input name from the key |
|
| 1439 | + $args['name'] = $key; |
|
| 1440 | + // |
|
| 1441 | + $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
|
| 1442 | + if ( $args['type'] == 'checkbox' && $argument_values[ $key ] == '' ) { |
|
| 1443 | + // don't set default for an empty checkbox |
|
| 1444 | + } elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
| 1445 | + $argument_values[ $key ] = $args['default']; |
|
| 1446 | + } |
|
| 1447 | + } |
|
| 1448 | + } |
|
| 1449 | + |
|
| 1450 | + return $argument_values; |
|
| 1451 | + } |
|
| 1452 | + |
|
| 1453 | + /** |
|
| 1454 | + * Set arguments in super duper. |
|
| 1455 | + * |
|
| 1456 | + * @since 1.0.0 |
|
| 1457 | + * |
|
| 1458 | + * @return array Set arguments. |
|
| 1459 | + */ |
|
| 1460 | + public function set_arguments() { |
|
| 1461 | + return $this->arguments; |
|
| 1462 | + } |
|
| 1463 | + |
|
| 1464 | + /** |
|
| 1465 | + * Get arguments in super duper. |
|
| 1466 | + * |
|
| 1467 | + * @since 1.0.0 |
|
| 1468 | + * |
|
| 1469 | + * @return array Get arguments. |
|
| 1470 | + */ |
|
| 1471 | + public function get_arguments() { |
|
| 1472 | + if ( empty( $this->arguments ) ) { |
|
| 1473 | + $this->arguments = $this->set_arguments(); |
|
| 1474 | + } |
|
| 1475 | + |
|
| 1476 | + $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance ); |
|
| 1477 | + $this->arguments = $this->add_name_from_key( $this->arguments, true ); |
|
| 1478 | + |
|
| 1479 | + return $this->arguments; |
|
| 1480 | + } |
|
| 1481 | + |
|
| 1482 | + /** |
|
| 1483 | + * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class. |
|
| 1484 | + * |
|
| 1485 | + * @param array $args |
|
| 1486 | + * @param array $widget_args |
|
| 1487 | + * @param string $content |
|
| 1488 | + */ |
|
| 1489 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 1490 | + |
|
| 1491 | + } |
|
| 1492 | + |
|
| 1493 | + /** |
|
| 1494 | + * Add the dynamic block code inline when the wp-block in enqueued. |
|
| 1495 | + */ |
|
| 1496 | + public function register_block() { |
|
| 1497 | + wp_add_inline_script( 'wp-blocks', $this->block() ); |
|
| 1498 | + if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
| 1499 | + wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() ); |
|
| 1500 | + } |
|
| 1501 | + } |
|
| 1502 | + |
|
| 1503 | + /** |
|
| 1504 | + * Check if we need to show advanced options. |
|
| 1505 | + * |
|
| 1506 | + * @return bool |
|
| 1507 | + */ |
|
| 1508 | + public function block_show_advanced() { |
|
| 1509 | + |
|
| 1510 | + $show = false; |
|
| 1511 | + $arguments = $this->arguments; |
|
| 1512 | + |
|
| 1513 | + if ( empty( $arguments ) ) { |
|
| 1514 | + $arguments = $this->get_arguments(); |
|
| 1515 | + } |
|
| 1516 | + |
|
| 1517 | + if ( ! empty( $arguments ) ) { |
|
| 1518 | + foreach ( $arguments as $argument ) { |
|
| 1519 | + if ( isset( $argument['advanced'] ) && $argument['advanced'] ) { |
|
| 1520 | + $show = true; |
|
| 1521 | + break; // no need to continue if we know we have it |
|
| 1522 | + } |
|
| 1523 | + } |
|
| 1524 | + } |
|
| 1525 | + |
|
| 1526 | + return $show; |
|
| 1527 | + } |
|
| 1528 | + |
|
| 1529 | + /** |
|
| 1530 | + * Get the url path to the current folder. |
|
| 1531 | + * |
|
| 1532 | + * @return string |
|
| 1533 | + */ |
|
| 1534 | + public function get_url() { |
|
| 1535 | + |
|
| 1536 | + $url = $this->url; |
|
| 1537 | + |
|
| 1538 | + if ( ! $url ) { |
|
| 1539 | + // check if we are inside a plugin |
|
| 1540 | + $file_dir = str_replace( "/includes", "", dirname( __FILE__ ) ); |
|
| 1541 | + |
|
| 1542 | + $dir_parts = explode( "/wp-content/", $file_dir ); |
|
| 1543 | + $url_parts = explode( "/wp-content/", plugins_url() ); |
|
| 1544 | + |
|
| 1545 | + if ( ! empty( $url_parts[0] ) && ! empty( $dir_parts[1] ) ) { |
|
| 1546 | + $url = trailingslashit( $url_parts[0] . "/wp-content/" . $dir_parts[1] ); |
|
| 1547 | + $this->url = $url; |
|
| 1548 | + } |
|
| 1549 | + } |
|
| 1550 | + |
|
| 1551 | + |
|
| 1552 | + return $url; |
|
| 1553 | + } |
|
| 1554 | + |
|
| 1555 | + /** |
|
| 1556 | + * Generate the block icon. |
|
| 1557 | + * |
|
| 1558 | + * Enables the use of Font Awesome icons. |
|
| 1559 | + * |
|
| 1560 | + * @note xlink:href is actually deprecated but href is not supported by all so we use both. |
|
| 1561 | + * |
|
| 1562 | + * @param $icon |
|
| 1563 | + * |
|
| 1564 | + * @since 1.1.0 |
|
| 1565 | + * @return string |
|
| 1566 | + */ |
|
| 1567 | + public function get_block_icon( $icon ) { |
|
| 1568 | + |
|
| 1569 | + // check if we have a Font Awesome icon |
|
| 1570 | + $fa_type = ''; |
|
| 1571 | + if ( substr( $icon, 0, 7 ) === "fas fa-" ) { |
|
| 1572 | + $fa_type = 'solid'; |
|
| 1573 | + } elseif ( substr( $icon, 0, 7 ) === "far fa-" ) { |
|
| 1574 | + $fa_type = 'regular'; |
|
| 1575 | + } elseif ( substr( $icon, 0, 7 ) === "fab fa-" ) { |
|
| 1576 | + $fa_type = 'brands'; |
|
| 1577 | + } else { |
|
| 1578 | + $icon = "'" . $icon . "'"; |
|
| 1579 | + } |
|
| 1580 | + |
|
| 1581 | + // set the icon if we found one |
|
| 1582 | + if ( $fa_type ) { |
|
| 1583 | + $fa_icon = str_replace( array( "fas fa-", "far fa-", "fab fa-" ), "", $icon ); |
|
| 1584 | + $icon = "el('svg',{width: 20, height: 20, viewBox: '0 0 20 20'},el('use', {'xlink:href': '" . $this->get_url() . "icons/" . $fa_type . ".svg#" . $fa_icon . "','href': '" . $this->get_url() . "icons/" . $fa_type . ".svg#" . $fa_icon . "'}))"; |
|
| 1585 | + } |
|
| 1586 | + |
|
| 1587 | + return $icon; |
|
| 1588 | + } |
|
| 1589 | + |
|
| 1590 | + public function group_arguments( $arguments ) { |
|
| 1591 | 1591 | // echo '###';print_r($arguments); |
| 1592 | - if ( ! empty( $arguments ) ) { |
|
| 1593 | - $temp_arguments = array(); |
|
| 1594 | - $general = __( "General" ); |
|
| 1595 | - $add_sections = false; |
|
| 1596 | - foreach ( $arguments as $key => $args ) { |
|
| 1597 | - if ( isset( $args['group'] ) ) { |
|
| 1598 | - $temp_arguments[ $args['group'] ][ $key ] = $args; |
|
| 1599 | - $add_sections = true; |
|
| 1600 | - } else { |
|
| 1601 | - $temp_arguments[ $general ][ $key ] = $args; |
|
| 1602 | - } |
|
| 1603 | - } |
|
| 1604 | - |
|
| 1605 | - // only add sections if more than one |
|
| 1606 | - if ( $add_sections ) { |
|
| 1607 | - $arguments = $temp_arguments; |
|
| 1608 | - } |
|
| 1609 | - } |
|
| 1592 | + if ( ! empty( $arguments ) ) { |
|
| 1593 | + $temp_arguments = array(); |
|
| 1594 | + $general = __( "General" ); |
|
| 1595 | + $add_sections = false; |
|
| 1596 | + foreach ( $arguments as $key => $args ) { |
|
| 1597 | + if ( isset( $args['group'] ) ) { |
|
| 1598 | + $temp_arguments[ $args['group'] ][ $key ] = $args; |
|
| 1599 | + $add_sections = true; |
|
| 1600 | + } else { |
|
| 1601 | + $temp_arguments[ $general ][ $key ] = $args; |
|
| 1602 | + } |
|
| 1603 | + } |
|
| 1604 | + |
|
| 1605 | + // only add sections if more than one |
|
| 1606 | + if ( $add_sections ) { |
|
| 1607 | + $arguments = $temp_arguments; |
|
| 1608 | + } |
|
| 1609 | + } |
|
| 1610 | 1610 | |
| 1611 | 1611 | // echo '###';print_r($arguments); |
| 1612 | - return $arguments; |
|
| 1613 | - } |
|
| 1614 | - |
|
| 1615 | - |
|
| 1616 | - /** |
|
| 1617 | - * Output the JS for building the dynamic Guntenberg block. |
|
| 1618 | - * |
|
| 1619 | - * @since 1.0.4 Added block_wrap property which will set the block wrapping output element ie: div, span, p or empty for no wrap. |
|
| 1620 | - * @since 1.0.9 Save numbers as numbers and not strings. |
|
| 1621 | - * @since 1.1.0 Font Awesome classes can be used for icons. |
|
| 1622 | - * @return mixed |
|
| 1623 | - */ |
|
| 1624 | - public function block() { |
|
| 1625 | - ob_start(); |
|
| 1626 | - |
|
| 1627 | - $show_advanced = $this->block_show_advanced(); |
|
| 1628 | - ?> |
|
| 1612 | + return $arguments; |
|
| 1613 | + } |
|
| 1614 | + |
|
| 1615 | + |
|
| 1616 | + /** |
|
| 1617 | + * Output the JS for building the dynamic Guntenberg block. |
|
| 1618 | + * |
|
| 1619 | + * @since 1.0.4 Added block_wrap property which will set the block wrapping output element ie: div, span, p or empty for no wrap. |
|
| 1620 | + * @since 1.0.9 Save numbers as numbers and not strings. |
|
| 1621 | + * @since 1.1.0 Font Awesome classes can be used for icons. |
|
| 1622 | + * @return mixed |
|
| 1623 | + */ |
|
| 1624 | + public function block() { |
|
| 1625 | + ob_start(); |
|
| 1626 | + |
|
| 1627 | + $show_advanced = $this->block_show_advanced(); |
|
| 1628 | + ?> |
|
| 1629 | 1629 | <script> |
| 1630 | 1630 | /** |
| 1631 | 1631 | * BLOCK: Basic |
@@ -1669,97 +1669,97 @@ discard block |
||
| 1669 | 1669 | icon: <?php echo $this->get_block_icon( $this->options['block-icon'] );?>,//'<?php echo isset( $this->options['block-icon'] ) ? esc_attr( $this->options['block-icon'] ) : 'shield-alt';?>', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/. |
| 1670 | 1670 | supports: { |
| 1671 | 1671 | <?php |
| 1672 | - if ( isset( $this->options['block-supports'] ) ) { |
|
| 1673 | - echo $this->array_to_attributes( $this->options['block-supports'] ); |
|
| 1674 | - } |
|
| 1675 | - ?> |
|
| 1672 | + if ( isset( $this->options['block-supports'] ) ) { |
|
| 1673 | + echo $this->array_to_attributes( $this->options['block-supports'] ); |
|
| 1674 | + } |
|
| 1675 | + ?> |
|
| 1676 | 1676 | }, |
| 1677 | 1677 | category: '<?php echo isset( $this->options['block-category'] ) ? esc_attr( $this->options['block-category'] ) : 'common';?>', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed. |
| 1678 | 1678 | <?php if ( isset( $this->options['block-keywords'] ) ) { |
| 1679 | - echo "keywords : " . $this->options['block-keywords'] . ","; |
|
| 1680 | - }?> |
|
| 1679 | + echo "keywords : " . $this->options['block-keywords'] . ","; |
|
| 1680 | + }?> |
|
| 1681 | 1681 | |
| 1682 | 1682 | <?php |
| 1683 | 1683 | |
| 1684 | - // maybe set no_wrap |
|
| 1685 | - $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false; |
|
| 1686 | - if ( isset( $this->arguments['no_wrap'] ) && $this->arguments['no_wrap'] ) { |
|
| 1687 | - $no_wrap = true; |
|
| 1688 | - } |
|
| 1689 | - if ( $no_wrap ) { |
|
| 1690 | - $this->options['block-wrap'] = ''; |
|
| 1691 | - } |
|
| 1684 | + // maybe set no_wrap |
|
| 1685 | + $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false; |
|
| 1686 | + if ( isset( $this->arguments['no_wrap'] ) && $this->arguments['no_wrap'] ) { |
|
| 1687 | + $no_wrap = true; |
|
| 1688 | + } |
|
| 1689 | + if ( $no_wrap ) { |
|
| 1690 | + $this->options['block-wrap'] = ''; |
|
| 1691 | + } |
|
| 1692 | 1692 | |
| 1693 | 1693 | |
| 1694 | 1694 | |
| 1695 | - $show_alignment = false; |
|
| 1696 | - // align feature |
|
| 1697 | - /*echo "supports: {"; |
|
| 1695 | + $show_alignment = false; |
|
| 1696 | + // align feature |
|
| 1697 | + /*echo "supports: {"; |
|
| 1698 | 1698 | echo " align: true,"; |
| 1699 | 1699 | echo " html: false"; |
| 1700 | 1700 | echo "},";*/ |
| 1701 | 1701 | |
| 1702 | - if ( ! empty( $this->arguments ) ) { |
|
| 1703 | - echo "attributes : {"; |
|
| 1704 | - |
|
| 1705 | - if ( $show_advanced ) { |
|
| 1706 | - echo "show_advanced: {"; |
|
| 1707 | - echo " type: 'boolean',"; |
|
| 1708 | - echo " default: false,"; |
|
| 1709 | - echo "},"; |
|
| 1710 | - } |
|
| 1711 | - |
|
| 1712 | - // block wrap element |
|
| 1713 | - if ( ! empty( $this->options['block-wrap'] ) ) { //@todo we should validate this? |
|
| 1714 | - echo "block_wrap: {"; |
|
| 1715 | - echo " type: 'string',"; |
|
| 1716 | - echo " default: '" . esc_attr( $this->options['block-wrap'] ) . "',"; |
|
| 1717 | - echo "},"; |
|
| 1718 | - } |
|
| 1719 | - |
|
| 1720 | - foreach ( $this->arguments as $key => $args ) { |
|
| 1721 | - |
|
| 1722 | - // set if we should show alignment |
|
| 1723 | - if ( $key == 'alignment' ) { |
|
| 1724 | - $show_alignment = true; |
|
| 1725 | - } |
|
| 1726 | - |
|
| 1727 | - $extra = ''; |
|
| 1728 | - |
|
| 1729 | - if ( $args['type'] == 'checkbox' ) { |
|
| 1730 | - $type = 'boolean'; |
|
| 1731 | - $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false'; |
|
| 1732 | - } elseif ( $args['type'] == 'number' ) { |
|
| 1733 | - $type = 'number'; |
|
| 1734 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1735 | - } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) { |
|
| 1736 | - $type = 'array'; |
|
| 1737 | - if ( is_array( $args['default'] ) ) { |
|
| 1738 | - $default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]"; |
|
| 1739 | - } else { |
|
| 1740 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1741 | - } |
|
| 1742 | - } elseif ( $args['type'] == 'multiselect' ) { |
|
| 1743 | - $type = 'array'; |
|
| 1744 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1745 | - } else { |
|
| 1746 | - $type = 'string'; |
|
| 1747 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1748 | - } |
|
| 1749 | - echo $key . " : {"; |
|
| 1750 | - echo "type : '$type',"; |
|
| 1751 | - echo "default : $default,"; |
|
| 1752 | - echo "},"; |
|
| 1753 | - } |
|
| 1754 | - |
|
| 1755 | - echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},"; |
|
| 1756 | - echo "className: { type: 'string', default: '' },"; |
|
| 1757 | - |
|
| 1758 | - echo "},"; |
|
| 1759 | - |
|
| 1760 | - } |
|
| 1761 | - |
|
| 1762 | - ?> |
|
| 1702 | + if ( ! empty( $this->arguments ) ) { |
|
| 1703 | + echo "attributes : {"; |
|
| 1704 | + |
|
| 1705 | + if ( $show_advanced ) { |
|
| 1706 | + echo "show_advanced: {"; |
|
| 1707 | + echo " type: 'boolean',"; |
|
| 1708 | + echo " default: false,"; |
|
| 1709 | + echo "},"; |
|
| 1710 | + } |
|
| 1711 | + |
|
| 1712 | + // block wrap element |
|
| 1713 | + if ( ! empty( $this->options['block-wrap'] ) ) { //@todo we should validate this? |
|
| 1714 | + echo "block_wrap: {"; |
|
| 1715 | + echo " type: 'string',"; |
|
| 1716 | + echo " default: '" . esc_attr( $this->options['block-wrap'] ) . "',"; |
|
| 1717 | + echo "},"; |
|
| 1718 | + } |
|
| 1719 | + |
|
| 1720 | + foreach ( $this->arguments as $key => $args ) { |
|
| 1721 | + |
|
| 1722 | + // set if we should show alignment |
|
| 1723 | + if ( $key == 'alignment' ) { |
|
| 1724 | + $show_alignment = true; |
|
| 1725 | + } |
|
| 1726 | + |
|
| 1727 | + $extra = ''; |
|
| 1728 | + |
|
| 1729 | + if ( $args['type'] == 'checkbox' ) { |
|
| 1730 | + $type = 'boolean'; |
|
| 1731 | + $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false'; |
|
| 1732 | + } elseif ( $args['type'] == 'number' ) { |
|
| 1733 | + $type = 'number'; |
|
| 1734 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1735 | + } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) { |
|
| 1736 | + $type = 'array'; |
|
| 1737 | + if ( is_array( $args['default'] ) ) { |
|
| 1738 | + $default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]"; |
|
| 1739 | + } else { |
|
| 1740 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1741 | + } |
|
| 1742 | + } elseif ( $args['type'] == 'multiselect' ) { |
|
| 1743 | + $type = 'array'; |
|
| 1744 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1745 | + } else { |
|
| 1746 | + $type = 'string'; |
|
| 1747 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1748 | + } |
|
| 1749 | + echo $key . " : {"; |
|
| 1750 | + echo "type : '$type',"; |
|
| 1751 | + echo "default : $default,"; |
|
| 1752 | + echo "},"; |
|
| 1753 | + } |
|
| 1754 | + |
|
| 1755 | + echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},"; |
|
| 1756 | + echo "className: { type: 'string', default: '' },"; |
|
| 1757 | + |
|
| 1758 | + echo "},"; |
|
| 1759 | + |
|
| 1760 | + } |
|
| 1761 | + |
|
| 1762 | + ?> |
|
| 1763 | 1763 | |
| 1764 | 1764 | // The "edit" property must be a valid function. |
| 1765 | 1765 | edit: function (props) { |
@@ -1767,9 +1767,9 @@ discard block |
||
| 1767 | 1767 | |
| 1768 | 1768 | var $value = ''; |
| 1769 | 1769 | <?php |
| 1770 | - // if we have a post_type and a category then link them |
|
| 1771 | - if( isset($this->arguments['post_type']) && isset($this->arguments['category']) && !empty($this->arguments['category']['post_type_linked']) ){ |
|
| 1772 | - ?> |
|
| 1770 | + // if we have a post_type and a category then link them |
|
| 1771 | + if( isset($this->arguments['post_type']) && isset($this->arguments['category']) && !empty($this->arguments['category']['post_type_linked']) ){ |
|
| 1772 | + ?> |
|
| 1773 | 1773 | if(typeof(prev_attributes[props.id]) != 'undefined' ){ |
| 1774 | 1774 | $pt = props.attributes.post_type; |
| 1775 | 1775 | if(post_type_rest_slugs.length){ |
@@ -1853,8 +1853,8 @@ discard block |
||
| 1853 | 1853 | 'shortcode': '<?php echo $this->options['base_id'];?>', |
| 1854 | 1854 | 'attributes': props.attributes, |
| 1855 | 1855 | 'post_id': <?php global $post; if ( isset( $post->ID ) ) { |
| 1856 | - echo $post->ID; |
|
| 1857 | - }?>, |
|
| 1856 | + echo $post->ID; |
|
| 1857 | + }?>, |
|
| 1858 | 1858 | '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>' |
| 1859 | 1859 | }; |
| 1860 | 1860 | |
@@ -1906,10 +1906,10 @@ discard block |
||
| 1906 | 1906 | |
| 1907 | 1907 | <?php |
| 1908 | 1908 | |
| 1909 | - if(! empty( $this->arguments )){ |
|
| 1909 | + if(! empty( $this->arguments )){ |
|
| 1910 | 1910 | |
| 1911 | - if ( $show_advanced ) { |
|
| 1912 | - ?> |
|
| 1911 | + if ( $show_advanced ) { |
|
| 1912 | + ?> |
|
| 1913 | 1913 | el('div', { |
| 1914 | 1914 | style: {'padding-left': '16px','padding-right': '16px'} |
| 1915 | 1915 | }, |
@@ -1927,72 +1927,72 @@ discard block |
||
| 1927 | 1927 | , |
| 1928 | 1928 | <?php |
| 1929 | 1929 | |
| 1930 | - } |
|
| 1930 | + } |
|
| 1931 | 1931 | |
| 1932 | - $arguments = $this->group_arguments( $this->arguments ); |
|
| 1932 | + $arguments = $this->group_arguments( $this->arguments ); |
|
| 1933 | 1933 | |
| 1934 | - // Do we have sections? |
|
| 1935 | - $has_sections = $arguments == $this->arguments ? false : true; |
|
| 1934 | + // Do we have sections? |
|
| 1935 | + $has_sections = $arguments == $this->arguments ? false : true; |
|
| 1936 | 1936 | |
| 1937 | 1937 | |
| 1938 | - if($has_sections){ |
|
| 1939 | - $panel_count = 0; |
|
| 1940 | - foreach($arguments as $key => $args){ |
|
| 1941 | - ?> |
|
| 1938 | + if($has_sections){ |
|
| 1939 | + $panel_count = 0; |
|
| 1940 | + foreach($arguments as $key => $args){ |
|
| 1941 | + ?> |
|
| 1942 | 1942 | el(wp.components.PanelBody, { |
| 1943 | 1943 | title: '<?php esc_attr_e( $key ); ?>', |
| 1944 | 1944 | initialOpen: <?php if ( $panel_count ) { |
| 1945 | - echo "false"; |
|
| 1946 | - } else { |
|
| 1947 | - echo "true"; |
|
| 1948 | - }?> |
|
| 1945 | + echo "false"; |
|
| 1946 | + } else { |
|
| 1947 | + echo "true"; |
|
| 1948 | + }?> |
|
| 1949 | 1949 | }, |
| 1950 | 1950 | <?php |
| 1951 | 1951 | |
| 1952 | - foreach ( $args as $k => $a ) { |
|
| 1953 | - $this->build_block_arguments( $k, $a ); |
|
| 1954 | - } |
|
| 1955 | - ?> |
|
| 1952 | + foreach ( $args as $k => $a ) { |
|
| 1953 | + $this->build_block_arguments( $k, $a ); |
|
| 1954 | + } |
|
| 1955 | + ?> |
|
| 1956 | 1956 | ), |
| 1957 | 1957 | <?php |
| 1958 | - $panel_count ++; |
|
| 1958 | + $panel_count ++; |
|
| 1959 | 1959 | |
| 1960 | - } |
|
| 1961 | - }else { |
|
| 1962 | - ?> |
|
| 1960 | + } |
|
| 1961 | + }else { |
|
| 1962 | + ?> |
|
| 1963 | 1963 | el(wp.components.PanelBody, { |
| 1964 | 1964 | title: '<?php esc_attr_e( "Settings" ); ?>', |
| 1965 | 1965 | initialOpen: true |
| 1966 | 1966 | }, |
| 1967 | 1967 | <?php |
| 1968 | - foreach ( $this->arguments as $key => $args ) { |
|
| 1969 | - $this->build_block_arguments( $key, $args ); |
|
| 1970 | - } |
|
| 1971 | - ?> |
|
| 1968 | + foreach ( $this->arguments as $key => $args ) { |
|
| 1969 | + $this->build_block_arguments( $key, $args ); |
|
| 1970 | + } |
|
| 1971 | + ?> |
|
| 1972 | 1972 | ), |
| 1973 | 1973 | <?php |
| 1974 | - } |
|
| 1974 | + } |
|
| 1975 | 1975 | |
| 1976 | - } |
|
| 1977 | - ?> |
|
| 1976 | + } |
|
| 1977 | + ?> |
|
| 1978 | 1978 | |
| 1979 | 1979 | ), |
| 1980 | 1980 | |
| 1981 | 1981 | <?php |
| 1982 | - // If the user sets block-output array then build it |
|
| 1983 | - if ( ! empty( $this->options['block-output'] ) ) { |
|
| 1984 | - $this->block_element( $this->options['block-output'] ); |
|
| 1985 | - }else{ |
|
| 1986 | - // if no block-output is set then we try and get the shortcode html output via ajax. |
|
| 1987 | - ?> |
|
| 1982 | + // If the user sets block-output array then build it |
|
| 1983 | + if ( ! empty( $this->options['block-output'] ) ) { |
|
| 1984 | + $this->block_element( $this->options['block-output'] ); |
|
| 1985 | + }else{ |
|
| 1986 | + // if no block-output is set then we try and get the shortcode html output via ajax. |
|
| 1987 | + ?> |
|
| 1988 | 1988 | el('div', { |
| 1989 | 1989 | dangerouslySetInnerHTML: {__html: onChangeContent()}, |
| 1990 | 1990 | className: props.className, |
| 1991 | 1991 | style: {'minHeight': '30px'} |
| 1992 | 1992 | }) |
| 1993 | 1993 | <?php |
| 1994 | - } |
|
| 1995 | - ?> |
|
| 1994 | + } |
|
| 1995 | + ?> |
|
| 1996 | 1996 | ]; // end return |
| 1997 | 1997 | }, |
| 1998 | 1998 | |
@@ -2010,10 +2010,10 @@ discard block |
||
| 2010 | 2010 | $html = ''; |
| 2011 | 2011 | <?php |
| 2012 | 2012 | |
| 2013 | - if(! empty( $this->arguments )){ |
|
| 2013 | + if(! empty( $this->arguments )){ |
|
| 2014 | 2014 | |
| 2015 | - foreach($this->arguments as $key => $args){ |
|
| 2016 | - ?> |
|
| 2015 | + foreach($this->arguments as $key => $args){ |
|
| 2016 | + ?> |
|
| 2017 | 2017 | if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) { |
| 2018 | 2018 | if ('<?php echo esc_attr( $key );?>' == 'html') { |
| 2019 | 2019 | $html = attr.<?php echo esc_attr( $key );?>; |
@@ -2022,10 +2022,10 @@ discard block |
||
| 2022 | 2022 | } |
| 2023 | 2023 | } |
| 2024 | 2024 | <?php |
| 2025 | - } |
|
| 2026 | - } |
|
| 2025 | + } |
|
| 2026 | + } |
|
| 2027 | 2027 | |
| 2028 | - ?> |
|
| 2028 | + ?> |
|
| 2029 | 2029 | content += "]"; |
| 2030 | 2030 | |
| 2031 | 2031 | // if has html element |
@@ -2048,20 +2048,20 @@ discard block |
||
| 2048 | 2048 | } |
| 2049 | 2049 | |
| 2050 | 2050 | <?php |
| 2051 | - if(isset( $this->options['block-wrap'] ) && $this->options['block-wrap'] == ''){ |
|
| 2052 | - ?> |
|
| 2051 | + if(isset( $this->options['block-wrap'] ) && $this->options['block-wrap'] == ''){ |
|
| 2052 | + ?> |
|
| 2053 | 2053 | return content; |
| 2054 | 2054 | <?php |
| 2055 | - }else{ |
|
| 2056 | - ?> |
|
| 2055 | + }else{ |
|
| 2056 | + ?> |
|
| 2057 | 2057 | var block_wrap = 'div'; |
| 2058 | 2058 | if (attr.hasOwnProperty("block_wrap")) { |
| 2059 | 2059 | block_wrap = attr.block_wrap; |
| 2060 | 2060 | } |
| 2061 | 2061 | return el(block_wrap, {dangerouslySetInnerHTML: {__html: content}, className: align}); |
| 2062 | 2062 | <?php |
| 2063 | - } |
|
| 2064 | - ?> |
|
| 2063 | + } |
|
| 2064 | + ?> |
|
| 2065 | 2065 | |
| 2066 | 2066 | |
| 2067 | 2067 | } |
@@ -2069,48 +2069,48 @@ discard block |
||
| 2069 | 2069 | })(); |
| 2070 | 2070 | </script> |
| 2071 | 2071 | <?php |
| 2072 | - $output = ob_get_clean(); |
|
| 2072 | + $output = ob_get_clean(); |
|
| 2073 | 2073 | |
| 2074 | - /* |
|
| 2074 | + /* |
|
| 2075 | 2075 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 2076 | 2076 | */ |
| 2077 | 2077 | |
| 2078 | - return str_replace( array( |
|
| 2079 | - '<script>', |
|
| 2080 | - '</script>' |
|
| 2081 | - ), '', $output ); |
|
| 2082 | - } |
|
| 2083 | - |
|
| 2084 | - public function build_block_arguments( $key, $args ) { |
|
| 2085 | - $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : ''; |
|
| 2086 | - $options = ''; |
|
| 2087 | - $extra = ''; |
|
| 2088 | - $require = ''; |
|
| 2089 | - |
|
| 2090 | - // `content` is a protected and special argument |
|
| 2091 | - if ( $key == 'content' ) { |
|
| 2092 | - return; |
|
| 2093 | - } |
|
| 2094 | - |
|
| 2095 | - // require advanced |
|
| 2096 | - $require_advanced = ! empty( $args['advanced'] ) ? "props.attributes.show_advanced && " : ""; |
|
| 2097 | - |
|
| 2098 | - // element require |
|
| 2099 | - $element_require = ! empty( $args['element_require'] ) ? $this->block_props_replace( $args['element_require'], true ) . " && " : ""; |
|
| 2100 | - |
|
| 2101 | - |
|
| 2102 | - $onchange = "props.setAttributes({ $key: $key } )"; |
|
| 2103 | - $onchangecomplete = ""; |
|
| 2104 | - $value = "props.attributes.$key"; |
|
| 2105 | - $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'colorx' ); |
|
| 2106 | - if ( in_array( $args['type'], $text_type ) ) { |
|
| 2107 | - $type = 'TextControl'; |
|
| 2108 | - // Save numbers as numbers and not strings |
|
| 2109 | - if ( $args['type'] == 'number' ) { |
|
| 2110 | - $onchange = "props.setAttributes({ $key: Number($key) } )"; |
|
| 2111 | - } |
|
| 2112 | - } |
|
| 2113 | - /* |
|
| 2078 | + return str_replace( array( |
|
| 2079 | + '<script>', |
|
| 2080 | + '</script>' |
|
| 2081 | + ), '', $output ); |
|
| 2082 | + } |
|
| 2083 | + |
|
| 2084 | + public function build_block_arguments( $key, $args ) { |
|
| 2085 | + $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : ''; |
|
| 2086 | + $options = ''; |
|
| 2087 | + $extra = ''; |
|
| 2088 | + $require = ''; |
|
| 2089 | + |
|
| 2090 | + // `content` is a protected and special argument |
|
| 2091 | + if ( $key == 'content' ) { |
|
| 2092 | + return; |
|
| 2093 | + } |
|
| 2094 | + |
|
| 2095 | + // require advanced |
|
| 2096 | + $require_advanced = ! empty( $args['advanced'] ) ? "props.attributes.show_advanced && " : ""; |
|
| 2097 | + |
|
| 2098 | + // element require |
|
| 2099 | + $element_require = ! empty( $args['element_require'] ) ? $this->block_props_replace( $args['element_require'], true ) . " && " : ""; |
|
| 2100 | + |
|
| 2101 | + |
|
| 2102 | + $onchange = "props.setAttributes({ $key: $key } )"; |
|
| 2103 | + $onchangecomplete = ""; |
|
| 2104 | + $value = "props.attributes.$key"; |
|
| 2105 | + $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'colorx' ); |
|
| 2106 | + if ( in_array( $args['type'], $text_type ) ) { |
|
| 2107 | + $type = 'TextControl'; |
|
| 2108 | + // Save numbers as numbers and not strings |
|
| 2109 | + if ( $args['type'] == 'number' ) { |
|
| 2110 | + $onchange = "props.setAttributes({ $key: Number($key) } )"; |
|
| 2111 | + } |
|
| 2112 | + } |
|
| 2113 | + /* |
|
| 2114 | 2114 | * https://www.wptricks.com/question/set-current-tab-on-a-gutenberg-tabpanel-component-from-outside-that-component/ es5 layout |
| 2115 | 2115 | elseif($args['type']=='tabs'){ |
| 2116 | 2116 | ?> |
@@ -2144,80 +2144,80 @@ discard block |
||
| 2144 | 2144 | return; |
| 2145 | 2145 | } |
| 2146 | 2146 | */ |
| 2147 | - elseif ( $args['type'] == 'color' ) { |
|
| 2148 | - $type = 'ColorPicker'; |
|
| 2149 | - $onchange = ""; |
|
| 2150 | - $extra = "color: $value,"; |
|
| 2151 | - if(!empty($args['disable_alpha'])){ |
|
| 2152 | - $extra .= "disableAlpha: true,"; |
|
| 2153 | - } |
|
| 2154 | - $onchangecomplete = "onChangeComplete: function($key) { |
|
| 2147 | + elseif ( $args['type'] == 'color' ) { |
|
| 2148 | + $type = 'ColorPicker'; |
|
| 2149 | + $onchange = ""; |
|
| 2150 | + $extra = "color: $value,"; |
|
| 2151 | + if(!empty($args['disable_alpha'])){ |
|
| 2152 | + $extra .= "disableAlpha: true,"; |
|
| 2153 | + } |
|
| 2154 | + $onchangecomplete = "onChangeComplete: function($key) { |
|
| 2155 | 2155 | value = $key.rgb.a && $key.rgb.a < 1 ? \"rgba(\"+$key.rgb.r+\",\"+$key.rgb.g+\",\"+$key.rgb.b+\",\"+$key.rgb.a+\")\" : $key.hex; |
| 2156 | 2156 | props.setAttributes({ |
| 2157 | 2157 | $key: value |
| 2158 | 2158 | }); |
| 2159 | 2159 | },"; |
| 2160 | - } |
|
| 2161 | - elseif ( $args['type'] == 'checkbox' ) { |
|
| 2162 | - $type = 'CheckboxControl'; |
|
| 2163 | - $extra .= "checked: props.attributes.$key,"; |
|
| 2164 | - $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )"; |
|
| 2165 | - } elseif ( $args['type'] == 'textarea' ) { |
|
| 2166 | - $type = 'TextareaControl'; |
|
| 2167 | - } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) { |
|
| 2168 | - $type = 'SelectControl'; |
|
| 2169 | - |
|
| 2170 | - if($args['name'] == 'category' && !empty($args['post_type_linked'])){ |
|
| 2171 | - $options .= "options: taxonomies_".str_replace("-","_", $this->id).","; |
|
| 2172 | - }elseif($args['name'] == 'sort_by' && !empty($args['post_type_linked'])){ |
|
| 2173 | - $options .= "options: sort_by_".str_replace("-","_", $this->id).","; |
|
| 2174 | - }else { |
|
| 2175 | - |
|
| 2176 | - if ( ! empty( $args['options'] ) ) { |
|
| 2177 | - $options .= "options: ["; |
|
| 2178 | - foreach ( $args['options'] as $option_val => $option_label ) { |
|
| 2179 | - $options .= "{ value: '" . esc_attr( $option_val ) . "', label: '" . addslashes( $option_label ) . "' },"; |
|
| 2180 | - } |
|
| 2181 | - $options .= "],"; |
|
| 2182 | - } |
|
| 2183 | - } |
|
| 2184 | - if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
| 2185 | - $extra .= ' multiple: true, '; |
|
| 2186 | - } |
|
| 2187 | - } elseif ( $args['type'] == 'alignment' ) { |
|
| 2188 | - $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example |
|
| 2189 | - } else { |
|
| 2190 | - return;// if we have not implemented the control then don't break the JS. |
|
| 2191 | - } |
|
| 2192 | - |
|
| 2193 | - |
|
| 2194 | - |
|
| 2195 | - // color input does not show the labels so we add them |
|
| 2196 | - if($args['type']=='color'){ |
|
| 2197 | - // add show only if advanced |
|
| 2198 | - echo $require_advanced; |
|
| 2199 | - // add setting require if defined |
|
| 2200 | - echo $element_require; |
|
| 2201 | - echo "el('div', {style: {'marginBottom': '8px'}}, '".addslashes( $args['title'] )."'),"; |
|
| 2202 | - } |
|
| 2203 | - |
|
| 2204 | - // add show only if advanced |
|
| 2205 | - echo $require_advanced; |
|
| 2206 | - // add setting require if defined |
|
| 2207 | - echo $element_require; |
|
| 2208 | - ?> |
|
| 2160 | + } |
|
| 2161 | + elseif ( $args['type'] == 'checkbox' ) { |
|
| 2162 | + $type = 'CheckboxControl'; |
|
| 2163 | + $extra .= "checked: props.attributes.$key,"; |
|
| 2164 | + $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )"; |
|
| 2165 | + } elseif ( $args['type'] == 'textarea' ) { |
|
| 2166 | + $type = 'TextareaControl'; |
|
| 2167 | + } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) { |
|
| 2168 | + $type = 'SelectControl'; |
|
| 2169 | + |
|
| 2170 | + if($args['name'] == 'category' && !empty($args['post_type_linked'])){ |
|
| 2171 | + $options .= "options: taxonomies_".str_replace("-","_", $this->id).","; |
|
| 2172 | + }elseif($args['name'] == 'sort_by' && !empty($args['post_type_linked'])){ |
|
| 2173 | + $options .= "options: sort_by_".str_replace("-","_", $this->id).","; |
|
| 2174 | + }else { |
|
| 2175 | + |
|
| 2176 | + if ( ! empty( $args['options'] ) ) { |
|
| 2177 | + $options .= "options: ["; |
|
| 2178 | + foreach ( $args['options'] as $option_val => $option_label ) { |
|
| 2179 | + $options .= "{ value: '" . esc_attr( $option_val ) . "', label: '" . addslashes( $option_label ) . "' },"; |
|
| 2180 | + } |
|
| 2181 | + $options .= "],"; |
|
| 2182 | + } |
|
| 2183 | + } |
|
| 2184 | + if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
| 2185 | + $extra .= ' multiple: true, '; |
|
| 2186 | + } |
|
| 2187 | + } elseif ( $args['type'] == 'alignment' ) { |
|
| 2188 | + $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example |
|
| 2189 | + } else { |
|
| 2190 | + return;// if we have not implemented the control then don't break the JS. |
|
| 2191 | + } |
|
| 2192 | + |
|
| 2193 | + |
|
| 2194 | + |
|
| 2195 | + // color input does not show the labels so we add them |
|
| 2196 | + if($args['type']=='color'){ |
|
| 2197 | + // add show only if advanced |
|
| 2198 | + echo $require_advanced; |
|
| 2199 | + // add setting require if defined |
|
| 2200 | + echo $element_require; |
|
| 2201 | + echo "el('div', {style: {'marginBottom': '8px'}}, '".addslashes( $args['title'] )."'),"; |
|
| 2202 | + } |
|
| 2203 | + |
|
| 2204 | + // add show only if advanced |
|
| 2205 | + echo $require_advanced; |
|
| 2206 | + // add setting require if defined |
|
| 2207 | + echo $element_require; |
|
| 2208 | + ?> |
|
| 2209 | 2209 | el( wp.components.<?php echo $type; ?>, { |
| 2210 | 2210 | label: '<?php echo addslashes( $args['title'] ); ?>', |
| 2211 | 2211 | help: '<?php if ( isset( $args['desc'] ) ) { |
| 2212 | - echo addslashes( $args['desc'] ); |
|
| 2213 | - } ?>', |
|
| 2212 | + echo addslashes( $args['desc'] ); |
|
| 2213 | + } ?>', |
|
| 2214 | 2214 | value: <?php echo $value; ?>, |
| 2215 | 2215 | <?php if ( $type == 'TextControl' && $args['type'] != 'text' ) { |
| 2216 | - echo "type: '" . addslashes( $args['type'] ) . "',"; |
|
| 2217 | - } ?> |
|
| 2216 | + echo "type: '" . addslashes( $args['type'] ) . "',"; |
|
| 2217 | + } ?> |
|
| 2218 | 2218 | <?php if ( ! empty( $args['placeholder'] ) ) { |
| 2219 | - echo "placeholder: '" . addslashes( $args['placeholder'] ) . "',"; |
|
| 2220 | - } ?> |
|
| 2219 | + echo "placeholder: '" . addslashes( $args['placeholder'] ) . "',"; |
|
| 2220 | + } ?> |
|
| 2221 | 2221 | <?php echo $options; ?> |
| 2222 | 2222 | <?php echo $extra; ?> |
| 2223 | 2223 | <?php echo $custom_attributes; ?> |
@@ -2228,534 +2228,534 @@ discard block |
||
| 2228 | 2228 | } ), |
| 2229 | 2229 | <?php |
| 2230 | 2230 | |
| 2231 | - } |
|
| 2232 | - |
|
| 2233 | - /** |
|
| 2234 | - * Convert an array of attributes to block string. |
|
| 2235 | - * |
|
| 2236 | - * @todo there is prob a faster way to do this, also we could add some validation here. |
|
| 2237 | - * |
|
| 2238 | - * @param $custom_attributes |
|
| 2239 | - * |
|
| 2240 | - * @return string |
|
| 2241 | - */ |
|
| 2242 | - public function array_to_attributes( $custom_attributes, $html = false ) { |
|
| 2243 | - $attributes = ''; |
|
| 2244 | - if ( ! empty( $custom_attributes ) ) { |
|
| 2245 | - |
|
| 2246 | - if ( $html ) { |
|
| 2247 | - foreach ( $custom_attributes as $key => $val ) { |
|
| 2248 | - $attributes .= " $key='$val' "; |
|
| 2249 | - } |
|
| 2250 | - } else { |
|
| 2251 | - foreach ( $custom_attributes as $key => $val ) { |
|
| 2252 | - $attributes .= "'$key': '$val',"; |
|
| 2253 | - } |
|
| 2254 | - } |
|
| 2255 | - } |
|
| 2256 | - |
|
| 2257 | - return $attributes; |
|
| 2258 | - } |
|
| 2259 | - |
|
| 2260 | - /** |
|
| 2261 | - * A self looping function to create the output for JS block elements. |
|
| 2262 | - * |
|
| 2263 | - * This is what is output in the WP Editor visual view. |
|
| 2264 | - * |
|
| 2265 | - * @param $args |
|
| 2266 | - */ |
|
| 2267 | - public function block_element( $args ) { |
|
| 2268 | - |
|
| 2269 | - |
|
| 2270 | - if ( ! empty( $args ) ) { |
|
| 2271 | - foreach ( $args as $element => $new_args ) { |
|
| 2272 | - |
|
| 2273 | - if ( is_array( $new_args ) ) { // its an element |
|
| 2274 | - |
|
| 2275 | - |
|
| 2276 | - if ( isset( $new_args['element'] ) ) { |
|
| 2277 | - |
|
| 2278 | - if ( isset( $new_args['element_require'] ) ) { |
|
| 2279 | - echo str_replace( array( |
|
| 2280 | - "'+", |
|
| 2281 | - "+'" |
|
| 2282 | - ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " && "; |
|
| 2283 | - unset( $new_args['element_require'] ); |
|
| 2284 | - } |
|
| 2285 | - |
|
| 2286 | - echo "\n el( '" . $new_args['element'] . "', {"; |
|
| 2287 | - |
|
| 2288 | - // get the attributes |
|
| 2289 | - foreach ( $new_args as $new_key => $new_value ) { |
|
| 2290 | - |
|
| 2291 | - |
|
| 2292 | - if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) { |
|
| 2293 | - // do nothing |
|
| 2294 | - } else { |
|
| 2295 | - echo $this->block_element( array( $new_key => $new_value ) ); |
|
| 2296 | - } |
|
| 2297 | - } |
|
| 2298 | - |
|
| 2299 | - echo "},";// end attributes |
|
| 2300 | - |
|
| 2301 | - // get the content |
|
| 2302 | - $first_item = 0; |
|
| 2303 | - foreach ( $new_args as $new_key => $new_value ) { |
|
| 2304 | - if ( $new_key === 'content' || is_array( $new_value ) ) { |
|
| 2305 | - |
|
| 2306 | - if ( $new_key === 'content' ) { |
|
| 2307 | - echo "'" . $this->block_props_replace( wp_slash( $new_value ) ) . "'"; |
|
| 2308 | - } |
|
| 2309 | - |
|
| 2310 | - if ( is_array( $new_value ) ) { |
|
| 2311 | - |
|
| 2312 | - if ( isset( $new_value['element_require'] ) ) { |
|
| 2313 | - echo str_replace( array( |
|
| 2314 | - "'+", |
|
| 2315 | - "+'" |
|
| 2316 | - ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " && "; |
|
| 2317 | - unset( $new_value['element_require'] ); |
|
| 2318 | - } |
|
| 2319 | - |
|
| 2320 | - if ( isset( $new_value['element_repeat'] ) ) { |
|
| 2321 | - $x = 1; |
|
| 2322 | - while ( $x <= absint( $new_value['element_repeat'] ) ) { |
|
| 2323 | - $this->block_element( array( '' => $new_value ) ); |
|
| 2324 | - $x ++; |
|
| 2325 | - } |
|
| 2326 | - } else { |
|
| 2327 | - $this->block_element( array( '' => $new_value ) ); |
|
| 2328 | - } |
|
| 2329 | - } |
|
| 2330 | - $first_item ++; |
|
| 2331 | - } |
|
| 2332 | - } |
|
| 2333 | - |
|
| 2334 | - echo ")";// end content |
|
| 2335 | - |
|
| 2336 | - echo ", \n"; |
|
| 2337 | - |
|
| 2338 | - } |
|
| 2339 | - } else { |
|
| 2340 | - |
|
| 2341 | - if ( substr( $element, 0, 3 ) === "if_" ) { |
|
| 2342 | - echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ","; |
|
| 2343 | - } elseif ( $element == 'style' ) { |
|
| 2344 | - echo $element . ": " . $this->block_props_replace( $new_args ) . ","; |
|
| 2345 | - } else { |
|
| 2346 | - echo $element . ": '" . $this->block_props_replace( $new_args ) . "',"; |
|
| 2347 | - } |
|
| 2348 | - |
|
| 2349 | - } |
|
| 2350 | - } |
|
| 2351 | - } |
|
| 2352 | - } |
|
| 2353 | - |
|
| 2354 | - /** |
|
| 2355 | - * Replace block attributes placeholders with the proper naming. |
|
| 2356 | - * |
|
| 2357 | - * @param $string |
|
| 2358 | - * |
|
| 2359 | - * @return mixed |
|
| 2360 | - */ |
|
| 2361 | - public function block_props_replace( $string, $no_wrap = false ) { |
|
| 2362 | - |
|
| 2363 | - if ( $no_wrap ) { |
|
| 2364 | - $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string ); |
|
| 2365 | - } else { |
|
| 2366 | - $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string ); |
|
| 2367 | - } |
|
| 2368 | - |
|
| 2369 | - return $string; |
|
| 2370 | - } |
|
| 2371 | - |
|
| 2372 | - /** |
|
| 2373 | - * Outputs the content of the widget |
|
| 2374 | - * |
|
| 2375 | - * @param array $args |
|
| 2376 | - * @param array $instance |
|
| 2377 | - */ |
|
| 2378 | - public function widget( $args, $instance ) { |
|
| 2379 | - |
|
| 2380 | - // get the filtered values |
|
| 2381 | - $argument_values = $this->argument_values( $instance ); |
|
| 2382 | - $argument_values = $this->string_to_bool( $argument_values ); |
|
| 2383 | - $output = $this->output( $argument_values, $args ); |
|
| 2384 | - |
|
| 2385 | - $no_wrap = false; |
|
| 2386 | - if ( isset( $argument_values['no_wrap'] ) && $argument_values['no_wrap'] ) { |
|
| 2387 | - $no_wrap = true; |
|
| 2388 | - } |
|
| 2389 | - |
|
| 2390 | - ob_start(); |
|
| 2391 | - if ( $output && ! $no_wrap ) { |
|
| 2392 | - |
|
| 2393 | - $class_original = $this->options['widget_ops']['classname']; |
|
| 2394 | - $class = $this->options['widget_ops']['classname']." sdel-".$this->get_instance_hash(); |
|
| 2395 | - |
|
| 2396 | - // Before widget |
|
| 2397 | - $before_widget = $args['before_widget']; |
|
| 2398 | - $before_widget = str_replace($class_original,$class,$before_widget); |
|
| 2399 | - $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this ); |
|
| 2400 | - $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this ); |
|
| 2401 | - |
|
| 2402 | - // After widget |
|
| 2403 | - $after_widget = $args['after_widget']; |
|
| 2404 | - $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this ); |
|
| 2405 | - $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this ); |
|
| 2406 | - |
|
| 2407 | - echo $before_widget; |
|
| 2408 | - // elementor strips the widget wrapping div so we check for and add it back if needed |
|
| 2409 | - if ( $this->is_elementor_widget_output() ) { |
|
| 2410 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $class ) . "'>" : ''; |
|
| 2411 | - } |
|
| 2412 | - echo $this->output_title( $args, $instance ); |
|
| 2413 | - echo $output; |
|
| 2414 | - if ( $this->is_elementor_widget_output() ) { |
|
| 2415 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : ''; |
|
| 2416 | - } |
|
| 2417 | - echo $after_widget; |
|
| 2418 | - } elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty |
|
| 2419 | - $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" ); |
|
| 2420 | - echo $output; |
|
| 2421 | - } elseif ( $output && $no_wrap ) { |
|
| 2422 | - echo $output; |
|
| 2423 | - } |
|
| 2424 | - $output = ob_get_clean(); |
|
| 2425 | - |
|
| 2426 | - $output = apply_filters( 'wp_super_duper_widget_output', $output, $instance, $args, $this ); |
|
| 2427 | - |
|
| 2428 | - echo $output; |
|
| 2429 | - } |
|
| 2430 | - |
|
| 2431 | - /** |
|
| 2432 | - * Tests if the current output is inside a elementor container. |
|
| 2433 | - * |
|
| 2434 | - * @since 1.0.4 |
|
| 2435 | - * @return bool |
|
| 2436 | - */ |
|
| 2437 | - public function is_elementor_widget_output() { |
|
| 2438 | - $result = false; |
|
| 2439 | - if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) { |
|
| 2440 | - $result = true; |
|
| 2441 | - } |
|
| 2442 | - |
|
| 2443 | - return $result; |
|
| 2444 | - } |
|
| 2445 | - |
|
| 2446 | - /** |
|
| 2447 | - * Tests if the current output is inside a elementor preview. |
|
| 2448 | - * |
|
| 2449 | - * @since 1.0.4 |
|
| 2450 | - * @return bool |
|
| 2451 | - */ |
|
| 2452 | - public function is_elementor_preview() { |
|
| 2453 | - $result = false; |
|
| 2454 | - if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) { |
|
| 2455 | - $result = true; |
|
| 2456 | - } |
|
| 2457 | - |
|
| 2458 | - return $result; |
|
| 2459 | - } |
|
| 2460 | - |
|
| 2461 | - /** |
|
| 2462 | - * Tests if the current output is inside a Divi preview. |
|
| 2463 | - * |
|
| 2464 | - * @since 1.0.6 |
|
| 2465 | - * @return bool |
|
| 2466 | - */ |
|
| 2467 | - public function is_divi_preview() { |
|
| 2468 | - $result = false; |
|
| 2469 | - if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) { |
|
| 2470 | - $result = true; |
|
| 2471 | - } |
|
| 2472 | - |
|
| 2473 | - return $result; |
|
| 2474 | - } |
|
| 2475 | - |
|
| 2476 | - /** |
|
| 2477 | - * Tests if the current output is inside a Beaver builder preview. |
|
| 2478 | - * |
|
| 2479 | - * @since 1.0.6 |
|
| 2480 | - * @return bool |
|
| 2481 | - */ |
|
| 2482 | - public function is_beaver_preview() { |
|
| 2483 | - $result = false; |
|
| 2484 | - if ( isset( $_REQUEST['fl_builder'] ) ) { |
|
| 2485 | - $result = true; |
|
| 2486 | - } |
|
| 2487 | - |
|
| 2488 | - return $result; |
|
| 2489 | - } |
|
| 2490 | - |
|
| 2491 | - /** |
|
| 2492 | - * Tests if the current output is inside a siteorigin builder preview. |
|
| 2493 | - * |
|
| 2494 | - * @since 1.0.6 |
|
| 2495 | - * @return bool |
|
| 2496 | - */ |
|
| 2497 | - public function is_siteorigin_preview() { |
|
| 2498 | - $result = false; |
|
| 2499 | - if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) { |
|
| 2500 | - $result = true; |
|
| 2501 | - } |
|
| 2502 | - |
|
| 2503 | - return $result; |
|
| 2504 | - } |
|
| 2505 | - |
|
| 2506 | - /** |
|
| 2507 | - * Tests if the current output is inside a cornerstone builder preview. |
|
| 2508 | - * |
|
| 2509 | - * @since 1.0.8 |
|
| 2510 | - * @return bool |
|
| 2511 | - */ |
|
| 2512 | - public function is_cornerstone_preview() { |
|
| 2513 | - $result = false; |
|
| 2514 | - if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) { |
|
| 2515 | - $result = true; |
|
| 2516 | - } |
|
| 2517 | - |
|
| 2518 | - return $result; |
|
| 2519 | - } |
|
| 2520 | - |
|
| 2521 | - /** |
|
| 2522 | - * Tests if the current output is inside a fusion builder preview. |
|
| 2523 | - * |
|
| 2524 | - * @since 1.1.0 |
|
| 2525 | - * @return bool |
|
| 2526 | - */ |
|
| 2527 | - public function is_fusion_preview() { |
|
| 2528 | - $result = false; |
|
| 2529 | - if ( ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ) ) { |
|
| 2530 | - $result = true; |
|
| 2531 | - } |
|
| 2532 | - |
|
| 2533 | - return $result; |
|
| 2534 | - } |
|
| 2535 | - |
|
| 2536 | - /** |
|
| 2537 | - * Tests if the current output is inside a Oxygen builder preview. |
|
| 2538 | - * |
|
| 2539 | - * @since 1.0.18 |
|
| 2540 | - * @return bool |
|
| 2541 | - */ |
|
| 2542 | - public function is_oxygen_preview() { |
|
| 2543 | - $result = false; |
|
| 2544 | - if ( ! empty( $_REQUEST['ct_builder'] ) || ( ! empty( $_REQUEST['action'] ) && ( substr( $_REQUEST['action'], 0, 11 ) === "oxy_render_" || substr( $_REQUEST['action'], 0, 10 ) === "ct_render_" ) ) ) { |
|
| 2545 | - $result = true; |
|
| 2546 | - } |
|
| 2547 | - |
|
| 2548 | - return $result; |
|
| 2549 | - } |
|
| 2550 | - |
|
| 2551 | - /** |
|
| 2552 | - * General function to check if we are in a preview situation. |
|
| 2553 | - * |
|
| 2554 | - * @since 1.0.6 |
|
| 2555 | - * @return bool |
|
| 2556 | - */ |
|
| 2557 | - public function is_preview() { |
|
| 2558 | - $preview = false; |
|
| 2559 | - if ( $this->is_divi_preview() ) { |
|
| 2560 | - $preview = true; |
|
| 2561 | - } elseif ( $this->is_elementor_preview() ) { |
|
| 2562 | - $preview = true; |
|
| 2563 | - } elseif ( $this->is_beaver_preview() ) { |
|
| 2564 | - $preview = true; |
|
| 2565 | - } elseif ( $this->is_siteorigin_preview() ) { |
|
| 2566 | - $preview = true; |
|
| 2567 | - } elseif ( $this->is_cornerstone_preview() ) { |
|
| 2568 | - $preview = true; |
|
| 2569 | - } elseif ( $this->is_fusion_preview() ) { |
|
| 2570 | - $preview = true; |
|
| 2571 | - } elseif ( $this->is_oxygen_preview() ) { |
|
| 2572 | - $preview = true; |
|
| 2573 | - } elseif( $this->is_block_content_call() ) { |
|
| 2574 | - $preview = true; |
|
| 2575 | - } |
|
| 2576 | - |
|
| 2577 | - return $preview; |
|
| 2578 | - } |
|
| 2579 | - |
|
| 2580 | - /** |
|
| 2581 | - * Output the super title. |
|
| 2582 | - * |
|
| 2583 | - * @param $args |
|
| 2584 | - * @param array $instance |
|
| 2585 | - * |
|
| 2586 | - * @return string |
|
| 2587 | - */ |
|
| 2588 | - public function output_title( $args, $instance = array() ) { |
|
| 2589 | - $output = ''; |
|
| 2590 | - if ( ! empty( $instance['title'] ) ) { |
|
| 2591 | - /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
|
| 2592 | - $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
|
| 2593 | - $output = $args['before_title'] . $title . $args['after_title']; |
|
| 2594 | - } |
|
| 2595 | - |
|
| 2596 | - return $output; |
|
| 2597 | - } |
|
| 2598 | - |
|
| 2599 | - /** |
|
| 2600 | - * Outputs the options form inputs for the widget. |
|
| 2601 | - * |
|
| 2602 | - * @param array $instance The widget options. |
|
| 2603 | - */ |
|
| 2604 | - public function form( $instance ) { |
|
| 2605 | - |
|
| 2606 | - // set widget instance |
|
| 2607 | - $this->instance = $instance; |
|
| 2608 | - |
|
| 2609 | - // set it as a SD widget |
|
| 2610 | - echo $this->widget_advanced_toggle(); |
|
| 2611 | - |
|
| 2612 | - echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>"; |
|
| 2613 | - $arguments_raw = $this->get_arguments(); |
|
| 2614 | - |
|
| 2615 | - if ( is_array( $arguments_raw ) ) { |
|
| 2616 | - |
|
| 2617 | - $arguments = $this->group_arguments( $arguments_raw ); |
|
| 2618 | - |
|
| 2619 | - // Do we have sections? |
|
| 2620 | - $has_sections = $arguments == $arguments_raw ? false : true; |
|
| 2621 | - |
|
| 2622 | - |
|
| 2623 | - if ( $has_sections ) { |
|
| 2624 | - $panel_count = 0; |
|
| 2625 | - foreach ( $arguments as $key => $args ) { |
|
| 2626 | - |
|
| 2627 | - ?> |
|
| 2231 | + } |
|
| 2232 | + |
|
| 2233 | + /** |
|
| 2234 | + * Convert an array of attributes to block string. |
|
| 2235 | + * |
|
| 2236 | + * @todo there is prob a faster way to do this, also we could add some validation here. |
|
| 2237 | + * |
|
| 2238 | + * @param $custom_attributes |
|
| 2239 | + * |
|
| 2240 | + * @return string |
|
| 2241 | + */ |
|
| 2242 | + public function array_to_attributes( $custom_attributes, $html = false ) { |
|
| 2243 | + $attributes = ''; |
|
| 2244 | + if ( ! empty( $custom_attributes ) ) { |
|
| 2245 | + |
|
| 2246 | + if ( $html ) { |
|
| 2247 | + foreach ( $custom_attributes as $key => $val ) { |
|
| 2248 | + $attributes .= " $key='$val' "; |
|
| 2249 | + } |
|
| 2250 | + } else { |
|
| 2251 | + foreach ( $custom_attributes as $key => $val ) { |
|
| 2252 | + $attributes .= "'$key': '$val',"; |
|
| 2253 | + } |
|
| 2254 | + } |
|
| 2255 | + } |
|
| 2256 | + |
|
| 2257 | + return $attributes; |
|
| 2258 | + } |
|
| 2259 | + |
|
| 2260 | + /** |
|
| 2261 | + * A self looping function to create the output for JS block elements. |
|
| 2262 | + * |
|
| 2263 | + * This is what is output in the WP Editor visual view. |
|
| 2264 | + * |
|
| 2265 | + * @param $args |
|
| 2266 | + */ |
|
| 2267 | + public function block_element( $args ) { |
|
| 2268 | + |
|
| 2269 | + |
|
| 2270 | + if ( ! empty( $args ) ) { |
|
| 2271 | + foreach ( $args as $element => $new_args ) { |
|
| 2272 | + |
|
| 2273 | + if ( is_array( $new_args ) ) { // its an element |
|
| 2274 | + |
|
| 2275 | + |
|
| 2276 | + if ( isset( $new_args['element'] ) ) { |
|
| 2277 | + |
|
| 2278 | + if ( isset( $new_args['element_require'] ) ) { |
|
| 2279 | + echo str_replace( array( |
|
| 2280 | + "'+", |
|
| 2281 | + "+'" |
|
| 2282 | + ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " && "; |
|
| 2283 | + unset( $new_args['element_require'] ); |
|
| 2284 | + } |
|
| 2285 | + |
|
| 2286 | + echo "\n el( '" . $new_args['element'] . "', {"; |
|
| 2287 | + |
|
| 2288 | + // get the attributes |
|
| 2289 | + foreach ( $new_args as $new_key => $new_value ) { |
|
| 2290 | + |
|
| 2291 | + |
|
| 2292 | + if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) { |
|
| 2293 | + // do nothing |
|
| 2294 | + } else { |
|
| 2295 | + echo $this->block_element( array( $new_key => $new_value ) ); |
|
| 2296 | + } |
|
| 2297 | + } |
|
| 2298 | + |
|
| 2299 | + echo "},";// end attributes |
|
| 2300 | + |
|
| 2301 | + // get the content |
|
| 2302 | + $first_item = 0; |
|
| 2303 | + foreach ( $new_args as $new_key => $new_value ) { |
|
| 2304 | + if ( $new_key === 'content' || is_array( $new_value ) ) { |
|
| 2305 | + |
|
| 2306 | + if ( $new_key === 'content' ) { |
|
| 2307 | + echo "'" . $this->block_props_replace( wp_slash( $new_value ) ) . "'"; |
|
| 2308 | + } |
|
| 2309 | + |
|
| 2310 | + if ( is_array( $new_value ) ) { |
|
| 2311 | + |
|
| 2312 | + if ( isset( $new_value['element_require'] ) ) { |
|
| 2313 | + echo str_replace( array( |
|
| 2314 | + "'+", |
|
| 2315 | + "+'" |
|
| 2316 | + ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " && "; |
|
| 2317 | + unset( $new_value['element_require'] ); |
|
| 2318 | + } |
|
| 2319 | + |
|
| 2320 | + if ( isset( $new_value['element_repeat'] ) ) { |
|
| 2321 | + $x = 1; |
|
| 2322 | + while ( $x <= absint( $new_value['element_repeat'] ) ) { |
|
| 2323 | + $this->block_element( array( '' => $new_value ) ); |
|
| 2324 | + $x ++; |
|
| 2325 | + } |
|
| 2326 | + } else { |
|
| 2327 | + $this->block_element( array( '' => $new_value ) ); |
|
| 2328 | + } |
|
| 2329 | + } |
|
| 2330 | + $first_item ++; |
|
| 2331 | + } |
|
| 2332 | + } |
|
| 2333 | + |
|
| 2334 | + echo ")";// end content |
|
| 2335 | + |
|
| 2336 | + echo ", \n"; |
|
| 2337 | + |
|
| 2338 | + } |
|
| 2339 | + } else { |
|
| 2340 | + |
|
| 2341 | + if ( substr( $element, 0, 3 ) === "if_" ) { |
|
| 2342 | + echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ","; |
|
| 2343 | + } elseif ( $element == 'style' ) { |
|
| 2344 | + echo $element . ": " . $this->block_props_replace( $new_args ) . ","; |
|
| 2345 | + } else { |
|
| 2346 | + echo $element . ": '" . $this->block_props_replace( $new_args ) . "',"; |
|
| 2347 | + } |
|
| 2348 | + |
|
| 2349 | + } |
|
| 2350 | + } |
|
| 2351 | + } |
|
| 2352 | + } |
|
| 2353 | + |
|
| 2354 | + /** |
|
| 2355 | + * Replace block attributes placeholders with the proper naming. |
|
| 2356 | + * |
|
| 2357 | + * @param $string |
|
| 2358 | + * |
|
| 2359 | + * @return mixed |
|
| 2360 | + */ |
|
| 2361 | + public function block_props_replace( $string, $no_wrap = false ) { |
|
| 2362 | + |
|
| 2363 | + if ( $no_wrap ) { |
|
| 2364 | + $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string ); |
|
| 2365 | + } else { |
|
| 2366 | + $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string ); |
|
| 2367 | + } |
|
| 2368 | + |
|
| 2369 | + return $string; |
|
| 2370 | + } |
|
| 2371 | + |
|
| 2372 | + /** |
|
| 2373 | + * Outputs the content of the widget |
|
| 2374 | + * |
|
| 2375 | + * @param array $args |
|
| 2376 | + * @param array $instance |
|
| 2377 | + */ |
|
| 2378 | + public function widget( $args, $instance ) { |
|
| 2379 | + |
|
| 2380 | + // get the filtered values |
|
| 2381 | + $argument_values = $this->argument_values( $instance ); |
|
| 2382 | + $argument_values = $this->string_to_bool( $argument_values ); |
|
| 2383 | + $output = $this->output( $argument_values, $args ); |
|
| 2384 | + |
|
| 2385 | + $no_wrap = false; |
|
| 2386 | + if ( isset( $argument_values['no_wrap'] ) && $argument_values['no_wrap'] ) { |
|
| 2387 | + $no_wrap = true; |
|
| 2388 | + } |
|
| 2389 | + |
|
| 2390 | + ob_start(); |
|
| 2391 | + if ( $output && ! $no_wrap ) { |
|
| 2392 | + |
|
| 2393 | + $class_original = $this->options['widget_ops']['classname']; |
|
| 2394 | + $class = $this->options['widget_ops']['classname']." sdel-".$this->get_instance_hash(); |
|
| 2395 | + |
|
| 2396 | + // Before widget |
|
| 2397 | + $before_widget = $args['before_widget']; |
|
| 2398 | + $before_widget = str_replace($class_original,$class,$before_widget); |
|
| 2399 | + $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this ); |
|
| 2400 | + $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this ); |
|
| 2401 | + |
|
| 2402 | + // After widget |
|
| 2403 | + $after_widget = $args['after_widget']; |
|
| 2404 | + $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this ); |
|
| 2405 | + $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this ); |
|
| 2406 | + |
|
| 2407 | + echo $before_widget; |
|
| 2408 | + // elementor strips the widget wrapping div so we check for and add it back if needed |
|
| 2409 | + if ( $this->is_elementor_widget_output() ) { |
|
| 2410 | + echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $class ) . "'>" : ''; |
|
| 2411 | + } |
|
| 2412 | + echo $this->output_title( $args, $instance ); |
|
| 2413 | + echo $output; |
|
| 2414 | + if ( $this->is_elementor_widget_output() ) { |
|
| 2415 | + echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : ''; |
|
| 2416 | + } |
|
| 2417 | + echo $after_widget; |
|
| 2418 | + } elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty |
|
| 2419 | + $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" ); |
|
| 2420 | + echo $output; |
|
| 2421 | + } elseif ( $output && $no_wrap ) { |
|
| 2422 | + echo $output; |
|
| 2423 | + } |
|
| 2424 | + $output = ob_get_clean(); |
|
| 2425 | + |
|
| 2426 | + $output = apply_filters( 'wp_super_duper_widget_output', $output, $instance, $args, $this ); |
|
| 2427 | + |
|
| 2428 | + echo $output; |
|
| 2429 | + } |
|
| 2430 | + |
|
| 2431 | + /** |
|
| 2432 | + * Tests if the current output is inside a elementor container. |
|
| 2433 | + * |
|
| 2434 | + * @since 1.0.4 |
|
| 2435 | + * @return bool |
|
| 2436 | + */ |
|
| 2437 | + public function is_elementor_widget_output() { |
|
| 2438 | + $result = false; |
|
| 2439 | + if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) { |
|
| 2440 | + $result = true; |
|
| 2441 | + } |
|
| 2442 | + |
|
| 2443 | + return $result; |
|
| 2444 | + } |
|
| 2445 | + |
|
| 2446 | + /** |
|
| 2447 | + * Tests if the current output is inside a elementor preview. |
|
| 2448 | + * |
|
| 2449 | + * @since 1.0.4 |
|
| 2450 | + * @return bool |
|
| 2451 | + */ |
|
| 2452 | + public function is_elementor_preview() { |
|
| 2453 | + $result = false; |
|
| 2454 | + if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) { |
|
| 2455 | + $result = true; |
|
| 2456 | + } |
|
| 2457 | + |
|
| 2458 | + return $result; |
|
| 2459 | + } |
|
| 2460 | + |
|
| 2461 | + /** |
|
| 2462 | + * Tests if the current output is inside a Divi preview. |
|
| 2463 | + * |
|
| 2464 | + * @since 1.0.6 |
|
| 2465 | + * @return bool |
|
| 2466 | + */ |
|
| 2467 | + public function is_divi_preview() { |
|
| 2468 | + $result = false; |
|
| 2469 | + if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) { |
|
| 2470 | + $result = true; |
|
| 2471 | + } |
|
| 2472 | + |
|
| 2473 | + return $result; |
|
| 2474 | + } |
|
| 2475 | + |
|
| 2476 | + /** |
|
| 2477 | + * Tests if the current output is inside a Beaver builder preview. |
|
| 2478 | + * |
|
| 2479 | + * @since 1.0.6 |
|
| 2480 | + * @return bool |
|
| 2481 | + */ |
|
| 2482 | + public function is_beaver_preview() { |
|
| 2483 | + $result = false; |
|
| 2484 | + if ( isset( $_REQUEST['fl_builder'] ) ) { |
|
| 2485 | + $result = true; |
|
| 2486 | + } |
|
| 2487 | + |
|
| 2488 | + return $result; |
|
| 2489 | + } |
|
| 2490 | + |
|
| 2491 | + /** |
|
| 2492 | + * Tests if the current output is inside a siteorigin builder preview. |
|
| 2493 | + * |
|
| 2494 | + * @since 1.0.6 |
|
| 2495 | + * @return bool |
|
| 2496 | + */ |
|
| 2497 | + public function is_siteorigin_preview() { |
|
| 2498 | + $result = false; |
|
| 2499 | + if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) { |
|
| 2500 | + $result = true; |
|
| 2501 | + } |
|
| 2502 | + |
|
| 2503 | + return $result; |
|
| 2504 | + } |
|
| 2505 | + |
|
| 2506 | + /** |
|
| 2507 | + * Tests if the current output is inside a cornerstone builder preview. |
|
| 2508 | + * |
|
| 2509 | + * @since 1.0.8 |
|
| 2510 | + * @return bool |
|
| 2511 | + */ |
|
| 2512 | + public function is_cornerstone_preview() { |
|
| 2513 | + $result = false; |
|
| 2514 | + if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) { |
|
| 2515 | + $result = true; |
|
| 2516 | + } |
|
| 2517 | + |
|
| 2518 | + return $result; |
|
| 2519 | + } |
|
| 2520 | + |
|
| 2521 | + /** |
|
| 2522 | + * Tests if the current output is inside a fusion builder preview. |
|
| 2523 | + * |
|
| 2524 | + * @since 1.1.0 |
|
| 2525 | + * @return bool |
|
| 2526 | + */ |
|
| 2527 | + public function is_fusion_preview() { |
|
| 2528 | + $result = false; |
|
| 2529 | + if ( ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ) ) { |
|
| 2530 | + $result = true; |
|
| 2531 | + } |
|
| 2532 | + |
|
| 2533 | + return $result; |
|
| 2534 | + } |
|
| 2535 | + |
|
| 2536 | + /** |
|
| 2537 | + * Tests if the current output is inside a Oxygen builder preview. |
|
| 2538 | + * |
|
| 2539 | + * @since 1.0.18 |
|
| 2540 | + * @return bool |
|
| 2541 | + */ |
|
| 2542 | + public function is_oxygen_preview() { |
|
| 2543 | + $result = false; |
|
| 2544 | + if ( ! empty( $_REQUEST['ct_builder'] ) || ( ! empty( $_REQUEST['action'] ) && ( substr( $_REQUEST['action'], 0, 11 ) === "oxy_render_" || substr( $_REQUEST['action'], 0, 10 ) === "ct_render_" ) ) ) { |
|
| 2545 | + $result = true; |
|
| 2546 | + } |
|
| 2547 | + |
|
| 2548 | + return $result; |
|
| 2549 | + } |
|
| 2550 | + |
|
| 2551 | + /** |
|
| 2552 | + * General function to check if we are in a preview situation. |
|
| 2553 | + * |
|
| 2554 | + * @since 1.0.6 |
|
| 2555 | + * @return bool |
|
| 2556 | + */ |
|
| 2557 | + public function is_preview() { |
|
| 2558 | + $preview = false; |
|
| 2559 | + if ( $this->is_divi_preview() ) { |
|
| 2560 | + $preview = true; |
|
| 2561 | + } elseif ( $this->is_elementor_preview() ) { |
|
| 2562 | + $preview = true; |
|
| 2563 | + } elseif ( $this->is_beaver_preview() ) { |
|
| 2564 | + $preview = true; |
|
| 2565 | + } elseif ( $this->is_siteorigin_preview() ) { |
|
| 2566 | + $preview = true; |
|
| 2567 | + } elseif ( $this->is_cornerstone_preview() ) { |
|
| 2568 | + $preview = true; |
|
| 2569 | + } elseif ( $this->is_fusion_preview() ) { |
|
| 2570 | + $preview = true; |
|
| 2571 | + } elseif ( $this->is_oxygen_preview() ) { |
|
| 2572 | + $preview = true; |
|
| 2573 | + } elseif( $this->is_block_content_call() ) { |
|
| 2574 | + $preview = true; |
|
| 2575 | + } |
|
| 2576 | + |
|
| 2577 | + return $preview; |
|
| 2578 | + } |
|
| 2579 | + |
|
| 2580 | + /** |
|
| 2581 | + * Output the super title. |
|
| 2582 | + * |
|
| 2583 | + * @param $args |
|
| 2584 | + * @param array $instance |
|
| 2585 | + * |
|
| 2586 | + * @return string |
|
| 2587 | + */ |
|
| 2588 | + public function output_title( $args, $instance = array() ) { |
|
| 2589 | + $output = ''; |
|
| 2590 | + if ( ! empty( $instance['title'] ) ) { |
|
| 2591 | + /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
|
| 2592 | + $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
|
| 2593 | + $output = $args['before_title'] . $title . $args['after_title']; |
|
| 2594 | + } |
|
| 2595 | + |
|
| 2596 | + return $output; |
|
| 2597 | + } |
|
| 2598 | + |
|
| 2599 | + /** |
|
| 2600 | + * Outputs the options form inputs for the widget. |
|
| 2601 | + * |
|
| 2602 | + * @param array $instance The widget options. |
|
| 2603 | + */ |
|
| 2604 | + public function form( $instance ) { |
|
| 2605 | + |
|
| 2606 | + // set widget instance |
|
| 2607 | + $this->instance = $instance; |
|
| 2608 | + |
|
| 2609 | + // set it as a SD widget |
|
| 2610 | + echo $this->widget_advanced_toggle(); |
|
| 2611 | + |
|
| 2612 | + echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>"; |
|
| 2613 | + $arguments_raw = $this->get_arguments(); |
|
| 2614 | + |
|
| 2615 | + if ( is_array( $arguments_raw ) ) { |
|
| 2616 | + |
|
| 2617 | + $arguments = $this->group_arguments( $arguments_raw ); |
|
| 2618 | + |
|
| 2619 | + // Do we have sections? |
|
| 2620 | + $has_sections = $arguments == $arguments_raw ? false : true; |
|
| 2621 | + |
|
| 2622 | + |
|
| 2623 | + if ( $has_sections ) { |
|
| 2624 | + $panel_count = 0; |
|
| 2625 | + foreach ( $arguments as $key => $args ) { |
|
| 2626 | + |
|
| 2627 | + ?> |
|
| 2628 | 2628 | <script> |
| 2629 | 2629 | // jQuery(this).find("i").toggleClass("fas fa-chevron-up fas fa-chevron-down");jQuery(this).next().toggle(); |
| 2630 | 2630 | </script> |
| 2631 | 2631 | <?php |
| 2632 | 2632 | |
| 2633 | - $hide = $panel_count ? ' style="display:none;" ' : ''; |
|
| 2634 | - $icon_class = $panel_count ? 'fas fa-chevron-up' : 'fas fa-chevron-down'; |
|
| 2635 | - echo "<button onclick='jQuery(this).find(\"i\").toggleClass(\"fas fa-chevron-up fas fa-chevron-down\");jQuery(this).next().slideToggle();' type='button' class='sd-toggle-group-button sd-input-group-toggle" . sanitize_title_with_dashes( $key ) . "'>" . esc_attr( $key ) . " <i style='float:right;' class='" . $icon_class . "'></i></button>"; |
|
| 2636 | - echo "<div class='sd-toggle-group sd-input-group-" . sanitize_title_with_dashes( $key ) . "' $hide>"; |
|
| 2637 | - |
|
| 2638 | - foreach ( $args as $k => $a ) { |
|
| 2639 | - $this->widget_inputs( $a, $instance ); |
|
| 2640 | - } |
|
| 2641 | - |
|
| 2642 | - echo "</div>"; |
|
| 2643 | - |
|
| 2644 | - $panel_count ++; |
|
| 2645 | - |
|
| 2646 | - } |
|
| 2647 | - } else { |
|
| 2648 | - foreach ( $arguments as $key => $args ) { |
|
| 2649 | - $this->widget_inputs( $args, $instance ); |
|
| 2650 | - } |
|
| 2651 | - } |
|
| 2652 | - |
|
| 2653 | - } |
|
| 2654 | - } |
|
| 2655 | - |
|
| 2656 | - /** |
|
| 2657 | - * Get the hidden input that when added makes the advanced button show on widget settings. |
|
| 2658 | - * |
|
| 2659 | - * @return string |
|
| 2660 | - */ |
|
| 2661 | - public function widget_advanced_toggle() { |
|
| 2662 | - |
|
| 2663 | - $output = ''; |
|
| 2664 | - if ( $this->block_show_advanced() ) { |
|
| 2665 | - $val = 1; |
|
| 2666 | - } else { |
|
| 2667 | - $val = 0; |
|
| 2668 | - } |
|
| 2669 | - |
|
| 2670 | - $output .= "<input type='hidden' class='sd-show-advanced' value='$val' />"; |
|
| 2671 | - |
|
| 2672 | - return $output; |
|
| 2673 | - } |
|
| 2674 | - |
|
| 2675 | - /** |
|
| 2676 | - * Convert require element. |
|
| 2677 | - * |
|
| 2678 | - * @since 1.0.0 |
|
| 2679 | - * |
|
| 2680 | - * @param string $input Input element. |
|
| 2681 | - * |
|
| 2682 | - * @return string $output |
|
| 2683 | - */ |
|
| 2684 | - public function convert_element_require( $input ) { |
|
| 2685 | - |
|
| 2686 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
| 2687 | - |
|
| 2688 | - $output = esc_attr( str_replace( array( "[%", "%]" ), array( |
|
| 2689 | - "jQuery(form).find('[data-argument=\"", |
|
| 2690 | - "\"]').find('input,select,textarea').val()" |
|
| 2691 | - ), $input ) ); |
|
| 2692 | - |
|
| 2693 | - return $output; |
|
| 2694 | - } |
|
| 2695 | - |
|
| 2696 | - /** |
|
| 2697 | - * Builds the inputs for the widget options. |
|
| 2698 | - * |
|
| 2699 | - * @param $args |
|
| 2700 | - * @param $instance |
|
| 2701 | - */ |
|
| 2702 | - public function widget_inputs( $args, $instance ) { |
|
| 2703 | - |
|
| 2704 | - $class = ""; |
|
| 2705 | - $element_require = ""; |
|
| 2706 | - $custom_attributes = ""; |
|
| 2707 | - |
|
| 2708 | - // get value |
|
| 2709 | - if ( isset( $instance[ $args['name'] ] ) ) { |
|
| 2710 | - $value = $instance[ $args['name'] ]; |
|
| 2711 | - } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) { |
|
| 2712 | - $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] ); |
|
| 2713 | - } else { |
|
| 2714 | - $value = ''; |
|
| 2715 | - } |
|
| 2716 | - |
|
| 2717 | - // get placeholder |
|
| 2718 | - if ( ! empty( $args['placeholder'] ) ) { |
|
| 2719 | - $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'"; |
|
| 2720 | - } else { |
|
| 2721 | - $placeholder = ''; |
|
| 2722 | - } |
|
| 2723 | - |
|
| 2724 | - // get if advanced |
|
| 2725 | - if ( isset( $args['advanced'] ) && $args['advanced'] ) { |
|
| 2726 | - $class .= " sd-advanced-setting "; |
|
| 2727 | - } |
|
| 2728 | - |
|
| 2729 | - // element_require |
|
| 2730 | - if ( isset( $args['element_require'] ) && $args['element_require'] ) { |
|
| 2731 | - $element_require = $args['element_require']; |
|
| 2732 | - } |
|
| 2733 | - |
|
| 2734 | - // custom_attributes |
|
| 2735 | - if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) { |
|
| 2736 | - $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true ); |
|
| 2737 | - } |
|
| 2738 | - |
|
| 2739 | - // before wrapper |
|
| 2740 | - ?> |
|
| 2633 | + $hide = $panel_count ? ' style="display:none;" ' : ''; |
|
| 2634 | + $icon_class = $panel_count ? 'fas fa-chevron-up' : 'fas fa-chevron-down'; |
|
| 2635 | + echo "<button onclick='jQuery(this).find(\"i\").toggleClass(\"fas fa-chevron-up fas fa-chevron-down\");jQuery(this).next().slideToggle();' type='button' class='sd-toggle-group-button sd-input-group-toggle" . sanitize_title_with_dashes( $key ) . "'>" . esc_attr( $key ) . " <i style='float:right;' class='" . $icon_class . "'></i></button>"; |
|
| 2636 | + echo "<div class='sd-toggle-group sd-input-group-" . sanitize_title_with_dashes( $key ) . "' $hide>"; |
|
| 2637 | + |
|
| 2638 | + foreach ( $args as $k => $a ) { |
|
| 2639 | + $this->widget_inputs( $a, $instance ); |
|
| 2640 | + } |
|
| 2641 | + |
|
| 2642 | + echo "</div>"; |
|
| 2643 | + |
|
| 2644 | + $panel_count ++; |
|
| 2645 | + |
|
| 2646 | + } |
|
| 2647 | + } else { |
|
| 2648 | + foreach ( $arguments as $key => $args ) { |
|
| 2649 | + $this->widget_inputs( $args, $instance ); |
|
| 2650 | + } |
|
| 2651 | + } |
|
| 2652 | + |
|
| 2653 | + } |
|
| 2654 | + } |
|
| 2655 | + |
|
| 2656 | + /** |
|
| 2657 | + * Get the hidden input that when added makes the advanced button show on widget settings. |
|
| 2658 | + * |
|
| 2659 | + * @return string |
|
| 2660 | + */ |
|
| 2661 | + public function widget_advanced_toggle() { |
|
| 2662 | + |
|
| 2663 | + $output = ''; |
|
| 2664 | + if ( $this->block_show_advanced() ) { |
|
| 2665 | + $val = 1; |
|
| 2666 | + } else { |
|
| 2667 | + $val = 0; |
|
| 2668 | + } |
|
| 2669 | + |
|
| 2670 | + $output .= "<input type='hidden' class='sd-show-advanced' value='$val' />"; |
|
| 2671 | + |
|
| 2672 | + return $output; |
|
| 2673 | + } |
|
| 2674 | + |
|
| 2675 | + /** |
|
| 2676 | + * Convert require element. |
|
| 2677 | + * |
|
| 2678 | + * @since 1.0.0 |
|
| 2679 | + * |
|
| 2680 | + * @param string $input Input element. |
|
| 2681 | + * |
|
| 2682 | + * @return string $output |
|
| 2683 | + */ |
|
| 2684 | + public function convert_element_require( $input ) { |
|
| 2685 | + |
|
| 2686 | + $input = str_replace( "'", '"', $input );// we only want double quotes |
|
| 2687 | + |
|
| 2688 | + $output = esc_attr( str_replace( array( "[%", "%]" ), array( |
|
| 2689 | + "jQuery(form).find('[data-argument=\"", |
|
| 2690 | + "\"]').find('input,select,textarea').val()" |
|
| 2691 | + ), $input ) ); |
|
| 2692 | + |
|
| 2693 | + return $output; |
|
| 2694 | + } |
|
| 2695 | + |
|
| 2696 | + /** |
|
| 2697 | + * Builds the inputs for the widget options. |
|
| 2698 | + * |
|
| 2699 | + * @param $args |
|
| 2700 | + * @param $instance |
|
| 2701 | + */ |
|
| 2702 | + public function widget_inputs( $args, $instance ) { |
|
| 2703 | + |
|
| 2704 | + $class = ""; |
|
| 2705 | + $element_require = ""; |
|
| 2706 | + $custom_attributes = ""; |
|
| 2707 | + |
|
| 2708 | + // get value |
|
| 2709 | + if ( isset( $instance[ $args['name'] ] ) ) { |
|
| 2710 | + $value = $instance[ $args['name'] ]; |
|
| 2711 | + } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) { |
|
| 2712 | + $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] ); |
|
| 2713 | + } else { |
|
| 2714 | + $value = ''; |
|
| 2715 | + } |
|
| 2716 | + |
|
| 2717 | + // get placeholder |
|
| 2718 | + if ( ! empty( $args['placeholder'] ) ) { |
|
| 2719 | + $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'"; |
|
| 2720 | + } else { |
|
| 2721 | + $placeholder = ''; |
|
| 2722 | + } |
|
| 2723 | + |
|
| 2724 | + // get if advanced |
|
| 2725 | + if ( isset( $args['advanced'] ) && $args['advanced'] ) { |
|
| 2726 | + $class .= " sd-advanced-setting "; |
|
| 2727 | + } |
|
| 2728 | + |
|
| 2729 | + // element_require |
|
| 2730 | + if ( isset( $args['element_require'] ) && $args['element_require'] ) { |
|
| 2731 | + $element_require = $args['element_require']; |
|
| 2732 | + } |
|
| 2733 | + |
|
| 2734 | + // custom_attributes |
|
| 2735 | + if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) { |
|
| 2736 | + $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true ); |
|
| 2737 | + } |
|
| 2738 | + |
|
| 2739 | + // before wrapper |
|
| 2740 | + ?> |
|
| 2741 | 2741 | <p class="sd-argument <?php echo esc_attr( $class ); ?>" |
| 2742 | 2742 | data-argument='<?php echo esc_attr( $args['name'] ); ?>' |
| 2743 | 2743 | data-element_require='<?php if ( $element_require ) { |
| 2744 | - echo $this->convert_element_require( $element_require ); |
|
| 2745 | - } ?>' |
|
| 2744 | + echo $this->convert_element_require( $element_require ); |
|
| 2745 | + } ?>' |
|
| 2746 | 2746 | > |
| 2747 | 2747 | <?php |
| 2748 | 2748 | |
| 2749 | - switch ( $args['type'] ) { |
|
| 2750 | - //array('text','password','number','email','tel','url','color') |
|
| 2751 | - case "text": |
|
| 2752 | - case "password": |
|
| 2753 | - case "number": |
|
| 2754 | - case "email": |
|
| 2755 | - case "tel": |
|
| 2756 | - case "url": |
|
| 2757 | - case "color": |
|
| 2758 | - ?> |
|
| 2749 | + switch ( $args['type'] ) { |
|
| 2750 | + //array('text','password','number','email','tel','url','color') |
|
| 2751 | + case "text": |
|
| 2752 | + case "password": |
|
| 2753 | + case "number": |
|
| 2754 | + case "email": |
|
| 2755 | + case "tel": |
|
| 2756 | + case "url": |
|
| 2757 | + case "color": |
|
| 2758 | + ?> |
|
| 2759 | 2759 | <label |
| 2760 | 2760 | for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
| 2761 | 2761 | <input <?php echo $placeholder; ?> class="widefat" |
@@ -2766,47 +2766,47 @@ discard block |
||
| 2766 | 2766 | value="<?php echo esc_attr( $value ); ?>"> |
| 2767 | 2767 | <?php |
| 2768 | 2768 | |
| 2769 | - break; |
|
| 2770 | - case "select": |
|
| 2771 | - $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false; |
|
| 2772 | - if ( $multiple ) { |
|
| 2773 | - if ( empty( $value ) ) { |
|
| 2774 | - $value = array(); |
|
| 2775 | - } |
|
| 2776 | - } |
|
| 2777 | - ?> |
|
| 2769 | + break; |
|
| 2770 | + case "select": |
|
| 2771 | + $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false; |
|
| 2772 | + if ( $multiple ) { |
|
| 2773 | + if ( empty( $value ) ) { |
|
| 2774 | + $value = array(); |
|
| 2775 | + } |
|
| 2776 | + } |
|
| 2777 | + ?> |
|
| 2778 | 2778 | <label |
| 2779 | 2779 | for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
| 2780 | 2780 | <select <?php echo $placeholder; ?> class="widefat" |
| 2781 | 2781 | <?php echo $custom_attributes; ?> |
| 2782 | 2782 | id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
| 2783 | 2783 | name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); |
| 2784 | - if ( $multiple ) { |
|
| 2785 | - echo "[]"; |
|
| 2786 | - } ?>" |
|
| 2784 | + if ( $multiple ) { |
|
| 2785 | + echo "[]"; |
|
| 2786 | + } ?>" |
|
| 2787 | 2787 | <?php if ( $multiple ) { |
| 2788 | - echo "multiple"; |
|
| 2789 | - } //@todo not implemented yet due to gutenberg not supporting it |
|
| 2790 | - ?> |
|
| 2788 | + echo "multiple"; |
|
| 2789 | + } //@todo not implemented yet due to gutenberg not supporting it |
|
| 2790 | + ?> |
|
| 2791 | 2791 | > |
| 2792 | 2792 | <?php |
| 2793 | 2793 | |
| 2794 | - if ( ! empty( $args['options'] ) ) { |
|
| 2795 | - foreach ( $args['options'] as $val => $label ) { |
|
| 2796 | - if ( $multiple ) { |
|
| 2797 | - $selected = in_array( $val, $value ) ? 'selected="selected"' : ''; |
|
| 2798 | - } else { |
|
| 2799 | - $selected = selected( $value, $val, false ); |
|
| 2800 | - } |
|
| 2801 | - echo "<option value='$val' " . $selected . ">$label</option>"; |
|
| 2802 | - } |
|
| 2803 | - } |
|
| 2804 | - ?> |
|
| 2794 | + if ( ! empty( $args['options'] ) ) { |
|
| 2795 | + foreach ( $args['options'] as $val => $label ) { |
|
| 2796 | + if ( $multiple ) { |
|
| 2797 | + $selected = in_array( $val, $value ) ? 'selected="selected"' : ''; |
|
| 2798 | + } else { |
|
| 2799 | + $selected = selected( $value, $val, false ); |
|
| 2800 | + } |
|
| 2801 | + echo "<option value='$val' " . $selected . ">$label</option>"; |
|
| 2802 | + } |
|
| 2803 | + } |
|
| 2804 | + ?> |
|
| 2805 | 2805 | </select> |
| 2806 | 2806 | <?php |
| 2807 | - break; |
|
| 2808 | - case "checkbox": |
|
| 2809 | - ?> |
|
| 2807 | + break; |
|
| 2808 | + case "checkbox": |
|
| 2809 | + ?> |
|
| 2810 | 2810 | <input <?php echo $placeholder; ?> |
| 2811 | 2811 | <?php checked( 1, $value, true ) ?> |
| 2812 | 2812 | <?php echo $custom_attributes; ?> |
@@ -2816,9 +2816,9 @@ discard block |
||
| 2816 | 2816 | <label |
| 2817 | 2817 | for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
| 2818 | 2818 | <?php |
| 2819 | - break; |
|
| 2820 | - case "textarea": |
|
| 2821 | - ?> |
|
| 2819 | + break; |
|
| 2820 | + case "textarea": |
|
| 2821 | + ?> |
|
| 2822 | 2822 | <label |
| 2823 | 2823 | for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
| 2824 | 2824 | <textarea <?php echo $placeholder; ?> class="widefat" |
@@ -2828,173 +2828,173 @@ discard block |
||
| 2828 | 2828 | ><?php echo esc_attr( $value ); ?></textarea> |
| 2829 | 2829 | <?php |
| 2830 | 2830 | |
| 2831 | - break; |
|
| 2832 | - case "hidden": |
|
| 2833 | - ?> |
|
| 2831 | + break; |
|
| 2832 | + case "hidden": |
|
| 2833 | + ?> |
|
| 2834 | 2834 | <input id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
| 2835 | 2835 | name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="hidden" |
| 2836 | 2836 | value="<?php echo esc_attr( $value ); ?>"> |
| 2837 | 2837 | <?php |
| 2838 | - break; |
|
| 2839 | - default: |
|
| 2840 | - echo "No input type found!"; // @todo we need to add more input types. |
|
| 2841 | - } |
|
| 2838 | + break; |
|
| 2839 | + default: |
|
| 2840 | + echo "No input type found!"; // @todo we need to add more input types. |
|
| 2841 | + } |
|
| 2842 | 2842 | |
| 2843 | - // after wrapper |
|
| 2844 | - ?> |
|
| 2843 | + // after wrapper |
|
| 2844 | + ?> |
|
| 2845 | 2845 | </p> |
| 2846 | 2846 | <?php |
| 2847 | 2847 | |
| 2848 | - } |
|
| 2849 | - |
|
| 2850 | - /** |
|
| 2851 | - * Get the widget input description html. |
|
| 2852 | - * |
|
| 2853 | - * @param $args |
|
| 2854 | - * |
|
| 2855 | - * @return string |
|
| 2856 | - * @todo, need to make its own tooltip script |
|
| 2857 | - */ |
|
| 2858 | - public function widget_field_desc( $args ) { |
|
| 2859 | - |
|
| 2860 | - $description = ''; |
|
| 2861 | - if ( isset( $args['desc'] ) && $args['desc'] ) { |
|
| 2862 | - if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) { |
|
| 2863 | - $description = $this->desc_tip( $args['desc'] ); |
|
| 2864 | - } else { |
|
| 2865 | - $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>'; |
|
| 2866 | - } |
|
| 2867 | - } |
|
| 2868 | - |
|
| 2869 | - return $description; |
|
| 2870 | - } |
|
| 2871 | - |
|
| 2872 | - /** |
|
| 2873 | - * Get the tool tip html. |
|
| 2874 | - * |
|
| 2875 | - * @param $tip |
|
| 2876 | - * @param bool $allow_html |
|
| 2877 | - * |
|
| 2878 | - * @return string |
|
| 2879 | - */ |
|
| 2880 | - function desc_tip( $tip, $allow_html = false ) { |
|
| 2881 | - if ( $allow_html ) { |
|
| 2882 | - $tip = $this->sanitize_tooltip( $tip ); |
|
| 2883 | - } else { |
|
| 2884 | - $tip = esc_attr( $tip ); |
|
| 2885 | - } |
|
| 2886 | - |
|
| 2887 | - return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
|
| 2888 | - } |
|
| 2889 | - |
|
| 2890 | - /** |
|
| 2891 | - * Sanitize a string destined to be a tooltip. |
|
| 2892 | - * |
|
| 2893 | - * @param string $var |
|
| 2894 | - * |
|
| 2895 | - * @return string |
|
| 2896 | - */ |
|
| 2897 | - public function sanitize_tooltip( $var ) { |
|
| 2898 | - return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
| 2899 | - 'br' => array(), |
|
| 2900 | - 'em' => array(), |
|
| 2901 | - 'strong' => array(), |
|
| 2902 | - 'small' => array(), |
|
| 2903 | - 'span' => array(), |
|
| 2904 | - 'ul' => array(), |
|
| 2905 | - 'li' => array(), |
|
| 2906 | - 'ol' => array(), |
|
| 2907 | - 'p' => array(), |
|
| 2908 | - ) ) ); |
|
| 2909 | - } |
|
| 2910 | - |
|
| 2911 | - /** |
|
| 2912 | - * Processing widget options on save |
|
| 2913 | - * |
|
| 2914 | - * @param array $new_instance The new options |
|
| 2915 | - * @param array $old_instance The previous options |
|
| 2916 | - * |
|
| 2917 | - * @return array |
|
| 2918 | - * @todo we should add some sanitation here. |
|
| 2919 | - */ |
|
| 2920 | - public function update( $new_instance, $old_instance ) { |
|
| 2921 | - |
|
| 2922 | - //save the widget |
|
| 2923 | - $instance = array_merge( (array) $old_instance, (array) $new_instance ); |
|
| 2924 | - |
|
| 2925 | - // set widget instance |
|
| 2926 | - $this->instance = $instance; |
|
| 2927 | - |
|
| 2928 | - if ( empty( $this->arguments ) ) { |
|
| 2929 | - $this->get_arguments(); |
|
| 2930 | - } |
|
| 2931 | - |
|
| 2932 | - // check for checkboxes |
|
| 2933 | - if ( ! empty( $this->arguments ) ) { |
|
| 2934 | - foreach ( $this->arguments as $argument ) { |
|
| 2935 | - if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) { |
|
| 2936 | - $instance[ $argument['name'] ] = '0'; |
|
| 2937 | - } |
|
| 2938 | - } |
|
| 2939 | - } |
|
| 2940 | - |
|
| 2941 | - return $instance; |
|
| 2942 | - } |
|
| 2943 | - |
|
| 2944 | - /** |
|
| 2945 | - * Checks if the current call is a ajax call to get the block content. |
|
| 2946 | - * |
|
| 2947 | - * This can be used in your widget to return different content as the block content. |
|
| 2948 | - * |
|
| 2949 | - * @since 1.0.3 |
|
| 2950 | - * @return bool |
|
| 2951 | - */ |
|
| 2952 | - public function is_block_content_call() { |
|
| 2953 | - $result = false; |
|
| 2954 | - if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) { |
|
| 2955 | - $result = true; |
|
| 2956 | - } |
|
| 2957 | - |
|
| 2958 | - return $result; |
|
| 2959 | - } |
|
| 2960 | - |
|
| 2961 | - /** |
|
| 2962 | - * Get an instance hash that will be unique to the type and settings. |
|
| 2963 | - * |
|
| 2964 | - * @since 1.0.20 |
|
| 2965 | - * @return string |
|
| 2966 | - */ |
|
| 2967 | - public function get_instance_hash(){ |
|
| 2968 | - $instance_string = $this->base_id.serialize($this->instance); |
|
| 2969 | - return hash('crc32b',$instance_string); |
|
| 2970 | - } |
|
| 2971 | - |
|
| 2972 | - /** |
|
| 2973 | - * Generate and return inline styles from CSS rules that will match the unique class of the instance. |
|
| 2974 | - * |
|
| 2975 | - * @param array $rules |
|
| 2976 | - * |
|
| 2977 | - * @since 1.0.20 |
|
| 2978 | - * @return string |
|
| 2979 | - */ |
|
| 2980 | - public function get_instance_style($rules = array()){ |
|
| 2981 | - $css = ''; |
|
| 2982 | - |
|
| 2983 | - if(!empty($rules)){ |
|
| 2984 | - $rules = array_unique($rules); |
|
| 2985 | - $instance_hash = $this->get_instance_hash(); |
|
| 2986 | - $css .= "<style>"; |
|
| 2987 | - foreach($rules as $rule){ |
|
| 2988 | - $css .= ".sdel-$instance_hash $rule"; |
|
| 2989 | - } |
|
| 2990 | - $css .= "</style>"; |
|
| 2991 | - } |
|
| 2992 | - |
|
| 2993 | - |
|
| 2994 | - return $css; |
|
| 2995 | - |
|
| 2996 | - } |
|
| 2997 | - |
|
| 2998 | - } |
|
| 2848 | + } |
|
| 2849 | + |
|
| 2850 | + /** |
|
| 2851 | + * Get the widget input description html. |
|
| 2852 | + * |
|
| 2853 | + * @param $args |
|
| 2854 | + * |
|
| 2855 | + * @return string |
|
| 2856 | + * @todo, need to make its own tooltip script |
|
| 2857 | + */ |
|
| 2858 | + public function widget_field_desc( $args ) { |
|
| 2859 | + |
|
| 2860 | + $description = ''; |
|
| 2861 | + if ( isset( $args['desc'] ) && $args['desc'] ) { |
|
| 2862 | + if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) { |
|
| 2863 | + $description = $this->desc_tip( $args['desc'] ); |
|
| 2864 | + } else { |
|
| 2865 | + $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>'; |
|
| 2866 | + } |
|
| 2867 | + } |
|
| 2868 | + |
|
| 2869 | + return $description; |
|
| 2870 | + } |
|
| 2871 | + |
|
| 2872 | + /** |
|
| 2873 | + * Get the tool tip html. |
|
| 2874 | + * |
|
| 2875 | + * @param $tip |
|
| 2876 | + * @param bool $allow_html |
|
| 2877 | + * |
|
| 2878 | + * @return string |
|
| 2879 | + */ |
|
| 2880 | + function desc_tip( $tip, $allow_html = false ) { |
|
| 2881 | + if ( $allow_html ) { |
|
| 2882 | + $tip = $this->sanitize_tooltip( $tip ); |
|
| 2883 | + } else { |
|
| 2884 | + $tip = esc_attr( $tip ); |
|
| 2885 | + } |
|
| 2886 | + |
|
| 2887 | + return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
|
| 2888 | + } |
|
| 2889 | + |
|
| 2890 | + /** |
|
| 2891 | + * Sanitize a string destined to be a tooltip. |
|
| 2892 | + * |
|
| 2893 | + * @param string $var |
|
| 2894 | + * |
|
| 2895 | + * @return string |
|
| 2896 | + */ |
|
| 2897 | + public function sanitize_tooltip( $var ) { |
|
| 2898 | + return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
| 2899 | + 'br' => array(), |
|
| 2900 | + 'em' => array(), |
|
| 2901 | + 'strong' => array(), |
|
| 2902 | + 'small' => array(), |
|
| 2903 | + 'span' => array(), |
|
| 2904 | + 'ul' => array(), |
|
| 2905 | + 'li' => array(), |
|
| 2906 | + 'ol' => array(), |
|
| 2907 | + 'p' => array(), |
|
| 2908 | + ) ) ); |
|
| 2909 | + } |
|
| 2910 | + |
|
| 2911 | + /** |
|
| 2912 | + * Processing widget options on save |
|
| 2913 | + * |
|
| 2914 | + * @param array $new_instance The new options |
|
| 2915 | + * @param array $old_instance The previous options |
|
| 2916 | + * |
|
| 2917 | + * @return array |
|
| 2918 | + * @todo we should add some sanitation here. |
|
| 2919 | + */ |
|
| 2920 | + public function update( $new_instance, $old_instance ) { |
|
| 2921 | + |
|
| 2922 | + //save the widget |
|
| 2923 | + $instance = array_merge( (array) $old_instance, (array) $new_instance ); |
|
| 2924 | + |
|
| 2925 | + // set widget instance |
|
| 2926 | + $this->instance = $instance; |
|
| 2927 | + |
|
| 2928 | + if ( empty( $this->arguments ) ) { |
|
| 2929 | + $this->get_arguments(); |
|
| 2930 | + } |
|
| 2931 | + |
|
| 2932 | + // check for checkboxes |
|
| 2933 | + if ( ! empty( $this->arguments ) ) { |
|
| 2934 | + foreach ( $this->arguments as $argument ) { |
|
| 2935 | + if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) { |
|
| 2936 | + $instance[ $argument['name'] ] = '0'; |
|
| 2937 | + } |
|
| 2938 | + } |
|
| 2939 | + } |
|
| 2940 | + |
|
| 2941 | + return $instance; |
|
| 2942 | + } |
|
| 2943 | + |
|
| 2944 | + /** |
|
| 2945 | + * Checks if the current call is a ajax call to get the block content. |
|
| 2946 | + * |
|
| 2947 | + * This can be used in your widget to return different content as the block content. |
|
| 2948 | + * |
|
| 2949 | + * @since 1.0.3 |
|
| 2950 | + * @return bool |
|
| 2951 | + */ |
|
| 2952 | + public function is_block_content_call() { |
|
| 2953 | + $result = false; |
|
| 2954 | + if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) { |
|
| 2955 | + $result = true; |
|
| 2956 | + } |
|
| 2957 | + |
|
| 2958 | + return $result; |
|
| 2959 | + } |
|
| 2960 | + |
|
| 2961 | + /** |
|
| 2962 | + * Get an instance hash that will be unique to the type and settings. |
|
| 2963 | + * |
|
| 2964 | + * @since 1.0.20 |
|
| 2965 | + * @return string |
|
| 2966 | + */ |
|
| 2967 | + public function get_instance_hash(){ |
|
| 2968 | + $instance_string = $this->base_id.serialize($this->instance); |
|
| 2969 | + return hash('crc32b',$instance_string); |
|
| 2970 | + } |
|
| 2971 | + |
|
| 2972 | + /** |
|
| 2973 | + * Generate and return inline styles from CSS rules that will match the unique class of the instance. |
|
| 2974 | + * |
|
| 2975 | + * @param array $rules |
|
| 2976 | + * |
|
| 2977 | + * @since 1.0.20 |
|
| 2978 | + * @return string |
|
| 2979 | + */ |
|
| 2980 | + public function get_instance_style($rules = array()){ |
|
| 2981 | + $css = ''; |
|
| 2982 | + |
|
| 2983 | + if(!empty($rules)){ |
|
| 2984 | + $rules = array_unique($rules); |
|
| 2985 | + $instance_hash = $this->get_instance_hash(); |
|
| 2986 | + $css .= "<style>"; |
|
| 2987 | + foreach($rules as $rule){ |
|
| 2988 | + $css .= ".sdel-$instance_hash $rule"; |
|
| 2989 | + } |
|
| 2990 | + $css .= "</style>"; |
|
| 2991 | + } |
|
| 2992 | + |
|
| 2993 | + |
|
| 2994 | + return $css; |
|
| 2995 | + |
|
| 2996 | + } |
|
| 2997 | + |
|
| 2998 | + } |
|
| 2999 | 2999 | |
| 3000 | 3000 | } |
@@ -1,9 +1,9 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
| 6 | -if ( ! class_exists( 'WP_Super_Duper' ) ) { |
|
| 6 | +if (!class_exists('WP_Super_Duper')) { |
|
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | /** |
@@ -37,27 +37,27 @@ discard block |
||
| 37 | 37 | /** |
| 38 | 38 | * Take the array options and use them to build. |
| 39 | 39 | */ |
| 40 | - public function __construct( $options ) { |
|
| 40 | + public function __construct($options) { |
|
| 41 | 41 | global $sd_widgets; |
| 42 | 42 | |
| 43 | - $sd_widgets[ $options['base_id'] ] = array( |
|
| 43 | + $sd_widgets[$options['base_id']] = array( |
|
| 44 | 44 | 'name' => $options['name'], |
| 45 | 45 | 'class_name' => $options['class_name'] |
| 46 | 46 | ); |
| 47 | - $this->base_id = $options['base_id']; |
|
| 47 | + $this->base_id = $options['base_id']; |
|
| 48 | 48 | // lets filter the options before we do anything |
| 49 | - $options = apply_filters( "wp_super_duper_options", $options ); |
|
| 50 | - $options = apply_filters( "wp_super_duper_options_{$this->base_id}", $options ); |
|
| 51 | - $options = $this->add_name_from_key( $options ); |
|
| 49 | + $options = apply_filters("wp_super_duper_options", $options); |
|
| 50 | + $options = apply_filters("wp_super_duper_options_{$this->base_id}", $options); |
|
| 51 | + $options = $this->add_name_from_key($options); |
|
| 52 | 52 | $this->options = $options; |
| 53 | 53 | |
| 54 | 54 | $this->base_id = $options['base_id']; |
| 55 | - $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array(); |
|
| 55 | + $this->arguments = isset($options['arguments']) ? $options['arguments'] : array(); |
|
| 56 | 56 | |
| 57 | 57 | // init parent |
| 58 | - parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] ); |
|
| 58 | + parent::__construct($options['base_id'], $options['name'], $options['widget_ops']); |
|
| 59 | 59 | |
| 60 | - if ( isset( $options['class_name'] ) ) { |
|
| 60 | + if (isset($options['class_name'])) { |
|
| 61 | 61 | // register widget |
| 62 | 62 | $this->class_name = $options['class_name']; |
| 63 | 63 | |
@@ -65,66 +65,66 @@ discard block |
||
| 65 | 65 | $this->register_shortcode(); |
| 66 | 66 | |
| 67 | 67 | // Fusion Builder (avada) support |
| 68 | - if ( function_exists( 'fusion_builder_map' ) ) { |
|
| 69 | - add_action( 'init', array( $this, 'register_fusion_element' ) ); |
|
| 68 | + if (function_exists('fusion_builder_map')) { |
|
| 69 | + add_action('init', array($this, 'register_fusion_element')); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | // register block |
| 73 | - add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) ); |
|
| 73 | + add_action('admin_enqueue_scripts', array($this, 'register_block')); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | // add the CSS and JS we need ONCE |
| 77 | 77 | global $sd_widget_scripts; |
| 78 | 78 | |
| 79 | - if ( ! $sd_widget_scripts ) { |
|
| 80 | - wp_add_inline_script( 'admin-widgets', $this->widget_js() ); |
|
| 81 | - wp_add_inline_script( 'customize-controls', $this->widget_js() ); |
|
| 82 | - wp_add_inline_style( 'widgets', $this->widget_css() ); |
|
| 79 | + if (!$sd_widget_scripts) { |
|
| 80 | + wp_add_inline_script('admin-widgets', $this->widget_js()); |
|
| 81 | + wp_add_inline_script('customize-controls', $this->widget_js()); |
|
| 82 | + wp_add_inline_style('widgets', $this->widget_css()); |
|
| 83 | 83 | |
| 84 | 84 | // maybe add elementor editor styles |
| 85 | - add_action( 'elementor/editor/after_enqueue_styles', array( $this, 'elementor_editor_styles' ) ); |
|
| 85 | + add_action('elementor/editor/after_enqueue_styles', array($this, 'elementor_editor_styles')); |
|
| 86 | 86 | |
| 87 | 87 | $sd_widget_scripts = true; |
| 88 | 88 | |
| 89 | 89 | // add shortcode insert button once |
| 90 | - add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) ); |
|
| 90 | + add_action('media_buttons', array($this, 'shortcode_insert_button')); |
|
| 91 | 91 | // generatepress theme sections compatibility |
| 92 | - if ( function_exists( 'generate_sections_sections_metabox' ) ) { |
|
| 93 | - add_action( 'generate_sections_metabox', array( $this, 'shortcode_insert_button_script' ) ); |
|
| 92 | + if (function_exists('generate_sections_sections_metabox')) { |
|
| 93 | + add_action('generate_sections_metabox', array($this, 'shortcode_insert_button_script')); |
|
| 94 | 94 | } |
| 95 | - if ( $this->is_preview() ) { |
|
| 96 | - add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) ); |
|
| 95 | + if ($this->is_preview()) { |
|
| 96 | + add_action('wp_footer', array($this, 'shortcode_insert_button_script')); |
|
| 97 | 97 | // this makes the insert button work for elementor |
| 98 | - add_action( 'elementor/editor/after_enqueue_scripts', array( |
|
| 98 | + add_action('elementor/editor/after_enqueue_scripts', array( |
|
| 99 | 99 | $this, |
| 100 | 100 | 'shortcode_insert_button_script' |
| 101 | - ) ); // for elementor |
|
| 101 | + )); // for elementor |
|
| 102 | 102 | } |
| 103 | 103 | // this makes the insert button work for cornerstone |
| 104 | - add_action( 'wp_print_footer_scripts', array( __CLASS__, 'maybe_cornerstone_builder' ) ); |
|
| 104 | + add_action('wp_print_footer_scripts', array(__CLASS__, 'maybe_cornerstone_builder')); |
|
| 105 | 105 | |
| 106 | - add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) ); |
|
| 107 | - add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) ); |
|
| 106 | + add_action('wp_ajax_super_duper_get_widget_settings', array(__CLASS__, 'get_widget_settings')); |
|
| 107 | + add_action('wp_ajax_super_duper_get_picker', array(__CLASS__, 'get_picker')); |
|
| 108 | 108 | |
| 109 | 109 | // add generator text to admin head |
| 110 | - add_action( 'admin_head', array( $this, 'generator' ) ); |
|
| 110 | + add_action('admin_head', array($this, 'generator')); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - do_action( 'wp_super_duper_widget_init', $options, $this ); |
|
| 113 | + do_action('wp_super_duper_widget_init', $options, $this); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
| 117 | 117 | * Add our widget CSS to elementor editor. |
| 118 | 118 | */ |
| 119 | 119 | public function elementor_editor_styles() { |
| 120 | - wp_add_inline_style( 'elementor-editor', $this->widget_css( false ) ); |
|
| 120 | + wp_add_inline_style('elementor-editor', $this->widget_css(false)); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | public function register_fusion_element() { |
| 124 | 124 | |
| 125 | 125 | $options = $this->options; |
| 126 | 126 | |
| 127 | - if ( $this->base_id ) { |
|
| 127 | + if ($this->base_id) { |
|
| 128 | 128 | |
| 129 | 129 | $params = $this->get_fusion_params(); |
| 130 | 130 | |
@@ -135,11 +135,11 @@ discard block |
||
| 135 | 135 | 'allow_generator' => true, |
| 136 | 136 | ); |
| 137 | 137 | |
| 138 | - if ( ! empty( $params ) ) { |
|
| 138 | + if (!empty($params)) { |
|
| 139 | 139 | $args['params'] = $params; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - fusion_builder_map( $args ); |
|
| 142 | + fusion_builder_map($args); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | } |
@@ -148,8 +148,8 @@ discard block |
||
| 148 | 148 | $params = array(); |
| 149 | 149 | $arguments = $this->get_arguments(); |
| 150 | 150 | |
| 151 | - if ( ! empty( $arguments ) ) { |
|
| 152 | - foreach ( $arguments as $key => $val ) { |
|
| 151 | + if (!empty($arguments)) { |
|
| 152 | + foreach ($arguments as $key => $val) { |
|
| 153 | 153 | $param = array(); |
| 154 | 154 | // type |
| 155 | 155 | $param['type'] = str_replace( |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | $val['type'] ); |
| 172 | 172 | |
| 173 | 173 | // multiselect |
| 174 | - if ( $val['type'] == 'multiselect' || ( ( $param['type'] == 'select' || $val['type'] == 'select' ) && ! empty( $val['multiple'] ) ) ) { |
|
| 174 | + if ($val['type'] == 'multiselect' || (($param['type'] == 'select' || $val['type'] == 'select') && !empty($val['multiple']))) { |
|
| 175 | 175 | $param['type'] = 'multiple_select'; |
| 176 | 176 | $param['multiple'] = true; |
| 177 | 177 | } |
@@ -180,29 +180,29 @@ discard block |
||
| 180 | 180 | $param['heading'] = $val['title']; |
| 181 | 181 | |
| 182 | 182 | // description |
| 183 | - $param['description'] = isset( $val['desc'] ) ? $val['desc'] : ''; |
|
| 183 | + $param['description'] = isset($val['desc']) ? $val['desc'] : ''; |
|
| 184 | 184 | |
| 185 | 185 | // param_name |
| 186 | 186 | $param['param_name'] = $key; |
| 187 | 187 | |
| 188 | 188 | // Default |
| 189 | - $param['default'] = isset( $val['default'] ) ? $val['default'] : ''; |
|
| 189 | + $param['default'] = isset($val['default']) ? $val['default'] : ''; |
|
| 190 | 190 | |
| 191 | 191 | // Group |
| 192 | - if ( isset( $val['group'] ) ) { |
|
| 192 | + if (isset($val['group'])) { |
|
| 193 | 193 | $param['group'] = $val['group']; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | // value |
| 197 | - if ( $val['type'] == 'checkbox' ) { |
|
| 198 | - if ( isset( $val['default'] ) && $val['default'] == '0' ) { |
|
| 199 | - unset( $param['default'] ); |
|
| 197 | + if ($val['type'] == 'checkbox') { |
|
| 198 | + if (isset($val['default']) && $val['default'] == '0') { |
|
| 199 | + unset($param['default']); |
|
| 200 | 200 | } |
| 201 | - $param['value'] = array( '' => __( "No" ), '1' => __( "Yes" ) ); |
|
| 202 | - } elseif ( $param['type'] == 'select' || $param['type'] == 'multiple_select' ) { |
|
| 203 | - $param['value'] = isset( $val['options'] ) ? $val['options'] : array(); |
|
| 201 | + $param['value'] = array('' => __("No"), '1' => __("Yes")); |
|
| 202 | + } elseif ($param['type'] == 'select' || $param['type'] == 'multiple_select') { |
|
| 203 | + $param['value'] = isset($val['options']) ? $val['options'] : array(); |
|
| 204 | 204 | } else { |
| 205 | - $param['value'] = isset( $val['default'] ) ? $val['default'] : ''; |
|
| 205 | + $param['value'] = isset($val['default']) ? $val['default'] : ''; |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | // setup the param |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | * Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder |
| 220 | 220 | */ |
| 221 | 221 | public static function maybe_cornerstone_builder() { |
| 222 | - if ( did_action( 'cornerstone_before_boot_app' ) ) { |
|
| 222 | + if (did_action('cornerstone_before_boot_app')) { |
|
| 223 | 223 | self::shortcode_insert_button_script(); |
| 224 | 224 | } |
| 225 | 225 | } |
@@ -231,12 +231,12 @@ discard block |
||
| 231 | 231 | * |
| 232 | 232 | * @return string |
| 233 | 233 | */ |
| 234 | - public static function get_picker( $editor_id = '' ) { |
|
| 234 | + public static function get_picker($editor_id = '') { |
|
| 235 | 235 | |
| 236 | 236 | ob_start(); |
| 237 | - if ( isset( $_POST['editor_id'] ) ) { |
|
| 238 | - $editor_id = esc_attr( $_POST['editor_id'] ); |
|
| 239 | - } elseif ( isset( $_REQUEST['et_fb'] ) ) { |
|
| 237 | + if (isset($_POST['editor_id'])) { |
|
| 238 | + $editor_id = esc_attr($_POST['editor_id']); |
|
| 239 | + } elseif (isset($_REQUEST['et_fb'])) { |
|
| 240 | 240 | $editor_id = 'main_content_content_vb_tiny_mce'; |
| 241 | 241 | } |
| 242 | 242 | |
@@ -245,13 +245,13 @@ discard block |
||
| 245 | 245 | |
| 246 | 246 | <div class="sd-shortcode-left-wrap"> |
| 247 | 247 | <?php |
| 248 | - ksort( $sd_widgets ); |
|
| 248 | + ksort($sd_widgets); |
|
| 249 | 249 | // print_r($sd_widgets);exit; |
| 250 | - if ( ! empty( $sd_widgets ) ) { |
|
| 250 | + if (!empty($sd_widgets)) { |
|
| 251 | 251 | echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">'; |
| 252 | - echo "<option>" . __( 'Select shortcode' ) . "</option>"; |
|
| 253 | - foreach ( $sd_widgets as $shortcode => $class ) { |
|
| 254 | - echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>"; |
|
| 252 | + echo "<option>" . __('Select shortcode') . "</option>"; |
|
| 253 | + foreach ($sd_widgets as $shortcode => $class) { |
|
| 254 | + echo "<option value='" . esc_attr($shortcode) . "'>" . esc_attr($shortcode) . " (" . esc_attr($class['name']) . ")</option>"; |
|
| 255 | 255 | } |
| 256 | 256 | echo "</select>"; |
| 257 | 257 | |
@@ -264,37 +264,37 @@ discard block |
||
| 264 | 264 | <div class="sd-shortcode-right-wrap"> |
| 265 | 265 | <textarea id='sd-shortcode-output' disabled></textarea> |
| 266 | 266 | <div id='sd-shortcode-output-actions'> |
| 267 | - <?php if ( $editor_id != '' ) { ?> |
|
| 267 | + <?php if ($editor_id != '') { ?> |
|
| 268 | 268 | <button class="button sd-insert-shortcode-button" |
| 269 | - onclick="sd_insert_shortcode(<?php if ( ! empty( $editor_id ) ) { |
|
| 269 | + onclick="sd_insert_shortcode(<?php if (!empty($editor_id)) { |
|
| 270 | 270 | echo "'" . $editor_id . "'"; |
| 271 | - } ?>)"><?php _e( 'Insert shortcode' ); ?></button> |
|
| 271 | + } ?>)"><?php _e('Insert shortcode'); ?></button> |
|
| 272 | 272 | <?php } ?> |
| 273 | 273 | <button class="button" |
| 274 | - onclick="sd_copy_to_clipboard()"><?php _e( 'Copy shortcode' ); ?></button> |
|
| 274 | + onclick="sd_copy_to_clipboard()"><?php _e('Copy shortcode'); ?></button> |
|
| 275 | 275 | </div> |
| 276 | 276 | </div> |
| 277 | 277 | <?php |
| 278 | 278 | |
| 279 | 279 | $html = ob_get_clean(); |
| 280 | 280 | |
| 281 | - if ( wp_doing_ajax() ) { |
|
| 281 | + if (wp_doing_ajax()) { |
|
| 282 | 282 | echo $html; |
| 283 | 283 | $should_die = true; |
| 284 | 284 | |
| 285 | 285 | // some builder get the editor via ajax so we should not die on those ocasions |
| 286 | 286 | $dont_die = array( |
| 287 | - 'parent_tag',// WP Bakery |
|
| 287 | + 'parent_tag', // WP Bakery |
|
| 288 | 288 | 'avia_request' // enfold |
| 289 | 289 | ); |
| 290 | 290 | |
| 291 | - foreach ( $dont_die as $request ) { |
|
| 292 | - if ( isset( $_REQUEST[ $request ] ) ) { |
|
| 291 | + foreach ($dont_die as $request) { |
|
| 292 | + if (isset($_REQUEST[$request])) { |
|
| 293 | 293 | $should_die = false; |
| 294 | 294 | } |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | - if ( $should_die ) { |
|
| 297 | + if ($should_die) { |
|
| 298 | 298 | wp_die(); |
| 299 | 299 | } |
| 300 | 300 | |
@@ -321,16 +321,16 @@ discard block |
||
| 321 | 321 | public static function get_widget_settings() { |
| 322 | 322 | global $sd_widgets; |
| 323 | 323 | |
| 324 | - $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : ''; |
|
| 325 | - if ( ! $shortcode ) { |
|
| 324 | + $shortcode = isset($_REQUEST['shortcode']) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes($_REQUEST['shortcode']) : ''; |
|
| 325 | + if (!$shortcode) { |
|
| 326 | 326 | wp_die(); |
| 327 | 327 | } |
| 328 | - $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : ''; |
|
| 329 | - if ( ! $widget_args ) { |
|
| 328 | + $widget_args = isset($sd_widgets[$shortcode]) ? $sd_widgets[$shortcode] : ''; |
|
| 329 | + if (!$widget_args) { |
|
| 330 | 330 | wp_die(); |
| 331 | 331 | } |
| 332 | - $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
| 333 | - if ( ! $class_name ) { |
|
| 332 | + $class_name = isset($widget_args['class_name']) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
| 333 | + if (!$class_name) { |
|
| 334 | 334 | wp_die(); |
| 335 | 335 | } |
| 336 | 336 | |
@@ -338,7 +338,7 @@ discard block |
||
| 338 | 338 | $widget = new $class_name; |
| 339 | 339 | |
| 340 | 340 | ob_start(); |
| 341 | - $widget->form( array() ); |
|
| 341 | + $widget->form(array()); |
|
| 342 | 342 | $form = ob_get_clean(); |
| 343 | 343 | echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>"; |
| 344 | 344 | echo "<style>" . $widget->widget_css() . "</style>"; |
@@ -356,9 +356,9 @@ discard block |
||
| 356 | 356 | * @param string $editor_id Optional. Shortcode editor id. Default null. |
| 357 | 357 | * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null. |
| 358 | 358 | */ |
| 359 | - public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) { |
|
| 359 | + public static function shortcode_insert_button($editor_id = '', $insert_shortcode_function = '') { |
|
| 360 | 360 | global $sd_widgets, $shortcode_insert_button_once; |
| 361 | - if ( $shortcode_insert_button_once ) { |
|
| 361 | + if ($shortcode_insert_button_once) { |
|
| 362 | 362 | return; |
| 363 | 363 | } |
| 364 | 364 | add_thickbox(); |
@@ -368,21 +368,21 @@ discard block |
||
| 368 | 368 | * Cornerstone makes us play dirty tricks :/ |
| 369 | 369 | * All media_buttons are removed via JS unless they are two specific id's so we wrap our content in this ID so it is not removed. |
| 370 | 370 | */ |
| 371 | - if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
| 371 | + if (function_exists('cornerstone_plugin_init') && !is_admin()) { |
|
| 372 | 372 | echo '<span id="insert-media-button">'; |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - echo self::shortcode_button( 'this', 'true' ); |
|
| 375 | + echo self::shortcode_button('this', 'true'); |
|
| 376 | 376 | |
| 377 | 377 | // see opening note |
| 378 | - if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
| 378 | + if (function_exists('cornerstone_plugin_init') && !is_admin()) { |
|
| 379 | 379 | echo '</span>'; // end #insert-media-button |
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | // Add separate script for generatepress theme sections |
| 383 | - if ( function_exists( 'generate_sections_sections_metabox' ) && did_action( 'generate_sections_metabox' ) ) { |
|
| 383 | + if (function_exists('generate_sections_sections_metabox') && did_action('generate_sections_metabox')) { |
|
| 384 | 384 | } else { |
| 385 | - self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function ); |
|
| 385 | + self::shortcode_insert_button_script($editor_id, $insert_shortcode_function); |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | $shortcode_insert_button_once = true; |
@@ -396,12 +396,12 @@ discard block |
||
| 396 | 396 | * |
| 397 | 397 | * @return mixed |
| 398 | 398 | */ |
| 399 | - public static function shortcode_button( $id = '', $search_for_id = '' ) { |
|
| 399 | + public static function shortcode_button($id = '', $search_for_id = '') { |
|
| 400 | 400 | ob_start(); |
| 401 | 401 | ?> |
| 402 | 402 | <span class="sd-lable-shortcode-inserter"> |
| 403 | 403 | <a onclick="sd_ajax_get_picker(<?php echo $id; |
| 404 | - if ( $search_for_id ) { |
|
| 404 | + if ($search_for_id) { |
|
| 405 | 405 | echo "," . $search_for_id; |
| 406 | 406 | } ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed" |
| 407 | 407 | class="thickbox button super-duper-content-open" title="Add Shortcode"> |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | $html = ob_get_clean(); |
| 418 | 418 | |
| 419 | 419 | // remove line breaks so we can use it in js |
| 420 | - return preg_replace( "/\r|\n/", "", trim( $html ) ); |
|
| 420 | + return preg_replace("/\r|\n/", "", trim($html)); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | /** |
@@ -475,7 +475,7 @@ discard block |
||
| 475 | 475 | jQuery($this).data('sd-widget-enabled', true); |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | - var $button = '<button title="<?php _e( 'Advanced Settings' );?>" class="button button-primary right sd-advanced-button" onclick="sd_so_toggle_advanced(this);return false;"><i class="fas fa-sliders-h" aria-hidden="true"></i></button>'; |
|
| 478 | + var $button = '<button title="<?php _e('Advanced Settings'); ?>" class="button button-primary right sd-advanced-button" onclick="sd_so_toggle_advanced(this);return false;"><i class="fas fa-sliders-h" aria-hidden="true"></i></button>'; |
|
| 479 | 479 | var form = jQuery($this).parents('' + $selector + ''); |
| 480 | 480 | |
| 481 | 481 | if (jQuery($this).val() == '1' && jQuery(form).find('.sd-advanced-button').length == 0) { |
@@ -512,10 +512,10 @@ discard block |
||
| 512 | 512 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 513 | 513 | */ |
| 514 | 514 | |
| 515 | - return str_replace( array( |
|
| 515 | + return str_replace(array( |
|
| 516 | 516 | '<script>', |
| 517 | 517 | '</script>' |
| 518 | - ), '', $output ); |
|
| 518 | + ), '', $output); |
|
| 519 | 519 | } |
| 520 | 520 | |
| 521 | 521 | /** |
@@ -526,7 +526,7 @@ discard block |
||
| 526 | 526 | * @param string $editor_id |
| 527 | 527 | * @param string $insert_shortcode_function |
| 528 | 528 | */ |
| 529 | - public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) { |
|
| 529 | + public static function shortcode_insert_button_script($editor_id = '', $insert_shortcode_function = '') { |
|
| 530 | 530 | ?> |
| 531 | 531 | <style> |
| 532 | 532 | .sd-shortcode-left-wrap { |
@@ -645,7 +645,7 @@ discard block |
||
| 645 | 645 | width: 100%; |
| 646 | 646 | } |
| 647 | 647 | |
| 648 | - <?php if ( function_exists( 'generate_sections_sections_metabox' ) ) { ?> |
|
| 648 | + <?php if (function_exists('generate_sections_sections_metabox')) { ?> |
|
| 649 | 649 | .generate-sections-modal #custom-media-buttons > .sd-lable-shortcode-inserter { |
| 650 | 650 | display: inline; |
| 651 | 651 | } |
@@ -653,15 +653,15 @@ discard block |
||
| 653 | 653 | <?php } ?> |
| 654 | 654 | </style> |
| 655 | 655 | <?php |
| 656 | - if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
| 656 | + if (class_exists('SiteOrigin_Panels')) { |
|
| 657 | 657 | echo "<script>" . self::siteorigin_js() . "</script>"; |
| 658 | 658 | } |
| 659 | 659 | ?> |
| 660 | 660 | <script> |
| 661 | 661 | <?php |
| 662 | - if(! empty( $insert_shortcode_function )){ |
|
| 662 | + if (!empty($insert_shortcode_function)) { |
|
| 663 | 663 | echo $insert_shortcode_function; |
| 664 | - }else{ |
|
| 664 | + } else { |
|
| 665 | 665 | |
| 666 | 666 | /** |
| 667 | 667 | * Function for super duper insert shortcode. |
@@ -674,9 +674,9 @@ discard block |
||
| 674 | 674 | if ($shortcode) { |
| 675 | 675 | if (!$editor_id) { |
| 676 | 676 | <?php |
| 677 | - if ( isset( $_REQUEST['et_fb'] ) ) { |
|
| 677 | + if (isset($_REQUEST['et_fb'])) { |
|
| 678 | 678 | echo '$editor_id = "#main_content_content_vb_tiny_mce";'; |
| 679 | - } elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) { |
|
| 679 | + } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor') { |
|
| 680 | 680 | echo '$editor_id = "#elementor-controls .wp-editor-container textarea";'; |
| 681 | 681 | } else { |
| 682 | 682 | echo '$editor_id = "#wp-content-editor-container textarea";'; |
@@ -761,11 +761,11 @@ discard block |
||
| 761 | 761 | 'shortcode': $short_code, |
| 762 | 762 | 'attributes': 123, |
| 763 | 763 | 'post_id': 321, |
| 764 | - '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>' |
|
| 764 | + '_ajax_nonce': '<?php echo wp_create_nonce('super_duper_output_shortcode'); ?>' |
|
| 765 | 765 | }; |
| 766 | 766 | |
| 767 | 767 | if (typeof ajaxurl === 'undefined') { |
| 768 | - var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' );?>"; |
|
| 768 | + var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>"; |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | jQuery.post(ajaxurl, data, function (response) { |
@@ -974,11 +974,11 @@ discard block |
||
| 974 | 974 | var data = { |
| 975 | 975 | 'action': 'super_duper_get_picker', |
| 976 | 976 | 'editor_id': $id, |
| 977 | - '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_picker' );?>' |
|
| 977 | + '_ajax_nonce': '<?php echo wp_create_nonce('super_duper_picker'); ?>' |
|
| 978 | 978 | }; |
| 979 | 979 | |
| 980 | 980 | if (!ajaxurl) { |
| 981 | - var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' ); ?>"; |
|
| 981 | + var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>"; |
|
| 982 | 982 | } |
| 983 | 983 | |
| 984 | 984 | jQuery.post(ajaxurl, data, function (response) { |
@@ -999,9 +999,9 @@ discard block |
||
| 999 | 999 | */ |
| 1000 | 1000 | function sd_shortcode_button($id) { |
| 1001 | 1001 | if ($id) { |
| 1002 | - return '<?php echo self::shortcode_button( "\\''+\$id+'\\'" );?>'; |
|
| 1002 | + return '<?php echo self::shortcode_button("\\''+\$id+'\\'"); ?>'; |
|
| 1003 | 1003 | } else { |
| 1004 | - return '<?php echo self::shortcode_button();?>'; |
|
| 1004 | + return '<?php echo self::shortcode_button(); ?>'; |
|
| 1005 | 1005 | } |
| 1006 | 1006 | } |
| 1007 | 1007 | |
@@ -1016,11 +1016,11 @@ discard block |
||
| 1016 | 1016 | * |
| 1017 | 1017 | * @return mixed |
| 1018 | 1018 | */ |
| 1019 | - public function widget_css( $advanced = true ) { |
|
| 1019 | + public function widget_css($advanced = true) { |
|
| 1020 | 1020 | ob_start(); |
| 1021 | 1021 | ?> |
| 1022 | 1022 | <style> |
| 1023 | - <?php if( $advanced ){ ?> |
|
| 1023 | + <?php if ($advanced) { ?> |
|
| 1024 | 1024 | .sd-advanced-setting { |
| 1025 | 1025 | display: none; |
| 1026 | 1026 | } |
@@ -1062,10 +1062,10 @@ discard block |
||
| 1062 | 1062 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 1063 | 1063 | */ |
| 1064 | 1064 | |
| 1065 | - return str_replace( array( |
|
| 1065 | + return str_replace(array( |
|
| 1066 | 1066 | '<style>', |
| 1067 | 1067 | '</style>' |
| 1068 | - ), '', $output ); |
|
| 1068 | + ), '', $output); |
|
| 1069 | 1069 | } |
| 1070 | 1070 | |
| 1071 | 1071 | /** |
@@ -1135,7 +1135,7 @@ discard block |
||
| 1135 | 1135 | jQuery($this).data('sd-widget-enabled', true); |
| 1136 | 1136 | } |
| 1137 | 1137 | |
| 1138 | - var $button = '<button title="<?php _e( 'Advanced Settings' );?>" style="line-height: 28px;" class="button button-primary right sd-advanced-button" onclick="sd_toggle_advanced(this);return false;"><span class="dashicons dashicons-admin-settings" style="width: 28px;font-size: 28px;"></span></button>'; |
|
| 1138 | + var $button = '<button title="<?php _e('Advanced Settings'); ?>" style="line-height: 28px;" class="button button-primary right sd-advanced-button" onclick="sd_toggle_advanced(this);return false;"><span class="dashicons dashicons-admin-settings" style="width: 28px;font-size: 28px;"></span></button>'; |
|
| 1139 | 1139 | var form = jQuery($this).parents('' + $selector + ''); |
| 1140 | 1140 | |
| 1141 | 1141 | if (jQuery($this).val() == '1' && jQuery(form).find('.sd-advanced-button').length == 0) { |
@@ -1227,7 +1227,7 @@ discard block |
||
| 1227 | 1227 | }); |
| 1228 | 1228 | |
| 1229 | 1229 | } |
| 1230 | - <?php do_action( 'wp_super_duper_widget_js', $this ); ?> |
|
| 1230 | + <?php do_action('wp_super_duper_widget_js', $this); ?> |
|
| 1231 | 1231 | </script> |
| 1232 | 1232 | <?php |
| 1233 | 1233 | $output = ob_get_clean(); |
@@ -1236,10 +1236,10 @@ discard block |
||
| 1236 | 1236 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 1237 | 1237 | */ |
| 1238 | 1238 | |
| 1239 | - return str_replace( array( |
|
| 1239 | + return str_replace(array( |
|
| 1240 | 1240 | '<script>', |
| 1241 | 1241 | '</script>' |
| 1242 | - ), '', $output ); |
|
| 1242 | + ), '', $output); |
|
| 1243 | 1243 | } |
| 1244 | 1244 | |
| 1245 | 1245 | |
@@ -1250,14 +1250,14 @@ discard block |
||
| 1250 | 1250 | * |
| 1251 | 1251 | * @return mixed |
| 1252 | 1252 | */ |
| 1253 | - private function add_name_from_key( $options, $arguments = false ) { |
|
| 1254 | - if ( ! empty( $options['arguments'] ) ) { |
|
| 1255 | - foreach ( $options['arguments'] as $key => $val ) { |
|
| 1256 | - $options['arguments'][ $key ]['name'] = $key; |
|
| 1253 | + private function add_name_from_key($options, $arguments = false) { |
|
| 1254 | + if (!empty($options['arguments'])) { |
|
| 1255 | + foreach ($options['arguments'] as $key => $val) { |
|
| 1256 | + $options['arguments'][$key]['name'] = $key; |
|
| 1257 | 1257 | } |
| 1258 | - } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) { |
|
| 1259 | - foreach ( $options as $key => $val ) { |
|
| 1260 | - $options[ $key ]['name'] = $key; |
|
| 1258 | + } elseif ($arguments && is_array($options) && !empty($options)) { |
|
| 1259 | + foreach ($options as $key => $val) { |
|
| 1260 | + $options[$key]['name'] = $key; |
|
| 1261 | 1261 | } |
| 1262 | 1262 | } |
| 1263 | 1263 | |
@@ -1270,8 +1270,8 @@ discard block |
||
| 1270 | 1270 | * @since 1.0.0 |
| 1271 | 1271 | */ |
| 1272 | 1272 | public function register_shortcode() { |
| 1273 | - add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) ); |
|
| 1274 | - add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) ); |
|
| 1273 | + add_shortcode($this->base_id, array($this, 'shortcode_output')); |
|
| 1274 | + add_action('wp_ajax_super_duper_output_shortcode', array(__CLASS__, 'render_shortcode')); |
|
| 1275 | 1275 | } |
| 1276 | 1276 | |
| 1277 | 1277 | /** |
@@ -1281,33 +1281,33 @@ discard block |
||
| 1281 | 1281 | */ |
| 1282 | 1282 | public static function render_shortcode() { |
| 1283 | 1283 | |
| 1284 | - check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true ); |
|
| 1285 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 1284 | + check_ajax_referer('super_duper_output_shortcode', '_ajax_nonce', true); |
|
| 1285 | + if (!current_user_can('manage_options')) { |
|
| 1286 | 1286 | wp_die(); |
| 1287 | 1287 | } |
| 1288 | 1288 | |
| 1289 | 1289 | // we might need the $post value here so lets set it. |
| 1290 | - if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) { |
|
| 1291 | - $post_obj = get_post( absint( $_POST['post_id'] ) ); |
|
| 1292 | - if ( ! empty( $post_obj ) && empty( $post ) ) { |
|
| 1290 | + if (isset($_POST['post_id']) && $_POST['post_id']) { |
|
| 1291 | + $post_obj = get_post(absint($_POST['post_id'])); |
|
| 1292 | + if (!empty($post_obj) && empty($post)) { |
|
| 1293 | 1293 | global $post; |
| 1294 | 1294 | $post = $post_obj; |
| 1295 | 1295 | } |
| 1296 | 1296 | } |
| 1297 | 1297 | |
| 1298 | - if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) { |
|
| 1299 | - $shortcode_name = sanitize_title_with_dashes( $_POST['shortcode'] ); |
|
| 1300 | - $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
| 1298 | + if (isset($_POST['shortcode']) && $_POST['shortcode']) { |
|
| 1299 | + $shortcode_name = sanitize_title_with_dashes($_POST['shortcode']); |
|
| 1300 | + $attributes_array = isset($_POST['attributes']) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
| 1301 | 1301 | $attributes = ''; |
| 1302 | - if ( ! empty( $attributes_array ) ) { |
|
| 1303 | - foreach ( $attributes_array as $key => $value ) { |
|
| 1304 | - $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' "; |
|
| 1302 | + if (!empty($attributes_array)) { |
|
| 1303 | + foreach ($attributes_array as $key => $value) { |
|
| 1304 | + $attributes .= " " . sanitize_title_with_dashes($key) . "='" . wp_slash($value) . "' "; |
|
| 1305 | 1305 | } |
| 1306 | 1306 | } |
| 1307 | 1307 | |
| 1308 | 1308 | $shortcode = "[" . $shortcode_name . " " . $attributes . "]"; |
| 1309 | 1309 | |
| 1310 | - echo do_shortcode( $shortcode ); |
|
| 1310 | + echo do_shortcode($shortcode); |
|
| 1311 | 1311 | |
| 1312 | 1312 | } |
| 1313 | 1313 | wp_die(); |
@@ -1321,45 +1321,45 @@ discard block |
||
| 1321 | 1321 | * |
| 1322 | 1322 | * @return string |
| 1323 | 1323 | */ |
| 1324 | - public function shortcode_output( $args = array(), $content = '' ) { |
|
| 1325 | - $args = $this->argument_values( $args ); |
|
| 1324 | + public function shortcode_output($args = array(), $content = '') { |
|
| 1325 | + $args = $this->argument_values($args); |
|
| 1326 | 1326 | |
| 1327 | 1327 | // add extra argument so we know its a output to gutenberg |
| 1328 | 1328 | //$args |
| 1329 | - $args = $this->string_to_bool( $args ); |
|
| 1329 | + $args = $this->string_to_bool($args); |
|
| 1330 | 1330 | |
| 1331 | 1331 | // if we have a enclosed shortcode we add it to the special `html` argument |
| 1332 | - if ( ! empty( $content ) ) { |
|
| 1332 | + if (!empty($content)) { |
|
| 1333 | 1333 | $args['html'] = $content; |
| 1334 | 1334 | } |
| 1335 | 1335 | |
| 1336 | - $class = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : ''; |
|
| 1337 | - $class .= " sdel-".$this->get_instance_hash(); |
|
| 1336 | + $class = isset($this->options['widget_ops']['classname']) ? esc_attr($this->options['widget_ops']['classname']) : ''; |
|
| 1337 | + $class .= " sdel-" . $this->get_instance_hash(); |
|
| 1338 | 1338 | |
| 1339 | - $class = apply_filters( 'wp_super_duper_div_classname', $class, $args, $this ); |
|
| 1340 | - $class = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $class, $args, $this ); |
|
| 1339 | + $class = apply_filters('wp_super_duper_div_classname', $class, $args, $this); |
|
| 1340 | + $class = apply_filters('wp_super_duper_div_classname_' . $this->base_id, $class, $args, $this); |
|
| 1341 | 1341 | |
| 1342 | - $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this ); |
|
| 1343 | - $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this ); //@todo this does not seem right @kiran? |
|
| 1342 | + $attrs = apply_filters('wp_super_duper_div_attrs', '', $args, $this); |
|
| 1343 | + $attrs = apply_filters('wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this); //@todo this does not seem right @kiran? |
|
| 1344 | 1344 | |
| 1345 | 1345 | $shortcode_args = array(); |
| 1346 | 1346 | $output = ''; |
| 1347 | - $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false; |
|
| 1348 | - if ( isset( $args['no_wrap'] ) && $args['no_wrap'] ) { |
|
| 1347 | + $no_wrap = isset($this->options['no_wrap']) && $this->options['no_wrap'] ? true : false; |
|
| 1348 | + if (isset($args['no_wrap']) && $args['no_wrap']) { |
|
| 1349 | 1349 | $no_wrap = true; |
| 1350 | 1350 | } |
| 1351 | - $main_content = $this->output( $args, $shortcode_args, $content ); |
|
| 1352 | - if ( $main_content && ! $no_wrap ) { |
|
| 1351 | + $main_content = $this->output($args, $shortcode_args, $content); |
|
| 1352 | + if ($main_content && !$no_wrap) { |
|
| 1353 | 1353 | // wrap the shortcode in a div with the same class as the widget |
| 1354 | 1354 | $output .= '<div class="' . $class . '" ' . $attrs . '>'; |
| 1355 | - if ( ! empty( $args['title'] ) ) { |
|
| 1355 | + if (!empty($args['title'])) { |
|
| 1356 | 1356 | // if its a shortcode and there is a title try to grab the title wrappers |
| 1357 | - $shortcode_args = array( 'before_title' => '', 'after_title' => '' ); |
|
| 1358 | - if ( empty( $instance ) ) { |
|
| 1357 | + $shortcode_args = array('before_title' => '', 'after_title' => ''); |
|
| 1358 | + if (empty($instance)) { |
|
| 1359 | 1359 | global $wp_registered_sidebars; |
| 1360 | - if ( ! empty( $wp_registered_sidebars ) ) { |
|
| 1361 | - foreach ( $wp_registered_sidebars as $sidebar ) { |
|
| 1362 | - if ( ! empty( $sidebar['before_title'] ) ) { |
|
| 1360 | + if (!empty($wp_registered_sidebars)) { |
|
| 1361 | + foreach ($wp_registered_sidebars as $sidebar) { |
|
| 1362 | + if (!empty($sidebar['before_title'])) { |
|
| 1363 | 1363 | $shortcode_args['before_title'] = $sidebar['before_title']; |
| 1364 | 1364 | $shortcode_args['after_title'] = $sidebar['after_title']; |
| 1365 | 1365 | break; |
@@ -1367,20 +1367,20 @@ discard block |
||
| 1367 | 1367 | } |
| 1368 | 1368 | } |
| 1369 | 1369 | } |
| 1370 | - $output .= $this->output_title( $shortcode_args, $args ); |
|
| 1370 | + $output .= $this->output_title($shortcode_args, $args); |
|
| 1371 | 1371 | } |
| 1372 | 1372 | $output .= $main_content; |
| 1373 | 1373 | $output .= '</div>'; |
| 1374 | - } elseif ( $main_content && $no_wrap ) { |
|
| 1374 | + } elseif ($main_content && $no_wrap) { |
|
| 1375 | 1375 | $output .= $main_content; |
| 1376 | 1376 | } |
| 1377 | 1377 | |
| 1378 | 1378 | // if preview show a placeholder if empty |
| 1379 | - if ( $this->is_preview() && $output == '' ) { |
|
| 1380 | - $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" ); |
|
| 1379 | + if ($this->is_preview() && $output == '') { |
|
| 1380 | + $output = $this->preview_placeholder_text("{{" . $this->base_id . "}}"); |
|
| 1381 | 1381 | } |
| 1382 | 1382 | |
| 1383 | - return apply_filters( 'wp_super_duper_widget_output', $output, $args, $shortcode_args, $this ); |
|
| 1383 | + return apply_filters('wp_super_duper_widget_output', $output, $args, $shortcode_args, $this); |
|
| 1384 | 1384 | } |
| 1385 | 1385 | |
| 1386 | 1386 | /** |
@@ -1390,8 +1390,8 @@ discard block |
||
| 1390 | 1390 | * |
| 1391 | 1391 | * @return string |
| 1392 | 1392 | */ |
| 1393 | - public function preview_placeholder_text( $name = '' ) { |
|
| 1394 | - return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>"; |
|
| 1393 | + public function preview_placeholder_text($name = '') { |
|
| 1394 | + return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf(__('Placeholder for: %s'), $name) . "</div>"; |
|
| 1395 | 1395 | } |
| 1396 | 1396 | |
| 1397 | 1397 | /** |
@@ -1401,13 +1401,13 @@ discard block |
||
| 1401 | 1401 | * |
| 1402 | 1402 | * @return mixed |
| 1403 | 1403 | */ |
| 1404 | - public function string_to_bool( $options ) { |
|
| 1404 | + public function string_to_bool($options) { |
|
| 1405 | 1405 | // convert bool strings to booleans |
| 1406 | - foreach ( $options as $key => $val ) { |
|
| 1407 | - if ( $val == 'false' ) { |
|
| 1408 | - $options[ $key ] = false; |
|
| 1409 | - } elseif ( $val == 'true' ) { |
|
| 1410 | - $options[ $key ] = true; |
|
| 1406 | + foreach ($options as $key => $val) { |
|
| 1407 | + if ($val == 'false') { |
|
| 1408 | + $options[$key] = false; |
|
| 1409 | + } elseif ($val == 'true') { |
|
| 1410 | + $options[$key] = true; |
|
| 1411 | 1411 | } |
| 1412 | 1412 | } |
| 1413 | 1413 | |
@@ -1423,26 +1423,26 @@ discard block |
||
| 1423 | 1423 | * |
| 1424 | 1424 | * @return array |
| 1425 | 1425 | */ |
| 1426 | - public function argument_values( $instance ) { |
|
| 1426 | + public function argument_values($instance) { |
|
| 1427 | 1427 | $argument_values = array(); |
| 1428 | 1428 | |
| 1429 | 1429 | // set widget instance |
| 1430 | 1430 | $this->instance = $instance; |
| 1431 | 1431 | |
| 1432 | - if ( empty( $this->arguments ) ) { |
|
| 1432 | + if (empty($this->arguments)) { |
|
| 1433 | 1433 | $this->arguments = $this->get_arguments(); |
| 1434 | 1434 | } |
| 1435 | 1435 | |
| 1436 | - if ( ! empty( $this->arguments ) ) { |
|
| 1437 | - foreach ( $this->arguments as $key => $args ) { |
|
| 1436 | + if (!empty($this->arguments)) { |
|
| 1437 | + foreach ($this->arguments as $key => $args) { |
|
| 1438 | 1438 | // set the input name from the key |
| 1439 | 1439 | $args['name'] = $key; |
| 1440 | 1440 | // |
| 1441 | - $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
|
| 1442 | - if ( $args['type'] == 'checkbox' && $argument_values[ $key ] == '' ) { |
|
| 1441 | + $argument_values[$key] = isset($instance[$key]) ? $instance[$key] : ''; |
|
| 1442 | + if ($args['type'] == 'checkbox' && $argument_values[$key] == '') { |
|
| 1443 | 1443 | // don't set default for an empty checkbox |
| 1444 | - } elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
| 1445 | - $argument_values[ $key ] = $args['default']; |
|
| 1444 | + } elseif ($argument_values[$key] == '' && isset($args['default'])) { |
|
| 1445 | + $argument_values[$key] = $args['default']; |
|
| 1446 | 1446 | } |
| 1447 | 1447 | } |
| 1448 | 1448 | } |
@@ -1469,12 +1469,12 @@ discard block |
||
| 1469 | 1469 | * @return array Get arguments. |
| 1470 | 1470 | */ |
| 1471 | 1471 | public function get_arguments() { |
| 1472 | - if ( empty( $this->arguments ) ) { |
|
| 1472 | + if (empty($this->arguments)) { |
|
| 1473 | 1473 | $this->arguments = $this->set_arguments(); |
| 1474 | 1474 | } |
| 1475 | 1475 | |
| 1476 | - $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance ); |
|
| 1477 | - $this->arguments = $this->add_name_from_key( $this->arguments, true ); |
|
| 1476 | + $this->arguments = apply_filters('wp_super_duper_arguments', $this->arguments, $this->options, $this->instance); |
|
| 1477 | + $this->arguments = $this->add_name_from_key($this->arguments, true); |
|
| 1478 | 1478 | |
| 1479 | 1479 | return $this->arguments; |
| 1480 | 1480 | } |
@@ -1486,7 +1486,7 @@ discard block |
||
| 1486 | 1486 | * @param array $widget_args |
| 1487 | 1487 | * @param string $content |
| 1488 | 1488 | */ |
| 1489 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 1489 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
| 1490 | 1490 | |
| 1491 | 1491 | } |
| 1492 | 1492 | |
@@ -1494,9 +1494,9 @@ discard block |
||
| 1494 | 1494 | * Add the dynamic block code inline when the wp-block in enqueued. |
| 1495 | 1495 | */ |
| 1496 | 1496 | public function register_block() { |
| 1497 | - wp_add_inline_script( 'wp-blocks', $this->block() ); |
|
| 1498 | - if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
| 1499 | - wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() ); |
|
| 1497 | + wp_add_inline_script('wp-blocks', $this->block()); |
|
| 1498 | + if (class_exists('SiteOrigin_Panels')) { |
|
| 1499 | + wp_add_inline_script('wp-blocks', $this->siteorigin_js()); |
|
| 1500 | 1500 | } |
| 1501 | 1501 | } |
| 1502 | 1502 | |
@@ -1510,13 +1510,13 @@ discard block |
||
| 1510 | 1510 | $show = false; |
| 1511 | 1511 | $arguments = $this->arguments; |
| 1512 | 1512 | |
| 1513 | - if ( empty( $arguments ) ) { |
|
| 1513 | + if (empty($arguments)) { |
|
| 1514 | 1514 | $arguments = $this->get_arguments(); |
| 1515 | 1515 | } |
| 1516 | 1516 | |
| 1517 | - if ( ! empty( $arguments ) ) { |
|
| 1518 | - foreach ( $arguments as $argument ) { |
|
| 1519 | - if ( isset( $argument['advanced'] ) && $argument['advanced'] ) { |
|
| 1517 | + if (!empty($arguments)) { |
|
| 1518 | + foreach ($arguments as $argument) { |
|
| 1519 | + if (isset($argument['advanced']) && $argument['advanced']) { |
|
| 1520 | 1520 | $show = true; |
| 1521 | 1521 | break; // no need to continue if we know we have it |
| 1522 | 1522 | } |
@@ -1535,15 +1535,15 @@ discard block |
||
| 1535 | 1535 | |
| 1536 | 1536 | $url = $this->url; |
| 1537 | 1537 | |
| 1538 | - if ( ! $url ) { |
|
| 1538 | + if (!$url) { |
|
| 1539 | 1539 | // check if we are inside a plugin |
| 1540 | - $file_dir = str_replace( "/includes", "", dirname( __FILE__ ) ); |
|
| 1540 | + $file_dir = str_replace("/includes", "", dirname(__FILE__)); |
|
| 1541 | 1541 | |
| 1542 | - $dir_parts = explode( "/wp-content/", $file_dir ); |
|
| 1543 | - $url_parts = explode( "/wp-content/", plugins_url() ); |
|
| 1542 | + $dir_parts = explode("/wp-content/", $file_dir); |
|
| 1543 | + $url_parts = explode("/wp-content/", plugins_url()); |
|
| 1544 | 1544 | |
| 1545 | - if ( ! empty( $url_parts[0] ) && ! empty( $dir_parts[1] ) ) { |
|
| 1546 | - $url = trailingslashit( $url_parts[0] . "/wp-content/" . $dir_parts[1] ); |
|
| 1545 | + if (!empty($url_parts[0]) && !empty($dir_parts[1])) { |
|
| 1546 | + $url = trailingslashit($url_parts[0] . "/wp-content/" . $dir_parts[1]); |
|
| 1547 | 1547 | $this->url = $url; |
| 1548 | 1548 | } |
| 1549 | 1549 | } |
@@ -1564,46 +1564,46 @@ discard block |
||
| 1564 | 1564 | * @since 1.1.0 |
| 1565 | 1565 | * @return string |
| 1566 | 1566 | */ |
| 1567 | - public function get_block_icon( $icon ) { |
|
| 1567 | + public function get_block_icon($icon) { |
|
| 1568 | 1568 | |
| 1569 | 1569 | // check if we have a Font Awesome icon |
| 1570 | 1570 | $fa_type = ''; |
| 1571 | - if ( substr( $icon, 0, 7 ) === "fas fa-" ) { |
|
| 1571 | + if (substr($icon, 0, 7) === "fas fa-") { |
|
| 1572 | 1572 | $fa_type = 'solid'; |
| 1573 | - } elseif ( substr( $icon, 0, 7 ) === "far fa-" ) { |
|
| 1573 | + } elseif (substr($icon, 0, 7) === "far fa-") { |
|
| 1574 | 1574 | $fa_type = 'regular'; |
| 1575 | - } elseif ( substr( $icon, 0, 7 ) === "fab fa-" ) { |
|
| 1575 | + } elseif (substr($icon, 0, 7) === "fab fa-") { |
|
| 1576 | 1576 | $fa_type = 'brands'; |
| 1577 | 1577 | } else { |
| 1578 | 1578 | $icon = "'" . $icon . "'"; |
| 1579 | 1579 | } |
| 1580 | 1580 | |
| 1581 | 1581 | // set the icon if we found one |
| 1582 | - if ( $fa_type ) { |
|
| 1583 | - $fa_icon = str_replace( array( "fas fa-", "far fa-", "fab fa-" ), "", $icon ); |
|
| 1582 | + if ($fa_type) { |
|
| 1583 | + $fa_icon = str_replace(array("fas fa-", "far fa-", "fab fa-"), "", $icon); |
|
| 1584 | 1584 | $icon = "el('svg',{width: 20, height: 20, viewBox: '0 0 20 20'},el('use', {'xlink:href': '" . $this->get_url() . "icons/" . $fa_type . ".svg#" . $fa_icon . "','href': '" . $this->get_url() . "icons/" . $fa_type . ".svg#" . $fa_icon . "'}))"; |
| 1585 | 1585 | } |
| 1586 | 1586 | |
| 1587 | 1587 | return $icon; |
| 1588 | 1588 | } |
| 1589 | 1589 | |
| 1590 | - public function group_arguments( $arguments ) { |
|
| 1590 | + public function group_arguments($arguments) { |
|
| 1591 | 1591 | // echo '###';print_r($arguments); |
| 1592 | - if ( ! empty( $arguments ) ) { |
|
| 1592 | + if (!empty($arguments)) { |
|
| 1593 | 1593 | $temp_arguments = array(); |
| 1594 | - $general = __( "General" ); |
|
| 1594 | + $general = __("General"); |
|
| 1595 | 1595 | $add_sections = false; |
| 1596 | - foreach ( $arguments as $key => $args ) { |
|
| 1597 | - if ( isset( $args['group'] ) ) { |
|
| 1598 | - $temp_arguments[ $args['group'] ][ $key ] = $args; |
|
| 1596 | + foreach ($arguments as $key => $args) { |
|
| 1597 | + if (isset($args['group'])) { |
|
| 1598 | + $temp_arguments[$args['group']][$key] = $args; |
|
| 1599 | 1599 | $add_sections = true; |
| 1600 | 1600 | } else { |
| 1601 | - $temp_arguments[ $general ][ $key ] = $args; |
|
| 1601 | + $temp_arguments[$general][$key] = $args; |
|
| 1602 | 1602 | } |
| 1603 | 1603 | } |
| 1604 | 1604 | |
| 1605 | 1605 | // only add sections if more than one |
| 1606 | - if ( $add_sections ) { |
|
| 1606 | + if ($add_sections) { |
|
| 1607 | 1607 | $arguments = $temp_arguments; |
| 1608 | 1608 | } |
| 1609 | 1609 | } |
@@ -1647,9 +1647,9 @@ discard block |
||
| 1647 | 1647 | var prev_attributes = []; |
| 1648 | 1648 | |
| 1649 | 1649 | var term_query_type = ''; |
| 1650 | - var post_type_rest_slugs = <?php if(! empty( $this->arguments ) && isset($this->arguments['post_type']['onchange_rest']['values'])){echo "[".json_encode($this->arguments['post_type']['onchange_rest']['values'])."]";}else{echo "[]";} ?>; |
|
| 1651 | - const taxonomies_<?php echo str_replace("-","_", $this->id);?> = [{label: "Please wait", value: 0}]; |
|
| 1652 | - const sort_by_<?php echo str_replace("-","_", $this->id);?> = [{label: "Please wait", value: 0}]; |
|
| 1650 | + var post_type_rest_slugs = <?php if (!empty($this->arguments) && isset($this->arguments['post_type']['onchange_rest']['values'])) {echo "[" . json_encode($this->arguments['post_type']['onchange_rest']['values']) . "]"; } else {echo "[]"; } ?>; |
|
| 1651 | + const taxonomies_<?php echo str_replace("-", "_", $this->id); ?> = [{label: "Please wait", value: 0}]; |
|
| 1652 | + const sort_by_<?php echo str_replace("-", "_", $this->id); ?> = [{label: "Please wait", value: 0}]; |
|
| 1653 | 1653 | |
| 1654 | 1654 | /** |
| 1655 | 1655 | * Register Basic Block. |
@@ -1663,30 +1663,30 @@ discard block |
||
| 1663 | 1663 | * @return {?WPBlock} The block, if it has been successfully |
| 1664 | 1664 | * registered; otherwise `undefined`. |
| 1665 | 1665 | */ |
| 1666 | - registerBlockType('<?php echo str_replace( "_", "-", sanitize_title_with_dashes( $this->options['textdomain'] ) . '/' . sanitize_title_with_dashes( $this->options['class_name'] ) ); ?>', { // Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block. |
|
| 1667 | - title: '<?php echo addslashes( $this->options['name'] ); ?>', // Block title. |
|
| 1668 | - description: '<?php echo addslashes( $this->options['widget_ops']['description'] )?>', // Block title. |
|
| 1669 | - icon: <?php echo $this->get_block_icon( $this->options['block-icon'] );?>,//'<?php echo isset( $this->options['block-icon'] ) ? esc_attr( $this->options['block-icon'] ) : 'shield-alt';?>', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/. |
|
| 1666 | + registerBlockType('<?php echo str_replace("_", "-", sanitize_title_with_dashes($this->options['textdomain']) . '/' . sanitize_title_with_dashes($this->options['class_name'])); ?>', { // Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block. |
|
| 1667 | + title: '<?php echo addslashes($this->options['name']); ?>', // Block title. |
|
| 1668 | + description: '<?php echo addslashes($this->options['widget_ops']['description'])?>', // Block title. |
|
| 1669 | + icon: <?php echo $this->get_block_icon($this->options['block-icon']); ?>,//'<?php echo isset($this->options['block-icon']) ? esc_attr($this->options['block-icon']) : 'shield-alt'; ?>', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/. |
|
| 1670 | 1670 | supports: { |
| 1671 | 1671 | <?php |
| 1672 | - if ( isset( $this->options['block-supports'] ) ) { |
|
| 1673 | - echo $this->array_to_attributes( $this->options['block-supports'] ); |
|
| 1672 | + if (isset($this->options['block-supports'])) { |
|
| 1673 | + echo $this->array_to_attributes($this->options['block-supports']); |
|
| 1674 | 1674 | } |
| 1675 | 1675 | ?> |
| 1676 | 1676 | }, |
| 1677 | - category: '<?php echo isset( $this->options['block-category'] ) ? esc_attr( $this->options['block-category'] ) : 'common';?>', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed. |
|
| 1678 | - <?php if ( isset( $this->options['block-keywords'] ) ) { |
|
| 1677 | + category: '<?php echo isset($this->options['block-category']) ? esc_attr($this->options['block-category']) : 'common'; ?>', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed. |
|
| 1678 | + <?php if (isset($this->options['block-keywords'])) { |
|
| 1679 | 1679 | echo "keywords : " . $this->options['block-keywords'] . ","; |
| 1680 | 1680 | }?> |
| 1681 | 1681 | |
| 1682 | 1682 | <?php |
| 1683 | 1683 | |
| 1684 | 1684 | // maybe set no_wrap |
| 1685 | - $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false; |
|
| 1686 | - if ( isset( $this->arguments['no_wrap'] ) && $this->arguments['no_wrap'] ) { |
|
| 1685 | + $no_wrap = isset($this->options['no_wrap']) && $this->options['no_wrap'] ? true : false; |
|
| 1686 | + if (isset($this->arguments['no_wrap']) && $this->arguments['no_wrap']) { |
|
| 1687 | 1687 | $no_wrap = true; |
| 1688 | 1688 | } |
| 1689 | - if ( $no_wrap ) { |
|
| 1689 | + if ($no_wrap) { |
|
| 1690 | 1690 | $this->options['block-wrap'] = ''; |
| 1691 | 1691 | } |
| 1692 | 1692 | |
@@ -1699,10 +1699,10 @@ discard block |
||
| 1699 | 1699 | echo " html: false"; |
| 1700 | 1700 | echo "},";*/ |
| 1701 | 1701 | |
| 1702 | - if ( ! empty( $this->arguments ) ) { |
|
| 1702 | + if (!empty($this->arguments)) { |
|
| 1703 | 1703 | echo "attributes : {"; |
| 1704 | 1704 | |
| 1705 | - if ( $show_advanced ) { |
|
| 1705 | + if ($show_advanced) { |
|
| 1706 | 1706 | echo "show_advanced: {"; |
| 1707 | 1707 | echo " type: 'boolean',"; |
| 1708 | 1708 | echo " default: false,"; |
@@ -1710,41 +1710,41 @@ discard block |
||
| 1710 | 1710 | } |
| 1711 | 1711 | |
| 1712 | 1712 | // block wrap element |
| 1713 | - if ( ! empty( $this->options['block-wrap'] ) ) { //@todo we should validate this? |
|
| 1713 | + if (!empty($this->options['block-wrap'])) { //@todo we should validate this? |
|
| 1714 | 1714 | echo "block_wrap: {"; |
| 1715 | 1715 | echo " type: 'string',"; |
| 1716 | - echo " default: '" . esc_attr( $this->options['block-wrap'] ) . "',"; |
|
| 1716 | + echo " default: '" . esc_attr($this->options['block-wrap']) . "',"; |
|
| 1717 | 1717 | echo "},"; |
| 1718 | 1718 | } |
| 1719 | 1719 | |
| 1720 | - foreach ( $this->arguments as $key => $args ) { |
|
| 1720 | + foreach ($this->arguments as $key => $args) { |
|
| 1721 | 1721 | |
| 1722 | 1722 | // set if we should show alignment |
| 1723 | - if ( $key == 'alignment' ) { |
|
| 1723 | + if ($key == 'alignment') { |
|
| 1724 | 1724 | $show_alignment = true; |
| 1725 | 1725 | } |
| 1726 | 1726 | |
| 1727 | 1727 | $extra = ''; |
| 1728 | 1728 | |
| 1729 | - if ( $args['type'] == 'checkbox' ) { |
|
| 1729 | + if ($args['type'] == 'checkbox') { |
|
| 1730 | 1730 | $type = 'boolean'; |
| 1731 | - $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false'; |
|
| 1732 | - } elseif ( $args['type'] == 'number' ) { |
|
| 1731 | + $default = isset($args['default']) && $args['default'] ? 'true' : 'false'; |
|
| 1732 | + } elseif ($args['type'] == 'number') { |
|
| 1733 | 1733 | $type = 'number'; |
| 1734 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1735 | - } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) { |
|
| 1734 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
| 1735 | + } elseif ($args['type'] == 'select' && !empty($args['multiple'])) { |
|
| 1736 | 1736 | $type = 'array'; |
| 1737 | - if ( is_array( $args['default'] ) ) { |
|
| 1738 | - $default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]"; |
|
| 1737 | + if (is_array($args['default'])) { |
|
| 1738 | + $default = isset($args['default']) ? "['" . implode("','", $args['default']) . "']" : "[]"; |
|
| 1739 | 1739 | } else { |
| 1740 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1740 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
| 1741 | 1741 | } |
| 1742 | - } elseif ( $args['type'] == 'multiselect' ) { |
|
| 1742 | + } elseif ($args['type'] == 'multiselect') { |
|
| 1743 | 1743 | $type = 'array'; |
| 1744 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1744 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
| 1745 | 1745 | } else { |
| 1746 | 1746 | $type = 'string'; |
| 1747 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
| 1747 | + $default = isset($args['default']) ? "'" . $args['default'] . "'" : "''"; |
|
| 1748 | 1748 | } |
| 1749 | 1749 | echo $key . " : {"; |
| 1750 | 1750 | echo "type : '$type',"; |
@@ -1768,7 +1768,7 @@ discard block |
||
| 1768 | 1768 | var $value = ''; |
| 1769 | 1769 | <?php |
| 1770 | 1770 | // if we have a post_type and a category then link them |
| 1771 | - if( isset($this->arguments['post_type']) && isset($this->arguments['category']) && !empty($this->arguments['category']['post_type_linked']) ){ |
|
| 1771 | + if (isset($this->arguments['post_type']) && isset($this->arguments['category']) && !empty($this->arguments['category']['post_type_linked'])) { |
|
| 1772 | 1772 | ?> |
| 1773 | 1773 | if(typeof(prev_attributes[props.id]) != 'undefined' ){ |
| 1774 | 1774 | $pt = props.attributes.post_type; |
@@ -1784,13 +1784,13 @@ discard block |
||
| 1784 | 1784 | |
| 1785 | 1785 | // taxonomies |
| 1786 | 1786 | if( $value && 'post_type' in prev_attributes[props.id] && 'category' in prev_attributes[props.id] && run ){ |
| 1787 | - wp.apiFetch({path: "<?php if(isset($this->arguments['post_type']['onchange_rest']['path'])){echo $this->arguments['post_type']['onchange_rest']['path'];}else{'/wp/v2/"+$value+"/categories';} ?>"}).then(terms => { |
|
| 1788 | - while (taxonomies_<?php echo str_replace("-","_", $this->id);?>.length) { |
|
| 1789 | - taxonomies_<?php echo str_replace("-","_", $this->id);?>.pop(); |
|
| 1787 | + wp.apiFetch({path: "<?php if (isset($this->arguments['post_type']['onchange_rest']['path'])) {echo $this->arguments['post_type']['onchange_rest']['path']; } else {'/wp/v2/"+$value+"/categories'; } ?>"}).then(terms => { |
|
| 1788 | + while (taxonomies_<?php echo str_replace("-", "_", $this->id); ?>.length) { |
|
| 1789 | + taxonomies_<?php echo str_replace("-", "_", $this->id); ?>.pop(); |
|
| 1790 | 1790 | } |
| 1791 | - taxonomies_<?php echo str_replace("-","_", $this->id);?>.push({label: "All", value: 0}); |
|
| 1791 | + taxonomies_<?php echo str_replace("-", "_", $this->id); ?>.push({label: "All", value: 0}); |
|
| 1792 | 1792 | jQuery.each( terms, function( key, val ) { |
| 1793 | - taxonomies_<?php echo str_replace("-","_", $this->id);?>.push({label: val.name, value: val.id}); |
|
| 1793 | + taxonomies_<?php echo str_replace("-", "_", $this->id); ?>.push({label: val.name, value: val.id}); |
|
| 1794 | 1794 | }); |
| 1795 | 1795 | |
| 1796 | 1796 | // setting the value back and fourth fixes the no update issue that sometimes happens where it won't update the options. |
@@ -1798,7 +1798,7 @@ discard block |
||
| 1798 | 1798 | props.setAttributes({category: [0] }); |
| 1799 | 1799 | props.setAttributes({category: $old_cat_value }); |
| 1800 | 1800 | |
| 1801 | - return taxonomies_<?php echo str_replace("-","_", $this->id);?>; |
|
| 1801 | + return taxonomies_<?php echo str_replace("-", "_", $this->id); ?>; |
|
| 1802 | 1802 | }); |
| 1803 | 1803 | } |
| 1804 | 1804 | |
@@ -1810,12 +1810,12 @@ discard block |
||
| 1810 | 1810 | }; |
| 1811 | 1811 | jQuery.post(ajaxurl, data, function(response) { |
| 1812 | 1812 | response = JSON.parse(response); |
| 1813 | - while (sort_by_<?php echo str_replace("-","_", $this->id);?>.length) { |
|
| 1814 | - sort_by_<?php echo str_replace("-","_", $this->id);?>.pop(); |
|
| 1813 | + while (sort_by_<?php echo str_replace("-", "_", $this->id); ?>.length) { |
|
| 1814 | + sort_by_<?php echo str_replace("-", "_", $this->id); ?>.pop(); |
|
| 1815 | 1815 | } |
| 1816 | 1816 | |
| 1817 | 1817 | jQuery.each( response, function( key, val ) { |
| 1818 | - sort_by_<?php echo str_replace("-","_", $this->id);?>.push({label: val, value: key}); |
|
| 1818 | + sort_by_<?php echo str_replace("-", "_", $this->id); ?>.push({label: val, value: key}); |
|
| 1819 | 1819 | }); |
| 1820 | 1820 | |
| 1821 | 1821 | // setting the value back and fourth fixes the no update issue that sometimes happens where it won't update the options. |
@@ -1823,7 +1823,7 @@ discard block |
||
| 1823 | 1823 | props.setAttributes({sort_by: [0] }); |
| 1824 | 1824 | props.setAttributes({sort_by: $old_sort_by_value }); |
| 1825 | 1825 | |
| 1826 | - return sort_by_<?php echo str_replace("-","_", $this->id);?>; |
|
| 1826 | + return sort_by_<?php echo str_replace("-", "_", $this->id); ?>; |
|
| 1827 | 1827 | }); |
| 1828 | 1828 | |
| 1829 | 1829 | } |
@@ -1850,12 +1850,12 @@ discard block |
||
| 1850 | 1850 | is_fetching = true; |
| 1851 | 1851 | var data = { |
| 1852 | 1852 | 'action': 'super_duper_output_shortcode', |
| 1853 | - 'shortcode': '<?php echo $this->options['base_id'];?>', |
|
| 1853 | + 'shortcode': '<?php echo $this->options['base_id']; ?>', |
|
| 1854 | 1854 | 'attributes': props.attributes, |
| 1855 | - 'post_id': <?php global $post; if ( isset( $post->ID ) ) { |
|
| 1855 | + 'post_id': <?php global $post; if (isset($post->ID)) { |
|
| 1856 | 1856 | echo $post->ID; |
| 1857 | 1857 | }?>, |
| 1858 | - '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>' |
|
| 1858 | + '_ajax_nonce': '<?php echo wp_create_nonce('super_duper_output_shortcode'); ?>' |
|
| 1859 | 1859 | }; |
| 1860 | 1860 | |
| 1861 | 1861 | jQuery.post(ajaxurl, data, function (response) { |
@@ -1864,7 +1864,7 @@ discard block |
||
| 1864 | 1864 | |
| 1865 | 1865 | // if the content is empty then we place some placeholder text |
| 1866 | 1866 | if (env == '') { |
| 1867 | - env = "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" + "<?php _e( 'Placeholder for: ' );?>" + props.name + "</div>"; |
|
| 1867 | + env = "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" + "<?php _e('Placeholder for: '); ?>" + props.name + "</div>"; |
|
| 1868 | 1868 | } |
| 1869 | 1869 | |
| 1870 | 1870 | props.setAttributes({content: env}); |
@@ -1888,7 +1888,7 @@ discard block |
||
| 1888 | 1888 | |
| 1889 | 1889 | el(wp.blockEditor.BlockControls, {key: 'controls'}, |
| 1890 | 1890 | |
| 1891 | - <?php if($show_alignment){?> |
|
| 1891 | + <?php if ($show_alignment) {?> |
|
| 1892 | 1892 | el( |
| 1893 | 1893 | wp.blockEditor.AlignmentToolbar, |
| 1894 | 1894 | { |
@@ -1906,9 +1906,9 @@ discard block |
||
| 1906 | 1906 | |
| 1907 | 1907 | <?php |
| 1908 | 1908 | |
| 1909 | - if(! empty( $this->arguments )){ |
|
| 1909 | + if (!empty($this->arguments)) { |
|
| 1910 | 1910 | |
| 1911 | - if ( $show_advanced ) { |
|
| 1911 | + if ($show_advanced) { |
|
| 1912 | 1912 | ?> |
| 1913 | 1913 | el('div', { |
| 1914 | 1914 | style: {'padding-left': '16px','padding-right': '16px'} |
@@ -1929,19 +1929,19 @@ discard block |
||
| 1929 | 1929 | |
| 1930 | 1930 | } |
| 1931 | 1931 | |
| 1932 | - $arguments = $this->group_arguments( $this->arguments ); |
|
| 1932 | + $arguments = $this->group_arguments($this->arguments); |
|
| 1933 | 1933 | |
| 1934 | 1934 | // Do we have sections? |
| 1935 | 1935 | $has_sections = $arguments == $this->arguments ? false : true; |
| 1936 | 1936 | |
| 1937 | 1937 | |
| 1938 | - if($has_sections){ |
|
| 1938 | + if ($has_sections) { |
|
| 1939 | 1939 | $panel_count = 0; |
| 1940 | - foreach($arguments as $key => $args){ |
|
| 1940 | + foreach ($arguments as $key => $args) { |
|
| 1941 | 1941 | ?> |
| 1942 | 1942 | el(wp.components.PanelBody, { |
| 1943 | - title: '<?php esc_attr_e( $key ); ?>', |
|
| 1944 | - initialOpen: <?php if ( $panel_count ) { |
|
| 1943 | + title: '<?php esc_attr_e($key); ?>', |
|
| 1944 | + initialOpen: <?php if ($panel_count) { |
|
| 1945 | 1945 | echo "false"; |
| 1946 | 1946 | } else { |
| 1947 | 1947 | echo "true"; |
@@ -1949,24 +1949,24 @@ discard block |
||
| 1949 | 1949 | }, |
| 1950 | 1950 | <?php |
| 1951 | 1951 | |
| 1952 | - foreach ( $args as $k => $a ) { |
|
| 1953 | - $this->build_block_arguments( $k, $a ); |
|
| 1952 | + foreach ($args as $k => $a) { |
|
| 1953 | + $this->build_block_arguments($k, $a); |
|
| 1954 | 1954 | } |
| 1955 | 1955 | ?> |
| 1956 | 1956 | ), |
| 1957 | 1957 | <?php |
| 1958 | - $panel_count ++; |
|
| 1958 | + $panel_count++; |
|
| 1959 | 1959 | |
| 1960 | 1960 | } |
| 1961 | - }else { |
|
| 1961 | + } else { |
|
| 1962 | 1962 | ?> |
| 1963 | 1963 | el(wp.components.PanelBody, { |
| 1964 | - title: '<?php esc_attr_e( "Settings" ); ?>', |
|
| 1964 | + title: '<?php esc_attr_e("Settings"); ?>', |
|
| 1965 | 1965 | initialOpen: true |
| 1966 | 1966 | }, |
| 1967 | 1967 | <?php |
| 1968 | - foreach ( $this->arguments as $key => $args ) { |
|
| 1969 | - $this->build_block_arguments( $key, $args ); |
|
| 1968 | + foreach ($this->arguments as $key => $args) { |
|
| 1969 | + $this->build_block_arguments($key, $args); |
|
| 1970 | 1970 | } |
| 1971 | 1971 | ?> |
| 1972 | 1972 | ), |
@@ -1980,9 +1980,9 @@ discard block |
||
| 1980 | 1980 | |
| 1981 | 1981 | <?php |
| 1982 | 1982 | // If the user sets block-output array then build it |
| 1983 | - if ( ! empty( $this->options['block-output'] ) ) { |
|
| 1984 | - $this->block_element( $this->options['block-output'] ); |
|
| 1985 | - }else{ |
|
| 1983 | + if (!empty($this->options['block-output'])) { |
|
| 1984 | + $this->block_element($this->options['block-output']); |
|
| 1985 | + } else { |
|
| 1986 | 1986 | // if no block-output is set then we try and get the shortcode html output via ajax. |
| 1987 | 1987 | ?> |
| 1988 | 1988 | el('div', { |
@@ -2006,19 +2006,19 @@ discard block |
||
| 2006 | 2006 | var align = ''; |
| 2007 | 2007 | |
| 2008 | 2008 | // build the shortcode. |
| 2009 | - var content = "[<?php echo $this->options['base_id'];?>"; |
|
| 2009 | + var content = "[<?php echo $this->options['base_id']; ?>"; |
|
| 2010 | 2010 | $html = ''; |
| 2011 | 2011 | <?php |
| 2012 | 2012 | |
| 2013 | - if(! empty( $this->arguments )){ |
|
| 2013 | + if (!empty($this->arguments)) { |
|
| 2014 | 2014 | |
| 2015 | - foreach($this->arguments as $key => $args){ |
|
| 2015 | + foreach ($this->arguments as $key => $args) { |
|
| 2016 | 2016 | ?> |
| 2017 | - if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) { |
|
| 2018 | - if ('<?php echo esc_attr( $key );?>' == 'html') { |
|
| 2019 | - $html = attr.<?php echo esc_attr( $key );?>; |
|
| 2017 | + if (attr.hasOwnProperty("<?php echo esc_attr($key); ?>")) { |
|
| 2018 | + if ('<?php echo esc_attr($key); ?>' == 'html') { |
|
| 2019 | + $html = attr.<?php echo esc_attr($key); ?>; |
|
| 2020 | 2020 | } else { |
| 2021 | - content += " <?php echo esc_attr( $key );?>='" + attr.<?php echo esc_attr( $key );?>+ "' "; |
|
| 2021 | + content += " <?php echo esc_attr($key); ?>='" + attr.<?php echo esc_attr($key); ?>+ "' "; |
|
| 2022 | 2022 | } |
| 2023 | 2023 | } |
| 2024 | 2024 | <?php |
@@ -2030,7 +2030,7 @@ discard block |
||
| 2030 | 2030 | |
| 2031 | 2031 | // if has html element |
| 2032 | 2032 | if ($html) { |
| 2033 | - content += $html + "[/<?php echo $this->options['base_id'];?>]"; |
|
| 2033 | + content += $html + "[/<?php echo $this->options['base_id']; ?>]"; |
|
| 2034 | 2034 | } |
| 2035 | 2035 | |
| 2036 | 2036 | |
@@ -2048,11 +2048,11 @@ discard block |
||
| 2048 | 2048 | } |
| 2049 | 2049 | |
| 2050 | 2050 | <?php |
| 2051 | - if(isset( $this->options['block-wrap'] ) && $this->options['block-wrap'] == ''){ |
|
| 2051 | + if (isset($this->options['block-wrap']) && $this->options['block-wrap'] == '') { |
|
| 2052 | 2052 | ?> |
| 2053 | 2053 | return content; |
| 2054 | 2054 | <?php |
| 2055 | - }else{ |
|
| 2055 | + } else { |
|
| 2056 | 2056 | ?> |
| 2057 | 2057 | var block_wrap = 'div'; |
| 2058 | 2058 | if (attr.hasOwnProperty("block_wrap")) { |
@@ -2075,38 +2075,38 @@ discard block |
||
| 2075 | 2075 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
| 2076 | 2076 | */ |
| 2077 | 2077 | |
| 2078 | - return str_replace( array( |
|
| 2078 | + return str_replace(array( |
|
| 2079 | 2079 | '<script>', |
| 2080 | 2080 | '</script>' |
| 2081 | - ), '', $output ); |
|
| 2081 | + ), '', $output); |
|
| 2082 | 2082 | } |
| 2083 | 2083 | |
| 2084 | - public function build_block_arguments( $key, $args ) { |
|
| 2085 | - $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : ''; |
|
| 2084 | + public function build_block_arguments($key, $args) { |
|
| 2085 | + $custom_attributes = !empty($args['custom_attributes']) ? $this->array_to_attributes($args['custom_attributes']) : ''; |
|
| 2086 | 2086 | $options = ''; |
| 2087 | 2087 | $extra = ''; |
| 2088 | 2088 | $require = ''; |
| 2089 | 2089 | |
| 2090 | 2090 | // `content` is a protected and special argument |
| 2091 | - if ( $key == 'content' ) { |
|
| 2091 | + if ($key == 'content') { |
|
| 2092 | 2092 | return; |
| 2093 | 2093 | } |
| 2094 | 2094 | |
| 2095 | 2095 | // require advanced |
| 2096 | - $require_advanced = ! empty( $args['advanced'] ) ? "props.attributes.show_advanced && " : ""; |
|
| 2096 | + $require_advanced = !empty($args['advanced']) ? "props.attributes.show_advanced && " : ""; |
|
| 2097 | 2097 | |
| 2098 | 2098 | // element require |
| 2099 | - $element_require = ! empty( $args['element_require'] ) ? $this->block_props_replace( $args['element_require'], true ) . " && " : ""; |
|
| 2099 | + $element_require = !empty($args['element_require']) ? $this->block_props_replace($args['element_require'], true) . " && " : ""; |
|
| 2100 | 2100 | |
| 2101 | 2101 | |
| 2102 | 2102 | $onchange = "props.setAttributes({ $key: $key } )"; |
| 2103 | - $onchangecomplete = ""; |
|
| 2103 | + $onchangecomplete = ""; |
|
| 2104 | 2104 | $value = "props.attributes.$key"; |
| 2105 | - $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'colorx' ); |
|
| 2106 | - if ( in_array( $args['type'], $text_type ) ) { |
|
| 2105 | + $text_type = array('text', 'password', 'number', 'email', 'tel', 'url', 'colorx'); |
|
| 2106 | + if (in_array($args['type'], $text_type)) { |
|
| 2107 | 2107 | $type = 'TextControl'; |
| 2108 | 2108 | // Save numbers as numbers and not strings |
| 2109 | - if ( $args['type'] == 'number' ) { |
|
| 2109 | + if ($args['type'] == 'number') { |
|
| 2110 | 2110 | $onchange = "props.setAttributes({ $key: Number($key) } )"; |
| 2111 | 2111 | } |
| 2112 | 2112 | } |
@@ -2144,11 +2144,11 @@ discard block |
||
| 2144 | 2144 | return; |
| 2145 | 2145 | } |
| 2146 | 2146 | */ |
| 2147 | - elseif ( $args['type'] == 'color' ) { |
|
| 2147 | + elseif ($args['type'] == 'color') { |
|
| 2148 | 2148 | $type = 'ColorPicker'; |
| 2149 | 2149 | $onchange = ""; |
| 2150 | 2150 | $extra = "color: $value,"; |
| 2151 | - if(!empty($args['disable_alpha'])){ |
|
| 2151 | + if (!empty($args['disable_alpha'])) { |
|
| 2152 | 2152 | $extra .= "disableAlpha: true,"; |
| 2153 | 2153 | } |
| 2154 | 2154 | $onchangecomplete = "onChangeComplete: function($key) { |
@@ -2158,47 +2158,47 @@ discard block |
||
| 2158 | 2158 | }); |
| 2159 | 2159 | },"; |
| 2160 | 2160 | } |
| 2161 | - elseif ( $args['type'] == 'checkbox' ) { |
|
| 2161 | + elseif ($args['type'] == 'checkbox') { |
|
| 2162 | 2162 | $type = 'CheckboxControl'; |
| 2163 | 2163 | $extra .= "checked: props.attributes.$key,"; |
| 2164 | 2164 | $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )"; |
| 2165 | - } elseif ( $args['type'] == 'textarea' ) { |
|
| 2165 | + } elseif ($args['type'] == 'textarea') { |
|
| 2166 | 2166 | $type = 'TextareaControl'; |
| 2167 | - } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) { |
|
| 2167 | + } elseif ($args['type'] == 'select' || $args['type'] == 'multiselect') { |
|
| 2168 | 2168 | $type = 'SelectControl'; |
| 2169 | 2169 | |
| 2170 | - if($args['name'] == 'category' && !empty($args['post_type_linked'])){ |
|
| 2171 | - $options .= "options: taxonomies_".str_replace("-","_", $this->id).","; |
|
| 2172 | - }elseif($args['name'] == 'sort_by' && !empty($args['post_type_linked'])){ |
|
| 2173 | - $options .= "options: sort_by_".str_replace("-","_", $this->id).","; |
|
| 2174 | - }else { |
|
| 2170 | + if ($args['name'] == 'category' && !empty($args['post_type_linked'])) { |
|
| 2171 | + $options .= "options: taxonomies_" . str_replace("-", "_", $this->id) . ","; |
|
| 2172 | + }elseif ($args['name'] == 'sort_by' && !empty($args['post_type_linked'])) { |
|
| 2173 | + $options .= "options: sort_by_" . str_replace("-", "_", $this->id) . ","; |
|
| 2174 | + } else { |
|
| 2175 | 2175 | |
| 2176 | - if ( ! empty( $args['options'] ) ) { |
|
| 2176 | + if (!empty($args['options'])) { |
|
| 2177 | 2177 | $options .= "options: ["; |
| 2178 | - foreach ( $args['options'] as $option_val => $option_label ) { |
|
| 2179 | - $options .= "{ value: '" . esc_attr( $option_val ) . "', label: '" . addslashes( $option_label ) . "' },"; |
|
| 2178 | + foreach ($args['options'] as $option_val => $option_label) { |
|
| 2179 | + $options .= "{ value: '" . esc_attr($option_val) . "', label: '" . addslashes($option_label) . "' },"; |
|
| 2180 | 2180 | } |
| 2181 | 2181 | $options .= "],"; |
| 2182 | 2182 | } |
| 2183 | 2183 | } |
| 2184 | - if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
| 2184 | + if (isset($args['multiple']) && $args['multiple']) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
| 2185 | 2185 | $extra .= ' multiple: true, '; |
| 2186 | 2186 | } |
| 2187 | - } elseif ( $args['type'] == 'alignment' ) { |
|
| 2187 | + } elseif ($args['type'] == 'alignment') { |
|
| 2188 | 2188 | $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example |
| 2189 | 2189 | } else { |
| 2190 | - return;// if we have not implemented the control then don't break the JS. |
|
| 2190 | + return; // if we have not implemented the control then don't break the JS. |
|
| 2191 | 2191 | } |
| 2192 | 2192 | |
| 2193 | 2193 | |
| 2194 | 2194 | |
| 2195 | 2195 | // color input does not show the labels so we add them |
| 2196 | - if($args['type']=='color'){ |
|
| 2196 | + if ($args['type'] == 'color') { |
|
| 2197 | 2197 | // add show only if advanced |
| 2198 | 2198 | echo $require_advanced; |
| 2199 | 2199 | // add setting require if defined |
| 2200 | 2200 | echo $element_require; |
| 2201 | - echo "el('div', {style: {'marginBottom': '8px'}}, '".addslashes( $args['title'] )."'),"; |
|
| 2201 | + echo "el('div', {style: {'marginBottom': '8px'}}, '" . addslashes($args['title']) . "'),"; |
|
| 2202 | 2202 | } |
| 2203 | 2203 | |
| 2204 | 2204 | // add show only if advanced |
@@ -2207,21 +2207,21 @@ discard block |
||
| 2207 | 2207 | echo $element_require; |
| 2208 | 2208 | ?> |
| 2209 | 2209 | el( wp.components.<?php echo $type; ?>, { |
| 2210 | - label: '<?php echo addslashes( $args['title'] ); ?>', |
|
| 2211 | - help: '<?php if ( isset( $args['desc'] ) ) { |
|
| 2212 | - echo addslashes( $args['desc'] ); |
|
| 2210 | + label: '<?php echo addslashes($args['title']); ?>', |
|
| 2211 | + help: '<?php if (isset($args['desc'])) { |
|
| 2212 | + echo addslashes($args['desc']); |
|
| 2213 | 2213 | } ?>', |
| 2214 | 2214 | value: <?php echo $value; ?>, |
| 2215 | - <?php if ( $type == 'TextControl' && $args['type'] != 'text' ) { |
|
| 2216 | - echo "type: '" . addslashes( $args['type'] ) . "',"; |
|
| 2215 | + <?php if ($type == 'TextControl' && $args['type'] != 'text') { |
|
| 2216 | + echo "type: '" . addslashes($args['type']) . "',"; |
|
| 2217 | 2217 | } ?> |
| 2218 | - <?php if ( ! empty( $args['placeholder'] ) ) { |
|
| 2219 | - echo "placeholder: '" . addslashes( $args['placeholder'] ) . "',"; |
|
| 2218 | + <?php if (!empty($args['placeholder'])) { |
|
| 2219 | + echo "placeholder: '" . addslashes($args['placeholder']) . "',"; |
|
| 2220 | 2220 | } ?> |
| 2221 | 2221 | <?php echo $options; ?> |
| 2222 | 2222 | <?php echo $extra; ?> |
| 2223 | 2223 | <?php echo $custom_attributes; ?> |
| 2224 | - <?php echo $onchangecomplete;?> |
|
| 2224 | + <?php echo $onchangecomplete; ?> |
|
| 2225 | 2225 | onChange: function ( <?php echo $key; ?> ) { |
| 2226 | 2226 | <?php echo $onchange; ?> |
| 2227 | 2227 | } |
@@ -2239,16 +2239,16 @@ discard block |
||
| 2239 | 2239 | * |
| 2240 | 2240 | * @return string |
| 2241 | 2241 | */ |
| 2242 | - public function array_to_attributes( $custom_attributes, $html = false ) { |
|
| 2242 | + public function array_to_attributes($custom_attributes, $html = false) { |
|
| 2243 | 2243 | $attributes = ''; |
| 2244 | - if ( ! empty( $custom_attributes ) ) { |
|
| 2244 | + if (!empty($custom_attributes)) { |
|
| 2245 | 2245 | |
| 2246 | - if ( $html ) { |
|
| 2247 | - foreach ( $custom_attributes as $key => $val ) { |
|
| 2246 | + if ($html) { |
|
| 2247 | + foreach ($custom_attributes as $key => $val) { |
|
| 2248 | 2248 | $attributes .= " $key='$val' "; |
| 2249 | 2249 | } |
| 2250 | 2250 | } else { |
| 2251 | - foreach ( $custom_attributes as $key => $val ) { |
|
| 2251 | + foreach ($custom_attributes as $key => $val) { |
|
| 2252 | 2252 | $attributes .= "'$key': '$val',"; |
| 2253 | 2253 | } |
| 2254 | 2254 | } |
@@ -2264,86 +2264,86 @@ discard block |
||
| 2264 | 2264 | * |
| 2265 | 2265 | * @param $args |
| 2266 | 2266 | */ |
| 2267 | - public function block_element( $args ) { |
|
| 2267 | + public function block_element($args) { |
|
| 2268 | 2268 | |
| 2269 | 2269 | |
| 2270 | - if ( ! empty( $args ) ) { |
|
| 2271 | - foreach ( $args as $element => $new_args ) { |
|
| 2270 | + if (!empty($args)) { |
|
| 2271 | + foreach ($args as $element => $new_args) { |
|
| 2272 | 2272 | |
| 2273 | - if ( is_array( $new_args ) ) { // its an element |
|
| 2273 | + if (is_array($new_args)) { // its an element |
|
| 2274 | 2274 | |
| 2275 | 2275 | |
| 2276 | - if ( isset( $new_args['element'] ) ) { |
|
| 2276 | + if (isset($new_args['element'])) { |
|
| 2277 | 2277 | |
| 2278 | - if ( isset( $new_args['element_require'] ) ) { |
|
| 2279 | - echo str_replace( array( |
|
| 2278 | + if (isset($new_args['element_require'])) { |
|
| 2279 | + echo str_replace(array( |
|
| 2280 | 2280 | "'+", |
| 2281 | 2281 | "+'" |
| 2282 | - ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " && "; |
|
| 2283 | - unset( $new_args['element_require'] ); |
|
| 2282 | + ), '', $this->block_props_replace($new_args['element_require'])) . " && "; |
|
| 2283 | + unset($new_args['element_require']); |
|
| 2284 | 2284 | } |
| 2285 | 2285 | |
| 2286 | 2286 | echo "\n el( '" . $new_args['element'] . "', {"; |
| 2287 | 2287 | |
| 2288 | 2288 | // get the attributes |
| 2289 | - foreach ( $new_args as $new_key => $new_value ) { |
|
| 2289 | + foreach ($new_args as $new_key => $new_value) { |
|
| 2290 | 2290 | |
| 2291 | 2291 | |
| 2292 | - if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) { |
|
| 2292 | + if ($new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array($new_value)) { |
|
| 2293 | 2293 | // do nothing |
| 2294 | 2294 | } else { |
| 2295 | - echo $this->block_element( array( $new_key => $new_value ) ); |
|
| 2295 | + echo $this->block_element(array($new_key => $new_value)); |
|
| 2296 | 2296 | } |
| 2297 | 2297 | } |
| 2298 | 2298 | |
| 2299 | - echo "},";// end attributes |
|
| 2299 | + echo "},"; // end attributes |
|
| 2300 | 2300 | |
| 2301 | 2301 | // get the content |
| 2302 | 2302 | $first_item = 0; |
| 2303 | - foreach ( $new_args as $new_key => $new_value ) { |
|
| 2304 | - if ( $new_key === 'content' || is_array( $new_value ) ) { |
|
| 2303 | + foreach ($new_args as $new_key => $new_value) { |
|
| 2304 | + if ($new_key === 'content' || is_array($new_value)) { |
|
| 2305 | 2305 | |
| 2306 | - if ( $new_key === 'content' ) { |
|
| 2307 | - echo "'" . $this->block_props_replace( wp_slash( $new_value ) ) . "'"; |
|
| 2306 | + if ($new_key === 'content') { |
|
| 2307 | + echo "'" . $this->block_props_replace(wp_slash($new_value)) . "'"; |
|
| 2308 | 2308 | } |
| 2309 | 2309 | |
| 2310 | - if ( is_array( $new_value ) ) { |
|
| 2310 | + if (is_array($new_value)) { |
|
| 2311 | 2311 | |
| 2312 | - if ( isset( $new_value['element_require'] ) ) { |
|
| 2313 | - echo str_replace( array( |
|
| 2312 | + if (isset($new_value['element_require'])) { |
|
| 2313 | + echo str_replace(array( |
|
| 2314 | 2314 | "'+", |
| 2315 | 2315 | "+'" |
| 2316 | - ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " && "; |
|
| 2317 | - unset( $new_value['element_require'] ); |
|
| 2316 | + ), '', $this->block_props_replace($new_value['element_require'])) . " && "; |
|
| 2317 | + unset($new_value['element_require']); |
|
| 2318 | 2318 | } |
| 2319 | 2319 | |
| 2320 | - if ( isset( $new_value['element_repeat'] ) ) { |
|
| 2320 | + if (isset($new_value['element_repeat'])) { |
|
| 2321 | 2321 | $x = 1; |
| 2322 | - while ( $x <= absint( $new_value['element_repeat'] ) ) { |
|
| 2323 | - $this->block_element( array( '' => $new_value ) ); |
|
| 2324 | - $x ++; |
|
| 2322 | + while ($x <= absint($new_value['element_repeat'])) { |
|
| 2323 | + $this->block_element(array('' => $new_value)); |
|
| 2324 | + $x++; |
|
| 2325 | 2325 | } |
| 2326 | 2326 | } else { |
| 2327 | - $this->block_element( array( '' => $new_value ) ); |
|
| 2327 | + $this->block_element(array('' => $new_value)); |
|
| 2328 | 2328 | } |
| 2329 | 2329 | } |
| 2330 | - $first_item ++; |
|
| 2330 | + $first_item++; |
|
| 2331 | 2331 | } |
| 2332 | 2332 | } |
| 2333 | 2333 | |
| 2334 | - echo ")";// end content |
|
| 2334 | + echo ")"; // end content |
|
| 2335 | 2335 | |
| 2336 | 2336 | echo ", \n"; |
| 2337 | 2337 | |
| 2338 | 2338 | } |
| 2339 | 2339 | } else { |
| 2340 | 2340 | |
| 2341 | - if ( substr( $element, 0, 3 ) === "if_" ) { |
|
| 2342 | - echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ","; |
|
| 2343 | - } elseif ( $element == 'style' ) { |
|
| 2344 | - echo $element . ": " . $this->block_props_replace( $new_args ) . ","; |
|
| 2341 | + if (substr($element, 0, 3) === "if_") { |
|
| 2342 | + echo str_replace("if_", "", $element) . ": " . $this->block_props_replace($new_args, true) . ","; |
|
| 2343 | + } elseif ($element == 'style') { |
|
| 2344 | + echo $element . ": " . $this->block_props_replace($new_args) . ","; |
|
| 2345 | 2345 | } else { |
| 2346 | - echo $element . ": '" . $this->block_props_replace( $new_args ) . "',"; |
|
| 2346 | + echo $element . ": '" . $this->block_props_replace($new_args) . "',"; |
|
| 2347 | 2347 | } |
| 2348 | 2348 | |
| 2349 | 2349 | } |
@@ -2358,12 +2358,12 @@ discard block |
||
| 2358 | 2358 | * |
| 2359 | 2359 | * @return mixed |
| 2360 | 2360 | */ |
| 2361 | - public function block_props_replace( $string, $no_wrap = false ) { |
|
| 2361 | + public function block_props_replace($string, $no_wrap = false) { |
|
| 2362 | 2362 | |
| 2363 | - if ( $no_wrap ) { |
|
| 2364 | - $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string ); |
|
| 2363 | + if ($no_wrap) { |
|
| 2364 | + $string = str_replace(array("[%", "%]"), array("props.attributes.", ""), $string); |
|
| 2365 | 2365 | } else { |
| 2366 | - $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string ); |
|
| 2366 | + $string = str_replace(array("[%", "%]"), array("'+props.attributes.", "+'"), $string); |
|
| 2367 | 2367 | } |
| 2368 | 2368 | |
| 2369 | 2369 | return $string; |
@@ -2375,55 +2375,55 @@ discard block |
||
| 2375 | 2375 | * @param array $args |
| 2376 | 2376 | * @param array $instance |
| 2377 | 2377 | */ |
| 2378 | - public function widget( $args, $instance ) { |
|
| 2378 | + public function widget($args, $instance) { |
|
| 2379 | 2379 | |
| 2380 | 2380 | // get the filtered values |
| 2381 | - $argument_values = $this->argument_values( $instance ); |
|
| 2382 | - $argument_values = $this->string_to_bool( $argument_values ); |
|
| 2383 | - $output = $this->output( $argument_values, $args ); |
|
| 2381 | + $argument_values = $this->argument_values($instance); |
|
| 2382 | + $argument_values = $this->string_to_bool($argument_values); |
|
| 2383 | + $output = $this->output($argument_values, $args); |
|
| 2384 | 2384 | |
| 2385 | 2385 | $no_wrap = false; |
| 2386 | - if ( isset( $argument_values['no_wrap'] ) && $argument_values['no_wrap'] ) { |
|
| 2386 | + if (isset($argument_values['no_wrap']) && $argument_values['no_wrap']) { |
|
| 2387 | 2387 | $no_wrap = true; |
| 2388 | 2388 | } |
| 2389 | 2389 | |
| 2390 | 2390 | ob_start(); |
| 2391 | - if ( $output && ! $no_wrap ) { |
|
| 2391 | + if ($output && !$no_wrap) { |
|
| 2392 | 2392 | |
| 2393 | 2393 | $class_original = $this->options['widget_ops']['classname']; |
| 2394 | - $class = $this->options['widget_ops']['classname']." sdel-".$this->get_instance_hash(); |
|
| 2394 | + $class = $this->options['widget_ops']['classname'] . " sdel-" . $this->get_instance_hash(); |
|
| 2395 | 2395 | |
| 2396 | 2396 | // Before widget |
| 2397 | 2397 | $before_widget = $args['before_widget']; |
| 2398 | - $before_widget = str_replace($class_original,$class,$before_widget); |
|
| 2399 | - $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this ); |
|
| 2400 | - $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this ); |
|
| 2398 | + $before_widget = str_replace($class_original, $class, $before_widget); |
|
| 2399 | + $before_widget = apply_filters('wp_super_duper_before_widget', $before_widget, $args, $instance, $this); |
|
| 2400 | + $before_widget = apply_filters('wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this); |
|
| 2401 | 2401 | |
| 2402 | 2402 | // After widget |
| 2403 | 2403 | $after_widget = $args['after_widget']; |
| 2404 | - $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this ); |
|
| 2405 | - $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this ); |
|
| 2404 | + $after_widget = apply_filters('wp_super_duper_after_widget', $after_widget, $args, $instance, $this); |
|
| 2405 | + $after_widget = apply_filters('wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this); |
|
| 2406 | 2406 | |
| 2407 | 2407 | echo $before_widget; |
| 2408 | 2408 | // elementor strips the widget wrapping div so we check for and add it back if needed |
| 2409 | - if ( $this->is_elementor_widget_output() ) { |
|
| 2410 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $class ) . "'>" : ''; |
|
| 2409 | + if ($this->is_elementor_widget_output()) { |
|
| 2410 | + echo !empty($this->options['widget_ops']['classname']) ? "<span class='" . esc_attr($class) . "'>" : ''; |
|
| 2411 | 2411 | } |
| 2412 | - echo $this->output_title( $args, $instance ); |
|
| 2412 | + echo $this->output_title($args, $instance); |
|
| 2413 | 2413 | echo $output; |
| 2414 | - if ( $this->is_elementor_widget_output() ) { |
|
| 2415 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : ''; |
|
| 2414 | + if ($this->is_elementor_widget_output()) { |
|
| 2415 | + echo !empty($this->options['widget_ops']['classname']) ? "</span>" : ''; |
|
| 2416 | 2416 | } |
| 2417 | 2417 | echo $after_widget; |
| 2418 | - } elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty |
|
| 2419 | - $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" ); |
|
| 2418 | + } elseif ($this->is_preview() && $output == '') {// if preview show a placeholder if empty |
|
| 2419 | + $output = $this->preview_placeholder_text("{{" . $this->base_id . "}}"); |
|
| 2420 | 2420 | echo $output; |
| 2421 | - } elseif ( $output && $no_wrap ) { |
|
| 2421 | + } elseif ($output && $no_wrap) { |
|
| 2422 | 2422 | echo $output; |
| 2423 | 2423 | } |
| 2424 | 2424 | $output = ob_get_clean(); |
| 2425 | 2425 | |
| 2426 | - $output = apply_filters( 'wp_super_duper_widget_output', $output, $instance, $args, $this ); |
|
| 2426 | + $output = apply_filters('wp_super_duper_widget_output', $output, $instance, $args, $this); |
|
| 2427 | 2427 | |
| 2428 | 2428 | echo $output; |
| 2429 | 2429 | } |
@@ -2436,7 +2436,7 @@ discard block |
||
| 2436 | 2436 | */ |
| 2437 | 2437 | public function is_elementor_widget_output() { |
| 2438 | 2438 | $result = false; |
| 2439 | - if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) { |
|
| 2439 | + if (defined('ELEMENTOR_VERSION') && isset($this->number) && $this->number == 'REPLACE_TO_ID') { |
|
| 2440 | 2440 | $result = true; |
| 2441 | 2441 | } |
| 2442 | 2442 | |
@@ -2451,7 +2451,7 @@ discard block |
||
| 2451 | 2451 | */ |
| 2452 | 2452 | public function is_elementor_preview() { |
| 2453 | 2453 | $result = false; |
| 2454 | - if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) { |
|
| 2454 | + if (isset($_REQUEST['elementor-preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor') || (isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor_ajax')) { |
|
| 2455 | 2455 | $result = true; |
| 2456 | 2456 | } |
| 2457 | 2457 | |
@@ -2466,7 +2466,7 @@ discard block |
||
| 2466 | 2466 | */ |
| 2467 | 2467 | public function is_divi_preview() { |
| 2468 | 2468 | $result = false; |
| 2469 | - if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) { |
|
| 2469 | + if (isset($_REQUEST['et_fb']) || isset($_REQUEST['et_pb_preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor')) { |
|
| 2470 | 2470 | $result = true; |
| 2471 | 2471 | } |
| 2472 | 2472 | |
@@ -2481,7 +2481,7 @@ discard block |
||
| 2481 | 2481 | */ |
| 2482 | 2482 | public function is_beaver_preview() { |
| 2483 | 2483 | $result = false; |
| 2484 | - if ( isset( $_REQUEST['fl_builder'] ) ) { |
|
| 2484 | + if (isset($_REQUEST['fl_builder'])) { |
|
| 2485 | 2485 | $result = true; |
| 2486 | 2486 | } |
| 2487 | 2487 | |
@@ -2496,7 +2496,7 @@ discard block |
||
| 2496 | 2496 | */ |
| 2497 | 2497 | public function is_siteorigin_preview() { |
| 2498 | 2498 | $result = false; |
| 2499 | - if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) { |
|
| 2499 | + if (!empty($_REQUEST['siteorigin_panels_live_editor'])) { |
|
| 2500 | 2500 | $result = true; |
| 2501 | 2501 | } |
| 2502 | 2502 | |
@@ -2511,7 +2511,7 @@ discard block |
||
| 2511 | 2511 | */ |
| 2512 | 2512 | public function is_cornerstone_preview() { |
| 2513 | 2513 | $result = false; |
| 2514 | - if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) { |
|
| 2514 | + if (!empty($_REQUEST['cornerstone_preview']) || basename($_SERVER['REQUEST_URI']) == 'cornerstone-endpoint') { |
|
| 2515 | 2515 | $result = true; |
| 2516 | 2516 | } |
| 2517 | 2517 | |
@@ -2526,7 +2526,7 @@ discard block |
||
| 2526 | 2526 | */ |
| 2527 | 2527 | public function is_fusion_preview() { |
| 2528 | 2528 | $result = false; |
| 2529 | - if ( ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] ) ) { |
|
| 2529 | + if (!empty($_REQUEST['fb-edit']) || !empty($_REQUEST['fusion_load_nonce'])) { |
|
| 2530 | 2530 | $result = true; |
| 2531 | 2531 | } |
| 2532 | 2532 | |
@@ -2541,7 +2541,7 @@ discard block |
||
| 2541 | 2541 | */ |
| 2542 | 2542 | public function is_oxygen_preview() { |
| 2543 | 2543 | $result = false; |
| 2544 | - if ( ! empty( $_REQUEST['ct_builder'] ) || ( ! empty( $_REQUEST['action'] ) && ( substr( $_REQUEST['action'], 0, 11 ) === "oxy_render_" || substr( $_REQUEST['action'], 0, 10 ) === "ct_render_" ) ) ) { |
|
| 2544 | + if (!empty($_REQUEST['ct_builder']) || (!empty($_REQUEST['action']) && (substr($_REQUEST['action'], 0, 11) === "oxy_render_" || substr($_REQUEST['action'], 0, 10) === "ct_render_"))) { |
|
| 2545 | 2545 | $result = true; |
| 2546 | 2546 | } |
| 2547 | 2547 | |
@@ -2556,21 +2556,21 @@ discard block |
||
| 2556 | 2556 | */ |
| 2557 | 2557 | public function is_preview() { |
| 2558 | 2558 | $preview = false; |
| 2559 | - if ( $this->is_divi_preview() ) { |
|
| 2559 | + if ($this->is_divi_preview()) { |
|
| 2560 | 2560 | $preview = true; |
| 2561 | - } elseif ( $this->is_elementor_preview() ) { |
|
| 2561 | + } elseif ($this->is_elementor_preview()) { |
|
| 2562 | 2562 | $preview = true; |
| 2563 | - } elseif ( $this->is_beaver_preview() ) { |
|
| 2563 | + } elseif ($this->is_beaver_preview()) { |
|
| 2564 | 2564 | $preview = true; |
| 2565 | - } elseif ( $this->is_siteorigin_preview() ) { |
|
| 2565 | + } elseif ($this->is_siteorigin_preview()) { |
|
| 2566 | 2566 | $preview = true; |
| 2567 | - } elseif ( $this->is_cornerstone_preview() ) { |
|
| 2567 | + } elseif ($this->is_cornerstone_preview()) { |
|
| 2568 | 2568 | $preview = true; |
| 2569 | - } elseif ( $this->is_fusion_preview() ) { |
|
| 2569 | + } elseif ($this->is_fusion_preview()) { |
|
| 2570 | 2570 | $preview = true; |
| 2571 | - } elseif ( $this->is_oxygen_preview() ) { |
|
| 2571 | + } elseif ($this->is_oxygen_preview()) { |
|
| 2572 | 2572 | $preview = true; |
| 2573 | - } elseif( $this->is_block_content_call() ) { |
|
| 2573 | + } elseif ($this->is_block_content_call()) { |
|
| 2574 | 2574 | $preview = true; |
| 2575 | 2575 | } |
| 2576 | 2576 | |
@@ -2585,11 +2585,11 @@ discard block |
||
| 2585 | 2585 | * |
| 2586 | 2586 | * @return string |
| 2587 | 2587 | */ |
| 2588 | - public function output_title( $args, $instance = array() ) { |
|
| 2588 | + public function output_title($args, $instance = array()) { |
|
| 2589 | 2589 | $output = ''; |
| 2590 | - if ( ! empty( $instance['title'] ) ) { |
|
| 2590 | + if (!empty($instance['title'])) { |
|
| 2591 | 2591 | /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
| 2592 | - $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
|
| 2592 | + $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); |
|
| 2593 | 2593 | $output = $args['before_title'] . $title . $args['after_title']; |
| 2594 | 2594 | } |
| 2595 | 2595 | |
@@ -2601,7 +2601,7 @@ discard block |
||
| 2601 | 2601 | * |
| 2602 | 2602 | * @param array $instance The widget options. |
| 2603 | 2603 | */ |
| 2604 | - public function form( $instance ) { |
|
| 2604 | + public function form($instance) { |
|
| 2605 | 2605 | |
| 2606 | 2606 | // set widget instance |
| 2607 | 2607 | $this->instance = $instance; |
@@ -2609,20 +2609,20 @@ discard block |
||
| 2609 | 2609 | // set it as a SD widget |
| 2610 | 2610 | echo $this->widget_advanced_toggle(); |
| 2611 | 2611 | |
| 2612 | - echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>"; |
|
| 2612 | + echo "<p>" . esc_attr($this->options['widget_ops']['description']) . "</p>"; |
|
| 2613 | 2613 | $arguments_raw = $this->get_arguments(); |
| 2614 | 2614 | |
| 2615 | - if ( is_array( $arguments_raw ) ) { |
|
| 2615 | + if (is_array($arguments_raw)) { |
|
| 2616 | 2616 | |
| 2617 | - $arguments = $this->group_arguments( $arguments_raw ); |
|
| 2617 | + $arguments = $this->group_arguments($arguments_raw); |
|
| 2618 | 2618 | |
| 2619 | 2619 | // Do we have sections? |
| 2620 | 2620 | $has_sections = $arguments == $arguments_raw ? false : true; |
| 2621 | 2621 | |
| 2622 | 2622 | |
| 2623 | - if ( $has_sections ) { |
|
| 2623 | + if ($has_sections) { |
|
| 2624 | 2624 | $panel_count = 0; |
| 2625 | - foreach ( $arguments as $key => $args ) { |
|
| 2625 | + foreach ($arguments as $key => $args) { |
|
| 2626 | 2626 | |
| 2627 | 2627 | ?> |
| 2628 | 2628 | <script> |
@@ -2632,21 +2632,21 @@ discard block |
||
| 2632 | 2632 | |
| 2633 | 2633 | $hide = $panel_count ? ' style="display:none;" ' : ''; |
| 2634 | 2634 | $icon_class = $panel_count ? 'fas fa-chevron-up' : 'fas fa-chevron-down'; |
| 2635 | - echo "<button onclick='jQuery(this).find(\"i\").toggleClass(\"fas fa-chevron-up fas fa-chevron-down\");jQuery(this).next().slideToggle();' type='button' class='sd-toggle-group-button sd-input-group-toggle" . sanitize_title_with_dashes( $key ) . "'>" . esc_attr( $key ) . " <i style='float:right;' class='" . $icon_class . "'></i></button>"; |
|
| 2636 | - echo "<div class='sd-toggle-group sd-input-group-" . sanitize_title_with_dashes( $key ) . "' $hide>"; |
|
| 2635 | + echo "<button onclick='jQuery(this).find(\"i\").toggleClass(\"fas fa-chevron-up fas fa-chevron-down\");jQuery(this).next().slideToggle();' type='button' class='sd-toggle-group-button sd-input-group-toggle" . sanitize_title_with_dashes($key) . "'>" . esc_attr($key) . " <i style='float:right;' class='" . $icon_class . "'></i></button>"; |
|
| 2636 | + echo "<div class='sd-toggle-group sd-input-group-" . sanitize_title_with_dashes($key) . "' $hide>"; |
|
| 2637 | 2637 | |
| 2638 | - foreach ( $args as $k => $a ) { |
|
| 2639 | - $this->widget_inputs( $a, $instance ); |
|
| 2638 | + foreach ($args as $k => $a) { |
|
| 2639 | + $this->widget_inputs($a, $instance); |
|
| 2640 | 2640 | } |
| 2641 | 2641 | |
| 2642 | 2642 | echo "</div>"; |
| 2643 | 2643 | |
| 2644 | - $panel_count ++; |
|
| 2644 | + $panel_count++; |
|
| 2645 | 2645 | |
| 2646 | 2646 | } |
| 2647 | 2647 | } else { |
| 2648 | - foreach ( $arguments as $key => $args ) { |
|
| 2649 | - $this->widget_inputs( $args, $instance ); |
|
| 2648 | + foreach ($arguments as $key => $args) { |
|
| 2649 | + $this->widget_inputs($args, $instance); |
|
| 2650 | 2650 | } |
| 2651 | 2651 | } |
| 2652 | 2652 | |
@@ -2661,7 +2661,7 @@ discard block |
||
| 2661 | 2661 | public function widget_advanced_toggle() { |
| 2662 | 2662 | |
| 2663 | 2663 | $output = ''; |
| 2664 | - if ( $this->block_show_advanced() ) { |
|
| 2664 | + if ($this->block_show_advanced()) { |
|
| 2665 | 2665 | $val = 1; |
| 2666 | 2666 | } else { |
| 2667 | 2667 | $val = 0; |
@@ -2681,14 +2681,14 @@ discard block |
||
| 2681 | 2681 | * |
| 2682 | 2682 | * @return string $output |
| 2683 | 2683 | */ |
| 2684 | - public function convert_element_require( $input ) { |
|
| 2684 | + public function convert_element_require($input) { |
|
| 2685 | 2685 | |
| 2686 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
| 2686 | + $input = str_replace("'", '"', $input); // we only want double quotes |
|
| 2687 | 2687 | |
| 2688 | - $output = esc_attr( str_replace( array( "[%", "%]" ), array( |
|
| 2688 | + $output = esc_attr(str_replace(array("[%", "%]"), array( |
|
| 2689 | 2689 | "jQuery(form).find('[data-argument=\"", |
| 2690 | 2690 | "\"]').find('input,select,textarea').val()" |
| 2691 | - ), $input ) ); |
|
| 2691 | + ), $input)); |
|
| 2692 | 2692 | |
| 2693 | 2693 | return $output; |
| 2694 | 2694 | } |
@@ -2699,54 +2699,54 @@ discard block |
||
| 2699 | 2699 | * @param $args |
| 2700 | 2700 | * @param $instance |
| 2701 | 2701 | */ |
| 2702 | - public function widget_inputs( $args, $instance ) { |
|
| 2702 | + public function widget_inputs($args, $instance) { |
|
| 2703 | 2703 | |
| 2704 | 2704 | $class = ""; |
| 2705 | 2705 | $element_require = ""; |
| 2706 | 2706 | $custom_attributes = ""; |
| 2707 | 2707 | |
| 2708 | 2708 | // get value |
| 2709 | - if ( isset( $instance[ $args['name'] ] ) ) { |
|
| 2710 | - $value = $instance[ $args['name'] ]; |
|
| 2711 | - } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) { |
|
| 2712 | - $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] ); |
|
| 2709 | + if (isset($instance[$args['name']])) { |
|
| 2710 | + $value = $instance[$args['name']]; |
|
| 2711 | + } elseif (!isset($instance[$args['name']]) && !empty($args['default'])) { |
|
| 2712 | + $value = is_array($args['default']) ? array_map("esc_html", $args['default']) : esc_html($args['default']); |
|
| 2713 | 2713 | } else { |
| 2714 | 2714 | $value = ''; |
| 2715 | 2715 | } |
| 2716 | 2716 | |
| 2717 | 2717 | // get placeholder |
| 2718 | - if ( ! empty( $args['placeholder'] ) ) { |
|
| 2719 | - $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'"; |
|
| 2718 | + if (!empty($args['placeholder'])) { |
|
| 2719 | + $placeholder = "placeholder='" . esc_html($args['placeholder']) . "'"; |
|
| 2720 | 2720 | } else { |
| 2721 | 2721 | $placeholder = ''; |
| 2722 | 2722 | } |
| 2723 | 2723 | |
| 2724 | 2724 | // get if advanced |
| 2725 | - if ( isset( $args['advanced'] ) && $args['advanced'] ) { |
|
| 2725 | + if (isset($args['advanced']) && $args['advanced']) { |
|
| 2726 | 2726 | $class .= " sd-advanced-setting "; |
| 2727 | 2727 | } |
| 2728 | 2728 | |
| 2729 | 2729 | // element_require |
| 2730 | - if ( isset( $args['element_require'] ) && $args['element_require'] ) { |
|
| 2730 | + if (isset($args['element_require']) && $args['element_require']) { |
|
| 2731 | 2731 | $element_require = $args['element_require']; |
| 2732 | 2732 | } |
| 2733 | 2733 | |
| 2734 | 2734 | // custom_attributes |
| 2735 | - if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) { |
|
| 2736 | - $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true ); |
|
| 2735 | + if (isset($args['custom_attributes']) && $args['custom_attributes']) { |
|
| 2736 | + $custom_attributes = $this->array_to_attributes($args['custom_attributes'], true); |
|
| 2737 | 2737 | } |
| 2738 | 2738 | |
| 2739 | 2739 | // before wrapper |
| 2740 | 2740 | ?> |
| 2741 | - <p class="sd-argument <?php echo esc_attr( $class ); ?>" |
|
| 2742 | - data-argument='<?php echo esc_attr( $args['name'] ); ?>' |
|
| 2743 | - data-element_require='<?php if ( $element_require ) { |
|
| 2744 | - echo $this->convert_element_require( $element_require ); |
|
| 2741 | + <p class="sd-argument <?php echo esc_attr($class); ?>" |
|
| 2742 | + data-argument='<?php echo esc_attr($args['name']); ?>' |
|
| 2743 | + data-element_require='<?php if ($element_require) { |
|
| 2744 | + echo $this->convert_element_require($element_require); |
|
| 2745 | 2745 | } ?>' |
| 2746 | 2746 | > |
| 2747 | 2747 | <?php |
| 2748 | 2748 | |
| 2749 | - switch ( $args['type'] ) { |
|
| 2749 | + switch ($args['type']) { |
|
| 2750 | 2750 | //array('text','password','number','email','tel','url','color') |
| 2751 | 2751 | case "text": |
| 2752 | 2752 | case "password": |
@@ -2757,46 +2757,46 @@ discard block |
||
| 2757 | 2757 | case "color": |
| 2758 | 2758 | ?> |
| 2759 | 2759 | <label |
| 2760 | - for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
|
| 2760 | + for="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"><?php echo esc_attr($args['title']); ?><?php echo $this->widget_field_desc($args); ?></label> |
|
| 2761 | 2761 | <input <?php echo $placeholder; ?> class="widefat" |
| 2762 | 2762 | <?php echo $custom_attributes; ?> |
| 2763 | - id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
| 2764 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" |
|
| 2765 | - type="<?php echo esc_attr( $args['type'] ); ?>" |
|
| 2766 | - value="<?php echo esc_attr( $value ); ?>"> |
|
| 2763 | + id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
| 2764 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" |
|
| 2765 | + type="<?php echo esc_attr($args['type']); ?>" |
|
| 2766 | + value="<?php echo esc_attr($value); ?>"> |
|
| 2767 | 2767 | <?php |
| 2768 | 2768 | |
| 2769 | 2769 | break; |
| 2770 | 2770 | case "select": |
| 2771 | - $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false; |
|
| 2772 | - if ( $multiple ) { |
|
| 2773 | - if ( empty( $value ) ) { |
|
| 2771 | + $multiple = isset($args['multiple']) && $args['multiple'] ? true : false; |
|
| 2772 | + if ($multiple) { |
|
| 2773 | + if (empty($value)) { |
|
| 2774 | 2774 | $value = array(); |
| 2775 | 2775 | } |
| 2776 | 2776 | } |
| 2777 | 2777 | ?> |
| 2778 | 2778 | <label |
| 2779 | - for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
|
| 2779 | + for="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"><?php echo esc_attr($args['title']); ?><?php echo $this->widget_field_desc($args); ?></label> |
|
| 2780 | 2780 | <select <?php echo $placeholder; ?> class="widefat" |
| 2781 | 2781 | <?php echo $custom_attributes; ?> |
| 2782 | - id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
| 2783 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); |
|
| 2784 | - if ( $multiple ) { |
|
| 2782 | + id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
| 2783 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); |
|
| 2784 | + if ($multiple) { |
|
| 2785 | 2785 | echo "[]"; |
| 2786 | 2786 | } ?>" |
| 2787 | - <?php if ( $multiple ) { |
|
| 2787 | + <?php if ($multiple) { |
|
| 2788 | 2788 | echo "multiple"; |
| 2789 | 2789 | } //@todo not implemented yet due to gutenberg not supporting it |
| 2790 | 2790 | ?> |
| 2791 | 2791 | > |
| 2792 | 2792 | <?php |
| 2793 | 2793 | |
| 2794 | - if ( ! empty( $args['options'] ) ) { |
|
| 2795 | - foreach ( $args['options'] as $val => $label ) { |
|
| 2796 | - if ( $multiple ) { |
|
| 2797 | - $selected = in_array( $val, $value ) ? 'selected="selected"' : ''; |
|
| 2794 | + if (!empty($args['options'])) { |
|
| 2795 | + foreach ($args['options'] as $val => $label) { |
|
| 2796 | + if ($multiple) { |
|
| 2797 | + $selected = in_array($val, $value) ? 'selected="selected"' : ''; |
|
| 2798 | 2798 | } else { |
| 2799 | - $selected = selected( $value, $val, false ); |
|
| 2799 | + $selected = selected($value, $val, false); |
|
| 2800 | 2800 | } |
| 2801 | 2801 | echo "<option value='$val' " . $selected . ">$label</option>"; |
| 2802 | 2802 | } |
@@ -2808,32 +2808,32 @@ discard block |
||
| 2808 | 2808 | case "checkbox": |
| 2809 | 2809 | ?> |
| 2810 | 2810 | <input <?php echo $placeholder; ?> |
| 2811 | - <?php checked( 1, $value, true ) ?> |
|
| 2811 | + <?php checked(1, $value, true) ?> |
|
| 2812 | 2812 | <?php echo $custom_attributes; ?> |
| 2813 | - class="widefat" id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
| 2814 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="checkbox" |
|
| 2813 | + class="widefat" id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
| 2814 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" type="checkbox" |
|
| 2815 | 2815 | value="1"> |
| 2816 | 2816 | <label |
| 2817 | - for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
|
| 2817 | + for="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"><?php echo esc_attr($args['title']); ?><?php echo $this->widget_field_desc($args); ?></label> |
|
| 2818 | 2818 | <?php |
| 2819 | 2819 | break; |
| 2820 | 2820 | case "textarea": |
| 2821 | 2821 | ?> |
| 2822 | 2822 | <label |
| 2823 | - for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label> |
|
| 2823 | + for="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"><?php echo esc_attr($args['title']); ?><?php echo $this->widget_field_desc($args); ?></label> |
|
| 2824 | 2824 | <textarea <?php echo $placeholder; ?> class="widefat" |
| 2825 | 2825 | <?php echo $custom_attributes; ?> |
| 2826 | - id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
| 2827 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" |
|
| 2828 | - ><?php echo esc_attr( $value ); ?></textarea> |
|
| 2826 | + id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
| 2827 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" |
|
| 2828 | + ><?php echo esc_attr($value); ?></textarea> |
|
| 2829 | 2829 | <?php |
| 2830 | 2830 | |
| 2831 | 2831 | break; |
| 2832 | 2832 | case "hidden": |
| 2833 | 2833 | ?> |
| 2834 | - <input id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
|
| 2835 | - name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="hidden" |
|
| 2836 | - value="<?php echo esc_attr( $value ); ?>"> |
|
| 2834 | + <input id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>" |
|
| 2835 | + name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" type="hidden" |
|
| 2836 | + value="<?php echo esc_attr($value); ?>"> |
|
| 2837 | 2837 | <?php |
| 2838 | 2838 | break; |
| 2839 | 2839 | default: |
@@ -2855,14 +2855,14 @@ discard block |
||
| 2855 | 2855 | * @return string |
| 2856 | 2856 | * @todo, need to make its own tooltip script |
| 2857 | 2857 | */ |
| 2858 | - public function widget_field_desc( $args ) { |
|
| 2858 | + public function widget_field_desc($args) { |
|
| 2859 | 2859 | |
| 2860 | 2860 | $description = ''; |
| 2861 | - if ( isset( $args['desc'] ) && $args['desc'] ) { |
|
| 2862 | - if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) { |
|
| 2863 | - $description = $this->desc_tip( $args['desc'] ); |
|
| 2861 | + if (isset($args['desc']) && $args['desc']) { |
|
| 2862 | + if (isset($args['desc_tip']) && $args['desc_tip']) { |
|
| 2863 | + $description = $this->desc_tip($args['desc']); |
|
| 2864 | 2864 | } else { |
| 2865 | - $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>'; |
|
| 2865 | + $description = '<span class="description">' . wp_kses_post($args['desc']) . '</span>'; |
|
| 2866 | 2866 | } |
| 2867 | 2867 | } |
| 2868 | 2868 | |
@@ -2877,11 +2877,11 @@ discard block |
||
| 2877 | 2877 | * |
| 2878 | 2878 | * @return string |
| 2879 | 2879 | */ |
| 2880 | - function desc_tip( $tip, $allow_html = false ) { |
|
| 2881 | - if ( $allow_html ) { |
|
| 2882 | - $tip = $this->sanitize_tooltip( $tip ); |
|
| 2880 | + function desc_tip($tip, $allow_html = false) { |
|
| 2881 | + if ($allow_html) { |
|
| 2882 | + $tip = $this->sanitize_tooltip($tip); |
|
| 2883 | 2883 | } else { |
| 2884 | - $tip = esc_attr( $tip ); |
|
| 2884 | + $tip = esc_attr($tip); |
|
| 2885 | 2885 | } |
| 2886 | 2886 | |
| 2887 | 2887 | return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
@@ -2894,8 +2894,8 @@ discard block |
||
| 2894 | 2894 | * |
| 2895 | 2895 | * @return string |
| 2896 | 2896 | */ |
| 2897 | - public function sanitize_tooltip( $var ) { |
|
| 2898 | - return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
| 2897 | + public function sanitize_tooltip($var) { |
|
| 2898 | + return htmlspecialchars(wp_kses(html_entity_decode($var), array( |
|
| 2899 | 2899 | 'br' => array(), |
| 2900 | 2900 | 'em' => array(), |
| 2901 | 2901 | 'strong' => array(), |
@@ -2905,7 +2905,7 @@ discard block |
||
| 2905 | 2905 | 'li' => array(), |
| 2906 | 2906 | 'ol' => array(), |
| 2907 | 2907 | 'p' => array(), |
| 2908 | - ) ) ); |
|
| 2908 | + ))); |
|
| 2909 | 2909 | } |
| 2910 | 2910 | |
| 2911 | 2911 | /** |
@@ -2917,23 +2917,23 @@ discard block |
||
| 2917 | 2917 | * @return array |
| 2918 | 2918 | * @todo we should add some sanitation here. |
| 2919 | 2919 | */ |
| 2920 | - public function update( $new_instance, $old_instance ) { |
|
| 2920 | + public function update($new_instance, $old_instance) { |
|
| 2921 | 2921 | |
| 2922 | 2922 | //save the widget |
| 2923 | - $instance = array_merge( (array) $old_instance, (array) $new_instance ); |
|
| 2923 | + $instance = array_merge((array) $old_instance, (array) $new_instance); |
|
| 2924 | 2924 | |
| 2925 | 2925 | // set widget instance |
| 2926 | 2926 | $this->instance = $instance; |
| 2927 | 2927 | |
| 2928 | - if ( empty( $this->arguments ) ) { |
|
| 2928 | + if (empty($this->arguments)) { |
|
| 2929 | 2929 | $this->get_arguments(); |
| 2930 | 2930 | } |
| 2931 | 2931 | |
| 2932 | 2932 | // check for checkboxes |
| 2933 | - if ( ! empty( $this->arguments ) ) { |
|
| 2934 | - foreach ( $this->arguments as $argument ) { |
|
| 2935 | - if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) { |
|
| 2936 | - $instance[ $argument['name'] ] = '0'; |
|
| 2933 | + if (!empty($this->arguments)) { |
|
| 2934 | + foreach ($this->arguments as $argument) { |
|
| 2935 | + if (isset($argument['type']) && $argument['type'] == 'checkbox' && !isset($new_instance[$argument['name']])) { |
|
| 2936 | + $instance[$argument['name']] = '0'; |
|
| 2937 | 2937 | } |
| 2938 | 2938 | } |
| 2939 | 2939 | } |
@@ -2951,7 +2951,7 @@ discard block |
||
| 2951 | 2951 | */ |
| 2952 | 2952 | public function is_block_content_call() { |
| 2953 | 2953 | $result = false; |
| 2954 | - if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) { |
|
| 2954 | + if (wp_doing_ajax() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'super_duper_output_shortcode') { |
|
| 2955 | 2955 | $result = true; |
| 2956 | 2956 | } |
| 2957 | 2957 | |
@@ -2964,9 +2964,9 @@ discard block |
||
| 2964 | 2964 | * @since 1.0.20 |
| 2965 | 2965 | * @return string |
| 2966 | 2966 | */ |
| 2967 | - public function get_instance_hash(){ |
|
| 2968 | - $instance_string = $this->base_id.serialize($this->instance); |
|
| 2969 | - return hash('crc32b',$instance_string); |
|
| 2967 | + public function get_instance_hash() { |
|
| 2968 | + $instance_string = $this->base_id . serialize($this->instance); |
|
| 2969 | + return hash('crc32b', $instance_string); |
|
| 2970 | 2970 | } |
| 2971 | 2971 | |
| 2972 | 2972 | /** |
@@ -2977,14 +2977,14 @@ discard block |
||
| 2977 | 2977 | * @since 1.0.20 |
| 2978 | 2978 | * @return string |
| 2979 | 2979 | */ |
| 2980 | - public function get_instance_style($rules = array()){ |
|
| 2980 | + public function get_instance_style($rules = array()) { |
|
| 2981 | 2981 | $css = ''; |
| 2982 | 2982 | |
| 2983 | - if(!empty($rules)){ |
|
| 2983 | + if (!empty($rules)) { |
|
| 2984 | 2984 | $rules = array_unique($rules); |
| 2985 | 2985 | $instance_hash = $this->get_instance_hash(); |
| 2986 | 2986 | $css .= "<style>"; |
| 2987 | - foreach($rules as $rule){ |
|
| 2987 | + foreach ($rules as $rule) { |
|
| 2988 | 2988 | $css .= ".sdel-$instance_hash $rule"; |
| 2989 | 2989 | } |
| 2990 | 2990 | $css .= "</style>"; |
@@ -661,7 +661,7 @@ discard block |
||
| 661 | 661 | <?php |
| 662 | 662 | if(! empty( $insert_shortcode_function )){ |
| 663 | 663 | echo $insert_shortcode_function; |
| 664 | - }else{ |
|
| 664 | + } else{ |
|
| 665 | 665 | |
| 666 | 666 | /** |
| 667 | 667 | * Function for super duper insert shortcode. |
@@ -1647,7 +1647,7 @@ discard block |
||
| 1647 | 1647 | var prev_attributes = []; |
| 1648 | 1648 | |
| 1649 | 1649 | var term_query_type = ''; |
| 1650 | - var post_type_rest_slugs = <?php if(! empty( $this->arguments ) && isset($this->arguments['post_type']['onchange_rest']['values'])){echo "[".json_encode($this->arguments['post_type']['onchange_rest']['values'])."]";}else{echo "[]";} ?>; |
|
| 1650 | + var post_type_rest_slugs = <?php if(! empty( $this->arguments ) && isset($this->arguments['post_type']['onchange_rest']['values'])){echo "[".json_encode($this->arguments['post_type']['onchange_rest']['values'])."]";} else{echo "[]";} ?>; |
|
| 1651 | 1651 | const taxonomies_<?php echo str_replace("-","_", $this->id);?> = [{label: "Please wait", value: 0}]; |
| 1652 | 1652 | const sort_by_<?php echo str_replace("-","_", $this->id);?> = [{label: "Please wait", value: 0}]; |
| 1653 | 1653 | |
@@ -1784,7 +1784,7 @@ discard block |
||
| 1784 | 1784 | |
| 1785 | 1785 | // taxonomies |
| 1786 | 1786 | if( $value && 'post_type' in prev_attributes[props.id] && 'category' in prev_attributes[props.id] && run ){ |
| 1787 | - wp.apiFetch({path: "<?php if(isset($this->arguments['post_type']['onchange_rest']['path'])){echo $this->arguments['post_type']['onchange_rest']['path'];}else{'/wp/v2/"+$value+"/categories';} ?>"}).then(terms => { |
|
| 1787 | + wp.apiFetch({path: "<?php if(isset($this->arguments['post_type']['onchange_rest']['path'])){echo $this->arguments['post_type']['onchange_rest']['path'];} else{'/wp/v2/"+$value+"/categories';} ?>"}).then(terms => { |
|
| 1788 | 1788 | while (taxonomies_<?php echo str_replace("-","_", $this->id);?>.length) { |
| 1789 | 1789 | taxonomies_<?php echo str_replace("-","_", $this->id);?>.pop(); |
| 1790 | 1790 | } |
@@ -1958,7 +1958,7 @@ discard block |
||
| 1958 | 1958 | $panel_count ++; |
| 1959 | 1959 | |
| 1960 | 1960 | } |
| 1961 | - }else { |
|
| 1961 | + } else { |
|
| 1962 | 1962 | ?> |
| 1963 | 1963 | el(wp.components.PanelBody, { |
| 1964 | 1964 | title: '<?php esc_attr_e( "Settings" ); ?>', |
@@ -1982,7 +1982,7 @@ discard block |
||
| 1982 | 1982 | // If the user sets block-output array then build it |
| 1983 | 1983 | if ( ! empty( $this->options['block-output'] ) ) { |
| 1984 | 1984 | $this->block_element( $this->options['block-output'] ); |
| 1985 | - }else{ |
|
| 1985 | + } else{ |
|
| 1986 | 1986 | // if no block-output is set then we try and get the shortcode html output via ajax. |
| 1987 | 1987 | ?> |
| 1988 | 1988 | el('div', { |
@@ -2052,7 +2052,7 @@ discard block |
||
| 2052 | 2052 | ?> |
| 2053 | 2053 | return content; |
| 2054 | 2054 | <?php |
| 2055 | - }else{ |
|
| 2055 | + } else{ |
|
| 2056 | 2056 | ?> |
| 2057 | 2057 | var block_wrap = 'div'; |
| 2058 | 2058 | if (attr.hasOwnProperty("block_wrap")) { |
@@ -2157,8 +2157,7 @@ discard block |
||
| 2157 | 2157 | $key: value |
| 2158 | 2158 | }); |
| 2159 | 2159 | },"; |
| 2160 | - } |
|
| 2161 | - elseif ( $args['type'] == 'checkbox' ) { |
|
| 2160 | + } elseif ( $args['type'] == 'checkbox' ) { |
|
| 2162 | 2161 | $type = 'CheckboxControl'; |
| 2163 | 2162 | $extra .= "checked: props.attributes.$key,"; |
| 2164 | 2163 | $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )"; |
@@ -2169,9 +2168,9 @@ discard block |
||
| 2169 | 2168 | |
| 2170 | 2169 | if($args['name'] == 'category' && !empty($args['post_type_linked'])){ |
| 2171 | 2170 | $options .= "options: taxonomies_".str_replace("-","_", $this->id).","; |
| 2172 | - }elseif($args['name'] == 'sort_by' && !empty($args['post_type_linked'])){ |
|
| 2171 | + } elseif($args['name'] == 'sort_by' && !empty($args['post_type_linked'])){ |
|
| 2173 | 2172 | $options .= "options: sort_by_".str_replace("-","_", $this->id).","; |
| 2174 | - }else { |
|
| 2173 | + } else { |
|
| 2175 | 2174 | |
| 2176 | 2175 | if ( ! empty( $args['options'] ) ) { |
| 2177 | 2176 | $options .= "options: ["; |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | * Bail if we are not in WP. |
| 14 | 14 | */ |
| 15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | - exit; |
|
| 16 | + exit; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -21,294 +21,294 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * A Class to be able to change settings for Font Awesome. |
|
| 26 | - * |
|
| 27 | - * Class WP_Font_Awesome_Settings |
|
| 28 | - * @since 1.0.10 Now able to pass wp.org theme check. |
|
| 29 | - * @since 1.0.11 Font Awesome Pro now supported. |
|
| 30 | - * @since 1.0.11 Font Awesome Kits now supported. |
|
| 31 | - * @ver 1.0.11 |
|
| 32 | - * @todo decide how to implement textdomain |
|
| 33 | - */ |
|
| 34 | - class WP_Font_Awesome_Settings { |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Class version version. |
|
| 38 | - * |
|
| 39 | - * @var string |
|
| 40 | - */ |
|
| 41 | - public $version = '1.0.12'; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Class textdomain. |
|
| 45 | - * |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 48 | - public $textdomain = 'font-awesome-settings'; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Latest version of Font Awesome at time of publish published. |
|
| 52 | - * |
|
| 53 | - * @var string |
|
| 54 | - */ |
|
| 55 | - public $latest = "5.8.2"; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * The title. |
|
| 59 | - * |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 62 | - public $name = 'Font Awesome'; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Holds the settings values. |
|
| 66 | - * |
|
| 67 | - * @var array |
|
| 68 | - */ |
|
| 69 | - private $settings; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * WP_Font_Awesome_Settings instance. |
|
| 73 | - * |
|
| 74 | - * @access private |
|
| 75 | - * @since 1.0.0 |
|
| 76 | - * @var WP_Font_Awesome_Settings There can be only one! |
|
| 77 | - */ |
|
| 78 | - private static $instance = null; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Main WP_Font_Awesome_Settings Instance. |
|
| 82 | - * |
|
| 83 | - * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
| 84 | - * |
|
| 85 | - * @since 1.0.0 |
|
| 86 | - * @static |
|
| 87 | - * @return WP_Font_Awesome_Settings - Main instance. |
|
| 88 | - */ |
|
| 89 | - public static function instance() { |
|
| 90 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
| 91 | - self::$instance = new WP_Font_Awesome_Settings; |
|
| 92 | - |
|
| 93 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
| 94 | - |
|
| 95 | - if ( is_admin() ) { |
|
| 96 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
| 97 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - return self::$instance; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Initiate the settings and add the required action hooks. |
|
| 108 | - * |
|
| 109 | - * @since 1.0.8 Settings name wrong - FIXED |
|
| 110 | - */ |
|
| 111 | - public function init() { |
|
| 112 | - $this->settings = $this->get_settings(); |
|
| 113 | - |
|
| 114 | - if ( $this->settings['type'] == 'CSS' ) { |
|
| 115 | - |
|
| 116 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
| 117 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
| 121 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - } else { |
|
| 125 | - |
|
| 126 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
| 127 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
| 131 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - // remove font awesome if set to do so |
|
| 136 | - if ( $this->settings['dequeue'] == '1' ) { |
|
| 137 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Adds the Font Awesome styles. |
|
| 144 | - */ |
|
| 145 | - public function enqueue_style() { |
|
| 146 | - // build url |
|
| 147 | - $url = $this->get_url(); |
|
| 148 | - |
|
| 149 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
| 150 | - wp_register_style( 'font-awesome', $url, array(), null ); |
|
| 151 | - wp_enqueue_style( 'font-awesome' ); |
|
| 152 | - |
|
| 153 | - if ( $this->settings['shims'] ) { |
|
| 154 | - $url = $this->get_url( true ); |
|
| 155 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
| 156 | - wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
| 157 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Adds the Font Awesome JS. |
|
| 163 | - */ |
|
| 164 | - public function enqueue_scripts() { |
|
| 165 | - // build url |
|
| 166 | - $url = $this->get_url(); |
|
| 167 | - |
|
| 168 | - $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
| 169 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
| 170 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
| 171 | - wp_enqueue_script( 'font-awesome' ); |
|
| 172 | - |
|
| 173 | - if ( $this->settings['shims'] ) { |
|
| 174 | - $url = $this->get_url( true ); |
|
| 175 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
| 176 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
| 177 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Get the url of the Font Awesome files. |
|
| 183 | - * |
|
| 184 | - * @param bool $shims If this is a shim file or not. |
|
| 185 | - * |
|
| 186 | - * @return string The url to the file. |
|
| 187 | - */ |
|
| 188 | - public function get_url( $shims = false ) { |
|
| 189 | - $script = $shims ? 'v4-shims' : 'all'; |
|
| 190 | - $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
| 191 | - $type = $this->settings['type']; |
|
| 192 | - $version = $this->settings['version']; |
|
| 193 | - $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
| 194 | - $url = ''; |
|
| 195 | - |
|
| 196 | - if ( $type == 'KIT' && $kit_url ) { |
|
| 197 | - if ( $shims ) { |
|
| 198 | - // if its a kit then we don't add shims here |
|
| 199 | - return ''; |
|
| 200 | - } |
|
| 201 | - $url .= $kit_url; // CDN |
|
| 202 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
| 203 | - } else { |
|
| 204 | - $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
| 205 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
| 206 | - $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
| 207 | - $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
| 208 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - return $url; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
| 216 | - * |
|
| 217 | - * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
| 218 | - * |
|
| 219 | - * @param $url |
|
| 220 | - * @param $original_url |
|
| 221 | - * @param $_context |
|
| 222 | - * |
|
| 223 | - * @return string The filtered url. |
|
| 224 | - */ |
|
| 225 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
| 226 | - |
|
| 227 | - if ( $_context == 'display' |
|
| 228 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
| 229 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
| 230 | - ) {// it's a font-awesome-url (probably) |
|
| 231 | - |
|
| 232 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
| 233 | - if ( $this->settings['type'] == 'JS' ) { |
|
| 234 | - if ( $this->settings['js-pseudo'] ) { |
|
| 235 | - $url .= "' data-search-pseudo-elements defer='defer"; |
|
| 236 | - } else { |
|
| 237 | - $url .= "' defer='defer"; |
|
| 238 | - } |
|
| 239 | - } |
|
| 240 | - } else { |
|
| 241 | - $url = ''; // removing the url removes the file |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - return $url; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Register the database settings with WordPress. |
|
| 251 | - */ |
|
| 252 | - public function register_settings() { |
|
| 253 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * Add the WordPress settings menu item. |
|
| 258 | - * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
| 259 | - */ |
|
| 260 | - public function menu_item() { |
|
| 261 | - $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
| 262 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
| 263 | - $this, |
|
| 264 | - 'settings_page' |
|
| 265 | - ) ); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * Get the current Font Awesome output settings. |
|
| 270 | - * |
|
| 271 | - * @return array The array of settings. |
|
| 272 | - */ |
|
| 273 | - public function get_settings() { |
|
| 274 | - |
|
| 275 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
| 276 | - |
|
| 277 | - $defaults = array( |
|
| 278 | - 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
| 279 | - 'version' => '', // latest |
|
| 280 | - 'enqueue' => '', // front and backend |
|
| 281 | - 'shims' => '0', // default OFF now in 2020 |
|
| 282 | - 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
| 283 | - 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
| 284 | - 'pro' => '0', // if pro CDN url should be used |
|
| 285 | - 'kit-url' => '', // the kit url |
|
| 286 | - ); |
|
| 287 | - |
|
| 288 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Filter the Font Awesome settings. |
|
| 292 | - * |
|
| 293 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
| 294 | - */ |
|
| 295 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * The settings page html output. |
|
| 301 | - */ |
|
| 302 | - public function settings_page() { |
|
| 303 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 304 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - // a hidden way to force the update of the verison number vai api instead of waiting the 48 hours |
|
| 308 | - if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
| 309 | - $this->get_latest_version( $force_api = true ); |
|
| 310 | - } |
|
| 311 | - ?> |
|
| 24 | + /** |
|
| 25 | + * A Class to be able to change settings for Font Awesome. |
|
| 26 | + * |
|
| 27 | + * Class WP_Font_Awesome_Settings |
|
| 28 | + * @since 1.0.10 Now able to pass wp.org theme check. |
|
| 29 | + * @since 1.0.11 Font Awesome Pro now supported. |
|
| 30 | + * @since 1.0.11 Font Awesome Kits now supported. |
|
| 31 | + * @ver 1.0.11 |
|
| 32 | + * @todo decide how to implement textdomain |
|
| 33 | + */ |
|
| 34 | + class WP_Font_Awesome_Settings { |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Class version version. |
|
| 38 | + * |
|
| 39 | + * @var string |
|
| 40 | + */ |
|
| 41 | + public $version = '1.0.12'; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Class textdomain. |
|
| 45 | + * |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | + public $textdomain = 'font-awesome-settings'; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Latest version of Font Awesome at time of publish published. |
|
| 52 | + * |
|
| 53 | + * @var string |
|
| 54 | + */ |
|
| 55 | + public $latest = "5.8.2"; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * The title. |
|
| 59 | + * |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | + public $name = 'Font Awesome'; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Holds the settings values. |
|
| 66 | + * |
|
| 67 | + * @var array |
|
| 68 | + */ |
|
| 69 | + private $settings; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * WP_Font_Awesome_Settings instance. |
|
| 73 | + * |
|
| 74 | + * @access private |
|
| 75 | + * @since 1.0.0 |
|
| 76 | + * @var WP_Font_Awesome_Settings There can be only one! |
|
| 77 | + */ |
|
| 78 | + private static $instance = null; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Main WP_Font_Awesome_Settings Instance. |
|
| 82 | + * |
|
| 83 | + * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
| 84 | + * |
|
| 85 | + * @since 1.0.0 |
|
| 86 | + * @static |
|
| 87 | + * @return WP_Font_Awesome_Settings - Main instance. |
|
| 88 | + */ |
|
| 89 | + public static function instance() { |
|
| 90 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
| 91 | + self::$instance = new WP_Font_Awesome_Settings; |
|
| 92 | + |
|
| 93 | + add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
| 94 | + |
|
| 95 | + if ( is_admin() ) { |
|
| 96 | + add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
| 97 | + add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + do_action( 'wp_font_awesome_settings_loaded' ); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + return self::$instance; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Initiate the settings and add the required action hooks. |
|
| 108 | + * |
|
| 109 | + * @since 1.0.8 Settings name wrong - FIXED |
|
| 110 | + */ |
|
| 111 | + public function init() { |
|
| 112 | + $this->settings = $this->get_settings(); |
|
| 113 | + |
|
| 114 | + if ( $this->settings['type'] == 'CSS' ) { |
|
| 115 | + |
|
| 116 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
| 117 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
| 121 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + } else { |
|
| 125 | + |
|
| 126 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
| 127 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
| 131 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + // remove font awesome if set to do so |
|
| 136 | + if ( $this->settings['dequeue'] == '1' ) { |
|
| 137 | + add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Adds the Font Awesome styles. |
|
| 144 | + */ |
|
| 145 | + public function enqueue_style() { |
|
| 146 | + // build url |
|
| 147 | + $url = $this->get_url(); |
|
| 148 | + |
|
| 149 | + wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
| 150 | + wp_register_style( 'font-awesome', $url, array(), null ); |
|
| 151 | + wp_enqueue_style( 'font-awesome' ); |
|
| 152 | + |
|
| 153 | + if ( $this->settings['shims'] ) { |
|
| 154 | + $url = $this->get_url( true ); |
|
| 155 | + wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
| 156 | + wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
| 157 | + wp_enqueue_style( 'font-awesome-shims' ); |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Adds the Font Awesome JS. |
|
| 163 | + */ |
|
| 164 | + public function enqueue_scripts() { |
|
| 165 | + // build url |
|
| 166 | + $url = $this->get_url(); |
|
| 167 | + |
|
| 168 | + $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
| 169 | + call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
| 170 | + wp_register_script( 'font-awesome', $url, array(), null ); |
|
| 171 | + wp_enqueue_script( 'font-awesome' ); |
|
| 172 | + |
|
| 173 | + if ( $this->settings['shims'] ) { |
|
| 174 | + $url = $this->get_url( true ); |
|
| 175 | + call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
| 176 | + wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
| 177 | + wp_enqueue_script( 'font-awesome-shims' ); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Get the url of the Font Awesome files. |
|
| 183 | + * |
|
| 184 | + * @param bool $shims If this is a shim file or not. |
|
| 185 | + * |
|
| 186 | + * @return string The url to the file. |
|
| 187 | + */ |
|
| 188 | + public function get_url( $shims = false ) { |
|
| 189 | + $script = $shims ? 'v4-shims' : 'all'; |
|
| 190 | + $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
| 191 | + $type = $this->settings['type']; |
|
| 192 | + $version = $this->settings['version']; |
|
| 193 | + $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
| 194 | + $url = ''; |
|
| 195 | + |
|
| 196 | + if ( $type == 'KIT' && $kit_url ) { |
|
| 197 | + if ( $shims ) { |
|
| 198 | + // if its a kit then we don't add shims here |
|
| 199 | + return ''; |
|
| 200 | + } |
|
| 201 | + $url .= $kit_url; // CDN |
|
| 202 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
| 203 | + } else { |
|
| 204 | + $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
| 205 | + $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
| 206 | + $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
| 207 | + $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
| 208 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + return $url; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
| 216 | + * |
|
| 217 | + * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
| 218 | + * |
|
| 219 | + * @param $url |
|
| 220 | + * @param $original_url |
|
| 221 | + * @param $_context |
|
| 222 | + * |
|
| 223 | + * @return string The filtered url. |
|
| 224 | + */ |
|
| 225 | + public function remove_font_awesome( $url, $original_url, $_context ) { |
|
| 226 | + |
|
| 227 | + if ( $_context == 'display' |
|
| 228 | + && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
| 229 | + && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
| 230 | + ) {// it's a font-awesome-url (probably) |
|
| 231 | + |
|
| 232 | + if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
| 233 | + if ( $this->settings['type'] == 'JS' ) { |
|
| 234 | + if ( $this->settings['js-pseudo'] ) { |
|
| 235 | + $url .= "' data-search-pseudo-elements defer='defer"; |
|
| 236 | + } else { |
|
| 237 | + $url .= "' defer='defer"; |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | + } else { |
|
| 241 | + $url = ''; // removing the url removes the file |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + return $url; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Register the database settings with WordPress. |
|
| 251 | + */ |
|
| 252 | + public function register_settings() { |
|
| 253 | + register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * Add the WordPress settings menu item. |
|
| 258 | + * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
| 259 | + */ |
|
| 260 | + public function menu_item() { |
|
| 261 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
| 262 | + call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
| 263 | + $this, |
|
| 264 | + 'settings_page' |
|
| 265 | + ) ); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * Get the current Font Awesome output settings. |
|
| 270 | + * |
|
| 271 | + * @return array The array of settings. |
|
| 272 | + */ |
|
| 273 | + public function get_settings() { |
|
| 274 | + |
|
| 275 | + $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
| 276 | + |
|
| 277 | + $defaults = array( |
|
| 278 | + 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
| 279 | + 'version' => '', // latest |
|
| 280 | + 'enqueue' => '', // front and backend |
|
| 281 | + 'shims' => '0', // default OFF now in 2020 |
|
| 282 | + 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
| 283 | + 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
| 284 | + 'pro' => '0', // if pro CDN url should be used |
|
| 285 | + 'kit-url' => '', // the kit url |
|
| 286 | + ); |
|
| 287 | + |
|
| 288 | + $settings = wp_parse_args( $db_settings, $defaults ); |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Filter the Font Awesome settings. |
|
| 292 | + * |
|
| 293 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
| 294 | + */ |
|
| 295 | + return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * The settings page html output. |
|
| 301 | + */ |
|
| 302 | + public function settings_page() { |
|
| 303 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
| 304 | + wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + // a hidden way to force the update of the verison number vai api instead of waiting the 48 hours |
|
| 308 | + if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
| 309 | + $this->get_latest_version( $force_api = true ); |
|
| 310 | + } |
|
| 311 | + ?> |
|
| 312 | 312 | <style> |
| 313 | 313 | .wpfas-kit-show { |
| 314 | 314 | display: none; |
@@ -326,10 +326,10 @@ discard block |
||
| 326 | 326 | <h1><?php echo $this->name; ?></h1> |
| 327 | 327 | <form method="post" action="options.php"> |
| 328 | 328 | <?php |
| 329 | - settings_fields( 'wp-font-awesome-settings' ); |
|
| 330 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
| 331 | - $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
|
| 332 | - ?> |
|
| 329 | + settings_fields( 'wp-font-awesome-settings' ); |
|
| 330 | + do_settings_sections( 'wp-font-awesome-settings' ); |
|
| 331 | + $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
|
| 332 | + ?> |
|
| 333 | 333 | <table class="form-table wpfas-table-settings <?php echo esc_attr( $kit_set ); ?>"> |
| 334 | 334 | <tr valign="top"> |
| 335 | 335 | <th scope="row"><label |
@@ -355,12 +355,12 @@ discard block |
||
| 355 | 355 | value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" |
| 356 | 356 | placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
| 357 | 357 | <span><?php |
| 358 | - echo sprintf( |
|
| 359 | - __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
| 360 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
| 361 | - '</a>' |
|
| 362 | - ); |
|
| 363 | - ?></span> |
|
| 358 | + echo sprintf( |
|
| 359 | + __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
| 360 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
| 361 | + '</a>' |
|
| 362 | + ); |
|
| 363 | + ?></span> |
|
| 364 | 364 | </td> |
| 365 | 365 | </tr> |
| 366 | 366 | |
@@ -420,14 +420,14 @@ discard block |
||
| 420 | 420 | <input type="checkbox" name="wp-font-awesome-settings[pro]" |
| 421 | 421 | value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro"/> |
| 422 | 422 | <span><?php |
| 423 | - echo sprintf( |
|
| 424 | - __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
| 425 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>', |
|
| 426 | - '</a>', |
|
| 427 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>', |
|
| 428 | - '</a>' |
|
| 429 | - ); |
|
| 430 | - ?></span> |
|
| 423 | + echo sprintf( |
|
| 424 | + __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
| 425 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>', |
|
| 426 | + '</a>', |
|
| 427 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>', |
|
| 428 | + '</a>' |
|
| 429 | + ); |
|
| 430 | + ?></span> |
|
| 431 | 431 | </td> |
| 432 | 432 | </tr> |
| 433 | 433 | |
@@ -470,88 +470,88 @@ discard block |
||
| 470 | 470 | |
| 471 | 471 | </table> |
| 472 | 472 | <?php |
| 473 | - submit_button(); |
|
| 474 | - ?> |
|
| 473 | + submit_button(); |
|
| 474 | + ?> |
|
| 475 | 475 | </form> |
| 476 | 476 | |
| 477 | 477 | <div id="wpfas-version"><?php echo $this->version; ?></div> |
| 478 | 478 | </div> |
| 479 | 479 | |
| 480 | 480 | <?php |
| 481 | - } |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * Check a version number is valid and if so return it or else return an empty string. |
|
| 485 | - * |
|
| 486 | - * @param $version string The version number to check. |
|
| 487 | - * |
|
| 488 | - * @since 1.0.6 |
|
| 489 | - * |
|
| 490 | - * @return string Either a valid version number or an empty string. |
|
| 491 | - */ |
|
| 492 | - public function validate_version_number( $version ) { |
|
| 493 | - |
|
| 494 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
| 495 | - // valid |
|
| 496 | - } else { |
|
| 497 | - $version = '';// not validated |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - return $version; |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - |
|
| 504 | - /** |
|
| 505 | - * Get the latest version of Font Awesome. |
|
| 506 | - * |
|
| 507 | - * We check for a cached bersion and if none we will check for a live version via API and then cache it for 48 hours. |
|
| 508 | - * |
|
| 509 | - * @since 1.0.7 |
|
| 510 | - * @return mixed|string The latest version number found. |
|
| 511 | - */ |
|
| 512 | - public function get_latest_version( $force_api = false ) { |
|
| 513 | - $latest_version = $this->latest; |
|
| 514 | - |
|
| 515 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
| 516 | - |
|
| 517 | - if ( $cache === false || $force_api ) { // its not set |
|
| 518 | - $api_ver = $this->get_latest_version_from_api(); |
|
| 519 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
| 520 | - $latest_version = $api_ver; |
|
| 521 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
| 522 | - } |
|
| 523 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
| 524 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
| 525 | - $latest_version = $cache; |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - return $latest_version; |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * Get the latest Font Awesome version from the github API. |
|
| 534 | - * |
|
| 535 | - * @since 1.0.7 |
|
| 536 | - * @return string The latest version number or `0` on API fail. |
|
| 537 | - */ |
|
| 538 | - public function get_latest_version_from_api() { |
|
| 539 | - $version = "0"; |
|
| 540 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
| 541 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
| 542 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 543 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
| 544 | - $version = $api_response['tag_name']; |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - return $version; |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - /** |
|
| 554 | - * Run the class if found. |
|
| 555 | - */ |
|
| 556 | - WP_Font_Awesome_Settings::instance(); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * Check a version number is valid and if so return it or else return an empty string. |
|
| 485 | + * |
|
| 486 | + * @param $version string The version number to check. |
|
| 487 | + * |
|
| 488 | + * @since 1.0.6 |
|
| 489 | + * |
|
| 490 | + * @return string Either a valid version number or an empty string. |
|
| 491 | + */ |
|
| 492 | + public function validate_version_number( $version ) { |
|
| 493 | + |
|
| 494 | + if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
| 495 | + // valid |
|
| 496 | + } else { |
|
| 497 | + $version = '';// not validated |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + return $version; |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + |
|
| 504 | + /** |
|
| 505 | + * Get the latest version of Font Awesome. |
|
| 506 | + * |
|
| 507 | + * We check for a cached bersion and if none we will check for a live version via API and then cache it for 48 hours. |
|
| 508 | + * |
|
| 509 | + * @since 1.0.7 |
|
| 510 | + * @return mixed|string The latest version number found. |
|
| 511 | + */ |
|
| 512 | + public function get_latest_version( $force_api = false ) { |
|
| 513 | + $latest_version = $this->latest; |
|
| 514 | + |
|
| 515 | + $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
| 516 | + |
|
| 517 | + if ( $cache === false || $force_api ) { // its not set |
|
| 518 | + $api_ver = $this->get_latest_version_from_api(); |
|
| 519 | + if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
| 520 | + $latest_version = $api_ver; |
|
| 521 | + set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
| 522 | + } |
|
| 523 | + } elseif ( $this->validate_version_number( $cache ) ) { |
|
| 524 | + if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
| 525 | + $latest_version = $cache; |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + return $latest_version; |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * Get the latest Font Awesome version from the github API. |
|
| 534 | + * |
|
| 535 | + * @since 1.0.7 |
|
| 536 | + * @return string The latest version number or `0` on API fail. |
|
| 537 | + */ |
|
| 538 | + public function get_latest_version_from_api() { |
|
| 539 | + $version = "0"; |
|
| 540 | + $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
| 541 | + if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
| 542 | + $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 543 | + if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
| 544 | + $version = $api_response['tag_name']; |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + return $version; |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + /** |
|
| 554 | + * Run the class if found. |
|
| 555 | + */ |
|
| 556 | + WP_Font_Awesome_Settings::instance(); |
|
| 557 | 557 | } |
| 558 | 558 | \ No newline at end of file |
@@ -12,14 +12,14 @@ discard block |
||
| 12 | 12 | /** |
| 13 | 13 | * Bail if we are not in WP. |
| 14 | 14 | */ |
| 15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 15 | +if (!defined('ABSPATH')) { |
|
| 16 | 16 | exit; |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * Only add if the class does not already exist. |
| 21 | 21 | */ |
| 22 | -if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
|
| 22 | +if (!class_exists('WP_Font_Awesome_Settings')) { |
|
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * A Class to be able to change settings for Font Awesome. |
@@ -87,17 +87,17 @@ discard block |
||
| 87 | 87 | * @return WP_Font_Awesome_Settings - Main instance. |
| 88 | 88 | */ |
| 89 | 89 | public static function instance() { |
| 90 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
| 90 | + if (!isset(self::$instance) && !(self::$instance instanceof WP_Font_Awesome_Settings)) { |
|
| 91 | 91 | self::$instance = new WP_Font_Awesome_Settings; |
| 92 | 92 | |
| 93 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
| 93 | + add_action('init', array(self::$instance, 'init')); // set settings |
|
| 94 | 94 | |
| 95 | - if ( is_admin() ) { |
|
| 96 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
| 97 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
| 95 | + if (is_admin()) { |
|
| 96 | + add_action('admin_menu', array(self::$instance, 'menu_item')); |
|
| 97 | + add_action('admin_init', array(self::$instance, 'register_settings')); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
| 100 | + do_action('wp_font_awesome_settings_loaded'); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | return self::$instance; |
@@ -111,30 +111,30 @@ discard block |
||
| 111 | 111 | public function init() { |
| 112 | 112 | $this->settings = $this->get_settings(); |
| 113 | 113 | |
| 114 | - if ( $this->settings['type'] == 'CSS' ) { |
|
| 114 | + if ($this->settings['type'] == 'CSS') { |
|
| 115 | 115 | |
| 116 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
| 117 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
| 116 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
| 117 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_style'), 5000); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
| 121 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
| 120 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') { |
|
| 121 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_style'), 5000); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | } else { |
| 125 | 125 | |
| 126 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
| 127 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
| 126 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
| 127 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
| 131 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
| 130 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') { |
|
| 131 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | // remove font awesome if set to do so |
| 136 | - if ( $this->settings['dequeue'] == '1' ) { |
|
| 137 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
| 136 | + if ($this->settings['dequeue'] == '1') { |
|
| 137 | + add_action('clean_url', array($this, 'remove_font_awesome'), 5000, 3); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | } |
@@ -146,15 +146,15 @@ discard block |
||
| 146 | 146 | // build url |
| 147 | 147 | $url = $this->get_url(); |
| 148 | 148 | |
| 149 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
| 150 | - wp_register_style( 'font-awesome', $url, array(), null ); |
|
| 151 | - wp_enqueue_style( 'font-awesome' ); |
|
| 149 | + wp_deregister_style('font-awesome'); // deregister in case its already there |
|
| 150 | + wp_register_style('font-awesome', $url, array(), null); |
|
| 151 | + wp_enqueue_style('font-awesome'); |
|
| 152 | 152 | |
| 153 | - if ( $this->settings['shims'] ) { |
|
| 154 | - $url = $this->get_url( true ); |
|
| 155 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
| 156 | - wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
| 157 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
| 153 | + if ($this->settings['shims']) { |
|
| 154 | + $url = $this->get_url(true); |
|
| 155 | + wp_deregister_style('font-awesome-shims'); // deregister in case its already there |
|
| 156 | + wp_register_style('font-awesome-shims', $url, array(), null); |
|
| 157 | + wp_enqueue_style('font-awesome-shims'); |
|
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | 160 | |
@@ -166,15 +166,15 @@ discard block |
||
| 166 | 166 | $url = $this->get_url(); |
| 167 | 167 | |
| 168 | 168 | $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
| 169 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
| 170 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
| 171 | - wp_enqueue_script( 'font-awesome' ); |
|
| 172 | - |
|
| 173 | - if ( $this->settings['shims'] ) { |
|
| 174 | - $url = $this->get_url( true ); |
|
| 175 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
| 176 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
| 177 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
| 169 | + call_user_func($deregister_function, 'font-awesome'); // deregister in case its already there |
|
| 170 | + wp_register_script('font-awesome', $url, array(), null); |
|
| 171 | + wp_enqueue_script('font-awesome'); |
|
| 172 | + |
|
| 173 | + if ($this->settings['shims']) { |
|
| 174 | + $url = $this->get_url(true); |
|
| 175 | + call_user_func($deregister_function, 'font-awesome-shims'); // deregister in case its already there |
|
| 176 | + wp_register_script('font-awesome-shims', $url, array(), null); |
|
| 177 | + wp_enqueue_script('font-awesome-shims'); |
|
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | |
@@ -185,16 +185,16 @@ discard block |
||
| 185 | 185 | * |
| 186 | 186 | * @return string The url to the file. |
| 187 | 187 | */ |
| 188 | - public function get_url( $shims = false ) { |
|
| 188 | + public function get_url($shims = false) { |
|
| 189 | 189 | $script = $shims ? 'v4-shims' : 'all'; |
| 190 | 190 | $sub = $this->settings['pro'] ? 'pro' : 'use'; |
| 191 | 191 | $type = $this->settings['type']; |
| 192 | 192 | $version = $this->settings['version']; |
| 193 | - $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
| 193 | + $kit_url = $this->settings['kit-url'] ? esc_url($this->settings['kit-url']) : ''; |
|
| 194 | 194 | $url = ''; |
| 195 | 195 | |
| 196 | - if ( $type == 'KIT' && $kit_url ) { |
|
| 197 | - if ( $shims ) { |
|
| 196 | + if ($type == 'KIT' && $kit_url) { |
|
| 197 | + if ($shims) { |
|
| 198 | 198 | // if its a kit then we don't add shims here |
| 199 | 199 | return ''; |
| 200 | 200 | } |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | $url .= "?wpfas=true"; // set our var so our version is not removed |
| 203 | 203 | } else { |
| 204 | 204 | $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
| 205 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
| 205 | + $url .= !empty($version) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
| 206 | 206 | $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
| 207 | 207 | $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
| 208 | 208 | $url .= "?wpfas=true"; // set our var so our version is not removed |
@@ -222,16 +222,16 @@ discard block |
||
| 222 | 222 | * |
| 223 | 223 | * @return string The filtered url. |
| 224 | 224 | */ |
| 225 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
| 225 | + public function remove_font_awesome($url, $original_url, $_context) { |
|
| 226 | 226 | |
| 227 | - if ( $_context == 'display' |
|
| 228 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
| 229 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
| 227 | + if ($_context == 'display' |
|
| 228 | + && (strstr($url, "fontawesome") !== false || strstr($url, "font-awesome") !== false) |
|
| 229 | + && (strstr($url, ".js") !== false || strstr($url, ".css") !== false) |
|
| 230 | 230 | ) {// it's a font-awesome-url (probably) |
| 231 | 231 | |
| 232 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
| 233 | - if ( $this->settings['type'] == 'JS' ) { |
|
| 234 | - if ( $this->settings['js-pseudo'] ) { |
|
| 232 | + if (strstr($url, "wpfas=true") !== false) { |
|
| 233 | + if ($this->settings['type'] == 'JS') { |
|
| 234 | + if ($this->settings['js-pseudo']) { |
|
| 235 | 235 | $url .= "' data-search-pseudo-elements defer='defer"; |
| 236 | 236 | } else { |
| 237 | 237 | $url .= "' defer='defer"; |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * Register the database settings with WordPress. |
| 251 | 251 | */ |
| 252 | 252 | public function register_settings() { |
| 253 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
| 253 | + register_setting('wp-font-awesome-settings', 'wp-font-awesome-settings'); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /** |
@@ -259,10 +259,10 @@ discard block |
||
| 259 | 259 | */ |
| 260 | 260 | public function menu_item() { |
| 261 | 261 | $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
| 262 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
| 262 | + call_user_func($menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
| 263 | 263 | $this, |
| 264 | 264 | 'settings_page' |
| 265 | - ) ); |
|
| 265 | + )); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | /** |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | */ |
| 273 | 273 | public function get_settings() { |
| 274 | 274 | |
| 275 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
| 275 | + $db_settings = get_option('wp-font-awesome-settings'); |
|
| 276 | 276 | |
| 277 | 277 | $defaults = array( |
| 278 | 278 | 'type' => 'CSS', // type to use, CSS or JS or KIT |
@@ -285,14 +285,14 @@ discard block |
||
| 285 | 285 | 'kit-url' => '', // the kit url |
| 286 | 286 | ); |
| 287 | 287 | |
| 288 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
| 288 | + $settings = wp_parse_args($db_settings, $defaults); |
|
| 289 | 289 | |
| 290 | 290 | /** |
| 291 | 291 | * Filter the Font Awesome settings. |
| 292 | 292 | * |
| 293 | 293 | * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
| 294 | 294 | */ |
| 295 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
| 295 | + return $this->settings = apply_filters('wp-font-awesome-settings', $settings, $db_settings, $defaults); |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | |
@@ -300,13 +300,13 @@ discard block |
||
| 300 | 300 | * The settings page html output. |
| 301 | 301 | */ |
| 302 | 302 | public function settings_page() { |
| 303 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
| 304 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
| 303 | + if (!current_user_can('manage_options')) { |
|
| 304 | + wp_die(__('You do not have sufficient permissions to access this page.', 'font-awesome-settings')); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | // a hidden way to force the update of the verison number vai api instead of waiting the 48 hours |
| 308 | - if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
| 309 | - $this->get_latest_version( $force_api = true ); |
|
| 308 | + if (isset($_REQUEST['force-version-check'])) { |
|
| 309 | + $this->get_latest_version($force_api = true); |
|
| 310 | 310 | } |
| 311 | 311 | ?> |
| 312 | 312 | <style> |
@@ -326,37 +326,37 @@ discard block |
||
| 326 | 326 | <h1><?php echo $this->name; ?></h1> |
| 327 | 327 | <form method="post" action="options.php"> |
| 328 | 328 | <?php |
| 329 | - settings_fields( 'wp-font-awesome-settings' ); |
|
| 330 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
| 329 | + settings_fields('wp-font-awesome-settings'); |
|
| 330 | + do_settings_sections('wp-font-awesome-settings'); |
|
| 331 | 331 | $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
| 332 | 332 | ?> |
| 333 | - <table class="form-table wpfas-table-settings <?php echo esc_attr( $kit_set ); ?>"> |
|
| 333 | + <table class="form-table wpfas-table-settings <?php echo esc_attr($kit_set); ?>"> |
|
| 334 | 334 | <tr valign="top"> |
| 335 | 335 | <th scope="row"><label |
| 336 | - for="wpfas-type"><?php _e( 'Type', 'font-awesome-settings' ); ?></label></th> |
|
| 336 | + for="wpfas-type"><?php _e('Type', 'font-awesome-settings'); ?></label></th> |
|
| 337 | 337 | <td> |
| 338 | 338 | <select name="wp-font-awesome-settings[type]" id="wpfas-type" |
| 339 | 339 | onchange="if(this.value=='KIT'){jQuery('.wpfas-table-settings').addClass('wpfas-kit-set');}else{jQuery('.wpfas-table-settings').removeClass('wpfas-kit-set');}"> |
| 340 | 340 | <option |
| 341 | - value="CSS" <?php selected( $this->settings['type'], 'CSS' ); ?>><?php _e( 'CSS (default)', 'font-awesome-settings' ); ?></option> |
|
| 342 | - <option value="JS" <?php selected( $this->settings['type'], 'JS' ); ?>>JS</option> |
|
| 341 | + value="CSS" <?php selected($this->settings['type'], 'CSS'); ?>><?php _e('CSS (default)', 'font-awesome-settings'); ?></option> |
|
| 342 | + <option value="JS" <?php selected($this->settings['type'], 'JS'); ?>>JS</option> |
|
| 343 | 343 | <option |
| 344 | - value="KIT" <?php selected( $this->settings['type'], 'KIT' ); ?>><?php _e( 'Kits (settings managed on fontawesome.com)', 'font-awesome-settings' ); ?></option> |
|
| 344 | + value="KIT" <?php selected($this->settings['type'], 'KIT'); ?>><?php _e('Kits (settings managed on fontawesome.com)', 'font-awesome-settings'); ?></option> |
|
| 345 | 345 | </select> |
| 346 | 346 | </td> |
| 347 | 347 | </tr> |
| 348 | 348 | |
| 349 | 349 | <tr valign="top" class="wpfas-kit-show"> |
| 350 | 350 | <th scope="row"><label |
| 351 | - for="wpfas-kit-url"><?php _e( 'Kit URL', 'font-awesome-settings' ); ?></label></th> |
|
| 351 | + for="wpfas-kit-url"><?php _e('Kit URL', 'font-awesome-settings'); ?></label></th> |
|
| 352 | 352 | <td> |
| 353 | 353 | <input class="regular-text" id="wpfas-kit-url" type="url" |
| 354 | 354 | name="wp-font-awesome-settings[kit-url]" |
| 355 | - value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" |
|
| 356 | - placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
|
| 355 | + value="<?php echo esc_attr($this->settings['kit-url']); ?>" |
|
| 356 | + placeholder="<?php echo 'https://kit.font'; echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
|
| 357 | 357 | <span><?php |
| 358 | 358 | echo sprintf( |
| 359 | - __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
| 359 | + __('Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings'), |
|
| 360 | 360 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
| 361 | 361 | '</a>' |
| 362 | 362 | ); |
@@ -366,31 +366,31 @@ discard block |
||
| 366 | 366 | |
| 367 | 367 | <tr valign="top" class="wpfas-kit-hide"> |
| 368 | 368 | <th scope="row"><label |
| 369 | - for="wpfas-version"><?php _e( 'Version', 'font-awesome-settings' ); ?></label></th> |
|
| 369 | + for="wpfas-version"><?php _e('Version', 'font-awesome-settings'); ?></label></th> |
|
| 370 | 370 | <td> |
| 371 | 371 | <select name="wp-font-awesome-settings[version]" id="wpfas-version"> |
| 372 | 372 | <option |
| 373 | - value="" <?php selected( $this->settings['version'], '' ); ?>><?php echo sprintf( __( 'Latest - %s (default)', 'font-awesome-settings' ), $this->get_latest_version() ); ?> |
|
| 373 | + value="" <?php selected($this->settings['version'], ''); ?>><?php echo sprintf(__('Latest - %s (default)', 'font-awesome-settings'), $this->get_latest_version()); ?> |
|
| 374 | 374 | </option> |
| 375 | - <option value="5.6.0" <?php selected( $this->settings['version'], '5.6.0' ); ?>> |
|
| 375 | + <option value="5.6.0" <?php selected($this->settings['version'], '5.6.0'); ?>> |
|
| 376 | 376 | 5.6.0 |
| 377 | 377 | </option> |
| 378 | - <option value="5.5.0" <?php selected( $this->settings['version'], '5.5.0' ); ?>> |
|
| 378 | + <option value="5.5.0" <?php selected($this->settings['version'], '5.5.0'); ?>> |
|
| 379 | 379 | 5.5.0 |
| 380 | 380 | </option> |
| 381 | - <option value="5.4.0" <?php selected( $this->settings['version'], '5.4.0' ); ?>> |
|
| 381 | + <option value="5.4.0" <?php selected($this->settings['version'], '5.4.0'); ?>> |
|
| 382 | 382 | 5.4.0 |
| 383 | 383 | </option> |
| 384 | - <option value="5.3.0" <?php selected( $this->settings['version'], '5.3.0' ); ?>> |
|
| 384 | + <option value="5.3.0" <?php selected($this->settings['version'], '5.3.0'); ?>> |
|
| 385 | 385 | 5.3.0 |
| 386 | 386 | </option> |
| 387 | - <option value="5.2.0" <?php selected( $this->settings['version'], '5.2.0' ); ?>> |
|
| 387 | + <option value="5.2.0" <?php selected($this->settings['version'], '5.2.0'); ?>> |
|
| 388 | 388 | 5.2.0 |
| 389 | 389 | </option> |
| 390 | - <option value="5.1.0" <?php selected( $this->settings['version'], '5.1.0' ); ?>> |
|
| 390 | + <option value="5.1.0" <?php selected($this->settings['version'], '5.1.0'); ?>> |
|
| 391 | 391 | 5.1.0 |
| 392 | 392 | </option> |
| 393 | - <option value="4.7.0" <?php selected( $this->settings['version'], '4.7.0' ); ?>> |
|
| 393 | + <option value="4.7.0" <?php selected($this->settings['version'], '4.7.0'); ?>> |
|
| 394 | 394 | 4.7.1 (CSS only) |
| 395 | 395 | </option> |
| 396 | 396 | </select> |
@@ -399,29 +399,29 @@ discard block |
||
| 399 | 399 | |
| 400 | 400 | <tr valign="top"> |
| 401 | 401 | <th scope="row"><label |
| 402 | - for="wpfas-enqueue"><?php _e( 'Enqueue', 'font-awesome-settings' ); ?></label></th> |
|
| 402 | + for="wpfas-enqueue"><?php _e('Enqueue', 'font-awesome-settings'); ?></label></th> |
|
| 403 | 403 | <td> |
| 404 | 404 | <select name="wp-font-awesome-settings[enqueue]" id="wpfas-enqueue"> |
| 405 | 405 | <option |
| 406 | - value="" <?php selected( $this->settings['enqueue'], '' ); ?>><?php _e( 'Frontend + Backend (default)', 'font-awesome-settings' ); ?></option> |
|
| 406 | + value="" <?php selected($this->settings['enqueue'], ''); ?>><?php _e('Frontend + Backend (default)', 'font-awesome-settings'); ?></option> |
|
| 407 | 407 | <option |
| 408 | - value="frontend" <?php selected( $this->settings['enqueue'], 'frontend' ); ?>><?php _e( 'Frontend', 'font-awesome-settings' ); ?></option> |
|
| 408 | + value="frontend" <?php selected($this->settings['enqueue'], 'frontend'); ?>><?php _e('Frontend', 'font-awesome-settings'); ?></option> |
|
| 409 | 409 | <option |
| 410 | - value="backend" <?php selected( $this->settings['enqueue'], 'backend' ); ?>><?php _e( 'Backend', 'font-awesome-settings' ); ?></option> |
|
| 410 | + value="backend" <?php selected($this->settings['enqueue'], 'backend'); ?>><?php _e('Backend', 'font-awesome-settings'); ?></option> |
|
| 411 | 411 | </select> |
| 412 | 412 | </td> |
| 413 | 413 | </tr> |
| 414 | 414 | |
| 415 | 415 | <tr valign="top" class="wpfas-kit-hide"> |
| 416 | 416 | <th scope="row"><label |
| 417 | - for="wpfas-pro"><?php _e( 'Enable pro', 'font-awesome-settings' ); ?></label></th> |
|
| 417 | + for="wpfas-pro"><?php _e('Enable pro', 'font-awesome-settings'); ?></label></th> |
|
| 418 | 418 | <td> |
| 419 | 419 | <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/> |
| 420 | 420 | <input type="checkbox" name="wp-font-awesome-settings[pro]" |
| 421 | - value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro"/> |
|
| 421 | + value="1" <?php checked($this->settings['pro'], '1'); ?> id="wpfas-pro"/> |
|
| 422 | 422 | <span><?php |
| 423 | 423 | echo sprintf( |
| 424 | - __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
| 424 | + __('Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings'), |
|
| 425 | 425 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>', |
| 426 | 426 | '</a>', |
| 427 | 427 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>', |
@@ -433,38 +433,38 @@ discard block |
||
| 433 | 433 | |
| 434 | 434 | <tr valign="top" class="wpfas-kit-hide"> |
| 435 | 435 | <th scope="row"><label |
| 436 | - for="wpfas-shims"><?php _e( 'Enable v4 shims compatibility', 'font-awesome-settings' ); ?></label> |
|
| 436 | + for="wpfas-shims"><?php _e('Enable v4 shims compatibility', 'font-awesome-settings'); ?></label> |
|
| 437 | 437 | </th> |
| 438 | 438 | <td> |
| 439 | 439 | <input type="hidden" name="wp-font-awesome-settings[shims]" value="0"/> |
| 440 | 440 | <input type="checkbox" name="wp-font-awesome-settings[shims]" |
| 441 | - value="1" <?php checked( $this->settings['shims'], '1' ); ?> id="wpfas-shims"/> |
|
| 442 | - <span><?php _e( 'This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'font-awesome-settings' ); ?></span> |
|
| 441 | + value="1" <?php checked($this->settings['shims'], '1'); ?> id="wpfas-shims"/> |
|
| 442 | + <span><?php _e('This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'font-awesome-settings'); ?></span> |
|
| 443 | 443 | </td> |
| 444 | 444 | </tr> |
| 445 | 445 | |
| 446 | 446 | <tr valign="top" class="wpfas-kit-hide"> |
| 447 | 447 | <th scope="row"><label |
| 448 | - for="wpfas-js-pseudo"><?php _e( 'Enable JS pseudo elements (not recommended)', 'font-awesome-settings' ); ?></label> |
|
| 448 | + for="wpfas-js-pseudo"><?php _e('Enable JS pseudo elements (not recommended)', 'font-awesome-settings'); ?></label> |
|
| 449 | 449 | </th> |
| 450 | 450 | <td> |
| 451 | 451 | <input type="hidden" name="wp-font-awesome-settings[js-pseudo]" value="0"/> |
| 452 | 452 | <input type="checkbox" name="wp-font-awesome-settings[js-pseudo]" |
| 453 | - value="1" <?php checked( $this->settings['js-pseudo'], '1' ); ?> |
|
| 453 | + value="1" <?php checked($this->settings['js-pseudo'], '1'); ?> |
|
| 454 | 454 | id="wpfas-js-pseudo"/> |
| 455 | - <span><?php _e( 'Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'font-awesome-settings' ); ?></span> |
|
| 455 | + <span><?php _e('Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'font-awesome-settings'); ?></span> |
|
| 456 | 456 | </td> |
| 457 | 457 | </tr> |
| 458 | 458 | |
| 459 | 459 | <tr valign="top"> |
| 460 | 460 | <th scope="row"><label |
| 461 | - for="wpfas-dequeue"><?php _e( 'Dequeue', 'font-awesome-settings' ); ?></label></th> |
|
| 461 | + for="wpfas-dequeue"><?php _e('Dequeue', 'font-awesome-settings'); ?></label></th> |
|
| 462 | 462 | <td> |
| 463 | 463 | <input type="hidden" name="wp-font-awesome-settings[dequeue]" value="0"/> |
| 464 | 464 | <input type="checkbox" name="wp-font-awesome-settings[dequeue]" |
| 465 | - value="1" <?php checked( $this->settings['dequeue'], '1' ); ?> |
|
| 465 | + value="1" <?php checked($this->settings['dequeue'], '1'); ?> |
|
| 466 | 466 | id="wpfas-dequeue"/> |
| 467 | - <span><?php _e( 'This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'font-awesome-settings' ); ?></span> |
|
| 467 | + <span><?php _e('This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'font-awesome-settings'); ?></span> |
|
| 468 | 468 | </td> |
| 469 | 469 | </tr> |
| 470 | 470 | |
@@ -489,12 +489,12 @@ discard block |
||
| 489 | 489 | * |
| 490 | 490 | * @return string Either a valid version number or an empty string. |
| 491 | 491 | */ |
| 492 | - public function validate_version_number( $version ) { |
|
| 492 | + public function validate_version_number($version) { |
|
| 493 | 493 | |
| 494 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
| 494 | + if (version_compare($version, '0.0.1', '>=') >= 0) { |
|
| 495 | 495 | // valid |
| 496 | 496 | } else { |
| 497 | - $version = '';// not validated |
|
| 497 | + $version = ''; // not validated |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | return $version; |
@@ -509,19 +509,19 @@ discard block |
||
| 509 | 509 | * @since 1.0.7 |
| 510 | 510 | * @return mixed|string The latest version number found. |
| 511 | 511 | */ |
| 512 | - public function get_latest_version( $force_api = false ) { |
|
| 512 | + public function get_latest_version($force_api = false) { |
|
| 513 | 513 | $latest_version = $this->latest; |
| 514 | 514 | |
| 515 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
| 515 | + $cache = get_transient('wp-font-awesome-settings-version'); |
|
| 516 | 516 | |
| 517 | - if ( $cache === false || $force_api ) { // its not set |
|
| 517 | + if ($cache === false || $force_api) { // its not set |
|
| 518 | 518 | $api_ver = $this->get_latest_version_from_api(); |
| 519 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
| 519 | + if (version_compare($api_ver, $this->latest, '>=') >= 0) { |
|
| 520 | 520 | $latest_version = $api_ver; |
| 521 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
| 521 | + set_transient('wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS); |
|
| 522 | 522 | } |
| 523 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
| 524 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
| 523 | + } elseif ($this->validate_version_number($cache)) { |
|
| 524 | + if (version_compare($cache, $this->latest, '>=') >= 0) { |
|
| 525 | 525 | $latest_version = $cache; |
| 526 | 526 | } |
| 527 | 527 | } |
@@ -537,10 +537,10 @@ discard block |
||
| 537 | 537 | */ |
| 538 | 538 | public function get_latest_version_from_api() { |
| 539 | 539 | $version = "0"; |
| 540 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
| 541 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
| 542 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
| 543 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
| 540 | + $response = wp_remote_get("https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest"); |
|
| 541 | + if (!is_wp_error($response) && is_array($response)) { |
|
| 542 | + $api_response = json_decode(wp_remote_retrieve_body($response), true); |
|
| 543 | + if (isset($api_response['tag_name']) && version_compare($api_response['tag_name'], $this->latest, '>=') >= 0 && empty($api_response['prerelease'])) { |
|
| 544 | 544 | $version = $api_response['tag_name']; |
| 545 | 545 | } |
| 546 | 546 | } |
@@ -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,77 +11,77 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | class AUI_Component_Pagination { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Build the component. |
|
| 16 | - * |
|
| 17 | - * @param array $args |
|
| 18 | - * |
|
| 19 | - * @return string The rendered component. |
|
| 20 | - */ |
|
| 21 | - public static function get( $args = array() ) { |
|
| 22 | - global $wp_query; |
|
| 23 | - |
|
| 24 | - $defaults = array( |
|
| 25 | - 'class' => '', |
|
| 26 | - 'mid_size' => 2, |
|
| 27 | - 'prev_text' => '<i class="fas fa-chevron-left"></i>', |
|
| 28 | - 'next_text' => '<i class="fas fa-chevron-right"></i>', |
|
| 29 | - 'screen_reader_text' => __( 'Posts navigation','aui' ), |
|
| 30 | - 'before_paging' => '', |
|
| 31 | - 'after_paging' => '', |
|
| 32 | - 'type' => 'array', |
|
| 33 | - 'total' => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1, |
|
| 34 | - 'links' => array() // an array of links if using custom links, this includes the a tag. |
|
| 35 | - ); |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 39 | - */ |
|
| 40 | - $args = wp_parse_args( $args, $defaults ); |
|
| 41 | - |
|
| 42 | - $output = ''; |
|
| 43 | - |
|
| 44 | - // Don't print empty markup if there's only one page. |
|
| 45 | - if ( $args['total'] > 1 ) { |
|
| 46 | - |
|
| 47 | - // Set up paginated links. |
|
| 48 | - $links = !empty( $args['links'] ) ? $args['links'] : paginate_links( $args ); |
|
| 49 | - |
|
| 50 | - $class = !empty($args['class']) ? $args['class'] : ''; |
|
| 51 | - |
|
| 52 | - // make the output bootstrap ready |
|
| 53 | - $links_html = "<ul class='pagination m-0 p-0 $class'>"; |
|
| 54 | - if ( ! empty( $links ) ) { |
|
| 55 | - foreach ( $links as $link ) { |
|
| 56 | - $active = strpos( $link, 'current' ) !== false ? 'active' : ''; |
|
| 57 | - $links_html .= "<li class='page-item $active'>"; |
|
| 58 | - $links_html .= str_replace( "page-numbers", "page-link", $link ); |
|
| 59 | - $links_html .= "</li>"; |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - $links_html .= "</ul>"; |
|
| 63 | - |
|
| 64 | - if ( $links ) { |
|
| 65 | - $output .= '<section class="px-0 py-2 w-100">'; |
|
| 66 | - $output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] ); |
|
| 67 | - $output .= '</section>'; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output ); |
|
| 71 | - $output = str_replace( "nav-links", "aui-nav-links", $output ); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - if ( $output ) { |
|
| 75 | - if ( ! empty( $args['before_paging'] ) ) { |
|
| 76 | - $output = $args['before_paging'] . $output; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - if ( ! empty( $args['after_paging'] ) ) { |
|
| 80 | - $output = $output . $args['after_paging']; |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - return $output; |
|
| 85 | - } |
|
| 14 | + /** |
|
| 15 | + * Build the component. |
|
| 16 | + * |
|
| 17 | + * @param array $args |
|
| 18 | + * |
|
| 19 | + * @return string The rendered component. |
|
| 20 | + */ |
|
| 21 | + public static function get( $args = array() ) { |
|
| 22 | + global $wp_query; |
|
| 23 | + |
|
| 24 | + $defaults = array( |
|
| 25 | + 'class' => '', |
|
| 26 | + 'mid_size' => 2, |
|
| 27 | + 'prev_text' => '<i class="fas fa-chevron-left"></i>', |
|
| 28 | + 'next_text' => '<i class="fas fa-chevron-right"></i>', |
|
| 29 | + 'screen_reader_text' => __( 'Posts navigation','aui' ), |
|
| 30 | + 'before_paging' => '', |
|
| 31 | + 'after_paging' => '', |
|
| 32 | + 'type' => 'array', |
|
| 33 | + 'total' => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1, |
|
| 34 | + 'links' => array() // an array of links if using custom links, this includes the a tag. |
|
| 35 | + ); |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 39 | + */ |
|
| 40 | + $args = wp_parse_args( $args, $defaults ); |
|
| 41 | + |
|
| 42 | + $output = ''; |
|
| 43 | + |
|
| 44 | + // Don't print empty markup if there's only one page. |
|
| 45 | + if ( $args['total'] > 1 ) { |
|
| 46 | + |
|
| 47 | + // Set up paginated links. |
|
| 48 | + $links = !empty( $args['links'] ) ? $args['links'] : paginate_links( $args ); |
|
| 49 | + |
|
| 50 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
| 51 | + |
|
| 52 | + // make the output bootstrap ready |
|
| 53 | + $links_html = "<ul class='pagination m-0 p-0 $class'>"; |
|
| 54 | + if ( ! empty( $links ) ) { |
|
| 55 | + foreach ( $links as $link ) { |
|
| 56 | + $active = strpos( $link, 'current' ) !== false ? 'active' : ''; |
|
| 57 | + $links_html .= "<li class='page-item $active'>"; |
|
| 58 | + $links_html .= str_replace( "page-numbers", "page-link", $link ); |
|
| 59 | + $links_html .= "</li>"; |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + $links_html .= "</ul>"; |
|
| 63 | + |
|
| 64 | + if ( $links ) { |
|
| 65 | + $output .= '<section class="px-0 py-2 w-100">'; |
|
| 66 | + $output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] ); |
|
| 67 | + $output .= '</section>'; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output ); |
|
| 71 | + $output = str_replace( "nav-links", "aui-nav-links", $output ); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + if ( $output ) { |
|
| 75 | + if ( ! empty( $args['before_paging'] ) ) { |
|
| 76 | + $output = $args['before_paging'] . $output; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + if ( ! empty( $args['after_paging'] ) ) { |
|
| 80 | + $output = $output . $args['after_paging']; |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + return $output; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | 87 | } |
| 88 | 88 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | +if (!defined('ABSPATH')) { |
|
| 4 | 4 | exit; // Exit if accessed directly |
| 5 | 5 | } |
| 6 | 6 | |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * |
| 19 | 19 | * @return string The rendered component. |
| 20 | 20 | */ |
| 21 | - public static function get( $args = array() ) { |
|
| 21 | + public static function get($args = array()) { |
|
| 22 | 22 | global $wp_query; |
| 23 | 23 | |
| 24 | 24 | $defaults = array( |
@@ -26,57 +26,57 @@ discard block |
||
| 26 | 26 | 'mid_size' => 2, |
| 27 | 27 | 'prev_text' => '<i class="fas fa-chevron-left"></i>', |
| 28 | 28 | 'next_text' => '<i class="fas fa-chevron-right"></i>', |
| 29 | - 'screen_reader_text' => __( 'Posts navigation','aui' ), |
|
| 29 | + 'screen_reader_text' => __('Posts navigation', 'aui'), |
|
| 30 | 30 | 'before_paging' => '', |
| 31 | 31 | 'after_paging' => '', |
| 32 | 32 | 'type' => 'array', |
| 33 | - 'total' => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1, |
|
| 33 | + 'total' => isset($wp_query->max_num_pages) ? $wp_query->max_num_pages : 1, |
|
| 34 | 34 | 'links' => array() // an array of links if using custom links, this includes the a tag. |
| 35 | 35 | ); |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * Parse incoming $args into an array and merge it with $defaults |
| 39 | 39 | */ |
| 40 | - $args = wp_parse_args( $args, $defaults ); |
|
| 40 | + $args = wp_parse_args($args, $defaults); |
|
| 41 | 41 | |
| 42 | 42 | $output = ''; |
| 43 | 43 | |
| 44 | 44 | // Don't print empty markup if there's only one page. |
| 45 | - if ( $args['total'] > 1 ) { |
|
| 45 | + if ($args['total'] > 1) { |
|
| 46 | 46 | |
| 47 | 47 | // Set up paginated links. |
| 48 | - $links = !empty( $args['links'] ) ? $args['links'] : paginate_links( $args ); |
|
| 48 | + $links = !empty($args['links']) ? $args['links'] : paginate_links($args); |
|
| 49 | 49 | |
| 50 | 50 | $class = !empty($args['class']) ? $args['class'] : ''; |
| 51 | 51 | |
| 52 | 52 | // make the output bootstrap ready |
| 53 | 53 | $links_html = "<ul class='pagination m-0 p-0 $class'>"; |
| 54 | - if ( ! empty( $links ) ) { |
|
| 55 | - foreach ( $links as $link ) { |
|
| 56 | - $active = strpos( $link, 'current' ) !== false ? 'active' : ''; |
|
| 54 | + if (!empty($links)) { |
|
| 55 | + foreach ($links as $link) { |
|
| 56 | + $active = strpos($link, 'current') !== false ? 'active' : ''; |
|
| 57 | 57 | $links_html .= "<li class='page-item $active'>"; |
| 58 | - $links_html .= str_replace( "page-numbers", "page-link", $link ); |
|
| 58 | + $links_html .= str_replace("page-numbers", "page-link", $link); |
|
| 59 | 59 | $links_html .= "</li>"; |
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | $links_html .= "</ul>"; |
| 63 | 63 | |
| 64 | - if ( $links ) { |
|
| 64 | + if ($links) { |
|
| 65 | 65 | $output .= '<section class="px-0 py-2 w-100">'; |
| 66 | - $output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] ); |
|
| 66 | + $output .= _navigation_markup($links_html, 'aui-pagination', $args['screen_reader_text']); |
|
| 67 | 67 | $output .= '</section>'; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - $output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output ); |
|
| 71 | - $output = str_replace( "nav-links", "aui-nav-links", $output ); |
|
| 70 | + $output = str_replace("screen-reader-text", "screen-reader-text sr-only", $output); |
|
| 71 | + $output = str_replace("nav-links", "aui-nav-links", $output); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - if ( $output ) { |
|
| 75 | - if ( ! empty( $args['before_paging'] ) ) { |
|
| 74 | + if ($output) { |
|
| 75 | + if (!empty($args['before_paging'])) { |
|
| 76 | 76 | $output = $args['before_paging'] . $output; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - if ( ! empty( $args['after_paging'] ) ) { |
|
| 79 | + if (!empty($args['after_paging'])) { |
|
| 80 | 80 | $output = $output . $args['after_paging']; |
| 81 | 81 | } |
| 82 | 82 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | +if (!defined('ABSPATH')) { |
|
| 4 | 4 | exit; // Exit if accessed directly |
| 5 | 5 | } |
| 6 | 6 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | * @return AUI|null |
| 36 | 36 | */ |
| 37 | 37 | public static function instance() { |
| 38 | - if ( self::$instance == null ) { |
|
| 38 | + if (self::$instance == null) { |
|
| 39 | 39 | self::$instance = new AUI(); |
| 40 | 40 | } |
| 41 | 41 | |
@@ -48,10 +48,10 @@ discard block |
||
| 48 | 48 | * @since 1.0.0 |
| 49 | 49 | */ |
| 50 | 50 | private function __construct() { |
| 51 | - if ( function_exists( "__autoload" ) ) { |
|
| 52 | - spl_autoload_register( "__autoload" ); |
|
| 51 | + if (function_exists("__autoload")) { |
|
| 52 | + spl_autoload_register("__autoload"); |
|
| 53 | 53 | } |
| 54 | - spl_autoload_register( array( $this, 'autoload' ) ); |
|
| 54 | + spl_autoload_register(array($this, 'autoload')); |
|
| 55 | 55 | |
| 56 | 56 | // load options |
| 57 | 57 | self::$options = get_option('aui_options'); |
@@ -64,11 +64,11 @@ discard block |
||
| 64 | 64 | * |
| 65 | 65 | * @param $classname |
| 66 | 66 | */ |
| 67 | - private function autoload( $classname ) { |
|
| 68 | - $class = str_replace( '_', '-', strtolower( $classname ) ); |
|
| 69 | - $file_path = trailingslashit( dirname( __FILE__ ) ) . "components/class-" . $class . '.php'; |
|
| 70 | - if ( $file_path && is_readable( $file_path ) ) { |
|
| 71 | - include_once( $file_path ); |
|
| 67 | + private function autoload($classname) { |
|
| 68 | + $class = str_replace('_', '-', strtolower($classname)); |
|
| 69 | + $file_path = trailingslashit(dirname(__FILE__)) . "components/class-" . $class . '.php'; |
|
| 70 | + if ($file_path && is_readable($file_path)) { |
|
| 71 | + include_once($file_path); |
|
| 72 | 72 | } |
| 73 | 73 | } |
| 74 | 74 | |
@@ -79,27 +79,27 @@ discard block |
||
| 79 | 79 | * |
| 80 | 80 | * @return string|void |
| 81 | 81 | */ |
| 82 | - public function get_option( $option ){ |
|
| 82 | + public function get_option($option) { |
|
| 83 | 83 | $result = isset(self::$options[$option]) ? esc_attr(self::$options[$option]) : ''; |
| 84 | 84 | |
| 85 | - if ( ! $result && $option) { |
|
| 86 | - if( $option == 'color_primary' ){ |
|
| 85 | + if (!$result && $option) { |
|
| 86 | + if ($option == 'color_primary') { |
|
| 87 | 87 | $result = AUI_PRIMARY_COLOR; |
| 88 | - }elseif( $option == 'color_secondary' ){ |
|
| 88 | + }elseif ($option == 'color_secondary') { |
|
| 89 | 89 | $result = AUI_SECONDARY_COLOR; |
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | return $result; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - public function render( $items = array() ) { |
|
| 95 | + public function render($items = array()) { |
|
| 96 | 96 | $output = ''; |
| 97 | 97 | |
| 98 | - if ( ! empty( $items ) ) { |
|
| 99 | - foreach ( $items as $args ) { |
|
| 100 | - $render = isset( $args['render'] ) ? $args['render'] : ''; |
|
| 101 | - if ( $render && method_exists( __CLASS__, $render ) ) { |
|
| 102 | - $output .= $this->$render( $args ); |
|
| 98 | + if (!empty($items)) { |
|
| 99 | + foreach ($items as $args) { |
|
| 100 | + $render = isset($args['render']) ? $args['render'] : ''; |
|
| 101 | + if ($render && method_exists(__CLASS__, $render)) { |
|
| 102 | + $output .= $this->$render($args); |
|
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | } |
@@ -116,8 +116,8 @@ discard block |
||
| 116 | 116 | * |
| 117 | 117 | * @return string The rendered component. |
| 118 | 118 | */ |
| 119 | - public function alert( $args = array() ) { |
|
| 120 | - return AUI_Component_Alert::get( $args ); |
|
| 119 | + public function alert($args = array()) { |
|
| 120 | + return AUI_Component_Alert::get($args); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -129,8 +129,8 @@ discard block |
||
| 129 | 129 | * |
| 130 | 130 | * @return string The rendered component. |
| 131 | 131 | */ |
| 132 | - public function input( $args = array() ) { |
|
| 133 | - return AUI_Component_Input::input( $args ); |
|
| 132 | + public function input($args = array()) { |
|
| 133 | + return AUI_Component_Input::input($args); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -142,8 +142,8 @@ discard block |
||
| 142 | 142 | * |
| 143 | 143 | * @return string The rendered component. |
| 144 | 144 | */ |
| 145 | - public function textarea( $args = array() ) { |
|
| 146 | - return AUI_Component_Input::textarea( $args ); |
|
| 145 | + public function textarea($args = array()) { |
|
| 146 | + return AUI_Component_Input::textarea($args); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -155,8 +155,8 @@ discard block |
||
| 155 | 155 | * |
| 156 | 156 | * @return string The rendered component. |
| 157 | 157 | */ |
| 158 | - public function button( $args = array() ) { |
|
| 159 | - return AUI_Component_Button::get( $args ); |
|
| 158 | + public function button($args = array()) { |
|
| 159 | + return AUI_Component_Button::get($args); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /** |
@@ -168,22 +168,22 @@ discard block |
||
| 168 | 168 | * |
| 169 | 169 | * @return string The rendered component. |
| 170 | 170 | */ |
| 171 | - public function badge( $args = array() ) { |
|
| 171 | + public function badge($args = array()) { |
|
| 172 | 172 | $defaults = array( |
| 173 | 173 | 'class' => 'badge badge-primary align-middle', |
| 174 | 174 | ); |
| 175 | 175 | |
| 176 | 176 | // maybe set type |
| 177 | - if ( empty( $args['href'] ) ) { |
|
| 177 | + if (empty($args['href'])) { |
|
| 178 | 178 | $defaults['type'] = 'badge'; |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
| 182 | 182 | * Parse incoming $args into an array and merge it with $defaults |
| 183 | 183 | */ |
| 184 | - $args = wp_parse_args( $args, $defaults ); |
|
| 184 | + $args = wp_parse_args($args, $defaults); |
|
| 185 | 185 | |
| 186 | - return AUI_Component_Button::get( $args ); |
|
| 186 | + return AUI_Component_Button::get($args); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | /** |
@@ -195,8 +195,8 @@ discard block |
||
| 195 | 195 | * |
| 196 | 196 | * @return string The rendered component. |
| 197 | 197 | */ |
| 198 | - public function dropdown( $args = array() ) { |
|
| 199 | - return AUI_Component_Dropdown::get( $args ); |
|
| 198 | + public function dropdown($args = array()) { |
|
| 199 | + return AUI_Component_Dropdown::get($args); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -208,8 +208,8 @@ discard block |
||
| 208 | 208 | * |
| 209 | 209 | * @return string The rendered component. |
| 210 | 210 | */ |
| 211 | - public function select( $args = array() ) { |
|
| 212 | - return AUI_Component_Input::select( $args ); |
|
| 211 | + public function select($args = array()) { |
|
| 212 | + return AUI_Component_Input::select($args); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -221,8 +221,8 @@ discard block |
||
| 221 | 221 | * |
| 222 | 222 | * @return string The rendered component. |
| 223 | 223 | */ |
| 224 | - public function radio( $args = array() ) { |
|
| 225 | - return AUI_Component_Input::radio( $args ); |
|
| 224 | + public function radio($args = array()) { |
|
| 225 | + return AUI_Component_Input::radio($args); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -234,8 +234,8 @@ discard block |
||
| 234 | 234 | * |
| 235 | 235 | * @return string The rendered component. |
| 236 | 236 | */ |
| 237 | - public function pagination( $args = array() ) { |
|
| 238 | - return AUI_Component_Pagination::get( $args ); |
|
| 237 | + public function pagination($args = array()) { |
|
| 238 | + return AUI_Component_Pagination::get($args); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | } |
| 242 | 242 | \ No newline at end of file |
@@ -85,7 +85,7 @@ |
||
| 85 | 85 | if ( ! $result && $option) { |
| 86 | 86 | if( $option == 'color_primary' ){ |
| 87 | 87 | $result = AUI_PRIMARY_COLOR; |
| 88 | - }elseif( $option == 'color_secondary' ){ |
|
| 88 | + } elseif( $option == 'color_secondary' ){ |
|
| 89 | 89 | $result = AUI_SECONDARY_COLOR; |
| 90 | 90 | } |
| 91 | 91 | } |
@@ -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,231 +11,231 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | class AUI { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Holds the class instance. |
|
| 16 | - * |
|
| 17 | - * @since 1.0.0 |
|
| 18 | - * @var null |
|
| 19 | - */ |
|
| 20 | - private static $instance = null; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Holds the current AUI version number. |
|
| 24 | - * |
|
| 25 | - * @var string $ver The current version number. |
|
| 26 | - */ |
|
| 27 | - public static $ver = '0.1.35'; |
|
| 28 | - |
|
| 29 | - public static $options = null; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * There can be only one. |
|
| 33 | - * |
|
| 34 | - * @since 1.0.0 |
|
| 35 | - * @return AUI|null |
|
| 36 | - */ |
|
| 37 | - public static function instance() { |
|
| 38 | - if ( self::$instance == null ) { |
|
| 39 | - self::$instance = new AUI(); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - return self::$instance; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * AUI constructor. |
|
| 47 | - * |
|
| 48 | - * @since 1.0.0 |
|
| 49 | - */ |
|
| 50 | - private function __construct() { |
|
| 51 | - if ( function_exists( "__autoload" ) ) { |
|
| 52 | - spl_autoload_register( "__autoload" ); |
|
| 53 | - } |
|
| 54 | - spl_autoload_register( array( $this, 'autoload' ) ); |
|
| 55 | - |
|
| 56 | - // load options |
|
| 57 | - self::$options = get_option('aui_options'); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Autoload any components on the fly. |
|
| 62 | - * |
|
| 63 | - * @since 1.0.0 |
|
| 64 | - * |
|
| 65 | - * @param $classname |
|
| 66 | - */ |
|
| 67 | - private function autoload( $classname ) { |
|
| 68 | - $class = str_replace( '_', '-', strtolower( $classname ) ); |
|
| 69 | - $file_path = trailingslashit( dirname( __FILE__ ) ) . "components/class-" . $class . '.php'; |
|
| 70 | - if ( $file_path && is_readable( $file_path ) ) { |
|
| 71 | - include_once( $file_path ); |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Get the AUI options. |
|
| 77 | - * |
|
| 78 | - * @param $option |
|
| 79 | - * |
|
| 80 | - * @return string|void |
|
| 81 | - */ |
|
| 82 | - public function get_option( $option ){ |
|
| 83 | - $result = isset(self::$options[$option]) ? esc_attr(self::$options[$option]) : ''; |
|
| 84 | - |
|
| 85 | - if ( ! $result && $option) { |
|
| 86 | - if( $option == 'color_primary' ){ |
|
| 87 | - $result = AUI_PRIMARY_COLOR; |
|
| 88 | - }elseif( $option == 'color_secondary' ){ |
|
| 89 | - $result = AUI_SECONDARY_COLOR; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - return $result; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - public function render( $items = array() ) { |
|
| 96 | - $output = ''; |
|
| 97 | - |
|
| 98 | - if ( ! empty( $items ) ) { |
|
| 99 | - foreach ( $items as $args ) { |
|
| 100 | - $render = isset( $args['render'] ) ? $args['render'] : ''; |
|
| 101 | - if ( $render && method_exists( __CLASS__, $render ) ) { |
|
| 102 | - $output .= $this->$render( $args ); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - return $output; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Render and return a bootstrap alert component. |
|
| 112 | - * |
|
| 113 | - * @since 1.0.0 |
|
| 114 | - * |
|
| 115 | - * @param array $args |
|
| 116 | - * |
|
| 117 | - * @return string The rendered component. |
|
| 118 | - */ |
|
| 119 | - public function alert( $args = array() ) { |
|
| 120 | - return AUI_Component_Alert::get( $args ); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Render and return a bootstrap input component. |
|
| 125 | - * |
|
| 126 | - * @since 1.0.0 |
|
| 127 | - * |
|
| 128 | - * @param array $args |
|
| 129 | - * |
|
| 130 | - * @return string The rendered component. |
|
| 131 | - */ |
|
| 132 | - public function input( $args = array() ) { |
|
| 133 | - return AUI_Component_Input::input( $args ); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Render and return a bootstrap textarea component. |
|
| 138 | - * |
|
| 139 | - * @since 1.0.0 |
|
| 140 | - * |
|
| 141 | - * @param array $args |
|
| 142 | - * |
|
| 143 | - * @return string The rendered component. |
|
| 144 | - */ |
|
| 145 | - public function textarea( $args = array() ) { |
|
| 146 | - return AUI_Component_Input::textarea( $args ); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Render and return a bootstrap button component. |
|
| 151 | - * |
|
| 152 | - * @since 1.0.0 |
|
| 153 | - * |
|
| 154 | - * @param array $args |
|
| 155 | - * |
|
| 156 | - * @return string The rendered component. |
|
| 157 | - */ |
|
| 158 | - public function button( $args = array() ) { |
|
| 159 | - return AUI_Component_Button::get( $args ); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Render and return a bootstrap button component. |
|
| 164 | - * |
|
| 165 | - * @since 1.0.0 |
|
| 166 | - * |
|
| 167 | - * @param array $args |
|
| 168 | - * |
|
| 169 | - * @return string The rendered component. |
|
| 170 | - */ |
|
| 171 | - public function badge( $args = array() ) { |
|
| 172 | - $defaults = array( |
|
| 173 | - 'class' => 'badge badge-primary align-middle', |
|
| 174 | - ); |
|
| 175 | - |
|
| 176 | - // maybe set type |
|
| 177 | - if ( empty( $args['href'] ) ) { |
|
| 178 | - $defaults['type'] = 'badge'; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Parse incoming $args into an array and merge it with $defaults |
|
| 183 | - */ |
|
| 184 | - $args = wp_parse_args( $args, $defaults ); |
|
| 185 | - |
|
| 186 | - return AUI_Component_Button::get( $args ); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Render and return a bootstrap dropdown component. |
|
| 191 | - * |
|
| 192 | - * @since 1.0.0 |
|
| 193 | - * |
|
| 194 | - * @param array $args |
|
| 195 | - * |
|
| 196 | - * @return string The rendered component. |
|
| 197 | - */ |
|
| 198 | - public function dropdown( $args = array() ) { |
|
| 199 | - return AUI_Component_Dropdown::get( $args ); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Render and return a bootstrap select component. |
|
| 204 | - * |
|
| 205 | - * @since 1.0.0 |
|
| 206 | - * |
|
| 207 | - * @param array $args |
|
| 208 | - * |
|
| 209 | - * @return string The rendered component. |
|
| 210 | - */ |
|
| 211 | - public function select( $args = array() ) { |
|
| 212 | - return AUI_Component_Input::select( $args ); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Render and return a bootstrap radio component. |
|
| 217 | - * |
|
| 218 | - * @since 1.0.0 |
|
| 219 | - * |
|
| 220 | - * @param array $args |
|
| 221 | - * |
|
| 222 | - * @return string The rendered component. |
|
| 223 | - */ |
|
| 224 | - public function radio( $args = array() ) { |
|
| 225 | - return AUI_Component_Input::radio( $args ); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Render and return a bootstrap pagination component. |
|
| 230 | - * |
|
| 231 | - * @since 1.0.0 |
|
| 232 | - * |
|
| 233 | - * @param array $args |
|
| 234 | - * |
|
| 235 | - * @return string The rendered component. |
|
| 236 | - */ |
|
| 237 | - public function pagination( $args = array() ) { |
|
| 238 | - return AUI_Component_Pagination::get( $args ); |
|
| 239 | - } |
|
| 14 | + /** |
|
| 15 | + * Holds the class instance. |
|
| 16 | + * |
|
| 17 | + * @since 1.0.0 |
|
| 18 | + * @var null |
|
| 19 | + */ |
|
| 20 | + private static $instance = null; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Holds the current AUI version number. |
|
| 24 | + * |
|
| 25 | + * @var string $ver The current version number. |
|
| 26 | + */ |
|
| 27 | + public static $ver = '0.1.35'; |
|
| 28 | + |
|
| 29 | + public static $options = null; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * There can be only one. |
|
| 33 | + * |
|
| 34 | + * @since 1.0.0 |
|
| 35 | + * @return AUI|null |
|
| 36 | + */ |
|
| 37 | + public static function instance() { |
|
| 38 | + if ( self::$instance == null ) { |
|
| 39 | + self::$instance = new AUI(); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + return self::$instance; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * AUI constructor. |
|
| 47 | + * |
|
| 48 | + * @since 1.0.0 |
|
| 49 | + */ |
|
| 50 | + private function __construct() { |
|
| 51 | + if ( function_exists( "__autoload" ) ) { |
|
| 52 | + spl_autoload_register( "__autoload" ); |
|
| 53 | + } |
|
| 54 | + spl_autoload_register( array( $this, 'autoload' ) ); |
|
| 55 | + |
|
| 56 | + // load options |
|
| 57 | + self::$options = get_option('aui_options'); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Autoload any components on the fly. |
|
| 62 | + * |
|
| 63 | + * @since 1.0.0 |
|
| 64 | + * |
|
| 65 | + * @param $classname |
|
| 66 | + */ |
|
| 67 | + private function autoload( $classname ) { |
|
| 68 | + $class = str_replace( '_', '-', strtolower( $classname ) ); |
|
| 69 | + $file_path = trailingslashit( dirname( __FILE__ ) ) . "components/class-" . $class . '.php'; |
|
| 70 | + if ( $file_path && is_readable( $file_path ) ) { |
|
| 71 | + include_once( $file_path ); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Get the AUI options. |
|
| 77 | + * |
|
| 78 | + * @param $option |
|
| 79 | + * |
|
| 80 | + * @return string|void |
|
| 81 | + */ |
|
| 82 | + public function get_option( $option ){ |
|
| 83 | + $result = isset(self::$options[$option]) ? esc_attr(self::$options[$option]) : ''; |
|
| 84 | + |
|
| 85 | + if ( ! $result && $option) { |
|
| 86 | + if( $option == 'color_primary' ){ |
|
| 87 | + $result = AUI_PRIMARY_COLOR; |
|
| 88 | + }elseif( $option == 'color_secondary' ){ |
|
| 89 | + $result = AUI_SECONDARY_COLOR; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + return $result; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + public function render( $items = array() ) { |
|
| 96 | + $output = ''; |
|
| 97 | + |
|
| 98 | + if ( ! empty( $items ) ) { |
|
| 99 | + foreach ( $items as $args ) { |
|
| 100 | + $render = isset( $args['render'] ) ? $args['render'] : ''; |
|
| 101 | + if ( $render && method_exists( __CLASS__, $render ) ) { |
|
| 102 | + $output .= $this->$render( $args ); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + return $output; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Render and return a bootstrap alert component. |
|
| 112 | + * |
|
| 113 | + * @since 1.0.0 |
|
| 114 | + * |
|
| 115 | + * @param array $args |
|
| 116 | + * |
|
| 117 | + * @return string The rendered component. |
|
| 118 | + */ |
|
| 119 | + public function alert( $args = array() ) { |
|
| 120 | + return AUI_Component_Alert::get( $args ); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Render and return a bootstrap input component. |
|
| 125 | + * |
|
| 126 | + * @since 1.0.0 |
|
| 127 | + * |
|
| 128 | + * @param array $args |
|
| 129 | + * |
|
| 130 | + * @return string The rendered component. |
|
| 131 | + */ |
|
| 132 | + public function input( $args = array() ) { |
|
| 133 | + return AUI_Component_Input::input( $args ); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Render and return a bootstrap textarea component. |
|
| 138 | + * |
|
| 139 | + * @since 1.0.0 |
|
| 140 | + * |
|
| 141 | + * @param array $args |
|
| 142 | + * |
|
| 143 | + * @return string The rendered component. |
|
| 144 | + */ |
|
| 145 | + public function textarea( $args = array() ) { |
|
| 146 | + return AUI_Component_Input::textarea( $args ); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Render and return a bootstrap button component. |
|
| 151 | + * |
|
| 152 | + * @since 1.0.0 |
|
| 153 | + * |
|
| 154 | + * @param array $args |
|
| 155 | + * |
|
| 156 | + * @return string The rendered component. |
|
| 157 | + */ |
|
| 158 | + public function button( $args = array() ) { |
|
| 159 | + return AUI_Component_Button::get( $args ); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Render and return a bootstrap button component. |
|
| 164 | + * |
|
| 165 | + * @since 1.0.0 |
|
| 166 | + * |
|
| 167 | + * @param array $args |
|
| 168 | + * |
|
| 169 | + * @return string The rendered component. |
|
| 170 | + */ |
|
| 171 | + public function badge( $args = array() ) { |
|
| 172 | + $defaults = array( |
|
| 173 | + 'class' => 'badge badge-primary align-middle', |
|
| 174 | + ); |
|
| 175 | + |
|
| 176 | + // maybe set type |
|
| 177 | + if ( empty( $args['href'] ) ) { |
|
| 178 | + $defaults['type'] = 'badge'; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Parse incoming $args into an array and merge it with $defaults |
|
| 183 | + */ |
|
| 184 | + $args = wp_parse_args( $args, $defaults ); |
|
| 185 | + |
|
| 186 | + return AUI_Component_Button::get( $args ); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Render and return a bootstrap dropdown component. |
|
| 191 | + * |
|
| 192 | + * @since 1.0.0 |
|
| 193 | + * |
|
| 194 | + * @param array $args |
|
| 195 | + * |
|
| 196 | + * @return string The rendered component. |
|
| 197 | + */ |
|
| 198 | + public function dropdown( $args = array() ) { |
|
| 199 | + return AUI_Component_Dropdown::get( $args ); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Render and return a bootstrap select component. |
|
| 204 | + * |
|
| 205 | + * @since 1.0.0 |
|
| 206 | + * |
|
| 207 | + * @param array $args |
|
| 208 | + * |
|
| 209 | + * @return string The rendered component. |
|
| 210 | + */ |
|
| 211 | + public function select( $args = array() ) { |
|
| 212 | + return AUI_Component_Input::select( $args ); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Render and return a bootstrap radio component. |
|
| 217 | + * |
|
| 218 | + * @since 1.0.0 |
|
| 219 | + * |
|
| 220 | + * @param array $args |
|
| 221 | + * |
|
| 222 | + * @return string The rendered component. |
|
| 223 | + */ |
|
| 224 | + public function radio( $args = array() ) { |
|
| 225 | + return AUI_Component_Input::radio( $args ); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Render and return a bootstrap pagination component. |
|
| 230 | + * |
|
| 231 | + * @since 1.0.0 |
|
| 232 | + * |
|
| 233 | + * @param array $args |
|
| 234 | + * |
|
| 235 | + * @return string The rendered component. |
|
| 236 | + */ |
|
| 237 | + public function pagination( $args = array() ) { |
|
| 238 | + return AUI_Component_Pagination::get( $args ); |
|
| 239 | + } |
|
| 240 | 240 | |
| 241 | 241 | } |
| 242 | 242 | \ No newline at end of file |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | function wpinv_subscriptions_page() { |
| 16 | 16 | |
| 17 | - ?> |
|
| 17 | + ?> |
|
| 18 | 18 | |
| 19 | 19 | <div class="wrap"> |
| 20 | 20 | <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
@@ -22,27 +22,27 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | <?php |
| 24 | 24 | |
| 25 | - // Verify user permissions. |
|
| 26 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 25 | + // Verify user permissions. |
|
| 26 | + if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 27 | 27 | |
| 28 | - echo aui()->alert( |
|
| 29 | - array( |
|
| 30 | - 'type' => 'danger', |
|
| 31 | - 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
| 32 | - ) |
|
| 33 | - ); |
|
| 28 | + echo aui()->alert( |
|
| 29 | + array( |
|
| 30 | + 'type' => 'danger', |
|
| 31 | + 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
| 32 | + ) |
|
| 33 | + ); |
|
| 34 | 34 | |
| 35 | - } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
| 35 | + } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
| 36 | 36 | |
| 37 | - // Display a single subscription. |
|
| 38 | - wpinv_recurring_subscription_details(); |
|
| 39 | - } else { |
|
| 37 | + // Display a single subscription. |
|
| 38 | + wpinv_recurring_subscription_details(); |
|
| 39 | + } else { |
|
| 40 | 40 | |
| 41 | - // Display a list of available subscriptions. |
|
| 42 | - getpaid_print_subscriptions_list(); |
|
| 43 | - } |
|
| 41 | + // Display a list of available subscriptions. |
|
| 42 | + getpaid_print_subscriptions_list(); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - ?> |
|
| 45 | + ?> |
|
| 46 | 46 | |
| 47 | 47 | </div> |
| 48 | 48 | </div> |
@@ -59,10 +59,10 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | function getpaid_print_subscriptions_list() { |
| 61 | 61 | |
| 62 | - $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
| 63 | - $subscribers_table->prepare_items(); |
|
| 62 | + $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
| 63 | + $subscribers_table->prepare_items(); |
|
| 64 | 64 | |
| 65 | - ?> |
|
| 65 | + ?> |
|
| 66 | 66 | <form id="subscribers-filter" class="bsui" method="get"> |
| 67 | 67 | <input type="hidden" name="page" value="wpinv-subscriptions" /> |
| 68 | 68 | <?php $subscribers_table->views(); ?> |
@@ -80,27 +80,27 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | function wpinv_recurring_subscription_details() { |
| 82 | 82 | |
| 83 | - // Fetch the subscription. |
|
| 84 | - $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
| 85 | - if ( ! $sub->get_id() ) { |
|
| 83 | + // Fetch the subscription. |
|
| 84 | + $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
| 85 | + if ( ! $sub->get_id() ) { |
|
| 86 | 86 | |
| 87 | - echo aui()->alert( |
|
| 88 | - array( |
|
| 89 | - 'type' => 'danger', |
|
| 90 | - 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
| 91 | - ) |
|
| 92 | - ); |
|
| 87 | + echo aui()->alert( |
|
| 88 | + array( |
|
| 89 | + 'type' => 'danger', |
|
| 90 | + 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
| 91 | + ) |
|
| 92 | + ); |
|
| 93 | 93 | |
| 94 | - return; |
|
| 95 | - } |
|
| 94 | + return; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - // Use metaboxes to display the subscription details. |
|
| 98 | - add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' ); |
|
| 99 | - add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
| 100 | - add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
| 101 | - do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
| 97 | + // Use metaboxes to display the subscription details. |
|
| 98 | + add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' ); |
|
| 99 | + add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
| 100 | + add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
| 101 | + do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
| 102 | 102 | |
| 103 | - ?> |
|
| 103 | + ?> |
|
| 104 | 104 | |
| 105 | 105 | <form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>"> |
| 106 | 106 | |
@@ -140,41 +140,41 @@ discard block |
||
| 140 | 140 | */ |
| 141 | 141 | function getpaid_admin_subscription_details_metabox( $sub ) { |
| 142 | 142 | |
| 143 | - // Prepare subscription detail columns. |
|
| 144 | - $fields = apply_filters( |
|
| 145 | - 'getpaid_subscription_admin_page_fields', |
|
| 146 | - array( |
|
| 147 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 148 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
| 149 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 150 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 151 | - 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
| 152 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 153 | - 'item' => __( 'Item', 'invoicing' ), |
|
| 154 | - 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
| 155 | - 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
| 156 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 157 | - ) |
|
| 158 | - ); |
|
| 159 | - |
|
| 160 | - if ( ! $sub->is_active() ) { |
|
| 161 | - |
|
| 162 | - if ( isset( $fields['renews_on'] ) ) { |
|
| 163 | - unset( $fields['renews_on'] ); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - if ( isset( $fields['gateway'] ) ) { |
|
| 167 | - unset( $fields['gateway'] ); |
|
| 168 | - } |
|
| 143 | + // Prepare subscription detail columns. |
|
| 144 | + $fields = apply_filters( |
|
| 145 | + 'getpaid_subscription_admin_page_fields', |
|
| 146 | + array( |
|
| 147 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 148 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
| 149 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
| 150 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 151 | + 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
| 152 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 153 | + 'item' => __( 'Item', 'invoicing' ), |
|
| 154 | + 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
| 155 | + 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
| 156 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 157 | + ) |
|
| 158 | + ); |
|
| 159 | + |
|
| 160 | + if ( ! $sub->is_active() ) { |
|
| 161 | + |
|
| 162 | + if ( isset( $fields['renews_on'] ) ) { |
|
| 163 | + unset( $fields['renews_on'] ); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + if ( isset( $fields['gateway'] ) ) { |
|
| 167 | + unset( $fields['gateway'] ); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - } |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - $profile_id = $sub->get_profile_id(); |
|
| 173 | - if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
| 174 | - unset( $fields['profile_id'] ); |
|
| 175 | - } |
|
| 172 | + $profile_id = $sub->get_profile_id(); |
|
| 173 | + if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
| 174 | + unset( $fields['profile_id'] ); |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - ?> |
|
| 177 | + ?> |
|
| 178 | 178 | |
| 179 | 179 | <table class="table table-borderless" style="font-size: 14px;"> |
| 180 | 180 | <tbody> |
@@ -208,20 +208,20 @@ discard block |
||
| 208 | 208 | */ |
| 209 | 209 | function getpaid_admin_subscription_metabox_display_customer( $subscription ) { |
| 210 | 210 | |
| 211 | - $username = __( '(Missing User)', 'invoicing' ); |
|
| 211 | + $username = __( '(Missing User)', 'invoicing' ); |
|
| 212 | 212 | |
| 213 | - $user = get_userdata( $subscription->get_customer_id() ); |
|
| 214 | - if ( $user ) { |
|
| 213 | + $user = get_userdata( $subscription->get_customer_id() ); |
|
| 214 | + if ( $user ) { |
|
| 215 | 215 | |
| 216 | - $username = sprintf( |
|
| 217 | - '<a href="user-edit.php?user_id=%s">%s</a>', |
|
| 218 | - absint( $user->ID ), |
|
| 219 | - ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 220 | - ); |
|
| 216 | + $username = sprintf( |
|
| 217 | + '<a href="user-edit.php?user_id=%s">%s</a>', |
|
| 218 | + absint( $user->ID ), |
|
| 219 | + ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 220 | + ); |
|
| 221 | 221 | |
| 222 | - } |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - echo $username; |
|
| 224 | + echo $username; |
|
| 225 | 225 | } |
| 226 | 226 | add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' ); |
| 227 | 227 | |
@@ -231,8 +231,8 @@ discard block |
||
| 231 | 231 | * @param WPInv_Subscription $subscription |
| 232 | 232 | */ |
| 233 | 233 | function getpaid_admin_subscription_metabox_display_amount( $subscription ) { |
| 234 | - $amount = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) ); |
|
| 235 | - echo "<span>$amount</span>"; |
|
| 234 | + $amount = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) ); |
|
| 235 | + echo "<span>$amount</span>"; |
|
| 236 | 236 | } |
| 237 | 237 | add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' ); |
| 238 | 238 | |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | * @param WPInv_Subscription $subscription |
| 243 | 243 | */ |
| 244 | 244 | function getpaid_admin_subscription_metabox_display_id( $subscription ) { |
| 245 | - echo '#' . absint( $subscription->get_id() ); |
|
| 245 | + echo '#' . absint( $subscription->get_id() ); |
|
| 246 | 246 | } |
| 247 | 247 | add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' ); |
| 248 | 248 | |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | * @param WPInv_Subscription $subscription |
| 253 | 253 | */ |
| 254 | 254 | function getpaid_admin_subscription_metabox_display_start_date( $subscription ) { |
| 255 | - echo getpaid_format_date_value( $subscription->get_date_created() ); |
|
| 255 | + echo getpaid_format_date_value( $subscription->get_date_created() ); |
|
| 256 | 256 | } |
| 257 | 257 | add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' ); |
| 258 | 258 | |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | * @param WPInv_Subscription $subscription |
| 263 | 263 | */ |
| 264 | 264 | function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) { |
| 265 | - echo getpaid_format_date_value( $subscription->get_expiration() ); |
|
| 265 | + echo getpaid_format_date_value( $subscription->get_expiration() ); |
|
| 266 | 266 | } |
| 267 | 267 | add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' ); |
| 268 | 268 | |
@@ -272,8 +272,8 @@ discard block |
||
| 272 | 272 | * @param WPInv_Subscription $subscription |
| 273 | 273 | */ |
| 274 | 274 | function getpaid_admin_subscription_metabox_display_renewals( $subscription ) { |
| 275 | - $max_bills = $subscription->get_bill_times(); |
|
| 276 | - echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
| 275 | + $max_bills = $subscription->get_bill_times(); |
|
| 276 | + echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
| 277 | 277 | } |
| 278 | 278 | add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' ); |
| 279 | 279 | /** |
@@ -283,16 +283,16 @@ discard block |
||
| 283 | 283 | */ |
| 284 | 284 | function getpaid_admin_subscription_metabox_display_item( $subscription ) { |
| 285 | 285 | |
| 286 | - $item = get_post( $subscription->get_product_id() ); |
|
| 286 | + $item = get_post( $subscription->get_product_id() ); |
|
| 287 | 287 | |
| 288 | - if ( ! empty( $item ) ) { |
|
| 289 | - $link = get_edit_post_link( $item ); |
|
| 290 | - $link = esc_url( $link ); |
|
| 291 | - $name = esc_html( get_the_title( $item ) ); |
|
| 292 | - echo "<a href='$link'>$name</a>"; |
|
| 293 | - } else { |
|
| 294 | - echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
| 295 | - } |
|
| 288 | + if ( ! empty( $item ) ) { |
|
| 289 | + $link = get_edit_post_link( $item ); |
|
| 290 | + $link = esc_url( $link ); |
|
| 291 | + $name = esc_html( get_the_title( $item ) ); |
|
| 292 | + echo "<a href='$link'>$name</a>"; |
|
| 293 | + } else { |
|
| 294 | + echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | 297 | } |
| 298 | 298 | add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item' ); |
@@ -304,13 +304,13 @@ discard block |
||
| 304 | 304 | */ |
| 305 | 305 | function getpaid_admin_subscription_metabox_display_gateway( $subscription ) { |
| 306 | 306 | |
| 307 | - $gateway = $subscription->get_gateway(); |
|
| 307 | + $gateway = $subscription->get_gateway(); |
|
| 308 | 308 | |
| 309 | - if ( ! empty( $gateway ) ) { |
|
| 310 | - echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) ); |
|
| 311 | - } else { |
|
| 312 | - echo "—"; |
|
| 313 | - } |
|
| 309 | + if ( ! empty( $gateway ) ) { |
|
| 310 | + echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) ); |
|
| 311 | + } else { |
|
| 312 | + echo "—"; |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | 315 | } |
| 316 | 316 | add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' ); |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | * @param WPInv_Subscription $subscription |
| 322 | 322 | */ |
| 323 | 323 | function getpaid_admin_subscription_metabox_display_status( $subscription ) { |
| 324 | - echo $subscription->get_status_label_html(); |
|
| 324 | + echo $subscription->get_status_label_html(); |
|
| 325 | 325 | } |
| 326 | 326 | add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' ); |
| 327 | 327 | |
@@ -332,14 +332,14 @@ discard block |
||
| 332 | 332 | */ |
| 333 | 333 | function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) { |
| 334 | 334 | |
| 335 | - $profile_id = $subscription->get_profile_id(); |
|
| 335 | + $profile_id = $subscription->get_profile_id(); |
|
| 336 | 336 | |
| 337 | - if ( ! empty( $profile_id ) ) { |
|
| 338 | - $profile_id = sanitize_text_field( $profile_id ); |
|
| 339 | - echo apply_filters( 'getpaid_subscription_profile_id_display', $profile_id, $subscription ); |
|
| 340 | - } else { |
|
| 341 | - echo "—"; |
|
| 342 | - } |
|
| 337 | + if ( ! empty( $profile_id ) ) { |
|
| 338 | + $profile_id = sanitize_text_field( $profile_id ); |
|
| 339 | + echo apply_filters( 'getpaid_subscription_profile_id_display', $profile_id, $subscription ); |
|
| 340 | + } else { |
|
| 341 | + echo "—"; |
|
| 342 | + } |
|
| 343 | 343 | |
| 344 | 344 | } |
| 345 | 345 | add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' ); |
@@ -351,39 +351,39 @@ discard block |
||
| 351 | 351 | */ |
| 352 | 352 | function getpaid_admin_subscription_update_metabox( $subscription ) { |
| 353 | 353 | |
| 354 | - ?> |
|
| 354 | + ?> |
|
| 355 | 355 | <div class="mt-3"> |
| 356 | 356 | |
| 357 | 357 | <?php |
| 358 | - echo aui()->select( |
|
| 359 | - array( |
|
| 360 | - 'options' => getpaid_get_subscription_statuses(), |
|
| 361 | - 'name' => 'subscription_status', |
|
| 362 | - 'id' => 'subscription_status_update_select', |
|
| 363 | - 'required' => true, |
|
| 364 | - 'no_wrap' => false, |
|
| 365 | - 'label' => __( 'Subscription Status', 'invoicing' ), |
|
| 366 | - 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
| 367 | - 'select2' => true, |
|
| 368 | - 'value' => $subscription->get_status( 'edit' ), |
|
| 369 | - ) |
|
| 370 | - ); |
|
| 371 | - ?> |
|
| 358 | + echo aui()->select( |
|
| 359 | + array( |
|
| 360 | + 'options' => getpaid_get_subscription_statuses(), |
|
| 361 | + 'name' => 'subscription_status', |
|
| 362 | + 'id' => 'subscription_status_update_select', |
|
| 363 | + 'required' => true, |
|
| 364 | + 'no_wrap' => false, |
|
| 365 | + 'label' => __( 'Subscription Status', 'invoicing' ), |
|
| 366 | + 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
| 367 | + 'select2' => true, |
|
| 368 | + 'value' => $subscription->get_status( 'edit' ), |
|
| 369 | + ) |
|
| 370 | + ); |
|
| 371 | + ?> |
|
| 372 | 372 | |
| 373 | 373 | <div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;"> |
| 374 | 374 | |
| 375 | 375 | <?php |
| 376 | - submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
| 376 | + submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
| 377 | 377 | |
| 378 | - $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
| 379 | - $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
| 380 | - $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
| 378 | + $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
| 379 | + $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
| 380 | + $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
| 381 | 381 | |
| 382 | - if ( $subscription->is_active() ) { |
|
| 383 | - echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
|
| 384 | - } |
|
| 382 | + if ( $subscription->is_active() ) { |
|
| 383 | + echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
|
| 384 | + } |
|
| 385 | 385 | |
| 386 | - echo '</div></div>'; |
|
| 386 | + echo '</div></div>'; |
|
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | /** |
@@ -393,33 +393,33 @@ discard block |
||
| 393 | 393 | */ |
| 394 | 394 | function getpaid_admin_subscription_invoice_details_metabox( $subscription ) { |
| 395 | 395 | |
| 396 | - $columns = apply_filters( |
|
| 397 | - 'getpaid_subscription_related_invoices_columns', |
|
| 398 | - array( |
|
| 399 | - 'invoice' => __( 'Invoice', 'invoicing' ), |
|
| 400 | - 'relationship' => __( 'Relationship', 'invoicing' ), |
|
| 401 | - 'date' => __( 'Date', 'invoicing' ), |
|
| 402 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 403 | - 'total' => __( 'Total', 'invoicing' ), |
|
| 404 | - ), |
|
| 405 | - $subscription |
|
| 406 | - ); |
|
| 407 | - |
|
| 408 | - // Prepare the invoices. |
|
| 409 | - $payments = $subscription->get_child_payments( ! is_admin() ); |
|
| 410 | - $parent = $subscription->get_parent_invoice(); |
|
| 411 | - |
|
| 412 | - if ( $parent->get_id() ) { |
|
| 413 | - $payments = array_merge( array( $parent ), $payments ); |
|
| 414 | - } |
|
| 396 | + $columns = apply_filters( |
|
| 397 | + 'getpaid_subscription_related_invoices_columns', |
|
| 398 | + array( |
|
| 399 | + 'invoice' => __( 'Invoice', 'invoicing' ), |
|
| 400 | + 'relationship' => __( 'Relationship', 'invoicing' ), |
|
| 401 | + 'date' => __( 'Date', 'invoicing' ), |
|
| 402 | + 'status' => __( 'Status', 'invoicing' ), |
|
| 403 | + 'total' => __( 'Total', 'invoicing' ), |
|
| 404 | + ), |
|
| 405 | + $subscription |
|
| 406 | + ); |
|
| 407 | + |
|
| 408 | + // Prepare the invoices. |
|
| 409 | + $payments = $subscription->get_child_payments( ! is_admin() ); |
|
| 410 | + $parent = $subscription->get_parent_invoice(); |
|
| 411 | + |
|
| 412 | + if ( $parent->get_id() ) { |
|
| 413 | + $payments = array_merge( array( $parent ), $payments ); |
|
| 414 | + } |
|
| 415 | 415 | |
| 416 | - $table_class = 'w-100 bg-white'; |
|
| 416 | + $table_class = 'w-100 bg-white'; |
|
| 417 | 417 | |
| 418 | - if ( ! is_admin() ) { |
|
| 419 | - $table_class = 'table table-bordered table-striped'; |
|
| 420 | - } |
|
| 418 | + if ( ! is_admin() ) { |
|
| 419 | + $table_class = 'table table-bordered table-striped'; |
|
| 420 | + } |
|
| 421 | 421 | |
| 422 | - ?> |
|
| 422 | + ?> |
|
| 423 | 423 | <div class="m-0" style="overflow: auto;"> |
| 424 | 424 | |
| 425 | 425 | <table class="<?php echo $table_class; ?>"> |
@@ -427,13 +427,13 @@ discard block |
||
| 427 | 427 | <thead> |
| 428 | 428 | <tr> |
| 429 | 429 | <?php |
| 430 | - foreach ( $columns as $key => $label ) { |
|
| 431 | - $key = esc_attr( $key ); |
|
| 432 | - $label = sanitize_text_field( $label ); |
|
| 430 | + foreach ( $columns as $key => $label ) { |
|
| 431 | + $key = esc_attr( $key ); |
|
| 432 | + $label = sanitize_text_field( $label ); |
|
| 433 | 433 | |
| 434 | - echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark'>$label</th>"; |
|
| 435 | - } |
|
| 436 | - ?> |
|
| 434 | + echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark'>$label</th>"; |
|
| 435 | + } |
|
| 436 | + ?> |
|
| 437 | 437 | </tr> |
| 438 | 438 | </thead> |
| 439 | 439 | |
@@ -449,66 +449,66 @@ discard block |
||
| 449 | 449 | |
| 450 | 450 | <?php |
| 451 | 451 | |
| 452 | - foreach( $payments as $payment ) : |
|
| 452 | + foreach( $payments as $payment ) : |
|
| 453 | 453 | |
| 454 | - // Ensure that we have an invoice. |
|
| 455 | - $payment = new WPInv_Invoice( $payment ); |
|
| 454 | + // Ensure that we have an invoice. |
|
| 455 | + $payment = new WPInv_Invoice( $payment ); |
|
| 456 | 456 | |
| 457 | - // Abort if the invoice is invalid. |
|
| 458 | - if ( ! $payment->get_id() ) { |
|
| 459 | - continue; |
|
| 460 | - } |
|
| 457 | + // Abort if the invoice is invalid. |
|
| 458 | + if ( ! $payment->get_id() ) { |
|
| 459 | + continue; |
|
| 460 | + } |
|
| 461 | 461 | |
| 462 | - echo '<tr>'; |
|
| 462 | + echo '<tr>'; |
|
| 463 | 463 | |
| 464 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 464 | + foreach ( array_keys( $columns ) as $key ) { |
|
| 465 | 465 | |
| 466 | - echo '<td class="p-2 text-left">'; |
|
| 466 | + echo '<td class="p-2 text-left">'; |
|
| 467 | 467 | |
| 468 | - switch( $key ) { |
|
| 468 | + switch( $key ) { |
|
| 469 | 469 | |
| 470 | - case 'total': |
|
| 471 | - echo '<strong>' . wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $payment->get_total() ) ), $payment->get_currency() ) . '</strong>'; |
|
| 472 | - break; |
|
| 470 | + case 'total': |
|
| 471 | + echo '<strong>' . wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $payment->get_total() ) ), $payment->get_currency() ) . '</strong>'; |
|
| 472 | + break; |
|
| 473 | 473 | |
| 474 | - case 'relationship': |
|
| 475 | - echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
| 476 | - break; |
|
| 474 | + case 'relationship': |
|
| 475 | + echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
| 476 | + break; |
|
| 477 | 477 | |
| 478 | - case 'date': |
|
| 479 | - echo getpaid_format_date_value( $payment->get_date_created() ); |
|
| 480 | - break; |
|
| 478 | + case 'date': |
|
| 479 | + echo getpaid_format_date_value( $payment->get_date_created() ); |
|
| 480 | + break; |
|
| 481 | 481 | |
| 482 | - case 'status': |
|
| 482 | + case 'status': |
|
| 483 | 483 | |
| 484 | - $status = $payment->get_status_nicename(); |
|
| 485 | - if ( is_admin() ) { |
|
| 486 | - $status = $payment->get_status_label_html(); |
|
| 487 | - } |
|
| 484 | + $status = $payment->get_status_nicename(); |
|
| 485 | + if ( is_admin() ) { |
|
| 486 | + $status = $payment->get_status_label_html(); |
|
| 487 | + } |
|
| 488 | 488 | |
| 489 | - echo $status; |
|
| 490 | - break; |
|
| 489 | + echo $status; |
|
| 490 | + break; |
|
| 491 | 491 | |
| 492 | - case 'invoice': |
|
| 493 | - $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
| 492 | + case 'invoice': |
|
| 493 | + $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
| 494 | 494 | |
| 495 | - if ( ! is_admin() ) { |
|
| 496 | - $link = esc_url( $payment->get_view_url() ); |
|
| 497 | - } |
|
| 495 | + if ( ! is_admin() ) { |
|
| 496 | + $link = esc_url( $payment->get_view_url() ); |
|
| 497 | + } |
|
| 498 | 498 | |
| 499 | - $invoice = sanitize_text_field( $payment->get_number() ); |
|
| 500 | - echo "<a href='$link'>$invoice</a>"; |
|
| 501 | - break; |
|
| 502 | - } |
|
| 499 | + $invoice = sanitize_text_field( $payment->get_number() ); |
|
| 500 | + echo "<a href='$link'>$invoice</a>"; |
|
| 501 | + break; |
|
| 502 | + } |
|
| 503 | 503 | |
| 504 | - echo '</td>'; |
|
| 504 | + echo '</td>'; |
|
| 505 | 505 | |
| 506 | - } |
|
| 506 | + } |
|
| 507 | 507 | |
| 508 | - echo '</tr>'; |
|
| 508 | + echo '</tr>'; |
|
| 509 | 509 | |
| 510 | - endforeach; |
|
| 511 | - ?> |
|
| 510 | + endforeach; |
|
| 511 | + ?> |
|
| 512 | 512 | |
| 513 | 513 | </tbody> |
| 514 | 514 | |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | * Contains functions that display the subscriptions admin page. |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | -defined( 'ABSPATH' ) || exit; |
|
| 6 | +defined('ABSPATH') || exit; |
|
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * Render the Subscriptions page |
@@ -17,22 +17,22 @@ discard block |
||
| 17 | 17 | ?> |
| 18 | 18 | |
| 19 | 19 | <div class="wrap"> |
| 20 | - <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
|
| 20 | + <h1><?php echo esc_html(get_admin_page_title()); ?></h1> |
|
| 21 | 21 | <div class="bsui"> |
| 22 | 22 | |
| 23 | 23 | <?php |
| 24 | 24 | |
| 25 | 25 | // Verify user permissions. |
| 26 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
| 26 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
| 27 | 27 | |
| 28 | 28 | echo aui()->alert( |
| 29 | 29 | array( |
| 30 | 30 | 'type' => 'danger', |
| 31 | - 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
| 31 | + 'content' => __('You are not permitted to view this page.', 'invoicing'), |
|
| 32 | 32 | ) |
| 33 | 33 | ); |
| 34 | 34 | |
| 35 | - } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
| 35 | + } else if (!empty($_GET['id']) && is_numeric($_GET['id'])) { |
|
| 36 | 36 | |
| 37 | 37 | // Display a single subscription. |
| 38 | 38 | wpinv_recurring_subscription_details(); |
@@ -81,13 +81,13 @@ discard block |
||
| 81 | 81 | function wpinv_recurring_subscription_details() { |
| 82 | 82 | |
| 83 | 83 | // Fetch the subscription. |
| 84 | - $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
| 85 | - if ( ! $sub->get_id() ) { |
|
| 84 | + $sub = new WPInv_Subscription((int) $_GET['id']); |
|
| 85 | + if (!$sub->get_id()) { |
|
| 86 | 86 | |
| 87 | 87 | echo aui()->alert( |
| 88 | 88 | array( |
| 89 | 89 | 'type' => 'danger', |
| 90 | - 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
| 90 | + 'content' => __('Subscription not found.', 'invoicing'), |
|
| 91 | 91 | ) |
| 92 | 92 | ); |
| 93 | 93 | |
@@ -95,31 +95,31 @@ discard block |
||
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | // Use metaboxes to display the subscription details. |
| 98 | - add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' ); |
|
| 99 | - add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
| 100 | - add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
| 101 | - do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
| 98 | + add_meta_box('getpaid_admin_subscription_details_metabox', __('Subscription Details', 'invoicing'), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal'); |
|
| 99 | + add_meta_box('getpaid_admin_subscription_update_metabox', __('Change Status', 'invoicing'), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side'); |
|
| 100 | + add_meta_box('getpaid_admin_subscription_invoice_details_metabox', __('Invoices', 'invoicing'), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced'); |
|
| 101 | + do_action('getpaid_admin_single_subscription_register_metabox', $sub); |
|
| 102 | 102 | |
| 103 | 103 | ?> |
| 104 | 104 | |
| 105 | - <form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>"> |
|
| 105 | + <form method="post" action="<?php echo admin_url('admin.php?page=wpinv-subscriptions&id=' . absint($sub->get_id())); ?>"> |
|
| 106 | 106 | |
| 107 | - <?php wp_nonce_field( 'getpaid-nonce', 'getpaid-nonce' ); ?> |
|
| 108 | - <?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?> |
|
| 109 | - <?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?> |
|
| 107 | + <?php wp_nonce_field('getpaid-nonce', 'getpaid-nonce'); ?> |
|
| 108 | + <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); ?> |
|
| 109 | + <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); ?> |
|
| 110 | 110 | <input type="hidden" name="getpaid-admin-action" value="update_single_subscription" /> |
| 111 | - <input type="hidden" name="subscription_id" value="<?php echo (int) $sub->get_id() ;?>" /> |
|
| 111 | + <input type="hidden" name="subscription_id" value="<?php echo (int) $sub->get_id(); ?>" /> |
|
| 112 | 112 | |
| 113 | 113 | <div id="poststuff"> |
| 114 | 114 | <div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>"> |
| 115 | 115 | |
| 116 | 116 | <div id="postbox-container-1" class="postbox-container"> |
| 117 | - <?php do_meta_boxes( get_current_screen(), 'side', $sub ); ?> |
|
| 117 | + <?php do_meta_boxes(get_current_screen(), 'side', $sub); ?> |
|
| 118 | 118 | </div> |
| 119 | 119 | |
| 120 | 120 | <div id="postbox-container-2" class="postbox-container"> |
| 121 | - <?php do_meta_boxes( get_current_screen(), 'normal', $sub ); ?> |
|
| 122 | - <?php do_meta_boxes( get_current_screen(), 'advanced', $sub ); ?> |
|
| 121 | + <?php do_meta_boxes(get_current_screen(), 'normal', $sub); ?> |
|
| 122 | + <?php do_meta_boxes(get_current_screen(), 'advanced', $sub); ?> |
|
| 123 | 123 | </div> |
| 124 | 124 | |
| 125 | 125 | </div> |
@@ -138,40 +138,40 @@ discard block |
||
| 138 | 138 | * |
| 139 | 139 | * @param WPInv_Subscription $sub |
| 140 | 140 | */ |
| 141 | -function getpaid_admin_subscription_details_metabox( $sub ) { |
|
| 141 | +function getpaid_admin_subscription_details_metabox($sub) { |
|
| 142 | 142 | |
| 143 | 143 | // Prepare subscription detail columns. |
| 144 | 144 | $fields = apply_filters( |
| 145 | 145 | 'getpaid_subscription_admin_page_fields', |
| 146 | 146 | array( |
| 147 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
| 148 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
| 149 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 150 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
| 151 | - 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
| 152 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
| 153 | - 'item' => __( 'Item', 'invoicing' ), |
|
| 154 | - 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
| 155 | - 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
| 156 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 147 | + 'subscription' => __('Subscription', 'invoicing'), |
|
| 148 | + 'customer' => __('Customer', 'invoicing'), |
|
| 149 | + 'amount' => __('Amount', 'invoicing'), |
|
| 150 | + 'start_date' => __('Start Date', 'invoicing'), |
|
| 151 | + 'renews_on' => __('Next Payment', 'invoicing'), |
|
| 152 | + 'renewals' => __('Payments', 'invoicing'), |
|
| 153 | + 'item' => __('Item', 'invoicing'), |
|
| 154 | + 'gateway' => __('Payment Method', 'invoicing'), |
|
| 155 | + 'profile_id' => __('Profile ID', 'invoicing'), |
|
| 156 | + 'status' => __('Status', 'invoicing'), |
|
| 157 | 157 | ) |
| 158 | 158 | ); |
| 159 | 159 | |
| 160 | - if ( ! $sub->is_active() ) { |
|
| 160 | + if (!$sub->is_active()) { |
|
| 161 | 161 | |
| 162 | - if ( isset( $fields['renews_on'] ) ) { |
|
| 163 | - unset( $fields['renews_on'] ); |
|
| 162 | + if (isset($fields['renews_on'])) { |
|
| 163 | + unset($fields['renews_on']); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - if ( isset( $fields['gateway'] ) ) { |
|
| 167 | - unset( $fields['gateway'] ); |
|
| 166 | + if (isset($fields['gateway'])) { |
|
| 167 | + unset($fields['gateway']); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | $profile_id = $sub->get_profile_id(); |
| 173 | - if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
| 174 | - unset( $fields['profile_id'] ); |
|
| 173 | + if (empty($profile_id) && isset($fields['profile_id'])) { |
|
| 174 | + unset($fields['profile_id']); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | ?> |
@@ -179,16 +179,16 @@ discard block |
||
| 179 | 179 | <table class="table table-borderless" style="font-size: 14px;"> |
| 180 | 180 | <tbody> |
| 181 | 181 | |
| 182 | - <?php foreach ( $fields as $key => $label ) : ?> |
|
| 182 | + <?php foreach ($fields as $key => $label) : ?> |
|
| 183 | 183 | |
| 184 | - <tr class="getpaid-subscription-meta-<?php echo sanitize_html_class( $key ); ?>"> |
|
| 184 | + <tr class="getpaid-subscription-meta-<?php echo sanitize_html_class($key); ?>"> |
|
| 185 | 185 | |
| 186 | 186 | <th class="w-25" style="font-weight: 500;"> |
| 187 | - <?php echo sanitize_text_field( $label ); ?> |
|
| 187 | + <?php echo sanitize_text_field($label); ?> |
|
| 188 | 188 | </th> |
| 189 | 189 | |
| 190 | 190 | <td class="w-75 text-muted"> |
| 191 | - <?php do_action( 'getpaid_subscription_admin_display_' . sanitize_text_field( $key ), $sub ); ?> |
|
| 191 | + <?php do_action('getpaid_subscription_admin_display_' . sanitize_text_field($key), $sub); ?> |
|
| 192 | 192 | </td> |
| 193 | 193 | |
| 194 | 194 | </tr> |
@@ -206,150 +206,150 @@ discard block |
||
| 206 | 206 | * |
| 207 | 207 | * @param WPInv_Subscription $subscription |
| 208 | 208 | */ |
| 209 | -function getpaid_admin_subscription_metabox_display_customer( $subscription ) { |
|
| 209 | +function getpaid_admin_subscription_metabox_display_customer($subscription) { |
|
| 210 | 210 | |
| 211 | - $username = __( '(Missing User)', 'invoicing' ); |
|
| 211 | + $username = __('(Missing User)', 'invoicing'); |
|
| 212 | 212 | |
| 213 | - $user = get_userdata( $subscription->get_customer_id() ); |
|
| 214 | - if ( $user ) { |
|
| 213 | + $user = get_userdata($subscription->get_customer_id()); |
|
| 214 | + if ($user) { |
|
| 215 | 215 | |
| 216 | 216 | $username = sprintf( |
| 217 | 217 | '<a href="user-edit.php?user_id=%s">%s</a>', |
| 218 | - absint( $user->ID ), |
|
| 219 | - ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
| 218 | + absint($user->ID), |
|
| 219 | + !empty($user->display_name) ? sanitize_text_field($user->display_name) : sanitize_email($user->user_email) |
|
| 220 | 220 | ); |
| 221 | 221 | |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | echo $username; |
| 225 | 225 | } |
| 226 | -add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' ); |
|
| 226 | +add_action('getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer'); |
|
| 227 | 227 | |
| 228 | 228 | /** |
| 229 | 229 | * Displays the subscription amount. |
| 230 | 230 | * |
| 231 | 231 | * @param WPInv_Subscription $subscription |
| 232 | 232 | */ |
| 233 | -function getpaid_admin_subscription_metabox_display_amount( $subscription ) { |
|
| 234 | - $amount = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) ); |
|
| 233 | +function getpaid_admin_subscription_metabox_display_amount($subscription) { |
|
| 234 | + $amount = sanitize_text_field(getpaid_get_formatted_subscription_amount($subscription)); |
|
| 235 | 235 | echo "<span>$amount</span>"; |
| 236 | 236 | } |
| 237 | -add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' ); |
|
| 237 | +add_action('getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount'); |
|
| 238 | 238 | |
| 239 | 239 | /** |
| 240 | 240 | * Displays the subscription id. |
| 241 | 241 | * |
| 242 | 242 | * @param WPInv_Subscription $subscription |
| 243 | 243 | */ |
| 244 | -function getpaid_admin_subscription_metabox_display_id( $subscription ) { |
|
| 245 | - echo '#' . absint( $subscription->get_id() ); |
|
| 244 | +function getpaid_admin_subscription_metabox_display_id($subscription) { |
|
| 245 | + echo '#' . absint($subscription->get_id()); |
|
| 246 | 246 | } |
| 247 | -add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' ); |
|
| 247 | +add_action('getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id'); |
|
| 248 | 248 | |
| 249 | 249 | /** |
| 250 | 250 | * Displays the subscription renewal date. |
| 251 | 251 | * |
| 252 | 252 | * @param WPInv_Subscription $subscription |
| 253 | 253 | */ |
| 254 | -function getpaid_admin_subscription_metabox_display_start_date( $subscription ) { |
|
| 255 | - echo getpaid_format_date_value( $subscription->get_date_created() ); |
|
| 254 | +function getpaid_admin_subscription_metabox_display_start_date($subscription) { |
|
| 255 | + echo getpaid_format_date_value($subscription->get_date_created()); |
|
| 256 | 256 | } |
| 257 | -add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' ); |
|
| 257 | +add_action('getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date'); |
|
| 258 | 258 | |
| 259 | 259 | /** |
| 260 | 260 | * Displays the subscription renewal date. |
| 261 | 261 | * |
| 262 | 262 | * @param WPInv_Subscription $subscription |
| 263 | 263 | */ |
| 264 | -function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) { |
|
| 265 | - echo getpaid_format_date_value( $subscription->get_expiration() ); |
|
| 264 | +function getpaid_admin_subscription_metabox_display_renews_on($subscription) { |
|
| 265 | + echo getpaid_format_date_value($subscription->get_expiration()); |
|
| 266 | 266 | } |
| 267 | -add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' ); |
|
| 267 | +add_action('getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on'); |
|
| 268 | 268 | |
| 269 | 269 | /** |
| 270 | 270 | * Displays the subscription renewal count. |
| 271 | 271 | * |
| 272 | 272 | * @param WPInv_Subscription $subscription |
| 273 | 273 | */ |
| 274 | -function getpaid_admin_subscription_metabox_display_renewals( $subscription ) { |
|
| 274 | +function getpaid_admin_subscription_metabox_display_renewals($subscription) { |
|
| 275 | 275 | $max_bills = $subscription->get_bill_times(); |
| 276 | - echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
| 276 | + echo $subscription->get_times_billed() . ' / ' . (empty($max_bills) ? "∞" : $max_bills); |
|
| 277 | 277 | } |
| 278 | -add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' ); |
|
| 278 | +add_action('getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals'); |
|
| 279 | 279 | /** |
| 280 | 280 | * Displays the subscription item. |
| 281 | 281 | * |
| 282 | 282 | * @param WPInv_Subscription $subscription |
| 283 | 283 | */ |
| 284 | -function getpaid_admin_subscription_metabox_display_item( $subscription ) { |
|
| 284 | +function getpaid_admin_subscription_metabox_display_item($subscription) { |
|
| 285 | 285 | |
| 286 | - $item = get_post( $subscription->get_product_id() ); |
|
| 286 | + $item = get_post($subscription->get_product_id()); |
|
| 287 | 287 | |
| 288 | - if ( ! empty( $item ) ) { |
|
| 289 | - $link = get_edit_post_link( $item ); |
|
| 290 | - $link = esc_url( $link ); |
|
| 291 | - $name = esc_html( get_the_title( $item ) ); |
|
| 288 | + if (!empty($item)) { |
|
| 289 | + $link = get_edit_post_link($item); |
|
| 290 | + $link = esc_url($link); |
|
| 291 | + $name = esc_html(get_the_title($item)); |
|
| 292 | 292 | echo "<a href='$link'>$name</a>"; |
| 293 | 293 | } else { |
| 294 | - echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
| 294 | + echo sprintf(__('Item #%s', 'invoicing'), $subscription->get_product_id()); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | } |
| 298 | -add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item' ); |
|
| 298 | +add_action('getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item'); |
|
| 299 | 299 | |
| 300 | 300 | /** |
| 301 | 301 | * Displays the subscription gateway. |
| 302 | 302 | * |
| 303 | 303 | * @param WPInv_Subscription $subscription |
| 304 | 304 | */ |
| 305 | -function getpaid_admin_subscription_metabox_display_gateway( $subscription ) { |
|
| 305 | +function getpaid_admin_subscription_metabox_display_gateway($subscription) { |
|
| 306 | 306 | |
| 307 | 307 | $gateway = $subscription->get_gateway(); |
| 308 | 308 | |
| 309 | - if ( ! empty( $gateway ) ) { |
|
| 310 | - echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) ); |
|
| 309 | + if (!empty($gateway)) { |
|
| 310 | + echo sanitize_text_field(wpinv_get_gateway_admin_label($gateway)); |
|
| 311 | 311 | } else { |
| 312 | 312 | echo "—"; |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | } |
| 316 | -add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' ); |
|
| 316 | +add_action('getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway'); |
|
| 317 | 317 | |
| 318 | 318 | /** |
| 319 | 319 | * Displays the subscription status. |
| 320 | 320 | * |
| 321 | 321 | * @param WPInv_Subscription $subscription |
| 322 | 322 | */ |
| 323 | -function getpaid_admin_subscription_metabox_display_status( $subscription ) { |
|
| 323 | +function getpaid_admin_subscription_metabox_display_status($subscription) { |
|
| 324 | 324 | echo $subscription->get_status_label_html(); |
| 325 | 325 | } |
| 326 | -add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' ); |
|
| 326 | +add_action('getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status'); |
|
| 327 | 327 | |
| 328 | 328 | /** |
| 329 | 329 | * Displays the subscription profile id. |
| 330 | 330 | * |
| 331 | 331 | * @param WPInv_Subscription $subscription |
| 332 | 332 | */ |
| 333 | -function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) { |
|
| 333 | +function getpaid_admin_subscription_metabox_display_profile_id($subscription) { |
|
| 334 | 334 | |
| 335 | 335 | $profile_id = $subscription->get_profile_id(); |
| 336 | 336 | |
| 337 | - if ( ! empty( $profile_id ) ) { |
|
| 338 | - $profile_id = sanitize_text_field( $profile_id ); |
|
| 339 | - echo apply_filters( 'getpaid_subscription_profile_id_display', $profile_id, $subscription ); |
|
| 337 | + if (!empty($profile_id)) { |
|
| 338 | + $profile_id = sanitize_text_field($profile_id); |
|
| 339 | + echo apply_filters('getpaid_subscription_profile_id_display', $profile_id, $subscription); |
|
| 340 | 340 | } else { |
| 341 | 341 | echo "—"; |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | } |
| 345 | -add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' ); |
|
| 345 | +add_action('getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id'); |
|
| 346 | 346 | |
| 347 | 347 | /** |
| 348 | 348 | * Displays the subscriptions update metabox. |
| 349 | 349 | * |
| 350 | 350 | * @param WPInv_Subscription $subscription |
| 351 | 351 | */ |
| 352 | -function getpaid_admin_subscription_update_metabox( $subscription ) { |
|
| 352 | +function getpaid_admin_subscription_update_metabox($subscription) { |
|
| 353 | 353 | |
| 354 | 354 | ?> |
| 355 | 355 | <div class="mt-3"> |
@@ -362,10 +362,10 @@ discard block |
||
| 362 | 362 | 'id' => 'subscription_status_update_select', |
| 363 | 363 | 'required' => true, |
| 364 | 364 | 'no_wrap' => false, |
| 365 | - 'label' => __( 'Subscription Status', 'invoicing' ), |
|
| 366 | - 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
| 365 | + 'label' => __('Subscription Status', 'invoicing'), |
|
| 366 | + 'help_text' => __('Updating the status will trigger related actions and hooks', 'invoicing'), |
|
| 367 | 367 | 'select2' => true, |
| 368 | - 'value' => $subscription->get_status( 'edit' ), |
|
| 368 | + 'value' => $subscription->get_status('edit'), |
|
| 369 | 369 | ) |
| 370 | 370 | ); |
| 371 | 371 | ?> |
@@ -373,13 +373,13 @@ discard block |
||
| 373 | 373 | <div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;"> |
| 374 | 374 | |
| 375 | 375 | <?php |
| 376 | - submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
| 376 | + submit_button(__('Update', 'invoicing'), 'primary', 'submit', false); |
|
| 377 | 377 | |
| 378 | - $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
| 379 | - $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
| 380 | - $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
| 378 | + $url = esc_url(wp_nonce_url(add_query_arg('getpaid-admin-action', 'subscription_manual_renew'), 'getpaid-nonce', 'getpaid-nonce')); |
|
| 379 | + $anchor = __('Renew Subscription', 'invoicing'); |
|
| 380 | + $title = esc_attr__('Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing'); |
|
| 381 | 381 | |
| 382 | - if ( $subscription->is_active() ) { |
|
| 382 | + if ($subscription->is_active()) { |
|
| 383 | 383 | echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
| 384 | 384 | } |
| 385 | 385 | |
@@ -391,31 +391,31 @@ discard block |
||
| 391 | 391 | * |
| 392 | 392 | * @param WPInv_Subscription $subscription |
| 393 | 393 | */ |
| 394 | -function getpaid_admin_subscription_invoice_details_metabox( $subscription ) { |
|
| 394 | +function getpaid_admin_subscription_invoice_details_metabox($subscription) { |
|
| 395 | 395 | |
| 396 | 396 | $columns = apply_filters( |
| 397 | 397 | 'getpaid_subscription_related_invoices_columns', |
| 398 | 398 | array( |
| 399 | - 'invoice' => __( 'Invoice', 'invoicing' ), |
|
| 400 | - 'relationship' => __( 'Relationship', 'invoicing' ), |
|
| 401 | - 'date' => __( 'Date', 'invoicing' ), |
|
| 402 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 403 | - 'total' => __( 'Total', 'invoicing' ), |
|
| 399 | + 'invoice' => __('Invoice', 'invoicing'), |
|
| 400 | + 'relationship' => __('Relationship', 'invoicing'), |
|
| 401 | + 'date' => __('Date', 'invoicing'), |
|
| 402 | + 'status' => __('Status', 'invoicing'), |
|
| 403 | + 'total' => __('Total', 'invoicing'), |
|
| 404 | 404 | ), |
| 405 | 405 | $subscription |
| 406 | 406 | ); |
| 407 | 407 | |
| 408 | 408 | // Prepare the invoices. |
| 409 | - $payments = $subscription->get_child_payments( ! is_admin() ); |
|
| 409 | + $payments = $subscription->get_child_payments(!is_admin()); |
|
| 410 | 410 | $parent = $subscription->get_parent_invoice(); |
| 411 | 411 | |
| 412 | - if ( $parent->get_id() ) { |
|
| 413 | - $payments = array_merge( array( $parent ), $payments ); |
|
| 412 | + if ($parent->get_id()) { |
|
| 413 | + $payments = array_merge(array($parent), $payments); |
|
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | $table_class = 'w-100 bg-white'; |
| 417 | 417 | |
| 418 | - if ( ! is_admin() ) { |
|
| 418 | + if (!is_admin()) { |
|
| 419 | 419 | $table_class = 'table table-bordered table-striped'; |
| 420 | 420 | } |
| 421 | 421 | |
@@ -427,9 +427,9 @@ discard block |
||
| 427 | 427 | <thead> |
| 428 | 428 | <tr> |
| 429 | 429 | <?php |
| 430 | - foreach ( $columns as $key => $label ) { |
|
| 431 | - $key = esc_attr( $key ); |
|
| 432 | - $label = sanitize_text_field( $label ); |
|
| 430 | + foreach ($columns as $key => $label) { |
|
| 431 | + $key = esc_attr($key); |
|
| 432 | + $label = sanitize_text_field($label); |
|
| 433 | 433 | |
| 434 | 434 | echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark'>$label</th>"; |
| 435 | 435 | } |
@@ -439,50 +439,50 @@ discard block |
||
| 439 | 439 | |
| 440 | 440 | <tbody> |
| 441 | 441 | |
| 442 | - <?php if ( empty( $payments ) ) : ?> |
|
| 442 | + <?php if (empty($payments)) : ?> |
|
| 443 | 443 | <tr> |
| 444 | 444 | <td colspan="<?php echo count($columns); ?>" class="p-2 text-left text-muted"> |
| 445 | - <?php _e( 'This subscription has no invoices.', 'invoicing' ); ?> |
|
| 445 | + <?php _e('This subscription has no invoices.', 'invoicing'); ?> |
|
| 446 | 446 | </td> |
| 447 | 447 | </tr> |
| 448 | 448 | <?php endif; ?> |
| 449 | 449 | |
| 450 | 450 | <?php |
| 451 | 451 | |
| 452 | - foreach( $payments as $payment ) : |
|
| 452 | + foreach ($payments as $payment) : |
|
| 453 | 453 | |
| 454 | 454 | // Ensure that we have an invoice. |
| 455 | - $payment = new WPInv_Invoice( $payment ); |
|
| 455 | + $payment = new WPInv_Invoice($payment); |
|
| 456 | 456 | |
| 457 | 457 | // Abort if the invoice is invalid. |
| 458 | - if ( ! $payment->get_id() ) { |
|
| 458 | + if (!$payment->get_id()) { |
|
| 459 | 459 | continue; |
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | echo '<tr>'; |
| 463 | 463 | |
| 464 | - foreach ( array_keys( $columns ) as $key ) { |
|
| 464 | + foreach (array_keys($columns) as $key) { |
|
| 465 | 465 | |
| 466 | 466 | echo '<td class="p-2 text-left">'; |
| 467 | 467 | |
| 468 | - switch( $key ) { |
|
| 468 | + switch ($key) { |
|
| 469 | 469 | |
| 470 | 470 | case 'total': |
| 471 | - echo '<strong>' . wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $payment->get_total() ) ), $payment->get_currency() ) . '</strong>'; |
|
| 471 | + echo '<strong>' . wpinv_price(wpinv_format_amount(wpinv_sanitize_amount($payment->get_total())), $payment->get_currency()) . '</strong>'; |
|
| 472 | 472 | break; |
| 473 | 473 | |
| 474 | 474 | case 'relationship': |
| 475 | - echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
| 475 | + echo $payment->is_renewal() ? __('Renewal Invoice', 'invoicing') : __('Initial Invoice', 'invoicing'); |
|
| 476 | 476 | break; |
| 477 | 477 | |
| 478 | 478 | case 'date': |
| 479 | - echo getpaid_format_date_value( $payment->get_date_created() ); |
|
| 479 | + echo getpaid_format_date_value($payment->get_date_created()); |
|
| 480 | 480 | break; |
| 481 | 481 | |
| 482 | 482 | case 'status': |
| 483 | 483 | |
| 484 | 484 | $status = $payment->get_status_nicename(); |
| 485 | - if ( is_admin() ) { |
|
| 485 | + if (is_admin()) { |
|
| 486 | 486 | $status = $payment->get_status_label_html(); |
| 487 | 487 | } |
| 488 | 488 | |
@@ -490,13 +490,13 @@ discard block |
||
| 490 | 490 | break; |
| 491 | 491 | |
| 492 | 492 | case 'invoice': |
| 493 | - $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
| 493 | + $link = esc_url(get_edit_post_link($payment->get_id())); |
|
| 494 | 494 | |
| 495 | - if ( ! is_admin() ) { |
|
| 496 | - $link = esc_url( $payment->get_view_url() ); |
|
| 495 | + if (!is_admin()) { |
|
| 496 | + $link = esc_url($payment->get_view_url()); |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | - $invoice = sanitize_text_field( $payment->get_number() ); |
|
| 499 | + $invoice = sanitize_text_field($payment->get_number()); |
|
| 500 | 500 | echo "<a href='$link'>$invoice</a>"; |
| 501 | 501 | break; |
| 502 | 502 | } |
@@ -15,125 +15,125 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | class WPInv_Subscription extends GetPaid_Data { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Which data store to load. |
|
| 20 | - * |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - protected $data_store_name = 'subscription'; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * This is the name of this object type. |
|
| 27 | - * |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - protected $object_type = 'subscription'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Item Data array. This is the core item data exposed in APIs. |
|
| 34 | - * |
|
| 35 | - * @since 1.0.19 |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - protected $data = array( |
|
| 39 | - 'customer_id' => 0, |
|
| 40 | - 'frequency' => 1, |
|
| 41 | - 'period' => 'D', |
|
| 42 | - 'initial_amount' => null, |
|
| 43 | - 'recurring_amount' => null, |
|
| 44 | - 'bill_times' => 0, |
|
| 45 | - 'transaction_id' => '', |
|
| 46 | - 'parent_payment_id' => null, |
|
| 47 | - 'product_id' => 0, |
|
| 48 | - 'created' => '0000-00-00 00:00:00', |
|
| 49 | - 'expiration' => '0000-00-00 00:00:00', |
|
| 50 | - 'trial_period' => '', |
|
| 51 | - 'status' => 'pending', |
|
| 52 | - 'profile_id' => '', |
|
| 53 | - 'gateway' => '', |
|
| 54 | - 'customer' => '', |
|
| 55 | - ); |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Stores the status transition information. |
|
| 59 | - * |
|
| 60 | - * @since 1.0.19 |
|
| 61 | - * @var bool |
|
| 62 | - */ |
|
| 63 | - protected $status_transition = false; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
| 67 | - * |
|
| 68 | - * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
| 69 | - * @param bool $deprecated |
|
| 70 | - */ |
|
| 71 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
| 72 | - |
|
| 73 | - parent::__construct( $subscription ); |
|
| 74 | - |
|
| 75 | - if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
| 76 | - $this->set_id( $subscription ); |
|
| 77 | - } elseif ( $subscription instanceof self ) { |
|
| 78 | - $this->set_id( $subscription->get_id() ); |
|
| 79 | - } elseif ( ! empty( $subscription->id ) ) { |
|
| 80 | - $this->set_id( $subscription->id ); |
|
| 81 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
| 82 | - $this->set_id( $subscription_id ); |
|
| 83 | - } else { |
|
| 84 | - $this->set_object_read( true ); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // Load the datastore. |
|
| 88 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 89 | - |
|
| 90 | - if ( $this->get_id() > 0 ) { |
|
| 91 | - $this->data_store->read( $this ); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
| 98 | - * |
|
| 99 | - * |
|
| 100 | - * @static |
|
| 101 | - * @param string $value |
|
| 102 | - * @param string $field Either invoice_id, transaction_id or profile_id. |
|
| 103 | - * @since 1.0.19 |
|
| 104 | - * @return int |
|
| 105 | - */ |
|
| 106 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
| 18 | + /** |
|
| 19 | + * Which data store to load. |
|
| 20 | + * |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + protected $data_store_name = 'subscription'; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * This is the name of this object type. |
|
| 27 | + * |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + protected $object_type = 'subscription'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Item Data array. This is the core item data exposed in APIs. |
|
| 34 | + * |
|
| 35 | + * @since 1.0.19 |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + protected $data = array( |
|
| 39 | + 'customer_id' => 0, |
|
| 40 | + 'frequency' => 1, |
|
| 41 | + 'period' => 'D', |
|
| 42 | + 'initial_amount' => null, |
|
| 43 | + 'recurring_amount' => null, |
|
| 44 | + 'bill_times' => 0, |
|
| 45 | + 'transaction_id' => '', |
|
| 46 | + 'parent_payment_id' => null, |
|
| 47 | + 'product_id' => 0, |
|
| 48 | + 'created' => '0000-00-00 00:00:00', |
|
| 49 | + 'expiration' => '0000-00-00 00:00:00', |
|
| 50 | + 'trial_period' => '', |
|
| 51 | + 'status' => 'pending', |
|
| 52 | + 'profile_id' => '', |
|
| 53 | + 'gateway' => '', |
|
| 54 | + 'customer' => '', |
|
| 55 | + ); |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Stores the status transition information. |
|
| 59 | + * |
|
| 60 | + * @since 1.0.19 |
|
| 61 | + * @var bool |
|
| 62 | + */ |
|
| 63 | + protected $status_transition = false; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
| 67 | + * |
|
| 68 | + * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
| 69 | + * @param bool $deprecated |
|
| 70 | + */ |
|
| 71 | + function __construct( $subscription = 0, $deprecated = false ) { |
|
| 72 | + |
|
| 73 | + parent::__construct( $subscription ); |
|
| 74 | + |
|
| 75 | + if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
| 76 | + $this->set_id( $subscription ); |
|
| 77 | + } elseif ( $subscription instanceof self ) { |
|
| 78 | + $this->set_id( $subscription->get_id() ); |
|
| 79 | + } elseif ( ! empty( $subscription->id ) ) { |
|
| 80 | + $this->set_id( $subscription->id ); |
|
| 81 | + } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
| 82 | + $this->set_id( $subscription_id ); |
|
| 83 | + } else { |
|
| 84 | + $this->set_object_read( true ); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // Load the datastore. |
|
| 88 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 89 | + |
|
| 90 | + if ( $this->get_id() > 0 ) { |
|
| 91 | + $this->data_store->read( $this ); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
| 98 | + * |
|
| 99 | + * |
|
| 100 | + * @static |
|
| 101 | + * @param string $value |
|
| 102 | + * @param string $field Either invoice_id, transaction_id or profile_id. |
|
| 103 | + * @since 1.0.19 |
|
| 104 | + * @return int |
|
| 105 | + */ |
|
| 106 | + public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
| 107 | 107 | global $wpdb; |
| 108 | 108 | |
| 109 | - // Trim the value. |
|
| 110 | - $value = trim( $value ); |
|
| 109 | + // Trim the value. |
|
| 110 | + $value = trim( $value ); |
|
| 111 | 111 | |
| 112 | - if ( empty( $value ) ) { |
|
| 113 | - return 0; |
|
| 114 | - } |
|
| 112 | + if ( empty( $value ) ) { |
|
| 113 | + return 0; |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - if ( 'invoice_id' == $field ) { |
|
| 117 | - $field = 'parent_payment_id'; |
|
| 118 | - } |
|
| 116 | + if ( 'invoice_id' == $field ) { |
|
| 117 | + $field = 'parent_payment_id'; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | 120 | // Valid fields. |
| 121 | 121 | $fields = array( |
| 122 | - 'parent_payment_id', |
|
| 123 | - 'transaction_id', |
|
| 124 | - 'profile_id' |
|
| 125 | - ); |
|
| 126 | - |
|
| 127 | - // Ensure a field has been passed. |
|
| 128 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 129 | - return 0; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - // Maybe retrieve from the cache. |
|
| 133 | - $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 134 | - if ( ! empty( $subscription_id ) ) { |
|
| 135 | - return $subscription_id; |
|
| 136 | - } |
|
| 122 | + 'parent_payment_id', |
|
| 123 | + 'transaction_id', |
|
| 124 | + 'profile_id' |
|
| 125 | + ); |
|
| 126 | + |
|
| 127 | + // Ensure a field has been passed. |
|
| 128 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 129 | + return 0; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + // Maybe retrieve from the cache. |
|
| 133 | + $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 134 | + if ( ! empty( $subscription_id ) ) { |
|
| 135 | + return $subscription_id; |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | 138 | // Fetch from the db. |
| 139 | 139 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
@@ -141,34 +141,34 @@ discard block |
||
| 141 | 141 | $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | - if ( empty( $subscription_id ) ) { |
|
| 145 | - return 0; |
|
| 146 | - } |
|
| 144 | + if ( empty( $subscription_id ) ) { |
|
| 145 | + return 0; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - // Update the cache with our data. |
|
| 149 | - wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 148 | + // Update the cache with our data. |
|
| 149 | + wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 150 | 150 | |
| 151 | - return $subscription_id; |
|
| 152 | - } |
|
| 151 | + return $subscription_id; |
|
| 152 | + } |
|
| 153 | 153 | |
| 154 | - /** |
|
| 154 | + /** |
|
| 155 | 155 | * Clears the subscription's cache. |
| 156 | 156 | */ |
| 157 | 157 | public function clear_cache() { |
| 158 | - wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
| 159 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
| 160 | - wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
| 161 | - wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
| 162 | - } |
|
| 158 | + wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
| 159 | + wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
| 160 | + wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
| 161 | + wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - /** |
|
| 164 | + /** |
|
| 165 | 165 | * Checks if a subscription key is set. |
| 166 | 166 | */ |
| 167 | 167 | public function _isset( $key ) { |
| 168 | 168 | return isset( $this->data[$key] ) || method_exists( $this, "get_$key" ); |
| 169 | - } |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | - /* |
|
| 171 | + /* |
|
| 172 | 172 | |-------------------------------------------------------------------------- |
| 173 | 173 | | CRUD methods |
| 174 | 174 | |-------------------------------------------------------------------------- |
@@ -177,545 +177,545 @@ discard block |
||
| 177 | 177 | | |
| 178 | 178 | */ |
| 179 | 179 | |
| 180 | - /* |
|
| 180 | + /* |
|
| 181 | 181 | |-------------------------------------------------------------------------- |
| 182 | 182 | | Getters |
| 183 | 183 | |-------------------------------------------------------------------------- |
| 184 | 184 | */ |
| 185 | 185 | |
| 186 | - /** |
|
| 187 | - * Get customer id. |
|
| 188 | - * |
|
| 189 | - * @since 1.0.19 |
|
| 190 | - * @param string $context View or edit context. |
|
| 191 | - * @return int |
|
| 192 | - */ |
|
| 193 | - public function get_customer_id( $context = 'view' ) { |
|
| 194 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Get customer information. |
|
| 199 | - * |
|
| 200 | - * @since 1.0.19 |
|
| 201 | - * @param string $context View or edit context. |
|
| 202 | - * @return WP_User|false WP_User object on success, false on failure. |
|
| 203 | - */ |
|
| 204 | - public function get_customer( $context = 'view' ) { |
|
| 205 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Get parent invoice id. |
|
| 210 | - * |
|
| 211 | - * @since 1.0.19 |
|
| 212 | - * @param string $context View or edit context. |
|
| 213 | - * @return int |
|
| 214 | - */ |
|
| 215 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
| 216 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Alias for self::get_parent_invoice_id(). |
|
| 221 | - * |
|
| 222 | - * @since 1.0.19 |
|
| 223 | - * @param string $context View or edit context. |
|
| 224 | - * @return int |
|
| 225 | - */ |
|
| 186 | + /** |
|
| 187 | + * Get customer id. |
|
| 188 | + * |
|
| 189 | + * @since 1.0.19 |
|
| 190 | + * @param string $context View or edit context. |
|
| 191 | + * @return int |
|
| 192 | + */ |
|
| 193 | + public function get_customer_id( $context = 'view' ) { |
|
| 194 | + return (int) $this->get_prop( 'customer_id', $context ); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Get customer information. |
|
| 199 | + * |
|
| 200 | + * @since 1.0.19 |
|
| 201 | + * @param string $context View or edit context. |
|
| 202 | + * @return WP_User|false WP_User object on success, false on failure. |
|
| 203 | + */ |
|
| 204 | + public function get_customer( $context = 'view' ) { |
|
| 205 | + return get_userdata( $this->get_customer_id( $context ) ); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Get parent invoice id. |
|
| 210 | + * |
|
| 211 | + * @since 1.0.19 |
|
| 212 | + * @param string $context View or edit context. |
|
| 213 | + * @return int |
|
| 214 | + */ |
|
| 215 | + public function get_parent_invoice_id( $context = 'view' ) { |
|
| 216 | + return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Alias for self::get_parent_invoice_id(). |
|
| 221 | + * |
|
| 222 | + * @since 1.0.19 |
|
| 223 | + * @param string $context View or edit context. |
|
| 224 | + * @return int |
|
| 225 | + */ |
|
| 226 | 226 | public function get_parent_payment_id( $context = 'view' ) { |
| 227 | 227 | return $this->get_parent_invoice_id( $context ); |
| 228 | - } |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Alias for self::get_parent_invoice_id(). |
|
| 232 | + * |
|
| 233 | + * @since 1.0.0 |
|
| 234 | + * @return int |
|
| 235 | + */ |
|
| 236 | + public function get_original_payment_id( $context = 'view' ) { |
|
| 237 | + return $this->get_parent_invoice_id( $context ); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Get parent invoice. |
|
| 242 | + * |
|
| 243 | + * @since 1.0.19 |
|
| 244 | + * @param string $context View or edit context. |
|
| 245 | + * @return WPInv_Invoice |
|
| 246 | + */ |
|
| 247 | + public function get_parent_invoice( $context = 'view' ) { |
|
| 248 | + return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * Alias for self::get_parent_invoice(). |
|
| 253 | + * |
|
| 254 | + * @since 1.0.19 |
|
| 255 | + * @param string $context View or edit context. |
|
| 256 | + * @return WPInv_Invoice |
|
| 257 | + */ |
|
| 258 | + public function get_parent_payment( $context = 'view' ) { |
|
| 259 | + return $this->get_parent_invoice( $context ); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * Get subscription's product id. |
|
| 264 | + * |
|
| 265 | + * @since 1.0.19 |
|
| 266 | + * @param string $context View or edit context. |
|
| 267 | + * @return int |
|
| 268 | + */ |
|
| 269 | + public function get_product_id( $context = 'view' ) { |
|
| 270 | + return (int) $this->get_prop( 'product_id', $context ); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * Get the subscription product. |
|
| 275 | + * |
|
| 276 | + * @since 1.0.19 |
|
| 277 | + * @param string $context View or edit context. |
|
| 278 | + * @return WPInv_Item |
|
| 279 | + */ |
|
| 280 | + public function get_product( $context = 'view' ) { |
|
| 281 | + return new WPInv_Item( $this->get_product_id( $context ) ); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * Get parent invoice's gateway. |
|
| 286 | + * |
|
| 287 | + * Here for backwards compatibility. |
|
| 288 | + * |
|
| 289 | + * @since 1.0.19 |
|
| 290 | + * @param string $context View or edit context. |
|
| 291 | + * @return string |
|
| 292 | + */ |
|
| 293 | + public function get_gateway( $context = 'view' ) { |
|
| 294 | + return $this->get_parent_invoice( $context )->get_gateway(); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + /** |
|
| 298 | + * Get the period of a renewal. |
|
| 299 | + * |
|
| 300 | + * @since 1.0.19 |
|
| 301 | + * @param string $context View or edit context. |
|
| 302 | + * @return string |
|
| 303 | + */ |
|
| 304 | + public function get_period( $context = 'view' ) { |
|
| 305 | + return $this->get_prop( 'period', $context ); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * Get number of periods each renewal is valid for. |
|
| 310 | + * |
|
| 311 | + * @since 1.0.19 |
|
| 312 | + * @param string $context View or edit context. |
|
| 313 | + * @return int |
|
| 314 | + */ |
|
| 315 | + public function get_frequency( $context = 'view' ) { |
|
| 316 | + return (int) $this->get_prop( 'frequency', $context ); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Get the initial amount for the subscription. |
|
| 321 | + * |
|
| 322 | + * @since 1.0.19 |
|
| 323 | + * @param string $context View or edit context. |
|
| 324 | + * @return float |
|
| 325 | + */ |
|
| 326 | + public function get_initial_amount( $context = 'view' ) { |
|
| 327 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * Get the recurring amount for the subscription. |
|
| 332 | + * |
|
| 333 | + * @since 1.0.19 |
|
| 334 | + * @param string $context View or edit context. |
|
| 335 | + * @return float |
|
| 336 | + */ |
|
| 337 | + public function get_recurring_amount( $context = 'view' ) { |
|
| 338 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * Get number of times that this subscription can be renewed. |
|
| 343 | + * |
|
| 344 | + * @since 1.0.19 |
|
| 345 | + * @param string $context View or edit context. |
|
| 346 | + * @return int |
|
| 347 | + */ |
|
| 348 | + public function get_bill_times( $context = 'view' ) { |
|
| 349 | + return (int) $this->get_prop( 'bill_times', $context ); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Get transaction id of this subscription's parent invoice. |
|
| 354 | + * |
|
| 355 | + * @since 1.0.19 |
|
| 356 | + * @param string $context View or edit context. |
|
| 357 | + * @return string |
|
| 358 | + */ |
|
| 359 | + public function get_transaction_id( $context = 'view' ) { |
|
| 360 | + return $this->get_prop( 'transaction_id', $context ); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * Get the date that the subscription was created. |
|
| 365 | + * |
|
| 366 | + * @since 1.0.19 |
|
| 367 | + * @param string $context View or edit context. |
|
| 368 | + * @return string |
|
| 369 | + */ |
|
| 370 | + public function get_created( $context = 'view' ) { |
|
| 371 | + return $this->get_prop( 'created', $context ); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * Alias for self::get_created(). |
|
| 376 | + * |
|
| 377 | + * @since 1.0.19 |
|
| 378 | + * @param string $context View or edit context. |
|
| 379 | + * @return string |
|
| 380 | + */ |
|
| 381 | + public function get_date_created( $context = 'view' ) { |
|
| 382 | + return $this->get_created( $context ); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Retrieves the creation date in a timestamp |
|
| 387 | + * |
|
| 388 | + * @since 1.0.0 |
|
| 389 | + * @return int |
|
| 390 | + */ |
|
| 391 | + public function get_time_created() { |
|
| 392 | + $created = $this->get_date_created(); |
|
| 393 | + return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * Get GMT date when the subscription was created. |
|
| 398 | + * |
|
| 399 | + * @since 1.0.19 |
|
| 400 | + * @param string $context View or edit context. |
|
| 401 | + * @return string |
|
| 402 | + */ |
|
| 403 | + public function get_date_created_gmt( $context = 'view' ) { |
|
| 404 | + $date = $this->get_date_created( $context ); |
|
| 405 | + |
|
| 406 | + if ( $date ) { |
|
| 407 | + $date = get_gmt_from_date( $date ); |
|
| 408 | + } |
|
| 409 | + return $date; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * Get the date that the subscription will renew. |
|
| 414 | + * |
|
| 415 | + * @since 1.0.19 |
|
| 416 | + * @param string $context View or edit context. |
|
| 417 | + * @return string |
|
| 418 | + */ |
|
| 419 | + public function get_next_renewal_date( $context = 'view' ) { |
|
| 420 | + return $this->get_prop( 'expiration', $context ); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * Alias for self::get_next_renewal_date(). |
|
| 425 | + * |
|
| 426 | + * @since 1.0.19 |
|
| 427 | + * @param string $context View or edit context. |
|
| 428 | + * @return string |
|
| 429 | + */ |
|
| 430 | + public function get_expiration( $context = 'view' ) { |
|
| 431 | + return $this->get_next_renewal_date( $context ); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * Retrieves the expiration date in a timestamp |
|
| 436 | + * |
|
| 437 | + * @since 1.0.0 |
|
| 438 | + * @return int |
|
| 439 | + */ |
|
| 440 | + public function get_expiration_time() { |
|
| 441 | + $expiration = $this->get_expiration(); |
|
| 442 | + |
|
| 443 | + if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 444 | + return current_time( 'timestamp' ); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
| 448 | + return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * Get GMT date when the subscription will renew. |
|
| 453 | + * |
|
| 454 | + * @since 1.0.19 |
|
| 455 | + * @param string $context View or edit context. |
|
| 456 | + * @return string |
|
| 457 | + */ |
|
| 458 | + public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
| 459 | + $date = $this->get_next_renewal_date( $context ); |
|
| 460 | + |
|
| 461 | + if ( $date ) { |
|
| 462 | + $date = get_gmt_from_date( $date ); |
|
| 463 | + } |
|
| 464 | + return $date; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Get the subscription's trial period. |
|
| 469 | + * |
|
| 470 | + * @since 1.0.19 |
|
| 471 | + * @param string $context View or edit context. |
|
| 472 | + * @return string |
|
| 473 | + */ |
|
| 474 | + public function get_trial_period( $context = 'view' ) { |
|
| 475 | + return $this->get_prop( 'trial_period', $context ); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * Get the subscription's status. |
|
| 480 | + * |
|
| 481 | + * @since 1.0.19 |
|
| 482 | + * @param string $context View or edit context. |
|
| 483 | + * @return string |
|
| 484 | + */ |
|
| 485 | + public function get_status( $context = 'view' ) { |
|
| 486 | + return $this->get_prop( 'status', $context ); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * Get the subscription's profile id. |
|
| 491 | + * |
|
| 492 | + * @since 1.0.19 |
|
| 493 | + * @param string $context View or edit context. |
|
| 494 | + * @return string |
|
| 495 | + */ |
|
| 496 | + public function get_profile_id( $context = 'view' ) { |
|
| 497 | + return $this->get_prop( 'profile_id', $context ); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + /* |
|
| 501 | + |-------------------------------------------------------------------------- |
|
| 502 | + | Setters |
|
| 503 | + |-------------------------------------------------------------------------- |
|
| 504 | + */ |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * Set customer id. |
|
| 508 | + * |
|
| 509 | + * @since 1.0.19 |
|
| 510 | + * @param int $value The customer's id. |
|
| 511 | + */ |
|
| 512 | + public function set_customer_id( $value ) { |
|
| 513 | + $this->set_prop( 'customer_id', (int) $value ); |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + /** |
|
| 517 | + * Set parent invoice id. |
|
| 518 | + * |
|
| 519 | + * @since 1.0.19 |
|
| 520 | + * @param int $value The parent invoice id. |
|
| 521 | + */ |
|
| 522 | + public function set_parent_invoice_id( $value ) { |
|
| 523 | + $this->set_prop( 'parent_payment_id', (int) $value ); |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * Alias for self::set_parent_invoice_id(). |
|
| 528 | + * |
|
| 529 | + * @since 1.0.19 |
|
| 530 | + * @param int $value The parent invoice id. |
|
| 531 | + */ |
|
| 532 | + public function set_parent_payment_id( $value ) { |
|
| 533 | + $this->set_parent_invoice_id( $value ); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | + * Alias for self::set_parent_invoice_id(). |
|
| 538 | + * |
|
| 539 | + * @since 1.0.19 |
|
| 540 | + * @param int $value The parent invoice id. |
|
| 541 | + */ |
|
| 542 | + public function set_original_payment_id( $value ) { |
|
| 543 | + $this->set_parent_invoice_id( $value ); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Set subscription's product id. |
|
| 548 | + * |
|
| 549 | + * @since 1.0.19 |
|
| 550 | + * @param int $value The subscription product id. |
|
| 551 | + */ |
|
| 552 | + public function set_product_id( $value ) { |
|
| 553 | + $this->set_prop( 'product_id', (int) $value ); |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * Set the period of a renewal. |
|
| 558 | + * |
|
| 559 | + * @since 1.0.19 |
|
| 560 | + * @param string $value The renewal period. |
|
| 561 | + */ |
|
| 562 | + public function set_period( $value ) { |
|
| 563 | + $this->set_prop( 'period', $value ); |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * Set number of periods each renewal is valid for. |
|
| 568 | + * |
|
| 569 | + * @since 1.0.19 |
|
| 570 | + * @param int $value The subscription frequency. |
|
| 571 | + */ |
|
| 572 | + public function set_frequency( $value ) { |
|
| 573 | + $value = empty( $value ) ? 1 : (int) $value; |
|
| 574 | + $this->set_prop( 'frequency', absint( $value ) ); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * Set the initial amount for the subscription. |
|
| 579 | + * |
|
| 580 | + * @since 1.0.19 |
|
| 581 | + * @param float $value The initial subcription amount. |
|
| 582 | + */ |
|
| 583 | + public function set_initial_amount( $value ) { |
|
| 584 | + $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * Set the recurring amount for the subscription. |
|
| 589 | + * |
|
| 590 | + * @since 1.0.19 |
|
| 591 | + * @param float $value The recurring subcription amount. |
|
| 592 | + */ |
|
| 593 | + public function set_recurring_amount( $value ) { |
|
| 594 | + $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + /** |
|
| 598 | + * Set number of times that this subscription can be renewed. |
|
| 599 | + * |
|
| 600 | + * @since 1.0.19 |
|
| 601 | + * @param int $value Bill times. |
|
| 602 | + */ |
|
| 603 | + public function set_bill_times( $value ) { |
|
| 604 | + $this->set_prop( 'bill_times', (int) $value ); |
|
| 605 | + } |
|
| 229 | 606 | |
| 230 | - /** |
|
| 231 | - * Alias for self::get_parent_invoice_id(). |
|
| 607 | + /** |
|
| 608 | + * Get transaction id of this subscription's parent invoice. |
|
| 232 | 609 | * |
| 233 | - * @since 1.0.0 |
|
| 234 | - * @return int |
|
| 610 | + * @since 1.0.19 |
|
| 611 | + * @param string $value Bill times. |
|
| 235 | 612 | */ |
| 236 | - public function get_original_payment_id( $context = 'view' ) { |
|
| 237 | - return $this->get_parent_invoice_id( $context ); |
|
| 613 | + public function set_transaction_id( $value ) { |
|
| 614 | + $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
| 238 | 615 | } |
| 239 | 616 | |
| 240 | - /** |
|
| 241 | - * Get parent invoice. |
|
| 242 | - * |
|
| 243 | - * @since 1.0.19 |
|
| 244 | - * @param string $context View or edit context. |
|
| 245 | - * @return WPInv_Invoice |
|
| 246 | - */ |
|
| 247 | - public function get_parent_invoice( $context = 'view' ) { |
|
| 248 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * Alias for self::get_parent_invoice(). |
|
| 253 | - * |
|
| 254 | - * @since 1.0.19 |
|
| 255 | - * @param string $context View or edit context. |
|
| 256 | - * @return WPInv_Invoice |
|
| 257 | - */ |
|
| 258 | - public function get_parent_payment( $context = 'view' ) { |
|
| 259 | - return $this->get_parent_invoice( $context ); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * Get subscription's product id. |
|
| 264 | - * |
|
| 265 | - * @since 1.0.19 |
|
| 266 | - * @param string $context View or edit context. |
|
| 267 | - * @return int |
|
| 268 | - */ |
|
| 269 | - public function get_product_id( $context = 'view' ) { |
|
| 270 | - return (int) $this->get_prop( 'product_id', $context ); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * Get the subscription product. |
|
| 275 | - * |
|
| 276 | - * @since 1.0.19 |
|
| 277 | - * @param string $context View or edit context. |
|
| 278 | - * @return WPInv_Item |
|
| 279 | - */ |
|
| 280 | - public function get_product( $context = 'view' ) { |
|
| 281 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * Get parent invoice's gateway. |
|
| 286 | - * |
|
| 287 | - * Here for backwards compatibility. |
|
| 288 | - * |
|
| 289 | - * @since 1.0.19 |
|
| 290 | - * @param string $context View or edit context. |
|
| 291 | - * @return string |
|
| 292 | - */ |
|
| 293 | - public function get_gateway( $context = 'view' ) { |
|
| 294 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - /** |
|
| 298 | - * Get the period of a renewal. |
|
| 299 | - * |
|
| 300 | - * @since 1.0.19 |
|
| 301 | - * @param string $context View or edit context. |
|
| 302 | - * @return string |
|
| 303 | - */ |
|
| 304 | - public function get_period( $context = 'view' ) { |
|
| 305 | - return $this->get_prop( 'period', $context ); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * Get number of periods each renewal is valid for. |
|
| 310 | - * |
|
| 311 | - * @since 1.0.19 |
|
| 312 | - * @param string $context View or edit context. |
|
| 313 | - * @return int |
|
| 314 | - */ |
|
| 315 | - public function get_frequency( $context = 'view' ) { |
|
| 316 | - return (int) $this->get_prop( 'frequency', $context ); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Get the initial amount for the subscription. |
|
| 321 | - * |
|
| 322 | - * @since 1.0.19 |
|
| 323 | - * @param string $context View or edit context. |
|
| 324 | - * @return float |
|
| 325 | - */ |
|
| 326 | - public function get_initial_amount( $context = 'view' ) { |
|
| 327 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * Get the recurring amount for the subscription. |
|
| 332 | - * |
|
| 333 | - * @since 1.0.19 |
|
| 334 | - * @param string $context View or edit context. |
|
| 335 | - * @return float |
|
| 336 | - */ |
|
| 337 | - public function get_recurring_amount( $context = 'view' ) { |
|
| 338 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * Get number of times that this subscription can be renewed. |
|
| 343 | - * |
|
| 344 | - * @since 1.0.19 |
|
| 345 | - * @param string $context View or edit context. |
|
| 346 | - * @return int |
|
| 347 | - */ |
|
| 348 | - public function get_bill_times( $context = 'view' ) { |
|
| 349 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Get transaction id of this subscription's parent invoice. |
|
| 354 | - * |
|
| 355 | - * @since 1.0.19 |
|
| 356 | - * @param string $context View or edit context. |
|
| 357 | - * @return string |
|
| 358 | - */ |
|
| 359 | - public function get_transaction_id( $context = 'view' ) { |
|
| 360 | - return $this->get_prop( 'transaction_id', $context ); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * Get the date that the subscription was created. |
|
| 365 | - * |
|
| 366 | - * @since 1.0.19 |
|
| 367 | - * @param string $context View or edit context. |
|
| 368 | - * @return string |
|
| 369 | - */ |
|
| 370 | - public function get_created( $context = 'view' ) { |
|
| 371 | - return $this->get_prop( 'created', $context ); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * Alias for self::get_created(). |
|
| 376 | - * |
|
| 377 | - * @since 1.0.19 |
|
| 378 | - * @param string $context View or edit context. |
|
| 379 | - * @return string |
|
| 380 | - */ |
|
| 381 | - public function get_date_created( $context = 'view' ) { |
|
| 382 | - return $this->get_created( $context ); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Retrieves the creation date in a timestamp |
|
| 387 | - * |
|
| 388 | - * @since 1.0.0 |
|
| 389 | - * @return int |
|
| 390 | - */ |
|
| 391 | - public function get_time_created() { |
|
| 392 | - $created = $this->get_date_created(); |
|
| 393 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * Get GMT date when the subscription was created. |
|
| 398 | - * |
|
| 399 | - * @since 1.0.19 |
|
| 400 | - * @param string $context View or edit context. |
|
| 401 | - * @return string |
|
| 402 | - */ |
|
| 403 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 404 | - $date = $this->get_date_created( $context ); |
|
| 617 | + /** |
|
| 618 | + * Set date when this subscription started. |
|
| 619 | + * |
|
| 620 | + * @since 1.0.19 |
|
| 621 | + * @param string $value strtotime compliant date. |
|
| 622 | + */ |
|
| 623 | + public function set_created( $value ) { |
|
| 624 | + $date = strtotime( $value ); |
|
| 405 | 625 | |
| 406 | - if ( $date ) { |
|
| 407 | - $date = get_gmt_from_date( $date ); |
|
| 626 | + if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 627 | + $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
| 628 | + return; |
|
| 408 | 629 | } |
| 409 | - return $date; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * Get the date that the subscription will renew. |
|
| 414 | - * |
|
| 415 | - * @since 1.0.19 |
|
| 416 | - * @param string $context View or edit context. |
|
| 417 | - * @return string |
|
| 418 | - */ |
|
| 419 | - public function get_next_renewal_date( $context = 'view' ) { |
|
| 420 | - return $this->get_prop( 'expiration', $context ); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * Alias for self::get_next_renewal_date(). |
|
| 425 | - * |
|
| 426 | - * @since 1.0.19 |
|
| 427 | - * @param string $context View or edit context. |
|
| 428 | - * @return string |
|
| 429 | - */ |
|
| 430 | - public function get_expiration( $context = 'view' ) { |
|
| 431 | - return $this->get_next_renewal_date( $context ); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * Retrieves the expiration date in a timestamp |
|
| 436 | - * |
|
| 437 | - * @since 1.0.0 |
|
| 438 | - * @return int |
|
| 439 | - */ |
|
| 440 | - public function get_expiration_time() { |
|
| 441 | - $expiration = $this->get_expiration(); |
|
| 442 | - |
|
| 443 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 444 | - return current_time( 'timestamp' ); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
| 448 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * Get GMT date when the subscription will renew. |
|
| 453 | - * |
|
| 454 | - * @since 1.0.19 |
|
| 455 | - * @param string $context View or edit context. |
|
| 456 | - * @return string |
|
| 457 | - */ |
|
| 458 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
| 459 | - $date = $this->get_next_renewal_date( $context ); |
|
| 460 | 630 | |
| 461 | - if ( $date ) { |
|
| 462 | - $date = get_gmt_from_date( $date ); |
|
| 463 | - } |
|
| 464 | - return $date; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Get the subscription's trial period. |
|
| 469 | - * |
|
| 470 | - * @since 1.0.19 |
|
| 471 | - * @param string $context View or edit context. |
|
| 472 | - * @return string |
|
| 473 | - */ |
|
| 474 | - public function get_trial_period( $context = 'view' ) { |
|
| 475 | - return $this->get_prop( 'trial_period', $context ); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * Get the subscription's status. |
|
| 480 | - * |
|
| 481 | - * @since 1.0.19 |
|
| 482 | - * @param string $context View or edit context. |
|
| 483 | - * @return string |
|
| 484 | - */ |
|
| 485 | - public function get_status( $context = 'view' ) { |
|
| 486 | - return $this->get_prop( 'status', $context ); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * Get the subscription's profile id. |
|
| 491 | - * |
|
| 492 | - * @since 1.0.19 |
|
| 493 | - * @param string $context View or edit context. |
|
| 494 | - * @return string |
|
| 495 | - */ |
|
| 496 | - public function get_profile_id( $context = 'view' ) { |
|
| 497 | - return $this->get_prop( 'profile_id', $context ); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - /* |
|
| 501 | - |-------------------------------------------------------------------------- |
|
| 502 | - | Setters |
|
| 503 | - |-------------------------------------------------------------------------- |
|
| 504 | - */ |
|
| 631 | + $this->set_prop( 'created', '' ); |
|
| 505 | 632 | |
| 506 | - /** |
|
| 507 | - * Set customer id. |
|
| 508 | - * |
|
| 509 | - * @since 1.0.19 |
|
| 510 | - * @param int $value The customer's id. |
|
| 511 | - */ |
|
| 512 | - public function set_customer_id( $value ) { |
|
| 513 | - $this->set_prop( 'customer_id', (int) $value ); |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - /** |
|
| 517 | - * Set parent invoice id. |
|
| 518 | - * |
|
| 519 | - * @since 1.0.19 |
|
| 520 | - * @param int $value The parent invoice id. |
|
| 521 | - */ |
|
| 522 | - public function set_parent_invoice_id( $value ) { |
|
| 523 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * Alias for self::set_parent_invoice_id(). |
|
| 528 | - * |
|
| 529 | - * @since 1.0.19 |
|
| 530 | - * @param int $value The parent invoice id. |
|
| 531 | - */ |
|
| 532 | - public function set_parent_payment_id( $value ) { |
|
| 533 | - $this->set_parent_invoice_id( $value ); |
|
| 534 | - } |
|
| 633 | + } |
|
| 535 | 634 | |
| 536 | - /** |
|
| 537 | - * Alias for self::set_parent_invoice_id(). |
|
| 635 | + /** |
|
| 636 | + * Alias for self::set_created(). |
|
| 538 | 637 | * |
| 539 | 638 | * @since 1.0.19 |
| 540 | - * @param int $value The parent invoice id. |
|
| 639 | + * @param string $value strtotime compliant date. |
|
| 541 | 640 | */ |
| 542 | - public function set_original_payment_id( $value ) { |
|
| 543 | - $this->set_parent_invoice_id( $value ); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Set subscription's product id. |
|
| 548 | - * |
|
| 549 | - * @since 1.0.19 |
|
| 550 | - * @param int $value The subscription product id. |
|
| 551 | - */ |
|
| 552 | - public function set_product_id( $value ) { |
|
| 553 | - $this->set_prop( 'product_id', (int) $value ); |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * Set the period of a renewal. |
|
| 558 | - * |
|
| 559 | - * @since 1.0.19 |
|
| 560 | - * @param string $value The renewal period. |
|
| 561 | - */ |
|
| 562 | - public function set_period( $value ) { |
|
| 563 | - $this->set_prop( 'period', $value ); |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * Set number of periods each renewal is valid for. |
|
| 568 | - * |
|
| 569 | - * @since 1.0.19 |
|
| 570 | - * @param int $value The subscription frequency. |
|
| 571 | - */ |
|
| 572 | - public function set_frequency( $value ) { |
|
| 573 | - $value = empty( $value ) ? 1 : (int) $value; |
|
| 574 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * Set the initial amount for the subscription. |
|
| 579 | - * |
|
| 580 | - * @since 1.0.19 |
|
| 581 | - * @param float $value The initial subcription amount. |
|
| 582 | - */ |
|
| 583 | - public function set_initial_amount( $value ) { |
|
| 584 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * Set the recurring amount for the subscription. |
|
| 589 | - * |
|
| 590 | - * @since 1.0.19 |
|
| 591 | - * @param float $value The recurring subcription amount. |
|
| 592 | - */ |
|
| 593 | - public function set_recurring_amount( $value ) { |
|
| 594 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - /** |
|
| 598 | - * Set number of times that this subscription can be renewed. |
|
| 599 | - * |
|
| 600 | - * @since 1.0.19 |
|
| 601 | - * @param int $value Bill times. |
|
| 602 | - */ |
|
| 603 | - public function set_bill_times( $value ) { |
|
| 604 | - $this->set_prop( 'bill_times', (int) $value ); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - /** |
|
| 608 | - * Get transaction id of this subscription's parent invoice. |
|
| 609 | - * |
|
| 610 | - * @since 1.0.19 |
|
| 611 | - * @param string $value Bill times. |
|
| 612 | - */ |
|
| 613 | - public function set_transaction_id( $value ) { |
|
| 614 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - /** |
|
| 618 | - * Set date when this subscription started. |
|
| 619 | - * |
|
| 620 | - * @since 1.0.19 |
|
| 621 | - * @param string $value strtotime compliant date. |
|
| 622 | - */ |
|
| 623 | - public function set_created( $value ) { |
|
| 641 | + public function set_date_created( $value ) { |
|
| 642 | + $this->set_created( $value ); |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + /** |
|
| 646 | + * Set the date that the subscription will renew. |
|
| 647 | + * |
|
| 648 | + * @since 1.0.19 |
|
| 649 | + * @param string $value strtotime compliant date. |
|
| 650 | + */ |
|
| 651 | + public function set_next_renewal_date( $value ) { |
|
| 624 | 652 | $date = strtotime( $value ); |
| 625 | 653 | |
| 626 | 654 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
| 627 | - $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
| 655 | + $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
| 628 | 656 | return; |
| 629 | 657 | } |
| 630 | 658 | |
| 631 | - $this->set_prop( 'created', '' ); |
|
| 659 | + $this->set_prop( 'expiration', '' ); |
|
| 632 | 660 | |
| 633 | - } |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + /** |
|
| 664 | + * Alias for self::set_next_renewal_date(). |
|
| 665 | + * |
|
| 666 | + * @since 1.0.19 |
|
| 667 | + * @param string $value strtotime compliant date. |
|
| 668 | + */ |
|
| 669 | + public function set_expiration( $value ) { |
|
| 670 | + $this->set_next_renewal_date( $value ); |
|
| 671 | + } |
|
| 634 | 672 | |
| 635 | - /** |
|
| 636 | - * Alias for self::set_created(). |
|
| 637 | - * |
|
| 638 | - * @since 1.0.19 |
|
| 639 | - * @param string $value strtotime compliant date. |
|
| 640 | - */ |
|
| 641 | - public function set_date_created( $value ) { |
|
| 642 | - $this->set_created( $value ); |
|
| 673 | + /** |
|
| 674 | + * Set the subscription's trial period. |
|
| 675 | + * |
|
| 676 | + * @since 1.0.19 |
|
| 677 | + * @param string $value trial period e.g 1 year. |
|
| 678 | + */ |
|
| 679 | + public function set_trial_period( $value ) { |
|
| 680 | + $this->set_prop( 'trial_period', $value ); |
|
| 643 | 681 | } |
| 644 | 682 | |
| 645 | - /** |
|
| 646 | - * Set the date that the subscription will renew. |
|
| 647 | - * |
|
| 648 | - * @since 1.0.19 |
|
| 649 | - * @param string $value strtotime compliant date. |
|
| 650 | - */ |
|
| 651 | - public function set_next_renewal_date( $value ) { |
|
| 652 | - $date = strtotime( $value ); |
|
| 683 | + /** |
|
| 684 | + * Set the subscription's status. |
|
| 685 | + * |
|
| 686 | + * @since 1.0.19 |
|
| 687 | + * @param string $new_status New subscription status. |
|
| 688 | + */ |
|
| 689 | + public function set_status( $new_status ) { |
|
| 653 | 690 | |
| 654 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 655 | - $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
| 691 | + // Abort if this is not a valid status; |
|
| 692 | + if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
| 656 | 693 | return; |
| 657 | - } |
|
| 658 | - |
|
| 659 | - $this->set_prop( 'expiration', '' ); |
|
| 660 | - |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - /** |
|
| 664 | - * Alias for self::set_next_renewal_date(). |
|
| 665 | - * |
|
| 666 | - * @since 1.0.19 |
|
| 667 | - * @param string $value strtotime compliant date. |
|
| 668 | - */ |
|
| 669 | - public function set_expiration( $value ) { |
|
| 670 | - $this->set_next_renewal_date( $value ); |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - /** |
|
| 674 | - * Set the subscription's trial period. |
|
| 675 | - * |
|
| 676 | - * @since 1.0.19 |
|
| 677 | - * @param string $value trial period e.g 1 year. |
|
| 678 | - */ |
|
| 679 | - public function set_trial_period( $value ) { |
|
| 680 | - $this->set_prop( 'trial_period', $value ); |
|
| 681 | - } |
|
| 682 | - |
|
| 683 | - /** |
|
| 684 | - * Set the subscription's status. |
|
| 685 | - * |
|
| 686 | - * @since 1.0.19 |
|
| 687 | - * @param string $new_status New subscription status. |
|
| 688 | - */ |
|
| 689 | - public function set_status( $new_status ) { |
|
| 690 | - |
|
| 691 | - // Abort if this is not a valid status; |
|
| 692 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
| 693 | - return; |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - $old_status = $this->get_status(); |
|
| 697 | - $this->set_prop( 'status', $new_status ); |
|
| 698 | - |
|
| 699 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 700 | - $this->status_transition = array( |
|
| 701 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 702 | - 'to' => $new_status, |
|
| 703 | - ); |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - } |
|
| 707 | - |
|
| 708 | - /** |
|
| 709 | - * Set the subscription's (remote) profile id. |
|
| 710 | - * |
|
| 711 | - * @since 1.0.19 |
|
| 712 | - * @param string $value the remote profile id. |
|
| 713 | - */ |
|
| 714 | - public function set_profile_id( $value ) { |
|
| 715 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - /* |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + $old_status = $this->get_status(); |
|
| 697 | + $this->set_prop( 'status', $new_status ); |
|
| 698 | + |
|
| 699 | + if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 700 | + $this->status_transition = array( |
|
| 701 | + 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 702 | + 'to' => $new_status, |
|
| 703 | + ); |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + } |
|
| 707 | + |
|
| 708 | + /** |
|
| 709 | + * Set the subscription's (remote) profile id. |
|
| 710 | + * |
|
| 711 | + * @since 1.0.19 |
|
| 712 | + * @param string $value the remote profile id. |
|
| 713 | + */ |
|
| 714 | + public function set_profile_id( $value ) { |
|
| 715 | + $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + /* |
|
| 719 | 719 | |-------------------------------------------------------------------------- |
| 720 | 720 | | Boolean methods |
| 721 | 721 | |-------------------------------------------------------------------------- |
@@ -724,55 +724,55 @@ discard block |
||
| 724 | 724 | | |
| 725 | 725 | */ |
| 726 | 726 | |
| 727 | - /** |
|
| 727 | + /** |
|
| 728 | 728 | * Checks if the subscription has a given status. |
| 729 | - * |
|
| 730 | - * @param string|array String or array of strings to check for. |
|
| 731 | - * @return bool |
|
| 729 | + * |
|
| 730 | + * @param string|array String or array of strings to check for. |
|
| 731 | + * @return bool |
|
| 732 | 732 | */ |
| 733 | 733 | public function has_status( $status ) { |
| 734 | 734 | return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) ); |
| 735 | - } |
|
| 735 | + } |
|
| 736 | 736 | |
| 737 | - /** |
|
| 737 | + /** |
|
| 738 | 738 | * Checks if the subscription has a trial period. |
| 739 | - * |
|
| 740 | - * @return bool |
|
| 739 | + * |
|
| 740 | + * @return bool |
|
| 741 | 741 | */ |
| 742 | 742 | public function has_trial_period() { |
| 743 | - $period = $this->get_trial_period(); |
|
| 743 | + $period = $this->get_trial_period(); |
|
| 744 | 744 | return ! empty( $period ); |
| 745 | - } |
|
| 746 | - |
|
| 747 | - /** |
|
| 748 | - * Is the subscription active? |
|
| 749 | - * |
|
| 750 | - * @return bool |
|
| 751 | - */ |
|
| 752 | - public function is_active() { |
|
| 753 | - return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - /** |
|
| 757 | - * Is the subscription expired? |
|
| 758 | - * |
|
| 759 | - * @return bool |
|
| 760 | - */ |
|
| 761 | - public function is_expired() { |
|
| 762 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - /** |
|
| 766 | - * Is this the last renewals? |
|
| 767 | - * |
|
| 768 | - * @return bool |
|
| 769 | - */ |
|
| 770 | - public function is_last_renewal() { |
|
| 771 | - $max_bills = $this->get_bill_times(); |
|
| 772 | - return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - /* |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + /** |
|
| 748 | + * Is the subscription active? |
|
| 749 | + * |
|
| 750 | + * @return bool |
|
| 751 | + */ |
|
| 752 | + public function is_active() { |
|
| 753 | + return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + /** |
|
| 757 | + * Is the subscription expired? |
|
| 758 | + * |
|
| 759 | + * @return bool |
|
| 760 | + */ |
|
| 761 | + public function is_expired() { |
|
| 762 | + return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + /** |
|
| 766 | + * Is this the last renewals? |
|
| 767 | + * |
|
| 768 | + * @return bool |
|
| 769 | + */ |
|
| 770 | + public function is_last_renewal() { |
|
| 771 | + $max_bills = $this->get_bill_times(); |
|
| 772 | + return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + /* |
|
| 776 | 776 | |-------------------------------------------------------------------------- |
| 777 | 777 | | Additional methods |
| 778 | 778 | |-------------------------------------------------------------------------- |
@@ -781,27 +781,27 @@ discard block |
||
| 781 | 781 | | |
| 782 | 782 | */ |
| 783 | 783 | |
| 784 | - /** |
|
| 785 | - * Backwards compatibilty. |
|
| 786 | - */ |
|
| 787 | - public function create( $data = array() ) { |
|
| 784 | + /** |
|
| 785 | + * Backwards compatibilty. |
|
| 786 | + */ |
|
| 787 | + public function create( $data = array() ) { |
|
| 788 | 788 | |
| 789 | - // Set the properties. |
|
| 790 | - if ( is_array( $data ) ) { |
|
| 791 | - $this->set_props( $data ); |
|
| 792 | - } |
|
| 789 | + // Set the properties. |
|
| 790 | + if ( is_array( $data ) ) { |
|
| 791 | + $this->set_props( $data ); |
|
| 792 | + } |
|
| 793 | 793 | |
| 794 | - // Save the item. |
|
| 795 | - return $this->save(); |
|
| 794 | + // Save the item. |
|
| 795 | + return $this->save(); |
|
| 796 | 796 | |
| 797 | - } |
|
| 797 | + } |
|
| 798 | 798 | |
| 799 | - /** |
|
| 800 | - * Backwards compatibilty. |
|
| 801 | - */ |
|
| 802 | - public function update( $args = array() ) { |
|
| 803 | - return $this->create( $args ); |
|
| 804 | - } |
|
| 799 | + /** |
|
| 800 | + * Backwards compatibilty. |
|
| 801 | + */ |
|
| 802 | + public function update( $args = array() ) { |
|
| 803 | + return $this->create( $args ); |
|
| 804 | + } |
|
| 805 | 805 | |
| 806 | 806 | /** |
| 807 | 807 | * Retrieve renewal payments for a subscription |
@@ -811,22 +811,22 @@ discard block |
||
| 811 | 811 | */ |
| 812 | 812 | public function get_child_payments( $hide_pending = true ) { |
| 813 | 813 | |
| 814 | - $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
| 814 | + $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
| 815 | 815 | |
| 816 | - if ( ! $hide_pending ) { |
|
| 817 | - $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
| 818 | - } |
|
| 816 | + if ( ! $hide_pending ) { |
|
| 817 | + $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
| 818 | + } |
|
| 819 | 819 | |
| 820 | 820 | return get_posts( |
| 821 | - array( |
|
| 822 | - 'post_parent' => $this->get_parent_payment_id(), |
|
| 823 | - 'numberposts' => -1, |
|
| 824 | - 'post_status' => $statuses, |
|
| 825 | - 'orderby' => 'ID', |
|
| 826 | - 'order' => 'DESC', |
|
| 827 | - 'post_type' => 'wpi_invoice' |
|
| 828 | - ) |
|
| 829 | - ); |
|
| 821 | + array( |
|
| 822 | + 'post_parent' => $this->get_parent_payment_id(), |
|
| 823 | + 'numberposts' => -1, |
|
| 824 | + 'post_status' => $statuses, |
|
| 825 | + 'orderby' => 'ID', |
|
| 826 | + 'order' => 'DESC', |
|
| 827 | + 'post_type' => 'wpi_invoice' |
|
| 828 | + ) |
|
| 829 | + ); |
|
| 830 | 830 | } |
| 831 | 831 | |
| 832 | 832 | /** |
@@ -836,16 +836,16 @@ discard block |
||
| 836 | 836 | * @return int |
| 837 | 837 | */ |
| 838 | 838 | public function get_total_payments() { |
| 839 | - global $wpdb; |
|
| 839 | + global $wpdb; |
|
| 840 | 840 | |
| 841 | - $count = (int) $wpdb->get_var( |
|
| 842 | - $wpdb->prepare( |
|
| 843 | - "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
| 844 | - $this->get_parent_invoice_id() |
|
| 845 | - ) |
|
| 846 | - ); |
|
| 841 | + $count = (int) $wpdb->get_var( |
|
| 842 | + $wpdb->prepare( |
|
| 843 | + "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
| 844 | + $this->get_parent_invoice_id() |
|
| 845 | + ) |
|
| 846 | + ); |
|
| 847 | 847 | |
| 848 | - // Maybe include parent invoice. |
|
| 848 | + // Maybe include parent invoice. |
|
| 849 | 849 | if ( $this->get_parent_payment()->is_paid() ) { |
| 850 | 850 | $count++; |
| 851 | 851 | } |
@@ -874,57 +874,57 @@ discard block |
||
| 874 | 874 | * |
| 875 | 875 | * @since 2.4 |
| 876 | 876 | * @param array $args Array of values for the payment, including amount and transaction ID |
| 877 | - * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
| 877 | + * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
| 878 | 878 | * @return bool |
| 879 | 879 | */ |
| 880 | 880 | public function add_payment( $args = array(), $invoice = false ) { |
| 881 | 881 | |
| 882 | - // Process each payment once. |
|
| 882 | + // Process each payment once. |
|
| 883 | 883 | if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
| 884 | 884 | return false; |
| 885 | 885 | } |
| 886 | 886 | |
| 887 | - // Are we creating a new invoice? |
|
| 888 | - if ( empty( $invoice ) ) { |
|
| 889 | - $invoice = $this->create_payment(); |
|
| 887 | + // Are we creating a new invoice? |
|
| 888 | + if ( empty( $invoice ) ) { |
|
| 889 | + $invoice = $this->create_payment(); |
|
| 890 | 890 | |
| 891 | - if ( empty( $invoice ) ) { |
|
| 892 | - return false; |
|
| 893 | - } |
|
| 891 | + if ( empty( $invoice ) ) { |
|
| 892 | + return false; |
|
| 893 | + } |
|
| 894 | 894 | |
| 895 | - } |
|
| 895 | + } |
|
| 896 | 896 | |
| 897 | - $invoice->set_status( 'wpi-renewal' ); |
|
| 897 | + $invoice->set_status( 'wpi-renewal' ); |
|
| 898 | 898 | |
| 899 | - // Maybe set a transaction id. |
|
| 900 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
| 901 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
| 902 | - } |
|
| 899 | + // Maybe set a transaction id. |
|
| 900 | + if ( ! empty( $args['transaction_id'] ) ) { |
|
| 901 | + $invoice->set_transaction_id( $args['transaction_id'] ); |
|
| 902 | + } |
|
| 903 | 903 | |
| 904 | - // Set the completed date. |
|
| 905 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
| 904 | + // Set the completed date. |
|
| 905 | + $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
| 906 | 906 | |
| 907 | - // And the gateway. |
|
| 908 | - if ( ! empty( $args['gateway'] ) ) { |
|
| 909 | - $invoice->set_gateway( $args['gateway'] ); |
|
| 910 | - } |
|
| 907 | + // And the gateway. |
|
| 908 | + if ( ! empty( $args['gateway'] ) ) { |
|
| 909 | + $invoice->set_gateway( $args['gateway'] ); |
|
| 910 | + } |
|
| 911 | 911 | |
| 912 | - $invoice->save(); |
|
| 912 | + $invoice->save(); |
|
| 913 | 913 | |
| 914 | - if ( ! $invoice->exists() ) { |
|
| 915 | - return false; |
|
| 916 | - } |
|
| 914 | + if ( ! $invoice->exists() ) { |
|
| 915 | + return false; |
|
| 916 | + } |
|
| 917 | 917 | |
| 918 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 919 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 918 | + do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 919 | + do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 920 | 920 | do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
| 921 | 921 | |
| 922 | 922 | update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
| 923 | 923 | |
| 924 | 924 | return $invoice->get_id(); |
| 925 | - } |
|
| 925 | + } |
|
| 926 | 926 | |
| 927 | - /** |
|
| 927 | + /** |
|
| 928 | 928 | * Creates a new invoice and returns it. |
| 929 | 929 | * |
| 930 | 930 | * @since 1.0.19 |
@@ -932,97 +932,97 @@ discard block |
||
| 932 | 932 | */ |
| 933 | 933 | public function create_payment() { |
| 934 | 934 | |
| 935 | - $parent_invoice = $this->get_parent_payment(); |
|
| 936 | - |
|
| 937 | - if ( ! $parent_invoice->exists() ) { |
|
| 938 | - return false; |
|
| 939 | - } |
|
| 940 | - |
|
| 941 | - // Duplicate the parent invoice. |
|
| 942 | - $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
| 943 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
| 944 | - $invoice->recalculate_total(); |
|
| 945 | - $invoice->set_status( 'wpi-pending' ); |
|
| 946 | - $invoice->save(); |
|
| 947 | - |
|
| 948 | - return $invoice->exists() ? $invoice : false; |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - /** |
|
| 952 | - * Renews or completes a subscription |
|
| 953 | - * |
|
| 954 | - * @since 1.0.0 |
|
| 955 | - * @return int The subscription's id |
|
| 956 | - */ |
|
| 957 | - public function renew() { |
|
| 958 | - |
|
| 959 | - // Complete subscription if applicable |
|
| 960 | - if ( $this->is_last_renewal() ) { |
|
| 961 | - return $this->complete(); |
|
| 962 | - } |
|
| 963 | - |
|
| 964 | - // Calculate new expiration |
|
| 965 | - $frequency = $this->get_frequency(); |
|
| 966 | - $period = $this->get_period(); |
|
| 967 | - $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
| 968 | - |
|
| 969 | - $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
| 970 | - $this->set_status( 'active' ); |
|
| 971 | - return $this->save(); |
|
| 972 | - |
|
| 973 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
| 974 | - |
|
| 975 | - } |
|
| 976 | - |
|
| 977 | - /** |
|
| 978 | - * Marks a subscription as completed |
|
| 979 | - * |
|
| 980 | - * Subscription is completed when the number of payments matches the billing_times field |
|
| 981 | - * |
|
| 982 | - * @since 1.0.0 |
|
| 983 | - * @return int|bool Subscription id or false if the subscription is cancelled. |
|
| 984 | - */ |
|
| 985 | - public function complete() { |
|
| 986 | - |
|
| 987 | - // Only mark a subscription as complete if it's not already cancelled. |
|
| 988 | - if ( $this->has_status( 'cancelled' ) ) { |
|
| 989 | - return false; |
|
| 990 | - } |
|
| 991 | - |
|
| 992 | - $this->set_status( 'completed' ); |
|
| 993 | - return $this->save(); |
|
| 994 | - |
|
| 995 | - } |
|
| 996 | - |
|
| 997 | - /** |
|
| 998 | - * Marks a subscription as expired |
|
| 999 | - * |
|
| 1000 | - * @since 1.0.0 |
|
| 1001 | - * @param bool $check_expiration |
|
| 1002 | - * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
| 1003 | - */ |
|
| 1004 | - public function expire( $check_expiration = false ) { |
|
| 1005 | - |
|
| 1006 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
| 1007 | - // Do not mark as expired since real expiration date is in the future |
|
| 1008 | - return false; |
|
| 1009 | - } |
|
| 1010 | - |
|
| 1011 | - $this->set_status( 'expired' ); |
|
| 1012 | - return $this->save(); |
|
| 1013 | - |
|
| 1014 | - } |
|
| 1015 | - |
|
| 1016 | - /** |
|
| 1017 | - * Marks a subscription as failing |
|
| 1018 | - * |
|
| 1019 | - * @since 2.4.2 |
|
| 1020 | - * @return int Subscription id. |
|
| 1021 | - */ |
|
| 1022 | - public function failing() { |
|
| 1023 | - $this->set_status( 'failing' ); |
|
| 1024 | - return $this->save(); |
|
| 1025 | - } |
|
| 935 | + $parent_invoice = $this->get_parent_payment(); |
|
| 936 | + |
|
| 937 | + if ( ! $parent_invoice->exists() ) { |
|
| 938 | + return false; |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + // Duplicate the parent invoice. |
|
| 942 | + $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
| 943 | + $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
| 944 | + $invoice->recalculate_total(); |
|
| 945 | + $invoice->set_status( 'wpi-pending' ); |
|
| 946 | + $invoice->save(); |
|
| 947 | + |
|
| 948 | + return $invoice->exists() ? $invoice : false; |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + /** |
|
| 952 | + * Renews or completes a subscription |
|
| 953 | + * |
|
| 954 | + * @since 1.0.0 |
|
| 955 | + * @return int The subscription's id |
|
| 956 | + */ |
|
| 957 | + public function renew() { |
|
| 958 | + |
|
| 959 | + // Complete subscription if applicable |
|
| 960 | + if ( $this->is_last_renewal() ) { |
|
| 961 | + return $this->complete(); |
|
| 962 | + } |
|
| 963 | + |
|
| 964 | + // Calculate new expiration |
|
| 965 | + $frequency = $this->get_frequency(); |
|
| 966 | + $period = $this->get_period(); |
|
| 967 | + $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
| 968 | + |
|
| 969 | + $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
| 970 | + $this->set_status( 'active' ); |
|
| 971 | + return $this->save(); |
|
| 972 | + |
|
| 973 | + do_action( 'getpaid_subscription_renewed', $this ); |
|
| 974 | + |
|
| 975 | + } |
|
| 976 | + |
|
| 977 | + /** |
|
| 978 | + * Marks a subscription as completed |
|
| 979 | + * |
|
| 980 | + * Subscription is completed when the number of payments matches the billing_times field |
|
| 981 | + * |
|
| 982 | + * @since 1.0.0 |
|
| 983 | + * @return int|bool Subscription id or false if the subscription is cancelled. |
|
| 984 | + */ |
|
| 985 | + public function complete() { |
|
| 986 | + |
|
| 987 | + // Only mark a subscription as complete if it's not already cancelled. |
|
| 988 | + if ( $this->has_status( 'cancelled' ) ) { |
|
| 989 | + return false; |
|
| 990 | + } |
|
| 991 | + |
|
| 992 | + $this->set_status( 'completed' ); |
|
| 993 | + return $this->save(); |
|
| 994 | + |
|
| 995 | + } |
|
| 996 | + |
|
| 997 | + /** |
|
| 998 | + * Marks a subscription as expired |
|
| 999 | + * |
|
| 1000 | + * @since 1.0.0 |
|
| 1001 | + * @param bool $check_expiration |
|
| 1002 | + * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
| 1003 | + */ |
|
| 1004 | + public function expire( $check_expiration = false ) { |
|
| 1005 | + |
|
| 1006 | + if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
| 1007 | + // Do not mark as expired since real expiration date is in the future |
|
| 1008 | + return false; |
|
| 1009 | + } |
|
| 1010 | + |
|
| 1011 | + $this->set_status( 'expired' ); |
|
| 1012 | + return $this->save(); |
|
| 1013 | + |
|
| 1014 | + } |
|
| 1015 | + |
|
| 1016 | + /** |
|
| 1017 | + * Marks a subscription as failing |
|
| 1018 | + * |
|
| 1019 | + * @since 2.4.2 |
|
| 1020 | + * @return int Subscription id. |
|
| 1021 | + */ |
|
| 1022 | + public function failing() { |
|
| 1023 | + $this->set_status( 'failing' ); |
|
| 1024 | + return $this->save(); |
|
| 1025 | + } |
|
| 1026 | 1026 | |
| 1027 | 1027 | /** |
| 1028 | 1028 | * Marks a subscription as cancelled |
@@ -1031,19 +1031,19 @@ discard block |
||
| 1031 | 1031 | * @return int Subscription id. |
| 1032 | 1032 | */ |
| 1033 | 1033 | public function cancel() { |
| 1034 | - $this->set_status( 'cancelled' ); |
|
| 1035 | - return $this->save(); |
|
| 1034 | + $this->set_status( 'cancelled' ); |
|
| 1035 | + return $this->save(); |
|
| 1036 | 1036 | } |
| 1037 | 1037 | |
| 1038 | - /** |
|
| 1039 | - * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
| 1040 | - * |
|
| 1041 | - * @since 1.0.0 |
|
| 1042 | - * @return bool |
|
| 1043 | - */ |
|
| 1044 | - public function can_cancel() { |
|
| 1045 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
| 1046 | - } |
|
| 1038 | + /** |
|
| 1039 | + * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
| 1040 | + * |
|
| 1041 | + * @since 1.0.0 |
|
| 1042 | + * @return bool |
|
| 1043 | + */ |
|
| 1044 | + public function can_cancel() { |
|
| 1045 | + return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
| 1046 | + } |
|
| 1047 | 1047 | |
| 1048 | 1048 | /** |
| 1049 | 1049 | * Returns an array of subscription statuses that can be cancelled |
@@ -1056,93 +1056,93 @@ discard block |
||
| 1056 | 1056 | return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | - /** |
|
| 1060 | - * Retrieves the URL to cancel subscription |
|
| 1061 | - * |
|
| 1062 | - * @since 1.0.0 |
|
| 1063 | - * @return string |
|
| 1064 | - */ |
|
| 1065 | - public function get_cancel_url() { |
|
| 1066 | - $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
| 1067 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 1068 | - } |
|
| 1069 | - |
|
| 1070 | - /** |
|
| 1071 | - * Retrieves the URL to view a subscription |
|
| 1072 | - * |
|
| 1073 | - * @since 1.0.19 |
|
| 1074 | - * @return string |
|
| 1075 | - */ |
|
| 1076 | - public function get_view_url() { |
|
| 1077 | - $url = add_query_arg( 'subscription', $this->get_id(), get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 1078 | - return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
| 1079 | - } |
|
| 1080 | - |
|
| 1081 | - /** |
|
| 1082 | - * Determines if subscription can be manually renewed |
|
| 1083 | - * |
|
| 1084 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
| 1085 | - * that can be renewed manually |
|
| 1086 | - * |
|
| 1087 | - * @since 2.5 |
|
| 1088 | - * @return bool |
|
| 1089 | - */ |
|
| 1090 | - public function can_renew() { |
|
| 1091 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 1092 | - } |
|
| 1093 | - |
|
| 1094 | - /** |
|
| 1095 | - * Retrieves the URL to renew a subscription |
|
| 1096 | - * |
|
| 1097 | - * @since 2.5 |
|
| 1098 | - * @return string |
|
| 1099 | - */ |
|
| 1100 | - public function get_renew_url() { |
|
| 1101 | - $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' ); |
|
| 1102 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 1103 | - } |
|
| 1104 | - |
|
| 1105 | - /** |
|
| 1106 | - * Determines if subscription can have their payment method updated |
|
| 1107 | - * |
|
| 1108 | - * @since 1.0.0 |
|
| 1109 | - * @return bool |
|
| 1110 | - */ |
|
| 1111 | - public function can_update() { |
|
| 1112 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 1113 | - } |
|
| 1114 | - |
|
| 1115 | - /** |
|
| 1116 | - * Retrieves the URL to update subscription |
|
| 1117 | - * |
|
| 1118 | - * @since 1.0.0 |
|
| 1119 | - * @return string |
|
| 1120 | - */ |
|
| 1121 | - public function get_update_url() { |
|
| 1122 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
| 1123 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 1124 | - } |
|
| 1125 | - |
|
| 1126 | - /** |
|
| 1127 | - * Retrieves the subscription status label |
|
| 1128 | - * |
|
| 1129 | - * @since 1.0.0 |
|
| 1130 | - * @return string |
|
| 1131 | - */ |
|
| 1132 | - public function get_status_label() { |
|
| 1133 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
| 1134 | - } |
|
| 1135 | - |
|
| 1136 | - /** |
|
| 1137 | - * Retrieves the subscription status class |
|
| 1138 | - * |
|
| 1139 | - * @since 1.0.19 |
|
| 1140 | - * @return string |
|
| 1141 | - */ |
|
| 1142 | - public function get_status_class() { |
|
| 1143 | - $statuses = getpaid_get_subscription_status_classes(); |
|
| 1144 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary'; |
|
| 1145 | - } |
|
| 1059 | + /** |
|
| 1060 | + * Retrieves the URL to cancel subscription |
|
| 1061 | + * |
|
| 1062 | + * @since 1.0.0 |
|
| 1063 | + * @return string |
|
| 1064 | + */ |
|
| 1065 | + public function get_cancel_url() { |
|
| 1066 | + $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
| 1067 | + return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 1068 | + } |
|
| 1069 | + |
|
| 1070 | + /** |
|
| 1071 | + * Retrieves the URL to view a subscription |
|
| 1072 | + * |
|
| 1073 | + * @since 1.0.19 |
|
| 1074 | + * @return string |
|
| 1075 | + */ |
|
| 1076 | + public function get_view_url() { |
|
| 1077 | + $url = add_query_arg( 'subscription', $this->get_id(), get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 1078 | + return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
| 1079 | + } |
|
| 1080 | + |
|
| 1081 | + /** |
|
| 1082 | + * Determines if subscription can be manually renewed |
|
| 1083 | + * |
|
| 1084 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
| 1085 | + * that can be renewed manually |
|
| 1086 | + * |
|
| 1087 | + * @since 2.5 |
|
| 1088 | + * @return bool |
|
| 1089 | + */ |
|
| 1090 | + public function can_renew() { |
|
| 1091 | + return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 1092 | + } |
|
| 1093 | + |
|
| 1094 | + /** |
|
| 1095 | + * Retrieves the URL to renew a subscription |
|
| 1096 | + * |
|
| 1097 | + * @since 2.5 |
|
| 1098 | + * @return string |
|
| 1099 | + */ |
|
| 1100 | + public function get_renew_url() { |
|
| 1101 | + $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' ); |
|
| 1102 | + return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 1103 | + } |
|
| 1104 | + |
|
| 1105 | + /** |
|
| 1106 | + * Determines if subscription can have their payment method updated |
|
| 1107 | + * |
|
| 1108 | + * @since 1.0.0 |
|
| 1109 | + * @return bool |
|
| 1110 | + */ |
|
| 1111 | + public function can_update() { |
|
| 1112 | + return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 1113 | + } |
|
| 1114 | + |
|
| 1115 | + /** |
|
| 1116 | + * Retrieves the URL to update subscription |
|
| 1117 | + * |
|
| 1118 | + * @since 1.0.0 |
|
| 1119 | + * @return string |
|
| 1120 | + */ |
|
| 1121 | + public function get_update_url() { |
|
| 1122 | + $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
| 1123 | + return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 1124 | + } |
|
| 1125 | + |
|
| 1126 | + /** |
|
| 1127 | + * Retrieves the subscription status label |
|
| 1128 | + * |
|
| 1129 | + * @since 1.0.0 |
|
| 1130 | + * @return string |
|
| 1131 | + */ |
|
| 1132 | + public function get_status_label() { |
|
| 1133 | + return getpaid_get_subscription_status_label( $this->get_status() ); |
|
| 1134 | + } |
|
| 1135 | + |
|
| 1136 | + /** |
|
| 1137 | + * Retrieves the subscription status class |
|
| 1138 | + * |
|
| 1139 | + * @since 1.0.19 |
|
| 1140 | + * @return string |
|
| 1141 | + */ |
|
| 1142 | + public function get_status_class() { |
|
| 1143 | + $statuses = getpaid_get_subscription_status_classes(); |
|
| 1144 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary'; |
|
| 1145 | + } |
|
| 1146 | 1146 | |
| 1147 | 1147 | /** |
| 1148 | 1148 | * Retrieves the subscription status label |
@@ -1152,11 +1152,11 @@ discard block |
||
| 1152 | 1152 | */ |
| 1153 | 1153 | public function get_status_label_html() { |
| 1154 | 1154 | |
| 1155 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
| 1156 | - $class = esc_attr( $this->get_status_class() ); |
|
| 1157 | - $status = sanitize_html_class( $this->get_status_label() ); |
|
| 1155 | + $status_label = sanitize_text_field( $this->get_status_label() ); |
|
| 1156 | + $class = esc_attr( $this->get_status_class() ); |
|
| 1157 | + $status = sanitize_html_class( $this->get_status_label() ); |
|
| 1158 | 1158 | |
| 1159 | - return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>"; |
|
| 1159 | + return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>"; |
|
| 1160 | 1160 | } |
| 1161 | 1161 | |
| 1162 | 1162 | /** |
@@ -1167,75 +1167,75 @@ discard block |
||
| 1167 | 1167 | * @return bool |
| 1168 | 1168 | */ |
| 1169 | 1169 | public function payment_exists( $txn_id = '' ) { |
| 1170 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 1170 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 1171 | 1171 | return ! empty( $invoice_id ); |
| 1172 | - } |
|
| 1173 | - |
|
| 1174 | - /** |
|
| 1175 | - * Handle the status transition. |
|
| 1176 | - */ |
|
| 1177 | - protected function status_transition() { |
|
| 1178 | - $status_transition = $this->status_transition; |
|
| 1179 | - |
|
| 1180 | - // Reset status transition variable. |
|
| 1181 | - $this->status_transition = false; |
|
| 1182 | - |
|
| 1183 | - if ( $status_transition ) { |
|
| 1184 | - try { |
|
| 1185 | - |
|
| 1186 | - // Fire a hook for the status change. |
|
| 1187 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 1188 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
| 1189 | - |
|
| 1190 | - if ( ! empty( $status_transition['from'] ) ) { |
|
| 1191 | - |
|
| 1192 | - /* translators: 1: old subscription status 2: new subscription status */ |
|
| 1193 | - $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1194 | - |
|
| 1195 | - // Note the transition occurred. |
|
| 1196 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1197 | - |
|
| 1198 | - // Fire another hook. |
|
| 1199 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 1200 | - do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 1201 | - |
|
| 1202 | - } else { |
|
| 1203 | - /* translators: %s: new invoice status */ |
|
| 1204 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1205 | - |
|
| 1206 | - // Note the transition occurred. |
|
| 1207 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1208 | - |
|
| 1209 | - } |
|
| 1210 | - } catch ( Exception $e ) { |
|
| 1211 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 1212 | - } |
|
| 1213 | - } |
|
| 1214 | - |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - /** |
|
| 1218 | - * Save data to the database. |
|
| 1219 | - * |
|
| 1220 | - * @since 1.0.19 |
|
| 1221 | - * @return int subscription ID |
|
| 1222 | - */ |
|
| 1223 | - public function save() { |
|
| 1224 | - parent::save(); |
|
| 1225 | - $this->status_transition(); |
|
| 1226 | - return $this->get_id(); |
|
| 1227 | - } |
|
| 1228 | - |
|
| 1229 | - /** |
|
| 1230 | - * Activates a subscription. |
|
| 1231 | - * |
|
| 1232 | - * @since 1.0.19 |
|
| 1233 | - * @return int subscription ID |
|
| 1234 | - */ |
|
| 1235 | - public function activate() { |
|
| 1236 | - $status = 'trialling' == $this->get_status() ? 'trialling' : 'active'; |
|
| 1237 | - $this->set_status( $status ); |
|
| 1238 | - return $this->save(); |
|
| 1239 | - } |
|
| 1172 | + } |
|
| 1173 | + |
|
| 1174 | + /** |
|
| 1175 | + * Handle the status transition. |
|
| 1176 | + */ |
|
| 1177 | + protected function status_transition() { |
|
| 1178 | + $status_transition = $this->status_transition; |
|
| 1179 | + |
|
| 1180 | + // Reset status transition variable. |
|
| 1181 | + $this->status_transition = false; |
|
| 1182 | + |
|
| 1183 | + if ( $status_transition ) { |
|
| 1184 | + try { |
|
| 1185 | + |
|
| 1186 | + // Fire a hook for the status change. |
|
| 1187 | + do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 1188 | + do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
| 1189 | + |
|
| 1190 | + if ( ! empty( $status_transition['from'] ) ) { |
|
| 1191 | + |
|
| 1192 | + /* translators: 1: old subscription status 2: new subscription status */ |
|
| 1193 | + $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1194 | + |
|
| 1195 | + // Note the transition occurred. |
|
| 1196 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1197 | + |
|
| 1198 | + // Fire another hook. |
|
| 1199 | + do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 1200 | + do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 1201 | + |
|
| 1202 | + } else { |
|
| 1203 | + /* translators: %s: new invoice status */ |
|
| 1204 | + $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1205 | + |
|
| 1206 | + // Note the transition occurred. |
|
| 1207 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1208 | + |
|
| 1209 | + } |
|
| 1210 | + } catch ( Exception $e ) { |
|
| 1211 | + $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 1212 | + } |
|
| 1213 | + } |
|
| 1214 | + |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + /** |
|
| 1218 | + * Save data to the database. |
|
| 1219 | + * |
|
| 1220 | + * @since 1.0.19 |
|
| 1221 | + * @return int subscription ID |
|
| 1222 | + */ |
|
| 1223 | + public function save() { |
|
| 1224 | + parent::save(); |
|
| 1225 | + $this->status_transition(); |
|
| 1226 | + return $this->get_id(); |
|
| 1227 | + } |
|
| 1228 | + |
|
| 1229 | + /** |
|
| 1230 | + * Activates a subscription. |
|
| 1231 | + * |
|
| 1232 | + * @since 1.0.19 |
|
| 1233 | + * @return int subscription ID |
|
| 1234 | + */ |
|
| 1235 | + public function activate() { |
|
| 1236 | + $status = 'trialling' == $this->get_status() ? 'trialling' : 'active'; |
|
| 1237 | + $this->set_status( $status ); |
|
| 1238 | + return $this->save(); |
|
| 1239 | + } |
|
| 1240 | 1240 | |
| 1241 | 1241 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * @package Invoicing |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -defined( 'ABSPATH' ) || exit; |
|
| 9 | +defined('ABSPATH') || exit; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * The Subscription Class |
@@ -68,27 +68,27 @@ discard block |
||
| 68 | 68 | * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
| 69 | 69 | * @param bool $deprecated |
| 70 | 70 | */ |
| 71 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
| 71 | + function __construct($subscription = 0, $deprecated = false) { |
|
| 72 | 72 | |
| 73 | - parent::__construct( $subscription ); |
|
| 73 | + parent::__construct($subscription); |
|
| 74 | 74 | |
| 75 | - if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
| 76 | - $this->set_id( $subscription ); |
|
| 77 | - } elseif ( $subscription instanceof self ) { |
|
| 78 | - $this->set_id( $subscription->get_id() ); |
|
| 79 | - } elseif ( ! empty( $subscription->id ) ) { |
|
| 80 | - $this->set_id( $subscription->id ); |
|
| 81 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
| 82 | - $this->set_id( $subscription_id ); |
|
| 75 | + if (!$deprecated && !empty($subscription) && is_numeric($subscription)) { |
|
| 76 | + $this->set_id($subscription); |
|
| 77 | + } elseif ($subscription instanceof self) { |
|
| 78 | + $this->set_id($subscription->get_id()); |
|
| 79 | + } elseif (!empty($subscription->id)) { |
|
| 80 | + $this->set_id($subscription->id); |
|
| 81 | + } elseif ($deprecated && $subscription_id = self::get_subscription_id_by_field($subscription, 'profile_id')) { |
|
| 82 | + $this->set_id($subscription_id); |
|
| 83 | 83 | } else { |
| 84 | - $this->set_object_read( true ); |
|
| 84 | + $this->set_object_read(true); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | // Load the datastore. |
| 88 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
| 88 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
| 89 | 89 | |
| 90 | - if ( $this->get_id() > 0 ) { |
|
| 91 | - $this->data_store->read( $this ); |
|
| 90 | + if ($this->get_id() > 0) { |
|
| 91 | + $this->data_store->read($this); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | } |
@@ -103,17 +103,17 @@ discard block |
||
| 103 | 103 | * @since 1.0.19 |
| 104 | 104 | * @return int |
| 105 | 105 | */ |
| 106 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
| 106 | + public static function get_subscription_id_by_field($value, $field = 'profile_id') { |
|
| 107 | 107 | global $wpdb; |
| 108 | 108 | |
| 109 | 109 | // Trim the value. |
| 110 | - $value = trim( $value ); |
|
| 110 | + $value = trim($value); |
|
| 111 | 111 | |
| 112 | - if ( empty( $value ) ) { |
|
| 112 | + if (empty($value)) { |
|
| 113 | 113 | return 0; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - if ( 'invoice_id' == $field ) { |
|
| 116 | + if ('invoice_id' == $field) { |
|
| 117 | 117 | $field = 'parent_payment_id'; |
| 118 | 118 | } |
| 119 | 119 | |
@@ -125,28 +125,28 @@ discard block |
||
| 125 | 125 | ); |
| 126 | 126 | |
| 127 | 127 | // Ensure a field has been passed. |
| 128 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
| 128 | + if (empty($field) || !in_array($field, $fields)) { |
|
| 129 | 129 | return 0; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | // Maybe retrieve from the cache. |
| 133 | - $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 134 | - if ( ! empty( $subscription_id ) ) { |
|
| 133 | + $subscription_id = wp_cache_get($value, "getpaid_subscription_{$field}s_to_subscription_ids"); |
|
| 134 | + if (!empty($subscription_id)) { |
|
| 135 | 135 | return $subscription_id; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | // Fetch from the db. |
| 139 | 139 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
| 140 | 140 | $subscription_id = (int) $wpdb->get_var( |
| 141 | - $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
|
| 141 | + $wpdb->prepare("SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value) |
|
| 142 | 142 | ); |
| 143 | 143 | |
| 144 | - if ( empty( $subscription_id ) ) { |
|
| 144 | + if (empty($subscription_id)) { |
|
| 145 | 145 | return 0; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | // Update the cache with our data. |
| 149 | - wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
| 149 | + wp_cache_set($value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids"); |
|
| 150 | 150 | |
| 151 | 151 | return $subscription_id; |
| 152 | 152 | } |
@@ -155,17 +155,17 @@ discard block |
||
| 155 | 155 | * Clears the subscription's cache. |
| 156 | 156 | */ |
| 157 | 157 | public function clear_cache() { |
| 158 | - wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
| 159 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
| 160 | - wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
| 161 | - wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
| 158 | + wp_cache_delete($this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids'); |
|
| 159 | + wp_cache_delete($this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids'); |
|
| 160 | + wp_cache_delete($this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids'); |
|
| 161 | + wp_cache_delete($this->get_id(), 'getpaid_subscriptions'); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
| 165 | 165 | * Checks if a subscription key is set. |
| 166 | 166 | */ |
| 167 | - public function _isset( $key ) { |
|
| 168 | - return isset( $this->data[$key] ) || method_exists( $this, "get_$key" ); |
|
| 167 | + public function _isset($key) { |
|
| 168 | + return isset($this->data[$key]) || method_exists($this, "get_$key"); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | /* |
@@ -190,8 +190,8 @@ discard block |
||
| 190 | 190 | * @param string $context View or edit context. |
| 191 | 191 | * @return int |
| 192 | 192 | */ |
| 193 | - public function get_customer_id( $context = 'view' ) { |
|
| 194 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
| 193 | + public function get_customer_id($context = 'view') { |
|
| 194 | + return (int) $this->get_prop('customer_id', $context); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -201,8 +201,8 @@ discard block |
||
| 201 | 201 | * @param string $context View or edit context. |
| 202 | 202 | * @return WP_User|false WP_User object on success, false on failure. |
| 203 | 203 | */ |
| 204 | - public function get_customer( $context = 'view' ) { |
|
| 205 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
| 204 | + public function get_customer($context = 'view') { |
|
| 205 | + return get_userdata($this->get_customer_id($context)); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /** |
@@ -212,8 +212,8 @@ discard block |
||
| 212 | 212 | * @param string $context View or edit context. |
| 213 | 213 | * @return int |
| 214 | 214 | */ |
| 215 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
| 216 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
| 215 | + public function get_parent_invoice_id($context = 'view') { |
|
| 216 | + return (int) $this->get_prop('parent_payment_id', $context); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -223,8 +223,8 @@ discard block |
||
| 223 | 223 | * @param string $context View or edit context. |
| 224 | 224 | * @return int |
| 225 | 225 | */ |
| 226 | - public function get_parent_payment_id( $context = 'view' ) { |
|
| 227 | - return $this->get_parent_invoice_id( $context ); |
|
| 226 | + public function get_parent_payment_id($context = 'view') { |
|
| 227 | + return $this->get_parent_invoice_id($context); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -233,8 +233,8 @@ discard block |
||
| 233 | 233 | * @since 1.0.0 |
| 234 | 234 | * @return int |
| 235 | 235 | */ |
| 236 | - public function get_original_payment_id( $context = 'view' ) { |
|
| 237 | - return $this->get_parent_invoice_id( $context ); |
|
| 236 | + public function get_original_payment_id($context = 'view') { |
|
| 237 | + return $this->get_parent_invoice_id($context); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -244,8 +244,8 @@ discard block |
||
| 244 | 244 | * @param string $context View or edit context. |
| 245 | 245 | * @return WPInv_Invoice |
| 246 | 246 | */ |
| 247 | - public function get_parent_invoice( $context = 'view' ) { |
|
| 248 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
| 247 | + public function get_parent_invoice($context = 'view') { |
|
| 248 | + return new WPInv_Invoice($this->get_parent_invoice_id($context)); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
@@ -255,8 +255,8 @@ discard block |
||
| 255 | 255 | * @param string $context View or edit context. |
| 256 | 256 | * @return WPInv_Invoice |
| 257 | 257 | */ |
| 258 | - public function get_parent_payment( $context = 'view' ) { |
|
| 259 | - return $this->get_parent_invoice( $context ); |
|
| 258 | + public function get_parent_payment($context = 'view') { |
|
| 259 | + return $this->get_parent_invoice($context); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -266,8 +266,8 @@ discard block |
||
| 266 | 266 | * @param string $context View or edit context. |
| 267 | 267 | * @return int |
| 268 | 268 | */ |
| 269 | - public function get_product_id( $context = 'view' ) { |
|
| 270 | - return (int) $this->get_prop( 'product_id', $context ); |
|
| 269 | + public function get_product_id($context = 'view') { |
|
| 270 | + return (int) $this->get_prop('product_id', $context); |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -277,8 +277,8 @@ discard block |
||
| 277 | 277 | * @param string $context View or edit context. |
| 278 | 278 | * @return WPInv_Item |
| 279 | 279 | */ |
| 280 | - public function get_product( $context = 'view' ) { |
|
| 281 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
| 280 | + public function get_product($context = 'view') { |
|
| 281 | + return new WPInv_Item($this->get_product_id($context)); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
@@ -290,8 +290,8 @@ discard block |
||
| 290 | 290 | * @param string $context View or edit context. |
| 291 | 291 | * @return string |
| 292 | 292 | */ |
| 293 | - public function get_gateway( $context = 'view' ) { |
|
| 294 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
| 293 | + public function get_gateway($context = 'view') { |
|
| 294 | + return $this->get_parent_invoice($context)->get_gateway(); |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | /** |
@@ -301,8 +301,8 @@ discard block |
||
| 301 | 301 | * @param string $context View or edit context. |
| 302 | 302 | * @return string |
| 303 | 303 | */ |
| 304 | - public function get_period( $context = 'view' ) { |
|
| 305 | - return $this->get_prop( 'period', $context ); |
|
| 304 | + public function get_period($context = 'view') { |
|
| 305 | + return $this->get_prop('period', $context); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -312,8 +312,8 @@ discard block |
||
| 312 | 312 | * @param string $context View or edit context. |
| 313 | 313 | * @return int |
| 314 | 314 | */ |
| 315 | - public function get_frequency( $context = 'view' ) { |
|
| 316 | - return (int) $this->get_prop( 'frequency', $context ); |
|
| 315 | + public function get_frequency($context = 'view') { |
|
| 316 | + return (int) $this->get_prop('frequency', $context); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | /** |
@@ -323,8 +323,8 @@ discard block |
||
| 323 | 323 | * @param string $context View or edit context. |
| 324 | 324 | * @return float |
| 325 | 325 | */ |
| 326 | - public function get_initial_amount( $context = 'view' ) { |
|
| 327 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
| 326 | + public function get_initial_amount($context = 'view') { |
|
| 327 | + return (float) wpinv_sanitize_amount($this->get_prop('initial_amount', $context)); |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
@@ -334,8 +334,8 @@ discard block |
||
| 334 | 334 | * @param string $context View or edit context. |
| 335 | 335 | * @return float |
| 336 | 336 | */ |
| 337 | - public function get_recurring_amount( $context = 'view' ) { |
|
| 338 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
| 337 | + public function get_recurring_amount($context = 'view') { |
|
| 338 | + return (float) wpinv_sanitize_amount($this->get_prop('recurring_amount', $context)); |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | /** |
@@ -345,8 +345,8 @@ discard block |
||
| 345 | 345 | * @param string $context View or edit context. |
| 346 | 346 | * @return int |
| 347 | 347 | */ |
| 348 | - public function get_bill_times( $context = 'view' ) { |
|
| 349 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
| 348 | + public function get_bill_times($context = 'view') { |
|
| 349 | + return (int) $this->get_prop('bill_times', $context); |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | /** |
@@ -356,8 +356,8 @@ discard block |
||
| 356 | 356 | * @param string $context View or edit context. |
| 357 | 357 | * @return string |
| 358 | 358 | */ |
| 359 | - public function get_transaction_id( $context = 'view' ) { |
|
| 360 | - return $this->get_prop( 'transaction_id', $context ); |
|
| 359 | + public function get_transaction_id($context = 'view') { |
|
| 360 | + return $this->get_prop('transaction_id', $context); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | /** |
@@ -367,8 +367,8 @@ discard block |
||
| 367 | 367 | * @param string $context View or edit context. |
| 368 | 368 | * @return string |
| 369 | 369 | */ |
| 370 | - public function get_created( $context = 'view' ) { |
|
| 371 | - return $this->get_prop( 'created', $context ); |
|
| 370 | + public function get_created($context = 'view') { |
|
| 371 | + return $this->get_prop('created', $context); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | /** |
@@ -378,8 +378,8 @@ discard block |
||
| 378 | 378 | * @param string $context View or edit context. |
| 379 | 379 | * @return string |
| 380 | 380 | */ |
| 381 | - public function get_date_created( $context = 'view' ) { |
|
| 382 | - return $this->get_created( $context ); |
|
| 381 | + public function get_date_created($context = 'view') { |
|
| 382 | + return $this->get_created($context); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | */ |
| 391 | 391 | public function get_time_created() { |
| 392 | 392 | $created = $this->get_date_created(); |
| 393 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
| 393 | + return empty($created) ? current_time('timestamp') : strtotime($created, current_time('timestamp')); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | /** |
@@ -400,11 +400,11 @@ discard block |
||
| 400 | 400 | * @param string $context View or edit context. |
| 401 | 401 | * @return string |
| 402 | 402 | */ |
| 403 | - public function get_date_created_gmt( $context = 'view' ) { |
|
| 404 | - $date = $this->get_date_created( $context ); |
|
| 403 | + public function get_date_created_gmt($context = 'view') { |
|
| 404 | + $date = $this->get_date_created($context); |
|
| 405 | 405 | |
| 406 | - if ( $date ) { |
|
| 407 | - $date = get_gmt_from_date( $date ); |
|
| 406 | + if ($date) { |
|
| 407 | + $date = get_gmt_from_date($date); |
|
| 408 | 408 | } |
| 409 | 409 | return $date; |
| 410 | 410 | } |
@@ -416,8 +416,8 @@ discard block |
||
| 416 | 416 | * @param string $context View or edit context. |
| 417 | 417 | * @return string |
| 418 | 418 | */ |
| 419 | - public function get_next_renewal_date( $context = 'view' ) { |
|
| 420 | - return $this->get_prop( 'expiration', $context ); |
|
| 419 | + public function get_next_renewal_date($context = 'view') { |
|
| 420 | + return $this->get_prop('expiration', $context); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | /** |
@@ -427,8 +427,8 @@ discard block |
||
| 427 | 427 | * @param string $context View or edit context. |
| 428 | 428 | * @return string |
| 429 | 429 | */ |
| 430 | - public function get_expiration( $context = 'view' ) { |
|
| 431 | - return $this->get_next_renewal_date( $context ); |
|
| 430 | + public function get_expiration($context = 'view') { |
|
| 431 | + return $this->get_next_renewal_date($context); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | /** |
@@ -440,12 +440,12 @@ discard block |
||
| 440 | 440 | public function get_expiration_time() { |
| 441 | 441 | $expiration = $this->get_expiration(); |
| 442 | 442 | |
| 443 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
| 444 | - return current_time( 'timestamp' ); |
|
| 443 | + if (empty($expiration) || '0000-00-00 00:00:00' == $expiration) { |
|
| 444 | + return current_time('timestamp'); |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
| 448 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
| 447 | + $expiration = strtotime($expiration, current_time('timestamp')); |
|
| 448 | + return $expiration < current_time('timestamp') ? current_time('timestamp') : $expiration; |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | /** |
@@ -455,11 +455,11 @@ discard block |
||
| 455 | 455 | * @param string $context View or edit context. |
| 456 | 456 | * @return string |
| 457 | 457 | */ |
| 458 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
| 459 | - $date = $this->get_next_renewal_date( $context ); |
|
| 458 | + public function get_next_renewal_date_gmt($context = 'view') { |
|
| 459 | + $date = $this->get_next_renewal_date($context); |
|
| 460 | 460 | |
| 461 | - if ( $date ) { |
|
| 462 | - $date = get_gmt_from_date( $date ); |
|
| 461 | + if ($date) { |
|
| 462 | + $date = get_gmt_from_date($date); |
|
| 463 | 463 | } |
| 464 | 464 | return $date; |
| 465 | 465 | } |
@@ -471,8 +471,8 @@ discard block |
||
| 471 | 471 | * @param string $context View or edit context. |
| 472 | 472 | * @return string |
| 473 | 473 | */ |
| 474 | - public function get_trial_period( $context = 'view' ) { |
|
| 475 | - return $this->get_prop( 'trial_period', $context ); |
|
| 474 | + public function get_trial_period($context = 'view') { |
|
| 475 | + return $this->get_prop('trial_period', $context); |
|
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | /** |
@@ -482,8 +482,8 @@ discard block |
||
| 482 | 482 | * @param string $context View or edit context. |
| 483 | 483 | * @return string |
| 484 | 484 | */ |
| 485 | - public function get_status( $context = 'view' ) { |
|
| 486 | - return $this->get_prop( 'status', $context ); |
|
| 485 | + public function get_status($context = 'view') { |
|
| 486 | + return $this->get_prop('status', $context); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | /** |
@@ -493,8 +493,8 @@ discard block |
||
| 493 | 493 | * @param string $context View or edit context. |
| 494 | 494 | * @return string |
| 495 | 495 | */ |
| 496 | - public function get_profile_id( $context = 'view' ) { |
|
| 497 | - return $this->get_prop( 'profile_id', $context ); |
|
| 496 | + public function get_profile_id($context = 'view') { |
|
| 497 | + return $this->get_prop('profile_id', $context); |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | /* |
@@ -509,8 +509,8 @@ discard block |
||
| 509 | 509 | * @since 1.0.19 |
| 510 | 510 | * @param int $value The customer's id. |
| 511 | 511 | */ |
| 512 | - public function set_customer_id( $value ) { |
|
| 513 | - $this->set_prop( 'customer_id', (int) $value ); |
|
| 512 | + public function set_customer_id($value) { |
|
| 513 | + $this->set_prop('customer_id', (int) $value); |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | /** |
@@ -519,8 +519,8 @@ discard block |
||
| 519 | 519 | * @since 1.0.19 |
| 520 | 520 | * @param int $value The parent invoice id. |
| 521 | 521 | */ |
| 522 | - public function set_parent_invoice_id( $value ) { |
|
| 523 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
| 522 | + public function set_parent_invoice_id($value) { |
|
| 523 | + $this->set_prop('parent_payment_id', (int) $value); |
|
| 524 | 524 | } |
| 525 | 525 | |
| 526 | 526 | /** |
@@ -529,8 +529,8 @@ discard block |
||
| 529 | 529 | * @since 1.0.19 |
| 530 | 530 | * @param int $value The parent invoice id. |
| 531 | 531 | */ |
| 532 | - public function set_parent_payment_id( $value ) { |
|
| 533 | - $this->set_parent_invoice_id( $value ); |
|
| 532 | + public function set_parent_payment_id($value) { |
|
| 533 | + $this->set_parent_invoice_id($value); |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | /** |
@@ -539,8 +539,8 @@ discard block |
||
| 539 | 539 | * @since 1.0.19 |
| 540 | 540 | * @param int $value The parent invoice id. |
| 541 | 541 | */ |
| 542 | - public function set_original_payment_id( $value ) { |
|
| 543 | - $this->set_parent_invoice_id( $value ); |
|
| 542 | + public function set_original_payment_id($value) { |
|
| 543 | + $this->set_parent_invoice_id($value); |
|
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | /** |
@@ -549,8 +549,8 @@ discard block |
||
| 549 | 549 | * @since 1.0.19 |
| 550 | 550 | * @param int $value The subscription product id. |
| 551 | 551 | */ |
| 552 | - public function set_product_id( $value ) { |
|
| 553 | - $this->set_prop( 'product_id', (int) $value ); |
|
| 552 | + public function set_product_id($value) { |
|
| 553 | + $this->set_prop('product_id', (int) $value); |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | /** |
@@ -559,8 +559,8 @@ discard block |
||
| 559 | 559 | * @since 1.0.19 |
| 560 | 560 | * @param string $value The renewal period. |
| 561 | 561 | */ |
| 562 | - public function set_period( $value ) { |
|
| 563 | - $this->set_prop( 'period', $value ); |
|
| 562 | + public function set_period($value) { |
|
| 563 | + $this->set_prop('period', $value); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | /** |
@@ -569,9 +569,9 @@ discard block |
||
| 569 | 569 | * @since 1.0.19 |
| 570 | 570 | * @param int $value The subscription frequency. |
| 571 | 571 | */ |
| 572 | - public function set_frequency( $value ) { |
|
| 573 | - $value = empty( $value ) ? 1 : (int) $value; |
|
| 574 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
| 572 | + public function set_frequency($value) { |
|
| 573 | + $value = empty($value) ? 1 : (int) $value; |
|
| 574 | + $this->set_prop('frequency', absint($value)); |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | /** |
@@ -580,8 +580,8 @@ discard block |
||
| 580 | 580 | * @since 1.0.19 |
| 581 | 581 | * @param float $value The initial subcription amount. |
| 582 | 582 | */ |
| 583 | - public function set_initial_amount( $value ) { |
|
| 584 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
| 583 | + public function set_initial_amount($value) { |
|
| 584 | + $this->set_prop('initial_amount', wpinv_sanitize_amount($value)); |
|
| 585 | 585 | } |
| 586 | 586 | |
| 587 | 587 | /** |
@@ -590,8 +590,8 @@ discard block |
||
| 590 | 590 | * @since 1.0.19 |
| 591 | 591 | * @param float $value The recurring subcription amount. |
| 592 | 592 | */ |
| 593 | - public function set_recurring_amount( $value ) { |
|
| 594 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
| 593 | + public function set_recurring_amount($value) { |
|
| 594 | + $this->set_prop('recurring_amount', wpinv_sanitize_amount($value)); |
|
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | /** |
@@ -600,8 +600,8 @@ discard block |
||
| 600 | 600 | * @since 1.0.19 |
| 601 | 601 | * @param int $value Bill times. |
| 602 | 602 | */ |
| 603 | - public function set_bill_times( $value ) { |
|
| 604 | - $this->set_prop( 'bill_times', (int) $value ); |
|
| 603 | + public function set_bill_times($value) { |
|
| 604 | + $this->set_prop('bill_times', (int) $value); |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | /** |
@@ -610,8 +610,8 @@ discard block |
||
| 610 | 610 | * @since 1.0.19 |
| 611 | 611 | * @param string $value Bill times. |
| 612 | 612 | */ |
| 613 | - public function set_transaction_id( $value ) { |
|
| 614 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
| 613 | + public function set_transaction_id($value) { |
|
| 614 | + $this->set_prop('transaction_id', sanitize_text_field($value)); |
|
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | /** |
@@ -620,15 +620,15 @@ discard block |
||
| 620 | 620 | * @since 1.0.19 |
| 621 | 621 | * @param string $value strtotime compliant date. |
| 622 | 622 | */ |
| 623 | - public function set_created( $value ) { |
|
| 624 | - $date = strtotime( $value ); |
|
| 623 | + public function set_created($value) { |
|
| 624 | + $date = strtotime($value); |
|
| 625 | 625 | |
| 626 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 627 | - $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
| 626 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
| 627 | + $this->set_prop('created', date('Y-m-d H:i:s', $date)); |
|
| 628 | 628 | return; |
| 629 | 629 | } |
| 630 | 630 | |
| 631 | - $this->set_prop( 'created', '' ); |
|
| 631 | + $this->set_prop('created', ''); |
|
| 632 | 632 | |
| 633 | 633 | } |
| 634 | 634 | |
@@ -638,8 +638,8 @@ discard block |
||
| 638 | 638 | * @since 1.0.19 |
| 639 | 639 | * @param string $value strtotime compliant date. |
| 640 | 640 | */ |
| 641 | - public function set_date_created( $value ) { |
|
| 642 | - $this->set_created( $value ); |
|
| 641 | + public function set_date_created($value) { |
|
| 642 | + $this->set_created($value); |
|
| 643 | 643 | } |
| 644 | 644 | |
| 645 | 645 | /** |
@@ -648,15 +648,15 @@ discard block |
||
| 648 | 648 | * @since 1.0.19 |
| 649 | 649 | * @param string $value strtotime compliant date. |
| 650 | 650 | */ |
| 651 | - public function set_next_renewal_date( $value ) { |
|
| 652 | - $date = strtotime( $value ); |
|
| 651 | + public function set_next_renewal_date($value) { |
|
| 652 | + $date = strtotime($value); |
|
| 653 | 653 | |
| 654 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
| 655 | - $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
| 654 | + if ($date && $value !== '0000-00-00 00:00:00') { |
|
| 655 | + $this->set_prop('expiration', date('Y-m-d H:i:s', $date)); |
|
| 656 | 656 | return; |
| 657 | 657 | } |
| 658 | 658 | |
| 659 | - $this->set_prop( 'expiration', '' ); |
|
| 659 | + $this->set_prop('expiration', ''); |
|
| 660 | 660 | |
| 661 | 661 | } |
| 662 | 662 | |
@@ -666,8 +666,8 @@ discard block |
||
| 666 | 666 | * @since 1.0.19 |
| 667 | 667 | * @param string $value strtotime compliant date. |
| 668 | 668 | */ |
| 669 | - public function set_expiration( $value ) { |
|
| 670 | - $this->set_next_renewal_date( $value ); |
|
| 669 | + public function set_expiration($value) { |
|
| 670 | + $this->set_next_renewal_date($value); |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | /** |
@@ -676,8 +676,8 @@ discard block |
||
| 676 | 676 | * @since 1.0.19 |
| 677 | 677 | * @param string $value trial period e.g 1 year. |
| 678 | 678 | */ |
| 679 | - public function set_trial_period( $value ) { |
|
| 680 | - $this->set_prop( 'trial_period', $value ); |
|
| 679 | + public function set_trial_period($value) { |
|
| 680 | + $this->set_prop('trial_period', $value); |
|
| 681 | 681 | } |
| 682 | 682 | |
| 683 | 683 | /** |
@@ -686,19 +686,19 @@ discard block |
||
| 686 | 686 | * @since 1.0.19 |
| 687 | 687 | * @param string $new_status New subscription status. |
| 688 | 688 | */ |
| 689 | - public function set_status( $new_status ) { |
|
| 689 | + public function set_status($new_status) { |
|
| 690 | 690 | |
| 691 | 691 | // Abort if this is not a valid status; |
| 692 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
| 692 | + if (!array_key_exists($new_status, getpaid_get_subscription_statuses())) { |
|
| 693 | 693 | return; |
| 694 | 694 | } |
| 695 | 695 | |
| 696 | 696 | $old_status = $this->get_status(); |
| 697 | - $this->set_prop( 'status', $new_status ); |
|
| 697 | + $this->set_prop('status', $new_status); |
|
| 698 | 698 | |
| 699 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
| 699 | + if (true === $this->object_read && $old_status !== $new_status) { |
|
| 700 | 700 | $this->status_transition = array( |
| 701 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
| 701 | + 'from' => !empty($this->status_transition['from']) ? $this->status_transition['from'] : $old_status, |
|
| 702 | 702 | 'to' => $new_status, |
| 703 | 703 | ); |
| 704 | 704 | } |
@@ -711,8 +711,8 @@ discard block |
||
| 711 | 711 | * @since 1.0.19 |
| 712 | 712 | * @param string $value the remote profile id. |
| 713 | 713 | */ |
| 714 | - public function set_profile_id( $value ) { |
|
| 715 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
| 714 | + public function set_profile_id($value) { |
|
| 715 | + $this->set_prop('profile_id', sanitize_text_field($value)); |
|
| 716 | 716 | } |
| 717 | 717 | |
| 718 | 718 | /* |
@@ -730,8 +730,8 @@ discard block |
||
| 730 | 730 | * @param string|array String or array of strings to check for. |
| 731 | 731 | * @return bool |
| 732 | 732 | */ |
| 733 | - public function has_status( $status ) { |
|
| 734 | - return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) ); |
|
| 733 | + public function has_status($status) { |
|
| 734 | + return in_array($this->get_status(), wpinv_clean(wpinv_parse_list($status))); |
|
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | /** |
@@ -741,7 +741,7 @@ discard block |
||
| 741 | 741 | */ |
| 742 | 742 | public function has_trial_period() { |
| 743 | 743 | $period = $this->get_trial_period(); |
| 744 | - return ! empty( $period ); |
|
| 744 | + return !empty($period); |
|
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | /** |
@@ -750,7 +750,7 @@ discard block |
||
| 750 | 750 | * @return bool |
| 751 | 751 | */ |
| 752 | 752 | public function is_active() { |
| 753 | - return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
| 753 | + return $this->has_status('active trialling') && !$this->is_expired(); |
|
| 754 | 754 | } |
| 755 | 755 | |
| 756 | 756 | /** |
@@ -759,7 +759,7 @@ discard block |
||
| 759 | 759 | * @return bool |
| 760 | 760 | */ |
| 761 | 761 | public function is_expired() { |
| 762 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
| 762 | + return $this->has_status('expired') || ($this->has_status('active cancelled trialling') && $this->get_expiration_time() < current_time('mysql')); |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | /** |
@@ -769,7 +769,7 @@ discard block |
||
| 769 | 769 | */ |
| 770 | 770 | public function is_last_renewal() { |
| 771 | 771 | $max_bills = $this->get_bill_times(); |
| 772 | - return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
| 772 | + return !empty($max_bills) && $max_bills <= $this->get_times_billed(); |
|
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | /* |
@@ -784,11 +784,11 @@ discard block |
||
| 784 | 784 | /** |
| 785 | 785 | * Backwards compatibilty. |
| 786 | 786 | */ |
| 787 | - public function create( $data = array() ) { |
|
| 787 | + public function create($data = array()) { |
|
| 788 | 788 | |
| 789 | 789 | // Set the properties. |
| 790 | - if ( is_array( $data ) ) { |
|
| 791 | - $this->set_props( $data ); |
|
| 790 | + if (is_array($data)) { |
|
| 791 | + $this->set_props($data); |
|
| 792 | 792 | } |
| 793 | 793 | |
| 794 | 794 | // Save the item. |
@@ -799,8 +799,8 @@ discard block |
||
| 799 | 799 | /** |
| 800 | 800 | * Backwards compatibilty. |
| 801 | 801 | */ |
| 802 | - public function update( $args = array() ) { |
|
| 803 | - return $this->create( $args ); |
|
| 802 | + public function update($args = array()) { |
|
| 803 | + return $this->create($args); |
|
| 804 | 804 | } |
| 805 | 805 | |
| 806 | 806 | /** |
@@ -809,12 +809,12 @@ discard block |
||
| 809 | 809 | * @since 1.0.0 |
| 810 | 810 | * @return WP_Post[] |
| 811 | 811 | */ |
| 812 | - public function get_child_payments( $hide_pending = true ) { |
|
| 812 | + public function get_child_payments($hide_pending = true) { |
|
| 813 | 813 | |
| 814 | - $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
| 814 | + $statuses = array('publish', 'wpi-processing', 'wpi-renewal'); |
|
| 815 | 815 | |
| 816 | - if ( ! $hide_pending ) { |
|
| 817 | - $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
| 816 | + if (!$hide_pending) { |
|
| 817 | + $statuses = array_keys(wpinv_get_invoice_statuses()); |
|
| 818 | 818 | } |
| 819 | 819 | |
| 820 | 820 | return get_posts( |
@@ -846,7 +846,7 @@ discard block |
||
| 846 | 846 | ); |
| 847 | 847 | |
| 848 | 848 | // Maybe include parent invoice. |
| 849 | - if ( $this->get_parent_payment()->is_paid() ) { |
|
| 849 | + if ($this->get_parent_payment()->is_paid()) { |
|
| 850 | 850 | $count++; |
| 851 | 851 | } |
| 852 | 852 | |
@@ -862,7 +862,7 @@ discard block |
||
| 862 | 862 | public function get_times_billed() { |
| 863 | 863 | $times_billed = $this->get_total_payments(); |
| 864 | 864 | |
| 865 | - if ( (float) $this->get_initial_amount() == 0 && $times_billed > 0 ) { |
|
| 865 | + if ((float) $this->get_initial_amount() == 0 && $times_billed > 0) { |
|
| 866 | 866 | $times_billed--; |
| 867 | 867 | } |
| 868 | 868 | |
@@ -877,49 +877,49 @@ discard block |
||
| 877 | 877 | * @param WPInv_Invoice $invoice If adding an existing invoice. |
| 878 | 878 | * @return bool |
| 879 | 879 | */ |
| 880 | - public function add_payment( $args = array(), $invoice = false ) { |
|
| 880 | + public function add_payment($args = array(), $invoice = false) { |
|
| 881 | 881 | |
| 882 | 882 | // Process each payment once. |
| 883 | - if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
|
| 883 | + if (!empty($args['transaction_id']) && $this->payment_exists($args['transaction_id'])) { |
|
| 884 | 884 | return false; |
| 885 | 885 | } |
| 886 | 886 | |
| 887 | 887 | // Are we creating a new invoice? |
| 888 | - if ( empty( $invoice ) ) { |
|
| 888 | + if (empty($invoice)) { |
|
| 889 | 889 | $invoice = $this->create_payment(); |
| 890 | 890 | |
| 891 | - if ( empty( $invoice ) ) { |
|
| 891 | + if (empty($invoice)) { |
|
| 892 | 892 | return false; |
| 893 | 893 | } |
| 894 | 894 | |
| 895 | 895 | } |
| 896 | 896 | |
| 897 | - $invoice->set_status( 'wpi-renewal' ); |
|
| 897 | + $invoice->set_status('wpi-renewal'); |
|
| 898 | 898 | |
| 899 | 899 | // Maybe set a transaction id. |
| 900 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
| 901 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
| 900 | + if (!empty($args['transaction_id'])) { |
|
| 901 | + $invoice->set_transaction_id($args['transaction_id']); |
|
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | // Set the completed date. |
| 905 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
| 905 | + $invoice->set_completed_date(current_time('mysql')); |
|
| 906 | 906 | |
| 907 | 907 | // And the gateway. |
| 908 | - if ( ! empty( $args['gateway'] ) ) { |
|
| 909 | - $invoice->set_gateway( $args['gateway'] ); |
|
| 908 | + if (!empty($args['gateway'])) { |
|
| 909 | + $invoice->set_gateway($args['gateway']); |
|
| 910 | 910 | } |
| 911 | 911 | |
| 912 | 912 | $invoice->save(); |
| 913 | 913 | |
| 914 | - if ( ! $invoice->exists() ) { |
|
| 914 | + if (!$invoice->exists()) { |
|
| 915 | 915 | return false; |
| 916 | 916 | } |
| 917 | 917 | |
| 918 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
| 919 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
| 920 | - do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
|
| 918 | + do_action('getpaid_after_create_subscription_renewal_invoice', $invoice, $this); |
|
| 919 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $this); |
|
| 920 | + do_action('wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id()); |
|
| 921 | 921 | |
| 922 | - update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
|
| 922 | + update_post_meta($invoice->get_id(), '_wpinv_subscription_id', $this->id); |
|
| 923 | 923 | |
| 924 | 924 | return $invoice->get_id(); |
| 925 | 925 | } |
@@ -934,15 +934,15 @@ discard block |
||
| 934 | 934 | |
| 935 | 935 | $parent_invoice = $this->get_parent_payment(); |
| 936 | 936 | |
| 937 | - if ( ! $parent_invoice->exists() ) { |
|
| 937 | + if (!$parent_invoice->exists()) { |
|
| 938 | 938 | return false; |
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | // Duplicate the parent invoice. |
| 942 | - $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
| 943 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
| 942 | + $invoice = getpaid_duplicate_invoice($parent_invoice); |
|
| 943 | + $invoice->set_parent_id($parent_invoice->get_id()); |
|
| 944 | 944 | $invoice->recalculate_total(); |
| 945 | - $invoice->set_status( 'wpi-pending' ); |
|
| 945 | + $invoice->set_status('wpi-pending'); |
|
| 946 | 946 | $invoice->save(); |
| 947 | 947 | |
| 948 | 948 | return $invoice->exists() ? $invoice : false; |
@@ -957,20 +957,20 @@ discard block |
||
| 957 | 957 | public function renew() { |
| 958 | 958 | |
| 959 | 959 | // Complete subscription if applicable |
| 960 | - if ( $this->is_last_renewal() ) { |
|
| 960 | + if ($this->is_last_renewal()) { |
|
| 961 | 961 | return $this->complete(); |
| 962 | 962 | } |
| 963 | 963 | |
| 964 | 964 | // Calculate new expiration |
| 965 | 965 | $frequency = $this->get_frequency(); |
| 966 | 966 | $period = $this->get_period(); |
| 967 | - $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
| 967 | + $new_expiration = strtotime("+ $frequency $period", $this->get_expiration_time()); |
|
| 968 | 968 | |
| 969 | - $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
| 970 | - $this->set_status( 'active' ); |
|
| 969 | + $this->set_expiration(date('Y-m-d H:i:s', $new_expiration)); |
|
| 970 | + $this->set_status('active'); |
|
| 971 | 971 | return $this->save(); |
| 972 | 972 | |
| 973 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
| 973 | + do_action('getpaid_subscription_renewed', $this); |
|
| 974 | 974 | |
| 975 | 975 | } |
| 976 | 976 | |
@@ -985,11 +985,11 @@ discard block |
||
| 985 | 985 | public function complete() { |
| 986 | 986 | |
| 987 | 987 | // Only mark a subscription as complete if it's not already cancelled. |
| 988 | - if ( $this->has_status( 'cancelled' ) ) { |
|
| 988 | + if ($this->has_status('cancelled')) { |
|
| 989 | 989 | return false; |
| 990 | 990 | } |
| 991 | 991 | |
| 992 | - $this->set_status( 'completed' ); |
|
| 992 | + $this->set_status('completed'); |
|
| 993 | 993 | return $this->save(); |
| 994 | 994 | |
| 995 | 995 | } |
@@ -1001,14 +1001,14 @@ discard block |
||
| 1001 | 1001 | * @param bool $check_expiration |
| 1002 | 1002 | * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
| 1003 | 1003 | */ |
| 1004 | - public function expire( $check_expiration = false ) { |
|
| 1004 | + public function expire($check_expiration = false) { |
|
| 1005 | 1005 | |
| 1006 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
| 1006 | + if ($check_expiration && $this->get_expiration_time() > current_time('timestamp')) { |
|
| 1007 | 1007 | // Do not mark as expired since real expiration date is in the future |
| 1008 | 1008 | return false; |
| 1009 | 1009 | } |
| 1010 | 1010 | |
| 1011 | - $this->set_status( 'expired' ); |
|
| 1011 | + $this->set_status('expired'); |
|
| 1012 | 1012 | return $this->save(); |
| 1013 | 1013 | |
| 1014 | 1014 | } |
@@ -1020,7 +1020,7 @@ discard block |
||
| 1020 | 1020 | * @return int Subscription id. |
| 1021 | 1021 | */ |
| 1022 | 1022 | public function failing() { |
| 1023 | - $this->set_status( 'failing' ); |
|
| 1023 | + $this->set_status('failing'); |
|
| 1024 | 1024 | return $this->save(); |
| 1025 | 1025 | } |
| 1026 | 1026 | |
@@ -1031,7 +1031,7 @@ discard block |
||
| 1031 | 1031 | * @return int Subscription id. |
| 1032 | 1032 | */ |
| 1033 | 1033 | public function cancel() { |
| 1034 | - $this->set_status( 'cancelled' ); |
|
| 1034 | + $this->set_status('cancelled'); |
|
| 1035 | 1035 | return $this->save(); |
| 1036 | 1036 | } |
| 1037 | 1037 | |
@@ -1042,7 +1042,7 @@ discard block |
||
| 1042 | 1042 | * @return bool |
| 1043 | 1043 | */ |
| 1044 | 1044 | public function can_cancel() { |
| 1045 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
| 1045 | + return apply_filters('wpinv_subscription_can_cancel', $this->has_status($this->get_cancellable_statuses()), $this); |
|
| 1046 | 1046 | } |
| 1047 | 1047 | |
| 1048 | 1048 | /** |
@@ -1053,7 +1053,7 @@ discard block |
||
| 1053 | 1053 | * @return array |
| 1054 | 1054 | */ |
| 1055 | 1055 | public function get_cancellable_statuses() { |
| 1056 | - return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
|
| 1056 | + return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing')); |
|
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | 1059 | /** |
@@ -1063,8 +1063,8 @@ discard block |
||
| 1063 | 1063 | * @return string |
| 1064 | 1064 | */ |
| 1065 | 1065 | public function get_cancel_url() { |
| 1066 | - $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
| 1067 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
| 1066 | + $url = getpaid_get_authenticated_action_url('subscription_cancel', $this->get_view_url()); |
|
| 1067 | + return apply_filters('wpinv_subscription_cancel_url', $url, $this); |
|
| 1068 | 1068 | } |
| 1069 | 1069 | |
| 1070 | 1070 | /** |
@@ -1074,8 +1074,8 @@ discard block |
||
| 1074 | 1074 | * @return string |
| 1075 | 1075 | */ |
| 1076 | 1076 | public function get_view_url() { |
| 1077 | - $url = add_query_arg( 'subscription', $this->get_id(), get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
| 1078 | - return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
| 1077 | + $url = add_query_arg('subscription', $this->get_id(), get_permalink((int) wpinv_get_option('invoice_subscription_page'))); |
|
| 1078 | + return apply_filters('getpaid_get_subscription_view_url', $url, $this); |
|
| 1079 | 1079 | } |
| 1080 | 1080 | |
| 1081 | 1081 | /** |
@@ -1088,7 +1088,7 @@ discard block |
||
| 1088 | 1088 | * @return bool |
| 1089 | 1089 | */ |
| 1090 | 1090 | public function can_renew() { |
| 1091 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
| 1091 | + return apply_filters('wpinv_subscription_can_renew', true, $this); |
|
| 1092 | 1092 | } |
| 1093 | 1093 | |
| 1094 | 1094 | /** |
@@ -1098,8 +1098,8 @@ discard block |
||
| 1098 | 1098 | * @return string |
| 1099 | 1099 | */ |
| 1100 | 1100 | public function get_renew_url() { |
| 1101 | - $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' ); |
|
| 1102 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
| 1101 | + $url = wp_nonce_url(add_query_arg(array('getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id)), 'getpaid-nonce'); |
|
| 1102 | + return apply_filters('wpinv_subscription_renew_url', $url, $this); |
|
| 1103 | 1103 | } |
| 1104 | 1104 | |
| 1105 | 1105 | /** |
@@ -1109,7 +1109,7 @@ discard block |
||
| 1109 | 1109 | * @return bool |
| 1110 | 1110 | */ |
| 1111 | 1111 | public function can_update() { |
| 1112 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
| 1112 | + return apply_filters('wpinv_subscription_can_update', false, $this); |
|
| 1113 | 1113 | } |
| 1114 | 1114 | |
| 1115 | 1115 | /** |
@@ -1119,8 +1119,8 @@ discard block |
||
| 1119 | 1119 | * @return string |
| 1120 | 1120 | */ |
| 1121 | 1121 | public function get_update_url() { |
| 1122 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
| 1123 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
| 1122 | + $url = add_query_arg(array('action' => 'update', 'subscription_id' => $this->get_id())); |
|
| 1123 | + return apply_filters('wpinv_subscription_update_url', $url, $this); |
|
| 1124 | 1124 | } |
| 1125 | 1125 | |
| 1126 | 1126 | /** |
@@ -1130,7 +1130,7 @@ discard block |
||
| 1130 | 1130 | * @return string |
| 1131 | 1131 | */ |
| 1132 | 1132 | public function get_status_label() { |
| 1133 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
| 1133 | + return getpaid_get_subscription_status_label($this->get_status()); |
|
| 1134 | 1134 | } |
| 1135 | 1135 | |
| 1136 | 1136 | /** |
@@ -1141,7 +1141,7 @@ discard block |
||
| 1141 | 1141 | */ |
| 1142 | 1142 | public function get_status_class() { |
| 1143 | 1143 | $statuses = getpaid_get_subscription_status_classes(); |
| 1144 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary'; |
|
| 1144 | + return isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : 'text-white bg-secondary'; |
|
| 1145 | 1145 | } |
| 1146 | 1146 | |
| 1147 | 1147 | /** |
@@ -1152,9 +1152,9 @@ discard block |
||
| 1152 | 1152 | */ |
| 1153 | 1153 | public function get_status_label_html() { |
| 1154 | 1154 | |
| 1155 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
| 1156 | - $class = esc_attr( $this->get_status_class() ); |
|
| 1157 | - $status = sanitize_html_class( $this->get_status_label() ); |
|
| 1155 | + $status_label = sanitize_text_field($this->get_status_label()); |
|
| 1156 | + $class = esc_attr($this->get_status_class()); |
|
| 1157 | + $status = sanitize_html_class($this->get_status_label()); |
|
| 1158 | 1158 | |
| 1159 | 1159 | return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>"; |
| 1160 | 1160 | } |
@@ -1166,9 +1166,9 @@ discard block |
||
| 1166 | 1166 | * @param string $txn_id The transaction ID from the merchant processor |
| 1167 | 1167 | * @return bool |
| 1168 | 1168 | */ |
| 1169 | - public function payment_exists( $txn_id = '' ) { |
|
| 1170 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
| 1171 | - return ! empty( $invoice_id ); |
|
| 1169 | + public function payment_exists($txn_id = '') { |
|
| 1170 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field($txn_id, 'transaction_id'); |
|
| 1171 | + return !empty($invoice_id); |
|
| 1172 | 1172 | } |
| 1173 | 1173 | |
| 1174 | 1174 | /** |
@@ -1180,35 +1180,35 @@ discard block |
||
| 1180 | 1180 | // Reset status transition variable. |
| 1181 | 1181 | $this->status_transition = false; |
| 1182 | 1182 | |
| 1183 | - if ( $status_transition ) { |
|
| 1183 | + if ($status_transition) { |
|
| 1184 | 1184 | try { |
| 1185 | 1185 | |
| 1186 | 1186 | // Fire a hook for the status change. |
| 1187 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
| 1188 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
| 1187 | + do_action('wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition); |
|
| 1188 | + do_action('getpaid_subscription_' . $status_transition['to'], $this, $status_transition); |
|
| 1189 | 1189 | |
| 1190 | - if ( ! empty( $status_transition['from'] ) ) { |
|
| 1190 | + if (!empty($status_transition['from'])) { |
|
| 1191 | 1191 | |
| 1192 | 1192 | /* translators: 1: old subscription status 2: new subscription status */ |
| 1193 | - $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1193 | + $transition_note = sprintf(__('Subscription status changed from %1$s to %2$s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['from']), getpaid_get_subscription_status_label($status_transition['to'])); |
|
| 1194 | 1194 | |
| 1195 | 1195 | // Note the transition occurred. |
| 1196 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1196 | + $this->get_parent_payment()->add_note($transition_note, false, false, true); |
|
| 1197 | 1197 | |
| 1198 | 1198 | // Fire another hook. |
| 1199 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
| 1200 | - do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
| 1199 | + do_action('getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this); |
|
| 1200 | + do_action('getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to']); |
|
| 1201 | 1201 | |
| 1202 | 1202 | } else { |
| 1203 | 1203 | /* translators: %s: new invoice status */ |
| 1204 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
| 1204 | + $transition_note = sprintf(__('Subscription status set to %s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['to'])); |
|
| 1205 | 1205 | |
| 1206 | 1206 | // Note the transition occurred. |
| 1207 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
| 1207 | + $this->get_parent_payment()->add_note($transition_note, false, false, true); |
|
| 1208 | 1208 | |
| 1209 | 1209 | } |
| 1210 | - } catch ( Exception $e ) { |
|
| 1211 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
| 1210 | + } catch (Exception $e) { |
|
| 1211 | + $this->get_parent_payment()->add_note(__('Error during subscription status transition.', 'invoicing') . ' ' . $e->getMessage()); |
|
| 1212 | 1212 | } |
| 1213 | 1213 | } |
| 1214 | 1214 | |
@@ -1234,7 +1234,7 @@ discard block |
||
| 1234 | 1234 | */ |
| 1235 | 1235 | public function activate() { |
| 1236 | 1236 | $status = 'trialling' == $this->get_status() ? 'trialling' : 'active'; |
| 1237 | - $this->set_status( $status ); |
|
| 1237 | + $this->set_status($status); |
|
| 1238 | 1238 | return $this->save(); |
| 1239 | 1239 | } |
| 1240 | 1240 | |
@@ -13,58 +13,58 @@ discard block |
||
| 13 | 13 | class GetPaid_Authorize_Net_Gateway extends GetPaid_Authorize_Net_Legacy_Gateway { |
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | - * Payment method id. |
|
| 17 | - * |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 16 | + * Payment method id. |
|
| 17 | + * |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | 20 | public $id = 'authorizenet'; |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * An array of features that this gateway supports. |
|
| 24 | - * |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 23 | + * An array of features that this gateway supports. |
|
| 24 | + * |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'tokens' ); |
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | - * Payment method order. |
|
| 31 | - * |
|
| 32 | - * @var int |
|
| 33 | - */ |
|
| 30 | + * Payment method order. |
|
| 31 | + * |
|
| 32 | + * @var int |
|
| 33 | + */ |
|
| 34 | 34 | public $order = 4; |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | - * Endpoint for requests from Authorize.net. |
|
| 38 | - * |
|
| 39 | - * @var string |
|
| 40 | - */ |
|
| 41 | - protected $notify_url; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Endpoint for requests to Authorize.net. |
|
| 45 | - * |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 37 | + * Endpoint for requests from Authorize.net. |
|
| 38 | + * |
|
| 39 | + * @var string |
|
| 40 | + */ |
|
| 41 | + protected $notify_url; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Endpoint for requests to Authorize.net. |
|
| 45 | + * |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | 48 | protected $endpoint; |
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | - * Currencies this gateway is allowed for. |
|
| 52 | - * |
|
| 53 | - * @var array |
|
| 54 | - */ |
|
| 55 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
| 51 | + * Currencies this gateway is allowed for. |
|
| 52 | + * |
|
| 53 | + * @var array |
|
| 54 | + */ |
|
| 55 | + public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | - * URL to view a transaction. |
|
| 59 | - * |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 58 | + * URL to view a transaction. |
|
| 59 | + * |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | 62 | public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s'; |
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | - * Class constructor. |
|
| 66 | - */ |
|
| 67 | - public function __construct() { |
|
| 65 | + * Class constructor. |
|
| 66 | + */ |
|
| 67 | + public function __construct() { |
|
| 68 | 68 | |
| 69 | 69 | $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
| 70 | 70 | $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
@@ -76,11 +76,11 @@ discard block |
||
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
| 79 | - * Displays the payment method select field. |
|
| 80 | - * |
|
| 81 | - * @param int $invoice_id 0 or invoice id. |
|
| 82 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
| 83 | - */ |
|
| 79 | + * Displays the payment method select field. |
|
| 80 | + * |
|
| 81 | + * @param int $invoice_id 0 or invoice id. |
|
| 82 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
| 83 | + */ |
|
| 84 | 84 | public function payment_fields( $invoice_id, $form ) { |
| 85 | 85 | |
| 86 | 86 | // Let the user select a payment method. |
@@ -91,16 +91,16 @@ discard block |
||
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
| 94 | - * Creates a customer profile. |
|
| 95 | - * |
|
| 96 | - * |
|
| 97 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 94 | + * Creates a customer profile. |
|
| 95 | + * |
|
| 96 | + * |
|
| 97 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 98 | 98 | * @param array $submission_data Posted checkout fields. |
| 99 | 99 | * @param bool $save Whether or not to save the payment as a token. |
| 100 | 100 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
| 101 | - * @return string|WP_Error Payment profile id. |
|
| 102 | - */ |
|
| 103 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
| 101 | + * @return string|WP_Error Payment profile id. |
|
| 102 | + */ |
|
| 103 | + public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
| 104 | 104 | |
| 105 | 105 | // Remove non-digits from the number |
| 106 | 106 | $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -167,14 +167,14 @@ discard block |
||
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
| 170 | - * Retrieves a customer profile. |
|
| 171 | - * |
|
| 172 | - * |
|
| 173 | - * @param string $profile_id profile id. |
|
| 174 | - * @return string|WP_Error Profile id. |
|
| 170 | + * Retrieves a customer profile. |
|
| 171 | + * |
|
| 172 | + * |
|
| 173 | + * @param string $profile_id profile id. |
|
| 174 | + * @return string|WP_Error Profile id. |
|
| 175 | 175 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
| 176 | - */ |
|
| 177 | - public function get_customer_profile( $profile_id ) { |
|
| 176 | + */ |
|
| 177 | + public function get_customer_profile( $profile_id ) { |
|
| 178 | 178 | |
| 179 | 179 | // Generate args. |
| 180 | 180 | $args = array( |
@@ -189,17 +189,17 @@ discard block |
||
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
| 192 | - * Creates a customer profile. |
|
| 193 | - * |
|
| 194 | - * |
|
| 192 | + * Creates a customer profile. |
|
| 193 | + * |
|
| 194 | + * |
|
| 195 | 195 | * @param string $profile_id profile id. |
| 196 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 196 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 197 | 197 | * @param array $submission_data Posted checkout fields. |
| 198 | 198 | * @param bool $save Whether or not to save the payment as a token. |
| 199 | 199 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
| 200 | - * @return string|WP_Error Profile id. |
|
| 201 | - */ |
|
| 202 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
| 200 | + * @return string|WP_Error Profile id. |
|
| 201 | + */ |
|
| 202 | + public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
| 203 | 203 | |
| 204 | 204 | // Remove non-digits from the number |
| 205 | 205 | $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -259,15 +259,15 @@ discard block |
||
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
| 262 | - * Retrieves a customer payment profile. |
|
| 263 | - * |
|
| 264 | - * |
|
| 265 | - * @param string $customer_profile_id customer profile id. |
|
| 262 | + * Retrieves a customer payment profile. |
|
| 263 | + * |
|
| 264 | + * |
|
| 265 | + * @param string $customer_profile_id customer profile id. |
|
| 266 | 266 | * @param string $payment_profile_id payment profile id. |
| 267 | - * @return string|WP_Error Profile id. |
|
| 267 | + * @return string|WP_Error Profile id. |
|
| 268 | 268 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
| 269 | - */ |
|
| 270 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
| 269 | + */ |
|
| 270 | + public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
| 271 | 271 | |
| 272 | 272 | // Generate args. |
| 273 | 273 | $args = array( |
@@ -283,15 +283,15 @@ discard block |
||
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | /** |
| 286 | - * Charges a customer payment profile. |
|
| 287 | - * |
|
| 286 | + * Charges a customer payment profile. |
|
| 287 | + * |
|
| 288 | 288 | * @param string $customer_profile_id customer profile id. |
| 289 | 289 | * @param string $payment_profile_id payment profile id. |
| 290 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 290 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 291 | 291 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
| 292 | - * @return WP_Error|object |
|
| 293 | - */ |
|
| 294 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
| 292 | + * @return WP_Error|object |
|
| 293 | + */ |
|
| 294 | + public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
| 295 | 295 | |
| 296 | 296 | // Generate args. |
| 297 | 297 | $args = array( |
@@ -333,41 +333,41 @@ discard block |
||
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
| 336 | - * Processes a customer charge. |
|
| 337 | - * |
|
| 336 | + * Processes a customer charge. |
|
| 337 | + * |
|
| 338 | 338 | * @param stdClass $result Api response. |
| 339 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 340 | - */ |
|
| 341 | - public function process_charge_response( $result, $invoice ) { |
|
| 339 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 340 | + */ |
|
| 341 | + public function process_charge_response( $result, $invoice ) { |
|
| 342 | 342 | |
| 343 | 343 | wpinv_clear_errors(); |
| 344 | - $response_code = (int) $result->transactionResponse->responseCode; |
|
| 344 | + $response_code = (int) $result->transactionResponse->responseCode; |
|
| 345 | 345 | |
| 346 | - // Succeeded. |
|
| 347 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
| 346 | + // Succeeded. |
|
| 347 | + if ( 1 == $response_code || 4 == $response_code ) { |
|
| 348 | 348 | |
| 349 | - // Maybe set a transaction id. |
|
| 350 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
| 351 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
| 352 | - } |
|
| 349 | + // Maybe set a transaction id. |
|
| 350 | + if ( ! empty( $result->transactionResponse->transId ) ) { |
|
| 351 | + $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
| 352 | + } |
|
| 353 | 353 | |
| 354 | - $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
| 354 | + $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
| 355 | 355 | |
| 356 | - if ( 1 == $response_code ) { |
|
| 357 | - return $invoice->mark_paid(); |
|
| 358 | - } |
|
| 356 | + if ( 1 == $response_code ) { |
|
| 357 | + return $invoice->mark_paid(); |
|
| 358 | + } |
|
| 359 | 359 | |
| 360 | - $invoice->set_status( 'wpi-onhold' ); |
|
| 361 | - $invoice->add_note( |
|
| 360 | + $invoice->set_status( 'wpi-onhold' ); |
|
| 361 | + $invoice->add_note( |
|
| 362 | 362 | sprintf( |
| 363 | 363 | __( 'Held for review: %s', 'invoicing' ), |
| 364 | 364 | $result->transactionResponse->messages->message[0]->description |
| 365 | 365 | ) |
| 366 | - ); |
|
| 366 | + ); |
|
| 367 | 367 | |
| 368 | - return $invoice->save(); |
|
| 368 | + return $invoice->save(); |
|
| 369 | 369 | |
| 370 | - } |
|
| 370 | + } |
|
| 371 | 371 | |
| 372 | 372 | wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) ); |
| 373 | 373 | |
@@ -379,13 +379,13 @@ discard block |
||
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | /** |
| 382 | - * Returns payment information. |
|
| 383 | - * |
|
| 384 | - * |
|
| 385 | - * @param array $card Card details. |
|
| 386 | - * @return array |
|
| 387 | - */ |
|
| 388 | - public function get_payment_information( $card ) { |
|
| 382 | + * Returns payment information. |
|
| 383 | + * |
|
| 384 | + * |
|
| 385 | + * @param array $card Card details. |
|
| 386 | + * @return array |
|
| 387 | + */ |
|
| 388 | + public function get_payment_information( $card ) { |
|
| 389 | 389 | return array( |
| 390 | 390 | |
| 391 | 391 | 'creditCard' => array ( |
@@ -398,25 +398,25 @@ discard block |
||
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | /** |
| 401 | - * Returns the customer profile meta name. |
|
| 402 | - * |
|
| 403 | - * |
|
| 404 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 405 | - * @return string |
|
| 406 | - */ |
|
| 407 | - public function get_customer_profile_meta_name( $invoice ) { |
|
| 401 | + * Returns the customer profile meta name. |
|
| 402 | + * |
|
| 403 | + * |
|
| 404 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 405 | + * @return string |
|
| 406 | + */ |
|
| 407 | + public function get_customer_profile_meta_name( $invoice ) { |
|
| 408 | 408 | return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | /** |
| 412 | - * Validates the submitted data. |
|
| 413 | - * |
|
| 414 | - * |
|
| 415 | - * @param array $submission_data Posted checkout fields. |
|
| 412 | + * Validates the submitted data. |
|
| 413 | + * |
|
| 414 | + * |
|
| 415 | + * @param array $submission_data Posted checkout fields. |
|
| 416 | 416 | * @param WPInv_Invoice $invoice |
| 417 | - * @return WP_Error|string The payment profile id |
|
| 418 | - */ |
|
| 419 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
| 417 | + * @return WP_Error|string The payment profile id |
|
| 418 | + */ |
|
| 419 | + public function validate_submission_data( $submission_data, $invoice ) { |
|
| 420 | 420 | |
| 421 | 421 | // Validate authentication details. |
| 422 | 422 | $auth = $this->get_auth_params(); |
@@ -448,13 +448,13 @@ discard block |
||
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | /** |
| 451 | - * Returns invoice line items. |
|
| 452 | - * |
|
| 453 | - * |
|
| 454 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 455 | - * @return array |
|
| 456 | - */ |
|
| 457 | - public function get_line_items( $invoice ) { |
|
| 451 | + * Returns invoice line items. |
|
| 452 | + * |
|
| 453 | + * |
|
| 454 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 455 | + * @return array |
|
| 456 | + */ |
|
| 457 | + public function get_line_items( $invoice ) { |
|
| 458 | 458 | $items = array(); |
| 459 | 459 | |
| 460 | 460 | foreach ( $invoice->get_items() as $item ) { |
@@ -474,15 +474,15 @@ discard block |
||
| 474 | 474 | } |
| 475 | 475 | |
| 476 | 476 | /** |
| 477 | - * Process Payment. |
|
| 478 | - * |
|
| 479 | - * |
|
| 480 | - * @param WPInv_Invoice $invoice Invoice. |
|
| 481 | - * @param array $submission_data Posted checkout fields. |
|
| 482 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 483 | - * @return array |
|
| 484 | - */ |
|
| 485 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 477 | + * Process Payment. |
|
| 478 | + * |
|
| 479 | + * |
|
| 480 | + * @param WPInv_Invoice $invoice Invoice. |
|
| 481 | + * @param array $submission_data Posted checkout fields. |
|
| 482 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
| 483 | + * @return array |
|
| 484 | + */ |
|
| 485 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 486 | 486 | |
| 487 | 487 | // Validate the submitted data. |
| 488 | 488 | $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
@@ -515,69 +515,69 @@ discard block |
||
| 515 | 515 | |
| 516 | 516 | exit; |
| 517 | 517 | |
| 518 | - } |
|
| 518 | + } |
|
| 519 | 519 | |
| 520 | - /** |
|
| 521 | - * Processes the initial payment. |
|
| 522 | - * |
|
| 520 | + /** |
|
| 521 | + * Processes the initial payment. |
|
| 522 | + * |
|
| 523 | 523 | * @param WPInv_Invoice $invoice Invoice. |
| 524 | - */ |
|
| 525 | - protected function process_initial_payment( $invoice ) { |
|
| 524 | + */ |
|
| 525 | + protected function process_initial_payment( $invoice ) { |
|
| 526 | 526 | |
| 527 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 527 | + $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 528 | 528 | $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
| 529 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
| 529 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
| 530 | 530 | |
| 531 | - // Do we have an error? |
|
| 532 | - if ( is_wp_error( $result ) ) { |
|
| 533 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
| 534 | - wpinv_send_back_to_checkout(); |
|
| 535 | - } |
|
| 531 | + // Do we have an error? |
|
| 532 | + if ( is_wp_error( $result ) ) { |
|
| 533 | + wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
| 534 | + wpinv_send_back_to_checkout(); |
|
| 535 | + } |
|
| 536 | 536 | |
| 537 | - // Process the response. |
|
| 538 | - $this->process_charge_response( $result, $invoice ); |
|
| 537 | + // Process the response. |
|
| 538 | + $this->process_charge_response( $result, $invoice ); |
|
| 539 | 539 | |
| 540 | - if ( wpinv_get_errors() ) { |
|
| 541 | - wpinv_send_back_to_checkout(); |
|
| 542 | - } |
|
| 540 | + if ( wpinv_get_errors() ) { |
|
| 541 | + wpinv_send_back_to_checkout(); |
|
| 542 | + } |
|
| 543 | 543 | |
| 544 | - } |
|
| 544 | + } |
|
| 545 | 545 | |
| 546 | 546 | /** |
| 547 | - * Processes recurring payments. |
|
| 548 | - * |
|
| 547 | + * Processes recurring payments. |
|
| 548 | + * |
|
| 549 | 549 | * @param WPInv_Invoice $invoice Invoice. |
| 550 | 550 | * @param WPInv_Subscription $subscription Subscription. |
| 551 | - */ |
|
| 552 | - public function process_subscription( $invoice, $subscription ) { |
|
| 551 | + */ |
|
| 552 | + public function process_subscription( $invoice, $subscription ) { |
|
| 553 | 553 | |
| 554 | 554 | // Check if there is an initial amount to charge. |
| 555 | 555 | if ( (float) $invoice->get_total() > 0 ) { |
| 556 | - $this->process_initial_payment( $invoice ); |
|
| 556 | + $this->process_initial_payment( $invoice ); |
|
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | // Activate the subscription. |
| 560 | 560 | $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
| 561 | 561 | $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
| 562 | 562 | |
| 563 | - $subscription->set_next_renewal_date( $expiry ); |
|
| 564 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 565 | - $subscription->set_profile_id( $invoice->generate_key() ); |
|
| 566 | - $subscription->activate(); |
|
| 563 | + $subscription->set_next_renewal_date( $expiry ); |
|
| 564 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 565 | + $subscription->set_profile_id( $invoice->generate_key() ); |
|
| 566 | + $subscription->activate(); |
|
| 567 | 567 | |
| 568 | - // Redirect to the success page. |
|
| 568 | + // Redirect to the success page. |
|
| 569 | 569 | wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
| 570 | 570 | |
| 571 | 571 | } |
| 572 | 572 | |
| 573 | - /** |
|
| 574 | - * (Maybe) renews an authorize.net subscription profile. |
|
| 575 | - * |
|
| 576 | - * |
|
| 577 | - * @param bool $should_expire |
|
| 573 | + /** |
|
| 574 | + * (Maybe) renews an authorize.net subscription profile. |
|
| 575 | + * |
|
| 576 | + * |
|
| 577 | + * @param bool $should_expire |
|
| 578 | 578 | * @param WPInv_Subscription $subscription |
| 579 | - */ |
|
| 580 | - public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
| 579 | + */ |
|
| 580 | + public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
| 581 | 581 | |
| 582 | 582 | // Ensure its our subscription && it's active. |
| 583 | 583 | if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) { |
@@ -594,18 +594,18 @@ discard block |
||
| 594 | 594 | |
| 595 | 595 | return false; |
| 596 | 596 | |
| 597 | - } |
|
| 597 | + } |
|
| 598 | 598 | |
| 599 | 599 | /** |
| 600 | - * Renews a subscription. |
|
| 601 | - * |
|
| 600 | + * Renews a subscription. |
|
| 601 | + * |
|
| 602 | 602 | * @param WPInv_Subscription $subscription |
| 603 | - */ |
|
| 604 | - public function renew_subscription( $subscription ) { |
|
| 603 | + */ |
|
| 604 | + public function renew_subscription( $subscription ) { |
|
| 605 | 605 | |
| 606 | - // Generate the renewal invoice. |
|
| 607 | - $new_invoice = $subscription->create_payment(); |
|
| 608 | - $old_invoice = $subscription->get_parent_payment(); |
|
| 606 | + // Generate the renewal invoice. |
|
| 607 | + $new_invoice = $subscription->create_payment(); |
|
| 608 | + $old_invoice = $subscription->get_parent_payment(); |
|
| 609 | 609 | |
| 610 | 610 | if ( empty( $new_invoice ) ) { |
| 611 | 611 | $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
@@ -614,37 +614,37 @@ discard block |
||
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | // Charge the payment method. |
| 617 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 618 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
| 619 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
| 620 | - |
|
| 621 | - // Do we have an error? |
|
| 622 | - if ( is_wp_error( $result ) ) { |
|
| 623 | - |
|
| 624 | - $old_invoice->add_note( |
|
| 625 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
| 626 | - true, |
|
| 627 | - false, |
|
| 628 | - true |
|
| 629 | - ); |
|
| 630 | - $subscription->failing(); |
|
| 631 | - return; |
|
| 632 | - |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - // Process the response. |
|
| 636 | - $this->process_charge_response( $result, $new_invoice ); |
|
| 637 | - |
|
| 638 | - if ( wpinv_get_errors() ) { |
|
| 639 | - |
|
| 640 | - $old_invoice->add_note( |
|
| 641 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
| 642 | - true, |
|
| 643 | - false, |
|
| 644 | - true |
|
| 645 | - ); |
|
| 646 | - $subscription->failing(); |
|
| 647 | - return; |
|
| 617 | + $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 618 | + $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
| 619 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
| 620 | + |
|
| 621 | + // Do we have an error? |
|
| 622 | + if ( is_wp_error( $result ) ) { |
|
| 623 | + |
|
| 624 | + $old_invoice->add_note( |
|
| 625 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
| 626 | + true, |
|
| 627 | + false, |
|
| 628 | + true |
|
| 629 | + ); |
|
| 630 | + $subscription->failing(); |
|
| 631 | + return; |
|
| 632 | + |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + // Process the response. |
|
| 636 | + $this->process_charge_response( $result, $new_invoice ); |
|
| 637 | + |
|
| 638 | + if ( wpinv_get_errors() ) { |
|
| 639 | + |
|
| 640 | + $old_invoice->add_note( |
|
| 641 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
| 642 | + true, |
|
| 643 | + false, |
|
| 644 | + true |
|
| 645 | + ); |
|
| 646 | + $subscription->failing(); |
|
| 647 | + return; |
|
| 648 | 648 | |
| 649 | 649 | } |
| 650 | 650 | |
@@ -670,11 +670,11 @@ discard block |
||
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | /** |
| 673 | - * Filters the gateway settings. |
|
| 674 | - * |
|
| 675 | - * @param array $admin_settings |
|
| 676 | - */ |
|
| 677 | - public function admin_settings( $admin_settings ) { |
|
| 673 | + * Filters the gateway settings. |
|
| 674 | + * |
|
| 675 | + * @param array $admin_settings |
|
| 676 | + */ |
|
| 677 | + public function admin_settings( $admin_settings ) { |
|
| 678 | 678 | |
| 679 | 679 | $currencies = sprintf( |
| 680 | 680 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -714,7 +714,7 @@ discard block |
||
| 714 | 714 | 'readonly' => true, |
| 715 | 715 | ); |
| 716 | 716 | |
| 717 | - return $admin_settings; |
|
| 718 | - } |
|
| 717 | + return $admin_settings; |
|
| 718 | + } |
|
| 719 | 719 | |
| 720 | 720 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Authorize.net Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @var array |
| 26 | 26 | */ |
| 27 | - protected $supports = array( 'subscription', 'sandbox', 'tokens' ); |
|
| 27 | + protected $supports = array('subscription', 'sandbox', 'tokens'); |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * Payment method order. |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * |
| 53 | 53 | * @var array |
| 54 | 54 | */ |
| 55 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
| 55 | + public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD'); |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * URL to view a transaction. |
@@ -66,12 +66,12 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function __construct() { |
| 68 | 68 | |
| 69 | - $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
|
| 70 | - $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
|
| 71 | - $this->notify_url = wpinv_get_ipn_url( $this->id ); |
|
| 69 | + $this->title = __('Credit Card / Debit Card', 'invoicing'); |
|
| 70 | + $this->method_title = __('Authorize.Net', 'invoicing'); |
|
| 71 | + $this->notify_url = wpinv_get_ipn_url($this->id); |
|
| 72 | 72 | |
| 73 | - add_filter( 'getpaid_daily_maintenance_should_expire_subscription', array( $this, 'maybe_renew_subscription' ), 10, 2 ); |
|
| 74 | - add_filter( 'getpaid_authorizenet_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
| 73 | + add_filter('getpaid_daily_maintenance_should_expire_subscription', array($this, 'maybe_renew_subscription'), 10, 2); |
|
| 74 | + add_filter('getpaid_authorizenet_sandbox_notice', array($this, 'sandbox_notice')); |
|
| 75 | 75 | parent::__construct(); |
| 76 | 76 | } |
| 77 | 77 | |
@@ -81,13 +81,13 @@ discard block |
||
| 81 | 81 | * @param int $invoice_id 0 or invoice id. |
| 82 | 82 | * @param GetPaid_Payment_Form $form Current payment form. |
| 83 | 83 | */ |
| 84 | - public function payment_fields( $invoice_id, $form ) { |
|
| 84 | + public function payment_fields($invoice_id, $form) { |
|
| 85 | 85 | |
| 86 | 86 | // Let the user select a payment method. |
| 87 | 87 | echo $this->saved_payment_methods(); |
| 88 | 88 | |
| 89 | 89 | // Show the credit card entry form. |
| 90 | - echo $this->new_payment_method_entry( $this->get_cc_form( true ) ); |
|
| 90 | + echo $this->new_payment_method_entry($this->get_cc_form(true)); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
@@ -100,64 +100,64 @@ discard block |
||
| 100 | 100 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
| 101 | 101 | * @return string|WP_Error Payment profile id. |
| 102 | 102 | */ |
| 103 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
| 103 | + public function create_customer_profile($invoice, $submission_data, $save = true) { |
|
| 104 | 104 | |
| 105 | 105 | // Remove non-digits from the number |
| 106 | - $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
| 106 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
| 107 | 107 | |
| 108 | 108 | // Generate args. |
| 109 | 109 | $args = array( |
| 110 | 110 | 'createCustomerProfileRequest' => array( |
| 111 | 111 | 'merchantAuthentication' => $this->get_auth_params(), |
| 112 | 112 | 'profile' => array( |
| 113 | - 'merchantCustomerId' => getpaid_limit_length( $invoice->get_user_id(), 20 ), |
|
| 114 | - 'description' => getpaid_limit_length( $invoice->get_full_name(), 255 ), |
|
| 115 | - 'email' => getpaid_limit_length( $invoice->get_email(), 255 ), |
|
| 113 | + 'merchantCustomerId' => getpaid_limit_length($invoice->get_user_id(), 20), |
|
| 114 | + 'description' => getpaid_limit_length($invoice->get_full_name(), 255), |
|
| 115 | + 'email' => getpaid_limit_length($invoice->get_email(), 255), |
|
| 116 | 116 | 'paymentProfiles' => array( |
| 117 | 117 | 'customerType' => 'individual', |
| 118 | 118 | |
| 119 | 119 | // Billing information. |
| 120 | 120 | 'billTo' => array( |
| 121 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
| 122 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
| 123 | - 'address' => getpaid_limit_length( $invoice->get_last_name(), 60 ), |
|
| 124 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
| 125 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
| 126 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
| 127 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
| 121 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
| 122 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
| 123 | + 'address' => getpaid_limit_length($invoice->get_last_name(), 60), |
|
| 124 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
| 125 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
| 126 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
| 127 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
| 128 | 128 | ), |
| 129 | 129 | |
| 130 | 130 | // Payment information. |
| 131 | - 'payment' => $this->get_payment_information( $submission_data['authorizenet'] ), |
|
| 131 | + 'payment' => $this->get_payment_information($submission_data['authorizenet']), |
|
| 132 | 132 | ) |
| 133 | 133 | ), |
| 134 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
| 134 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
| 135 | 135 | ) |
| 136 | 136 | ); |
| 137 | 137 | |
| 138 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice ); |
|
| 138 | + $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice); |
|
| 139 | 139 | |
| 140 | - if ( is_wp_error( $response ) ) { |
|
| 140 | + if (is_wp_error($response)) { |
|
| 141 | 141 | return $response; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId ); |
|
| 144 | + update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId); |
|
| 145 | 145 | |
| 146 | 146 | // Save the payment token. |
| 147 | - if ( $save ) { |
|
| 147 | + if ($save) { |
|
| 148 | 148 | $this->save_token( |
| 149 | 149 | array( |
| 150 | 150 | 'id' => $response->customerPaymentProfileIdList[0], |
| 151 | - 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '····' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
| 151 | + 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . '····' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
| 152 | 152 | 'default' => true, |
| 153 | - 'type' => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live', |
|
| 153 | + 'type' => $this->is_sandbox($invoice) ? 'sandbox' : 'live', |
|
| 154 | 154 | ) |
| 155 | 155 | ); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | // Add a note about the validation response. |
| 159 | 159 | $invoice->add_note( |
| 160 | - sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ), |
|
| 160 | + sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]), |
|
| 161 | 161 | false, |
| 162 | 162 | false, |
| 163 | 163 | true |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | * @return string|WP_Error Profile id. |
| 175 | 175 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
| 176 | 176 | */ |
| 177 | - public function get_customer_profile( $profile_id ) { |
|
| 177 | + public function get_customer_profile($profile_id) { |
|
| 178 | 178 | |
| 179 | 179 | // Generate args. |
| 180 | 180 | $args = array( |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | ) |
| 185 | 185 | ); |
| 186 | 186 | |
| 187 | - return $this->post( $args, false ); |
|
| 187 | + return $this->post($args, false); |
|
| 188 | 188 | |
| 189 | 189 | } |
| 190 | 190 | |
@@ -199,10 +199,10 @@ discard block |
||
| 199 | 199 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
| 200 | 200 | * @return string|WP_Error Profile id. |
| 201 | 201 | */ |
| 202 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
| 202 | + public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) { |
|
| 203 | 203 | |
| 204 | 204 | // Remove non-digits from the number |
| 205 | - $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
|
| 205 | + $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']); |
|
| 206 | 206 | |
| 207 | 207 | // Generate args. |
| 208 | 208 | $args = array( |
@@ -213,34 +213,34 @@ discard block |
||
| 213 | 213 | |
| 214 | 214 | // Billing information. |
| 215 | 215 | 'billTo' => array( |
| 216 | - 'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ), |
|
| 217 | - 'lastName' => getpaid_limit_length( $invoice->get_last_name(), 50 ), |
|
| 218 | - 'address' => getpaid_limit_length( $invoice->get_last_name(), 60 ), |
|
| 219 | - 'city' => getpaid_limit_length( $invoice->get_city(), 40 ), |
|
| 220 | - 'state' => getpaid_limit_length( $invoice->get_state(), 40 ), |
|
| 221 | - 'zip' => getpaid_limit_length( $invoice->get_zip(), 20 ), |
|
| 222 | - 'country' => getpaid_limit_length( $invoice->get_country(), 60 ), |
|
| 216 | + 'firstName' => getpaid_limit_length($invoice->get_first_name(), 50), |
|
| 217 | + 'lastName' => getpaid_limit_length($invoice->get_last_name(), 50), |
|
| 218 | + 'address' => getpaid_limit_length($invoice->get_last_name(), 60), |
|
| 219 | + 'city' => getpaid_limit_length($invoice->get_city(), 40), |
|
| 220 | + 'state' => getpaid_limit_length($invoice->get_state(), 40), |
|
| 221 | + 'zip' => getpaid_limit_length($invoice->get_zip(), 20), |
|
| 222 | + 'country' => getpaid_limit_length($invoice->get_country(), 60), |
|
| 223 | 223 | ), |
| 224 | 224 | |
| 225 | 225 | // Payment information. |
| 226 | - 'payment' => $this->get_payment_information( $submission_data['authorizenet'] ) |
|
| 226 | + 'payment' => $this->get_payment_information($submission_data['authorizenet']) |
|
| 227 | 227 | ), |
| 228 | - 'validationMode' => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode', |
|
| 228 | + 'validationMode' => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode', |
|
| 229 | 229 | ) |
| 230 | 230 | ); |
| 231 | 231 | |
| 232 | - $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
| 232 | + $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice); |
|
| 233 | 233 | |
| 234 | - if ( is_wp_error( $response ) ) { |
|
| 234 | + if (is_wp_error($response)) { |
|
| 235 | 235 | return $response; |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | // Save the payment token. |
| 239 | - if ( $save ) { |
|
| 239 | + if ($save) { |
|
| 240 | 240 | $this->save_token( |
| 241 | 241 | array( |
| 242 | 242 | 'id' => $response->customerPaymentProfileId, |
| 243 | - 'name' => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' ···· ' . substr( $submission_data['authorizenet']['cc_number'], -4 ), |
|
| 243 | + 'name' => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . ' ···· ' . substr($submission_data['authorizenet']['cc_number'], -4), |
|
| 244 | 244 | 'default' => true |
| 245 | 245 | ) |
| 246 | 246 | ); |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | |
| 249 | 249 | // Add a note about the validation response. |
| 250 | 250 | $invoice->add_note( |
| 251 | - sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ), |
|
| 251 | + sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse), |
|
| 252 | 252 | false, |
| 253 | 253 | false, |
| 254 | 254 | true |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | * @return string|WP_Error Profile id. |
| 268 | 268 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
| 269 | 269 | */ |
| 270 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
| 270 | + public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) { |
|
| 271 | 271 | |
| 272 | 272 | // Generate args. |
| 273 | 273 | $args = array( |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | ) |
| 279 | 279 | ); |
| 280 | 280 | |
| 281 | - return $this->post( $args, false ); |
|
| 281 | + return $this->post($args, false); |
|
| 282 | 282 | |
| 283 | 283 | } |
| 284 | 284 | |
@@ -291,7 +291,7 @@ discard block |
||
| 291 | 291 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
| 292 | 292 | * @return WP_Error|object |
| 293 | 293 | */ |
| 294 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
| 294 | + public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) { |
|
| 295 | 295 | |
| 296 | 296 | // Generate args. |
| 297 | 297 | $args = array( |
@@ -311,28 +311,28 @@ discard block |
||
| 311 | 311 | ) |
| 312 | 312 | ), |
| 313 | 313 | 'order' => array( |
| 314 | - 'invoiceNumber' => getpaid_limit_length( $invoice->get_number(), 20 ), |
|
| 314 | + 'invoiceNumber' => getpaid_limit_length($invoice->get_number(), 20), |
|
| 315 | 315 | ), |
| 316 | - 'lineItems' => array( 'lineItem' => $this->get_line_items( $invoice ) ), |
|
| 316 | + 'lineItems' => array('lineItem' => $this->get_line_items($invoice)), |
|
| 317 | 317 | 'tax' => array( |
| 318 | 318 | 'amount' => $invoice->get_total_tax(), |
| 319 | 319 | 'name' => getpaid_tax()->get_vat_name(), |
| 320 | 320 | ), |
| 321 | - 'poNumber' => getpaid_limit_length( $invoice->get_number(), 25 ), |
|
| 321 | + 'poNumber' => getpaid_limit_length($invoice->get_number(), 25), |
|
| 322 | 322 | 'customer' => array( |
| 323 | - 'id' => getpaid_limit_length( $invoice->get_user_id(), 25 ), |
|
| 324 | - 'email' => getpaid_limit_length( $invoice->get_email(), 25 ), |
|
| 323 | + 'id' => getpaid_limit_length($invoice->get_user_id(), 25), |
|
| 324 | + 'email' => getpaid_limit_length($invoice->get_email(), 25), |
|
| 325 | 325 | ), |
| 326 | 326 | 'customerIP' => $invoice->get_ip(), |
| 327 | 327 | ) |
| 328 | 328 | ) |
| 329 | 329 | ); |
| 330 | 330 | |
| 331 | - if ( 0 == $invoice->get_total_tax() ) { |
|
| 332 | - unset( $args['createTransactionRequest']['transactionRequest']['tax'] ); |
|
| 331 | + if (0 == $invoice->get_total_tax()) { |
|
| 332 | + unset($args['createTransactionRequest']['transactionRequest']['tax']); |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | - return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice ); |
|
| 335 | + return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice); |
|
| 336 | 336 | |
| 337 | 337 | } |
| 338 | 338 | |
@@ -342,29 +342,29 @@ discard block |
||
| 342 | 342 | * @param stdClass $result Api response. |
| 343 | 343 | * @param WPInv_Invoice $invoice Invoice. |
| 344 | 344 | */ |
| 345 | - public function process_charge_response( $result, $invoice ) { |
|
| 345 | + public function process_charge_response($result, $invoice) { |
|
| 346 | 346 | |
| 347 | 347 | wpinv_clear_errors(); |
| 348 | 348 | $response_code = (int) $result->transactionResponse->responseCode; |
| 349 | 349 | |
| 350 | 350 | // Succeeded. |
| 351 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
| 351 | + if (1 == $response_code || 4 == $response_code) { |
|
| 352 | 352 | |
| 353 | 353 | // Maybe set a transaction id. |
| 354 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
| 355 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
| 354 | + if (!empty($result->transactionResponse->transId)) { |
|
| 355 | + $invoice->set_transaction_id($result->transactionResponse->transId); |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | - $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
| 358 | + $invoice->add_note(sprintf(__('Authentication code: %s (%s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true); |
|
| 359 | 359 | |
| 360 | - if ( 1 == $response_code ) { |
|
| 360 | + if (1 == $response_code) { |
|
| 361 | 361 | return $invoice->mark_paid(); |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | - $invoice->set_status( 'wpi-onhold' ); |
|
| 364 | + $invoice->set_status('wpi-onhold'); |
|
| 365 | 365 | $invoice->add_note( |
| 366 | 366 | sprintf( |
| 367 | - __( 'Held for review: %s', 'invoicing' ), |
|
| 367 | + __('Held for review: %s', 'invoicing'), |
|
| 368 | 368 | $result->transactionResponse->messages->message[0]->description |
| 369 | 369 | ) |
| 370 | 370 | ); |
@@ -373,11 +373,11 @@ discard block |
||
| 373 | 373 | |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | - wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) ); |
|
| 376 | + wpinv_set_error('card_declined', __('Credit card declined.', 'invoicing')); |
|
| 377 | 377 | |
| 378 | - if ( ! empty( $result->transactionResponse->errors ) ) { |
|
| 378 | + if (!empty($result->transactionResponse->errors)) { |
|
| 379 | 379 | $errors = (object) $result->transactionResponse->errors; |
| 380 | - wpinv_set_error( $errors->error[0]->errorCode, esc_html( $errors->error[0]->errorText ) ); |
|
| 380 | + wpinv_set_error($errors->error[0]->errorCode, esc_html($errors->error[0]->errorText)); |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | } |
@@ -389,10 +389,10 @@ discard block |
||
| 389 | 389 | * @param array $card Card details. |
| 390 | 390 | * @return array |
| 391 | 391 | */ |
| 392 | - public function get_payment_information( $card ) { |
|
| 392 | + public function get_payment_information($card) { |
|
| 393 | 393 | return array( |
| 394 | 394 | |
| 395 | - 'creditCard' => array ( |
|
| 395 | + 'creditCard' => array( |
|
| 396 | 396 | 'cardNumber' => $card['cc_number'], |
| 397 | 397 | 'expirationDate' => $card['cc_expire_year'] . '-' . $card['cc_expire_month'], |
| 398 | 398 | 'cardCode' => $card['cc_cvv2'], |
@@ -408,8 +408,8 @@ discard block |
||
| 408 | 408 | * @param WPInv_Invoice $invoice Invoice. |
| 409 | 409 | * @return string |
| 410 | 410 | */ |
| 411 | - public function get_customer_profile_meta_name( $invoice ) { |
|
| 412 | - return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
| 411 | + public function get_customer_profile_meta_name($invoice) { |
|
| 412 | + return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | /** |
@@ -420,34 +420,34 @@ discard block |
||
| 420 | 420 | * @param WPInv_Invoice $invoice |
| 421 | 421 | * @return WP_Error|string The payment profile id |
| 422 | 422 | */ |
| 423 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
| 423 | + public function validate_submission_data($submission_data, $invoice) { |
|
| 424 | 424 | |
| 425 | 425 | // Validate authentication details. |
| 426 | 426 | $auth = $this->get_auth_params(); |
| 427 | 427 | |
| 428 | - if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) { |
|
| 429 | - return new WP_Error( 'invalid_settings', __( 'Please set-up your login id and transaction key before using this gateway.', 'invoicing') ); |
|
| 428 | + if (empty($auth['name']) || empty($auth['transactionKey'])) { |
|
| 429 | + return new WP_Error('invalid_settings', __('Please set-up your login id and transaction key before using this gateway.', 'invoicing')); |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | // Validate the payment method. |
| 433 | - if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) { |
|
| 434 | - return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing') ); |
|
| 433 | + if (empty($submission_data['getpaid-authorizenet-payment-method'])) { |
|
| 434 | + return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing')); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | // Are we adding a new payment method? |
| 438 | - if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) { |
|
| 438 | + if ('new' != $submission_data['getpaid-authorizenet-payment-method']) { |
|
| 439 | 439 | return $submission_data['getpaid-authorizenet-payment-method']; |
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | // Retrieve the customer profile id. |
| 443 | - $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
| 443 | + $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
| 444 | 444 | |
| 445 | 445 | // Create payment method. |
| 446 | - if ( empty( $profile_id ) ) { |
|
| 447 | - return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
| 446 | + if (empty($profile_id)) { |
|
| 447 | + return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | - return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) ); |
|
| 450 | + return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method'])); |
|
| 451 | 451 | |
| 452 | 452 | } |
| 453 | 453 | |
@@ -458,16 +458,16 @@ discard block |
||
| 458 | 458 | * @param WPInv_Invoice $invoice Invoice. |
| 459 | 459 | * @return array |
| 460 | 460 | */ |
| 461 | - public function get_line_items( $invoice ) { |
|
| 461 | + public function get_line_items($invoice) { |
|
| 462 | 462 | $items = array(); |
| 463 | 463 | |
| 464 | - foreach ( $invoice->get_items() as $item ) { |
|
| 464 | + foreach ($invoice->get_items() as $item) { |
|
| 465 | 465 | |
| 466 | 466 | $amount = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price(); |
| 467 | 467 | $items[] = array( |
| 468 | - 'itemId' => getpaid_limit_length( $item->get_id(), 31 ), |
|
| 469 | - 'name' => getpaid_limit_length( $item->get_raw_name(), 31 ), |
|
| 470 | - 'description' => getpaid_limit_length( $item->get_description(), 255 ), |
|
| 468 | + 'itemId' => getpaid_limit_length($item->get_id(), 31), |
|
| 469 | + 'name' => getpaid_limit_length($item->get_raw_name(), 31), |
|
| 470 | + 'description' => getpaid_limit_length($item->get_description(), 255), |
|
| 471 | 471 | 'quantity' => (string) $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(), |
| 472 | 472 | 'unitPrice' => (float) $amount, |
| 473 | 473 | 'taxable' => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(), |
@@ -475,15 +475,15 @@ discard block |
||
| 475 | 475 | |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | - foreach ( $invoice->get_fees() as $fee_name => $fee ) { |
|
| 478 | + foreach ($invoice->get_fees() as $fee_name => $fee) { |
|
| 479 | 479 | |
| 480 | - $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee']; |
|
| 480 | + $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee']; |
|
| 481 | 481 | |
| 482 | - if ( $amount > 0 ) { |
|
| 482 | + if ($amount > 0) { |
|
| 483 | 483 | $items[] = array( |
| 484 | - 'itemId' => getpaid_limit_length( $fee_name, 31 ), |
|
| 485 | - 'name' => getpaid_limit_length( $fee_name, 31 ), |
|
| 486 | - 'description' => getpaid_limit_length( $fee_name, 255 ), |
|
| 484 | + 'itemId' => getpaid_limit_length($fee_name, 31), |
|
| 485 | + 'name' => getpaid_limit_length($fee_name, 31), |
|
| 486 | + 'description' => getpaid_limit_length($fee_name, 255), |
|
| 487 | 487 | 'quantity' => '1', |
| 488 | 488 | 'unitPrice' => (float) $amount, |
| 489 | 489 | 'taxable' => false, |
@@ -504,36 +504,36 @@ discard block |
||
| 504 | 504 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
| 505 | 505 | * @return array |
| 506 | 506 | */ |
| 507 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
| 507 | + public function process_payment($invoice, $submission_data, $submission) { |
|
| 508 | 508 | |
| 509 | 509 | // Validate the submitted data. |
| 510 | - $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
|
| 510 | + $payment_profile_id = $this->validate_submission_data($submission_data, $invoice); |
|
| 511 | 511 | |
| 512 | 512 | // Do we have an error? |
| 513 | - if ( is_wp_error( $payment_profile_id ) ) { |
|
| 514 | - wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() ); |
|
| 513 | + if (is_wp_error($payment_profile_id)) { |
|
| 514 | + wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message()); |
|
| 515 | 515 | wpinv_send_back_to_checkout(); |
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | // Save the payment method to the order. |
| 519 | - update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id ); |
|
| 519 | + update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id); |
|
| 520 | 520 | |
| 521 | 521 | // Check if this is a subscription or not. |
| 522 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
| 523 | - if ( ! empty( $subscription ) ) { |
|
| 524 | - $this->process_subscription( $invoice, $subscription ); |
|
| 522 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
| 523 | + if (!empty($subscription)) { |
|
| 524 | + $this->process_subscription($invoice, $subscription); |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | // If it is free, send to the success page. |
| 528 | - if ( ! $invoice->needs_payment() ) { |
|
| 528 | + if (!$invoice->needs_payment()) { |
|
| 529 | 529 | $invoice->mark_paid(); |
| 530 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 530 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
| 531 | 531 | } |
| 532 | 532 | |
| 533 | 533 | // Charge the payment profile. |
| 534 | - $this->process_initial_payment( $invoice ); |
|
| 534 | + $this->process_initial_payment($invoice); |
|
| 535 | 535 | |
| 536 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 536 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
| 537 | 537 | |
| 538 | 538 | exit; |
| 539 | 539 | |
@@ -544,22 +544,22 @@ discard block |
||
| 544 | 544 | * |
| 545 | 545 | * @param WPInv_Invoice $invoice Invoice. |
| 546 | 546 | */ |
| 547 | - protected function process_initial_payment( $invoice ) { |
|
| 547 | + protected function process_initial_payment($invoice) { |
|
| 548 | 548 | |
| 549 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 550 | - $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
|
| 551 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
| 549 | + $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
| 550 | + $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true); |
|
| 551 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice); |
|
| 552 | 552 | |
| 553 | 553 | // Do we have an error? |
| 554 | - if ( is_wp_error( $result ) ) { |
|
| 555 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
| 554 | + if (is_wp_error($result)) { |
|
| 555 | + wpinv_set_error($result->get_error_code(), $result->get_error_message()); |
|
| 556 | 556 | wpinv_send_back_to_checkout(); |
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | // Process the response. |
| 560 | - $this->process_charge_response( $result, $invoice ); |
|
| 560 | + $this->process_charge_response($result, $invoice); |
|
| 561 | 561 | |
| 562 | - if ( wpinv_get_errors() ) { |
|
| 562 | + if (wpinv_get_errors()) { |
|
| 563 | 563 | wpinv_send_back_to_checkout(); |
| 564 | 564 | } |
| 565 | 565 | |
@@ -571,24 +571,24 @@ discard block |
||
| 571 | 571 | * @param WPInv_Invoice $invoice Invoice. |
| 572 | 572 | * @param WPInv_Subscription $subscription Subscription. |
| 573 | 573 | */ |
| 574 | - public function process_subscription( $invoice, $subscription ) { |
|
| 574 | + public function process_subscription($invoice, $subscription) { |
|
| 575 | 575 | |
| 576 | 576 | // Check if there is an initial amount to charge. |
| 577 | - if ( (float) $invoice->get_total() > 0 ) { |
|
| 578 | - $this->process_initial_payment( $invoice ); |
|
| 577 | + if ((float) $invoice->get_total() > 0) { |
|
| 578 | + $this->process_initial_payment($invoice); |
|
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | // Activate the subscription. |
| 582 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
| 583 | - $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
|
| 582 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
| 583 | + $expiry = date('Y-m-d H:i:s', (current_time('timestamp') + $duration)); |
|
| 584 | 584 | |
| 585 | - $subscription->set_next_renewal_date( $expiry ); |
|
| 586 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 587 | - $subscription->set_profile_id( $invoice->generate_key() ); |
|
| 585 | + $subscription->set_next_renewal_date($expiry); |
|
| 586 | + $subscription->set_date_created(current_time('mysql')); |
|
| 587 | + $subscription->set_profile_id($invoice->generate_key()); |
|
| 588 | 588 | $subscription->activate(); |
| 589 | 589 | |
| 590 | 590 | // Redirect to the success page. |
| 591 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
| 591 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
| 592 | 592 | |
| 593 | 593 | } |
| 594 | 594 | |
@@ -599,20 +599,20 @@ discard block |
||
| 599 | 599 | * @param bool $should_expire |
| 600 | 600 | * @param WPInv_Subscription $subscription |
| 601 | 601 | */ |
| 602 | - public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
| 602 | + public function maybe_renew_subscription($should_expire, $subscription) { |
|
| 603 | 603 | |
| 604 | 604 | // Ensure its our subscription && it's active. |
| 605 | - if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) { |
|
| 605 | + if ($this->id != $subscription->get_gateway() || !$subscription->has_status('active trialling')) { |
|
| 606 | 606 | return $should_expire; |
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | // If this is the last renewal, complete the subscription. |
| 610 | - if ( $subscription->is_last_renewal() ) { |
|
| 610 | + if ($subscription->is_last_renewal()) { |
|
| 611 | 611 | $subscription->complete(); |
| 612 | 612 | return false; |
| 613 | 613 | } |
| 614 | 614 | |
| 615 | - $this->renew_subscription( $subscription ); |
|
| 615 | + $this->renew_subscription($subscription); |
|
| 616 | 616 | |
| 617 | 617 | return false; |
| 618 | 618 | |
@@ -623,28 +623,28 @@ discard block |
||
| 623 | 623 | * |
| 624 | 624 | * @param WPInv_Subscription $subscription |
| 625 | 625 | */ |
| 626 | - public function renew_subscription( $subscription ) { |
|
| 626 | + public function renew_subscription($subscription) { |
|
| 627 | 627 | |
| 628 | 628 | // Generate the renewal invoice. |
| 629 | 629 | $new_invoice = $subscription->create_payment(); |
| 630 | 630 | $old_invoice = $subscription->get_parent_payment(); |
| 631 | 631 | |
| 632 | - if ( empty( $new_invoice ) ) { |
|
| 633 | - $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
|
| 632 | + if (empty($new_invoice)) { |
|
| 633 | + $old_invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false); |
|
| 634 | 634 | $subscription->failing(); |
| 635 | 635 | return; |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | // Charge the payment method. |
| 639 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
| 640 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
| 641 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
| 639 | + $payment_profile_id = get_post_meta($old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true); |
|
| 640 | + $customer_profile = get_user_meta($old_invoice->get_user_id(), $this->get_customer_profile_meta_name($old_invoice), true); |
|
| 641 | + $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice); |
|
| 642 | 642 | |
| 643 | 643 | // Do we have an error? |
| 644 | - if ( is_wp_error( $result ) ) { |
|
| 644 | + if (is_wp_error($result)) { |
|
| 645 | 645 | |
| 646 | 646 | $old_invoice->add_note( |
| 647 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
| 647 | + sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()), |
|
| 648 | 648 | true, |
| 649 | 649 | false, |
| 650 | 650 | true |
@@ -655,12 +655,12 @@ discard block |
||
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | // Process the response. |
| 658 | - $this->process_charge_response( $result, $new_invoice ); |
|
| 658 | + $this->process_charge_response($result, $new_invoice); |
|
| 659 | 659 | |
| 660 | - if ( wpinv_get_errors() ) { |
|
| 660 | + if (wpinv_get_errors()) { |
|
| 661 | 661 | |
| 662 | 662 | $old_invoice->add_note( |
| 663 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
| 663 | + sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()), |
|
| 664 | 664 | true, |
| 665 | 665 | false, |
| 666 | 666 | true |
@@ -670,7 +670,7 @@ discard block |
||
| 670 | 670 | |
| 671 | 671 | } |
| 672 | 672 | |
| 673 | - $subscription->add_payment( array(), $new_invoice ); |
|
| 673 | + $subscription->add_payment(array(), $new_invoice); |
|
| 674 | 674 | $subscription->renew(); |
| 675 | 675 | } |
| 676 | 676 | |
@@ -680,7 +680,7 @@ discard block |
||
| 680 | 680 | public function sandbox_notice() { |
| 681 | 681 | |
| 682 | 682 | return sprintf( |
| 683 | - __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
| 683 | + __('SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing'), |
|
| 684 | 684 | '<a href="https://developer.authorize.net/hello_world/testing_guide.html">', |
| 685 | 685 | '</a>' |
| 686 | 686 | ); |
@@ -692,42 +692,42 @@ discard block |
||
| 692 | 692 | * |
| 693 | 693 | * @param array $admin_settings |
| 694 | 694 | */ |
| 695 | - public function admin_settings( $admin_settings ) { |
|
| 695 | + public function admin_settings($admin_settings) { |
|
| 696 | 696 | |
| 697 | 697 | $currencies = sprintf( |
| 698 | - __( 'Supported Currencies: %s', 'invoicing' ), |
|
| 699 | - implode( ', ', $this->currencies ) |
|
| 698 | + __('Supported Currencies: %s', 'invoicing'), |
|
| 699 | + implode(', ', $this->currencies) |
|
| 700 | 700 | ); |
| 701 | 701 | |
| 702 | 702 | $admin_settings['authorizenet_active']['desc'] .= " ($currencies)"; |
| 703 | - $admin_settings['authorizenet_desc']['std'] = __( 'Pay securely using your credit or debit card.', 'invoicing' ); |
|
| 703 | + $admin_settings['authorizenet_desc']['std'] = __('Pay securely using your credit or debit card.', 'invoicing'); |
|
| 704 | 704 | |
| 705 | 705 | $admin_settings['authorizenet_login_id'] = array( |
| 706 | 706 | 'type' => 'text', |
| 707 | 707 | 'id' => 'authorizenet_login_id', |
| 708 | - 'name' => __( 'API Login ID', 'invoicing' ), |
|
| 709 | - 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>', |
|
| 708 | + 'name' => __('API Login ID', 'invoicing'), |
|
| 709 | + 'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>', |
|
| 710 | 710 | ); |
| 711 | 711 | |
| 712 | 712 | $admin_settings['authorizenet_transaction_key'] = array( |
| 713 | 713 | 'type' => 'text', |
| 714 | 714 | 'id' => 'authorizenet_transaction_key', |
| 715 | - 'name' => __( 'Transaction Key', 'invoicing' ), |
|
| 715 | + 'name' => __('Transaction Key', 'invoicing'), |
|
| 716 | 716 | ); |
| 717 | 717 | |
| 718 | 718 | $admin_settings['authorizenet_signature_key'] = array( |
| 719 | 719 | 'type' => 'text', |
| 720 | 720 | 'id' => 'authorizenet_signature_key', |
| 721 | - 'name' => __( 'Signature Key', 'invoicing' ), |
|
| 722 | - 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
| 721 | + 'name' => __('Signature Key', 'invoicing'), |
|
| 722 | + 'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
| 723 | 723 | ); |
| 724 | 724 | |
| 725 | 725 | $admin_settings['authorizenet_ipn_url'] = array( |
| 726 | 726 | 'type' => 'ipn_url', |
| 727 | 727 | 'id' => 'authorizenet_ipn_url', |
| 728 | - 'name' => __( 'Webhook URL', 'invoicing' ), |
|
| 728 | + 'name' => __('Webhook URL', 'invoicing'), |
|
| 729 | 729 | 'std' => $this->notify_url, |
| 730 | - 'desc' => __( 'Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing' ) . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>', |
|
| 730 | + 'desc' => __('Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing') . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __('Learn more.', 'invoicing') . '</em></a>', |
|
| 731 | 731 | 'custom' => 'authorizenet', |
| 732 | 732 | 'readonly' => true, |
| 733 | 733 | ); |