PluginProbe
Independent Analytics – WordPress Analytics Plugin / 2.8.9
Independent Analytics – WordPress Analytics Plugin v2.8.9
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 All 120 releases
independent-analytics / IAWP / AJAX / Set_Favorite_Report.php
Set_Favorite_Report.php
39 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IAWP\AJAX;
4
5 use IAWP\Report;
6 use IAWP\Report_Finder;
7 /** @internal */
8 class Set_Favorite_Report extends \IAWP\AJAX\AJAX
9 {
10 /**
11 * @inheritDoc
12 */
13 protected function action_name() : string
14 {
15 return 'iawp_set_favorite_report';
16 }
17 /**
18 * @inheritDoc
19 */
20 protected function action_callback() : void
21 {
22 $id = $this->get_field('id');
23 $type = $this->get_field('type');
24 if (!\is_null(Report_Finder::by_id($id))) {
25 \delete_user_meta(\get_current_user_id(), 'iawp_favorite_report_id');
26 \delete_user_meta(\get_current_user_id(), 'iawp_favorite_report_type');
27 \update_user_meta(\get_current_user_id(), 'iawp_favorite_report_id', $id);
28 \wp_send_json_success([]);
29 }
30 if (Report::is_valid_report_type($type)) {
31 \delete_user_meta(\get_current_user_id(), 'iawp_favorite_report_id');
32 \delete_user_meta(\get_current_user_id(), 'iawp_favorite_report_type');
33 \update_user_meta(\get_current_user_id(), 'iawp_favorite_report_type', $type);
34 \wp_send_json_success([]);
35 }
36 \wp_send_json_error([], 400);
37 }
38 }
39