@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * |
7 | 7 | */ |
8 | 8 | if ( ! defined( 'ABSPATH' ) ) { |
9 | - exit; |
|
9 | + exit; |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | /** |
@@ -15,85 +15,85 @@ discard block |
||
15 | 15 | class WPInv_Admin_Addons extends Ayecode_Addons { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * Get the extensions page tabs. |
|
20 | - * |
|
21 | - * @return array of tabs. |
|
22 | - */ |
|
23 | - public function get_tabs(){ |
|
24 | - $tabs = array( |
|
25 | - 'addons' => __("Addons", "invoicing"), |
|
18 | + /** |
|
19 | + * Get the extensions page tabs. |
|
20 | + * |
|
21 | + * @return array of tabs. |
|
22 | + */ |
|
23 | + public function get_tabs(){ |
|
24 | + $tabs = array( |
|
25 | + 'addons' => __("Addons", "invoicing"), |
|
26 | 26 | 'gateways' => __("Payment Gateways", "invoicing"), |
27 | 27 | 'recommended_plugins' => __("Recommended plugins", "invoicing"), |
28 | 28 | 'membership' => __("Membership", "invoicing"), |
29 | - ); |
|
30 | - |
|
31 | - return $tabs; |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * Get section content for the addons screen. |
|
36 | - * |
|
37 | - * @param string $section_id |
|
38 | - * |
|
39 | - * @return array |
|
40 | - */ |
|
41 | - public function get_section_data( $section_id ) { |
|
42 | - $section = self::get_tab( $section_id ); |
|
43 | - $api_url = "https://wpinvoicing.com/edd-api/v2/products/"; |
|
44 | - $section_data = new stdClass(); |
|
45 | - |
|
46 | - if($section_id=='recommended_plugins'){ |
|
47 | - $section_data->products = self::get_recommend_wp_plugins_edd_formatted(); |
|
48 | - } |
|
49 | - elseif ( ! empty( $section ) ) { |
|
50 | - if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing |
|
51 | - //if ( 1==1) { |
|
52 | - |
|
53 | - $query_args = array( 'category' => $section_id, 'number' => 100); |
|
54 | - $query_args = apply_filters('wpeu_edd_api_query_args',$query_args,$api_url,$section_id); |
|
55 | - |
|
56 | - $raw_section = wp_safe_remote_get( esc_url_raw( add_query_arg($query_args ,$api_url) ), array( 'user-agent' => 'Invoicing Addons Page','timeout' => 15, ) ); |
|
57 | - |
|
58 | - if ( ! is_wp_error( $raw_section ) ) { |
|
59 | - $section_data = json_decode( wp_remote_retrieve_body( $raw_section ) ); |
|
60 | - |
|
61 | - if ( ! empty( $section_data->products ) ) { |
|
62 | - set_transient( 'wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS ); |
|
63 | - } |
|
64 | - } |
|
65 | - } |
|
66 | - |
|
67 | - } |
|
68 | - |
|
69 | - $products = isset($section_data->products) ? $section_data->products : array(); |
|
70 | - if ( 'addons' == $section_id ) { |
|
71 | - |
|
72 | - $quotes = new stdClass(); |
|
73 | - $quotes->info = new stdClass(); |
|
74 | - $quotes->info->id = ''; |
|
75 | - $quotes->info->slug = 'invoicing-quotes'; |
|
76 | - $quotes->info->title = __( 'Quotes', 'invoicing' ); |
|
77 | - $quotes->info->excerpt = __( 'Create quotes and estimates', 'invoicing' ); |
|
78 | - $quotes->info->link = 'https://wordpress.org/plugins/invoicing-quotes/'; |
|
79 | - $quotes->info->thumbnail = 'https://wpgetpaid.com/wp-content/uploads/sites/13/edd/2019/11/Quotes-1-768x384.png'; |
|
80 | - |
|
81 | - $products[] = $quotes; |
|
82 | - } |
|
29 | + ); |
|
30 | + |
|
31 | + return $tabs; |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * Get section content for the addons screen. |
|
36 | + * |
|
37 | + * @param string $section_id |
|
38 | + * |
|
39 | + * @return array |
|
40 | + */ |
|
41 | + public function get_section_data( $section_id ) { |
|
42 | + $section = self::get_tab( $section_id ); |
|
43 | + $api_url = "https://wpinvoicing.com/edd-api/v2/products/"; |
|
44 | + $section_data = new stdClass(); |
|
45 | + |
|
46 | + if($section_id=='recommended_plugins'){ |
|
47 | + $section_data->products = self::get_recommend_wp_plugins_edd_formatted(); |
|
48 | + } |
|
49 | + elseif ( ! empty( $section ) ) { |
|
50 | + if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing |
|
51 | + //if ( 1==1) { |
|
52 | + |
|
53 | + $query_args = array( 'category' => $section_id, 'number' => 100); |
|
54 | + $query_args = apply_filters('wpeu_edd_api_query_args',$query_args,$api_url,$section_id); |
|
55 | + |
|
56 | + $raw_section = wp_safe_remote_get( esc_url_raw( add_query_arg($query_args ,$api_url) ), array( 'user-agent' => 'Invoicing Addons Page','timeout' => 15, ) ); |
|
57 | + |
|
58 | + if ( ! is_wp_error( $raw_section ) ) { |
|
59 | + $section_data = json_decode( wp_remote_retrieve_body( $raw_section ) ); |
|
60 | + |
|
61 | + if ( ! empty( $section_data->products ) ) { |
|
62 | + set_transient( 'wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS ); |
|
63 | + } |
|
64 | + } |
|
65 | + } |
|
66 | + |
|
67 | + } |
|
68 | + |
|
69 | + $products = isset($section_data->products) ? $section_data->products : array(); |
|
70 | + if ( 'addons' == $section_id ) { |
|
71 | + |
|
72 | + $quotes = new stdClass(); |
|
73 | + $quotes->info = new stdClass(); |
|
74 | + $quotes->info->id = ''; |
|
75 | + $quotes->info->slug = 'invoicing-quotes'; |
|
76 | + $quotes->info->title = __( 'Quotes', 'invoicing' ); |
|
77 | + $quotes->info->excerpt = __( 'Create quotes and estimates', 'invoicing' ); |
|
78 | + $quotes->info->link = 'https://wordpress.org/plugins/invoicing-quotes/'; |
|
79 | + $quotes->info->thumbnail = 'https://wpgetpaid.com/wp-content/uploads/sites/13/edd/2019/11/Quotes-1-768x384.png'; |
|
80 | + |
|
81 | + $products[] = $quotes; |
|
82 | + } |
|
83 | 83 | |
84 | - return apply_filters( 'wpi_addons_section_data', $products, $section_id ); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Outputs a button. |
|
89 | - *ccc |
|
90 | - * @param string $url |
|
91 | - * @param string $text |
|
92 | - * @param string $theme |
|
93 | - * @param string $plugin |
|
94 | - */ |
|
95 | - public function output_button( $addon ) { |
|
96 | - $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
84 | + return apply_filters( 'wpi_addons_section_data', $products, $section_id ); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Outputs a button. |
|
89 | + *ccc |
|
90 | + * @param string $url |
|
91 | + * @param string $text |
|
92 | + * @param string $theme |
|
93 | + * @param string $plugin |
|
94 | + */ |
|
95 | + public function output_button( $addon ) { |
|
96 | + $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
97 | 97 | // $button_text = __('Free','invoicing'); |
98 | 98 | // $licensing = false; |
99 | 99 | // $installed = false; |
@@ -105,123 +105,123 @@ discard block |
||
105 | 105 | // $install_status = 'get'; |
106 | 106 | // $onclick = ''; |
107 | 107 | |
108 | - $wp_org_themes = array('supreme-directory','directory-starter'); |
|
109 | - |
|
110 | - $button_args = array( |
|
111 | - 'type' => ($current_tab == 'addons' || $current_tab =='gateways') ? 'addons' : $current_tab, |
|
112 | - 'id' => isset($addon->info->id) ? absint($addon->info->id) : '', |
|
113 | - 'title' => isset($addon->info->title) ? $addon->info->title : '', |
|
114 | - 'button_text' => __('Free','invoicing'), |
|
115 | - 'price_text' => __('Free','invoicing'), |
|
116 | - 'link' => isset($addon->info->link) ? $addon->info->link : '', // link to product |
|
117 | - 'url' => isset($addon->info->link) ? $addon->info->link : '', // button url |
|
118 | - 'class' => 'button-primary', |
|
119 | - 'install_status' => 'get', |
|
120 | - 'installed' => false, |
|
121 | - 'price' => '', |
|
122 | - 'licensing' => isset($addon->licensing->enabled) && $addon->licensing->enabled ? true : false, |
|
123 | - 'license' => isset($addon->licensing->license) && $addon->licensing->license ? $addon->licensing->license : '', |
|
124 | - 'onclick' => '', |
|
125 | - 'slug' => isset($addon->info->slug) ? $addon->info->slug : '', |
|
126 | - 'active' => false, |
|
127 | - 'file' => '', |
|
128 | - 'update_url' => '', |
|
129 | - ); |
|
130 | - |
|
131 | - if( 'invoicing-quotes' == $addon->info->slug || 'getpaid-stripe-payments' == $addon->info->slug || ( $current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug )){ |
|
132 | - include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
|
133 | - $status = install_plugin_install_status(array("slug"=>$button_args['slug'],"version"=>"")); |
|
134 | - $button_args['install_status'] = isset($status['status']) ? $status['status'] : 'install'; |
|
135 | - $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
|
136 | - }elseif( ($current_tab == 'addons' || $current_tab =='gateways') && isset($addon->info->id) && $addon->info->id){ |
|
137 | - include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
|
138 | - if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
|
139 | - $status = self::install_plugin_install_status($addon); |
|
140 | - $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
|
141 | - if(isset($status['status'])){$button_args['install_status'] = $status['status'];} |
|
142 | - $button_args['update_url'] = "https://wpinvoicing.com"; |
|
143 | - }elseif($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) { |
|
144 | - if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
|
145 | - $button_args['installed'] = self::is_theme_installed($addon); |
|
146 | - if(!in_array($button_args['slug'],$wp_org_themes)){ |
|
147 | - $button_args['update_url'] = "https://wpinvoicing.com"; |
|
148 | - } |
|
149 | - } |
|
150 | - |
|
151 | - // set price |
|
152 | - if(isset($addon->pricing) && !empty($addon->pricing)){ |
|
153 | - if(is_object($addon->pricing)){ |
|
154 | - $prices = (Array)$addon->pricing; |
|
155 | - $button_args['price'] = reset($prices); |
|
156 | - }elseif(isset($addon->pricing)){ |
|
157 | - $button_args['price'] = $addon->pricing; |
|
158 | - } |
|
159 | - } |
|
160 | - |
|
161 | - // set price text |
|
162 | - if( $button_args['price'] && $button_args['price'] != '0.00' ){ |
|
163 | - $button_args['price_text'] = sprintf( __('From: $%d', 'invoicing'), $button_args['price']); |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - // set if installed |
|
168 | - if(in_array($button_args['install_status'], array('installed','latest_installed','update_available','newer_installed'))){ |
|
169 | - $button_args['installed'] = true; |
|
170 | - } |
|
108 | + $wp_org_themes = array('supreme-directory','directory-starter'); |
|
109 | + |
|
110 | + $button_args = array( |
|
111 | + 'type' => ($current_tab == 'addons' || $current_tab =='gateways') ? 'addons' : $current_tab, |
|
112 | + 'id' => isset($addon->info->id) ? absint($addon->info->id) : '', |
|
113 | + 'title' => isset($addon->info->title) ? $addon->info->title : '', |
|
114 | + 'button_text' => __('Free','invoicing'), |
|
115 | + 'price_text' => __('Free','invoicing'), |
|
116 | + 'link' => isset($addon->info->link) ? $addon->info->link : '', // link to product |
|
117 | + 'url' => isset($addon->info->link) ? $addon->info->link : '', // button url |
|
118 | + 'class' => 'button-primary', |
|
119 | + 'install_status' => 'get', |
|
120 | + 'installed' => false, |
|
121 | + 'price' => '', |
|
122 | + 'licensing' => isset($addon->licensing->enabled) && $addon->licensing->enabled ? true : false, |
|
123 | + 'license' => isset($addon->licensing->license) && $addon->licensing->license ? $addon->licensing->license : '', |
|
124 | + 'onclick' => '', |
|
125 | + 'slug' => isset($addon->info->slug) ? $addon->info->slug : '', |
|
126 | + 'active' => false, |
|
127 | + 'file' => '', |
|
128 | + 'update_url' => '', |
|
129 | + ); |
|
130 | + |
|
131 | + if( 'invoicing-quotes' == $addon->info->slug || 'getpaid-stripe-payments' == $addon->info->slug || ( $current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug )){ |
|
132 | + include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
|
133 | + $status = install_plugin_install_status(array("slug"=>$button_args['slug'],"version"=>"")); |
|
134 | + $button_args['install_status'] = isset($status['status']) ? $status['status'] : 'install'; |
|
135 | + $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
|
136 | + }elseif( ($current_tab == 'addons' || $current_tab =='gateways') && isset($addon->info->id) && $addon->info->id){ |
|
137 | + include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
|
138 | + if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
|
139 | + $status = self::install_plugin_install_status($addon); |
|
140 | + $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
|
141 | + if(isset($status['status'])){$button_args['install_status'] = $status['status'];} |
|
142 | + $button_args['update_url'] = "https://wpinvoicing.com"; |
|
143 | + }elseif($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) { |
|
144 | + if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
|
145 | + $button_args['installed'] = self::is_theme_installed($addon); |
|
146 | + if(!in_array($button_args['slug'],$wp_org_themes)){ |
|
147 | + $button_args['update_url'] = "https://wpinvoicing.com"; |
|
148 | + } |
|
149 | + } |
|
150 | + |
|
151 | + // set price |
|
152 | + if(isset($addon->pricing) && !empty($addon->pricing)){ |
|
153 | + if(is_object($addon->pricing)){ |
|
154 | + $prices = (Array)$addon->pricing; |
|
155 | + $button_args['price'] = reset($prices); |
|
156 | + }elseif(isset($addon->pricing)){ |
|
157 | + $button_args['price'] = $addon->pricing; |
|
158 | + } |
|
159 | + } |
|
160 | + |
|
161 | + // set price text |
|
162 | + if( $button_args['price'] && $button_args['price'] != '0.00' ){ |
|
163 | + $button_args['price_text'] = sprintf( __('From: $%d', 'invoicing'), $button_args['price']); |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + // set if installed |
|
168 | + if(in_array($button_args['install_status'], array('installed','latest_installed','update_available','newer_installed'))){ |
|
169 | + $button_args['installed'] = true; |
|
170 | + } |
|
171 | 171 | |
172 | 172 | // print_r($button_args); |
173 | - // set if active |
|
174 | - if($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')){ |
|
175 | - if($button_args['type'] != 'themes'){ |
|
176 | - $button_args['active'] = is_plugin_active($button_args['file']); |
|
177 | - }else{ |
|
178 | - $button_args['active'] = self::is_theme_active($addon); |
|
179 | - } |
|
180 | - } |
|
181 | - |
|
182 | - // set button text and class |
|
183 | - if($button_args['active']){ |
|
184 | - $button_args['button_text'] = __('Active','invoicing'); |
|
185 | - $button_args['class'] = ' button-secondary disabled '; |
|
186 | - }elseif($button_args['installed']){ |
|
187 | - $button_args['button_text'] = __('Activate','invoicing'); |
|
188 | - |
|
189 | - if($button_args['type'] != 'themes'){ |
|
190 | - if ( current_user_can( 'manage_options' ) ) { |
|
191 | - $button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin='.$button_args['file']), 'activate-plugin_' . $button_args['file']); |
|
192 | - }else{ |
|
193 | - $button_args['url'] = '#'; |
|
194 | - } |
|
195 | - }else{ |
|
196 | - if ( current_user_can( 'switch_themes' ) ) { |
|
197 | - $button_args['url'] = self::get_theme_activation_url($addon); |
|
198 | - }else{ |
|
199 | - $button_args['url'] = '#'; |
|
200 | - } |
|
201 | - } |
|
202 | - |
|
203 | - }else{ |
|
204 | - if($button_args['type'] == 'recommended_plugins'){ |
|
205 | - $button_args['button_text'] = __('Install','invoicing'); |
|
206 | - }else{ |
|
207 | - $button_args['button_text'] = __('Get it','invoicing'); |
|
208 | - |
|
209 | - /*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){ |
|
173 | + // set if active |
|
174 | + if($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')){ |
|
175 | + if($button_args['type'] != 'themes'){ |
|
176 | + $button_args['active'] = is_plugin_active($button_args['file']); |
|
177 | + }else{ |
|
178 | + $button_args['active'] = self::is_theme_active($addon); |
|
179 | + } |
|
180 | + } |
|
181 | + |
|
182 | + // set button text and class |
|
183 | + if($button_args['active']){ |
|
184 | + $button_args['button_text'] = __('Active','invoicing'); |
|
185 | + $button_args['class'] = ' button-secondary disabled '; |
|
186 | + }elseif($button_args['installed']){ |
|
187 | + $button_args['button_text'] = __('Activate','invoicing'); |
|
188 | + |
|
189 | + if($button_args['type'] != 'themes'){ |
|
190 | + if ( current_user_can( 'manage_options' ) ) { |
|
191 | + $button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin='.$button_args['file']), 'activate-plugin_' . $button_args['file']); |
|
192 | + }else{ |
|
193 | + $button_args['url'] = '#'; |
|
194 | + } |
|
195 | + }else{ |
|
196 | + if ( current_user_can( 'switch_themes' ) ) { |
|
197 | + $button_args['url'] = self::get_theme_activation_url($addon); |
|
198 | + }else{ |
|
199 | + $button_args['url'] = '#'; |
|
200 | + } |
|
201 | + } |
|
202 | + |
|
203 | + }else{ |
|
204 | + if($button_args['type'] == 'recommended_plugins'){ |
|
205 | + $button_args['button_text'] = __('Install','invoicing'); |
|
206 | + }else{ |
|
207 | + $button_args['button_text'] = __('Get it','invoicing'); |
|
208 | + |
|
209 | + /*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){ |
|
210 | 210 | $button_args['button_text'] = __('Install','invoicing'); |
211 | 211 | $button_args['url'] = self::get_theme_install_url($button_args['slug']); |
212 | 212 | $button_args['onclick'] = 'gd_set_button_installing(this);'; |
213 | 213 | }*/ |
214 | 214 | |
215 | - } |
|
216 | - } |
|
215 | + } |
|
216 | + } |
|
217 | 217 | |
218 | 218 | |
219 | - // filter the button arguments |
|
220 | - $button_args = apply_filters('edd_api_button_args',$button_args); |
|
219 | + // filter the button arguments |
|
220 | + $button_args = apply_filters('edd_api_button_args',$button_args); |
|
221 | 221 | // print_r($button_args); |
222 | - // set price text |
|
223 | - if(isset($button_args['price_text'])){ |
|
224 | - ?> |
|
222 | + // set price text |
|
223 | + if(isset($button_args['price_text'])){ |
|
224 | + ?> |
|
225 | 225 | <a |
226 | 226 | target="_blank" |
227 | 227 | class="addons-price-text" |
@@ -229,15 +229,15 @@ discard block |
||
229 | 229 | <?php echo esc_html( $button_args['price_text'] ); ?> |
230 | 230 | </a> |
231 | 231 | <?php |
232 | - } |
|
232 | + } |
|
233 | 233 | |
234 | 234 | |
235 | - $target = ''; |
|
236 | - if ( ! empty( $button_args['url'] ) ) { |
|
237 | - $target = strpos($button_args['url'], get_site_url()) !== false ? '' : ' target="_blank" '; |
|
238 | - } |
|
235 | + $target = ''; |
|
236 | + if ( ! empty( $button_args['url'] ) ) { |
|
237 | + $target = strpos($button_args['url'], get_site_url()) !== false ? '' : ' target="_blank" '; |
|
238 | + } |
|
239 | 239 | |
240 | - ?> |
|
240 | + ?> |
|
241 | 241 | <a |
242 | 242 | data-licence="<?php echo esc_attr($button_args['license']);?>" |
243 | 243 | data-licensing="<?php echo $button_args['licensing'] ? 1 : 0;?>" |
@@ -260,33 +260,33 @@ discard block |
||
260 | 260 | <?php |
261 | 261 | |
262 | 262 | |
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - /** |
|
267 | - * Handles output of the addons page in admin. |
|
268 | - */ |
|
269 | - public function output() { |
|
270 | - $tabs = self::get_tabs(); |
|
271 | - $sections = self::get_sections(); |
|
272 | - $theme = wp_get_theme(); |
|
273 | - $section_keys = array_keys( $sections ); |
|
274 | - $current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys ); |
|
275 | - $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
276 | - include_once( WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php' ); |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * A list of recommended wp.org plugins. |
|
281 | - * @return array |
|
282 | - */ |
|
283 | - public function get_recommend_wp_plugins(){ |
|
284 | - $plugins = array( |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + /** |
|
267 | + * Handles output of the addons page in admin. |
|
268 | + */ |
|
269 | + public function output() { |
|
270 | + $tabs = self::get_tabs(); |
|
271 | + $sections = self::get_sections(); |
|
272 | + $theme = wp_get_theme(); |
|
273 | + $section_keys = array_keys( $sections ); |
|
274 | + $current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys ); |
|
275 | + $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
276 | + include_once( WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php' ); |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * A list of recommended wp.org plugins. |
|
281 | + * @return array |
|
282 | + */ |
|
283 | + public function get_recommend_wp_plugins(){ |
|
284 | + $plugins = array( |
|
285 | 285 | 'invoicing-quotes' => array( |
286 | 286 | 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
287 | 287 | 'slug' => 'invoicing-quotes', |
288 | - 'name' => 'Quotes', |
|
289 | - 'thumbnail' => 'https://ps.w.org/invoicing-quotes/assets/banner-772x250.png', |
|
288 | + 'name' => 'Quotes', |
|
289 | + 'thumbnail' => 'https://ps.w.org/invoicing-quotes/assets/banner-772x250.png', |
|
290 | 290 | 'desc' => __('Allows you to create quotes, send them to clients and convert them to Invoices when accepted by the customer.','invoicing'), |
291 | 291 | ), |
292 | 292 | 'geodirectory' => array( |
@@ -301,8 +301,8 @@ discard block |
||
301 | 301 | 'name' => 'UsersWP', |
302 | 302 | 'desc' => __('Allow frontend user login and registration as well as have slick profile pages.','invoicing'), |
303 | 303 | ), |
304 | - ); |
|
304 | + ); |
|
305 | 305 | |
306 | - return $plugins; |
|
307 | - } |
|
306 | + return $plugins; |
|
307 | + } |
|
308 | 308 | } |
@@ -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 |
@@ -13,96 +13,96 @@ discard block |
||
13 | 13 | class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'paypal'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'single_subscription_group' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | 34 | public $order = 1; |
35 | 35 | |
36 | 36 | /** |
37 | - * Stores line items to send to PayPal. |
|
38 | - * |
|
39 | - * @var array |
|
40 | - */ |
|
37 | + * Stores line items to send to PayPal. |
|
38 | + * |
|
39 | + * @var array |
|
40 | + */ |
|
41 | 41 | protected $line_items = array(); |
42 | 42 | |
43 | 43 | /** |
44 | - * Endpoint for requests from PayPal. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
48 | - protected $notify_url; |
|
49 | - |
|
50 | - /** |
|
51 | - * Endpoint for requests to PayPal. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
44 | + * Endpoint for requests from PayPal. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + protected $notify_url; |
|
49 | + |
|
50 | + /** |
|
51 | + * Endpoint for requests to PayPal. |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | 55 | protected $endpoint; |
56 | 56 | |
57 | 57 | /** |
58 | - * Currencies this gateway is allowed for. |
|
59 | - * |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
58 | + * Currencies this gateway is allowed for. |
|
59 | + * |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
63 | 63 | |
64 | 64 | /** |
65 | - * URL to view a transaction. |
|
66 | - * |
|
67 | - * @var string |
|
68 | - */ |
|
65 | + * URL to view a transaction. |
|
66 | + * |
|
67 | + * @var string |
|
68 | + */ |
|
69 | 69 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
70 | 70 | |
71 | 71 | /** |
72 | - * URL to view a subscription. |
|
73 | - * |
|
74 | - * @var string |
|
75 | - */ |
|
76 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
72 | + * URL to view a subscription. |
|
73 | + * |
|
74 | + * @var string |
|
75 | + */ |
|
76 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
77 | 77 | |
78 | 78 | /** |
79 | - * Class constructor. |
|
80 | - */ |
|
81 | - public function __construct() { |
|
79 | + * Class constructor. |
|
80 | + */ |
|
81 | + public function __construct() { |
|
82 | 82 | |
83 | 83 | $this->title = __( 'PayPal Standard', 'invoicing' ); |
84 | 84 | $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
85 | 85 | $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
86 | 86 | $this->notify_url = wpinv_get_ipn_url( $this->id ); |
87 | 87 | |
88 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
88 | + add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
89 | 89 | add_filter( 'getpaid_paypal_sandbox_notice', array( $this, 'sandbox_notice' ) ); |
90 | - add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
91 | - add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
90 | + add_filter( 'getpaid_get_paypal_connect_url', array( $this, 'maybe_get_connect_url' ), 10, 2 ); |
|
91 | + add_action( 'getpaid_authenticated_admin_action_connect_paypal', array( $this, 'connect_paypal' ) ); |
|
92 | 92 | |
93 | 93 | parent::__construct(); |
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
97 | - * Process Payment. |
|
98 | - * |
|
99 | - * |
|
100 | - * @param WPInv_Invoice $invoice Invoice. |
|
101 | - * @param array $submission_data Posted checkout fields. |
|
102 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
103 | - * @return array |
|
104 | - */ |
|
105 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
97 | + * Process Payment. |
|
98 | + * |
|
99 | + * |
|
100 | + * @param WPInv_Invoice $invoice Invoice. |
|
101 | + * @param array $submission_data Posted checkout fields. |
|
102 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
103 | + * @return array |
|
104 | + */ |
|
105 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
106 | 106 | |
107 | 107 | // Get redirect url. |
108 | 108 | $paypal_redirect = $this->get_request_url( $invoice ); |
@@ -125,15 +125,15 @@ discard block |
||
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
128 | - * Get the PayPal request URL for an invoice. |
|
129 | - * |
|
130 | - * @param WPInv_Invoice $invoice Invoice object. |
|
131 | - * @return string |
|
132 | - */ |
|
133 | - public function get_request_url( $invoice ) { |
|
128 | + * Get the PayPal request URL for an invoice. |
|
129 | + * |
|
130 | + * @param WPInv_Invoice $invoice Invoice object. |
|
131 | + * @return string |
|
132 | + */ |
|
133 | + public function get_request_url( $invoice ) { |
|
134 | 134 | |
135 | 135 | // Endpoint for this request |
136 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
136 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
137 | 137 | |
138 | 138 | // Retrieve paypal args. |
139 | 139 | $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
@@ -146,45 +146,45 @@ discard block |
||
146 | 146 | |
147 | 147 | return add_query_arg( $paypal_args, $this->endpoint ); |
148 | 148 | |
149 | - } |
|
149 | + } |
|
150 | 150 | |
151 | 151 | /** |
152 | - * Get PayPal Args for passing to PP. |
|
153 | - * |
|
154 | - * @param WPInv_Invoice $invoice Invoice object. |
|
155 | - * @return array |
|
156 | - */ |
|
157 | - protected function get_paypal_args( $invoice ) { |
|
152 | + * Get PayPal Args for passing to PP. |
|
153 | + * |
|
154 | + * @param WPInv_Invoice $invoice Invoice object. |
|
155 | + * @return array |
|
156 | + */ |
|
157 | + protected function get_paypal_args( $invoice ) { |
|
158 | 158 | |
159 | 159 | // Whether or not to send the line items as one item. |
160 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
161 | - |
|
162 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
163 | - $force_one_line_item = true; |
|
164 | - } |
|
165 | - |
|
166 | - $paypal_args = apply_filters( |
|
167 | - 'getpaid_paypal_args', |
|
168 | - array_merge( |
|
169 | - $this->get_transaction_args( $invoice ), |
|
170 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
171 | - ), |
|
172 | - $invoice |
|
173 | - ); |
|
174 | - |
|
175 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
160 | + $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', true, $invoice ); |
|
161 | + |
|
162 | + if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
163 | + $force_one_line_item = true; |
|
164 | + } |
|
165 | + |
|
166 | + $paypal_args = apply_filters( |
|
167 | + 'getpaid_paypal_args', |
|
168 | + array_merge( |
|
169 | + $this->get_transaction_args( $invoice ), |
|
170 | + $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
171 | + ), |
|
172 | + $invoice |
|
173 | + ); |
|
174 | + |
|
175 | + return $this->fix_request_length( $invoice, $paypal_args ); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
179 | - * Get transaction args for paypal request. |
|
180 | - * |
|
181 | - * @param WPInv_Invoice $invoice Invoice object. |
|
182 | - * @return array |
|
183 | - */ |
|
184 | - protected function get_transaction_args( $invoice ) { |
|
185 | - |
|
186 | - $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
187 | - return array( |
|
179 | + * Get transaction args for paypal request. |
|
180 | + * |
|
181 | + * @param WPInv_Invoice $invoice Invoice object. |
|
182 | + * @return array |
|
183 | + */ |
|
184 | + protected function get_transaction_args( $invoice ) { |
|
185 | + |
|
186 | + $email = $this->is_sandbox( $invoice ) ? wpinv_get_option( 'paypal_sandbox_email', wpinv_get_option( 'paypal_email', '' ) ) : wpinv_get_option( 'paypal_email', '' ); |
|
187 | + return array( |
|
188 | 188 | 'cmd' => '_cart', |
189 | 189 | 'business' => $email, |
190 | 190 | 'no_shipping' => '1', |
@@ -209,16 +209,16 @@ discard block |
||
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
212 | - * Get line item args for paypal request. |
|
213 | - * |
|
214 | - * @param WPInv_Invoice $invoice Invoice object. |
|
215 | - * @param bool $force_one_line_item Create only one item for this invoice. |
|
216 | - * @return array |
|
217 | - */ |
|
218 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
212 | + * Get line item args for paypal request. |
|
213 | + * |
|
214 | + * @param WPInv_Invoice $invoice Invoice object. |
|
215 | + * @param bool $force_one_line_item Create only one item for this invoice. |
|
216 | + * @return array |
|
217 | + */ |
|
218 | + protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
219 | 219 | |
220 | 220 | // Maybe send invoice as a single item. |
221 | - if ( $force_one_line_item ) { |
|
221 | + if ( $force_one_line_item ) { |
|
222 | 222 | return $this->get_line_item_args_single_item( $invoice ); |
223 | 223 | } |
224 | 224 | |
@@ -238,129 +238,129 @@ discard block |
||
238 | 238 | $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
239 | 239 | } |
240 | 240 | |
241 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
241 | + return array_merge( $line_item_args, $this->get_line_items() ); |
|
242 | 242 | |
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
246 | - * Get line item args for paypal request as a single line item. |
|
247 | - * |
|
248 | - * @param WPInv_Invoice $invoice Invoice object. |
|
249 | - * @return array |
|
250 | - */ |
|
251 | - protected function get_line_item_args_single_item( $invoice ) { |
|
252 | - $this->delete_line_items(); |
|
246 | + * Get line item args for paypal request as a single line item. |
|
247 | + * |
|
248 | + * @param WPInv_Invoice $invoice Invoice object. |
|
249 | + * @return array |
|
250 | + */ |
|
251 | + protected function get_line_item_args_single_item( $invoice ) { |
|
252 | + $this->delete_line_items(); |
|
253 | 253 | |
254 | 254 | $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
255 | - $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
255 | + $this->add_line_item( $item_name, 1, wpinv_round_amount( (float) $invoice->get_total(), 2, true ), $invoice->get_id() ); |
|
256 | 256 | |
257 | - return $this->get_line_items(); |
|
257 | + return $this->get_line_items(); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
261 | - * Return all line items. |
|
262 | - */ |
|
263 | - protected function get_line_items() { |
|
264 | - return $this->line_items; |
|
265 | - } |
|
261 | + * Return all line items. |
|
262 | + */ |
|
263 | + protected function get_line_items() { |
|
264 | + return $this->line_items; |
|
265 | + } |
|
266 | 266 | |
267 | 267 | /** |
268 | - * Remove all line items. |
|
269 | - */ |
|
270 | - protected function delete_line_items() { |
|
271 | - $this->line_items = array(); |
|
268 | + * Remove all line items. |
|
269 | + */ |
|
270 | + protected function delete_line_items() { |
|
271 | + $this->line_items = array(); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
275 | - * Prepare line items to send to paypal. |
|
276 | - * |
|
277 | - * @param WPInv_Invoice $invoice Invoice object. |
|
278 | - */ |
|
279 | - protected function prepare_line_items( $invoice ) { |
|
280 | - $this->delete_line_items(); |
|
281 | - |
|
282 | - // Items. |
|
283 | - foreach ( $invoice->get_items() as $item ) { |
|
284 | - $amount = $item->get_price(); |
|
285 | - $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
286 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
275 | + * Prepare line items to send to paypal. |
|
276 | + * |
|
277 | + * @param WPInv_Invoice $invoice Invoice object. |
|
278 | + */ |
|
279 | + protected function prepare_line_items( $invoice ) { |
|
280 | + $this->delete_line_items(); |
|
281 | + |
|
282 | + // Items. |
|
283 | + foreach ( $invoice->get_items() as $item ) { |
|
284 | + $amount = $item->get_price(); |
|
285 | + $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
286 | + $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | // Fees. |
290 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
290 | + foreach ( $invoice->get_fees() as $fee => $data ) { |
|
291 | 291 | $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
292 | 292 | } |
293 | 293 | |
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
297 | - * Add PayPal Line Item. |
|
298 | - * |
|
299 | - * @param string $item_name Item name. |
|
300 | - * @param float $quantity Item quantity. |
|
301 | - * @param float $amount Amount. |
|
302 | - * @param string $item_number Item number. |
|
303 | - */ |
|
304 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
305 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
306 | - |
|
307 | - $item = apply_filters( |
|
308 | - 'getpaid_paypal_line_item', |
|
309 | - array( |
|
310 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
311 | - 'quantity' => (float) $quantity, |
|
312 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
313 | - 'item_number' => $item_number, |
|
314 | - ), |
|
315 | - $item_name, |
|
316 | - $quantity, |
|
317 | - $amount, |
|
318 | - $item_number |
|
319 | - ); |
|
320 | - |
|
321 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
297 | + * Add PayPal Line Item. |
|
298 | + * |
|
299 | + * @param string $item_name Item name. |
|
300 | + * @param float $quantity Item quantity. |
|
301 | + * @param float $amount Amount. |
|
302 | + * @param string $item_number Item number. |
|
303 | + */ |
|
304 | + protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
305 | + $index = ( count( $this->line_items ) / 4 ) + 1; |
|
306 | + |
|
307 | + $item = apply_filters( |
|
308 | + 'getpaid_paypal_line_item', |
|
309 | + array( |
|
310 | + 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
311 | + 'quantity' => (float) $quantity, |
|
312 | + 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
313 | + 'item_number' => $item_number, |
|
314 | + ), |
|
315 | + $item_name, |
|
316 | + $quantity, |
|
317 | + $amount, |
|
318 | + $item_number |
|
319 | + ); |
|
320 | + |
|
321 | + $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
322 | 322 | $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
323 | 323 | |
324 | 324 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
325 | - $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
326 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
325 | + $this->line_items[ 'amount_' . $index ] = $item['amount'] * $item['quantity']; |
|
326 | + $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
330 | - * If the default request with line items is too long, generate a new one with only one line item. |
|
331 | - * |
|
332 | - * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
333 | - * |
|
334 | - * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
335 | - * @param array $paypal_args Arguments sent to Paypal in the request. |
|
336 | - * @return array |
|
337 | - */ |
|
338 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
339 | - $max_paypal_length = 2083; |
|
340 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
341 | - |
|
342 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
343 | - return $paypal_args; |
|
344 | - } |
|
345 | - |
|
346 | - return apply_filters( |
|
347 | - 'getpaid_paypal_args', |
|
348 | - array_merge( |
|
349 | - $this->get_transaction_args( $invoice ), |
|
350 | - $this->get_line_item_args( $invoice, true ) |
|
351 | - ), |
|
352 | - $invoice |
|
353 | - ); |
|
330 | + * If the default request with line items is too long, generate a new one with only one line item. |
|
331 | + * |
|
332 | + * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
333 | + * |
|
334 | + * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
335 | + * @param array $paypal_args Arguments sent to Paypal in the request. |
|
336 | + * @return array |
|
337 | + */ |
|
338 | + protected function fix_request_length( $invoice, $paypal_args ) { |
|
339 | + $max_paypal_length = 2083; |
|
340 | + $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
341 | + |
|
342 | + if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
343 | + return $paypal_args; |
|
344 | + } |
|
345 | + |
|
346 | + return apply_filters( |
|
347 | + 'getpaid_paypal_args', |
|
348 | + array_merge( |
|
349 | + $this->get_transaction_args( $invoice ), |
|
350 | + $this->get_line_item_args( $invoice, true ) |
|
351 | + ), |
|
352 | + $invoice |
|
353 | + ); |
|
354 | 354 | |
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
358 | - * Processes recurring invoices. |
|
359 | - * |
|
360 | - * @param array $paypal_args PayPal args. |
|
361 | - * @param WPInv_Invoice $invoice Invoice object. |
|
362 | - */ |
|
363 | - public function process_subscription( $paypal_args, $invoice ) { |
|
358 | + * Processes recurring invoices. |
|
359 | + * |
|
360 | + * @param array $paypal_args PayPal args. |
|
361 | + * @param WPInv_Invoice $invoice Invoice object. |
|
362 | + */ |
|
363 | + public function process_subscription( $paypal_args, $invoice ) { |
|
364 | 364 | |
365 | 365 | // Make sure this is a subscription. |
366 | 366 | if ( ! $invoice->is_recurring() || ! $subscription = getpaid_get_invoice_subscription( $invoice ) ) { |
@@ -385,11 +385,11 @@ discard block |
||
385 | 385 | |
386 | 386 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
387 | 387 | |
388 | - // Trial period length. |
|
389 | - $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
388 | + // Trial period length. |
|
389 | + $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
390 | 390 | |
391 | - // Trial period. |
|
392 | - $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
391 | + // Trial period. |
|
392 | + $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
393 | 393 | |
394 | 394 | } else if ( $initial_amount != $recurring_amount ) { |
395 | 395 | |
@@ -412,40 +412,40 @@ discard block |
||
412 | 412 | } |
413 | 413 | |
414 | 414 | // We have a recurring payment |
415 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
415 | + if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
416 | 416 | |
417 | - // Subscription price |
|
418 | - $paypal_args['a3'] = $recurring_amount; |
|
417 | + // Subscription price |
|
418 | + $paypal_args['a3'] = $recurring_amount; |
|
419 | 419 | |
420 | - // Subscription duration |
|
421 | - $paypal_args['p3'] = $interval; |
|
420 | + // Subscription duration |
|
421 | + $paypal_args['p3'] = $interval; |
|
422 | 422 | |
423 | - // Subscription period |
|
424 | - $paypal_args['t3'] = $period; |
|
423 | + // Subscription period |
|
424 | + $paypal_args['t3'] = $period; |
|
425 | 425 | |
426 | 426 | } |
427 | 427 | |
428 | 428 | // Recurring payments |
429 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
429 | + if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
430 | 430 | |
431 | - // Non-recurring payments |
|
432 | - $paypal_args['src'] = 0; |
|
431 | + // Non-recurring payments |
|
432 | + $paypal_args['src'] = 0; |
|
433 | 433 | |
434 | - } else { |
|
434 | + } else { |
|
435 | 435 | |
436 | - $paypal_args['src'] = 1; |
|
436 | + $paypal_args['src'] = 1; |
|
437 | 437 | |
438 | - if ( $bill_times > 0 ) { |
|
438 | + if ( $bill_times > 0 ) { |
|
439 | 439 | |
440 | - // An initial period is being used to charge a sign-up fee |
|
441 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
442 | - $bill_times--; |
|
443 | - } |
|
440 | + // An initial period is being used to charge a sign-up fee |
|
441 | + if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
442 | + $bill_times--; |
|
443 | + } |
|
444 | 444 | |
445 | 445 | // Make sure it's not over the max of 52 |
446 | 446 | $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
447 | 447 | |
448 | - } |
|
448 | + } |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | // Force return URL so that order description & instructions display |
@@ -461,19 +461,19 @@ discard block |
||
461 | 461 | } |
462 | 462 | |
463 | 463 | return apply_filters( |
464 | - 'getpaid_paypal_subscription_args', |
|
465 | - $paypal_args, |
|
466 | - $invoice |
|
464 | + 'getpaid_paypal_subscription_args', |
|
465 | + $paypal_args, |
|
466 | + $invoice |
|
467 | 467 | ); |
468 | 468 | |
469 | 469 | } |
470 | 470 | |
471 | 471 | /** |
472 | - * Processes ipns and marks payments as complete. |
|
473 | - * |
|
474 | - * @return void |
|
475 | - */ |
|
476 | - public function verify_ipn() { |
|
472 | + * Processes ipns and marks payments as complete. |
|
473 | + * |
|
474 | + * @return void |
|
475 | + */ |
|
476 | + public function verify_ipn() { |
|
477 | 477 | new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
478 | 478 | } |
479 | 479 | |
@@ -483,19 +483,19 @@ discard block |
||
483 | 483 | public function sandbox_notice() { |
484 | 484 | |
485 | 485 | return sprintf( |
486 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
487 | - '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
488 | - '</a>' |
|
489 | - ); |
|
486 | + __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
487 | + '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
|
488 | + '</a>' |
|
489 | + ); |
|
490 | 490 | |
491 | 491 | } |
492 | 492 | |
493 | - /** |
|
494 | - * Filters the gateway settings. |
|
495 | - * |
|
496 | - * @param array $admin_settings |
|
497 | - */ |
|
498 | - public function admin_settings( $admin_settings ) { |
|
493 | + /** |
|
494 | + * Filters the gateway settings. |
|
495 | + * |
|
496 | + * @param array $admin_settings |
|
497 | + */ |
|
498 | + public function admin_settings( $admin_settings ) { |
|
499 | 499 | |
500 | 500 | $currencies = sprintf( |
501 | 501 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -505,39 +505,39 @@ discard block |
||
505 | 505 | $admin_settings['paypal_active']['desc'] .= " ($currencies)"; |
506 | 506 | $admin_settings['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
507 | 507 | |
508 | - // Access tokens. |
|
509 | - $live_email = wpinv_get_option( 'paypal_email' ); |
|
510 | - $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
511 | - |
|
512 | - $admin_settings['paypal_connect'] = array( |
|
513 | - 'type' => 'raw_html', |
|
514 | - 'id' => 'paypal_connect', |
|
515 | - 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
516 | - 'desc' => sprintf( |
|
517 | - '<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a></div>%s', |
|
518 | - esc_url( self::get_connect_url( false ) ), |
|
519 | - __( 'Connect to PayPal', 'invoicing' ), |
|
520 | - esc_url( self::get_connect_url( true ) ), |
|
521 | - __( 'Connect to PayPal Sandox', 'invoicing' ), |
|
522 | - $this->get_js() |
|
523 | - ), |
|
524 | - ); |
|
508 | + // Access tokens. |
|
509 | + $live_email = wpinv_get_option( 'paypal_email' ); |
|
510 | + $sandbox_email = wpinv_get_option( 'paypal_sandbox_email' ); |
|
511 | + |
|
512 | + $admin_settings['paypal_connect'] = array( |
|
513 | + 'type' => 'raw_html', |
|
514 | + 'id' => 'paypal_connect', |
|
515 | + 'name' => __( 'Connect to PayPal', 'invoicing' ), |
|
516 | + 'desc' => sprintf( |
|
517 | + '<div class="wpinv-paypal-connect-live"><a class="button button-primary" href="%s">%s</a></div><div class="wpinv-paypal-connect-sandbox"><a class="button button-primary" href="%s">%s</a></div>%s', |
|
518 | + esc_url( self::get_connect_url( false ) ), |
|
519 | + __( 'Connect to PayPal', 'invoicing' ), |
|
520 | + esc_url( self::get_connect_url( true ) ), |
|
521 | + __( 'Connect to PayPal Sandox', 'invoicing' ), |
|
522 | + $this->get_js() |
|
523 | + ), |
|
524 | + ); |
|
525 | 525 | |
526 | 526 | $admin_settings['paypal_email'] = array( |
527 | 527 | 'type' => 'text', |
528 | - 'class' => 'live-auth-data', |
|
528 | + 'class' => 'live-auth-data', |
|
529 | 529 | 'id' => 'paypal_email', |
530 | 530 | 'name' => __( 'Live Email Address', 'invoicing' ), |
531 | 531 | 'desc' => __( 'The email address of your PayPal account.', 'invoicing' ), |
532 | 532 | ); |
533 | 533 | |
534 | - $admin_settings['paypal_sandbox_email'] = array( |
|
534 | + $admin_settings['paypal_sandbox_email'] = array( |
|
535 | 535 | 'type' => 'text', |
536 | - 'class' => 'sandbox-auth-data', |
|
536 | + 'class' => 'sandbox-auth-data', |
|
537 | 537 | 'id' => 'paypal_sandbox_email', |
538 | 538 | 'name' => __( 'Sandbox Email Address', 'invoicing' ), |
539 | 539 | 'desc' => __( 'The email address of your sandbox PayPal account.', 'invoicing' ), |
540 | - 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
540 | + 'std' => wpinv_get_option( 'paypal_email', '' ), |
|
541 | 541 | ); |
542 | 542 | |
543 | 543 | $admin_settings['paypal_ipn_url'] = array( |
@@ -549,29 +549,29 @@ discard block |
||
549 | 549 | 'readonly' => true, |
550 | 550 | ); |
551 | 551 | |
552 | - return $admin_settings; |
|
553 | - } |
|
552 | + return $admin_settings; |
|
553 | + } |
|
554 | 554 | |
555 | - /** |
|
556 | - * Retrieves the PayPal connect URL when using the setup wizzard. |
|
557 | - * |
|
558 | - * |
|
555 | + /** |
|
556 | + * Retrieves the PayPal connect URL when using the setup wizzard. |
|
557 | + * |
|
558 | + * |
|
559 | 559 | * @param array $data |
560 | 560 | * @return string |
561 | - */ |
|
562 | - public static function maybe_get_connect_url( $url = '', $data ) { |
|
563 | - return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
564 | - } |
|
565 | - |
|
566 | - /** |
|
567 | - * Retrieves the PayPal connect URL. |
|
568 | - * |
|
569 | - * |
|
561 | + */ |
|
562 | + public static function maybe_get_connect_url( $url = '', $data ) { |
|
563 | + return self::get_connect_url( false, urldecode( $data['redirect'] ) ); |
|
564 | + } |
|
565 | + |
|
566 | + /** |
|
567 | + * Retrieves the PayPal connect URL. |
|
568 | + * |
|
569 | + * |
|
570 | 570 | * @param bool $is_sandbox |
571 | - * @param string $redirect |
|
571 | + * @param string $redirect |
|
572 | 572 | * @return string |
573 | - */ |
|
574 | - public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
573 | + */ |
|
574 | + public static function get_connect_url( $is_sandbox, $redirect = '' ) { |
|
575 | 575 | |
576 | 576 | $redirect_url = add_query_arg( |
577 | 577 | array( |
@@ -581,7 +581,7 @@ discard block |
||
581 | 581 | 'tab' => 'gateways', |
582 | 582 | 'section' => 'paypal', |
583 | 583 | 'getpaid-nonce' => wp_create_nonce( 'getpaid-nonce' ), |
584 | - 'redirect' => urlencode( $redirect ), |
|
584 | + 'redirect' => urlencode( $redirect ), |
|
585 | 585 | ), |
586 | 586 | admin_url( 'admin.php' ) |
587 | 587 | ); |
@@ -596,12 +596,12 @@ discard block |
||
596 | 596 | |
597 | 597 | } |
598 | 598 | |
599 | - /** |
|
600 | - * Generates settings page js. |
|
601 | - * |
|
599 | + /** |
|
600 | + * Generates settings page js. |
|
601 | + * |
|
602 | 602 | * @return void |
603 | - */ |
|
604 | - public static function get_js() { |
|
603 | + */ |
|
604 | + public static function get_js() { |
|
605 | 605 | ob_start(); |
606 | 606 | ?> |
607 | 607 | <script> |
@@ -637,72 +637,72 @@ discard block |
||
637 | 637 | return ob_get_clean(); |
638 | 638 | } |
639 | 639 | |
640 | - /** |
|
641 | - * Connects to PayPal. |
|
642 | - * |
|
643 | - * @param array $data Connection data. |
|
644 | - * @return void |
|
645 | - */ |
|
646 | - public function connect_paypal( $data ) { |
|
647 | - |
|
648 | - $sandbox = $this->is_sandbox(); |
|
649 | - $data = wp_unslash( $data ); |
|
650 | - $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
651 | - |
|
652 | - if ( isset( $data['live_mode'] ) ) { |
|
653 | - $sandbox = empty( $data['live_mode'] ); |
|
654 | - } |
|
655 | - |
|
656 | - wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
657 | - wpinv_update_option( 'paypal_active', 1 ); |
|
658 | - |
|
659 | - if ( ! empty( $data['error_description'] ) ) { |
|
660 | - getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
661 | - } else { |
|
662 | - |
|
663 | - // Retrieve the user info. |
|
664 | - $user_info = wp_remote_get( |
|
665 | - ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
666 | - array( |
|
667 | - |
|
668 | - 'headers' => array( |
|
669 | - 'Authorization' => 'Bearer ' . $access_token, |
|
670 | - 'Content-type' => 'application/json', |
|
671 | - ) |
|
672 | - |
|
673 | - ) |
|
674 | - ); |
|
675 | - |
|
676 | - if ( is_wp_error( $user_info ) ) { |
|
677 | - getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
678 | - } else { |
|
679 | - |
|
680 | - // Create application. |
|
681 | - $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
682 | - |
|
683 | - if ( $sandbox ) { |
|
684 | - wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
685 | - wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
686 | - set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
687 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
688 | - } else { |
|
689 | - wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
690 | - wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
691 | - set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
692 | - getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
693 | - } |
|
694 | - |
|
695 | - } |
|
696 | - |
|
697 | - } |
|
698 | - |
|
699 | - $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
700 | - |
|
701 | - if ( isset( $data['step'] ) ) { |
|
702 | - $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
703 | - } |
|
704 | - wp_redirect( $redirect ); |
|
705 | - exit; |
|
706 | - } |
|
640 | + /** |
|
641 | + * Connects to PayPal. |
|
642 | + * |
|
643 | + * @param array $data Connection data. |
|
644 | + * @return void |
|
645 | + */ |
|
646 | + public function connect_paypal( $data ) { |
|
647 | + |
|
648 | + $sandbox = $this->is_sandbox(); |
|
649 | + $data = wp_unslash( $data ); |
|
650 | + $access_token = empty( $data['access_token'] ) ? '' : sanitize_text_field( $data['access_token'] ); |
|
651 | + |
|
652 | + if ( isset( $data['live_mode'] ) ) { |
|
653 | + $sandbox = empty( $data['live_mode'] ); |
|
654 | + } |
|
655 | + |
|
656 | + wpinv_update_option( 'paypal_sandbox', (int) $sandbox ); |
|
657 | + wpinv_update_option( 'paypal_active', 1 ); |
|
658 | + |
|
659 | + if ( ! empty( $data['error_description'] ) ) { |
|
660 | + getpaid_admin()->show_error( wp_kses_post( urldecode( $data['error_description'] ) ) ); |
|
661 | + } else { |
|
662 | + |
|
663 | + // Retrieve the user info. |
|
664 | + $user_info = wp_remote_get( |
|
665 | + ! $sandbox ? 'https://api-m.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1' : 'https://api-m.sandbox.paypal.com/v1/identity/oauth2/userinfo?schema=paypalv1.1', |
|
666 | + array( |
|
667 | + |
|
668 | + 'headers' => array( |
|
669 | + 'Authorization' => 'Bearer ' . $access_token, |
|
670 | + 'Content-type' => 'application/json', |
|
671 | + ) |
|
672 | + |
|
673 | + ) |
|
674 | + ); |
|
675 | + |
|
676 | + if ( is_wp_error( $user_info ) ) { |
|
677 | + getpaid_admin()->show_error( wp_kses_post( $user_info->get_error_message() ) ); |
|
678 | + } else { |
|
679 | + |
|
680 | + // Create application. |
|
681 | + $user_info = json_decode( wp_remote_retrieve_body( $user_info ) ); |
|
682 | + |
|
683 | + if ( $sandbox ) { |
|
684 | + wpinv_update_option( 'paypal_sandbox_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
685 | + wpinv_update_option( 'paypal_sandbox_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
686 | + set_transient( 'getpaid_paypal_sandbox_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
687 | + getpaid_admin()->show_success( __( 'Successfully connected your PayPal sandbox account', 'invoicing' ) ); |
|
688 | + } else { |
|
689 | + wpinv_update_option( 'paypal_email', sanitize_email( $user_info->emails[0]->value ) ); |
|
690 | + wpinv_update_option( 'paypal_refresh_token', sanitize_text_field( urldecode( $data['refresh_token'] ) ) ); |
|
691 | + set_transient( 'getpaid_paypal_access_token', sanitize_text_field( urldecode( $data['access_token'] ) ), (int) $data['expires_in'] ); |
|
692 | + getpaid_admin()->show_success( __( 'Successfully connected your PayPal account', 'invoicing' ) ); |
|
693 | + } |
|
694 | + |
|
695 | + } |
|
696 | + |
|
697 | + } |
|
698 | + |
|
699 | + $redirect = empty( $data['redirect'] ) ? admin_url( 'admin.php?page=wpinv-settings&tab=gateways§ion=paypal' ) : urldecode( $data['redirect'] ); |
|
700 | + |
|
701 | + if ( isset( $data['step'] ) ) { |
|
702 | + $redirect = add_query_arg( 'step', $data['step'], $redirect ); |
|
703 | + } |
|
704 | + wp_redirect( $redirect ); |
|
705 | + exit; |
|
706 | + } |
|
707 | 707 | |
708 | 708 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
8 | - exit; |
|
8 | + exit; |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | /** |
@@ -15,542 +15,542 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Invoice_Data_Store extends GetPaid_Data_Store_WP { |
17 | 17 | |
18 | - /** |
|
19 | - * Data stored in meta keys, but not considered "meta" for a discount. |
|
20 | - * |
|
21 | - * @since 1.0.19 |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $internal_meta_keys = array( |
|
25 | - '_wpinv_subscr_profile_id', |
|
26 | - '_wpinv_subscription_id', |
|
27 | - '_wpinv_taxes', |
|
28 | - '_wpinv_fees', |
|
29 | - '_wpinv_discounts', |
|
30 | - '_wpinv_submission_id', |
|
31 | - '_wpinv_payment_form', |
|
32 | - '_wpinv_is_viewed', |
|
33 | - '_wpinv_phone', |
|
34 | - '_wpinv_company_id', |
|
35 | - 'wpinv_email_cc', |
|
36 | - 'wpinv_template', |
|
37 | - 'wpinv_created_via' |
|
38 | - ); |
|
39 | - |
|
40 | - /** |
|
41 | - * A map of meta keys to data props. |
|
42 | - * |
|
43 | - * @since 1.0.19 |
|
44 | - * |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - protected $meta_key_to_props = array( |
|
48 | - '_wpinv_subscr_profile_id' => 'remote_subscription_id', |
|
49 | - '_wpinv_subscription_id' => 'subscription_id', |
|
50 | - '_wpinv_taxes' => 'taxes', |
|
51 | - '_wpinv_fees' => 'fees', |
|
52 | - '_wpinv_discounts' => 'discounts', |
|
53 | - '_wpinv_submission_id' => 'submission_id', |
|
54 | - '_wpinv_payment_form' => 'payment_form', |
|
55 | - '_wpinv_is_viewed' => 'is_viewed', |
|
56 | - 'wpinv_email_cc' => 'email_cc', |
|
57 | - 'wpinv_template' => 'template', |
|
58 | - 'wpinv_created_via' => 'created_via', |
|
59 | - '_wpinv_phone' => 'phone', |
|
60 | - '_wpinv_company_id' => 'company_id', |
|
61 | - ); |
|
62 | - |
|
63 | - /** |
|
64 | - * A map of database fields to data props. |
|
65 | - * |
|
66 | - * @since 1.0.19 |
|
67 | - * |
|
68 | - * @var array |
|
69 | - */ |
|
70 | - protected $database_fields_to_props = array( |
|
71 | - 'post_id' => 'id', |
|
72 | - 'number' => 'number', |
|
73 | - 'currency' => 'currency', |
|
74 | - 'key' => 'key', |
|
75 | - 'type' => 'type', |
|
76 | - 'mode' => 'mode', |
|
77 | - 'user_ip' => 'user_ip', |
|
78 | - 'first_name' => 'first_name', |
|
79 | - 'last_name' => 'last_name', |
|
80 | - 'address' => 'address', |
|
81 | - 'city' => 'city', |
|
82 | - 'state' => 'state', |
|
83 | - 'country' => 'country', |
|
84 | - 'zip' => 'zip', |
|
85 | - 'zip' => 'zip', |
|
86 | - 'adddress_confirmed' => 'address_confirmed', |
|
87 | - 'gateway' => 'gateway', |
|
88 | - 'transaction_id' => 'transaction_id', |
|
89 | - 'currency' => 'currency', |
|
90 | - 'subtotal' => 'subtotal', |
|
91 | - 'tax' => 'total_tax', |
|
92 | - 'fees_total' => 'total_fees', |
|
93 | - 'discount' => 'total_discount', |
|
94 | - 'total' => 'total', |
|
95 | - 'discount_code' => 'discount_code', |
|
96 | - 'disable_taxes' => 'disable_taxes', |
|
97 | - 'due_date' => 'due_date', |
|
98 | - 'completed_date' => 'completed_date', |
|
99 | - 'company' => 'company', |
|
100 | - 'vat_number' => 'vat_number', |
|
101 | - 'vat_rate' => 'vat_rate', |
|
102 | - ); |
|
103 | - |
|
104 | - /* |
|
18 | + /** |
|
19 | + * Data stored in meta keys, but not considered "meta" for a discount. |
|
20 | + * |
|
21 | + * @since 1.0.19 |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $internal_meta_keys = array( |
|
25 | + '_wpinv_subscr_profile_id', |
|
26 | + '_wpinv_subscription_id', |
|
27 | + '_wpinv_taxes', |
|
28 | + '_wpinv_fees', |
|
29 | + '_wpinv_discounts', |
|
30 | + '_wpinv_submission_id', |
|
31 | + '_wpinv_payment_form', |
|
32 | + '_wpinv_is_viewed', |
|
33 | + '_wpinv_phone', |
|
34 | + '_wpinv_company_id', |
|
35 | + 'wpinv_email_cc', |
|
36 | + 'wpinv_template', |
|
37 | + 'wpinv_created_via' |
|
38 | + ); |
|
39 | + |
|
40 | + /** |
|
41 | + * A map of meta keys to data props. |
|
42 | + * |
|
43 | + * @since 1.0.19 |
|
44 | + * |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + protected $meta_key_to_props = array( |
|
48 | + '_wpinv_subscr_profile_id' => 'remote_subscription_id', |
|
49 | + '_wpinv_subscription_id' => 'subscription_id', |
|
50 | + '_wpinv_taxes' => 'taxes', |
|
51 | + '_wpinv_fees' => 'fees', |
|
52 | + '_wpinv_discounts' => 'discounts', |
|
53 | + '_wpinv_submission_id' => 'submission_id', |
|
54 | + '_wpinv_payment_form' => 'payment_form', |
|
55 | + '_wpinv_is_viewed' => 'is_viewed', |
|
56 | + 'wpinv_email_cc' => 'email_cc', |
|
57 | + 'wpinv_template' => 'template', |
|
58 | + 'wpinv_created_via' => 'created_via', |
|
59 | + '_wpinv_phone' => 'phone', |
|
60 | + '_wpinv_company_id' => 'company_id', |
|
61 | + ); |
|
62 | + |
|
63 | + /** |
|
64 | + * A map of database fields to data props. |
|
65 | + * |
|
66 | + * @since 1.0.19 |
|
67 | + * |
|
68 | + * @var array |
|
69 | + */ |
|
70 | + protected $database_fields_to_props = array( |
|
71 | + 'post_id' => 'id', |
|
72 | + 'number' => 'number', |
|
73 | + 'currency' => 'currency', |
|
74 | + 'key' => 'key', |
|
75 | + 'type' => 'type', |
|
76 | + 'mode' => 'mode', |
|
77 | + 'user_ip' => 'user_ip', |
|
78 | + 'first_name' => 'first_name', |
|
79 | + 'last_name' => 'last_name', |
|
80 | + 'address' => 'address', |
|
81 | + 'city' => 'city', |
|
82 | + 'state' => 'state', |
|
83 | + 'country' => 'country', |
|
84 | + 'zip' => 'zip', |
|
85 | + 'zip' => 'zip', |
|
86 | + 'adddress_confirmed' => 'address_confirmed', |
|
87 | + 'gateway' => 'gateway', |
|
88 | + 'transaction_id' => 'transaction_id', |
|
89 | + 'currency' => 'currency', |
|
90 | + 'subtotal' => 'subtotal', |
|
91 | + 'tax' => 'total_tax', |
|
92 | + 'fees_total' => 'total_fees', |
|
93 | + 'discount' => 'total_discount', |
|
94 | + 'total' => 'total', |
|
95 | + 'discount_code' => 'discount_code', |
|
96 | + 'disable_taxes' => 'disable_taxes', |
|
97 | + 'due_date' => 'due_date', |
|
98 | + 'completed_date' => 'completed_date', |
|
99 | + 'company' => 'company', |
|
100 | + 'vat_number' => 'vat_number', |
|
101 | + 'vat_rate' => 'vat_rate', |
|
102 | + ); |
|
103 | + |
|
104 | + /* |
|
105 | 105 | |-------------------------------------------------------------------------- |
106 | 106 | | CRUD Methods |
107 | 107 | |-------------------------------------------------------------------------- |
108 | 108 | */ |
109 | 109 | |
110 | - /** |
|
111 | - * Method to create a new invoice in the database. |
|
112 | - * |
|
113 | - * @param WPInv_Invoice $invoice Invoice object. |
|
114 | - */ |
|
115 | - public function create( &$invoice ) { |
|
116 | - $invoice->set_version( WPINV_VERSION ); |
|
117 | - $invoice->set_date_created( current_time('mysql') ); |
|
118 | - |
|
119 | - // Create a new post. |
|
120 | - $id = wp_insert_post( |
|
121 | - apply_filters( |
|
122 | - 'getpaid_new_invoice_data', |
|
123 | - array( |
|
124 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
125 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
126 | - 'post_status' => $this->get_post_status( $invoice ), |
|
127 | - 'ping_status' => 'closed', |
|
128 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
129 | - 'post_title' => $invoice->get_title( 'edit' ), |
|
130 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
131 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
132 | - ) |
|
133 | - ), |
|
134 | - true |
|
135 | - ); |
|
136 | - |
|
137 | - if ( $id && ! is_wp_error( $id ) ) { |
|
138 | - |
|
139 | - // Update the new id and regenerate a title. |
|
140 | - $invoice->set_id( $id ); |
|
141 | - |
|
142 | - $invoice->maybe_set_number(); |
|
143 | - |
|
144 | - wp_update_post( |
|
145 | - array( |
|
146 | - 'ID' => $invoice->get_id(), |
|
147 | - 'post_title' => $invoice->get_number( 'edit' ), |
|
148 | - 'post_name' => $invoice->get_path( 'edit' ) |
|
149 | - ) |
|
150 | - ); |
|
151 | - |
|
152 | - // Save special fields and items. |
|
153 | - $this->save_special_fields( $invoice ); |
|
154 | - $this->save_items( $invoice ); |
|
155 | - |
|
156 | - // Update meta data. |
|
157 | - $this->update_post_meta( $invoice ); |
|
158 | - $invoice->save_meta_data(); |
|
159 | - |
|
160 | - // Apply changes. |
|
161 | - $invoice->apply_changes(); |
|
162 | - $this->clear_caches( $invoice ); |
|
163 | - |
|
164 | - // Fires after a new invoice is created. |
|
165 | - do_action( 'getpaid_new_invoice', $invoice ); |
|
166 | - return true; |
|
167 | - } |
|
168 | - |
|
169 | - if ( is_wp_error( $id ) ) { |
|
170 | - $invoice->last_error = $id->get_error_message(); |
|
171 | - } |
|
172 | - |
|
173 | - return false; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Method to read an invoice from the database. |
|
178 | - * |
|
179 | - * @param WPInv_Invoice $invoice Invoice object. |
|
180 | - * |
|
181 | - */ |
|
182 | - public function read( &$invoice ) { |
|
183 | - |
|
184 | - $invoice->set_defaults(); |
|
185 | - $invoice_object = get_post( $invoice->get_id() ); |
|
186 | - |
|
187 | - if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
188 | - $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
189 | - $invoice->set_id( 0 ); |
|
190 | - return false; |
|
191 | - } |
|
192 | - |
|
193 | - $invoice->set_props( |
|
194 | - array( |
|
195 | - 'date_created' => 0 < $invoice_object->post_date ? $invoice_object->post_date : null, |
|
196 | - 'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null, |
|
197 | - 'status' => $invoice_object->post_status, |
|
198 | - 'author' => $invoice_object->post_author, |
|
199 | - 'description' => $invoice_object->post_excerpt, |
|
200 | - 'parent_id' => $invoice_object->post_parent, |
|
201 | - 'name' => $invoice_object->post_title, |
|
202 | - 'path' => $invoice_object->post_name, |
|
203 | - 'post_type' => $invoice_object->post_type, |
|
204 | - ) |
|
205 | - ); |
|
206 | - |
|
207 | - $invoice->set_type( $invoice_object->post_type ); |
|
208 | - |
|
209 | - $this->read_object_data( $invoice, $invoice_object ); |
|
210 | - $this->add_special_fields( $invoice ); |
|
211 | - $this->add_items( $invoice ); |
|
212 | - $invoice->read_meta_data(); |
|
213 | - $invoice->set_object_read( true ); |
|
214 | - do_action( 'getpaid_read_invoice', $invoice ); |
|
215 | - |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * Method to update an invoice in the database. |
|
220 | - * |
|
221 | - * @param WPInv_Invoice $invoice Invoice object. |
|
222 | - */ |
|
223 | - public function update( &$invoice ) { |
|
224 | - $invoice->save_meta_data(); |
|
225 | - $invoice->set_version( WPINV_VERSION ); |
|
226 | - |
|
227 | - if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
228 | - $invoice->set_date_created( current_time('mysql') ); |
|
229 | - } |
|
230 | - |
|
231 | - // Ensure both the key and number are set. |
|
232 | - $invoice->get_path(); |
|
233 | - |
|
234 | - // Grab the current status so we can compare. |
|
235 | - $previous_status = get_post_status( $invoice->get_id() ); |
|
236 | - |
|
237 | - $changes = $invoice->get_changes(); |
|
238 | - |
|
239 | - // Only update the post when the post data changes. |
|
240 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
241 | - $post_data = array( |
|
242 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
243 | - 'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ), |
|
244 | - 'post_status' => $invoice->get_status( 'edit' ), |
|
245 | - 'post_title' => $invoice->get_name( 'edit' ), |
|
246 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
247 | - 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
248 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
249 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
250 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
251 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
252 | - ); |
|
253 | - |
|
254 | - /** |
|
255 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
256 | - * to update data, since wp_update_post spawns more calls to the |
|
257 | - * save_post action. |
|
258 | - * |
|
259 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
260 | - * or an update purely from CRUD. |
|
261 | - */ |
|
262 | - if ( doing_action( 'save_post' ) ) { |
|
263 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
264 | - clean_post_cache( $invoice->get_id() ); |
|
265 | - } else { |
|
266 | - wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
267 | - } |
|
268 | - $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
269 | - } |
|
270 | - |
|
271 | - // Update meta data. |
|
272 | - $this->update_post_meta( $invoice ); |
|
273 | - |
|
274 | - // Save special fields and items. |
|
275 | - $this->save_special_fields( $invoice ); |
|
276 | - $this->save_items( $invoice ); |
|
277 | - |
|
278 | - // Apply the changes. |
|
279 | - $invoice->apply_changes(); |
|
280 | - |
|
281 | - // Clear caches. |
|
282 | - $this->clear_caches( $invoice ); |
|
283 | - |
|
284 | - // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
285 | - $new_status = $invoice->get_status( 'edit' ); |
|
286 | - |
|
287 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
288 | - do_action( 'getpaid_new_invoice', $invoice ); |
|
289 | - } else { |
|
290 | - do_action( 'getpaid_update_invoice', $invoice ); |
|
291 | - } |
|
292 | - |
|
293 | - } |
|
294 | - |
|
295 | - /* |
|
110 | + /** |
|
111 | + * Method to create a new invoice in the database. |
|
112 | + * |
|
113 | + * @param WPInv_Invoice $invoice Invoice object. |
|
114 | + */ |
|
115 | + public function create( &$invoice ) { |
|
116 | + $invoice->set_version( WPINV_VERSION ); |
|
117 | + $invoice->set_date_created( current_time('mysql') ); |
|
118 | + |
|
119 | + // Create a new post. |
|
120 | + $id = wp_insert_post( |
|
121 | + apply_filters( |
|
122 | + 'getpaid_new_invoice_data', |
|
123 | + array( |
|
124 | + 'post_date' => $invoice->get_date_created( 'edit' ), |
|
125 | + 'post_type' => $invoice->get_post_type( 'edit' ), |
|
126 | + 'post_status' => $this->get_post_status( $invoice ), |
|
127 | + 'ping_status' => 'closed', |
|
128 | + 'post_author' => $invoice->get_user_id( 'edit' ), |
|
129 | + 'post_title' => $invoice->get_title( 'edit' ), |
|
130 | + 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
131 | + 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
132 | + ) |
|
133 | + ), |
|
134 | + true |
|
135 | + ); |
|
136 | + |
|
137 | + if ( $id && ! is_wp_error( $id ) ) { |
|
138 | + |
|
139 | + // Update the new id and regenerate a title. |
|
140 | + $invoice->set_id( $id ); |
|
141 | + |
|
142 | + $invoice->maybe_set_number(); |
|
143 | + |
|
144 | + wp_update_post( |
|
145 | + array( |
|
146 | + 'ID' => $invoice->get_id(), |
|
147 | + 'post_title' => $invoice->get_number( 'edit' ), |
|
148 | + 'post_name' => $invoice->get_path( 'edit' ) |
|
149 | + ) |
|
150 | + ); |
|
151 | + |
|
152 | + // Save special fields and items. |
|
153 | + $this->save_special_fields( $invoice ); |
|
154 | + $this->save_items( $invoice ); |
|
155 | + |
|
156 | + // Update meta data. |
|
157 | + $this->update_post_meta( $invoice ); |
|
158 | + $invoice->save_meta_data(); |
|
159 | + |
|
160 | + // Apply changes. |
|
161 | + $invoice->apply_changes(); |
|
162 | + $this->clear_caches( $invoice ); |
|
163 | + |
|
164 | + // Fires after a new invoice is created. |
|
165 | + do_action( 'getpaid_new_invoice', $invoice ); |
|
166 | + return true; |
|
167 | + } |
|
168 | + |
|
169 | + if ( is_wp_error( $id ) ) { |
|
170 | + $invoice->last_error = $id->get_error_message(); |
|
171 | + } |
|
172 | + |
|
173 | + return false; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Method to read an invoice from the database. |
|
178 | + * |
|
179 | + * @param WPInv_Invoice $invoice Invoice object. |
|
180 | + * |
|
181 | + */ |
|
182 | + public function read( &$invoice ) { |
|
183 | + |
|
184 | + $invoice->set_defaults(); |
|
185 | + $invoice_object = get_post( $invoice->get_id() ); |
|
186 | + |
|
187 | + if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
188 | + $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
189 | + $invoice->set_id( 0 ); |
|
190 | + return false; |
|
191 | + } |
|
192 | + |
|
193 | + $invoice->set_props( |
|
194 | + array( |
|
195 | + 'date_created' => 0 < $invoice_object->post_date ? $invoice_object->post_date : null, |
|
196 | + 'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null, |
|
197 | + 'status' => $invoice_object->post_status, |
|
198 | + 'author' => $invoice_object->post_author, |
|
199 | + 'description' => $invoice_object->post_excerpt, |
|
200 | + 'parent_id' => $invoice_object->post_parent, |
|
201 | + 'name' => $invoice_object->post_title, |
|
202 | + 'path' => $invoice_object->post_name, |
|
203 | + 'post_type' => $invoice_object->post_type, |
|
204 | + ) |
|
205 | + ); |
|
206 | + |
|
207 | + $invoice->set_type( $invoice_object->post_type ); |
|
208 | + |
|
209 | + $this->read_object_data( $invoice, $invoice_object ); |
|
210 | + $this->add_special_fields( $invoice ); |
|
211 | + $this->add_items( $invoice ); |
|
212 | + $invoice->read_meta_data(); |
|
213 | + $invoice->set_object_read( true ); |
|
214 | + do_action( 'getpaid_read_invoice', $invoice ); |
|
215 | + |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * Method to update an invoice in the database. |
|
220 | + * |
|
221 | + * @param WPInv_Invoice $invoice Invoice object. |
|
222 | + */ |
|
223 | + public function update( &$invoice ) { |
|
224 | + $invoice->save_meta_data(); |
|
225 | + $invoice->set_version( WPINV_VERSION ); |
|
226 | + |
|
227 | + if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
228 | + $invoice->set_date_created( current_time('mysql') ); |
|
229 | + } |
|
230 | + |
|
231 | + // Ensure both the key and number are set. |
|
232 | + $invoice->get_path(); |
|
233 | + |
|
234 | + // Grab the current status so we can compare. |
|
235 | + $previous_status = get_post_status( $invoice->get_id() ); |
|
236 | + |
|
237 | + $changes = $invoice->get_changes(); |
|
238 | + |
|
239 | + // Only update the post when the post data changes. |
|
240 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
241 | + $post_data = array( |
|
242 | + 'post_date' => $invoice->get_date_created( 'edit' ), |
|
243 | + 'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ), |
|
244 | + 'post_status' => $invoice->get_status( 'edit' ), |
|
245 | + 'post_title' => $invoice->get_name( 'edit' ), |
|
246 | + 'post_author' => $invoice->get_user_id( 'edit' ), |
|
247 | + 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
248 | + 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
249 | + 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
250 | + 'post_name' => $invoice->get_path( 'edit' ), |
|
251 | + 'post_type' => $invoice->get_post_type( 'edit' ), |
|
252 | + ); |
|
253 | + |
|
254 | + /** |
|
255 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
256 | + * to update data, since wp_update_post spawns more calls to the |
|
257 | + * save_post action. |
|
258 | + * |
|
259 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
260 | + * or an update purely from CRUD. |
|
261 | + */ |
|
262 | + if ( doing_action( 'save_post' ) ) { |
|
263 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
264 | + clean_post_cache( $invoice->get_id() ); |
|
265 | + } else { |
|
266 | + wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
267 | + } |
|
268 | + $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
269 | + } |
|
270 | + |
|
271 | + // Update meta data. |
|
272 | + $this->update_post_meta( $invoice ); |
|
273 | + |
|
274 | + // Save special fields and items. |
|
275 | + $this->save_special_fields( $invoice ); |
|
276 | + $this->save_items( $invoice ); |
|
277 | + |
|
278 | + // Apply the changes. |
|
279 | + $invoice->apply_changes(); |
|
280 | + |
|
281 | + // Clear caches. |
|
282 | + $this->clear_caches( $invoice ); |
|
283 | + |
|
284 | + // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
|
285 | + $new_status = $invoice->get_status( 'edit' ); |
|
286 | + |
|
287 | + if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
288 | + do_action( 'getpaid_new_invoice', $invoice ); |
|
289 | + } else { |
|
290 | + do_action( 'getpaid_update_invoice', $invoice ); |
|
291 | + } |
|
292 | + |
|
293 | + } |
|
294 | + |
|
295 | + /* |
|
296 | 296 | |-------------------------------------------------------------------------- |
297 | 297 | | Additional Methods |
298 | 298 | |-------------------------------------------------------------------------- |
299 | 299 | */ |
300 | 300 | |
301 | - /** |
|
301 | + /** |
|
302 | 302 | * Retrieves special fields and adds to the invoice. |
303 | - * |
|
304 | - * @param WPInv_Invoice $invoice Invoice object. |
|
303 | + * |
|
304 | + * @param WPInv_Invoice $invoice Invoice object. |
|
305 | 305 | */ |
306 | 306 | public function add_special_fields( &$invoice ) { |
307 | - global $wpdb; |
|
307 | + global $wpdb; |
|
308 | 308 | |
309 | - // Maybe retrieve from the cache. |
|
310 | - $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
309 | + // Maybe retrieve from the cache. |
|
310 | + $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
311 | 311 | |
312 | - // If not found, retrieve from the db. |
|
313 | - if ( false === $data ) { |
|
314 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
312 | + // If not found, retrieve from the db. |
|
313 | + if ( false === $data ) { |
|
314 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
315 | 315 | |
316 | - $data = $wpdb->get_row( |
|
317 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
318 | - ARRAY_A |
|
319 | - ); |
|
316 | + $data = $wpdb->get_row( |
|
317 | + $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
318 | + ARRAY_A |
|
319 | + ); |
|
320 | 320 | |
321 | - // Update the cache with our data |
|
322 | - wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
321 | + // Update the cache with our data |
|
322 | + wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
323 | 323 | |
324 | - } |
|
324 | + } |
|
325 | 325 | |
326 | - // Abort if the data does not exist. |
|
327 | - if ( empty( $data ) ) { |
|
328 | - $invoice->set_object_read( true ); |
|
329 | - $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) ); |
|
330 | - return; |
|
331 | - } |
|
326 | + // Abort if the data does not exist. |
|
327 | + if ( empty( $data ) ) { |
|
328 | + $invoice->set_object_read( true ); |
|
329 | + $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) ); |
|
330 | + return; |
|
331 | + } |
|
332 | 332 | |
333 | - $props = array(); |
|
333 | + $props = array(); |
|
334 | 334 | |
335 | - foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
335 | + foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
336 | 336 | |
337 | - if ( $db_field == 'post_id' ) { |
|
338 | - continue; |
|
339 | - } |
|
340 | - |
|
341 | - $props[ $prop ] = $data[ $db_field ]; |
|
342 | - } |
|
343 | - |
|
344 | - $invoice->set_props( $props ); |
|
345 | - |
|
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * Gets a list of special fields that need updated based on change state |
|
350 | - * or if they are present in the database or not. |
|
351 | - * |
|
352 | - * @param WPInv_Invoice $invoice The Invoice object. |
|
353 | - * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
|
354 | - */ |
|
355 | - protected function get_special_fields_to_update( $invoice ) { |
|
356 | - $fields_to_update = array(); |
|
357 | - $changed_props = $invoice->get_changes(); |
|
358 | - |
|
359 | - // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
360 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
361 | - if ( array_key_exists( $prop, $changed_props ) ) { |
|
362 | - $fields_to_update[ $database_field ] = $prop; |
|
363 | - } |
|
364 | - } |
|
365 | - |
|
366 | - return $fields_to_update; |
|
367 | - } |
|
368 | - |
|
369 | - /** |
|
370 | - * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class. |
|
371 | - * |
|
372 | - * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
373 | - * @since 1.0.19 |
|
374 | - */ |
|
375 | - protected function update_special_fields( &$invoice ) { |
|
376 | - global $wpdb; |
|
377 | - |
|
378 | - $updated_props = array(); |
|
379 | - $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
380 | - |
|
381 | - foreach ( $fields_to_update as $database_field => $prop ) { |
|
382 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
383 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
384 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
385 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
386 | - } |
|
387 | - |
|
388 | - if ( ! empty( $updated_props ) ) { |
|
389 | - |
|
390 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
391 | - $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
392 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
393 | - do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props ); |
|
394 | - |
|
395 | - } |
|
396 | - |
|
397 | - } |
|
398 | - |
|
399 | - /** |
|
400 | - * Helper method that inserts special fields to the database. |
|
401 | - * |
|
402 | - * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
403 | - * @since 1.0.19 |
|
404 | - */ |
|
405 | - protected function insert_special_fields( &$invoice ) { |
|
406 | - global $wpdb; |
|
407 | - |
|
408 | - $updated_props = array(); |
|
409 | - |
|
410 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
411 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
412 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
413 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
414 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
415 | - } |
|
416 | - |
|
417 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
418 | - $wpdb->insert( $table, $updated_props ); |
|
419 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
420 | - do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props ); |
|
421 | - |
|
422 | - } |
|
423 | - |
|
424 | - /** |
|
337 | + if ( $db_field == 'post_id' ) { |
|
338 | + continue; |
|
339 | + } |
|
340 | + |
|
341 | + $props[ $prop ] = $data[ $db_field ]; |
|
342 | + } |
|
343 | + |
|
344 | + $invoice->set_props( $props ); |
|
345 | + |
|
346 | + } |
|
347 | + |
|
348 | + /** |
|
349 | + * Gets a list of special fields that need updated based on change state |
|
350 | + * or if they are present in the database or not. |
|
351 | + * |
|
352 | + * @param WPInv_Invoice $invoice The Invoice object. |
|
353 | + * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
|
354 | + */ |
|
355 | + protected function get_special_fields_to_update( $invoice ) { |
|
356 | + $fields_to_update = array(); |
|
357 | + $changed_props = $invoice->get_changes(); |
|
358 | + |
|
359 | + // Props should be updated if they are a part of the $changed array or don't exist yet. |
|
360 | + foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
361 | + if ( array_key_exists( $prop, $changed_props ) ) { |
|
362 | + $fields_to_update[ $database_field ] = $prop; |
|
363 | + } |
|
364 | + } |
|
365 | + |
|
366 | + return $fields_to_update; |
|
367 | + } |
|
368 | + |
|
369 | + /** |
|
370 | + * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class. |
|
371 | + * |
|
372 | + * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
373 | + * @since 1.0.19 |
|
374 | + */ |
|
375 | + protected function update_special_fields( &$invoice ) { |
|
376 | + global $wpdb; |
|
377 | + |
|
378 | + $updated_props = array(); |
|
379 | + $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
380 | + |
|
381 | + foreach ( $fields_to_update as $database_field => $prop ) { |
|
382 | + $value = $invoice->{"get_$prop"}( 'edit' ); |
|
383 | + $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
384 | + $value = is_bool( $value ) ? ( int ) $value : $value; |
|
385 | + $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
386 | + } |
|
387 | + |
|
388 | + if ( ! empty( $updated_props ) ) { |
|
389 | + |
|
390 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
391 | + $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
392 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
393 | + do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props ); |
|
394 | + |
|
395 | + } |
|
396 | + |
|
397 | + } |
|
398 | + |
|
399 | + /** |
|
400 | + * Helper method that inserts special fields to the database. |
|
401 | + * |
|
402 | + * @param WPInv_Invoice $invoice WPInv_Invoice object. |
|
403 | + * @since 1.0.19 |
|
404 | + */ |
|
405 | + protected function insert_special_fields( &$invoice ) { |
|
406 | + global $wpdb; |
|
407 | + |
|
408 | + $updated_props = array(); |
|
409 | + |
|
410 | + foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
411 | + $value = $invoice->{"get_$prop"}( 'edit' ); |
|
412 | + $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
413 | + $value = is_bool( $value ) ? ( int ) $value : $value; |
|
414 | + $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
415 | + } |
|
416 | + |
|
417 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
418 | + $wpdb->insert( $table, $updated_props ); |
|
419 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
420 | + do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props ); |
|
421 | + |
|
422 | + } |
|
423 | + |
|
424 | + /** |
|
425 | 425 | * Saves all special fields. |
426 | - * |
|
427 | - * @param WPInv_Invoice $invoice Invoice object. |
|
426 | + * |
|
427 | + * @param WPInv_Invoice $invoice Invoice object. |
|
428 | 428 | */ |
429 | 429 | public function save_special_fields( & $invoice ) { |
430 | - global $wpdb; |
|
430 | + global $wpdb; |
|
431 | 431 | |
432 | - // The invoices table. |
|
433 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
434 | - $id = (int) $invoice->get_id(); |
|
435 | - $invoice->maybe_set_key(); |
|
432 | + // The invoices table. |
|
433 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
434 | + $id = (int) $invoice->get_id(); |
|
435 | + $invoice->maybe_set_key(); |
|
436 | 436 | |
437 | - if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
437 | + if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
438 | 438 | |
439 | - $this->update_special_fields( $invoice ); |
|
439 | + $this->update_special_fields( $invoice ); |
|
440 | 440 | |
441 | - } else { |
|
441 | + } else { |
|
442 | 442 | |
443 | - $this->insert_special_fields( $invoice ); |
|
443 | + $this->insert_special_fields( $invoice ); |
|
444 | 444 | |
445 | - } |
|
445 | + } |
|
446 | 446 | |
447 | - } |
|
447 | + } |
|
448 | 448 | |
449 | - /** |
|
449 | + /** |
|
450 | 450 | * Set's up cart details. |
451 | - * |
|
452 | - * @param WPInv_Invoice $invoice Invoice object. |
|
451 | + * |
|
452 | + * @param WPInv_Invoice $invoice Invoice object. |
|
453 | 453 | */ |
454 | 454 | public function add_items( &$invoice ) { |
455 | - global $wpdb; |
|
455 | + global $wpdb; |
|
456 | 456 | |
457 | - // Maybe retrieve from the cache. |
|
458 | - $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
457 | + // Maybe retrieve from the cache. |
|
458 | + $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
459 | 459 | |
460 | - // If not found, retrieve from the db. |
|
461 | - if ( false === $items ) { |
|
462 | - $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
460 | + // If not found, retrieve from the db. |
|
461 | + if ( false === $items ) { |
|
462 | + $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
463 | 463 | |
464 | - $items = $wpdb->get_results( |
|
465 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
466 | - ); |
|
464 | + $items = $wpdb->get_results( |
|
465 | + $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
466 | + ); |
|
467 | 467 | |
468 | - // Update the cache with our data |
|
469 | - wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
468 | + // Update the cache with our data |
|
469 | + wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
470 | 470 | |
471 | - } |
|
471 | + } |
|
472 | 472 | |
473 | - // Abort if no items found. |
|
473 | + // Abort if no items found. |
|
474 | 474 | if ( empty( $items ) ) { |
475 | 475 | return; |
476 | - } |
|
477 | - |
|
478 | - $_items = array(); |
|
479 | - foreach ( $items as $item_data ) { |
|
480 | - $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
481 | - |
|
482 | - // Set item data. |
|
483 | - $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
484 | - $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
485 | - $item->set_name( $item_data->item_name ); |
|
486 | - $item->set_description( $item_data->item_description ); |
|
487 | - $item->set_price( $item_data->item_price ); |
|
488 | - $item->set_quantity( $item_data->quantity ); |
|
489 | - $item->set_item_meta( $item_data->meta ); |
|
490 | - $_items[] = $item; |
|
491 | - } |
|
492 | - |
|
493 | - $invoice->set_items( $_items ); |
|
494 | - } |
|
495 | - |
|
496 | - /** |
|
476 | + } |
|
477 | + |
|
478 | + $_items = array(); |
|
479 | + foreach ( $items as $item_data ) { |
|
480 | + $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
481 | + |
|
482 | + // Set item data. |
|
483 | + $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
484 | + $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
485 | + $item->set_name( $item_data->item_name ); |
|
486 | + $item->set_description( $item_data->item_description ); |
|
487 | + $item->set_price( $item_data->item_price ); |
|
488 | + $item->set_quantity( $item_data->quantity ); |
|
489 | + $item->set_item_meta( $item_data->meta ); |
|
490 | + $_items[] = $item; |
|
491 | + } |
|
492 | + |
|
493 | + $invoice->set_items( $_items ); |
|
494 | + } |
|
495 | + |
|
496 | + /** |
|
497 | 497 | * Saves cart details. |
498 | - * |
|
499 | - * @param WPInv_Invoice $invoice Invoice object. |
|
498 | + * |
|
499 | + * @param WPInv_Invoice $invoice Invoice object. |
|
500 | 500 | */ |
501 | 501 | public function save_items( $invoice ) { |
502 | 502 | |
503 | - // Delete previously existing items. |
|
504 | - $this->delete_items( $invoice ); |
|
503 | + // Delete previously existing items. |
|
504 | + $this->delete_items( $invoice ); |
|
505 | 505 | |
506 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
506 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
507 | 507 | |
508 | - foreach ( $invoice->get_cart_details() as $item_data ) { |
|
509 | - $item_data = array_map( 'maybe_serialize', $item_data ); |
|
510 | - $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
511 | - } |
|
508 | + foreach ( $invoice->get_cart_details() as $item_data ) { |
|
509 | + $item_data = array_map( 'maybe_serialize', $item_data ); |
|
510 | + $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
511 | + } |
|
512 | 512 | |
513 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
514 | - do_action( "getpaid_invoice_save_items", $invoice ); |
|
513 | + wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
514 | + do_action( "getpaid_invoice_save_items", $invoice ); |
|
515 | 515 | |
516 | - } |
|
516 | + } |
|
517 | 517 | |
518 | - /** |
|
518 | + /** |
|
519 | 519 | * Deletes an invoice's cart details from the database. |
520 | - * |
|
521 | - * @param WPInv_Invoice $invoice Invoice object. |
|
520 | + * |
|
521 | + * @param WPInv_Invoice $invoice Invoice object. |
|
522 | 522 | */ |
523 | 523 | public function delete_items( $invoice ) { |
524 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
525 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
526 | - } |
|
524 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
525 | + return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
526 | + } |
|
527 | 527 | |
528 | - /** |
|
528 | + /** |
|
529 | 529 | * Deletes an invoice's special fields from the database. |
530 | - * |
|
531 | - * @param WPInv_Invoice $invoice Invoice object. |
|
530 | + * |
|
531 | + * @param WPInv_Invoice $invoice Invoice object. |
|
532 | 532 | */ |
533 | 533 | public function delete_special_fields( $invoice ) { |
534 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
535 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
536 | - } |
|
534 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
535 | + return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
536 | + } |
|
537 | 537 | |
538 | - /** |
|
539 | - * Get the status to save to the post object. |
|
540 | - * |
|
541 | - * |
|
542 | - * @since 1.0.19 |
|
543 | - * @param WPInv_Invoice $object GetPaid_Data object. |
|
544 | - * @return string |
|
545 | - */ |
|
546 | - protected function get_post_status( $object ) { |
|
547 | - $object_status = $object->get_status( 'edit' ); |
|
548 | - |
|
549 | - if ( ! $object_status ) { |
|
550 | - $object_status = $object->get_default_status(); |
|
551 | - } |
|
552 | - |
|
553 | - return $object_status; |
|
554 | - } |
|
538 | + /** |
|
539 | + * Get the status to save to the post object. |
|
540 | + * |
|
541 | + * |
|
542 | + * @since 1.0.19 |
|
543 | + * @param WPInv_Invoice $object GetPaid_Data object. |
|
544 | + * @return string |
|
545 | + */ |
|
546 | + protected function get_post_status( $object ) { |
|
547 | + $object_status = $object->get_status( 'edit' ); |
|
548 | + |
|
549 | + if ( ! $object_status ) { |
|
550 | + $object_status = $object->get_default_status(); |
|
551 | + } |
|
552 | + |
|
553 | + return $object_status; |
|
554 | + } |
|
555 | 555 | |
556 | 556 | } |
@@ -5,110 +5,110 @@ discard block |
||
5 | 5 | */ |
6 | 6 | |
7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
8 | - exit; // Exit if accessed directly |
|
8 | + exit; // Exit if accessed directly |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | if ( ! class_exists( 'GetPaid_Admin_Profile', false ) ) : |
12 | 12 | |
13 | - /** |
|
14 | - * GetPaid_Admin_Profile Class. |
|
15 | - */ |
|
16 | - class GetPaid_Admin_Profile { |
|
17 | - |
|
18 | - /** |
|
19 | - * Hook in tabs. |
|
20 | - */ |
|
21 | - public function __construct() { |
|
22 | - add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
23 | - add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
24 | - |
|
25 | - add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) ); |
|
26 | - add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) ); |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Get Address Fields for the edit user pages. |
|
31 | - * |
|
32 | - * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned |
|
33 | - */ |
|
34 | - public function get_customer_meta_fields() { |
|
35 | - |
|
36 | - $show_fields = apply_filters( |
|
37 | - 'getpaid_customer_meta_fields', |
|
38 | - array( |
|
39 | - 'billing' => array( |
|
40 | - 'title' => __( 'Billing Details (GetPaid)', 'invoicing' ), |
|
41 | - 'fields' => array( |
|
42 | - '_wpinv_first_name' => array( |
|
43 | - 'label' => __( 'First name', 'invoicing' ), |
|
44 | - 'description' => '', |
|
45 | - ), |
|
46 | - '_wpinv_last_name' => array( |
|
47 | - 'label' => __( 'Last name', 'invoicing' ), |
|
48 | - 'description' => '', |
|
49 | - ), |
|
50 | - '_wpinv_company' => array( |
|
51 | - 'label' => __( 'Company', 'invoicing' ), |
|
52 | - 'description' => '', |
|
53 | - ), |
|
54 | - '_wpinv_company_id' => array( |
|
55 | - 'label' => __( 'Company ID', 'invoicing' ), |
|
56 | - 'description' => '', |
|
57 | - ), |
|
58 | - '_wpinv_address' => array( |
|
59 | - 'label' => __( 'Address', 'invoicing' ), |
|
60 | - 'description' => '', |
|
61 | - ), |
|
62 | - '_wpinv_city' => array( |
|
63 | - 'label' => __( 'City', 'invoicing' ), |
|
64 | - 'description' => '', |
|
65 | - ), |
|
66 | - '_wpinv_zip' => array( |
|
67 | - 'label' => __( 'Postcode / ZIP', 'invoicing' ), |
|
68 | - 'description' => '', |
|
69 | - ), |
|
70 | - '_wpinv_country' => array( |
|
71 | - 'label' => __( 'Country / Region', 'invoicing' ), |
|
72 | - 'description' => '', |
|
73 | - 'class' => 'getpaid_js_field-country', |
|
74 | - 'type' => 'select', |
|
75 | - 'options' => array( '' => __( 'Select a country / region…', 'invoicing' ) ) + wpinv_get_country_list(), |
|
76 | - ), |
|
77 | - '_wpinv_state' => array( |
|
78 | - 'label' => __( 'State / County', 'invoicing' ), |
|
79 | - 'description' => __( 'State / County or state code', 'invoicing' ), |
|
80 | - 'class' => 'getpaid_js_field-state regular-text', |
|
81 | - ), |
|
82 | - '_wpinv_phone' => array( |
|
83 | - 'label' => __( 'Phone', 'invoicing' ), |
|
84 | - 'description' => '', |
|
85 | - ), |
|
86 | - '_wpinv_vat_number' => array( |
|
87 | - 'label' => __( 'VAT Number', 'invoicing' ), |
|
88 | - 'description' => '', |
|
89 | - ), |
|
90 | - ), |
|
91 | - ), |
|
92 | - ) |
|
93 | - ); |
|
94 | - return $show_fields; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Show Address Fields on edit user pages. |
|
99 | - * |
|
100 | - * @param WP_User $user |
|
101 | - */ |
|
102 | - public function add_customer_meta_fields( $user ) { |
|
103 | - |
|
104 | - if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) { |
|
105 | - return; |
|
106 | - } |
|
107 | - |
|
108 | - $show_fields = $this->get_customer_meta_fields(); |
|
109 | - |
|
110 | - foreach ( $show_fields as $fieldset_key => $fieldset ) : |
|
111 | - ?> |
|
13 | + /** |
|
14 | + * GetPaid_Admin_Profile Class. |
|
15 | + */ |
|
16 | + class GetPaid_Admin_Profile { |
|
17 | + |
|
18 | + /** |
|
19 | + * Hook in tabs. |
|
20 | + */ |
|
21 | + public function __construct() { |
|
22 | + add_action( 'show_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
23 | + add_action( 'edit_user_profile', array( $this, 'add_customer_meta_fields' ), 100 ); |
|
24 | + |
|
25 | + add_action( 'personal_options_update', array( $this, 'save_customer_meta_fields' ) ); |
|
26 | + add_action( 'edit_user_profile_update', array( $this, 'save_customer_meta_fields' ) ); |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Get Address Fields for the edit user pages. |
|
31 | + * |
|
32 | + * @return array Fields to display which are filtered through invoicing_customer_meta_fields before being returned |
|
33 | + */ |
|
34 | + public function get_customer_meta_fields() { |
|
35 | + |
|
36 | + $show_fields = apply_filters( |
|
37 | + 'getpaid_customer_meta_fields', |
|
38 | + array( |
|
39 | + 'billing' => array( |
|
40 | + 'title' => __( 'Billing Details (GetPaid)', 'invoicing' ), |
|
41 | + 'fields' => array( |
|
42 | + '_wpinv_first_name' => array( |
|
43 | + 'label' => __( 'First name', 'invoicing' ), |
|
44 | + 'description' => '', |
|
45 | + ), |
|
46 | + '_wpinv_last_name' => array( |
|
47 | + 'label' => __( 'Last name', 'invoicing' ), |
|
48 | + 'description' => '', |
|
49 | + ), |
|
50 | + '_wpinv_company' => array( |
|
51 | + 'label' => __( 'Company', 'invoicing' ), |
|
52 | + 'description' => '', |
|
53 | + ), |
|
54 | + '_wpinv_company_id' => array( |
|
55 | + 'label' => __( 'Company ID', 'invoicing' ), |
|
56 | + 'description' => '', |
|
57 | + ), |
|
58 | + '_wpinv_address' => array( |
|
59 | + 'label' => __( 'Address', 'invoicing' ), |
|
60 | + 'description' => '', |
|
61 | + ), |
|
62 | + '_wpinv_city' => array( |
|
63 | + 'label' => __( 'City', 'invoicing' ), |
|
64 | + 'description' => '', |
|
65 | + ), |
|
66 | + '_wpinv_zip' => array( |
|
67 | + 'label' => __( 'Postcode / ZIP', 'invoicing' ), |
|
68 | + 'description' => '', |
|
69 | + ), |
|
70 | + '_wpinv_country' => array( |
|
71 | + 'label' => __( 'Country / Region', 'invoicing' ), |
|
72 | + 'description' => '', |
|
73 | + 'class' => 'getpaid_js_field-country', |
|
74 | + 'type' => 'select', |
|
75 | + 'options' => array( '' => __( 'Select a country / region…', 'invoicing' ) ) + wpinv_get_country_list(), |
|
76 | + ), |
|
77 | + '_wpinv_state' => array( |
|
78 | + 'label' => __( 'State / County', 'invoicing' ), |
|
79 | + 'description' => __( 'State / County or state code', 'invoicing' ), |
|
80 | + 'class' => 'getpaid_js_field-state regular-text', |
|
81 | + ), |
|
82 | + '_wpinv_phone' => array( |
|
83 | + 'label' => __( 'Phone', 'invoicing' ), |
|
84 | + 'description' => '', |
|
85 | + ), |
|
86 | + '_wpinv_vat_number' => array( |
|
87 | + 'label' => __( 'VAT Number', 'invoicing' ), |
|
88 | + 'description' => '', |
|
89 | + ), |
|
90 | + ), |
|
91 | + ), |
|
92 | + ) |
|
93 | + ); |
|
94 | + return $show_fields; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Show Address Fields on edit user pages. |
|
99 | + * |
|
100 | + * @param WP_User $user |
|
101 | + */ |
|
102 | + public function add_customer_meta_fields( $user ) { |
|
103 | + |
|
104 | + if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user->ID ) ) { |
|
105 | + return; |
|
106 | + } |
|
107 | + |
|
108 | + $show_fields = $this->get_customer_meta_fields(); |
|
109 | + |
|
110 | + foreach ( $show_fields as $fieldset_key => $fieldset ) : |
|
111 | + ?> |
|
112 | 112 | <h2><?php echo $fieldset['title']; ?></h2> |
113 | 113 | <table class="form-table" id="<?php echo esc_attr( 'getpaid-fieldset-' . $fieldset_key ); ?>"> |
114 | 114 | <?php foreach ( $fieldset['fields'] as $key => $field ) : ?> |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | <?php if ( ! empty( $field['type'] ) && 'select' === $field['type'] ) : ?> |
121 | 121 | <select name="<?php echo esc_attr( $key ); ?>" id="<?php echo esc_attr( $key ); ?>" class="<?php echo esc_attr( $field['class'] ); ?> wpi_select2" style="width: 25em;"> |
122 | 122 | <?php |
123 | - $selected = esc_attr( get_user_meta( $user->ID, $key, true ) ); |
|
124 | - foreach ( $field['options'] as $option_key => $option_value ) : |
|
125 | - ?> |
|
123 | + $selected = esc_attr( get_user_meta( $user->ID, $key, true ) ); |
|
124 | + foreach ( $field['options'] as $option_key => $option_value ) : |
|
125 | + ?> |
|
126 | 126 | <option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( $selected, $option_key, true ); ?>><?php echo esc_html( $option_value ); ?></option> |
127 | 127 | <?php endforeach; ?> |
128 | 128 | </select> |
@@ -137,52 +137,52 @@ discard block |
||
137 | 137 | <?php endforeach; ?> |
138 | 138 | </table> |
139 | 139 | <?php |
140 | - endforeach; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Save Address Fields on edit user pages. |
|
145 | - * |
|
146 | - * @param int $user_id User ID of the user being saved |
|
147 | - */ |
|
148 | - public function save_customer_meta_fields( $user_id ) { |
|
149 | - if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) { |
|
150 | - return; |
|
151 | - } |
|
152 | - |
|
153 | - $save_fields = $this->get_customer_meta_fields(); |
|
154 | - |
|
155 | - foreach ( $save_fields as $fieldset ) { |
|
156 | - |
|
157 | - foreach ( $fieldset['fields'] as $key => $field ) { |
|
158 | - |
|
159 | - if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) { |
|
160 | - update_user_meta( $user_id, $key, isset( $_POST[ $key ] ) ); |
|
161 | - } elseif ( isset( $_POST[ $key ] ) ) { |
|
162 | - update_user_meta( $user_id, $key, wpinv_clean( $_POST[ $key ] ) ); |
|
163 | - } |
|
164 | - } |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Get user meta for a given key, with fallbacks to core user info for pre-existing fields. |
|
170 | - * |
|
171 | - * @since 3.1.0 |
|
172 | - * @param int $user_id User ID of the user being edited |
|
173 | - * @param string $key Key for user meta field |
|
174 | - * @return string |
|
175 | - */ |
|
176 | - protected function get_user_meta( $user_id, $key ) { |
|
177 | - $value = get_user_meta( $user_id, $key, true ); |
|
178 | - $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' ); |
|
179 | - if ( ! $value && in_array( $key, $existing_fields ) ) { |
|
180 | - $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true ); |
|
181 | - } |
|
182 | - |
|
183 | - return $value; |
|
184 | - } |
|
185 | - } |
|
140 | + endforeach; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Save Address Fields on edit user pages. |
|
145 | + * |
|
146 | + * @param int $user_id User ID of the user being saved |
|
147 | + */ |
|
148 | + public function save_customer_meta_fields( $user_id ) { |
|
149 | + if ( ! apply_filters( 'getpaid_current_user_can_edit_customer_meta_fields', current_user_can( 'manage_options' ), $user_id ) ) { |
|
150 | + return; |
|
151 | + } |
|
152 | + |
|
153 | + $save_fields = $this->get_customer_meta_fields(); |
|
154 | + |
|
155 | + foreach ( $save_fields as $fieldset ) { |
|
156 | + |
|
157 | + foreach ( $fieldset['fields'] as $key => $field ) { |
|
158 | + |
|
159 | + if ( isset( $field['type'] ) && 'checkbox' === $field['type'] ) { |
|
160 | + update_user_meta( $user_id, $key, isset( $_POST[ $key ] ) ); |
|
161 | + } elseif ( isset( $_POST[ $key ] ) ) { |
|
162 | + update_user_meta( $user_id, $key, wpinv_clean( $_POST[ $key ] ) ); |
|
163 | + } |
|
164 | + } |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Get user meta for a given key, with fallbacks to core user info for pre-existing fields. |
|
170 | + * |
|
171 | + * @since 3.1.0 |
|
172 | + * @param int $user_id User ID of the user being edited |
|
173 | + * @param string $key Key for user meta field |
|
174 | + * @return string |
|
175 | + */ |
|
176 | + protected function get_user_meta( $user_id, $key ) { |
|
177 | + $value = get_user_meta( $user_id, $key, true ); |
|
178 | + $existing_fields = array( '_wpinv_first_name', '_wpinv_last_name' ); |
|
179 | + if ( ! $value && in_array( $key, $existing_fields ) ) { |
|
180 | + $value = get_user_meta( $user_id, str_replace( '_wpinv_', '', $key ), true ); |
|
181 | + } |
|
182 | + |
|
183 | + return $value; |
|
184 | + } |
|
185 | + } |
|
186 | 186 | |
187 | 187 | endif; |
188 | 188 |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
4 | - exit; // Exit if accessed directly |
|
4 | + exit; // Exit if accessed directly |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -11,372 +11,372 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class AUI_Component_Helper { |
13 | 13 | |
14 | - /** |
|
15 | - * A component helper for generating a input name. |
|
16 | - * |
|
17 | - * @param $text |
|
18 | - * @param $multiple bool If the name is set to be multiple but no brackets found then we add some. |
|
19 | - * |
|
20 | - * @return string |
|
21 | - */ |
|
22 | - public static function name($text,$multiple = false){ |
|
23 | - $output = ''; |
|
24 | - |
|
25 | - if($text){ |
|
26 | - $is_multiple = strpos($text, '[') === false && $multiple ? '[]' : ''; |
|
27 | - $output = ' name="'.esc_attr($text).$is_multiple.'" '; |
|
28 | - } |
|
29 | - |
|
30 | - return $output; |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * A component helper for generating a item id. |
|
35 | - * |
|
36 | - * @param $text string The text to be used as the value. |
|
37 | - * |
|
38 | - * @return string The sanitized item. |
|
39 | - */ |
|
40 | - public static function id($text){ |
|
41 | - $output = ''; |
|
42 | - |
|
43 | - if($text){ |
|
44 | - $output = ' id="'.sanitize_html_class($text).'" '; |
|
45 | - } |
|
46 | - |
|
47 | - return $output; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * A component helper for generating a item title. |
|
52 | - * |
|
53 | - * @param $text string The text to be used as the value. |
|
54 | - * |
|
55 | - * @return string The sanitized item. |
|
56 | - */ |
|
57 | - public static function title($text){ |
|
58 | - $output = ''; |
|
59 | - |
|
60 | - if($text){ |
|
61 | - $output = ' title="'.esc_attr($text).'" '; |
|
62 | - } |
|
63 | - |
|
64 | - return $output; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * A component helper for generating a item value. |
|
69 | - * |
|
70 | - * @param $text string The text to be used as the value. |
|
71 | - * |
|
72 | - * @return string The sanitized item. |
|
73 | - */ |
|
74 | - public static function value( $text ) { |
|
75 | - $output = ''; |
|
76 | - |
|
77 | - if ( $text !== null && $text !== false ) { |
|
78 | - $output = ' value="' . esc_attr( wp_unslash( $text ) ) . '" '; |
|
79 | - } |
|
80 | - |
|
81 | - return $output; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * A component helper for generating a item class attribute. |
|
86 | - * |
|
87 | - * @param $text string The text to be used as the value. |
|
88 | - * |
|
89 | - * @return string The sanitized item. |
|
90 | - */ |
|
91 | - public static function class_attr($text){ |
|
92 | - $output = ''; |
|
93 | - |
|
94 | - if($text){ |
|
95 | - $classes = self::esc_classes($text); |
|
96 | - if(!empty($classes)){ |
|
97 | - $output = ' class="'.$classes.'" '; |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - return $output; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Escape a string of classes. |
|
106 | - * |
|
107 | - * @param $text |
|
108 | - * |
|
109 | - * @return string |
|
110 | - */ |
|
111 | - public static function esc_classes($text){ |
|
112 | - $output = ''; |
|
113 | - |
|
114 | - if($text){ |
|
115 | - $classes = explode(" ",$text); |
|
116 | - $classes = array_map("trim",$classes); |
|
117 | - $classes = array_map("sanitize_html_class",$classes); |
|
118 | - if(!empty($classes)){ |
|
119 | - $output = implode(" ",$classes); |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - return $output; |
|
124 | - |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * @param $args |
|
129 | - * |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - public static function data_attributes($args){ |
|
133 | - $output = ''; |
|
134 | - |
|
135 | - if(!empty($args)){ |
|
136 | - |
|
137 | - foreach($args as $key => $val){ |
|
138 | - if(substr( $key, 0, 5 ) === "data-"){ |
|
139 | - $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
140 | - } |
|
141 | - } |
|
142 | - } |
|
143 | - |
|
144 | - return $output; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @param $args |
|
149 | - * |
|
150 | - * @return string |
|
151 | - */ |
|
152 | - public static function aria_attributes($args){ |
|
153 | - $output = ''; |
|
154 | - |
|
155 | - if(!empty($args)){ |
|
156 | - |
|
157 | - foreach($args as $key => $val){ |
|
158 | - if(substr( $key, 0, 5 ) === "aria-"){ |
|
159 | - $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
160 | - } |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - return $output; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Build a font awesome icon from a class. |
|
169 | - * |
|
170 | - * @param $class |
|
171 | - * @param bool $space_after |
|
172 | - * @param array $extra_attributes An array of extra attributes. |
|
173 | - * |
|
174 | - * @return string |
|
175 | - */ |
|
176 | - public static function icon($class,$space_after = false, $extra_attributes = array()){ |
|
177 | - $output = ''; |
|
178 | - |
|
179 | - if($class){ |
|
180 | - $classes = self::esc_classes($class); |
|
181 | - if(!empty($classes)){ |
|
182 | - $output = '<i class="'.$classes.'" '; |
|
183 | - // extra attributes |
|
184 | - if(!empty($extra_attributes)){ |
|
185 | - $output .= AUI_Component_Helper::extra_attributes($extra_attributes); |
|
186 | - } |
|
187 | - $output .= '></i>'; |
|
188 | - if($space_after){ |
|
189 | - $output .= " "; |
|
190 | - } |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - return $output; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * @param $args |
|
199 | - * |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public static function extra_attributes($args){ |
|
203 | - $output = ''; |
|
204 | - |
|
205 | - if(!empty($args)){ |
|
206 | - |
|
207 | - if( is_array($args) ){ |
|
208 | - foreach($args as $key => $val){ |
|
209 | - $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
210 | - } |
|
211 | - }else{ |
|
212 | - $output .= ' '.$args.' '; |
|
213 | - } |
|
214 | - |
|
215 | - } |
|
216 | - |
|
217 | - return $output; |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * @param $args |
|
222 | - * |
|
223 | - * @return string |
|
224 | - */ |
|
225 | - public static function help_text($text){ |
|
226 | - $output = ''; |
|
227 | - |
|
228 | - if($text){ |
|
229 | - $output .= '<small class="form-text text-muted">'.wp_kses_post($text).'</small>'; |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - return $output; |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Replace element require context with JS. |
|
238 | - * |
|
239 | - * @param $input |
|
240 | - * |
|
241 | - * @return string|void |
|
242 | - */ |
|
243 | - public static function element_require( $input ) { |
|
244 | - |
|
245 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
246 | - |
|
247 | - $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array( |
|
248 | - "jQuery(form).find('[data-argument=\"", |
|
249 | - "\"]').find('input,select,textarea').val()", |
|
250 | - "\"]').find('input:checked').val()", |
|
251 | - ), $input ) ); |
|
252 | - |
|
253 | - if($output){ |
|
254 | - $output = ' data-element-require="'.$output.'" '; |
|
255 | - } |
|
256 | - |
|
257 | - return $output; |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Returns an array of allowed HTML tags and attributes for a given context. |
|
262 | - * |
|
263 | - * @since 0.1.41 |
|
264 | - * |
|
265 | - * @param string|array $context The context for which to retrieve tags. Allowed values are 'post', |
|
266 | - * 'strip', 'data', 'entities', or the name of a field filter such as |
|
267 | - * 'pre_user_description'. |
|
268 | - * @param array $input Input. |
|
269 | - * @return array Array of allowed HTML tags and their allowed attributes. |
|
270 | - */ |
|
271 | - public static function kses_allowed_html( $context = 'post', $input = array() ) { |
|
272 | - $allowed_html = wp_kses_allowed_html( $context ); |
|
273 | - |
|
274 | - if ( is_array( $allowed_html ) ) { |
|
275 | - // <iframe> |
|
276 | - if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) { |
|
277 | - $allowed_html['iframe'] = array( |
|
278 | - 'class' => true, |
|
279 | - 'id' => true, |
|
280 | - 'src' => true, |
|
281 | - 'width' => true, |
|
282 | - 'height' => true, |
|
283 | - 'frameborder' => true, |
|
284 | - 'marginwidth' => true, |
|
285 | - 'marginheight' => true, |
|
286 | - 'scrolling' => true, |
|
287 | - 'style' => true, |
|
288 | - 'title' => true, |
|
289 | - 'allow' => true, |
|
290 | - 'allowfullscreen' => true, |
|
291 | - 'data-*' => true, |
|
292 | - ); |
|
293 | - } |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * Filters the allowed html tags. |
|
298 | - * |
|
299 | - * @since 0.1.41 |
|
300 | - * |
|
301 | - * @param array[]|string $allowed_html Allowed html tags. |
|
302 | - * @param @param string|array $context The context for which to retrieve tags. |
|
303 | - * @param array $input Input field. |
|
304 | - */ |
|
305 | - return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input ); |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Filters content and keeps only allowable HTML elements. |
|
310 | - * |
|
311 | - * This function makes sure that only the allowed HTML element names, attribute |
|
312 | - * names and attribute values plus only sane HTML entities will occur in |
|
313 | - * $string. You have to remove any slashes from PHP's magic quotes before you |
|
314 | - * call this function. |
|
315 | - * |
|
316 | - * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news', |
|
317 | - * 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This |
|
318 | - * covers all common link protocols, except for 'javascript' which should not |
|
319 | - * be allowed for untrusted users. |
|
320 | - * |
|
321 | - * @since 0.1.41 |
|
322 | - * |
|
323 | - * @param string|array $value Content to filter through kses. |
|
324 | - * @param array $input Input Field. |
|
325 | - * @return string Filtered content with only allowed HTML elements. |
|
326 | - */ |
|
327 | - public static function _sanitize_html_field( $value, $input = array() ) { |
|
328 | - if ( $value === '' ) { |
|
329 | - return $value; |
|
330 | - } |
|
331 | - |
|
332 | - $allowed_html = self::kses_allowed_html( 'post', $input ); |
|
333 | - |
|
334 | - if ( ! is_array( $allowed_html ) ) { |
|
335 | - $allowed_html = wp_kses_allowed_html( 'post' ); |
|
336 | - } |
|
337 | - |
|
338 | - $filtered = trim( wp_unslash( $value ) ); |
|
339 | - $filtered = wp_kses( $filtered, $allowed_html ); |
|
340 | - $filtered = balanceTags( $filtered ); // Balances tags |
|
341 | - |
|
342 | - return $filtered; |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * Navigates through an array, object, or scalar, and removes slashes from the values. |
|
347 | - * |
|
348 | - * @since 0.1.41 |
|
349 | - * |
|
350 | - * @param mixed $value The value to be stripped. |
|
351 | - * @param array $input Input Field. |
|
352 | - * @return mixed Stripped value. |
|
353 | - */ |
|
354 | - public static function sanitize_html_field( $value, $input = array() ) { |
|
355 | - $original = $value; |
|
356 | - |
|
357 | - if ( is_array( $value ) ) { |
|
358 | - foreach ( $value as $index => $item ) { |
|
359 | - $value[ $index ] = self::_sanitize_html_field( $value, $input ); |
|
360 | - } |
|
361 | - } elseif ( is_object( $value ) ) { |
|
362 | - $object_vars = get_object_vars( $value ); |
|
363 | - |
|
364 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
365 | - $value->$property_name = self::_sanitize_html_field( $property_value, $input ); |
|
366 | - } |
|
367 | - } else { |
|
368 | - $value = self::_sanitize_html_field( $value, $input ); |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Filters content and keeps only allowable HTML elements. |
|
373 | - * |
|
374 | - * @since 0.1.41 |
|
375 | - * |
|
376 | - * @param string|array $value Content to filter through kses. |
|
377 | - * @param string|array $value Original content without filter. |
|
378 | - * @param array $input Input Field. |
|
379 | - */ |
|
380 | - return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input ); |
|
381 | - } |
|
14 | + /** |
|
15 | + * A component helper for generating a input name. |
|
16 | + * |
|
17 | + * @param $text |
|
18 | + * @param $multiple bool If the name is set to be multiple but no brackets found then we add some. |
|
19 | + * |
|
20 | + * @return string |
|
21 | + */ |
|
22 | + public static function name($text,$multiple = false){ |
|
23 | + $output = ''; |
|
24 | + |
|
25 | + if($text){ |
|
26 | + $is_multiple = strpos($text, '[') === false && $multiple ? '[]' : ''; |
|
27 | + $output = ' name="'.esc_attr($text).$is_multiple.'" '; |
|
28 | + } |
|
29 | + |
|
30 | + return $output; |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * A component helper for generating a item id. |
|
35 | + * |
|
36 | + * @param $text string The text to be used as the value. |
|
37 | + * |
|
38 | + * @return string The sanitized item. |
|
39 | + */ |
|
40 | + public static function id($text){ |
|
41 | + $output = ''; |
|
42 | + |
|
43 | + if($text){ |
|
44 | + $output = ' id="'.sanitize_html_class($text).'" '; |
|
45 | + } |
|
46 | + |
|
47 | + return $output; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * A component helper for generating a item title. |
|
52 | + * |
|
53 | + * @param $text string The text to be used as the value. |
|
54 | + * |
|
55 | + * @return string The sanitized item. |
|
56 | + */ |
|
57 | + public static function title($text){ |
|
58 | + $output = ''; |
|
59 | + |
|
60 | + if($text){ |
|
61 | + $output = ' title="'.esc_attr($text).'" '; |
|
62 | + } |
|
63 | + |
|
64 | + return $output; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * A component helper for generating a item value. |
|
69 | + * |
|
70 | + * @param $text string The text to be used as the value. |
|
71 | + * |
|
72 | + * @return string The sanitized item. |
|
73 | + */ |
|
74 | + public static function value( $text ) { |
|
75 | + $output = ''; |
|
76 | + |
|
77 | + if ( $text !== null && $text !== false ) { |
|
78 | + $output = ' value="' . esc_attr( wp_unslash( $text ) ) . '" '; |
|
79 | + } |
|
80 | + |
|
81 | + return $output; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * A component helper for generating a item class attribute. |
|
86 | + * |
|
87 | + * @param $text string The text to be used as the value. |
|
88 | + * |
|
89 | + * @return string The sanitized item. |
|
90 | + */ |
|
91 | + public static function class_attr($text){ |
|
92 | + $output = ''; |
|
93 | + |
|
94 | + if($text){ |
|
95 | + $classes = self::esc_classes($text); |
|
96 | + if(!empty($classes)){ |
|
97 | + $output = ' class="'.$classes.'" '; |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + return $output; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Escape a string of classes. |
|
106 | + * |
|
107 | + * @param $text |
|
108 | + * |
|
109 | + * @return string |
|
110 | + */ |
|
111 | + public static function esc_classes($text){ |
|
112 | + $output = ''; |
|
113 | + |
|
114 | + if($text){ |
|
115 | + $classes = explode(" ",$text); |
|
116 | + $classes = array_map("trim",$classes); |
|
117 | + $classes = array_map("sanitize_html_class",$classes); |
|
118 | + if(!empty($classes)){ |
|
119 | + $output = implode(" ",$classes); |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + return $output; |
|
124 | + |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * @param $args |
|
129 | + * |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + public static function data_attributes($args){ |
|
133 | + $output = ''; |
|
134 | + |
|
135 | + if(!empty($args)){ |
|
136 | + |
|
137 | + foreach($args as $key => $val){ |
|
138 | + if(substr( $key, 0, 5 ) === "data-"){ |
|
139 | + $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
140 | + } |
|
141 | + } |
|
142 | + } |
|
143 | + |
|
144 | + return $output; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @param $args |
|
149 | + * |
|
150 | + * @return string |
|
151 | + */ |
|
152 | + public static function aria_attributes($args){ |
|
153 | + $output = ''; |
|
154 | + |
|
155 | + if(!empty($args)){ |
|
156 | + |
|
157 | + foreach($args as $key => $val){ |
|
158 | + if(substr( $key, 0, 5 ) === "aria-"){ |
|
159 | + $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
160 | + } |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + return $output; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Build a font awesome icon from a class. |
|
169 | + * |
|
170 | + * @param $class |
|
171 | + * @param bool $space_after |
|
172 | + * @param array $extra_attributes An array of extra attributes. |
|
173 | + * |
|
174 | + * @return string |
|
175 | + */ |
|
176 | + public static function icon($class,$space_after = false, $extra_attributes = array()){ |
|
177 | + $output = ''; |
|
178 | + |
|
179 | + if($class){ |
|
180 | + $classes = self::esc_classes($class); |
|
181 | + if(!empty($classes)){ |
|
182 | + $output = '<i class="'.$classes.'" '; |
|
183 | + // extra attributes |
|
184 | + if(!empty($extra_attributes)){ |
|
185 | + $output .= AUI_Component_Helper::extra_attributes($extra_attributes); |
|
186 | + } |
|
187 | + $output .= '></i>'; |
|
188 | + if($space_after){ |
|
189 | + $output .= " "; |
|
190 | + } |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + return $output; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * @param $args |
|
199 | + * |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public static function extra_attributes($args){ |
|
203 | + $output = ''; |
|
204 | + |
|
205 | + if(!empty($args)){ |
|
206 | + |
|
207 | + if( is_array($args) ){ |
|
208 | + foreach($args as $key => $val){ |
|
209 | + $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
210 | + } |
|
211 | + }else{ |
|
212 | + $output .= ' '.$args.' '; |
|
213 | + } |
|
214 | + |
|
215 | + } |
|
216 | + |
|
217 | + return $output; |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * @param $args |
|
222 | + * |
|
223 | + * @return string |
|
224 | + */ |
|
225 | + public static function help_text($text){ |
|
226 | + $output = ''; |
|
227 | + |
|
228 | + if($text){ |
|
229 | + $output .= '<small class="form-text text-muted">'.wp_kses_post($text).'</small>'; |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + return $output; |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Replace element require context with JS. |
|
238 | + * |
|
239 | + * @param $input |
|
240 | + * |
|
241 | + * @return string|void |
|
242 | + */ |
|
243 | + public static function element_require( $input ) { |
|
244 | + |
|
245 | + $input = str_replace( "'", '"', $input );// we only want double quotes |
|
246 | + |
|
247 | + $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array( |
|
248 | + "jQuery(form).find('[data-argument=\"", |
|
249 | + "\"]').find('input,select,textarea').val()", |
|
250 | + "\"]').find('input:checked').val()", |
|
251 | + ), $input ) ); |
|
252 | + |
|
253 | + if($output){ |
|
254 | + $output = ' data-element-require="'.$output.'" '; |
|
255 | + } |
|
256 | + |
|
257 | + return $output; |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Returns an array of allowed HTML tags and attributes for a given context. |
|
262 | + * |
|
263 | + * @since 0.1.41 |
|
264 | + * |
|
265 | + * @param string|array $context The context for which to retrieve tags. Allowed values are 'post', |
|
266 | + * 'strip', 'data', 'entities', or the name of a field filter such as |
|
267 | + * 'pre_user_description'. |
|
268 | + * @param array $input Input. |
|
269 | + * @return array Array of allowed HTML tags and their allowed attributes. |
|
270 | + */ |
|
271 | + public static function kses_allowed_html( $context = 'post', $input = array() ) { |
|
272 | + $allowed_html = wp_kses_allowed_html( $context ); |
|
273 | + |
|
274 | + if ( is_array( $allowed_html ) ) { |
|
275 | + // <iframe> |
|
276 | + if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) { |
|
277 | + $allowed_html['iframe'] = array( |
|
278 | + 'class' => true, |
|
279 | + 'id' => true, |
|
280 | + 'src' => true, |
|
281 | + 'width' => true, |
|
282 | + 'height' => true, |
|
283 | + 'frameborder' => true, |
|
284 | + 'marginwidth' => true, |
|
285 | + 'marginheight' => true, |
|
286 | + 'scrolling' => true, |
|
287 | + 'style' => true, |
|
288 | + 'title' => true, |
|
289 | + 'allow' => true, |
|
290 | + 'allowfullscreen' => true, |
|
291 | + 'data-*' => true, |
|
292 | + ); |
|
293 | + } |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * Filters the allowed html tags. |
|
298 | + * |
|
299 | + * @since 0.1.41 |
|
300 | + * |
|
301 | + * @param array[]|string $allowed_html Allowed html tags. |
|
302 | + * @param @param string|array $context The context for which to retrieve tags. |
|
303 | + * @param array $input Input field. |
|
304 | + */ |
|
305 | + return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input ); |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Filters content and keeps only allowable HTML elements. |
|
310 | + * |
|
311 | + * This function makes sure that only the allowed HTML element names, attribute |
|
312 | + * names and attribute values plus only sane HTML entities will occur in |
|
313 | + * $string. You have to remove any slashes from PHP's magic quotes before you |
|
314 | + * call this function. |
|
315 | + * |
|
316 | + * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news', |
|
317 | + * 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This |
|
318 | + * covers all common link protocols, except for 'javascript' which should not |
|
319 | + * be allowed for untrusted users. |
|
320 | + * |
|
321 | + * @since 0.1.41 |
|
322 | + * |
|
323 | + * @param string|array $value Content to filter through kses. |
|
324 | + * @param array $input Input Field. |
|
325 | + * @return string Filtered content with only allowed HTML elements. |
|
326 | + */ |
|
327 | + public static function _sanitize_html_field( $value, $input = array() ) { |
|
328 | + if ( $value === '' ) { |
|
329 | + return $value; |
|
330 | + } |
|
331 | + |
|
332 | + $allowed_html = self::kses_allowed_html( 'post', $input ); |
|
333 | + |
|
334 | + if ( ! is_array( $allowed_html ) ) { |
|
335 | + $allowed_html = wp_kses_allowed_html( 'post' ); |
|
336 | + } |
|
337 | + |
|
338 | + $filtered = trim( wp_unslash( $value ) ); |
|
339 | + $filtered = wp_kses( $filtered, $allowed_html ); |
|
340 | + $filtered = balanceTags( $filtered ); // Balances tags |
|
341 | + |
|
342 | + return $filtered; |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * Navigates through an array, object, or scalar, and removes slashes from the values. |
|
347 | + * |
|
348 | + * @since 0.1.41 |
|
349 | + * |
|
350 | + * @param mixed $value The value to be stripped. |
|
351 | + * @param array $input Input Field. |
|
352 | + * @return mixed Stripped value. |
|
353 | + */ |
|
354 | + public static function sanitize_html_field( $value, $input = array() ) { |
|
355 | + $original = $value; |
|
356 | + |
|
357 | + if ( is_array( $value ) ) { |
|
358 | + foreach ( $value as $index => $item ) { |
|
359 | + $value[ $index ] = self::_sanitize_html_field( $value, $input ); |
|
360 | + } |
|
361 | + } elseif ( is_object( $value ) ) { |
|
362 | + $object_vars = get_object_vars( $value ); |
|
363 | + |
|
364 | + foreach ( $object_vars as $property_name => $property_value ) { |
|
365 | + $value->$property_name = self::_sanitize_html_field( $property_value, $input ); |
|
366 | + } |
|
367 | + } else { |
|
368 | + $value = self::_sanitize_html_field( $value, $input ); |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Filters content and keeps only allowable HTML elements. |
|
373 | + * |
|
374 | + * @since 0.1.41 |
|
375 | + * |
|
376 | + * @param string|array $value Content to filter through kses. |
|
377 | + * @param string|array $value Original content without filter. |
|
378 | + * @param array $input Input Field. |
|
379 | + */ |
|
380 | + return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input ); |
|
381 | + } |
|
382 | 382 | } |
383 | 383 | \ No newline at end of file |
@@ -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 | } |
@@ -7,40 +7,40 @@ |
||
7 | 7 | * Bail if we are not in WP. |
8 | 8 | */ |
9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
10 | - exit; |
|
10 | + exit; |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Set the version only if its the current newest while loading. |
15 | 15 | */ |
16 | 16 | add_action('after_setup_theme', function () { |
17 | - global $ayecode_ui_version,$ayecode_ui_file_key; |
|
18 | - $this_version = "0.1.59"; |
|
19 | - if(version_compare($this_version , $ayecode_ui_version, '>')){ |
|
20 | - $ayecode_ui_version = $this_version ; |
|
21 | - $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
22 | - } |
|
17 | + global $ayecode_ui_version,$ayecode_ui_file_key; |
|
18 | + $this_version = "0.1.59"; |
|
19 | + if(version_compare($this_version , $ayecode_ui_version, '>')){ |
|
20 | + $ayecode_ui_version = $this_version ; |
|
21 | + $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
22 | + } |
|
23 | 23 | },0); |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Load this version of WP Bootstrap Settings only if the file hash is the current one. |
27 | 27 | */ |
28 | 28 | add_action('after_setup_theme', function () { |
29 | - global $ayecode_ui_file_key; |
|
30 | - if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
31 | - include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
32 | - include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
33 | - } |
|
29 | + global $ayecode_ui_file_key; |
|
30 | + if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
31 | + include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
32 | + include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
33 | + } |
|
34 | 34 | },1); |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Add the function that calls the class. |
38 | 38 | */ |
39 | 39 | if(!function_exists('aui')){ |
40 | - function aui(){ |
|
41 | - if(!class_exists("AUI",false)){ |
|
42 | - return false; |
|
43 | - } |
|
44 | - return AUI::instance(); |
|
45 | - } |
|
40 | + function aui(){ |
|
41 | + if(!class_exists("AUI",false)){ |
|
42 | + return false; |
|
43 | + } |
|
44 | + return AUI::instance(); |
|
45 | + } |
|
46 | 46 | } |
47 | 47 | \ No newline at end of file |
@@ -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 |