' . esc_html__('Run an audit', 'aiot-site-audit') . ''); return $l; }); function aiotsa_tabs() { return apply_filters('aiotsa_tabs', ['audit' => __('Audit', 'aiot-site-audit'), 'report' => __('Report', 'aiot-site-audit'), 'tools' => __('Tools', 'aiot-site-audit'), 'settings' => __('Settings', 'aiot-site-audit'), 'keys' => __('API Keys', 'aiot-site-audit'), 'help' => __('Help', 'aiot-site-audit')]); } function aiotsa_buf_modes() { ob_start(); do_action('aiotsa_form_modes'); return (string) ob_get_clean(); } function aiotsa_buf_toolbar() { ob_start(); do_action('aiotsa_report_toolbar'); return (string) ob_get_clean(); } function aiotsa_tab() { $t = isset($_GET['tab']) ? sanitize_key($_GET['tab']) : 'audit'; return isset(aiotsa_tabs()[$t]) ? $t : 'audit'; } // phpcs:ignore WordPress.Security.NonceVerification add_action('admin_enqueue_scripts', function ($hook) { if ($hook !== 'toplevel_page_aiotsa') return; wp_enqueue_media(); wp_enqueue_style('aiotsa-report', AIOTSA_URL . 'assets/css/report.css', [], AIOTSA_VERSION); wp_enqueue_style('aiotsa-admin', AIOTSA_URL . 'assets/css/admin.css', ['aiotsa-report'], AIOTSA_VERSION); $aiotsa_css = aiotsa_report_css('admin'); if ($aiotsa_css !== '') wp_add_inline_style('aiotsa-report', $aiotsa_css); wp_enqueue_script('aiotsa-admin', AIOTSA_URL . 'assets/js/admin.js', [], AIOTSA_VERSION, true); wp_localize_script('aiotsa-admin', 'AIOTSA', ['rest' => esc_url_raw(rest_url('aiotsa/v1')), 'nonce' => wp_create_nonce('wp_rest'), 'tab' => aiotsa_tab(), 'active' => aiotsa_audit_current(), 'id' => isset($_GET['id']) ? (int) $_GET['id'] : (int) (is_array(get_option('aiotsa_last')) ? get_option('aiotsa_last')['id'] : aiotsa_audit_latest('own')), // phpcs:ignore WordPress.Security.NonceVerification 'reportUrl' => admin_url('admin.php?page=aiotsa&tab=report&id='), 'keysUrl' => admin_url('admin.php?page=aiotsa&tab=keys'), 'presets' => aiotsa_robots_presets(), 'types' => ['own' => __('This website', 'aiot-site-audit'), 'page' => __('One page', 'aiot-site-audit'), 'external' => __('Another website', 'aiot-site-audit')], 's' => ['starting' => __('Starting...', 'aiot-site-audit'), 'left' => /* translators: %s: time left, like "2 min" */ __('about %s left', 'aiot-site-audit'), 'min' => __('min', 'aiot-site-audit'), 'sec' => __('sec', 'aiot-site-audit'), 'done' => __('Completed', 'aiot-site-audit'), 'running' => __('Running', 'aiot-site-audit'), 'pending' => __('Pending', 'aiot-site-audit'), 'failed' => __('could not finish', 'aiot-site-audit'), 'paused' => __('Paused', 'aiot-site-audit'), 'pages' => __('pages', 'aiot-site-audit'), 'confirmDel' => __('Delete this audit?', 'aiot-site-audit'), 'loading' => __('Loading...', 'aiot-site-audit'), 'close' => __('Close', 'aiot-site-audit'), 'copied' => __('Copied', 'aiot-site-audit'), 'saved' => __('Saved', 'aiot-site-audit'), 'error' => __('Something went wrong. Please try again.', 'aiot-site-audit'), 'rechecked' => __('Checked again', 'aiot-site-audit'), 'none' => __('Nothing here yet. This list is made from a full audit of "This website" (the site where the plugin is installed). Run one first.', 'aiot-site-audit'), 'ok' => __('The key works.', 'aiot-site-audit'), 'view' => __('View report', 'aiot-site-audit'), 'del' => __('Delete', 'aiot-site-audit'), 'linkFrom' => __('Add a link in', 'aiot-site-audit'), 'linkTo' => __('to', 'aiot-site-audit'), 'edit' => __('Edit', 'aiot-site-audit'), 'physical' => __('Your site has a real robots.txt file, so WordPress cannot add these lines for you. Copy them into that file.', 'aiot-site-audit')]]); }); /** * The fields of the settings forms, each cleaned for its own type as it is read. Only the fields named here are read from the request; * add-ons name their own fields (and the type of each) with the aiotsa_post_fields filter. The nonce is checked here before anything is read. */ function aiotsa_post_fields() { $types = ['lang' => 'key', 'thin' => 'int', 'keep' => 'int', 'pages' => 'urls', 'notes_print' => 'bool']; foreach ((array) apply_filters('aiotsa_key_ids', ['psi']) as $k) { $k = sanitize_key($k); $types['key_' . $k] = 'text'; $types['del_' . $k] = 'bool'; } check_admin_referer('aiotsa_save'); $types = (array) apply_filters('aiotsa_post_fields', $types); $P = []; foreach ($types as $name => $type) { $name = (string) $name; if (!isset($_POST[$name])) continue; if ($type === 'int') $P[$name] = (int) $_POST[$name]; elseif ($type === 'bool') $P[$name] = empty($_POST[$name]) ? 0 : 1; elseif ($type === 'key') $P[$name] = sanitize_key(wp_unslash($_POST[$name])); elseif ($type === 'url') $P[$name] = esc_url_raw(wp_unslash($_POST[$name])); elseif ($type === 'textarea') $P[$name] = sanitize_textarea_field(wp_unslash($_POST[$name])); elseif ($type === 'urls') $P[$name] = is_array($_POST[$name]) ? array_map('esc_url_raw', wp_unslash($_POST[$name])) : []; elseif ($type === 'bools') $P[$name] = is_array($_POST[$name]) ? array_map(function ($v) { return $v ? 1 : 0; }, array_map('absint', wp_unslash($_POST[$name]))) : []; else $P[$name] = sanitize_text_field(wp_unslash($_POST[$name])); } return $P; } add_action('admin_init', function () { if (empty($_POST['aiotsa_save']) || !current_user_can('manage_options')) return; check_admin_referer('aiotsa_save'); $what = sanitize_key(wp_unslash($_POST['aiotsa_save'])); $S = aiotsa_settings(); $P = aiotsa_post_fields(); if ($what === 'settings') { $S['lang'] = isset(aiotsa_langs()[$P['lang'] ?? '']) ? $P['lang'] : 'en'; $S['thin'] = max(100, min(1500, (int) ($P['thin'] ?? 300))); $S['keep'] = max(2, min(100, (int) ($P['keep'] ?? 10))); $S['notes_print'] = empty($P['notes_print']) ? 0 : 1; foreach ($S['pages'] as $k => $v) $S['pages'][$k] = esc_url_raw($P['pages'][$k] ?? ''); } if ($what === 'keys') { $K = get_option('aiotsa_keys', []); if (!is_array($K)) $K = []; foreach (apply_filters('aiotsa_key_ids', ['psi']) as $k) { $v = trim((string) ($P['key_' . $k] ?? '')); if (!empty($P['del_' . $k])) unset($K[$k]); elseif ($v !== '' && preg_match('/^[A-Za-z0-9_\-]{20,120}$/', $v)) $K[$k] = $v; elseif ($v !== '') add_settings_error('aiotsa', 'key', __('That does not look like a valid key. Copy it again, without spaces.', 'aiot-site-audit')); } update_option('aiotsa_keys', $K, false); } $S = apply_filters('aiotsa_save_settings', $S, $what, $P); update_option('aiotsa_settings', $S, false); if (!get_settings_errors('aiotsa')) add_settings_error('aiotsa', 'saved', __('Saved.', 'aiot-site-audit'), 'success'); set_transient('settings_errors', get_settings_errors(), 30); wp_safe_redirect(add_query_arg(['page' => 'aiotsa', 'tab' => in_array($what, ['testmail'], true) ? 'settings' : $what, 'settings-updated' => 1], admin_url('admin.php'))); exit; }); function aiotsa_admin_page() { if (!current_user_can('manage_options')) return; $tab = aiotsa_tab(); $S = aiotsa_settings(); echo '

