@@ -7,49 +7,49 @@ |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | ?> |
13 | 13 | |
14 | 14 | <div class='form-group'> |
15 | 15 | <label class="d-block"> |
16 | - <span><?php esc_html_e( 'Field Label', 'invoicing' ); ?></span> |
|
16 | + <span><?php esc_html_e('Field Label', 'invoicing'); ?></span> |
|
17 | 17 | <input v-model='active_form_element.label' class='form-control' type="text"/> |
18 | 18 | </label> |
19 | 19 | </div> |
20 | 20 | |
21 | 21 | <div class='form-group'> |
22 | 22 | <label class="d-block"> |
23 | - <span><?php esc_html_e( 'Placeholder text', 'invoicing' ); ?></span> |
|
23 | + <span><?php esc_html_e('Placeholder text', 'invoicing'); ?></span> |
|
24 | 24 | <input v-model='active_form_element.placeholder' class='form-control' type="text"/> |
25 | 25 | </label> |
26 | 26 | </div> |
27 | 27 | |
28 | 28 | <div class='form-group'> |
29 | 29 | <label class="d-block"> |
30 | - <span><?php esc_html_e( 'Help Text', 'invoicing' ); ?></span> |
|
31 | - <textarea placeholder='<?php esc_attr_e( 'Add some help text for this field', 'invoicing' ); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea> |
|
32 | - <small class="form-text text-muted"><?php _e( 'HTML is allowed', 'invoicing' ); ?></small> |
|
30 | + <span><?php esc_html_e('Help Text', 'invoicing'); ?></span> |
|
31 | + <textarea placeholder='<?php esc_attr_e('Add some help text for this field', 'invoicing'); ?>' v-model='active_form_element.description' class='form-control' rows='3'></textarea> |
|
32 | + <small class="form-text text-muted"><?php _e('HTML is allowed', 'invoicing'); ?></small> |
|
33 | 33 | </label> |
34 | 34 | </div> |
35 | 35 | |
36 | 36 | <div class='form-group form-check'> |
37 | 37 | <input :id="active_form_element.id + '_edit'" v-model='active_form_element.required' type='checkbox' class='form-check-input' /> |
38 | - <label class='form-check-label' :for="active_form_element.id + '_edit'"><?php esc_html_e( 'Is this field required?', 'invoicing' ); ?></label> |
|
38 | + <label class='form-check-label' :for="active_form_element.id + '_edit'"><?php esc_html_e('Is this field required?', 'invoicing'); ?></label> |
|
39 | 39 | </div> |
40 | 40 | |
41 | 41 | <div class='form-group form-check'> |
42 | 42 | <input :id="active_form_element.id + '_add_meta'" v-model='active_form_element.add_meta' type='checkbox' class='form-check-input' /> |
43 | - <label class='form-check-label' :for="active_form_element.id + '_add_meta'"><?php esc_html_e( 'Show this field in receipts and emails?', 'invoicing' ); ?></label> |
|
43 | + <label class='form-check-label' :for="active_form_element.id + '_add_meta'"><?php esc_html_e('Show this field in receipts and emails?', 'invoicing'); ?></label> |
|
44 | 44 | </div> |
45 | 45 | |
46 | 46 | <hr class='featurette-divider mt-4'> |
47 | 47 | |
48 | 48 | <div class='form-group'> |
49 | 49 | <label class="d-block"> |
50 | - <span><?php esc_html_e( 'Email Merge Tag', 'invoicing' ); ?></span> |
|
50 | + <span><?php esc_html_e('Email Merge Tag', 'invoicing'); ?></span> |
|
51 | 51 | <input :value='active_form_element.label | formatMergeTag' class='form-control bg-white' type="text" readonly onclick="this.select()" /> |
52 | - <span class="form-text text-muted"><?php esc_html_e( 'You can use this merge tag in notification emails', 'invoicing' ); ?></span> |
|
52 | + <span class="form-text text-muted"><?php esc_html_e('You can use this merge tag in notification emails', 'invoicing'); ?></span> |
|
53 | 53 | </label> |
54 | 54 | </div> |
55 | 55 |
@@ -12,114 +12,114 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Fees { |
14 | 14 | |
15 | - /** |
|
16 | - * The fee validation error. |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - public $fee_error; |
|
20 | - |
|
21 | - /** |
|
22 | - * Submission fees. |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - public $fees = array(); |
|
15 | + /** |
|
16 | + * The fee validation error. |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + public $fee_error; |
|
20 | + |
|
21 | + /** |
|
22 | + * Submission fees. |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + public $fees = array(); |
|
26 | + |
|
27 | + /** |
|
28 | + * Class constructor |
|
29 | + * |
|
30 | + * @param GetPaid_Payment_Form_Submission $submission |
|
31 | + */ |
|
32 | + public function __construct( $submission ) { |
|
33 | + |
|
34 | + // Process any existing invoice fees. |
|
35 | + if ( $submission->has_invoice() ) { |
|
36 | + $this->fees = $submission->get_invoice()->get_fees(); |
|
37 | + } |
|
38 | + |
|
39 | + // Process price fields. |
|
40 | + $data = $submission->get_data(); |
|
41 | + $payment_form = $submission->get_payment_form(); |
|
42 | + |
|
43 | + foreach ( $payment_form->get_elements() as $element ) { |
|
44 | + |
|
45 | + if ( 'price_input' == $element['type'] ) { |
|
46 | + $this->process_price_input( $element, $data, $submission ); |
|
47 | + } |
|
48 | + |
|
49 | + if ( 'price_select' == $element['type'] ) { |
|
50 | + $this->process_price_select( $element, $data ); |
|
51 | + } |
|
52 | + |
|
53 | + } |
|
54 | + |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Process a price input field. |
|
59 | + * |
|
60 | + * @param array $element |
|
61 | + * @param array $data |
|
62 | + * @param GetPaid_Payment_Form_Submission $submission |
|
63 | + */ |
|
64 | + public function process_price_input( $element, $data, $submission ) { |
|
65 | + |
|
66 | + // Abort if not passed. |
|
67 | + if ( empty( $data[ $element['id'] ] ) ) { |
|
68 | + return; |
|
69 | + } |
|
70 | + |
|
71 | + $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
72 | + $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
73 | + |
|
74 | + if ( $amount < $minimum ) { |
|
75 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $minimum, $submission->get_currency() ) ) ); |
|
76 | + } |
|
77 | + |
|
78 | + $this->fees[ $element['label'] ] = array( |
|
79 | + 'name' => $element['label'], |
|
80 | + 'initial_fee' => $amount, |
|
81 | + 'recurring_fee' => 0, |
|
82 | + ); |
|
83 | + |
|
84 | + } |
|
26 | 85 | |
27 | 86 | /** |
28 | - * Class constructor |
|
29 | - * |
|
30 | - * @param GetPaid_Payment_Form_Submission $submission |
|
31 | - */ |
|
32 | - public function __construct( $submission ) { |
|
33 | - |
|
34 | - // Process any existing invoice fees. |
|
35 | - if ( $submission->has_invoice() ) { |
|
36 | - $this->fees = $submission->get_invoice()->get_fees(); |
|
37 | - } |
|
38 | - |
|
39 | - // Process price fields. |
|
40 | - $data = $submission->get_data(); |
|
41 | - $payment_form = $submission->get_payment_form(); |
|
42 | - |
|
43 | - foreach ( $payment_form->get_elements() as $element ) { |
|
44 | - |
|
45 | - if ( 'price_input' == $element['type'] ) { |
|
46 | - $this->process_price_input( $element, $data, $submission ); |
|
47 | - } |
|
48 | - |
|
49 | - if ( 'price_select' == $element['type'] ) { |
|
50 | - $this->process_price_select( $element, $data ); |
|
51 | - } |
|
52 | - |
|
53 | - } |
|
54 | - |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Process a price input field. |
|
59 | - * |
|
60 | - * @param array $element |
|
61 | - * @param array $data |
|
62 | - * @param GetPaid_Payment_Form_Submission $submission |
|
63 | - */ |
|
64 | - public function process_price_input( $element, $data, $submission ) { |
|
65 | - |
|
66 | - // Abort if not passed. |
|
67 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
68 | - return; |
|
69 | - } |
|
70 | - |
|
71 | - $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
72 | - $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
73 | - |
|
74 | - if ( $amount < $minimum ) { |
|
75 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $minimum, $submission->get_currency() ) ) ); |
|
76 | - } |
|
77 | - |
|
78 | - $this->fees[ $element['label'] ] = array( |
|
79 | - 'name' => $element['label'], |
|
80 | - 'initial_fee' => $amount, |
|
81 | - 'recurring_fee' => 0, |
|
82 | - ); |
|
83 | - |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Process a price select field. |
|
88 | - * |
|
89 | - * @param array $element |
|
90 | - * @param array $data |
|
91 | - */ |
|
92 | - public function process_price_select( $element, $data ) { |
|
93 | - |
|
94 | - // Abort if not passed. |
|
95 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
96 | - return; |
|
97 | - } |
|
98 | - |
|
99 | - $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
100 | - $selected = array_filter( array_map( 'trim', explode( ',', $data[ $element['id'] ] ) ) ); |
|
101 | - $total = 0; |
|
102 | - $sub_labels = array(); |
|
103 | - |
|
104 | - foreach ( $selected as $price ) { |
|
105 | - |
|
106 | - if ( ! isset( $options[ $price ] ) ) { |
|
107 | - throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
108 | - } |
|
109 | - |
|
110 | - $price = explode( '|', $price ); |
|
111 | - |
|
112 | - $sub_labels[] = $price[0]; |
|
113 | - $total += (float) wpinv_sanitize_amount( $price[1] ); |
|
114 | - } |
|
115 | - |
|
116 | - $this->fees[ $element['label'] ] = array( |
|
117 | - 'name' => $element['label'], |
|
118 | - 'initial_fee' => $total, |
|
119 | - 'recurring_fee' => 0, |
|
120 | - 'description' => implode( ', ', $sub_labels ), |
|
121 | - ); |
|
122 | - |
|
123 | - } |
|
87 | + * Process a price select field. |
|
88 | + * |
|
89 | + * @param array $element |
|
90 | + * @param array $data |
|
91 | + */ |
|
92 | + public function process_price_select( $element, $data ) { |
|
93 | + |
|
94 | + // Abort if not passed. |
|
95 | + if ( empty( $data[ $element['id'] ] ) ) { |
|
96 | + return; |
|
97 | + } |
|
98 | + |
|
99 | + $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
100 | + $selected = array_filter( array_map( 'trim', explode( ',', $data[ $element['id'] ] ) ) ); |
|
101 | + $total = 0; |
|
102 | + $sub_labels = array(); |
|
103 | + |
|
104 | + foreach ( $selected as $price ) { |
|
105 | + |
|
106 | + if ( ! isset( $options[ $price ] ) ) { |
|
107 | + throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
108 | + } |
|
109 | + |
|
110 | + $price = explode( '|', $price ); |
|
111 | + |
|
112 | + $sub_labels[] = $price[0]; |
|
113 | + $total += (float) wpinv_sanitize_amount( $price[1] ); |
|
114 | + } |
|
115 | + |
|
116 | + $this->fees[ $element['label'] ] = array( |
|
117 | + 'name' => $element['label'], |
|
118 | + 'initial_fee' => $total, |
|
119 | + 'recurring_fee' => 0, |
|
120 | + 'description' => implode( ', ', $sub_labels ), |
|
121 | + ); |
|
122 | + |
|
123 | + } |
|
124 | 124 | |
125 | 125 | } |
@@ -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 | * Payment form submission fees class |
@@ -29,10 +29,10 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @param GetPaid_Payment_Form_Submission $submission |
31 | 31 | */ |
32 | - public function __construct( $submission ) { |
|
32 | + public function __construct($submission) { |
|
33 | 33 | |
34 | 34 | // Process any existing invoice fees. |
35 | - if ( $submission->has_invoice() ) { |
|
35 | + if ($submission->has_invoice()) { |
|
36 | 36 | $this->fees = $submission->get_invoice()->get_fees(); |
37 | 37 | } |
38 | 38 | |
@@ -40,14 +40,14 @@ discard block |
||
40 | 40 | $data = $submission->get_data(); |
41 | 41 | $payment_form = $submission->get_payment_form(); |
42 | 42 | |
43 | - foreach ( $payment_form->get_elements() as $element ) { |
|
43 | + foreach ($payment_form->get_elements() as $element) { |
|
44 | 44 | |
45 | - if ( 'price_input' == $element['type'] ) { |
|
46 | - $this->process_price_input( $element, $data, $submission ); |
|
45 | + if ('price_input' == $element['type']) { |
|
46 | + $this->process_price_input($element, $data, $submission); |
|
47 | 47 | } |
48 | 48 | |
49 | - if ( 'price_select' == $element['type'] ) { |
|
50 | - $this->process_price_select( $element, $data ); |
|
49 | + if ('price_select' == $element['type']) { |
|
50 | + $this->process_price_select($element, $data); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | } |
@@ -61,21 +61,21 @@ discard block |
||
61 | 61 | * @param array $data |
62 | 62 | * @param GetPaid_Payment_Form_Submission $submission |
63 | 63 | */ |
64 | - public function process_price_input( $element, $data, $submission ) { |
|
64 | + public function process_price_input($element, $data, $submission) { |
|
65 | 65 | |
66 | 66 | // Abort if not passed. |
67 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
67 | + if (empty($data[$element['id']])) { |
|
68 | 68 | return; |
69 | 69 | } |
70 | 70 | |
71 | - $amount = (float) wpinv_sanitize_amount( $data[ $element['id'] ] ); |
|
72 | - $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] ); |
|
71 | + $amount = (float) wpinv_sanitize_amount($data[$element['id']]); |
|
72 | + $minimum = empty($element['minimum']) ? 0 : (float) wpinv_sanitize_amount($element['minimum']); |
|
73 | 73 | |
74 | - if ( $amount < $minimum ) { |
|
75 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $minimum, $submission->get_currency() ) ) ); |
|
74 | + if ($amount < $minimum) { |
|
75 | + throw new Exception(sprintf(__('The minimum allowed amount is %s', 'invoicing'), getpaid_unstandardize_amount($minimum, $submission->get_currency()))); |
|
76 | 76 | } |
77 | 77 | |
78 | - $this->fees[ $element['label'] ] = array( |
|
78 | + $this->fees[$element['label']] = array( |
|
79 | 79 | 'name' => $element['label'], |
80 | 80 | 'initial_fee' => $amount, |
81 | 81 | 'recurring_fee' => 0, |
@@ -89,35 +89,35 @@ discard block |
||
89 | 89 | * @param array $element |
90 | 90 | * @param array $data |
91 | 91 | */ |
92 | - public function process_price_select( $element, $data ) { |
|
92 | + public function process_price_select($element, $data) { |
|
93 | 93 | |
94 | 94 | // Abort if not passed. |
95 | - if ( empty( $data[ $element['id'] ] ) ) { |
|
95 | + if (empty($data[$element['id']])) { |
|
96 | 96 | return; |
97 | 97 | } |
98 | 98 | |
99 | - $options = getpaid_convert_price_string_to_options( $element['options'] ); |
|
100 | - $selected = array_filter( array_map( 'trim', explode( ',', $data[ $element['id'] ] ) ) ); |
|
99 | + $options = getpaid_convert_price_string_to_options($element['options']); |
|
100 | + $selected = array_filter(array_map('trim', explode(',', $data[$element['id']]))); |
|
101 | 101 | $total = 0; |
102 | 102 | $sub_labels = array(); |
103 | 103 | |
104 | - foreach ( $selected as $price ) { |
|
104 | + foreach ($selected as $price) { |
|
105 | 105 | |
106 | - if ( ! isset( $options[ $price ] ) ) { |
|
107 | - throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) ); |
|
106 | + if (!isset($options[$price])) { |
|
107 | + throw new Exception(__('You have selected an invalid amount', 'invoicing')); |
|
108 | 108 | } |
109 | 109 | |
110 | - $price = explode( '|', $price ); |
|
110 | + $price = explode('|', $price); |
|
111 | 111 | |
112 | 112 | $sub_labels[] = $price[0]; |
113 | - $total += (float) wpinv_sanitize_amount( $price[1] ); |
|
113 | + $total += (float) wpinv_sanitize_amount($price[1]); |
|
114 | 114 | } |
115 | 115 | |
116 | - $this->fees[ $element['label'] ] = array( |
|
116 | + $this->fees[$element['label']] = array( |
|
117 | 117 | 'name' => $element['label'], |
118 | 118 | 'initial_fee' => $total, |
119 | 119 | 'recurring_fee' => 0, |
120 | - 'description' => implode( ', ', $sub_labels ), |
|
120 | + 'description' => implode(', ', $sub_labels), |
|
121 | 121 | ); |
122 | 122 | |
123 | 123 | } |
@@ -17,397 +17,397 @@ |
||
17 | 17 | */ |
18 | 18 | class GetPaid_Admin_Setup_Wizard { |
19 | 19 | |
20 | - /** |
|
21 | - * @var string Current Step |
|
22 | - */ |
|
23 | - protected $step = ''; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var string|false Previous Step |
|
27 | - */ |
|
28 | - protected $previous_step = ''; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string|false Next Step |
|
32 | - */ |
|
33 | - protected $next_step = ''; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var array All available steps for the setup wizard |
|
37 | - */ |
|
38 | - protected $steps = array(); |
|
39 | - |
|
40 | - /** |
|
41 | - * Class constructor. |
|
42 | - * |
|
43 | - * @since 2.4.0 |
|
44 | - */ |
|
45 | - public function __construct() { |
|
46 | - |
|
47 | - if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) { |
|
48 | - add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
|
49 | - add_action( 'current_screen', array( $this, 'setup_wizard' ) ); |
|
50 | - } |
|
51 | - |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Add admin menus/screens. |
|
56 | - * |
|
57 | - * @since 2.4.0 |
|
58 | - */ |
|
59 | - public function add_menu() { |
|
60 | - add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' ); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Sets up the setup wizard. |
|
65 | - * |
|
66 | - * @since 2.4.0 |
|
67 | - */ |
|
68 | - public function setup_wizard() { |
|
69 | - |
|
70 | - if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) { |
|
71 | - $this->setup_globals(); |
|
72 | - $this->maybe_save_current_step(); |
|
73 | - $this->display_wizard(); |
|
74 | - exit; |
|
75 | - } |
|
76 | - |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * Sets up class variables. |
|
81 | - * |
|
82 | - * @since 2.4.0 |
|
83 | - */ |
|
84 | - protected function setup_globals() { |
|
85 | - $this->steps = $this->get_setup_steps(); |
|
86 | - $this->step = $this->get_current_step(); |
|
87 | - $this->previous_step = $this->get_previous_step(); |
|
88 | - $this->next_step = $this->get_next_step(); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Saves the current step. |
|
93 | - * |
|
94 | - * @since 2.4.0 |
|
95 | - */ |
|
96 | - protected function maybe_save_current_step() { |
|
97 | - if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) { |
|
98 | - call_user_func( $this->steps[ $this->step ]['handler'], $this ); |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Returns the setup steps. |
|
104 | - * |
|
105 | - * @since 2.4.0 |
|
106 | - * @return array |
|
107 | - */ |
|
108 | - protected function get_setup_steps() { |
|
109 | - |
|
110 | - $steps = array( |
|
111 | - |
|
112 | - 'introduction' => array( |
|
113 | - 'name' => __( 'Introduction', 'invoicing' ), |
|
114 | - 'view' => array( $this, 'setup_introduction' ), |
|
115 | - 'handler' => '', |
|
116 | - ), |
|
117 | - |
|
118 | - 'business_details' => array( |
|
119 | - 'name' => __( "Business Details", 'invoicing' ), |
|
120 | - 'view' => array( $this, 'setup_business' ), |
|
121 | - 'handler' => '', |
|
122 | - ), |
|
123 | - |
|
124 | - 'currency' => array( |
|
125 | - 'name' => __( 'Currency', 'invoicing' ), |
|
126 | - 'view' => array( $this, 'setup_currency' ), |
|
127 | - 'handler' => '', |
|
128 | - ), |
|
129 | - |
|
130 | - 'payments' => array( |
|
131 | - 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
132 | - 'view' => array( $this, 'setup_payments' ), |
|
133 | - 'handler' => array( $this, 'setup_payments_save' ), |
|
134 | - ), |
|
135 | - |
|
136 | - 'recommend' => array( |
|
137 | - 'name' => __( 'Recommend', 'invoicing' ), |
|
138 | - 'view' => array( $this, 'setup_recommend' ), |
|
139 | - 'handler' => '', |
|
140 | - ), |
|
141 | - |
|
142 | - 'next_steps' => array( |
|
143 | - 'name' => __( 'Get Paid', 'invoicing' ), |
|
144 | - 'view' => array( $this, 'setup_ready' ), |
|
145 | - 'handler' => '', |
|
146 | - ), |
|
147 | - |
|
148 | - ); |
|
149 | - |
|
150 | - return apply_filters( 'getpaid_setup_wizard_steps', $steps ); |
|
151 | - |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Returns the current step. |
|
156 | - * |
|
157 | - * @since 2.4.0 |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - protected function get_current_step() { |
|
161 | - $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : ''; |
|
162 | - return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) ); |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Returns the previous step. |
|
167 | - * |
|
168 | - * @since 2.4.0 |
|
169 | - * @return string|false |
|
170 | - */ |
|
171 | - protected function get_previous_step() { |
|
172 | - |
|
173 | - $previous = false; |
|
174 | - $current = $this->step; |
|
175 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
176 | - if ( $current === $step ) { |
|
177 | - return $previous; |
|
178 | - } |
|
179 | - |
|
180 | - $previous = $step; |
|
181 | - } |
|
182 | - |
|
183 | - return false; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Returns the next step. |
|
188 | - * |
|
189 | - * @since 2.4.0 |
|
190 | - * @return string|false |
|
191 | - */ |
|
192 | - protected function get_next_step() { |
|
193 | - |
|
194 | - $on_current = false; |
|
195 | - $current = $this->step; |
|
196 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
197 | - |
|
198 | - if ( $on_current ) { |
|
199 | - return $step; |
|
200 | - } |
|
201 | - |
|
202 | - if ( $current === $step ) { |
|
203 | - return $on_current = true; |
|
204 | - } |
|
205 | - |
|
206 | - } |
|
207 | - |
|
208 | - return false; |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * Displays the setup wizard. |
|
213 | - * |
|
214 | - * @since 2.4.0 |
|
215 | - */ |
|
216 | - public function display_wizard() { |
|
217 | - $this->display_header(); |
|
218 | - $this->display_current_step(); |
|
219 | - $this->display_footer(); |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Displays the Wizard Header. |
|
224 | - * |
|
225 | - * @since 2.0.0 |
|
226 | - */ |
|
227 | - public function display_header() { |
|
228 | - $steps = $this->steps; |
|
229 | - $current = $this->step; |
|
230 | - $next_step = $this->next_step; |
|
231 | - array_shift( $steps ); |
|
232 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php'; |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Displays the content for the current step. |
|
237 | - * |
|
238 | - * @since 2.4.0 |
|
239 | - */ |
|
240 | - public function display_current_step() { |
|
241 | - ?> |
|
20 | + /** |
|
21 | + * @var string Current Step |
|
22 | + */ |
|
23 | + protected $step = ''; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var string|false Previous Step |
|
27 | + */ |
|
28 | + protected $previous_step = ''; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string|false Next Step |
|
32 | + */ |
|
33 | + protected $next_step = ''; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var array All available steps for the setup wizard |
|
37 | + */ |
|
38 | + protected $steps = array(); |
|
39 | + |
|
40 | + /** |
|
41 | + * Class constructor. |
|
42 | + * |
|
43 | + * @since 2.4.0 |
|
44 | + */ |
|
45 | + public function __construct() { |
|
46 | + |
|
47 | + if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) { |
|
48 | + add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
|
49 | + add_action( 'current_screen', array( $this, 'setup_wizard' ) ); |
|
50 | + } |
|
51 | + |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Add admin menus/screens. |
|
56 | + * |
|
57 | + * @since 2.4.0 |
|
58 | + */ |
|
59 | + public function add_menu() { |
|
60 | + add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' ); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Sets up the setup wizard. |
|
65 | + * |
|
66 | + * @since 2.4.0 |
|
67 | + */ |
|
68 | + public function setup_wizard() { |
|
69 | + |
|
70 | + if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) { |
|
71 | + $this->setup_globals(); |
|
72 | + $this->maybe_save_current_step(); |
|
73 | + $this->display_wizard(); |
|
74 | + exit; |
|
75 | + } |
|
76 | + |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * Sets up class variables. |
|
81 | + * |
|
82 | + * @since 2.4.0 |
|
83 | + */ |
|
84 | + protected function setup_globals() { |
|
85 | + $this->steps = $this->get_setup_steps(); |
|
86 | + $this->step = $this->get_current_step(); |
|
87 | + $this->previous_step = $this->get_previous_step(); |
|
88 | + $this->next_step = $this->get_next_step(); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Saves the current step. |
|
93 | + * |
|
94 | + * @since 2.4.0 |
|
95 | + */ |
|
96 | + protected function maybe_save_current_step() { |
|
97 | + if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) { |
|
98 | + call_user_func( $this->steps[ $this->step ]['handler'], $this ); |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Returns the setup steps. |
|
104 | + * |
|
105 | + * @since 2.4.0 |
|
106 | + * @return array |
|
107 | + */ |
|
108 | + protected function get_setup_steps() { |
|
109 | + |
|
110 | + $steps = array( |
|
111 | + |
|
112 | + 'introduction' => array( |
|
113 | + 'name' => __( 'Introduction', 'invoicing' ), |
|
114 | + 'view' => array( $this, 'setup_introduction' ), |
|
115 | + 'handler' => '', |
|
116 | + ), |
|
117 | + |
|
118 | + 'business_details' => array( |
|
119 | + 'name' => __( "Business Details", 'invoicing' ), |
|
120 | + 'view' => array( $this, 'setup_business' ), |
|
121 | + 'handler' => '', |
|
122 | + ), |
|
123 | + |
|
124 | + 'currency' => array( |
|
125 | + 'name' => __( 'Currency', 'invoicing' ), |
|
126 | + 'view' => array( $this, 'setup_currency' ), |
|
127 | + 'handler' => '', |
|
128 | + ), |
|
129 | + |
|
130 | + 'payments' => array( |
|
131 | + 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
132 | + 'view' => array( $this, 'setup_payments' ), |
|
133 | + 'handler' => array( $this, 'setup_payments_save' ), |
|
134 | + ), |
|
135 | + |
|
136 | + 'recommend' => array( |
|
137 | + 'name' => __( 'Recommend', 'invoicing' ), |
|
138 | + 'view' => array( $this, 'setup_recommend' ), |
|
139 | + 'handler' => '', |
|
140 | + ), |
|
141 | + |
|
142 | + 'next_steps' => array( |
|
143 | + 'name' => __( 'Get Paid', 'invoicing' ), |
|
144 | + 'view' => array( $this, 'setup_ready' ), |
|
145 | + 'handler' => '', |
|
146 | + ), |
|
147 | + |
|
148 | + ); |
|
149 | + |
|
150 | + return apply_filters( 'getpaid_setup_wizard_steps', $steps ); |
|
151 | + |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Returns the current step. |
|
156 | + * |
|
157 | + * @since 2.4.0 |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + protected function get_current_step() { |
|
161 | + $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : ''; |
|
162 | + return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) ); |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Returns the previous step. |
|
167 | + * |
|
168 | + * @since 2.4.0 |
|
169 | + * @return string|false |
|
170 | + */ |
|
171 | + protected function get_previous_step() { |
|
172 | + |
|
173 | + $previous = false; |
|
174 | + $current = $this->step; |
|
175 | + foreach ( array_keys( $this->steps ) as $step ) { |
|
176 | + if ( $current === $step ) { |
|
177 | + return $previous; |
|
178 | + } |
|
179 | + |
|
180 | + $previous = $step; |
|
181 | + } |
|
182 | + |
|
183 | + return false; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Returns the next step. |
|
188 | + * |
|
189 | + * @since 2.4.0 |
|
190 | + * @return string|false |
|
191 | + */ |
|
192 | + protected function get_next_step() { |
|
193 | + |
|
194 | + $on_current = false; |
|
195 | + $current = $this->step; |
|
196 | + foreach ( array_keys( $this->steps ) as $step ) { |
|
197 | + |
|
198 | + if ( $on_current ) { |
|
199 | + return $step; |
|
200 | + } |
|
201 | + |
|
202 | + if ( $current === $step ) { |
|
203 | + return $on_current = true; |
|
204 | + } |
|
205 | + |
|
206 | + } |
|
207 | + |
|
208 | + return false; |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * Displays the setup wizard. |
|
213 | + * |
|
214 | + * @since 2.4.0 |
|
215 | + */ |
|
216 | + public function display_wizard() { |
|
217 | + $this->display_header(); |
|
218 | + $this->display_current_step(); |
|
219 | + $this->display_footer(); |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Displays the Wizard Header. |
|
224 | + * |
|
225 | + * @since 2.0.0 |
|
226 | + */ |
|
227 | + public function display_header() { |
|
228 | + $steps = $this->steps; |
|
229 | + $current = $this->step; |
|
230 | + $next_step = $this->next_step; |
|
231 | + array_shift( $steps ); |
|
232 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php'; |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Displays the content for the current step. |
|
237 | + * |
|
238 | + * @since 2.4.0 |
|
239 | + */ |
|
240 | + public function display_current_step() { |
|
241 | + ?> |
|
242 | 242 | <div class="gp-setup-content rowx mw-100 text-center mb-3"> |
243 | 243 | <div class="col-12 col-md-5 m-auto"> |
244 | 244 | <?php call_user_func( $this->steps[ $this->step ]['view'], $this ); ?> |
245 | 245 | </div> |
246 | 246 | </div> |
247 | 247 | <?php |
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Setup Wizard Footer. |
|
252 | - * |
|
253 | - * @since 2.4.0 |
|
254 | - */ |
|
255 | - public function display_footer() { |
|
256 | - |
|
257 | - if ( isset( $_GET['step'] ) ) { |
|
258 | - $next_url = esc_url( $this->get_next_step_link() ); |
|
259 | - $label = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' ); |
|
260 | - |
|
261 | - echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . $next_url . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . $label . '</a></p>'; |
|
262 | - } |
|
263 | - |
|
264 | - echo '</body></html>'; |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * Introduction step. |
|
269 | - * |
|
270 | - * @since 2.0.0 |
|
271 | - */ |
|
272 | - public function setup_introduction() { |
|
273 | - $next_url = $this->get_next_step_link(); |
|
274 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php'; |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Get the URL for the next step's screen. |
|
279 | - * |
|
280 | - * @param string step slug (default: current step) |
|
281 | - * |
|
282 | - * @return string URL for next step if a next step exists. |
|
283 | - * Admin URL if it's the last step. |
|
284 | - * Empty string on failure. |
|
285 | - * @since 3.0.0 |
|
286 | - */ |
|
287 | - public function get_next_step_link( $step = '' ) { |
|
288 | - if ( ! $step ) { |
|
289 | - $step = $this->step; |
|
290 | - } |
|
291 | - |
|
292 | - $keys = array_keys( $this->steps ); |
|
293 | - if ( end( $keys ) === $step ) { |
|
294 | - return admin_url(); |
|
295 | - } |
|
296 | - |
|
297 | - $step_index = array_search( $step, $keys ); |
|
298 | - if ( false === $step_index ) { |
|
299 | - return ''; |
|
300 | - } |
|
301 | - |
|
302 | - return remove_query_arg('settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] )); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Setup maps api. |
|
307 | - * |
|
308 | - * @since 2.0.0 |
|
309 | - */ |
|
310 | - public function setup_business() { |
|
311 | - $next_url = $this->get_next_step_link(); |
|
312 | - $wizard = $this; |
|
313 | - $page = 'wpinv_settings_general_main'; |
|
314 | - $section = 'wpinv_settings_general_main'; |
|
315 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * Default Location settings. |
|
320 | - * |
|
321 | - * @since 2.0.0 |
|
322 | - */ |
|
323 | - public function setup_currency() { |
|
324 | - $next_url = $this->get_next_step_link(); |
|
325 | - $wizard = $this; |
|
326 | - $page = 'wpinv_settings_general_currency_section'; |
|
327 | - $section = 'wpinv_settings_general_currency_section'; |
|
328 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * Installation of recommended plugins. |
|
333 | - * |
|
334 | - * @since 1.0.0 |
|
335 | - */ |
|
336 | - public function setup_recommend() { |
|
337 | - $next_url = $this->get_next_step_link(); |
|
338 | - $recommended_plugins = self::get_recommend_wp_plugins(); |
|
339 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php'; |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * A list of recommended wp.org plugins. |
|
344 | - * @return array |
|
345 | - */ |
|
346 | - public static function get_recommend_wp_plugins(){ |
|
347 | - return array( |
|
348 | - 'ayecode-connect' => array( |
|
349 | - 'file' => 'ayecode-connect/ayecode-connect.php', |
|
350 | - 'url' => 'https://wordpress.org/plugins/ayecode-connect/', |
|
351 | - 'slug' => 'ayecode-connect', |
|
352 | - 'name' => 'AyeCode Connect', |
|
353 | - 'desc' => __( 'Documentation and Support from within your WordPress admin.', 'geodirectory' ), |
|
354 | - ), |
|
355 | - 'invoicing-quotes' => array( |
|
356 | - 'file' => 'invoicing-quotes/wpinv-quote.php', |
|
357 | - 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
|
358 | - 'slug' => 'invoicing-quotes', |
|
359 | - 'name' => 'Customer Quotes', |
|
360 | - 'desc' => __('Create & Send Quotes to Customers and have them accept and pay.','geodirectory'), |
|
361 | - ), |
|
362 | - 'userswp' => array( |
|
363 | - 'file' => 'userswp/userswp.php', |
|
364 | - 'url' => 'https://wordpress.org/plugins/userswp/', |
|
365 | - 'slug' => 'userswp', |
|
366 | - 'name' => 'UsersWP', |
|
367 | - 'desc' => __('Frontend user login and registration as well as slick profile pages.','geodirectory'), |
|
368 | - ), |
|
369 | - ); |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Dummy Data setup. |
|
374 | - * |
|
375 | - * @since 2.4.0 |
|
376 | - */ |
|
377 | - public function setup_payments() { |
|
378 | - $next_url = $this->get_next_step_link(); |
|
379 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php'; |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * Dummy data save. |
|
384 | - * |
|
385 | - * This is done via ajax so we just pass onto the next step. |
|
386 | - * |
|
387 | - * @since 2.0.0 |
|
388 | - */ |
|
389 | - public function setup_payments_save() { |
|
390 | - check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); |
|
391 | - wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) ); |
|
392 | - |
|
393 | - if ( ! empty( $_POST['paypal-email'] ) ) { |
|
394 | - wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) ); |
|
395 | - wpinv_update_option( 'paypal_active', 1 ); |
|
396 | - wpinv_update_option( 'paypal_sandbox', 0 ); |
|
397 | - } |
|
398 | - |
|
399 | - wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
|
400 | - exit; |
|
401 | - } |
|
402 | - |
|
403 | - /** |
|
404 | - * Final step. |
|
405 | - * |
|
406 | - * @since 2.0.0 |
|
407 | - */ |
|
408 | - public function setup_ready() { |
|
409 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php'; |
|
410 | - } |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Setup Wizard Footer. |
|
252 | + * |
|
253 | + * @since 2.4.0 |
|
254 | + */ |
|
255 | + public function display_footer() { |
|
256 | + |
|
257 | + if ( isset( $_GET['step'] ) ) { |
|
258 | + $next_url = esc_url( $this->get_next_step_link() ); |
|
259 | + $label = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' ); |
|
260 | + |
|
261 | + echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . $next_url . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . $label . '</a></p>'; |
|
262 | + } |
|
263 | + |
|
264 | + echo '</body></html>'; |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * Introduction step. |
|
269 | + * |
|
270 | + * @since 2.0.0 |
|
271 | + */ |
|
272 | + public function setup_introduction() { |
|
273 | + $next_url = $this->get_next_step_link(); |
|
274 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php'; |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Get the URL for the next step's screen. |
|
279 | + * |
|
280 | + * @param string step slug (default: current step) |
|
281 | + * |
|
282 | + * @return string URL for next step if a next step exists. |
|
283 | + * Admin URL if it's the last step. |
|
284 | + * Empty string on failure. |
|
285 | + * @since 3.0.0 |
|
286 | + */ |
|
287 | + public function get_next_step_link( $step = '' ) { |
|
288 | + if ( ! $step ) { |
|
289 | + $step = $this->step; |
|
290 | + } |
|
291 | + |
|
292 | + $keys = array_keys( $this->steps ); |
|
293 | + if ( end( $keys ) === $step ) { |
|
294 | + return admin_url(); |
|
295 | + } |
|
296 | + |
|
297 | + $step_index = array_search( $step, $keys ); |
|
298 | + if ( false === $step_index ) { |
|
299 | + return ''; |
|
300 | + } |
|
301 | + |
|
302 | + return remove_query_arg('settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] )); |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Setup maps api. |
|
307 | + * |
|
308 | + * @since 2.0.0 |
|
309 | + */ |
|
310 | + public function setup_business() { |
|
311 | + $next_url = $this->get_next_step_link(); |
|
312 | + $wizard = $this; |
|
313 | + $page = 'wpinv_settings_general_main'; |
|
314 | + $section = 'wpinv_settings_general_main'; |
|
315 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * Default Location settings. |
|
320 | + * |
|
321 | + * @since 2.0.0 |
|
322 | + */ |
|
323 | + public function setup_currency() { |
|
324 | + $next_url = $this->get_next_step_link(); |
|
325 | + $wizard = $this; |
|
326 | + $page = 'wpinv_settings_general_currency_section'; |
|
327 | + $section = 'wpinv_settings_general_currency_section'; |
|
328 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * Installation of recommended plugins. |
|
333 | + * |
|
334 | + * @since 1.0.0 |
|
335 | + */ |
|
336 | + public function setup_recommend() { |
|
337 | + $next_url = $this->get_next_step_link(); |
|
338 | + $recommended_plugins = self::get_recommend_wp_plugins(); |
|
339 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php'; |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * A list of recommended wp.org plugins. |
|
344 | + * @return array |
|
345 | + */ |
|
346 | + public static function get_recommend_wp_plugins(){ |
|
347 | + return array( |
|
348 | + 'ayecode-connect' => array( |
|
349 | + 'file' => 'ayecode-connect/ayecode-connect.php', |
|
350 | + 'url' => 'https://wordpress.org/plugins/ayecode-connect/', |
|
351 | + 'slug' => 'ayecode-connect', |
|
352 | + 'name' => 'AyeCode Connect', |
|
353 | + 'desc' => __( 'Documentation and Support from within your WordPress admin.', 'geodirectory' ), |
|
354 | + ), |
|
355 | + 'invoicing-quotes' => array( |
|
356 | + 'file' => 'invoicing-quotes/wpinv-quote.php', |
|
357 | + 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
|
358 | + 'slug' => 'invoicing-quotes', |
|
359 | + 'name' => 'Customer Quotes', |
|
360 | + 'desc' => __('Create & Send Quotes to Customers and have them accept and pay.','geodirectory'), |
|
361 | + ), |
|
362 | + 'userswp' => array( |
|
363 | + 'file' => 'userswp/userswp.php', |
|
364 | + 'url' => 'https://wordpress.org/plugins/userswp/', |
|
365 | + 'slug' => 'userswp', |
|
366 | + 'name' => 'UsersWP', |
|
367 | + 'desc' => __('Frontend user login and registration as well as slick profile pages.','geodirectory'), |
|
368 | + ), |
|
369 | + ); |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Dummy Data setup. |
|
374 | + * |
|
375 | + * @since 2.4.0 |
|
376 | + */ |
|
377 | + public function setup_payments() { |
|
378 | + $next_url = $this->get_next_step_link(); |
|
379 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php'; |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * Dummy data save. |
|
384 | + * |
|
385 | + * This is done via ajax so we just pass onto the next step. |
|
386 | + * |
|
387 | + * @since 2.0.0 |
|
388 | + */ |
|
389 | + public function setup_payments_save() { |
|
390 | + check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); |
|
391 | + wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) ); |
|
392 | + |
|
393 | + if ( ! empty( $_POST['paypal-email'] ) ) { |
|
394 | + wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) ); |
|
395 | + wpinv_update_option( 'paypal_active', 1 ); |
|
396 | + wpinv_update_option( 'paypal_sandbox', 0 ); |
|
397 | + } |
|
398 | + |
|
399 | + wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
|
400 | + exit; |
|
401 | + } |
|
402 | + |
|
403 | + /** |
|
404 | + * Final step. |
|
405 | + * |
|
406 | + * @since 2.0.0 |
|
407 | + */ |
|
408 | + public function setup_ready() { |
|
409 | + include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php'; |
|
410 | + } |
|
411 | 411 | |
412 | 412 | } |
413 | 413 |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @version 2.4.0 |
11 | 11 | * @info GetPaid Setup Wizard. |
12 | 12 | */ |
13 | -defined( 'ABSPATH' ) || exit; |
|
13 | +defined('ABSPATH') || exit; |
|
14 | 14 | |
15 | 15 | /** |
16 | 16 | * GetPaid_Admin_Setup_Wizard class. |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public function __construct() { |
46 | 46 | |
47 | - if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) { |
|
48 | - add_action( 'admin_menu', array( $this, 'add_menu' ) ); |
|
49 | - add_action( 'current_screen', array( $this, 'setup_wizard' ) ); |
|
47 | + if (apply_filters('getpaid_enable_setup_wizard', true) && wpinv_current_user_can_manage_invoicing()) { |
|
48 | + add_action('admin_menu', array($this, 'add_menu')); |
|
49 | + add_action('current_screen', array($this, 'setup_wizard')); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | * @since 2.4.0 |
58 | 58 | */ |
59 | 59 | public function add_menu() { |
60 | - add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' ); |
|
60 | + add_dashboard_page('', '', wpinv_get_capability(), 'gp-setup', ''); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function setup_wizard() { |
69 | 69 | |
70 | - if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) { |
|
70 | + if (isset($_GET['page']) && 'gp-setup' === $_GET['page']) { |
|
71 | 71 | $this->setup_globals(); |
72 | 72 | $this->maybe_save_current_step(); |
73 | 73 | $this->display_wizard(); |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | * @since 2.4.0 |
95 | 95 | */ |
96 | 96 | protected function maybe_save_current_step() { |
97 | - if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) { |
|
98 | - call_user_func( $this->steps[ $this->step ]['handler'], $this ); |
|
97 | + if (!empty($_POST['save_step']) && is_callable($this->steps[$this->step]['handler'])) { |
|
98 | + call_user_func($this->steps[$this->step]['handler'], $this); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
@@ -110,44 +110,44 @@ discard block |
||
110 | 110 | $steps = array( |
111 | 111 | |
112 | 112 | 'introduction' => array( |
113 | - 'name' => __( 'Introduction', 'invoicing' ), |
|
114 | - 'view' => array( $this, 'setup_introduction' ), |
|
113 | + 'name' => __('Introduction', 'invoicing'), |
|
114 | + 'view' => array($this, 'setup_introduction'), |
|
115 | 115 | 'handler' => '', |
116 | 116 | ), |
117 | 117 | |
118 | 118 | 'business_details' => array( |
119 | - 'name' => __( "Business Details", 'invoicing' ), |
|
120 | - 'view' => array( $this, 'setup_business' ), |
|
119 | + 'name' => __("Business Details", 'invoicing'), |
|
120 | + 'view' => array($this, 'setup_business'), |
|
121 | 121 | 'handler' => '', |
122 | 122 | ), |
123 | 123 | |
124 | 124 | 'currency' => array( |
125 | - 'name' => __( 'Currency', 'invoicing' ), |
|
126 | - 'view' => array( $this, 'setup_currency' ), |
|
125 | + 'name' => __('Currency', 'invoicing'), |
|
126 | + 'view' => array($this, 'setup_currency'), |
|
127 | 127 | 'handler' => '', |
128 | 128 | ), |
129 | 129 | |
130 | 130 | 'payments' => array( |
131 | - 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
132 | - 'view' => array( $this, 'setup_payments' ), |
|
133 | - 'handler' => array( $this, 'setup_payments_save' ), |
|
131 | + 'name' => __('Payment Gateways', 'invoicing'), |
|
132 | + 'view' => array($this, 'setup_payments'), |
|
133 | + 'handler' => array($this, 'setup_payments_save'), |
|
134 | 134 | ), |
135 | 135 | |
136 | 136 | 'recommend' => array( |
137 | - 'name' => __( 'Recommend', 'invoicing' ), |
|
138 | - 'view' => array( $this, 'setup_recommend' ), |
|
137 | + 'name' => __('Recommend', 'invoicing'), |
|
138 | + 'view' => array($this, 'setup_recommend'), |
|
139 | 139 | 'handler' => '', |
140 | 140 | ), |
141 | 141 | |
142 | 142 | 'next_steps' => array( |
143 | - 'name' => __( 'Get Paid', 'invoicing' ), |
|
144 | - 'view' => array( $this, 'setup_ready' ), |
|
143 | + 'name' => __('Get Paid', 'invoicing'), |
|
144 | + 'view' => array($this, 'setup_ready'), |
|
145 | 145 | 'handler' => '', |
146 | 146 | ), |
147 | 147 | |
148 | 148 | ); |
149 | 149 | |
150 | - return apply_filters( 'getpaid_setup_wizard_steps', $steps ); |
|
150 | + return apply_filters('getpaid_setup_wizard_steps', $steps); |
|
151 | 151 | |
152 | 152 | } |
153 | 153 | |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | protected function get_current_step() { |
161 | - $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : ''; |
|
162 | - return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) ); |
|
161 | + $step = isset($_GET['step']) ? sanitize_key($_GET['step']) : ''; |
|
162 | + return !empty($step) && in_array($step, array_keys($this->steps)) ? $step : current(array_keys($this->steps)); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -172,8 +172,8 @@ discard block |
||
172 | 172 | |
173 | 173 | $previous = false; |
174 | 174 | $current = $this->step; |
175 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
176 | - if ( $current === $step ) { |
|
175 | + foreach (array_keys($this->steps) as $step) { |
|
176 | + if ($current === $step) { |
|
177 | 177 | return $previous; |
178 | 178 | } |
179 | 179 | |
@@ -193,13 +193,13 @@ discard block |
||
193 | 193 | |
194 | 194 | $on_current = false; |
195 | 195 | $current = $this->step; |
196 | - foreach ( array_keys( $this->steps ) as $step ) { |
|
196 | + foreach (array_keys($this->steps) as $step) { |
|
197 | 197 | |
198 | - if ( $on_current ) { |
|
198 | + if ($on_current) { |
|
199 | 199 | return $step; |
200 | 200 | } |
201 | 201 | |
202 | - if ( $current === $step ) { |
|
202 | + if ($current === $step) { |
|
203 | 203 | return $on_current = true; |
204 | 204 | } |
205 | 205 | |
@@ -228,8 +228,8 @@ discard block |
||
228 | 228 | $steps = $this->steps; |
229 | 229 | $current = $this->step; |
230 | 230 | $next_step = $this->next_step; |
231 | - array_shift( $steps ); |
|
232 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php'; |
|
231 | + array_shift($steps); |
|
232 | + include plugin_dir_path(__FILE__) . 'views/wizard-header.php'; |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | ?> |
242 | 242 | <div class="gp-setup-content rowx mw-100 text-center mb-3"> |
243 | 243 | <div class="col-12 col-md-5 m-auto"> |
244 | - <?php call_user_func( $this->steps[ $this->step ]['view'], $this ); ?> |
|
244 | + <?php call_user_func($this->steps[$this->step]['view'], $this); ?> |
|
245 | 245 | </div> |
246 | 246 | </div> |
247 | 247 | <?php |
@@ -254,9 +254,9 @@ discard block |
||
254 | 254 | */ |
255 | 255 | public function display_footer() { |
256 | 256 | |
257 | - if ( isset( $_GET['step'] ) ) { |
|
258 | - $next_url = esc_url( $this->get_next_step_link() ); |
|
259 | - $label = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' ); |
|
257 | + if (isset($_GET['step'])) { |
|
258 | + $next_url = esc_url($this->get_next_step_link()); |
|
259 | + $label = $this->step == 'next_steps' ? __('Return to the WordPress Dashboard', 'invoicing') : __('Skip this step', 'invoicing'); |
|
260 | 260 | |
261 | 261 | echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . $next_url . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . $label . '</a></p>'; |
262 | 262 | } |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | */ |
272 | 272 | public function setup_introduction() { |
273 | 273 | $next_url = $this->get_next_step_link(); |
274 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php'; |
|
274 | + include plugin_dir_path(__FILE__) . 'views/wizard-introduction.php'; |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -284,22 +284,22 @@ discard block |
||
284 | 284 | * Empty string on failure. |
285 | 285 | * @since 3.0.0 |
286 | 286 | */ |
287 | - public function get_next_step_link( $step = '' ) { |
|
288 | - if ( ! $step ) { |
|
287 | + public function get_next_step_link($step = '') { |
|
288 | + if (!$step) { |
|
289 | 289 | $step = $this->step; |
290 | 290 | } |
291 | 291 | |
292 | - $keys = array_keys( $this->steps ); |
|
293 | - if ( end( $keys ) === $step ) { |
|
292 | + $keys = array_keys($this->steps); |
|
293 | + if (end($keys) === $step) { |
|
294 | 294 | return admin_url(); |
295 | 295 | } |
296 | 296 | |
297 | - $step_index = array_search( $step, $keys ); |
|
298 | - if ( false === $step_index ) { |
|
297 | + $step_index = array_search($step, $keys); |
|
298 | + if (false === $step_index) { |
|
299 | 299 | return ''; |
300 | 300 | } |
301 | 301 | |
302 | - return remove_query_arg('settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] )); |
|
302 | + return remove_query_arg('settings-updated', add_query_arg('step', $keys[$step_index + 1])); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | $wizard = $this; |
313 | 313 | $page = 'wpinv_settings_general_main'; |
314 | 314 | $section = 'wpinv_settings_general_main'; |
315 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
315 | + include plugin_dir_path(__FILE__) . 'views/wizard-settings.php'; |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | /** |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | $wizard = $this; |
326 | 326 | $page = 'wpinv_settings_general_currency_section'; |
327 | 327 | $section = 'wpinv_settings_general_currency_section'; |
328 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php'; |
|
328 | + include plugin_dir_path(__FILE__) . 'views/wizard-settings.php'; |
|
329 | 329 | } |
330 | 330 | |
331 | 331 | /** |
@@ -336,35 +336,35 @@ discard block |
||
336 | 336 | public function setup_recommend() { |
337 | 337 | $next_url = $this->get_next_step_link(); |
338 | 338 | $recommended_plugins = self::get_recommend_wp_plugins(); |
339 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php'; |
|
339 | + include plugin_dir_path(__FILE__) . 'views/wizard-plugins.php'; |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | /** |
343 | 343 | * A list of recommended wp.org plugins. |
344 | 344 | * @return array |
345 | 345 | */ |
346 | - public static function get_recommend_wp_plugins(){ |
|
346 | + public static function get_recommend_wp_plugins() { |
|
347 | 347 | return array( |
348 | 348 | 'ayecode-connect' => array( |
349 | 349 | 'file' => 'ayecode-connect/ayecode-connect.php', |
350 | 350 | 'url' => 'https://wordpress.org/plugins/ayecode-connect/', |
351 | 351 | 'slug' => 'ayecode-connect', |
352 | 352 | 'name' => 'AyeCode Connect', |
353 | - 'desc' => __( 'Documentation and Support from within your WordPress admin.', 'geodirectory' ), |
|
353 | + 'desc' => __('Documentation and Support from within your WordPress admin.', 'geodirectory'), |
|
354 | 354 | ), |
355 | 355 | 'invoicing-quotes' => array( |
356 | 356 | 'file' => 'invoicing-quotes/wpinv-quote.php', |
357 | 357 | 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
358 | 358 | 'slug' => 'invoicing-quotes', |
359 | 359 | 'name' => 'Customer Quotes', |
360 | - 'desc' => __('Create & Send Quotes to Customers and have them accept and pay.','geodirectory'), |
|
360 | + 'desc' => __('Create & Send Quotes to Customers and have them accept and pay.', 'geodirectory'), |
|
361 | 361 | ), |
362 | 362 | 'userswp' => array( |
363 | 363 | 'file' => 'userswp/userswp.php', |
364 | 364 | 'url' => 'https://wordpress.org/plugins/userswp/', |
365 | 365 | 'slug' => 'userswp', |
366 | 366 | 'name' => 'UsersWP', |
367 | - 'desc' => __('Frontend user login and registration as well as slick profile pages.','geodirectory'), |
|
367 | + 'desc' => __('Frontend user login and registration as well as slick profile pages.', 'geodirectory'), |
|
368 | 368 | ), |
369 | 369 | ); |
370 | 370 | } |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | */ |
377 | 377 | public function setup_payments() { |
378 | 378 | $next_url = $this->get_next_step_link(); |
379 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php'; |
|
379 | + include plugin_dir_path(__FILE__) . 'views/wizard-gateways.php'; |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | /** |
@@ -387,16 +387,16 @@ discard block |
||
387 | 387 | * @since 2.0.0 |
388 | 388 | */ |
389 | 389 | public function setup_payments_save() { |
390 | - check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); |
|
391 | - wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) ); |
|
390 | + check_admin_referer('getpaid-setup-wizard', 'getpaid-setup-wizard'); |
|
391 | + wpinv_update_option('manual_active', !empty($_POST['enable-manual-gateway'])); |
|
392 | 392 | |
393 | - if ( ! empty( $_POST['paypal-email'] ) ) { |
|
394 | - wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) ); |
|
395 | - wpinv_update_option( 'paypal_active', 1 ); |
|
396 | - wpinv_update_option( 'paypal_sandbox', 0 ); |
|
393 | + if (!empty($_POST['paypal-email'])) { |
|
394 | + wpinv_update_option('paypal_email', sanitize_email($_POST['paypal-email'])); |
|
395 | + wpinv_update_option('paypal_active', 1); |
|
396 | + wpinv_update_option('paypal_sandbox', 0); |
|
397 | 397 | } |
398 | 398 | |
399 | - wp_redirect( esc_url_raw( $this->get_next_step_link() ) ); |
|
399 | + wp_redirect(esc_url_raw($this->get_next_step_link())); |
|
400 | 400 | exit; |
401 | 401 | } |
402 | 402 | |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | * @since 2.0.0 |
407 | 407 | */ |
408 | 408 | public function setup_ready() { |
409 | - include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php'; |
|
409 | + include plugin_dir_path(__FILE__) . 'views/wizard-thank-you.php'; |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | } |
@@ -36,8 +36,11 @@ |
||
36 | 36 | 'getpaid-nonce' |
37 | 37 | ); ?>" |
38 | 38 | class="btn btn-sm btn-outline-primary"><?php _e( 'Connect', 'invoicing' ); ?></a> |
39 | - <?php else: ?> |
|
40 | - <span class="btn btn-sm btn-success"><?php _e( 'Connected', 'invoicing' ); ?></span> |
|
39 | + <?php else { |
|
40 | + : ?> |
|
41 | + <span class="btn btn-sm btn-success"><?php _e( 'Connected', 'invoicing' ); |
|
42 | +} |
|
43 | +?></span> |
|
41 | 44 | <?php endif; ?> |
42 | 45 | </li> |
43 | 46 |
@@ -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 | |
@@ -12,54 +12,54 @@ discard block |
||
12 | 12 | |
13 | 13 | <form method="post" class="text-center card-body"> |
14 | 14 | <div class="gp-wizard-payments"> |
15 | - <h2 class="gd-settings-title h3 "><?php _e( 'Gateway Setup', 'invoicing' ); ?></h2> |
|
16 | - <p><?php _e( 'Below are a few gateways that can be setup in a few seconds.', 'invoicing' ); ?> |
|
15 | + <h2 class="gd-settings-title h3 "><?php _e('Gateway Setup', 'invoicing'); ?></h2> |
|
16 | + <p><?php _e('Below are a few gateways that can be setup in a few seconds.', 'invoicing'); ?> |
|
17 | 17 | <br> |
18 | - <?php _e( 'We have 20+ Gateways that can be setup later.', 'invoicing' ); ?> |
|
18 | + <?php _e('We have 20+ Gateways that can be setup later.', 'invoicing'); ?> |
|
19 | 19 | </p> |
20 | 20 | |
21 | 21 | <ul class="list-group"> |
22 | 22 | |
23 | 23 | <li class="list-group-item d-flex justify-content-between align-items-center"> |
24 | - <span class="mr-auto"><img src="<?php echo esc_url( WPINV_PLUGIN_URL . 'assets/images/stripe-verified.svg' );?>" class="ml-n2" alt="Stripe"></span> |
|
25 | - <?php if ( false === wpinv_get_option( 'stripe_live_connect_account_id' ) ) : ?> |
|
24 | + <span class="mr-auto"><img src="<?php echo esc_url(WPINV_PLUGIN_URL . 'assets/images/stripe-verified.svg'); ?>" class="ml-n2" alt="Stripe"></span> |
|
25 | + <?php if (false === wpinv_get_option('stripe_live_connect_account_id')) : ?> |
|
26 | 26 | <a href="<?php echo wp_nonce_url( |
27 | 27 | add_query_arg( |
28 | 28 | array( |
29 | 29 | 'getpaid-admin-action' => 'connect_gateway', |
30 | 30 | 'plugin' => 'stripe', |
31 | - 'redirect' => urlencode( add_query_arg( 'step', 'payments' ) ), |
|
31 | + 'redirect' => urlencode(add_query_arg('step', 'payments')), |
|
32 | 32 | ), |
33 | 33 | admin_url() |
34 | 34 | ), |
35 | 35 | 'getpaid-nonce', |
36 | 36 | 'getpaid-nonce' |
37 | 37 | ); ?>" |
38 | - class="btn btn-sm btn-outline-primary"><?php _e( 'Connect', 'invoicing' ); ?></a> |
|
38 | + class="btn btn-sm btn-outline-primary"><?php _e('Connect', 'invoicing'); ?></a> |
|
39 | 39 | <?php else: ?> |
40 | - <span class="btn btn-sm btn-success"><?php _e( 'Connected', 'invoicing' ); ?></span> |
|
40 | + <span class="btn btn-sm btn-success"><?php _e('Connected', 'invoicing'); ?></span> |
|
41 | 41 | <?php endif; ?> |
42 | 42 | </li> |
43 | 43 | |
44 | 44 | <li class="list-group-item"> |
45 | 45 | <div class="d-flex justify-content-between align-items-center"> |
46 | 46 | <span class="mr-auto"> |
47 | - <img src="<?php echo esc_url( WPINV_PLUGIN_URL . 'assets/images/pp-logo-150px.webp' );?>" class="" alt="PayPal" height="25"> |
|
47 | + <img src="<?php echo esc_url(WPINV_PLUGIN_URL . 'assets/images/pp-logo-150px.webp'); ?>" class="" alt="PayPal" height="25"> |
|
48 | 48 | </span> |
49 | 49 | <a |
50 | 50 | href="#" |
51 | 51 | onclick="jQuery('.getpaid-setup-paypal-input').toggleClass('d-none'); return false;" |
52 | - class="getpaid-setup-paypal btn btn-sm btn-outline-primary"><?php _e( 'Set-up', 'invoicing' ); ?></a> |
|
52 | + class="getpaid-setup-paypal btn btn-sm btn-outline-primary"><?php _e('Set-up', 'invoicing'); ?></a> |
|
53 | 53 | </div> |
54 | 54 | <div class="mt-4 getpaid-setup-paypal-input d-none"> |
55 | - <input type="text" placeholder="<?php esc_attr_e( 'PayPal Email', 'invoicing' ); ?>" name="paypal-email" class="form-control" value="<?php echo esc_attr( wpinv_get_option( 'paypal_email' ) ); ?>"> |
|
55 | + <input type="text" placeholder="<?php esc_attr_e('PayPal Email', 'invoicing'); ?>" name="paypal-email" class="form-control" value="<?php echo esc_attr(wpinv_get_option('paypal_email')); ?>"> |
|
56 | 56 | </div> |
57 | 57 | </li> |
58 | 58 | |
59 | 59 | <li class="list-group-item d-flex justify-content-between align-items-center"> |
60 | - <span class="mr-auto"><?php _e( 'Test Gateway', 'invoicing' ); ?></span> |
|
60 | + <span class="mr-auto"><?php _e('Test Gateway', 'invoicing'); ?></span> |
|
61 | 61 | <div class="custom-control custom-switch"> |
62 | - <input type="checkbox" name="enable-manual-gateway" class="custom-control-input" id="enable-manual-gateway" <?php checked( wpinv_is_gateway_active( 'manual' ) ); ?>> |
|
62 | + <input type="checkbox" name="enable-manual-gateway" class="custom-control-input" id="enable-manual-gateway" <?php checked(wpinv_is_gateway_active('manual')); ?>> |
|
63 | 63 | <label class="custom-control-label" for="enable-manual-gateway"></label> |
64 | 64 | </div> |
65 | 65 | </li> |
@@ -68,10 +68,10 @@ discard block |
||
68 | 68 | </div> |
69 | 69 | |
70 | 70 | <p class="gp-setup-actions step text-center mt-4"> |
71 | - <input type="submit" class="btn btn-primary" value="<?php esc_attr_e( 'Continue', 'invoicing' ); ?>" /> |
|
71 | + <input type="submit" class="btn btn-primary" value="<?php esc_attr_e('Continue', 'invoicing'); ?>" /> |
|
72 | 72 | </p> |
73 | 73 | |
74 | - <?php getpaid_hidden_field( 'save_step', 1 ); ?> |
|
75 | - <?php wp_nonce_field( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); ?> |
|
74 | + <?php getpaid_hidden_field('save_step', 1); ?> |
|
75 | + <?php wp_nonce_field('getpaid-setup-wizard', 'getpaid-setup-wizard'); ?> |
|
76 | 76 | </form> |
77 | 77 | </div> |
@@ -4,78 +4,78 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | ?> |
10 | 10 | |
11 | 11 | <div class="card shadow-sm my-5"> |
12 | 12 | |
13 | 13 | <h1 class="h4 card-header bg-white border-bottom-0 pt-4 pb-1"> |
14 | - <?php esc_html_e( 'Welcome to the GetPaid Setup Wizard!', 'invoicing' ); ?> |
|
14 | + <?php esc_html_e('Welcome to the GetPaid Setup Wizard!', 'invoicing'); ?> |
|
15 | 15 | </h1> |
16 | 16 | |
17 | 17 | <div class="card-body text-muted "> |
18 | - <p><?php _e( 'Thank you for choosing GetPaid - The most Powerful Payments Plugin for WordPress', 'invoicing' ); ?></p> |
|
18 | + <p><?php _e('Thank you for choosing GetPaid - The most Powerful Payments Plugin for WordPress', 'invoicing'); ?></p> |
|
19 | 19 | <hr class="mt-4 pt-3 pb-0" /> |
20 | - <p class="small"><?php _e( 'This quick setup wizard will help you <b>configure the basic settings</b>. It’s <b>completely optional</b> and shouldn’t take longer than <b>five minutes</b>.', 'invoicing' ); ?></p> |
|
20 | + <p class="small"><?php _e('This quick setup wizard will help you <b>configure the basic settings</b>. It’s <b>completely optional</b> and shouldn’t take longer than <b>five minutes</b>.', 'invoicing'); ?></p> |
|
21 | 21 | </div> |
22 | 22 | |
23 | 23 | <div class="card-footer mb-0 bg-white gp-setup-actions step border-top-0"> |
24 | 24 | <a |
25 | - href="<?php echo esc_url( $next_url ); ?>" |
|
26 | - class="btn btn-primary button-next"><?php esc_html_e( "Let's go!", 'invoicing' ); ?></a> |
|
25 | + href="<?php echo esc_url($next_url); ?>" |
|
26 | + class="btn btn-primary button-next"><?php esc_html_e("Let's go!", 'invoicing'); ?></a> |
|
27 | 27 | <a |
28 | - href="<?php echo esc_url( admin_url() ); ?>" |
|
29 | - class="btn btn-link d-block mt-2 "><?php esc_html_e( 'Not right now', 'invoicing' ); ?></a> |
|
28 | + href="<?php echo esc_url(admin_url()); ?>" |
|
29 | + class="btn btn-link d-block mt-2 "><?php esc_html_e('Not right now', 'invoicing'); ?></a> |
|
30 | 30 | </div> |
31 | 31 | </div> |
32 | 32 | |
33 | 33 | <div class="card shadow-sm my-5 overflow-hidden"> |
34 | 34 | <h1 class="h4 card-header bg-white border-bottom-0 pt-4 pb-1"> |
35 | - <?php esc_html_e( 'GetPaid Features & Addons!', 'invoicing' ); ?> |
|
35 | + <?php esc_html_e('GetPaid Features & Addons!', 'invoicing'); ?> |
|
36 | 36 | </h1> |
37 | 37 | |
38 | 38 | <div class="card-body text-muted overflow-hidden"> |
39 | - <p><?php _e( 'Collect one time & recurring payments online within minutes. No complex setup required.', 'invoicing' ); ?></p> |
|
39 | + <p><?php _e('Collect one time & recurring payments online within minutes. No complex setup required.', 'invoicing'); ?></p> |
|
40 | 40 | <hr> |
41 | 41 | |
42 | 42 | <div class="row row-cols-2 text-left"> |
43 | 43 | <div class="col mt-3"> |
44 | 44 | <div class="media"> |
45 | - <img src="<?php echo WPINV_PLUGIN_URL . 'assets/images/buy.svg';?>" class="mr-3" alt="..."> |
|
45 | + <img src="<?php echo WPINV_PLUGIN_URL . 'assets/images/buy.svg'; ?>" class="mr-3" alt="..."> |
|
46 | 46 | <div class="media-body"> |
47 | - <h6 class="mt-0 font-weight-bold"><?php _e( 'GetPaid via Buy Now Buttons', 'invoicing' );?></h6> |
|
48 | - <small><?php _e( 'Sell via buy now buttons anywhere on your site', 'invoicing' );?></small> |
|
47 | + <h6 class="mt-0 font-weight-bold"><?php _e('GetPaid via Buy Now Buttons', 'invoicing'); ?></h6> |
|
48 | + <small><?php _e('Sell via buy now buttons anywhere on your site', 'invoicing'); ?></small> |
|
49 | 49 | </div> |
50 | 50 | </div> |
51 | 51 | </div> |
52 | 52 | |
53 | 53 | <div class="col mt-3"> |
54 | 54 | <div class="media"> |
55 | - <img src="<?php echo WPINV_PLUGIN_URL . 'assets/images/report.svg';?>" class="mr-3" alt="..."> |
|
55 | + <img src="<?php echo WPINV_PLUGIN_URL . 'assets/images/report.svg'; ?>" class="mr-3" alt="..."> |
|
56 | 56 | <div class="media-body"> |
57 | - <h6 class="mt-0 font-weight-bold"><?php _e( 'GetPaid via payment form', 'invoicing' );?></h6> |
|
58 | - <small><?php _e( 'Payment forms are conversion-optimized checkout forms', 'invoicing' );?></small> |
|
57 | + <h6 class="mt-0 font-weight-bold"><?php _e('GetPaid via payment form', 'invoicing'); ?></h6> |
|
58 | + <small><?php _e('Payment forms are conversion-optimized checkout forms', 'invoicing'); ?></small> |
|
59 | 59 | </div> |
60 | 60 | </div> |
61 | 61 | </div> |
62 | 62 | |
63 | 63 | <div class="col mt-3"> |
64 | 64 | <div class="media"> |
65 | - <img src="<?php echo WPINV_PLUGIN_URL . 'assets/images/invoices.svg';?>" class="mr-3" alt="..."> |
|
65 | + <img src="<?php echo WPINV_PLUGIN_URL . 'assets/images/invoices.svg'; ?>" class="mr-3" alt="..."> |
|
66 | 66 | <div class="media-body"> |
67 | - <h6 class="mt-0 font-weight-bold"><?php _e('GetPaid via Invoice','invoicing');?></h6> |
|
68 | - <small><?php _e('Create and send invoices for just about anything from the WordPress dashboard','invoicing');?></small> |
|
67 | + <h6 class="mt-0 font-weight-bold"><?php _e('GetPaid via Invoice', 'invoicing'); ?></h6> |
|
68 | + <small><?php _e('Create and send invoices for just about anything from the WordPress dashboard', 'invoicing'); ?></small> |
|
69 | 69 | </div> |
70 | 70 | </div> |
71 | 71 | </div> |
72 | 72 | |
73 | 73 | <div class="col mt-3"> |
74 | 74 | <div class="media"> |
75 | - <img src="<?php echo WPINV_PLUGIN_URL . 'assets/images/payment.svg';?>" class="mr-3" alt="..."> |
|
75 | + <img src="<?php echo WPINV_PLUGIN_URL . 'assets/images/payment.svg'; ?>" class="mr-3" alt="..."> |
|
76 | 76 | <div class="media-body"> |
77 | - <h6 class="mt-0 font-weight-bold"><?php _e('Affordable payment gateways','invoicing');?></h6> |
|
78 | - <small><?php _e('On average our gateways are over 66% cheaper than our competition','invoicing');?></small> |
|
77 | + <h6 class="mt-0 font-weight-bold"><?php _e('Affordable payment gateways', 'invoicing'); ?></h6> |
|
78 | + <small><?php _e('On average our gateways are over 66% cheaper than our competition', 'invoicing'); ?></small> |
|
79 | 79 | </div> |
80 | 80 | </div> |
81 | 81 | </div> |
@@ -86,51 +86,51 @@ discard block |
||
86 | 86 | <div class="mt-5"> |
87 | 87 | <a |
88 | 88 | href="https://wpgetpaid.com/features-list/" |
89 | - class="btn btn-primary"><?php esc_html_e( 'View All Features!', 'invoicing' ); ?></a> |
|
89 | + class="btn btn-primary"><?php esc_html_e('View All Features!', 'invoicing'); ?></a> |
|
90 | 90 | </div> |
91 | 91 | |
92 | 92 | <div class="mt-5 mx-n4 py-4" style="background:#eafaf6;"> |
93 | - <h4 class="mt-0 font-weight-bold text-dark mb-4"><?php _e( 'More with Membership!' , 'invoicing' );?></h4> |
|
93 | + <h4 class="mt-0 font-weight-bold text-dark mb-4"><?php _e('More with Membership!', 'invoicing'); ?></h4> |
|
94 | 94 | <div class="row row-cols-2 text-left px-5"> |
95 | 95 | |
96 | 96 | <div class="col"> |
97 | 97 | <ul class="list-unstyled"> |
98 | - <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e( 'PDF Invoices' , 'invoicing' );?></li> |
|
99 | - <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e( 'Gravity Forms' , 'invoicing' );?></li> |
|
100 | - <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e( 'Contact form 7' , 'invoicing' );?></li> |
|
101 | - <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e( 'AffiliateWP Integration' , 'invoicing' );?></li> |
|
98 | + <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e('PDF Invoices', 'invoicing'); ?></li> |
|
99 | + <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e('Gravity Forms', 'invoicing'); ?></li> |
|
100 | + <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e('Contact form 7', 'invoicing'); ?></li> |
|
101 | + <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e('AffiliateWP Integration', 'invoicing'); ?></li> |
|
102 | 102 | </ul> |
103 | 103 | </div> |
104 | 104 | |
105 | 105 | <div class="col"> |
106 | 106 | <ul class="list-unstyled"> |
107 | - <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e( 'Ninja forms' , 'invoicing' );?></li> |
|
108 | - <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e( 'Digital Downloads' , 'invoicing' );?></li> |
|
109 | - <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e( 'Wallet' , 'invoicing' );?></li> |
|
107 | + <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e('Ninja forms', 'invoicing'); ?></li> |
|
108 | + <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e('Digital Downloads', 'invoicing'); ?></li> |
|
109 | + <li class="my-2"><i class="far fa-check-circle text-success"></i> <?php _e('Wallet', 'invoicing'); ?></li> |
|
110 | 110 | </ul> |
111 | 111 | </div> |
112 | 112 | </div> |
113 | 113 | |
114 | - <h5 class="mt-4 font-weight-bold text-dark mb-3"><?php _e('Membership Starts From','invoicing');?></h5> |
|
115 | - <h1 class="mt-0 font-weight-bold text-dark mb-4 display-3"><?php esc_html_e( '$49', 'invoicing' ); ?></h1> |
|
114 | + <h5 class="mt-4 font-weight-bold text-dark mb-3"><?php _e('Membership Starts From', 'invoicing'); ?></h5> |
|
115 | + <h1 class="mt-0 font-weight-bold text-dark mb-4 display-3"><?php esc_html_e('$49', 'invoicing'); ?></h1> |
|
116 | 116 | |
117 | 117 | <div class="mt-2"> |
118 | 118 | <a |
119 | 119 | href="https://wpgetpaid.com/downloads/membership/" |
120 | - class="btn btn-primary"><?php esc_html_e( 'Buy Membership Now!', 'invoicing' ); ?></a> |
|
120 | + class="btn btn-primary"><?php esc_html_e('Buy Membership Now!', 'invoicing'); ?></a> |
|
121 | 121 | </div> |
122 | 122 | |
123 | 123 | </div> |
124 | 124 | |
125 | 125 | <div class="card-footer mb-0 bg-white gp-setup-actions step border-top-0"> |
126 | 126 | <a |
127 | - href="<?php echo esc_url( $next_url ); ?>" |
|
128 | - class="btn btn-outline-primary button-next"><?php esc_html_e( 'Launch the Setup Wizard!', 'invoicing' ); ?></a> |
|
127 | + href="<?php echo esc_url($next_url); ?>" |
|
128 | + class="btn btn-outline-primary button-next"><?php esc_html_e('Launch the Setup Wizard!', 'invoicing'); ?></a> |
|
129 | 129 | <a |
130 | 130 | href="https://docs.wpgetpaid.com/" |
131 | - class="btn btn-outline-primary ml-4"><?php esc_html_e( 'Documentation', 'invoicing' ); ?></a> |
|
131 | + class="btn btn-outline-primary ml-4"><?php esc_html_e('Documentation', 'invoicing'); ?></a> |
|
132 | 132 | <a |
133 | - href="<?php echo esc_url( admin_url() ); ?>" |
|
134 | - class="btn btn-link d-block mt-2 "><?php esc_html_e( 'Not right now', 'invoicing' ); ?></a> |
|
133 | + href="<?php echo esc_url(admin_url()); ?>" |
|
134 | + class="btn btn-link d-block mt-2 "><?php esc_html_e('Not right now', 'invoicing'); ?></a> |
|
135 | 135 | </div> |
136 | 136 | </div> |
@@ -12,145 +12,145 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Daily_Maintenance { |
14 | 14 | |
15 | - /** |
|
16 | - * Class constructor. |
|
17 | - */ |
|
18 | - public function __construct(){ |
|
19 | - |
|
20 | - // Clear deprecated events. |
|
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | - |
|
23 | - // (Maybe) schedule a cron that runs daily. |
|
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | - |
|
26 | - // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | - add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
31 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
32 | - |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Schedules a cron to run every day at 7 a.m |
|
37 | - * |
|
38 | - */ |
|
39 | - public function maybe_create_scheduled_event() { |
|
40 | - |
|
41 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
42 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
43 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
44 | - } |
|
45 | - |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Clears deprecated events. |
|
50 | - * |
|
51 | - */ |
|
52 | - public function maybe_clear_deprecated_events() { |
|
53 | - |
|
54 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
55 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
56 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
57 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
58 | - } |
|
59 | - |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Fires the old hook for backwards compatibility. |
|
64 | - * |
|
65 | - */ |
|
66 | - public function backwards_compat() { |
|
67 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Checks for subscriptions that are scheduled to renew. |
|
72 | - * |
|
73 | - */ |
|
74 | - public function check_renewing_subscriptions() { |
|
75 | - |
|
76 | - // Fetch subscriptions that expire today. |
|
77 | - $args = array( |
|
78 | - 'number' => -1, |
|
79 | - 'count_total' => false, |
|
80 | - 'status' => 'trialling active', |
|
81 | - 'date_expires_query' => array( |
|
82 | - array( |
|
83 | - 'year' => date( 'Y', current_time( 'timestamp' ) ), |
|
84 | - 'month' => date( 'n', current_time( 'timestamp' ) ), |
|
85 | - 'day' => date( 'j', current_time( 'timestamp' ) ), |
|
86 | - 'compare' => '=', |
|
87 | - ), |
|
88 | - ), |
|
89 | - ); |
|
90 | - |
|
91 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
92 | - |
|
93 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
94 | - |
|
95 | - /** @var WPInv_Subscription $subscription */ |
|
96 | - if ( $subscription->is_last_renewal() ) { |
|
97 | - $subscription->complete(); |
|
98 | - } else { |
|
99 | - do_action( 'getpaid_should_renew_subscription', $subscription ); |
|
100 | - } |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Expires expired subscriptions. |
|
108 | - * |
|
109 | - */ |
|
110 | - public function maybe_expire_subscriptions() { |
|
111 | - |
|
112 | - // Fetch expired subscriptions (skips those that expire today). |
|
113 | - $args = array( |
|
114 | - 'number' => -1, |
|
115 | - 'count_total' => false, |
|
116 | - 'status' => 'trialling active failing cancelled', |
|
117 | - 'date_expires_query' => array( |
|
118 | - 'before' => 'yesterday', |
|
119 | - 'inclusive' => false, |
|
120 | - ), |
|
121 | - ); |
|
122 | - |
|
123 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
124 | - |
|
125 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
126 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
127 | - $subscription->set_status( 'expired' ); |
|
128 | - $subscription->save(); |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Logs cron runs. |
|
136 | - * |
|
137 | - */ |
|
138 | - public function log_cron_run() { |
|
139 | - wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Updates GeoIP databases. |
|
144 | - * |
|
145 | - */ |
|
146 | - public function maybe_update_geoip_databases() { |
|
147 | - $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
148 | - |
|
149 | - if ( false === $updated ) { |
|
150 | - set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
151 | - do_action( 'getpaid_update_geoip_databases' ); |
|
152 | - } |
|
153 | - |
|
154 | - } |
|
15 | + /** |
|
16 | + * Class constructor. |
|
17 | + */ |
|
18 | + public function __construct(){ |
|
19 | + |
|
20 | + // Clear deprecated events. |
|
21 | + add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | + |
|
23 | + // (Maybe) schedule a cron that runs daily. |
|
24 | + add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | + |
|
26 | + // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | + add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | + add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | + add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
31 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
32 | + |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Schedules a cron to run every day at 7 a.m |
|
37 | + * |
|
38 | + */ |
|
39 | + public function maybe_create_scheduled_event() { |
|
40 | + |
|
41 | + if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
42 | + $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
43 | + wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
44 | + } |
|
45 | + |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Clears deprecated events. |
|
50 | + * |
|
51 | + */ |
|
52 | + public function maybe_clear_deprecated_events() { |
|
53 | + |
|
54 | + if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
55 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
56 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
57 | + update_option( 'wpinv_cleared_old_events', 1 ); |
|
58 | + } |
|
59 | + |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Fires the old hook for backwards compatibility. |
|
64 | + * |
|
65 | + */ |
|
66 | + public function backwards_compat() { |
|
67 | + do_action( 'wpinv_register_schedule_event_daily' ); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Checks for subscriptions that are scheduled to renew. |
|
72 | + * |
|
73 | + */ |
|
74 | + public function check_renewing_subscriptions() { |
|
75 | + |
|
76 | + // Fetch subscriptions that expire today. |
|
77 | + $args = array( |
|
78 | + 'number' => -1, |
|
79 | + 'count_total' => false, |
|
80 | + 'status' => 'trialling active', |
|
81 | + 'date_expires_query' => array( |
|
82 | + array( |
|
83 | + 'year' => date( 'Y', current_time( 'timestamp' ) ), |
|
84 | + 'month' => date( 'n', current_time( 'timestamp' ) ), |
|
85 | + 'day' => date( 'j', current_time( 'timestamp' ) ), |
|
86 | + 'compare' => '=', |
|
87 | + ), |
|
88 | + ), |
|
89 | + ); |
|
90 | + |
|
91 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
92 | + |
|
93 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
94 | + |
|
95 | + /** @var WPInv_Subscription $subscription */ |
|
96 | + if ( $subscription->is_last_renewal() ) { |
|
97 | + $subscription->complete(); |
|
98 | + } else { |
|
99 | + do_action( 'getpaid_should_renew_subscription', $subscription ); |
|
100 | + } |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Expires expired subscriptions. |
|
108 | + * |
|
109 | + */ |
|
110 | + public function maybe_expire_subscriptions() { |
|
111 | + |
|
112 | + // Fetch expired subscriptions (skips those that expire today). |
|
113 | + $args = array( |
|
114 | + 'number' => -1, |
|
115 | + 'count_total' => false, |
|
116 | + 'status' => 'trialling active failing cancelled', |
|
117 | + 'date_expires_query' => array( |
|
118 | + 'before' => 'yesterday', |
|
119 | + 'inclusive' => false, |
|
120 | + ), |
|
121 | + ); |
|
122 | + |
|
123 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
124 | + |
|
125 | + foreach ( $subscriptions->get_results() as $subscription ) { |
|
126 | + if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
127 | + $subscription->set_status( 'expired' ); |
|
128 | + $subscription->save(); |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Logs cron runs. |
|
136 | + * |
|
137 | + */ |
|
138 | + public function log_cron_run() { |
|
139 | + wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Updates GeoIP databases. |
|
144 | + * |
|
145 | + */ |
|
146 | + public function maybe_update_geoip_databases() { |
|
147 | + $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
148 | + |
|
149 | + if ( false === $updated ) { |
|
150 | + set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
151 | + do_action( 'getpaid_update_geoip_databases' ); |
|
152 | + } |
|
153 | + |
|
154 | + } |
|
155 | 155 | |
156 | 156 | } |
@@ -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 | * Daily maintenance class. |
@@ -15,20 +15,20 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * Class constructor. |
17 | 17 | */ |
18 | - public function __construct(){ |
|
18 | + public function __construct() { |
|
19 | 19 | |
20 | 20 | // Clear deprecated events. |
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
21 | + add_action('wp', array($this, 'maybe_clear_deprecated_events')); |
|
22 | 22 | |
23 | 23 | // (Maybe) schedule a cron that runs daily. |
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
24 | + add_action('wp', array($this, 'maybe_create_scheduled_event')); |
|
25 | 25 | |
26 | 26 | // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | - add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) ); |
|
31 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) ); |
|
27 | + add_action('getpaid_daily_maintenance', array($this, 'log_cron_run')); |
|
28 | + add_action('getpaid_daily_maintenance', array($this, 'backwards_compat')); |
|
29 | + add_action('getpaid_daily_maintenance', array($this, 'maybe_expire_subscriptions')); |
|
30 | + add_action('getpaid_daily_maintenance', array($this, 'check_renewing_subscriptions')); |
|
31 | + add_action('getpaid_daily_maintenance', array($this, 'maybe_update_geoip_databases')); |
|
32 | 32 | |
33 | 33 | } |
34 | 34 | |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function maybe_create_scheduled_event() { |
40 | 40 | |
41 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
42 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
43 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
41 | + if (!wp_next_scheduled('getpaid_daily_maintenance')) { |
|
42 | + $timestamp = strtotime('tomorrow 07:00:00', current_time('timestamp')); |
|
43 | + wp_schedule_event($timestamp, 'daily', 'getpaid_daily_maintenance'); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | } |
@@ -51,10 +51,10 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function maybe_clear_deprecated_events() { |
53 | 53 | |
54 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
55 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
56 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
57 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
54 | + if (!get_option('wpinv_cleared_old_events')) { |
|
55 | + wp_clear_scheduled_hook('wpinv_register_schedule_event_twicedaily'); |
|
56 | + wp_clear_scheduled_hook('wpinv_register_schedule_event_daily'); |
|
57 | + update_option('wpinv_cleared_old_events', 1); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * |
65 | 65 | */ |
66 | 66 | public function backwards_compat() { |
67 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
67 | + do_action('wpinv_register_schedule_event_daily'); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -74,29 +74,29 @@ discard block |
||
74 | 74 | public function check_renewing_subscriptions() { |
75 | 75 | |
76 | 76 | // Fetch subscriptions that expire today. |
77 | - $args = array( |
|
77 | + $args = array( |
|
78 | 78 | 'number' => -1, |
79 | 79 | 'count_total' => false, |
80 | 80 | 'status' => 'trialling active', |
81 | 81 | 'date_expires_query' => array( |
82 | 82 | array( |
83 | - 'year' => date( 'Y', current_time( 'timestamp' ) ), |
|
84 | - 'month' => date( 'n', current_time( 'timestamp' ) ), |
|
85 | - 'day' => date( 'j', current_time( 'timestamp' ) ), |
|
83 | + 'year' => date('Y', current_time('timestamp')), |
|
84 | + 'month' => date('n', current_time('timestamp')), |
|
85 | + 'day' => date('j', current_time('timestamp')), |
|
86 | 86 | 'compare' => '=', |
87 | 87 | ), |
88 | 88 | ), |
89 | 89 | ); |
90 | 90 | |
91 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
91 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
92 | 92 | |
93 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
93 | + foreach ($subscriptions->get_results() as $subscription) { |
|
94 | 94 | |
95 | 95 | /** @var WPInv_Subscription $subscription */ |
96 | - if ( $subscription->is_last_renewal() ) { |
|
96 | + if ($subscription->is_last_renewal()) { |
|
97 | 97 | $subscription->complete(); |
98 | 98 | } else { |
99 | - do_action( 'getpaid_should_renew_subscription', $subscription ); |
|
99 | + do_action('getpaid_should_renew_subscription', $subscription); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | public function maybe_expire_subscriptions() { |
111 | 111 | |
112 | 112 | // Fetch expired subscriptions (skips those that expire today). |
113 | - $args = array( |
|
113 | + $args = array( |
|
114 | 114 | 'number' => -1, |
115 | 115 | 'count_total' => false, |
116 | 116 | 'status' => 'trialling active failing cancelled', |
@@ -120,11 +120,11 @@ discard block |
||
120 | 120 | ), |
121 | 121 | ); |
122 | 122 | |
123 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
123 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
124 | 124 | |
125 | - foreach ( $subscriptions->get_results() as $subscription ) { |
|
126 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) { |
|
127 | - $subscription->set_status( 'expired' ); |
|
125 | + foreach ($subscriptions->get_results() as $subscription) { |
|
126 | + if (apply_filters('getpaid_daily_maintenance_should_expire_subscription', false, $subscription)) { |
|
127 | + $subscription->set_status('expired'); |
|
128 | 128 | $subscription->save(); |
129 | 129 | } |
130 | 130 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * |
137 | 137 | */ |
138 | 138 | public function log_cron_run() { |
139 | - wpinv_error_log( 'GetPaid Daily Cron', false ); |
|
139 | + wpinv_error_log('GetPaid Daily Cron', false); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -144,11 +144,11 @@ discard block |
||
144 | 144 | * |
145 | 145 | */ |
146 | 146 | public function maybe_update_geoip_databases() { |
147 | - $updated = get_transient( 'getpaid_updated_geoip_databases' ); |
|
147 | + $updated = get_transient('getpaid_updated_geoip_databases'); |
|
148 | 148 | |
149 | - if ( false === $updated ) { |
|
150 | - set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS ); |
|
151 | - do_action( 'getpaid_update_geoip_databases' ); |
|
149 | + if (false === $updated) { |
|
150 | + set_transient('getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS); |
|
151 | + do_action('getpaid_update_geoip_databases'); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * Bail if we are not in WP. |
14 | 14 | */ |
15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
16 | - exit; |
|
16 | + exit; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -21,300 +21,300 @@ discard block |
||
21 | 21 | */ |
22 | 22 | if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
23 | 23 | |
24 | - /** |
|
25 | - * A Class to be able to change settings for Font Awesome. |
|
26 | - * |
|
27 | - * Class WP_Font_Awesome_Settings |
|
28 | - * @since 1.0.10 Now able to pass wp.org theme check. |
|
29 | - * @since 1.0.11 Font Awesome Pro now supported. |
|
30 | - * @since 1.0.11 Font Awesome Kits now supported. |
|
31 | - * @since 1.0.13 RTL language support added. |
|
32 | - * @ver 1.0.13 |
|
33 | - * @todo decide how to implement textdomain |
|
34 | - */ |
|
35 | - class WP_Font_Awesome_Settings { |
|
36 | - |
|
37 | - /** |
|
38 | - * Class version version. |
|
39 | - * |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - public $version = '1.0.13'; |
|
43 | - |
|
44 | - /** |
|
45 | - * Class textdomain. |
|
46 | - * |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - public $textdomain = 'font-awesome-settings'; |
|
50 | - |
|
51 | - /** |
|
52 | - * Latest version of Font Awesome at time of publish published. |
|
53 | - * |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - public $latest = "5.8.2"; |
|
57 | - |
|
58 | - /** |
|
59 | - * The title. |
|
60 | - * |
|
61 | - * @var string |
|
62 | - */ |
|
63 | - public $name = 'Font Awesome'; |
|
64 | - |
|
65 | - /** |
|
66 | - * Holds the settings values. |
|
67 | - * |
|
68 | - * @var array |
|
69 | - */ |
|
70 | - private $settings; |
|
71 | - |
|
72 | - /** |
|
73 | - * WP_Font_Awesome_Settings instance. |
|
74 | - * |
|
75 | - * @access private |
|
76 | - * @since 1.0.0 |
|
77 | - * @var WP_Font_Awesome_Settings There can be only one! |
|
78 | - */ |
|
79 | - private static $instance = null; |
|
80 | - |
|
81 | - /** |
|
82 | - * Main WP_Font_Awesome_Settings Instance. |
|
83 | - * |
|
84 | - * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
85 | - * |
|
86 | - * @since 1.0.0 |
|
87 | - * @static |
|
88 | - * @return WP_Font_Awesome_Settings - Main instance. |
|
89 | - */ |
|
90 | - public static function instance() { |
|
91 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
92 | - self::$instance = new WP_Font_Awesome_Settings; |
|
93 | - |
|
94 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
95 | - |
|
96 | - if ( is_admin() ) { |
|
97 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
98 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
99 | - } |
|
100 | - |
|
101 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
102 | - } |
|
103 | - |
|
104 | - return self::$instance; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Initiate the settings and add the required action hooks. |
|
109 | - * |
|
110 | - * @since 1.0.8 Settings name wrong - FIXED |
|
111 | - */ |
|
112 | - public function init() { |
|
113 | - $this->settings = $this->get_settings(); |
|
114 | - |
|
115 | - if ( $this->settings['type'] == 'CSS' ) { |
|
116 | - |
|
117 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
118 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
119 | - } |
|
120 | - |
|
121 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
122 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
123 | - } |
|
124 | - |
|
125 | - } else { |
|
126 | - |
|
127 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
128 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
129 | - } |
|
130 | - |
|
131 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
132 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
133 | - } |
|
134 | - } |
|
135 | - |
|
136 | - // remove font awesome if set to do so |
|
137 | - if ( $this->settings['dequeue'] == '1' ) { |
|
138 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
139 | - } |
|
140 | - |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Adds the Font Awesome styles. |
|
145 | - */ |
|
146 | - public function enqueue_style() { |
|
147 | - // build url |
|
148 | - $url = $this->get_url(); |
|
149 | - |
|
150 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
151 | - wp_register_style( 'font-awesome', $url, array(), null ); |
|
152 | - wp_enqueue_style( 'font-awesome' ); |
|
153 | - |
|
154 | - // RTL language support CSS. |
|
155 | - if ( is_rtl() ) { |
|
156 | - wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
157 | - } |
|
158 | - |
|
159 | - if ( $this->settings['shims'] ) { |
|
160 | - $url = $this->get_url( true ); |
|
161 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
162 | - wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
163 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
164 | - } |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Adds the Font Awesome JS. |
|
169 | - */ |
|
170 | - public function enqueue_scripts() { |
|
171 | - // build url |
|
172 | - $url = $this->get_url(); |
|
173 | - |
|
174 | - $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
175 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
176 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
177 | - wp_enqueue_script( 'font-awesome' ); |
|
178 | - |
|
179 | - if ( $this->settings['shims'] ) { |
|
180 | - $url = $this->get_url( true ); |
|
181 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
182 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
183 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
184 | - } |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Get the url of the Font Awesome files. |
|
189 | - * |
|
190 | - * @param bool $shims If this is a shim file or not. |
|
191 | - * |
|
192 | - * @return string The url to the file. |
|
193 | - */ |
|
194 | - public function get_url( $shims = false ) { |
|
195 | - $script = $shims ? 'v4-shims' : 'all'; |
|
196 | - $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
197 | - $type = $this->settings['type']; |
|
198 | - $version = $this->settings['version']; |
|
199 | - $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
200 | - $url = ''; |
|
201 | - |
|
202 | - if ( $type == 'KIT' && $kit_url ) { |
|
203 | - if ( $shims ) { |
|
204 | - // if its a kit then we don't add shims here |
|
205 | - return ''; |
|
206 | - } |
|
207 | - $url .= $kit_url; // CDN |
|
208 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
209 | - } else { |
|
210 | - $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
211 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
212 | - $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
213 | - $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
214 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
215 | - } |
|
216 | - |
|
217 | - return $url; |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
222 | - * |
|
223 | - * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
224 | - * |
|
225 | - * @param $url |
|
226 | - * @param $original_url |
|
227 | - * @param $_context |
|
228 | - * |
|
229 | - * @return string The filtered url. |
|
230 | - */ |
|
231 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
232 | - |
|
233 | - if ( $_context == 'display' |
|
234 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
235 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
236 | - ) {// it's a font-awesome-url (probably) |
|
237 | - |
|
238 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
239 | - if ( $this->settings['type'] == 'JS' ) { |
|
240 | - if ( $this->settings['js-pseudo'] ) { |
|
241 | - $url .= "' data-search-pseudo-elements defer='defer"; |
|
242 | - } else { |
|
243 | - $url .= "' defer='defer"; |
|
244 | - } |
|
245 | - } |
|
246 | - } else { |
|
247 | - $url = ''; // removing the url removes the file |
|
248 | - } |
|
249 | - |
|
250 | - } |
|
251 | - |
|
252 | - return $url; |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Register the database settings with WordPress. |
|
257 | - */ |
|
258 | - public function register_settings() { |
|
259 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Add the WordPress settings menu item. |
|
264 | - * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
265 | - */ |
|
266 | - public function menu_item() { |
|
267 | - $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
268 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
269 | - $this, |
|
270 | - 'settings_page' |
|
271 | - ) ); |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Get the current Font Awesome output settings. |
|
276 | - * |
|
277 | - * @return array The array of settings. |
|
278 | - */ |
|
279 | - public function get_settings() { |
|
280 | - |
|
281 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
282 | - |
|
283 | - $defaults = array( |
|
284 | - 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
285 | - 'version' => '', // latest |
|
286 | - 'enqueue' => '', // front and backend |
|
287 | - 'shims' => '0', // default OFF now in 2020 |
|
288 | - 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
289 | - 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
290 | - 'pro' => '0', // if pro CDN url should be used |
|
291 | - 'kit-url' => '', // the kit url |
|
292 | - ); |
|
293 | - |
|
294 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
295 | - |
|
296 | - /** |
|
297 | - * Filter the Font Awesome settings. |
|
298 | - * |
|
299 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
300 | - */ |
|
301 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * The settings page html output. |
|
307 | - */ |
|
308 | - public function settings_page() { |
|
309 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
310 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
311 | - } |
|
312 | - |
|
313 | - // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
|
314 | - if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
315 | - $this->get_latest_version( $force_api = true ); |
|
316 | - } |
|
317 | - ?> |
|
24 | + /** |
|
25 | + * A Class to be able to change settings for Font Awesome. |
|
26 | + * |
|
27 | + * Class WP_Font_Awesome_Settings |
|
28 | + * @since 1.0.10 Now able to pass wp.org theme check. |
|
29 | + * @since 1.0.11 Font Awesome Pro now supported. |
|
30 | + * @since 1.0.11 Font Awesome Kits now supported. |
|
31 | + * @since 1.0.13 RTL language support added. |
|
32 | + * @ver 1.0.13 |
|
33 | + * @todo decide how to implement textdomain |
|
34 | + */ |
|
35 | + class WP_Font_Awesome_Settings { |
|
36 | + |
|
37 | + /** |
|
38 | + * Class version version. |
|
39 | + * |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + public $version = '1.0.13'; |
|
43 | + |
|
44 | + /** |
|
45 | + * Class textdomain. |
|
46 | + * |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + public $textdomain = 'font-awesome-settings'; |
|
50 | + |
|
51 | + /** |
|
52 | + * Latest version of Font Awesome at time of publish published. |
|
53 | + * |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + public $latest = "5.8.2"; |
|
57 | + |
|
58 | + /** |
|
59 | + * The title. |
|
60 | + * |
|
61 | + * @var string |
|
62 | + */ |
|
63 | + public $name = 'Font Awesome'; |
|
64 | + |
|
65 | + /** |
|
66 | + * Holds the settings values. |
|
67 | + * |
|
68 | + * @var array |
|
69 | + */ |
|
70 | + private $settings; |
|
71 | + |
|
72 | + /** |
|
73 | + * WP_Font_Awesome_Settings instance. |
|
74 | + * |
|
75 | + * @access private |
|
76 | + * @since 1.0.0 |
|
77 | + * @var WP_Font_Awesome_Settings There can be only one! |
|
78 | + */ |
|
79 | + private static $instance = null; |
|
80 | + |
|
81 | + /** |
|
82 | + * Main WP_Font_Awesome_Settings Instance. |
|
83 | + * |
|
84 | + * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
85 | + * |
|
86 | + * @since 1.0.0 |
|
87 | + * @static |
|
88 | + * @return WP_Font_Awesome_Settings - Main instance. |
|
89 | + */ |
|
90 | + public static function instance() { |
|
91 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
92 | + self::$instance = new WP_Font_Awesome_Settings; |
|
93 | + |
|
94 | + add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
95 | + |
|
96 | + if ( is_admin() ) { |
|
97 | + add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
98 | + add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
99 | + } |
|
100 | + |
|
101 | + do_action( 'wp_font_awesome_settings_loaded' ); |
|
102 | + } |
|
103 | + |
|
104 | + return self::$instance; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Initiate the settings and add the required action hooks. |
|
109 | + * |
|
110 | + * @since 1.0.8 Settings name wrong - FIXED |
|
111 | + */ |
|
112 | + public function init() { |
|
113 | + $this->settings = $this->get_settings(); |
|
114 | + |
|
115 | + if ( $this->settings['type'] == 'CSS' ) { |
|
116 | + |
|
117 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
118 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
119 | + } |
|
120 | + |
|
121 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
122 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
123 | + } |
|
124 | + |
|
125 | + } else { |
|
126 | + |
|
127 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
128 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
129 | + } |
|
130 | + |
|
131 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
132 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
133 | + } |
|
134 | + } |
|
135 | + |
|
136 | + // remove font awesome if set to do so |
|
137 | + if ( $this->settings['dequeue'] == '1' ) { |
|
138 | + add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
139 | + } |
|
140 | + |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Adds the Font Awesome styles. |
|
145 | + */ |
|
146 | + public function enqueue_style() { |
|
147 | + // build url |
|
148 | + $url = $this->get_url(); |
|
149 | + |
|
150 | + wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
151 | + wp_register_style( 'font-awesome', $url, array(), null ); |
|
152 | + wp_enqueue_style( 'font-awesome' ); |
|
153 | + |
|
154 | + // RTL language support CSS. |
|
155 | + if ( is_rtl() ) { |
|
156 | + wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
157 | + } |
|
158 | + |
|
159 | + if ( $this->settings['shims'] ) { |
|
160 | + $url = $this->get_url( true ); |
|
161 | + wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
162 | + wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
163 | + wp_enqueue_style( 'font-awesome-shims' ); |
|
164 | + } |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Adds the Font Awesome JS. |
|
169 | + */ |
|
170 | + public function enqueue_scripts() { |
|
171 | + // build url |
|
172 | + $url = $this->get_url(); |
|
173 | + |
|
174 | + $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
175 | + call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
176 | + wp_register_script( 'font-awesome', $url, array(), null ); |
|
177 | + wp_enqueue_script( 'font-awesome' ); |
|
178 | + |
|
179 | + if ( $this->settings['shims'] ) { |
|
180 | + $url = $this->get_url( true ); |
|
181 | + call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
182 | + wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
183 | + wp_enqueue_script( 'font-awesome-shims' ); |
|
184 | + } |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Get the url of the Font Awesome files. |
|
189 | + * |
|
190 | + * @param bool $shims If this is a shim file or not. |
|
191 | + * |
|
192 | + * @return string The url to the file. |
|
193 | + */ |
|
194 | + public function get_url( $shims = false ) { |
|
195 | + $script = $shims ? 'v4-shims' : 'all'; |
|
196 | + $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
197 | + $type = $this->settings['type']; |
|
198 | + $version = $this->settings['version']; |
|
199 | + $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
200 | + $url = ''; |
|
201 | + |
|
202 | + if ( $type == 'KIT' && $kit_url ) { |
|
203 | + if ( $shims ) { |
|
204 | + // if its a kit then we don't add shims here |
|
205 | + return ''; |
|
206 | + } |
|
207 | + $url .= $kit_url; // CDN |
|
208 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
209 | + } else { |
|
210 | + $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
211 | + $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
212 | + $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
213 | + $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
214 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
215 | + } |
|
216 | + |
|
217 | + return $url; |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
222 | + * |
|
223 | + * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
224 | + * |
|
225 | + * @param $url |
|
226 | + * @param $original_url |
|
227 | + * @param $_context |
|
228 | + * |
|
229 | + * @return string The filtered url. |
|
230 | + */ |
|
231 | + public function remove_font_awesome( $url, $original_url, $_context ) { |
|
232 | + |
|
233 | + if ( $_context == 'display' |
|
234 | + && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
235 | + && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
236 | + ) {// it's a font-awesome-url (probably) |
|
237 | + |
|
238 | + if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
239 | + if ( $this->settings['type'] == 'JS' ) { |
|
240 | + if ( $this->settings['js-pseudo'] ) { |
|
241 | + $url .= "' data-search-pseudo-elements defer='defer"; |
|
242 | + } else { |
|
243 | + $url .= "' defer='defer"; |
|
244 | + } |
|
245 | + } |
|
246 | + } else { |
|
247 | + $url = ''; // removing the url removes the file |
|
248 | + } |
|
249 | + |
|
250 | + } |
|
251 | + |
|
252 | + return $url; |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Register the database settings with WordPress. |
|
257 | + */ |
|
258 | + public function register_settings() { |
|
259 | + register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Add the WordPress settings menu item. |
|
264 | + * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
265 | + */ |
|
266 | + public function menu_item() { |
|
267 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
268 | + call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
269 | + $this, |
|
270 | + 'settings_page' |
|
271 | + ) ); |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Get the current Font Awesome output settings. |
|
276 | + * |
|
277 | + * @return array The array of settings. |
|
278 | + */ |
|
279 | + public function get_settings() { |
|
280 | + |
|
281 | + $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
282 | + |
|
283 | + $defaults = array( |
|
284 | + 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
285 | + 'version' => '', // latest |
|
286 | + 'enqueue' => '', // front and backend |
|
287 | + 'shims' => '0', // default OFF now in 2020 |
|
288 | + 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
289 | + 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
290 | + 'pro' => '0', // if pro CDN url should be used |
|
291 | + 'kit-url' => '', // the kit url |
|
292 | + ); |
|
293 | + |
|
294 | + $settings = wp_parse_args( $db_settings, $defaults ); |
|
295 | + |
|
296 | + /** |
|
297 | + * Filter the Font Awesome settings. |
|
298 | + * |
|
299 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
300 | + */ |
|
301 | + return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * The settings page html output. |
|
307 | + */ |
|
308 | + public function settings_page() { |
|
309 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
310 | + wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
311 | + } |
|
312 | + |
|
313 | + // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
|
314 | + if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
315 | + $this->get_latest_version( $force_api = true ); |
|
316 | + } |
|
317 | + ?> |
|
318 | 318 | <style> |
319 | 319 | .wpfas-kit-show { |
320 | 320 | display: none; |
@@ -332,10 +332,10 @@ discard block |
||
332 | 332 | <h1><?php echo $this->name; ?></h1> |
333 | 333 | <form method="post" action="options.php"> |
334 | 334 | <?php |
335 | - settings_fields( 'wp-font-awesome-settings' ); |
|
336 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
337 | - $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
|
338 | - ?> |
|
335 | + settings_fields( 'wp-font-awesome-settings' ); |
|
336 | + do_settings_sections( 'wp-font-awesome-settings' ); |
|
337 | + $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
|
338 | + ?> |
|
339 | 339 | <table class="form-table wpfas-table-settings <?php echo esc_attr( $kit_set ); ?>"> |
340 | 340 | <tr valign="top"> |
341 | 341 | <th scope="row"><label |
@@ -361,12 +361,12 @@ discard block |
||
361 | 361 | value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" |
362 | 362 | placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
363 | 363 | <span><?php |
364 | - echo sprintf( |
|
365 | - __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
366 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
367 | - '</a>' |
|
368 | - ); |
|
369 | - ?></span> |
|
364 | + echo sprintf( |
|
365 | + __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
366 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
367 | + '</a>' |
|
368 | + ); |
|
369 | + ?></span> |
|
370 | 370 | </td> |
371 | 371 | </tr> |
372 | 372 | |
@@ -426,14 +426,14 @@ discard block |
||
426 | 426 | <input type="checkbox" name="wp-font-awesome-settings[pro]" |
427 | 427 | value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro"/> |
428 | 428 | <span><?php |
429 | - echo sprintf( |
|
430 | - __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
431 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>', |
|
432 | - '</a>', |
|
433 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>', |
|
434 | - '</a>' |
|
435 | - ); |
|
436 | - ?></span> |
|
429 | + echo sprintf( |
|
430 | + __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
431 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>', |
|
432 | + '</a>', |
|
433 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>', |
|
434 | + '</a>' |
|
435 | + ); |
|
436 | + ?></span> |
|
437 | 437 | </td> |
438 | 438 | </tr> |
439 | 439 | |
@@ -476,100 +476,100 @@ discard block |
||
476 | 476 | |
477 | 477 | </table> |
478 | 478 | <?php |
479 | - submit_button(); |
|
480 | - ?> |
|
479 | + submit_button(); |
|
480 | + ?> |
|
481 | 481 | </form> |
482 | 482 | |
483 | 483 | <div id="wpfas-version"><?php echo $this->version; ?></div> |
484 | 484 | </div> |
485 | 485 | |
486 | 486 | <?php |
487 | - } |
|
488 | - |
|
489 | - /** |
|
490 | - * Check a version number is valid and if so return it or else return an empty string. |
|
491 | - * |
|
492 | - * @param $version string The version number to check. |
|
493 | - * |
|
494 | - * @since 1.0.6 |
|
495 | - * |
|
496 | - * @return string Either a valid version number or an empty string. |
|
497 | - */ |
|
498 | - public function validate_version_number( $version ) { |
|
499 | - |
|
500 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
501 | - // valid |
|
502 | - } else { |
|
503 | - $version = '';// not validated |
|
504 | - } |
|
505 | - |
|
506 | - return $version; |
|
507 | - } |
|
508 | - |
|
509 | - |
|
510 | - /** |
|
511 | - * Get the latest version of Font Awesome. |
|
512 | - * |
|
513 | - * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours. |
|
514 | - * |
|
515 | - * @since 1.0.7 |
|
516 | - * @return mixed|string The latest version number found. |
|
517 | - */ |
|
518 | - public function get_latest_version( $force_api = false ) { |
|
519 | - $latest_version = $this->latest; |
|
520 | - |
|
521 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
522 | - |
|
523 | - if ( $cache === false || $force_api ) { // its not set |
|
524 | - $api_ver = $this->get_latest_version_from_api(); |
|
525 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
526 | - $latest_version = $api_ver; |
|
527 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
528 | - } |
|
529 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
530 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
531 | - $latest_version = $cache; |
|
532 | - } |
|
533 | - } |
|
534 | - |
|
535 | - return $latest_version; |
|
536 | - } |
|
537 | - |
|
538 | - /** |
|
539 | - * Get the latest Font Awesome version from the github API. |
|
540 | - * |
|
541 | - * @since 1.0.7 |
|
542 | - * @return string The latest version number or `0` on API fail. |
|
543 | - */ |
|
544 | - public function get_latest_version_from_api() { |
|
545 | - $version = "0"; |
|
546 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
547 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
548 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
549 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
550 | - $version = $api_response['tag_name']; |
|
551 | - } |
|
552 | - } |
|
553 | - |
|
554 | - return $version; |
|
555 | - } |
|
556 | - |
|
557 | - /** |
|
558 | - * Inline CSS for RTL language support. |
|
559 | - * |
|
560 | - * @since 1.0.13 |
|
561 | - * @return string Inline CSS. |
|
562 | - */ |
|
563 | - public function rtl_inline_css() { |
|
564 | - $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}'; |
|
565 | - |
|
566 | - return $inline_css; |
|
567 | - } |
|
568 | - |
|
569 | - } |
|
570 | - |
|
571 | - /** |
|
572 | - * Run the class if found. |
|
573 | - */ |
|
574 | - WP_Font_Awesome_Settings::instance(); |
|
487 | + } |
|
488 | + |
|
489 | + /** |
|
490 | + * Check a version number is valid and if so return it or else return an empty string. |
|
491 | + * |
|
492 | + * @param $version string The version number to check. |
|
493 | + * |
|
494 | + * @since 1.0.6 |
|
495 | + * |
|
496 | + * @return string Either a valid version number or an empty string. |
|
497 | + */ |
|
498 | + public function validate_version_number( $version ) { |
|
499 | + |
|
500 | + if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
501 | + // valid |
|
502 | + } else { |
|
503 | + $version = '';// not validated |
|
504 | + } |
|
505 | + |
|
506 | + return $version; |
|
507 | + } |
|
508 | + |
|
509 | + |
|
510 | + /** |
|
511 | + * Get the latest version of Font Awesome. |
|
512 | + * |
|
513 | + * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours. |
|
514 | + * |
|
515 | + * @since 1.0.7 |
|
516 | + * @return mixed|string The latest version number found. |
|
517 | + */ |
|
518 | + public function get_latest_version( $force_api = false ) { |
|
519 | + $latest_version = $this->latest; |
|
520 | + |
|
521 | + $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
522 | + |
|
523 | + if ( $cache === false || $force_api ) { // its not set |
|
524 | + $api_ver = $this->get_latest_version_from_api(); |
|
525 | + if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
526 | + $latest_version = $api_ver; |
|
527 | + set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
528 | + } |
|
529 | + } elseif ( $this->validate_version_number( $cache ) ) { |
|
530 | + if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
531 | + $latest_version = $cache; |
|
532 | + } |
|
533 | + } |
|
534 | + |
|
535 | + return $latest_version; |
|
536 | + } |
|
537 | + |
|
538 | + /** |
|
539 | + * Get the latest Font Awesome version from the github API. |
|
540 | + * |
|
541 | + * @since 1.0.7 |
|
542 | + * @return string The latest version number or `0` on API fail. |
|
543 | + */ |
|
544 | + public function get_latest_version_from_api() { |
|
545 | + $version = "0"; |
|
546 | + $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
547 | + if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
548 | + $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
549 | + if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
550 | + $version = $api_response['tag_name']; |
|
551 | + } |
|
552 | + } |
|
553 | + |
|
554 | + return $version; |
|
555 | + } |
|
556 | + |
|
557 | + /** |
|
558 | + * Inline CSS for RTL language support. |
|
559 | + * |
|
560 | + * @since 1.0.13 |
|
561 | + * @return string Inline CSS. |
|
562 | + */ |
|
563 | + public function rtl_inline_css() { |
|
564 | + $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}'; |
|
565 | + |
|
566 | + return $inline_css; |
|
567 | + } |
|
568 | + |
|
569 | + } |
|
570 | + |
|
571 | + /** |
|
572 | + * Run the class if found. |
|
573 | + */ |
|
574 | + WP_Font_Awesome_Settings::instance(); |
|
575 | 575 | } |
576 | 576 | \ No newline at end of file |
@@ -12,14 +12,14 @@ discard block |
||
12 | 12 | /** |
13 | 13 | * Bail if we are not in WP. |
14 | 14 | */ |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if (!defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Only add if the class does not already exist. |
21 | 21 | */ |
22 | -if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
|
22 | +if (!class_exists('WP_Font_Awesome_Settings')) { |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * A Class to be able to change settings for Font Awesome. |
@@ -88,17 +88,17 @@ discard block |
||
88 | 88 | * @return WP_Font_Awesome_Settings - Main instance. |
89 | 89 | */ |
90 | 90 | public static function instance() { |
91 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
91 | + if (!isset(self::$instance) && !(self::$instance instanceof WP_Font_Awesome_Settings)) { |
|
92 | 92 | self::$instance = new WP_Font_Awesome_Settings; |
93 | 93 | |
94 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
94 | + add_action('init', array(self::$instance, 'init')); // set settings |
|
95 | 95 | |
96 | - if ( is_admin() ) { |
|
97 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
98 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
96 | + if (is_admin()) { |
|
97 | + add_action('admin_menu', array(self::$instance, 'menu_item')); |
|
98 | + add_action('admin_init', array(self::$instance, 'register_settings')); |
|
99 | 99 | } |
100 | 100 | |
101 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
101 | + do_action('wp_font_awesome_settings_loaded'); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | return self::$instance; |
@@ -112,30 +112,30 @@ discard block |
||
112 | 112 | public function init() { |
113 | 113 | $this->settings = $this->get_settings(); |
114 | 114 | |
115 | - if ( $this->settings['type'] == 'CSS' ) { |
|
115 | + if ($this->settings['type'] == 'CSS') { |
|
116 | 116 | |
117 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
118 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
117 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
118 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_style'), 5000); |
|
119 | 119 | } |
120 | 120 | |
121 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
122 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
121 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') { |
|
122 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_style'), 5000); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | } else { |
126 | 126 | |
127 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
128 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
127 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
128 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); |
|
129 | 129 | } |
130 | 130 | |
131 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
132 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
131 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') { |
|
132 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | |
136 | 136 | // remove font awesome if set to do so |
137 | - if ( $this->settings['dequeue'] == '1' ) { |
|
138 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
137 | + if ($this->settings['dequeue'] == '1') { |
|
138 | + add_action('clean_url', array($this, 'remove_font_awesome'), 5000, 3); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | } |
@@ -147,20 +147,20 @@ discard block |
||
147 | 147 | // build url |
148 | 148 | $url = $this->get_url(); |
149 | 149 | |
150 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
151 | - wp_register_style( 'font-awesome', $url, array(), null ); |
|
152 | - wp_enqueue_style( 'font-awesome' ); |
|
150 | + wp_deregister_style('font-awesome'); // deregister in case its already there |
|
151 | + wp_register_style('font-awesome', $url, array(), null); |
|
152 | + wp_enqueue_style('font-awesome'); |
|
153 | 153 | |
154 | 154 | // RTL language support CSS. |
155 | - if ( is_rtl() ) { |
|
156 | - wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
155 | + if (is_rtl()) { |
|
156 | + wp_add_inline_style('font-awesome', $this->rtl_inline_css()); |
|
157 | 157 | } |
158 | 158 | |
159 | - if ( $this->settings['shims'] ) { |
|
160 | - $url = $this->get_url( true ); |
|
161 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
162 | - wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
163 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
159 | + if ($this->settings['shims']) { |
|
160 | + $url = $this->get_url(true); |
|
161 | + wp_deregister_style('font-awesome-shims'); // deregister in case its already there |
|
162 | + wp_register_style('font-awesome-shims', $url, array(), null); |
|
163 | + wp_enqueue_style('font-awesome-shims'); |
|
164 | 164 | } |
165 | 165 | } |
166 | 166 | |
@@ -172,15 +172,15 @@ discard block |
||
172 | 172 | $url = $this->get_url(); |
173 | 173 | |
174 | 174 | $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
175 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
176 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
177 | - wp_enqueue_script( 'font-awesome' ); |
|
178 | - |
|
179 | - if ( $this->settings['shims'] ) { |
|
180 | - $url = $this->get_url( true ); |
|
181 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
182 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
183 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
175 | + call_user_func($deregister_function, 'font-awesome'); // deregister in case its already there |
|
176 | + wp_register_script('font-awesome', $url, array(), null); |
|
177 | + wp_enqueue_script('font-awesome'); |
|
178 | + |
|
179 | + if ($this->settings['shims']) { |
|
180 | + $url = $this->get_url(true); |
|
181 | + call_user_func($deregister_function, 'font-awesome-shims'); // deregister in case its already there |
|
182 | + wp_register_script('font-awesome-shims', $url, array(), null); |
|
183 | + wp_enqueue_script('font-awesome-shims'); |
|
184 | 184 | } |
185 | 185 | } |
186 | 186 | |
@@ -191,16 +191,16 @@ discard block |
||
191 | 191 | * |
192 | 192 | * @return string The url to the file. |
193 | 193 | */ |
194 | - public function get_url( $shims = false ) { |
|
194 | + public function get_url($shims = false) { |
|
195 | 195 | $script = $shims ? 'v4-shims' : 'all'; |
196 | 196 | $sub = $this->settings['pro'] ? 'pro' : 'use'; |
197 | 197 | $type = $this->settings['type']; |
198 | 198 | $version = $this->settings['version']; |
199 | - $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
199 | + $kit_url = $this->settings['kit-url'] ? esc_url($this->settings['kit-url']) : ''; |
|
200 | 200 | $url = ''; |
201 | 201 | |
202 | - if ( $type == 'KIT' && $kit_url ) { |
|
203 | - if ( $shims ) { |
|
202 | + if ($type == 'KIT' && $kit_url) { |
|
203 | + if ($shims) { |
|
204 | 204 | // if its a kit then we don't add shims here |
205 | 205 | return ''; |
206 | 206 | } |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | $url .= "?wpfas=true"; // set our var so our version is not removed |
209 | 209 | } else { |
210 | 210 | $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
211 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
211 | + $url .= !empty($version) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
212 | 212 | $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
213 | 213 | $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
214 | 214 | $url .= "?wpfas=true"; // set our var so our version is not removed |
@@ -228,16 +228,16 @@ discard block |
||
228 | 228 | * |
229 | 229 | * @return string The filtered url. |
230 | 230 | */ |
231 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
231 | + public function remove_font_awesome($url, $original_url, $_context) { |
|
232 | 232 | |
233 | - if ( $_context == 'display' |
|
234 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
235 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
233 | + if ($_context == 'display' |
|
234 | + && (strstr($url, "fontawesome") !== false || strstr($url, "font-awesome") !== false) |
|
235 | + && (strstr($url, ".js") !== false || strstr($url, ".css") !== false) |
|
236 | 236 | ) {// it's a font-awesome-url (probably) |
237 | 237 | |
238 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
239 | - if ( $this->settings['type'] == 'JS' ) { |
|
240 | - if ( $this->settings['js-pseudo'] ) { |
|
238 | + if (strstr($url, "wpfas=true") !== false) { |
|
239 | + if ($this->settings['type'] == 'JS') { |
|
240 | + if ($this->settings['js-pseudo']) { |
|
241 | 241 | $url .= "' data-search-pseudo-elements defer='defer"; |
242 | 242 | } else { |
243 | 243 | $url .= "' defer='defer"; |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | * Register the database settings with WordPress. |
257 | 257 | */ |
258 | 258 | public function register_settings() { |
259 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
259 | + register_setting('wp-font-awesome-settings', 'wp-font-awesome-settings'); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -265,10 +265,10 @@ discard block |
||
265 | 265 | */ |
266 | 266 | public function menu_item() { |
267 | 267 | $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
268 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
268 | + call_user_func($menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
269 | 269 | $this, |
270 | 270 | 'settings_page' |
271 | - ) ); |
|
271 | + )); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | */ |
279 | 279 | public function get_settings() { |
280 | 280 | |
281 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
281 | + $db_settings = get_option('wp-font-awesome-settings'); |
|
282 | 282 | |
283 | 283 | $defaults = array( |
284 | 284 | 'type' => 'CSS', // type to use, CSS or JS or KIT |
@@ -291,14 +291,14 @@ discard block |
||
291 | 291 | 'kit-url' => '', // the kit url |
292 | 292 | ); |
293 | 293 | |
294 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
294 | + $settings = wp_parse_args($db_settings, $defaults); |
|
295 | 295 | |
296 | 296 | /** |
297 | 297 | * Filter the Font Awesome settings. |
298 | 298 | * |
299 | 299 | * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
300 | 300 | */ |
301 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
301 | + return $this->settings = apply_filters('wp-font-awesome-settings', $settings, $db_settings, $defaults); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | |
@@ -306,13 +306,13 @@ discard block |
||
306 | 306 | * The settings page html output. |
307 | 307 | */ |
308 | 308 | public function settings_page() { |
309 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
310 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
309 | + if (!current_user_can('manage_options')) { |
|
310 | + wp_die(__('You do not have sufficient permissions to access this page.', 'font-awesome-settings')); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
314 | - if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
315 | - $this->get_latest_version( $force_api = true ); |
|
314 | + if (isset($_REQUEST['force-version-check'])) { |
|
315 | + $this->get_latest_version($force_api = true); |
|
316 | 316 | } |
317 | 317 | ?> |
318 | 318 | <style> |
@@ -332,37 +332,37 @@ discard block |
||
332 | 332 | <h1><?php echo $this->name; ?></h1> |
333 | 333 | <form method="post" action="options.php"> |
334 | 334 | <?php |
335 | - settings_fields( 'wp-font-awesome-settings' ); |
|
336 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
335 | + settings_fields('wp-font-awesome-settings'); |
|
336 | + do_settings_sections('wp-font-awesome-settings'); |
|
337 | 337 | $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
338 | 338 | ?> |
339 | - <table class="form-table wpfas-table-settings <?php echo esc_attr( $kit_set ); ?>"> |
|
339 | + <table class="form-table wpfas-table-settings <?php echo esc_attr($kit_set); ?>"> |
|
340 | 340 | <tr valign="top"> |
341 | 341 | <th scope="row"><label |
342 | - for="wpfas-type"><?php _e( 'Type', 'font-awesome-settings' ); ?></label></th> |
|
342 | + for="wpfas-type"><?php _e('Type', 'font-awesome-settings'); ?></label></th> |
|
343 | 343 | <td> |
344 | 344 | <select name="wp-font-awesome-settings[type]" id="wpfas-type" |
345 | 345 | onchange="if(this.value=='KIT'){jQuery('.wpfas-table-settings').addClass('wpfas-kit-set');}else{jQuery('.wpfas-table-settings').removeClass('wpfas-kit-set');}"> |
346 | 346 | <option |
347 | - value="CSS" <?php selected( $this->settings['type'], 'CSS' ); ?>><?php _e( 'CSS (default)', 'font-awesome-settings' ); ?></option> |
|
348 | - <option value="JS" <?php selected( $this->settings['type'], 'JS' ); ?>>JS</option> |
|
347 | + value="CSS" <?php selected($this->settings['type'], 'CSS'); ?>><?php _e('CSS (default)', 'font-awesome-settings'); ?></option> |
|
348 | + <option value="JS" <?php selected($this->settings['type'], 'JS'); ?>>JS</option> |
|
349 | 349 | <option |
350 | - value="KIT" <?php selected( $this->settings['type'], 'KIT' ); ?>><?php _e( 'Kits (settings managed on fontawesome.com)', 'font-awesome-settings' ); ?></option> |
|
350 | + value="KIT" <?php selected($this->settings['type'], 'KIT'); ?>><?php _e('Kits (settings managed on fontawesome.com)', 'font-awesome-settings'); ?></option> |
|
351 | 351 | </select> |
352 | 352 | </td> |
353 | 353 | </tr> |
354 | 354 | |
355 | 355 | <tr valign="top" class="wpfas-kit-show"> |
356 | 356 | <th scope="row"><label |
357 | - for="wpfas-kit-url"><?php _e( 'Kit URL', 'font-awesome-settings' ); ?></label></th> |
|
357 | + for="wpfas-kit-url"><?php _e('Kit URL', 'font-awesome-settings'); ?></label></th> |
|
358 | 358 | <td> |
359 | 359 | <input class="regular-text" id="wpfas-kit-url" type="url" |
360 | 360 | name="wp-font-awesome-settings[kit-url]" |
361 | - value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" |
|
362 | - placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
|
361 | + value="<?php echo esc_attr($this->settings['kit-url']); ?>" |
|
362 | + placeholder="<?php echo 'https://kit.font'; echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
|
363 | 363 | <span><?php |
364 | 364 | echo sprintf( |
365 | - __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
365 | + __('Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings'), |
|
366 | 366 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
367 | 367 | '</a>' |
368 | 368 | ); |
@@ -372,31 +372,31 @@ discard block |
||
372 | 372 | |
373 | 373 | <tr valign="top" class="wpfas-kit-hide"> |
374 | 374 | <th scope="row"><label |
375 | - for="wpfas-version"><?php _e( 'Version', 'font-awesome-settings' ); ?></label></th> |
|
375 | + for="wpfas-version"><?php _e('Version', 'font-awesome-settings'); ?></label></th> |
|
376 | 376 | <td> |
377 | 377 | <select name="wp-font-awesome-settings[version]" id="wpfas-version"> |
378 | 378 | <option |
379 | - value="" <?php selected( $this->settings['version'], '' ); ?>><?php echo sprintf( __( 'Latest - %s (default)', 'font-awesome-settings' ), $this->get_latest_version() ); ?> |
|
379 | + value="" <?php selected($this->settings['version'], ''); ?>><?php echo sprintf(__('Latest - %s (default)', 'font-awesome-settings'), $this->get_latest_version()); ?> |
|
380 | 380 | </option> |
381 | - <option value="5.6.0" <?php selected( $this->settings['version'], '5.6.0' ); ?>> |
|
381 | + <option value="5.6.0" <?php selected($this->settings['version'], '5.6.0'); ?>> |
|
382 | 382 | 5.6.0 |
383 | 383 | </option> |
384 | - <option value="5.5.0" <?php selected( $this->settings['version'], '5.5.0' ); ?>> |
|
384 | + <option value="5.5.0" <?php selected($this->settings['version'], '5.5.0'); ?>> |
|
385 | 385 | 5.5.0 |
386 | 386 | </option> |
387 | - <option value="5.4.0" <?php selected( $this->settings['version'], '5.4.0' ); ?>> |
|
387 | + <option value="5.4.0" <?php selected($this->settings['version'], '5.4.0'); ?>> |
|
388 | 388 | 5.4.0 |
389 | 389 | </option> |
390 | - <option value="5.3.0" <?php selected( $this->settings['version'], '5.3.0' ); ?>> |
|
390 | + <option value="5.3.0" <?php selected($this->settings['version'], '5.3.0'); ?>> |
|
391 | 391 | 5.3.0 |
392 | 392 | </option> |
393 | - <option value="5.2.0" <?php selected( $this->settings['version'], '5.2.0' ); ?>> |
|
393 | + <option value="5.2.0" <?php selected($this->settings['version'], '5.2.0'); ?>> |
|
394 | 394 | 5.2.0 |
395 | 395 | </option> |
396 | - <option value="5.1.0" <?php selected( $this->settings['version'], '5.1.0' ); ?>> |
|
396 | + <option value="5.1.0" <?php selected($this->settings['version'], '5.1.0'); ?>> |
|
397 | 397 | 5.1.0 |
398 | 398 | </option> |
399 | - <option value="4.7.0" <?php selected( $this->settings['version'], '4.7.0' ); ?>> |
|
399 | + <option value="4.7.0" <?php selected($this->settings['version'], '4.7.0'); ?>> |
|
400 | 400 | 4.7.1 (CSS only) |
401 | 401 | </option> |
402 | 402 | </select> |
@@ -405,29 +405,29 @@ discard block |
||
405 | 405 | |
406 | 406 | <tr valign="top"> |
407 | 407 | <th scope="row"><label |
408 | - for="wpfas-enqueue"><?php _e( 'Enqueue', 'font-awesome-settings' ); ?></label></th> |
|
408 | + for="wpfas-enqueue"><?php _e('Enqueue', 'font-awesome-settings'); ?></label></th> |
|
409 | 409 | <td> |
410 | 410 | <select name="wp-font-awesome-settings[enqueue]" id="wpfas-enqueue"> |
411 | 411 | <option |
412 | - value="" <?php selected( $this->settings['enqueue'], '' ); ?>><?php _e( 'Frontend + Backend (default)', 'font-awesome-settings' ); ?></option> |
|
412 | + value="" <?php selected($this->settings['enqueue'], ''); ?>><?php _e('Frontend + Backend (default)', 'font-awesome-settings'); ?></option> |
|
413 | 413 | <option |
414 | - value="frontend" <?php selected( $this->settings['enqueue'], 'frontend' ); ?>><?php _e( 'Frontend', 'font-awesome-settings' ); ?></option> |
|
414 | + value="frontend" <?php selected($this->settings['enqueue'], 'frontend'); ?>><?php _e('Frontend', 'font-awesome-settings'); ?></option> |
|
415 | 415 | <option |
416 | - value="backend" <?php selected( $this->settings['enqueue'], 'backend' ); ?>><?php _e( 'Backend', 'font-awesome-settings' ); ?></option> |
|
416 | + value="backend" <?php selected($this->settings['enqueue'], 'backend'); ?>><?php _e('Backend', 'font-awesome-settings'); ?></option> |
|
417 | 417 | </select> |
418 | 418 | </td> |
419 | 419 | </tr> |
420 | 420 | |
421 | 421 | <tr valign="top" class="wpfas-kit-hide"> |
422 | 422 | <th scope="row"><label |
423 | - for="wpfas-pro"><?php _e( 'Enable pro', 'font-awesome-settings' ); ?></label></th> |
|
423 | + for="wpfas-pro"><?php _e('Enable pro', 'font-awesome-settings'); ?></label></th> |
|
424 | 424 | <td> |
425 | 425 | <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/> |
426 | 426 | <input type="checkbox" name="wp-font-awesome-settings[pro]" |
427 | - value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro"/> |
|
427 | + value="1" <?php checked($this->settings['pro'], '1'); ?> id="wpfas-pro"/> |
|
428 | 428 | <span><?php |
429 | 429 | echo sprintf( |
430 | - __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
430 | + __('Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings'), |
|
431 | 431 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>', |
432 | 432 | '</a>', |
433 | 433 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>', |
@@ -439,38 +439,38 @@ discard block |
||
439 | 439 | |
440 | 440 | <tr valign="top" class="wpfas-kit-hide"> |
441 | 441 | <th scope="row"><label |
442 | - for="wpfas-shims"><?php _e( 'Enable v4 shims compatibility', 'font-awesome-settings' ); ?></label> |
|
442 | + for="wpfas-shims"><?php _e('Enable v4 shims compatibility', 'font-awesome-settings'); ?></label> |
|
443 | 443 | </th> |
444 | 444 | <td> |
445 | 445 | <input type="hidden" name="wp-font-awesome-settings[shims]" value="0"/> |
446 | 446 | <input type="checkbox" name="wp-font-awesome-settings[shims]" |
447 | - value="1" <?php checked( $this->settings['shims'], '1' ); ?> id="wpfas-shims"/> |
|
448 | - <span><?php _e( 'This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'font-awesome-settings' ); ?></span> |
|
447 | + value="1" <?php checked($this->settings['shims'], '1'); ?> id="wpfas-shims"/> |
|
448 | + <span><?php _e('This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'font-awesome-settings'); ?></span> |
|
449 | 449 | </td> |
450 | 450 | </tr> |
451 | 451 | |
452 | 452 | <tr valign="top" class="wpfas-kit-hide"> |
453 | 453 | <th scope="row"><label |
454 | - for="wpfas-js-pseudo"><?php _e( 'Enable JS pseudo elements (not recommended)', 'font-awesome-settings' ); ?></label> |
|
454 | + for="wpfas-js-pseudo"><?php _e('Enable JS pseudo elements (not recommended)', 'font-awesome-settings'); ?></label> |
|
455 | 455 | </th> |
456 | 456 | <td> |
457 | 457 | <input type="hidden" name="wp-font-awesome-settings[js-pseudo]" value="0"/> |
458 | 458 | <input type="checkbox" name="wp-font-awesome-settings[js-pseudo]" |
459 | - value="1" <?php checked( $this->settings['js-pseudo'], '1' ); ?> |
|
459 | + value="1" <?php checked($this->settings['js-pseudo'], '1'); ?> |
|
460 | 460 | id="wpfas-js-pseudo"/> |
461 | - <span><?php _e( 'Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'font-awesome-settings' ); ?></span> |
|
461 | + <span><?php _e('Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'font-awesome-settings'); ?></span> |
|
462 | 462 | </td> |
463 | 463 | </tr> |
464 | 464 | |
465 | 465 | <tr valign="top"> |
466 | 466 | <th scope="row"><label |
467 | - for="wpfas-dequeue"><?php _e( 'Dequeue', 'font-awesome-settings' ); ?></label></th> |
|
467 | + for="wpfas-dequeue"><?php _e('Dequeue', 'font-awesome-settings'); ?></label></th> |
|
468 | 468 | <td> |
469 | 469 | <input type="hidden" name="wp-font-awesome-settings[dequeue]" value="0"/> |
470 | 470 | <input type="checkbox" name="wp-font-awesome-settings[dequeue]" |
471 | - value="1" <?php checked( $this->settings['dequeue'], '1' ); ?> |
|
471 | + value="1" <?php checked($this->settings['dequeue'], '1'); ?> |
|
472 | 472 | id="wpfas-dequeue"/> |
473 | - <span><?php _e( 'This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'font-awesome-settings' ); ?></span> |
|
473 | + <span><?php _e('This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'font-awesome-settings'); ?></span> |
|
474 | 474 | </td> |
475 | 475 | </tr> |
476 | 476 | |
@@ -495,12 +495,12 @@ discard block |
||
495 | 495 | * |
496 | 496 | * @return string Either a valid version number or an empty string. |
497 | 497 | */ |
498 | - public function validate_version_number( $version ) { |
|
498 | + public function validate_version_number($version) { |
|
499 | 499 | |
500 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
500 | + if (version_compare($version, '0.0.1', '>=') >= 0) { |
|
501 | 501 | // valid |
502 | 502 | } else { |
503 | - $version = '';// not validated |
|
503 | + $version = ''; // not validated |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | return $version; |
@@ -515,19 +515,19 @@ discard block |
||
515 | 515 | * @since 1.0.7 |
516 | 516 | * @return mixed|string The latest version number found. |
517 | 517 | */ |
518 | - public function get_latest_version( $force_api = false ) { |
|
518 | + public function get_latest_version($force_api = false) { |
|
519 | 519 | $latest_version = $this->latest; |
520 | 520 | |
521 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
521 | + $cache = get_transient('wp-font-awesome-settings-version'); |
|
522 | 522 | |
523 | - if ( $cache === false || $force_api ) { // its not set |
|
523 | + if ($cache === false || $force_api) { // its not set |
|
524 | 524 | $api_ver = $this->get_latest_version_from_api(); |
525 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
525 | + if (version_compare($api_ver, $this->latest, '>=') >= 0) { |
|
526 | 526 | $latest_version = $api_ver; |
527 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
527 | + set_transient('wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS); |
|
528 | 528 | } |
529 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
530 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
529 | + } elseif ($this->validate_version_number($cache)) { |
|
530 | + if (version_compare($cache, $this->latest, '>=') >= 0) { |
|
531 | 531 | $latest_version = $cache; |
532 | 532 | } |
533 | 533 | } |
@@ -543,10 +543,10 @@ discard block |
||
543 | 543 | */ |
544 | 544 | public function get_latest_version_from_api() { |
545 | 545 | $version = "0"; |
546 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
547 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
548 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
549 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
546 | + $response = wp_remote_get("https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest"); |
|
547 | + if (!is_wp_error($response) && is_array($response)) { |
|
548 | + $api_response = json_decode(wp_remote_retrieve_body($response), true); |
|
549 | + if (isset($api_response['tag_name']) && version_compare($api_response['tag_name'], $this->latest, '>=') >= 0 && empty($api_response['prerelease'])) { |
|
550 | 550 | $version = $api_response['tag_name']; |
551 | 551 | } |
552 | 552 | } |
@@ -12,228 +12,228 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Taxes { |
14 | 14 | |
15 | - /** |
|
16 | - * Submission taxes. |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public $taxes = array(); |
|
20 | - |
|
21 | - /** |
|
22 | - * Whether or not we should skip the taxes. |
|
23 | - * @var bool |
|
24 | - */ |
|
25 | - protected $skip_taxes = false; |
|
15 | + /** |
|
16 | + * Submission taxes. |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public $taxes = array(); |
|
20 | + |
|
21 | + /** |
|
22 | + * Whether or not we should skip the taxes. |
|
23 | + * @var bool |
|
24 | + */ |
|
25 | + protected $skip_taxes = false; |
|
26 | 26 | |
27 | 27 | /** |
28 | - * Class constructor |
|
29 | - * |
|
30 | - * @param GetPaid_Payment_Form_Submission $submission |
|
31 | - */ |
|
32 | - public function __construct( $submission ) { |
|
33 | - |
|
34 | - // Validate VAT number. |
|
35 | - $this->validate_vat( $submission ); |
|
36 | - |
|
37 | - if ( $this->skip_taxes ) { |
|
38 | - return; |
|
39 | - } |
|
40 | - |
|
41 | - foreach ( $submission->get_items() as $item ) { |
|
42 | - $this->process_item_tax( $item, $submission ); |
|
43 | - } |
|
44 | - |
|
45 | - // Process any existing invoice taxes. |
|
46 | - if ( $submission->has_invoice() ) { |
|
47 | - $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
48 | - } |
|
49 | - |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Maybe process tax. |
|
54 | - * |
|
55 | - * @since 1.0.19 |
|
56 | - * @param GetPaid_Form_Item $item |
|
57 | - * @param GetPaid_Payment_Form_Submission $submission |
|
58 | - */ |
|
59 | - public function process_item_tax( $item, $submission ) { |
|
60 | - |
|
61 | - $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
62 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
63 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
64 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
65 | - |
|
66 | - foreach ( $taxes as $name => $amount ) { |
|
67 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
68 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
69 | - |
|
70 | - $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
71 | - |
|
72 | - if ( ! isset( $this->taxes[ $name ] ) ) { |
|
73 | - $this->taxes[ $name ] = $tax; |
|
74 | - continue; |
|
75 | - } |
|
76 | - |
|
77 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
78 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
79 | - |
|
80 | - } |
|
81 | - |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Checks if the submission has a digital item. |
|
86 | - * |
|
87 | - * @param GetPaid_Payment_Form_Submission $submission |
|
88 | - * @since 1.0.19 |
|
89 | - * @return bool |
|
90 | - */ |
|
91 | - public function has_digital_item( $submission ) { |
|
92 | - |
|
93 | - foreach ( $submission->get_items() as $item ) { |
|
94 | - |
|
95 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
96 | - return true; |
|
97 | - } |
|
98 | - |
|
99 | - } |
|
100 | - |
|
101 | - return false; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Checks if this is an eu store. |
|
106 | - * |
|
107 | - * @since 1.0.19 |
|
108 | - * @return bool |
|
109 | - */ |
|
110 | - public static function is_eu_store() { |
|
111 | - return self::is_eu_country( wpinv_get_default_country() ); |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Checks if this is an eu country. |
|
116 | - * |
|
117 | - * @param string $country |
|
118 | - * @since 1.0.19 |
|
119 | - * @return bool |
|
120 | - */ |
|
121 | - public static function is_eu_country( $country ) { |
|
122 | - return getpaid_is_eu_state( $country ); |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Checks if this is an eu purchase. |
|
127 | - * |
|
128 | - * @param string $customer_country |
|
129 | - * @since 1.0.19 |
|
130 | - * @return bool |
|
131 | - */ |
|
132 | - public static function is_eu_transaction( $customer_country ) { |
|
133 | - return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Retrieves the vat number. |
|
138 | - * |
|
139 | - * @param GetPaid_Payment_Form_Submission $submission |
|
140 | - * @since 1.0.19 |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - public function get_vat_number( $submission ) { |
|
144 | - |
|
145 | - // Retrieve from the posted number. |
|
146 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
147 | - if ( ! is_null( $vat_number ) ) { |
|
148 | - return wpinv_clean( $vat_number ); |
|
149 | - } |
|
150 | - |
|
151 | - return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Retrieves the company. |
|
156 | - * |
|
157 | - * @param GetPaid_Payment_Form_Submission $submission |
|
158 | - * @since 1.0.19 |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - public function get_company( $submission ) { |
|
162 | - |
|
163 | - // Retrieve from the posted data. |
|
164 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
165 | - if ( ! empty( $company ) ) { |
|
166 | - return wpinv_clean( $company ); |
|
167 | - } |
|
168 | - |
|
169 | - // Retrieve from the invoice. |
|
170 | - return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * Checks if we require a VAT number. |
|
175 | - * |
|
176 | - * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
177 | - * @param bool $country_in_eu Whether the customer country is from the EU |
|
178 | - * @since 1.0.19 |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
182 | - |
|
183 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
184 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
185 | - $is_eu = $ip_in_eu || $country_in_eu; |
|
186 | - |
|
187 | - return $prevent_b2c && $is_eu; |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Validate VAT data. |
|
192 | - * |
|
193 | - * @param GetPaid_Payment_Form_Submission $submission |
|
194 | - * @since 1.0.19 |
|
195 | - */ |
|
196 | - public function validate_vat( $submission ) { |
|
197 | - |
|
198 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
199 | - |
|
200 | - // Abort if we are not validating vat numbers. |
|
201 | - if ( ! $in_eu ) { |
|
28 | + * Class constructor |
|
29 | + * |
|
30 | + * @param GetPaid_Payment_Form_Submission $submission |
|
31 | + */ |
|
32 | + public function __construct( $submission ) { |
|
33 | + |
|
34 | + // Validate VAT number. |
|
35 | + $this->validate_vat( $submission ); |
|
36 | + |
|
37 | + if ( $this->skip_taxes ) { |
|
202 | 38 | return; |
203 | - } |
|
39 | + } |
|
40 | + |
|
41 | + foreach ( $submission->get_items() as $item ) { |
|
42 | + $this->process_item_tax( $item, $submission ); |
|
43 | + } |
|
44 | + |
|
45 | + // Process any existing invoice taxes. |
|
46 | + if ( $submission->has_invoice() ) { |
|
47 | + $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
48 | + } |
|
49 | + |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Maybe process tax. |
|
54 | + * |
|
55 | + * @since 1.0.19 |
|
56 | + * @param GetPaid_Form_Item $item |
|
57 | + * @param GetPaid_Payment_Form_Submission $submission |
|
58 | + */ |
|
59 | + public function process_item_tax( $item, $submission ) { |
|
60 | + |
|
61 | + $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
62 | + $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
63 | + $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
64 | + $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
65 | + |
|
66 | + foreach ( $taxes as $name => $amount ) { |
|
67 | + $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
68 | + $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
69 | + |
|
70 | + $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
71 | + |
|
72 | + if ( ! isset( $this->taxes[ $name ] ) ) { |
|
73 | + $this->taxes[ $name ] = $tax; |
|
74 | + continue; |
|
75 | + } |
|
76 | + |
|
77 | + $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
78 | + $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
79 | + |
|
80 | + } |
|
81 | + |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Checks if the submission has a digital item. |
|
86 | + * |
|
87 | + * @param GetPaid_Payment_Form_Submission $submission |
|
88 | + * @since 1.0.19 |
|
89 | + * @return bool |
|
90 | + */ |
|
91 | + public function has_digital_item( $submission ) { |
|
92 | + |
|
93 | + foreach ( $submission->get_items() as $item ) { |
|
94 | + |
|
95 | + if ( 'digital' == $item->get_vat_rule() ) { |
|
96 | + return true; |
|
97 | + } |
|
98 | + |
|
99 | + } |
|
204 | 100 | |
205 | - // Prepare variables. |
|
206 | - $vat_number = $this->get_vat_number( $submission ); |
|
207 | - $ip_country = getpaid_get_ip_country(); |
|
101 | + return false; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Checks if this is an eu store. |
|
106 | + * |
|
107 | + * @since 1.0.19 |
|
108 | + * @return bool |
|
109 | + */ |
|
110 | + public static function is_eu_store() { |
|
111 | + return self::is_eu_country( wpinv_get_default_country() ); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Checks if this is an eu country. |
|
116 | + * |
|
117 | + * @param string $country |
|
118 | + * @since 1.0.19 |
|
119 | + * @return bool |
|
120 | + */ |
|
121 | + public static function is_eu_country( $country ) { |
|
122 | + return getpaid_is_eu_state( $country ); |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Checks if this is an eu purchase. |
|
127 | + * |
|
128 | + * @param string $customer_country |
|
129 | + * @since 1.0.19 |
|
130 | + * @return bool |
|
131 | + */ |
|
132 | + public static function is_eu_transaction( $customer_country ) { |
|
133 | + return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Retrieves the vat number. |
|
138 | + * |
|
139 | + * @param GetPaid_Payment_Form_Submission $submission |
|
140 | + * @since 1.0.19 |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + public function get_vat_number( $submission ) { |
|
144 | + |
|
145 | + // Retrieve from the posted number. |
|
146 | + $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
147 | + if ( ! is_null( $vat_number ) ) { |
|
148 | + return wpinv_clean( $vat_number ); |
|
149 | + } |
|
150 | + |
|
151 | + return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Retrieves the company. |
|
156 | + * |
|
157 | + * @param GetPaid_Payment_Form_Submission $submission |
|
158 | + * @since 1.0.19 |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + public function get_company( $submission ) { |
|
162 | + |
|
163 | + // Retrieve from the posted data. |
|
164 | + $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
165 | + if ( ! empty( $company ) ) { |
|
166 | + return wpinv_clean( $company ); |
|
167 | + } |
|
168 | + |
|
169 | + // Retrieve from the invoice. |
|
170 | + return $submission->has_invoice() ? $submission->get_invoice()->get_company() : ''; |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * Checks if we require a VAT number. |
|
175 | + * |
|
176 | + * @param bool $ip_in_eu Whether the customer IP is from the EU |
|
177 | + * @param bool $country_in_eu Whether the customer country is from the EU |
|
178 | + * @since 1.0.19 |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
182 | + |
|
183 | + $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
184 | + $prevent_b2c = ! empty( $prevent_b2c ); |
|
185 | + $is_eu = $ip_in_eu || $country_in_eu; |
|
186 | + |
|
187 | + return $prevent_b2c && $is_eu; |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Validate VAT data. |
|
192 | + * |
|
193 | + * @param GetPaid_Payment_Form_Submission $submission |
|
194 | + * @since 1.0.19 |
|
195 | + */ |
|
196 | + public function validate_vat( $submission ) { |
|
197 | + |
|
198 | + $in_eu = $this->is_eu_transaction( $submission->country ); |
|
199 | + |
|
200 | + // Abort if we are not validating vat numbers. |
|
201 | + if ( ! $in_eu ) { |
|
202 | + return; |
|
203 | + } |
|
204 | + |
|
205 | + // Prepare variables. |
|
206 | + $vat_number = $this->get_vat_number( $submission ); |
|
207 | + $ip_country = getpaid_get_ip_country(); |
|
208 | 208 | $is_eu = $this->is_eu_country( $submission->country ); |
209 | 209 | $is_ip_eu = $this->is_eu_country( $ip_country ); |
210 | 210 | |
211 | - // Maybe abort early for initial fetches. |
|
212 | - if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
213 | - return; |
|
214 | - } |
|
211 | + // Maybe abort early for initial fetches. |
|
212 | + if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
213 | + return; |
|
214 | + } |
|
215 | 215 | |
216 | - // If we're preventing business to consumer purchases, |
|
217 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
216 | + // If we're preventing business to consumer purchases, |
|
217 | + if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
218 | 218 | |
219 | - // Ensure that a vat number has been specified. |
|
220 | - throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) ); |
|
219 | + // Ensure that a vat number has been specified. |
|
220 | + throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) ); |
|
221 | 221 | |
222 | - } |
|
222 | + } |
|
223 | 223 | |
224 | - if ( empty( $vat_number ) ) { |
|
225 | - return; |
|
226 | - } |
|
224 | + if ( empty( $vat_number ) ) { |
|
225 | + return; |
|
226 | + } |
|
227 | 227 | |
228 | - if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
229 | - throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
230 | - } |
|
228 | + if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
229 | + throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
230 | + } |
|
231 | 231 | |
232 | - if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
233 | - return; |
|
234 | - } |
|
232 | + if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
233 | + return; |
|
234 | + } |
|
235 | 235 | |
236 | - $this->skip_taxes = true; |
|
237 | - } |
|
236 | + $this->skip_taxes = true; |
|
237 | + } |
|
238 | 238 | |
239 | 239 | } |
@@ -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 | * Payment form submission taxes class |
@@ -29,22 +29,22 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @param GetPaid_Payment_Form_Submission $submission |
31 | 31 | */ |
32 | - public function __construct( $submission ) { |
|
32 | + public function __construct($submission) { |
|
33 | 33 | |
34 | 34 | // Validate VAT number. |
35 | - $this->validate_vat( $submission ); |
|
35 | + $this->validate_vat($submission); |
|
36 | 36 | |
37 | - if ( $this->skip_taxes ) { |
|
37 | + if ($this->skip_taxes) { |
|
38 | 38 | return; |
39 | 39 | } |
40 | 40 | |
41 | - foreach ( $submission->get_items() as $item ) { |
|
42 | - $this->process_item_tax( $item, $submission ); |
|
41 | + foreach ($submission->get_items() as $item) { |
|
42 | + $this->process_item_tax($item, $submission); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | // Process any existing invoice taxes. |
46 | - if ( $submission->has_invoice() ) { |
|
47 | - $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes ); |
|
46 | + if ($submission->has_invoice()) { |
|
47 | + $this->taxes = array_replace($submission->get_invoice()->get_taxes(), $this->taxes); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | } |
@@ -56,26 +56,26 @@ discard block |
||
56 | 56 | * @param GetPaid_Form_Item $item |
57 | 57 | * @param GetPaid_Payment_Form_Submission $submission |
58 | 58 | */ |
59 | - public function process_item_tax( $item, $submission ) { |
|
59 | + public function process_item_tax($item, $submission) { |
|
60 | 60 | |
61 | - $rates = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state ); |
|
62 | - $rates = getpaid_filter_item_tax_rates( $item, $rates ); |
|
63 | - $taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates ); |
|
64 | - $r_taxes = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates ); |
|
61 | + $rates = getpaid_get_item_tax_rates($item, $submission->country, $submission->state); |
|
62 | + $rates = getpaid_filter_item_tax_rates($item, $rates); |
|
63 | + $taxes = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, false), $rates); |
|
64 | + $r_taxes = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, true), $rates); |
|
65 | 65 | |
66 | - foreach ( $taxes as $name => $amount ) { |
|
67 | - $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0; |
|
68 | - $tax = getpaid_prepare_item_tax( $item, $name, $amount, $recurring ); |
|
66 | + foreach ($taxes as $name => $amount) { |
|
67 | + $recurring = isset($r_taxes[$name]) ? $r_taxes[$name] : 0; |
|
68 | + $tax = getpaid_prepare_item_tax($item, $name, $amount, $recurring); |
|
69 | 69 | |
70 | - $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
70 | + $item->item_tax += wpinv_sanitize_amount($tax['initial_tax']); |
|
71 | 71 | |
72 | - if ( ! isset( $this->taxes[ $name ] ) ) { |
|
73 | - $this->taxes[ $name ] = $tax; |
|
72 | + if (!isset($this->taxes[$name])) { |
|
73 | + $this->taxes[$name] = $tax; |
|
74 | 74 | continue; |
75 | 75 | } |
76 | 76 | |
77 | - $this->taxes[ $name ]['initial_tax'] += $tax['initial_tax']; |
|
78 | - $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax']; |
|
77 | + $this->taxes[$name]['initial_tax'] += $tax['initial_tax']; |
|
78 | + $this->taxes[$name]['recurring_tax'] += $tax['recurring_tax']; |
|
79 | 79 | |
80 | 80 | } |
81 | 81 | |
@@ -88,11 +88,11 @@ discard block |
||
88 | 88 | * @since 1.0.19 |
89 | 89 | * @return bool |
90 | 90 | */ |
91 | - public function has_digital_item( $submission ) { |
|
91 | + public function has_digital_item($submission) { |
|
92 | 92 | |
93 | - foreach ( $submission->get_items() as $item ) { |
|
93 | + foreach ($submission->get_items() as $item) { |
|
94 | 94 | |
95 | - if ( 'digital' == $item->get_vat_rule() ) { |
|
95 | + if ('digital' == $item->get_vat_rule()) { |
|
96 | 96 | return true; |
97 | 97 | } |
98 | 98 | |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * @return bool |
109 | 109 | */ |
110 | 110 | public static function is_eu_store() { |
111 | - return self::is_eu_country( wpinv_get_default_country() ); |
|
111 | + return self::is_eu_country(wpinv_get_default_country()); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | * @since 1.0.19 |
119 | 119 | * @return bool |
120 | 120 | */ |
121 | - public static function is_eu_country( $country ) { |
|
122 | - return getpaid_is_eu_state( $country ); |
|
121 | + public static function is_eu_country($country) { |
|
122 | + return getpaid_is_eu_state($country); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | * @since 1.0.19 |
130 | 130 | * @return bool |
131 | 131 | */ |
132 | - public static function is_eu_transaction( $customer_country ) { |
|
133 | - return self::is_eu_country( $customer_country ) && self::is_eu_store(); |
|
132 | + public static function is_eu_transaction($customer_country) { |
|
133 | + return self::is_eu_country($customer_country) && self::is_eu_store(); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -140,12 +140,12 @@ discard block |
||
140 | 140 | * @since 1.0.19 |
141 | 141 | * @return string |
142 | 142 | */ |
143 | - public function get_vat_number( $submission ) { |
|
143 | + public function get_vat_number($submission) { |
|
144 | 144 | |
145 | 145 | // Retrieve from the posted number. |
146 | - $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' ); |
|
147 | - if ( ! is_null( $vat_number ) ) { |
|
148 | - return wpinv_clean( $vat_number ); |
|
146 | + $vat_number = $submission->get_field('wpinv_vat_number', 'billing'); |
|
147 | + if (!is_null($vat_number)) { |
|
148 | + return wpinv_clean($vat_number); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : ''; |
@@ -158,12 +158,12 @@ discard block |
||
158 | 158 | * @since 1.0.19 |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - public function get_company( $submission ) { |
|
161 | + public function get_company($submission) { |
|
162 | 162 | |
163 | 163 | // Retrieve from the posted data. |
164 | - $company = $submission->get_field( 'wpinv_company', 'billing' ); |
|
165 | - if ( ! empty( $company ) ) { |
|
166 | - return wpinv_clean( $company ); |
|
164 | + $company = $submission->get_field('wpinv_company', 'billing'); |
|
165 | + if (!empty($company)) { |
|
166 | + return wpinv_clean($company); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | // Retrieve from the invoice. |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | * @since 1.0.19 |
179 | 179 | * @return string |
180 | 180 | */ |
181 | - public function requires_vat( $ip_in_eu, $country_in_eu ) { |
|
181 | + public function requires_vat($ip_in_eu, $country_in_eu) { |
|
182 | 182 | |
183 | - $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' ); |
|
184 | - $prevent_b2c = ! empty( $prevent_b2c ); |
|
183 | + $prevent_b2c = wpinv_get_option('vat_prevent_b2c_purchase'); |
|
184 | + $prevent_b2c = !empty($prevent_b2c); |
|
185 | 185 | $is_eu = $ip_in_eu || $country_in_eu; |
186 | 186 | |
187 | 187 | return $prevent_b2c && $is_eu; |
@@ -193,43 +193,43 @@ discard block |
||
193 | 193 | * @param GetPaid_Payment_Form_Submission $submission |
194 | 194 | * @since 1.0.19 |
195 | 195 | */ |
196 | - public function validate_vat( $submission ) { |
|
196 | + public function validate_vat($submission) { |
|
197 | 197 | |
198 | - $in_eu = $this->is_eu_transaction( $submission->country ); |
|
198 | + $in_eu = $this->is_eu_transaction($submission->country); |
|
199 | 199 | |
200 | 200 | // Abort if we are not validating vat numbers. |
201 | - if ( ! $in_eu ) { |
|
201 | + if (!$in_eu) { |
|
202 | 202 | return; |
203 | 203 | } |
204 | 204 | |
205 | 205 | // Prepare variables. |
206 | - $vat_number = $this->get_vat_number( $submission ); |
|
206 | + $vat_number = $this->get_vat_number($submission); |
|
207 | 207 | $ip_country = getpaid_get_ip_country(); |
208 | - $is_eu = $this->is_eu_country( $submission->country ); |
|
209 | - $is_ip_eu = $this->is_eu_country( $ip_country ); |
|
208 | + $is_eu = $this->is_eu_country($submission->country); |
|
209 | + $is_ip_eu = $this->is_eu_country($ip_country); |
|
210 | 210 | |
211 | 211 | // Maybe abort early for initial fetches. |
212 | - if ( $submission->is_initial_fetch() && empty( $vat_number ) ) { |
|
212 | + if ($submission->is_initial_fetch() && empty($vat_number)) { |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 | |
216 | 216 | // If we're preventing business to consumer purchases, |
217 | - if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) { |
|
217 | + if ($this->requires_vat($is_ip_eu, $is_eu) && empty($vat_number)) { |
|
218 | 218 | |
219 | 219 | // Ensure that a vat number has been specified. |
220 | - throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' ) ); |
|
220 | + throw new GetPaid_Payment_Exception('.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __('Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing')); |
|
221 | 221 | |
222 | 222 | } |
223 | 223 | |
224 | - if ( empty( $vat_number ) ) { |
|
224 | + if (empty($vat_number)) { |
|
225 | 225 | return; |
226 | 226 | } |
227 | 227 | |
228 | - if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) { |
|
229 | - throw new GetPaid_Payment_Exception( '.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __( 'Your VAT number is invalid', 'invoicing' ) ); |
|
228 | + if (wpinv_should_validate_vat_number() && !wpinv_validate_vat_number($vat_number, $submission->country)) { |
|
229 | + throw new GetPaid_Payment_Exception('.getpaid-error-billingwpinv_vat_number.getpaid-custom-payment-form-errors', __('Your VAT number is invalid', 'invoicing')); |
|
230 | 230 | } |
231 | 231 | |
232 | - if ( wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) { |
|
232 | + if (wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option('vat_same_country_rule', 'vat_too')) { |
|
233 | 233 | return; |
234 | 234 | } |
235 | 235 |
@@ -11,18 +11,18 @@ discard block |
||
11 | 11 | * @return mixed|void |
12 | 12 | */ |
13 | 13 | function sd_pagenow_exclude(){ |
14 | - return apply_filters( 'sd_pagenow_exclude', array( |
|
15 | - 'upload.php', |
|
16 | - 'edit-comments.php', |
|
17 | - 'edit-tags.php', |
|
18 | - 'index.php', |
|
19 | - 'media-new.php', |
|
20 | - 'options-discussion.php', |
|
21 | - 'options-writing.php', |
|
22 | - 'edit.php', |
|
23 | - 'themes.php', |
|
24 | - 'users.php', |
|
25 | - ) ); |
|
14 | + return apply_filters( 'sd_pagenow_exclude', array( |
|
15 | + 'upload.php', |
|
16 | + 'edit-comments.php', |
|
17 | + 'edit-tags.php', |
|
18 | + 'index.php', |
|
19 | + 'media-new.php', |
|
20 | + 'options-discussion.php', |
|
21 | + 'options-writing.php', |
|
22 | + 'edit.php', |
|
23 | + 'themes.php', |
|
24 | + 'users.php', |
|
25 | + ) ); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | |
@@ -34,5 +34,5 @@ discard block |
||
34 | 34 | * @return mixed|void |
35 | 35 | */ |
36 | 36 | function sd_widget_exclude(){ |
37 | - return apply_filters( 'sd_widget_exclude', array() ); |
|
37 | + return apply_filters( 'sd_widget_exclude', array() ); |
|
38 | 38 | } |
39 | 39 | \ No newline at end of file |
@@ -10,8 +10,8 @@ discard block |
||
10 | 10 | * |
11 | 11 | * @return mixed|void |
12 | 12 | */ |
13 | -function sd_pagenow_exclude(){ |
|
14 | - return apply_filters( 'sd_pagenow_exclude', array( |
|
13 | +function sd_pagenow_exclude() { |
|
14 | + return apply_filters('sd_pagenow_exclude', array( |
|
15 | 15 | 'upload.php', |
16 | 16 | 'edit-comments.php', |
17 | 17 | 'edit-tags.php', |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | 'edit.php', |
23 | 23 | 'themes.php', |
24 | 24 | 'users.php', |
25 | - ) ); |
|
25 | + )); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | |
@@ -33,6 +33,6 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @return mixed|void |
35 | 35 | */ |
36 | -function sd_widget_exclude(){ |
|
37 | - return apply_filters( 'sd_widget_exclude', array() ); |
|
36 | +function sd_widget_exclude() { |
|
37 | + return apply_filters('sd_widget_exclude', array()); |
|
38 | 38 | } |
39 | 39 | \ No newline at end of file |