Skip to content

Code Generators (make:*)

Xe Plugin includes command-line scaffolding generators that save repetitive boilerplate creation when adding new modules, database sequences, and Elementor widgets.


php xe make:module <Name>

Generates a new business module class that extends Xe_Plugin\Modules\BaseModule.

php xe make:module Ticket

Generated File:

  • Location: src/Modules/Ticket.php
  • Namespace: Xe_Plugin\Modules
  • Features Included:
  • Request validation and nonce verification.
  • Automatic save(), trash(), restore(), and delete() handlers.
  • Form error handling with transient storage (_xe_plugin_alert, _xe_plugin_errors).
  • Post meta synchronization.
  • Safe redirects after state changes.

Customizing the Generated Module:

namespace Xe_Plugin\Modules;

use Xe_Plugin\Modules\BaseModule;

class Ticket extends BaseModule {

  protected $nonce = '_xe_plugin_ticket_nonce';
  protected $nonce_action = '_xe_plugin_ticket_action';
  public $post_type = 'custom-ticket';
  public $endpoint = 'tickets';

  public function save() {
    // Custom save logic...
    parent::save();
  }

}

php xe make:sequence <Name>

Generates a custom database table class to manage persistent, atomic auto-increment sequential numbering (ideal for invoices, order IDs, booking numbers, or ticket reference numbers).

php xe make:sequence Invoice

Generated File:

  • Location: src/Database/Sequences/Invoice.php
  • Namespace: Xe_Plugin
  • Methods Included:
  • Invoice::create_table(): Creates the sequence table using WordPress dbDelta.
  • Invoice::add( $name ): Registers a new named sequence.
  • Invoice::next( $name ): Atomically increments and returns the next sequential number.
  • Invoice::current( $name ): Retrieves the current sequence number without incrementing.
  • Invoice::reset( $name, $number = 1 ): Resets the sequence counter.

Example Usage:

use Xe_Plugin\Invoice;

// Create table during plugin activation
Invoice::create_table();

// Add and retrieve next number
Invoice::add( 'annual-sales' );
$invoice_number = Invoice::next( 'annual-sales' ); // Returns 1, next call returns 2, etc.

php xe make:elementor <Name>

Generates a custom Elementor widget class that extends \Elementor\Widget_Base.

php xe make:elementor PricingTable

Generated File:

  • Location: src/Elementor/PricingTable.php
  • Namespace: Xe_Plugin\Elementor
  • Features Included:
  • Automatically categorized under the custom _xe_plugin Elementor category.
  • Pre-configured Content and Style control sections.
  • Frontend render() method with sanitization via wp_kses() and esc_html().
  • Automatically discovered and loaded by Xe_Plugin\Elementor.

Example Control Configuration:

namespace Xe_Plugin\Elementor;

class PricingTable extends \Elementor\Widget_Base {

  public function get_name() {
    return 'pricingtable';
  }

  public function get_title() {
    return esc_html__( 'Pricing Table', 'xe-plugin' );
  }

  public function get_icon() {
    return 'fas fa-tags';
  }

  public function get_categories() {
    return ['_xe_plugin'];
  }

  protected function register_controls() {
    // Add Elementor controls...
  }

  protected function render() {
    // Frontend HTML rendering...
  }

}