' . esc_html__('AllInOneTools Site Audit', 'aiot-site-audit') . '

'; settings_errors('aiotsa'); echo '
'; call_user_func('aiotsa_tab_' . $tab, $S); echo '
'; } function aiotsa_lang_select($name, $cur) { $h = ''; } function aiotsa_tab_audit($S) { $det = aiotsa_find_pages(['mode' => 'own', 'opts' => ['pages' => $S['pages']], 'summary' => ['ctx' => []]]); $last = get_option('aiotsa_last'); if (is_array($last) && aiotsa_audit_get((int) $last['id'])) { echo '
' . wp_kses(aiotsa_ring((int) $last['score'], 84), aiotsa_allowed_html()) . '
' . esc_html__('Latest audit of this site', 'aiot-site-audit') . '
' . esc_html(wp_date(get_option('date_format') . ' ' . get_option('time_format'), (int) $last['time'])) . '
' . esc_html__('View report', 'aiot-site-audit') . '
'; foreach (aiotsa_sections() as $k => [$n]) if (isset($last['sec'][$k])) echo '' . (int) $last['sec'][$k]['score'] . ' ' . esc_html($n) . ''; echo '
'; } $nt = get_option('aiotsa_notice'); if (is_array($nt) && !aiotsa_audit_current()) echo '

