Developers

Developer Overview

This guide orients you around the free Kitbix Commerce plugin internals—how it boots, where routes live, and how to extend it safely.

Architecture snapshot

Boot process

  • KitbixCommerce\Core\Plugin::boot() wires up REST routes, assets, addon registry, payment gateways, and hooks into init, admin_menu, wp_enqueue_scripts, etc.
  • Activation (Plugin::activate()) runs database migrations (Core\Database::migrate()) and ensures required pages exist.
  • Addon bootstrap happens on init (priority 20) via AddonRegistry::boot(); each addon registers metadata + hooks.

Key directories

  • app/Controllers: REST endpoints (Products, Orders, Analytics, Settings, etc.).
  • app/Models: Thin wrappers around Kitbix tables using a shared Model base class.
  • app/Addons: Free addons (toast, view counter, trust badge…), each with contract + assets.
  • database/migrations: dbDelta callbacks executed on activation.

Developer workflow

  1. Confirm requirements: decide whether a hook, addon, REST route, or shortcode override best solves the problem.
  2. Inspect the relevant controller/model. All REST logic runs through /wp-json/kitbix-commerce/v1 (admin + public route files describe every endpoint).
  3. Extend using hooks (kitbix_commerce_order_created, kitbix_commerce_product_saved, etc.) or register new addons through kitbix_commerce_register_addons.
  4. Add tests/logging. Most controllers sanitize via sanitize_text_field/current_time, so mirror that style when posting data.
  5. Ship via MU plugin or standalone plugin so updates to Kitbix core remain drop-in.

Core services

  • Database layer: Core\Database prefixes tables and exposes migrate(). Models call static::wpdb() to run queries.
  • Cart/checkout: Services\CartService and CheckoutTotals calculate totals, handle gateway charges, and update stock.
  • Email notifications: EmailNotificationService sends confirmations/status emails keyed off controller actions.
  • Router: REST routes are declared in routes/admin.php and routes/public.php then registered automatically.

Tips & best practices

Tip: Load WordPress stubs (or phpstan/wordpress) in your IDE to satisfy functions such as sanitize_text_field() and current_time().
Tip: Keep addon logic idempotent—addons can be toggled on/off without flushing state, so guard expensive operations behind AddonRegistry::isEnabled().
Tip: Namespaces follow PSR-4. Autoload new code via Composer or spl_autoload_register before hooking into Kitbix.

Common mistakes

  • Editing plugin templates directly instead of using hooks (e.g., kitbix_commerce_checkout_after_payment_methods).
  • Skipping nonce verification when calling admin endpoints (Controller::verifyNonce() blocks those requests).
  • Writing raw SQL without $wpdb->prepare() or respecting the Kitbix table prefix helper.
Reminder: Never fork the plugin to add logic—upgrades will overwrite your changes. Build extensions as separate plugins or addons so the free core can be updated safely.