VAT
Your cart

Your cart is empty.

Quick start: your first Addofy extension

This page builds the smallest useful extension: a separate plugin that registers one Addofy module and shows a notice on the dashboard. It uses three files and nothing but the public API.

You need a site with Addofy active and a plugins folder you can write to.

Every function, hook, handle and CSS token of Addofy starts with adba. That is the fixed code prefix of Addofy and it does not change (why).

1. The plugin file

Create wp-content/plugins/hello-addofy/hello-addofy.php. The plugin does nothing unless Addofy is active, so it can never break a site that has Addofy switched off.

<?php
/**
 * Plugin Name: Hello Addofy
 * Description: A first Addofy extension.
 * Version: 1.0.0
 */

// Load the module class only when Addofy is active. The class extends an Addofy class,
// so a plugin that loads before Addofy would otherwise fail.
add_action( 'plugins_loaded', static function () {
	if ( ! function_exists( 'adba_register_module' ) ) {
		return;
	}
	require_once __DIR__ . '/class-hello-module.php';
	adba_register_module( Hello_Module::class );
}, 5 );

Register before plugins_loaded priority 20: that is the moment Addofy collects the module classes.

2. The module

Create class-hello-module.php in the same folder. A module needs an id, a label, a description and a default state. Everything else has a default.

<?php
use AddoBack\Core\Screen;
use AddoBack\Modules\AbstractModule;

final class Hello_Module extends AbstractModule {

	public function id(): string {
		return 'hello'; // Prefix it with your plugin slug in a real plugin.
	}

	public function label(): string {
		return __( 'Hello', 'hello-addofy' );
	}

	public function description(): string {
		return __( 'Shows a notice on the dashboard.', 'hello-addofy' );
	}

	public function default_enabled(): bool {
		return true;
	}

	public function screens(): array {
		return array( 'dashboard' ); // Screen ids. An empty array means every screen.
	}

	public function on_screen( Screen $screen ): void {
		adba( 'assets' )->enqueue_external(
			'hello-addofy',
			plugins_url( 'hello.js', __FILE__ ),
			array( 'adba-core' ), // Needed for window.adba.
			'1.0.0'
		);
	}
}

on_screen() only runs on the screens the module names, and only when Addofy is active there. The script you queue through enqueue_external() follows the same rules: it never loads on the frontend, in safe mode or on an excluded screen.

3. The script

Create hello.js in the same folder.

adba.boot( 'hello', () => {
	adba.notices.add( { id: 'hello', level: 'success', text: 'Hello from my extension.', source: 'hello' } );
} );

adba.boot() runs your code in isolation: if it throws, Addofy logs the error with the id hello and carries on.

4. Try it

  1. Activate Hello Addofy under Plugins.
  2. Open Addofy > Modules. Your module is listed there with its own card and a switch.
  3. Open the dashboard. The notice appears in the notice panel.

Switch the module off in Addofy > Modules and the notice is gone. That switch is part of what a module gives you for free.

Where to go next

Ready to connect your AI to real tools?

Start free trial