🚀 Upgrade to Pro',
'manage_options',
'aicomo-upgrade', // Renamed slug
'aicomo_upgrade_page'
);
add_submenu_page(
'ai-comment-auto-moderator',
__('Documentation', 'ai-powered-comment-moderator'),
'Documentation',
'manage_options',
'aicomo-documentation', // Renamed slug
'aicomo_documentation_page'
);
}
add_action('admin_menu', 'aicomo_add_admin_menu');
// ?? Admin Notice for Premium Upgrade
function aicomo_admin_notice() {
if (!get_option('aicomo_dismiss_notice')) {
?>
' . esc_html__('?? Settings', 'ai-powered-comment-moderator') . '';
$premium_link = '?? ' . esc_html__('Premium Features', 'ai-powered-comment-moderator') . '';
$docs_link = '' . esc_html__('?? Documentation', 'ai-powered-comment-moderator') . '';
// Insert links before the default "Deactivate"
array_unshift($links, $settings_link, $premium_link, $docs_link);
return $links;
}
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'aicomo_plugin_action_links');
// ?? AI Moderator Pro - Upgrade Page
function aicomo_upgrade_page() {
?>
📚 AI Moderator Documentation
Everything you need to know about AI-powered comment moderation.
📌 Getting Started
Configure your AI settings in
Settings.
❓ FAQ
How does AI filtering work? AI detects spam, toxicity, and inappropriate content.
Is AI 100% accurate? AI is highly effective, but manual review is recommended for certain cases.
🔧 AI Moderator Settings Explained
The AI Moderator plugin includes the following settings for fine-tuned AI comment filtering:
?? Settings';
$premium_link = 'Go Premium';
$feedback_link = 'Give Feedback';
array_unshift($links, $settings_link, $premium_link, $feedback_link);
return $links;
}
add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'aicomo_plugin_link3');
function aicomo_enqueue_scripts($hook) {
if ($hook !== 'toplevel_page_ai-comment-auto-moderator') {
return;
}
wp_enqueue_script('ai-moderator-js', plugin_dir_url(__FILE__) . 'js/ai-moderator.js', ['jquery'], '1.1.0', true);
wp_enqueue_script('ai-moderator-js', plugin_dir_url(__FILE__) . 'js/ai-main-mod.js', ['jquery'], '1.1.0', true);
wp_localize_script('ai-moderator-js', 'aiModeratorAjax', [
'ajaxurl' => admin_url('admin-ajax.php'),
'security' => wp_create_nonce('ai-moderator-nonce')
]);
}
add_action('admin_enqueue_scripts', 'aicomo_enqueue_scripts');
function aicomo_display_comments() {
if (!current_user_can('manage_options')) {
wp_die(esc_html__('Sorry, you are not allowed to access this page.', 'ai-powered-comment-moderator'));
}
global $wpdb;
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$per_page = isset($_GET['per_page']) ? absint($_GET['per_page']) : 50;
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$current_page = isset($_GET['paged']) ? absint($_GET['paged']) : 1;
// New filters (author, decision, keyword)
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$author_filter = isset($_GET['author_filter']) ? sanitize_text_field( wp_unslash($_GET['author_filter']) ) : '';
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$decision_filter = isset($_GET['decision_filter']) ? sanitize_text_field( wp_unslash($_GET['decision_filter']) ) : '';
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$keyword_filter = isset($_GET['keyword_filter']) ? sanitize_text_field( wp_unslash($_GET['keyword_filter']) ) : '';
if ($per_page < 1) {
$per_page = 50;
}
if ($current_page < 1) {
$current_page = 1;
}
$offset = ($current_page - 1) * $per_page;
// Count total comments (unchanged)
$count_cache_key = 'ai_mod_comment_count';
$count_cache_group = 'ai_moderator';
$total_comments = wp_cache_get($count_cache_key, $count_cache_group);
if (false === $total_comments) {
// ...
}
// Build a WHERE clause for filters
$where = "WHERE 1=1";
if ( $author_filter !== '' ) {
$where .= $wpdb->prepare(
" AND c.comment_author LIKE %s",
'%' . $wpdb->esc_like($author_filter) . '%'
);
}
if ( $decision_filter !== '' ) {
$where .= $wpdb->prepare(
" AND h.action = %s",
$decision_filter
);
}
if ( $keyword_filter !== '' ) {
$where .= $wpdb->prepare(
" AND c.comment_content LIKE %s",
'%' . $wpdb->esc_like($keyword_filter) . '%'
);
}
// Combine filter keys into the cache key
$comments_cache_key = "ai_mod_comments_{$current_page}_{$per_page}_"
. md5($author_filter.$decision_filter.$keyword_filter);
$comments_cache_group = 'ai_moderator';
$comments = wp_cache_get($comments_cache_key, $comments_cache_group);
if (false === $comments) {
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery
$comments = $wpdb->get_results($wpdb->prepare("SELECT c.comment_ID, c.comment_author, c.comment_content, h.action, h.ai_confidence FROM {$wpdb->comments} c LEFT JOIN {$wpdb->prefix}ai_moderation_history h ON c.comment_ID = h.comment_id $where ORDER BY c.comment_date DESC LIMIT %d OFFSET %d", $per_page, $offset));
wp_cache_set($comments_cache_key, $comments, $comments_cache_group, 300);
}
// If no comments, show notice
if (!$comments) {
echo '';
return;
}
?>
AI Comment Auto-Moderator
| ID |
Author |
Comment |
AI Decision |
Confidence |
Actions |
action) && $comment->action !== 'Pending';
?>