' . esc_html(sprintf(/* translators: 1: website, 2: score */ __('The audit of %1$s is ready. Score: %2$d of 100.', 'aiot-site-audit'), $nt['target'], $nt['score'])) . ' ' . esc_html__('View report', 'aiot-site-audit') . '

'; echo ''; echo '

' . esc_html__('New audit', 'aiot-site-audit') . '

' . wp_kses(aiotsa_buf_modes(), aiotsa_allowed_html()) . '
'; echo ''; echo '

' . esc_html__('Policy and trust pages', 'aiot-site-audit') . '

' . esc_html__('We found these on your site. Correct a link if it is wrong, or leave a box empty if the page does not exist.', 'aiot-site-audit') . '

'; foreach (['privacy' => __('Privacy Policy', 'aiot-site-audit'), 'about' => __('About', 'aiot-site-audit'), 'contact' => __('Contact', 'aiot-site-audit'), 'terms' => __('Terms', 'aiot-site-audit'), 'disclaimer' => __('Disclaimer', 'aiot-site-audit')] as $k => $l) echo '

'; echo '
'; do_action('aiotsa_form_fields', $S); echo '

' . wp_kses(aiotsa_lang_select('lang', $S['lang']), aiotsa_allowed_html()) . '

'; do_action('aiotsa_form_options', $S); echo '

'; echo '

' . esc_html__('History', 'aiot-site-audit') . '

'; $types = ['own' => __('This website', 'aiot-site-audit'), 'page' => __('One page', 'aiot-site-audit'), 'external' => __('Another website', 'aiot-site-audit')]; $rows = aiotsa_audit_list(); if (!$rows) echo ''; foreach ($rows as $r) echo ''; echo '
' . esc_html__('Date', 'aiot-site-audit') . '' . esc_html__('Website', 'aiot-site-audit') . '' . esc_html__('Type', 'aiot-site-audit') . '' . esc_html__('Status', 'aiot-site-audit') . '' . esc_html__('Score', 'aiot-site-audit') . '
' . esc_html__('No audits yet.', 'aiot-site-audit') . '
' . esc_html(wp_date(get_option('date_format') . ' ' . get_option('time_format'), strtotime($r['created'] . ' UTC'))) . '' . esc_html($r['target']) . '' . esc_html($types[$r['mode']] ?? $r['mode']) . '' . esc_html($r['status']) . '' . ($r['status'] === 'done' ? '' . (int) $r['score'] . '' : '-') . '' . esc_html__('View report', 'aiot-site-audit') . ' ·
'; } function aiotsa_tab_report($S) { delete_option('aiotsa_notice'); echo ''; echo '

' . esc_html__('Loading...', 'aiot-site-audit') . '

'; } function aiotsa_tab_tools($S) { $ro = aiotsa_robots_opts(); $lo = aiotsa_llms_opts(); echo '

' . esc_html__('AI crawler rules for robots.txt', 'aiot-site-audit') . '

' . esc_html__('Choose which AI services may read your site. "Allow" and "Block" add a rule; "No rule" leaves the crawler to your normal robots.txt. Well-behaved crawlers follow these rules; nothing can force a crawler to obey.', 'aiot-site-audit') . '

'; foreach (aiotsa_ai_bots() as $b => $w) { $v = $ro['bots'][$b] ?? 'none'; echo ''; } echo '
' . esc_html($b) . '
' . esc_html($w) . '

' . esc_html__('Open robots.txt', 'aiot-site-audit') . '

'; echo '

llms.txt

' . esc_html__('A short list of your most useful pages for AI services. It is a new, optional standard: adding it does no harm, but no AI company promises to use it.', 'aiot-site-audit') . '

' . esc_html__('Open llms.txt', 'aiot-site-audit') . '

'; echo ''; do_action('aiotsa_tools_panels', $S); } function aiotsa_form_open($what) { echo '
'; wp_nonce_field('aiotsa_save'); echo ''; } function aiotsa_tab_settings($S) { aiotsa_form_open('settings'); do_action('aiotsa_settings_top', $S); echo '

