WP-CLI Scripts

These scripts are developer utilities that run against a live WordPress installation using the wp eval-file command. They are intended for local development workflows — seeding data, resetting state between tests, and automating tasks that would otherwise require browser interaction.

Prerequisites

  • WP-CLI must be installed and available as wp in your shell.
  • Run all commands from the WordPress root directory (where wp-config.php lives).
  • The Sanil Website Builder plugin must be active — the scripts depend on its PHP classes.

Available Scripts

Script File Purpose
Create Template bin/create-template.php Insert a new template row + compile it from a JSON definition file
Reset Plugin Data bin/reset-plugin-data.php Wipe all DB rows, options, post meta, and generated files created by the plugin

How wp eval-file Works

wp eval-file is a built-in WP-CLI command that:

  1. Bootstraps WordPress (loads wp-config.php, all active plugins, the active theme).
  2. Evaluates the given PHP file inside that bootstrapped context.
  3. Passes any extra positional arguments to the script as the $args array.

Because WordPress is fully loaded, all plugin classes (SANILWB_DB, SANILWB_Template_Compiler, etc.) are available without any manual require.

Syntax:

wp eval-file <script-path> [arg1] [arg2] ...

Example with an argument:

wp eval-file wp-content/plugins/sanil-website-builder/bin/create-template.php definitions/my-card.json

Keeping Scripts Organised

All scripts live in wp-content/plugins/sanil-website-builder/bin/. This directory is not web-accessible (there is no public URL pointing to it). Each script is a standalone PHP file — no class registration, no autoloading, no side effects beyond what the script explicitly does.