WP Optimal State Plugin Banner

📘 User Manual - PRO Version 1.1.6

📑 Table of Contents

    1. 🚀 Introduction
    2. 🛠️ Getting Started
    3. 🎯 Dashboard Philosophy: The 3-Step Workflow
    4. 💾 The Database Backup & Restore Manager (Section 1)
    5. 🧹 The Database Optimization Suite (Sections 2-6)
    6. ⏰ Automatic Backup & Cleanup (Section 7)
    7. ⚡ Performance Features Manager (Section 8)
    8. 🎯 Optimization Strategies: Putting It All Together
    9. 📥 Settings Export & Import (Section 9)
    10. 🔧 Troubleshooting & Advanced FAQ
    11. 🏗️ Technical Architecture
    12. 📝 Disclaimer
    13. 🆘 Technical Support

🚀 1. Introduction

🧠 1.1. The Philosophy of WP Optimal State PRO

WP Optimal State PRO is an advanced, all-in-one WordPress optimization and management suite. It was built on the philosophy that site management should be comprehensive, secure, and powerful. It provides a complete set of tools to clean, optimize, back up, and secure your WordPress database, combined with a robust performance module to make your site exceptionally fast.

This plugin is not just a simple "cleaner." It's a complete toolkit for database management and site performance, giving you both "one-click" simplicity and the granular, advanced control that professionals demand.

👥 1.2. Who is This Manual For?

This manual is for every user of WP Optimal State PRO.

⚠️ 1.3. A CRITICAL First Warning: ALWAYS BACK UP

🚨 WARNING: THIS IS A POWERFUL TOOL

WP Optimal State PRO interacts directly and deeply with your website's database. Operations like cleanup, optimization, and restoration are powerful and, in most cases, irreversible.

While this plugin includes its own robust, best-in-class backup system, we cannot overstate the importance of caution.

💾 Before performing ANY cleanup or restore operation, you MUST create a fresh backup.

The plugin's built-in "Safety Backup" feature during restores provides a strong safety net, but a separate, downloadable backup is your ultimate insurance policy. Use this plugin responsibly. The author and this manual are not responsible for any data loss.

🛠️ 2. Getting Started

💻 2.1. System Requirements

To ensure full compatibility and smooth operation, your server should meet these minimum requirements:

📁 2.2. A Note on File & Directory Permissions

This plugin requires the ability to write files to your wp-content/uploads/ directory. This is a standard WordPress capability, but if your server has non-standard or overly restrictive permissions, you may encounter errors.

The plugin uses the WP_Filesystem API to safely read and write files. If you see an error like "Cannot initialize WP_Filesystem," it means your server is not configured to allow WordPress to manage its own files. You must contact your hosting provider to resolve this.

🚫 2.3. CRITICAL: Multisite Not Supported

🚨 IMPORTANT

WP Optimal State PRO cannot be activated on a WordPress Multisite (WPMU) installation.

The plugin is designed specifically for single-site WordPress installations. Its database operations (which target tables like wp_options and wp_posts) are not compatible with a multisite network (which uses wp_sitemeta, wp_blogs, and per-site tables like wp_2_options). Running it on a multisite network could cause irreversible data integrity issues. The plugin will automatically block its own activation if it detects a multisite environment.

⚡ 2.4. Installation & Activation

  1. Navigate to your WordPress Admin Dashboard.
  2. Go to Plugins > Add New.
  3. Click Upload Plugin.
  4. Choose the WP_Optimal_State_PRO_vX-X-X.zip file from your computer and click Install Now.
  5. Once installed, click Activate Plugin.
  6. Upon activation, the plugin will immediately check for and create its required directories and default settings files (Section 2.6).
  7. Look for "Optimal State" in you admin menu.

🔄 2.5. Upgrading From FREE Version

The upgrade process is straightforward. Simply uninstall the free version, then install the PRO version.

📝 PLEASE NOTE: The standard upgrade procedure based on the following 8 steps involves uninstalling the free version and then installing the pro version. This will cause custom settings and database backups to be lost. Follow steps 1 and 2 closely to save a copy of these data.

🟢 KEEP YOUR DATA: To upgrade without losing any data, you need to either use an FTP client or a file explorer included in your hosting panel (e.g. cPanel or hPanel). In this case, you simply have to unzip the .zip file containing the pro version and upload the optistate folder to /wp-content/plugins/, replacing the existing folder. By replacing the files instead of deactivating and deleting the free version, all data will be preserved.