' . esc_html__('Reports', 'aiot-site-audit') . '

'; echo ''; echo ''; do_action('aiotsa_settings_rows', $S); echo '

' . esc_html__('Policy and trust pages', 'aiot-site-audit') . '

' . esc_html__('Leave empty to let the audit find them.', 'aiot-site-audit') . '

'; foreach (['privacy' => 'Privacy Policy', 'about' => 'About', 'contact' => 'Contact', 'terms' => 'Terms', 'disclaimer' => 'Disclaimer'] as $k => $l) echo ''; echo ''; submit_button(); echo '
'; do_action('aiotsa_settings_after', $S); } function aiotsa_tab_keys($S) { aiotsa_form_open('keys'); $hint = function ($k) { $v = aiotsa_key($k); return $v === '' ? '' : str_repeat('•', 8) . substr($v, -4); }; echo '

' . esc_html__('API keys are optional and free. The audit works without them. Keys are stored in your WordPress database, used only from your server, and never shown to visitors.', 'aiot-site-audit') . '

'; foreach (apply_filters('aiotsa_key_defs', [['psi', 'Google PageSpeed Insights API', __('Used for: PageSpeed scores and Core Web Vitals (LCP, CLS, INP) in the Speed section.', 'aiot-site-audit'), __('Cost: free. Google allows 25,000 tests a day per key.', 'aiot-site-audit'), ['Open the PageSpeed Insights API page and press "Get a Key".', 'Choose or create a project.', 'Copy the key and paste it here, then Save.', 'Press "Test key".'], 'https://developers.google.com/speed/docs/insights/v5/get-started', '']]) as [$k, $name, $use, $cost, $steps, $url, $limits]) { $h = $hint($k); echo '

' . esc_html($name) . ' ' . esc_html__('Optional', 'aiot-site-audit') . ' ' . esc_html__('Free', 'aiot-site-audit') . ' ' . ($h ? '' . esc_html__('Saved', 'aiot-site-audit') . ' ' . esc_html($h) . '' : '' . esc_html__('Not set', 'aiot-site-audit') . '') . '

' . esc_html($use) . '
' . esc_html($cost) . ($limits ? ' ' . esc_html__('Current limits', 'aiot-site-audit') . '' : '') . '

    '; foreach ($steps as $s) echo '
  1. ' . esc_html($s) . '
  2. '; echo '

' . esc_html__('Open the page to get the key', 'aiot-site-audit') . '

'; echo '

' . ($h ? '' : '') . '

'; do_action('aiotsa_key_card_extra', $k, $S); echo '
'; } submit_button(); echo ''; do_action('aiotsa_keys_after', $S); } function aiotsa_tab_help($S) { echo '

' . esc_html__('How it works', 'aiot-site-audit') . '

  1. ' . esc_html__('Open the Audit tab, check the policy page links, and press Start audit.', 'aiot-site-audit') . '
  2. ' . esc_html__('The audit runs in the background in small steps. You can close the page; a notice (and an e-mail) tells you when it is ready.', 'aiot-site-audit') . '
  3. ' . esc_html__('Open the report. Start with "Fix these first". Each check says what was found and how to fix it.', 'aiot-site-audit') . '
  4. ' . esc_html__('Choose the report language, then print it or save it as a PDF.', 'aiot-site-audit') . '
'; echo '

' . esc_html__('How long it takes', 'aiot-site-audit') . '

' . esc_html__('It depends on your hosting. As a guide: one page under a minute; a site with 50 posts a few minutes; several hundred posts 15 minutes or more. PageSpeed adds a few minutes.', 'aiot-site-audit') . '

'; echo '

' . esc_html__('If an audit stops moving when the page is closed', 'aiot-site-audit') . '

' . esc_html__('WordPress runs background work when someone visits the site. On a site with very few visitors, add a real cron job in your hosting panel (Hostinger: Advanced > Cron Jobs; cPanel: Cron Jobs), every 5 minutes:', 'aiot-site-audit') . '

wget -q -O - ' . esc_html(site_url('wp-cron.php?doing_wp_cron')) . ' >/dev/null 2>&1
'; echo '

' . esc_html__('What this plugin does not measure', 'aiot-site-audit') . '

'; echo '

' . esc_html__('Privacy', 'aiot-site-audit') . '

' . esc_html__('The audit runs on your own server and nothing is sent to the plugin author. The only outside service is Google PageSpeed Insights, and only if you add that key: it receives the address of the audited page.', 'aiot-site-audit') . '

' . esc_html__('Full documentation', 'aiot-site-audit') . '

