This repository has been archived by the owner on Oct 27, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcovid.php
660 lines (584 loc) · 25 KB
/
covid.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
<?php
/*
Plugin Name: Coronavirus COVID-19 Watch
Plugin URI: https://mmediagroup.fr/covid-19
Description: Free live, historical, and vaccine data with total cases around the world or by country. Get live data on the admin dashboard, using the helpful link in the top toolbar to quickly get more info, or via shortcode (by country or global). There's even a widget that you can add to your footers, menus, and widget areas.
Author: M Media
Version: 1.5.0
Author URI: https://profiles.wordpress.org/mmediagroup/
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
{Plugin Name} is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
any later version.
{Plugin Name} is distributed in the hope that it will be useful to Covid clients,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with {Plugin Name}. If not, see {License URI}.
*/
if (!defined('MMEDIA_COVID_VER')) {
define('MMEDIA_COVID_VER', '1.5.0');
}
// Start up the engine
class MMedia_Covid
{
/**
* Static property to hold our singleton instance
*
*/
public static $instance = false;
private static $request_args;
/**
* This is our constructor
*
* @return void
*/
private function __construct()
{
self::$request_args = array('headers' => array("Accept" => "application/json", "origin" => site_url()));
// register_activation_hook(__FILE__, array($this, 'covid_install'));
// register_deactivation_hook(__FILE__, array($this, 'covid_uninstall'));
// back end
add_action('admin_enqueue_scripts', array($this, 'admin_scripts'), 999);
add_action('wp_enqueue_scripts', array($this, 'load_scripts'));
add_action('do_meta_boxes', array($this, 'create_metaboxes'), 10, 2);
add_filter('auto_update_plugin', array($this, 'auto_update_specific_plugins'), 10, 2);
add_action('admin_init', array($this, 'handle_admin_init'));
// add_action('admin_menu', array($this, 'covid_create_menu'));
// add_action('admin_menu', array($this, 'covid_remove_menus'), 999);
// add_action('admin_notices', array($this, 'my_error_notice'));
// add_action('wp_dashboard_setup', array($this, 'my_custom_dashboard_widgets'));
add_action('widgets_init', array($this, 'wpdocs_register_widgets'));
add_action('admin_bar_menu', array($this, 'covid_remove_toolbar_nodes'), 999);
add_shortcode('covid-watch', array($this, 'shortcode_cases'));
add_shortcode('covid-history', array($this, 'shortcode_history'));
add_shortcode('covid-vaccines', array($this, 'shortcode_vaccines'));
add_shortcode('covid-live-map', array($this, 'shortcode_map'));
}
public static function getCasesData()
{
$body = get_transient('mmedia_covid_cases');
if (false === $body) {
$response = wp_remote_get('https://covid-api.mmediagroup.fr/v1/cases', self::$request_args);
$body = json_decode($response['body'], true);
set_transient('mmedia_covid_cases', $body, HOUR_IN_SECONDS);
}
return $body;
}
public static function getHistoryData($status = 'confirmed')
{
$body = get_transient('mmedia_covid_history_' . $status);
if (false === $body) {
$response = wp_remote_get('https://covid-api.mmediagroup.fr/v1/history?status=' . $status, self::$request_args);
$body = json_decode($response['body'], true);
set_transient('mmedia_covid_history_' . $status, $body, DAY_IN_SECONDS);
}
return $body;
}
public static function getVaccinesData()
{
$body = get_transient('mmedia_covid_vaccines');
if (false === $body) {
$response = wp_remote_get('https://covid-api.mmediagroup.fr/v1/vaccines', self::$request_args);
$body = json_decode($response['body'], true);
set_transient('mmedia_covid_vaccines', $body, DAY_IN_SECONDS);
}
return $body;
}
public function shortcode_cases($atts = [], $content = null)
{
// do something to $content
// always return
$atts = array_change_key_case((array) $atts, CASE_LOWER);
// override default attributes with user attributes
$covid_atts = shortcode_atts([
'country' => 'Global',
'status' => 'confirmed',
'sort' => 'alphabetical',
'limit' => 0,
], $atts);
$body = $this->getCasesData();
if (strtolower($covid_atts['country']) == 'all') {
$covid_atts['sort'] = strtolower($covid_atts['sort']);
if ($covid_atts['sort'] == 'confirmed' || $covid_atts['sort'] == 'deaths') {
uasort($body, function (array $a, array $b) use ($covid_atts) {
return $b['All'][$covid_atts['sort']] - $a['All'][$covid_atts['sort']];
});
} else {
ksort($body);
}
$iteration = 0;
$html = "<table>";
$html .= "<tr>";
$html .= "<th>" . __('Country', 'coronavirus-covid-19-watch') . "</th>";
$html .= "<th>" . __('Confirmed cases', 'coronavirus-covid-19-watch') . "</th>";
$html .= "<th>" . __('Deaths', 'coronavirus-covid-19-watch') . "</th>";
$html .= "</tr>";
foreach ($body as $key => $value) {
if ($key == 'Global') {
continue;
}
if ($covid_atts['limit'] !== 0 && $iteration == $covid_atts['limit']) {
break;
}
$html .= "<tr>";
$html .= "<td>" . $key . "</td>";
$html .= "<td>" . number_format($value['All']['confirmed']) . "</td>";
$html .= "<td>" . number_format($value['All']['deaths']) . "</td>";
$html .= "</tr>";
$iteration++;
}
$html .= "<tr>";
$html .= "<td><strong>Global</strong></td>";
$html .= "<td>" . number_format($body['Global']['All']['confirmed']) . "</td>";
$html .= "<td>" . number_format($body['Global']['All']['deaths']) . "</td>";
$html .= "</tr>";
if (get_option('covid_setting_attribute')) {
$html .= "<tfoot><tr>";
$html .= "<td><strong>" . __('API provider', 'coronavirus-covid-19-watch') . "</strong></td>";
$html .= '<td><strong><a href="https://mmediagroup.fr/covid-19?utm_source=wordpress&utm_medium=covid_plugin&utm_campaign=' . get_site_url() . '&utm_content=shortcode_cases" target="_BLANK" rel="noreferrer">M Media</a></strong></td>';
$html .= "<td></td>";
$html .= "</tr></tfoot>";
}
$html .= "</table>";
return $html;
} elseif (isset($body[esc_html__($covid_atts['country'])])) {
$number = number_format($body[esc_html__($covid_atts['country'])]['All'][esc_html__($covid_atts['status'])]);
return get_option('covid_setting_attribute') ? '<a href="https://mmediagroup.fr/covid-19?utm_source=wordpress&utm_medium=covid_plugin&utm_campaign=' . get_site_url() . '&utm_content=shortcode_cases" target="_BLANK" rel="noreferrer">' . $number . '</a>' : $number;
}
return "Country '" . $covid_atts['country'] . "' is invalid.";
}
public function shortcode_history($atts = [], $content = null)
{
// do something to $content
// always return
$atts = array_change_key_case((array) $atts, CASE_LOWER);
// override default attributes with user attributes
$covid_atts = shortcode_atts([
'country' => 'Global',
'status' => 'confirmed',
'limit' => 0,
], $atts);
$body = $this->getHistoryData(esc_html__($covid_atts['status']));
if (isset($body[esc_html__($covid_atts['country'])])) {
$body = $body[esc_html__($covid_atts['country'])]['All']['dates'];
} else {
return "Country '" . $covid_atts['country'] . "' or status is invalid.";
}
$html = "<table>";
$html .= "<tr>";
$html .= "<th>" . __('Date', 'coronavirus-covid-19-watch') . " (YYYY-MM-DD)</th>";
$html .= "<th>" . ($covid_atts['status'] == 'confirmed' ? __('Cases', 'coronavirus-covid-19-watch') : __('Deaths', 'coronavirus-covid-19-watch')) . " (" . esc_html__($covid_atts['country']) . ")</th>";
$html .= "</tr>";
$iteration = 0;
foreach ($body as $key => $value) {
if ($covid_atts['limit'] !== 0 && $iteration == $covid_atts['limit']) {
break;
}
$html .= "<tr>";
$html .= "<td>" . $key . "</td>";
$html .= "<td>" . number_format($value) . "</td>";
$html .= "</tr>";
$iteration++;
}
if (get_option('covid_setting_attribute')) {
$html .= "<tfoot><tr>";
$html .= "<td><strong>" . __('API provider', 'coronavirus-covid-19-watch') . "</strong></td>";
$html .= '<td><strong><a href="https://mmediagroup.fr/covid-19?utm_source=wordpress&utm_medium=covid_plugin&utm_campaign=' . get_site_url() . '&utm_content=shortcode_history" target="_BLANK" rel="noreferrer">M Media</a></strong></td>';
$html .= "</tr></tfoot>";
}
$html .= "</table>";
return $html;
}
public function shortcode_vaccines($atts = [], $content = null)
{
// do something to $content
// always return
$atts = array_change_key_case((array) $atts, CASE_LOWER);
// override default attributes with user attributes
$covid_atts = shortcode_atts([
'country' => 'Global',
'status' => 'administered',
'sort' => 'alphabetical',
'limit' => 0,
], $atts);
$body = $this->getVaccinesData();
if (strtolower($covid_atts['country']) == 'all') {
$covid_atts['sort'] = strtolower($covid_atts['sort']);
if ($covid_atts['sort'] == 'administered' || $covid_atts['sort'] == 'people_vaccinated') {
uasort($body, function (array $a, array $b) use ($covid_atts) {
return $b['All'][$covid_atts['sort']] - $a['All'][$covid_atts['sort']];
});
} else {
ksort($body);
}
$iteration = 0;
$html = "<table>";
$html .= "<tr>";
$html .= "<th>" . __('Country', 'coronavirus-covid-19-watch') . "</th>";
$html .= "<th>" . __('Administered vaccines', 'coronavirus-covid-19-watch') . "</th>";
$html .= "<th>" . __('People vaccinated', 'coronavirus-covid-19-watch') . "</th>";
$html .= "<th>" . __('People partially vaccinated', 'coronavirus-covid-19-watch') . "</th>";
$html .= "</tr>";
foreach ($body as $key => $value) {
if ($key == 'Global') {
continue;
}
if ($covid_atts['limit'] !== 0 && $iteration == $covid_atts['limit']) {
break;
}
$html .= "<tr>";
$html .= "<td>" . $key . "</td>";
$html .= "<td>" . number_format($value['All']['administered']) . "</td>";
$html .= "<td>" . number_format($value['All']['people_vaccinated']) . "</td>";
$html .= "<td>" . number_format($value['All']['people_partially_vaccinated']) . "</td>";
$html .= "</tr>";
$iteration++;
}
$html .= "<tr>";
$html .= "<td><strong>Global</strong></td>";
$html .= "<td>" . number_format($body['Global']['All']['administered']) . "</td>";
$html .= "<td>" . number_format($body['Global']['All']['people_vaccinated']) . "</td>";
$html .= "<td>" . number_format($body['Global']['All']['people_partially_vaccinated']) . "</td>";
$html .= "</tr>";
if (get_option('covid_setting_attribute')) {
$html .= "<tfoot><tr>";
$html .= "<td><strong>" . __('API provider', 'coronavirus-covid-19-watch') . "</strong></td>";
$html .= '<td><strong><a href="https://mmediagroup.fr/covid-19?utm_source=wordpress&utm_medium=covid_plugin&utm_campaign=' . get_site_url() . '&utm_content=shortcode_vaccines" target="_BLANK" rel="noreferrer">M Media</a></strong></td>';
$html .= "<td></td>";
$html .= "</tr></tfoot>";
}
$html .= "</table>";
return $html;
} elseif (isset($body[esc_html__($covid_atts['country'])])) {
$number = number_format($body[esc_html__($covid_atts['country'])]['All'][esc_html__($covid_atts['status'])]);
return get_option('covid_setting_attribute') ? '<a href="https://mmediagroup.fr/covid-19?utm_source=wordpress&utm_medium=covid_plugin&utm_campaign=' . get_site_url() . '&utm_content=shortcode_vaccines" target="_BLANK" rel="noreferrer">' . $number . '</a>' : $number;
}
return "Country '" . $covid_atts['country'] . "' is invalid.";
}
public static function shortcode_map($atts = [], $content = null)
{
wp_enqueue_style('covid-map-css');
wp_enqueue_script('covid-map-js');
$div_id = 'svgMapPopulation' . rand();
wp_enqueue_script('map-data-' . $div_id, plugin_dir_url(__FILE__) . '/js/map-data.js', array(), MMEDIA_COVID_VER, 'all');
// do something to $content
// always return
$atts = array_change_key_case((array) $atts, CASE_LOWER);
// override default attributes with user attributes
$covid_atts = shortcode_atts([
'sort' => 'confirmed',
'height' => '70vh',
], $atts);
$body = self::getCasesData();
unset($body['Global']);
$translation_array = array(
'json_data' => $body,
'selector' => $div_id,
'color_by' => $covid_atts['sort'],
'attribution_text' => __('Data source', 'coronavirus-covid-19-watch') . ': <a href="https://mmediagroup.fr/covid-19?utm_source=wordpress&utm_medium=covid_plugin&utm_campaign=' . get_site_url() . '&utm_content=shortcode_map" target="_BLANK" rel="noreferrer">M Media API</a>',
);
wp_localize_script('map-data-' . $div_id, 'covid_data', $translation_array);
$html = '<div id="' . $div_id . '" style="height: ' . esc_html__($covid_atts['height']) . ';"></div>';
return $html;
}
/**
* If an instance exists, this returns it. If not, it creates one and
* retuns it.
*
* @return Covid
*/
public static function getInstance()
{
if (!self::$instance) {
self::$instance = new self;
}
return self::$instance;
}
public function wpdocs_register_widgets()
{
register_widget('MMedia_Covid_Widget');
}
/**
* load textdomain
*
* @return void
*/
public function covid_install()
{
}
/**
* load textdomain
*
* @return void
*/
public function covid_uninstall()
{
}
/**
* Admin styles
*
* @return void
*/
public function admin_scripts()
{
if (function_exists('covid19_style')) {
wp_enqueue_style('style.css', plugin_dir_url(__FILE__) . '/css/style.css', array(), MMEDIA_COVID_VER, 'all');
}
}
public function load_scripts()
{
wp_register_style('covid-map-css', plugin_dir_url(__FILE__) . '/css/svgMap.css');
wp_register_script('covid-map-js', plugin_dir_url(__FILE__) . '/js/svgMap.js');
}
/**
* call metabox
*
* @return void
*/
public function create_metaboxes($context)
{
add_meta_box('covid_help_widget', 'COVID-19 Watch (' . get_option('covid_setting_country') . ')', array($this, 'custom_dashboard_help'), 'dashboard', 'normal', 'high');
}
/**
* Enable auto updates
*
* @return void
*/
public function auto_update_specific_plugins($update, $item)
{
$plugins = array('coronavirus-covid-19-watch');
if (in_array($item->slug, $plugins)) {
// update plugin
return true;
} else {
// use default settings
return $update;
}
}
/**
* display meta fields for notes meta
*
* @return void
*/
public function custom_dashboard_help($post)
{
$body = $this->getCasesData();
echo '<div style="text-align: center;"><h2>' . number_format($body[get_option('covid_setting_country')]['All']['confirmed']) . ' ' . __('confirmed cases', 'coronavirus-covid-19-watch') . '</h2><h3>' . number_format($body[get_option('covid_setting_country')]['All']['deaths']) . ' ' . __('deaths', 'coronavirus-covid-19-watch') . '</h3><p>' . __('Only cases tested in a laboratory are counted; with news of sketchy reporting and others staying at home, there\'s more cases out there.', 'coronavirus-covid-19-watch') . '</p><a class="button" href="https://mmediagroup.fr/covid-19?utm_source=wordpress&utm_medium=covid_plugin&utm_campaign=' . get_site_url() . '&utm_content=dashboard" target="_BLANK" rel="noreferrer">' . __('More info', 'coronavirus-covid-19-watch') . '</a></div>';
}
/**
* load textdomain
*
* @return void
*/
public function covid_create_menu()
{
//create new top-level menu
// add_menu_page('Covid Plugin', 'Covid',
// 'publish_pages', 'covid_main_menu', array($this, 'covid_settings_page'),
// plugins_url('images/m.svg', __FILE__));
}
/**
* load textdomain
*
* @return void
*/
public function covid_remove_menus()
{
}
/**
* load textdomain
*
* @return void
*/
public function my_error_notice()
{
}
/**
* load textdomain
*
* @return void
*/
public function my_custom_dashboard_widgets()
{
}
/**
* load textdomain
*
* @return void
*/
public function covid_remove_toolbar_nodes($wp_admin_bar)
{
if (get_option('covid_setting_toolbar')) {
$wp_admin_bar->add_node([
'id' => 'covid',
'title' => 'COVID Watch',
'href' => 'https://mmediagroup.fr/covid-19?utm_source=wordpress&utm_medium=covid_plugin&utm_campaign=' . get_site_url() . '&utm_content=toolbar',
'meta' => [
'target' => '_BLANK',
],
]);
}
}
/**
* load textdomain
*
* @return void
*/
public function handle_admin_init()
{
// register_nav_menu('covid-menu', __('Covid Menu'));
// register a new section in the "reading" page
register_setting('reading', 'covid_setting_country', array(
'type' => 'string',
'sanitize_callback' => array($this, 'validateCountry'),
'default' => 'Global',
));
register_setting('reading', 'covid_setting_attribute', array(
'type' => 'boolean',
'default' => false,
));
register_setting('reading', 'covid_setting_toolbar', array(
'type' => 'boolean',
'default' => false,
));
add_settings_section(
'covid_settings_section',
'COVID-19 Watch',
array($this, 'covid_settings_section_cb'),
'reading'
);
// register a new field in the "covid_settings_section" section, inside the "reading" page
add_settings_field(
'covid_settings_field',
__('Dashboard country', 'coronavirus-covid-19-watch'),
array($this, 'covid_settings_field_cb'),
'reading',
'covid_settings_section'
);
add_settings_field(
'covid_settings_field_attr',
__('Show attribution', 'coronavirus-covid-19-watch'),
array($this, 'covid_settings_field_attribute'),
'reading',
'covid_settings_section'
);
add_settings_field(
'covid_settings_field_toolbarmenu',
__('Show toolbar menu', 'coronavirus-covid-19-watch'),
array($this, 'covid_settings_field_toolbar'),
'reading',
'covid_settings_section'
);
}
public function validateCountry($input)
{
if (!$input) {
return "Global";
}
$body = $this->getCasesData();
if (isset($body[$input])) {
return $input;
}
return 'INVALID COUNTRY';
}
/**
* register covid_settings_init to the admin_init action hook
*/
/**
* callback functions
*/
// section content cb
public function covid_settings_section_cb()
{
echo '<p>Control settings regarding the Coronavirus COVID-19 Watch plugin.</p>';
}
public function covid_settings_field_cb()
{
$setting = get_option('covid_setting_country');
$array = $this->getCasesData();
ksort($array); ?>
<select id="covid_setting_country" name="covid_setting_country" value="<?php echo $setting ? esc_attr($setting) : 'Global'; ?>">
<?php
foreach ($array as $key => $value) {
echo '<option value="' . $key . '" ' . ($setting == $key ? 'selected' : '') . '>' . $key . '</option>';
} ?>
</select>
<p class="description"><?php _e('Try Global, US, France, Spain, Italy, United Kingdom, and more.', 'coronavirus-covid-19-watch'); ?></p>
<?php
}
public function covid_settings_field_attribute()
{
// get the value of the setting we've registered with register_setting()
$setting = get_option('covid_setting_attribute');
// output the field?>
<fieldset>
<legend class="screen-reader-text"><span><?php _e('Show attribution', 'coronavirus-covid-19-watch'); ?></span></legend>
<label for="covid_setting_attribute"><input type="checkbox" id="covid_setting_attribute" name="covid_setting_attribute" <?php echo $setting ? 'checked="checked"' : ''; ?>><?php _e('Attribute M Media, the maker of this plugin and API for the data from Johns Hopkins University, on the front-end.', 'coronavirus-covid-19-watch'); ?></label>
</fieldset>
<?php
}
public function covid_settings_field_toolbar()
{
// get the value of the setting we've registered with register_setting()
$setting = get_option('covid_setting_toolbar');
// output the field?>
<fieldset>
<legend class="screen-reader-text"><span><?php _e('Show toolbar menu', 'coronavirus-covid-19-watch'); ?></span></legend>
<label for="covid_setting_toolbar"><input type="checkbox" id="covid_setting_toolbar" name="covid_setting_toolbar" <?php echo $setting ? 'checked="checked"' : ''; ?>><?php _e('Show the toolbar menu at the top', 'coronavirus-covid-19-watch'); ?></label>
</fieldset>
<?php
}
public function covid_settings_page()
{
}
/// end class
}
class MMedia_Covid_Widget extends WP_Widget
{
public function __construct()
{
parent::__construct(
'covid-widget', // Base ID
__('COVID-19 confirmed cases', 'coronavirus-covid-19-watch') // Name
);
add_action('widgets_init', function () {
register_widget('MMedia_Covid_Widget');
});
}
public $args = array(
'before_title' => '<h4 class="widgettitle">',
'after_title' => '</h4>',
'before_widget' => '<div class="widget-wrap">',
'after_widget' => '</div></div>',
);
public function widget($args, $instance)
{
$body = MMedia_Covid::getCasesData();
$number = number_format($body['Global']['All']['confirmed']);
echo $args['before_widget'];
// if (!empty($instance['title'])) {
// echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title'];
// }
echo '<div class="textwidget">';
echo get_option('covid_setting_attribute') ? '<a href="https://mmediagroup.fr/covid-19?utm_source=wordpress&utm_medium=covid_plugin&utm_campaign=' . get_site_url() . '&utm_content=widget" target="_BLANK" rel="noreferrer">' . $number . '</a>' : $number;
echo ' ' . __('confirmed cases', 'coronavirus-covid-19-watch');
echo '</div>';
echo $args['after_widget'];
}
public function form($instance)
{
}
public function update($new_instance, $old_instance)
{
$instance = array();
// $instance['title'] = (!empty($new_instance['title'])) ? strip_tags($new_instance['title']) : '';
// $instance['text'] = (!empty($new_instance['text'])) ? $new_instance['text'] : '';
return $instance;
}
}
// Instantiate our class
$covid = MMedia_Covid::getInstance();