@@ -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 == 'addons' || $current_tab =='gateways') ? 'addons' : $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 == 'addons' || $current_tab =='gateways') ? 'addons' : $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 | // print_r($button_args); |
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,33 +246,33 @@ 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', |
274 | - 'name' => 'Quotes', |
|
275 | - 'thumbnail' => 'https://ps.w.org/invoicing-quotes/assets/banner-772x250.jpg', |
|
274 | + 'name' => 'Quotes', |
|
275 | + 'thumbnail' => 'https://ps.w.org/invoicing-quotes/assets/banner-772x250.jpg', |
|
276 | 276 | 'desc' => __('Allows you to create quotes, send them to clients and convert them to Invoices when accepted by the customer.','invoicing'), |
277 | 277 | ), |
278 | 278 | 'geodirectory' => array( |
@@ -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 | } |
@@ -1355,10 +1355,10 @@ |
||
1355 | 1355 | $data['cart_details'][$key]['price'] = wpinv_round_amount( $item_total ); |
1356 | 1356 | } |
1357 | 1357 | |
1358 | - $total = $data['subtotal'] - $data['discount'] + $data['tax']; |
|
1359 | - if ( $total < 0 ) { |
|
1360 | - $total = 0; |
|
1361 | - } |
|
1358 | + $total = $data['subtotal'] - $data['discount'] + $data['tax']; |
|
1359 | + if ( $total < 0 ) { |
|
1360 | + $total = 0; |
|
1361 | + } |
|
1362 | 1362 | |
1363 | 1363 | $data['subtotal'] = wpinv_round_amount( $cart_subtotal ); |
1364 | 1364 | $data['discount'] = wpinv_round_amount( $cart_discount ); |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | // Load WP_List_Table if not loaded |
11 | 11 | if ( ! class_exists( 'WP_List_Table' ) ) { |
12 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
12 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | /** |
@@ -21,145 +21,145 @@ discard block |
||
21 | 21 | */ |
22 | 22 | class WPInv_Taxes_Reports_Table extends WP_List_Table { |
23 | 23 | |
24 | - /** |
|
25 | - * @var int Number of items per page |
|
26 | - * @since 1.0.19 |
|
27 | - */ |
|
28 | - public $per_page = 300; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * Get things started |
|
33 | - * |
|
34 | - * @since 1.0.19 |
|
35 | - * @see WP_List_Table::__construct() |
|
36 | - */ |
|
37 | - public function __construct() { |
|
38 | - |
|
39 | - // Set parent defaults |
|
40 | - parent::__construct( array( |
|
41 | - 'singular' => 'id', |
|
42 | - 'plural' => 'ids', |
|
43 | - 'ajax' => false, |
|
44 | - ) ); |
|
45 | - |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Gets the name of the primary column. |
|
50 | - * |
|
51 | - * @since 1.0.19 |
|
52 | - * @access protected |
|
53 | - * |
|
54 | - * @return string Name of the primary column. |
|
55 | - */ |
|
56 | - protected function get_primary_column_name() { |
|
57 | - return 'month'; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * This function renders most of the columns in the list table. |
|
62 | - * |
|
63 | - * @since 1.0.19 |
|
64 | - * |
|
65 | - * @param array $item Contains all the data of the gateways |
|
66 | - * @param string $column_name The name of the column |
|
67 | - * |
|
68 | - * @return string Column Name |
|
69 | - */ |
|
70 | - public function column_default( $item, $column_name ) { |
|
71 | - return esc_html( $item[ $column_name ] ); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Retrieve the table columns |
|
76 | - * |
|
77 | - * @since 1.0.19 |
|
78 | - * @return array $columns Array of all the list table columns |
|
79 | - */ |
|
80 | - public function get_columns() { |
|
81 | - |
|
82 | - return array( |
|
83 | - 'month' => __( 'Month', 'invoicing' ), |
|
84 | - 'tax' => __( 'Total Taxes', 'invoicing' ), |
|
85 | - ); |
|
86 | - |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Retrieve the current page number |
|
91 | - * |
|
92 | - * @since 1.0.19 |
|
93 | - * @return int Current page number |
|
94 | - */ |
|
95 | - public function get_paged() { |
|
96 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Outputs the reporting views |
|
101 | - * |
|
102 | - * @since 1.0.19 |
|
103 | - * @return void |
|
104 | - */ |
|
105 | - public function bulk_actions( $which = '' ) { |
|
106 | - return array(); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Build all the reports data |
|
111 | - * |
|
112 | - * @since 1.0.19 |
|
113 | - * @return array $reports_data All the data for taxes reports |
|
114 | - */ |
|
115 | - public function reports_data() { |
|
116 | - |
|
117 | - $reports_data = $this->taxes_reports_data(); |
|
118 | - $months = array( |
|
119 | - '1' => __( 'January', 'invoicing' ), |
|
120 | - '2' => __( 'February', 'invoicing' ), |
|
121 | - '3' => __( 'March', 'invoicing' ), |
|
122 | - '4' => __( 'April', 'invoicing' ), |
|
123 | - '5' => __( 'May', 'invoicing' ), |
|
124 | - '6' => __( 'June', 'invoicing' ), |
|
125 | - '7' => __( 'July', 'invoicing' ), |
|
126 | - '8' => __( 'August', 'invoicing' ), |
|
127 | - '9' => __( 'September', 'invoicing' ), |
|
128 | - '10' => __( 'October', 'invoicing' ), |
|
129 | - '11' => __( 'November', 'invoicing' ), |
|
130 | - '12' => __( 'December', 'invoicing' ), |
|
131 | - ); |
|
132 | - |
|
133 | - $prepared = array(); |
|
134 | - foreach ( $months as $month => $label ) { |
|
135 | - |
|
136 | - $tax = wpinv_price( 0 ); |
|
137 | - if ( ! empty( $reports_data[ $month ] ) ) { |
|
138 | - $tax = wpinv_price( wpinv_format_amount( $reports_data[ $month ] ) ); |
|
139 | - } |
|
140 | - |
|
141 | - $prepared[] = array( |
|
142 | - 'month' => $label, |
|
143 | - 'tax' => $tax, |
|
144 | - ); |
|
145 | - |
|
146 | - } |
|
147 | - |
|
148 | - return $prepared; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Retrieves taxes data. |
|
153 | - * |
|
154 | - * @since 1.0.19 |
|
155 | - */ |
|
156 | - public function taxes_reports_data() { |
|
157 | - global $wpdb; |
|
158 | - |
|
159 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
160 | - $year = isset( $_GET['year'] ) ? absint( $_GET['year'] ) : date( 'Y' ); |
|
161 | - $data = $wpdb->get_results( |
|
162 | - "SELECT |
|
24 | + /** |
|
25 | + * @var int Number of items per page |
|
26 | + * @since 1.0.19 |
|
27 | + */ |
|
28 | + public $per_page = 300; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * Get things started |
|
33 | + * |
|
34 | + * @since 1.0.19 |
|
35 | + * @see WP_List_Table::__construct() |
|
36 | + */ |
|
37 | + public function __construct() { |
|
38 | + |
|
39 | + // Set parent defaults |
|
40 | + parent::__construct( array( |
|
41 | + 'singular' => 'id', |
|
42 | + 'plural' => 'ids', |
|
43 | + 'ajax' => false, |
|
44 | + ) ); |
|
45 | + |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Gets the name of the primary column. |
|
50 | + * |
|
51 | + * @since 1.0.19 |
|
52 | + * @access protected |
|
53 | + * |
|
54 | + * @return string Name of the primary column. |
|
55 | + */ |
|
56 | + protected function get_primary_column_name() { |
|
57 | + return 'month'; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * This function renders most of the columns in the list table. |
|
62 | + * |
|
63 | + * @since 1.0.19 |
|
64 | + * |
|
65 | + * @param array $item Contains all the data of the gateways |
|
66 | + * @param string $column_name The name of the column |
|
67 | + * |
|
68 | + * @return string Column Name |
|
69 | + */ |
|
70 | + public function column_default( $item, $column_name ) { |
|
71 | + return esc_html( $item[ $column_name ] ); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Retrieve the table columns |
|
76 | + * |
|
77 | + * @since 1.0.19 |
|
78 | + * @return array $columns Array of all the list table columns |
|
79 | + */ |
|
80 | + public function get_columns() { |
|
81 | + |
|
82 | + return array( |
|
83 | + 'month' => __( 'Month', 'invoicing' ), |
|
84 | + 'tax' => __( 'Total Taxes', 'invoicing' ), |
|
85 | + ); |
|
86 | + |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Retrieve the current page number |
|
91 | + * |
|
92 | + * @since 1.0.19 |
|
93 | + * @return int Current page number |
|
94 | + */ |
|
95 | + public function get_paged() { |
|
96 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Outputs the reporting views |
|
101 | + * |
|
102 | + * @since 1.0.19 |
|
103 | + * @return void |
|
104 | + */ |
|
105 | + public function bulk_actions( $which = '' ) { |
|
106 | + return array(); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Build all the reports data |
|
111 | + * |
|
112 | + * @since 1.0.19 |
|
113 | + * @return array $reports_data All the data for taxes reports |
|
114 | + */ |
|
115 | + public function reports_data() { |
|
116 | + |
|
117 | + $reports_data = $this->taxes_reports_data(); |
|
118 | + $months = array( |
|
119 | + '1' => __( 'January', 'invoicing' ), |
|
120 | + '2' => __( 'February', 'invoicing' ), |
|
121 | + '3' => __( 'March', 'invoicing' ), |
|
122 | + '4' => __( 'April', 'invoicing' ), |
|
123 | + '5' => __( 'May', 'invoicing' ), |
|
124 | + '6' => __( 'June', 'invoicing' ), |
|
125 | + '7' => __( 'July', 'invoicing' ), |
|
126 | + '8' => __( 'August', 'invoicing' ), |
|
127 | + '9' => __( 'September', 'invoicing' ), |
|
128 | + '10' => __( 'October', 'invoicing' ), |
|
129 | + '11' => __( 'November', 'invoicing' ), |
|
130 | + '12' => __( 'December', 'invoicing' ), |
|
131 | + ); |
|
132 | + |
|
133 | + $prepared = array(); |
|
134 | + foreach ( $months as $month => $label ) { |
|
135 | + |
|
136 | + $tax = wpinv_price( 0 ); |
|
137 | + if ( ! empty( $reports_data[ $month ] ) ) { |
|
138 | + $tax = wpinv_price( wpinv_format_amount( $reports_data[ $month ] ) ); |
|
139 | + } |
|
140 | + |
|
141 | + $prepared[] = array( |
|
142 | + 'month' => $label, |
|
143 | + 'tax' => $tax, |
|
144 | + ); |
|
145 | + |
|
146 | + } |
|
147 | + |
|
148 | + return $prepared; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Retrieves taxes data. |
|
153 | + * |
|
154 | + * @since 1.0.19 |
|
155 | + */ |
|
156 | + public function taxes_reports_data() { |
|
157 | + global $wpdb; |
|
158 | + |
|
159 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
160 | + $year = isset( $_GET['year'] ) ? absint( $_GET['year'] ) : date( 'Y' ); |
|
161 | + $data = $wpdb->get_results( |
|
162 | + "SELECT |
|
163 | 163 | MONTH(meta.completed_date) as _month, |
164 | 164 | SUM(meta.tax) as tax |
165 | 165 | FROM $wpdb->posts as posts |
@@ -171,21 +171,21 @@ discard block |
||
171 | 171 | AND ( YEAR(meta.completed_date) = '$year' ) |
172 | 172 | GROUP BY MONTH(meta.completed_date)"); |
173 | 173 | |
174 | - return wp_list_pluck( $data, 'tax', '_month' ); |
|
175 | - |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Setup the final data for the table |
|
180 | - * |
|
181 | - * @since 1.0.19 |
|
182 | - * @return void |
|
183 | - */ |
|
184 | - public function prepare_items() { |
|
185 | - $columns = $this->get_columns(); |
|
186 | - $hidden = array(); // No hidden columns |
|
187 | - $sortable = $this->get_sortable_columns(); |
|
188 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
189 | - $this->items = $this->reports_data(); |
|
190 | - } |
|
174 | + return wp_list_pluck( $data, 'tax', '_month' ); |
|
175 | + |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Setup the final data for the table |
|
180 | + * |
|
181 | + * @since 1.0.19 |
|
182 | + * @return void |
|
183 | + */ |
|
184 | + public function prepare_items() { |
|
185 | + $columns = $this->get_columns(); |
|
186 | + $hidden = array(); // No hidden columns |
|
187 | + $sortable = $this->get_sortable_columns(); |
|
188 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
189 | + $this->items = $this->reports_data(); |
|
190 | + } |
|
191 | 191 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | // Load WP_List_Table if not loaded |
11 | 11 | if ( ! class_exists( 'WP_List_Table' ) ) { |
12 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
12 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | /** |
@@ -21,148 +21,148 @@ discard block |
||
21 | 21 | */ |
22 | 22 | class WPInv_Gateways_Report_Table extends WP_List_Table { |
23 | 23 | |
24 | - /** |
|
25 | - * @var int Number of items per page |
|
26 | - * @since 1.0.19 |
|
27 | - */ |
|
28 | - public $per_page = 300; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * Get things started |
|
33 | - * |
|
34 | - * @since 1.0.19 |
|
35 | - * @see WP_List_Table::__construct() |
|
36 | - */ |
|
37 | - public function __construct() { |
|
38 | - |
|
39 | - // Set parent defaults |
|
40 | - parent::__construct( array( |
|
41 | - 'singular' => 'id', |
|
42 | - 'plural' => 'ids', |
|
43 | - 'ajax' => false, |
|
44 | - ) ); |
|
45 | - |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Gets the name of the primary column. |
|
50 | - * |
|
51 | - * @since 1.0.19 |
|
52 | - * @access protected |
|
53 | - * |
|
54 | - * @return string Name of the primary column. |
|
55 | - */ |
|
56 | - protected function get_primary_column_name() { |
|
57 | - return 'gateway'; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * This function renders most of the columns in the list table. |
|
62 | - * |
|
63 | - * @since 1.0.19 |
|
64 | - * |
|
65 | - * @param array $item Contains all the data of the gateways |
|
66 | - * @param string $column_name The name of the column |
|
67 | - * |
|
68 | - * @return string Column Name |
|
69 | - */ |
|
70 | - public function column_default( $item, $column_name ) { |
|
71 | - return esc_html( $item[ $column_name ] ); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Retrieve the table columns |
|
76 | - * |
|
77 | - * @since 1.0.19 |
|
78 | - * @return array $columns Array of all the list table columns |
|
79 | - */ |
|
80 | - public function get_columns() { |
|
81 | - |
|
82 | - return array( |
|
83 | - 'gateway' => __( 'Gateway', 'invoicing' ), |
|
84 | - 'sales' => __( 'Total Sales', 'invoicing' ), |
|
85 | - 'total' => __( 'Total Earnings', 'invoicing' ), |
|
86 | - 'discount' => __( 'Total Discounts', 'invoicing' ), |
|
87 | - 'tax' => __( 'Total Taxes', 'invoicing' ), |
|
88 | - 'fees' => __( 'Total Fees', 'invoicing' ), |
|
89 | - ); |
|
90 | - |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Retrieve the current page number |
|
95 | - * |
|
96 | - * @since 1.0.19 |
|
97 | - * @return int Current page number |
|
98 | - */ |
|
99 | - public function get_paged() { |
|
100 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Outputs the reporting views |
|
105 | - * |
|
106 | - * @since 1.0.19 |
|
107 | - * @return void |
|
108 | - */ |
|
109 | - public function bulk_actions( $which = '' ) { |
|
110 | - return array(); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Build all the reports data |
|
115 | - * |
|
116 | - * @since 1.0.19 |
|
117 | - * @return array $reports_data All the data for gateway reports |
|
118 | - */ |
|
119 | - public function reports_data() { |
|
120 | - |
|
121 | - $reports_data = $this->revenue_reports_data(); |
|
122 | - $gateways = wpinv_get_payment_gateways(); |
|
123 | - |
|
124 | - foreach ( $gateways as $gateway_id => $gateway ) { |
|
125 | - |
|
126 | - if ( ! empty( $reports_data[ $gateway_id ] ) ) { |
|
127 | - continue; |
|
128 | - } |
|
129 | - |
|
130 | - $reports_data[] = array( |
|
131 | - 'gateway' => $gateway_id, |
|
132 | - 'sales' => 0, |
|
133 | - 'total' => 0, |
|
134 | - 'discount' => 0, |
|
135 | - 'tax' => 0, |
|
136 | - 'fees' => 0, |
|
137 | - ); |
|
138 | - } |
|
139 | - |
|
140 | - $prepared = array(); |
|
141 | - foreach ( $reports_data as $report_data ) { |
|
142 | - $prepared[] = array( |
|
143 | - 'gateway' => wpinv_get_gateway_admin_label( $report_data['gateway'] ), |
|
144 | - 'sales' => $report_data['sales'], |
|
145 | - 'total' => wpinv_price( wpinv_format_amount( $report_data['total'] ) ), |
|
146 | - 'discount' => wpinv_price( wpinv_format_amount( $report_data['discount'] ) ), |
|
147 | - 'tax' => wpinv_price( wpinv_format_amount( $report_data['tax'] ) ), |
|
148 | - 'fees' => wpinv_price( wpinv_format_amount( $report_data['fees'] ) ), |
|
149 | - ); |
|
150 | - } |
|
151 | - |
|
152 | - return $prepared; |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Retrieves report data. |
|
157 | - * |
|
158 | - * @since 1.0.19 |
|
159 | - */ |
|
160 | - public function revenue_reports_data() { |
|
161 | - global $wpdb; |
|
162 | - |
|
163 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
164 | - $data = $wpdb->get_results( |
|
165 | - "SELECT |
|
24 | + /** |
|
25 | + * @var int Number of items per page |
|
26 | + * @since 1.0.19 |
|
27 | + */ |
|
28 | + public $per_page = 300; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * Get things started |
|
33 | + * |
|
34 | + * @since 1.0.19 |
|
35 | + * @see WP_List_Table::__construct() |
|
36 | + */ |
|
37 | + public function __construct() { |
|
38 | + |
|
39 | + // Set parent defaults |
|
40 | + parent::__construct( array( |
|
41 | + 'singular' => 'id', |
|
42 | + 'plural' => 'ids', |
|
43 | + 'ajax' => false, |
|
44 | + ) ); |
|
45 | + |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Gets the name of the primary column. |
|
50 | + * |
|
51 | + * @since 1.0.19 |
|
52 | + * @access protected |
|
53 | + * |
|
54 | + * @return string Name of the primary column. |
|
55 | + */ |
|
56 | + protected function get_primary_column_name() { |
|
57 | + return 'gateway'; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * This function renders most of the columns in the list table. |
|
62 | + * |
|
63 | + * @since 1.0.19 |
|
64 | + * |
|
65 | + * @param array $item Contains all the data of the gateways |
|
66 | + * @param string $column_name The name of the column |
|
67 | + * |
|
68 | + * @return string Column Name |
|
69 | + */ |
|
70 | + public function column_default( $item, $column_name ) { |
|
71 | + return esc_html( $item[ $column_name ] ); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Retrieve the table columns |
|
76 | + * |
|
77 | + * @since 1.0.19 |
|
78 | + * @return array $columns Array of all the list table columns |
|
79 | + */ |
|
80 | + public function get_columns() { |
|
81 | + |
|
82 | + return array( |
|
83 | + 'gateway' => __( 'Gateway', 'invoicing' ), |
|
84 | + 'sales' => __( 'Total Sales', 'invoicing' ), |
|
85 | + 'total' => __( 'Total Earnings', 'invoicing' ), |
|
86 | + 'discount' => __( 'Total Discounts', 'invoicing' ), |
|
87 | + 'tax' => __( 'Total Taxes', 'invoicing' ), |
|
88 | + 'fees' => __( 'Total Fees', 'invoicing' ), |
|
89 | + ); |
|
90 | + |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Retrieve the current page number |
|
95 | + * |
|
96 | + * @since 1.0.19 |
|
97 | + * @return int Current page number |
|
98 | + */ |
|
99 | + public function get_paged() { |
|
100 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Outputs the reporting views |
|
105 | + * |
|
106 | + * @since 1.0.19 |
|
107 | + * @return void |
|
108 | + */ |
|
109 | + public function bulk_actions( $which = '' ) { |
|
110 | + return array(); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Build all the reports data |
|
115 | + * |
|
116 | + * @since 1.0.19 |
|
117 | + * @return array $reports_data All the data for gateway reports |
|
118 | + */ |
|
119 | + public function reports_data() { |
|
120 | + |
|
121 | + $reports_data = $this->revenue_reports_data(); |
|
122 | + $gateways = wpinv_get_payment_gateways(); |
|
123 | + |
|
124 | + foreach ( $gateways as $gateway_id => $gateway ) { |
|
125 | + |
|
126 | + if ( ! empty( $reports_data[ $gateway_id ] ) ) { |
|
127 | + continue; |
|
128 | + } |
|
129 | + |
|
130 | + $reports_data[] = array( |
|
131 | + 'gateway' => $gateway_id, |
|
132 | + 'sales' => 0, |
|
133 | + 'total' => 0, |
|
134 | + 'discount' => 0, |
|
135 | + 'tax' => 0, |
|
136 | + 'fees' => 0, |
|
137 | + ); |
|
138 | + } |
|
139 | + |
|
140 | + $prepared = array(); |
|
141 | + foreach ( $reports_data as $report_data ) { |
|
142 | + $prepared[] = array( |
|
143 | + 'gateway' => wpinv_get_gateway_admin_label( $report_data['gateway'] ), |
|
144 | + 'sales' => $report_data['sales'], |
|
145 | + 'total' => wpinv_price( wpinv_format_amount( $report_data['total'] ) ), |
|
146 | + 'discount' => wpinv_price( wpinv_format_amount( $report_data['discount'] ) ), |
|
147 | + 'tax' => wpinv_price( wpinv_format_amount( $report_data['tax'] ) ), |
|
148 | + 'fees' => wpinv_price( wpinv_format_amount( $report_data['fees'] ) ), |
|
149 | + ); |
|
150 | + } |
|
151 | + |
|
152 | + return $prepared; |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Retrieves report data. |
|
157 | + * |
|
158 | + * @since 1.0.19 |
|
159 | + */ |
|
160 | + public function revenue_reports_data() { |
|
161 | + global $wpdb; |
|
162 | + |
|
163 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
164 | + $data = $wpdb->get_results( |
|
165 | + "SELECT |
|
166 | 166 | COUNT(posts.ID) as sales, |
167 | 167 | meta.gateway as gateway, |
168 | 168 | SUM(meta.total) as total, |
@@ -177,27 +177,27 @@ discard block |
||
177 | 177 | AND ( posts.post_status = 'publish' OR posts.post_status = 'renewal' ) |
178 | 178 | GROUP BY meta.gateway", ARRAY_A); |
179 | 179 | |
180 | - $return = array(); |
|
181 | - |
|
182 | - foreach ( $data as $gateway ) { |
|
183 | - $return[ $gateway ['gateway']] = $gateway; |
|
184 | - } |
|
185 | - |
|
186 | - return $return; |
|
187 | - |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Setup the final data for the table |
|
192 | - * |
|
193 | - * @since 1.0.19 |
|
194 | - * @return void |
|
195 | - */ |
|
196 | - public function prepare_items() { |
|
197 | - $columns = $this->get_columns(); |
|
198 | - $hidden = array(); // No hidden columns |
|
199 | - $sortable = $this->get_sortable_columns(); |
|
200 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
201 | - $this->items = $this->reports_data(); |
|
202 | - } |
|
180 | + $return = array(); |
|
181 | + |
|
182 | + foreach ( $data as $gateway ) { |
|
183 | + $return[ $gateway ['gateway']] = $gateway; |
|
184 | + } |
|
185 | + |
|
186 | + return $return; |
|
187 | + |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Setup the final data for the table |
|
192 | + * |
|
193 | + * @since 1.0.19 |
|
194 | + * @return void |
|
195 | + */ |
|
196 | + public function prepare_items() { |
|
197 | + $columns = $this->get_columns(); |
|
198 | + $hidden = array(); // No hidden columns |
|
199 | + $sortable = $this->get_sortable_columns(); |
|
200 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
201 | + $this->items = $this->reports_data(); |
|
202 | + } |
|
203 | 203 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | // Load WP_List_Table if not loaded |
11 | 11 | if ( ! class_exists( 'WP_List_Table' ) ) { |
12 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
12 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | /** |
@@ -21,129 +21,129 @@ discard block |
||
21 | 21 | */ |
22 | 22 | class WPInv_Items_Report_Table extends WP_List_Table { |
23 | 23 | |
24 | - /** |
|
25 | - * @var int Number of items per page |
|
26 | - * @since 1.0.19 |
|
27 | - */ |
|
28 | - public $per_page = 300; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * Get things started |
|
33 | - * |
|
34 | - * @since 1.0.19 |
|
35 | - * @see WP_List_Table::__construct() |
|
36 | - */ |
|
37 | - public function __construct() { |
|
38 | - |
|
39 | - // Set parent defaults |
|
40 | - parent::__construct( array( |
|
41 | - 'singular' => 'id', |
|
42 | - 'plural' => 'ids', |
|
43 | - 'ajax' => false, |
|
44 | - ) ); |
|
45 | - |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Gets the name of the primary column. |
|
50 | - * |
|
51 | - * @since 1.0.19 |
|
52 | - * @access protected |
|
53 | - * |
|
54 | - * @return string Name of the primary column. |
|
55 | - */ |
|
56 | - protected function get_primary_column_name() { |
|
57 | - return 'item'; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * This function renders most of the columns in the list table. |
|
62 | - * |
|
63 | - * @since 1.0.19 |
|
64 | - * |
|
65 | - * @param array $item Contains all the data of the gateways |
|
66 | - * @param string $column_name The name of the column |
|
67 | - * |
|
68 | - * @return string Column Name |
|
69 | - */ |
|
70 | - public function column_default( $item, $column_name ) { |
|
71 | - return esc_html( $item[ $column_name ] ); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Retrieve the table columns |
|
76 | - * |
|
77 | - * @since 1.0.19 |
|
78 | - * @return array $columns Array of all the list table columns |
|
79 | - */ |
|
80 | - public function get_columns() { |
|
81 | - |
|
82 | - return array( |
|
83 | - 'item' => __( 'Item', 'invoicing' ), |
|
84 | - 'sales' => __( 'Quantity Sold', 'invoicing' ), |
|
85 | - 'total' => __( 'Total Earnings', 'invoicing' ), |
|
86 | - 'discount' => __( 'Total Discounts', 'invoicing' ), |
|
87 | - 'tax' => __( 'Total Taxes', 'invoicing' ), |
|
88 | - ); |
|
89 | - |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Retrieve the current page number |
|
94 | - * |
|
95 | - * @since 1.0.19 |
|
96 | - * @return int Current page number |
|
97 | - */ |
|
98 | - public function get_paged() { |
|
99 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Outputs the reporting views |
|
104 | - * |
|
105 | - * @since 1.0.19 |
|
106 | - * @return void |
|
107 | - */ |
|
108 | - public function bulk_actions( $which = '' ) { |
|
109 | - return array(); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Build all the reports data |
|
114 | - * |
|
115 | - * @since 1.0.19 |
|
116 | - * @return array $reports_data All the data for gateway reports |
|
117 | - */ |
|
118 | - public function reports_data() { |
|
119 | - |
|
120 | - $reports_data = $this->revenue_reports_data(); |
|
121 | - |
|
122 | - $prepared = array(); |
|
123 | - foreach ( $reports_data as $report_data ) { |
|
124 | - $prepared[] = array( |
|
125 | - 'item' => $report_data['item_name'], |
|
126 | - 'sales' => $report_data['sales'], |
|
127 | - 'total' => wpinv_price( wpinv_format_amount( $report_data['total'] ) ), |
|
128 | - 'discount' => wpinv_price( wpinv_format_amount( $report_data['discount'] ) ), |
|
129 | - 'tax' => wpinv_price( wpinv_format_amount( $report_data['tax'] ) ), |
|
130 | - ); |
|
131 | - } |
|
132 | - |
|
133 | - return $prepared; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Retrieves report data. |
|
138 | - * |
|
139 | - * @since 1.0.19 |
|
140 | - */ |
|
141 | - public function revenue_reports_data() { |
|
142 | - global $wpdb; |
|
143 | - |
|
144 | - $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
145 | - return $wpdb->get_results( |
|
146 | - "SELECT |
|
24 | + /** |
|
25 | + * @var int Number of items per page |
|
26 | + * @since 1.0.19 |
|
27 | + */ |
|
28 | + public $per_page = 300; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * Get things started |
|
33 | + * |
|
34 | + * @since 1.0.19 |
|
35 | + * @see WP_List_Table::__construct() |
|
36 | + */ |
|
37 | + public function __construct() { |
|
38 | + |
|
39 | + // Set parent defaults |
|
40 | + parent::__construct( array( |
|
41 | + 'singular' => 'id', |
|
42 | + 'plural' => 'ids', |
|
43 | + 'ajax' => false, |
|
44 | + ) ); |
|
45 | + |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Gets the name of the primary column. |
|
50 | + * |
|
51 | + * @since 1.0.19 |
|
52 | + * @access protected |
|
53 | + * |
|
54 | + * @return string Name of the primary column. |
|
55 | + */ |
|
56 | + protected function get_primary_column_name() { |
|
57 | + return 'item'; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * This function renders most of the columns in the list table. |
|
62 | + * |
|
63 | + * @since 1.0.19 |
|
64 | + * |
|
65 | + * @param array $item Contains all the data of the gateways |
|
66 | + * @param string $column_name The name of the column |
|
67 | + * |
|
68 | + * @return string Column Name |
|
69 | + */ |
|
70 | + public function column_default( $item, $column_name ) { |
|
71 | + return esc_html( $item[ $column_name ] ); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Retrieve the table columns |
|
76 | + * |
|
77 | + * @since 1.0.19 |
|
78 | + * @return array $columns Array of all the list table columns |
|
79 | + */ |
|
80 | + public function get_columns() { |
|
81 | + |
|
82 | + return array( |
|
83 | + 'item' => __( 'Item', 'invoicing' ), |
|
84 | + 'sales' => __( 'Quantity Sold', 'invoicing' ), |
|
85 | + 'total' => __( 'Total Earnings', 'invoicing' ), |
|
86 | + 'discount' => __( 'Total Discounts', 'invoicing' ), |
|
87 | + 'tax' => __( 'Total Taxes', 'invoicing' ), |
|
88 | + ); |
|
89 | + |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Retrieve the current page number |
|
94 | + * |
|
95 | + * @since 1.0.19 |
|
96 | + * @return int Current page number |
|
97 | + */ |
|
98 | + public function get_paged() { |
|
99 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Outputs the reporting views |
|
104 | + * |
|
105 | + * @since 1.0.19 |
|
106 | + * @return void |
|
107 | + */ |
|
108 | + public function bulk_actions( $which = '' ) { |
|
109 | + return array(); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Build all the reports data |
|
114 | + * |
|
115 | + * @since 1.0.19 |
|
116 | + * @return array $reports_data All the data for gateway reports |
|
117 | + */ |
|
118 | + public function reports_data() { |
|
119 | + |
|
120 | + $reports_data = $this->revenue_reports_data(); |
|
121 | + |
|
122 | + $prepared = array(); |
|
123 | + foreach ( $reports_data as $report_data ) { |
|
124 | + $prepared[] = array( |
|
125 | + 'item' => $report_data['item_name'], |
|
126 | + 'sales' => $report_data['sales'], |
|
127 | + 'total' => wpinv_price( wpinv_format_amount( $report_data['total'] ) ), |
|
128 | + 'discount' => wpinv_price( wpinv_format_amount( $report_data['discount'] ) ), |
|
129 | + 'tax' => wpinv_price( wpinv_format_amount( $report_data['tax'] ) ), |
|
130 | + ); |
|
131 | + } |
|
132 | + |
|
133 | + return $prepared; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Retrieves report data. |
|
138 | + * |
|
139 | + * @since 1.0.19 |
|
140 | + */ |
|
141 | + public function revenue_reports_data() { |
|
142 | + global $wpdb; |
|
143 | + |
|
144 | + $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
145 | + return $wpdb->get_results( |
|
146 | + "SELECT |
|
147 | 147 | SUM(quantity) as sales, |
148 | 148 | item_name, |
149 | 149 | SUM(tax) as tax, |
@@ -157,19 +157,19 @@ discard block |
||
157 | 157 | GROUP BY item_id |
158 | 158 | ORDER BY item_name ASC", ARRAY_A); |
159 | 159 | |
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Setup the final data for the table |
|
164 | - * |
|
165 | - * @since 1.0.19 |
|
166 | - * @return void |
|
167 | - */ |
|
168 | - public function prepare_items() { |
|
169 | - $columns = $this->get_columns(); |
|
170 | - $hidden = array(); // No hidden columns |
|
171 | - $sortable = $this->get_sortable_columns(); |
|
172 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
173 | - $this->items = $this->reports_data(); |
|
174 | - } |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Setup the final data for the table |
|
164 | + * |
|
165 | + * @since 1.0.19 |
|
166 | + * @return void |
|
167 | + */ |
|
168 | + public function prepare_items() { |
|
169 | + $columns = $this->get_columns(); |
|
170 | + $hidden = array(); // No hidden columns |
|
171 | + $sortable = $this->get_sortable_columns(); |
|
172 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
173 | + $this->items = $this->reports_data(); |
|
174 | + } |
|
175 | 175 | } |
@@ -3,102 +3,102 @@ discard block |
||
3 | 3 | class SD_Hello_World extends WP_Super_Duper { |
4 | 4 | |
5 | 5 | |
6 | - public $arguments; |
|
7 | - |
|
8 | - /** |
|
9 | - * Sets up the widgets name etc |
|
10 | - */ |
|
11 | - public function __construct() { |
|
12 | - |
|
13 | - $options = array( |
|
14 | - 'textdomain' => 'super-duper', |
|
15 | - // textdomain of the plugin/theme (used to prefix the Gutenberg block) |
|
16 | - 'block-icon' => 'fas fa-globe-americas', |
|
17 | - // Dash icon name for the block: https://developer.wordpress.org/resource/dashicons/#arrow-right |
|
18 | - // OR font-awesome 5 class name: fas fa-globe-americas |
|
19 | - 'block-category' => 'widgets', |
|
20 | - // the category for the block, 'common', 'formatting', 'layout', 'widgets', 'embed'. |
|
21 | - 'block-keywords' => "['hello','world']", |
|
22 | - // used in the block search, MAX 3 |
|
23 | - 'block-output' => array( // the block visual output elements as an array |
|
24 | - array( |
|
25 | - 'element' => 'p', |
|
26 | - 'title' => __( 'Placeholder', 'hello-world' ), |
|
27 | - 'class' => '[%className%]', |
|
28 | - 'content' => 'Hello: [%after_text%]' // block properties can be added by wrapping them in [%name%] |
|
29 | - ) |
|
30 | - ), |
|
31 | - 'block-wrap' => '', // You can specify the type of element to wrap the block `div` or `span` etc.. Or blank for no wrap at all. |
|
32 | - 'class_name' => __CLASS__, |
|
33 | - // The calling class name |
|
34 | - 'base_id' => 'hello_world', |
|
35 | - // this is used as the widget id and the shortcode id. |
|
36 | - 'name' => __( 'Hello World', 'hello-world' ), |
|
37 | - // the name of the widget/block |
|
38 | - 'widget_ops' => array( |
|
39 | - 'classname' => 'hello-world-class', |
|
40 | - // widget class |
|
41 | - 'description' => esc_html__( 'This is an example that will take a text parameter and output it after `Hello:`.', 'hello-world' ), |
|
42 | - // widget description |
|
43 | - ), |
|
44 | - 'no_wrap' => true, // This will prevent the widget being wrapped in the containing widget class div. |
|
45 | - 'arguments' => array( // these are the arguments that will be used in the widget, shortcode and block settings. |
|
46 | - 'after_text' => array( // this is the input name='' |
|
47 | - 'title' => __( 'Text after hello:', 'hello-world' ), |
|
48 | - // input title |
|
49 | - 'desc' => __( 'This is the text that will appear after `Hello:`.', 'hello-world' ), |
|
50 | - // input description |
|
51 | - 'type' => 'text', |
|
52 | - // the type of input, test, select, checkbox etc. |
|
53 | - 'placeholder' => 'World', |
|
54 | - // the input placeholder text. |
|
55 | - 'desc_tip' => true, |
|
56 | - // if the input should show the widget description text as a tooltip. |
|
57 | - 'default' => 'World', |
|
58 | - // the input default value. |
|
59 | - 'advanced' => false |
|
60 | - // not yet implemented |
|
61 | - ), |
|
62 | - ) |
|
63 | - ); |
|
64 | - |
|
65 | - parent::__construct( $options ); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * This is the output function for the widget, shortcode and block (front end). |
|
71 | - * |
|
72 | - * @param array $args The arguments values. |
|
73 | - * @param array $widget_args The widget arguments when used. |
|
74 | - * @param string $content The shortcode content argument |
|
75 | - * |
|
76 | - * @return string |
|
77 | - */ |
|
78 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
79 | - |
|
80 | - /** |
|
81 | - * @var string $after_text |
|
82 | - * @var string $another_input This is added by filter below. |
|
83 | - */ |
|
84 | - extract( $args, EXTR_SKIP ); |
|
85 | - |
|
86 | - /* |
|
6 | + public $arguments; |
|
7 | + |
|
8 | + /** |
|
9 | + * Sets up the widgets name etc |
|
10 | + */ |
|
11 | + public function __construct() { |
|
12 | + |
|
13 | + $options = array( |
|
14 | + 'textdomain' => 'super-duper', |
|
15 | + // textdomain of the plugin/theme (used to prefix the Gutenberg block) |
|
16 | + 'block-icon' => 'fas fa-globe-americas', |
|
17 | + // Dash icon name for the block: https://developer.wordpress.org/resource/dashicons/#arrow-right |
|
18 | + // OR font-awesome 5 class name: fas fa-globe-americas |
|
19 | + 'block-category' => 'widgets', |
|
20 | + // the category for the block, 'common', 'formatting', 'layout', 'widgets', 'embed'. |
|
21 | + 'block-keywords' => "['hello','world']", |
|
22 | + // used in the block search, MAX 3 |
|
23 | + 'block-output' => array( // the block visual output elements as an array |
|
24 | + array( |
|
25 | + 'element' => 'p', |
|
26 | + 'title' => __( 'Placeholder', 'hello-world' ), |
|
27 | + 'class' => '[%className%]', |
|
28 | + 'content' => 'Hello: [%after_text%]' // block properties can be added by wrapping them in [%name%] |
|
29 | + ) |
|
30 | + ), |
|
31 | + 'block-wrap' => '', // You can specify the type of element to wrap the block `div` or `span` etc.. Or blank for no wrap at all. |
|
32 | + 'class_name' => __CLASS__, |
|
33 | + // The calling class name |
|
34 | + 'base_id' => 'hello_world', |
|
35 | + // this is used as the widget id and the shortcode id. |
|
36 | + 'name' => __( 'Hello World', 'hello-world' ), |
|
37 | + // the name of the widget/block |
|
38 | + 'widget_ops' => array( |
|
39 | + 'classname' => 'hello-world-class', |
|
40 | + // widget class |
|
41 | + 'description' => esc_html__( 'This is an example that will take a text parameter and output it after `Hello:`.', 'hello-world' ), |
|
42 | + // widget description |
|
43 | + ), |
|
44 | + 'no_wrap' => true, // This will prevent the widget being wrapped in the containing widget class div. |
|
45 | + 'arguments' => array( // these are the arguments that will be used in the widget, shortcode and block settings. |
|
46 | + 'after_text' => array( // this is the input name='' |
|
47 | + 'title' => __( 'Text after hello:', 'hello-world' ), |
|
48 | + // input title |
|
49 | + 'desc' => __( 'This is the text that will appear after `Hello:`.', 'hello-world' ), |
|
50 | + // input description |
|
51 | + 'type' => 'text', |
|
52 | + // the type of input, test, select, checkbox etc. |
|
53 | + 'placeholder' => 'World', |
|
54 | + // the input placeholder text. |
|
55 | + 'desc_tip' => true, |
|
56 | + // if the input should show the widget description text as a tooltip. |
|
57 | + 'default' => 'World', |
|
58 | + // the input default value. |
|
59 | + 'advanced' => false |
|
60 | + // not yet implemented |
|
61 | + ), |
|
62 | + ) |
|
63 | + ); |
|
64 | + |
|
65 | + parent::__construct( $options ); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * This is the output function for the widget, shortcode and block (front end). |
|
71 | + * |
|
72 | + * @param array $args The arguments values. |
|
73 | + * @param array $widget_args The widget arguments when used. |
|
74 | + * @param string $content The shortcode content argument |
|
75 | + * |
|
76 | + * @return string |
|
77 | + */ |
|
78 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
79 | + |
|
80 | + /** |
|
81 | + * @var string $after_text |
|
82 | + * @var string $another_input This is added by filter below. |
|
83 | + */ |
|
84 | + extract( $args, EXTR_SKIP ); |
|
85 | + |
|
86 | + /* |
|
87 | 87 | * This value is added by filter so might not exist if filter is removed so we check. |
88 | 88 | */ |
89 | - if ( ! isset( $another_input ) ) { |
|
90 | - $another_input = ''; |
|
91 | - } |
|
89 | + if ( ! isset( $another_input ) ) { |
|
90 | + $another_input = ''; |
|
91 | + } |
|
92 | 92 | |
93 | - return "Hello: " . $after_text . "" . $another_input; |
|
93 | + return "Hello: " . $after_text . "" . $another_input; |
|
94 | 94 | |
95 | - } |
|
95 | + } |
|
96 | 96 | |
97 | 97 | } |
98 | 98 | |
99 | 99 | // register it. |
100 | 100 | add_action( 'widgets_init', function () { |
101 | - register_widget( 'SD_Hello_World' ); |
|
101 | + register_widget( 'SD_Hello_World' ); |
|
102 | 102 | } ); |
103 | 103 | |
104 | 104 | |
@@ -111,26 +111,26 @@ discard block |
||
111 | 111 | */ |
112 | 112 | function _my_extra_arguments( $options ) { |
113 | 113 | |
114 | - /* |
|
114 | + /* |
|
115 | 115 | * Add a new input option. |
116 | 116 | */ |
117 | - $options['arguments']['another_input'] = array( |
|
118 | - 'name' => 'another_input', // this is the input name='' |
|
119 | - 'title' => __( 'Another input:', 'hello-world' ), // input title |
|
120 | - 'desc' => __( 'This is an input added via filter.', 'hello-world' ), // input description |
|
121 | - 'type' => 'text', // the type of input, test, select, checkbox etc. |
|
122 | - 'placeholder' => 'Placeholder text', // the input placeholder text. |
|
123 | - 'desc_tip' => true, // if the input should show the widget description text as a tooltip. |
|
124 | - 'default' => '', // the input default value. |
|
125 | - 'advanced' => false // not yet implemented |
|
126 | - ); |
|
127 | - |
|
128 | - /* |
|
117 | + $options['arguments']['another_input'] = array( |
|
118 | + 'name' => 'another_input', // this is the input name='' |
|
119 | + 'title' => __( 'Another input:', 'hello-world' ), // input title |
|
120 | + 'desc' => __( 'This is an input added via filter.', 'hello-world' ), // input description |
|
121 | + 'type' => 'text', // the type of input, test, select, checkbox etc. |
|
122 | + 'placeholder' => 'Placeholder text', // the input placeholder text. |
|
123 | + 'desc_tip' => true, // if the input should show the widget description text as a tooltip. |
|
124 | + 'default' => '', // the input default value. |
|
125 | + 'advanced' => false // not yet implemented |
|
126 | + ); |
|
127 | + |
|
128 | + /* |
|
129 | 129 | * Output the new option in the block output also. |
130 | 130 | */ |
131 | - $options['block-output']['element::p']['content'] = $options['block-output']['element::p']['content'] . " [%another_input%]";; |
|
131 | + $options['block-output']['element::p']['content'] = $options['block-output']['element::p']['content'] . " [%another_input%]";; |
|
132 | 132 | |
133 | - return $options; |
|
133 | + return $options; |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | //add_filter( 'wp_super_duper_options_hello_world', '_my_extra_arguments' ); |
137 | 137 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
4 | - exit; // Exit if accessed directly |
|
4 | + exit; // Exit if accessed directly |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -11,81 +11,81 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class AUI_Component_Alert { |
13 | 13 | |
14 | - /** |
|
15 | - * Build the component. |
|
16 | - * |
|
17 | - * @param array $args |
|
18 | - * |
|
19 | - * @return string The rendered component. |
|
20 | - */ |
|
21 | - public static function get($args = array()){ |
|
22 | - $defaults = array( |
|
23 | - 'type' => 'info', |
|
24 | - 'class' => '', |
|
25 | - 'icon' => '', |
|
26 | - 'heading' => '', |
|
27 | - 'content' => '', |
|
28 | - 'footer' => '', |
|
29 | - 'dismissible'=> false, |
|
30 | - 'data' => '', |
|
31 | - ); |
|
14 | + /** |
|
15 | + * Build the component. |
|
16 | + * |
|
17 | + * @param array $args |
|
18 | + * |
|
19 | + * @return string The rendered component. |
|
20 | + */ |
|
21 | + public static function get($args = array()){ |
|
22 | + $defaults = array( |
|
23 | + 'type' => 'info', |
|
24 | + 'class' => '', |
|
25 | + 'icon' => '', |
|
26 | + 'heading' => '', |
|
27 | + 'content' => '', |
|
28 | + 'footer' => '', |
|
29 | + 'dismissible'=> false, |
|
30 | + 'data' => '', |
|
31 | + ); |
|
32 | 32 | |
33 | - /** |
|
34 | - * Parse incoming $args into an array and merge it with $defaults |
|
35 | - */ |
|
36 | - $args = wp_parse_args( $args, $defaults ); |
|
37 | - $output = ''; |
|
38 | - if ( ! empty( $args['content'] ) ) { |
|
39 | - $type = sanitize_html_class( $args['type'] ); |
|
40 | - if($type=='error'){$type='danger';} |
|
41 | - $icon = !empty($args['icon']) ? "<i class='".esc_attr($args['icon'])."'></i>" : ''; |
|
33 | + /** |
|
34 | + * Parse incoming $args into an array and merge it with $defaults |
|
35 | + */ |
|
36 | + $args = wp_parse_args( $args, $defaults ); |
|
37 | + $output = ''; |
|
38 | + if ( ! empty( $args['content'] ) ) { |
|
39 | + $type = sanitize_html_class( $args['type'] ); |
|
40 | + if($type=='error'){$type='danger';} |
|
41 | + $icon = !empty($args['icon']) ? "<i class='".esc_attr($args['icon'])."'></i>" : ''; |
|
42 | 42 | |
43 | - // set default icon |
|
44 | - if(!$icon && $args['icon']!==false && $type){ |
|
45 | - if($type=='danger'){$icon = '<i class="fas fa-exclamation-circle"></i>';} |
|
46 | - elseif($type=='warning'){$icon = '<i class="fas fa-exclamation-triangle"></i>';} |
|
47 | - elseif($type=='success'){$icon = '<i class="fas fa-check-circle"></i>';} |
|
48 | - elseif($type=='info'){$icon = '<i class="fas fa-info-circle"></i>';} |
|
49 | - } |
|
43 | + // set default icon |
|
44 | + if(!$icon && $args['icon']!==false && $type){ |
|
45 | + if($type=='danger'){$icon = '<i class="fas fa-exclamation-circle"></i>';} |
|
46 | + elseif($type=='warning'){$icon = '<i class="fas fa-exclamation-triangle"></i>';} |
|
47 | + elseif($type=='success'){$icon = '<i class="fas fa-check-circle"></i>';} |
|
48 | + elseif($type=='info'){$icon = '<i class="fas fa-info-circle"></i>';} |
|
49 | + } |
|
50 | 50 | |
51 | - $data = ''; |
|
52 | - $class = !empty($args['class']) ? esc_attr($args['class']) : ''; |
|
53 | - if($args['dismissible']){$class .= " alert-dismissible fade show";} |
|
51 | + $data = ''; |
|
52 | + $class = !empty($args['class']) ? esc_attr($args['class']) : ''; |
|
53 | + if($args['dismissible']){$class .= " alert-dismissible fade show";} |
|
54 | 54 | |
55 | - // open |
|
56 | - $output .= '<div class="alert alert-' . $type . ' '.$class.'" role="alert" '.$data.'>'; |
|
55 | + // open |
|
56 | + $output .= '<div class="alert alert-' . $type . ' '.$class.'" role="alert" '.$data.'>'; |
|
57 | 57 | |
58 | - // heading |
|
59 | - if ( ! empty( $args['heading'] ) ) { |
|
60 | - $output .= '<h4 class="alert-heading">' . $args['heading'] . '</h4>'; |
|
61 | - } |
|
58 | + // heading |
|
59 | + if ( ! empty( $args['heading'] ) ) { |
|
60 | + $output .= '<h4 class="alert-heading">' . $args['heading'] . '</h4>'; |
|
61 | + } |
|
62 | 62 | |
63 | - // icon |
|
64 | - if ( ! empty( $icon) ) { |
|
65 | - $output .= $icon." "; |
|
66 | - } |
|
63 | + // icon |
|
64 | + if ( ! empty( $icon) ) { |
|
65 | + $output .= $icon." "; |
|
66 | + } |
|
67 | 67 | |
68 | - // content |
|
69 | - $output .= $args['content']; |
|
68 | + // content |
|
69 | + $output .= $args['content']; |
|
70 | 70 | |
71 | - // dismissible |
|
72 | - if($args['dismissible']){ |
|
73 | - $output .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close">'; |
|
74 | - $output .= '<span aria-hidden="true">×</span>'; |
|
75 | - $output .= '</button>'; |
|
76 | - } |
|
71 | + // dismissible |
|
72 | + if($args['dismissible']){ |
|
73 | + $output .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close">'; |
|
74 | + $output .= '<span aria-hidden="true">×</span>'; |
|
75 | + $output .= '</button>'; |
|
76 | + } |
|
77 | 77 | |
78 | - // footer |
|
79 | - if ( ! empty( $args['footer'] ) ) { |
|
80 | - $output .= '<hr>'; |
|
81 | - $output .= '<p class="mb-0">' . $args['footer'] . '</p>'; |
|
82 | - } |
|
78 | + // footer |
|
79 | + if ( ! empty( $args['footer'] ) ) { |
|
80 | + $output .= '<hr>'; |
|
81 | + $output .= '<p class="mb-0">' . $args['footer'] . '</p>'; |
|
82 | + } |
|
83 | 83 | |
84 | - // close |
|
85 | - $output .= '</div>'; |
|
86 | - } |
|
84 | + // close |
|
85 | + $output .= '</div>'; |
|
86 | + } |
|
87 | 87 | |
88 | - return $output; |
|
89 | - } |
|
88 | + return $output; |
|
89 | + } |
|
90 | 90 | |
91 | 91 | } |
92 | 92 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
4 | - exit; // Exit if accessed directly |
|
4 | + exit; // Exit if accessed directly |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -11,62 +11,62 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class AUI_Component_Dropdown { |
13 | 13 | |
14 | - /** |
|
15 | - * Build the component. |
|
16 | - * |
|
17 | - * @param array $args |
|
18 | - * |
|
19 | - * @return string The rendered component. |
|
20 | - */ |
|
21 | - public static function get($args = array()){ |
|
22 | - $defaults = array( |
|
23 | - 'type' => 'button', |
|
24 | - 'href' => '#', |
|
25 | - 'class' => 'btn btn-primary dropdown-toggle', |
|
26 | - 'wrapper_class' => '', |
|
27 | - 'dropdown_menu_class' => '', |
|
28 | - 'id' => '', |
|
29 | - 'title' => '', |
|
30 | - 'value' => '', |
|
31 | - 'content' => '', |
|
32 | - 'icon' => '', |
|
33 | - 'hover_content' => '', |
|
34 | - 'hover_icon' => '', |
|
35 | - 'data-toggle' => 'dropdown', |
|
36 | - 'aria-haspopup' => 'true', |
|
37 | - 'aria-expanded' => 'false', |
|
38 | - 'dropdown_menu' => '', // unescaped html menu (non-preferred way) |
|
39 | - 'dropdown_items' => array(), // array of AUI calls |
|
14 | + /** |
|
15 | + * Build the component. |
|
16 | + * |
|
17 | + * @param array $args |
|
18 | + * |
|
19 | + * @return string The rendered component. |
|
20 | + */ |
|
21 | + public static function get($args = array()){ |
|
22 | + $defaults = array( |
|
23 | + 'type' => 'button', |
|
24 | + 'href' => '#', |
|
25 | + 'class' => 'btn btn-primary dropdown-toggle', |
|
26 | + 'wrapper_class' => '', |
|
27 | + 'dropdown_menu_class' => '', |
|
28 | + 'id' => '', |
|
29 | + 'title' => '', |
|
30 | + 'value' => '', |
|
31 | + 'content' => '', |
|
32 | + 'icon' => '', |
|
33 | + 'hover_content' => '', |
|
34 | + 'hover_icon' => '', |
|
35 | + 'data-toggle' => 'dropdown', |
|
36 | + 'aria-haspopup' => 'true', |
|
37 | + 'aria-expanded' => 'false', |
|
38 | + 'dropdown_menu' => '', // unescaped html menu (non-preferred way) |
|
39 | + 'dropdown_items' => array(), // array of AUI calls |
|
40 | 40 | |
41 | - ); |
|
41 | + ); |
|
42 | 42 | |
43 | - /** |
|
44 | - * Parse incoming $args into an array and merge it with $defaults |
|
45 | - */ |
|
46 | - $args = wp_parse_args( $args, $defaults ); |
|
47 | - $output = ''; |
|
48 | - if ( ! empty( $args['type'] ) ) { |
|
49 | - // wrapper open |
|
50 | - $output .= '<div class="dropdown '.AUI_Component_Helper::esc_classes($args['wrapper_class']).'">'; |
|
43 | + /** |
|
44 | + * Parse incoming $args into an array and merge it with $defaults |
|
45 | + */ |
|
46 | + $args = wp_parse_args( $args, $defaults ); |
|
47 | + $output = ''; |
|
48 | + if ( ! empty( $args['type'] ) ) { |
|
49 | + // wrapper open |
|
50 | + $output .= '<div class="dropdown '.AUI_Component_Helper::esc_classes($args['wrapper_class']).'">'; |
|
51 | 51 | |
52 | - // button part |
|
53 | - $output .= aui()->button($args); |
|
52 | + // button part |
|
53 | + $output .= aui()->button($args); |
|
54 | 54 | |
55 | - // dropdown-menu |
|
56 | - if(!empty($args['dropdown_menu'])){ |
|
57 | - $output .= $args['dropdown_menu']; |
|
58 | - }elseif(!empty($args['dropdown_items'])){ |
|
59 | - $output .= '<div class="dropdown-menu '.AUI_Component_Helper::esc_classes($args['dropdown_menu_class']).'" aria-labelledby="'.sanitize_html_class($args['id']).'">'; |
|
60 | - $output .= aui()->render($args['dropdown_items']); |
|
61 | - $output .= '</div>'; |
|
62 | - } |
|
55 | + // dropdown-menu |
|
56 | + if(!empty($args['dropdown_menu'])){ |
|
57 | + $output .= $args['dropdown_menu']; |
|
58 | + }elseif(!empty($args['dropdown_items'])){ |
|
59 | + $output .= '<div class="dropdown-menu '.AUI_Component_Helper::esc_classes($args['dropdown_menu_class']).'" aria-labelledby="'.sanitize_html_class($args['id']).'">'; |
|
60 | + $output .= aui()->render($args['dropdown_items']); |
|
61 | + $output .= '</div>'; |
|
62 | + } |
|
63 | 63 | |
64 | - // wrapper close |
|
65 | - $output .= '</div>'; |
|
64 | + // wrapper close |
|
65 | + $output .= '</div>'; |
|
66 | 66 | |
67 | - } |
|
67 | + } |
|
68 | 68 | |
69 | - return $output; |
|
70 | - } |
|
69 | + return $output; |
|
70 | + } |
|
71 | 71 | |
72 | 72 | } |
73 | 73 | \ No newline at end of file |
@@ -16,132 +16,132 @@ |
||
16 | 16 | |
17 | 17 | // If this file is called directly, abort. |
18 | 18 | if ( ! defined( 'WPINC' ) ) { |
19 | - die; |
|
19 | + die; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | class AyeCode_UI_Plugin { |
23 | 23 | |
24 | - /** |
|
25 | - * AUI Plugin constructor. |
|
26 | - * |
|
27 | - * @since 1.0.0 |
|
28 | - */ |
|
29 | - public function __construct() { |
|
30 | - |
|
31 | - // load AUI |
|
32 | - require_once( dirname( __FILE__ ) . '/ayecode-ui-loader.php' ); |
|
33 | - |
|
34 | - // Maybe show example page |
|
35 | - add_action( 'template_redirect', array( $this,'maybe_show_examples' ) ); |
|
36 | - } |
|
37 | - |
|
38 | - public function maybe_show_examples(){ |
|
39 | - if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
40 | - echo "<head>"; |
|
41 | - wp_head(); |
|
42 | - echo "</head>"; |
|
43 | - echo "<body>"; |
|
44 | - echo $this->get_examples(); |
|
45 | - echo "</body>"; |
|
46 | - exit; |
|
47 | - } |
|
48 | - } |
|
49 | - |
|
50 | - public function get_examples(){ |
|
51 | - $output = ''; |
|
52 | - |
|
53 | - |
|
54 | - // open form |
|
55 | - $output .= "<form class='p-5 m-5 border rounded'>"; |
|
56 | - |
|
57 | - // input example |
|
58 | - $output .= aui()->input(array( |
|
59 | - 'type' => 'text', |
|
60 | - 'id' => 'text-example', |
|
61 | - 'name' => 'text-example', |
|
62 | - 'placeholder' => 'text placeholder', |
|
63 | - 'title' => 'Text input example', |
|
64 | - 'value' => '', |
|
65 | - 'required' => false, |
|
66 | - 'help_text' => 'help text', |
|
67 | - 'label' => 'Text input example label' |
|
68 | - )); |
|
69 | - |
|
70 | - // input example |
|
71 | - $output .= aui()->input(array( |
|
72 | - 'type' => 'url', |
|
73 | - 'id' => 'text-example2', |
|
74 | - 'name' => 'text-example', |
|
75 | - 'placeholder' => 'url placeholder', |
|
76 | - 'title' => 'Text input example', |
|
77 | - 'value' => '', |
|
78 | - 'required' => false, |
|
79 | - 'help_text' => 'help text', |
|
80 | - 'label' => 'Text input example label' |
|
81 | - )); |
|
82 | - |
|
83 | - // checkbox example |
|
84 | - $output .= aui()->input(array( |
|
85 | - 'type' => 'checkbox', |
|
86 | - 'id' => 'checkbox-example', |
|
87 | - 'name' => 'checkbox-example', |
|
88 | - 'placeholder' => 'checkbox-example', |
|
89 | - 'title' => 'Checkbox example', |
|
90 | - 'value' => '1', |
|
91 | - 'checked' => true, |
|
92 | - 'required' => false, |
|
93 | - 'help_text' => 'help text', |
|
94 | - 'label' => 'Checkbox checked' |
|
95 | - )); |
|
96 | - |
|
97 | - // checkbox example |
|
98 | - $output .= aui()->input(array( |
|
99 | - 'type' => 'checkbox', |
|
100 | - 'id' => 'checkbox-example2', |
|
101 | - 'name' => 'checkbox-example2', |
|
102 | - 'placeholder' => 'checkbox-example', |
|
103 | - 'title' => 'Checkbox example', |
|
104 | - 'value' => '1', |
|
105 | - 'checked' => false, |
|
106 | - 'required' => false, |
|
107 | - 'help_text' => 'help text', |
|
108 | - 'label' => 'Checkbox un-checked' |
|
109 | - )); |
|
110 | - |
|
111 | - // switch example |
|
112 | - $output .= aui()->input(array( |
|
113 | - 'type' => 'checkbox', |
|
114 | - 'id' => 'switch-example', |
|
115 | - 'name' => 'switch-example', |
|
116 | - 'placeholder' => 'checkbox-example', |
|
117 | - 'title' => 'Switch example', |
|
118 | - 'value' => '1', |
|
119 | - 'checked' => true, |
|
120 | - 'switch' => true, |
|
121 | - 'required' => false, |
|
122 | - 'help_text' => 'help text', |
|
123 | - 'label' => 'Switch on' |
|
124 | - )); |
|
125 | - |
|
126 | - // switch example |
|
127 | - $output .= aui()->input(array( |
|
128 | - 'type' => 'checkbox', |
|
129 | - 'id' => 'switch-example2', |
|
130 | - 'name' => 'switch-example2', |
|
131 | - 'placeholder' => 'checkbox-example', |
|
132 | - 'title' => 'Switch example', |
|
133 | - 'value' => '1', |
|
134 | - 'checked' => false, |
|
135 | - 'switch' => true, |
|
136 | - 'required' => false, |
|
137 | - 'help_text' => 'help text', |
|
138 | - 'label' => 'Switch off' |
|
139 | - )); |
|
140 | - |
|
141 | - // close form |
|
142 | - $output .= "</form>"; |
|
143 | - |
|
144 | - return $output; |
|
145 | - } |
|
24 | + /** |
|
25 | + * AUI Plugin constructor. |
|
26 | + * |
|
27 | + * @since 1.0.0 |
|
28 | + */ |
|
29 | + public function __construct() { |
|
30 | + |
|
31 | + // load AUI |
|
32 | + require_once( dirname( __FILE__ ) . '/ayecode-ui-loader.php' ); |
|
33 | + |
|
34 | + // Maybe show example page |
|
35 | + add_action( 'template_redirect', array( $this,'maybe_show_examples' ) ); |
|
36 | + } |
|
37 | + |
|
38 | + public function maybe_show_examples(){ |
|
39 | + if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
40 | + echo "<head>"; |
|
41 | + wp_head(); |
|
42 | + echo "</head>"; |
|
43 | + echo "<body>"; |
|
44 | + echo $this->get_examples(); |
|
45 | + echo "</body>"; |
|
46 | + exit; |
|
47 | + } |
|
48 | + } |
|
49 | + |
|
50 | + public function get_examples(){ |
|
51 | + $output = ''; |
|
52 | + |
|
53 | + |
|
54 | + // open form |
|
55 | + $output .= "<form class='p-5 m-5 border rounded'>"; |
|
56 | + |
|
57 | + // input example |
|
58 | + $output .= aui()->input(array( |
|
59 | + 'type' => 'text', |
|
60 | + 'id' => 'text-example', |
|
61 | + 'name' => 'text-example', |
|
62 | + 'placeholder' => 'text placeholder', |
|
63 | + 'title' => 'Text input example', |
|
64 | + 'value' => '', |
|
65 | + 'required' => false, |
|
66 | + 'help_text' => 'help text', |
|
67 | + 'label' => 'Text input example label' |
|
68 | + )); |
|
69 | + |
|
70 | + // input example |
|
71 | + $output .= aui()->input(array( |
|
72 | + 'type' => 'url', |
|
73 | + 'id' => 'text-example2', |
|
74 | + 'name' => 'text-example', |
|
75 | + 'placeholder' => 'url placeholder', |
|
76 | + 'title' => 'Text input example', |
|
77 | + 'value' => '', |
|
78 | + 'required' => false, |
|
79 | + 'help_text' => 'help text', |
|
80 | + 'label' => 'Text input example label' |
|
81 | + )); |
|
82 | + |
|
83 | + // checkbox example |
|
84 | + $output .= aui()->input(array( |
|
85 | + 'type' => 'checkbox', |
|
86 | + 'id' => 'checkbox-example', |
|
87 | + 'name' => 'checkbox-example', |
|
88 | + 'placeholder' => 'checkbox-example', |
|
89 | + 'title' => 'Checkbox example', |
|
90 | + 'value' => '1', |
|
91 | + 'checked' => true, |
|
92 | + 'required' => false, |
|
93 | + 'help_text' => 'help text', |
|
94 | + 'label' => 'Checkbox checked' |
|
95 | + )); |
|
96 | + |
|
97 | + // checkbox example |
|
98 | + $output .= aui()->input(array( |
|
99 | + 'type' => 'checkbox', |
|
100 | + 'id' => 'checkbox-example2', |
|
101 | + 'name' => 'checkbox-example2', |
|
102 | + 'placeholder' => 'checkbox-example', |
|
103 | + 'title' => 'Checkbox example', |
|
104 | + 'value' => '1', |
|
105 | + 'checked' => false, |
|
106 | + 'required' => false, |
|
107 | + 'help_text' => 'help text', |
|
108 | + 'label' => 'Checkbox un-checked' |
|
109 | + )); |
|
110 | + |
|
111 | + // switch example |
|
112 | + $output .= aui()->input(array( |
|
113 | + 'type' => 'checkbox', |
|
114 | + 'id' => 'switch-example', |
|
115 | + 'name' => 'switch-example', |
|
116 | + 'placeholder' => 'checkbox-example', |
|
117 | + 'title' => 'Switch example', |
|
118 | + 'value' => '1', |
|
119 | + 'checked' => true, |
|
120 | + 'switch' => true, |
|
121 | + 'required' => false, |
|
122 | + 'help_text' => 'help text', |
|
123 | + 'label' => 'Switch on' |
|
124 | + )); |
|
125 | + |
|
126 | + // switch example |
|
127 | + $output .= aui()->input(array( |
|
128 | + 'type' => 'checkbox', |
|
129 | + 'id' => 'switch-example2', |
|
130 | + 'name' => 'switch-example2', |
|
131 | + 'placeholder' => 'checkbox-example', |
|
132 | + 'title' => 'Switch example', |
|
133 | + 'value' => '1', |
|
134 | + 'checked' => false, |
|
135 | + 'switch' => true, |
|
136 | + 'required' => false, |
|
137 | + 'help_text' => 'help text', |
|
138 | + 'label' => 'Switch off' |
|
139 | + )); |
|
140 | + |
|
141 | + // close form |
|
142 | + $output .= "</form>"; |
|
143 | + |
|
144 | + return $output; |
|
145 | + } |
|
146 | 146 | } |
147 | 147 | new AyeCode_UI_Plugin(); |
148 | 148 | \ No newline at end of file |