@@ -10,67 +10,67 @@ discard block |
||
10 | 10 | * @var array $columns |
11 | 11 | */ |
12 | 12 | |
13 | -defined( 'ABSPATH' ) || exit; |
|
13 | +defined('ABSPATH') || exit; |
|
14 | 14 | |
15 | 15 | ?> |
16 | 16 | |
17 | -<?php do_action( 'getpaid_before_email_line_item', $invoice, $item ); ?> |
|
17 | +<?php do_action('getpaid_before_email_line_item', $invoice, $item); ?> |
|
18 | 18 | |
19 | -<tr class="wpinv_cart_item item-type-<?php echo sanitize_html_class( $item->get_type() ); ?>"> |
|
19 | +<tr class="wpinv_cart_item item-type-<?php echo sanitize_html_class($item->get_type()); ?>"> |
|
20 | 20 | |
21 | - <?php foreach ( array_keys( $columns ) as $column ): ?> |
|
21 | + <?php foreach (array_keys($columns) as $column): ?> |
|
22 | 22 | |
23 | - <td class="<?php echo 'name' == $column ? 'text-left' : 'text-right' ?> wpinv_cart_item_<?php echo sanitize_html_class( $column ); ?>"> |
|
23 | + <td class="<?php echo 'name' == $column ? 'text-left' : 'text-right' ?> wpinv_cart_item_<?php echo sanitize_html_class($column); ?>"> |
|
24 | 24 | |
25 | 25 | <?php |
26 | 26 | |
27 | 27 | // Fires before printing a line item column. |
28 | - do_action( "getpaid_email_line_item_before_$column", $item, $invoice ); |
|
28 | + do_action("getpaid_email_line_item_before_$column", $item, $invoice); |
|
29 | 29 | |
30 | 30 | // Item name. |
31 | - if ( 'name' == $column ) { |
|
31 | + if ('name' == $column) { |
|
32 | 32 | |
33 | 33 | // Display the name. |
34 | - echo '<div class="wpinv_email_cart_item_title">' . sanitize_text_field( $item->get_name() ) . '</div>'; |
|
34 | + echo '<div class="wpinv_email_cart_item_title">' . sanitize_text_field($item->get_name()) . '</div>'; |
|
35 | 35 | |
36 | 36 | // And an optional description. |
37 | 37 | $description = $item->get_description(); |
38 | 38 | |
39 | - if ( ! empty( $description ) ) { |
|
40 | - $description = wp_kses_post( $description ); |
|
39 | + if (!empty($description)) { |
|
40 | + $description = wp_kses_post($description); |
|
41 | 41 | echo "<p class='small'>$description</p>"; |
42 | 42 | } |
43 | 43 | |
44 | 44 | // Price help text |
45 | - $description = getpaid_item_recurring_price_help_text( $item, $invoice->get_currency() ); |
|
46 | - if ( $description ) { |
|
45 | + $description = getpaid_item_recurring_price_help_text($item, $invoice->get_currency()); |
|
46 | + if ($description) { |
|
47 | 47 | echo "<p class='small'>$description</p>"; |
48 | 48 | } |
49 | 49 | |
50 | 50 | } |
51 | 51 | |
52 | 52 | // Item price. |
53 | - if ( 'price' == $column ) { |
|
53 | + if ('price' == $column) { |
|
54 | 54 | |
55 | 55 | // Display the item price (or recurring price if this is a renewal invoice) |
56 | 56 | $price = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price(); |
57 | - echo wpinv_price( $price, $invoice->get_currency() ); |
|
57 | + echo wpinv_price($price, $invoice->get_currency()); |
|
58 | 58 | |
59 | 59 | } |
60 | 60 | |
61 | 61 | // Item quantity. |
62 | - if ( 'quantity' == $column ) { |
|
62 | + if ('quantity' == $column) { |
|
63 | 63 | echo (float) $item->get_quantity(); |
64 | 64 | } |
65 | 65 | |
66 | 66 | // Item sub total. |
67 | - if ( 'subtotal' == $column ) { |
|
67 | + if ('subtotal' == $column) { |
|
68 | 68 | $subtotal = $invoice->is_renewal() ? $item->get_recurring_sub_total() : $item->get_sub_total(); |
69 | - echo wpinv_price( $subtotal, $invoice->get_currency() ); |
|
69 | + echo wpinv_price($subtotal, $invoice->get_currency()); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | // Fires when printing a line item column. |
73 | - do_action( "getpaid_email_line_item_$column", $item, $invoice ); |
|
73 | + do_action("getpaid_email_line_item_$column", $item, $invoice); |
|
74 | 74 | |
75 | 75 | ?> |
76 | 76 | |
@@ -80,4 +80,4 @@ discard block |
||
80 | 80 | |
81 | 81 | </tr> |
82 | 82 | |
83 | -<?php do_action( 'getpaid_after_email_line_item', $invoice, $item ); ?> |
|
83 | +<?php do_action('getpaid_after_email_line_item', $invoice, $item); ?> |
@@ -10,61 +10,61 @@ discard block |
||
10 | 10 | * @var array $columns |
11 | 11 | */ |
12 | 12 | |
13 | -defined( 'ABSPATH' ) || exit; |
|
13 | +defined('ABSPATH') || exit; |
|
14 | 14 | |
15 | -do_action( 'getpaid_before_invoice_line_item', $invoice, $item ); |
|
15 | +do_action('getpaid_before_invoice_line_item', $invoice, $item); |
|
16 | 16 | |
17 | 17 | ?> |
18 | 18 | |
19 | -<div class='getpaid-invoice-item item-<?php echo (int) $item->get_id(); ?> item-type-<?php echo sanitize_html_class( $item->get_type() ); ?> border-bottom'> |
|
19 | +<div class='getpaid-invoice-item item-<?php echo (int) $item->get_id(); ?> item-type-<?php echo sanitize_html_class($item->get_type()); ?> border-bottom'> |
|
20 | 20 | |
21 | 21 | <div class="form-row"> |
22 | 22 | |
23 | - <?php foreach ( array_keys( $columns ) as $column ): ?> |
|
23 | + <?php foreach (array_keys($columns) as $column): ?> |
|
24 | 24 | |
25 | - <div class="<?php echo 'name' == $column ? 'col-12 col-sm-6' : 'col-12 col-sm' ?> getpaid-invoice-item-<?php echo sanitize_html_class( $column ); ?>"> |
|
25 | + <div class="<?php echo 'name' == $column ? 'col-12 col-sm-6' : 'col-12 col-sm' ?> getpaid-invoice-item-<?php echo sanitize_html_class($column); ?>"> |
|
26 | 26 | |
27 | 27 | <?php |
28 | 28 | |
29 | 29 | // Fires before printing a line item column. |
30 | - do_action( "getpaid_invoice_line_item_before_$column", $item, $invoice ); |
|
30 | + do_action("getpaid_invoice_line_item_before_$column", $item, $invoice); |
|
31 | 31 | |
32 | 32 | // Item name. |
33 | - if ( 'name' == $column ) { |
|
33 | + if ('name' == $column) { |
|
34 | 34 | |
35 | 35 | // Display the name. |
36 | - echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>'; |
|
36 | + echo '<div class="mb-1">' . sanitize_text_field($item->get_name()) . '</div>'; |
|
37 | 37 | |
38 | 38 | // And an optional description. |
39 | 39 | $description = $item->get_description(); |
40 | 40 | |
41 | - if ( ! empty( $description ) ) { |
|
42 | - $description = wp_kses_post( $description ); |
|
41 | + if (!empty($description)) { |
|
42 | + $description = wp_kses_post($description); |
|
43 | 43 | echo "<small class='form-text text-muted pr-2 m-0'>$description</small>"; |
44 | 44 | } |
45 | 45 | |
46 | 46 | // Price help text. |
47 | - $description = getpaid_item_recurring_price_help_text( $item, $invoice->get_currency() ); |
|
48 | - if ( $description ) { |
|
47 | + $description = getpaid_item_recurring_price_help_text($item, $invoice->get_currency()); |
|
48 | + if ($description) { |
|
49 | 49 | echo "<small class='form-text text-muted pr-2 m-0'>$description</small>"; |
50 | 50 | } |
51 | 51 | |
52 | 52 | // Fires before printing the line item actions. |
53 | - do_action( "getpaid_before_invoice_line_item_actions", $item, $invoice ); |
|
53 | + do_action("getpaid_before_invoice_line_item_actions", $item, $invoice); |
|
54 | 54 | |
55 | - $actions = apply_filters( 'getpaid-invoice-page-line-item-actions', array(), $item, $invoice ); |
|
55 | + $actions = apply_filters('getpaid-invoice-page-line-item-actions', array(), $item, $invoice); |
|
56 | 56 | |
57 | - if ( ! empty( $actions ) ) { |
|
57 | + if (!empty($actions)) { |
|
58 | 58 | |
59 | - $sanitized = array(); |
|
60 | - foreach ( $actions as $key => $action ) { |
|
61 | - $key = sanitize_html_class( $key ); |
|
62 | - $action = wp_kses_post( $action ); |
|
59 | + $sanitized = array(); |
|
60 | + foreach ($actions as $key => $action) { |
|
61 | + $key = sanitize_html_class($key); |
|
62 | + $action = wp_kses_post($action); |
|
63 | 63 | $sanitized[] = "<span class='$key'>$action</span>"; |
64 | 64 | } |
65 | 65 | |
66 | 66 | echo "<small class='form-text getpaid-line-item-actions'>"; |
67 | - echo implode( ' | ', $sanitized ); |
|
67 | + echo implode(' | ', $sanitized); |
|
68 | 68 | echo '</small>'; |
69 | 69 | |
70 | 70 | } |
@@ -72,30 +72,30 @@ discard block |
||
72 | 72 | } |
73 | 73 | |
74 | 74 | // Item price. |
75 | - if ( 'price' == $column ) { |
|
75 | + if ('price' == $column) { |
|
76 | 76 | |
77 | 77 | // Display the item price (or recurring price if this is a renewal invoice) |
78 | 78 | $price = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price(); |
79 | - echo wpinv_price( $price, $invoice->get_currency() ); |
|
79 | + echo wpinv_price($price, $invoice->get_currency()); |
|
80 | 80 | |
81 | 81 | } |
82 | 82 | |
83 | 83 | // Item quantity. |
84 | - if ( 'quantity' == $column ) { |
|
84 | + if ('quantity' == $column) { |
|
85 | 85 | echo (float) $item->get_quantity(); |
86 | 86 | } |
87 | 87 | |
88 | 88 | // Item sub total. |
89 | - if ( 'subtotal' == $column ) { |
|
89 | + if ('subtotal' == $column) { |
|
90 | 90 | $subtotal = $invoice->is_renewal() ? $item->get_recurring_sub_total() : $item->get_sub_total(); |
91 | - echo wpinv_price( $subtotal, $invoice->get_currency() ); |
|
91 | + echo wpinv_price($subtotal, $invoice->get_currency()); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | // Fires when printing a line item column. |
95 | - do_action( "getpaid_invoice_line_item_$column", $item, $invoice ); |
|
95 | + do_action("getpaid_invoice_line_item_$column", $item, $invoice); |
|
96 | 96 | |
97 | 97 | // Fires after printing a line item column. |
98 | - do_action( "getpaid_invoice_line_item_after_$column", $item, $invoice ); |
|
98 | + do_action("getpaid_invoice_line_item_after_$column", $item, $invoice); |
|
99 | 99 | |
100 | 100 | ?> |
101 | 101 |
@@ -24,48 +24,48 @@ discard block |
||
24 | 24 | |
25 | 25 | <?php |
26 | 26 | |
27 | - // Fires before printing a line item column. |
|
28 | - do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
27 | + // Fires before printing a line item column. |
|
28 | + do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
29 | 29 | |
30 | - // Item name. |
|
31 | - if ( 'name' == $key ) { |
|
30 | + // Item name. |
|
31 | + if ( 'name' == $key ) { |
|
32 | 32 | |
33 | - // Display the name. |
|
34 | - echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>'; |
|
33 | + // Display the name. |
|
34 | + echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>'; |
|
35 | 35 | |
36 | - // And an optional description. |
|
36 | + // And an optional description. |
|
37 | 37 | $description = $item->get_description(); |
38 | 38 | |
39 | 39 | if ( ! empty( $description ) ) { |
40 | 40 | $description = wp_kses_post( $description ); |
41 | 41 | echo "<small class='form-text text-muted pr-2 m-0'>$description</small>"; |
42 | - } |
|
42 | + } |
|
43 | 43 | |
44 | - // Price help text. |
|
44 | + // Price help text. |
|
45 | 45 | $description = getpaid_item_recurring_price_help_text( $item, $currency ); |
46 | 46 | if ( $description ) { |
47 | 47 | echo "<small class='form-text text-muted pr-2 m-0'>$description</small>"; |
48 | - } |
|
48 | + } |
|
49 | 49 | |
50 | - } |
|
50 | + } |
|
51 | 51 | |
52 | - // Item price. |
|
53 | - if ( 'price' == $key ) { |
|
52 | + // Item price. |
|
53 | + if ( 'price' == $key ) { |
|
54 | 54 | |
55 | - // Set the currency position. |
|
56 | - $position = wpinv_currency_position(); |
|
55 | + // Set the currency position. |
|
56 | + $position = wpinv_currency_position(); |
|
57 | 57 | |
58 | - if ( $position == 'left_space' ) { |
|
59 | - $position = 'left'; |
|
60 | - } |
|
58 | + if ( $position == 'left_space' ) { |
|
59 | + $position = 'left'; |
|
60 | + } |
|
61 | 61 | |
62 | - if ( $position == 'right_space' ) { |
|
63 | - $position = 'right'; |
|
64 | - } |
|
62 | + if ( $position == 'right_space' ) { |
|
63 | + $position = 'right'; |
|
64 | + } |
|
65 | 65 | |
66 | - if ( $item->user_can_set_their_price() ) { |
|
67 | - $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
68 | - ?> |
|
66 | + if ( $item->user_can_set_their_price() ) { |
|
67 | + $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
68 | + ?> |
|
69 | 69 | <div class="input-group input-group-sm"> |
70 | 70 | <?php if( 'left' == $position ) : ?> |
71 | 71 | <div class="input-group-prepend"> |
@@ -81,37 +81,37 @@ discard block |
||
81 | 81 | <?php endif; ?> |
82 | 82 | </div> |
83 | 83 | <?php |
84 | - } else { |
|
85 | - echo wpinv_price( $item->get_price(), $currency ); |
|
86 | - ?> |
|
84 | + } else { |
|
85 | + echo wpinv_price( $item->get_price(), $currency ); |
|
86 | + ?> |
|
87 | 87 | <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr( $item->get_price() ); ?>'> |
88 | 88 | <?php |
89 | - } |
|
90 | - } |
|
89 | + } |
|
90 | + } |
|
91 | 91 | |
92 | - // Item quantity. |
|
93 | - if ( 'quantity' == $key ) { |
|
92 | + // Item quantity. |
|
93 | + if ( 'quantity' == $key ) { |
|
94 | 94 | |
95 | - if ( $item->allows_quantities() ) { |
|
96 | - ?> |
|
95 | + if ( $item->allows_quantities() ) { |
|
96 | + ?> |
|
97 | 97 | <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' type='text' class='getpaid-item-quantity-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border' value='<?php echo (float) $item->get_quantity(); ?>' min='1' required> |
98 | 98 | <?php |
99 | - } else { |
|
100 | - echo (float) $item->get_quantity(); |
|
101 | - echo ' '; |
|
102 | - ?> |
|
99 | + } else { |
|
100 | + echo (float) $item->get_quantity(); |
|
101 | + echo ' '; |
|
102 | + ?> |
|
103 | 103 | <input type='hidden' name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' class='getpaid-item-quantity-input' value='<?php echo (float) $item->get_quantity(); ?>'> |
104 | 104 | <?php |
105 | - } |
|
106 | - } |
|
105 | + } |
|
106 | + } |
|
107 | 107 | |
108 | - // Item sub total. |
|
109 | - if ( 'subtotal' == $key ) { |
|
110 | - echo wpinv_price( $item->get_sub_total(), $currency ); |
|
111 | - } |
|
108 | + // Item sub total. |
|
109 | + if ( 'subtotal' == $key ) { |
|
110 | + echo wpinv_price( $item->get_sub_total(), $currency ); |
|
111 | + } |
|
112 | 112 | |
113 | - do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
114 | - ?> |
|
113 | + do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
114 | + ?> |
|
115 | 115 | |
116 | 116 | </div> |
117 | 117 |
@@ -7,92 +7,92 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | -do_action( 'getpaid_before_payment_form_cart_item', $form, $item ); |
|
12 | +do_action('getpaid_before_payment_form_cart_item', $form, $item); |
|
13 | 13 | |
14 | 14 | $currency = $form->get_currency(); |
15 | 15 | |
16 | 16 | ?> |
17 | -<div class='getpaid-payment-form-items-cart-item getpaid-<?php echo $item->is_required() ? 'required' : 'selectable'; ?> item-<?php echo $item->get_id(); ?> border-bottom py-2 px-3'> |
|
17 | +<div class='getpaid-payment-form-items-cart-item getpaid-<?php echo $item->is_required() ? 'required' : 'selectable'; ?> item-<?php echo $item->get_id(); ?> border-bottom py-2 px-3'> |
|
18 | 18 | |
19 | 19 | <div class="form-row"> |
20 | 20 | |
21 | - <?php foreach ( array_keys( $columns ) as $key ) : ?> |
|
21 | + <?php foreach (array_keys($columns) as $key) : ?> |
|
22 | 22 | |
23 | - <div class="<?php echo 'name' == $key ? 'col-12 col-sm-6' : 'col-12 col-sm' ?> getpaid-form-cart-item-<?php echo sanitize_html_class( $key ); ?> getpaid-form-cart-item-<?php echo sanitize_html_class( $key ); ?>-<?php echo $item->get_id(); ?>"> |
|
23 | + <div class="<?php echo 'name' == $key ? 'col-12 col-sm-6' : 'col-12 col-sm' ?> getpaid-form-cart-item-<?php echo sanitize_html_class($key); ?> getpaid-form-cart-item-<?php echo sanitize_html_class($key); ?>-<?php echo $item->get_id(); ?>"> |
|
24 | 24 | |
25 | 25 | <?php |
26 | 26 | |
27 | 27 | // Fires before printing a line item column. |
28 | - do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
28 | + do_action("getpaid_form_cart_item_before_$key", $item, $form); |
|
29 | 29 | |
30 | 30 | // Item name. |
31 | - if ( 'name' == $key ) { |
|
31 | + if ('name' == $key) { |
|
32 | 32 | |
33 | 33 | // Display the name. |
34 | - echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>'; |
|
34 | + echo '<div class="mb-1">' . sanitize_text_field($item->get_name()) . '</div>'; |
|
35 | 35 | |
36 | 36 | // And an optional description. |
37 | 37 | $description = $item->get_description(); |
38 | 38 | |
39 | - if ( ! empty( $description ) ) { |
|
40 | - $description = wp_kses_post( $description ); |
|
39 | + if (!empty($description)) { |
|
40 | + $description = wp_kses_post($description); |
|
41 | 41 | echo "<small class='form-text text-muted pr-2 m-0'>$description</small>"; |
42 | 42 | } |
43 | 43 | |
44 | 44 | // Price help text. |
45 | - $description = getpaid_item_recurring_price_help_text( $item, $currency ); |
|
46 | - if ( $description ) { |
|
45 | + $description = getpaid_item_recurring_price_help_text($item, $currency); |
|
46 | + if ($description) { |
|
47 | 47 | echo "<small class='form-text text-muted pr-2 m-0'>$description</small>"; |
48 | 48 | } |
49 | 49 | |
50 | 50 | } |
51 | 51 | |
52 | 52 | // Item price. |
53 | - if ( 'price' == $key ) { |
|
53 | + if ('price' == $key) { |
|
54 | 54 | |
55 | 55 | // Set the currency position. |
56 | 56 | $position = wpinv_currency_position(); |
57 | 57 | |
58 | - if ( $position == 'left_space' ) { |
|
58 | + if ($position == 'left_space') { |
|
59 | 59 | $position = 'left'; |
60 | 60 | } |
61 | 61 | |
62 | - if ( $position == 'right_space' ) { |
|
62 | + if ($position == 'right_space') { |
|
63 | 63 | $position = 'right'; |
64 | 64 | } |
65 | 65 | |
66 | - if ( $item->user_can_set_their_price() ) { |
|
67 | - $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
66 | + if ($item->user_can_set_their_price()) { |
|
67 | + $price = max((float) $item->get_price(), (float) $item->get_minimum_price()); |
|
68 | 68 | ?> |
69 | 69 | <div class="input-group input-group-sm"> |
70 | - <?php if( 'left' == $position ) : ?> |
|
70 | + <?php if ('left' == $position) : ?> |
|
71 | 71 | <div class="input-group-prepend"> |
72 | - <span class="input-group-text"><?php echo wpinv_currency_symbol( $currency ); ?></span> |
|
72 | + <span class="input-group-text"><?php echo wpinv_currency_symbol($currency); ?></span> |
|
73 | 73 | </div> |
74 | 74 | <?php endif; ?> |
75 | - <input type="text" name="getpaid-items[<?php echo (int) $item->get_id(); ?>][price]" value="<?php echo $price; ?>" placeholder="<?php echo esc_attr( $item->get_minimum_price() ); ?>" class="getpaid-item-price-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border border"> |
|
75 | + <input type="text" name="getpaid-items[<?php echo (int) $item->get_id(); ?>][price]" value="<?php echo $price; ?>" placeholder="<?php echo esc_attr($item->get_minimum_price()); ?>" class="getpaid-item-price-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border border"> |
|
76 | 76 | |
77 | - <?php if( 'left' != $position ) : ?> |
|
77 | + <?php if ('left' != $position) : ?> |
|
78 | 78 | <div class="input-group-append"> |
79 | - <span class="input-group-text"><?php echo wpinv_currency_symbol( $currency ); ?></span> |
|
79 | + <span class="input-group-text"><?php echo wpinv_currency_symbol($currency); ?></span> |
|
80 | 80 | </div> |
81 | 81 | <?php endif; ?> |
82 | 82 | </div> |
83 | 83 | <?php |
84 | 84 | } else { |
85 | - echo wpinv_price( $item->get_price(), $currency ); |
|
85 | + echo wpinv_price($item->get_price(), $currency); |
|
86 | 86 | ?> |
87 | - <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr( $item->get_price() ); ?>'> |
|
87 | + <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr($item->get_price()); ?>'> |
|
88 | 88 | <?php |
89 | 89 | } |
90 | 90 | } |
91 | 91 | |
92 | 92 | // Item quantity. |
93 | - if ( 'quantity' == $key ) { |
|
93 | + if ('quantity' == $key) { |
|
94 | 94 | |
95 | - if ( $item->allows_quantities() ) { |
|
95 | + if ($item->allows_quantities()) { |
|
96 | 96 | ?> |
97 | 97 | <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' type='text' class='getpaid-item-quantity-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border' value='<?php echo (float) $item->get_quantity(); ?>' min='1' required> |
98 | 98 | <?php |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | } |
107 | 107 | |
108 | 108 | // Item sub total. |
109 | - if ( 'subtotal' == $key ) { |
|
110 | - echo wpinv_price( $item->get_sub_total(), $currency ); |
|
109 | + if ('subtotal' == $key) { |
|
110 | + echo wpinv_price($item->get_sub_total(), $currency); |
|
111 | 111 | } |
112 | 112 | |
113 | - do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
113 | + do_action("getpaid_payment_form_cart_item_$key", $item, $form); |
|
114 | 114 | ?> |
115 | 115 | |
116 | 116 | </div> |
@@ -121,4 +121,4 @@ discard block |
||
121 | 121 | |
122 | 122 | </div> |
123 | 123 | <?php |
124 | -do_action( 'getpaid_payment_form_cart_item', $form, $item ); |
|
124 | +do_action('getpaid_payment_form_cart_item', $form, $item); |
@@ -13,94 +13,94 @@ discard block |
||
13 | 13 | class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'paypal'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'sandbox' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | 34 | public $order = 1; |
35 | 35 | |
36 | 36 | /** |
37 | - * Stores line items to send to PayPal. |
|
38 | - * |
|
39 | - * @var array |
|
40 | - */ |
|
37 | + * Stores line items to send to PayPal. |
|
38 | + * |
|
39 | + * @var array |
|
40 | + */ |
|
41 | 41 | protected $line_items = array(); |
42 | 42 | |
43 | 43 | /** |
44 | - * Endpoint for requests from PayPal. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
48 | - protected $notify_url; |
|
49 | - |
|
50 | - /** |
|
51 | - * Endpoint for requests to PayPal. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
44 | + * Endpoint for requests from PayPal. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + protected $notify_url; |
|
49 | + |
|
50 | + /** |
|
51 | + * Endpoint for requests to PayPal. |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | 55 | protected $endpoint; |
56 | 56 | |
57 | 57 | /** |
58 | - * Currencies this gateway is allowed for. |
|
59 | - * |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
58 | + * Currencies this gateway is allowed for. |
|
59 | + * |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
63 | 63 | |
64 | 64 | /** |
65 | - * URL to view a transaction. |
|
66 | - * |
|
67 | - * @var string |
|
68 | - */ |
|
65 | + * URL to view a transaction. |
|
66 | + * |
|
67 | + * @var string |
|
68 | + */ |
|
69 | 69 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
70 | 70 | |
71 | 71 | /** |
72 | - * URL to view a subscription. |
|
73 | - * |
|
74 | - * @var string |
|
75 | - */ |
|
76 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
72 | + * URL to view a subscription. |
|
73 | + * |
|
74 | + * @var string |
|
75 | + */ |
|
76 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
77 | 77 | |
78 | 78 | /** |
79 | - * Class constructor. |
|
80 | - */ |
|
81 | - public function __construct() { |
|
79 | + * Class constructor. |
|
80 | + */ |
|
81 | + public function __construct() { |
|
82 | 82 | |
83 | 83 | $this->title = __( 'PayPal Standard', 'invoicing' ); |
84 | 84 | $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
85 | 85 | $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
86 | 86 | $this->notify_url = wpinv_get_ipn_url( $this->id ); |
87 | 87 | |
88 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
88 | + add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
89 | 89 | add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
90 | 90 | |
91 | 91 | parent::__construct(); |
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
95 | - * Process Payment. |
|
96 | - * |
|
97 | - * |
|
98 | - * @param WPInv_Invoice $invoice Invoice. |
|
99 | - * @param array $submission_data Posted checkout fields. |
|
100 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
101 | - * @return array |
|
102 | - */ |
|
103 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
95 | + * Process Payment. |
|
96 | + * |
|
97 | + * |
|
98 | + * @param WPInv_Invoice $invoice Invoice. |
|
99 | + * @param array $submission_data Posted checkout fields. |
|
100 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
101 | + * @return array |
|
102 | + */ |
|
103 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
104 | 104 | |
105 | 105 | // Get redirect url. |
106 | 106 | $paypal_redirect = $this->get_request_url( $invoice ); |
@@ -123,15 +123,15 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
126 | - * Get the PayPal request URL for an invoice. |
|
127 | - * |
|
128 | - * @param WPInv_Invoice $invoice Invoice object. |
|
129 | - * @return string |
|
130 | - */ |
|
131 | - public function get_request_url( $invoice ) { |
|
126 | + * Get the PayPal request URL for an invoice. |
|
127 | + * |
|
128 | + * @param WPInv_Invoice $invoice Invoice object. |
|
129 | + * @return string |
|
130 | + */ |
|
131 | + public function get_request_url( $invoice ) { |
|
132 | 132 | |
133 | 133 | // Endpoint for this request |
134 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
134 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
135 | 135 | |
136 | 136 | // Retrieve paypal args. |
137 | 137 | $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
@@ -144,44 +144,44 @@ discard block |
||
144 | 144 | |
145 | 145 | return add_query_arg( $paypal_args, $this->endpoint ); |
146 | 146 | |
147 | - } |
|
147 | + } |
|
148 | 148 | |
149 | 149 | /** |
150 | - * Get PayPal Args for passing to PP. |
|
151 | - * |
|
152 | - * @param WPInv_Invoice $invoice Invoice object. |
|
153 | - * @return array |
|
154 | - */ |
|
155 | - protected function get_paypal_args( $invoice ) { |
|
150 | + * Get PayPal Args for passing to PP. |
|
151 | + * |
|
152 | + * @param WPInv_Invoice $invoice Invoice object. |
|
153 | + * @return array |
|
154 | + */ |
|
155 | + protected function get_paypal_args( $invoice ) { |
|
156 | 156 | |
157 | 157 | // Whether or not to send the line items as one item. |
158 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice ); |
|
159 | - |
|
160 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
161 | - $force_one_line_item = true; |
|
162 | - } |
|
163 | - |
|
164 | - $paypal_args = apply_filters( |
|
165 | - 'getpaid_paypal_args', |
|
166 | - array_merge( |
|
167 | - $this->get_transaction_args( $invoice ), |
|
168 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
169 | - ), |
|
170 | - $invoice |
|
171 | - ); |
|
172 | - |
|
173 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
158 | + $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice ); |
|
159 | + |
|
160 | + if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
161 | + $force_one_line_item = true; |
|
162 | + } |
|
163 | + |
|
164 | + $paypal_args = apply_filters( |
|
165 | + 'getpaid_paypal_args', |
|
166 | + array_merge( |
|
167 | + $this->get_transaction_args( $invoice ), |
|
168 | + $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
169 | + ), |
|
170 | + $invoice |
|
171 | + ); |
|
172 | + |
|
173 | + return $this->fix_request_length( $invoice, $paypal_args ); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
177 | - * Get transaction args for paypal request. |
|
178 | - * |
|
179 | - * @param WPInv_Invoice $invoice Invoice object. |
|
180 | - * @return array |
|
181 | - */ |
|
182 | - protected function get_transaction_args( $invoice ) { |
|
183 | - |
|
184 | - return array( |
|
177 | + * Get transaction args for paypal request. |
|
178 | + * |
|
179 | + * @param WPInv_Invoice $invoice Invoice object. |
|
180 | + * @return array |
|
181 | + */ |
|
182 | + protected function get_transaction_args( $invoice ) { |
|
183 | + |
|
184 | + return array( |
|
185 | 185 | 'cmd' => '_cart', |
186 | 186 | 'business' => wpinv_get_option( 'paypal_email', false ), |
187 | 187 | 'no_shipping' => '1', |
@@ -206,16 +206,16 @@ discard block |
||
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
209 | - * Get line item args for paypal request. |
|
210 | - * |
|
211 | - * @param WPInv_Invoice $invoice Invoice object. |
|
212 | - * @param bool $force_one_line_item Create only one item for this invoice. |
|
213 | - * @return array |
|
214 | - */ |
|
215 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
209 | + * Get line item args for paypal request. |
|
210 | + * |
|
211 | + * @param WPInv_Invoice $invoice Invoice object. |
|
212 | + * @param bool $force_one_line_item Create only one item for this invoice. |
|
213 | + * @return array |
|
214 | + */ |
|
215 | + protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
216 | 216 | |
217 | 217 | // Maybe send invoice as a single item. |
218 | - if ( $force_one_line_item ) { |
|
218 | + if ( $force_one_line_item ) { |
|
219 | 219 | return $this->get_line_item_args_single_item( $invoice ); |
220 | 220 | } |
221 | 221 | |
@@ -235,129 +235,129 @@ discard block |
||
235 | 235 | $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
236 | 236 | } |
237 | 237 | |
238 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
238 | + return array_merge( $line_item_args, $this->get_line_items() ); |
|
239 | 239 | |
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
243 | - * Get line item args for paypal request as a single line item. |
|
244 | - * |
|
245 | - * @param WPInv_Invoice $invoice Invoice object. |
|
246 | - * @return array |
|
247 | - */ |
|
248 | - protected function get_line_item_args_single_item( $invoice ) { |
|
249 | - $this->delete_line_items(); |
|
243 | + * Get line item args for paypal request as a single line item. |
|
244 | + * |
|
245 | + * @param WPInv_Invoice $invoice Invoice object. |
|
246 | + * @return array |
|
247 | + */ |
|
248 | + protected function get_line_item_args_single_item( $invoice ) { |
|
249 | + $this->delete_line_items(); |
|
250 | 250 | |
251 | 251 | $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
252 | - $this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() ); |
|
252 | + $this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() ); |
|
253 | 253 | |
254 | - return $this->get_line_items(); |
|
254 | + return $this->get_line_items(); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
258 | - * Return all line items. |
|
259 | - */ |
|
260 | - protected function get_line_items() { |
|
261 | - return $this->line_items; |
|
262 | - } |
|
258 | + * Return all line items. |
|
259 | + */ |
|
260 | + protected function get_line_items() { |
|
261 | + return $this->line_items; |
|
262 | + } |
|
263 | 263 | |
264 | 264 | /** |
265 | - * Remove all line items. |
|
266 | - */ |
|
267 | - protected function delete_line_items() { |
|
268 | - $this->line_items = array(); |
|
265 | + * Remove all line items. |
|
266 | + */ |
|
267 | + protected function delete_line_items() { |
|
268 | + $this->line_items = array(); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
272 | - * Prepare line items to send to paypal. |
|
273 | - * |
|
274 | - * @param WPInv_Invoice $invoice Invoice object. |
|
275 | - */ |
|
276 | - protected function prepare_line_items( $invoice ) { |
|
277 | - $this->delete_line_items(); |
|
278 | - |
|
279 | - // Items. |
|
280 | - foreach ( $invoice->get_items() as $item ) { |
|
281 | - $amount = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total(); |
|
282 | - $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
283 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
272 | + * Prepare line items to send to paypal. |
|
273 | + * |
|
274 | + * @param WPInv_Invoice $invoice Invoice object. |
|
275 | + */ |
|
276 | + protected function prepare_line_items( $invoice ) { |
|
277 | + $this->delete_line_items(); |
|
278 | + |
|
279 | + // Items. |
|
280 | + foreach ( $invoice->get_items() as $item ) { |
|
281 | + $amount = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total(); |
|
282 | + $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
283 | + $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | // Fees. |
287 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
287 | + foreach ( $invoice->get_fees() as $fee => $data ) { |
|
288 | 288 | $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
289 | 289 | } |
290 | 290 | |
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
294 | - * Add PayPal Line Item. |
|
295 | - * |
|
296 | - * @param string $item_name Item name. |
|
297 | - * @param int $quantity Item quantity. |
|
298 | - * @param float $amount Amount. |
|
299 | - * @param string $item_number Item number. |
|
300 | - */ |
|
301 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
302 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
303 | - |
|
304 | - $item = apply_filters( |
|
305 | - 'getpaid_paypal_line_item', |
|
306 | - array( |
|
307 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
308 | - 'quantity' => (float) $quantity, |
|
309 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
310 | - 'item_number' => $item_number, |
|
311 | - ), |
|
312 | - $item_name, |
|
313 | - $quantity, |
|
314 | - $amount, |
|
315 | - $item_number |
|
316 | - ); |
|
317 | - |
|
318 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
294 | + * Add PayPal Line Item. |
|
295 | + * |
|
296 | + * @param string $item_name Item name. |
|
297 | + * @param int $quantity Item quantity. |
|
298 | + * @param float $amount Amount. |
|
299 | + * @param string $item_number Item number. |
|
300 | + */ |
|
301 | + protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
302 | + $index = ( count( $this->line_items ) / 4 ) + 1; |
|
303 | + |
|
304 | + $item = apply_filters( |
|
305 | + 'getpaid_paypal_line_item', |
|
306 | + array( |
|
307 | + 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
308 | + 'quantity' => (float) $quantity, |
|
309 | + 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
310 | + 'item_number' => $item_number, |
|
311 | + ), |
|
312 | + $item_name, |
|
313 | + $quantity, |
|
314 | + $amount, |
|
315 | + $item_number |
|
316 | + ); |
|
317 | + |
|
318 | + $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
319 | 319 | $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
320 | 320 | |
321 | 321 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
322 | - $this->line_items[ 'amount_' . $index ] = $item['amount']; |
|
323 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
322 | + $this->line_items[ 'amount_' . $index ] = $item['amount']; |
|
323 | + $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
327 | - * If the default request with line items is too long, generate a new one with only one line item. |
|
328 | - * |
|
329 | - * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
330 | - * |
|
331 | - * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
332 | - * @param array $paypal_args Arguments sent to Paypal in the request. |
|
333 | - * @return array |
|
334 | - */ |
|
335 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
336 | - $max_paypal_length = 2083; |
|
337 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
338 | - |
|
339 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
340 | - return $paypal_args; |
|
341 | - } |
|
342 | - |
|
343 | - return apply_filters( |
|
344 | - 'getpaid_paypal_args', |
|
345 | - array_merge( |
|
346 | - $this->get_transaction_args( $invoice ), |
|
347 | - $this->get_line_item_args( $invoice, true ) |
|
348 | - ), |
|
349 | - $invoice |
|
350 | - ); |
|
327 | + * If the default request with line items is too long, generate a new one with only one line item. |
|
328 | + * |
|
329 | + * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
330 | + * |
|
331 | + * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
332 | + * @param array $paypal_args Arguments sent to Paypal in the request. |
|
333 | + * @return array |
|
334 | + */ |
|
335 | + protected function fix_request_length( $invoice, $paypal_args ) { |
|
336 | + $max_paypal_length = 2083; |
|
337 | + $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
338 | + |
|
339 | + if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
340 | + return $paypal_args; |
|
341 | + } |
|
342 | + |
|
343 | + return apply_filters( |
|
344 | + 'getpaid_paypal_args', |
|
345 | + array_merge( |
|
346 | + $this->get_transaction_args( $invoice ), |
|
347 | + $this->get_line_item_args( $invoice, true ) |
|
348 | + ), |
|
349 | + $invoice |
|
350 | + ); |
|
351 | 351 | |
352 | 352 | } |
353 | 353 | |
354 | 354 | /** |
355 | - * Processes recurring invoices. |
|
356 | - * |
|
357 | - * @param array $paypal_args PayPal args. |
|
358 | - * @param WPInv_Invoice $invoice Invoice object. |
|
359 | - */ |
|
360 | - public function process_subscription( $paypal_args, $invoice ) { |
|
355 | + * Processes recurring invoices. |
|
356 | + * |
|
357 | + * @param array $paypal_args PayPal args. |
|
358 | + * @param WPInv_Invoice $invoice Invoice object. |
|
359 | + */ |
|
360 | + public function process_subscription( $paypal_args, $invoice ) { |
|
361 | 361 | |
362 | 362 | // Make sure this is a subscription. |
363 | 363 | if ( ! $invoice->is_recurring() || ! $subscription = wpinv_get_subscription( $invoice ) ) { |
@@ -382,11 +382,11 @@ discard block |
||
382 | 382 | |
383 | 383 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
384 | 384 | |
385 | - // Trial period length. |
|
386 | - $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
385 | + // Trial period length. |
|
386 | + $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
387 | 387 | |
388 | - // Trial period. |
|
389 | - $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
388 | + // Trial period. |
|
389 | + $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
390 | 390 | |
391 | 391 | } else if ( $initial_amount != $recurring_amount ) { |
392 | 392 | |
@@ -409,40 +409,40 @@ discard block |
||
409 | 409 | } |
410 | 410 | |
411 | 411 | // We have a recurring payment |
412 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
412 | + if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
413 | 413 | |
414 | - // Subscription price |
|
415 | - $paypal_args['a3'] = $recurring_amount; |
|
414 | + // Subscription price |
|
415 | + $paypal_args['a3'] = $recurring_amount; |
|
416 | 416 | |
417 | - // Subscription duration |
|
418 | - $paypal_args['p3'] = $interval; |
|
417 | + // Subscription duration |
|
418 | + $paypal_args['p3'] = $interval; |
|
419 | 419 | |
420 | - // Subscription period |
|
421 | - $paypal_args['t3'] = $period; |
|
420 | + // Subscription period |
|
421 | + $paypal_args['t3'] = $period; |
|
422 | 422 | |
423 | 423 | } |
424 | 424 | |
425 | 425 | // Recurring payments |
426 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
426 | + if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
427 | 427 | |
428 | - // Non-recurring payments |
|
429 | - $paypal_args['src'] = 0; |
|
428 | + // Non-recurring payments |
|
429 | + $paypal_args['src'] = 0; |
|
430 | 430 | |
431 | - } else { |
|
431 | + } else { |
|
432 | 432 | |
433 | - $paypal_args['src'] = 1; |
|
433 | + $paypal_args['src'] = 1; |
|
434 | 434 | |
435 | - if ( $bill_times > 0 ) { |
|
435 | + if ( $bill_times > 0 ) { |
|
436 | 436 | |
437 | - // An initial period is being used to charge a sign-up fee |
|
438 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
439 | - $bill_times--; |
|
440 | - } |
|
437 | + // An initial period is being used to charge a sign-up fee |
|
438 | + if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
439 | + $bill_times--; |
|
440 | + } |
|
441 | 441 | |
442 | 442 | // Make sure it's not over the max of 52 |
443 | 443 | $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
444 | 444 | |
445 | - } |
|
445 | + } |
|
446 | 446 | } |
447 | 447 | |
448 | 448 | // Force return URL so that order description & instructions display |
@@ -458,19 +458,19 @@ discard block |
||
458 | 458 | } |
459 | 459 | |
460 | 460 | return apply_filters( |
461 | - 'getpaid_paypal_subscription_args', |
|
462 | - $paypal_args, |
|
463 | - $invoice |
|
461 | + 'getpaid_paypal_subscription_args', |
|
462 | + $paypal_args, |
|
463 | + $invoice |
|
464 | 464 | ); |
465 | 465 | |
466 | 466 | } |
467 | 467 | |
468 | 468 | /** |
469 | - * Processes ipns and marks payments as complete. |
|
470 | - * |
|
471 | - * @return void |
|
472 | - */ |
|
473 | - public function verify_ipn() { |
|
469 | + * Processes ipns and marks payments as complete. |
|
470 | + * |
|
471 | + * @return void |
|
472 | + */ |
|
473 | + public function verify_ipn() { |
|
474 | 474 | new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
475 | 475 | } |
476 | 476 | |
@@ -480,10 +480,10 @@ discard block |
||
480 | 480 | public function sandbox_notice() { |
481 | 481 | |
482 | 482 | return sprintf( |
483 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
484 | - '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
485 | - '</a>' |
|
486 | - ); |
|
483 | + __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
484 | + '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
485 | + '</a>' |
|
486 | + ); |
|
487 | 487 | |
488 | 488 | } |
489 | 489 |
@@ -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 | * Paypal Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'sandbox' ); |
|
27 | + protected $supports = array('subscription', 'sandbox'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @var array |
61 | 61 | */ |
62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
62 | + public $currencies = array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR'); |
|
63 | 63 | |
64 | 64 | /** |
65 | 65 | * URL to view a transaction. |
@@ -80,13 +80,13 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function __construct() { |
82 | 82 | |
83 | - $this->title = __( 'PayPal Standard', 'invoicing' ); |
|
84 | - $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
|
85 | - $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
|
86 | - $this->notify_url = wpinv_get_ipn_url( $this->id ); |
|
83 | + $this->title = __('PayPal Standard', 'invoicing'); |
|
84 | + $this->method_title = __('PayPal Standard', 'invoicing'); |
|
85 | + $this->checkout_button_text = __('Proceed to PayPal', 'invoicing'); |
|
86 | + $this->notify_url = wpinv_get_ipn_url($this->id); |
|
87 | 87 | |
88 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
89 | - add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
|
88 | + add_filter('getpaid_paypal_args', array($this, 'process_subscription'), 10, 2); |
|
89 | + add_filter('getpaid_paypal_sandbox_notice', array($this, 'sandbox_notice')); |
|
90 | 90 | |
91 | 91 | parent::__construct(); |
92 | 92 | } |
@@ -100,16 +100,16 @@ discard block |
||
100 | 100 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
101 | 101 | * @return array |
102 | 102 | */ |
103 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
103 | + public function process_payment($invoice, $submission_data, $submission) { |
|
104 | 104 | |
105 | 105 | // Get redirect url. |
106 | - $paypal_redirect = $this->get_request_url( $invoice ); |
|
106 | + $paypal_redirect = $this->get_request_url($invoice); |
|
107 | 107 | |
108 | 108 | // Add a note about the request url. |
109 | 109 | $invoice->add_note( |
110 | 110 | sprintf( |
111 | - __( 'Redirecting to PayPal: %s', 'invoicing' ), |
|
112 | - esc_url( $paypal_redirect ) |
|
111 | + __('Redirecting to PayPal: %s', 'invoicing'), |
|
112 | + esc_url($paypal_redirect) |
|
113 | 113 | ), |
114 | 114 | false, |
115 | 115 | false, |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | ); |
118 | 118 | |
119 | 119 | // Redirect to PayPal |
120 | - wp_redirect( $paypal_redirect ); |
|
120 | + wp_redirect($paypal_redirect); |
|
121 | 121 | exit; |
122 | 122 | |
123 | 123 | } |
@@ -128,21 +128,21 @@ discard block |
||
128 | 128 | * @param WPInv_Invoice $invoice Invoice object. |
129 | 129 | * @return string |
130 | 130 | */ |
131 | - public function get_request_url( $invoice ) { |
|
131 | + public function get_request_url($invoice) { |
|
132 | 132 | |
133 | 133 | // Endpoint for this request |
134 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
134 | + $this->endpoint = $this->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
135 | 135 | |
136 | 136 | // Retrieve paypal args. |
137 | - $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
|
137 | + $paypal_args = map_deep($this->get_paypal_args($invoice), 'urlencode'); |
|
138 | 138 | |
139 | - if ( $invoice->is_recurring() ) { |
|
139 | + if ($invoice->is_recurring()) { |
|
140 | 140 | $paypal_args['bn'] = 'GetPaid_Subscribe_WPS_US'; |
141 | 141 | } else { |
142 | 142 | $paypal_args['bn'] = 'GetPaid_ShoppingCart_WPS_US'; |
143 | 143 | } |
144 | 144 | |
145 | - return add_query_arg( $paypal_args, $this->endpoint ); |
|
145 | + return add_query_arg($paypal_args, $this->endpoint); |
|
146 | 146 | |
147 | 147 | } |
148 | 148 | |
@@ -152,25 +152,25 @@ discard block |
||
152 | 152 | * @param WPInv_Invoice $invoice Invoice object. |
153 | 153 | * @return array |
154 | 154 | */ |
155 | - protected function get_paypal_args( $invoice ) { |
|
155 | + protected function get_paypal_args($invoice) { |
|
156 | 156 | |
157 | 157 | // Whether or not to send the line items as one item. |
158 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice ); |
|
158 | + $force_one_line_item = apply_filters('getpaid_paypal_force_one_line_item', false, $invoice); |
|
159 | 159 | |
160 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
160 | + if ($invoice->is_recurring() || (wpinv_use_taxes() && wpinv_prices_include_tax())) { |
|
161 | 161 | $force_one_line_item = true; |
162 | 162 | } |
163 | 163 | |
164 | 164 | $paypal_args = apply_filters( |
165 | 165 | 'getpaid_paypal_args', |
166 | 166 | array_merge( |
167 | - $this->get_transaction_args( $invoice ), |
|
168 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
167 | + $this->get_transaction_args($invoice), |
|
168 | + $this->get_line_item_args($invoice, $force_one_line_item) |
|
169 | 169 | ), |
170 | 170 | $invoice |
171 | 171 | ); |
172 | 172 | |
173 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
173 | + return $this->fix_request_length($invoice, $paypal_args); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -179,11 +179,11 @@ discard block |
||
179 | 179 | * @param WPInv_Invoice $invoice Invoice object. |
180 | 180 | * @return array |
181 | 181 | */ |
182 | - protected function get_transaction_args( $invoice ) { |
|
182 | + protected function get_transaction_args($invoice) { |
|
183 | 183 | |
184 | 184 | return array( |
185 | 185 | 'cmd' => '_cart', |
186 | - 'business' => wpinv_get_option( 'paypal_email', false ), |
|
186 | + 'business' => wpinv_get_option('paypal_email', false), |
|
187 | 187 | 'no_shipping' => '1', |
188 | 188 | 'shipping' => '0', |
189 | 189 | 'no_note' => '1', |
@@ -191,16 +191,16 @@ discard block |
||
191 | 191 | 'rm' => is_ssl() ? 2 : 1, |
192 | 192 | 'upload' => 1, |
193 | 193 | 'currency_code' => $invoice->get_currency(), // https://developer.paypal.com/docs/nvp-soap-api/currency-codes/#paypal |
194 | - 'return' => esc_url_raw( $this->get_return_url( $invoice ) ), |
|
195 | - 'cancel_return' => esc_url_raw( $invoice->get_checkout_payment_url() ), |
|
196 | - 'notify_url' => getpaid_limit_length( $this->notify_url, 255 ), |
|
197 | - 'invoice' => getpaid_limit_length( $invoice->get_number(), 127 ), |
|
194 | + 'return' => esc_url_raw($this->get_return_url($invoice)), |
|
195 | + 'cancel_return' => esc_url_raw($invoice->get_checkout_payment_url()), |
|
196 | + 'notify_url' => getpaid_limit_length($this->notify_url, 255), |
|
197 | + 'invoice' => getpaid_limit_length($invoice->get_number(), 127), |
|
198 | 198 | 'custom' => $invoice->get_id(), |
199 | - 'first_name' => getpaid_limit_length( $invoice->get_first_name(), 32 ), |
|
200 | - 'last_name' => getpaid_limit_length( $invoice->get_last_name(), 64 ), |
|
201 | - 'country' => getpaid_limit_length( $invoice->get_country(), 2 ), |
|
202 | - 'email' => getpaid_limit_length( $invoice->get_email(), 127 ), |
|
203 | - 'cbt' => get_bloginfo( 'name' ) |
|
199 | + 'first_name' => getpaid_limit_length($invoice->get_first_name(), 32), |
|
200 | + 'last_name' => getpaid_limit_length($invoice->get_last_name(), 64), |
|
201 | + 'country' => getpaid_limit_length($invoice->get_country(), 2), |
|
202 | + 'email' => getpaid_limit_length($invoice->get_email(), 127), |
|
203 | + 'cbt' => get_bloginfo('name') |
|
204 | 204 | ); |
205 | 205 | |
206 | 206 | } |
@@ -212,30 +212,30 @@ discard block |
||
212 | 212 | * @param bool $force_one_line_item Create only one item for this invoice. |
213 | 213 | * @return array |
214 | 214 | */ |
215 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
215 | + protected function get_line_item_args($invoice, $force_one_line_item = false) { |
|
216 | 216 | |
217 | 217 | // Maybe send invoice as a single item. |
218 | - if ( $force_one_line_item ) { |
|
219 | - return $this->get_line_item_args_single_item( $invoice ); |
|
218 | + if ($force_one_line_item) { |
|
219 | + return $this->get_line_item_args_single_item($invoice); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | // Send each line item individually. |
223 | 223 | $line_item_args = array(); |
224 | 224 | |
225 | 225 | // Prepare line items. |
226 | - $this->prepare_line_items( $invoice ); |
|
226 | + $this->prepare_line_items($invoice); |
|
227 | 227 | |
228 | 228 | // Add taxes to the cart |
229 | - if ( wpinv_use_taxes() && $invoice->is_taxable() ) { |
|
230 | - $line_item_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_tax(), 2 ); |
|
229 | + if (wpinv_use_taxes() && $invoice->is_taxable()) { |
|
230 | + $line_item_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_tax(), 2); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | // Add discount. |
234 | - if ( $invoice->get_total_discount() > 0 ) { |
|
235 | - $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
|
234 | + if ($invoice->get_total_discount() > 0) { |
|
235 | + $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_discount(), 2); |
|
236 | 236 | } |
237 | 237 | |
238 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
238 | + return array_merge($line_item_args, $this->get_line_items()); |
|
239 | 239 | |
240 | 240 | } |
241 | 241 | |
@@ -245,11 +245,11 @@ discard block |
||
245 | 245 | * @param WPInv_Invoice $invoice Invoice object. |
246 | 246 | * @return array |
247 | 247 | */ |
248 | - protected function get_line_item_args_single_item( $invoice ) { |
|
248 | + protected function get_line_item_args_single_item($invoice) { |
|
249 | 249 | $this->delete_line_items(); |
250 | 250 | |
251 | - $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
252 | - $this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() ); |
|
251 | + $item_name = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
252 | + $this->add_line_item($item_name, 1, wpinv_sanitize_amount((float) $invoice->get_total(), 2), $invoice->get_id()); |
|
253 | 253 | |
254 | 254 | return $this->get_line_items(); |
255 | 255 | } |
@@ -273,19 +273,19 @@ discard block |
||
273 | 273 | * |
274 | 274 | * @param WPInv_Invoice $invoice Invoice object. |
275 | 275 | */ |
276 | - protected function prepare_line_items( $invoice ) { |
|
276 | + protected function prepare_line_items($invoice) { |
|
277 | 277 | $this->delete_line_items(); |
278 | 278 | |
279 | 279 | // Items. |
280 | - foreach ( $invoice->get_items() as $item ) { |
|
280 | + foreach ($invoice->get_items() as $item) { |
|
281 | 281 | $amount = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total(); |
282 | 282 | $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
283 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
283 | + $this->add_line_item($item->get_raw_name(), $quantity, $amount, $item->get_id()); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | // Fees. |
287 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
288 | - $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
|
287 | + foreach ($invoice->get_fees() as $fee => $data) { |
|
288 | + $this->add_line_item($fee, 1, wpinv_sanitize_amount($data['initial_fee'])); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | } |
@@ -298,15 +298,15 @@ discard block |
||
298 | 298 | * @param float $amount Amount. |
299 | 299 | * @param string $item_number Item number. |
300 | 300 | */ |
301 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
302 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
301 | + protected function add_line_item($item_name, $quantity = 1, $amount = 0.0, $item_number = '') { |
|
302 | + $index = (count($this->line_items) / 4) + 1; |
|
303 | 303 | |
304 | 304 | $item = apply_filters( |
305 | 305 | 'getpaid_paypal_line_item', |
306 | 306 | array( |
307 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
307 | + 'item_name' => html_entity_decode(getpaid_limit_length($item_name ? wp_strip_all_tags($item_name) : __('Item', 'invoicing'), 127), ENT_NOQUOTES, 'UTF-8'), |
|
308 | 308 | 'quantity' => (float) $quantity, |
309 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
309 | + 'amount' => wpinv_sanitize_amount((float) $amount, 2), |
|
310 | 310 | 'item_number' => $item_number, |
311 | 311 | ), |
312 | 312 | $item_name, |
@@ -315,12 +315,12 @@ discard block |
||
315 | 315 | $item_number |
316 | 316 | ); |
317 | 317 | |
318 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
319 | - $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
|
318 | + $this->line_items['item_name_' . $index] = getpaid_limit_length($item['item_name'], 127); |
|
319 | + $this->line_items['quantity_' . $index] = $item['quantity']; |
|
320 | 320 | |
321 | 321 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
322 | - $this->line_items[ 'amount_' . $index ] = $item['amount']; |
|
323 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
322 | + $this->line_items['amount_' . $index] = $item['amount']; |
|
323 | + $this->line_items['item_number_' . $index] = getpaid_limit_length($item['item_number'], 127); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
@@ -332,19 +332,19 @@ discard block |
||
332 | 332 | * @param array $paypal_args Arguments sent to Paypal in the request. |
333 | 333 | * @return array |
334 | 334 | */ |
335 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
335 | + protected function fix_request_length($invoice, $paypal_args) { |
|
336 | 336 | $max_paypal_length = 2083; |
337 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
337 | + $query_candidate = http_build_query($paypal_args, '', '&'); |
|
338 | 338 | |
339 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
339 | + if (strlen($this->endpoint . $query_candidate) <= $max_paypal_length) { |
|
340 | 340 | return $paypal_args; |
341 | 341 | } |
342 | 342 | |
343 | 343 | return apply_filters( |
344 | 344 | 'getpaid_paypal_args', |
345 | 345 | array_merge( |
346 | - $this->get_transaction_args( $invoice ), |
|
347 | - $this->get_line_item_args( $invoice, true ) |
|
346 | + $this->get_transaction_args($invoice), |
|
347 | + $this->get_line_item_args($invoice, true) |
|
348 | 348 | ), |
349 | 349 | $invoice |
350 | 350 | ); |
@@ -357,10 +357,10 @@ discard block |
||
357 | 357 | * @param array $paypal_args PayPal args. |
358 | 358 | * @param WPInv_Invoice $invoice Invoice object. |
359 | 359 | */ |
360 | - public function process_subscription( $paypal_args, $invoice ) { |
|
360 | + public function process_subscription($paypal_args, $invoice) { |
|
361 | 361 | |
362 | 362 | // Make sure this is a subscription. |
363 | - if ( ! $invoice->is_recurring() || ! $subscription = wpinv_get_subscription( $invoice ) ) { |
|
363 | + if (!$invoice->is_recurring() || !$subscription = wpinv_get_subscription($invoice)) { |
|
364 | 364 | return $paypal_args; |
365 | 365 | } |
366 | 366 | |
@@ -368,17 +368,17 @@ discard block |
||
368 | 368 | $paypal_args['cmd'] = '_xclick-subscriptions'; |
369 | 369 | |
370 | 370 | // Subscription name. |
371 | - $paypal_args['item_name'] = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
371 | + $paypal_args['item_name'] = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
372 | 372 | |
373 | 373 | // Get subscription args. |
374 | - $period = strtoupper( substr( $subscription->get_period(), 0, 1) ); |
|
374 | + $period = strtoupper(substr($subscription->get_period(), 0, 1)); |
|
375 | 375 | $interval = (int) $subscription->get_frequency(); |
376 | 376 | $bill_times = (int) $subscription->get_bill_times(); |
377 | - $initial_amount = (float) wpinv_sanitize_amount( $invoice->get_initial_total(), 2 ); |
|
378 | - $recurring_amount = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 ); |
|
379 | - $subscription_item = $invoice->get_recurring( true ); |
|
377 | + $initial_amount = (float) wpinv_sanitize_amount($invoice->get_initial_total(), 2); |
|
378 | + $recurring_amount = (float) wpinv_sanitize_amount($invoice->get_recurring_total(), 2); |
|
379 | + $subscription_item = $invoice->get_recurring(true); |
|
380 | 380 | |
381 | - if ( $subscription_item->has_free_trial() ) { |
|
381 | + if ($subscription_item->has_free_trial()) { |
|
382 | 382 | |
383 | 383 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
384 | 384 | |
@@ -388,28 +388,28 @@ discard block |
||
388 | 388 | // Trial period. |
389 | 389 | $paypal_args['t1'] = $subscription_item->get_trial_period(); |
390 | 390 | |
391 | - } else if ( $initial_amount != $recurring_amount ) { |
|
391 | + } else if ($initial_amount != $recurring_amount) { |
|
392 | 392 | |
393 | 393 | // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period. |
394 | 394 | |
395 | - if ( 1 == $bill_times ) { |
|
395 | + if (1 == $bill_times) { |
|
396 | 396 | $param_number = 3; |
397 | 397 | } else { |
398 | 398 | $param_number = 1; |
399 | 399 | } |
400 | 400 | |
401 | - $paypal_args[ 'a' . $param_number ] = $initial_amount ? $initial_amount : 0; |
|
401 | + $paypal_args['a' . $param_number] = $initial_amount ? $initial_amount : 0; |
|
402 | 402 | |
403 | 403 | // Sign Up interval |
404 | - $paypal_args[ 'p' . $param_number ] = $interval; |
|
404 | + $paypal_args['p' . $param_number] = $interval; |
|
405 | 405 | |
406 | 406 | // Sign Up unit of duration |
407 | - $paypal_args[ 't' . $param_number ] = $period; |
|
407 | + $paypal_args['t' . $param_number] = $period; |
|
408 | 408 | |
409 | 409 | } |
410 | 410 | |
411 | 411 | // We have a recurring payment |
412 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
412 | + if (!isset($param_number) || 1 == $param_number) { |
|
413 | 413 | |
414 | 414 | // Subscription price |
415 | 415 | $paypal_args['a3'] = $recurring_amount; |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | } |
424 | 424 | |
425 | 425 | // Recurring payments |
426 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
426 | + if (1 == $bill_times || ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial() && 2 == $bill_times)) { |
|
427 | 427 | |
428 | 428 | // Non-recurring payments |
429 | 429 | $paypal_args['src'] = 0; |
@@ -432,15 +432,15 @@ discard block |
||
432 | 432 | |
433 | 433 | $paypal_args['src'] = 1; |
434 | 434 | |
435 | - if ( $bill_times > 0 ) { |
|
435 | + if ($bill_times > 0) { |
|
436 | 436 | |
437 | 437 | // An initial period is being used to charge a sign-up fee |
438 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
438 | + if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) { |
|
439 | 439 | $bill_times--; |
440 | 440 | } |
441 | 441 | |
442 | 442 | // Make sure it's not over the max of 52 |
443 | - $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
|
443 | + $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52); |
|
444 | 444 | |
445 | 445 | } |
446 | 446 | } |
@@ -449,10 +449,10 @@ discard block |
||
449 | 449 | $paypal_args['rm'] = 2; |
450 | 450 | |
451 | 451 | // Get rid of redudant items. |
452 | - foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) { |
|
452 | + foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) { |
|
453 | 453 | |
454 | - if ( isset( $paypal_args[ $arg ] ) ) { |
|
455 | - unset( $paypal_args[ $arg ] ); |
|
454 | + if (isset($paypal_args[$arg])) { |
|
455 | + unset($paypal_args[$arg]); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | } |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | * @return void |
472 | 472 | */ |
473 | 473 | public function verify_ipn() { |
474 | - new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
|
474 | + new GetPaid_Paypal_Gateway_IPN_Handler($this); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | public function sandbox_notice() { |
481 | 481 | |
482 | 482 | return sprintf( |
483 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
483 | + __('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing'), |
|
484 | 484 | '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
485 | 485 | '</a>' |
486 | 486 | ); |
@@ -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 | * WPInv_Ajax class. |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | * Hook in ajax handlers. |
18 | 18 | */ |
19 | 19 | public static function init() { |
20 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
21 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
20 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
21 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
22 | 22 | self::add_ajax_events(); |
23 | 23 | } |
24 | 24 | |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public static function define_ajax() { |
29 | 29 | |
30 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
31 | - getpaid_maybe_define_constant( 'DOING_AJAX', true ); |
|
32 | - getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true ); |
|
33 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
34 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
30 | + if (!empty($_GET['wpinv-ajax'])) { |
|
31 | + getpaid_maybe_define_constant('DOING_AJAX', true); |
|
32 | + getpaid_maybe_define_constant('WPInv_DOING_AJAX', true); |
|
33 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
34 | + /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0); |
|
35 | 35 | } |
36 | 36 | $GLOBALS['wpdb']->hide_errors(); |
37 | 37 | } |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | * @since 1.0.18 |
45 | 45 | */ |
46 | 46 | private static function wpinv_ajax_headers() { |
47 | - if ( ! headers_sent() ) { |
|
47 | + if (!headers_sent()) { |
|
48 | 48 | send_origin_headers(); |
49 | 49 | send_nosniff_header(); |
50 | 50 | nocache_headers(); |
51 | - header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
52 | - header( 'X-Robots-Tag: noindex' ); |
|
53 | - status_header( 200 ); |
|
51 | + header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
52 | + header('X-Robots-Tag: noindex'); |
|
53 | + status_header(200); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
@@ -60,16 +60,16 @@ discard block |
||
60 | 60 | public static function do_wpinv_ajax() { |
61 | 61 | global $wp_query; |
62 | 62 | |
63 | - if ( ! empty( $_GET['wpinv-ajax'] ) ) { |
|
64 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) ); |
|
63 | + if (!empty($_GET['wpinv-ajax'])) { |
|
64 | + $wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax']))); |
|
65 | 65 | } |
66 | 66 | |
67 | - $action = $wp_query->get( 'wpinv-ajax' ); |
|
67 | + $action = $wp_query->get('wpinv-ajax'); |
|
68 | 68 | |
69 | - if ( $action ) { |
|
69 | + if ($action) { |
|
70 | 70 | self::wpinv_ajax_headers(); |
71 | - $action = sanitize_text_field( $action ); |
|
72 | - do_action( 'wpinv_ajax_' . $action ); |
|
71 | + $action = sanitize_text_field($action); |
|
72 | + do_action('wpinv_ajax_' . $action); |
|
73 | 73 | wp_die(); |
74 | 74 | } |
75 | 75 | |
@@ -101,36 +101,36 @@ discard block |
||
101 | 101 | 'payment_form_refresh_prices' => true, |
102 | 102 | ); |
103 | 103 | |
104 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
105 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
106 | - add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
104 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
105 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
106 | + add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
107 | 107 | |
108 | - if ( $nopriv ) { |
|
109 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
110 | - add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
111 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
108 | + if ($nopriv) { |
|
109 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
110 | + add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
111 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
116 | 116 | public static function add_note() { |
117 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
117 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
118 | 118 | |
119 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
119 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
120 | 120 | die(-1); |
121 | 121 | } |
122 | 122 | |
123 | - $post_id = absint( $_POST['post_id'] ); |
|
124 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
125 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
123 | + $post_id = absint($_POST['post_id']); |
|
124 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
125 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
126 | 126 | |
127 | 127 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
128 | 128 | |
129 | - if ( $post_id > 0 ) { |
|
130 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
129 | + if ($post_id > 0) { |
|
130 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
131 | 131 | |
132 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
133 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
132 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
133 | + wpinv_get_invoice_note_line_item($note_id); |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | |
@@ -138,16 +138,16 @@ discard block |
||
138 | 138 | } |
139 | 139 | |
140 | 140 | public static function delete_note() { |
141 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
141 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
142 | 142 | |
143 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
143 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
144 | 144 | die(-1); |
145 | 145 | } |
146 | 146 | |
147 | - $note_id = (int)$_POST['note_id']; |
|
147 | + $note_id = (int) $_POST['note_id']; |
|
148 | 148 | |
149 | - if ( $note_id > 0 ) { |
|
150 | - wp_delete_comment( $note_id, true ); |
|
149 | + if ($note_id > 0) { |
|
150 | + wp_delete_comment($note_id, true); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | die(); |
@@ -165,34 +165,34 @@ discard block |
||
165 | 165 | public static function get_billing_details() { |
166 | 166 | |
167 | 167 | // Verify nonce. |
168 | - check_ajax_referer( 'wpinv-nonce' ); |
|
168 | + check_ajax_referer('wpinv-nonce'); |
|
169 | 169 | |
170 | 170 | // Can the user manage the plugin? |
171 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
171 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
172 | 172 | die(-1); |
173 | 173 | } |
174 | 174 | |
175 | 175 | // Do we have a user id? |
176 | 176 | $user_id = $_GET['user_id']; |
177 | 177 | |
178 | - if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
|
178 | + if (empty($user_id) || !is_numeric($user_id)) { |
|
179 | 179 | die(-1); |
180 | 180 | } |
181 | 181 | |
182 | 182 | // Fetch the billing details. |
183 | - $billing_details = wpinv_get_user_address( $user_id ); |
|
184 | - $billing_details = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id ); |
|
183 | + $billing_details = wpinv_get_user_address($user_id); |
|
184 | + $billing_details = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id); |
|
185 | 185 | |
186 | 186 | // unset the user id and email. |
187 | - $to_ignore = array( 'user_id', 'email' ); |
|
187 | + $to_ignore = array('user_id', 'email'); |
|
188 | 188 | |
189 | - foreach ( $to_ignore as $key ) { |
|
190 | - if ( isset( $billing_details[ $key ] ) ) { |
|
191 | - unset( $billing_details[ $key ] ); |
|
189 | + foreach ($to_ignore as $key) { |
|
190 | + if (isset($billing_details[$key])) { |
|
191 | + unset($billing_details[$key]); |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | |
195 | - wp_send_json_success( $billing_details ); |
|
195 | + wp_send_json_success($billing_details); |
|
196 | 196 | |
197 | 197 | } |
198 | 198 | |
@@ -202,47 +202,47 @@ discard block |
||
202 | 202 | public static function check_new_user_email() { |
203 | 203 | |
204 | 204 | // Verify nonce. |
205 | - check_ajax_referer( 'wpinv-nonce' ); |
|
205 | + check_ajax_referer('wpinv-nonce'); |
|
206 | 206 | |
207 | 207 | // Can the user manage the plugin? |
208 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
208 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
209 | 209 | die(-1); |
210 | 210 | } |
211 | 211 | |
212 | 212 | // We need an email address. |
213 | - if ( empty( $_GET['email'] ) ) { |
|
214 | - _e( "Provide the new user's email address", 'invoicing' ); |
|
213 | + if (empty($_GET['email'])) { |
|
214 | + _e("Provide the new user's email address", 'invoicing'); |
|
215 | 215 | exit; |
216 | 216 | } |
217 | 217 | |
218 | 218 | // Ensure the email is valid. |
219 | - $email = sanitize_text_field( $_GET['email'] ); |
|
220 | - if ( ! is_email( $email ) ) { |
|
221 | - _e( 'Invalid email address', 'invoicing' ); |
|
219 | + $email = sanitize_text_field($_GET['email']); |
|
220 | + if (!is_email($email)) { |
|
221 | + _e('Invalid email address', 'invoicing'); |
|
222 | 222 | exit; |
223 | 223 | } |
224 | 224 | |
225 | 225 | // And it does not exist. |
226 | - if ( email_exists( $email ) ) { |
|
227 | - _e( 'A user with this email address already exists', 'invoicing' ); |
|
226 | + if (email_exists($email)) { |
|
227 | + _e('A user with this email address already exists', 'invoicing'); |
|
228 | 228 | exit; |
229 | 229 | } |
230 | 230 | |
231 | - wp_send_json_success( true ); |
|
231 | + wp_send_json_success(true); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | public static function run_tool() { |
235 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
236 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
235 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
236 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
237 | 237 | die(-1); |
238 | 238 | } |
239 | 239 | |
240 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
240 | + $tool = sanitize_text_field($_POST['tool']); |
|
241 | 241 | |
242 | - do_action( 'wpinv_run_tool' ); |
|
242 | + do_action('wpinv_run_tool'); |
|
243 | 243 | |
244 | - if ( !empty( $tool ) ) { |
|
245 | - do_action( 'wpinv_tool_' . $tool ); |
|
244 | + if (!empty($tool)) { |
|
245 | + do_action('wpinv_tool_' . $tool); |
|
246 | 246 | } |
247 | 247 | } |
248 | 248 | |
@@ -252,27 +252,27 @@ discard block |
||
252 | 252 | public static function get_payment_form() { |
253 | 253 | |
254 | 254 | // Check nonce. |
255 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
255 | + check_ajax_referer('getpaid_form_nonce'); |
|
256 | 256 | |
257 | 257 | // Is the request set up correctly? |
258 | - if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) { |
|
258 | + if (empty($_GET['form']) && empty($_GET['item'])) { |
|
259 | 259 | echo aui()->alert( |
260 | 260 | array( |
261 | 261 | 'type' => 'warning', |
262 | - 'content' => __( 'No payment form or item provided', 'invoicing' ), |
|
262 | + 'content' => __('No payment form or item provided', 'invoicing'), |
|
263 | 263 | ) |
264 | 264 | ); |
265 | 265 | exit; |
266 | 266 | } |
267 | 267 | |
268 | 268 | // Payment form or button? |
269 | - if ( ! empty( $_GET['form'] ) ) { |
|
270 | - getpaid_display_payment_form( urldecode( $_GET['form'] ) ); |
|
271 | - } else if( ! empty( $_GET['invoice'] ) ) { |
|
272 | - getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) ); |
|
269 | + if (!empty($_GET['form'])) { |
|
270 | + getpaid_display_payment_form(urldecode($_GET['form'])); |
|
271 | + } else if (!empty($_GET['invoice'])) { |
|
272 | + getpaid_display_invoice_payment_form(urldecode($_GET['invoice'])); |
|
273 | 273 | } else { |
274 | - $items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) ); |
|
275 | - getpaid_display_item_payment_form( $items ); |
|
274 | + $items = getpaid_convert_items_to_array(urldecode($_GET['item'])); |
|
275 | + getpaid_display_item_payment_form($items); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | exit; |
@@ -287,17 +287,17 @@ discard block |
||
287 | 287 | public static function payment_form() { |
288 | 288 | |
289 | 289 | // Check nonce. |
290 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
290 | + check_ajax_referer('getpaid_form_nonce'); |
|
291 | 291 | |
292 | 292 | // ... form fields... |
293 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
294 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
293 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
294 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
295 | 295 | exit; |
296 | 296 | } |
297 | 297 | |
298 | 298 | // Process the payment form. |
299 | - $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' ); |
|
300 | - $checkout = new $checkout_class( new GetPaid_Payment_Form_Submission() ); |
|
299 | + $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout'); |
|
300 | + $checkout = new $checkout_class(new GetPaid_Payment_Form_Submission()); |
|
301 | 301 | $checkout->process_checkout(); |
302 | 302 | |
303 | 303 | exit; |
@@ -310,55 +310,55 @@ discard block |
||
310 | 310 | */ |
311 | 311 | public static function get_payment_form_states_field() { |
312 | 312 | |
313 | - if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) { |
|
313 | + if (empty($_GET['country']) || empty($_GET['form'])) { |
|
314 | 314 | exit; |
315 | 315 | } |
316 | 316 | |
317 | - $elements = getpaid_get_payment_form_elements( $_GET['form'] ); |
|
317 | + $elements = getpaid_get_payment_form_elements($_GET['form']); |
|
318 | 318 | |
319 | - if ( empty( $elements ) ) { |
|
319 | + if (empty($elements)) { |
|
320 | 320 | exit; |
321 | 321 | } |
322 | 322 | |
323 | 323 | $address_fields = array(); |
324 | - foreach ( $elements as $element ) { |
|
325 | - if ( 'address' === $element['type'] ) { |
|
324 | + foreach ($elements as $element) { |
|
325 | + if ('address' === $element['type']) { |
|
326 | 326 | $address_fields = $element; |
327 | 327 | break; |
328 | 328 | } |
329 | 329 | } |
330 | 330 | |
331 | - if ( empty( $address_fields ) ) { |
|
331 | + if (empty($address_fields)) { |
|
332 | 332 | exit; |
333 | 333 | } |
334 | 334 | |
335 | - foreach ( $address_fields['fields'] as $address_field ) { |
|
335 | + foreach ($address_fields['fields'] as $address_field) { |
|
336 | 336 | |
337 | - if ( 'wpinv_state' == $address_field['name'] ) { |
|
337 | + if ('wpinv_state' == $address_field['name']) { |
|
338 | 338 | |
339 | - $wrap_class = getpaid_get_form_element_grid_class( $address_field ); |
|
340 | - $wrap_class = esc_attr( "$wrap_class getpaid-address-field-wrapper" ); |
|
341 | - $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] ); |
|
342 | - $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] ); |
|
343 | - $value = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : ''; |
|
344 | - $label = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] ); |
|
339 | + $wrap_class = getpaid_get_form_element_grid_class($address_field); |
|
340 | + $wrap_class = esc_attr("$wrap_class getpaid-address-field-wrapper"); |
|
341 | + $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']); |
|
342 | + $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']); |
|
343 | + $value = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : ''; |
|
344 | + $label = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']); |
|
345 | 345 | |
346 | - if ( ! empty( $address_field['required'] ) ) { |
|
346 | + if (!empty($address_field['required'])) { |
|
347 | 347 | $label .= "<span class='text-danger'> *</span>"; |
348 | 348 | } |
349 | 349 | |
350 | - $html = getpaid_get_states_select_markup ( |
|
351 | - sanitize_text_field( $_GET['country'] ), |
|
350 | + $html = getpaid_get_states_select_markup( |
|
351 | + sanitize_text_field($_GET['country']), |
|
352 | 352 | $value, |
353 | 353 | $placeholder, |
354 | 354 | $label, |
355 | 355 | $description, |
356 | - ! empty( $address_field['required'] ), |
|
356 | + !empty($address_field['required']), |
|
357 | 357 | $wrap_class, |
358 | - wpinv_clean( $_GET['name'] ) |
|
358 | + wpinv_clean($_GET['name']) |
|
359 | 359 | ); |
360 | 360 | |
361 | - wp_send_json_success( $html ); |
|
361 | + wp_send_json_success($html); |
|
362 | 362 | exit; |
363 | 363 | |
364 | 364 | } |
@@ -374,56 +374,56 @@ discard block |
||
374 | 374 | public static function recalculate_invoice_totals() { |
375 | 375 | |
376 | 376 | // Verify nonce. |
377 | - check_ajax_referer( 'wpinv-nonce' ); |
|
377 | + check_ajax_referer('wpinv-nonce'); |
|
378 | 378 | |
379 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
379 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
380 | 380 | exit; |
381 | 381 | } |
382 | 382 | |
383 | 383 | // We need an invoice. |
384 | - if ( empty( $_POST['post_id'] ) ) { |
|
384 | + if (empty($_POST['post_id'])) { |
|
385 | 385 | exit; |
386 | 386 | } |
387 | 387 | |
388 | 388 | // Fetch the invoice. |
389 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
389 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
390 | 390 | |
391 | 391 | // Ensure it exists. |
392 | - if ( ! $invoice->get_id() ) { |
|
392 | + if (!$invoice->get_id()) { |
|
393 | 393 | exit; |
394 | 394 | } |
395 | 395 | |
396 | 396 | // Maybe set the country, state, currency. |
397 | - foreach ( array( 'country', 'state', 'currency' ) as $key ) { |
|
398 | - if ( isset( $_POST[ $key ] ) ) { |
|
397 | + foreach (array('country', 'state', 'currency') as $key) { |
|
398 | + if (isset($_POST[$key])) { |
|
399 | 399 | $method = "set_$key"; |
400 | - $invoice->$method( $_POST[ $key ] ); |
|
400 | + $invoice->$method($_POST[$key]); |
|
401 | 401 | } |
402 | 402 | } |
403 | 403 | |
404 | 404 | // Maybe disable taxes. |
405 | - $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) ); |
|
405 | + $invoice->set_disable_taxes(!empty($_POST['taxes'])); |
|
406 | 406 | |
407 | 407 | // Recalculate totals. |
408 | 408 | $invoice->recalculate_total(); |
409 | 409 | |
410 | - $total = wpinv_price( $invoice->get_total(), $invoice->get_currency() ); |
|
410 | + $total = wpinv_price($invoice->get_total(), $invoice->get_currency()); |
|
411 | 411 | |
412 | - if ( $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) { |
|
413 | - $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() ); |
|
414 | - $total .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>'; |
|
412 | + if ($invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) { |
|
413 | + $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency()); |
|
414 | + $total .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>'; |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | $totals = array( |
418 | - 'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ), |
|
419 | - 'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
|
420 | - 'tax' => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ), |
|
418 | + 'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()), |
|
419 | + 'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()), |
|
420 | + 'tax' => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()), |
|
421 | 421 | 'total' => $total, |
422 | 422 | ); |
423 | 423 | |
424 | - $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice ); |
|
424 | + $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice); |
|
425 | 425 | |
426 | - wp_send_json_success( compact( 'totals' ) ); |
|
426 | + wp_send_json_success(compact('totals')); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | /** |
@@ -432,33 +432,33 @@ discard block |
||
432 | 432 | public static function get_invoice_items() { |
433 | 433 | |
434 | 434 | // Verify nonce. |
435 | - check_ajax_referer( 'wpinv-nonce' ); |
|
435 | + check_ajax_referer('wpinv-nonce'); |
|
436 | 436 | |
437 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
437 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
438 | 438 | exit; |
439 | 439 | } |
440 | 440 | |
441 | 441 | // We need an invoice and items. |
442 | - if ( empty( $_POST['post_id'] ) ) { |
|
442 | + if (empty($_POST['post_id'])) { |
|
443 | 443 | exit; |
444 | 444 | } |
445 | 445 | |
446 | 446 | // Fetch the invoice. |
447 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
447 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
448 | 448 | |
449 | 449 | // Ensure it exists. |
450 | - if ( ! $invoice->get_id() ) { |
|
450 | + if (!$invoice->get_id()) { |
|
451 | 451 | exit; |
452 | 452 | } |
453 | 453 | |
454 | 454 | // Return an array of invoice items. |
455 | 455 | $items = array(); |
456 | 456 | |
457 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
458 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
457 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
458 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
459 | 459 | } |
460 | 460 | |
461 | - wp_send_json_success( compact( 'items' ) ); |
|
461 | + wp_send_json_success(compact('items')); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | /** |
@@ -467,50 +467,50 @@ discard block |
||
467 | 467 | public static function edit_invoice_item() { |
468 | 468 | |
469 | 469 | // Verify nonce. |
470 | - check_ajax_referer( 'wpinv-nonce' ); |
|
470 | + check_ajax_referer('wpinv-nonce'); |
|
471 | 471 | |
472 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
472 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
473 | 473 | exit; |
474 | 474 | } |
475 | 475 | |
476 | 476 | // We need an invoice and item details. |
477 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) { |
|
477 | + if (empty($_POST['post_id']) || empty($_POST['data'])) { |
|
478 | 478 | exit; |
479 | 479 | } |
480 | 480 | |
481 | 481 | // Fetch the invoice. |
482 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
482 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
483 | 483 | |
484 | 484 | // Ensure it exists and its not been paid for. |
485 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
485 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
486 | 486 | exit; |
487 | 487 | } |
488 | 488 | |
489 | 489 | // Format the data. |
490 | - $data = wp_list_pluck( $_POST['data'], 'value', 'field' ); |
|
490 | + $data = wp_list_pluck($_POST['data'], 'value', 'field'); |
|
491 | 491 | |
492 | 492 | // Ensure that we have an item id. |
493 | - if ( empty( $data['id'] ) ) { |
|
493 | + if (empty($data['id'])) { |
|
494 | 494 | exit; |
495 | 495 | } |
496 | 496 | |
497 | 497 | // Abort if the invoice does not have the specified item. |
498 | - $item = $invoice->get_item( (int) $data['id'] ); |
|
498 | + $item = $invoice->get_item((int) $data['id']); |
|
499 | 499 | |
500 | - if ( empty( $item ) ) { |
|
500 | + if (empty($item)) { |
|
501 | 501 | exit; |
502 | 502 | } |
503 | 503 | |
504 | 504 | // Update the item. |
505 | - $item->set_price( $data['price'] ); |
|
506 | - $item->set_name( $data['name'] ); |
|
507 | - $item->set_description( $data['description'] ); |
|
508 | - $item->set_quantity( $data['quantity'] ); |
|
505 | + $item->set_price($data['price']); |
|
506 | + $item->set_name($data['name']); |
|
507 | + $item->set_description($data['description']); |
|
508 | + $item->set_quantity($data['quantity']); |
|
509 | 509 | |
510 | 510 | // Add it to the invoice. |
511 | - $error = $invoice->add_item( $item ); |
|
511 | + $error = $invoice->add_item($item); |
|
512 | 512 | $alert = false; |
513 | - if ( is_wp_error( $error ) ) { |
|
513 | + if (is_wp_error($error)) { |
|
514 | 514 | $alert = $error->get_error_message(); |
515 | 515 | } |
516 | 516 | |
@@ -523,11 +523,11 @@ discard block |
||
523 | 523 | // Return an array of invoice items. |
524 | 524 | $items = array(); |
525 | 525 | |
526 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
527 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
526 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
527 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
528 | 528 | } |
529 | 529 | |
530 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
530 | + wp_send_json_success(compact('items', 'alert')); |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | /** |
@@ -536,33 +536,33 @@ discard block |
||
536 | 536 | public static function remove_invoice_item() { |
537 | 537 | |
538 | 538 | // Verify nonce. |
539 | - check_ajax_referer( 'wpinv-nonce' ); |
|
539 | + check_ajax_referer('wpinv-nonce'); |
|
540 | 540 | |
541 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
541 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
542 | 542 | exit; |
543 | 543 | } |
544 | 544 | |
545 | 545 | // We need an invoice and an item. |
546 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) { |
|
546 | + if (empty($_POST['post_id']) || empty($_POST['item_id'])) { |
|
547 | 547 | exit; |
548 | 548 | } |
549 | 549 | |
550 | 550 | // Fetch the invoice. |
551 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
551 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
552 | 552 | |
553 | 553 | // Ensure it exists and its not been paid for. |
554 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
554 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
555 | 555 | exit; |
556 | 556 | } |
557 | 557 | |
558 | 558 | // Abort if the invoice does not have the specified item. |
559 | - $item = $invoice->get_item( (int) $_POST['item_id'] ); |
|
559 | + $item = $invoice->get_item((int) $_POST['item_id']); |
|
560 | 560 | |
561 | - if ( empty( $item ) ) { |
|
561 | + if (empty($item)) { |
|
562 | 562 | exit; |
563 | 563 | } |
564 | 564 | |
565 | - $invoice->remove_item( (int) $_POST['item_id'] ); |
|
565 | + $invoice->remove_item((int) $_POST['item_id']); |
|
566 | 566 | |
567 | 567 | // Update totals. |
568 | 568 | $invoice->recalculate_total(); |
@@ -573,11 +573,11 @@ discard block |
||
573 | 573 | // Return an array of invoice items. |
574 | 574 | $items = array(); |
575 | 575 | |
576 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
577 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
576 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
577 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
578 | 578 | } |
579 | 579 | |
580 | - wp_send_json_success( compact( 'items' ) ); |
|
580 | + wp_send_json_success(compact('items')); |
|
581 | 581 | } |
582 | 582 | |
583 | 583 | /** |
@@ -586,39 +586,39 @@ discard block |
||
586 | 586 | public static function add_invoice_items() { |
587 | 587 | |
588 | 588 | // Verify nonce. |
589 | - check_ajax_referer( 'wpinv-nonce' ); |
|
589 | + check_ajax_referer('wpinv-nonce'); |
|
590 | 590 | |
591 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
591 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
592 | 592 | exit; |
593 | 593 | } |
594 | 594 | |
595 | 595 | // We need an invoice and items. |
596 | - if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) { |
|
596 | + if (empty($_POST['post_id']) || empty($_POST['items'])) { |
|
597 | 597 | exit; |
598 | 598 | } |
599 | 599 | |
600 | 600 | // Fetch the invoice. |
601 | - $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) ); |
|
601 | + $invoice = new WPInv_Invoice(trim($_POST['post_id'])); |
|
602 | 602 | $alert = false; |
603 | 603 | |
604 | 604 | // Ensure it exists and its not been paid for. |
605 | - if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
605 | + if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) { |
|
606 | 606 | exit; |
607 | 607 | } |
608 | 608 | |
609 | 609 | // Add the items. |
610 | - foreach ( $_POST['items'] as $data ) { |
|
610 | + foreach ($_POST['items'] as $data) { |
|
611 | 611 | |
612 | - $item = new GetPaid_Form_Item( $data[ 'id' ] ); |
|
612 | + $item = new GetPaid_Form_Item($data['id']); |
|
613 | 613 | |
614 | - if ( is_numeric( $data[ 'qty' ] ) && (float) $data[ 'qty' ] > 0 ) { |
|
615 | - $item->set_quantity( $data[ 'qty' ] ); |
|
614 | + if (is_numeric($data['qty']) && (float) $data['qty'] > 0) { |
|
615 | + $item->set_quantity($data['qty']); |
|
616 | 616 | } |
617 | 617 | |
618 | - if ( $item->get_id() > 0 ) { |
|
619 | - $error = $invoice->add_item( $item ); |
|
618 | + if ($item->get_id() > 0) { |
|
619 | + $error = $invoice->add_item($item); |
|
620 | 620 | |
621 | - if ( is_wp_error( $error ) ) { |
|
621 | + if (is_wp_error($error)) { |
|
622 | 622 | $alert = $error->get_error_message(); |
623 | 623 | } |
624 | 624 | |
@@ -633,11 +633,11 @@ discard block |
||
633 | 633 | // Return an array of invoice items. |
634 | 634 | $items = array(); |
635 | 635 | |
636 | - foreach ( $invoice->get_items() as $item_id => $item ) { |
|
637 | - $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() ); |
|
636 | + foreach ($invoice->get_items() as $item_id => $item) { |
|
637 | + $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency()); |
|
638 | 638 | } |
639 | 639 | |
640 | - wp_send_json_success( compact( 'items', 'alert' ) ); |
|
640 | + wp_send_json_success(compact('items', 'alert')); |
|
641 | 641 | } |
642 | 642 | |
643 | 643 | /** |
@@ -646,15 +646,15 @@ discard block |
||
646 | 646 | public static function get_invoicing_items() { |
647 | 647 | |
648 | 648 | // Verify nonce. |
649 | - check_ajax_referer( 'wpinv-nonce' ); |
|
649 | + check_ajax_referer('wpinv-nonce'); |
|
650 | 650 | |
651 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
651 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
652 | 652 | exit; |
653 | 653 | } |
654 | 654 | |
655 | 655 | // We need a search term. |
656 | - if ( empty( $_GET['search'] ) ) { |
|
657 | - wp_send_json_success( array() ); |
|
656 | + if (empty($_GET['search'])) { |
|
657 | + wp_send_json_success(array()); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | // Retrieve items. |
@@ -663,8 +663,8 @@ discard block |
||
663 | 663 | 'orderby' => 'title', |
664 | 664 | 'order' => 'ASC', |
665 | 665 | 'posts_per_page' => -1, |
666 | - 'post_status' => array( 'publish' ), |
|
667 | - 's' => trim( $_GET['search'] ), |
|
666 | + 'post_status' => array('publish'), |
|
667 | + 's' => trim($_GET['search']), |
|
668 | 668 | 'meta_query' => array( |
669 | 669 | array( |
670 | 670 | 'key' => '_wpinv_type', |
@@ -674,22 +674,22 @@ discard block |
||
674 | 674 | ) |
675 | 675 | ); |
676 | 676 | |
677 | - $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) ); |
|
677 | + $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args)); |
|
678 | 678 | $data = array(); |
679 | 679 | |
680 | 680 | |
681 | - $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) ); |
|
681 | + $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id'])); |
|
682 | 682 | |
683 | - foreach ( $items as $item ) { |
|
684 | - $item = new GetPaid_Form_Item( $item ); |
|
683 | + foreach ($items as $item) { |
|
684 | + $item = new GetPaid_Form_Item($item); |
|
685 | 685 | $data[] = array( |
686 | 686 | 'id' => (int) $item->get_id(), |
687 | - 'text' => strip_tags( $item->get_name() ), |
|
688 | - 'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '', |
|
687 | + 'text' => strip_tags($item->get_name()), |
|
688 | + 'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '', |
|
689 | 689 | ); |
690 | 690 | } |
691 | 691 | |
692 | - wp_send_json_success( $data ); |
|
692 | + wp_send_json_success($data); |
|
693 | 693 | |
694 | 694 | } |
695 | 695 | |
@@ -699,24 +699,24 @@ discard block |
||
699 | 699 | public static function get_aui_states_field() { |
700 | 700 | |
701 | 701 | // Verify nonce. |
702 | - check_ajax_referer( 'wpinv-nonce' ); |
|
702 | + check_ajax_referer('wpinv-nonce'); |
|
703 | 703 | |
704 | 704 | // We need a country. |
705 | - if ( empty( $_GET['country'] ) ) { |
|
705 | + if (empty($_GET['country'])) { |
|
706 | 706 | exit; |
707 | 707 | } |
708 | 708 | |
709 | - $states = wpinv_get_country_states( trim( $_GET['country'] ) ); |
|
710 | - $state = isset( $_GET['state'] ) ? trim( $_GET['state'] ) : wpinv_get_default_state(); |
|
709 | + $states = wpinv_get_country_states(trim($_GET['country'])); |
|
710 | + $state = isset($_GET['state']) ? trim($_GET['state']) : wpinv_get_default_state(); |
|
711 | 711 | |
712 | - if ( empty( $states ) ) { |
|
712 | + if (empty($states)) { |
|
713 | 713 | |
714 | 714 | $html = aui()->input( |
715 | 715 | array( |
716 | 716 | 'type' => 'text', |
717 | 717 | 'id' => 'wpinv_state', |
718 | 718 | 'name' => 'wpinv_state', |
719 | - 'label' => __( 'State', 'invoicing' ), |
|
719 | + 'label' => __('State', 'invoicing'), |
|
720 | 720 | 'label_type' => 'vertical', |
721 | 721 | 'placeholder' => 'Liège', |
722 | 722 | 'class' => 'form-control-sm', |
@@ -730,9 +730,9 @@ discard block |
||
730 | 730 | array( |
731 | 731 | 'id' => 'wpinv_state', |
732 | 732 | 'name' => 'wpinv_state', |
733 | - 'label' => __( 'State', 'invoicing' ), |
|
733 | + 'label' => __('State', 'invoicing'), |
|
734 | 734 | 'label_type' => 'vertical', |
735 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
735 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
736 | 736 | 'class' => 'form-control-sm', |
737 | 737 | 'value' => $state, |
738 | 738 | 'options' => $states, |
@@ -746,7 +746,7 @@ discard block |
||
746 | 746 | wp_send_json_success( |
747 | 747 | array( |
748 | 748 | 'html' => $html, |
749 | - 'select' => ! empty ( $states ) |
|
749 | + 'select' => !empty ($states) |
|
750 | 750 | ) |
751 | 751 | ); |
752 | 752 | |
@@ -760,11 +760,11 @@ discard block |
||
760 | 760 | public static function payment_form_refresh_prices() { |
761 | 761 | |
762 | 762 | // Check nonce. |
763 | - check_ajax_referer( 'getpaid_form_nonce' ); |
|
763 | + check_ajax_referer('getpaid_form_nonce'); |
|
764 | 764 | |
765 | 765 | // ... form fields... |
766 | - if ( empty( $_POST['getpaid_payment_form_submission'] ) ) { |
|
767 | - _e( 'Error: Reload the page and try again.', 'invoicing' ); |
|
766 | + if (empty($_POST['getpaid_payment_form_submission'])) { |
|
767 | + _e('Error: Reload the page and try again.', 'invoicing'); |
|
768 | 768 | exit; |
769 | 769 | } |
770 | 770 | |
@@ -772,18 +772,18 @@ discard block |
||
772 | 772 | $submission = new GetPaid_Payment_Form_Submission(); |
773 | 773 | |
774 | 774 | // Do we have an error? |
775 | - if ( ! empty( $submission->last_error ) ) { |
|
775 | + if (!empty($submission->last_error)) { |
|
776 | 776 | echo $submission->last_error; |
777 | 777 | exit; |
778 | 778 | } |
779 | 779 | |
780 | 780 | // Prepare the response. |
781 | - $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission ); |
|
781 | + $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission); |
|
782 | 782 | |
783 | 783 | // Filter the response. |
784 | - $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission ); |
|
784 | + $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission); |
|
785 | 785 | |
786 | - wp_send_json_success( $response ); |
|
786 | + wp_send_json_success($response); |
|
787 | 787 | } |
788 | 788 | |
789 | 789 | } |
@@ -20,214 +20,214 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class GetPaid_Installer { |
22 | 22 | |
23 | - /** |
|
24 | - * Upgrades the install. |
|
25 | - * |
|
26 | - * @param string $upgrade_from The current invoicing version. |
|
27 | - */ |
|
28 | - public function upgrade_db( $upgrade_from ) { |
|
29 | - |
|
30 | - // Save the current invoicing version. |
|
31 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
32 | - |
|
33 | - // Setup the invoice Custom Post Type. |
|
34 | - GetPaid_Post_Types::register_post_types(); |
|
35 | - |
|
36 | - // Clear the permalinks |
|
37 | - flush_rewrite_rules(); |
|
38 | - |
|
39 | - // Maybe create new/missing pages. |
|
40 | - $this->create_pages(); |
|
41 | - |
|
42 | - // Maybe re(add) admin capabilities. |
|
43 | - $this->add_capabilities(); |
|
44 | - |
|
45 | - // Maybe create the default payment form. |
|
46 | - wpinv_get_default_payment_form(); |
|
47 | - |
|
48 | - // Create any missing database tables. |
|
49 | - $method = "upgrade_from_$upgrade_from"; |
|
50 | - |
|
51 | - if ( method_exists( $this, $method ) ) { |
|
52 | - $this->$method(); |
|
53 | - } |
|
54 | - |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Do a fresh install. |
|
59 | - * |
|
60 | - */ |
|
61 | - public function upgrade_from_0() { |
|
62 | - $this->create_subscriptions_table(); |
|
63 | - $this->create_invoices_table(); |
|
64 | - $this->create_invoice_items_table(); |
|
65 | - |
|
66 | - // Save default tax rates. |
|
67 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Upgrade to 0.0.5 |
|
72 | - * |
|
73 | - */ |
|
74 | - public function upgrade_from_004() { |
|
75 | - global $wpdb; |
|
76 | - |
|
77 | - // Invoices. |
|
78 | - $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
79 | - if ( ! empty( $results ) ) { |
|
80 | - $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
81 | - |
|
82 | - // Clean post cache |
|
83 | - foreach ( $results as $row ) { |
|
84 | - clean_post_cache( $row->ID ); |
|
85 | - } |
|
86 | - |
|
87 | - } |
|
88 | - |
|
89 | - // Item meta key changes |
|
90 | - $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
|
91 | - $results = $wpdb->get_results( $query ); |
|
92 | - |
|
93 | - if ( ! empty( $results ) ) { |
|
94 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
95 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
96 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
97 | - |
|
98 | - foreach ( $results as $row ) { |
|
99 | - clean_post_cache( $row->post_id ); |
|
100 | - } |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - $this->upgrade_from_102(); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Upgrade to 1.0.3 |
|
109 | - * |
|
110 | - */ |
|
111 | - public function upgrade_from_102() { |
|
112 | - $this->create_subscriptions_table(); |
|
113 | - $this->upgrade_from_118(); |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Upgrade to version 2.0.0. |
|
118 | - * |
|
119 | - */ |
|
120 | - public function upgrade_from_118() { |
|
121 | - $this->create_invoices_table(); |
|
122 | - $this->create_invoice_items_table(); |
|
123 | - $this->migrate_old_invoices(); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Upgrade to version 2.0.8. |
|
128 | - * |
|
129 | - */ |
|
130 | - public function upgrade_from_207() { |
|
131 | - global $wpdb; |
|
132 | - $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" ); |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Give administrators the capability to manage GetPaid. |
|
137 | - * |
|
138 | - */ |
|
139 | - public function add_capabilities() { |
|
140 | - $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Re-create GetPaid pages. |
|
145 | - * |
|
146 | - */ |
|
147 | - public function create_pages() { |
|
148 | - |
|
149 | - $pages = apply_filters( |
|
150 | - 'wpinv_create_pages', |
|
151 | - array( |
|
152 | - |
|
153 | - // Checkout page. |
|
154 | - 'checkout_page' => array( |
|
155 | - 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
156 | - 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
157 | - 'content' => ' |
|
23 | + /** |
|
24 | + * Upgrades the install. |
|
25 | + * |
|
26 | + * @param string $upgrade_from The current invoicing version. |
|
27 | + */ |
|
28 | + public function upgrade_db( $upgrade_from ) { |
|
29 | + |
|
30 | + // Save the current invoicing version. |
|
31 | + update_option( 'wpinv_version', WPINV_VERSION ); |
|
32 | + |
|
33 | + // Setup the invoice Custom Post Type. |
|
34 | + GetPaid_Post_Types::register_post_types(); |
|
35 | + |
|
36 | + // Clear the permalinks |
|
37 | + flush_rewrite_rules(); |
|
38 | + |
|
39 | + // Maybe create new/missing pages. |
|
40 | + $this->create_pages(); |
|
41 | + |
|
42 | + // Maybe re(add) admin capabilities. |
|
43 | + $this->add_capabilities(); |
|
44 | + |
|
45 | + // Maybe create the default payment form. |
|
46 | + wpinv_get_default_payment_form(); |
|
47 | + |
|
48 | + // Create any missing database tables. |
|
49 | + $method = "upgrade_from_$upgrade_from"; |
|
50 | + |
|
51 | + if ( method_exists( $this, $method ) ) { |
|
52 | + $this->$method(); |
|
53 | + } |
|
54 | + |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Do a fresh install. |
|
59 | + * |
|
60 | + */ |
|
61 | + public function upgrade_from_0() { |
|
62 | + $this->create_subscriptions_table(); |
|
63 | + $this->create_invoices_table(); |
|
64 | + $this->create_invoice_items_table(); |
|
65 | + |
|
66 | + // Save default tax rates. |
|
67 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Upgrade to 0.0.5 |
|
72 | + * |
|
73 | + */ |
|
74 | + public function upgrade_from_004() { |
|
75 | + global $wpdb; |
|
76 | + |
|
77 | + // Invoices. |
|
78 | + $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
79 | + if ( ! empty( $results ) ) { |
|
80 | + $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
81 | + |
|
82 | + // Clean post cache |
|
83 | + foreach ( $results as $row ) { |
|
84 | + clean_post_cache( $row->ID ); |
|
85 | + } |
|
86 | + |
|
87 | + } |
|
88 | + |
|
89 | + // Item meta key changes |
|
90 | + $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
|
91 | + $results = $wpdb->get_results( $query ); |
|
92 | + |
|
93 | + if ( ! empty( $results ) ) { |
|
94 | + $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
95 | + $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
96 | + $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
97 | + |
|
98 | + foreach ( $results as $row ) { |
|
99 | + clean_post_cache( $row->post_id ); |
|
100 | + } |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + $this->upgrade_from_102(); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Upgrade to 1.0.3 |
|
109 | + * |
|
110 | + */ |
|
111 | + public function upgrade_from_102() { |
|
112 | + $this->create_subscriptions_table(); |
|
113 | + $this->upgrade_from_118(); |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Upgrade to version 2.0.0. |
|
118 | + * |
|
119 | + */ |
|
120 | + public function upgrade_from_118() { |
|
121 | + $this->create_invoices_table(); |
|
122 | + $this->create_invoice_items_table(); |
|
123 | + $this->migrate_old_invoices(); |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * Upgrade to version 2.0.8. |
|
128 | + * |
|
129 | + */ |
|
130 | + public function upgrade_from_207() { |
|
131 | + global $wpdb; |
|
132 | + $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" ); |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Give administrators the capability to manage GetPaid. |
|
137 | + * |
|
138 | + */ |
|
139 | + public function add_capabilities() { |
|
140 | + $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Re-create GetPaid pages. |
|
145 | + * |
|
146 | + */ |
|
147 | + public function create_pages() { |
|
148 | + |
|
149 | + $pages = apply_filters( |
|
150 | + 'wpinv_create_pages', |
|
151 | + array( |
|
152 | + |
|
153 | + // Checkout page. |
|
154 | + 'checkout_page' => array( |
|
155 | + 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
156 | + 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
157 | + 'content' => ' |
|
158 | 158 | <!-- wp:shortcode --> |
159 | 159 | [wpinv_checkout] |
160 | 160 | <!-- /wp:shortcode --> |
161 | 161 | ', |
162 | - 'parent' => '', |
|
163 | - ), |
|
164 | - |
|
165 | - // Invoice history page. |
|
166 | - 'invoice_history_page' => array( |
|
167 | - 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
168 | - 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
169 | - 'content' => ' |
|
162 | + 'parent' => '', |
|
163 | + ), |
|
164 | + |
|
165 | + // Invoice history page. |
|
166 | + 'invoice_history_page' => array( |
|
167 | + 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
168 | + 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
169 | + 'content' => ' |
|
170 | 170 | <!-- wp:shortcode --> |
171 | 171 | [wpinv_history] |
172 | 172 | <!-- /wp:shortcode --> |
173 | 173 | ', |
174 | - 'parent' => '', |
|
175 | - ), |
|
176 | - |
|
177 | - // Success page content. |
|
178 | - 'success_page' => array( |
|
179 | - 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
180 | - 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
181 | - 'content' => ' |
|
174 | + 'parent' => '', |
|
175 | + ), |
|
176 | + |
|
177 | + // Success page content. |
|
178 | + 'success_page' => array( |
|
179 | + 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
180 | + 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
181 | + 'content' => ' |
|
182 | 182 | <!-- wp:shortcode --> |
183 | 183 | [wpinv_receipt] |
184 | 184 | <!-- /wp:shortcode --> |
185 | 185 | ', |
186 | - 'parent' => 'gp-checkout', |
|
187 | - ), |
|
188 | - |
|
189 | - // Failure page content. |
|
190 | - 'failure_page' => array( |
|
191 | - 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
192 | - 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
193 | - 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
194 | - 'parent' => 'gp-checkout', |
|
195 | - ), |
|
196 | - |
|
197 | - // Subscriptions history page. |
|
198 | - 'invoice_subscription_page' => array( |
|
199 | - 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
200 | - 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
201 | - 'content' => ' |
|
186 | + 'parent' => 'gp-checkout', |
|
187 | + ), |
|
188 | + |
|
189 | + // Failure page content. |
|
190 | + 'failure_page' => array( |
|
191 | + 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
192 | + 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
193 | + 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
194 | + 'parent' => 'gp-checkout', |
|
195 | + ), |
|
196 | + |
|
197 | + // Subscriptions history page. |
|
198 | + 'invoice_subscription_page' => array( |
|
199 | + 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
200 | + 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
201 | + 'content' => ' |
|
202 | 202 | <!-- wp:shortcode --> |
203 | 203 | [wpinv_subscriptions] |
204 | 204 | <!-- /wp:shortcode --> |
205 | 205 | ', |
206 | - 'parent' => '', |
|
207 | - ), |
|
206 | + 'parent' => '', |
|
207 | + ), |
|
208 | 208 | |
209 | - ) |
|
210 | - ); |
|
209 | + ) |
|
210 | + ); |
|
211 | 211 | |
212 | - foreach ( $pages as $key => $page ) { |
|
213 | - wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
214 | - } |
|
212 | + foreach ( $pages as $key => $page ) { |
|
213 | + wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
214 | + } |
|
215 | 215 | |
216 | - } |
|
216 | + } |
|
217 | 217 | |
218 | - /** |
|
219 | - * Create subscriptions table. |
|
220 | - * |
|
221 | - */ |
|
222 | - public function create_subscriptions_table() { |
|
218 | + /** |
|
219 | + * Create subscriptions table. |
|
220 | + * |
|
221 | + */ |
|
222 | + public function create_subscriptions_table() { |
|
223 | 223 | |
224 | - global $wpdb; |
|
224 | + global $wpdb; |
|
225 | 225 | |
226 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
226 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
227 | 227 | |
228 | - // Create tables. |
|
229 | - $charset_collate = $wpdb->get_charset_collate(); |
|
230 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions ( |
|
228 | + // Create tables. |
|
229 | + $charset_collate = $wpdb->get_charset_collate(); |
|
230 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions ( |
|
231 | 231 | id bigint(20) unsigned NOT NULL auto_increment, |
232 | 232 | customer_id bigint(20) NOT NULL, |
233 | 233 | frequency int(11) NOT NULL DEFAULT '1', |
@@ -250,22 +250,22 @@ discard block |
||
250 | 250 | KEY customer_and_status (customer_id, status) |
251 | 251 | ) $charset_collate;"; |
252 | 252 | |
253 | - dbDelta( $sql ); |
|
253 | + dbDelta( $sql ); |
|
254 | 254 | |
255 | - } |
|
255 | + } |
|
256 | 256 | |
257 | - /** |
|
258 | - * Create invoices table. |
|
259 | - * |
|
260 | - */ |
|
261 | - public function create_invoices_table() { |
|
262 | - global $wpdb; |
|
257 | + /** |
|
258 | + * Create invoices table. |
|
259 | + * |
|
260 | + */ |
|
261 | + public function create_invoices_table() { |
|
262 | + global $wpdb; |
|
263 | 263 | |
264 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
264 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
265 | 265 | |
266 | - // Create tables. |
|
267 | - $charset_collate = $wpdb->get_charset_collate(); |
|
268 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices ( |
|
266 | + // Create tables. |
|
267 | + $charset_collate = $wpdb->get_charset_collate(); |
|
268 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices ( |
|
269 | 269 | post_id BIGINT(20) NOT NULL, |
270 | 270 | `number` VARCHAR(100), |
271 | 271 | `key` VARCHAR(100), |
@@ -301,22 +301,22 @@ discard block |
||
301 | 301 | KEY `key` (`key`) |
302 | 302 | ) $charset_collate;"; |
303 | 303 | |
304 | - dbDelta( $sql ); |
|
304 | + dbDelta( $sql ); |
|
305 | 305 | |
306 | - } |
|
306 | + } |
|
307 | 307 | |
308 | - /** |
|
309 | - * Create invoice items table. |
|
310 | - * |
|
311 | - */ |
|
312 | - public function create_invoice_items_table() { |
|
313 | - global $wpdb; |
|
308 | + /** |
|
309 | + * Create invoice items table. |
|
310 | + * |
|
311 | + */ |
|
312 | + public function create_invoice_items_table() { |
|
313 | + global $wpdb; |
|
314 | 314 | |
315 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
315 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
316 | 316 | |
317 | - // Create tables. |
|
318 | - $charset_collate = $wpdb->get_charset_collate(); |
|
319 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items ( |
|
317 | + // Create tables. |
|
318 | + $charset_collate = $wpdb->get_charset_collate(); |
|
319 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items ( |
|
320 | 320 | ID BIGINT(20) NOT NULL AUTO_INCREMENT, |
321 | 321 | post_id BIGINT(20) NOT NULL, |
322 | 322 | item_id BIGINT(20) NOT NULL, |
@@ -338,138 +338,138 @@ discard block |
||
338 | 338 | KEY post_id (post_id) |
339 | 339 | ) $charset_collate;"; |
340 | 340 | |
341 | - dbDelta( $sql ); |
|
342 | - |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * Migrates old invoices to new invoices. |
|
347 | - * |
|
348 | - */ |
|
349 | - public function migrate_old_invoices() { |
|
350 | - global $wpdb; |
|
351 | - |
|
352 | - $invoices = array_unique( |
|
353 | - get_posts( |
|
354 | - array( |
|
355 | - 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
356 | - 'posts_per_page' => -1, |
|
357 | - 'fields' => 'ids', |
|
358 | - 'post_status' => array_keys( get_post_stati() ), |
|
359 | - ) |
|
360 | - ) |
|
361 | - ); |
|
362 | - |
|
363 | - // Abort if we do not have any invoices. |
|
364 | - if ( empty( $invoices ) ) { |
|
365 | - return; |
|
366 | - } |
|
367 | - |
|
368 | - $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
369 | - $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
370 | - |
|
371 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' ); |
|
372 | - |
|
373 | - $invoice_rows = array(); |
|
374 | - foreach ( $invoices as $invoice ) { |
|
375 | - |
|
376 | - $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
377 | - |
|
378 | - if ( empty( $invoice->ID ) ) { |
|
379 | - return; |
|
380 | - } |
|
381 | - |
|
382 | - $fields = array ( |
|
383 | - 'post_id' => $invoice->ID, |
|
384 | - 'number' => $invoice->get_number(), |
|
385 | - 'key' => $invoice->get_key(), |
|
386 | - 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
387 | - 'mode' => $invoice->mode, |
|
388 | - 'user_ip' => $invoice->get_ip(), |
|
389 | - 'first_name' => $invoice->get_first_name(), |
|
390 | - 'last_name' => $invoice->get_last_name(), |
|
391 | - 'address' => $invoice->get_address(), |
|
392 | - 'city' => $invoice->city, |
|
393 | - 'state' => $invoice->state, |
|
394 | - 'country' => $invoice->country, |
|
395 | - 'zip' => $invoice->zip, |
|
396 | - 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
397 | - 'gateway' => $invoice->get_gateway(), |
|
398 | - 'transaction_id' => $invoice->get_transaction_id(), |
|
399 | - 'currency' => $invoice->get_currency(), |
|
400 | - 'subtotal' => $invoice->get_subtotal(), |
|
401 | - 'tax' => $invoice->get_tax(), |
|
402 | - 'fees_total' => $invoice->get_fees_total(), |
|
403 | - 'total' => $invoice->get_total(), |
|
404 | - 'discount' => $invoice->get_discount(), |
|
405 | - 'discount_code' => $invoice->get_discount_code(), |
|
406 | - 'disable_taxes' => $invoice->disable_taxes, |
|
407 | - 'due_date' => $invoice->get_due_date(), |
|
408 | - 'completed_date' => $invoice->get_completed_date(), |
|
409 | - 'company' => $invoice->company, |
|
410 | - 'vat_number' => $invoice->vat_number, |
|
411 | - 'vat_rate' => $invoice->vat_rate, |
|
412 | - 'custom_meta' => $invoice->payment_meta |
|
413 | - ); |
|
414 | - |
|
415 | - foreach ( $fields as $key => $val ) { |
|
416 | - if ( is_null( $val ) ) { |
|
417 | - $val = ''; |
|
418 | - } |
|
419 | - $val = maybe_serialize( $val ); |
|
420 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
421 | - } |
|
422 | - |
|
423 | - $fields = implode( ', ', $fields ); |
|
424 | - $invoice_rows[] = "($fields)"; |
|
425 | - |
|
426 | - $item_rows = array(); |
|
427 | - $item_columns = array(); |
|
428 | - foreach ( $invoice->get_cart_details() as $details ) { |
|
429 | - $fields = array( |
|
430 | - 'post_id' => $invoice->ID, |
|
431 | - 'item_id' => $details['id'], |
|
432 | - 'item_name' => $details['name'], |
|
433 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
434 | - 'vat_rate' => $details['vat_rate'], |
|
435 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
436 | - 'tax' => $details['tax'], |
|
437 | - 'item_price' => $details['item_price'], |
|
438 | - 'custom_price' => $details['custom_price'], |
|
439 | - 'quantity' => $details['quantity'], |
|
440 | - 'discount' => $details['discount'], |
|
441 | - 'subtotal' => $details['subtotal'], |
|
442 | - 'price' => $details['price'], |
|
443 | - 'meta' => $details['meta'], |
|
444 | - 'fees' => $details['fees'], |
|
445 | - ); |
|
446 | - |
|
447 | - $item_columns = array_keys ( $fields ); |
|
448 | - |
|
449 | - foreach ( $fields as $key => $val ) { |
|
450 | - if ( is_null( $val ) ) { |
|
451 | - $val = ''; |
|
452 | - } |
|
453 | - $val = maybe_serialize( $val ); |
|
454 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
455 | - } |
|
456 | - |
|
457 | - $fields = implode( ', ', $fields ); |
|
458 | - $item_rows[] = "($fields)"; |
|
459 | - } |
|
460 | - |
|
461 | - $item_rows = implode( ', ', $item_rows ); |
|
462 | - $item_columns = implode( ', ', $item_columns ); |
|
463 | - $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
464 | - } |
|
465 | - |
|
466 | - if ( empty( $invoice_rows ) ) { |
|
467 | - return; |
|
468 | - } |
|
469 | - |
|
470 | - $invoice_rows = implode( ', ', $invoice_rows ); |
|
471 | - $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
472 | - |
|
473 | - } |
|
341 | + dbDelta( $sql ); |
|
342 | + |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * Migrates old invoices to new invoices. |
|
347 | + * |
|
348 | + */ |
|
349 | + public function migrate_old_invoices() { |
|
350 | + global $wpdb; |
|
351 | + |
|
352 | + $invoices = array_unique( |
|
353 | + get_posts( |
|
354 | + array( |
|
355 | + 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
356 | + 'posts_per_page' => -1, |
|
357 | + 'fields' => 'ids', |
|
358 | + 'post_status' => array_keys( get_post_stati() ), |
|
359 | + ) |
|
360 | + ) |
|
361 | + ); |
|
362 | + |
|
363 | + // Abort if we do not have any invoices. |
|
364 | + if ( empty( $invoices ) ) { |
|
365 | + return; |
|
366 | + } |
|
367 | + |
|
368 | + $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
369 | + $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
370 | + |
|
371 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' ); |
|
372 | + |
|
373 | + $invoice_rows = array(); |
|
374 | + foreach ( $invoices as $invoice ) { |
|
375 | + |
|
376 | + $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
377 | + |
|
378 | + if ( empty( $invoice->ID ) ) { |
|
379 | + return; |
|
380 | + } |
|
381 | + |
|
382 | + $fields = array ( |
|
383 | + 'post_id' => $invoice->ID, |
|
384 | + 'number' => $invoice->get_number(), |
|
385 | + 'key' => $invoice->get_key(), |
|
386 | + 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
387 | + 'mode' => $invoice->mode, |
|
388 | + 'user_ip' => $invoice->get_ip(), |
|
389 | + 'first_name' => $invoice->get_first_name(), |
|
390 | + 'last_name' => $invoice->get_last_name(), |
|
391 | + 'address' => $invoice->get_address(), |
|
392 | + 'city' => $invoice->city, |
|
393 | + 'state' => $invoice->state, |
|
394 | + 'country' => $invoice->country, |
|
395 | + 'zip' => $invoice->zip, |
|
396 | + 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
397 | + 'gateway' => $invoice->get_gateway(), |
|
398 | + 'transaction_id' => $invoice->get_transaction_id(), |
|
399 | + 'currency' => $invoice->get_currency(), |
|
400 | + 'subtotal' => $invoice->get_subtotal(), |
|
401 | + 'tax' => $invoice->get_tax(), |
|
402 | + 'fees_total' => $invoice->get_fees_total(), |
|
403 | + 'total' => $invoice->get_total(), |
|
404 | + 'discount' => $invoice->get_discount(), |
|
405 | + 'discount_code' => $invoice->get_discount_code(), |
|
406 | + 'disable_taxes' => $invoice->disable_taxes, |
|
407 | + 'due_date' => $invoice->get_due_date(), |
|
408 | + 'completed_date' => $invoice->get_completed_date(), |
|
409 | + 'company' => $invoice->company, |
|
410 | + 'vat_number' => $invoice->vat_number, |
|
411 | + 'vat_rate' => $invoice->vat_rate, |
|
412 | + 'custom_meta' => $invoice->payment_meta |
|
413 | + ); |
|
414 | + |
|
415 | + foreach ( $fields as $key => $val ) { |
|
416 | + if ( is_null( $val ) ) { |
|
417 | + $val = ''; |
|
418 | + } |
|
419 | + $val = maybe_serialize( $val ); |
|
420 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
421 | + } |
|
422 | + |
|
423 | + $fields = implode( ', ', $fields ); |
|
424 | + $invoice_rows[] = "($fields)"; |
|
425 | + |
|
426 | + $item_rows = array(); |
|
427 | + $item_columns = array(); |
|
428 | + foreach ( $invoice->get_cart_details() as $details ) { |
|
429 | + $fields = array( |
|
430 | + 'post_id' => $invoice->ID, |
|
431 | + 'item_id' => $details['id'], |
|
432 | + 'item_name' => $details['name'], |
|
433 | + 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
434 | + 'vat_rate' => $details['vat_rate'], |
|
435 | + 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
436 | + 'tax' => $details['tax'], |
|
437 | + 'item_price' => $details['item_price'], |
|
438 | + 'custom_price' => $details['custom_price'], |
|
439 | + 'quantity' => $details['quantity'], |
|
440 | + 'discount' => $details['discount'], |
|
441 | + 'subtotal' => $details['subtotal'], |
|
442 | + 'price' => $details['price'], |
|
443 | + 'meta' => $details['meta'], |
|
444 | + 'fees' => $details['fees'], |
|
445 | + ); |
|
446 | + |
|
447 | + $item_columns = array_keys ( $fields ); |
|
448 | + |
|
449 | + foreach ( $fields as $key => $val ) { |
|
450 | + if ( is_null( $val ) ) { |
|
451 | + $val = ''; |
|
452 | + } |
|
453 | + $val = maybe_serialize( $val ); |
|
454 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
455 | + } |
|
456 | + |
|
457 | + $fields = implode( ', ', $fields ); |
|
458 | + $item_rows[] = "($fields)"; |
|
459 | + } |
|
460 | + |
|
461 | + $item_rows = implode( ', ', $item_rows ); |
|
462 | + $item_columns = implode( ', ', $item_columns ); |
|
463 | + $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
464 | + } |
|
465 | + |
|
466 | + if ( empty( $invoice_rows ) ) { |
|
467 | + return; |
|
468 | + } |
|
469 | + |
|
470 | + $invoice_rows = implode( ', ', $invoice_rows ); |
|
471 | + $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
472 | + |
|
473 | + } |
|
474 | 474 | |
475 | 475 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 2.0.2 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * The main installer/updater class. |
@@ -25,10 +25,10 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @param string $upgrade_from The current invoicing version. |
27 | 27 | */ |
28 | - public function upgrade_db( $upgrade_from ) { |
|
28 | + public function upgrade_db($upgrade_from) { |
|
29 | 29 | |
30 | 30 | // Save the current invoicing version. |
31 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
31 | + update_option('wpinv_version', WPINV_VERSION); |
|
32 | 32 | |
33 | 33 | // Setup the invoice Custom Post Type. |
34 | 34 | GetPaid_Post_Types::register_post_types(); |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | // Create any missing database tables. |
49 | 49 | $method = "upgrade_from_$upgrade_from"; |
50 | 50 | |
51 | - if ( method_exists( $this, $method ) ) { |
|
51 | + if (method_exists($this, $method)) { |
|
52 | 52 | $this->$method(); |
53 | 53 | } |
54 | 54 | |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $this->create_invoice_items_table(); |
65 | 65 | |
66 | 66 | // Save default tax rates. |
67 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
67 | + update_option('wpinv_tax_rates', wpinv_get_data('tax-rates')); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -75,28 +75,28 @@ discard block |
||
75 | 75 | global $wpdb; |
76 | 76 | |
77 | 77 | // Invoices. |
78 | - $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
79 | - if ( ! empty( $results ) ) { |
|
80 | - $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
78 | + $results = $wpdb->get_results("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); |
|
79 | + if (!empty($results)) { |
|
80 | + $wpdb->query("UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); |
|
81 | 81 | |
82 | 82 | // Clean post cache |
83 | - foreach ( $results as $row ) { |
|
84 | - clean_post_cache( $row->ID ); |
|
83 | + foreach ($results as $row) { |
|
84 | + clean_post_cache($row->ID); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | } |
88 | 88 | |
89 | 89 | // Item meta key changes |
90 | 90 | $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
91 | - $results = $wpdb->get_results( $query ); |
|
91 | + $results = $wpdb->get_results($query); |
|
92 | 92 | |
93 | - if ( ! empty( $results ) ) { |
|
94 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
95 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
96 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
93 | + if (!empty($results)) { |
|
94 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )"); |
|
95 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'"); |
|
96 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'"); |
|
97 | 97 | |
98 | - foreach ( $results as $row ) { |
|
99 | - clean_post_cache( $row->post_id ); |
|
98 | + foreach ($results as $row) { |
|
99 | + clean_post_cache($row->post_id); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | } |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | */ |
130 | 130 | public function upgrade_from_207() { |
131 | 131 | global $wpdb; |
132 | - $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" ); |
|
132 | + $wpdb->query("ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);"); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * |
138 | 138 | */ |
139 | 139 | public function add_capabilities() { |
140 | - $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
140 | + $GLOBALS['wp_roles']->add_cap('administrator', 'manage_invoicing'); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
@@ -152,8 +152,8 @@ discard block |
||
152 | 152 | |
153 | 153 | // Checkout page. |
154 | 154 | 'checkout_page' => array( |
155 | - 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
156 | - 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
155 | + 'name' => _x('gp-checkout', 'Page slug', 'invoicing'), |
|
156 | + 'title' => _x('Checkout', 'Page title', 'invoicing'), |
|
157 | 157 | 'content' => ' |
158 | 158 | <!-- wp:shortcode --> |
159 | 159 | [wpinv_checkout] |
@@ -164,8 +164,8 @@ discard block |
||
164 | 164 | |
165 | 165 | // Invoice history page. |
166 | 166 | 'invoice_history_page' => array( |
167 | - 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
168 | - 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
167 | + 'name' => _x('gp-invoices', 'Page slug', 'invoicing'), |
|
168 | + 'title' => _x('My Invoices', 'Page title', 'invoicing'), |
|
169 | 169 | 'content' => ' |
170 | 170 | <!-- wp:shortcode --> |
171 | 171 | [wpinv_history] |
@@ -176,8 +176,8 @@ discard block |
||
176 | 176 | |
177 | 177 | // Success page content. |
178 | 178 | 'success_page' => array( |
179 | - 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
180 | - 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
179 | + 'name' => _x('gp-receipt', 'Page slug', 'invoicing'), |
|
180 | + 'title' => _x('Payment Confirmation', 'Page title', 'invoicing'), |
|
181 | 181 | 'content' => ' |
182 | 182 | <!-- wp:shortcode --> |
183 | 183 | [wpinv_receipt] |
@@ -188,16 +188,16 @@ discard block |
||
188 | 188 | |
189 | 189 | // Failure page content. |
190 | 190 | 'failure_page' => array( |
191 | - 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
192 | - 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
193 | - 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
191 | + 'name' => _x('gp-transaction-failed', 'Page slug', 'invoicing'), |
|
192 | + 'title' => _x('Transaction Failed', 'Page title', 'invoicing'), |
|
193 | + 'content' => __('Your transaction failed, please try again or contact site support.', 'invoicing'), |
|
194 | 194 | 'parent' => 'gp-checkout', |
195 | 195 | ), |
196 | 196 | |
197 | 197 | // Subscriptions history page. |
198 | 198 | 'invoice_subscription_page' => array( |
199 | - 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
200 | - 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
199 | + 'name' => _x('gp-subscriptions', 'Page slug', 'invoicing'), |
|
200 | + 'title' => _x('My Subscriptions', 'Page title', 'invoicing'), |
|
201 | 201 | 'content' => ' |
202 | 202 | <!-- wp:shortcode --> |
203 | 203 | [wpinv_subscriptions] |
@@ -209,8 +209,8 @@ discard block |
||
209 | 209 | ) |
210 | 210 | ); |
211 | 211 | |
212 | - foreach ( $pages as $key => $page ) { |
|
213 | - wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
212 | + foreach ($pages as $key => $page) { |
|
213 | + wpinv_create_page(esc_sql($page['name']), $key, $page['title'], $page['content'], $page['parent']); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | } |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | |
224 | 224 | global $wpdb; |
225 | 225 | |
226 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
226 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
227 | 227 | |
228 | 228 | // Create tables. |
229 | 229 | $charset_collate = $wpdb->get_charset_collate(); |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | KEY customer_and_status (customer_id, status) |
251 | 251 | ) $charset_collate;"; |
252 | 252 | |
253 | - dbDelta( $sql ); |
|
253 | + dbDelta($sql); |
|
254 | 254 | |
255 | 255 | } |
256 | 256 | |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | public function create_invoices_table() { |
262 | 262 | global $wpdb; |
263 | 263 | |
264 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
264 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
265 | 265 | |
266 | 266 | // Create tables. |
267 | 267 | $charset_collate = $wpdb->get_charset_collate(); |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | KEY `key` (`key`) |
302 | 302 | ) $charset_collate;"; |
303 | 303 | |
304 | - dbDelta( $sql ); |
|
304 | + dbDelta($sql); |
|
305 | 305 | |
306 | 306 | } |
307 | 307 | |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | public function create_invoice_items_table() { |
313 | 313 | global $wpdb; |
314 | 314 | |
315 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
315 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
316 | 316 | |
317 | 317 | // Create tables. |
318 | 318 | $charset_collate = $wpdb->get_charset_collate(); |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | KEY post_id (post_id) |
339 | 339 | ) $charset_collate;"; |
340 | 340 | |
341 | - dbDelta( $sql ); |
|
341 | + dbDelta($sql); |
|
342 | 342 | |
343 | 343 | } |
344 | 344 | |
@@ -352,38 +352,38 @@ discard block |
||
352 | 352 | $invoices = array_unique( |
353 | 353 | get_posts( |
354 | 354 | array( |
355 | - 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
355 | + 'post_type' => array('wpi_invoice', 'wpi_quote'), |
|
356 | 356 | 'posts_per_page' => -1, |
357 | 357 | 'fields' => 'ids', |
358 | - 'post_status' => array_keys( get_post_stati() ), |
|
358 | + 'post_status' => array_keys(get_post_stati()), |
|
359 | 359 | ) |
360 | 360 | ) |
361 | 361 | ); |
362 | 362 | |
363 | 363 | // Abort if we do not have any invoices. |
364 | - if ( empty( $invoices ) ) { |
|
364 | + if (empty($invoices)) { |
|
365 | 365 | return; |
366 | 366 | } |
367 | 367 | |
368 | 368 | $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
369 | 369 | $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
370 | 370 | |
371 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' ); |
|
371 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'); |
|
372 | 372 | |
373 | 373 | $invoice_rows = array(); |
374 | - foreach ( $invoices as $invoice ) { |
|
374 | + foreach ($invoices as $invoice) { |
|
375 | 375 | |
376 | - $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
376 | + $invoice = new WPInv_Legacy_Invoice($invoice); |
|
377 | 377 | |
378 | - if ( empty( $invoice->ID ) ) { |
|
378 | + if (empty($invoice->ID)) { |
|
379 | 379 | return; |
380 | 380 | } |
381 | 381 | |
382 | - $fields = array ( |
|
382 | + $fields = array( |
|
383 | 383 | 'post_id' => $invoice->ID, |
384 | 384 | 'number' => $invoice->get_number(), |
385 | 385 | 'key' => $invoice->get_key(), |
386 | - 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
386 | + 'type' => str_replace('wpi_', '', $invoice->post_type), |
|
387 | 387 | 'mode' => $invoice->mode, |
388 | 388 | 'user_ip' => $invoice->get_ip(), |
389 | 389 | 'first_name' => $invoice->get_first_name(), |
@@ -412,27 +412,27 @@ discard block |
||
412 | 412 | 'custom_meta' => $invoice->payment_meta |
413 | 413 | ); |
414 | 414 | |
415 | - foreach ( $fields as $key => $val ) { |
|
416 | - if ( is_null( $val ) ) { |
|
415 | + foreach ($fields as $key => $val) { |
|
416 | + if (is_null($val)) { |
|
417 | 417 | $val = ''; |
418 | 418 | } |
419 | - $val = maybe_serialize( $val ); |
|
420 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
419 | + $val = maybe_serialize($val); |
|
420 | + $fields[$key] = $wpdb->prepare('%s', $val); |
|
421 | 421 | } |
422 | 422 | |
423 | - $fields = implode( ', ', $fields ); |
|
423 | + $fields = implode(', ', $fields); |
|
424 | 424 | $invoice_rows[] = "($fields)"; |
425 | 425 | |
426 | 426 | $item_rows = array(); |
427 | 427 | $item_columns = array(); |
428 | - foreach ( $invoice->get_cart_details() as $details ) { |
|
428 | + foreach ($invoice->get_cart_details() as $details) { |
|
429 | 429 | $fields = array( |
430 | 430 | 'post_id' => $invoice->ID, |
431 | 431 | 'item_id' => $details['id'], |
432 | 432 | 'item_name' => $details['name'], |
433 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
433 | + 'item_description' => empty($details['meta']['description']) ? '' : $details['meta']['description'], |
|
434 | 434 | 'vat_rate' => $details['vat_rate'], |
435 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
435 | + 'vat_class' => empty($details['vat_class']) ? '_standard' : $details['vat_class'], |
|
436 | 436 | 'tax' => $details['tax'], |
437 | 437 | 'item_price' => $details['item_price'], |
438 | 438 | 'custom_price' => $details['custom_price'], |
@@ -444,31 +444,31 @@ discard block |
||
444 | 444 | 'fees' => $details['fees'], |
445 | 445 | ); |
446 | 446 | |
447 | - $item_columns = array_keys ( $fields ); |
|
447 | + $item_columns = array_keys($fields); |
|
448 | 448 | |
449 | - foreach ( $fields as $key => $val ) { |
|
450 | - if ( is_null( $val ) ) { |
|
449 | + foreach ($fields as $key => $val) { |
|
450 | + if (is_null($val)) { |
|
451 | 451 | $val = ''; |
452 | 452 | } |
453 | - $val = maybe_serialize( $val ); |
|
454 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
453 | + $val = maybe_serialize($val); |
|
454 | + $fields[$key] = $wpdb->prepare('%s', $val); |
|
455 | 455 | } |
456 | 456 | |
457 | - $fields = implode( ', ', $fields ); |
|
457 | + $fields = implode(', ', $fields); |
|
458 | 458 | $item_rows[] = "($fields)"; |
459 | 459 | } |
460 | 460 | |
461 | - $item_rows = implode( ', ', $item_rows ); |
|
462 | - $item_columns = implode( ', ', $item_columns ); |
|
463 | - $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
461 | + $item_rows = implode(', ', $item_rows); |
|
462 | + $item_columns = implode(', ', $item_columns); |
|
463 | + $wpdb->query("INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows"); |
|
464 | 464 | } |
465 | 465 | |
466 | - if ( empty( $invoice_rows ) ) { |
|
466 | + if (empty($invoice_rows)) { |
|
467 | 467 | return; |
468 | 468 | } |
469 | 469 | |
470 | - $invoice_rows = implode( ', ', $invoice_rows ); |
|
471 | - $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
470 | + $invoice_rows = implode(', ', $invoice_rows); |
|
471 | + $wpdb->query("INSERT INTO $invoices_table VALUES $invoice_rows"); |
|
472 | 472 | |
473 | 473 | } |
474 | 474 |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if (!defined('ABSPATH')) { |
|
11 | 11 | exit; // Exit if accessed directly |
12 | 12 | } |
13 | 13 | |
@@ -21,51 +21,51 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param WP_Post $post |
23 | 23 | */ |
24 | - public static function output( $post ) { |
|
24 | + public static function output($post) { |
|
25 | 25 | |
26 | 26 | // Prepare the invoice. |
27 | - $invoice = new WPInv_Invoice( $post ); |
|
27 | + $invoice = new WPInv_Invoice($post); |
|
28 | 28 | |
29 | 29 | // Invoice items. |
30 | 30 | $items = $invoice->get_items(); |
31 | 31 | |
32 | 32 | // New item url. |
33 | - $new_item = admin_url( 'post-new.php?post_type=wpi_item' ); |
|
33 | + $new_item = admin_url('post-new.php?post_type=wpi_item'); |
|
34 | 34 | |
35 | 35 | // Totals. |
36 | - $total = wpinv_price( $invoice->get_total(), $invoice->get_currency() ); |
|
36 | + $total = wpinv_price($invoice->get_total(), $invoice->get_currency()); |
|
37 | 37 | |
38 | - if ( $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) { |
|
39 | - $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() ); |
|
40 | - $total .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>'; |
|
38 | + if ($invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) { |
|
39 | + $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency()); |
|
40 | + $total .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>'; |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | $totals = array( |
44 | 44 | |
45 | 45 | 'subtotal' => array( |
46 | - 'label' => __( 'Items Subtotal', 'invoicing' ), |
|
47 | - 'value' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ), |
|
46 | + 'label' => __('Items Subtotal', 'invoicing'), |
|
47 | + 'value' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()), |
|
48 | 48 | ), |
49 | 49 | |
50 | 50 | 'discount' => array( |
51 | - 'label' => __( 'Total Discount', 'invoicing' ), |
|
52 | - 'value' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ), |
|
51 | + 'label' => __('Total Discount', 'invoicing'), |
|
52 | + 'value' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()), |
|
53 | 53 | ), |
54 | 54 | |
55 | 55 | 'tax' => array( |
56 | - 'label' => __( 'Total Tax', 'invoicing' ), |
|
57 | - 'value' => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ), |
|
56 | + 'label' => __('Total Tax', 'invoicing'), |
|
57 | + 'value' => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()), |
|
58 | 58 | ), |
59 | 59 | |
60 | 60 | 'total' => array( |
61 | - 'label' => __( 'Invoice Total', 'invoicing' ), |
|
61 | + 'label' => __('Invoice Total', 'invoicing'), |
|
62 | 62 | 'value' => $total, |
63 | 63 | ) |
64 | 64 | ); |
65 | 65 | |
66 | 66 | |
67 | - if ( ! wpinv_use_taxes() ) { |
|
68 | - unset( $totals['tax'] ); |
|
67 | + if (!wpinv_use_taxes()) { |
|
68 | + unset($totals['tax']); |
|
69 | 69 | } |
70 | 70 | ?> |
71 | 71 | |
@@ -81,10 +81,10 @@ discard block |
||
81 | 81 | } |
82 | 82 | </style> |
83 | 83 | |
84 | - <div class="bsui getpaid-invoice-items-inner <?php echo sanitize_html_class( $invoice->get_template( 'edit' ) ); ?> <?php echo empty( $items ) ? 'no-items' : 'has-items'; ?> <?php echo $invoice->is_paid() || $invoice->is_refunded() ? 'not-editable' : 'editable'; ?>" style="margin-top: 1.5rem"> |
|
84 | + <div class="bsui getpaid-invoice-items-inner <?php echo sanitize_html_class($invoice->get_template('edit')); ?> <?php echo empty($items) ? 'no-items' : 'has-items'; ?> <?php echo $invoice->is_paid() || $invoice->is_refunded() ? 'not-editable' : 'editable'; ?>" style="margin-top: 1.5rem"> |
|
85 | 85 | |
86 | - <?php if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) : ?> |
|
87 | - <?php do_action( 'wpinv_meta_box_before_invoice_template_row', $invoice->get_id() ); ?> |
|
86 | + <?php if (!$invoice->is_paid() && !$invoice->is_refunded()) : ?> |
|
87 | + <?php do_action('wpinv_meta_box_before_invoice_template_row', $invoice->get_id()); ?> |
|
88 | 88 | |
89 | 89 | <div class="row"> |
90 | 90 | <div class="col-12 col-sm-6"> |
@@ -93,15 +93,15 @@ discard block |
||
93 | 93 | array( |
94 | 94 | 'id' => 'wpinv_template', |
95 | 95 | 'name' => 'wpinv_template', |
96 | - 'label' => __( 'Template', 'invoicing' ), |
|
96 | + 'label' => __('Template', 'invoicing'), |
|
97 | 97 | 'label_type' => 'vertical', |
98 | - 'placeholder' => __( 'Choose a template', 'invoicing' ), |
|
98 | + 'placeholder' => __('Choose a template', 'invoicing'), |
|
99 | 99 | 'class' => 'form-control-sm', |
100 | - 'value' => $invoice->get_template( 'edit' ), |
|
100 | + 'value' => $invoice->get_template('edit'), |
|
101 | 101 | 'options' => array( |
102 | - 'quantity' => __( 'Quantity', 'invoicing' ), |
|
103 | - 'hours' => __( 'Hours', 'invoicing' ), |
|
104 | - 'amount' => __( 'Amount Only', 'invoicing' ), |
|
102 | + 'quantity' => __('Quantity', 'invoicing'), |
|
103 | + 'hours' => __('Hours', 'invoicing'), |
|
104 | + 'amount' => __('Amount Only', 'invoicing'), |
|
105 | 105 | ), |
106 | 106 | 'data-allow-clear' => 'false', |
107 | 107 | 'select2' => true, |
@@ -117,11 +117,11 @@ discard block |
||
117 | 117 | array( |
118 | 118 | 'id' => 'wpinv_currency', |
119 | 119 | 'name' => 'wpinv_currency', |
120 | - 'label' => __( 'Currency', 'invoicing' ), |
|
120 | + 'label' => __('Currency', 'invoicing'), |
|
121 | 121 | 'label_type' => 'vertical', |
122 | - 'placeholder' => __( 'Select Invoice Currency', 'invoicing' ), |
|
122 | + 'placeholder' => __('Select Invoice Currency', 'invoicing'), |
|
123 | 123 | 'class' => 'form-control-sm', |
124 | - 'value' => $invoice->get_currency( 'edit' ), |
|
124 | + 'value' => $invoice->get_currency('edit'), |
|
125 | 125 | 'required' => false, |
126 | 126 | 'data-allow-clear' => 'false', |
127 | 127 | 'select2' => true, |
@@ -133,24 +133,24 @@ discard block |
||
133 | 133 | </div> |
134 | 134 | </div> |
135 | 135 | |
136 | - <?php do_action( 'wpinv_meta_box_invoice_template_row', $invoice->get_id() ); ?> |
|
136 | + <?php do_action('wpinv_meta_box_invoice_template_row', $invoice->get_id()); ?> |
|
137 | 137 | <?php endif; ?> |
138 | 138 | |
139 | 139 | <table cellpadding="0" cellspacing="0" class="getpaid_invoice_items"> |
140 | 140 | <thead> |
141 | 141 | <tr> |
142 | - <th class="getpaid-item" colspan="2"><?php _e( 'Item', 'invoicing' ) ?></th> |
|
142 | + <th class="getpaid-item" colspan="2"><?php _e('Item', 'invoicing') ?></th> |
|
143 | 143 | <th class="getpaid-quantity hide-if-amount text-right"> |
144 | - <span class="getpaid-hide-if-hours"><?php _e( 'Quantity', 'invoicing' ) ?></span> |
|
145 | - <span class="getpaid-hide-if-quantity"><?php _e( 'Hours', 'invoicing' ) ?></span> |
|
144 | + <span class="getpaid-hide-if-hours"><?php _e('Quantity', 'invoicing') ?></span> |
|
145 | + <span class="getpaid-hide-if-quantity"><?php _e('Hours', 'invoicing') ?></span> |
|
146 | 146 | </th> |
147 | 147 | <th class="getpaid-price hide-if-amount text-right"> |
148 | - <span class="getpaid-hide-if-hours"><?php _e( 'Price', 'invoicing' ) ?></span> |
|
149 | - <span class="getpaid-hide-if-quantity"><?php _e( 'Rate', 'invoicing' ) ?></span> |
|
148 | + <span class="getpaid-hide-if-hours"><?php _e('Price', 'invoicing') ?></span> |
|
149 | + <span class="getpaid-hide-if-quantity"><?php _e('Rate', 'invoicing') ?></span> |
|
150 | 150 | </th> |
151 | 151 | <th class="getpaid-item-subtotal text-right"> |
152 | - <span class="getpaid-hide-if-hours getpaid-hide-if-quantity"><?php _e( 'Amount', 'invoicing' ) ?></span> |
|
153 | - <span class="hide-if-amount"><?php _e( 'Total', 'invoicing' ) ?></span> |
|
152 | + <span class="getpaid-hide-if-hours getpaid-hide-if-quantity"><?php _e('Amount', 'invoicing') ?></span> |
|
153 | + <span class="hide-if-amount"><?php _e('Total', 'invoicing') ?></span> |
|
154 | 154 | </th> |
155 | 155 | <th class="getpaid-item-actions hide-if-not-editable" width="70px"> </th> |
156 | 156 | </tr> |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | <tbody class="getpaid_invoice_line_items"> |
159 | 159 | <tr class="hide-if-has-items hide-if-not-editable"> |
160 | 160 | <td colspan="2" class="pt-4 pb-4"> |
161 | - <button type="button" class="button button-primary add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php _e( 'Add Existing Items', 'invoicing' ) ?></button> |
|
162 | - <a href="<?php echo esc_url( $new_item ); ?>" target="_blank" class="button button-secondary"><?php _e( 'Create New Item', 'invoicing' ) ?></a> |
|
161 | + <button type="button" class="button button-primary add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php _e('Add Existing Items', 'invoicing') ?></button> |
|
162 | + <a href="<?php echo esc_url($new_item); ?>" target="_blank" class="button button-secondary"><?php _e('Create New Item', 'invoicing') ?></a> |
|
163 | 163 | </td> |
164 | 164 | <td class="hide-if-amount"> </th> |
165 | 165 | <td class="hide-if-amount"> </th> |
@@ -191,11 +191,11 @@ discard block |
||
191 | 191 | <div class="col-12 col-sm-6 offset-sm-6"> |
192 | 192 | <table class="getpaid-invoice-totals text-right w-100"> |
193 | 193 | <tbody> |
194 | - <?php foreach ( apply_filters( 'getpaid_invoice_subtotal_rows', $totals, $invoice ) as $key => $data ) : ?> |
|
195 | - <tr class="getpaid-totals-<?php echo sanitize_html_class( $key ); ?>"> |
|
196 | - <td class="label"><?php echo sanitize_text_field( $data['label'] ) ?>:</td> |
|
194 | + <?php foreach (apply_filters('getpaid_invoice_subtotal_rows', $totals, $invoice) as $key => $data) : ?> |
|
195 | + <tr class="getpaid-totals-<?php echo sanitize_html_class($key); ?>"> |
|
196 | + <td class="label"><?php echo sanitize_text_field($data['label']) ?>:</td> |
|
197 | 197 | <td width="1%"></td> |
198 | - <td class="value"><?php echo wp_kses_post( $data['value'] ) ?></td> |
|
198 | + <td class="value"><?php echo wp_kses_post($data['value']) ?></td> |
|
199 | 199 | </tr> |
200 | 200 | <?php endforeach; ?> |
201 | 201 | </tbody> |
@@ -208,18 +208,18 @@ discard block |
||
208 | 208 | <div class="getpaid-invoice-item-actions hide-if-no-items hide-if-not-editable"> |
209 | 209 | <div class="row"> |
210 | 210 | <div class="text-left col-12 col-sm-8"> |
211 | - <button type="button" class="button add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php _e( 'Add Existing Item', 'invoicing' ) ?></button> |
|
212 | - <a href="<?php echo esc_url( $new_item ); ?>" target="_blank" class="button button-secondary"><?php _e( 'Create New Item', 'invoicing' ) ?></a> |
|
213 | - <?php do_action( 'getpaid-invoice-items-actions', $invoice ); ?> |
|
211 | + <button type="button" class="button add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php _e('Add Existing Item', 'invoicing') ?></button> |
|
212 | + <a href="<?php echo esc_url($new_item); ?>" target="_blank" class="button button-secondary"><?php _e('Create New Item', 'invoicing') ?></a> |
|
213 | + <?php do_action('getpaid-invoice-items-actions', $invoice); ?> |
|
214 | 214 | </div> |
215 | 215 | <div class="text-right col-12 col-sm-4"> |
216 | - <button type="button" class="button button-primary recalculate-totals-button"><?php _e( 'Recalculate Totals', 'invoicing' ) ?></button> |
|
216 | + <button type="button" class="button button-primary recalculate-totals-button"><?php _e('Recalculate Totals', 'invoicing') ?></button> |
|
217 | 217 | </div> |
218 | 218 | </div> |
219 | 219 | </div> |
220 | 220 | |
221 | 221 | <div class="getpaid-invoice-item-actions hide-if-editable"> |
222 | - <p class="description m-2 text-right text-muted"><?php _e( 'This invoice is no longer editable', 'invoicing' ); ?></p> |
|
222 | + <p class="description m-2 text-right text-muted"><?php _e('This invoice is no longer editable', 'invoicing'); ?></p> |
|
223 | 223 | </div> |
224 | 224 | |
225 | 225 | <!-- Add items to an invoice --> |
@@ -227,8 +227,8 @@ discard block |
||
227 | 227 | <div class="modal-dialog modal-dialog-centered" role="document"> |
228 | 228 | <div class="modal-content"> |
229 | 229 | <div class="modal-header"> |
230 | - <h5 class="modal-title" id="getpaid-add-item-to-invoice-label"><?php _e( "Add Item(s)", 'invoicing' ); ?></h5> |
|
231 | - <button type="button" class="close" data-dismiss="modal" aria-label="<?php _e( "Close", 'invoicing' ); ?>"> |
|
230 | + <h5 class="modal-title" id="getpaid-add-item-to-invoice-label"><?php _e("Add Item(s)", 'invoicing'); ?></h5> |
|
231 | + <button type="button" class="close" data-dismiss="modal" aria-label="<?php _e("Close", 'invoicing'); ?>"> |
|
232 | 232 | <span aria-hidden="true">×</span> |
233 | 233 | </button> |
234 | 234 | </div> |
@@ -236,17 +236,17 @@ discard block |
||
236 | 236 | <table class="widefat"> |
237 | 237 | <thead> |
238 | 238 | <tr> |
239 | - <th class="pl-0 text-left"><?php _e( 'Item', 'invoicing' ) ?></th> |
|
239 | + <th class="pl-0 text-left"><?php _e('Item', 'invoicing') ?></th> |
|
240 | 240 | <th class="pr-0 text-right hide-if-amount"> |
241 | - <span class="getpaid-hide-if-hours"><?php _e( 'Quantity', 'invoicing' ) ?></span> |
|
242 | - <span class="getpaid-hide-if-quantity"><?php _e( 'Hours', 'invoicing' ) ?></span> |
|
241 | + <span class="getpaid-hide-if-hours"><?php _e('Quantity', 'invoicing') ?></span> |
|
242 | + <span class="getpaid-hide-if-quantity"><?php _e('Hours', 'invoicing') ?></span> |
|
243 | 243 | </th> |
244 | 244 | </tr> |
245 | 245 | </thead> |
246 | 246 | <tbody> |
247 | 247 | <tr> |
248 | 248 | <td class="pl-0 text-left"> |
249 | - <select class="getpaid-item-search regular-text" data-placeholder="<?php esc_attr_e( 'Search for an item…', 'invoicing' ); ?>"></select> |
|
249 | + <select class="getpaid-item-search regular-text" data-placeholder="<?php esc_attr_e('Search for an item…', 'invoicing'); ?>"></select> |
|
250 | 250 | </td> |
251 | 251 | <td class="pr-0 text-right hide-if-amount"> |
252 | 252 | <input type="number" class="w100" step="1" min="1" autocomplete="off" value="1" placeholder="1"> |
@@ -256,8 +256,8 @@ discard block |
||
256 | 256 | </table> |
257 | 257 | </div> |
258 | 258 | <div class="modal-footer"> |
259 | - <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php _e( 'Cancel', 'invoicing' ); ?></button> |
|
260 | - <button type="button" class="btn btn-primary getpaid-add" data-dismiss="modal"><?php _e( 'Add', 'invoicing' ); ?></button> |
|
259 | + <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php _e('Cancel', 'invoicing'); ?></button> |
|
260 | + <button type="button" class="btn btn-primary getpaid-add" data-dismiss="modal"><?php _e('Add', 'invoicing'); ?></button> |
|
261 | 261 | </div> |
262 | 262 | </div> |
263 | 263 | </div> |
@@ -268,8 +268,8 @@ discard block |
||
268 | 268 | <div class="modal-dialog modal-dialog-centered" role="document"> |
269 | 269 | <div class="modal-content"> |
270 | 270 | <div class="modal-header"> |
271 | - <h5 class="modal-title" id="getpaid-edit-invoice-item-label"><?php _e( "Edit Item", 'invoicing' ); ?></h5> |
|
272 | - <button type="button" class="close" data-dismiss="modal" aria-label="<?php _e( "Close", 'invoicing' ); ?>"> |
|
271 | + <h5 class="modal-title" id="getpaid-edit-invoice-item-label"><?php _e("Edit Item", 'invoicing'); ?></h5> |
|
272 | + <button type="button" class="close" data-dismiss="modal" aria-label="<?php _e("Close", 'invoicing'); ?>"> |
|
273 | 273 | <span aria-hidden="true">×</span> |
274 | 274 | </button> |
275 | 275 | </div> |
@@ -277,27 +277,27 @@ discard block |
||
277 | 277 | <div class="getpaid-edit-item-div"> |
278 | 278 | <input type="hidden" name="id" class="form-control form-control-sm item-id"> |
279 | 279 | <label class="form-group w-100"> |
280 | - <span><?php _e( 'Name', 'invoicing' ); ?></span> |
|
281 | - <input type="text" name="name" placeholder="<?php esc_attr_e( 'Item Name', 'invoicing' ); ?>" class="form-control form-control-sm item-name"> |
|
280 | + <span><?php _e('Name', 'invoicing'); ?></span> |
|
281 | + <input type="text" name="name" placeholder="<?php esc_attr_e('Item Name', 'invoicing'); ?>" class="form-control form-control-sm item-name"> |
|
282 | 282 | </label> |
283 | 283 | <label class="form-group w-100"> |
284 | - <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"><?php _e( 'Amount', 'invoicing' ); ?></span> |
|
285 | - <span class="hide-if-amount"><?php _e( 'Price', 'invoicing' ); ?></span> |
|
286 | - <input type="text" name="price" placeholder="<?php wpinv_sanitize_amount( 0 ); ?>" class="form-control form-control-sm item-price"> |
|
284 | + <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"><?php _e('Amount', 'invoicing'); ?></span> |
|
285 | + <span class="hide-if-amount"><?php _e('Price', 'invoicing'); ?></span> |
|
286 | + <input type="text" name="price" placeholder="<?php wpinv_sanitize_amount(0); ?>" class="form-control form-control-sm item-price"> |
|
287 | 287 | </label> |
288 | 288 | <label class="form-group w-100 hide-if-amount"> |
289 | - <span><?php _e( 'Quantity', 'invoicing' ); ?></span> |
|
289 | + <span><?php _e('Quantity', 'invoicing'); ?></span> |
|
290 | 290 | <input type="text" name="quantity" placeholder="1" class="form-control form-control-sm item-quantity"> |
291 | 291 | </label> |
292 | 292 | <label class="form-group w-100"> |
293 | - <span><?php _e( 'Item Description', 'invoicing' ); ?></span> |
|
294 | - <textarea name="description" placeholder="<?php esc_attr_e( 'Enter a description for this item', 'invoicing' ); ?>" class="form-control item-description"></textarea> |
|
293 | + <span><?php _e('Item Description', 'invoicing'); ?></span> |
|
294 | + <textarea name="description" placeholder="<?php esc_attr_e('Enter a description for this item', 'invoicing'); ?>" class="form-control item-description"></textarea> |
|
295 | 295 | </label> |
296 | 296 | </div> |
297 | 297 | </div> |
298 | 298 | <div class="modal-footer"> |
299 | - <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php _e( 'Cancel', 'invoicing' ); ?></button> |
|
300 | - <button type="button" class="btn btn-primary getpaid-save" data-dismiss="modal"><?php _e( 'Save', 'invoicing' ); ?></button> |
|
299 | + <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php _e('Cancel', 'invoicing'); ?></button> |
|
300 | + <button type="button" class="btn btn-primary getpaid-save" data-dismiss="modal"><?php _e('Save', 'invoicing'); ?></button> |
|
301 | 301 | </div> |
302 | 302 | </div> |
303 | 303 | </div> |
@@ -14,545 +14,545 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class WPInv_Plugin { |
16 | 16 | |
17 | - /** |
|
18 | - * GetPaid version. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $version; |
|
23 | - |
|
24 | - /** |
|
25 | - * Data container. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $data = array(); |
|
30 | - |
|
31 | - /** |
|
32 | - * Form elements instance. |
|
33 | - * |
|
34 | - * @var WPInv_Payment_Form_Elements |
|
35 | - */ |
|
36 | - public $form_elements; |
|
37 | - |
|
38 | - /** |
|
39 | - * @param array An array of payment gateways. |
|
40 | - */ |
|
41 | - public $gateways; |
|
42 | - |
|
43 | - /** |
|
44 | - * Class constructor. |
|
45 | - */ |
|
46 | - public function __construct() { |
|
47 | - $this->define_constants(); |
|
48 | - $this->includes(); |
|
49 | - $this->init_hooks(); |
|
50 | - $this->set_properties(); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * Sets a custom data property. |
|
55 | - * |
|
56 | - * @param string $prop The prop to set. |
|
57 | - * @param mixed $value The value to retrieve. |
|
58 | - */ |
|
59 | - public function set( $prop, $value ) { |
|
60 | - $this->data[ $prop ] = $value; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Gets a custom data property. |
|
65 | - * |
|
66 | - * @param string $prop The prop to set. |
|
67 | - * @return mixed The value. |
|
68 | - */ |
|
69 | - public function get( $prop ) { |
|
70 | - |
|
71 | - if ( isset( $this->data[ $prop ] ) ) { |
|
72 | - return $this->data[ $prop ]; |
|
73 | - } |
|
74 | - |
|
75 | - return null; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Define class properties. |
|
80 | - */ |
|
81 | - public function set_properties() { |
|
82 | - |
|
83 | - // Sessions. |
|
84 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
86 | - $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
87 | - |
|
88 | - // Init other objects. |
|
89 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
90 | - $this->set( 'notes', new WPInv_Notes() ); |
|
91 | - $this->set( 'api', new WPInv_API() ); |
|
92 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | - $this->set( 'template', new GetPaid_Template() ); |
|
94 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Define plugin constants. |
|
106 | - */ |
|
107 | - public function define_constants() { |
|
108 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
110 | - $this->version = WPINV_VERSION; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Hook into actions and filters. |
|
115 | - * |
|
116 | - * @since 1.0.19 |
|
117 | - */ |
|
118 | - protected function init_hooks() { |
|
119 | - /* Internationalize the text strings used. */ |
|
120 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
121 | - |
|
122 | - // Init the plugin after WordPress inits. |
|
123 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
127 | - |
|
128 | - if ( class_exists( 'BuddyPress' ) ) { |
|
129 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
130 | - } |
|
131 | - |
|
132 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
133 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
134 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
135 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
136 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
137 | - |
|
138 | - // Fires after registering actions. |
|
139 | - do_action( 'wpinv_actions', $this ); |
|
140 | - do_action( 'getpaid_actions', $this ); |
|
141 | - |
|
142 | - } |
|
143 | - |
|
144 | - public function plugins_loaded() { |
|
145 | - /* Internationalize the text strings used. */ |
|
146 | - $this->load_textdomain(); |
|
147 | - |
|
148 | - do_action( 'wpinv_loaded' ); |
|
149 | - |
|
150 | - // Fix oxygen page builder conflict |
|
151 | - if ( function_exists( 'ct_css_output' ) ) { |
|
152 | - wpinv_oxygen_fix_conflict(); |
|
153 | - } |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Load the translation of the plugin. |
|
158 | - * |
|
159 | - * @since 1.0 |
|
160 | - */ |
|
161 | - public function load_textdomain( $locale = NULL ) { |
|
162 | - if ( empty( $locale ) ) { |
|
163 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
164 | - } |
|
165 | - |
|
166 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
167 | - |
|
168 | - unload_textdomain( 'invoicing' ); |
|
169 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
170 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
171 | - |
|
172 | - /** |
|
173 | - * Define language constants. |
|
174 | - */ |
|
175 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Include required core files used in admin and on the frontend. |
|
180 | - */ |
|
181 | - public function includes() { |
|
182 | - |
|
183 | - // Start with the settings. |
|
184 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
185 | - |
|
186 | - // Packages/libraries. |
|
187 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
188 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
189 | - |
|
190 | - // Load functions. |
|
191 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
192 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
193 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
194 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
195 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
196 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
198 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
199 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
200 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' ); |
|
205 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
206 | - |
|
207 | - // Register autoloader. |
|
208 | - try { |
|
209 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
210 | - } catch ( Exception $e ) { |
|
211 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
212 | - } |
|
213 | - |
|
214 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
215 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
216 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
217 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
218 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
219 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
220 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
221 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
222 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
223 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
224 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
234 | - |
|
235 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
236 | - GetPaid_Post_Types_Admin::init(); |
|
237 | - |
|
238 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
239 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
240 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
241 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
242 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
243 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
244 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
245 | - // load the user class only on the users.php page |
|
246 | - global $pagenow; |
|
247 | - if($pagenow=='users.php'){ |
|
248 | - new WPInv_Admin_Users(); |
|
249 | - } |
|
250 | - } |
|
251 | - |
|
252 | - // Register cli commands |
|
253 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
254 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
255 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
256 | - } |
|
257 | - |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Class autoloader |
|
262 | - * |
|
263 | - * @param string $class_name The name of the class to load. |
|
264 | - * @access public |
|
265 | - * @since 1.0.19 |
|
266 | - * @return void |
|
267 | - */ |
|
268 | - public function autoload( $class_name ) { |
|
269 | - |
|
270 | - // Normalize the class name... |
|
271 | - $class_name = strtolower( $class_name ); |
|
272 | - |
|
273 | - // ... and make sure it is our class. |
|
274 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
275 | - return; |
|
276 | - } |
|
277 | - |
|
278 | - // Next, prepare the file name from the class. |
|
279 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
280 | - |
|
281 | - // Base path of the classes. |
|
282 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
283 | - |
|
284 | - // And an array of possible locations in order of importance. |
|
285 | - $locations = array( |
|
286 | - "$plugin_path/includes", |
|
287 | - "$plugin_path/includes/data-stores", |
|
288 | - "$plugin_path/includes/gateways", |
|
289 | - "$plugin_path/includes/payments", |
|
290 | - "$plugin_path/includes/geolocation", |
|
291 | - "$plugin_path/includes/reports", |
|
292 | - "$plugin_path/includes/api", |
|
293 | - "$plugin_path/includes/admin", |
|
294 | - "$plugin_path/includes/admin/meta-boxes", |
|
295 | - ); |
|
296 | - |
|
297 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
298 | - |
|
299 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
300 | - include trailingslashit( $location ) . $file_name; |
|
301 | - break; |
|
302 | - } |
|
303 | - |
|
304 | - } |
|
305 | - |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Inits hooks etc. |
|
310 | - */ |
|
311 | - public function init() { |
|
312 | - |
|
313 | - // Fires before getpaid inits. |
|
314 | - do_action( 'before_getpaid_init', $this ); |
|
315 | - |
|
316 | - // Maybe upgrade. |
|
317 | - $this->maybe_upgrade_database(); |
|
318 | - |
|
319 | - // Load default gateways. |
|
320 | - $gateways = apply_filters( |
|
321 | - 'getpaid_default_gateways', |
|
322 | - array( |
|
323 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
324 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
325 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
326 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
327 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
328 | - ) |
|
329 | - ); |
|
330 | - |
|
331 | - foreach ( $gateways as $id => $class ) { |
|
332 | - $this->gateways[ $id ] = new $class(); |
|
333 | - } |
|
334 | - |
|
335 | - // Fires after getpaid inits. |
|
336 | - do_action( 'getpaid_init', $this ); |
|
337 | - |
|
338 | - } |
|
339 | - |
|
340 | - /** |
|
341 | - * Checks if this is an IPN request and processes it. |
|
342 | - */ |
|
343 | - public function maybe_process_ipn() { |
|
344 | - |
|
345 | - // Ensure that this is an IPN request. |
|
346 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
347 | - return; |
|
348 | - } |
|
349 | - |
|
350 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
351 | - |
|
352 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
353 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
354 | - exit; |
|
355 | - |
|
356 | - } |
|
357 | - |
|
358 | - public function enqueue_scripts() { |
|
359 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
360 | - |
|
361 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
362 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
363 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
364 | - |
|
365 | - // Register scripts |
|
366 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
367 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ), true ); |
|
17 | + /** |
|
18 | + * GetPaid version. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $version; |
|
23 | + |
|
24 | + /** |
|
25 | + * Data container. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $data = array(); |
|
30 | + |
|
31 | + /** |
|
32 | + * Form elements instance. |
|
33 | + * |
|
34 | + * @var WPInv_Payment_Form_Elements |
|
35 | + */ |
|
36 | + public $form_elements; |
|
37 | + |
|
38 | + /** |
|
39 | + * @param array An array of payment gateways. |
|
40 | + */ |
|
41 | + public $gateways; |
|
42 | + |
|
43 | + /** |
|
44 | + * Class constructor. |
|
45 | + */ |
|
46 | + public function __construct() { |
|
47 | + $this->define_constants(); |
|
48 | + $this->includes(); |
|
49 | + $this->init_hooks(); |
|
50 | + $this->set_properties(); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * Sets a custom data property. |
|
55 | + * |
|
56 | + * @param string $prop The prop to set. |
|
57 | + * @param mixed $value The value to retrieve. |
|
58 | + */ |
|
59 | + public function set( $prop, $value ) { |
|
60 | + $this->data[ $prop ] = $value; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Gets a custom data property. |
|
65 | + * |
|
66 | + * @param string $prop The prop to set. |
|
67 | + * @return mixed The value. |
|
68 | + */ |
|
69 | + public function get( $prop ) { |
|
70 | + |
|
71 | + if ( isset( $this->data[ $prop ] ) ) { |
|
72 | + return $this->data[ $prop ]; |
|
73 | + } |
|
74 | + |
|
75 | + return null; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Define class properties. |
|
80 | + */ |
|
81 | + public function set_properties() { |
|
82 | + |
|
83 | + // Sessions. |
|
84 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
86 | + $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
|
87 | + |
|
88 | + // Init other objects. |
|
89 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
90 | + $this->set( 'notes', new WPInv_Notes() ); |
|
91 | + $this->set( 'api', new WPInv_API() ); |
|
92 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | + $this->set( 'template', new GetPaid_Template() ); |
|
94 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | + $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Define plugin constants. |
|
106 | + */ |
|
107 | + public function define_constants() { |
|
108 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
110 | + $this->version = WPINV_VERSION; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Hook into actions and filters. |
|
115 | + * |
|
116 | + * @since 1.0.19 |
|
117 | + */ |
|
118 | + protected function init_hooks() { |
|
119 | + /* Internationalize the text strings used. */ |
|
120 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
121 | + |
|
122 | + // Init the plugin after WordPress inits. |
|
123 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
127 | + |
|
128 | + if ( class_exists( 'BuddyPress' ) ) { |
|
129 | + add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
130 | + } |
|
131 | + |
|
132 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
133 | + add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
134 | + add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
135 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
136 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
137 | + |
|
138 | + // Fires after registering actions. |
|
139 | + do_action( 'wpinv_actions', $this ); |
|
140 | + do_action( 'getpaid_actions', $this ); |
|
141 | + |
|
142 | + } |
|
143 | + |
|
144 | + public function plugins_loaded() { |
|
145 | + /* Internationalize the text strings used. */ |
|
146 | + $this->load_textdomain(); |
|
147 | + |
|
148 | + do_action( 'wpinv_loaded' ); |
|
149 | + |
|
150 | + // Fix oxygen page builder conflict |
|
151 | + if ( function_exists( 'ct_css_output' ) ) { |
|
152 | + wpinv_oxygen_fix_conflict(); |
|
153 | + } |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Load the translation of the plugin. |
|
158 | + * |
|
159 | + * @since 1.0 |
|
160 | + */ |
|
161 | + public function load_textdomain( $locale = NULL ) { |
|
162 | + if ( empty( $locale ) ) { |
|
163 | + $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
164 | + } |
|
165 | + |
|
166 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
167 | + |
|
168 | + unload_textdomain( 'invoicing' ); |
|
169 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
170 | + load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
171 | + |
|
172 | + /** |
|
173 | + * Define language constants. |
|
174 | + */ |
|
175 | + require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Include required core files used in admin and on the frontend. |
|
180 | + */ |
|
181 | + public function includes() { |
|
182 | + |
|
183 | + // Start with the settings. |
|
184 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
185 | + |
|
186 | + // Packages/libraries. |
|
187 | + require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
188 | + require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
189 | + |
|
190 | + // Load functions. |
|
191 | + require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
192 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
193 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
194 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
195 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
196 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
197 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
198 | + require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
199 | + require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
200 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
201 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
202 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
203 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
204 | + require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' ); |
|
205 | + require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
206 | + |
|
207 | + // Register autoloader. |
|
208 | + try { |
|
209 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
210 | + } catch ( Exception $e ) { |
|
211 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
212 | + } |
|
213 | + |
|
214 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
215 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
216 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
217 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
218 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
219 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
220 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
221 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
222 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
223 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
224 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
225 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
226 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
227 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
228 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
229 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
230 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
231 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
232 | + require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
233 | + require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
234 | + |
|
235 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
236 | + GetPaid_Post_Types_Admin::init(); |
|
237 | + |
|
238 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
239 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
240 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
241 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
242 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
243 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
244 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
245 | + // load the user class only on the users.php page |
|
246 | + global $pagenow; |
|
247 | + if($pagenow=='users.php'){ |
|
248 | + new WPInv_Admin_Users(); |
|
249 | + } |
|
250 | + } |
|
251 | + |
|
252 | + // Register cli commands |
|
253 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
254 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
255 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
256 | + } |
|
257 | + |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Class autoloader |
|
262 | + * |
|
263 | + * @param string $class_name The name of the class to load. |
|
264 | + * @access public |
|
265 | + * @since 1.0.19 |
|
266 | + * @return void |
|
267 | + */ |
|
268 | + public function autoload( $class_name ) { |
|
269 | + |
|
270 | + // Normalize the class name... |
|
271 | + $class_name = strtolower( $class_name ); |
|
272 | + |
|
273 | + // ... and make sure it is our class. |
|
274 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
275 | + return; |
|
276 | + } |
|
277 | + |
|
278 | + // Next, prepare the file name from the class. |
|
279 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
368 | 280 | |
369 | - $localize = array(); |
|
370 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
371 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
372 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
373 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
374 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
375 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
376 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
281 | + // Base path of the classes. |
|
282 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
377 | 283 | |
378 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
379 | - |
|
380 | - wp_enqueue_script( 'jquery-blockui' ); |
|
381 | - |
|
382 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
383 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
384 | - |
|
385 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
386 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
387 | - |
|
388 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
389 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script' ), $version, true ); |
|
390 | - } |
|
284 | + // And an array of possible locations in order of importance. |
|
285 | + $locations = array( |
|
286 | + "$plugin_path/includes", |
|
287 | + "$plugin_path/includes/data-stores", |
|
288 | + "$plugin_path/includes/gateways", |
|
289 | + "$plugin_path/includes/payments", |
|
290 | + "$plugin_path/includes/geolocation", |
|
291 | + "$plugin_path/includes/reports", |
|
292 | + "$plugin_path/includes/api", |
|
293 | + "$plugin_path/includes/admin", |
|
294 | + "$plugin_path/includes/admin/meta-boxes", |
|
295 | + ); |
|
391 | 296 | |
392 | - public function wpinv_actions() { |
|
393 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
394 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
395 | - } |
|
396 | - } |
|
297 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
397 | 298 | |
398 | - /** |
|
299 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
300 | + include trailingslashit( $location ) . $file_name; |
|
301 | + break; |
|
302 | + } |
|
303 | + |
|
304 | + } |
|
305 | + |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Inits hooks etc. |
|
310 | + */ |
|
311 | + public function init() { |
|
312 | + |
|
313 | + // Fires before getpaid inits. |
|
314 | + do_action( 'before_getpaid_init', $this ); |
|
315 | + |
|
316 | + // Maybe upgrade. |
|
317 | + $this->maybe_upgrade_database(); |
|
318 | + |
|
319 | + // Load default gateways. |
|
320 | + $gateways = apply_filters( |
|
321 | + 'getpaid_default_gateways', |
|
322 | + array( |
|
323 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
324 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
325 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
326 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
327 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
328 | + ) |
|
329 | + ); |
|
330 | + |
|
331 | + foreach ( $gateways as $id => $class ) { |
|
332 | + $this->gateways[ $id ] = new $class(); |
|
333 | + } |
|
334 | + |
|
335 | + // Fires after getpaid inits. |
|
336 | + do_action( 'getpaid_init', $this ); |
|
337 | + |
|
338 | + } |
|
339 | + |
|
340 | + /** |
|
341 | + * Checks if this is an IPN request and processes it. |
|
342 | + */ |
|
343 | + public function maybe_process_ipn() { |
|
344 | + |
|
345 | + // Ensure that this is an IPN request. |
|
346 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
347 | + return; |
|
348 | + } |
|
349 | + |
|
350 | + $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
351 | + |
|
352 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
353 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
354 | + exit; |
|
355 | + |
|
356 | + } |
|
357 | + |
|
358 | + public function enqueue_scripts() { |
|
359 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
360 | + |
|
361 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
362 | + wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
363 | + wp_enqueue_style( 'wpinv_front_style' ); |
|
364 | + |
|
365 | + // Register scripts |
|
366 | + wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
367 | + wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ), true ); |
|
368 | + |
|
369 | + $localize = array(); |
|
370 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
371 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
372 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
373 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
374 | + $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
375 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
376 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
377 | + |
|
378 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
379 | + |
|
380 | + wp_enqueue_script( 'jquery-blockui' ); |
|
381 | + |
|
382 | + wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
383 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
384 | + |
|
385 | + wp_enqueue_script( 'wpinv-front-script' ); |
|
386 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
387 | + |
|
388 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
389 | + wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script' ), $version, true ); |
|
390 | + } |
|
391 | + |
|
392 | + public function wpinv_actions() { |
|
393 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
394 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
395 | + } |
|
396 | + } |
|
397 | + |
|
398 | + /** |
|
399 | 399 | * Fires an action after verifying that a user can fire them. |
400 | - * |
|
401 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
402 | - * current user owns the invoice/subscription. |
|
400 | + * |
|
401 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
402 | + * current user owns the invoice/subscription. |
|
403 | 403 | */ |
404 | 404 | public function maybe_do_authenticated_action() { |
405 | 405 | |
406 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
406 | + if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
407 | + |
|
408 | + $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
409 | + $data = wp_unslash( $_REQUEST ); |
|
410 | + if ( is_user_logged_in() ) { |
|
411 | + do_action( "getpaid_authenticated_action_$key", $data ); |
|
412 | + } |
|
407 | 413 | |
408 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
409 | - $data = wp_unslash( $_REQUEST ); |
|
410 | - if ( is_user_logged_in() ) { |
|
411 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
412 | - } |
|
414 | + do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
415 | + |
|
416 | + } |
|
417 | + |
|
418 | + } |
|
413 | 419 | |
414 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
420 | + public function pre_get_posts( $wp_query ) { |
|
415 | 421 | |
416 | - } |
|
422 | + if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
423 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
424 | + } |
|
417 | 425 | |
426 | + return $wp_query; |
|
418 | 427 | } |
419 | 428 | |
420 | - public function pre_get_posts( $wp_query ) { |
|
421 | - |
|
422 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
423 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
424 | - } |
|
425 | - |
|
426 | - return $wp_query; |
|
427 | - } |
|
428 | - |
|
429 | - public function bp_invoicing_init() { |
|
430 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
431 | - } |
|
432 | - |
|
433 | - /** |
|
434 | - * Register widgets |
|
435 | - * |
|
436 | - */ |
|
437 | - public function register_widgets() { |
|
438 | - |
|
439 | - // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
440 | - // So we disable our widgets when editing a page with UX Builder. |
|
441 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
442 | - return; |
|
443 | - } |
|
444 | - |
|
445 | - $widgets = apply_filters( |
|
446 | - 'getpaid_widget_classes', |
|
447 | - array( |
|
448 | - 'WPInv_Checkout_Widget', |
|
449 | - 'WPInv_History_Widget', |
|
450 | - 'WPInv_Receipt_Widget', |
|
451 | - 'WPInv_Subscriptions_Widget', |
|
452 | - 'WPInv_Buy_Item_Widget', |
|
453 | - 'WPInv_Messages_Widget', |
|
454 | - 'WPInv_GetPaid_Widget' |
|
455 | - ) |
|
456 | - ); |
|
457 | - |
|
458 | - foreach ( $widgets as $widget ) { |
|
459 | - register_widget( $widget ); |
|
460 | - } |
|
429 | + public function bp_invoicing_init() { |
|
430 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
431 | + } |
|
432 | + |
|
433 | + /** |
|
434 | + * Register widgets |
|
435 | + * |
|
436 | + */ |
|
437 | + public function register_widgets() { |
|
438 | + |
|
439 | + // Currently, UX Builder does not work particulaly well with SuperDuper. |
|
440 | + // So we disable our widgets when editing a page with UX Builder. |
|
441 | + if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
442 | + return; |
|
443 | + } |
|
444 | + |
|
445 | + $widgets = apply_filters( |
|
446 | + 'getpaid_widget_classes', |
|
447 | + array( |
|
448 | + 'WPInv_Checkout_Widget', |
|
449 | + 'WPInv_History_Widget', |
|
450 | + 'WPInv_Receipt_Widget', |
|
451 | + 'WPInv_Subscriptions_Widget', |
|
452 | + 'WPInv_Buy_Item_Widget', |
|
453 | + 'WPInv_Messages_Widget', |
|
454 | + 'WPInv_GetPaid_Widget' |
|
455 | + ) |
|
456 | + ); |
|
457 | + |
|
458 | + foreach ( $widgets as $widget ) { |
|
459 | + register_widget( $widget ); |
|
460 | + } |
|
461 | 461 | |
462 | - } |
|
462 | + } |
|
463 | 463 | |
464 | - /** |
|
465 | - * Upgrades the database. |
|
466 | - * |
|
467 | - * @since 2.0.2 |
|
468 | - */ |
|
469 | - public function maybe_upgrade_database() { |
|
464 | + /** |
|
465 | + * Upgrades the database. |
|
466 | + * |
|
467 | + * @since 2.0.2 |
|
468 | + */ |
|
469 | + public function maybe_upgrade_database() { |
|
470 | 470 | |
471 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
471 | + $wpi_version = get_option( 'wpinv_version', 0 ); |
|
472 | 472 | |
473 | - if ( $wpi_version == WPINV_VERSION ) { |
|
474 | - return; |
|
475 | - } |
|
473 | + if ( $wpi_version == WPINV_VERSION ) { |
|
474 | + return; |
|
475 | + } |
|
476 | 476 | |
477 | - $installer = new GetPaid_Installer(); |
|
477 | + $installer = new GetPaid_Installer(); |
|
478 | 478 | |
479 | - if ( empty( $wpi_version ) ) { |
|
480 | - return $installer->upgrade_db( 0 ); |
|
481 | - } |
|
479 | + if ( empty( $wpi_version ) ) { |
|
480 | + return $installer->upgrade_db( 0 ); |
|
481 | + } |
|
482 | 482 | |
483 | - $upgrades = array( |
|
484 | - '0.0.5' => '004', |
|
485 | - '1.0.3' => '102', |
|
486 | - '2.0.0' => '118', |
|
487 | - '2.0.8' => '207', |
|
488 | - ); |
|
483 | + $upgrades = array( |
|
484 | + '0.0.5' => '004', |
|
485 | + '1.0.3' => '102', |
|
486 | + '2.0.0' => '118', |
|
487 | + '2.0.8' => '207', |
|
488 | + ); |
|
489 | 489 | |
490 | - foreach ( $upgrades as $key => $method ) { |
|
490 | + foreach ( $upgrades as $key => $method ) { |
|
491 | 491 | |
492 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
493 | - return $installer->upgrade_db( $method ); |
|
494 | - } |
|
492 | + if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
493 | + return $installer->upgrade_db( $method ); |
|
494 | + } |
|
495 | 495 | |
496 | - } |
|
496 | + } |
|
497 | 497 | |
498 | - } |
|
498 | + } |
|
499 | 499 | |
500 | - /** |
|
501 | - * Flushes the permalinks if needed. |
|
502 | - * |
|
503 | - * @since 2.0.8 |
|
504 | - */ |
|
505 | - public function maybe_flush_permalinks() { |
|
500 | + /** |
|
501 | + * Flushes the permalinks if needed. |
|
502 | + * |
|
503 | + * @since 2.0.8 |
|
504 | + */ |
|
505 | + public function maybe_flush_permalinks() { |
|
506 | 506 | |
507 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
507 | + $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
508 | 508 | |
509 | - if ( ! empty( $flush ) ) { |
|
510 | - flush_rewrite_rules(); |
|
511 | - delete_option( 'wpinv_flush_permalinks' ); |
|
512 | - } |
|
509 | + if ( ! empty( $flush ) ) { |
|
510 | + flush_rewrite_rules(); |
|
511 | + delete_option( 'wpinv_flush_permalinks' ); |
|
512 | + } |
|
513 | 513 | |
514 | - } |
|
514 | + } |
|
515 | 515 | |
516 | - /** |
|
517 | - * Remove our pages from yoast sitemaps. |
|
518 | - * |
|
519 | - * @since 1.0.19 |
|
520 | - * @param int[] $excluded_posts_ids |
|
521 | - */ |
|
522 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
516 | + /** |
|
517 | + * Remove our pages from yoast sitemaps. |
|
518 | + * |
|
519 | + * @since 1.0.19 |
|
520 | + * @param int[] $excluded_posts_ids |
|
521 | + */ |
|
522 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
523 | 523 | |
524 | - // Ensure that we have an array. |
|
525 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
526 | - $excluded_posts_ids = array(); |
|
527 | - } |
|
524 | + // Ensure that we have an array. |
|
525 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
526 | + $excluded_posts_ids = array(); |
|
527 | + } |
|
528 | 528 | |
529 | - // Prepare our pages. |
|
530 | - $our_pages = array(); |
|
529 | + // Prepare our pages. |
|
530 | + $our_pages = array(); |
|
531 | 531 | |
532 | - // Checkout page. |
|
533 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
532 | + // Checkout page. |
|
533 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
534 | 534 | |
535 | - // Success page. |
|
536 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
535 | + // Success page. |
|
536 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
537 | 537 | |
538 | - // Failure page. |
|
539 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
538 | + // Failure page. |
|
539 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
540 | 540 | |
541 | - // History page. |
|
542 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
541 | + // History page. |
|
542 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
543 | 543 | |
544 | - // Subscriptions page. |
|
545 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
544 | + // Subscriptions page. |
|
545 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
546 | 546 | |
547 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
547 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
548 | 548 | |
549 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
550 | - return array_unique( $excluded_posts_ids ); |
|
549 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
550 | + return array_unique( $excluded_posts_ids ); |
|
551 | 551 | |
552 | - } |
|
552 | + } |
|
553 | 553 | |
554 | - public function wp_footer() { |
|
555 | - echo ' |
|
554 | + public function wp_footer() { |
|
555 | + echo ' |
|
556 | 556 | <div class="bsui"> |
557 | 557 | <div id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog"> |
558 | 558 | <div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;"> |
@@ -568,6 +568,6 @@ discard block |
||
568 | 568 | </div> |
569 | 569 | </div> |
570 | 570 | '; |
571 | - } |
|
571 | + } |
|
572 | 572 | |
573 | 573 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 1.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Main Invoicing class. |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | * @param string $prop The prop to set. |
57 | 57 | * @param mixed $value The value to retrieve. |
58 | 58 | */ |
59 | - public function set( $prop, $value ) { |
|
60 | - $this->data[ $prop ] = $value; |
|
59 | + public function set($prop, $value) { |
|
60 | + $this->data[$prop] = $value; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | * @param string $prop The prop to set. |
67 | 67 | * @return mixed The value. |
68 | 68 | */ |
69 | - public function get( $prop ) { |
|
69 | + public function get($prop) { |
|
70 | 70 | |
71 | - if ( isset( $this->data[ $prop ] ) ) { |
|
72 | - return $this->data[ $prop ]; |
|
71 | + if (isset($this->data[$prop])) { |
|
72 | + return $this->data[$prop]; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | return null; |
@@ -81,23 +81,23 @@ discard block |
||
81 | 81 | public function set_properties() { |
82 | 82 | |
83 | 83 | // Sessions. |
84 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
85 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
84 | + $this->set('session', new WPInv_Session_Handler()); |
|
85 | + $GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility. |
|
86 | 86 | $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility. |
87 | 87 | |
88 | 88 | // Init other objects. |
89 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
90 | - $this->set( 'notes', new WPInv_Notes() ); |
|
91 | - $this->set( 'api', new WPInv_API() ); |
|
92 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
93 | - $this->set( 'template', new GetPaid_Template() ); |
|
94 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
95 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
96 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
97 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
98 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
99 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
100 | - $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() ); |
|
89 | + $this->set('session', new WPInv_Session_Handler()); |
|
90 | + $this->set('notes', new WPInv_Notes()); |
|
91 | + $this->set('api', new WPInv_API()); |
|
92 | + $this->set('post_types', new GetPaid_Post_Types()); |
|
93 | + $this->set('template', new GetPaid_Template()); |
|
94 | + $this->set('admin', new GetPaid_Admin()); |
|
95 | + $this->set('subscriptions', new WPInv_Subscriptions()); |
|
96 | + $this->set('invoice_emails', new GetPaid_Invoice_Notification_Emails()); |
|
97 | + $this->set('subscription_emails', new GetPaid_Subscription_Notification_Emails()); |
|
98 | + $this->set('daily_maintenace', new GetPaid_Daily_Maintenance()); |
|
99 | + $this->set('payment_forms', new GetPaid_Payment_Forms()); |
|
100 | + $this->set('maxmind', new GetPaid_MaxMind_Geolocation()); |
|
101 | 101 | |
102 | 102 | } |
103 | 103 | |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | * Define plugin constants. |
106 | 106 | */ |
107 | 107 | public function define_constants() { |
108 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
109 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
108 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
109 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
110 | 110 | $this->version = WPINV_VERSION; |
111 | 111 | } |
112 | 112 | |
@@ -117,27 +117,27 @@ discard block |
||
117 | 117 | */ |
118 | 118 | protected function init_hooks() { |
119 | 119 | /* Internationalize the text strings used. */ |
120 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
120 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
121 | 121 | |
122 | 122 | // Init the plugin after WordPress inits. |
123 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
124 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
125 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
126 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
123 | + add_action('init', array($this, 'init'), 1); |
|
124 | + add_action('init', array($this, 'maybe_process_ipn'), 10); |
|
125 | + add_action('init', array($this, 'wpinv_actions')); |
|
126 | + add_action('init', array($this, 'maybe_do_authenticated_action'), 100); |
|
127 | 127 | |
128 | - if ( class_exists( 'BuddyPress' ) ) { |
|
129 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
128 | + if (class_exists('BuddyPress')) { |
|
129 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
130 | 130 | } |
131 | 131 | |
132 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 ); |
|
133 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
134 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
135 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
136 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
132 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 11); |
|
133 | + add_action('wp_footer', array(&$this, 'wp_footer')); |
|
134 | + add_action('widgets_init', array(&$this, 'register_widgets')); |
|
135 | + add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids')); |
|
136 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
137 | 137 | |
138 | 138 | // Fires after registering actions. |
139 | - do_action( 'wpinv_actions', $this ); |
|
140 | - do_action( 'getpaid_actions', $this ); |
|
139 | + do_action('wpinv_actions', $this); |
|
140 | + do_action('getpaid_actions', $this); |
|
141 | 141 | |
142 | 142 | } |
143 | 143 | |
@@ -145,10 +145,10 @@ discard block |
||
145 | 145 | /* Internationalize the text strings used. */ |
146 | 146 | $this->load_textdomain(); |
147 | 147 | |
148 | - do_action( 'wpinv_loaded' ); |
|
148 | + do_action('wpinv_loaded'); |
|
149 | 149 | |
150 | 150 | // Fix oxygen page builder conflict |
151 | - if ( function_exists( 'ct_css_output' ) ) { |
|
151 | + if (function_exists('ct_css_output')) { |
|
152 | 152 | wpinv_oxygen_fix_conflict(); |
153 | 153 | } |
154 | 154 | } |
@@ -158,21 +158,21 @@ discard block |
||
158 | 158 | * |
159 | 159 | * @since 1.0 |
160 | 160 | */ |
161 | - public function load_textdomain( $locale = NULL ) { |
|
162 | - if ( empty( $locale ) ) { |
|
163 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
161 | + public function load_textdomain($locale = NULL) { |
|
162 | + if (empty($locale)) { |
|
163 | + $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
|
164 | 164 | } |
165 | 165 | |
166 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
166 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
167 | 167 | |
168 | - unload_textdomain( 'invoicing' ); |
|
169 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
170 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
168 | + unload_textdomain('invoicing'); |
|
169 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
170 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
171 | 171 | |
172 | 172 | /** |
173 | 173 | * Define language constants. |
174 | 174 | */ |
175 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
175 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -181,78 +181,78 @@ discard block |
||
181 | 181 | public function includes() { |
182 | 182 | |
183 | 183 | // Start with the settings. |
184 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
184 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
185 | 185 | |
186 | 186 | // Packages/libraries. |
187 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
188 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
187 | + require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php'); |
|
188 | + require_once(WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'); |
|
189 | 189 | |
190 | 190 | // Load functions. |
191 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
192 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
193 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
194 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
195 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
196 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
198 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
199 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
200 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' ); |
|
205 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
191 | + require_once(WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'); |
|
192 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
193 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
194 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
195 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
196 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
197 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
198 | + require_once(WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'); |
|
199 | + require_once(WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'); |
|
200 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
201 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
202 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
203 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
204 | + require_once(WPINV_PLUGIN_DIR . 'includes/user-functions.php'); |
|
205 | + require_once(WPINV_PLUGIN_DIR . 'includes/error-functions.php'); |
|
206 | 206 | |
207 | 207 | // Register autoloader. |
208 | 208 | try { |
209 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
210 | - } catch ( Exception $e ) { |
|
211 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
209 | + spl_autoload_register(array($this, 'autoload'), true); |
|
210 | + } catch (Exception $e) { |
|
211 | + wpinv_error_log($e->getMessage(), '', __FILE__, 149, true); |
|
212 | 212 | } |
213 | 213 | |
214 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
215 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
216 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
217 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
218 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
219 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
220 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
221 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
222 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
223 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
224 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
234 | - |
|
235 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
214 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'); |
|
215 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'); |
|
216 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
217 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
218 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'); |
|
219 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'); |
|
220 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'); |
|
221 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'); |
|
222 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'); |
|
223 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'); |
|
224 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'); |
|
225 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'); |
|
226 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'); |
|
227 | + require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php'); |
|
228 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'); |
|
229 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'); |
|
230 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'); |
|
231 | + require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'); |
|
232 | + require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php'); |
|
233 | + require_once(WPINV_PLUGIN_DIR . 'widgets/getpaid.php'); |
|
234 | + |
|
235 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
236 | 236 | GetPaid_Post_Types_Admin::init(); |
237 | 237 | |
238 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
239 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
240 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
241 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
242 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
243 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
244 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
238 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
239 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'); |
|
240 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
241 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
242 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'); |
|
243 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'); |
|
244 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'); |
|
245 | 245 | // load the user class only on the users.php page |
246 | 246 | global $pagenow; |
247 | - if($pagenow=='users.php'){ |
|
247 | + if ($pagenow == 'users.php') { |
|
248 | 248 | new WPInv_Admin_Users(); |
249 | 249 | } |
250 | 250 | } |
251 | 251 | |
252 | 252 | // Register cli commands |
253 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
254 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
255 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
253 | + if (defined('WP_CLI') && WP_CLI) { |
|
254 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'); |
|
255 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | } |
@@ -265,21 +265,21 @@ discard block |
||
265 | 265 | * @since 1.0.19 |
266 | 266 | * @return void |
267 | 267 | */ |
268 | - public function autoload( $class_name ) { |
|
268 | + public function autoload($class_name) { |
|
269 | 269 | |
270 | 270 | // Normalize the class name... |
271 | - $class_name = strtolower( $class_name ); |
|
271 | + $class_name = strtolower($class_name); |
|
272 | 272 | |
273 | 273 | // ... and make sure it is our class. |
274 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
274 | + if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) { |
|
275 | 275 | return; |
276 | 276 | } |
277 | 277 | |
278 | 278 | // Next, prepare the file name from the class. |
279 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
279 | + $file_name = 'class-' . str_replace('_', '-', $class_name) . '.php'; |
|
280 | 280 | |
281 | 281 | // Base path of the classes. |
282 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
282 | + $plugin_path = untrailingslashit(WPINV_PLUGIN_DIR); |
|
283 | 283 | |
284 | 284 | // And an array of possible locations in order of importance. |
285 | 285 | $locations = array( |
@@ -294,10 +294,10 @@ discard block |
||
294 | 294 | "$plugin_path/includes/admin/meta-boxes", |
295 | 295 | ); |
296 | 296 | |
297 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
297 | + foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) { |
|
298 | 298 | |
299 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
300 | - include trailingslashit( $location ) . $file_name; |
|
299 | + if (file_exists(trailingslashit($location) . $file_name)) { |
|
300 | + include trailingslashit($location) . $file_name; |
|
301 | 301 | break; |
302 | 302 | } |
303 | 303 | |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | public function init() { |
312 | 312 | |
313 | 313 | // Fires before getpaid inits. |
314 | - do_action( 'before_getpaid_init', $this ); |
|
314 | + do_action('before_getpaid_init', $this); |
|
315 | 315 | |
316 | 316 | // Maybe upgrade. |
317 | 317 | $this->maybe_upgrade_database(); |
@@ -328,12 +328,12 @@ discard block |
||
328 | 328 | ) |
329 | 329 | ); |
330 | 330 | |
331 | - foreach ( $gateways as $id => $class ) { |
|
332 | - $this->gateways[ $id ] = new $class(); |
|
331 | + foreach ($gateways as $id => $class) { |
|
332 | + $this->gateways[$id] = new $class(); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | // Fires after getpaid inits. |
336 | - do_action( 'getpaid_init', $this ); |
|
336 | + do_action('getpaid_init', $this); |
|
337 | 337 | |
338 | 338 | } |
339 | 339 | |
@@ -343,55 +343,55 @@ discard block |
||
343 | 343 | public function maybe_process_ipn() { |
344 | 344 | |
345 | 345 | // Ensure that this is an IPN request. |
346 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
346 | + if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) { |
|
347 | 347 | return; |
348 | 348 | } |
349 | 349 | |
350 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
350 | + $gateway = wpinv_clean($_GET['wpi-gateway']); |
|
351 | 351 | |
352 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
353 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
352 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
353 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
354 | 354 | exit; |
355 | 355 | |
356 | 356 | } |
357 | 357 | |
358 | 358 | public function enqueue_scripts() { |
359 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
359 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
360 | 360 | |
361 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
362 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
363 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
361 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css'); |
|
362 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version); |
|
363 | + wp_enqueue_style('wpinv_front_style'); |
|
364 | 364 | |
365 | 365 | // Register scripts |
366 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
367 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ), true ); |
|
366 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
367 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), filemtime(WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js'), true); |
|
368 | 368 | |
369 | 369 | $localize = array(); |
370 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
371 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
372 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
370 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
371 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
372 | + $localize['txtComplete'] = __('Continue', 'invoicing'); |
|
373 | 373 | $localize['UseTaxes'] = wpinv_use_taxes(); |
374 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
375 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
376 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
374 | + $localize['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce'); |
|
375 | + $localize['formNonce'] = wp_create_nonce('getpaid_form_nonce'); |
|
376 | + $localize['connectionError'] = __('Could not establish a connection to the server.', 'invoicing'); |
|
377 | 377 | |
378 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
378 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
379 | 379 | |
380 | - wp_enqueue_script( 'jquery-blockui' ); |
|
380 | + wp_enqueue_script('jquery-blockui'); |
|
381 | 381 | |
382 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
383 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
382 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all'); |
|
383 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
384 | 384 | |
385 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
386 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
385 | + wp_enqueue_script('wpinv-front-script'); |
|
386 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
387 | 387 | |
388 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
389 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script' ), $version, true ); |
|
388 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js'); |
|
389 | + wp_enqueue_script('wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('wpinv-front-script'), $version, true); |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | public function wpinv_actions() { |
393 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
394 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
393 | + if (isset($_REQUEST['wpi_action'])) { |
|
394 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
395 | 395 | } |
396 | 396 | } |
397 | 397 | |
@@ -403,31 +403,31 @@ discard block |
||
403 | 403 | */ |
404 | 404 | public function maybe_do_authenticated_action() { |
405 | 405 | |
406 | - if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
406 | + if (isset($_REQUEST['getpaid-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
407 | 407 | |
408 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
409 | - $data = wp_unslash( $_REQUEST ); |
|
410 | - if ( is_user_logged_in() ) { |
|
411 | - do_action( "getpaid_authenticated_action_$key", $data ); |
|
408 | + $key = sanitize_key($_REQUEST['getpaid-action']); |
|
409 | + $data = wp_unslash($_REQUEST); |
|
410 | + if (is_user_logged_in()) { |
|
411 | + do_action("getpaid_authenticated_action_$key", $data); |
|
412 | 412 | } |
413 | 413 | |
414 | - do_action( "getpaid_unauthenticated_action_$key", $data ); |
|
414 | + do_action("getpaid_unauthenticated_action_$key", $data); |
|
415 | 415 | |
416 | 416 | } |
417 | 417 | |
418 | 418 | } |
419 | 419 | |
420 | - public function pre_get_posts( $wp_query ) { |
|
420 | + public function pre_get_posts($wp_query) { |
|
421 | 421 | |
422 | - if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
423 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) ); |
|
422 | + if (!is_admin() && !empty($wp_query->query_vars['post_type']) && getpaid_is_invoice_post_type($wp_query->query_vars['post_type']) && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
423 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses(false, false, $wp_query->query_vars['post_type'])); |
|
424 | 424 | } |
425 | 425 | |
426 | 426 | return $wp_query; |
427 | 427 | } |
428 | 428 | |
429 | 429 | public function bp_invoicing_init() { |
430 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
430 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
431 | 431 | } |
432 | 432 | |
433 | 433 | /** |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | |
439 | 439 | // Currently, UX Builder does not work particulaly well with SuperDuper. |
440 | 440 | // So we disable our widgets when editing a page with UX Builder. |
441 | - if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) { |
|
441 | + if (function_exists('ux_builder_is_active') && ux_builder_is_active()) { |
|
442 | 442 | return; |
443 | 443 | } |
444 | 444 | |
@@ -455,8 +455,8 @@ discard block |
||
455 | 455 | ) |
456 | 456 | ); |
457 | 457 | |
458 | - foreach ( $widgets as $widget ) { |
|
459 | - register_widget( $widget ); |
|
458 | + foreach ($widgets as $widget) { |
|
459 | + register_widget($widget); |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | } |
@@ -468,29 +468,29 @@ discard block |
||
468 | 468 | */ |
469 | 469 | public function maybe_upgrade_database() { |
470 | 470 | |
471 | - $wpi_version = get_option( 'wpinv_version', 0 ); |
|
471 | + $wpi_version = get_option('wpinv_version', 0); |
|
472 | 472 | |
473 | - if ( $wpi_version == WPINV_VERSION ) { |
|
473 | + if ($wpi_version == WPINV_VERSION) { |
|
474 | 474 | return; |
475 | 475 | } |
476 | 476 | |
477 | 477 | $installer = new GetPaid_Installer(); |
478 | 478 | |
479 | - if ( empty( $wpi_version ) ) { |
|
480 | - return $installer->upgrade_db( 0 ); |
|
479 | + if (empty($wpi_version)) { |
|
480 | + return $installer->upgrade_db(0); |
|
481 | 481 | } |
482 | 482 | |
483 | - $upgrades = array( |
|
483 | + $upgrades = array( |
|
484 | 484 | '0.0.5' => '004', |
485 | 485 | '1.0.3' => '102', |
486 | 486 | '2.0.0' => '118', |
487 | 487 | '2.0.8' => '207', |
488 | 488 | ); |
489 | 489 | |
490 | - foreach ( $upgrades as $key => $method ) { |
|
490 | + foreach ($upgrades as $key => $method) { |
|
491 | 491 | |
492 | - if ( version_compare( $wpi_version, $key, '<' ) ) { |
|
493 | - return $installer->upgrade_db( $method ); |
|
492 | + if (version_compare($wpi_version, $key, '<')) { |
|
493 | + return $installer->upgrade_db($method); |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | } |
@@ -504,11 +504,11 @@ discard block |
||
504 | 504 | */ |
505 | 505 | public function maybe_flush_permalinks() { |
506 | 506 | |
507 | - $flush = get_option( 'wpinv_flush_permalinks', 0 ); |
|
507 | + $flush = get_option('wpinv_flush_permalinks', 0); |
|
508 | 508 | |
509 | - if ( ! empty( $flush ) ) { |
|
509 | + if (!empty($flush)) { |
|
510 | 510 | flush_rewrite_rules(); |
511 | - delete_option( 'wpinv_flush_permalinks' ); |
|
511 | + delete_option('wpinv_flush_permalinks'); |
|
512 | 512 | } |
513 | 513 | |
514 | 514 | } |
@@ -519,10 +519,10 @@ discard block |
||
519 | 519 | * @since 1.0.19 |
520 | 520 | * @param int[] $excluded_posts_ids |
521 | 521 | */ |
522 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
522 | + public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) { |
|
523 | 523 | |
524 | 524 | // Ensure that we have an array. |
525 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
525 | + if (!is_array($excluded_posts_ids)) { |
|
526 | 526 | $excluded_posts_ids = array(); |
527 | 527 | } |
528 | 528 | |
@@ -530,24 +530,24 @@ discard block |
||
530 | 530 | $our_pages = array(); |
531 | 531 | |
532 | 532 | // Checkout page. |
533 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
533 | + $our_pages[] = wpinv_get_option('checkout_page', false); |
|
534 | 534 | |
535 | 535 | // Success page. |
536 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
536 | + $our_pages[] = wpinv_get_option('success_page', false); |
|
537 | 537 | |
538 | 538 | // Failure page. |
539 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
539 | + $our_pages[] = wpinv_get_option('failure_page', false); |
|
540 | 540 | |
541 | 541 | // History page. |
542 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
542 | + $our_pages[] = wpinv_get_option('invoice_history_page', false); |
|
543 | 543 | |
544 | 544 | // Subscriptions page. |
545 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
545 | + $our_pages[] = wpinv_get_option('invoice_subscription_page', false); |
|
546 | 546 | |
547 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
547 | + $our_pages = array_map('intval', array_filter($our_pages)); |
|
548 | 548 | |
549 | 549 | $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
550 | - return array_unique( $excluded_posts_ids ); |
|
550 | + return array_unique($excluded_posts_ids); |
|
551 | 551 | |
552 | 552 | } |
553 | 553 | |
@@ -558,7 +558,7 @@ discard block |
||
558 | 558 | <div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;"> |
559 | 559 | <div class="modal-content"> |
560 | 560 | <div class="modal-body"> |
561 | - <button type="button" class="close p-2 getpaid-payment-modal-close d-sm-none" data-dismiss="modal" aria-label="' . esc_attr__( 'Close', 'invoicing' ) . '"> |
|
561 | + <button type="button" class="close p-2 getpaid-payment-modal-close d-sm-none" data-dismiss="modal" aria-label="' . esc_attr__('Close', 'invoicing') . '"> |
|
562 | 562 | <i class="fa fa-times" aria-hidden="true"></i> |
563 | 563 | </button> |
564 | 564 | <div class="modal-body-wrapper"></div> |
@@ -18,179 +18,179 @@ |
||
18 | 18 | */ |
19 | 19 | class GetPaid_REST_Report_Top_Sellers_Controller extends GetPaid_REST_Report_Sales_Controller { |
20 | 20 | |
21 | - /** |
|
22 | - * Route base. |
|
23 | - * |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - protected $rest_base = 'reports/top_sellers'; |
|
27 | - |
|
28 | - /** |
|
29 | - * Get top sellers report. |
|
30 | - * |
|
31 | - * @param WP_REST_Request $request |
|
32 | - * @return array|WP_Error |
|
33 | - */ |
|
34 | - public function get_items( $request ) { |
|
35 | - |
|
36 | - // Prepare items. |
|
37 | - $this->report_range = $this->get_date_range( $request ); |
|
38 | - $report_data = $this->get_report_data(); |
|
39 | - |
|
40 | - $top_sellers = array(); |
|
41 | - |
|
42 | - foreach ( $report_data as $item ) { |
|
43 | - |
|
44 | - $item_obj = new WPInv_Item( $item ); |
|
45 | - $item_name = $item->invoice_item_name; |
|
46 | - $item_qty = floatval( $item->invoice_item_qty ); |
|
47 | - $item_id = absint( $item->invoice_item_id ); |
|
48 | - $price = sanitize_text_field( wpinv_price( $item->invoice_item_price ) ); |
|
49 | - |
|
50 | - $item_obj = new WPInv_Item( $item_id ); |
|
51 | - |
|
52 | - if ( $item_obj->exists() ) { |
|
53 | - $item_name = $item_obj->get_name(); |
|
54 | - } else { |
|
55 | - $item_id = 0; |
|
56 | - } |
|
57 | - |
|
58 | - $top_sellers[] = array( |
|
59 | - 'name' =>sanitize_text_field( $item_name ), |
|
60 | - 'item_id' => $item_id, |
|
61 | - 'quantity' => $item_qty, |
|
62 | - 'earnings' => wpinv_round_amount( $item->invoice_item_price ), |
|
63 | - 'earnings_formatted' => sanitize_text_field( wpinv_price( $price ) ), |
|
64 | - ); |
|
65 | - |
|
66 | - } |
|
67 | - |
|
68 | - $data = array(); |
|
69 | - foreach ( $top_sellers as $top_seller ) { |
|
70 | - $item = $this->prepare_item_for_response( (object) $top_seller, $request ); |
|
71 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
72 | - } |
|
73 | - |
|
74 | - return rest_ensure_response( $data ); |
|
75 | - |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Prepare a report sales object for serialization. |
|
80 | - * |
|
81 | - * @param stdClass $top_seller |
|
82 | - * @param WP_REST_Request $request Request object. |
|
83 | - * @return WP_REST_Response $response Response data. |
|
84 | - */ |
|
85 | - public function prepare_item_for_response( $top_seller, $request ) { |
|
86 | - $data = (array) $top_seller; |
|
87 | - |
|
88 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
89 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
90 | - $data = $this->filter_response_by_context( $data, $context ); |
|
91 | - |
|
92 | - // Wrap the data in a response object. |
|
93 | - $response = rest_ensure_response( $data ); |
|
94 | - $links = array( |
|
95 | - 'about' => array( |
|
96 | - 'href' => rest_url( sprintf( '%s/reports', $this->namespace ) ), |
|
97 | - ), |
|
98 | - ); |
|
99 | - |
|
100 | - if ( ! empty( $top_seller->item_id ) ) { |
|
101 | - $links['item'] = array( |
|
102 | - 'href' => rest_url( sprintf( '/%s/items/%s', $this->namespace, $top_seller->item_id ) ), |
|
103 | - 'embeddable' => true, |
|
104 | - ); |
|
105 | - } |
|
106 | - |
|
107 | - $response->add_links( $links ); |
|
108 | - return apply_filters( 'getpaid_rest_prepare_report_' . $this->rest_base, $response, $top_seller, $request ); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Get all data needed for this report and store in the class. |
|
113 | - */ |
|
114 | - protected function query_report_data() { |
|
115 | - |
|
116 | - $this->report_data = GetPaid_Reports_Helper::get_invoice_report_data( |
|
117 | - array( |
|
118 | - 'data' => array( |
|
119 | - 'quantity' => array( |
|
120 | - 'type' => 'invoice_item', |
|
121 | - 'function' => 'SUM', |
|
122 | - 'name' => 'invoice_item_qty', |
|
123 | - ), |
|
124 | - 'item_id' => array( |
|
125 | - 'type' => 'invoice_item', |
|
126 | - 'function' => '', |
|
127 | - 'name' => 'invoice_item_id', |
|
128 | - ), |
|
129 | - 'item_name' => array( |
|
130 | - 'type' => 'invoice_item', |
|
131 | - 'function' => '', |
|
132 | - 'name' => 'invoice_item_name', |
|
133 | - ), |
|
134 | - 'price' => array( |
|
135 | - 'type' => 'invoice_item', |
|
136 | - 'function' => 'SUM', |
|
137 | - 'name' => 'invoice_item_price', |
|
138 | - ), |
|
139 | - ), |
|
140 | - 'group_by' => 'invoice_item_id', |
|
141 | - 'order_by' => 'invoice_item_qty DESC', |
|
142 | - 'query_type' => 'get_results', |
|
143 | - 'limit' => 10, |
|
144 | - 'filter_range' => $this->report_range, |
|
145 | - ) |
|
146 | - ); |
|
147 | - |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Get the Report's schema, conforming to JSON Schema. |
|
152 | - * |
|
153 | - * @return array |
|
154 | - */ |
|
155 | - public function get_item_schema() { |
|
156 | - $schema = array( |
|
157 | - '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
158 | - 'title' => $this->rest_base, |
|
159 | - 'type' => 'object', |
|
160 | - 'properties' => array( |
|
161 | - 'name' => array( |
|
162 | - 'description' => __( 'Item name.', 'invoicing' ), |
|
163 | - 'type' => 'string', |
|
164 | - 'context' => array( 'view' ), |
|
165 | - 'readonly' => true, |
|
166 | - ), |
|
167 | - 'item_id' => array( |
|
168 | - 'description' => __( 'Item ID.', 'invoicing' ), |
|
169 | - 'type' => 'integer', |
|
170 | - 'context' => array( 'view' ), |
|
171 | - 'readonly' => true, |
|
172 | - ), |
|
173 | - 'quantity' => array( |
|
174 | - 'description' => __( 'Total number of purchases.', 'invoicing' ), |
|
175 | - 'type' => 'number', |
|
176 | - 'context' => array( 'view' ), |
|
177 | - 'readonly' => true, |
|
178 | - ), |
|
179 | - 'earnings' => array( |
|
180 | - 'description' => __( 'Total earnings for the item.', 'invoicing' ), |
|
181 | - 'type' => 'number', |
|
182 | - 'context' => array( 'view' ), |
|
183 | - 'readonly' => true, |
|
184 | - ), |
|
185 | - 'earnings_formatted"' => array( |
|
186 | - 'description' => __( 'Total earnings (formatted) for the item.', 'invoicing' ), |
|
187 | - 'type' => 'string', |
|
188 | - 'context' => array( 'view' ), |
|
189 | - 'readonly' => true, |
|
190 | - ), |
|
191 | - ), |
|
192 | - ); |
|
193 | - |
|
194 | - return $this->add_additional_fields_schema( $schema ); |
|
195 | - } |
|
21 | + /** |
|
22 | + * Route base. |
|
23 | + * |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + protected $rest_base = 'reports/top_sellers'; |
|
27 | + |
|
28 | + /** |
|
29 | + * Get top sellers report. |
|
30 | + * |
|
31 | + * @param WP_REST_Request $request |
|
32 | + * @return array|WP_Error |
|
33 | + */ |
|
34 | + public function get_items( $request ) { |
|
35 | + |
|
36 | + // Prepare items. |
|
37 | + $this->report_range = $this->get_date_range( $request ); |
|
38 | + $report_data = $this->get_report_data(); |
|
39 | + |
|
40 | + $top_sellers = array(); |
|
41 | + |
|
42 | + foreach ( $report_data as $item ) { |
|
43 | + |
|
44 | + $item_obj = new WPInv_Item( $item ); |
|
45 | + $item_name = $item->invoice_item_name; |
|
46 | + $item_qty = floatval( $item->invoice_item_qty ); |
|
47 | + $item_id = absint( $item->invoice_item_id ); |
|
48 | + $price = sanitize_text_field( wpinv_price( $item->invoice_item_price ) ); |
|
49 | + |
|
50 | + $item_obj = new WPInv_Item( $item_id ); |
|
51 | + |
|
52 | + if ( $item_obj->exists() ) { |
|
53 | + $item_name = $item_obj->get_name(); |
|
54 | + } else { |
|
55 | + $item_id = 0; |
|
56 | + } |
|
57 | + |
|
58 | + $top_sellers[] = array( |
|
59 | + 'name' =>sanitize_text_field( $item_name ), |
|
60 | + 'item_id' => $item_id, |
|
61 | + 'quantity' => $item_qty, |
|
62 | + 'earnings' => wpinv_round_amount( $item->invoice_item_price ), |
|
63 | + 'earnings_formatted' => sanitize_text_field( wpinv_price( $price ) ), |
|
64 | + ); |
|
65 | + |
|
66 | + } |
|
67 | + |
|
68 | + $data = array(); |
|
69 | + foreach ( $top_sellers as $top_seller ) { |
|
70 | + $item = $this->prepare_item_for_response( (object) $top_seller, $request ); |
|
71 | + $data[] = $this->prepare_response_for_collection( $item ); |
|
72 | + } |
|
73 | + |
|
74 | + return rest_ensure_response( $data ); |
|
75 | + |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Prepare a report sales object for serialization. |
|
80 | + * |
|
81 | + * @param stdClass $top_seller |
|
82 | + * @param WP_REST_Request $request Request object. |
|
83 | + * @return WP_REST_Response $response Response data. |
|
84 | + */ |
|
85 | + public function prepare_item_for_response( $top_seller, $request ) { |
|
86 | + $data = (array) $top_seller; |
|
87 | + |
|
88 | + $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
89 | + $data = $this->add_additional_fields_to_object( $data, $request ); |
|
90 | + $data = $this->filter_response_by_context( $data, $context ); |
|
91 | + |
|
92 | + // Wrap the data in a response object. |
|
93 | + $response = rest_ensure_response( $data ); |
|
94 | + $links = array( |
|
95 | + 'about' => array( |
|
96 | + 'href' => rest_url( sprintf( '%s/reports', $this->namespace ) ), |
|
97 | + ), |
|
98 | + ); |
|
99 | + |
|
100 | + if ( ! empty( $top_seller->item_id ) ) { |
|
101 | + $links['item'] = array( |
|
102 | + 'href' => rest_url( sprintf( '/%s/items/%s', $this->namespace, $top_seller->item_id ) ), |
|
103 | + 'embeddable' => true, |
|
104 | + ); |
|
105 | + } |
|
106 | + |
|
107 | + $response->add_links( $links ); |
|
108 | + return apply_filters( 'getpaid_rest_prepare_report_' . $this->rest_base, $response, $top_seller, $request ); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Get all data needed for this report and store in the class. |
|
113 | + */ |
|
114 | + protected function query_report_data() { |
|
115 | + |
|
116 | + $this->report_data = GetPaid_Reports_Helper::get_invoice_report_data( |
|
117 | + array( |
|
118 | + 'data' => array( |
|
119 | + 'quantity' => array( |
|
120 | + 'type' => 'invoice_item', |
|
121 | + 'function' => 'SUM', |
|
122 | + 'name' => 'invoice_item_qty', |
|
123 | + ), |
|
124 | + 'item_id' => array( |
|
125 | + 'type' => 'invoice_item', |
|
126 | + 'function' => '', |
|
127 | + 'name' => 'invoice_item_id', |
|
128 | + ), |
|
129 | + 'item_name' => array( |
|
130 | + 'type' => 'invoice_item', |
|
131 | + 'function' => '', |
|
132 | + 'name' => 'invoice_item_name', |
|
133 | + ), |
|
134 | + 'price' => array( |
|
135 | + 'type' => 'invoice_item', |
|
136 | + 'function' => 'SUM', |
|
137 | + 'name' => 'invoice_item_price', |
|
138 | + ), |
|
139 | + ), |
|
140 | + 'group_by' => 'invoice_item_id', |
|
141 | + 'order_by' => 'invoice_item_qty DESC', |
|
142 | + 'query_type' => 'get_results', |
|
143 | + 'limit' => 10, |
|
144 | + 'filter_range' => $this->report_range, |
|
145 | + ) |
|
146 | + ); |
|
147 | + |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Get the Report's schema, conforming to JSON Schema. |
|
152 | + * |
|
153 | + * @return array |
|
154 | + */ |
|
155 | + public function get_item_schema() { |
|
156 | + $schema = array( |
|
157 | + '$schema' => 'http://json-schema.org/draft-04/schema#', |
|
158 | + 'title' => $this->rest_base, |
|
159 | + 'type' => 'object', |
|
160 | + 'properties' => array( |
|
161 | + 'name' => array( |
|
162 | + 'description' => __( 'Item name.', 'invoicing' ), |
|
163 | + 'type' => 'string', |
|
164 | + 'context' => array( 'view' ), |
|
165 | + 'readonly' => true, |
|
166 | + ), |
|
167 | + 'item_id' => array( |
|
168 | + 'description' => __( 'Item ID.', 'invoicing' ), |
|
169 | + 'type' => 'integer', |
|
170 | + 'context' => array( 'view' ), |
|
171 | + 'readonly' => true, |
|
172 | + ), |
|
173 | + 'quantity' => array( |
|
174 | + 'description' => __( 'Total number of purchases.', 'invoicing' ), |
|
175 | + 'type' => 'number', |
|
176 | + 'context' => array( 'view' ), |
|
177 | + 'readonly' => true, |
|
178 | + ), |
|
179 | + 'earnings' => array( |
|
180 | + 'description' => __( 'Total earnings for the item.', 'invoicing' ), |
|
181 | + 'type' => 'number', |
|
182 | + 'context' => array( 'view' ), |
|
183 | + 'readonly' => true, |
|
184 | + ), |
|
185 | + 'earnings_formatted"' => array( |
|
186 | + 'description' => __( 'Total earnings (formatted) for the item.', 'invoicing' ), |
|
187 | + 'type' => 'string', |
|
188 | + 'context' => array( 'view' ), |
|
189 | + 'readonly' => true, |
|
190 | + ), |
|
191 | + ), |
|
192 | + ); |
|
193 | + |
|
194 | + return $this->add_additional_fields_schema( $schema ); |
|
195 | + } |
|
196 | 196 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | * @since 2.0.0 |
10 | 10 | */ |
11 | 11 | |
12 | -defined( 'ABSPATH' ) || exit; |
|
12 | +defined('ABSPATH') || exit; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * GetPaid REST top sellers controller class. |
@@ -31,47 +31,47 @@ discard block |
||
31 | 31 | * @param WP_REST_Request $request |
32 | 32 | * @return array|WP_Error |
33 | 33 | */ |
34 | - public function get_items( $request ) { |
|
34 | + public function get_items($request) { |
|
35 | 35 | |
36 | 36 | // Prepare items. |
37 | - $this->report_range = $this->get_date_range( $request ); |
|
37 | + $this->report_range = $this->get_date_range($request); |
|
38 | 38 | $report_data = $this->get_report_data(); |
39 | 39 | |
40 | 40 | $top_sellers = array(); |
41 | 41 | |
42 | - foreach ( $report_data as $item ) { |
|
42 | + foreach ($report_data as $item) { |
|
43 | 43 | |
44 | - $item_obj = new WPInv_Item( $item ); |
|
44 | + $item_obj = new WPInv_Item($item); |
|
45 | 45 | $item_name = $item->invoice_item_name; |
46 | - $item_qty = floatval( $item->invoice_item_qty ); |
|
47 | - $item_id = absint( $item->invoice_item_id ); |
|
48 | - $price = sanitize_text_field( wpinv_price( $item->invoice_item_price ) ); |
|
46 | + $item_qty = floatval($item->invoice_item_qty); |
|
47 | + $item_id = absint($item->invoice_item_id); |
|
48 | + $price = sanitize_text_field(wpinv_price($item->invoice_item_price)); |
|
49 | 49 | |
50 | - $item_obj = new WPInv_Item( $item_id ); |
|
50 | + $item_obj = new WPInv_Item($item_id); |
|
51 | 51 | |
52 | - if ( $item_obj->exists() ) { |
|
52 | + if ($item_obj->exists()) { |
|
53 | 53 | $item_name = $item_obj->get_name(); |
54 | 54 | } else { |
55 | 55 | $item_id = 0; |
56 | 56 | } |
57 | 57 | |
58 | 58 | $top_sellers[] = array( |
59 | - 'name' =>sanitize_text_field( $item_name ), |
|
59 | + 'name' =>sanitize_text_field($item_name), |
|
60 | 60 | 'item_id' => $item_id, |
61 | 61 | 'quantity' => $item_qty, |
62 | - 'earnings' => wpinv_round_amount( $item->invoice_item_price ), |
|
63 | - 'earnings_formatted' => sanitize_text_field( wpinv_price( $price ) ), |
|
62 | + 'earnings' => wpinv_round_amount($item->invoice_item_price), |
|
63 | + 'earnings_formatted' => sanitize_text_field(wpinv_price($price)), |
|
64 | 64 | ); |
65 | 65 | |
66 | 66 | } |
67 | 67 | |
68 | 68 | $data = array(); |
69 | - foreach ( $top_sellers as $top_seller ) { |
|
70 | - $item = $this->prepare_item_for_response( (object) $top_seller, $request ); |
|
71 | - $data[] = $this->prepare_response_for_collection( $item ); |
|
69 | + foreach ($top_sellers as $top_seller) { |
|
70 | + $item = $this->prepare_item_for_response((object) $top_seller, $request); |
|
71 | + $data[] = $this->prepare_response_for_collection($item); |
|
72 | 72 | } |
73 | 73 | |
74 | - return rest_ensure_response( $data ); |
|
74 | + return rest_ensure_response($data); |
|
75 | 75 | |
76 | 76 | } |
77 | 77 | |
@@ -82,30 +82,30 @@ discard block |
||
82 | 82 | * @param WP_REST_Request $request Request object. |
83 | 83 | * @return WP_REST_Response $response Response data. |
84 | 84 | */ |
85 | - public function prepare_item_for_response( $top_seller, $request ) { |
|
85 | + public function prepare_item_for_response($top_seller, $request) { |
|
86 | 86 | $data = (array) $top_seller; |
87 | 87 | |
88 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
89 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
90 | - $data = $this->filter_response_by_context( $data, $context ); |
|
88 | + $context = !empty($request['context']) ? $request['context'] : 'view'; |
|
89 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
90 | + $data = $this->filter_response_by_context($data, $context); |
|
91 | 91 | |
92 | 92 | // Wrap the data in a response object. |
93 | - $response = rest_ensure_response( $data ); |
|
93 | + $response = rest_ensure_response($data); |
|
94 | 94 | $links = array( |
95 | 95 | 'about' => array( |
96 | - 'href' => rest_url( sprintf( '%s/reports', $this->namespace ) ), |
|
96 | + 'href' => rest_url(sprintf('%s/reports', $this->namespace)), |
|
97 | 97 | ), |
98 | 98 | ); |
99 | 99 | |
100 | - if ( ! empty( $top_seller->item_id ) ) { |
|
101 | - $links['item'] = array( |
|
102 | - 'href' => rest_url( sprintf( '/%s/items/%s', $this->namespace, $top_seller->item_id ) ), |
|
100 | + if (!empty($top_seller->item_id)) { |
|
101 | + $links['item'] = array( |
|
102 | + 'href' => rest_url(sprintf('/%s/items/%s', $this->namespace, $top_seller->item_id)), |
|
103 | 103 | 'embeddable' => true, |
104 | 104 | ); |
105 | 105 | } |
106 | 106 | |
107 | - $response->add_links( $links ); |
|
108 | - return apply_filters( 'getpaid_rest_prepare_report_' . $this->rest_base, $response, $top_seller, $request ); |
|
107 | + $response->add_links($links); |
|
108 | + return apply_filters('getpaid_rest_prepare_report_' . $this->rest_base, $response, $top_seller, $request); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -159,38 +159,38 @@ discard block |
||
159 | 159 | 'type' => 'object', |
160 | 160 | 'properties' => array( |
161 | 161 | 'name' => array( |
162 | - 'description' => __( 'Item name.', 'invoicing' ), |
|
162 | + 'description' => __('Item name.', 'invoicing'), |
|
163 | 163 | 'type' => 'string', |
164 | - 'context' => array( 'view' ), |
|
164 | + 'context' => array('view'), |
|
165 | 165 | 'readonly' => true, |
166 | 166 | ), |
167 | 167 | 'item_id' => array( |
168 | - 'description' => __( 'Item ID.', 'invoicing' ), |
|
168 | + 'description' => __('Item ID.', 'invoicing'), |
|
169 | 169 | 'type' => 'integer', |
170 | - 'context' => array( 'view' ), |
|
170 | + 'context' => array('view'), |
|
171 | 171 | 'readonly' => true, |
172 | 172 | ), |
173 | 173 | 'quantity' => array( |
174 | - 'description' => __( 'Total number of purchases.', 'invoicing' ), |
|
174 | + 'description' => __('Total number of purchases.', 'invoicing'), |
|
175 | 175 | 'type' => 'number', |
176 | - 'context' => array( 'view' ), |
|
176 | + 'context' => array('view'), |
|
177 | 177 | 'readonly' => true, |
178 | 178 | ), |
179 | 179 | 'earnings' => array( |
180 | - 'description' => __( 'Total earnings for the item.', 'invoicing' ), |
|
180 | + 'description' => __('Total earnings for the item.', 'invoicing'), |
|
181 | 181 | 'type' => 'number', |
182 | - 'context' => array( 'view' ), |
|
182 | + 'context' => array('view'), |
|
183 | 183 | 'readonly' => true, |
184 | 184 | ), |
185 | 185 | 'earnings_formatted"' => array( |
186 | - 'description' => __( 'Total earnings (formatted) for the item.', 'invoicing' ), |
|
186 | + 'description' => __('Total earnings (formatted) for the item.', 'invoicing'), |
|
187 | 187 | 'type' => 'string', |
188 | - 'context' => array( 'view' ), |
|
188 | + 'context' => array('view'), |
|
189 | 189 | 'readonly' => true, |
190 | 190 | ), |
191 | 191 | ), |
192 | 192 | ); |
193 | 193 | |
194 | - return $this->add_additional_fields_schema( $schema ); |
|
194 | + return $this->add_additional_fields_schema($schema); |
|
195 | 195 | } |
196 | 196 | } |