VAT
Your cart

Your cart is empty.

Recipe: add a step to the Addofy quick start

Goal: your plugin adds a step to the Addofy quick start, the wizard that walks a site through its first settings.

The step

A step implements AddoBack\Setup\StepInterface. Extend AddoBack\Setup\AbstractStep to get defaults for applies(), fields(), render() and save().

The interface has these parts:

  • id(): a stable id, used in the URL (&step=...) and the nonce.
  • label(): a short name for the progress bar.
  • description(): a one-line explanation under the step title.
  • applies(): whether the step is part of this run. A step that does not apply is skipped and not counted.
  • fields(): schema definitions of the fields this step edits, keyed by config key.
  • render( $values ): the inside of the step form. Output must be escaped.
  • save( $input ): saves a submission. The nonce and capability are already checked, and the input is still unsanitized.
use AddoBack\Setup\AbstractStep;

final class Myplugin_Step extends AbstractStep {

	public function id(): string {
		return 'myplugin';
	}

	public function label(): string {
		return __( 'My plugin', 'myplugin' );
	}

	public function description(): string {
		return __( 'Choose how My plugin behaves.', 'myplugin' );
	}

	public function applies(): bool {
		return defined( 'MYPLUGIN_VERSION' ); // Skipped when your plugin is not there.
	}

	public function render( array $values ): string {
		return '<p><label>' . esc_html__( 'Greeting', 'myplugin' )
			. ' <input name="' . esc_attr( self::input_name( 'greeting' ) ) . '" value="' . esc_attr( (string) get_option( 'myplugin_greeting', '' ) ) . '"></label></p>';
	}

	public function save( array $input ): array {
		update_option( 'myplugin_greeting', sanitize_text_field( (string) ( $input['greeting'] ?? '' ) ) );
		return array(); // Optional keys: goto (a step id), locked, notice.
	}
}

Register it

add_filter( 'adba_setup_steps', static function ( array $steps ) {
	$steps[] = new Myplugin_Step( adba() );
	return $steps;
} );

AbstractStep takes the Addofy container in its constructor, so pass adba(). Steps run in the order of the list.

Ready to connect your AI to real tools?

Start free trial