Follow these steps:

  1. 📤 Export your settings to your device (Section 9. Settings Export & Import).
  2. 💾 Generate and download a database backup.
  3. From your dashboard, go to Plugins > Installed Plugins.
  4. Find WP Optimal State Free and click Deactivate.
  5. After deactivating it, click Delete (backups and settings will be deleted as well).
  6. Now, install the PRO version: Plugins > Add New > Upload Plugin.
  7. Import your settings from your device (Section 9. Settings Export & Import).
  8. Upgrade complete. Enjoy WP Optimal State Pro!

📊 2.6. Filesystem Footprint (What the Plugin Creates)

On activation, the plugin creates the following directories and files to store its data. All data is kept securely within your wp-content/uploads/ folder.

⚠️ WARNING - NGINX SERVERS

If your server is running Nginx, your site's sensitive directories are currently unprotected. The .htaccess files this plugin relies on are ignored, leaving your files and settings exposed.

To secure your server, you must manually add the security rules to your Nginx configuration. Read Section 7.3.1 for immediate instructions.

🔔 2.7. Keep the Plugin Updated

Your update process depends on whether you are using the FREE or PRO version. Please read the correct section for your plugin.

✔ UPDATING THE FREE VERSION

If you installed the free version of WP Optimal State from the official WordPress plugin repository, you can update it directly from your WordPress dashboard.

✅ All your database backups and settings will be preserved automatically.

⭐ UPDATING THE PRO VERSION

Updating the PRO version (which you received as a .zip file) takes just a couple of minutes. You have two equally valid options.

💡 Option 1: Via the Dashboard

  1. In the plugin interface, go to section 1 and download your database backups (they will download as compressed .sql.gz files).
  2. Then, go to section 9 (Settings Export & Import) and click Export Settings to download your .json settings file.
  3. Go to Plugins > Add Plugin, then click Upload Plugin. Choose the .zip file containing the latest plugin release and click Install Now.
  4. At this point, you will now be asked to either replace the current version with the uploaded one, or cancel and go back. Click Replace current with uploaded.
  5. The update is complete! Visit the plugin admin panel to confirm that your backups and settings are intact.

👨‍💻 Option 2: Via FTP Client

  1. Unzip the new plugin .zip file on your computer to get a folder named optistate.
  2. Open your FTP client or hosting file explorer and navigate to wp-content/plugins/.
  3. Upload the optistate folder from your computer, choosing to replace or overwrite all existing files in the /wp-content/plugins/optistate/ directory.
  4. Once complete, go to Plugins > Installed Plugins, find WP Optimal State and verify that the new version number is displayed.
  5. The update is complete! Visit the plugin admin panel to confirm that your backups and settings are intact.

📥 How to Get PRO Updates

🎯 3. Dashboard Philosophy: The 3-Step Workflow

The plugin dashboard is organized to guide you through a logical and safe workflow.

🛡️ Step 1: The Safety Net (Backup)

Section: 1. Create a Database Backup

Before you diagnose or fix anything, you must have an exit strategy. This section is your safety net. You can create a new, verifiable backup in seconds.

🔍 Step 2: The Diagnosis (Analyze)

Sections: 3. Database Health Score, 4. Database Statistics, 6. Database Structure Analysis

You can't fix what you don't understand. These sections are your diagnostic tools.

✨ Step 3: The Solution (Optimize)

Sections: 2. One-Click Optimization, 5. Detailed Cleanup, 6. Advanced Optimization, 7. Automation, 8. Performance

Once you have a backup and have diagnosed the problems, you can apply the solution.

💾 4. The Database Backup & Restore Manager (Section 1)

This is the plugin's most critical feature. It allows you to create, manage, download, and restore your database with a focus on security and integrity.

📥 4.1. Creating a Database Backup

  1. 📊 Maximum Backups to Keep: This setting (a number from 1 to 10) controls how many backups are stored on your server. When you create a new backup that exceeds this limit, the oldest backup will be automatically deleted.
    • 💡 Recommendation: Set this to 3. This provides a good balance between having recent restore points and saving server disk space.
  2. 🔄 Create Backup Now Button: Clicking this button will:
    • Instantly begin backing up your entire WordPress database.
    • Package it into a .sql file.
    • Generate a .checksum file (a unique SHA-256 "fingerprint") to verify the file is not corrupted.
    • Generate a .meta file containing information about the backup (date, WP version, etc.).
    • Store all three files in your wp-content/uploads/optistate/db-backups/ directory.
    • Refresh the "Manage Existing Backups" list.

