/*
Plugin Name: AI Internal Linking Tool
Description: Automatically add internal links using AI – Map keywords to URLs in real-time and boost your website's SEO and crawling efficiency.
Version: 1.0
Author: KumarHarshit.in
Plugin URI: https://kumarharshit.in/ai-internal-linking-tool-documentation/
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: ai-internal-linking-tool
Domain Path: /languages
*/
/*
* © 2024-2025 KumarHarshit.in
* This plugin is licensed under the GNU General Public License v2.0 or later.
* You are free to use, modify, and distribute it under GPL terms.
*
* However, this plugin represents original innovation and development by KumarHarshit.in.
* Any rebranding, redistribution, or derivative work must retain visible attribution to the original author.
* Failure to do so may be considered a violation of GPL terms and will result in appropriate legal or DMCA action.
*
* We respectfully request that you do not clone or resell this plugin without permission.
* Let's grow ethically — respect the work behind the code.
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
// Define plugin path constants
define('ASEO_PATH', plugin_dir_path(__FILE__));
define('ASEO_URL', plugin_dir_url(__FILE__));
// Include required files
require_once ASEO_PATH . 'includes/db-functions.php';
require_once ASEO_PATH . 'includes/admin-page.php';
// Enqueue admin styles and scripts
function aseo_enqueue_admin_assets($hook) {
// Load styles & JS for all plugin admin pages
$allowed_hooks = array(
'toplevel_page_ai-internal-linking-tool',
'ai-internal-linking-tool_page_ai-content-analytics',
'ai-internal-linking-tool_page_ai-coverage-report',
'ai-internal-linking-tool_page_ai-plugin-self-test',
'ai-internal-linking-tool_page_ai-link-auto-fix',
'ai-internal-linking-tool_page_ai-bulk-editor',
'ai-internal-linking-tool_page_ai-orphaned-report',
'ai-internal-linking-tool_page_ai-topic-cluster-report',
'ai-internal-linking-tool_page_ai-internal-link-audit',
'ai-internal-linking-tool_page_ai-link-user-log',
'ai-internal-linking-tool_page_ai-smart-suggestions'
);
if (!in_array($hook, $allowed_hooks)) {
return;
}
wp_enqueue_style('aseo-admin-style', ASEO_URL . 'assets/css/style.css');
wp_enqueue_script('aseo-admin-script', ASEO_URL . 'assets/js/script.js', array('jquery'), null, true);
// Only load Chart.js on the Content Analytics dashboard
if ($hook === 'ai-internal-linking-tool_page_ai-content-analytics') {
wp_enqueue_script('chartjs', 'https://cdn.jsdelivr.net/npm/chart.js', array(), null, true);
}
}
add_action('admin_enqueue_scripts', 'aseo_enqueue_admin_assets');
// Register admin menu
function aseo_register_admin_menu() {
add_menu_page(
'AI Internal Linking Tool',
'AI Internal Linking',
'manage_options',
'ai-internal-linking-tool',
'aseo_display_admin_page'
);
add_submenu_page(
'ai-internal-linking-tool',
'Coverage Report',
'Coverage Report',
'manage_options',
'aseo-coverage-report',
'aseo_render_coverage_report_page'
);
add_submenu_page(
'ai-internal-linking-tool',
'Plugin Self-Test',
'Plugin Self-Test',
'manage_options',
'aseo-plugin-self-test',
'aseo_run_plugin_self_test'
);
}
add_action('admin_menu', 'aseo_register_admin_menu');
// Create DB tables on plugin activation
register_activation_hook(__FILE__, function() {
aseo_create_table();
aseo_create_404_table();
aseo_schedule_daily_404_check();
});
// Remove scheduled task on deactivation
register_deactivation_hook(__FILE__, 'aseo_clear_daily_404_check');
// Hook for daily scheduled event
add_action('aseo_daily_check_event', 'aseo_run_daily_404_checker');
// Apply internal links to content
function aseo_apply_internal_links($content) {
if (is_singular() || is_home() || is_archive()) {
global $wpdb;
$table_name = $wpdb->prefix . 'seo_internal_links';
$pairs = $wpdb->get_results("SELECT * FROM $table_name");
foreach ($pairs as $pair) {
$keyword = preg_quote($pair->keyword, '/');
$link = esc_url($pair->link);
$attribute = isset($pair->attribute) ? strtolower($pair->attribute) : 'dofollow';
$rel_attr = ($attribute === 'nofollow') ? ' rel="nofollow"' : '';
// Anchor rotation logic (from previous feature)
$anchor = $pair->keyword;
$anchors = get_post_meta($pair->id, '_aseo_anchors', true);
if ($anchors && is_array($anchors)) {
$anchor = $anchors[array_rand($anchors)];
}
$link_html = '' . esc_html($anchor) . '';
// Use the contextual filter, let it decide where to insert the link
if (has_filter('aseo_before_apply_link')) {
$content = apply_filters(
'aseo_before_apply_link',
$content,
$pair->keyword,
$link_html,
1 // Only 1 insertion per keyword per post
);
} else {
$content = preg_replace(
'/\b(' . $keyword . ')\b/i',
$link_html,
$content,
1
);
}
}
}
return $content;
}
add_filter('the_content', 'aseo_apply_internal_links');
// Real-time 404 logger (safe fallback)
add_action('template_redirect', function () {
if (is_404()) {
global $wpdb;
$broken_url = esc_url_raw(home_url(add_query_arg([], $_SERVER['REQUEST_URI'])));
$referrer = esc_url_raw(wp_get_referer());
if (!empty($broken_url)) {
$wpdb->insert(
$wpdb->prefix . 'seo_404_logs',
[
'keyword' => '', // Blank because we can't extract it here
'broken_url' => $broken_url,
'status_code' => '404',
'found_on_url' => $referrer ?: '',
'anchor_text' => '',
'detected_at' => current_time('mysql')
]
);
}
}
});
// Load broken link email notification feature
require_once plugin_dir_path(__FILE__) . 'includes/email-notifications.php';
// Load report page
require_once plugin_dir_path(__FILE__) . 'includes/internal-linking-report.php';
// Load self-test page
require_once plugin_dir_path(__FILE__) . 'includes/plugin-self-test.php';
// Load backend filter to block external links during CSV import
require_once plugin_dir_path(__FILE__) . 'includes/link-validation.php';
// Load validation to restrict external links in manual and CSV submissions
require_once plugin_dir_path(__FILE__) . 'includes/manual-link-validation.php';
require_once ASEO_PATH . 'includes/features/smart-recommendations.php';
require_once ASEO_PATH . 'includes/features/broken-link-auto-fix.php';
require_once ASEO_PATH . 'includes/features/orphan-finder.php';
require_once ASEO_PATH . 'includes/features/topic-cluster.php';
require_once ASEO_PATH . 'includes/features/health-audit.php';
require_once ASEO_PATH . 'includes/features/anchor-rotation.php';
require_once ASEO_PATH . 'includes/features/contextual-placement.php';
require_once ASEO_PATH . 'includes/features/bulk-editor.php';
require_once ASEO_PATH . 'includes/features/user-permissions.php';
require_once ASEO_PATH . 'includes/features/content-analytics.php';
add_filter('plugin_row_meta', 'aseo_custom_plugin_meta_links', 10, 2);
function aseo_custom_plugin_meta_links($links, $file) {
if (plugin_basename(__FILE__) == $file) {
$custom_link = 'Plugin Help & Documentation';
$links[] = $custom_link;
}
return $links;
}
?>
https://imgto.me/post-sitemap.xml
2025-07-13T12:23:53+00:00
https://imgto.me/page-sitemap.xml
2025-02-18T16:29:11+00:00
https://imgto.me/category-sitemap.xml
2025-07-13T12:23:53+00:00