Skip to content

Faker Studio Addon Development ​

Addon Plugin Structure ​

Minimal directory layout for a Faker Studio addon WordPress plugin:

my-faker-studio-addon/
├── my-faker-studio-addon.php          # Plugin entry point
├── src/
│   ├── Adapters/
│   │   └── MyAdapter.php         # FieldPluginAdapterInterface implementation
│   └── AiProviders/
│       └── MyAiProvider.php      # AiProviderInterface implementation (optional)
├── tests/
│   └── Unit/
│       └── MyAdapterTest.php
├── composer.json
└── readme.txt

Entry Point Pattern ​

The addon MUST wait for the faker_studio_loaded action before registering anything. This ensures Faker Studio classes and contracts are available.

php
<?php
/**
 * Plugin Name: My Faker Studio Addon
 */

add_action('faker_studio_loaded', function (string $version) {
    // Register a custom field adapter
    add_action('faker_studio_register_adapters', function () {
        \FakerStudio\Services\AdapterFactory::register('my_plugin', MyAdapter::class);
    });

    // Register a custom AI provider (optional)
    add_action('faker_studio_register_ai_providers', function () {
        \FakerStudio\Services\AiProviderFactory::register('my_ai', MyAiProvider::class, 'My AI Service');
    });
});

Registering a Custom Field Adapter ​

Your adapter must implement \FakerStudio\Contracts\FieldPluginAdapterInterface. The adapter constructor receives a FakerService instance.

Required Methods ​

MethodReturnPurpose
isActive()boolReturn true if your field plugin is active
getName()stringHuman-readable plugin name
getVersion()stringPlugin version string
getCustomPostTypes()arrayCPTs registered by the plugin
getCustomTaxonomies()arrayTaxonomies registered by the plugin
getFieldGroups()arrayAll field group configs
getFieldGroupsForPostType(string $postType)arrayField groups for a specific CPT
getFields($fieldGroupId)arrayFields within a group
getFieldsForPostType(string $postType)arrayAll fields for a CPT
saveFieldValue(int $postId, string $fieldName, $value)boolSave a field value
getFieldConfig(string $fieldNameOrKey)?arrayGet field config by name
mapFieldTypeToFaker(array $field)stringMap field type to Faker method
getSupportedFieldTypes()arrayList of supported field type slugs
setCptContext(string $slug, ?string $label)selfSet CPT context for detection

Registration ​

php
\FakerStudio\Services\AdapterFactory::register('my_plugin', MyAdapter::class);

Registering a Custom AI Provider ​

Your provider must implement \FakerStudio\Contracts\AiProviderInterface. Custom providers auto-appear in the Settings dropdown once registered.

Required Methods ​

MethodReturnPurpose
getProviderKey()stringUnique key
getProviderName()stringDisplay name for Settings UI
isAvailable()boolHas API key + is enabled
isEnabled()boolIs enabled regardless of key
getMaskedApiKey()stringMasked API key for display
detectFieldType(...)?arraySingle field detection
detectFieldsBatch(...)?arrayBatch field detection
detectFieldsBatchWithConfig(...)?arrayBatch with faker configs
generateTitleTemplates(...)?arrayGenerate title templates
generateCptContext(...)?arrayGenerate CPT context
testConnection()arrayTest API connection

Registration ​

php
\FakerStudio\Services\AiProviderFactory::register('my_ai', MyAiProvider::class, 'My AI Service');

Available Hooks ​

Actions ​

HookParametersPurpose
faker_studio_loadedstring $versionFaker Studio fully loaded, addon entry point
faker_studio_register_adaptersnoneTime to register custom adapters
faker_studio_register_ai_providersnoneTime to register custom AI providers
faker_studio_activatenonePlugin activated
faker_studio_deactivatebool $deleteDataPlugin deactivated
faker_studio_after_generate_itemstring $type, int $id, int $index, int $total, array $optionsAfter each item generated
faker_studio_after_generatestring $type, array $ids, array $optionsAfter all items in batch

Filters ​

HookParametersPurpose
faker_studio_post_dataarray $postData, string $postType, int $index, int $total, array $optionsModify post data before wp_insert_post
faker_studio_field_valuemixed $value, array $config, string $postType, int $postIdModify field value before save
faker_studio_adapter_priorityarray $priorityChange adapter resolution order
faker_studio_field_name_detection_enabledbool $enabledEnable/disable field name detection

Testing Pattern ​

Use Pest PHP with source-check patterns for adapter tests. Use AdapterFactory::resetRegistry() between tests for isolation:

php
beforeEach(function () {
    \FakerStudio\Services\AdapterFactory::resetRegistry();
});

it('registers the adapter', function () {
    \FakerStudio\Services\AdapterFactory::register('my_plugin', MyAdapter::class);

    expect(\FakerStudio\Services\AdapterFactory::has('my_plugin'))->toBeTrue();
});

Key Classes ​

  • \FakerStudio\Services\AdapterFactory — Registry for field plugin adapters
  • \FakerStudio\Services\AiProviderFactory — Registry for AI providers
  • \FakerStudio\Contracts\FieldPluginAdapterInterface — Contract for field adapters
  • \FakerStudio\Contracts\AiProviderInterface — Contract for AI providers
  • \FakerStudio\Services\FakerService — Core faker data generation service (injected into adapters)