'; if (!defined('AIOTSA_PRO_VERSION')) echo '

' . esc_html__('Site Audit Pro', 'aiot-site-audit') . '

' . esc_html__('A separate add-on adds: competitor comparison, AI Insights and "Fix with AI" with your own Google Gemini key, Word and CSV reports with your logo, client share links, audits of other websites, and automatic audits with e-mail reports.', 'aiot-site-audit') . '

' . esc_html__('See Site Audit Pro', 'aiot-site-audit') . '

'; } /* ---------- around WordPress: admin bar, notice, post list, editor box, dashboard ---------- */ add_action('admin_bar_menu', function ($bar) { if (!is_admin() || !current_user_can('manage_options')) return; $id = aiotsa_audit_active(); if (!$id) return; $A = aiotsa_audit_get($id); if (!$A) return; $p = aiotsa_progress($A); $bar->add_node(['id' => 'aiotsa', 'title' => '' . esc_html(sprintf(/* translators: %d: percent */ __('Audit %d%%', 'aiot-site-audit'), $p['pct'])) . '', 'href' => admin_url('admin.php?page=aiotsa')]); }, 90); add_action('admin_notices', function () { if (!current_user_can('manage_options')) return; $n = get_option('aiotsa_notice'); if (!is_array($n) || (isset($_GET['page']) && $_GET['page'] === 'aiotsa')) return; // phpcs:ignore WordPress.Security.NonceVerification echo '

' . esc_html__('Site Audit', 'aiot-site-audit') . ': ' . esc_html(sprintf(/* translators: 1: website, 2: score */ __('The audit of %1$s is ready. Score: %2$d of 100.', 'aiot-site-audit'), $n['target'], $n['score'])) . ' ' . esc_html__('View report', 'aiot-site-audit') . '

'; }); function aiotsa_badge($pid) { $m = get_post_meta($pid, '_aiotsa_score', true); if (!is_array($m)) return '' . esc_html__('Not audited yet', 'aiot-site-audit') . ''; $s = (int) $m['s']; return '' . $s . ''; } foreach (['post', 'page'] as $aiotsa_pt) { add_filter('manage_' . $aiotsa_pt . '_posts_columns', function ($c) { if (current_user_can('manage_options')) $c['aiotsa'] = __('Audit', 'aiot-site-audit'); return $c; }); add_action('manage_' . $aiotsa_pt . '_posts_custom_column', function ($col, $pid) { if ($col === 'aiotsa') echo wp_kses(aiotsa_badge($pid), aiotsa_allowed_html()); }, 10, 2); } add_action('admin_enqueue_scripts', function ($hook) { if ($hook !== 'edit.php') return; wp_register_style('aiotsa-column', false, [], AIOTSA_VERSION); wp_enqueue_style('aiotsa-column'); wp_add_inline_style('aiotsa-column', '.column-aiotsa{width:64px}'); }); add_action('add_meta_boxes', function () { if (current_user_can('manage_options')) add_meta_box('aiotsa', __('Site Audit', 'aiot-site-audit'), function ($post) { $m = get_post_meta($post->ID, '_aiotsa_score', true); if (!is_array($m)) { echo '

' . esc_html__('Not audited yet. Run a full audit from the Site Audit menu.', 'aiot-site-audit') . '

'; return; } $il = aiotsa_issue_labels(); echo '

' . wp_kses(aiotsa_badge($post->ID), aiotsa_allowed_html()) . ' ' . esc_html(wp_date(get_option('date_format'), (int) $m['t'])) . '

'; if (!empty($m['is'])) { echo ''; } else echo '

' . esc_html__('No issues found.', 'aiot-site-audit') . '

'; echo '

' . esc_html__('Open the report', 'aiot-site-audit') . '

'; }, ['post', 'page'], 'side', 'low'); }); add_action('wp_dashboard_setup', function () { if (current_user_can('manage_options')) wp_add_dashboard_widget('aiotsa_w', __('Site Audit', 'aiot-site-audit'), function () { $l = get_option('aiotsa_last'); if (!is_array($l)) { echo '

' . esc_html__('No audit yet.', 'aiot-site-audit') . '

' . esc_html__('Run an audit', 'aiot-site-audit') . '

'; return; } echo '
' . wp_kses(aiotsa_ring((int) $l['score'], 84), aiotsa_allowed_html()) . '
' . esc_html__('Overall score', 'aiot-site-audit') . '
' . esc_html(wp_date(get_option('date_format'), (int) $l['time'])) . '
' . esc_html__('View report', 'aiot-site-audit') . ' · ' . esc_html__('New audit', 'aiot-site-audit') . '
'; }); });