The Performance Module provides a three-tab performance analysis dashboard within the WordPress admin. It combines automated site health checking, URL tracking, and Google PageSpeed Insights integration to give administrators a comprehensive view of their site’s performance, security, and SEO posture.
Key Capabilities
Site Health — 32 automated checks across Security, Speed, and Resources categories with weighted scoring (0–100)
URLs — URL tracking list with per-URL asset collection and PageSpeed analysis
Page Speed — Google PageSpeed Insights API v5 integration for mobile and desktop analysis
Core Web Vitals metrics: FCP, LCP, TBT, CLS, SI
Category scores for Accessibility, Best Practices, SEO, and Performance
Audit filtering by Core Web Vital metric type
Diagnostic and opportunity identification with expandable detail panels
Screenshot and filmstrip rendering from Lighthouse data
Chart.js doughnut gauge visualization for scores
Dark mode support via aadvana-darkskin CSS class
Cached results with configurable refresh
Encrypted API key storage at rest
Technology Stack
PHP 7.4+ (strict types)
Google PageSpeed Insights API v5
WordPress REST API for data retrieval
Chart.js for gauge and score visualizations
wp.template (Underscore.js) for client-side rendering
wp-api-fetch and custom makeRestRequest() for REST calls
Check results table — per-category (Security, Speed, Resources) with status icon, title, description, result, recommendation
Score Calculation
Scanner::run_all() returns results grouped by category: security, speed, resources
Each check has a status (pass, warning, info, fail) and optional severity
Score_Calculator::calculate() produces: overall, security, speed, resources scores (0–100) plus counts
Percentages for the gauge chart are computed as count / total * 100
Session Safety: The scanner is invoked in the load-{page} hook (via ensure_checks_cached()) rather than during page rendering. This prevents loopback HTTP requests from rotating the session token after the REST nonce has been embedded in the page, which would cause 403 errors on subsequent REST calls.
Main controller for the Performance page. Handles menu registration, tab routing, Site Health check execution and rendering, and caching logic. All methods are static.
Registers the “Performance” submenu under Error Logs at position 9. Adds load-{hook} actions for help tabs, URL list processing, check refresh, and cache priming.
analytics_performance_page()
—
void
Main page callback — renders the 3-tab UI (Site Health / URLs / Page Speed). Reads tab query parameter to determine which tab to display. Enqueues Chart.js for the checks tab.
render_checks_tab(string $refresh_url)
Nonce-protected refresh URL
void
Renders the Site Health dashboard: score banner, Chart.js gauge, category badges, and per-category check result tables.
handle_refresh_checks()
—
void
Hooked to load-{page}. Handles ?refresh_checks=1 with nonce verification (advan_refresh_checks). Deletes transient, re-runs scanner, and redirects.
ensure_checks_cached()
—
void
Hooked to load-{page}. Runs scanner on first visit or after transient expiry (checks tab only). Prevents session-rotation issues.
add_help_content_performance()
—
string
Returns help tab content text.
Private Methods
Method
Description
run_and_cache_checks()
Runs Scanner::run_all(), calculates scores via Score_Calculator::calculate(), computes status percentages, stores everything in the transient (1 day TTL).
Per-device radio buttons filter audit accordion items by CWV metric type. Each audit carries a data-metric-type attribute (set from the diagnostics mapping in prepare_pagespeed_api_response()). Selecting a filter hides non-matching audits.
js/admin/util.js (51 lines)
Generic REST helper: makeRestRequest(endpoint, data, method) — uses fetch() with X-WP-Nonce header from advanPagespeedSettings.nonce.
8. Underscore.js Templates
Templates defined in pagespeed-templates.php using WordPress wp.template (Underscore.js syntax). Included by Performance_View::analytics_performance_page().
Single CWV metric tile with color coding (fail/average/pass)
tmpl-aadvana-pagespeed-diagnostics
data.id, data.title, data.score, data.description
Single audit accordion row with score icon and expandable detail panel
tmpl-aadvana-pagespeed-gauge
data.overallPerformance
Performance score number overlay centered on the doughnut chart canvas
tmpl-aadvana-pagespeed-category-score
data.title, data.scoreInt, data.device
Category score circle badge (pass=green, average=orange, fail=red)
tmpl-aadvana-pagespeed-screenshot
data.src
Final screenshot image element
tmpl-aadvana-pagespeed-filmstrip
data.src, data.timing
Page-load filmstrip thumbnail with timing label
9. Hooks & Actions
WordPress Hooks Registered ACTION
Hook
Callback
Priority
Description
admin_print_styles-{PAGE_SLUG}
PageSpeed_List::print_styles()
default
Enqueues PageSpeed JS, CSS, and localized data
load-{performance_hook}
Settings::aadvana_common_help()
default
Adds common help tabs to the page
load-{performance_hook}
Urls_List::process_actions_load()
default
Processes URL list actions before output
load-{performance_hook}
Performance_View::handle_refresh_checks()
default
Handles site health check refresh with nonce verification
load-{performance_hook}
Performance_View::ensure_checks_cached()
default
Primes the checks transient on first visit
rest_api_init
Endpoints::init_endpoints()
default
Registers all REST routes including PageSpeed endpoints
10. Settings Reference
Settings are managed via the Performance tab in the plugin settings page (admin.php?page=advan_logs_settings#aadvana-options-tab-performance).
Setting
ID
Type
Description
Enable performance module
performance_module_enabled
checkbox
Master toggle for the Performance module. When disabled, the sub-menu is hidden.
Google PageSpeed API Key
pagespeed_api_key
text (encrypted)
Google PageSpeed Insights API key. Required for the Page Speed tab. Encrypted at rest via Secure_Store.
Enable URLs module
urls_module_enabled
checkbox
Enables the URLs tab within the Performance page.
Enable URL data collection
advana_urls_enable
checkbox
Enables active URL data collection. When disabled, existing data remains viewable but no new data is collected.
Reading Settings Programmatically
PHP
<?php
use ADVAN\Helpers\Settings;
// Check if the performance module is enabled$enabled = Settings::get_option( 'performance_module_enabled' );
// Get the (decrypted) PageSpeed API key$api_key = Settings::get_option( 'pagespeed_api_key' );
11. Caching Strategy
The Performance module uses two separate WordPress transients for caching:
Transient Key
TTL
Content
Invalidation
aadvana_cached_pagespeed_api_data
1 hour (HOUR_IN_SECONDS)
Normalized PageSpeed API response (mobile + desktop data + analysed URL)
Auto-expires; overwritten on each fresh analysis
aadvana_site_checks_data
1 day (DAY_IN_SECONDS)
Scanner results, score calculations, status percentages, cache timestamp
Deleted and re-populated when user clicks “Re-run Site Health Checks” (nonce-protected)
Cache Priming Strategy
Site health checks are primed in the load-{page} hook (before admin_print_styles) to prevent session-token rotation issues. The scanner’s loopback HTTP requests can rotate auth cookies; running them after the REST nonce has been embedded in the page would cause 403 errors. By running the scanner early, the nonce generated later is always valid.
PageSpeed Auto-Load
On page load, pagespeed.js automatically requests cached data (?cached=1). If a cache hit occurs, results are rendered immediately without requiring a new API call.
12. Security Model
Capability Checks
manage_options enforced on: page rendering (analytics_performance_page()), all REST API endpoints (via check_permissions), and menu visibility (optionally via menu_admins_only)
Nonce Verification
Context
Nonce Action
Verification Method
REST API calls
wp_rest
WP REST nonce sent via X-WP-Nonce header
Site health refresh
advan_refresh_checks
wp_verify_nonce() on $_GET['_wpnonce']
Input Sanitization
URL input — sanitized via esc_url_raw(wp_unslash()) before passing to the Google API
Tab parameter — sanitized via sanitize_text_field(wp_unslash()) / sanitize_key()
API responses — HTML descriptions sanitized with regex-based markdown-to-HTML conversion; all output is escaped via esc_html() / esc_attr()
API Key Security
The pagespeed_api_key is encrypted at rest via the Secure_Store class
encrypt_sensitive_fields() encrypts the key on save
decrypt_sensitive_fields() decrypts on read, with transparent migration from plaintext to encrypted
External API Communication
All Google API requests use wp_remote_get() with a 300-second timeout
API categories requested: ACCESSIBILITY, BEST_PRACTICES, PERFORMANCE, PWA, SEO
Two requests per analysis: one for MOBILE strategy, one for DESKTOP
Response validation guards against empty, errored, or incomplete API responses
13. Diagnostics & Audit Mapping
The prepare_pagespeed_api_response() method maps Lighthouse audit IDs to Core Web Vital metric types. This mapping powers the audit filter system in the UI.
Audit ID
Metrics
Description
font-display
FCP, LCP
Font display strategy
critical-request-chains
FCP, LCP
Critical request chain length
largest-contentful-paint-element
LCP
LCP element identification
layout-shift-elements
CLS
Elements causing layout shifts
long-tasks
TBT
Long main-thread tasks
render-blocking-resources
FCP, LCP
Render-blocking CSS/JS
unused-css-rules
FCP, LCP
Unused CSS coverage
unminified-css
FCP, LCP
Unminified CSS files
unminified-javascript
FCP, LCP
Unminified JS files
unused-javascript
LCP
Unused JS coverage
uses-text-compression
FCP, LCP
Text compression (gzip/brotli)
uses-rel-preconnect
FCP, LCP
Preconnect to required origins
server-response-time
FCP, LCP
Server response time (TTFB)
redirects
FCP, LCP
HTTP redirects
uses-rel-preload
FCP, LCP
Preloading key requests
efficient-animated-content
LCP
Efficient animated content (video vs GIF)
duplicated-javascript
TBT
Duplicated JS modules
legacy-javascript
TBT
Legacy JS polyfills
total-byte-weight
LCP
Total page weight
dom-size
TBT
DOM element count
bootup-time
TBT
JS execution time
mainthread-work-breakdown
TBT
Main-thread work breakdown
third-party-summary
TBT
Third-party code impact
third-party-facades
TBT
Lazy-loadable third-party resources
non-composited-animations
CLS
Non-composited animations
unsized-images
CLS
Images without explicit dimensions
viewport
TBT
Viewport meta tag configuration
Audit Detail Rendering
The prepare_pagespeed_api_response() method filters audit details to only include renderable types:
Items: Limited to 20 per audit; only scalar-typed values are kept (url, source-location, bytes, ms, timespanMs, numeric, text, code, link)
Headings: Reduced to key, label, valueType triples
Screenshot Types
Key
Data Source
Description
final-screenshot
details.data (base64)
Final rendered page screenshot
full-page-screenshot
details.screenshot.data (base64)
Full-page screenshot
screenshot-thumbnails
details.items[].data (base64)
Filmstrip thumbnails with timestamp and timing data
14. Code Examples
Example 1: Check If PageSpeed API Key Is Configured
PHP
<?php
use ADVAN\Helpers\Settings;
$api_key = Settings::get_option( 'pagespeed_api_key' );
if ( empty( $api_key ) ) {
echo'PageSpeed API key is not configured.';
} else {
echo'PageSpeed API key is set and ready.';
}
Example 2: Fetch PageSpeed Data for a URL Programmatically