@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -defined( 'ABSPATH' ) || exit; |
|
| 7 | +defined('ABSPATH') || exit; |
|
| 8 | 8 | /** |
| 9 | 9 | * Main Subscriptions class. |
| 10 | 10 | * |
@@ -14,31 +14,31 @@ discard block |
||
| 14 | 14 | /** |
| 15 | 15 | * Class constructor. |
| 16 | 16 | */ |
| 17 | - public function __construct(){ |
|
| 17 | + public function __construct() { |
|
| 18 | 18 | |
| 19 | 19 | // Fire gateway specific hooks when a subscription changes. |
| 20 | - add_action( 'getpaid_subscription_status_changed', array( $this, 'process_subscription_status_change' ), 10, 3 ); |
|
| 20 | + add_action('getpaid_subscription_status_changed', array($this, 'process_subscription_status_change'), 10, 3); |
|
| 21 | 21 | |
| 22 | 22 | // De-activate a subscription whenever the invoice changes payment statuses. |
| 23 | - add_action( 'getpaid_invoice_status_wpi-refunded', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
| 24 | - add_action( 'getpaid_invoice_status_wpi-failed', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
| 25 | - add_action( 'getpaid_invoice_status_wpi-cancelled', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
| 26 | - add_action( 'getpaid_invoice_status_wpi-pending', array( $this, 'maybe_deactivate_invoice_subscription' ), 20 ); |
|
| 23 | + add_action('getpaid_invoice_status_wpi-refunded', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
| 24 | + add_action('getpaid_invoice_status_wpi-failed', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
| 25 | + add_action('getpaid_invoice_status_wpi-cancelled', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
| 26 | + add_action('getpaid_invoice_status_wpi-pending', array($this, 'maybe_deactivate_invoice_subscription'), 20); |
|
| 27 | 27 | |
| 28 | 28 | // Handles subscription cancelations. |
| 29 | - add_action( 'getpaid_authenticated_action_subscription_cancel', array( $this, 'user_cancel_single_subscription' ) ); |
|
| 29 | + add_action('getpaid_authenticated_action_subscription_cancel', array($this, 'user_cancel_single_subscription')); |
|
| 30 | 30 | |
| 31 | 31 | // Create a subscription whenever an invoice is created, (and update it when it is updated). |
| 32 | - add_action( 'getpaid_new_invoice', array( $this, 'maybe_create_invoice_subscription' ) ); |
|
| 33 | - add_action( 'getpaid_update_invoice', array( $this, 'maybe_update_invoice_subscription' ) ); |
|
| 32 | + add_action('getpaid_new_invoice', array($this, 'maybe_create_invoice_subscription')); |
|
| 33 | + add_action('getpaid_update_invoice', array($this, 'maybe_update_invoice_subscription')); |
|
| 34 | 34 | |
| 35 | 35 | // Handles admin subscription update actions. |
| 36 | - add_action( 'getpaid_authenticated_admin_action_update_single_subscription', array( $this, 'admin_update_single_subscription' ) ); |
|
| 37 | - add_action( 'getpaid_authenticated_admin_action_subscription_manual_renew', array( $this, 'admin_renew_single_subscription' ) ); |
|
| 38 | - add_action( 'getpaid_authenticated_admin_action_subscription_manual_delete', array( $this, 'admin_delete_single_subscription' ) ); |
|
| 36 | + add_action('getpaid_authenticated_admin_action_update_single_subscription', array($this, 'admin_update_single_subscription')); |
|
| 37 | + add_action('getpaid_authenticated_admin_action_subscription_manual_renew', array($this, 'admin_renew_single_subscription')); |
|
| 38 | + add_action('getpaid_authenticated_admin_action_subscription_manual_delete', array($this, 'admin_delete_single_subscription')); |
|
| 39 | 39 | |
| 40 | 40 | // Filter invoice item row actions. |
| 41 | - add_action( 'getpaid-invoice-page-line-item-actions', array( $this, 'filter_invoice_line_item_actions' ), 10, 3 ); |
|
| 41 | + add_action('getpaid-invoice-page-line-item-actions', array($this, 'filter_invoice_line_item_actions'), 10, 3); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -47,19 +47,19 @@ discard block |
||
| 47 | 47 | * @param WPInv_Invoice $invoice |
| 48 | 48 | * @return WPInv_Subscription|bool |
| 49 | 49 | */ |
| 50 | - public function get_invoice_subscription( $invoice ) { |
|
| 50 | + public function get_invoice_subscription($invoice) { |
|
| 51 | 51 | $subscription_id = $invoice->get_subscription_id(); |
| 52 | 52 | |
| 53 | 53 | // Fallback to the parent invoice if the child invoice has no subscription id. |
| 54 | - if ( empty( $subscription_id && $invoice->is_renewal() ) ) { |
|
| 54 | + if (empty($subscription_id && $invoice->is_renewal())) { |
|
| 55 | 55 | $subscription_id = $invoice->get_parent_payment()->get_subscription_id(); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | // Fetch the subscription. |
| 59 | - $subscription = new WPInv_Subscription( $subscription_id ); |
|
| 59 | + $subscription = new WPInv_Subscription($subscription_id); |
|
| 60 | 60 | |
| 61 | 61 | // Return subscription or use a fallback for backwards compatibility. |
| 62 | - return $subscription->get_id() ? $subscription : wpinv_get_subscription( $invoice ); |
|
| 62 | + return $subscription->get_id() ? $subscription : wpinv_get_subscription($invoice); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -67,16 +67,16 @@ discard block |
||
| 67 | 67 | * |
| 68 | 68 | * @param WPInv_Invoice $invoice |
| 69 | 69 | */ |
| 70 | - public function maybe_deactivate_invoice_subscription( $invoice ) { |
|
| 70 | + public function maybe_deactivate_invoice_subscription($invoice) { |
|
| 71 | 71 | |
| 72 | - $subscription = $this->get_invoice_subscription( $invoice ); |
|
| 72 | + $subscription = $this->get_invoice_subscription($invoice); |
|
| 73 | 73 | |
| 74 | 74 | // Abort if the subscription is missing or not active. |
| 75 | - if ( empty( $subscription ) || ! $subscription->is_active() ) { |
|
| 75 | + if (empty($subscription) || !$subscription->is_active()) { |
|
| 76 | 76 | return; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - $subscription->set_status( 'pending' ); |
|
| 79 | + $subscription->set_status('pending'); |
|
| 80 | 80 | $subscription->save(); |
| 81 | 81 | |
| 82 | 82 | } |
@@ -88,15 +88,15 @@ discard block |
||
| 88 | 88 | * @param string $from |
| 89 | 89 | * @param string $to |
| 90 | 90 | */ |
| 91 | - public function process_subscription_status_change( $subscription, $from, $to ) { |
|
| 91 | + public function process_subscription_status_change($subscription, $from, $to) { |
|
| 92 | 92 | |
| 93 | 93 | $gateway = $subscription->get_gateway(); |
| 94 | 94 | |
| 95 | - if ( ! empty( $gateway ) ) { |
|
| 96 | - $gateway = sanitize_key( $gateway ); |
|
| 97 | - $from = sanitize_key( $from ); |
|
| 98 | - $to = sanitize_key( $to ); |
|
| 99 | - do_action( "getpaid_{$gateway}_subscription_$to", $subscription, $from ); |
|
| 95 | + if (!empty($gateway)) { |
|
| 96 | + $gateway = sanitize_key($gateway); |
|
| 97 | + $from = sanitize_key($from); |
|
| 98 | + $to = sanitize_key($to); |
|
| 99 | + do_action("getpaid_{$gateway}_subscription_$to", $subscription, $from); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | } |
@@ -109,8 +109,8 @@ discard block |
||
| 109 | 109 | * @deprecated |
| 110 | 110 | * @return mixed|string|void |
| 111 | 111 | */ |
| 112 | - public static function wpinv_get_pretty_subscription_frequency( $period, $frequency_count = 1 ) { |
|
| 113 | - return getpaid_get_subscription_period_label( $period, $frequency_count ); |
|
| 112 | + public static function wpinv_get_pretty_subscription_frequency($period, $frequency_count = 1) { |
|
| 113 | + return getpaid_get_subscription_period_label($period, $frequency_count); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -120,34 +120,34 @@ discard block |
||
| 120 | 120 | * @since 1.0.0 |
| 121 | 121 | * @return void |
| 122 | 122 | */ |
| 123 | - public function user_cancel_single_subscription( $data ) { |
|
| 123 | + public function user_cancel_single_subscription($data) { |
|
| 124 | 124 | |
| 125 | 125 | // Ensure there is a subscription to cancel. |
| 126 | - if ( empty( $data['subscription'] ) ) { |
|
| 126 | + if (empty($data['subscription'])) { |
|
| 127 | 127 | return; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - $subscription = new WPInv_Subscription( (int) $data['subscription'] ); |
|
| 130 | + $subscription = new WPInv_Subscription((int) $data['subscription']); |
|
| 131 | 131 | |
| 132 | 132 | // Ensure that it exists and that it belongs to the current user. |
| 133 | - if ( ! $subscription->get_id() || $subscription->get_customer_id() != get_current_user_id() ) { |
|
| 134 | - wpinv_set_error( 'invalid_subscription', __( 'You do not have permission to cancel this subscription', 'invoicing' ) ); |
|
| 133 | + if (!$subscription->get_id() || $subscription->get_customer_id() != get_current_user_id()) { |
|
| 134 | + wpinv_set_error('invalid_subscription', __('You do not have permission to cancel this subscription', 'invoicing')); |
|
| 135 | 135 | |
| 136 | 136 | // Can it be cancelled. |
| 137 | - } else if ( ! $subscription->can_cancel() ) { |
|
| 138 | - wpinv_set_error( 'cannot_cancel', __( 'This subscription cannot be cancelled as it is not active.', 'invoicing' ) ); |
|
| 137 | + } else if (!$subscription->can_cancel()) { |
|
| 138 | + wpinv_set_error('cannot_cancel', __('This subscription cannot be cancelled as it is not active.', 'invoicing')); |
|
| 139 | 139 | |
| 140 | 140 | |
| 141 | 141 | // Cancel it. |
| 142 | 142 | } else { |
| 143 | 143 | |
| 144 | 144 | $subscription->cancel(); |
| 145 | - wpinv_set_error( 'cancelled', __( 'This subscription has been cancelled.', 'invoicing' ), 'info' ); |
|
| 145 | + wpinv_set_error('cancelled', __('This subscription has been cancelled.', 'invoicing'), 'info'); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - $redirect = remove_query_arg( array( 'getpaid-action', 'getpaid-nonce' ) ); |
|
| 148 | + $redirect = remove_query_arg(array('getpaid-action', 'getpaid-nonce')); |
|
| 149 | 149 | |
| 150 | - wp_safe_redirect( $redirect ); |
|
| 150 | + wp_safe_redirect($redirect); |
|
| 151 | 151 | exit; |
| 152 | 152 | |
| 153 | 153 | } |
@@ -159,15 +159,15 @@ discard block |
||
| 159 | 159 | * @param WPInv_Invoice $invoice |
| 160 | 160 | * @since 1.0.0 |
| 161 | 161 | */ |
| 162 | - public function maybe_create_invoice_subscription( $invoice ) { |
|
| 162 | + public function maybe_create_invoice_subscription($invoice) { |
|
| 163 | 163 | |
| 164 | 164 | // Abort if it is not recurring. |
| 165 | - if ( $invoice->is_free() || ! $invoice->is_recurring() || $invoice->is_renewal() ) { |
|
| 165 | + if ($invoice->is_free() || !$invoice->is_recurring() || $invoice->is_renewal()) { |
|
| 166 | 166 | return; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | $subscription = new WPInv_Subscription(); |
| 170 | - return $this->update_invoice_subscription( $subscription, $invoice ); |
|
| 170 | + return $this->update_invoice_subscription($subscription, $invoice); |
|
| 171 | 171 | |
| 172 | 172 | } |
| 173 | 173 | |
@@ -178,32 +178,32 @@ discard block |
||
| 178 | 178 | * @param WPInv_Invoice $invoice |
| 179 | 179 | * @since 1.0.19 |
| 180 | 180 | */ |
| 181 | - public function maybe_update_invoice_subscription( $invoice ) { |
|
| 181 | + public function maybe_update_invoice_subscription($invoice) { |
|
| 182 | 182 | |
| 183 | 183 | // Do not process renewals. |
| 184 | - if ( $invoice->is_renewal() ) { |
|
| 184 | + if ($invoice->is_renewal()) { |
|
| 185 | 185 | return; |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | // Delete existing subscription if available and the invoice is not recurring. |
| 189 | - if ( ! $invoice->is_recurring() ) { |
|
| 190 | - $subscription = new WPInv_Subscription( $invoice->get_subscription_id() ); |
|
| 191 | - $subscription->delete( true ); |
|
| 189 | + if (!$invoice->is_recurring()) { |
|
| 190 | + $subscription = new WPInv_Subscription($invoice->get_subscription_id()); |
|
| 191 | + $subscription->delete(true); |
|
| 192 | 192 | return; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | // (Maybe) create a new subscription. |
| 196 | - $subscription = $this->get_invoice_subscription( $invoice ); |
|
| 197 | - if ( empty( $subscription ) ) { |
|
| 198 | - return $this->maybe_create_invoice_subscription( $invoice ); |
|
| 196 | + $subscription = $this->get_invoice_subscription($invoice); |
|
| 197 | + if (empty($subscription)) { |
|
| 198 | + return $this->maybe_create_invoice_subscription($invoice); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | // Abort if an invoice is paid and already has a subscription. |
| 202 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 202 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
| 203 | 203 | return; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - return $this->update_invoice_subscription( $subscription, $invoice ); |
|
| 206 | + return $this->update_invoice_subscription($subscription, $invoice); |
|
| 207 | 207 | |
| 208 | 208 | } |
| 209 | 209 | |
@@ -215,57 +215,57 @@ discard block |
||
| 215 | 215 | * @param WPInv_Invoice $invoice |
| 216 | 216 | * @since 1.0.19 |
| 217 | 217 | */ |
| 218 | - public function update_invoice_subscription( $subscription, $invoice ) { |
|
| 218 | + public function update_invoice_subscription($subscription, $invoice) { |
|
| 219 | 219 | |
| 220 | 220 | // Delete the subscription if an invoice is free or nolonger recurring. |
| 221 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_free() || ! $invoice->is_recurring() ) { |
|
| 221 | + if (!$invoice->is_type('invoice') || $invoice->is_free() || !$invoice->is_recurring()) { |
|
| 222 | 222 | return $subscription->delete(); |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - $subscription->set_customer_id( $invoice->get_customer_id() ); |
|
| 226 | - $subscription->set_parent_invoice_id( $invoice->get_id() ); |
|
| 227 | - $subscription->set_initial_amount( $invoice->get_initial_total() ); |
|
| 228 | - $subscription->set_recurring_amount( $invoice->get_recurring_total() ); |
|
| 229 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
| 230 | - $subscription->set_status( $invoice->is_paid() ? 'active' : 'pending' ); |
|
| 225 | + $subscription->set_customer_id($invoice->get_customer_id()); |
|
| 226 | + $subscription->set_parent_invoice_id($invoice->get_id()); |
|
| 227 | + $subscription->set_initial_amount($invoice->get_initial_total()); |
|
| 228 | + $subscription->set_recurring_amount($invoice->get_recurring_total()); |
|
| 229 | + $subscription->set_date_created(current_time('mysql')); |
|
| 230 | + $subscription->set_status($invoice->is_paid() ? 'active' : 'pending'); |
|
| 231 | 231 | |
| 232 | 232 | // Get the recurring item and abort if it does not exist. |
| 233 | - $subscription_item = $invoice->get_recurring( true ); |
|
| 234 | - if ( ! $subscription_item->get_id() ) { |
|
| 233 | + $subscription_item = $invoice->get_recurring(true); |
|
| 234 | + if (!$subscription_item->get_id()) { |
|
| 235 | 235 | $invoice->set_subscription_id(0); |
| 236 | 236 | $invoice->save(); |
| 237 | 237 | return $subscription->delete(); |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - $subscription->set_product_id( $subscription_item->get_id() ); |
|
| 241 | - $subscription->set_period( $subscription_item->get_recurring_period( true ) ); |
|
| 242 | - $subscription->set_frequency( $subscription_item->get_recurring_interval() ); |
|
| 243 | - $subscription->set_bill_times( $subscription_item->get_recurring_limit() ); |
|
| 240 | + $subscription->set_product_id($subscription_item->get_id()); |
|
| 241 | + $subscription->set_period($subscription_item->get_recurring_period(true)); |
|
| 242 | + $subscription->set_frequency($subscription_item->get_recurring_interval()); |
|
| 243 | + $subscription->set_bill_times($subscription_item->get_recurring_limit()); |
|
| 244 | 244 | |
| 245 | 245 | // Calculate the next renewal date. |
| 246 | - $period = $subscription_item->get_recurring_period( true ); |
|
| 246 | + $period = $subscription_item->get_recurring_period(true); |
|
| 247 | 247 | $interval = $subscription_item->get_recurring_interval(); |
| 248 | 248 | |
| 249 | 249 | // If the subscription item has a trial period... |
| 250 | - if ( $subscription_item->has_free_trial() ) { |
|
| 251 | - $period = $subscription_item->get_trial_period( true ); |
|
| 250 | + if ($subscription_item->has_free_trial()) { |
|
| 251 | + $period = $subscription_item->get_trial_period(true); |
|
| 252 | 252 | $interval = $subscription_item->get_trial_interval(); |
| 253 | - $subscription->set_trial_period( $interval . ' ' . $period ); |
|
| 254 | - $subscription->set_status( 'trialling' ); |
|
| 253 | + $subscription->set_trial_period($interval . ' ' . $period); |
|
| 254 | + $subscription->set_status('trialling'); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | // If initial amount is free, treat it as a free trial even if the subscription item does not have a free trial. |
| 258 | - if ( $invoice->has_free_trial() ) { |
|
| 259 | - $subscription->set_trial_period( $interval . ' ' . $period ); |
|
| 260 | - $subscription->set_status( 'trialling' ); |
|
| 258 | + if ($invoice->has_free_trial()) { |
|
| 259 | + $subscription->set_trial_period($interval . ' ' . $period); |
|
| 260 | + $subscription->set_status('trialling'); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | // Calculate the next renewal date. |
| 264 | - $expiration = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", strtotime( $subscription->get_date_created() ) ) ); |
|
| 264 | + $expiration = date('Y-m-d H:i:s', strtotime("+$interval $period", strtotime($subscription->get_date_created()))); |
|
| 265 | 265 | |
| 266 | - $subscription->set_next_renewal_date( $expiration ); |
|
| 266 | + $subscription->set_next_renewal_date($expiration); |
|
| 267 | 267 | $subscription->save(); |
| 268 | - $invoice->set_subscription_id( $subscription->get_id() ); |
|
| 268 | + $invoice->set_subscription_id($subscription->get_id()); |
|
| 269 | 269 | return $subscription->get_id(); |
| 270 | 270 | |
| 271 | 271 | } |
@@ -276,27 +276,27 @@ discard block |
||
| 276 | 276 | * @param array $data |
| 277 | 277 | * @since 1.0.19 |
| 278 | 278 | */ |
| 279 | - public function admin_update_single_subscription( $args ) { |
|
| 279 | + public function admin_update_single_subscription($args) { |
|
| 280 | 280 | |
| 281 | 281 | // Ensure the subscription exists and that a status has been given. |
| 282 | - if ( empty( $args['subscription_id'] ) ) { |
|
| 282 | + if (empty($args['subscription_id'])) { |
|
| 283 | 283 | return; |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | // Retrieve the subscriptions. |
| 287 | - $subscription = new WPInv_Subscription( $args['subscription_id'] ); |
|
| 287 | + $subscription = new WPInv_Subscription($args['subscription_id']); |
|
| 288 | 288 | |
| 289 | - if ( $subscription->get_id() ) { |
|
| 289 | + if ($subscription->get_id()) { |
|
| 290 | 290 | |
| 291 | 291 | $subscription->set_props( |
| 292 | 292 | array( |
| 293 | - 'status' => isset( $args['subscription_status'] ) ? $args['subscription_status'] : null, |
|
| 294 | - 'profile_id' => isset( $args['wpinv_subscription_profile_id'] ) ? $args['wpinv_subscription_profile_id'] : null, |
|
| 293 | + 'status' => isset($args['subscription_status']) ? $args['subscription_status'] : null, |
|
| 294 | + 'profile_id' => isset($args['wpinv_subscription_profile_id']) ? $args['wpinv_subscription_profile_id'] : null, |
|
| 295 | 295 | ) |
| 296 | 296 | ); |
| 297 | 297 | |
| 298 | 298 | $subscription->save(); |
| 299 | - getpaid_admin()->show_info( __( 'Subscription updated', 'invoicing' ) ); |
|
| 299 | + getpaid_admin()->show_info(__('Subscription updated', 'invoicing')); |
|
| 300 | 300 | |
| 301 | 301 | } |
| 302 | 302 | |
@@ -308,27 +308,27 @@ discard block |
||
| 308 | 308 | * @param array $data |
| 309 | 309 | * @since 1.0.19 |
| 310 | 310 | */ |
| 311 | - public function admin_renew_single_subscription( $args ) { |
|
| 311 | + public function admin_renew_single_subscription($args) { |
|
| 312 | 312 | |
| 313 | 313 | // Ensure the subscription exists and that a status has been given. |
| 314 | - if ( empty( $args['id'] ) ) { |
|
| 314 | + if (empty($args['id'])) { |
|
| 315 | 315 | return; |
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | // Retrieve the subscriptions. |
| 319 | - $subscription = new WPInv_Subscription( $args['id'] ); |
|
| 319 | + $subscription = new WPInv_Subscription($args['id']); |
|
| 320 | 320 | |
| 321 | - if ( $subscription->get_id() ) { |
|
| 321 | + if ($subscription->get_id()) { |
|
| 322 | 322 | |
| 323 | - do_action( 'getpaid_admin_renew_subscription', $subscription ); |
|
| 323 | + do_action('getpaid_admin_renew_subscription', $subscription); |
|
| 324 | 324 | |
| 325 | - $args = array( 'transaction_id', $subscription->get_parent_invoice()->generate_key( 'renewal_' ) ); |
|
| 325 | + $args = array('transaction_id', $subscription->get_parent_invoice()->generate_key('renewal_')); |
|
| 326 | 326 | |
| 327 | - if ( ! $subscription->add_payment( $args ) ) { |
|
| 328 | - getpaid_admin()->show_error( __( 'We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing' ) ); |
|
| 327 | + if (!$subscription->add_payment($args)) { |
|
| 328 | + getpaid_admin()->show_error(__('We are unable to renew this subscription as the parent invoice does not exist.', 'invoicing')); |
|
| 329 | 329 | } else { |
| 330 | 330 | $subscription->renew(); |
| 331 | - getpaid_admin()->show_info( __( 'This subscription has been renewed and extended.', 'invoicing' ) ); |
|
| 331 | + getpaid_admin()->show_info(__('This subscription has been renewed and extended.', 'invoicing')); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | wp_safe_redirect( |
@@ -351,20 +351,20 @@ discard block |
||
| 351 | 351 | * @param array $data |
| 352 | 352 | * @since 1.0.19 |
| 353 | 353 | */ |
| 354 | - public function admin_delete_single_subscription( $args ) { |
|
| 354 | + public function admin_delete_single_subscription($args) { |
|
| 355 | 355 | |
| 356 | 356 | // Ensure the subscription exists and that a status has been given. |
| 357 | - if ( empty( $args['id'] ) ) { |
|
| 357 | + if (empty($args['id'])) { |
|
| 358 | 358 | return; |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | // Retrieve the subscriptions. |
| 362 | - $subscription = new WPInv_Subscription( $args['id'] ); |
|
| 362 | + $subscription = new WPInv_Subscription($args['id']); |
|
| 363 | 363 | |
| 364 | - if ( $subscription->delete() ) { |
|
| 365 | - getpaid_admin()->show_info( __( 'This subscription has been deleted.', 'invoicing' ) ); |
|
| 364 | + if ($subscription->delete()) { |
|
| 365 | + getpaid_admin()->show_info(__('This subscription has been deleted.', 'invoicing')); |
|
| 366 | 366 | } else { |
| 367 | - getpaid_admin()->show_error( __( 'We are unable to delete this subscription. Please try again.', 'invoicing' ) ); |
|
| 367 | + getpaid_admin()->show_error(__('We are unable to delete this subscription. Please try again.', 'invoicing')); |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | $redirected = wp_safe_redirect( |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | ) |
| 378 | 378 | ); |
| 379 | 379 | |
| 380 | - if ( $redirected ) { |
|
| 380 | + if ($redirected) { |
|
| 381 | 381 | exit; |
| 382 | 382 | } |
| 383 | 383 | |
@@ -390,10 +390,10 @@ discard block |
||
| 390 | 390 | * @param WPInv_Item $item |
| 391 | 391 | * @param WPInv_Invoice $invoice |
| 392 | 392 | */ |
| 393 | - public function filter_invoice_line_item_actions( $actions, $item, $invoice ) { |
|
| 393 | + public function filter_invoice_line_item_actions($actions, $item, $invoice) { |
|
| 394 | 394 | |
| 395 | 395 | // Fetch item subscription. |
| 396 | - $args = array( |
|
| 396 | + $args = array( |
|
| 397 | 397 | 'invoice_in' => $invoice->is_parent() ? $invoice->get_id() : $invoice->get_parent_id(), |
| 398 | 398 | 'product_in' => $item->get_id(), |
| 399 | 399 | 'number' => 1, |
@@ -401,13 +401,13 @@ discard block |
||
| 401 | 401 | 'fields' => 'id', |
| 402 | 402 | ); |
| 403 | 403 | |
| 404 | - $subscription = new GetPaid_Subscriptions_Query( $args ); |
|
| 404 | + $subscription = new GetPaid_Subscriptions_Query($args); |
|
| 405 | 405 | $subscription = $subscription->get_results(); |
| 406 | 406 | |
| 407 | 407 | // In case we found a match... |
| 408 | - if ( ! empty( $subscription ) ) { |
|
| 409 | - $url = esc_url( add_query_arg( 'subscription', (int) $subscription[0], get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); |
|
| 410 | - $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
| 408 | + if (!empty($subscription)) { |
|
| 409 | + $url = esc_url(add_query_arg('subscription', (int) $subscription[0], get_permalink((int) wpinv_get_option('invoice_subscription_page')))); |
|
| 410 | + $actions['subscription'] = "<a href='$url' class='text-decoration-none'>" . __('Manage Subscription', 'invoicing') . '</a>'; |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | return $actions; |