| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* @package Logtivity |
| 5 |
* @contact logtivity.io, hello@logtivity.io |
| 6 |
* @copyright 2024-2026 Logtivity. All rights reserved |
| 7 |
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL |
| 8 |
* |
| 9 |
* This file is part of Logtivity. |
| 10 |
* |
| 11 |
* Logtivity is free software: you can redistribute it and/or modify |
| 12 |
* it under the terms of the GNU General Public License as published by |
| 13 |
* the Free Software Foundation, either version 2 of the License, or |
| 14 |
* (at your option) any later version. |
| 15 |
* |
| 16 |
* Logtivity is distributed in the hope that it will be useful, |
| 17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 |
* GNU General Public License for more details. |
| 20 |
* |
| 21 |
* You should have received a copy of the GNU General Public License |
| 22 |
* along with Logtivity. If not, see <https://www.gnu.org/licenses/>. |
| 23 |
*/ |
| 24 |
|
| 25 |
// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols |
| 26 |
// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace |
| 27 |
// phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps |
| 28 |
|
| 29 |
class Logtivity_Dismiss_Notice_Controller |
| 30 |
{ |
| 31 |
/** |
| 32 |
* @var string[] |
| 33 |
*/ |
| 34 |
protected array $notices = [ |
| 35 |
'logtivity-site-url-has-changed-notice', |
| 36 |
]; |
| 37 |
|
| 38 |
public function __construct() |
| 39 |
{ |
| 40 |
add_action('wp_ajax_nopriv_logtivity_dismiss_notice', [$this, 'dismiss']); |
| 41 |
add_action('wp_ajax_logtivity_dismiss_notice', [$this, 'dismiss']); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* @return self |
| 46 |
*/ |
| 47 |
public static function init(): self |
| 48 |
{ |
| 49 |
return new static(); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* @return void |
| 54 |
*/ |
| 55 |
public function dismiss(): void |
| 56 |
{ |
| 57 |
if (!current_user_can(Logtivity::ACCESS_SETTINGS)) { |
| 58 |
wp_die(__('You do not have sufficient permissions to access this page.')); |
| 59 |
} |
| 60 |
|
| 61 |
$postType = sanitize_text_field($_POST['postType'] ?? null); |
| 62 |
if (in_array($postType, $this->notices)) { |
| 63 |
$dismissUntil = sanitize_text_field($_POST['dismissUntil'] ?? null); |
| 64 |
|
| 65 |
if ($dismissUntil) { |
| 66 |
set_transient( |
| 67 |
'dismissed-' . $postType, |
| 68 |
true, |
| 69 |
(int)$dismissUntil |
| 70 |
); |
| 71 |
} else { |
| 72 |
update_option('dismissed-' . $postType, true); |
| 73 |
} |
| 74 |
|
| 75 |
wp_send_json(['message' => 'success']); |
| 76 |
} |
| 77 |
} |
| 78 |
} |
| 79 |
|