Skip to content

Managed JS Files

Richard Kent Gates edited this page Mar 6, 2026 · 1 revision

Managed JS Files (Pro)

Pro feature. Managed JS Files requires an active Scriptomatic Pro licence. A 3-day free trial is available — visit Scriptomatic → Account.

Create, edit, upload, and delete standalone .js files stored in wp-content/uploads/scriptomatic/. Each file has its own Head/Footer selector, load conditions, CodeMirror editor, and activity log. Files persist across plugin updates because they live in the uploads directory, not the plugin folder.


JS Files List Page

Navigate to Scriptomatic → JS Files to see the list of all managed files. The table shows:

  • Label — human-readable name
  • Filename — the .js filename on disk
  • Location — Head or Footer
  • Conditions — summary of load conditions (or "All pages")
  • Edit / Delete links

An Upload a JS File card at the top lets you import a local .js file directly from your computer.


Creating a File

  1. Go to Scriptomatic → JS Files
  2. Click Add New JS File
  3. Enter a Label, optional Filename (auto-generated from label if left blank), Head / Footer location
  4. Write or paste JavaScript in the CodeMirror editor
  5. Optionally set Load Conditions to restrict when the file loads
  6. Click Save JS File

Editing a File

Click Edit next to any file in the list. The edit page shows:

  • The CodeMirror editor with the current file contents
  • Label, filename, Head/Footer selector, and Load Conditions
  • A per-file Activity Log panel at the bottom (file saves, rollbacks, deletes)

Uploading a File

From the list page UI:

  1. Click Choose File in the Upload card and select a local .js file
  2. Click Upload & Edit — you are taken to the edit page to review the code and set label, location, and conditions before the file goes live

Via REST API:

curl -X POST https://example.com/wp-json/scriptomatic/v1/files/upload \
  -H "Authorization: Basic $(echo -n 'admin:xxxx xxxx xxxx xxxx xxxx xxxx' | base64)" \
  -F "file=@/path/to/tracker.js" \
  -F "label=My Tracker" \
  -F "location=head"

Via WP-CLI:

wp scriptomatic files upload --path=/path/to/tracker.js --label="My Tracker" --location=head

Deleting a File

Click Delete on the list page, or use the Delete button on the edit page. Confirm the prompt. The file is removed from disk and its metadata is removed from scriptomatic_js_files. The deletion is recorded in the Activity Log.


Upload Validation

All upload paths (admin UI, REST API, WP-CLI) run through the same central validation:

  • Extension must be .js
  • MIME type is validated via finfo_open() / mime_content_type() fallback
  • File size is checked against the server's wp_max_upload_size()
  • Content is validated for UTF-8, control characters, PHP tags, and 100 KB inline limit

Storage Location

Files are stored in: wp-content/uploads/scriptomatic/

The directory is created automatically on first use. The URL is derived from wp_upload_dir(). Because files live in the uploads directory they survive plugin deactivation, reactivation, and updates.


File Metadata

Each file's metadata is stored in the scriptomatic_js_files WordPress option as a JSON array. Each entry:

{
  "id": "my-tracker",
  "label": "My Tracker",
  "filename": "my-tracker.js",
  "location": "head",
  "conditions": { "logic": "and", "rules": [] }
}

Home

Clone this wiki locally