🔧 4.2. Under the Hood: The Backup & Verification Process

The backup mechanism is designed to be server-timeout proof using an asynchronous, chunked process. The plugin will execute a series of timed AJAX requests. Each request runs for a maximum of ~25 seconds, writes a chunk of data, saves its current file position in a transient, and then requests the next chunk from the browser. This ensures that the process reliably backs up databases of any size without violating server execution limits.

  1. 🔓 Lock File: When you start a backup, a temporary lock file is created to prevent concurrent operations. The .sql file is opened for writing.
  2. 🏗️ Structure Dump: The plugin gets the SHOW CREATE TABLE command for every table in your database and writes it to the file. This ensures the table structure is perfectly preserved.
  3. 📦 Data Dump (Chunked): It then selects data from each table in batches (SELECT * FROM ... LIMIT ... OFFSET ...) and writes it as a series of INSERT INTO ... commands to the .sql file. Crucially, this process is chunked and saves its state between requests.
  4. ✅ Verification: Once the last chunk is complete, the plugin generates a secure SHA-256 checksum (fingerprint) of the final file. It stores this in a dedicated .checksum file next to the backup. The backup is 100% valid and safe to restore.

📋 4.3. Managing Existing Backups (The Action Buttons)

This table lists all available backups.

🛡️ 4.4. The Chunked, 4-Phase Safety Restore (In-Depth)

Restoring a database backup is the most critical operation the plugin performs. To ensure zero-risk data integrity against server timeouts, crashes, or corrupted files, the restore is broken down into four transactional, asynchronous phases.

🔐 Phase 1: Preemptive Safety Backup & Validation

  1. ✅ Validation: The plugin verifies the selected backup file's SHA-256 checksum against its saved fingerprint. If the file is corrupted or tampered with, the process is aborted.
  2. 💾 Safety Backup (Chunked): A complete, real-time SAFETY-RESTORE-*.sql is created in a reliable, chunked manner. This is your guaranteed rollback point.
  3. 🚧 Maintenance Mode: The site is put into a brief, non-WordPress maintenance mode to prevent data inconsistencies while the database tables are being swapped.

⚙️ Phase 2: Isolated & Chunked Staging

  1. 📊 Temporary Tables: The restore process begins by creating temporary tables (e.g., optistate_temp_wp_posts) instead of directly overwriting your live tables.
  2. 📦 Chunked Import: The backup file is imported asynchronously. The script runs for ~25 seconds, imports a chunk of SQL data into the temporary tables, saves the file position, and initiates the next request. This process runs until the entire backup is staged.

🔍 Phase 3: Critical Data Verification

⚡ Phase 4: Atomic Swap & Rollback Guarantee

  1. 🔄 Atomic Transaction: The swap is executed as a single, all-or-nothing database transaction. The live tables are instantly renamed to `_old` and the temporary tables are renamed to the live prefix.
  2. 🛟 Safety Rollback: If the atomic transaction fails (or if a fatal PHP error occurs), the database engine automatically rolls back all renames. Furthermore, the script is guaranteed to trigger an asynchronous rollback to the `SAFETY-RESTORE` backup created in Phase 1, ensuring zero data loss.

Upon successful completion, the old tables are cleaned up, the safety backup is deleted, and maintenance mode is deactivated.

This "Safety Restore" mechanism is your ultimate protection against a failed restore process, which could otherwise leave your site in a broken, half-restored state.

📤 4.5. How to Restore Database from an Uploaded File

This feature is designed to upload a .sql or .sql.gz file. You can upload a compressed backup downloaded from this plugin or an uncompressed file from phpMyAdmin.

🚨 WARNING

Only upload .sql or .sql.gz files generated by WP Optimal State or phpMyAdmin. Uploading a random file or a backup from another plugin may damage your database structure. 🧩 phpMyAdmin Compatibility: To ensure 100% compatibility with WP Optimal State, uncheck the Enclose export in a transaction option before performing exports.

