PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.2
6.2.3 6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 All 156 releases
← All changes | modules/cost-tracker/classes/class-cost-tracker-hooks.php +341 -355 5.0.3.2 → 6.2.2 View file →
@@ -8,415 +8,401 @@
8 8
9 9 namespace MainWP\Dashboard\Module\CostTracker;
10 10
11 11 use MainWP\Dashboard\MainWP_DB_Client;
12 +
13 +// Exit if accessed directly.
14 +if ( ! defined( 'ABSPATH' ) ) {
15 + exit;
16 +}
17 +
12 18 /**
13 19 * Class Cost_Tracker_Hooks
14 20 */
15 21 class Cost_Tracker_Hooks {
16 22
17 - /**
18 - * Public static variable to hold the single instance of the class.
19 - *
20 - * @static
21 - *
22 - * @var mixed Default null
23 - */
24 - public static $instance = null;
23 + /**
24 + * Public static variable to hold the single instance of the class.
25 + *
26 + * @static
27 + *
28 + * @var mixed Default null
29 + */
30 + public static $instance = null;
25 31
26 - /**
27 - * Public static variable to hold the clients costs.
28 - *
29 - * @var mixed Default null
30 - */
31 - public $clients_costs = null;
32 + /**
33 + * Public static variable to hold the clients costs.
34 + *
35 + * @var mixed Default null
36 + */
37 + public $clients_costs = null;
32 38
33 - /**
34 - * Public static variable to hold the clients costs.
35 - *
36 - * @var mixed Default null
37 - */
38 - public $clients_sites = null;
39 + /**
40 + * Public static variable to hold the clients costs.
41 + *
42 + * @var mixed Default null
43 + */
44 + public $clients_sites = null;
39 45
40 - /**
41 - * Public static variable to hold the clients costs.
42 - *
43 - * @var mixed Default null
44 - */
45 - public $sites_costs = null;
46 + /**
47 + * Public static variable to hold the clients costs.
48 + *
49 + * @var mixed Default null
50 + */
51 + public $sites_costs = null;
46 52
47 - /**
48 - * Get Instance
49 - *
50 - * Creates public static instance.
51 - *
52 - * @static
53 - *
54 - * @return Cost_Tracker_Hooks
55 - */
56 - public static function get_instance() {
57 - if ( null === self::$instance ) {
58 - self::$instance = new self();
59 - }
60 - return self::$instance;
61 - }
53 + /**
54 + * Get Instance
55 + *
56 + * Creates public static instance.
57 + *
58 + * @static
59 + *
60 + * @return Cost_Tracker_Hooks
61 + */
62 + public static function get_instance() {
63 + if ( null === static::$instance ) {
64 + static::$instance = new self();
65 + }
66 + return static::$instance;
67 + }
62 68
63 - /**
64 - * Constructor
65 - *
66 - * Runs each time the class is called.
67 - */
68 - public function __construct() {
69 - }
69 + /**
70 + * Constructor
71 + *
72 + * Runs each time the class is called.
73 + */
74 + public function __construct() {
75 + }
70 76
71 - /**
72 - * Initiate Hooks
73 - *
74 - * Initiates hooks for the extension.
75 - */
76 - public function init() {
77 - add_filter( 'mainwp_widgets_screen_options', array( &$this, 'hook_widgets_screen_options' ), 10, 1 ); // for both client, site overview widgets.
78 - add_filter( 'mainwp_header_actions_right', array( $this, 'hook_screen_options' ), 10, 2 );
79 - add_action( 'mainwp_clientstable_prepared_items', array( &$this, 'hook_clientstable_prepared_items' ), 10, 2 );
80 - add_filter( 'mainwp_clients_sitestable_getcolumns', array( &$this, 'hook_manage_clients_column' ), 10 );
81 - add_filter( 'mainwp_clients_sitestable_item', array( &$this, 'hook_manage_clients_display_item' ), 10 );
82 - add_filter( 'mainwp_sitestable_getcolumns', array( &$this, 'hook_manage_sites_column' ), 10 );
83 - add_action( 'mainwp_sitestable_prepared_items', array( &$this, 'hook_sitestable_prepared_items' ), 10, 2 );
84 - add_filter( 'mainwp_sitestable_item', array( &$this, 'hook_manage_sites_display_item' ), 10 );
77 + /**
78 + * Initiate Hooks
79 + *
80 + * Initiates hooks for the extension.
81 + */
82 + public function init() {
83 + add_filter( 'mainwp_widgets_screen_options', array( &$this, 'hook_widgets_screen_options' ), 10, 1 ); // for both client, site overview widgets.
84 + add_filter( 'mainwp_header_actions_right', array( $this, 'hook_screen_options' ), 10, 2 );
85 + add_action( 'mainwp_clientstable_prepared_items', array( &$this, 'hook_clientstable_prepared_items' ), 10, 2 );
86 + add_filter( 'mainwp_clients_sitestable_getcolumns', array( &$this, 'hook_manage_clients_column' ), 10 );
87 + add_filter( 'mainwp_clients_sitestable_item', array( &$this, 'hook_manage_clients_display_item' ), 10 );
88 + add_filter( 'mainwp_sitestable_getcolumns', array( &$this, 'hook_manage_sites_column' ), 10 );
89 + add_action( 'mainwp_sitestable_prepared_items', array( &$this, 'hook_sitestable_prepared_items' ), 10, 2 );
90 + add_filter( 'mainwp_sitestable_item', array( &$this, 'hook_manage_sites_display_item' ), 10 );
85 91
86 - add_filter( 'mainwp_clients_getmetaboxes', array( &$this, 'hook_get_client_page_metaboxes' ), 10, 1 );
87 - add_filter( 'mainwp_clients_widgets_screen_options', array( &$this, 'hook_get_widgets_screen_options' ), 10, 1 );
92 + add_filter( 'mainwp_clients_getmetaboxes', array( &$this, 'hook_get_client_page_metaboxes' ), 10, 1 );
93 + add_filter( 'mainwp_clients_widgets_screen_options', array( &$this, 'hook_get_widgets_screen_options' ), 10, 1 );
88 94
89 - add_filter( 'mainwp_getmetaboxes', array( &$this, 'hook_get_site_overview_page_metaboxes' ), 10, 2 );
90 - }
95 + add_filter( 'mainwp_getmetaboxes', array( &$this, 'hook_get_site_overview_page_metaboxes' ), 10, 2 );
96 + }
91 97
92 - /**
93 - * Widgets screen options.
94 - *
95 - * @param array $input Input.
96 - *
97 - * @return array $input Input.
98 - */
99 - public function hook_widgets_screen_options( $input ) {
100 - $input['advanced-cost-tracker-widget'] = esc_html__( 'Cost Tracker', 'mainwp' );
101 - return $input;
102 - }
98 + /**
99 + * Widgets screen options.
100 + *
101 + * @param array $input Input.
102 + *
103 + * @return array $input Input.
104 + */
105 + public function hook_widgets_screen_options( $input ) {
106 + $input['advanced-cost-tracker-widget'] = esc_html__( 'Cost Tracker (Individual Site Operations page)', 'mainwp' );
107 + return $input;
108 + }
103 109
104 - /**
105 - * Method hook_screen_options()
106 - *
107 - * Create Screen Options button.
108 - *
109 - * @param mixed $input Screen options button HTML.
110 - *
111 - * @return mixed Screen sptions button.
112 - */
113 - public function hook_screen_options( $input ) {
114 - if ( isset( $_GET['page'] ) && 'ManageCostTracker' === $_GET['page'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
115 - $input .= '<a class="ui button basic icon" onclick="mainwp_module_cost_tracker_sites_screen_options(); return false;" data-inverted="" data-position="bottom right" href="#" target="_blank" data-tooltip="' . esc_html__( 'Page Settings', 'mainwp' ) . '"><i class="cog icon"></i></a>';
116 - }
117 - return $input;
118 - }
110 + /**
111 + * Method hook_screen_options()
112 + *
113 + * Create Screen Options button.
114 + *
115 + * @param mixed $input Screen options button HTML.
116 + *
117 + * @return mixed Screen sptions button.
118 + */
119 + public function hook_screen_options( $input ) {
120 + if ( isset( $_GET['page'] ) && 'ManageCostTracker' === $_GET['page'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
121 + $input .= '<a class="ui button basic icon" onclick="mainwp_module_cost_tracker_sites_screen_options(); return false;" data-inverted="" data-position="bottom right" href="#" target="_blank" data-tooltip="' . esc_html__( 'Page Settings', 'mainwp' ) . '"><i class="cog icon"></i></a>';
122 + }
123 + return $input;
124 + }
119 125
120 126
121 - /**
122 - * Method hook_manage_clients_column().
123 - *
124 - * Handle hook to manage sites columns.
125 - *
126 - * @param array $columns sites table columns.
127 - *
128 - * @return array $columns columns.
129 - */
130 - public function hook_manage_clients_column( $columns ) {
131 - $columns['client-cost-tracker'] = '<span data-tooltip="30-Day cost forecast" data-position="left center" data-inverted=""><i class="dollar sign icon"></i></span>';
132 - return $columns;
133 - }
127 + /**
128 + * Method hook_manage_clients_column().
129 + *
130 + * Handle hook to manage sites columns.
131 + *
132 + * @param array $columns sites table columns.
133 + *
134 + * @return array $columns columns.
135 + */
136 + public function hook_manage_clients_column( $columns ) {
137 + $columns['client-cost-tracker'] = '<span data-tooltip="30-Day cost forecast" data-position="left center" data-inverted="">' . __( 'Costs', 'mainwp' ) . '</span>';
138 + return $columns;
139 + }
134 140
135 - /**
136 - * Method hook_clientstable_prepared_items().
137 - *
138 - * Handle hook to prepared manage sites items.
139 - *
140 - * @param array $clients sites prepared.
141 - * @param array $clients_ids sites ids prepared.
142 - */
143 - public function hook_clientstable_prepared_items( $clients, $clients_ids ) {
144 - if ( null === $this->clients_costs ) {
145 - $this->clients_sites = array();
146 - // get all sites of the $clients_ids.
147 - $cls_sites = MainWP_DB_Client::instance()->get_websites_by_client_ids( $clients_ids );
148 - if ( is_array( $cls_sites ) ) {
149 - foreach ( $cls_sites as $cls_site ) {
150 - if ( ! empty( $cls_site->client_id ) && ! isset( $this->clients_sites[ $cls_site->client_id ] ) ) {
151 - $this->clients_sites[ $cls_site->client_id ] = array();
152 - }
153 - $this->clients_sites[ $cls_site->client_id ][] = $cls_site->id;
154 - }
155 - }
156 - $this->clients_costs = Cost_Tracker_DB::get_instance()->get_all_cost_trackers_by_clients( $clients_ids, array( 'get_cost_sites' => true ) );
157 - }
158 - }
141 + /**
142 + * Method hook_clientstable_prepared_items().
143 + *
144 + * Handle hook to prepared manage sites items.
145 + *
146 + * @param array $clients sites prepared.
147 + * @param array $clients_ids sites ids prepared.
148 + */
149 + public function hook_clientstable_prepared_items( $clients, $clients_ids ) {
150 + unset( $clients );
151 + if ( null === $this->clients_costs ) {
152 + $this->clients_sites = array();
153 + // get all sites of the $clients_ids.
154 + $cls_sites = MainWP_DB_Client::instance()->get_websites_by_client_ids( $clients_ids );
155 + if ( is_array( $cls_sites ) ) {
156 + foreach ( $cls_sites as $cls_site ) {
157 + if ( ! empty( $cls_site->client_id ) && ! isset( $this->clients_sites[ $cls_site->client_id ] ) ) {
158 + $this->clients_sites[ $cls_site->client_id ] = array();
159 + }
160 + $this->clients_sites[ $cls_site->client_id ][] = $cls_site->id;
161 + }
162 + }
163 + $this->clients_costs = Cost_Tracker_DB::get_instance()->get_all_cost_trackers_by_clients( $clients_ids, array( 'get_cost_sites' => true ) );
164 + }
165 + }
159 166
160 - /**
161 - * Manage Sites Item
162 - *
163 - * Adds the custom column data in the Manage Sites and Monitoring tables.
164 - *
165 - * @param array $item Site comlumn data.
166 - *
167 - * @return array $item Site comlumn data.
168 - */
169 - public function hook_manage_clients_display_item( $item ) { //phpcs:ignore -- complex.
170 - if ( ! is_array( $item ) || ! isset( $item['client_id'] ) ) {
171 - return $item;
172 - }
173 - $client_id = $item['client_id'];
174 - if ( ! isset( $item['client-cost-tracker'] ) ) {
175 - $array_costs = array(
176 - 'weekly' => 0,
177 - 'monthly' => 0,
178 - 'quarterly' => 0,
179 - 'yearly' => 0,
180 - 'lifetime' => 0,
181 - );
167 + /**
168 + * Manage Sites Item
169 + *
170 + * Adds the custom column data in the Manage Sites and Monitoring tables.
171 + *
172 + * @param array $item Site comlumn data.
173 + *
174 + * @return array $item Site comlumn data.
175 + */
176 + public function hook_manage_clients_display_item( $item ) { //phpcs:ignore -- NOSONAR - complex.
177 + if ( ! is_array( $item ) || ! isset( $item['client_id'] ) ) {
178 + return $item;
179 + }
180 + $client_id = $item['client_id'];
181 + if ( ! isset( $item['client-cost-tracker'] ) ) {
182 182
183 - $current_time = time();
184 - $upcoming1 = strtotime( gmdate( 'Y-m-d 00:00:00', $current_time ) );
185 - $upcoming2 = strtotime( '+1 month', $current_time );
183 + $current_time = time();
184 + $upcoming1 = strtotime( gmdate( 'Y-m-d 00:00:00', $current_time ) );
185 + $upcoming2 = strtotime( '+1 month', $current_time );
186 186
187 - $series_products_price = array();
188 - $total_prices = 0;
187 + $series_products_price = array();
188 + $total_prices = 0;
189 189
190 - // get all cost trackers of current client.
191 - $client_costs = is_array( $this->clients_costs ) && isset( $this->clients_costs[ $client_id ] ) ? $this->clients_costs[ $client_id ] : array();
192 - if ( is_array( $client_costs ) && ! empty( $this->clients_sites[ $client_id ] ) ) {
190 + // get all cost trackers of current client.
191 + $client_costs = is_array( $this->clients_costs ) && isset( $this->clients_costs[ $client_id ] ) ? $this->clients_costs[ $client_id ] : array();
192 + if ( is_array( $client_costs ) && ! empty( $this->clients_sites[ $client_id ] ) ) {
193 193
194 - foreach ( $client_costs as $cost ) {
195 - if ( 'active' !== $cost->cost_status || 'subscription' !== $cost->type ) {
196 - continue;
197 - }
194 + foreach ( $client_costs as $cost ) {
195 + if ( 'active' !== $cost->cost_status || 'subscription' !== $cost->type ) {
196 + continue;
197 + }
198 198
199 - $next_rl = $cost->next_renewal;
199 + $next_rl = $cost->next_renewal;
200 200
201 - if ( $next_rl <= $upcoming1 ) {
202 - $next_rl = Cost_Tracker_Admin::get_next_renewal( $upcoming1, $cost->renewal_type, false );
203 - }
201 + if ( $next_rl <= $upcoming1 ) {
202 + $next_rl = Cost_Tracker_Admin::get_next_renewal( $upcoming1, $cost->renewal_type, false );
203 + }
204 204
205 - $next_price = 0;
206 - while ( $next_rl <= $upcoming2 ) {
205 + $next_price = 0;
206 + while ( $next_rl <= $upcoming2 ) {
207 207
208 - if ( $next_rl > $upcoming1 && $next_rl <= $upcoming2 ) {
209 - $next_price = $cost->price;
210 - }
208 + if ( $next_rl > $upcoming1 && $next_rl <= $upcoming2 ) {
209 + $next_price = $cost->price;
210 + }
211 211
212 - $cost_val = 0;
212 + $cost_val = 0;
213 213
214 - if ( ! empty( $next_price ) ) {
215 - if ( is_array( $cost->cost_sites_ids ) ) {
216 - foreach ( $cost->cost_sites_ids as $ct_siteid ) {
217 - // if site of cost tracker in the client's sites then calculate the site's cost/price.
218 - if ( is_array( $this->clients_sites[ $client_id ] ) && in_array( $ct_siteid, $this->clients_sites[ $client_id ] ) ) {
219 - if ( 'single_site' === $cost->license_type ) {
220 - $cost_val += $cost->price;
221 - } elseif ( 'multi_site' === $cost->license_type && ! empty( $cost->count_sites ) ) {
222 - $cost_val += $cost->price / $cost->count_sites;
223 - }
224 - }
225 - }
226 - }
227 - }
214 + if ( ! empty( $next_price ) && is_array( $cost->cost_sites_ids ) ) {
215 + foreach ( $cost->cost_sites_ids as $ct_siteid ) {
216 + // if site of cost tracker in the client's sites then calculate the site's cost/price.
217 + if ( is_array( $this->clients_sites[ $client_id ] ) && in_array( $ct_siteid, $this->clients_sites[ $client_id ] ) ) {
218 + if ( 'single_site' === $cost->license_type ) {
219 + $cost_val += $cost->price;
220 + } elseif ( 'multi_site' === $cost->license_type && ! empty( $cost->count_sites ) ) {
221 + $cost_val += $cost->price / $cost->count_sites;
222 + }
223 + }
224 + }
225 + }
228 226
229 - if ( ! empty( $cost_val ) ) {
230 - if ( ! isset( $series_products_price[ $cost->id ] ) ) {
231 - $series_products_price[ $cost->id ] = 0;
232 - }
233 - $series_products_price[ $cost->id ] += $cost_val;
234 - $total_prices += $cost_val;
235 - }
227 + if ( ! empty( $cost_val ) ) {
228 + if ( ! isset( $series_products_price[ $cost->id ] ) ) {
229 + $series_products_price[ $cost->id ] = 0;
230 + }
231 + $series_products_price[ $cost->id ] += $cost_val;
232 + $total_prices += $cost_val;
233 + }
236 234
237 - $next_rl = Cost_Tracker_Admin::get_next_renewal( $next_rl, $cost->renewal_type, false );
238 - $next_price = 0;
239 - }
240 - }
241 - }
235 + $next_rl = Cost_Tracker_Admin::get_next_renewal( $next_rl, $cost->renewal_type, false );
236 + $next_price = 0;
237 + }
238 + }
239 + }
242 240
243 - $params = '';
244 - $selected_ids = array_keys( $series_products_price );
245 - if ( ! empty( $selected_ids ) ) {
246 - $params = '&selected_ids=' . implode( ',', $selected_ids ) . '&client_id=' . intval( $client_id );
247 - }
248 - $item['client-cost-tracker'] = '<a href="admin.php?page=ManageCostTracker' . $params . '" >' . Cost_Tracker_Utility::cost_tracker_format_price( $total_prices, true ) . '</a>';
241 + $params = '';
242 + $selected_ids = array_keys( $series_products_price );
243 + if ( ! empty( $selected_ids ) ) {
244 + $params = '&selected_ids=' . implode( ',', $selected_ids ) . '&client_id=' . intval( $client_id );
245 + }
246 + $item['client-cost-tracker'] = '<a class="ui mini basic grey button" href="admin.php?page=ManageCostTracker' . $params . '" ><i class="file invoice dollar icon"></i>' . Cost_Tracker_Utility::cost_tracker_format_price( $total_prices, true ) . '</a>';
249 247
250 - }
251 - return $item;
252 - }
248 + }
249 + return $item;
250 + }
253 251
254 252
255 253
256 - /**
257 - * Method hook_manage_sites_column().
258 - *
259 - * Handle hook to manage sites columns.
260 - *
261 - * @param array $columns sites table columns.
262 - *
263 - * @return array $columns columns.
264 - */
265 - public function hook_manage_sites_column( $columns ) {
266 - $columns['site-cost-tracker'] = '<span data-tooltip="30-Day cost forecast" data-position="left center" data-inverted=""><i class="dollar sign icon"></i></span>';
267 - return $columns;
268 - }
254 + /**
255 + * Method hook_manage_sites_column().
256 + *
257 + * Handle hook to manage sites columns.
258 + *
259 + * @param array $columns sites table columns.
260 + *
261 + * @return array $columns columns.
262 + */
263 + public function hook_manage_sites_column( $columns ) {
264 + $columns['site-cost-tracker'] = '<span data-tooltip="30-Day cost forecast" data-position="left center" data-inverted="">' . __( 'Costs', 'mainwp' ) . '</span>';
265 + return $columns;
266 + }
269 267
270 268
271 - /**
272 - * Method hook_sitestable_prepared_items().
273 - *
274 - * Handle hook to prepared manage sites items.
275 - *
276 - * @param array $websites sites prepared.
277 - * @param array $site_ids sites ids prepared.
278 - */
279 - public function hook_sitestable_prepared_items( $websites, $site_ids ) {
280 - if ( null === $this->sites_costs ) {
281 - $this->sites_costs = Cost_Tracker_DB::get_instance()->get_all_cost_trackers_by_sites( $site_ids );
282 - }
283 - }
269 + /**
270 + * Method hook_sitestable_prepared_items().
271 + *
272 + * Handle hook to prepared manage sites items.
273 + *
274 + * @param array $websites sites prepared.
275 + * @param array $site_ids sites ids prepared.
276 + */
277 + public function hook_sitestable_prepared_items( $websites, $site_ids ) {
278 + unset( $websites );
279 + if ( null === $this->sites_costs ) {
280 + $this->sites_costs = Cost_Tracker_DB::get_instance()->get_all_cost_trackers_by_sites( $site_ids );
281 + }
282 + }
284 283
285 - /**
286 - * Manage Sites Item
287 - *
288 - * Adds the custom column data in the Manage Sites and Monitoring tables.
289 - *
290 - * @param array $item Site comlumn data.
291 - *
292 - * @return array $item Site comlumn data.
293 - */
294 - public function hook_manage_sites_display_item( $item ) { //phpcs:ignore -- complex.
295 - if ( ! is_array( $item ) || ! isset( $item['id'] ) ) {
296 - return $item;
297 - }
284 + /**
285 + * Manage Sites Item
286 + *
287 + * Adds the custom column data in the Manage Sites and Monitoring tables.
288 + *
289 + * @param array $item Site comlumn data.
290 + *
291 + * @return array $item Site comlumn data.
292 + */
293 + public function hook_manage_sites_display_item( $item ) { //phpcs:ignore -- NOSONAR - complex.
294 + if ( ! is_array( $item ) || ! isset( $item['id'] ) ) {
295 + return $item;
296 + }
298 297
299 - $item_id = $item['id'];
298 + $item_id = $item['id'];
300 299
301 - if ( ! isset( $item['site-cost-tracker'] ) ) {
300 + if ( ! isset( $item['site-cost-tracker'] ) ) {
302 301
303 - $current_time = time();
304 - $upcoming1 = strtotime( gmdate( 'Y-m-d 00:00:00', $current_time ) );
305 - $upcoming2 = strtotime( '+1 month', $current_time );
302 + $current_time = time();
303 + $upcoming1 = strtotime( gmdate( 'Y-m-d 00:00:00', $current_time ) );
304 + $upcoming2 = strtotime( '+1 month', $current_time );
306 305
307 - $series_products_price = array();
308 - $total_prices = 0;
309 - $site_costs = is_array( $this->sites_costs ) && isset( $this->sites_costs[ $item_id ] ) ? $this->sites_costs[ $item_id ] : array();
310 - if ( is_array( $site_costs ) ) {
311 - foreach ( $site_costs as $cost ) {
312 - if ( 'active' !== $cost->cost_status || 'subscription' !== $cost->type ) {
313 - continue;
314 - }
315 - $next_rl = $cost->next_renewal;
316 - if ( $next_rl <= $upcoming1 ) {
317 - $next_rl = Cost_Tracker_Admin::get_next_renewal( $upcoming1, $cost->renewal_type, false );
318 - }
319 - $next_price = 0;
320 - while ( $next_rl <= $upcoming2 ) {
321 - if ( $next_rl > $upcoming1 && $next_rl <= $upcoming2 ) {
322 - $next_price = $cost->price;
323 - }
306 + $series_products_price = array();
307 + $total_prices = 0;
308 + $site_costs = is_array( $this->sites_costs ) && isset( $this->sites_costs[ $item_id ] ) ? $this->sites_costs[ $item_id ] : array();
309 + if ( is_array( $site_costs ) ) {
310 + foreach ( $site_costs as $cost ) {
311 + if ( 'active' !== $cost->cost_status || 'subscription' !== $cost->type ) {
312 + continue;
313 + }
314 + $next_rl = $cost->next_renewal;
315 + if ( $next_rl <= $upcoming1 ) {
316 + $next_rl = Cost_Tracker_Admin::get_next_renewal( $upcoming1, $cost->renewal_type, false );
317 + }
318 + $next_price = 0;
319 + while ( $next_rl <= $upcoming2 ) {
320 + if ( $next_rl > $upcoming1 && $next_rl <= $upcoming2 ) {
321 + $next_price = $cost->price;
322 + }
324 323
325 - $price = 0;
326 - if ( ! empty( $next_price ) ) {
327 - if ( 'single_site' === $cost->license_type ) {
328 - $price = $cost->price;
329 - } elseif ( 'multi_site' === $cost->license_type && ! empty( $cost->count_sites ) ) {
330 - $price = $cost->price / $cost->count_sites;
331 - }
332 - }
324 + $price = 0;
325 + if ( ! empty( $next_price ) ) {
326 + if ( 'single_site' === $cost->license_type ) {
327 + $price = $cost->price;
328 + } elseif ( 'multi_site' === $cost->license_type && ! empty( $cost->count_sites ) ) {
329 + $price = $cost->price / $cost->count_sites;
330 + }
331 + }
333 332
334 - if ( ! empty( $price ) ) {
333 + if ( ! empty( $price ) ) {
335 334
336 - if ( ! isset( $series_products_price[ $cost->id ] ) ) {
337 - $series_products_price[ $cost->id ] = 0;
338 - }
335 + if ( ! isset( $series_products_price[ $cost->id ] ) ) {
336 + $series_products_price[ $cost->id ] = 0;
337 + }
339 338
340 - $series_products_price[ $cost->id ] += $price;
341 - $total_prices += $price;
342 - }
339 + $series_products_price[ $cost->id ] += $price;
340 + $total_prices += $price;
341 + }
343 342
344 - $next_rl = Cost_Tracker_Admin::get_next_renewal( $next_rl, $cost->renewal_type, false );
345 - $next_price = 0;
346 - }
347 - }
348 - }
349 - $params = '';
350 - $selected_ids = array_keys( $series_products_price );
351 - if ( ! empty( $selected_ids ) ) {
352 - $params = '&selected_ids=' . implode( ',', $selected_ids ) . '&site_id=' . intval( $item_id );
353 - }
354 - $item['site-cost-tracker'] = '<a href="admin.php?page=ManageCostTracker' . $params . '" >' . Cost_Tracker_Utility::cost_tracker_format_price( $total_prices, true ) . '</a>';
355 - }
343 + $next_rl = Cost_Tracker_Admin::get_next_renewal( $next_rl, $cost->renewal_type, false );
344 + $next_price = 0;
345 + }
346 + }
347 + }
348 + $params = '';
349 + $selected_ids = array_keys( $series_products_price );
350 + if ( ! empty( $selected_ids ) ) {
351 + $params = '&selected_ids=' . implode( ',', $selected_ids ) . '&site_id=' . intval( $item_id );
352 + }
353 + $item['site-cost-tracker'] = '<a class="ui mini basic grey button" href="admin.php?page=ManageCostTracker' . $params . '" ><i class="file invoice dollar icon"></i>' . Cost_Tracker_Utility::cost_tracker_format_price( $total_prices, true ) . '</a>';
354 + }
356 355
357 - return $item;
358 - }
356 + return $item;
357 + }
359 358
360 359
361 360
362 - /**
363 - * Widgets screen options.
364 - *
365 - * @param array $input Input.
366 - *
367 - * @return array $input Input.
368 - */
369 - public function hook_get_widgets_screen_options( $input ) {
370 - $input['advanced-cost-tracker-costs'] = __( 'Cost Tracker', 'mainwp' );
371 - return $input;
372 - }
361 + /**
362 + * Widgets screen options.
363 + *
364 + * @param array $input Input.
365 + *
366 + * @return array $input Input.
367 + */
368 + public function hook_get_widgets_screen_options( $input ) {
369 + $input['advanced-cost-tracker-costs'] = __( 'Cost Tracker', 'mainwp' );
370 + return $input;
371 + }
373 372
374 373
375 - /**
376 - * Method hook_get_client_page_metaboxes().
377 - *
378 - * Hook Clients get metaboxes.
379 - *
380 - * @param array $widgets Client widgets.
381 - */
382 - public function hook_get_client_page_metaboxes( $widgets ) {
383 - $widgets[] = array(
384 - 'id' => 'cost-tracker-costs',
385 - 'callback' => array( Cost_Tracker_Clients_Widget::instance(), 'callback_render_costs_widget' ),
386 - );
387 - return $widgets;
388 - }
374 + /**
375 + * Method hook_get_client_page_metaboxes().
376 + *
377 + * Hook Clients get metaboxes.
378 + *
379 + * @param array $widgets Client widgets.
380 + */
381 + public function hook_get_client_page_metaboxes( $widgets ) {
382 + $widgets[] = array(
383 + 'id' => 'cost-tracker-costs',
384 + 'callback' => array( Cost_Tracker_Clients_Widget::instance(), 'callback_render_costs_widget' ),
385 + );
386 + return $widgets;
387 + }
389 388
390 - /**
391 - * Widgets screen options.
392 - *
393 - * @param array $input Input.
394 - *
395 - * @return array $input Input.
396 - */
397 - public function hook_get_site_overview_screen_options( $input ) {
398 - $input['advanced-cost-tracker-costs'] = __( 'Cost Tracker', 'mainwp' );
399 - return $input;
400 - }
401 -
402 -
403 - /**
404 - * Method hook_get_client_page_metaboxes().
405 - *
406 - * Hook Clients get metaboxes.
407 - *
408 - * @param array $widgets Client widgets.
409 - * @param int $dashboard_siteid Site Id.
410 - *
411 - * @return array $widgets Widgets data.
412 - */
413 - public function hook_get_site_overview_page_metaboxes( $widgets, $dashboard_siteid = 0 ) {
414 - if ( ! empty( $dashboard_siteid ) ) {
415 - $widgets[] = array(
416 - 'id' => 'cost-tracker-widget',
417 - 'callback' => array( Cost_Tracker_Sites_Widget::instance(), 'callback_render_costs_widget' ),
418 - );
419 - }
420 - return $widgets;
421 - }
389 + /**
390 + * Method hook_get_client_page_metaboxes().
391 + *
392 + * Hook Clients get metaboxes.
393 + *
394 + * @param array $widgets Client widgets.
395 + * @param int $dashboard_siteid Site Id.
396 + *
397 + * @return array $widgets Widgets data.
398 + */
399 + public function hook_get_site_overview_page_metaboxes( $widgets, $dashboard_siteid = 0 ) {
400 + if ( ! empty( $dashboard_siteid ) ) {
401 + $widgets[] = array(
402 + 'id' => 'cost-tracker-widget',
403 + 'callback' => array( Cost_Tracker_Sites_Widget::instance(), 'callback_render_costs_widget' ),
404 + );
405 + }
406 + return $widgets;
407 + }
422 408 }