@@ -73,10 +73,6 @@ |
||
73 | 73 | /** |
74 | 74 | * Outputs a button. |
75 | 75 | *ccc |
76 | - * @param string $url |
|
77 | - * @param string $text |
|
78 | - * @param string $theme |
|
79 | - * @param string $plugin |
|
80 | 76 | */ |
81 | 77 | public function output_button( $addon ) { |
82 | 78 | $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
@@ -45,8 +45,7 @@ discard block |
||
45 | 45 | |
46 | 46 | if($section_id=='recommended_plugins'){ |
47 | 47 | $section_data->products = self::get_recommend_wp_plugins_edd_formatted(); |
48 | - } |
|
49 | - elseif ( ! empty( $section ) ) { |
|
48 | + } elseif ( ! empty( $section ) ) { |
|
50 | 49 | if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing |
51 | 50 | //if ( 1==1) { |
52 | 51 | |
@@ -121,13 +120,13 @@ discard block |
||
121 | 120 | $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
122 | 121 | if(isset($status['status'])){$button_args['install_status'] = $status['status'];} |
123 | 122 | $button_args['update_url'] = "https://wpinvoicing.com"; |
124 | - }elseif($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) { |
|
123 | + } elseif($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) { |
|
125 | 124 | if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
126 | 125 | $button_args['installed'] = self::is_theme_installed($addon); |
127 | 126 | if(!in_array($button_args['slug'],$wp_org_themes)){ |
128 | 127 | $button_args['update_url'] = "https://wpinvoicing.com"; |
129 | 128 | } |
130 | - }elseif($current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug){ |
|
129 | + } elseif($current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug){ |
|
131 | 130 | include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
132 | 131 | $status = install_plugin_install_status(array("slug"=>$button_args['slug'],"version"=>"")); |
133 | 132 | $button_args['install_status'] = isset($status['status']) ? $status['status'] : 'install'; |
@@ -139,7 +138,7 @@ discard block |
||
139 | 138 | if(is_object($addon->pricing)){ |
140 | 139 | $prices = (Array)$addon->pricing; |
141 | 140 | $button_args['price'] = reset($prices); |
142 | - }elseif(isset($addon->pricing)){ |
|
141 | + } elseif(isset($addon->pricing)){ |
|
143 | 142 | $button_args['price'] = $addon->pricing; |
144 | 143 | } |
145 | 144 | } |
@@ -160,7 +159,7 @@ discard block |
||
160 | 159 | if($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')){ |
161 | 160 | if($button_args['type'] != 'themes'){ |
162 | 161 | $button_args['active'] = is_plugin_active($button_args['file']); |
163 | - }else{ |
|
162 | + } else{ |
|
164 | 163 | $button_args['active'] = self::is_theme_active($addon); |
165 | 164 | } |
166 | 165 | } |
@@ -169,27 +168,27 @@ discard block |
||
169 | 168 | if($button_args['active']){ |
170 | 169 | $button_args['button_text'] = __('Active','invoicing'); |
171 | 170 | $button_args['class'] = ' button-secondary disabled '; |
172 | - }elseif($button_args['installed']){ |
|
171 | + } elseif($button_args['installed']){ |
|
173 | 172 | $button_args['button_text'] = __('Activate','invoicing'); |
174 | 173 | |
175 | 174 | if($button_args['type'] != 'themes'){ |
176 | 175 | if ( current_user_can( 'manage_options' ) ) { |
177 | 176 | $button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin='.$button_args['file']), 'activate-plugin_' . $button_args['file']); |
178 | - }else{ |
|
177 | + } else{ |
|
179 | 178 | $button_args['url'] = '#'; |
180 | 179 | } |
181 | - }else{ |
|
180 | + } else{ |
|
182 | 181 | if ( current_user_can( 'switch_themes' ) ) { |
183 | 182 | $button_args['url'] = self::get_theme_activation_url($addon); |
184 | - }else{ |
|
183 | + } else{ |
|
185 | 184 | $button_args['url'] = '#'; |
186 | 185 | } |
187 | 186 | } |
188 | 187 | |
189 | - }else{ |
|
188 | + } else{ |
|
190 | 189 | if($button_args['type'] == 'recommended_plugins'){ |
191 | 190 | $button_args['button_text'] = __('Install','invoicing'); |
192 | - }else{ |
|
191 | + } else{ |
|
193 | 192 | $button_args['button_text'] = __('Get it','invoicing'); |
194 | 193 | |
195 | 194 | /*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){ |
@@ -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,71 +15,71 @@ 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 | - $products = isset($section_data->products) ? $section_data->products : ''; |
|
69 | - |
|
70 | - return apply_filters( 'wpi_addons_section_data', $products, $section_id ); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Outputs a button. |
|
75 | - *ccc |
|
76 | - * @param string $url |
|
77 | - * @param string $text |
|
78 | - * @param string $theme |
|
79 | - * @param string $plugin |
|
80 | - */ |
|
81 | - public function output_button( $addon ) { |
|
82 | - $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
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 | + $products = isset($section_data->products) ? $section_data->products : ''; |
|
69 | + |
|
70 | + return apply_filters( 'wpi_addons_section_data', $products, $section_id ); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Outputs a button. |
|
75 | + *ccc |
|
76 | + * @param string $url |
|
77 | + * @param string $text |
|
78 | + * @param string $theme |
|
79 | + * @param string $plugin |
|
80 | + */ |
|
81 | + public function output_button( $addon ) { |
|
82 | + $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
83 | 83 | // $button_text = __('Free','invoicing'); |
84 | 84 | // $licensing = false; |
85 | 85 | // $installed = false; |
@@ -91,123 +91,123 @@ discard block |
||
91 | 91 | // $install_status = 'get'; |
92 | 92 | // $onclick = ''; |
93 | 93 | |
94 | - $wp_org_themes = array('supreme-directory','directory-starter'); |
|
95 | - |
|
96 | - $button_args = array( |
|
97 | - 'type' => $current_tab, |
|
98 | - 'id' => isset($addon->info->id) ? absint($addon->info->id) : '', |
|
99 | - 'title' => isset($addon->info->title) ? $addon->info->title : '', |
|
100 | - 'button_text' => __('Free','invoicing'), |
|
101 | - 'price_text' => __('Free','invoicing'), |
|
102 | - 'link' => isset($addon->info->link) ? $addon->info->link : '', // link to product |
|
103 | - 'url' => isset($addon->info->link) ? $addon->info->link : '', // button url |
|
104 | - 'class' => 'button-primary', |
|
105 | - 'install_status' => 'get', |
|
106 | - 'installed' => false, |
|
107 | - 'price' => '', |
|
108 | - 'licensing' => isset($addon->licensing->enabled) && $addon->licensing->enabled ? true : false, |
|
109 | - 'license' => isset($addon->licensing->license) && $addon->licensing->license ? $addon->licensing->license : '', |
|
110 | - 'onclick' => '', |
|
111 | - 'slug' => isset($addon->info->slug) ? $addon->info->slug : '', |
|
112 | - 'active' => false, |
|
113 | - 'file' => '', |
|
114 | - 'update_url' => '', |
|
115 | - ); |
|
116 | - |
|
117 | - if( ($current_tab == 'addons' || $current_tab =='gateways') && isset($addon->info->id) && $addon->info->id){ |
|
118 | - include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
|
119 | - if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
|
120 | - $status = self::install_plugin_install_status($addon); |
|
121 | - $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
|
122 | - if(isset($status['status'])){$button_args['install_status'] = $status['status'];} |
|
123 | - $button_args['update_url'] = "https://wpinvoicing.com"; |
|
124 | - }elseif($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) { |
|
125 | - if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
|
126 | - $button_args['installed'] = self::is_theme_installed($addon); |
|
127 | - if(!in_array($button_args['slug'],$wp_org_themes)){ |
|
128 | - $button_args['update_url'] = "https://wpinvoicing.com"; |
|
129 | - } |
|
130 | - }elseif($current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug){ |
|
131 | - include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
|
132 | - $status = install_plugin_install_status(array("slug"=>$button_args['slug'],"version"=>"")); |
|
133 | - $button_args['install_status'] = isset($status['status']) ? $status['status'] : 'install'; |
|
134 | - $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
|
135 | - } |
|
136 | - |
|
137 | - // set price |
|
138 | - if(isset($addon->pricing) && !empty($addon->pricing)){ |
|
139 | - if(is_object($addon->pricing)){ |
|
140 | - $prices = (Array)$addon->pricing; |
|
141 | - $button_args['price'] = reset($prices); |
|
142 | - }elseif(isset($addon->pricing)){ |
|
143 | - $button_args['price'] = $addon->pricing; |
|
144 | - } |
|
145 | - } |
|
146 | - |
|
147 | - // set price text |
|
148 | - if( $button_args['price'] && $button_args['price'] != '0.00' ){ |
|
149 | - $button_args['price_text'] = sprintf( __('From: $%d', 'invoicing'), $button_args['price']); |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - // set if installed |
|
154 | - if(in_array($button_args['install_status'], array('installed','latest_installed','update_available','newer_installed'))){ |
|
155 | - $button_args['installed'] = true; |
|
156 | - } |
|
94 | + $wp_org_themes = array('supreme-directory','directory-starter'); |
|
95 | + |
|
96 | + $button_args = array( |
|
97 | + 'type' => $current_tab, |
|
98 | + 'id' => isset($addon->info->id) ? absint($addon->info->id) : '', |
|
99 | + 'title' => isset($addon->info->title) ? $addon->info->title : '', |
|
100 | + 'button_text' => __('Free','invoicing'), |
|
101 | + 'price_text' => __('Free','invoicing'), |
|
102 | + 'link' => isset($addon->info->link) ? $addon->info->link : '', // link to product |
|
103 | + 'url' => isset($addon->info->link) ? $addon->info->link : '', // button url |
|
104 | + 'class' => 'button-primary', |
|
105 | + 'install_status' => 'get', |
|
106 | + 'installed' => false, |
|
107 | + 'price' => '', |
|
108 | + 'licensing' => isset($addon->licensing->enabled) && $addon->licensing->enabled ? true : false, |
|
109 | + 'license' => isset($addon->licensing->license) && $addon->licensing->license ? $addon->licensing->license : '', |
|
110 | + 'onclick' => '', |
|
111 | + 'slug' => isset($addon->info->slug) ? $addon->info->slug : '', |
|
112 | + 'active' => false, |
|
113 | + 'file' => '', |
|
114 | + 'update_url' => '', |
|
115 | + ); |
|
116 | + |
|
117 | + if( ($current_tab == 'addons' || $current_tab =='gateways') && isset($addon->info->id) && $addon->info->id){ |
|
118 | + include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
|
119 | + if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
|
120 | + $status = self::install_plugin_install_status($addon); |
|
121 | + $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
|
122 | + if(isset($status['status'])){$button_args['install_status'] = $status['status'];} |
|
123 | + $button_args['update_url'] = "https://wpinvoicing.com"; |
|
124 | + }elseif($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) { |
|
125 | + if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
|
126 | + $button_args['installed'] = self::is_theme_installed($addon); |
|
127 | + if(!in_array($button_args['slug'],$wp_org_themes)){ |
|
128 | + $button_args['update_url'] = "https://wpinvoicing.com"; |
|
129 | + } |
|
130 | + }elseif($current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug){ |
|
131 | + include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
|
132 | + $status = install_plugin_install_status(array("slug"=>$button_args['slug'],"version"=>"")); |
|
133 | + $button_args['install_status'] = isset($status['status']) ? $status['status'] : 'install'; |
|
134 | + $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
|
135 | + } |
|
136 | + |
|
137 | + // set price |
|
138 | + if(isset($addon->pricing) && !empty($addon->pricing)){ |
|
139 | + if(is_object($addon->pricing)){ |
|
140 | + $prices = (Array)$addon->pricing; |
|
141 | + $button_args['price'] = reset($prices); |
|
142 | + }elseif(isset($addon->pricing)){ |
|
143 | + $button_args['price'] = $addon->pricing; |
|
144 | + } |
|
145 | + } |
|
146 | + |
|
147 | + // set price text |
|
148 | + if( $button_args['price'] && $button_args['price'] != '0.00' ){ |
|
149 | + $button_args['price_text'] = sprintf( __('From: $%d', 'invoicing'), $button_args['price']); |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + // set if installed |
|
154 | + if(in_array($button_args['install_status'], array('installed','latest_installed','update_available','newer_installed'))){ |
|
155 | + $button_args['installed'] = true; |
|
156 | + } |
|
157 | 157 | |
158 | 158 | // print_r($button_args); |
159 | - // set if active |
|
160 | - if($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')){ |
|
161 | - if($button_args['type'] != 'themes'){ |
|
162 | - $button_args['active'] = is_plugin_active($button_args['file']); |
|
163 | - }else{ |
|
164 | - $button_args['active'] = self::is_theme_active($addon); |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - // set button text and class |
|
169 | - if($button_args['active']){ |
|
170 | - $button_args['button_text'] = __('Active','invoicing'); |
|
171 | - $button_args['class'] = ' button-secondary disabled '; |
|
172 | - }elseif($button_args['installed']){ |
|
173 | - $button_args['button_text'] = __('Activate','invoicing'); |
|
174 | - |
|
175 | - if($button_args['type'] != 'themes'){ |
|
176 | - if ( current_user_can( 'manage_options' ) ) { |
|
177 | - $button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin='.$button_args['file']), 'activate-plugin_' . $button_args['file']); |
|
178 | - }else{ |
|
179 | - $button_args['url'] = '#'; |
|
180 | - } |
|
181 | - }else{ |
|
182 | - if ( current_user_can( 'switch_themes' ) ) { |
|
183 | - $button_args['url'] = self::get_theme_activation_url($addon); |
|
184 | - }else{ |
|
185 | - $button_args['url'] = '#'; |
|
186 | - } |
|
187 | - } |
|
188 | - |
|
189 | - }else{ |
|
190 | - if($button_args['type'] == 'recommended_plugins'){ |
|
191 | - $button_args['button_text'] = __('Install','invoicing'); |
|
192 | - }else{ |
|
193 | - $button_args['button_text'] = __('Get it','invoicing'); |
|
194 | - |
|
195 | - /*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){ |
|
159 | + // set if active |
|
160 | + if($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')){ |
|
161 | + if($button_args['type'] != 'themes'){ |
|
162 | + $button_args['active'] = is_plugin_active($button_args['file']); |
|
163 | + }else{ |
|
164 | + $button_args['active'] = self::is_theme_active($addon); |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + // set button text and class |
|
169 | + if($button_args['active']){ |
|
170 | + $button_args['button_text'] = __('Active','invoicing'); |
|
171 | + $button_args['class'] = ' button-secondary disabled '; |
|
172 | + }elseif($button_args['installed']){ |
|
173 | + $button_args['button_text'] = __('Activate','invoicing'); |
|
174 | + |
|
175 | + if($button_args['type'] != 'themes'){ |
|
176 | + if ( current_user_can( 'manage_options' ) ) { |
|
177 | + $button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin='.$button_args['file']), 'activate-plugin_' . $button_args['file']); |
|
178 | + }else{ |
|
179 | + $button_args['url'] = '#'; |
|
180 | + } |
|
181 | + }else{ |
|
182 | + if ( current_user_can( 'switch_themes' ) ) { |
|
183 | + $button_args['url'] = self::get_theme_activation_url($addon); |
|
184 | + }else{ |
|
185 | + $button_args['url'] = '#'; |
|
186 | + } |
|
187 | + } |
|
188 | + |
|
189 | + }else{ |
|
190 | + if($button_args['type'] == 'recommended_plugins'){ |
|
191 | + $button_args['button_text'] = __('Install','invoicing'); |
|
192 | + }else{ |
|
193 | + $button_args['button_text'] = __('Get it','invoicing'); |
|
194 | + |
|
195 | + /*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){ |
|
196 | 196 | $button_args['button_text'] = __('Install','invoicing'); |
197 | 197 | $button_args['url'] = self::get_theme_install_url($button_args['slug']); |
198 | 198 | $button_args['onclick'] = 'gd_set_button_installing(this);'; |
199 | 199 | }*/ |
200 | 200 | |
201 | - } |
|
202 | - } |
|
201 | + } |
|
202 | + } |
|
203 | 203 | |
204 | 204 | |
205 | - // filter the button arguments |
|
206 | - $button_args = apply_filters('edd_api_button_args',$button_args); |
|
205 | + // filter the button arguments |
|
206 | + $button_args = apply_filters('edd_api_button_args',$button_args); |
|
207 | 207 | |
208 | - // set price text |
|
209 | - if(isset($button_args['price_text'])){ |
|
210 | - ?> |
|
208 | + // set price text |
|
209 | + if(isset($button_args['price_text'])){ |
|
210 | + ?> |
|
211 | 211 | <a |
212 | 212 | target="_blank" |
213 | 213 | class="addons-price-text" |
@@ -215,15 +215,15 @@ discard block |
||
215 | 215 | <?php echo esc_html( $button_args['price_text'] ); ?> |
216 | 216 | </a> |
217 | 217 | <?php |
218 | - } |
|
218 | + } |
|
219 | 219 | |
220 | 220 | |
221 | - $target = ''; |
|
222 | - if ( ! empty( $button_args['url'] ) ) { |
|
223 | - $target = strpos($button_args['url'], get_site_url()) !== false ? '' : ' target="_blank" '; |
|
224 | - } |
|
221 | + $target = ''; |
|
222 | + if ( ! empty( $button_args['url'] ) ) { |
|
223 | + $target = strpos($button_args['url'], get_site_url()) !== false ? '' : ' target="_blank" '; |
|
224 | + } |
|
225 | 225 | |
226 | - ?> |
|
226 | + ?> |
|
227 | 227 | <a |
228 | 228 | data-licence="<?php echo esc_attr($button_args['license']);?>" |
229 | 229 | data-licensing="<?php echo $button_args['licensing'] ? 1 : 0;?>" |
@@ -246,28 +246,28 @@ discard block |
||
246 | 246 | <?php |
247 | 247 | |
248 | 248 | |
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * Handles output of the addons page in admin. |
|
254 | - */ |
|
255 | - public function output() { |
|
256 | - $tabs = self::get_tabs(); |
|
257 | - $sections = self::get_sections(); |
|
258 | - $theme = wp_get_theme(); |
|
259 | - $section_keys = array_keys( $sections ); |
|
260 | - $current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys ); |
|
261 | - $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
262 | - include_once( WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php' ); |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * A list of recommended wp.org plugins. |
|
267 | - * @return array |
|
268 | - */ |
|
269 | - public function get_recommend_wp_plugins(){ |
|
270 | - $plugins = array( |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * Handles output of the addons page in admin. |
|
254 | + */ |
|
255 | + public function output() { |
|
256 | + $tabs = self::get_tabs(); |
|
257 | + $sections = self::get_sections(); |
|
258 | + $theme = wp_get_theme(); |
|
259 | + $section_keys = array_keys( $sections ); |
|
260 | + $current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys ); |
|
261 | + $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
262 | + include_once( WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php' ); |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * A list of recommended wp.org plugins. |
|
267 | + * @return array |
|
268 | + */ |
|
269 | + public function get_recommend_wp_plugins(){ |
|
270 | + $plugins = array( |
|
271 | 271 | 'invoicing-quotes' => array( |
272 | 272 | 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
273 | 273 | 'slug' => 'invoicing-quotes', |
@@ -287,8 +287,8 @@ discard block |
||
287 | 287 | 'name' => 'UsersWP', |
288 | 288 | 'desc' => __('Allow frontend user login and registration as well as have slick profile pages.','invoicing'), |
289 | 289 | ), |
290 | - ); |
|
290 | + ); |
|
291 | 291 | |
292 | - return $plugins; |
|
293 | - } |
|
292 | + return $plugins; |
|
293 | + } |
|
294 | 294 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * All Invoicing extensions screen related functions can be found here. |
6 | 6 | * |
7 | 7 | */ |
8 | -if ( ! defined( 'ABSPATH' ) ) { |
|
8 | +if (!defined('ABSPATH')) { |
|
9 | 9 | exit; |
10 | 10 | } |
11 | 11 | |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @return array of tabs. |
22 | 22 | */ |
23 | - public function get_tabs(){ |
|
23 | + public function get_tabs() { |
|
24 | 24 | $tabs = array( |
25 | 25 | 'addons' => __("Addons", "invoicing"), |
26 | 26 | 'gateways' => __("Payment Gateways", "invoicing"), |
@@ -38,28 +38,28 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @return array |
40 | 40 | */ |
41 | - public function get_section_data( $section_id ) { |
|
42 | - $section = self::get_tab( $section_id ); |
|
41 | + public function get_section_data($section_id) { |
|
42 | + $section = self::get_tab($section_id); |
|
43 | 43 | $api_url = "https://wpinvoicing.com/edd-api/v2/products/"; |
44 | 44 | $section_data = new stdClass(); |
45 | 45 | |
46 | - if($section_id=='recommended_plugins'){ |
|
46 | + if ($section_id == 'recommended_plugins') { |
|
47 | 47 | $section_data->products = self::get_recommend_wp_plugins_edd_formatted(); |
48 | 48 | } |
49 | - elseif ( ! empty( $section ) ) { |
|
50 | - if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing |
|
49 | + elseif (!empty($section)) { |
|
50 | + if (false === ($section_data = get_transient('wpi_addons_section_' . $section_id))) { //@todo restore after testing |
|
51 | 51 | //if ( 1==1) { |
52 | 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); |
|
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 | 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, ) ); |
|
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 | 57 | |
58 | - if ( ! is_wp_error( $raw_section ) ) { |
|
59 | - $section_data = json_decode( wp_remote_retrieve_body( $raw_section ) ); |
|
58 | + if (!is_wp_error($raw_section)) { |
|
59 | + $section_data = json_decode(wp_remote_retrieve_body($raw_section)); |
|
60 | 60 | |
61 | - if ( ! empty( $section_data->products ) ) { |
|
62 | - set_transient( 'wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS ); |
|
61 | + if (!empty($section_data->products)) { |
|
62 | + set_transient('wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS); |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 | } |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | |
68 | 68 | $products = isset($section_data->products) ? $section_data->products : ''; |
69 | 69 | |
70 | - return apply_filters( 'wpi_addons_section_data', $products, $section_id ); |
|
70 | + return apply_filters('wpi_addons_section_data', $products, $section_id); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | * @param string $theme |
79 | 79 | * @param string $plugin |
80 | 80 | */ |
81 | - public function output_button( $addon ) { |
|
82 | - $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
81 | + public function output_button($addon) { |
|
82 | + $current_tab = empty($_GET['tab']) ? 'addons' : sanitize_title($_GET['tab']); |
|
83 | 83 | // $button_text = __('Free','invoicing'); |
84 | 84 | // $licensing = false; |
85 | 85 | // $installed = false; |
@@ -91,14 +91,14 @@ discard block |
||
91 | 91 | // $install_status = 'get'; |
92 | 92 | // $onclick = ''; |
93 | 93 | |
94 | - $wp_org_themes = array('supreme-directory','directory-starter'); |
|
94 | + $wp_org_themes = array('supreme-directory', 'directory-starter'); |
|
95 | 95 | |
96 | 96 | $button_args = array( |
97 | 97 | 'type' => $current_tab, |
98 | 98 | 'id' => isset($addon->info->id) ? absint($addon->info->id) : '', |
99 | 99 | 'title' => isset($addon->info->title) ? $addon->info->title : '', |
100 | - 'button_text' => __('Free','invoicing'), |
|
101 | - 'price_text' => __('Free','invoicing'), |
|
100 | + 'button_text' => __('Free', 'invoicing'), |
|
101 | + 'price_text' => __('Free', 'invoicing'), |
|
102 | 102 | 'link' => isset($addon->info->link) ? $addon->info->link : '', // link to product |
103 | 103 | 'url' => isset($addon->info->link) ? $addon->info->link : '', // button url |
104 | 104 | 'class' => 'button-primary', |
@@ -114,83 +114,83 @@ discard block |
||
114 | 114 | 'update_url' => '', |
115 | 115 | ); |
116 | 116 | |
117 | - if( ($current_tab == 'addons' || $current_tab =='gateways') && isset($addon->info->id) && $addon->info->id){ |
|
118 | - include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
|
119 | - if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
|
117 | + if (($current_tab == 'addons' || $current_tab == 'gateways') && isset($addon->info->id) && $addon->info->id) { |
|
118 | + include_once(ABSPATH . 'wp-admin/includes/plugin-install.php'); //for plugins_api.. |
|
119 | + if (!empty($addon->licensing->edd_slug)) {$button_args['slug'] = $addon->licensing->edd_slug; } |
|
120 | 120 | $status = self::install_plugin_install_status($addon); |
121 | 121 | $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
122 | - if(isset($status['status'])){$button_args['install_status'] = $status['status'];} |
|
122 | + if (isset($status['status'])) {$button_args['install_status'] = $status['status']; } |
|
123 | 123 | $button_args['update_url'] = "https://wpinvoicing.com"; |
124 | - }elseif($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) { |
|
125 | - if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;} |
|
124 | + }elseif ($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) { |
|
125 | + if (!empty($addon->licensing->edd_slug)) {$button_args['slug'] = $addon->licensing->edd_slug; } |
|
126 | 126 | $button_args['installed'] = self::is_theme_installed($addon); |
127 | - if(!in_array($button_args['slug'],$wp_org_themes)){ |
|
127 | + if (!in_array($button_args['slug'], $wp_org_themes)) { |
|
128 | 128 | $button_args['update_url'] = "https://wpinvoicing.com"; |
129 | 129 | } |
130 | - }elseif($current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug){ |
|
131 | - include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api.. |
|
132 | - $status = install_plugin_install_status(array("slug"=>$button_args['slug'],"version"=>"")); |
|
130 | + }elseif ($current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug) { |
|
131 | + include_once(ABSPATH . 'wp-admin/includes/plugin-install.php'); //for plugins_api.. |
|
132 | + $status = install_plugin_install_status(array("slug"=>$button_args['slug'], "version"=>"")); |
|
133 | 133 | $button_args['install_status'] = isset($status['status']) ? $status['status'] : 'install'; |
134 | 134 | $button_args['file'] = isset($status['file']) ? $status['file'] : ''; |
135 | 135 | } |
136 | 136 | |
137 | 137 | // set price |
138 | - if(isset($addon->pricing) && !empty($addon->pricing)){ |
|
139 | - if(is_object($addon->pricing)){ |
|
138 | + if (isset($addon->pricing) && !empty($addon->pricing)) { |
|
139 | + if (is_object($addon->pricing)) { |
|
140 | 140 | $prices = (Array)$addon->pricing; |
141 | 141 | $button_args['price'] = reset($prices); |
142 | - }elseif(isset($addon->pricing)){ |
|
142 | + }elseif (isset($addon->pricing)) { |
|
143 | 143 | $button_args['price'] = $addon->pricing; |
144 | 144 | } |
145 | 145 | } |
146 | 146 | |
147 | 147 | // set price text |
148 | - if( $button_args['price'] && $button_args['price'] != '0.00' ){ |
|
149 | - $button_args['price_text'] = sprintf( __('From: $%d', 'invoicing'), $button_args['price']); |
|
148 | + if ($button_args['price'] && $button_args['price'] != '0.00') { |
|
149 | + $button_args['price_text'] = sprintf(__('From: $%d', 'invoicing'), $button_args['price']); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | |
153 | 153 | // set if installed |
154 | - if(in_array($button_args['install_status'], array('installed','latest_installed','update_available','newer_installed'))){ |
|
154 | + if (in_array($button_args['install_status'], array('installed', 'latest_installed', 'update_available', 'newer_installed'))) { |
|
155 | 155 | $button_args['installed'] = true; |
156 | 156 | } |
157 | 157 | |
158 | 158 | // print_r($button_args); |
159 | 159 | // set if active |
160 | - if($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')){ |
|
161 | - if($button_args['type'] != 'themes'){ |
|
160 | + if ($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')) { |
|
161 | + if ($button_args['type'] != 'themes') { |
|
162 | 162 | $button_args['active'] = is_plugin_active($button_args['file']); |
163 | - }else{ |
|
163 | + } else { |
|
164 | 164 | $button_args['active'] = self::is_theme_active($addon); |
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
168 | 168 | // set button text and class |
169 | - if($button_args['active']){ |
|
170 | - $button_args['button_text'] = __('Active','invoicing'); |
|
169 | + if ($button_args['active']) { |
|
170 | + $button_args['button_text'] = __('Active', 'invoicing'); |
|
171 | 171 | $button_args['class'] = ' button-secondary disabled '; |
172 | - }elseif($button_args['installed']){ |
|
173 | - $button_args['button_text'] = __('Activate','invoicing'); |
|
172 | + }elseif ($button_args['installed']) { |
|
173 | + $button_args['button_text'] = __('Activate', 'invoicing'); |
|
174 | 174 | |
175 | - if($button_args['type'] != 'themes'){ |
|
176 | - if ( current_user_can( 'manage_options' ) ) { |
|
177 | - $button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin='.$button_args['file']), 'activate-plugin_' . $button_args['file']); |
|
178 | - }else{ |
|
175 | + if ($button_args['type'] != 'themes') { |
|
176 | + if (current_user_can('manage_options')) { |
|
177 | + $button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin=' . $button_args['file']), 'activate-plugin_' . $button_args['file']); |
|
178 | + } else { |
|
179 | 179 | $button_args['url'] = '#'; |
180 | 180 | } |
181 | - }else{ |
|
182 | - if ( current_user_can( 'switch_themes' ) ) { |
|
181 | + } else { |
|
182 | + if (current_user_can('switch_themes')) { |
|
183 | 183 | $button_args['url'] = self::get_theme_activation_url($addon); |
184 | - }else{ |
|
184 | + } else { |
|
185 | 185 | $button_args['url'] = '#'; |
186 | 186 | } |
187 | 187 | } |
188 | 188 | |
189 | - }else{ |
|
190 | - if($button_args['type'] == 'recommended_plugins'){ |
|
191 | - $button_args['button_text'] = __('Install','invoicing'); |
|
192 | - }else{ |
|
193 | - $button_args['button_text'] = __('Get it','invoicing'); |
|
189 | + } else { |
|
190 | + if ($button_args['type'] == 'recommended_plugins') { |
|
191 | + $button_args['button_text'] = __('Install', 'invoicing'); |
|
192 | + } else { |
|
193 | + $button_args['button_text'] = __('Get it', 'invoicing'); |
|
194 | 194 | |
195 | 195 | /*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){ |
196 | 196 | $button_args['button_text'] = __('Install','invoicing'); |
@@ -203,45 +203,45 @@ discard block |
||
203 | 203 | |
204 | 204 | |
205 | 205 | // filter the button arguments |
206 | - $button_args = apply_filters('edd_api_button_args',$button_args); |
|
206 | + $button_args = apply_filters('edd_api_button_args', $button_args); |
|
207 | 207 | |
208 | 208 | // set price text |
209 | - if(isset($button_args['price_text'])){ |
|
209 | + if (isset($button_args['price_text'])) { |
|
210 | 210 | ?> |
211 | 211 | <a |
212 | 212 | target="_blank" |
213 | 213 | class="addons-price-text" |
214 | - href="<?php echo esc_url( $button_args['link'] ); ?>"> |
|
215 | - <?php echo esc_html( $button_args['price_text'] ); ?> |
|
214 | + href="<?php echo esc_url($button_args['link']); ?>"> |
|
215 | + <?php echo esc_html($button_args['price_text']); ?> |
|
216 | 216 | </a> |
217 | 217 | <?php |
218 | 218 | } |
219 | 219 | |
220 | 220 | |
221 | 221 | $target = ''; |
222 | - if ( ! empty( $button_args['url'] ) ) { |
|
222 | + if (!empty($button_args['url'])) { |
|
223 | 223 | $target = strpos($button_args['url'], get_site_url()) !== false ? '' : ' target="_blank" '; |
224 | 224 | } |
225 | 225 | |
226 | 226 | ?> |
227 | 227 | <a |
228 | - data-licence="<?php echo esc_attr($button_args['license']);?>" |
|
229 | - data-licensing="<?php echo $button_args['licensing'] ? 1 : 0;?>" |
|
230 | - data-title="<?php echo esc_attr($button_args['title']);?>" |
|
231 | - data-type="<?php echo esc_attr($button_args['type']);?>" |
|
232 | - data-text-error-message="<?php _e('Something went wrong!','invoicing');?>" |
|
233 | - data-text-activate="<?php _e('Activate','invoicing');?>" |
|
234 | - data-text-activating="<?php _e('Activating','invoicing');?>" |
|
235 | - data-text-deactivate="<?php _e('Deactivate','invoicing');?>" |
|
236 | - data-text-installed="<?php _e('Installed','invoicing');?>" |
|
237 | - data-text-install="<?php _e('Install','invoicing');?>" |
|
238 | - data-text-installing="<?php _e('Installing','invoicing');?>" |
|
239 | - data-text-error="<?php _e('Error','invoicing');?>" |
|
240 | - <?php if(!empty($button_args['onclick'])){echo " onclick='".$button_args['onclick']."' ";}?> |
|
241 | - <?php echo $target;?> |
|
242 | - class="addons-button <?php echo esc_attr( $button_args['class'] ); ?>" |
|
243 | - href="<?php echo esc_url( $button_args['url'] ); ?>"> |
|
244 | - <?php echo esc_html( $button_args['button_text'] ); ?> |
|
228 | + data-licence="<?php echo esc_attr($button_args['license']); ?>" |
|
229 | + data-licensing="<?php echo $button_args['licensing'] ? 1 : 0; ?>" |
|
230 | + data-title="<?php echo esc_attr($button_args['title']); ?>" |
|
231 | + data-type="<?php echo esc_attr($button_args['type']); ?>" |
|
232 | + data-text-error-message="<?php _e('Something went wrong!', 'invoicing'); ?>" |
|
233 | + data-text-activate="<?php _e('Activate', 'invoicing'); ?>" |
|
234 | + data-text-activating="<?php _e('Activating', 'invoicing'); ?>" |
|
235 | + data-text-deactivate="<?php _e('Deactivate', 'invoicing'); ?>" |
|
236 | + data-text-installed="<?php _e('Installed', 'invoicing'); ?>" |
|
237 | + data-text-install="<?php _e('Install', 'invoicing'); ?>" |
|
238 | + data-text-installing="<?php _e('Installing', 'invoicing'); ?>" |
|
239 | + data-text-error="<?php _e('Error', 'invoicing'); ?>" |
|
240 | + <?php if (!empty($button_args['onclick'])) {echo " onclick='" . $button_args['onclick'] . "' "; }?> |
|
241 | + <?php echo $target; ?> |
|
242 | + class="addons-button <?php echo esc_attr($button_args['class']); ?>" |
|
243 | + href="<?php echo esc_url($button_args['url']); ?>"> |
|
244 | + <?php echo esc_html($button_args['button_text']); ?> |
|
245 | 245 | </a> |
246 | 246 | <?php |
247 | 247 | |
@@ -256,35 +256,35 @@ discard block |
||
256 | 256 | $tabs = self::get_tabs(); |
257 | 257 | $sections = self::get_sections(); |
258 | 258 | $theme = wp_get_theme(); |
259 | - $section_keys = array_keys( $sections ); |
|
260 | - $current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys ); |
|
261 | - $current_tab = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] ); |
|
262 | - include_once( WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php' ); |
|
259 | + $section_keys = array_keys($sections); |
|
260 | + $current_section = isset($_GET['section']) ? sanitize_text_field($_GET['section']) : current($section_keys); |
|
261 | + $current_tab = empty($_GET['tab']) ? 'addons' : sanitize_title($_GET['tab']); |
|
262 | + include_once(WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php'); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
266 | 266 | * A list of recommended wp.org plugins. |
267 | 267 | * @return array |
268 | 268 | */ |
269 | - public function get_recommend_wp_plugins(){ |
|
269 | + public function get_recommend_wp_plugins() { |
|
270 | 270 | $plugins = array( |
271 | 271 | 'invoicing-quotes' => array( |
272 | 272 | 'url' => 'https://wordpress.org/plugins/invoicing-quotes/', |
273 | 273 | 'slug' => 'invoicing-quotes', |
274 | 274 | 'name' => 'Quotes', |
275 | - 'desc' => __('Allows you to create quotes, send them to clients and convert them to Invoices when accepted by the customer.','invoicing'), |
|
275 | + 'desc' => __('Allows you to create quotes, send them to clients and convert them to Invoices when accepted by the customer.', 'invoicing'), |
|
276 | 276 | ), |
277 | 277 | 'geodirectory' => array( |
278 | 278 | 'url' => 'https://wordpress.org/plugins/geodirectory/', |
279 | 279 | 'slug' => 'geodirectory', |
280 | 280 | 'name' => 'GeoDirectory', |
281 | - 'desc' => __('Turn any WordPress theme into a global business directory portal.','invoicing'), |
|
281 | + 'desc' => __('Turn any WordPress theme into a global business directory portal.', 'invoicing'), |
|
282 | 282 | ), |
283 | 283 | 'userswp' => array( |
284 | 284 | 'url' => 'https://wordpress.org/plugins/userswp/', |
285 | 285 | 'slug' => 'userswp', |
286 | 286 | 'name' => 'UsersWP', |
287 | - 'desc' => __('Allow frontend user login and registration as well as have slick profile pages.','invoicing'), |
|
287 | + 'desc' => __('Allow frontend user login and registration as well as have slick profile pages.', 'invoicing'), |
|
288 | 288 | ), |
289 | 289 | ); |
290 | 290 |
@@ -51,8 +51,8 @@ |
||
51 | 51 | /** |
52 | 52 | * Get section for the addons screen. |
53 | 53 | * |
54 | - * @param string $section_id |
|
55 | 54 | * |
55 | + * @param string $tab_id |
|
56 | 56 | * @return object|bool |
57 | 57 | */ |
58 | 58 | public function get_tab($tab_id) |
@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
4 | -if(!class_exists('Ayecode_Addons')) { |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | +if (!class_exists('Ayecode_Addons')) { |
|
5 | 5 | |
6 | 6 | abstract class Ayecode_Addons |
7 | 7 | { |
@@ -1,6 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if ( ! defined( 'ABSPATH' ) ) { |
|
4 | + exit; |
|
5 | +} |
|
4 | 6 | if(!class_exists('Ayecode_Addons')) { |
5 | 7 | |
6 | 8 | abstract class Ayecode_Addons |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Setup menus in WP admin. |
4 | 4 | */ |
5 | 5 | |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * WC_Admin_Menus Class. |
@@ -13,34 +13,34 @@ discard block |
||
13 | 13 | * Hook in tabs. |
14 | 14 | */ |
15 | 15 | public function __construct() { |
16 | - add_action( 'admin_menu', array( $this, 'admin_menu' ), 10 ); |
|
17 | - add_action( 'admin_menu', array( $this, 'add_addons_menu' ), 99 ); |
|
18 | - add_action( 'admin_menu', array( $this, 'remove_admin_submenus' ), 10 ); |
|
19 | - add_action( 'admin_head-nav-menus.php', array( $this, 'add_nav_menu_meta_boxes' ) ); |
|
16 | + add_action('admin_menu', array($this, 'admin_menu'), 10); |
|
17 | + add_action('admin_menu', array($this, 'add_addons_menu'), 99); |
|
18 | + add_action('admin_menu', array($this, 'remove_admin_submenus'), 10); |
|
19 | + add_action('admin_head-nav-menus.php', array($this, 'add_nav_menu_meta_boxes')); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | public function admin_menu() { |
23 | 23 | global $menu; |
24 | 24 | |
25 | - if ( !(current_user_can( 'manage_invoicing' ) || current_user_can( 'manage_options' )) ) { |
|
25 | + if (!(current_user_can('manage_invoicing') || current_user_can('manage_options'))) { |
|
26 | 26 | return; |
27 | 27 | } |
28 | 28 | |
29 | - $capability = apply_filters( 'invoicing_capability', 'manage_invoicing' ); |
|
29 | + $capability = apply_filters('invoicing_capability', 'manage_invoicing'); |
|
30 | 30 | |
31 | - if ( current_user_can( 'manage_options' ) ) { |
|
32 | - $menu[] = array( '', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv' ); |
|
31 | + if (current_user_can('manage_options')) { |
|
32 | + $menu[] = array('', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv'); |
|
33 | 33 | } |
34 | 34 | |
35 | - $wpi_invoice = get_post_type_object( 'wpi_invoice' ); |
|
35 | + $wpi_invoice = get_post_type_object('wpi_invoice'); |
|
36 | 36 | |
37 | - add_menu_page( __( 'Invoicing', 'invoicing' ), __( 'Invoicing', 'invoicing' ), $capability, 'wpinv', null, $wpi_invoice->menu_icon, '54.123460' ); |
|
37 | + add_menu_page(__('Invoicing', 'invoicing'), __('Invoicing', 'invoicing'), $capability, 'wpinv', null, $wpi_invoice->menu_icon, '54.123460'); |
|
38 | 38 | |
39 | - add_submenu_page( 'wpinv', __( 'Invoice Settings', 'invoicing' ), __( 'Settings', 'invoicing' ), $capability, 'wpinv-settings', array( $this, 'options_page' )); |
|
39 | + add_submenu_page('wpinv', __('Invoice Settings', 'invoicing'), __('Settings', 'invoicing'), $capability, 'wpinv-settings', array($this, 'options_page')); |
|
40 | 40 | } |
41 | 41 | |
42 | - public function add_addons_menu(){ |
|
43 | - if ( !apply_filters( 'wpi_show_addons_page', true ) ) { |
|
42 | + public function add_addons_menu() { |
|
43 | + if (!apply_filters('wpi_show_addons_page', true)) { |
|
44 | 44 | return; |
45 | 45 | } |
46 | 46 | |
@@ -50,78 +50,78 @@ discard block |
||
50 | 50 | __('Extensions', 'userswp'), |
51 | 51 | 'manage_options', |
52 | 52 | 'wpi-addons', |
53 | - array( $this, 'addons_page' ) |
|
53 | + array($this, 'addons_page') |
|
54 | 54 | ); |
55 | 55 | } |
56 | 56 | |
57 | - public function addons_page(){ |
|
57 | + public function addons_page() { |
|
58 | 58 | $addon_obj = new WPInv_Admin_Addons(); |
59 | 59 | $addon_obj->output(); |
60 | 60 | } |
61 | 61 | |
62 | 62 | function options_page() { |
63 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
63 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
64 | 64 | |
65 | - if ( $page !== 'wpinv-settings' ) { |
|
65 | + if ($page !== 'wpinv-settings') { |
|
66 | 66 | return; |
67 | 67 | } |
68 | 68 | |
69 | 69 | $settings_tabs = wpinv_get_settings_tabs(); |
70 | 70 | $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs; |
71 | - $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general'; |
|
72 | - $sections = wpinv_get_settings_tab_sections( $active_tab ); |
|
71 | + $active_tab = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general'; |
|
72 | + $sections = wpinv_get_settings_tab_sections($active_tab); |
|
73 | 73 | $key = 'main'; |
74 | 74 | |
75 | - if ( is_array( $sections ) ) { |
|
76 | - $key = key( $sections ); |
|
75 | + if (is_array($sections)) { |
|
76 | + $key = key($sections); |
|
77 | 77 | } |
78 | 78 | |
79 | - $registered_sections = wpinv_get_settings_tab_sections( $active_tab ); |
|
80 | - $section = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key; |
|
79 | + $registered_sections = wpinv_get_settings_tab_sections($active_tab); |
|
80 | + $section = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? $_GET['section'] : $key; |
|
81 | 81 | ob_start(); |
82 | 82 | ?> |
83 | 83 | <div class="wrap"> |
84 | 84 | <h1 class="nav-tab-wrapper"> |
85 | 85 | <?php |
86 | - foreach( wpinv_get_settings_tabs() as $tab_id => $tab_name ) { |
|
87 | - $tab_url = add_query_arg( array( |
|
86 | + foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) { |
|
87 | + $tab_url = add_query_arg(array( |
|
88 | 88 | 'settings-updated' => false, |
89 | 89 | 'tab' => $tab_id, |
90 | - ) ); |
|
90 | + )); |
|
91 | 91 | |
92 | 92 | // Remove the section from the tabs so we always end up at the main section |
93 | - $tab_url = remove_query_arg( 'section', $tab_url ); |
|
94 | - $tab_url = remove_query_arg( 'wpi_sub', $tab_url ); |
|
93 | + $tab_url = remove_query_arg('section', $tab_url); |
|
94 | + $tab_url = remove_query_arg('wpi_sub', $tab_url); |
|
95 | 95 | |
96 | 96 | $active = $active_tab == $tab_id ? ' nav-tab-active' : ''; |
97 | 97 | |
98 | - echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">'; |
|
99 | - echo esc_html( $tab_name ); |
|
98 | + echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">'; |
|
99 | + echo esc_html($tab_name); |
|
100 | 100 | echo '</a>'; |
101 | 101 | } |
102 | 102 | ?> |
103 | 103 | </h1> |
104 | 104 | <?php |
105 | - $number_of_sections = count( $sections ); |
|
105 | + $number_of_sections = count($sections); |
|
106 | 106 | $number = 0; |
107 | - if ( $number_of_sections > 1 ) { |
|
107 | + if ($number_of_sections > 1) { |
|
108 | 108 | echo '<div><ul class="subsubsub">'; |
109 | - foreach( $sections as $section_id => $section_name ) { |
|
109 | + foreach ($sections as $section_id => $section_name) { |
|
110 | 110 | echo '<li>'; |
111 | 111 | $number++; |
112 | - $tab_url = add_query_arg( array( |
|
112 | + $tab_url = add_query_arg(array( |
|
113 | 113 | 'settings-updated' => false, |
114 | 114 | 'tab' => $active_tab, |
115 | 115 | 'section' => $section_id |
116 | - ) ); |
|
117 | - $tab_url = remove_query_arg( 'wpi_sub', $tab_url ); |
|
116 | + )); |
|
117 | + $tab_url = remove_query_arg('wpi_sub', $tab_url); |
|
118 | 118 | $class = ''; |
119 | - if ( $section == $section_id ) { |
|
119 | + if ($section == $section_id) { |
|
120 | 120 | $class = 'current'; |
121 | 121 | } |
122 | - echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>'; |
|
122 | + echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>'; |
|
123 | 123 | |
124 | - if ( $number != $number_of_sections ) { |
|
124 | + if ($number != $number_of_sections) { |
|
125 | 125 | echo ' | '; |
126 | 126 | } |
127 | 127 | echo '</li>'; |
@@ -133,19 +133,19 @@ discard block |
||
133 | 133 | <form method="post" action="options.php"> |
134 | 134 | <table class="form-table"> |
135 | 135 | <?php |
136 | - settings_fields( 'wpinv_settings' ); |
|
136 | + settings_fields('wpinv_settings'); |
|
137 | 137 | |
138 | - if ( 'main' === $section ) { |
|
139 | - do_action( 'wpinv_settings_tab_top', $active_tab ); |
|
138 | + if ('main' === $section) { |
|
139 | + do_action('wpinv_settings_tab_top', $active_tab); |
|
140 | 140 | } |
141 | 141 | |
142 | - do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
143 | - do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
144 | - do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section ); |
|
142 | + do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section); |
|
143 | + do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section); |
|
144 | + do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section); |
|
145 | 145 | |
146 | 146 | // For backwards compatibility |
147 | - if ( 'main' === $section ) { |
|
148 | - do_action( 'wpinv_settings_tab_bottom', $active_tab ); |
|
147 | + if ('main' === $section) { |
|
148 | + do_action('wpinv_settings_tab_bottom', $active_tab); |
|
149 | 149 | } |
150 | 150 | ?> |
151 | 151 | </table> |
@@ -159,52 +159,52 @@ discard block |
||
159 | 159 | } |
160 | 160 | |
161 | 161 | public function remove_admin_submenus() { |
162 | - remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' ); |
|
162 | + remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice'); |
|
163 | 163 | } |
164 | 164 | |
165 | - public function add_nav_menu_meta_boxes(){ |
|
166 | - add_meta_box( 'wpinv_endpoints_nav_link', __( 'Invoicing Pages', 'invoicing' ), array( $this, 'nav_menu_links' ), 'nav-menus', 'side', 'low' ); |
|
165 | + public function add_nav_menu_meta_boxes() { |
|
166 | + add_meta_box('wpinv_endpoints_nav_link', __('Invoicing Pages', 'invoicing'), array($this, 'nav_menu_links'), 'nav-menus', 'side', 'low'); |
|
167 | 167 | } |
168 | 168 | |
169 | - public function nav_menu_links(){ |
|
169 | + public function nav_menu_links() { |
|
170 | 170 | $endpoints = $this->get_menu_items(); |
171 | 171 | ?> |
172 | 172 | <div id="invoicing-endpoints" class="posttypediv"> |
173 | - <?php if(!empty($endpoints['pages'])){ ?> |
|
173 | + <?php if (!empty($endpoints['pages'])) { ?> |
|
174 | 174 | <div id="tabs-panel-invoicing-endpoints" class="tabs-panel tabs-panel-active"> |
175 | 175 | <ul id="invoicing-endpoints-checklist" class="categorychecklist form-no-clear"> |
176 | 176 | <?php |
177 | 177 | $walker = new Walker_Nav_Menu_Checklist(array()); |
178 | - echo walk_nav_menu_tree(array_map('wp_setup_nav_menu_item', $endpoints['pages']), 0, (object) array('walker' => $walker)); |
|
178 | + echo walk_nav_menu_tree(array_map('wp_setup_nav_menu_item', $endpoints['pages']), 0, (object)array('walker' => $walker)); |
|
179 | 179 | ?> |
180 | 180 | </ul> |
181 | 181 | </div> |
182 | 182 | <?php } ?> |
183 | 183 | <p class="button-controls"> |
184 | 184 | <span class="list-controls"> |
185 | - <a href="<?php echo admin_url( 'nav-menus.php?page-tab=all&selectall=1#invoicing-endpoints' ); ?>" class="select-all"><?php _e( 'Select all', 'invoicing' ); ?></a> |
|
185 | + <a href="<?php echo admin_url('nav-menus.php?page-tab=all&selectall=1#invoicing-endpoints'); ?>" class="select-all"><?php _e('Select all', 'invoicing'); ?></a> |
|
186 | 186 | </span> |
187 | 187 | <span class="add-to-menu"> |
188 | - <input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to menu', 'invoicing' ); ?>" name="add-post-type-menu-item" id="submit-invoicing-endpoints"> |
|
188 | + <input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to menu', 'invoicing'); ?>" name="add-post-type-menu-item" id="submit-invoicing-endpoints"> |
|
189 | 189 | <span class="spinner"></span> |
190 | 190 | </span> |
191 | 191 | </p> |
192 | 192 | <?php |
193 | 193 | } |
194 | 194 | |
195 | - public function get_menu_items(){ |
|
195 | + public function get_menu_items() { |
|
196 | 196 | $items = array(); |
197 | 197 | |
198 | - $wpinv_history_page_id = (int)wpinv_get_option( 'invoice_history_page' ); |
|
199 | - if($wpinv_history_page_id > 0){ |
|
198 | + $wpinv_history_page_id = (int)wpinv_get_option('invoice_history_page'); |
|
199 | + if ($wpinv_history_page_id > 0) { |
|
200 | 200 | $item = new stdClass(); |
201 | 201 | $item->object_id = $wpinv_history_page_id; |
202 | 202 | $item->db_id = 0; |
203 | - $item->object = 'page'; |
|
203 | + $item->object = 'page'; |
|
204 | 204 | $item->menu_item_parent = 0; |
205 | 205 | $item->type = 'post_type'; |
206 | - $item->title = __('Invoice History Page','invoicing'); |
|
207 | - $item->url = get_permalink( $wpinv_history_page_id ); |
|
206 | + $item->title = __('Invoice History Page', 'invoicing'); |
|
207 | + $item->url = get_permalink($wpinv_history_page_id); |
|
208 | 208 | $item->target = ''; |
209 | 209 | $item->attr_title = ''; |
210 | 210 | $item->classes = array('wpinv-menu-item'); |
@@ -213,16 +213,16 @@ discard block |
||
213 | 213 | $items['pages'][] = $item; |
214 | 214 | } |
215 | 215 | |
216 | - $wpinv_sub_history_page_id = (int)wpinv_get_option( 'invoice_subscription_page' ); |
|
217 | - if($wpinv_sub_history_page_id > 0){ |
|
216 | + $wpinv_sub_history_page_id = (int)wpinv_get_option('invoice_subscription_page'); |
|
217 | + if ($wpinv_sub_history_page_id > 0) { |
|
218 | 218 | $item = new stdClass(); |
219 | 219 | $item->object_id = $wpinv_sub_history_page_id; |
220 | 220 | $item->db_id = 0; |
221 | - $item->object = 'page'; |
|
221 | + $item->object = 'page'; |
|
222 | 222 | $item->menu_item_parent = 0; |
223 | 223 | $item->type = 'post_type'; |
224 | - $item->title = __('Invoice Subscriptions Page','invoicing'); |
|
225 | - $item->url = get_permalink( $wpinv_sub_history_page_id ); |
|
224 | + $item->title = __('Invoice Subscriptions Page', 'invoicing'); |
|
225 | + $item->url = get_permalink($wpinv_sub_history_page_id); |
|
226 | 226 | $item->target = ''; |
227 | 227 | $item->attr_title = ''; |
228 | 228 | $item->classes = array('wpinv-menu-item'); |
@@ -231,16 +231,16 @@ discard block |
||
231 | 231 | $items['pages'][] = $item; |
232 | 232 | } |
233 | 233 | |
234 | - $wpinv_checkout_page_id = (int)wpinv_get_option( 'checkout_page' ); |
|
235 | - if($wpinv_checkout_page_id > 0){ |
|
234 | + $wpinv_checkout_page_id = (int)wpinv_get_option('checkout_page'); |
|
235 | + if ($wpinv_checkout_page_id > 0) { |
|
236 | 236 | $item = new stdClass(); |
237 | 237 | $item->object_id = $wpinv_checkout_page_id; |
238 | 238 | $item->db_id = 0; |
239 | - $item->object = 'page'; |
|
239 | + $item->object = 'page'; |
|
240 | 240 | $item->menu_item_parent = 0; |
241 | 241 | $item->type = 'post_type'; |
242 | - $item->title = __('Checkout Page','invoicing'); |
|
243 | - $item->url = get_permalink( $wpinv_checkout_page_id ); |
|
242 | + $item->title = __('Checkout Page', 'invoicing'); |
|
243 | + $item->url = get_permalink($wpinv_checkout_page_id); |
|
244 | 244 | $item->target = ''; |
245 | 245 | $item->attr_title = ''; |
246 | 246 | $item->classes = array('wpinv-menu-item'); |
@@ -249,16 +249,16 @@ discard block |
||
249 | 249 | $items['pages'][] = $item; |
250 | 250 | } |
251 | 251 | |
252 | - $wpinv_tandc_page_id = (int)wpinv_get_option( 'tandc_page' ); |
|
253 | - if($wpinv_tandc_page_id > 0){ |
|
252 | + $wpinv_tandc_page_id = (int)wpinv_get_option('tandc_page'); |
|
253 | + if ($wpinv_tandc_page_id > 0) { |
|
254 | 254 | $item = new stdClass(); |
255 | 255 | $item->object_id = $wpinv_tandc_page_id; |
256 | 256 | $item->db_id = 0; |
257 | - $item->object = 'page'; |
|
257 | + $item->object = 'page'; |
|
258 | 258 | $item->menu_item_parent = 0; |
259 | 259 | $item->type = 'post_type'; |
260 | - $item->title = __('Terms & Conditions','invoicing'); |
|
261 | - $item->url = get_permalink( $wpinv_tandc_page_id ); |
|
260 | + $item->title = __('Terms & Conditions', 'invoicing'); |
|
261 | + $item->url = get_permalink($wpinv_tandc_page_id); |
|
262 | 262 | $item->target = ''; |
263 | 263 | $item->attr_title = ''; |
264 | 264 | $item->classes = array('wpinv-menu-item'); |
@@ -267,16 +267,16 @@ discard block |
||
267 | 267 | $items['pages'][] = $item; |
268 | 268 | } |
269 | 269 | |
270 | - $wpinv_success_page_id = (int)wpinv_get_option( 'success_page' ); |
|
271 | - if($wpinv_success_page_id > 0){ |
|
270 | + $wpinv_success_page_id = (int)wpinv_get_option('success_page'); |
|
271 | + if ($wpinv_success_page_id > 0) { |
|
272 | 272 | $item = new stdClass(); |
273 | 273 | $item->object_id = $wpinv_success_page_id; |
274 | 274 | $item->db_id = 0; |
275 | - $item->object = 'page'; |
|
275 | + $item->object = 'page'; |
|
276 | 276 | $item->menu_item_parent = 0; |
277 | 277 | $item->type = 'post_type'; |
278 | - $item->title = __('Success Page','invoicing'); |
|
279 | - $item->url = get_permalink( $wpinv_success_page_id ); |
|
278 | + $item->title = __('Success Page', 'invoicing'); |
|
279 | + $item->url = get_permalink($wpinv_success_page_id); |
|
280 | 280 | $item->target = ''; |
281 | 281 | $item->attr_title = ''; |
282 | 282 | $item->classes = array('wpinv-menu-item'); |
@@ -285,16 +285,16 @@ discard block |
||
285 | 285 | $items['pages'][] = $item; |
286 | 286 | } |
287 | 287 | |
288 | - $wpinv_failure_page_id = (int)wpinv_get_option( 'failure_page' ); |
|
289 | - if($wpinv_failure_page_id > 0){ |
|
288 | + $wpinv_failure_page_id = (int)wpinv_get_option('failure_page'); |
|
289 | + if ($wpinv_failure_page_id > 0) { |
|
290 | 290 | $item = new stdClass(); |
291 | 291 | $item->object_id = $wpinv_failure_page_id; |
292 | 292 | $item->db_id = 0; |
293 | - $item->object = 'page'; |
|
293 | + $item->object = 'page'; |
|
294 | 294 | $item->menu_item_parent = 0; |
295 | 295 | $item->type = 'post_type'; |
296 | - $item->title = __('Failed Transaction Page','invoicing'); |
|
297 | - $item->url = get_permalink( $wpinv_failure_page_id ); |
|
296 | + $item->title = __('Failed Transaction Page', 'invoicing'); |
|
297 | + $item->url = get_permalink($wpinv_failure_page_id); |
|
298 | 298 | $item->target = ''; |
299 | 299 | $item->attr_title = ''; |
300 | 300 | $item->classes = array('wpinv-menu-item'); |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | $items['pages'][] = $item; |
304 | 304 | } |
305 | 305 | |
306 | - return apply_filters( 'wpinv_menu_items', $items ); |
|
306 | + return apply_filters('wpinv_menu_items', $items); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * Bail if we are not in WP. |
14 | 14 | */ |
15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
16 | - exit; |
|
16 | + exit; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -21,294 +21,294 @@ discard block |
||
21 | 21 | */ |
22 | 22 | if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
23 | 23 | |
24 | - /** |
|
25 | - * A Class to be able to change settings for Font Awesome. |
|
26 | - * |
|
27 | - * Class WP_Font_Awesome_Settings |
|
28 | - * @since 1.0.10 Now able to pass wp.org theme check. |
|
29 | - * @since 1.0.11 Font Awesome Pro now supported. |
|
30 | - * @since 1.0.11 Font Awesome Kits now supported. |
|
31 | - * @ver 1.0.11 |
|
32 | - * @todo decide how to implement textdomain |
|
33 | - */ |
|
34 | - class WP_Font_Awesome_Settings { |
|
35 | - |
|
36 | - /** |
|
37 | - * Class version version. |
|
38 | - * |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - public $version = '1.0.11'; |
|
42 | - |
|
43 | - /** |
|
44 | - * Class textdomain. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
48 | - public $textdomain = 'font-awesome-settings'; |
|
49 | - |
|
50 | - /** |
|
51 | - * Latest version of Font Awesome at time of publish published. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - public $latest = "5.8.2"; |
|
56 | - |
|
57 | - /** |
|
58 | - * The title. |
|
59 | - * |
|
60 | - * @var string |
|
61 | - */ |
|
62 | - public $name = 'Font Awesome'; |
|
63 | - |
|
64 | - /** |
|
65 | - * Holds the settings values. |
|
66 | - * |
|
67 | - * @var array |
|
68 | - */ |
|
69 | - private $settings; |
|
70 | - |
|
71 | - /** |
|
72 | - * WP_Font_Awesome_Settings instance. |
|
73 | - * |
|
74 | - * @access private |
|
75 | - * @since 1.0.0 |
|
76 | - * @var WP_Font_Awesome_Settings There can be only one! |
|
77 | - */ |
|
78 | - private static $instance = null; |
|
79 | - |
|
80 | - /** |
|
81 | - * Main WP_Font_Awesome_Settings Instance. |
|
82 | - * |
|
83 | - * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
84 | - * |
|
85 | - * @since 1.0.0 |
|
86 | - * @static |
|
87 | - * @return WP_Font_Awesome_Settings - Main instance. |
|
88 | - */ |
|
89 | - public static function instance() { |
|
90 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
91 | - self::$instance = new WP_Font_Awesome_Settings; |
|
92 | - |
|
93 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
94 | - |
|
95 | - if ( is_admin() ) { |
|
96 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
97 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
98 | - } |
|
99 | - |
|
100 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
101 | - } |
|
102 | - |
|
103 | - return self::$instance; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Initiate the settings and add the required action hooks. |
|
108 | - * |
|
109 | - * @since 1.0.8 Settings name wrong - FIXED |
|
110 | - */ |
|
111 | - public function init() { |
|
112 | - $this->settings = $this->get_settings(); |
|
113 | - |
|
114 | - if ( $this->settings['type'] == 'CSS' ) { |
|
115 | - |
|
116 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
117 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
118 | - } |
|
119 | - |
|
120 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
121 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
122 | - } |
|
123 | - |
|
124 | - } else { |
|
125 | - |
|
126 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
127 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
128 | - } |
|
129 | - |
|
130 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
131 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
132 | - } |
|
133 | - } |
|
134 | - |
|
135 | - // remove font awesome if set to do so |
|
136 | - if ( $this->settings['dequeue'] == '1' ) { |
|
137 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
138 | - } |
|
139 | - |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Adds the Font Awesome styles. |
|
144 | - */ |
|
145 | - public function enqueue_style() { |
|
146 | - // build url |
|
147 | - $url = $this->get_url(); |
|
148 | - |
|
149 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
150 | - wp_register_style( 'font-awesome', $url, array(), null ); |
|
151 | - wp_enqueue_style( 'font-awesome' ); |
|
152 | - |
|
153 | - if ( $this->settings['shims'] ) { |
|
154 | - $url = $this->get_url( true ); |
|
155 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
156 | - wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
157 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
158 | - } |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * Adds the Font Awesome JS. |
|
163 | - */ |
|
164 | - public function enqueue_scripts() { |
|
165 | - // build url |
|
166 | - $url = $this->get_url(); |
|
167 | - |
|
168 | - $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
169 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
170 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
171 | - wp_enqueue_script( 'font-awesome' ); |
|
172 | - |
|
173 | - if ( $this->settings['shims'] ) { |
|
174 | - $url = $this->get_url( true ); |
|
175 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
176 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
177 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
178 | - } |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Get the url of the Font Awesome files. |
|
183 | - * |
|
184 | - * @param bool $shims If this is a shim file or not. |
|
185 | - * |
|
186 | - * @return string The url to the file. |
|
187 | - */ |
|
188 | - public function get_url( $shims = false ) { |
|
189 | - $script = $shims ? 'v4-shims' : 'all'; |
|
190 | - $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
191 | - $type = $this->settings['type']; |
|
192 | - $version = $this->settings['version']; |
|
193 | - $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
194 | - $url = ''; |
|
195 | - |
|
196 | - if ( $type == 'KIT' && $kit_url ) { |
|
197 | - if ( $shims ) { |
|
198 | - // if its a kit then we don't add shims here |
|
199 | - return ''; |
|
200 | - } |
|
201 | - $url .= $kit_url; // CDN |
|
202 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
203 | - } else { |
|
204 | - $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
205 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
206 | - $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
207 | - $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
208 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
209 | - } |
|
210 | - |
|
211 | - return $url; |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
216 | - * |
|
217 | - * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
218 | - * |
|
219 | - * @param $url |
|
220 | - * @param $original_url |
|
221 | - * @param $_context |
|
222 | - * |
|
223 | - * @return string The filtered url. |
|
224 | - */ |
|
225 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
226 | - |
|
227 | - if ( $_context == 'display' |
|
228 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
229 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
230 | - ) {// it's a font-awesome-url (probably) |
|
231 | - |
|
232 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
233 | - if ( $this->settings['type'] == 'JS' ) { |
|
234 | - if ( $this->settings['js-pseudo'] ) { |
|
235 | - $url .= "' data-search-pseudo-elements defer='defer"; |
|
236 | - } else { |
|
237 | - $url .= "' defer='defer"; |
|
238 | - } |
|
239 | - } |
|
240 | - } else { |
|
241 | - $url = ''; // removing the url removes the file |
|
242 | - } |
|
243 | - |
|
244 | - } |
|
245 | - |
|
246 | - return $url; |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * Register the database settings with WordPress. |
|
251 | - */ |
|
252 | - public function register_settings() { |
|
253 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
254 | - } |
|
255 | - |
|
256 | - /** |
|
257 | - * Add the WordPress settings menu item. |
|
258 | - * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
259 | - */ |
|
260 | - public function menu_item() { |
|
261 | - $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
262 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
263 | - $this, |
|
264 | - 'settings_page' |
|
265 | - ) ); |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * Get the current Font Awesome output settings. |
|
270 | - * |
|
271 | - * @return array The array of settings. |
|
272 | - */ |
|
273 | - public function get_settings() { |
|
274 | - |
|
275 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
276 | - |
|
277 | - $defaults = array( |
|
278 | - 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
279 | - 'version' => '', // latest |
|
280 | - 'enqueue' => '', // front and backend |
|
281 | - 'shims' => '1', // default on for now, @todo maybe change to off in 2020 |
|
282 | - 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
283 | - 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
284 | - 'pro' => '0', // if pro CDN url should be used |
|
285 | - 'kit-url' => '', // the kit url |
|
286 | - ); |
|
287 | - |
|
288 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
289 | - |
|
290 | - /** |
|
291 | - * Filter the Font Awesome settings. |
|
292 | - * |
|
293 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
294 | - */ |
|
295 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * The settings page html output. |
|
301 | - */ |
|
302 | - public function settings_page() { |
|
303 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
304 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
305 | - } |
|
306 | - |
|
307 | - // a hidden way to force the update of the verison number vai api instead of waiting the 48 hours |
|
308 | - if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
309 | - $this->get_latest_version( $force_api = true ); |
|
310 | - } |
|
311 | - ?> |
|
24 | + /** |
|
25 | + * A Class to be able to change settings for Font Awesome. |
|
26 | + * |
|
27 | + * Class WP_Font_Awesome_Settings |
|
28 | + * @since 1.0.10 Now able to pass wp.org theme check. |
|
29 | + * @since 1.0.11 Font Awesome Pro now supported. |
|
30 | + * @since 1.0.11 Font Awesome Kits now supported. |
|
31 | + * @ver 1.0.11 |
|
32 | + * @todo decide how to implement textdomain |
|
33 | + */ |
|
34 | + class WP_Font_Awesome_Settings { |
|
35 | + |
|
36 | + /** |
|
37 | + * Class version version. |
|
38 | + * |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + public $version = '1.0.11'; |
|
42 | + |
|
43 | + /** |
|
44 | + * Class textdomain. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + public $textdomain = 'font-awesome-settings'; |
|
49 | + |
|
50 | + /** |
|
51 | + * Latest version of Font Awesome at time of publish published. |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + public $latest = "5.8.2"; |
|
56 | + |
|
57 | + /** |
|
58 | + * The title. |
|
59 | + * |
|
60 | + * @var string |
|
61 | + */ |
|
62 | + public $name = 'Font Awesome'; |
|
63 | + |
|
64 | + /** |
|
65 | + * Holds the settings values. |
|
66 | + * |
|
67 | + * @var array |
|
68 | + */ |
|
69 | + private $settings; |
|
70 | + |
|
71 | + /** |
|
72 | + * WP_Font_Awesome_Settings instance. |
|
73 | + * |
|
74 | + * @access private |
|
75 | + * @since 1.0.0 |
|
76 | + * @var WP_Font_Awesome_Settings There can be only one! |
|
77 | + */ |
|
78 | + private static $instance = null; |
|
79 | + |
|
80 | + /** |
|
81 | + * Main WP_Font_Awesome_Settings Instance. |
|
82 | + * |
|
83 | + * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
84 | + * |
|
85 | + * @since 1.0.0 |
|
86 | + * @static |
|
87 | + * @return WP_Font_Awesome_Settings - Main instance. |
|
88 | + */ |
|
89 | + public static function instance() { |
|
90 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
91 | + self::$instance = new WP_Font_Awesome_Settings; |
|
92 | + |
|
93 | + add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
94 | + |
|
95 | + if ( is_admin() ) { |
|
96 | + add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
97 | + add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
98 | + } |
|
99 | + |
|
100 | + do_action( 'wp_font_awesome_settings_loaded' ); |
|
101 | + } |
|
102 | + |
|
103 | + return self::$instance; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Initiate the settings and add the required action hooks. |
|
108 | + * |
|
109 | + * @since 1.0.8 Settings name wrong - FIXED |
|
110 | + */ |
|
111 | + public function init() { |
|
112 | + $this->settings = $this->get_settings(); |
|
113 | + |
|
114 | + if ( $this->settings['type'] == 'CSS' ) { |
|
115 | + |
|
116 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
117 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
118 | + } |
|
119 | + |
|
120 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
121 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
122 | + } |
|
123 | + |
|
124 | + } else { |
|
125 | + |
|
126 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
127 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
128 | + } |
|
129 | + |
|
130 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
131 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
132 | + } |
|
133 | + } |
|
134 | + |
|
135 | + // remove font awesome if set to do so |
|
136 | + if ( $this->settings['dequeue'] == '1' ) { |
|
137 | + add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
138 | + } |
|
139 | + |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Adds the Font Awesome styles. |
|
144 | + */ |
|
145 | + public function enqueue_style() { |
|
146 | + // build url |
|
147 | + $url = $this->get_url(); |
|
148 | + |
|
149 | + wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
150 | + wp_register_style( 'font-awesome', $url, array(), null ); |
|
151 | + wp_enqueue_style( 'font-awesome' ); |
|
152 | + |
|
153 | + if ( $this->settings['shims'] ) { |
|
154 | + $url = $this->get_url( true ); |
|
155 | + wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
156 | + wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
157 | + wp_enqueue_style( 'font-awesome-shims' ); |
|
158 | + } |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * Adds the Font Awesome JS. |
|
163 | + */ |
|
164 | + public function enqueue_scripts() { |
|
165 | + // build url |
|
166 | + $url = $this->get_url(); |
|
167 | + |
|
168 | + $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
169 | + call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
170 | + wp_register_script( 'font-awesome', $url, array(), null ); |
|
171 | + wp_enqueue_script( 'font-awesome' ); |
|
172 | + |
|
173 | + if ( $this->settings['shims'] ) { |
|
174 | + $url = $this->get_url( true ); |
|
175 | + call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
176 | + wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
177 | + wp_enqueue_script( 'font-awesome-shims' ); |
|
178 | + } |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Get the url of the Font Awesome files. |
|
183 | + * |
|
184 | + * @param bool $shims If this is a shim file or not. |
|
185 | + * |
|
186 | + * @return string The url to the file. |
|
187 | + */ |
|
188 | + public function get_url( $shims = false ) { |
|
189 | + $script = $shims ? 'v4-shims' : 'all'; |
|
190 | + $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
191 | + $type = $this->settings['type']; |
|
192 | + $version = $this->settings['version']; |
|
193 | + $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
194 | + $url = ''; |
|
195 | + |
|
196 | + if ( $type == 'KIT' && $kit_url ) { |
|
197 | + if ( $shims ) { |
|
198 | + // if its a kit then we don't add shims here |
|
199 | + return ''; |
|
200 | + } |
|
201 | + $url .= $kit_url; // CDN |
|
202 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
203 | + } else { |
|
204 | + $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
205 | + $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
206 | + $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
207 | + $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
208 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
209 | + } |
|
210 | + |
|
211 | + return $url; |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
216 | + * |
|
217 | + * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
218 | + * |
|
219 | + * @param $url |
|
220 | + * @param $original_url |
|
221 | + * @param $_context |
|
222 | + * |
|
223 | + * @return string The filtered url. |
|
224 | + */ |
|
225 | + public function remove_font_awesome( $url, $original_url, $_context ) { |
|
226 | + |
|
227 | + if ( $_context == 'display' |
|
228 | + && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
229 | + && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
230 | + ) {// it's a font-awesome-url (probably) |
|
231 | + |
|
232 | + if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
233 | + if ( $this->settings['type'] == 'JS' ) { |
|
234 | + if ( $this->settings['js-pseudo'] ) { |
|
235 | + $url .= "' data-search-pseudo-elements defer='defer"; |
|
236 | + } else { |
|
237 | + $url .= "' defer='defer"; |
|
238 | + } |
|
239 | + } |
|
240 | + } else { |
|
241 | + $url = ''; // removing the url removes the file |
|
242 | + } |
|
243 | + |
|
244 | + } |
|
245 | + |
|
246 | + return $url; |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * Register the database settings with WordPress. |
|
251 | + */ |
|
252 | + public function register_settings() { |
|
253 | + register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
254 | + } |
|
255 | + |
|
256 | + /** |
|
257 | + * Add the WordPress settings menu item. |
|
258 | + * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
259 | + */ |
|
260 | + public function menu_item() { |
|
261 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
262 | + call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
263 | + $this, |
|
264 | + 'settings_page' |
|
265 | + ) ); |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * Get the current Font Awesome output settings. |
|
270 | + * |
|
271 | + * @return array The array of settings. |
|
272 | + */ |
|
273 | + public function get_settings() { |
|
274 | + |
|
275 | + $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
276 | + |
|
277 | + $defaults = array( |
|
278 | + 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
279 | + 'version' => '', // latest |
|
280 | + 'enqueue' => '', // front and backend |
|
281 | + 'shims' => '1', // default on for now, @todo maybe change to off in 2020 |
|
282 | + 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
283 | + 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
284 | + 'pro' => '0', // if pro CDN url should be used |
|
285 | + 'kit-url' => '', // the kit url |
|
286 | + ); |
|
287 | + |
|
288 | + $settings = wp_parse_args( $db_settings, $defaults ); |
|
289 | + |
|
290 | + /** |
|
291 | + * Filter the Font Awesome settings. |
|
292 | + * |
|
293 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
294 | + */ |
|
295 | + return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * The settings page html output. |
|
301 | + */ |
|
302 | + public function settings_page() { |
|
303 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
304 | + wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
305 | + } |
|
306 | + |
|
307 | + // a hidden way to force the update of the verison number vai api instead of waiting the 48 hours |
|
308 | + if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
309 | + $this->get_latest_version( $force_api = true ); |
|
310 | + } |
|
311 | + ?> |
|
312 | 312 | <style> |
313 | 313 | .wpfas-kit-show { |
314 | 314 | display: none; |
@@ -326,10 +326,10 @@ discard block |
||
326 | 326 | <h1><?php echo $this->name; ?></h1> |
327 | 327 | <form method="post" action="options.php"> |
328 | 328 | <?php |
329 | - settings_fields( 'wp-font-awesome-settings' ); |
|
330 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
331 | - $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
|
332 | - ?> |
|
329 | + settings_fields( 'wp-font-awesome-settings' ); |
|
330 | + do_settings_sections( 'wp-font-awesome-settings' ); |
|
331 | + $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
|
332 | + ?> |
|
333 | 333 | <table class="form-table wpfas-table-settings <?php echo esc_attr( $kit_set ); ?>"> |
334 | 334 | <tr valign="top"> |
335 | 335 | <th scope="row"><label |
@@ -355,12 +355,12 @@ discard block |
||
355 | 355 | value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" |
356 | 356 | placeholder="https://kit.fontawesome.com/123abc.js"/> |
357 | 357 | <span><?php |
358 | - echo sprintf( |
|
359 | - __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
360 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
361 | - '</a>' |
|
362 | - ); |
|
363 | - ?></span> |
|
358 | + echo sprintf( |
|
359 | + __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
360 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
361 | + '</a>' |
|
362 | + ); |
|
363 | + ?></span> |
|
364 | 364 | </td> |
365 | 365 | </tr> |
366 | 366 | |
@@ -420,14 +420,14 @@ discard block |
||
420 | 420 | <input type="checkbox" name="wp-font-awesome-settings[pro]" |
421 | 421 | value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro"/> |
422 | 422 | <span><?php |
423 | - echo sprintf( |
|
424 | - __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
425 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>', |
|
426 | - '</a>', |
|
427 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>', |
|
428 | - '</a>' |
|
429 | - ); |
|
430 | - ?></span> |
|
423 | + echo sprintf( |
|
424 | + __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
425 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>', |
|
426 | + '</a>', |
|
427 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>', |
|
428 | + '</a>' |
|
429 | + ); |
|
430 | + ?></span> |
|
431 | 431 | </td> |
432 | 432 | </tr> |
433 | 433 | |
@@ -470,88 +470,88 @@ discard block |
||
470 | 470 | |
471 | 471 | </table> |
472 | 472 | <?php |
473 | - submit_button(); |
|
474 | - ?> |
|
473 | + submit_button(); |
|
474 | + ?> |
|
475 | 475 | </form> |
476 | 476 | |
477 | 477 | <div id="wpfas-version"><?php echo $this->version; ?></div> |
478 | 478 | </div> |
479 | 479 | |
480 | 480 | <?php |
481 | - } |
|
482 | - |
|
483 | - /** |
|
484 | - * Check a version number is valid and if so return it or else return an empty string. |
|
485 | - * |
|
486 | - * @param $version string The version number to check. |
|
487 | - * |
|
488 | - * @since 1.0.6 |
|
489 | - * |
|
490 | - * @return string Either a valid version number or an empty string. |
|
491 | - */ |
|
492 | - public function validate_version_number( $version ) { |
|
493 | - |
|
494 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
495 | - // valid |
|
496 | - } else { |
|
497 | - $version = '';// not validated |
|
498 | - } |
|
499 | - |
|
500 | - return $version; |
|
501 | - } |
|
502 | - |
|
503 | - |
|
504 | - /** |
|
505 | - * Get the latest version of Font Awesome. |
|
506 | - * |
|
507 | - * We check for a cached bersion and if none we will check for a live version via API and then cache it for 48 hours. |
|
508 | - * |
|
509 | - * @since 1.0.7 |
|
510 | - * @return mixed|string The latest version number found. |
|
511 | - */ |
|
512 | - public function get_latest_version( $force_api = false ) { |
|
513 | - $latest_version = $this->latest; |
|
514 | - |
|
515 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
516 | - |
|
517 | - if ( $cache === false || $force_api ) { // its not set |
|
518 | - $api_ver = $this->get_latest_version_from_api(); |
|
519 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
520 | - $latest_version = $api_ver; |
|
521 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
522 | - } |
|
523 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
524 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
525 | - $latest_version = $cache; |
|
526 | - } |
|
527 | - } |
|
528 | - |
|
529 | - return $latest_version; |
|
530 | - } |
|
531 | - |
|
532 | - /** |
|
533 | - * Get the latest Font Awesome version from the github API. |
|
534 | - * |
|
535 | - * @since 1.0.7 |
|
536 | - * @return string The latest version number or `0` on API fail. |
|
537 | - */ |
|
538 | - public function get_latest_version_from_api() { |
|
539 | - $version = "0"; |
|
540 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
541 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
542 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
543 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
544 | - $version = $api_response['tag_name']; |
|
545 | - } |
|
546 | - } |
|
547 | - |
|
548 | - return $version; |
|
549 | - } |
|
550 | - |
|
551 | - } |
|
552 | - |
|
553 | - /** |
|
554 | - * Run the class if found. |
|
555 | - */ |
|
556 | - WP_Font_Awesome_Settings::instance(); |
|
481 | + } |
|
482 | + |
|
483 | + /** |
|
484 | + * Check a version number is valid and if so return it or else return an empty string. |
|
485 | + * |
|
486 | + * @param $version string The version number to check. |
|
487 | + * |
|
488 | + * @since 1.0.6 |
|
489 | + * |
|
490 | + * @return string Either a valid version number or an empty string. |
|
491 | + */ |
|
492 | + public function validate_version_number( $version ) { |
|
493 | + |
|
494 | + if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
495 | + // valid |
|
496 | + } else { |
|
497 | + $version = '';// not validated |
|
498 | + } |
|
499 | + |
|
500 | + return $version; |
|
501 | + } |
|
502 | + |
|
503 | + |
|
504 | + /** |
|
505 | + * Get the latest version of Font Awesome. |
|
506 | + * |
|
507 | + * We check for a cached bersion and if none we will check for a live version via API and then cache it for 48 hours. |
|
508 | + * |
|
509 | + * @since 1.0.7 |
|
510 | + * @return mixed|string The latest version number found. |
|
511 | + */ |
|
512 | + public function get_latest_version( $force_api = false ) { |
|
513 | + $latest_version = $this->latest; |
|
514 | + |
|
515 | + $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
516 | + |
|
517 | + if ( $cache === false || $force_api ) { // its not set |
|
518 | + $api_ver = $this->get_latest_version_from_api(); |
|
519 | + if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
520 | + $latest_version = $api_ver; |
|
521 | + set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
522 | + } |
|
523 | + } elseif ( $this->validate_version_number( $cache ) ) { |
|
524 | + if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
525 | + $latest_version = $cache; |
|
526 | + } |
|
527 | + } |
|
528 | + |
|
529 | + return $latest_version; |
|
530 | + } |
|
531 | + |
|
532 | + /** |
|
533 | + * Get the latest Font Awesome version from the github API. |
|
534 | + * |
|
535 | + * @since 1.0.7 |
|
536 | + * @return string The latest version number or `0` on API fail. |
|
537 | + */ |
|
538 | + public function get_latest_version_from_api() { |
|
539 | + $version = "0"; |
|
540 | + $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
541 | + if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
542 | + $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
543 | + if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
544 | + $version = $api_response['tag_name']; |
|
545 | + } |
|
546 | + } |
|
547 | + |
|
548 | + return $version; |
|
549 | + } |
|
550 | + |
|
551 | + } |
|
552 | + |
|
553 | + /** |
|
554 | + * Run the class if found. |
|
555 | + */ |
|
556 | + WP_Font_Awesome_Settings::instance(); |
|
557 | 557 | } |
558 | 558 | \ No newline at end of file |
@@ -12,14 +12,14 @@ discard block |
||
12 | 12 | /** |
13 | 13 | * Bail if we are not in WP. |
14 | 14 | */ |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if (!defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Only add if the class does not already exist. |
21 | 21 | */ |
22 | -if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
|
22 | +if (!class_exists('WP_Font_Awesome_Settings')) { |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * A Class to be able to change settings for Font Awesome. |
@@ -87,17 +87,17 @@ discard block |
||
87 | 87 | * @return WP_Font_Awesome_Settings - Main instance. |
88 | 88 | */ |
89 | 89 | public static function instance() { |
90 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
90 | + if (!isset(self::$instance) && !(self::$instance instanceof WP_Font_Awesome_Settings)) { |
|
91 | 91 | self::$instance = new WP_Font_Awesome_Settings; |
92 | 92 | |
93 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
93 | + add_action('init', array(self::$instance, 'init')); // set settings |
|
94 | 94 | |
95 | - if ( is_admin() ) { |
|
96 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
97 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
95 | + if (is_admin()) { |
|
96 | + add_action('admin_menu', array(self::$instance, 'menu_item')); |
|
97 | + add_action('admin_init', array(self::$instance, 'register_settings')); |
|
98 | 98 | } |
99 | 99 | |
100 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
100 | + do_action('wp_font_awesome_settings_loaded'); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | return self::$instance; |
@@ -111,30 +111,30 @@ discard block |
||
111 | 111 | public function init() { |
112 | 112 | $this->settings = $this->get_settings(); |
113 | 113 | |
114 | - if ( $this->settings['type'] == 'CSS' ) { |
|
114 | + if ($this->settings['type'] == 'CSS') { |
|
115 | 115 | |
116 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
117 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
116 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
117 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_style'), 5000); |
|
118 | 118 | } |
119 | 119 | |
120 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
121 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
120 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') { |
|
121 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_style'), 5000); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | } else { |
125 | 125 | |
126 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
127 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
126 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
127 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); |
|
128 | 128 | } |
129 | 129 | |
130 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
131 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
130 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') { |
|
131 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); |
|
132 | 132 | } |
133 | 133 | } |
134 | 134 | |
135 | 135 | // remove font awesome if set to do so |
136 | - if ( $this->settings['dequeue'] == '1' ) { |
|
137 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
136 | + if ($this->settings['dequeue'] == '1') { |
|
137 | + add_action('clean_url', array($this, 'remove_font_awesome'), 5000, 3); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | } |
@@ -146,15 +146,15 @@ discard block |
||
146 | 146 | // build url |
147 | 147 | $url = $this->get_url(); |
148 | 148 | |
149 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
150 | - wp_register_style( 'font-awesome', $url, array(), null ); |
|
151 | - wp_enqueue_style( 'font-awesome' ); |
|
149 | + wp_deregister_style('font-awesome'); // deregister in case its already there |
|
150 | + wp_register_style('font-awesome', $url, array(), null); |
|
151 | + wp_enqueue_style('font-awesome'); |
|
152 | 152 | |
153 | - if ( $this->settings['shims'] ) { |
|
154 | - $url = $this->get_url( true ); |
|
155 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
156 | - wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
157 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
153 | + if ($this->settings['shims']) { |
|
154 | + $url = $this->get_url(true); |
|
155 | + wp_deregister_style('font-awesome-shims'); // deregister in case its already there |
|
156 | + wp_register_style('font-awesome-shims', $url, array(), null); |
|
157 | + wp_enqueue_style('font-awesome-shims'); |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | |
@@ -166,15 +166,15 @@ discard block |
||
166 | 166 | $url = $this->get_url(); |
167 | 167 | |
168 | 168 | $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
169 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
170 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
171 | - wp_enqueue_script( 'font-awesome' ); |
|
172 | - |
|
173 | - if ( $this->settings['shims'] ) { |
|
174 | - $url = $this->get_url( true ); |
|
175 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
176 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
177 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
169 | + call_user_func($deregister_function, 'font-awesome'); // deregister in case its already there |
|
170 | + wp_register_script('font-awesome', $url, array(), null); |
|
171 | + wp_enqueue_script('font-awesome'); |
|
172 | + |
|
173 | + if ($this->settings['shims']) { |
|
174 | + $url = $this->get_url(true); |
|
175 | + call_user_func($deregister_function, 'font-awesome-shims'); // deregister in case its already there |
|
176 | + wp_register_script('font-awesome-shims', $url, array(), null); |
|
177 | + wp_enqueue_script('font-awesome-shims'); |
|
178 | 178 | } |
179 | 179 | } |
180 | 180 | |
@@ -185,16 +185,16 @@ discard block |
||
185 | 185 | * |
186 | 186 | * @return string The url to the file. |
187 | 187 | */ |
188 | - public function get_url( $shims = false ) { |
|
188 | + public function get_url($shims = false) { |
|
189 | 189 | $script = $shims ? 'v4-shims' : 'all'; |
190 | 190 | $sub = $this->settings['pro'] ? 'pro' : 'use'; |
191 | 191 | $type = $this->settings['type']; |
192 | 192 | $version = $this->settings['version']; |
193 | - $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
193 | + $kit_url = $this->settings['kit-url'] ? esc_url($this->settings['kit-url']) : ''; |
|
194 | 194 | $url = ''; |
195 | 195 | |
196 | - if ( $type == 'KIT' && $kit_url ) { |
|
197 | - if ( $shims ) { |
|
196 | + if ($type == 'KIT' && $kit_url) { |
|
197 | + if ($shims) { |
|
198 | 198 | // if its a kit then we don't add shims here |
199 | 199 | return ''; |
200 | 200 | } |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | $url .= "?wpfas=true"; // set our var so our version is not removed |
203 | 203 | } else { |
204 | 204 | $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
205 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
205 | + $url .= !empty($version) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
206 | 206 | $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
207 | 207 | $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
208 | 208 | $url .= "?wpfas=true"; // set our var so our version is not removed |
@@ -222,16 +222,16 @@ discard block |
||
222 | 222 | * |
223 | 223 | * @return string The filtered url. |
224 | 224 | */ |
225 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
225 | + public function remove_font_awesome($url, $original_url, $_context) { |
|
226 | 226 | |
227 | - if ( $_context == 'display' |
|
228 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
229 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
227 | + if ($_context == 'display' |
|
228 | + && (strstr($url, "fontawesome") !== false || strstr($url, "font-awesome") !== false) |
|
229 | + && (strstr($url, ".js") !== false || strstr($url, ".css") !== false) |
|
230 | 230 | ) {// it's a font-awesome-url (probably) |
231 | 231 | |
232 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
233 | - if ( $this->settings['type'] == 'JS' ) { |
|
234 | - if ( $this->settings['js-pseudo'] ) { |
|
232 | + if (strstr($url, "wpfas=true") !== false) { |
|
233 | + if ($this->settings['type'] == 'JS') { |
|
234 | + if ($this->settings['js-pseudo']) { |
|
235 | 235 | $url .= "' data-search-pseudo-elements defer='defer"; |
236 | 236 | } else { |
237 | 237 | $url .= "' defer='defer"; |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | * Register the database settings with WordPress. |
251 | 251 | */ |
252 | 252 | public function register_settings() { |
253 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
253 | + register_setting('wp-font-awesome-settings', 'wp-font-awesome-settings'); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | /** |
@@ -259,10 +259,10 @@ discard block |
||
259 | 259 | */ |
260 | 260 | public function menu_item() { |
261 | 261 | $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
262 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
262 | + call_user_func($menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
263 | 263 | $this, |
264 | 264 | 'settings_page' |
265 | - ) ); |
|
265 | + )); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | */ |
273 | 273 | public function get_settings() { |
274 | 274 | |
275 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
275 | + $db_settings = get_option('wp-font-awesome-settings'); |
|
276 | 276 | |
277 | 277 | $defaults = array( |
278 | 278 | 'type' => 'CSS', // type to use, CSS or JS or KIT |
@@ -285,14 +285,14 @@ discard block |
||
285 | 285 | 'kit-url' => '', // the kit url |
286 | 286 | ); |
287 | 287 | |
288 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
288 | + $settings = wp_parse_args($db_settings, $defaults); |
|
289 | 289 | |
290 | 290 | /** |
291 | 291 | * Filter the Font Awesome settings. |
292 | 292 | * |
293 | 293 | * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
294 | 294 | */ |
295 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
295 | + return $this->settings = apply_filters('wp-font-awesome-settings', $settings, $db_settings, $defaults); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | |
@@ -300,13 +300,13 @@ discard block |
||
300 | 300 | * The settings page html output. |
301 | 301 | */ |
302 | 302 | public function settings_page() { |
303 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
304 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
303 | + if (!current_user_can('manage_options')) { |
|
304 | + wp_die(__('You do not have sufficient permissions to access this page.', 'font-awesome-settings')); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | // a hidden way to force the update of the verison number vai api instead of waiting the 48 hours |
308 | - if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
309 | - $this->get_latest_version( $force_api = true ); |
|
308 | + if (isset($_REQUEST['force-version-check'])) { |
|
309 | + $this->get_latest_version($force_api = true); |
|
310 | 310 | } |
311 | 311 | ?> |
312 | 312 | <style> |
@@ -326,37 +326,37 @@ discard block |
||
326 | 326 | <h1><?php echo $this->name; ?></h1> |
327 | 327 | <form method="post" action="options.php"> |
328 | 328 | <?php |
329 | - settings_fields( 'wp-font-awesome-settings' ); |
|
330 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
329 | + settings_fields('wp-font-awesome-settings'); |
|
330 | + do_settings_sections('wp-font-awesome-settings'); |
|
331 | 331 | $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
332 | 332 | ?> |
333 | - <table class="form-table wpfas-table-settings <?php echo esc_attr( $kit_set ); ?>"> |
|
333 | + <table class="form-table wpfas-table-settings <?php echo esc_attr($kit_set); ?>"> |
|
334 | 334 | <tr valign="top"> |
335 | 335 | <th scope="row"><label |
336 | - for="wpfas-type"><?php _e( 'Type', 'font-awesome-settings' ); ?></label></th> |
|
336 | + for="wpfas-type"><?php _e('Type', 'font-awesome-settings'); ?></label></th> |
|
337 | 337 | <td> |
338 | 338 | <select name="wp-font-awesome-settings[type]" id="wpfas-type" |
339 | 339 | onchange="if(this.value=='KIT'){jQuery('.wpfas-table-settings').addClass('wpfas-kit-set');}else{jQuery('.wpfas-table-settings').removeClass('wpfas-kit-set');}"> |
340 | 340 | <option |
341 | - value="CSS" <?php selected( $this->settings['type'], 'CSS' ); ?>><?php _e( 'CSS (default)', 'font-awesome-settings' ); ?></option> |
|
342 | - <option value="JS" <?php selected( $this->settings['type'], 'JS' ); ?>>JS</option> |
|
341 | + value="CSS" <?php selected($this->settings['type'], 'CSS'); ?>><?php _e('CSS (default)', 'font-awesome-settings'); ?></option> |
|
342 | + <option value="JS" <?php selected($this->settings['type'], 'JS'); ?>>JS</option> |
|
343 | 343 | <option |
344 | - value="KIT" <?php selected( $this->settings['type'], 'KIT' ); ?>><?php _e( 'Kits (settings managed on fontawesome.com)', 'font-awesome-settings' ); ?></option> |
|
344 | + value="KIT" <?php selected($this->settings['type'], 'KIT'); ?>><?php _e('Kits (settings managed on fontawesome.com)', 'font-awesome-settings'); ?></option> |
|
345 | 345 | </select> |
346 | 346 | </td> |
347 | 347 | </tr> |
348 | 348 | |
349 | 349 | <tr valign="top" class="wpfas-kit-show"> |
350 | 350 | <th scope="row"><label |
351 | - for="wpfas-kit-url"><?php _e( 'Kit URL', 'font-awesome-settings' ); ?></label></th> |
|
351 | + for="wpfas-kit-url"><?php _e('Kit URL', 'font-awesome-settings'); ?></label></th> |
|
352 | 352 | <td> |
353 | 353 | <input class="regular-text" id="wpfas-kit-url" type="url" |
354 | 354 | name="wp-font-awesome-settings[kit-url]" |
355 | - value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" |
|
355 | + value="<?php echo esc_attr($this->settings['kit-url']); ?>" |
|
356 | 356 | placeholder="https://kit.fontawesome.com/123abc.js"/> |
357 | 357 | <span><?php |
358 | 358 | echo sprintf( |
359 | - __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
359 | + __('Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings'), |
|
360 | 360 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
361 | 361 | '</a>' |
362 | 362 | ); |
@@ -366,31 +366,31 @@ discard block |
||
366 | 366 | |
367 | 367 | <tr valign="top" class="wpfas-kit-hide"> |
368 | 368 | <th scope="row"><label |
369 | - for="wpfas-version"><?php _e( 'Version', 'font-awesome-settings' ); ?></label></th> |
|
369 | + for="wpfas-version"><?php _e('Version', 'font-awesome-settings'); ?></label></th> |
|
370 | 370 | <td> |
371 | 371 | <select name="wp-font-awesome-settings[version]" id="wpfas-version"> |
372 | 372 | <option |
373 | - value="" <?php selected( $this->settings['version'], '' ); ?>><?php echo sprintf( __( 'Latest - %s (default)', 'font-awesome-settings' ), $this->get_latest_version() ); ?> |
|
373 | + value="" <?php selected($this->settings['version'], ''); ?>><?php echo sprintf(__('Latest - %s (default)', 'font-awesome-settings'), $this->get_latest_version()); ?> |
|
374 | 374 | </option> |
375 | - <option value="5.6.0" <?php selected( $this->settings['version'], '5.6.0' ); ?>> |
|
375 | + <option value="5.6.0" <?php selected($this->settings['version'], '5.6.0'); ?>> |
|
376 | 376 | 5.6.0 |
377 | 377 | </option> |
378 | - <option value="5.5.0" <?php selected( $this->settings['version'], '5.5.0' ); ?>> |
|
378 | + <option value="5.5.0" <?php selected($this->settings['version'], '5.5.0'); ?>> |
|
379 | 379 | 5.5.0 |
380 | 380 | </option> |
381 | - <option value="5.4.0" <?php selected( $this->settings['version'], '5.4.0' ); ?>> |
|
381 | + <option value="5.4.0" <?php selected($this->settings['version'], '5.4.0'); ?>> |
|
382 | 382 | 5.4.0 |
383 | 383 | </option> |
384 | - <option value="5.3.0" <?php selected( $this->settings['version'], '5.3.0' ); ?>> |
|
384 | + <option value="5.3.0" <?php selected($this->settings['version'], '5.3.0'); ?>> |
|
385 | 385 | 5.3.0 |
386 | 386 | </option> |
387 | - <option value="5.2.0" <?php selected( $this->settings['version'], '5.2.0' ); ?>> |
|
387 | + <option value="5.2.0" <?php selected($this->settings['version'], '5.2.0'); ?>> |
|
388 | 388 | 5.2.0 |
389 | 389 | </option> |
390 | - <option value="5.1.0" <?php selected( $this->settings['version'], '5.1.0' ); ?>> |
|
390 | + <option value="5.1.0" <?php selected($this->settings['version'], '5.1.0'); ?>> |
|
391 | 391 | 5.1.0 |
392 | 392 | </option> |
393 | - <option value="4.7.0" <?php selected( $this->settings['version'], '4.7.0' ); ?>> |
|
393 | + <option value="4.7.0" <?php selected($this->settings['version'], '4.7.0'); ?>> |
|
394 | 394 | 4.7.1 (CSS only) |
395 | 395 | </option> |
396 | 396 | </select> |
@@ -399,29 +399,29 @@ discard block |
||
399 | 399 | |
400 | 400 | <tr valign="top"> |
401 | 401 | <th scope="row"><label |
402 | - for="wpfas-enqueue"><?php _e( 'Enqueue', 'font-awesome-settings' ); ?></label></th> |
|
402 | + for="wpfas-enqueue"><?php _e('Enqueue', 'font-awesome-settings'); ?></label></th> |
|
403 | 403 | <td> |
404 | 404 | <select name="wp-font-awesome-settings[enqueue]" id="wpfas-enqueue"> |
405 | 405 | <option |
406 | - value="" <?php selected( $this->settings['enqueue'], '' ); ?>><?php _e( 'Frontend + Backend (default)', 'font-awesome-settings' ); ?></option> |
|
406 | + value="" <?php selected($this->settings['enqueue'], ''); ?>><?php _e('Frontend + Backend (default)', 'font-awesome-settings'); ?></option> |
|
407 | 407 | <option |
408 | - value="frontend" <?php selected( $this->settings['enqueue'], 'frontend' ); ?>><?php _e( 'Frontend', 'font-awesome-settings' ); ?></option> |
|
408 | + value="frontend" <?php selected($this->settings['enqueue'], 'frontend'); ?>><?php _e('Frontend', 'font-awesome-settings'); ?></option> |
|
409 | 409 | <option |
410 | - value="backend" <?php selected( $this->settings['enqueue'], 'backend' ); ?>><?php _e( 'Backend', 'font-awesome-settings' ); ?></option> |
|
410 | + value="backend" <?php selected($this->settings['enqueue'], 'backend'); ?>><?php _e('Backend', 'font-awesome-settings'); ?></option> |
|
411 | 411 | </select> |
412 | 412 | </td> |
413 | 413 | </tr> |
414 | 414 | |
415 | 415 | <tr valign="top" class="wpfas-kit-hide"> |
416 | 416 | <th scope="row"><label |
417 | - for="wpfas-pro"><?php _e( 'Enable pro', 'font-awesome-settings' ); ?></label></th> |
|
417 | + for="wpfas-pro"><?php _e('Enable pro', 'font-awesome-settings'); ?></label></th> |
|
418 | 418 | <td> |
419 | 419 | <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/> |
420 | 420 | <input type="checkbox" name="wp-font-awesome-settings[pro]" |
421 | - value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro"/> |
|
421 | + value="1" <?php checked($this->settings['pro'], '1'); ?> id="wpfas-pro"/> |
|
422 | 422 | <span><?php |
423 | 423 | echo sprintf( |
424 | - __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
424 | + __('Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings'), |
|
425 | 425 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>', |
426 | 426 | '</a>', |
427 | 427 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>', |
@@ -433,38 +433,38 @@ discard block |
||
433 | 433 | |
434 | 434 | <tr valign="top" class="wpfas-kit-hide"> |
435 | 435 | <th scope="row"><label |
436 | - for="wpfas-shims"><?php _e( 'Enable v4 shims compatibility', 'font-awesome-settings' ); ?></label> |
|
436 | + for="wpfas-shims"><?php _e('Enable v4 shims compatibility', 'font-awesome-settings'); ?></label> |
|
437 | 437 | </th> |
438 | 438 | <td> |
439 | 439 | <input type="hidden" name="wp-font-awesome-settings[shims]" value="0"/> |
440 | 440 | <input type="checkbox" name="wp-font-awesome-settings[shims]" |
441 | - value="1" <?php checked( $this->settings['shims'], '1' ); ?> id="wpfas-shims"/> |
|
442 | - <span><?php _e( 'This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'font-awesome-settings' ); ?></span> |
|
441 | + value="1" <?php checked($this->settings['shims'], '1'); ?> id="wpfas-shims"/> |
|
442 | + <span><?php _e('This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'font-awesome-settings'); ?></span> |
|
443 | 443 | </td> |
444 | 444 | </tr> |
445 | 445 | |
446 | 446 | <tr valign="top" class="wpfas-kit-hide"> |
447 | 447 | <th scope="row"><label |
448 | - for="wpfas-js-pseudo"><?php _e( 'Enable JS pseudo elements (not recommended)', 'font-awesome-settings' ); ?></label> |
|
448 | + for="wpfas-js-pseudo"><?php _e('Enable JS pseudo elements (not recommended)', 'font-awesome-settings'); ?></label> |
|
449 | 449 | </th> |
450 | 450 | <td> |
451 | 451 | <input type="hidden" name="wp-font-awesome-settings[js-pseudo]" value="0"/> |
452 | 452 | <input type="checkbox" name="wp-font-awesome-settings[js-pseudo]" |
453 | - value="1" <?php checked( $this->settings['js-pseudo'], '1' ); ?> |
|
453 | + value="1" <?php checked($this->settings['js-pseudo'], '1'); ?> |
|
454 | 454 | id="wpfas-js-pseudo"/> |
455 | - <span><?php _e( 'Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'font-awesome-settings' ); ?></span> |
|
455 | + <span><?php _e('Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'font-awesome-settings'); ?></span> |
|
456 | 456 | </td> |
457 | 457 | </tr> |
458 | 458 | |
459 | 459 | <tr valign="top"> |
460 | 460 | <th scope="row"><label |
461 | - for="wpfas-dequeue"><?php _e( 'Dequeue', 'font-awesome-settings' ); ?></label></th> |
|
461 | + for="wpfas-dequeue"><?php _e('Dequeue', 'font-awesome-settings'); ?></label></th> |
|
462 | 462 | <td> |
463 | 463 | <input type="hidden" name="wp-font-awesome-settings[dequeue]" value="0"/> |
464 | 464 | <input type="checkbox" name="wp-font-awesome-settings[dequeue]" |
465 | - value="1" <?php checked( $this->settings['dequeue'], '1' ); ?> |
|
465 | + value="1" <?php checked($this->settings['dequeue'], '1'); ?> |
|
466 | 466 | id="wpfas-dequeue"/> |
467 | - <span><?php _e( 'This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'font-awesome-settings' ); ?></span> |
|
467 | + <span><?php _e('This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'font-awesome-settings'); ?></span> |
|
468 | 468 | </td> |
469 | 469 | </tr> |
470 | 470 | |
@@ -489,12 +489,12 @@ discard block |
||
489 | 489 | * |
490 | 490 | * @return string Either a valid version number or an empty string. |
491 | 491 | */ |
492 | - public function validate_version_number( $version ) { |
|
492 | + public function validate_version_number($version) { |
|
493 | 493 | |
494 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
494 | + if (version_compare($version, '0.0.1', '>=') >= 0) { |
|
495 | 495 | // valid |
496 | 496 | } else { |
497 | - $version = '';// not validated |
|
497 | + $version = ''; // not validated |
|
498 | 498 | } |
499 | 499 | |
500 | 500 | return $version; |
@@ -509,19 +509,19 @@ discard block |
||
509 | 509 | * @since 1.0.7 |
510 | 510 | * @return mixed|string The latest version number found. |
511 | 511 | */ |
512 | - public function get_latest_version( $force_api = false ) { |
|
512 | + public function get_latest_version($force_api = false) { |
|
513 | 513 | $latest_version = $this->latest; |
514 | 514 | |
515 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
515 | + $cache = get_transient('wp-font-awesome-settings-version'); |
|
516 | 516 | |
517 | - if ( $cache === false || $force_api ) { // its not set |
|
517 | + if ($cache === false || $force_api) { // its not set |
|
518 | 518 | $api_ver = $this->get_latest_version_from_api(); |
519 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
519 | + if (version_compare($api_ver, $this->latest, '>=') >= 0) { |
|
520 | 520 | $latest_version = $api_ver; |
521 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
521 | + set_transient('wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS); |
|
522 | 522 | } |
523 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
524 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
523 | + } elseif ($this->validate_version_number($cache)) { |
|
524 | + if (version_compare($cache, $this->latest, '>=') >= 0) { |
|
525 | 525 | $latest_version = $cache; |
526 | 526 | } |
527 | 527 | } |
@@ -537,10 +537,10 @@ discard block |
||
537 | 537 | */ |
538 | 538 | public function get_latest_version_from_api() { |
539 | 539 | $version = "0"; |
540 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
541 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
542 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
543 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
540 | + $response = wp_remote_get("https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest"); |
|
541 | + if (!is_wp_error($response) && is_array($response)) { |
|
542 | + $api_response = json_decode(wp_remote_retrieve_body($response), true); |
|
543 | + if (isset($api_response['tag_name']) && version_compare($api_response['tag_name'], $this->latest, '>=') >= 0 && empty($api_response['prerelease'])) { |
|
544 | 544 | $version = $api_response['tag_name']; |
545 | 545 | } |
546 | 546 | } |
@@ -130,6 +130,10 @@ discard block |
||
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
133 | + /** |
|
134 | + * @param string $name |
|
135 | + * @param string $value |
|
136 | + */ |
|
133 | 137 | public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){ |
134 | 138 | if ( ! headers_sent() ) { |
135 | 139 | setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure ) ); |
@@ -274,7 +278,7 @@ discard block |
||
274 | 278 | * When a user is logged out, ensure they have a unique nonce by using the customer/session ID. |
275 | 279 | * |
276 | 280 | * @param int $uid User ID. |
277 | - * @return string |
|
281 | + * @return integer |
|
278 | 282 | */ |
279 | 283 | public function nonce_user_logged_out( $uid ) { |
280 | 284 | return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid; |
@@ -12,124 +12,124 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class WPInv_Session_Handler extends WPInv_Session { |
14 | 14 | |
15 | - /** |
|
16 | - * Cookie name used for the session. |
|
17 | - * |
|
18 | - * @var string cookie name |
|
19 | - */ |
|
20 | - protected $_cookie; |
|
21 | - |
|
22 | - /** |
|
23 | - * Stores session expiry. |
|
24 | - * |
|
25 | - * @var int session due to expire timestamp |
|
26 | - */ |
|
27 | - protected $_session_expiring; |
|
28 | - |
|
29 | - /** |
|
30 | - * Stores session due to expire timestamp. |
|
31 | - * |
|
32 | - * @var string session expiration timestamp |
|
33 | - */ |
|
34 | - protected $_session_expiration; |
|
35 | - |
|
36 | - /** |
|
37 | - * True when the cookie exists. |
|
38 | - * |
|
39 | - * @var bool Based on whether a cookie exists. |
|
40 | - */ |
|
41 | - protected $_has_cookie = false; |
|
42 | - |
|
43 | - /** |
|
44 | - * Table name for session data. |
|
45 | - * |
|
46 | - * @var string Custom session table name |
|
47 | - */ |
|
48 | - protected $_table; |
|
49 | - |
|
50 | - /** |
|
51 | - * Constructor for the session class. |
|
52 | - */ |
|
53 | - public function __construct() { |
|
54 | - |
|
55 | - $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH ); |
|
15 | + /** |
|
16 | + * Cookie name used for the session. |
|
17 | + * |
|
18 | + * @var string cookie name |
|
19 | + */ |
|
20 | + protected $_cookie; |
|
21 | + |
|
22 | + /** |
|
23 | + * Stores session expiry. |
|
24 | + * |
|
25 | + * @var int session due to expire timestamp |
|
26 | + */ |
|
27 | + protected $_session_expiring; |
|
28 | + |
|
29 | + /** |
|
30 | + * Stores session due to expire timestamp. |
|
31 | + * |
|
32 | + * @var string session expiration timestamp |
|
33 | + */ |
|
34 | + protected $_session_expiration; |
|
35 | + |
|
36 | + /** |
|
37 | + * True when the cookie exists. |
|
38 | + * |
|
39 | + * @var bool Based on whether a cookie exists. |
|
40 | + */ |
|
41 | + protected $_has_cookie = false; |
|
42 | + |
|
43 | + /** |
|
44 | + * Table name for session data. |
|
45 | + * |
|
46 | + * @var string Custom session table name |
|
47 | + */ |
|
48 | + protected $_table; |
|
49 | + |
|
50 | + /** |
|
51 | + * Constructor for the session class. |
|
52 | + */ |
|
53 | + public function __construct() { |
|
54 | + |
|
55 | + $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH ); |
|
56 | 56 | add_action( 'init', array( $this, 'init' ), -1 ); |
57 | - add_action( 'wp_logout', array( $this, 'destroy_session' ) ); |
|
58 | - add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 ); |
|
59 | - add_action( 'shutdown', array( $this, 'save_data' ), 20 ); |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Init hooks and session data. |
|
64 | - * |
|
65 | - * @since 3.3.0 |
|
66 | - */ |
|
67 | - public function init() { |
|
68 | - $this->init_session_cookie(); |
|
69 | - |
|
70 | - if ( ! is_user_logged_in() ) { |
|
71 | - add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) ); |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Setup cookie and customer ID. |
|
77 | - * |
|
78 | - * @since 3.6.0 |
|
79 | - */ |
|
80 | - public function init_session_cookie() { |
|
81 | - $cookie = $this->get_session_cookie(); |
|
82 | - |
|
83 | - if ( $cookie ) { |
|
84 | - $this->_customer_id = $cookie[0]; |
|
85 | - $this->_session_expiration = $cookie[1]; |
|
86 | - $this->_session_expiring = $cookie[2]; |
|
87 | - $this->_has_cookie = true; |
|
88 | - $this->_data = $this->get_session_data(); |
|
89 | - |
|
90 | - // If the user logs in, update session. |
|
91 | - if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) { |
|
92 | - $this->_customer_id = get_current_user_id(); |
|
93 | - $this->_dirty = true; |
|
94 | - $this->save_data(); |
|
95 | - $this->set_customer_session_cookie( true ); |
|
96 | - } |
|
97 | - |
|
98 | - // Update session if its close to expiring. |
|
99 | - if ( time() > $this->_session_expiring ) { |
|
100 | - $this->set_session_expiration(); |
|
101 | - $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration ); |
|
102 | - } |
|
103 | - } else { |
|
104 | - $this->set_session_expiration(); |
|
105 | - $this->_customer_id = $this->generate_customer_id(); |
|
106 | - $this->_data = $this->get_session_data(); |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Sets the session cookie on-demand (usually after adding an item to the cart). |
|
112 | - * |
|
113 | - * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set. |
|
114 | - * |
|
115 | - * Warning: Cookies will only be set if this is called before the headers are sent. |
|
116 | - * |
|
117 | - * @param bool $set Should the session cookie be set. |
|
118 | - */ |
|
119 | - public function set_customer_session_cookie( $set ) { |
|
120 | - if ( $set ) { |
|
121 | - $to_hash = $this->_customer_id . '|' . $this->_session_expiration; |
|
122 | - $cookie_hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
123 | - $cookie_value = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash; |
|
124 | - $this->_has_cookie = true; |
|
125 | - |
|
126 | - if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) { |
|
127 | - $this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true ); |
|
128 | - } |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){ |
|
57 | + add_action( 'wp_logout', array( $this, 'destroy_session' ) ); |
|
58 | + add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 ); |
|
59 | + add_action( 'shutdown', array( $this, 'save_data' ), 20 ); |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Init hooks and session data. |
|
64 | + * |
|
65 | + * @since 3.3.0 |
|
66 | + */ |
|
67 | + public function init() { |
|
68 | + $this->init_session_cookie(); |
|
69 | + |
|
70 | + if ( ! is_user_logged_in() ) { |
|
71 | + add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) ); |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Setup cookie and customer ID. |
|
77 | + * |
|
78 | + * @since 3.6.0 |
|
79 | + */ |
|
80 | + public function init_session_cookie() { |
|
81 | + $cookie = $this->get_session_cookie(); |
|
82 | + |
|
83 | + if ( $cookie ) { |
|
84 | + $this->_customer_id = $cookie[0]; |
|
85 | + $this->_session_expiration = $cookie[1]; |
|
86 | + $this->_session_expiring = $cookie[2]; |
|
87 | + $this->_has_cookie = true; |
|
88 | + $this->_data = $this->get_session_data(); |
|
89 | + |
|
90 | + // If the user logs in, update session. |
|
91 | + if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) { |
|
92 | + $this->_customer_id = get_current_user_id(); |
|
93 | + $this->_dirty = true; |
|
94 | + $this->save_data(); |
|
95 | + $this->set_customer_session_cookie( true ); |
|
96 | + } |
|
97 | + |
|
98 | + // Update session if its close to expiring. |
|
99 | + if ( time() > $this->_session_expiring ) { |
|
100 | + $this->set_session_expiration(); |
|
101 | + $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration ); |
|
102 | + } |
|
103 | + } else { |
|
104 | + $this->set_session_expiration(); |
|
105 | + $this->_customer_id = $this->generate_customer_id(); |
|
106 | + $this->_data = $this->get_session_data(); |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Sets the session cookie on-demand (usually after adding an item to the cart). |
|
112 | + * |
|
113 | + * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set. |
|
114 | + * |
|
115 | + * Warning: Cookies will only be set if this is called before the headers are sent. |
|
116 | + * |
|
117 | + * @param bool $set Should the session cookie be set. |
|
118 | + */ |
|
119 | + public function set_customer_session_cookie( $set ) { |
|
120 | + if ( $set ) { |
|
121 | + $to_hash = $this->_customer_id . '|' . $this->_session_expiration; |
|
122 | + $cookie_hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
123 | + $cookie_value = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash; |
|
124 | + $this->_has_cookie = true; |
|
125 | + |
|
126 | + if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) { |
|
127 | + $this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true ); |
|
128 | + } |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){ |
|
133 | 133 | if ( ! headers_sent() ) { |
134 | 134 | setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure ) ); |
135 | 135 | } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
@@ -138,96 +138,96 @@ discard block |
||
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
141 | - /** |
|
142 | - * Should the session cookie be secure? |
|
143 | - * |
|
144 | - * @since 3.6.0 |
|
145 | - * @return bool |
|
146 | - */ |
|
147 | - protected function use_secure_cookie() { |
|
141 | + /** |
|
142 | + * Should the session cookie be secure? |
|
143 | + * |
|
144 | + * @since 3.6.0 |
|
145 | + * @return bool |
|
146 | + */ |
|
147 | + protected function use_secure_cookie() { |
|
148 | 148 | $is_https = false !== strstr( get_option( 'home' ), 'https:' ); |
149 | - return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() ); |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Return true if the current user has an active session, i.e. a cookie to retrieve values. |
|
154 | - * |
|
155 | - * @return bool |
|
156 | - */ |
|
157 | - public function has_session() { |
|
158 | - return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * Set session expiration. |
|
163 | - */ |
|
164 | - public function set_session_expiration() { |
|
165 | - $this->_session_expiring = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours. |
|
166 | - $this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours. |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Generate a unique customer ID for guests, or return user ID if logged in. |
|
171 | - * |
|
172 | - * Uses Portable PHP password hashing framework to generate a unique cryptographically strong ID. |
|
173 | - * |
|
174 | - * @return string |
|
175 | - */ |
|
176 | - public function generate_customer_id() { |
|
177 | - $customer_id = ''; |
|
178 | - |
|
179 | - if ( is_user_logged_in() ) { |
|
180 | - $customer_id = get_current_user_id(); |
|
181 | - } |
|
182 | - |
|
183 | - if ( empty( $customer_id ) ) { |
|
149 | + return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() ); |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Return true if the current user has an active session, i.e. a cookie to retrieve values. |
|
154 | + * |
|
155 | + * @return bool |
|
156 | + */ |
|
157 | + public function has_session() { |
|
158 | + return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * Set session expiration. |
|
163 | + */ |
|
164 | + public function set_session_expiration() { |
|
165 | + $this->_session_expiring = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours. |
|
166 | + $this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours. |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Generate a unique customer ID for guests, or return user ID if logged in. |
|
171 | + * |
|
172 | + * Uses Portable PHP password hashing framework to generate a unique cryptographically strong ID. |
|
173 | + * |
|
174 | + * @return string |
|
175 | + */ |
|
176 | + public function generate_customer_id() { |
|
177 | + $customer_id = ''; |
|
178 | + |
|
179 | + if ( is_user_logged_in() ) { |
|
180 | + $customer_id = get_current_user_id(); |
|
181 | + } |
|
182 | + |
|
183 | + if ( empty( $customer_id ) ) { |
|
184 | 184 | $customer_id = wp_create_nonce('wpinv-session-customer-id'); |
185 | - } |
|
186 | - |
|
187 | - return $customer_id; |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Get the session cookie, if set. Otherwise return false. |
|
192 | - * |
|
193 | - * Session cookies without a customer ID are invalid. |
|
194 | - * |
|
195 | - * @return bool|array |
|
196 | - */ |
|
197 | - public function get_session_cookie() { |
|
198 | - $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine. |
|
199 | - |
|
200 | - if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) { |
|
201 | - return false; |
|
202 | - } |
|
203 | - |
|
204 | - list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value ); |
|
205 | - |
|
206 | - if ( empty( $customer_id ) ) { |
|
207 | - return false; |
|
208 | - } |
|
209 | - |
|
210 | - // Validate hash. |
|
211 | - $to_hash = $customer_id . '|' . $session_expiration; |
|
212 | - $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
213 | - |
|
214 | - if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) { |
|
215 | - return false; |
|
216 | - } |
|
217 | - |
|
218 | - return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash ); |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Get session data. |
|
223 | - * |
|
224 | - * @return array |
|
225 | - */ |
|
226 | - public function get_session_data() { |
|
227 | - return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array(); |
|
228 | - } |
|
229 | - |
|
230 | - public function generate_key($customer_id){ |
|
185 | + } |
|
186 | + |
|
187 | + return $customer_id; |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Get the session cookie, if set. Otherwise return false. |
|
192 | + * |
|
193 | + * Session cookies without a customer ID are invalid. |
|
194 | + * |
|
195 | + * @return bool|array |
|
196 | + */ |
|
197 | + public function get_session_cookie() { |
|
198 | + $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine. |
|
199 | + |
|
200 | + if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) { |
|
201 | + return false; |
|
202 | + } |
|
203 | + |
|
204 | + list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value ); |
|
205 | + |
|
206 | + if ( empty( $customer_id ) ) { |
|
207 | + return false; |
|
208 | + } |
|
209 | + |
|
210 | + // Validate hash. |
|
211 | + $to_hash = $customer_id . '|' . $session_expiration; |
|
212 | + $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
213 | + |
|
214 | + if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) { |
|
215 | + return false; |
|
216 | + } |
|
217 | + |
|
218 | + return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash ); |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Get session data. |
|
223 | + * |
|
224 | + * @return array |
|
225 | + */ |
|
226 | + public function get_session_data() { |
|
227 | + return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array(); |
|
228 | + } |
|
229 | + |
|
230 | + public function generate_key($customer_id){ |
|
231 | 231 | if(!$customer_id){ |
232 | 232 | return; |
233 | 233 | } |
@@ -235,62 +235,62 @@ discard block |
||
235 | 235 | return 'wpi_trans_'.$customer_id; |
236 | 236 | } |
237 | 237 | |
238 | - /** |
|
239 | - * Save data. |
|
240 | - */ |
|
241 | - public function save_data() { |
|
242 | - // Dirty if something changed - prevents saving nothing new. |
|
243 | - if ( $this->_dirty && $this->has_session() ) { |
|
238 | + /** |
|
239 | + * Save data. |
|
240 | + */ |
|
241 | + public function save_data() { |
|
242 | + // Dirty if something changed - prevents saving nothing new. |
|
243 | + if ( $this->_dirty && $this->has_session() ) { |
|
244 | 244 | |
245 | 245 | set_transient( $this->generate_key($this->_customer_id), $this->_data, $this->_session_expiration); |
246 | 246 | |
247 | - $this->_dirty = false; |
|
248 | - } |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * Destroy all session data. |
|
253 | - */ |
|
254 | - public function destroy_session() { |
|
255 | - $this->delete_session( $this->_customer_id ); |
|
256 | - $this->forget_session(); |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Forget all session data without destroying it. |
|
261 | - */ |
|
262 | - public function forget_session() { |
|
263 | - $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true ); |
|
264 | - |
|
265 | - wpinv_empty_cart(); |
|
266 | - |
|
267 | - $this->_data = array(); |
|
268 | - $this->_dirty = false; |
|
269 | - $this->_customer_id = $this->generate_customer_id(); |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * When a user is logged out, ensure they have a unique nonce by using the customer/session ID. |
|
274 | - * |
|
275 | - * @param int $uid User ID. |
|
276 | - * @return string |
|
277 | - */ |
|
278 | - public function nonce_user_logged_out( $uid ) { |
|
279 | - return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid; |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * Returns the session. |
|
284 | - * |
|
285 | - * @param string $customer_id Customer ID. |
|
286 | - * @param mixed $default Default session value. |
|
287 | - * @return string|array |
|
288 | - */ |
|
289 | - public function get_session( $customer_id, $default = false ) { |
|
290 | - |
|
291 | - if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
292 | - return array(); |
|
293 | - } |
|
247 | + $this->_dirty = false; |
|
248 | + } |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * Destroy all session data. |
|
253 | + */ |
|
254 | + public function destroy_session() { |
|
255 | + $this->delete_session( $this->_customer_id ); |
|
256 | + $this->forget_session(); |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Forget all session data without destroying it. |
|
261 | + */ |
|
262 | + public function forget_session() { |
|
263 | + $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true ); |
|
264 | + |
|
265 | + wpinv_empty_cart(); |
|
266 | + |
|
267 | + $this->_data = array(); |
|
268 | + $this->_dirty = false; |
|
269 | + $this->_customer_id = $this->generate_customer_id(); |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * When a user is logged out, ensure they have a unique nonce by using the customer/session ID. |
|
274 | + * |
|
275 | + * @param int $uid User ID. |
|
276 | + * @return string |
|
277 | + */ |
|
278 | + public function nonce_user_logged_out( $uid ) { |
|
279 | + return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid; |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * Returns the session. |
|
284 | + * |
|
285 | + * @param string $customer_id Customer ID. |
|
286 | + * @param mixed $default Default session value. |
|
287 | + * @return string|array |
|
288 | + */ |
|
289 | + public function get_session( $customer_id, $default = false ) { |
|
290 | + |
|
291 | + if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
292 | + return array(); |
|
293 | + } |
|
294 | 294 | |
295 | 295 | if ( !is_user_logged_in() ) { |
296 | 296 | if(!wp_verify_nonce( $customer_id, 'wpinv-session-customer-id' )){ |
@@ -305,32 +305,32 @@ discard block |
||
305 | 305 | $value = $default; |
306 | 306 | } |
307 | 307 | |
308 | - return maybe_unserialize( $value ); |
|
309 | - } |
|
308 | + return maybe_unserialize( $value ); |
|
309 | + } |
|
310 | 310 | |
311 | - /** |
|
312 | - * Delete the session from the cache and database. |
|
313 | - * |
|
314 | - * @param int $customer_id Customer ID. |
|
315 | - */ |
|
316 | - public function delete_session( $customer_id ) { |
|
311 | + /** |
|
312 | + * Delete the session from the cache and database. |
|
313 | + * |
|
314 | + * @param int $customer_id Customer ID. |
|
315 | + */ |
|
316 | + public function delete_session( $customer_id ) { |
|
317 | 317 | |
318 | 318 | $key = $this->generate_key($customer_id); |
319 | 319 | |
320 | - delete_transient($key); |
|
321 | - } |
|
320 | + delete_transient($key); |
|
321 | + } |
|
322 | 322 | |
323 | - /** |
|
324 | - * Update the session expiry timestamp. |
|
325 | - * |
|
326 | - * @param string $customer_id Customer ID. |
|
327 | - * @param int $timestamp Timestamp to expire the cookie. |
|
328 | - */ |
|
329 | - public function update_session_timestamp( $customer_id, $timestamp ) { |
|
323 | + /** |
|
324 | + * Update the session expiry timestamp. |
|
325 | + * |
|
326 | + * @param string $customer_id Customer ID. |
|
327 | + * @param int $timestamp Timestamp to expire the cookie. |
|
328 | + */ |
|
329 | + public function update_session_timestamp( $customer_id, $timestamp ) { |
|
330 | 330 | |
331 | 331 | set_transient( $this->generate_key($customer_id), maybe_serialize( $this->_data ), $timestamp); |
332 | 332 | |
333 | - } |
|
333 | + } |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | global $wpi_session; |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Session handler class. |
@@ -52,11 +52,11 @@ discard block |
||
52 | 52 | */ |
53 | 53 | public function __construct() { |
54 | 54 | |
55 | - $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH ); |
|
56 | - add_action( 'init', array( $this, 'init' ), -1 ); |
|
57 | - add_action( 'wp_logout', array( $this, 'destroy_session' ) ); |
|
58 | - add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 ); |
|
59 | - add_action( 'shutdown', array( $this, 'save_data' ), 20 ); |
|
55 | + $this->_cookie = apply_filters('wpinv_cookie', 'wpinv_session_' . COOKIEHASH); |
|
56 | + add_action('init', array($this, 'init'), -1); |
|
57 | + add_action('wp_logout', array($this, 'destroy_session')); |
|
58 | + add_action('wp', array($this, 'set_customer_session_cookie'), 10); |
|
59 | + add_action('shutdown', array($this, 'save_data'), 20); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | public function init() { |
68 | 68 | $this->init_session_cookie(); |
69 | 69 | |
70 | - if ( ! is_user_logged_in() ) { |
|
71 | - add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) ); |
|
70 | + if (!is_user_logged_in()) { |
|
71 | + add_filter('nonce_user_logged_out', array($this, 'nonce_user_logged_out')); |
|
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | public function init_session_cookie() { |
81 | 81 | $cookie = $this->get_session_cookie(); |
82 | 82 | |
83 | - if ( $cookie ) { |
|
83 | + if ($cookie) { |
|
84 | 84 | $this->_customer_id = $cookie[0]; |
85 | 85 | $this->_session_expiration = $cookie[1]; |
86 | 86 | $this->_session_expiring = $cookie[2]; |
@@ -88,17 +88,17 @@ discard block |
||
88 | 88 | $this->_data = $this->get_session_data(); |
89 | 89 | |
90 | 90 | // If the user logs in, update session. |
91 | - if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) { |
|
91 | + if (is_user_logged_in() && get_current_user_id() != $this->_customer_id) { |
|
92 | 92 | $this->_customer_id = get_current_user_id(); |
93 | 93 | $this->_dirty = true; |
94 | 94 | $this->save_data(); |
95 | - $this->set_customer_session_cookie( true ); |
|
95 | + $this->set_customer_session_cookie(true); |
|
96 | 96 | } |
97 | 97 | |
98 | 98 | // Update session if its close to expiring. |
99 | - if ( time() > $this->_session_expiring ) { |
|
99 | + if (time() > $this->_session_expiring) { |
|
100 | 100 | $this->set_session_expiration(); |
101 | - $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration ); |
|
101 | + $this->update_session_timestamp($this->_customer_id, $this->_session_expiration); |
|
102 | 102 | } |
103 | 103 | } else { |
104 | 104 | $this->set_session_expiration(); |
@@ -116,25 +116,25 @@ discard block |
||
116 | 116 | * |
117 | 117 | * @param bool $set Should the session cookie be set. |
118 | 118 | */ |
119 | - public function set_customer_session_cookie( $set ) { |
|
120 | - if ( $set ) { |
|
119 | + public function set_customer_session_cookie($set) { |
|
120 | + if ($set) { |
|
121 | 121 | $to_hash = $this->_customer_id . '|' . $this->_session_expiration; |
122 | - $cookie_hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
122 | + $cookie_hash = hash_hmac('md5', $to_hash, wp_hash($to_hash)); |
|
123 | 123 | $cookie_value = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash; |
124 | 124 | $this->_has_cookie = true; |
125 | 125 | |
126 | - if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) { |
|
127 | - $this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true ); |
|
126 | + if (!isset($_COOKIE[$this->_cookie]) || $_COOKIE[$this->_cookie] !== $cookie_value) { |
|
127 | + $this->setcookie($this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true); |
|
128 | 128 | } |
129 | 129 | } |
130 | 130 | } |
131 | 131 | |
132 | - public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){ |
|
133 | - if ( ! headers_sent() ) { |
|
134 | - setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure ) ); |
|
135 | - } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
136 | - headers_sent( $file, $line ); |
|
137 | - trigger_error( "{$name} cookie cannot be set - headers already sent by {$file} on line {$line}", E_USER_NOTICE ); // @codingStandardsIgnoreLine |
|
132 | + public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false) { |
|
133 | + if (!headers_sent()) { |
|
134 | + setcookie($name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters('wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure)); |
|
135 | + } elseif (defined('WP_DEBUG') && WP_DEBUG) { |
|
136 | + headers_sent($file, $line); |
|
137 | + trigger_error("{$name} cookie cannot be set - headers already sent by {$file} on line {$line}", E_USER_NOTICE); // @codingStandardsIgnoreLine |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
@@ -145,8 +145,8 @@ discard block |
||
145 | 145 | * @return bool |
146 | 146 | */ |
147 | 147 | protected function use_secure_cookie() { |
148 | - $is_https = false !== strstr( get_option( 'home' ), 'https:' ); |
|
149 | - return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() ); |
|
148 | + $is_https = false !== strstr(get_option('home'), 'https:'); |
|
149 | + return apply_filters('wpinv_session_use_secure_cookie', $is_https && is_ssl()); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
@@ -155,15 +155,15 @@ discard block |
||
155 | 155 | * @return bool |
156 | 156 | */ |
157 | 157 | public function has_session() { |
158 | - return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. |
|
158 | + return isset($_COOKIE[$this->_cookie]) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
162 | 162 | * Set session expiration. |
163 | 163 | */ |
164 | 164 | public function set_session_expiration() { |
165 | - $this->_session_expiring = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours. |
|
166 | - $this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours. |
|
165 | + $this->_session_expiring = time() + intval(apply_filters('wpinv_session_expiring', 60 * 60 * 47)); // 47 Hours. |
|
166 | + $this->_session_expiration = time() + intval(apply_filters('wpinv_session_expiration', 60 * 60 * 48)); // 48 Hours. |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -176,11 +176,11 @@ discard block |
||
176 | 176 | public function generate_customer_id() { |
177 | 177 | $customer_id = ''; |
178 | 178 | |
179 | - if ( is_user_logged_in() ) { |
|
179 | + if (is_user_logged_in()) { |
|
180 | 180 | $customer_id = get_current_user_id(); |
181 | 181 | } |
182 | 182 | |
183 | - if ( empty( $customer_id ) ) { |
|
183 | + if (empty($customer_id)) { |
|
184 | 184 | $customer_id = wp_create_nonce('wpinv-session-customer-id'); |
185 | 185 | } |
186 | 186 | |
@@ -195,27 +195,27 @@ discard block |
||
195 | 195 | * @return bool|array |
196 | 196 | */ |
197 | 197 | public function get_session_cookie() { |
198 | - $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine. |
|
198 | + $cookie_value = isset($_COOKIE[$this->_cookie]) ? wp_unslash($_COOKIE[$this->_cookie]) : false; // @codingStandardsIgnoreLine. |
|
199 | 199 | |
200 | - if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) { |
|
200 | + if (empty($cookie_value) || !is_string($cookie_value)) { |
|
201 | 201 | return false; |
202 | 202 | } |
203 | 203 | |
204 | - list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value ); |
|
204 | + list($customer_id, $session_expiration, $session_expiring, $cookie_hash) = explode('||', $cookie_value); |
|
205 | 205 | |
206 | - if ( empty( $customer_id ) ) { |
|
206 | + if (empty($customer_id)) { |
|
207 | 207 | return false; |
208 | 208 | } |
209 | 209 | |
210 | 210 | // Validate hash. |
211 | 211 | $to_hash = $customer_id . '|' . $session_expiration; |
212 | - $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
212 | + $hash = hash_hmac('md5', $to_hash, wp_hash($to_hash)); |
|
213 | 213 | |
214 | - if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) { |
|
214 | + if (empty($cookie_hash) || !hash_equals($hash, $cookie_hash)) { |
|
215 | 215 | return false; |
216 | 216 | } |
217 | 217 | |
218 | - return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash ); |
|
218 | + return array($customer_id, $session_expiration, $session_expiring, $cookie_hash); |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -224,15 +224,15 @@ discard block |
||
224 | 224 | * @return array |
225 | 225 | */ |
226 | 226 | public function get_session_data() { |
227 | - return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array(); |
|
227 | + return $this->has_session() ? (array)$this->get_session($this->_customer_id) : array(); |
|
228 | 228 | } |
229 | 229 | |
230 | - public function generate_key($customer_id){ |
|
231 | - if(!$customer_id){ |
|
230 | + public function generate_key($customer_id) { |
|
231 | + if (!$customer_id) { |
|
232 | 232 | return; |
233 | 233 | } |
234 | 234 | |
235 | - return 'wpi_trans_'.$customer_id; |
|
235 | + return 'wpi_trans_' . $customer_id; |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | /** |
@@ -240,9 +240,9 @@ discard block |
||
240 | 240 | */ |
241 | 241 | public function save_data() { |
242 | 242 | // Dirty if something changed - prevents saving nothing new. |
243 | - if ( $this->_dirty && $this->has_session() ) { |
|
243 | + if ($this->_dirty && $this->has_session()) { |
|
244 | 244 | |
245 | - set_transient( $this->generate_key($this->_customer_id), $this->_data, $this->_session_expiration); |
|
245 | + set_transient($this->generate_key($this->_customer_id), $this->_data, $this->_session_expiration); |
|
246 | 246 | |
247 | 247 | $this->_dirty = false; |
248 | 248 | } |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | * Destroy all session data. |
253 | 253 | */ |
254 | 254 | public function destroy_session() { |
255 | - $this->delete_session( $this->_customer_id ); |
|
255 | + $this->delete_session($this->_customer_id); |
|
256 | 256 | $this->forget_session(); |
257 | 257 | } |
258 | 258 | |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | * Forget all session data without destroying it. |
261 | 261 | */ |
262 | 262 | public function forget_session() { |
263 | - $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true ); |
|
263 | + $this->setcookie($this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true); |
|
264 | 264 | |
265 | 265 | wpinv_empty_cart(); |
266 | 266 | |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | * @param int $uid User ID. |
276 | 276 | * @return string |
277 | 277 | */ |
278 | - public function nonce_user_logged_out( $uid ) { |
|
278 | + public function nonce_user_logged_out($uid) { |
|
279 | 279 | return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid; |
280 | 280 | } |
281 | 281 | |
@@ -286,14 +286,14 @@ discard block |
||
286 | 286 | * @param mixed $default Default session value. |
287 | 287 | * @return string|array |
288 | 288 | */ |
289 | - public function get_session( $customer_id, $default = false ) { |
|
289 | + public function get_session($customer_id, $default = false) { |
|
290 | 290 | |
291 | - if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
291 | + if (defined('WP_SETUP_CONFIG')) { |
|
292 | 292 | return array(); |
293 | 293 | } |
294 | 294 | |
295 | - if ( !is_user_logged_in() ) { |
|
296 | - if(!wp_verify_nonce( $customer_id, 'wpinv-session-customer-id' )){ |
|
295 | + if (!is_user_logged_in()) { |
|
296 | + if (!wp_verify_nonce($customer_id, 'wpinv-session-customer-id')) { |
|
297 | 297 | return array(); |
298 | 298 | } |
299 | 299 | } |
@@ -301,11 +301,11 @@ discard block |
||
301 | 301 | $key = $this->generate_key($customer_id); |
302 | 302 | $value = get_transient($key); |
303 | 303 | |
304 | - if ( !$value ) { |
|
304 | + if (!$value) { |
|
305 | 305 | $value = $default; |
306 | 306 | } |
307 | 307 | |
308 | - return maybe_unserialize( $value ); |
|
308 | + return maybe_unserialize($value); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | /** |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | * |
314 | 314 | * @param int $customer_id Customer ID. |
315 | 315 | */ |
316 | - public function delete_session( $customer_id ) { |
|
316 | + public function delete_session($customer_id) { |
|
317 | 317 | |
318 | 318 | $key = $this->generate_key($customer_id); |
319 | 319 | |
@@ -326,9 +326,9 @@ discard block |
||
326 | 326 | * @param string $customer_id Customer ID. |
327 | 327 | * @param int $timestamp Timestamp to expire the cookie. |
328 | 328 | */ |
329 | - public function update_session_timestamp( $customer_id, $timestamp ) { |
|
329 | + public function update_session_timestamp($customer_id, $timestamp) { |
|
330 | 330 | |
331 | - set_transient( $this->generate_key($customer_id), maybe_serialize( $this->_data ), $timestamp); |
|
331 | + set_transient($this->generate_key($customer_id), maybe_serialize($this->_data), $timestamp); |
|
332 | 332 | |
333 | 333 | } |
334 | 334 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Abstract privacy class. |
4 | 4 | */ |
5 | 5 | |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * Abstract class that is intended to be extended by |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @param string $name Plugin identifier. |
40 | 40 | */ |
41 | - public function __construct( $name = '' ) { |
|
41 | + public function __construct($name = '') { |
|
42 | 42 | $this->name = $name; |
43 | 43 | $this->init(); |
44 | 44 | } |
@@ -47,22 +47,22 @@ discard block |
||
47 | 47 | * Hook in events. |
48 | 48 | */ |
49 | 49 | protected function init() { |
50 | - add_action( 'admin_init', array( $this, 'add_privacy_message' ) ); |
|
50 | + add_action('admin_init', array($this, 'add_privacy_message')); |
|
51 | 51 | // Register data exporters |
52 | - add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'register_exporters' ), 10 ); |
|
52 | + add_filter('wp_privacy_personal_data_exporters', array($this, 'register_exporters'), 10); |
|
53 | 53 | // Register data erasers |
54 | - add_filter( 'wp_privacy_personal_data_erasers', array( $this, 'register_erasers' ) ); |
|
54 | + add_filter('wp_privacy_personal_data_erasers', array($this, 'register_erasers')); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Adds the privacy message on invoicing privacy page. |
59 | 59 | */ |
60 | 60 | public function add_privacy_message() { |
61 | - if ( function_exists( 'wp_add_privacy_policy_content' ) ) { |
|
61 | + if (function_exists('wp_add_privacy_policy_content')) { |
|
62 | 62 | $content = $this->get_privacy_message(); |
63 | 63 | |
64 | - if ( $content ) { |
|
65 | - wp_add_privacy_policy_content( $this->name, $this->get_privacy_message() ); |
|
64 | + if ($content) { |
|
65 | + wp_add_privacy_policy_content($this->name, $this->get_privacy_message()); |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 | } |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | * @param array $exporters List of exporter callbacks. |
84 | 84 | * @return array |
85 | 85 | */ |
86 | - public function register_exporters( $exporters = array() ) { |
|
87 | - foreach ( $this->exporters as $id => $exporter ) { |
|
88 | - $exporters[ $id ] = $exporter; |
|
86 | + public function register_exporters($exporters = array()) { |
|
87 | + foreach ($this->exporters as $id => $exporter) { |
|
88 | + $exporters[$id] = $exporter; |
|
89 | 89 | } |
90 | 90 | return $exporters; |
91 | 91 | } |
@@ -96,9 +96,9 @@ discard block |
||
96 | 96 | * @param array $erasers List of eraser callbacks. |
97 | 97 | * @return array |
98 | 98 | */ |
99 | - public function register_erasers( $erasers = array() ) { |
|
100 | - foreach ( $this->erasers as $id => $eraser ) { |
|
101 | - $erasers[ $id ] = $eraser; |
|
99 | + public function register_erasers($erasers = array()) { |
|
100 | + foreach ($this->erasers as $id => $eraser) { |
|
101 | + $erasers[$id] = $eraser; |
|
102 | 102 | } |
103 | 103 | return $erasers; |
104 | 104 | } |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @return array |
114 | 114 | */ |
115 | - public function add_exporter( $id, $name, $callback ) { |
|
116 | - $this->exporters[ $id ] = array( |
|
115 | + public function add_exporter($id, $name, $callback) { |
|
116 | + $this->exporters[$id] = array( |
|
117 | 117 | 'exporter_friendly_name' => $name, |
118 | 118 | 'callback' => $callback, |
119 | 119 | ); |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @return array |
131 | 131 | */ |
132 | - public function add_eraser( $id, $name, $callback ) { |
|
133 | - $this->erasers[ $id ] = array( |
|
132 | + public function add_eraser($id, $name, $callback) { |
|
133 | + $this->erasers[$id] = array( |
|
134 | 134 | 'eraser_friendly_name' => $name, |
135 | 135 | 'callback' => $callback, |
136 | 136 | ); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | */ |
5 | 5 | |
6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
7 | - exit; |
|
7 | + exit; |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
@@ -12,112 +12,112 @@ discard block |
||
12 | 12 | */ |
13 | 13 | abstract class WPInv_Session { |
14 | 14 | |
15 | - /** |
|
16 | - * Customer ID. |
|
17 | - * |
|
18 | - * @var int $_customer_id Customer ID. |
|
19 | - */ |
|
20 | - protected $_customer_id; |
|
15 | + /** |
|
16 | + * Customer ID. |
|
17 | + * |
|
18 | + * @var int $_customer_id Customer ID. |
|
19 | + */ |
|
20 | + protected $_customer_id; |
|
21 | 21 | |
22 | - /** |
|
23 | - * Session Data. |
|
24 | - * |
|
25 | - * @var array $_data Data array. |
|
26 | - */ |
|
27 | - protected $_data = array(); |
|
22 | + /** |
|
23 | + * Session Data. |
|
24 | + * |
|
25 | + * @var array $_data Data array. |
|
26 | + */ |
|
27 | + protected $_data = array(); |
|
28 | 28 | |
29 | - /** |
|
30 | - * Dirty when the session needs saving. |
|
31 | - * |
|
32 | - * @var bool $_dirty When something changes |
|
33 | - */ |
|
34 | - protected $_dirty = false; |
|
29 | + /** |
|
30 | + * Dirty when the session needs saving. |
|
31 | + * |
|
32 | + * @var bool $_dirty When something changes |
|
33 | + */ |
|
34 | + protected $_dirty = false; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Init hooks and session data. Extended by child classes. |
|
38 | - * |
|
39 | - * @since 3.3.0 |
|
40 | - */ |
|
41 | - public function init() {} |
|
36 | + /** |
|
37 | + * Init hooks and session data. Extended by child classes. |
|
38 | + * |
|
39 | + * @since 3.3.0 |
|
40 | + */ |
|
41 | + public function init() {} |
|
42 | 42 | |
43 | - /** |
|
44 | - * Cleanup session data. Extended by child classes. |
|
45 | - */ |
|
46 | - public function cleanup_sessions() {} |
|
43 | + /** |
|
44 | + * Cleanup session data. Extended by child classes. |
|
45 | + */ |
|
46 | + public function cleanup_sessions() {} |
|
47 | 47 | |
48 | - /** |
|
49 | - * Magic get method. |
|
50 | - * |
|
51 | - * @param mixed $key Key to get. |
|
52 | - * @return mixed |
|
53 | - */ |
|
54 | - public function __get( $key ) { |
|
55 | - return $this->get( $key ); |
|
56 | - } |
|
48 | + /** |
|
49 | + * Magic get method. |
|
50 | + * |
|
51 | + * @param mixed $key Key to get. |
|
52 | + * @return mixed |
|
53 | + */ |
|
54 | + public function __get( $key ) { |
|
55 | + return $this->get( $key ); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Magic set method. |
|
60 | - * |
|
61 | - * @param mixed $key Key to set. |
|
62 | - * @param mixed $value Value to set. |
|
63 | - */ |
|
64 | - public function __set( $key, $value ) { |
|
65 | - $this->set( $key, $value ); |
|
66 | - } |
|
58 | + /** |
|
59 | + * Magic set method. |
|
60 | + * |
|
61 | + * @param mixed $key Key to set. |
|
62 | + * @param mixed $value Value to set. |
|
63 | + */ |
|
64 | + public function __set( $key, $value ) { |
|
65 | + $this->set( $key, $value ); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Magic isset method. |
|
70 | - * |
|
71 | - * @param mixed $key Key to check. |
|
72 | - * @return bool |
|
73 | - */ |
|
74 | - public function __isset( $key ) { |
|
75 | - return isset( $this->_data[ sanitize_title( $key ) ] ); |
|
76 | - } |
|
68 | + /** |
|
69 | + * Magic isset method. |
|
70 | + * |
|
71 | + * @param mixed $key Key to check. |
|
72 | + * @return bool |
|
73 | + */ |
|
74 | + public function __isset( $key ) { |
|
75 | + return isset( $this->_data[ sanitize_title( $key ) ] ); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Magic unset method. |
|
80 | - * |
|
81 | - * @param mixed $key Key to unset. |
|
82 | - */ |
|
83 | - public function __unset( $key ) { |
|
84 | - if ( isset( $this->_data[ $key ] ) ) { |
|
85 | - unset( $this->_data[ $key ] ); |
|
86 | - $this->_dirty = true; |
|
87 | - } |
|
88 | - } |
|
78 | + /** |
|
79 | + * Magic unset method. |
|
80 | + * |
|
81 | + * @param mixed $key Key to unset. |
|
82 | + */ |
|
83 | + public function __unset( $key ) { |
|
84 | + if ( isset( $this->_data[ $key ] ) ) { |
|
85 | + unset( $this->_data[ $key ] ); |
|
86 | + $this->_dirty = true; |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Get a session variable. |
|
92 | - * |
|
93 | - * @param string $key Key to get. |
|
94 | - * @param mixed $default used if the session variable isn't set. |
|
95 | - * @return array|string value of session variable |
|
96 | - */ |
|
97 | - public function get( $key, $default = null ) { |
|
98 | - $key = sanitize_key( $key ); |
|
99 | - return isset( $this->_data[ $key ] ) ? maybe_unserialize( $this->_data[ $key ] ) : $default; |
|
100 | - } |
|
90 | + /** |
|
91 | + * Get a session variable. |
|
92 | + * |
|
93 | + * @param string $key Key to get. |
|
94 | + * @param mixed $default used if the session variable isn't set. |
|
95 | + * @return array|string value of session variable |
|
96 | + */ |
|
97 | + public function get( $key, $default = null ) { |
|
98 | + $key = sanitize_key( $key ); |
|
99 | + return isset( $this->_data[ $key ] ) ? maybe_unserialize( $this->_data[ $key ] ) : $default; |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Set a session variable. |
|
104 | - * |
|
105 | - * @param string $key Key to set. |
|
106 | - * @param mixed $value Value to set. |
|
107 | - */ |
|
108 | - public function set( $key, $value ) { |
|
109 | - if ( $value !== $this->get( $key ) ) { |
|
110 | - $this->_data[ sanitize_key( $key ) ] = maybe_serialize( $value ); |
|
111 | - $this->_dirty = true; |
|
112 | - } |
|
113 | - } |
|
102 | + /** |
|
103 | + * Set a session variable. |
|
104 | + * |
|
105 | + * @param string $key Key to set. |
|
106 | + * @param mixed $value Value to set. |
|
107 | + */ |
|
108 | + public function set( $key, $value ) { |
|
109 | + if ( $value !== $this->get( $key ) ) { |
|
110 | + $this->_data[ sanitize_key( $key ) ] = maybe_serialize( $value ); |
|
111 | + $this->_dirty = true; |
|
112 | + } |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Get customer ID. |
|
117 | - * |
|
118 | - * @return int |
|
119 | - */ |
|
120 | - public function get_customer_id() { |
|
121 | - return $this->_customer_id; |
|
122 | - } |
|
115 | + /** |
|
116 | + * Get customer ID. |
|
117 | + * |
|
118 | + * @return int |
|
119 | + */ |
|
120 | + public function get_customer_id() { |
|
121 | + return $this->_customer_id; |
|
122 | + } |
|
123 | 123 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Handle data for the current customer session |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | * @param mixed $key Key to get. |
52 | 52 | * @return mixed |
53 | 53 | */ |
54 | - public function __get( $key ) { |
|
55 | - return $this->get( $key ); |
|
54 | + public function __get($key) { |
|
55 | + return $this->get($key); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | * @param mixed $key Key to set. |
62 | 62 | * @param mixed $value Value to set. |
63 | 63 | */ |
64 | - public function __set( $key, $value ) { |
|
65 | - $this->set( $key, $value ); |
|
64 | + public function __set($key, $value) { |
|
65 | + $this->set($key, $value); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | * @param mixed $key Key to check. |
72 | 72 | * @return bool |
73 | 73 | */ |
74 | - public function __isset( $key ) { |
|
75 | - return isset( $this->_data[ sanitize_title( $key ) ] ); |
|
74 | + public function __isset($key) { |
|
75 | + return isset($this->_data[sanitize_title($key)]); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @param mixed $key Key to unset. |
82 | 82 | */ |
83 | - public function __unset( $key ) { |
|
84 | - if ( isset( $this->_data[ $key ] ) ) { |
|
85 | - unset( $this->_data[ $key ] ); |
|
83 | + public function __unset($key) { |
|
84 | + if (isset($this->_data[$key])) { |
|
85 | + unset($this->_data[$key]); |
|
86 | 86 | $this->_dirty = true; |
87 | 87 | } |
88 | 88 | } |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | * @param mixed $default used if the session variable isn't set. |
95 | 95 | * @return array|string value of session variable |
96 | 96 | */ |
97 | - public function get( $key, $default = null ) { |
|
98 | - $key = sanitize_key( $key ); |
|
99 | - return isset( $this->_data[ $key ] ) ? maybe_unserialize( $this->_data[ $key ] ) : $default; |
|
97 | + public function get($key, $default = null) { |
|
98 | + $key = sanitize_key($key); |
|
99 | + return isset($this->_data[$key]) ? maybe_unserialize($this->_data[$key]) : $default; |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | * @param string $key Key to set. |
106 | 106 | * @param mixed $value Value to set. |
107 | 107 | */ |
108 | - public function set( $key, $value ) { |
|
109 | - if ( $value !== $this->get( $key ) ) { |
|
110 | - $this->_data[ sanitize_key( $key ) ] = maybe_serialize( $value ); |
|
108 | + public function set($key, $value) { |
|
109 | + if ($value !== $this->get($key)) { |
|
110 | + $this->_data[sanitize_key($key)] = maybe_serialize($value); |
|
111 | 111 | $this->_dirty = true; |
112 | 112 | } |
113 | 113 | } |
@@ -7,15 +7,15 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | class WPInv_Plugin { |
15 | 15 | private static $instance; |
16 | 16 | |
17 | 17 | public static function run() { |
18 | - if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) { |
|
18 | + if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) { |
|
19 | 19 | self::$instance = new WPInv_Plugin; |
20 | 20 | self::$instance->includes(); |
21 | 21 | self::$instance->actions(); |
@@ -31,31 +31,31 @@ discard block |
||
31 | 31 | } |
32 | 32 | |
33 | 33 | public function define_constants() { |
34 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
35 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
34 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
35 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | private function actions() { |
39 | 39 | /* Internationalize the text strings used. */ |
40 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
40 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
41 | 41 | |
42 | 42 | /* Perform actions on admin initialization. */ |
43 | - add_action( 'admin_init', array( &$this, 'admin_init') ); |
|
44 | - add_action( 'init', array( &$this, 'init' ), 3 ); |
|
45 | - add_action( 'init', array( 'WPInv_Shortcodes', 'init' ) ); |
|
46 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
43 | + add_action('admin_init', array(&$this, 'admin_init')); |
|
44 | + add_action('init', array(&$this, 'init'), 3); |
|
45 | + add_action('init', array('WPInv_Shortcodes', 'init')); |
|
46 | + add_action('init', array(&$this, 'wpinv_actions')); |
|
47 | 47 | |
48 | - if ( class_exists( 'BuddyPress' ) ) { |
|
49 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
48 | + if (class_exists('BuddyPress')) { |
|
49 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
50 | 50 | } |
51 | 51 | |
52 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
52 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
53 | 53 | |
54 | - if ( is_admin() ) { |
|
55 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
56 | - add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
54 | + if (is_admin()) { |
|
55 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts')); |
|
56 | + add_action('admin_body_class', array(&$this, 'admin_body_class')); |
|
57 | 57 | } else { |
58 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
58 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -65,16 +65,16 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference. |
67 | 67 | */ |
68 | - do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
|
68 | + do_action_ref_array('wpinv_actions', array(&$this)); |
|
69 | 69 | |
70 | - add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
70 | + add_action('admin_init', array(&$this, 'activation_redirect')); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | public function plugins_loaded() { |
74 | 74 | /* Internationalize the text strings used. */ |
75 | 75 | $this->load_textdomain(); |
76 | 76 | |
77 | - do_action( 'wpinv_loaded' ); |
|
77 | + do_action('wpinv_loaded'); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -82,217 +82,217 @@ discard block |
||
82 | 82 | * |
83 | 83 | * @since 1.0 |
84 | 84 | */ |
85 | - public function load_textdomain( $locale = NULL ) { |
|
86 | - if ( empty( $locale ) ) { |
|
87 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
85 | + public function load_textdomain($locale = NULL) { |
|
86 | + if (empty($locale)) { |
|
87 | + $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
|
88 | 88 | } |
89 | 89 | |
90 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
90 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
91 | 91 | |
92 | - unload_textdomain( 'invoicing' ); |
|
93 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
94 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
92 | + unload_textdomain('invoicing'); |
|
93 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
94 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
95 | 95 | |
96 | 96 | /** |
97 | 97 | * Define language constants. |
98 | 98 | */ |
99 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
99 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | public function includes() { |
103 | 103 | global $wpinv_options; |
104 | 104 | |
105 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
105 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
106 | 106 | $wpinv_options = wpinv_get_settings(); |
107 | 107 | |
108 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' ); |
|
109 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
110 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
111 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
112 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
113 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
114 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
115 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' ); |
|
116 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
117 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
118 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
119 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
120 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
121 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
|
122 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' ); |
|
123 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' ); |
|
124 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' ); |
|
125 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
126 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
127 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
128 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
129 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
130 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' ); |
|
131 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
132 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
133 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
134 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
135 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' ); |
|
136 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
137 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' ); |
|
138 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
139 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
140 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
141 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
142 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
108 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php'); |
|
109 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
110 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
111 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
112 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
113 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
114 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
115 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php'); |
|
116 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
117 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
118 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
119 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
120 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
121 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php'); |
|
122 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php'); |
|
123 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php'); |
|
124 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php'); |
|
125 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'); |
|
126 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'); |
|
127 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
128 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
129 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
130 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php'); |
|
131 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'); |
|
132 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'); |
|
133 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'); |
|
134 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'); |
|
135 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php'); |
|
136 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'); |
|
137 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php'); |
|
138 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'); |
|
139 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'); |
|
140 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'); |
|
141 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'); |
|
142 | + require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php'); |
|
143 | 143 | |
144 | - if ( !class_exists( 'WPInv_EUVat' ) ) { |
|
145 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
144 | + if (!class_exists('WPInv_EUVat')) { |
|
145 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
146 | 146 | } |
147 | 147 | |
148 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
149 | - if ( !empty( $gateways ) ) { |
|
150 | - foreach ( $gateways as $gateway ) { |
|
151 | - if ( $gateway == 'manual' ) { |
|
148 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
149 | + if (!empty($gateways)) { |
|
150 | + foreach ($gateways as $gateway) { |
|
151 | + if ($gateway == 'manual') { |
|
152 | 152 | continue; |
153 | 153 | } |
154 | 154 | |
155 | 155 | $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
156 | 156 | |
157 | - if ( file_exists( $gateway_file ) ) { |
|
158 | - require_once( $gateway_file ); |
|
157 | + if (file_exists($gateway_file)) { |
|
158 | + require_once($gateway_file); |
|
159 | 159 | } |
160 | 160 | } |
161 | 161 | } |
162 | - require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' ); |
|
162 | + require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php'); |
|
163 | 163 | |
164 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
165 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
166 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
167 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' ); |
|
164 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
165 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
166 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
167 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php'); |
|
168 | 168 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
169 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' ); |
|
170 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' ); |
|
171 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
172 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' ); |
|
173 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
174 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
175 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
169 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php'); |
|
170 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php'); |
|
171 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
172 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php'); |
|
173 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
174 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'); |
|
175 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'); |
|
176 | 176 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
177 | 177 | // load the user class only on the users.php page |
178 | 178 | global $pagenow; |
179 | - if($pagenow=='users.php'){ |
|
179 | + if ($pagenow == 'users.php') { |
|
180 | 180 | new WPInv_Admin_Users(); |
181 | 181 | } |
182 | 182 | } |
183 | 183 | |
184 | 184 | // include css inliner |
185 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
186 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
185 | + if (!class_exists('Emogrifier') && class_exists('DOMDocument')) { |
|
186 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
187 | 187 | } |
188 | 188 | |
189 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
189 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | public function init() { |
193 | 193 | } |
194 | 194 | |
195 | 195 | public function admin_init() { |
196 | - add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
196 | + add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php')); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | public function activation_redirect() { |
200 | 200 | // Bail if no activation redirect |
201 | - if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
201 | + if (!get_transient('_wpinv_activation_redirect')) { |
|
202 | 202 | return; |
203 | 203 | } |
204 | 204 | |
205 | 205 | // Delete the redirect transient |
206 | - delete_transient( '_wpinv_activation_redirect' ); |
|
206 | + delete_transient('_wpinv_activation_redirect'); |
|
207 | 207 | |
208 | 208 | // Bail if activating from network, or bulk |
209 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
209 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
210 | 210 | return; |
211 | 211 | } |
212 | 212 | |
213 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
213 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
214 | 214 | exit; |
215 | 215 | } |
216 | 216 | |
217 | 217 | public function enqueue_scripts() { |
218 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
218 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
219 | 219 | |
220 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION ); |
|
221 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
220 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION); |
|
221 | + wp_enqueue_style('wpinv_front_style'); |
|
222 | 222 | |
223 | 223 | // Register scripts |
224 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
225 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), WPINV_VERSION ); |
|
224 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
225 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), WPINV_VERSION); |
|
226 | 226 | |
227 | 227 | $localize = array(); |
228 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
229 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
228 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
229 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
230 | 230 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
231 | 231 | $localize['currency_pos'] = wpinv_currency_position(); |
232 | 232 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
233 | 233 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
234 | 234 | $localize['decimals'] = wpinv_decimals(); |
235 | - $localize['txtComplete'] = __( 'Complete', 'invoicing' ); |
|
235 | + $localize['txtComplete'] = __('Complete', 'invoicing'); |
|
236 | 236 | $localize['UseTaxes'] = wpinv_use_taxes(); |
237 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
237 | + $localize['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce'); |
|
238 | 238 | |
239 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
239 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
240 | 240 | |
241 | - wp_enqueue_script( 'jquery-blockui' ); |
|
241 | + wp_enqueue_script('jquery-blockui'); |
|
242 | 242 | $autofill_api = wpinv_get_option('address_autofill_api'); |
243 | 243 | $autofill_active = wpinv_get_option('address_autofill_active'); |
244 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
245 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
246 | - wp_dequeue_script( 'google-maps-api' ); |
|
244 | + if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) { |
|
245 | + if (wp_script_is('google-maps-api', 'enqueued')) { |
|
246 | + wp_dequeue_script('google-maps-api'); |
|
247 | 247 | } |
248 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
249 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
248 | + wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false); |
|
249 | + wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true); |
|
250 | 250 | } |
251 | 251 | |
252 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
253 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
252 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all'); |
|
253 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
254 | 254 | |
255 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
256 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
255 | + wp_enqueue_script('wpinv-front-script'); |
|
256 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | public function admin_enqueue_scripts() { |
260 | 260 | global $post, $pagenow; |
261 | 261 | |
262 | 262 | $post_type = wpinv_admin_post_type(); |
263 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
264 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : ''; |
|
263 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
264 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : ''; |
|
265 | 265 | |
266 | 266 | $jquery_ui_css = false; |
267 | - if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
267 | + if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
268 | 268 | $jquery_ui_css = true; |
269 | - } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) { |
|
269 | + } else if ($page == 'wpinv-settings' || $page == 'wpinv-reports') { |
|
270 | 270 | $jquery_ui_css = true; |
271 | 271 | } |
272 | - if ( $jquery_ui_css ) { |
|
273 | - wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
274 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
272 | + if ($jquery_ui_css) { |
|
273 | + wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16'); |
|
274 | + wp_enqueue_style('jquery-ui-css'); |
|
275 | 275 | } |
276 | 276 | |
277 | - wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
278 | - wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
277 | + wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
278 | + wp_enqueue_style('wpinv_meta_box_style'); |
|
279 | 279 | |
280 | - wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION ); |
|
281 | - wp_enqueue_style( 'wpinv_admin_style' ); |
|
280 | + wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION); |
|
281 | + wp_enqueue_style('wpinv_admin_style'); |
|
282 | 282 | |
283 | - $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ); |
|
284 | - if ( $page == 'wpinv-subscriptions' ) { |
|
285 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
283 | + $enqueue = ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')); |
|
284 | + if ($page == 'wpinv-subscriptions') { |
|
285 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
286 | 286 | } |
287 | 287 | |
288 | - if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) { |
|
289 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
288 | + if ($enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue)) { |
|
289 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
290 | 290 | } |
291 | 291 | |
292 | - wp_enqueue_style( 'wp-color-picker' ); |
|
293 | - wp_enqueue_script( 'wp-color-picker' ); |
|
292 | + wp_enqueue_style('wp-color-picker'); |
|
293 | + wp_enqueue_script('wp-color-picker'); |
|
294 | 294 | |
295 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
295 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
296 | 296 | |
297 | 297 | if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
298 | 298 | $autofill_api = wpinv_get_option('address_autofill_api'); |
@@ -303,20 +303,20 @@ discard block |
||
303 | 303 | } |
304 | 304 | } |
305 | 305 | |
306 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
307 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
306 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all'); |
|
307 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
308 | 308 | |
309 | - wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ), WPINV_VERSION ); |
|
310 | - wp_enqueue_script( 'wpinv-admin-script' ); |
|
309 | + wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), WPINV_VERSION); |
|
310 | + wp_enqueue_script('wpinv-admin-script'); |
|
311 | 311 | |
312 | 312 | $localize = array(); |
313 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
314 | - $localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
315 | - $localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
316 | - $localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
317 | - $localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
318 | - $localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
319 | - $localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
313 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
314 | + $localize['post_ID'] = isset($post->ID) ? $post->ID : ''; |
|
315 | + $localize['wpinv_nonce'] = wp_create_nonce('wpinv-nonce'); |
|
316 | + $localize['add_invoice_note_nonce'] = wp_create_nonce('add-invoice-note'); |
|
317 | + $localize['delete_invoice_note_nonce'] = wp_create_nonce('delete-invoice-note'); |
|
318 | + $localize['invoice_item_nonce'] = wp_create_nonce('invoice-item'); |
|
319 | + $localize['billing_details_nonce'] = wp_create_nonce('get-billing-details'); |
|
320 | 320 | $localize['tax'] = wpinv_tax_amount(); |
321 | 321 | $localize['discount'] = wpinv_discount_amount(); |
322 | 322 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
@@ -324,69 +324,69 @@ discard block |
||
324 | 324 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
325 | 325 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
326 | 326 | $localize['decimals'] = wpinv_decimals(); |
327 | - $localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
328 | - $localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
329 | - $localize['status_pending'] = wpinv_status_nicename( 'wpi-pending' ); |
|
330 | - $localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
331 | - $localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
332 | - $localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
333 | - $localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
334 | - $localize['confirmCalcTotals'] = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ); |
|
335 | - $localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
336 | - $localize['emptyInvoice'] = __( 'Add at least one item to save invoice!', 'invoicing' ); |
|
337 | - $localize['errDeleteItem'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
338 | - $localize['delete_subscription'] = __( 'Are you sure you want to delete this subscription?', 'invoicing' ); |
|
339 | - $localize['action_edit'] = __( 'Edit', 'invoicing' ); |
|
340 | - $localize['action_cancel'] = __( 'Cancel', 'invoicing' ); |
|
327 | + $localize['save_invoice'] = __('Save Invoice', 'invoicing'); |
|
328 | + $localize['status_publish'] = wpinv_status_nicename('publish'); |
|
329 | + $localize['status_pending'] = wpinv_status_nicename('wpi-pending'); |
|
330 | + $localize['delete_tax_rate'] = __('Are you sure you wish to delete this tax rate?', 'invoicing'); |
|
331 | + $localize['OneItemMin'] = __('Invoice must contain at least one item', 'invoicing'); |
|
332 | + $localize['DeleteInvoiceItem'] = __('Are you sure you wish to delete this item?', 'invoicing'); |
|
333 | + $localize['FillBillingDetails'] = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'); |
|
334 | + $localize['confirmCalcTotals'] = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'); |
|
335 | + $localize['AreYouSure'] = __('Are you sure?', 'invoicing'); |
|
336 | + $localize['emptyInvoice'] = __('Add at least one item to save invoice!', 'invoicing'); |
|
337 | + $localize['errDeleteItem'] = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'); |
|
338 | + $localize['delete_subscription'] = __('Are you sure you want to delete this subscription?', 'invoicing'); |
|
339 | + $localize['action_edit'] = __('Edit', 'invoicing'); |
|
340 | + $localize['action_cancel'] = __('Cancel', 'invoicing'); |
|
341 | 341 | |
342 | - $localize = apply_filters( 'wpinv_admin_js_localize', $localize ); |
|
342 | + $localize = apply_filters('wpinv_admin_js_localize', $localize); |
|
343 | 343 | |
344 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
344 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize); |
|
345 | 345 | |
346 | - if ( $page == 'wpinv-subscriptions' ) { |
|
347 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
348 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
346 | + if ($page == 'wpinv-subscriptions') { |
|
347 | + wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION); |
|
348 | + wp_enqueue_script('wpinv-sub-admin-script'); |
|
349 | 349 | } |
350 | 350 | } |
351 | 351 | |
352 | - public function admin_body_class( $classes ) { |
|
352 | + public function admin_body_class($classes) { |
|
353 | 353 | global $pagenow, $post, $current_screen; |
354 | 354 | |
355 | - if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote' ) ) { |
|
355 | + if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote')) { |
|
356 | 356 | $classes .= ' wpinv-cpt'; |
357 | 357 | } |
358 | 358 | |
359 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
359 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
360 | 360 | |
361 | - $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false; |
|
362 | - if ( $add_class ) { |
|
363 | - $classes .= ' wpi-' . wpinv_sanitize_key( $page ); |
|
361 | + $add_class = $page && $pagenow == 'admin.php' && strpos($page, 'wpinv-') === 0 ? true : false; |
|
362 | + if ($add_class) { |
|
363 | + $classes .= ' wpi-' . wpinv_sanitize_key($page); |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | $settings_class = array(); |
367 | - if ( $page == 'wpinv-settings' ) { |
|
368 | - if ( !empty( $_REQUEST['tab'] ) ) { |
|
369 | - $settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
367 | + if ($page == 'wpinv-settings') { |
|
368 | + if (!empty($_REQUEST['tab'])) { |
|
369 | + $settings_class[] = sanitize_text_field($_REQUEST['tab']); |
|
370 | 370 | } |
371 | 371 | |
372 | - if ( !empty( $_REQUEST['section'] ) ) { |
|
373 | - $settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
372 | + if (!empty($_REQUEST['section'])) { |
|
373 | + $settings_class[] = sanitize_text_field($_REQUEST['section']); |
|
374 | 374 | } |
375 | 375 | |
376 | - $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
376 | + $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main'; |
|
377 | 377 | } |
378 | 378 | |
379 | - if ( !empty( $settings_class ) ) { |
|
380 | - $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
379 | + if (!empty($settings_class)) { |
|
380 | + $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-')); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | $post_type = wpinv_admin_post_type(); |
384 | 384 | |
385 | - if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) { |
|
385 | + if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) { |
|
386 | 386 | return $classes .= ' wpinv'; |
387 | 387 | } |
388 | 388 | |
389 | - if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) { |
|
389 | + if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) { |
|
390 | 390 | $classes .= ' wpi-editable-n'; |
391 | 391 | } |
392 | 392 | |
@@ -398,20 +398,20 @@ discard block |
||
398 | 398 | } |
399 | 399 | |
400 | 400 | public function wpinv_actions() { |
401 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
402 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
401 | + if (isset($_REQUEST['wpi_action'])) { |
|
402 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
403 | 403 | } |
404 | 404 | } |
405 | 405 | |
406 | - public function pre_get_posts( $wp_query ) { |
|
407 | - if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
408 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
406 | + public function pre_get_posts($wp_query) { |
|
407 | + if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
408 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | return $wp_query; |
412 | 412 | } |
413 | 413 | |
414 | 414 | public function bp_invoicing_init() { |
415 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
415 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
416 | 416 | } |
417 | 417 | } |
418 | 418 | \ No newline at end of file |
@@ -29,7 +29,7 @@ |
||
29 | 29 | add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high' ); |
30 | 30 | add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' ); |
31 | 31 | |
32 | - remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal'); |
|
32 | + remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal'); |
|
33 | 33 | } |
34 | 34 | add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 ); |
35 | 35 |
@@ -1,67 +1,67 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | -function wpinv_add_meta_boxes( $post_type, $post ) { |
|
7 | +function wpinv_add_meta_boxes($post_type, $post) { |
|
8 | 8 | global $wpi_mb_invoice; |
9 | - if ( $post_type == 'wpi_invoice' && !empty( $post->ID ) ) { |
|
10 | - $wpi_mb_invoice = wpinv_get_invoice( $post->ID ); |
|
9 | + if ($post_type == 'wpi_invoice' && !empty($post->ID)) { |
|
10 | + $wpi_mb_invoice = wpinv_get_invoice($post->ID); |
|
11 | 11 | } |
12 | 12 | |
13 | - if ( !empty( $wpi_mb_invoice ) && !$wpi_mb_invoice->has_status( array( 'draft', 'auto-draft' ) ) ) { |
|
14 | - add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high' ); |
|
13 | + if (!empty($wpi_mb_invoice) && !$wpi_mb_invoice->has_status(array('draft', 'auto-draft'))) { |
|
14 | + add_meta_box('wpinv-mb-resend-invoice', __('Resend Invoice', 'invoicing'), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high'); |
|
15 | 15 | } |
16 | 16 | |
17 | - if ( !empty( $wpi_mb_invoice ) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent() ) { |
|
18 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscriptions', 'invoicing' ), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high' ); |
|
17 | + if (!empty($wpi_mb_invoice) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent()) { |
|
18 | + add_meta_box('wpinv-mb-subscriptions', __('Subscriptions', 'invoicing'), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high'); |
|
19 | 19 | } |
20 | 20 | |
21 | - if ( wpinv_is_subscription_payment( $wpi_mb_invoice ) ) { |
|
22 | - add_meta_box( 'wpinv-mb-renewals', __( 'Renewal Payment', 'invoicing' ), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high' ); |
|
21 | + if (wpinv_is_subscription_payment($wpi_mb_invoice)) { |
|
22 | + add_meta_box('wpinv-mb-renewals', __('Renewal Payment', 'invoicing'), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high'); |
|
23 | 23 | } |
24 | 24 | |
25 | - add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default' ); |
|
26 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default' ); |
|
25 | + add_meta_box('wpinv-details', __('Invoice Details', 'invoicing'), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default'); |
|
26 | + add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default'); |
|
27 | 27 | |
28 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high' ); |
|
29 | - add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high' ); |
|
30 | - add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' ); |
|
28 | + add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high'); |
|
29 | + add_meta_box('wpinv-items', __('Invoice Items', 'invoicing'), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high'); |
|
30 | + add_meta_box('wpinv-notes', __('Invoice Notes', 'invoicing'), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high'); |
|
31 | 31 | |
32 | 32 | remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal'); |
33 | 33 | } |
34 | -add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 ); |
|
34 | +add_action('add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2); |
|
35 | 35 | |
36 | -function wpinv_save_meta_boxes( $post_id, $post, $update = false ) { |
|
37 | - remove_action( 'save_post', __FUNCTION__ ); |
|
36 | +function wpinv_save_meta_boxes($post_id, $post, $update = false) { |
|
37 | + remove_action('save_post', __FUNCTION__); |
|
38 | 38 | |
39 | 39 | // $post_id and $post are required |
40 | - if ( empty( $post_id ) || empty( $post ) ) { |
|
40 | + if (empty($post_id) || empty($post)) { |
|
41 | 41 | return; |
42 | 42 | } |
43 | 43 | |
44 | - if ( !current_user_can( 'edit_post', $post_id ) || empty( $post->post_type ) ) { |
|
44 | + if (!current_user_can('edit_post', $post_id) || empty($post->post_type)) { |
|
45 | 45 | return; |
46 | 46 | } |
47 | 47 | |
48 | 48 | // Dont' save meta boxes for revisions or autosaves |
49 | - if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
49 | + if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
50 | 50 | return; |
51 | 51 | } |
52 | 52 | |
53 | - if ( $post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote' ) { |
|
54 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
53 | + if ($post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote') { |
|
54 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
55 | 55 | return; |
56 | 56 | } |
57 | 57 | |
58 | - if ( isset( $_POST['wpinv_save_invoice'] ) && wp_verify_nonce( $_POST['wpinv_save_invoice'], 'wpinv_save_invoice' ) ) { |
|
59 | - WPInv_Meta_Box_Items::save( $post_id, $_POST, $post ); |
|
58 | + if (isset($_POST['wpinv_save_invoice']) && wp_verify_nonce($_POST['wpinv_save_invoice'], 'wpinv_save_invoice')) { |
|
59 | + WPInv_Meta_Box_Items::save($post_id, $_POST, $post); |
|
60 | 60 | } |
61 | - } else if ( $post->post_type == 'wpi_item' ) { |
|
61 | + } else if ($post->post_type == 'wpi_item') { |
|
62 | 62 | // verify nonce |
63 | - if ( isset( $_POST['wpinv_vat_meta_box_nonce'] ) && wp_verify_nonce( $_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save' ) ) { |
|
64 | - $fields = array(); |
|
63 | + if (isset($_POST['wpinv_vat_meta_box_nonce']) && wp_verify_nonce($_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save')) { |
|
64 | + $fields = array(); |
|
65 | 65 | $fields['_wpinv_price'] = 'wpinv_item_price'; |
66 | 66 | $fields['_wpinv_vat_class'] = 'wpinv_vat_class'; |
67 | 67 | $fields['_wpinv_vat_rule'] = 'wpinv_vat_rules'; |
@@ -76,96 +76,96 @@ discard block |
||
76 | 76 | $fields['_wpinv_dynamic_pricing'] = 'wpinv_name_your_price'; |
77 | 77 | $fields['_minimum_price'] = 'wpinv_minimum_price'; |
78 | 78 | |
79 | - if ( !isset( $_POST['wpinv_is_recurring'] ) ) { |
|
79 | + if (!isset($_POST['wpinv_is_recurring'])) { |
|
80 | 80 | $_POST['wpinv_is_recurring'] = 0; |
81 | 81 | } |
82 | 82 | |
83 | - if ( !isset( $_POST['wpinv_name_your_price'] ) ) { |
|
83 | + if (!isset($_POST['wpinv_name_your_price'])) { |
|
84 | 84 | $_POST['wpinv_name_your_price'] = 0; |
85 | 85 | } |
86 | 86 | |
87 | - if ( !isset( $_POST['wpinv_free_trial'] ) || empty( $_POST['wpinv_is_recurring'] ) ) { |
|
87 | + if (!isset($_POST['wpinv_free_trial']) || empty($_POST['wpinv_is_recurring'])) { |
|
88 | 88 | $_POST['wpinv_free_trial'] = 0; |
89 | 89 | } |
90 | 90 | |
91 | - foreach ( $fields as $field => $name ) { |
|
92 | - if ( isset( $_POST[ $name ] ) ) { |
|
93 | - $allowed = apply_filters( 'wpinv_item_allowed_save_meta_value', true, $field, $post_id ); |
|
91 | + foreach ($fields as $field => $name) { |
|
92 | + if (isset($_POST[$name])) { |
|
93 | + $allowed = apply_filters('wpinv_item_allowed_save_meta_value', true, $field, $post_id); |
|
94 | 94 | |
95 | - if ( !$allowed ) { |
|
95 | + if (!$allowed) { |
|
96 | 96 | continue; |
97 | 97 | } |
98 | 98 | |
99 | - if ( $field == '_wpinv_price' ) { |
|
100 | - $value = wpinv_sanitize_amount( $_POST[ $name ] ); |
|
99 | + if ($field == '_wpinv_price') { |
|
100 | + $value = wpinv_sanitize_amount($_POST[$name]); |
|
101 | 101 | } else { |
102 | - $value = is_string( $_POST[ $name ] ) ? sanitize_text_field( $_POST[ $name ] ) : $_POST[ $name ]; |
|
102 | + $value = is_string($_POST[$name]) ? sanitize_text_field($_POST[$name]) : $_POST[$name]; |
|
103 | 103 | } |
104 | 104 | |
105 | - $value = apply_filters( 'wpinv_item_metabox_save_' . $field, $value, $name ); |
|
106 | - update_post_meta( $post_id, $field, $value ); |
|
105 | + $value = apply_filters('wpinv_item_metabox_save_' . $field, $value, $name); |
|
106 | + update_post_meta($post_id, $field, $value); |
|
107 | 107 | } |
108 | 108 | } |
109 | 109 | |
110 | - if ( !get_post_meta( $post_id, '_wpinv_custom_id', true ) ) { |
|
111 | - update_post_meta( $post_id, '_wpinv_custom_id', $post_id ); |
|
110 | + if (!get_post_meta($post_id, '_wpinv_custom_id', true)) { |
|
111 | + update_post_meta($post_id, '_wpinv_custom_id', $post_id); |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | } |
115 | 115 | } |
116 | -add_action( 'save_post', 'wpinv_save_meta_boxes', 10, 3 ); |
|
116 | +add_action('save_post', 'wpinv_save_meta_boxes', 10, 3); |
|
117 | 117 | |
118 | 118 | function wpinv_register_item_meta_boxes() { |
119 | 119 | global $wpinv_euvat; |
120 | 120 | |
121 | - add_meta_box( 'wpinv_field_prices', __( 'Item Price', 'invoicing' ), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high' ); |
|
121 | + add_meta_box('wpinv_field_prices', __('Item Price', 'invoicing'), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high'); |
|
122 | 122 | |
123 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
124 | - add_meta_box( 'wpinv_field_vat_rules', __( 'VAT rules type to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high' ); |
|
123 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
124 | + add_meta_box('wpinv_field_vat_rules', __('VAT rules type to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high'); |
|
125 | 125 | } |
126 | 126 | |
127 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
128 | - add_meta_box( 'wpinv_field_vat_classes', __( 'VAT rates class to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high' ); |
|
127 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
128 | + add_meta_box('wpinv_field_vat_classes', __('VAT rates class to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high'); |
|
129 | 129 | } |
130 | 130 | |
131 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core' ); |
|
132 | - add_meta_box( 'wpinv_field_meta_values', __( 'Item Meta Values', 'invoicing' ), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core' ); |
|
131 | + add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core'); |
|
132 | + add_meta_box('wpinv_field_meta_values', __('Item Meta Values', 'invoicing'), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core'); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | function wpinv_register_discount_meta_boxes() { |
136 | - add_meta_box( 'wpinv_discount_fields', __( 'Discount Details', 'invoicing' ), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high' ); |
|
136 | + add_meta_box('wpinv_discount_fields', __('Discount Details', 'invoicing'), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high'); |
|
137 | 137 | } |
138 | 138 | |
139 | -function wpinv_discount_metabox_details( $post ) { |
|
139 | +function wpinv_discount_metabox_details($post) { |
|
140 | 140 | $discount_id = $post->ID; |
141 | - $discount = wpinv_get_discount( $discount_id ); |
|
141 | + $discount = wpinv_get_discount($discount_id); |
|
142 | 142 | |
143 | - $type = wpinv_get_discount_type( $discount_id ); |
|
144 | - $item_reqs = wpinv_get_discount_item_reqs( $discount_id ); |
|
145 | - $excluded_items = wpinv_get_discount_excluded_items( $discount_id ); |
|
146 | - $min_total = wpinv_get_discount_min_total( $discount_id ); |
|
147 | - $max_total = wpinv_get_discount_max_total( $discount_id ); |
|
148 | - $max_uses = wpinv_get_discount_max_uses( $discount_id ); |
|
149 | - $single_use = wpinv_discount_is_single_use( $discount_id ); |
|
150 | - $recurring = (bool)wpinv_discount_is_recurring( $discount_id ); |
|
151 | - $start_date = wpinv_get_discount_start_date( $discount_id ); |
|
152 | - $expiration_date = wpinv_get_discount_expiration( $discount_id ); |
|
143 | + $type = wpinv_get_discount_type($discount_id); |
|
144 | + $item_reqs = wpinv_get_discount_item_reqs($discount_id); |
|
145 | + $excluded_items = wpinv_get_discount_excluded_items($discount_id); |
|
146 | + $min_total = wpinv_get_discount_min_total($discount_id); |
|
147 | + $max_total = wpinv_get_discount_max_total($discount_id); |
|
148 | + $max_uses = wpinv_get_discount_max_uses($discount_id); |
|
149 | + $single_use = wpinv_discount_is_single_use($discount_id); |
|
150 | + $recurring = (bool)wpinv_discount_is_recurring($discount_id); |
|
151 | + $start_date = wpinv_get_discount_start_date($discount_id); |
|
152 | + $expiration_date = wpinv_get_discount_expiration($discount_id); |
|
153 | 153 | |
154 | - if ( ! empty( $start_date ) && strpos( $start_date, '0000' ) === false ) { |
|
155 | - $start_time = strtotime( $start_date ); |
|
156 | - $start_h = date_i18n( 'H', $start_time ); |
|
157 | - $start_m = date_i18n( 'i', $start_time ); |
|
158 | - $start_date = date_i18n( 'Y-m-d', $start_time ); |
|
154 | + if (!empty($start_date) && strpos($start_date, '0000') === false) { |
|
155 | + $start_time = strtotime($start_date); |
|
156 | + $start_h = date_i18n('H', $start_time); |
|
157 | + $start_m = date_i18n('i', $start_time); |
|
158 | + $start_date = date_i18n('Y-m-d', $start_time); |
|
159 | 159 | } else { |
160 | 160 | $start_h = '00'; |
161 | 161 | $start_m = '00'; |
162 | 162 | } |
163 | 163 | |
164 | - if ( ! empty( $expiration_date ) && strpos( $expiration_date, '0000' ) === false ) { |
|
165 | - $expiration_time = strtotime( $expiration_date ); |
|
166 | - $expiration_h = date_i18n( 'H', $expiration_time ); |
|
167 | - $expiration_m = date_i18n( 'i', $expiration_time ); |
|
168 | - $expiration_date = date_i18n( 'Y-m-d', $expiration_time ); |
|
164 | + if (!empty($expiration_date) && strpos($expiration_date, '0000') === false) { |
|
165 | + $expiration_time = strtotime($expiration_date); |
|
166 | + $expiration_h = date_i18n('H', $expiration_time); |
|
167 | + $expiration_m = date_i18n('i', $expiration_time); |
|
168 | + $expiration_date = date_i18n('Y-m-d', $expiration_time); |
|
169 | 169 | } else { |
170 | 170 | $expiration_h = '23'; |
171 | 171 | $expiration_m = '59'; |
@@ -175,207 +175,207 @@ discard block |
||
175 | 175 | $max_total = $max_total > 0 ? $max_total : ''; |
176 | 176 | $max_uses = $max_uses > 0 ? $max_uses : ''; |
177 | 177 | ?> |
178 | -<?php do_action( 'wpinv_discount_form_top', $post ); ?> |
|
179 | -<?php wp_nonce_field( 'wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce' ); ;?> |
|
178 | +<?php do_action('wpinv_discount_form_top', $post); ?> |
|
179 | +<?php wp_nonce_field('wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce'); ;?> |
|
180 | 180 | <table class="form-table wpi-form-table"> |
181 | 181 | <tbody> |
182 | - <?php do_action( 'wpinv_discount_form_first', $post ); ?> |
|
183 | - <?php do_action( 'wpinv_discount_form_before_code', $post ); ?> |
|
182 | + <?php do_action('wpinv_discount_form_first', $post); ?> |
|
183 | + <?php do_action('wpinv_discount_form_before_code', $post); ?> |
|
184 | 184 | <tr> |
185 | 185 | <th valign="top" scope="row"> |
186 | - <label for="wpinv_discount_code"><?php _e( 'Discount Code', 'invoicing' ); ?></label> |
|
186 | + <label for="wpinv_discount_code"><?php _e('Discount Code', 'invoicing'); ?></label> |
|
187 | 187 | </th> |
188 | 188 | <td> |
189 | - <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr( wpinv_get_discount_code( $discount_id ) ); ?>" required> |
|
190 | - <p class="description"><?php _e( 'Enter a code for this discount, such as 10OFF', 'invoicing' ); ?></p> |
|
189 | + <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr(wpinv_get_discount_code($discount_id)); ?>" required> |
|
190 | + <p class="description"><?php _e('Enter a code for this discount, such as 10OFF', 'invoicing'); ?></p> |
|
191 | 191 | </td> |
192 | 192 | </tr> |
193 | - <?php do_action( 'wpinv_discount_form_before_type', $post ); ?> |
|
193 | + <?php do_action('wpinv_discount_form_before_type', $post); ?> |
|
194 | 194 | <tr> |
195 | 195 | <th valign="top" scope="row"> |
196 | - <label for="wpinv_discount_type"><?php _e( 'Discount Type', 'invoicing' ); ?></label> |
|
196 | + <label for="wpinv_discount_type"><?php _e('Discount Type', 'invoicing'); ?></label> |
|
197 | 197 | </th> |
198 | 198 | <td> |
199 | 199 | <select id="wpinv_discount_type" name="type" class="medium-text wpi_select2"> |
200 | - <?php foreach ( wpinv_get_discount_types() as $value => $label ) { ?> |
|
201 | - <option value="<?php echo $value ;?>" <?php selected( $type, $value ); ?>><?php echo $label; ?></option> |
|
200 | + <?php foreach (wpinv_get_discount_types() as $value => $label) { ?> |
|
201 | + <option value="<?php echo $value; ?>" <?php selected($type, $value); ?>><?php echo $label; ?></option> |
|
202 | 202 | <?php } ?> |
203 | 203 | </select> |
204 | - <p class="description"><?php _e( 'The kind of discount to apply for this discount.', 'invoicing' ); ?></p> |
|
204 | + <p class="description"><?php _e('The kind of discount to apply for this discount.', 'invoicing'); ?></p> |
|
205 | 205 | </td> |
206 | 206 | </tr> |
207 | - <?php do_action( 'wpinv_discount_form_before_amount', $post ); ?> |
|
207 | + <?php do_action('wpinv_discount_form_before_amount', $post); ?> |
|
208 | 208 | <tr> |
209 | 209 | <th valign="top" scope="row"> |
210 | - <label for="wpinv_discount_amount"><?php _e( 'Amount', 'invoicing' ); ?></label> |
|
210 | + <label for="wpinv_discount_amount"><?php _e('Amount', 'invoicing'); ?></label> |
|
211 | 211 | </th> |
212 | 212 | <td> |
213 | - <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr( wpinv_get_discount_amount( $discount_id ) ); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol() ;?></font> |
|
214 | - <p style="display:none;" class="description"><?php _e( 'Enter the discount amount in USD', 'invoicing' ); ?></p> |
|
215 | - <p class="description"><?php _e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?></p> |
|
213 | + <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr(wpinv_get_discount_amount($discount_id)); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol(); ?></font> |
|
214 | + <p style="display:none;" class="description"><?php _e('Enter the discount amount in USD', 'invoicing'); ?></p> |
|
215 | + <p class="description"><?php _e('Enter the discount value. Ex: 10', 'invoicing'); ?></p> |
|
216 | 216 | </td> |
217 | 217 | </tr> |
218 | - <?php do_action( 'wpinv_discount_form_before_items', $post ); ?> |
|
218 | + <?php do_action('wpinv_discount_form_before_items', $post); ?> |
|
219 | 219 | <tr> |
220 | 220 | <th valign="top" scope="row"> |
221 | - <label for="wpinv_discount_items"><?php _e( 'Items', 'invoicing' ); ?></label> |
|
221 | + <label for="wpinv_discount_items"><?php _e('Items', 'invoicing'); ?></label> |
|
222 | 222 | </th> |
223 | 223 | <td> |
224 | - <p><?php echo wpinv_item_dropdown( array( |
|
224 | + <p><?php echo wpinv_item_dropdown(array( |
|
225 | 225 | 'name' => 'items[]', |
226 | 226 | 'id' => 'items', |
227 | 227 | 'selected' => $item_reqs, |
228 | 228 | 'multiple' => true, |
229 | 229 | 'class' => 'medium-text wpi_select2', |
230 | - 'placeholder' => __( 'Select one or more Items', 'invoicing' ), |
|
230 | + 'placeholder' => __('Select one or more Items', 'invoicing'), |
|
231 | 231 | 'show_recurring' => true, |
232 | - ) ); ?> |
|
232 | + )); ?> |
|
233 | 233 | </p> |
234 | - <p class="description"><?php _e( 'Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing' ); ?></p> |
|
234 | + <p class="description"><?php _e('Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing'); ?></p> |
|
235 | 235 | </td> |
236 | 236 | </tr> |
237 | - <?php do_action( 'wpinv_discount_form_before_excluded_items', $post ); ?> |
|
237 | + <?php do_action('wpinv_discount_form_before_excluded_items', $post); ?> |
|
238 | 238 | <tr> |
239 | 239 | <th valign="top" scope="row"> |
240 | - <label for="wpinv_discount_excluded_items"><?php _e( 'Excluded Items', 'invoicing' ); ?></label> |
|
240 | + <label for="wpinv_discount_excluded_items"><?php _e('Excluded Items', 'invoicing'); ?></label> |
|
241 | 241 | </th> |
242 | 242 | <td> |
243 | - <p><?php echo wpinv_item_dropdown( array( |
|
243 | + <p><?php echo wpinv_item_dropdown(array( |
|
244 | 244 | 'name' => 'excluded_items[]', |
245 | 245 | 'id' => 'excluded_items', |
246 | 246 | 'selected' => $excluded_items, |
247 | 247 | 'multiple' => true, |
248 | 248 | 'class' => 'medium-text wpi_select2', |
249 | - 'placeholder' => __( 'Select one or more Items', 'invoicing' ), |
|
249 | + 'placeholder' => __('Select one or more Items', 'invoicing'), |
|
250 | 250 | 'show_recurring' => true, |
251 | - ) ); ?> |
|
251 | + )); ?> |
|
252 | 252 | </p> |
253 | - <p class="description"><?php _e( 'Items which are NOT allowed to use this discount.', 'invoicing' ); ?></p> |
|
253 | + <p class="description"><?php _e('Items which are NOT allowed to use this discount.', 'invoicing'); ?></p> |
|
254 | 254 | </td> |
255 | 255 | </tr> |
256 | - <?php do_action( 'wpinv_discount_form_before_start', $post ); ?> |
|
256 | + <?php do_action('wpinv_discount_form_before_start', $post); ?> |
|
257 | 257 | <tr> |
258 | 258 | <th valign="top" scope="row"> |
259 | - <label for="wpinv_discount_start"><?php _e( 'Start Date', 'invoicing' ); ?></label> |
|
259 | + <label for="wpinv_discount_start"><?php _e('Start Date', 'invoicing'); ?></label> |
|
260 | 260 | </th> |
261 | 261 | <td> |
262 | - <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr( $start_date ); ?>"> @ <select id="wpinv_discount_start_h" name="start_h"> |
|
263 | - <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
264 | - <option value="<?php echo $value;?>" <?php selected( $value, $start_h ); ?>><?php echo $value;?></option> |
|
262 | + <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr($start_date); ?>"> @ <select id="wpinv_discount_start_h" name="start_h"> |
|
263 | + <?php for ($i = 0; $i <= 23; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
264 | + <option value="<?php echo $value; ?>" <?php selected($value, $start_h); ?>><?php echo $value; ?></option> |
|
265 | 265 | <?php } ?> |
266 | 266 | </select> : <select id="wpinv_discount_start_m" name="start_m"> |
267 | - <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
268 | - <option value="<?php echo $value;?>" <?php selected( $value, $start_m ); ?>><?php echo $value;?></option> |
|
267 | + <?php for ($i = 0; $i <= 59; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
268 | + <option value="<?php echo $value; ?>" <?php selected($value, $start_m); ?>><?php echo $value; ?></option> |
|
269 | 269 | <?php } ?> |
270 | 270 | </select> |
271 | - <p class="description"><?php _e( 'Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?></p> |
|
271 | + <p class="description"><?php _e('Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing'); ?></p> |
|
272 | 272 | </td> |
273 | 273 | </tr> |
274 | - <?php do_action( 'wpinv_discount_form_before_expiration', $post ); ?> |
|
274 | + <?php do_action('wpinv_discount_form_before_expiration', $post); ?> |
|
275 | 275 | <tr> |
276 | 276 | <th valign="top" scope="row"> |
277 | - <label for="wpinv_discount_expiration"><?php _e( 'Expiration Date', 'invoicing' ); ?></label> |
|
277 | + <label for="wpinv_discount_expiration"><?php _e('Expiration Date', 'invoicing'); ?></label> |
|
278 | 278 | </th> |
279 | 279 | <td> |
280 | - <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr( $expiration_date ); ?>"> @ <select id="wpinv_discount_expiration_h" name="expiration_h"> |
|
281 | - <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
282 | - <option value="<?php echo $value;?>" <?php selected( $value, $expiration_h ); ?>><?php echo $value;?></option> |
|
280 | + <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr($expiration_date); ?>"> @ <select id="wpinv_discount_expiration_h" name="expiration_h"> |
|
281 | + <?php for ($i = 0; $i <= 23; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
282 | + <option value="<?php echo $value; ?>" <?php selected($value, $expiration_h); ?>><?php echo $value; ?></option> |
|
283 | 283 | <?php } ?> |
284 | 284 | </select> : <select id="wpinv_discount_expiration_m" name="expiration_m"> |
285 | - <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
286 | - <option value="<?php echo $value;?>" <?php selected( $value, $expiration_m ); ?>><?php echo $value;?></option> |
|
285 | + <?php for ($i = 0; $i <= 59; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
286 | + <option value="<?php echo $value; ?>" <?php selected($value, $expiration_m); ?>><?php echo $value; ?></option> |
|
287 | 287 | <?php } ?> |
288 | 288 | </select> |
289 | - <p class="description"><?php _e( 'Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing' ); ?></p> |
|
289 | + <p class="description"><?php _e('Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing'); ?></p> |
|
290 | 290 | </td> |
291 | 291 | </tr> |
292 | - <?php do_action( 'wpinv_discount_form_before_min_total', $post ); ?> |
|
292 | + <?php do_action('wpinv_discount_form_before_min_total', $post); ?> |
|
293 | 293 | <tr> |
294 | 294 | <th valign="top" scope="row"> |
295 | - <label for="wpinv_discount_min_total"><?php _e( 'Minimum Amount', 'invoicing' ); ?></label> |
|
295 | + <label for="wpinv_discount_min_total"><?php _e('Minimum Amount', 'invoicing'); ?></label> |
|
296 | 296 | </th> |
297 | 297 | <td> |
298 | 298 | <input type="text" name="min_total" id="wpinv_discount_min_total" class="wpi-field-price wpi-price" value="<?php echo $min_total; ?>"> |
299 | - <p class="description"><?php _e( 'This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p> |
|
299 | + <p class="description"><?php _e('This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p> |
|
300 | 300 | </td> |
301 | 301 | </tr> |
302 | - <?php do_action( 'wpinv_discount_form_before_max_total', $post ); ?> |
|
302 | + <?php do_action('wpinv_discount_form_before_max_total', $post); ?> |
|
303 | 303 | <tr> |
304 | 304 | <th valign="top" scope="row"> |
305 | - <label for="wpinv_discount_max_total"><?php _e( 'Maximum Amount', 'invoicing' ); ?></label> |
|
305 | + <label for="wpinv_discount_max_total"><?php _e('Maximum Amount', 'invoicing'); ?></label> |
|
306 | 306 | </th> |
307 | 307 | <td> |
308 | 308 | <input type="text" name="max_total" id="wpinv_discount_max_total" class="wpi-field-price wpi-price" value="<?php echo $max_total; ?>"> |
309 | - <p class="description"><?php _e( 'This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p> |
|
309 | + <p class="description"><?php _e('This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p> |
|
310 | 310 | </td> |
311 | 311 | </tr> |
312 | - <?php do_action( 'wpinv_discount_form_before_recurring', $post ); ?> |
|
312 | + <?php do_action('wpinv_discount_form_before_recurring', $post); ?> |
|
313 | 313 | <tr> |
314 | 314 | <th valign="top" scope="row"> |
315 | - <label for="wpinv_discount_recurring"><?php _e( 'For recurring apply to', 'invoicing' ); ?></label> |
|
315 | + <label for="wpinv_discount_recurring"><?php _e('For recurring apply to', 'invoicing'); ?></label> |
|
316 | 316 | </th> |
317 | 317 | <td> |
318 | 318 | <select id="wpinv_discount_recurring" name="recurring" class="medium-text wpi_select2"> |
319 | - <option value="0" <?php selected( false, $recurring ); ?>><?php _e( 'All payments', 'invoicing' ); ?></option> |
|
320 | - <option value="1" <?php selected( true, $recurring ); ?>><?php _e( 'First payment only', 'invoicing' ); ?></option> |
|
319 | + <option value="0" <?php selected(false, $recurring); ?>><?php _e('All payments', 'invoicing'); ?></option> |
|
320 | + <option value="1" <?php selected(true, $recurring); ?>><?php _e('First payment only', 'invoicing'); ?></option> |
|
321 | 321 | </select> |
322 | - <p class="description"><?php _e( '<b>All payments:</b> Apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> Apply this discount to only first payment of the recurring invoice.', 'invoicing' ); ?></p> |
|
322 | + <p class="description"><?php _e('<b>All payments:</b> Apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> Apply this discount to only first payment of the recurring invoice.', 'invoicing'); ?></p> |
|
323 | 323 | </td> |
324 | 324 | </tr> |
325 | - <?php do_action( 'wpinv_discount_form_before_max_uses', $post ); ?> |
|
325 | + <?php do_action('wpinv_discount_form_before_max_uses', $post); ?> |
|
326 | 326 | <tr> |
327 | 327 | <th valign="top" scope="row"> |
328 | - <label for="wpinv_discount_max_uses"><?php _e( 'Max Uses', 'invoicing' ); ?></label> |
|
328 | + <label for="wpinv_discount_max_uses"><?php _e('Max Uses', 'invoicing'); ?></label> |
|
329 | 329 | </th> |
330 | 330 | <td> |
331 | 331 | <input type="number" min="0" step="1" id="wpinv_discount_max_uses" name="max_uses" class="medium-text" value="<?php echo $max_uses; ?>"> |
332 | - <p class="description"><?php _e( 'The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing' ); ?></p> |
|
332 | + <p class="description"><?php _e('The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing'); ?></p> |
|
333 | 333 | </td> |
334 | 334 | </tr> |
335 | - <?php do_action( 'wpinv_discount_form_before_single_use', $post ); ?> |
|
335 | + <?php do_action('wpinv_discount_form_before_single_use', $post); ?> |
|
336 | 336 | <tr> |
337 | 337 | <th valign="top" scope="row"> |
338 | - <label for="wpinv_discount_single_use"><?php _e( 'Use Once Per User', 'invoicing' ); ?></label> |
|
338 | + <label for="wpinv_discount_single_use"><?php _e('Use Once Per User', 'invoicing'); ?></label> |
|
339 | 339 | </th> |
340 | 340 | <td> |
341 | - <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked( true, $single_use ); ?>> |
|
342 | - <span class="description"><?php _e( 'Limit this discount to a single use per user?', 'invoicing' ); ?></span> |
|
341 | + <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked(true, $single_use); ?>> |
|
342 | + <span class="description"><?php _e('Limit this discount to a single use per user?', 'invoicing'); ?></span> |
|
343 | 343 | </td> |
344 | 344 | </tr> |
345 | - <?php do_action( 'wpinv_discount_form_last', $post ); ?> |
|
345 | + <?php do_action('wpinv_discount_form_last', $post); ?> |
|
346 | 346 | </tbody> |
347 | 347 | </table> |
348 | -<?php do_action( 'wpinv_discount_form_bottom', $post ); ?> |
|
348 | +<?php do_action('wpinv_discount_form_bottom', $post); ?> |
|
349 | 349 | <?php |
350 | 350 | } |
351 | 351 | |
352 | -function wpinv_discount_metabox_save( $post_id, $post, $update = false ) { |
|
353 | - $post_type = !empty( $post ) ? $post->post_type : ''; |
|
352 | +function wpinv_discount_metabox_save($post_id, $post, $update = false) { |
|
353 | + $post_type = !empty($post) ? $post->post_type : ''; |
|
354 | 354 | |
355 | - if ( $post_type != 'wpi_discount' ) { |
|
355 | + if ($post_type != 'wpi_discount') { |
|
356 | 356 | return; |
357 | 357 | } |
358 | 358 | |
359 | - if ( !isset( $_POST['wpinv_discount_metabox_nonce'] ) || ( isset( $_POST['wpinv_discount_metabox_nonce'] ) && !wp_verify_nonce( $_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce' ) ) ) { |
|
359 | + if (!isset($_POST['wpinv_discount_metabox_nonce']) || (isset($_POST['wpinv_discount_metabox_nonce']) && !wp_verify_nonce($_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce'))) { |
|
360 | 360 | return; |
361 | 361 | } |
362 | 362 | |
363 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
363 | + if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
364 | 364 | return; |
365 | 365 | } |
366 | 366 | |
367 | - if ( !current_user_can( 'manage_options', $post_id ) ) { |
|
367 | + if (!current_user_can('manage_options', $post_id)) { |
|
368 | 368 | return; |
369 | 369 | } |
370 | 370 | |
371 | - if ( !empty( $_POST['start'] ) && isset( $_POST['start_h'] ) && isset( $_POST['start_m'] ) && $_POST['start_h'] !== '' && $_POST['start_m'] !== '' ) { |
|
371 | + if (!empty($_POST['start']) && isset($_POST['start_h']) && isset($_POST['start_m']) && $_POST['start_h'] !== '' && $_POST['start_m'] !== '') { |
|
372 | 372 | $_POST['start'] = $_POST['start'] . ' ' . $_POST['start_h'] . ':' . $_POST['start_m']; |
373 | 373 | } |
374 | 374 | |
375 | - if ( !empty( $_POST['expiration'] ) && isset( $_POST['expiration_h'] ) && isset( $_POST['expiration_m'] ) ) { |
|
375 | + if (!empty($_POST['expiration']) && isset($_POST['expiration_h']) && isset($_POST['expiration_m'])) { |
|
376 | 376 | $_POST['expiration'] = $_POST['expiration'] . ' ' . $_POST['expiration_h'] . ':' . $_POST['expiration_m']; |
377 | 377 | } |
378 | 378 | |
379 | - return wpinv_store_discount( $post_id, $_POST, $post, $update ); |
|
379 | + return wpinv_store_discount($post_id, $_POST, $post, $update); |
|
380 | 380 | } |
381 | -add_action( 'save_post', 'wpinv_discount_metabox_save', 10, 3 ); |
|
382 | 381 | \ No newline at end of file |
382 | +add_action('save_post', 'wpinv_discount_metabox_save', 10, 3); |
|
383 | 383 | \ No newline at end of file |