🔄 Process:

  1. 📁 Choose SQL File: Click the button to select a .sql or .sql.gz file from your computer.
  2. 🔍 Validation & Upload: The file will be uploaded, and a progress bar will be displayed. During this process, a multi-step security validation occurs (see 4.6).
  3. 🔄 Restore from File: Once the upload is complete and validated, the "Restore from File" button will appear.
  4. ✅ Confirmation: Clicking this button will trigger the same confirmation modal and the exact same 4-Phase Safety Restore process described in section 4.4.
  5. ⏳ Execution: The time required to complete the restore will vary significantly depending on both the size of the database and the available server resources (from a few seconds to 30-60 minutes).

🔒 4.6. Security-First: The Upload Validation Process

When you upload a .sql or .sql.gz file, it undergoes a rigorous security scan before it is ever used.

  1. 📄 File Type Check: Verifies the file extension is .sql or .sql.gz. It also verifies the MIME type (e.g., text/plain, application/sql, application/gzip) to prevent file type spoofing.
  2. 📏 File Size Check: Enforces a 3GB maximum file size.
  3. 🛡️ Malicious Content Scan: If the file is compressed (.sql.gz), it is first securely decompressed. The plugin then reads the content of the .sql file, scanning for:
    • PHP tags (<?php, <?=)
    • Suspicious functions (eval(, system(, exec(, base64_decode)
  4. 🗄️ Database Name Check: The plugin (during the restore phase) reads the header of the SQL file and looks for the -- Database: dbname comment. If the database name in the file does not match your current WordPress database name, the restore is aborted. This is a critical check that prevents you from accidentally restoring a backup from a different website.

If any of these checks fail, the file is deleted, and the restore is aborted.

🛑 FALSE POSITIVES (security risks detected)
In some cases, the security scan may detect issues that do not pose a real threat.
If you are sure that your backup is secure, select Disable Restore Security Checks just below the database upload function in section 1.1.

🧹 5. The Database Optimization Suite (Sections 2-6)

This is the core optimization suite. These sections work together to help you diagnose and clean your database.

❤️ 5.1. Database Health Score (The "Why")

This is your central diagnostic hub. It gives you a "grade" from 0-100 based on the current state of your database.

📈 5.2. Database Statistics (The "What" - A Detailed Glossary)

This is the raw data used to calculate your Health Score. It shows you exactly what was found in your database.

🚀 5.3. One-Click Optimization (The "Easy Button")

This is the simplest and safest way to clean your database. Clicking the "🚀 Optimize Now" button will:

  1. Ask for confirmation.
  2. Run all safe cleanup tasks (it will not touch your trash bins or unapproved comments).
  3. Perform "Optimize All Tables" (see section 5.5).
  4. Show you a summary of what was cleaned.
  5. Refresh your Health Score.

This is the recommended action for most users after creating a backup.

🔪 5.4. Detailed Database Cleanup (The "Scalpel")

This section provides a button for every single item listed in the Database Statistics. It allows you to clean items one by one.

⚠️ IMPORTANT: Safe vs. Unsafe (Review First)

Most items are "safe" to clean. However, some items are marked with a ⚠️ Warning Icon. These are "unsafe" because they involve deleting data you might want to review first.

⚡ 5.5. Advanced Database Optimization (The "Power Tools")

These are powerful tools for database maintenance. 💾 Always create a backup before using them.

🔍 5.6. Database Structure Analysis

At the bottom of Section 6, this tool provides a complete, read-only map of your database.

⏰ 6. Automatic Backup & Cleanup (Section 7)

This section provides a "set it and forget it" scheduler for all the tools you just learned about.

⚙️ 6.1. Configuring the Scheduler

🔄 6.2. What the Scheduler Does (when it runs):

The scheduler will run in one of two modes, depending on your settings: *backup & cleanup* or *backup only*:

  1. First, it 💾 creates a new database backup.
  2. Then, it 🚀 runs the One-Click Optimization (all safe cleanups + table optimization).
  3. Finally, it 📊 enforces the backup limit, deleting the oldest backup if necessary.
  4. If enabled, it sends a success or failure email.

📧 6.3. Understanding Email Notifications (Success & Failure)

This is a key "pro" feature.

⏱️ 6.4. A Note on WP-Cron

This scheduler uses the built-in WordPress Cron system (wp_schedule_single_event). This is not a "true" cron job, which means it relies on someone visiting your website to trigger the schedule.

If you set a schedule for 3:00 AM, the tasks will run on the first site visit that occurs at or after 3:00 AM. For most sites, this is perfectly reliable.

⚡ 7. Performance Features Manager (Section 8)

This is a complete, standalone performance suite.

🚫 7.1. CRITICAL: Do NOT Use With Other Caching Plugins

🚨 WARNING

The Server-Side Page Caching and Browser Caching features in this section will conflict with other caching plugins like WP Rocket, LiteSpeed Cache, W3 Total Cache, WP Super Cache, etc.

🤔 You must choose ONE.

If you are already using another caching plugin, 🚫 DO NOT enable "Server-Side Page Caching" or "Browser Caching" in WP Optimal State PRO. You can, however, still use all the "WordPress Core Optimizations" (Section 7.4).

💨 7.2. Feature: Server-Side Page Caching (Deep Dive)

This is the single most effective way to speed up your site.

🌐 7.3. Feature: Browser Caching (.htaccess)

This complements Server Caching. It tells a visitor's browser to save static files (like your logo, CSS, and JS) on their computer.

The following code block will be automatically added to the .htaccess file when this feature is activated:

👉 CLICK TO EXPAND (.htaccess code)
# ============================================================
# BEGIN WP Optimal State Caching
# ============================================================
# 1. EXPIRATION HEADERS
<IfModule mod_expires.c>

ExpiresActive On

# Default: 30 days
ExpiresDefault "access plus 30 days"

# Static Assets: 1 year
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresByType font/woff "access plus 1 year"
ExpiresByType font/woff2 "access plus 1 year"
ExpiresByType application/font-woff "access plus 1 year"

# CSS & JavaScript: 1 month
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"

# HTML: Respect server-side caching headers
ExpiresByType text/html "access plus 24 hours"
</IfModule>


# 2. CACHE-CONTROL & SECURITY HEADERS
<IfModule mod_headers.c>

# Security Headers
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "SAMEORIGIN"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Header always set X-XSS-Protection "1; mode=block"

# Long cache for static assets
<FilesMatch "\.(css|js|ico|pdf|jpg|jpeg|png|gif|webp|svg|woff|woff2|eot|ttf|mp4|webm|mp3|ogg|wav|aac|m4a|flac)$">
Header set Cache-Control "max-age=31536000, public, immutable"
</FilesMatch>

# Dynamic content
<FilesMatch "\.(php|html|htm)$">
Header set Cache-Control "public, max-age=86400" env=!PHP_CACHE_HEADERS
</FilesMatch>

# Protect sensitive WP files
<FilesMatch "(wp-config\.php|readme\.html|license\.txt|wp-login\.php|wp-admin/|xmlrpc\.php)">
Header set Cache-Control "no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "0"
</FilesMatch>

# Ensure proper encoding handling
<FilesMatch "\.(js|css|html|htm|xml|json)$">
Header append Vary Accept-Encoding
</FilesMatch>

# Remove ETag
Header unset ETag
FileETag None
</IfModule>


# 3. COMPRESSION
# Brotli Compression
<IfModule mod_brotli.c>
AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/css application/javascript application/json image/svg+xml application/xml
</IfModule>

# GZIP Compression
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/json
AddOutputFilterByType DEFLATE font/woff
AddOutputFilterByType DEFLATE font/woff2
AddOutputFilterByType DEFLATE image/svg+xml

# Skip already compressed files
SetEnvIfNoCase Request_URI \.(?:gz|zip|bz2|rar|7z|mp4|webm|avi)$ no-gzip dont-vary

# Browser workarounds
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>


# 4. OPTIONAL PERFORMANCE TUNING
# Disable directory listing
Options -Indexes

# Leverage Keep-Alive connections
<IfModule mod_headers.c>
Header set Connection keep-alive
</IfModule>
# ============================================================
# END WP Optimal State Caching
# ============================================================

🖥 7.3.1. Nginx Server Configuration (Security + Caching)

ℹ️ IMPORTANT: Nginx Users

If your server runs on Nginx instead of Apache, the Browser Caching (.htaccess) feature cannot be activated automatically because Nginx does not use .htaccess files.

All other plugin features work normally on Nginx servers, including:

This section provides the configuration you need to manually add to your Nginx configuration file to enable browser caching and secure your plugin directories.

📍 Where to Add This Configuration

You need to add the configuration blocks below to your Nginx configuration file. This file is typically located at:

⚠️ Important: Add these blocks inside your server { ... } block for your WordPress site.

🔐 Step 1: Secure Plugin Directories (Important)

Add this configuration to block direct access to sensitive plugin directories, such as database backups and your custom settings:

👉 CLICK TO EXPAND: Directory Security Configuration
# ============================================================
# WP Optimal State - Directory Security (Nginx)
# ============================================================

# Block access to plugin settings directory
location ~* /wp-content/uploads/optistate-settings/ {
    deny all;
    return 403;
}

# Block access to database backup directory
location ~* /wp-content/uploads/optistate/db-backups/ {
    deny all;
    return 403;
}

# Block access to temp restore directory
location ~* /wp-content/uploads/optistate/db-restore-temp/ {
    deny all;
    return 403;
}

# Allow only .html files in cache directory, block everything else
location ~* /wp-content/uploads/optistate/page-cache/ {
    location ~* \.html$ {
        # Allow HTML files to be served
    }
    location ~* {
        deny all;
        return 403;
    }
}

🚀 Step 2: Browser Caching Configuration (Optional)

Add this configuration to enable browser caching for static assets:

👉 CLICK TO EXPAND: Browser Caching Configuration
# ============================================================
# WP Optimal State - Browser Caching (Nginx)
# ============================================================

# Static Assets: 1 year caching
location ~* \.(jpg|jpeg|png|gif|webp|svg|ico|woff|woff2|eot|ttf|mp4|webm|mp3|ogg|wav|aac|m4a|flac|pdf)$ {
    expires 1y;
    add_header Cache-Control "max-age=31536000, public, immutable";
    add_header Vary "Accept-Encoding";
}

# CSS and JavaScript: 1 month caching
location ~* \.(css|js)$ {
    expires 1M;
    add_header Cache-Control "max-age=2592000, public, immutable";
    add_header Vary "Accept-Encoding";
}

# HTML: 24 hours (for static .html files)
location ~* \.(html|htm)$ {
    expires 24h;
    add_header Cache-Control "public, max-age=86400";
    add_header Vary "Accept-Encoding";
}

# Protect sensitive WP files - always no cache
location ~* (wp-config\.php|readme\.html|license\.txt|wp-login\.php|wp-admin/|xmlrpc\.php) {
    add_header Cache-Control "no-cache, no-store, must-revalidate" always;
    add_header Pragma "no-cache" always;
    expires 0;
}

# Security headers for all responses
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always; # For legacy browsers
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header X-Content-Type-Options "nosniff" always; # Set globally once

# Remove ETag for consistency across CDNs
etag off;

# Gzip compression
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/html text/css text/xml text/javascript 
           application/json application/javascript application/xml+rss 
           application/rss+xml application/xml application/x-javascript
           font/woff font/woff2 font/truetype font/opentype 
           application/vnd.ms-fontobject image/svg+xml;
gzip_disable "msie6";

# Brotli compression (if available)
brotli on;
brotli_comp_level 6;
brotli_types text/plain text/html text/css text/xml text/javascript 
             application/json application/javascript application/xml+rss 
             application/rss+xml application/xml application/x-javascript
             font/woff font/woff2 font/truetype font/opentype 
             application/vnd.ms-fontobject image/svg+xml;

📝 Step 3: Apply the Configuration

  1. Access your server via SSH or your hosting control panel's file manager.
  2. Open your Nginx configuration file for editing (the location depends on your server setup).
  3. Add both configuration blocks inside your server { ... } block.
  4. Test your configuration by running:
    sudo nginx -t
  5. If the test passes, reload Nginx:
    sudo systemctl reload nginx
⚠️ IMPORTANT

If you're not comfortable editing Nginx configuration files, please contact your hosting provider or system administrator for assistance. Incorrect Nginx configuration can cause your site to become inaccessible.

Always backup your configuration file before making changes.

✅ Verification

After applying the configuration, you can verify it's working by:

🏗️ 7.4. Feature: WordPress Core Optimizations (A-Z)

This is a list of toggles and dropdowns to disable or modify non-essential WordPress features that can slow down your site. These are all safe to use even with other caching plugins.

🎯 8. Optimization Strategies: Putting It All Together

Here are a few "recipes" for common scenarios.

🚀 8.1. Strategy 1: The First-Time Setup (5-Minute Tune-Up)

  1. 💾 Backup: Go to Section 1 -> Click Create Backup Now.
  2. 🔍 Diagnose: Go to Section 3 -> Click Refresh Analysis to see your starting Health Score.
  3. ✨ Optimize: Go to Section 2 -> Click 🚀 Optimize Now.
  4. ⏰ Automate: Go to Section 7 -> Set "Run Tasks" to 7 days and your preferred time. Check 📧 Email Notifications. Click Save Settings.
  5. 🛡️ Harden: Go to Section 8 -> Activate all the "WordPress Core Optimizations" (Emoji Scripts, XML-RPC, etc.). Click Save Performance Settings.
  6. ✅ Done. Your database is now clean and will stay clean automatically.

🆘 8.2. Strategy 2: The "My Site is Slow" Emergency Plan

  1. 💾 Backup: Go to Section 1 -> Click Create Backup Now.
  2. 🔍 Diagnose: Go to Section 4. Look at Autoload Data Size. If this is high (e.g., > 1 MB), this is your problem.
  3. 🔧 Fix Autoload: Go to Section 6 -> Click ⚙️ Optimize Autoloaded Options.
  4. 🔧 Fix Overhead: Go to Section 6 -> Click ⚡ Optimize All Tables.
  5. 💨 Enable Caching: (If you have no other cache plugin) Go to Section 8.
    • Enable Server-Side Page Caching. Use the "Include Safe" query mode.
    • Enable Browser Caching (.htaccess).
    • Click Save Performance Settings.
  6. 🗑️ Purge & Preload: Go to Section 8 -> Click 🗑️ Purge All Cache. If you enabled "Automatic Preload," this will start the cache warming process.
  7. ✅ Done. Your site should now be significantly faster.

📅 8.3. Strategy 3: The Monthly Maintenance Tune-Up

(Assuming you already have the automatic schedule running).

  1. 🔍 Check Backups: Go to Section 1. Make sure your automated backups are being created.
  2. ❤️ Review Health: Go to Section 3. Check your Health Score.
  3. 🔪 Manual Cleanup: Go to Section 5. Manually clean the "unsafe" items if you wish:
    • Click "Clean Now" for 🗑️ Trashed Posts.
    • Click "Clean Now" for ⏳ Unapproved Comments (if you've already moderated them).

📥 9. Settings Export & Import (Section 9)

This utility allows you to save all your plugin configurations (from Section 1, 7, 8) to a single .json file. You can use this to create a backup of your settings or to quickly migrate your exact setup to another website.

🚨 IMPORTANT: What is NOT Exported

This feature ONLY exports the plugin's settings, such as your configurations for scheduled tasks and performance features. It does NOT export your database backups, cached pages, or activity logs. Always download your .sql backups separately from Section 1.

📤 9.1. Exporting Settings

  1. Navigate to Section 9: Settings Export & Import in the plugin dashboard and expand it.
  2. Click the "Export Settings" button.
  3. Your browser will download a file named optistate-settings-YYYY-MM-DD-His.json.
  4. Keep this file in a safe place.

📥 9.2. Importing Settings

This will completely overwrite all your current plugin settings. This is useful for restoring your configuration after an update (as described in Section 2.7) or for setting up a new site.

  1. Click the "Choose JSON File" button and select the json file you previously exported.
  2. The plugin validates the file. It must be a valid .json file, under 1MB, and contain the "WP Optimal State" signature.
  3. Once validated, click the "Import Settings" button.
  4. A confirmation pop-up will appear warning you that your current settings will be overwritten. Click "OK" to proceed.
  5. After a successful import, you will be prompted to reload the page to see the new settings take effect.

🔧 10. Troubleshooting & Advanced FAQ

🏗️ 11. Technical Architecture

📝 12. Disclaimer

This plugin provides powerful, low-level access to your WordPress database and server configuration. It is designed to be safe, secure, and effective. However, all servers and WordPress installations are different.

By using WP Optimal State PRO, you agree that you are doing so at your own risk. The author is not responsible for any data loss, site downtime, or other issues that may arise from the use or misuse of this software.

💾 Always create a backup before performing any optimization.

🆘 13. Technical Support

As a lifetime licence holder, you are entitled to priority support.

Before using the support form, please get your license key and be sure to include it in your request along with your website URL.

Also, check the FAQs, as you may find the answer to your question there.