| 1 |
<?php |
| 2 |
/** |
| 3 |
* SEO Plugin Notice Manager |
| 4 |
* |
| 5 |
* Handles admin notices for SEO plugin conflicts |
| 6 |
* |
| 7 |
* @package ThinkRank\Admin |
| 8 |
* @since 1.0.0 |
| 9 |
*/ |
| 10 |
|
| 11 |
declare(strict_types=1); |
| 12 |
|
| 13 |
namespace ThinkRank\Admin; |
| 14 |
|
| 15 |
use ThinkRank\Core\SEO_Plugin_Detector; |
| 16 |
|
| 17 |
// Prevent direct access |
| 18 |
if (!defined('ABSPATH')) { |
| 19 |
exit; |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* SEO Notice Manager Class |
| 24 |
* |
| 25 |
* Single Responsibility: Display admin notices for SEO plugin conflicts |
| 26 |
* |
| 27 |
* @since 1.0.0 |
| 28 |
*/ |
| 29 |
class SEO_Notice { |
| 30 |
|
| 31 |
/** |
| 32 |
* Initialize notice manager |
| 33 |
* |
| 34 |
* @return void |
| 35 |
*/ |
| 36 |
public function init(): void { |
| 37 |
add_action('admin_notices', [$this, 'display_seo_plugin_notice']); |
| 38 |
add_action('wp_ajax_thinkrank_dismiss_seo_notice', [$this, 'ajax_dismiss_notice']); |
| 39 |
add_action('admin_enqueue_scripts', [$this, 'enqueue_notice_scripts']); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Display SEO plugin conflict notice |
| 44 |
* |
| 45 |
* @return void |
| 46 |
*/ |
| 47 |
public function display_seo_plugin_notice(): void { |
| 48 |
if (!SEO_Plugin_Detector::should_show_notice()) { |
| 49 |
return; |
| 50 |
} |
| 51 |
|
| 52 |
$message = SEO_Plugin_Detector::get_notice_message(); |
| 53 |
if (empty($message)) { |
| 54 |
return; |
| 55 |
} |
| 56 |
|
| 57 |
?> |
| 58 |
<div class="notice notice-warning is-dismissible thinkrank-seo-notice"> |
| 59 |
<h3><?php esc_html_e('ThinkRank SEO Priority', 'thinkrank'); ?></h3> |
| 60 |
<p><?php echo esc_html($message); ?></p> |
| 61 |
|
| 62 |
<p> |
| 63 |
<strong><?php esc_html_e('How it works:', 'thinkrank'); ?></strong><br> |
| 64 |
• <?php esc_html_e('Posts with ThinkRank AI metadata → ThinkRank takes priority', 'thinkrank'); ?><br> |
| 65 |
• <?php esc_html_e('Posts without ThinkRank metadata → Other SEO plugins work normally', 'thinkrank'); ?><br> |
| 66 |
• <?php esc_html_e('You have full control per post', 'thinkrank'); ?> |
| 67 |
</p> |
| 68 |
|
| 69 |
<p> |
| 70 |
<a href="#" class="button button-secondary thinkrank-dismiss-seo-notice"> |
| 71 |
<?php esc_html_e('Got it, dismiss this notice', 'thinkrank'); ?> |
| 72 |
</a> |
| 73 |
</p> |
| 74 |
</div> |
| 75 |
<?php |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* Enqueue notice scripts |
| 80 |
* |
| 81 |
* @param string $hook Current admin page hook |
| 82 |
* @return void |
| 83 |
*/ |
| 84 |
public function enqueue_notice_scripts(string $hook): void { |
| 85 |
if (!SEO_Plugin_Detector::has_seo_plugins()) { |
| 86 |
return; |
| 87 |
} |
| 88 |
|
| 89 |
wp_add_inline_script('jquery', ' |
| 90 |
jQuery(document).ready(function($) { |
| 91 |
$(".thinkrank-dismiss-seo-notice").on("click", function(e) { |
| 92 |
e.preventDefault(); |
| 93 |
|
| 94 |
$.post(ajaxurl, { |
| 95 |
action: "thinkrank_dismiss_seo_notice", |
| 96 |
nonce: "' . wp_create_nonce('thinkrank_seo_notice_nonce') . '" |
| 97 |
}, function(response) { |
| 98 |
if (response.success) { |
| 99 |
$(".thinkrank-seo-notice").fadeOut(); |
| 100 |
} |
| 101 |
}); |
| 102 |
}); |
| 103 |
}); |
| 104 |
'); |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* AJAX handler to dismiss SEO notice |
| 109 |
* |
| 110 |
* @return void |
| 111 |
*/ |
| 112 |
public function ajax_dismiss_notice(): void { |
| 113 |
$nonce = sanitize_text_field(wp_unslash($_POST['nonce'] ?? '')); |
| 114 |
if (!wp_verify_nonce($nonce, 'thinkrank_seo_notice_nonce')) { |
| 115 |
wp_send_json_error('Security check failed'); |
| 116 |
} |
| 117 |
|
| 118 |
SEO_Plugin_Detector::dismiss_notice(); |
| 119 |
wp_send_json_success(); |
| 120 |
} |
| 121 |
} |
| 122 |
|