documentation/Transformers/add-transformer.md
2023-11-22 21:57:19 +01:00

26 lines
1.1 KiB
Markdown

# Add New Transformer
The WordPress ActivityPub plugin offers an advanced built-in transformer, but it also allows other plugins to register new transformers.
## Hooks
To do that we simply hook to the `activivitypub_transformer_register` action which provides access to the transformer manager as a parameter. Developers can use this manager to add new transformers using the `register()` method of this manager instance.
## Registering Transformers
To register new transformers use the following code:
```php
function register_new_transformers( $transformers_manager ) {
require_once( __DIR__ . '/activitypub/transformer/name-1.php' );
require_once( __DIR__ . '/activitypub/transformer/name-2.php' );
$transformers_manager->register( new \Transformer_1() );
$transformers_manager->register( new \Transformer_2() );
}
add_action( 'activivitypub_transformer_register', 'register_new_transformers' );
```
The transformer manager registers new transformers by accepting transformer instances. For more information about the transformer class, read about the [transformer class structure](./transformer-structure.md/).