documentation/Transformers/add-transformer.md

27 lines
1.1 KiB
Markdown
Raw Normal View History

2023-11-22 18:27:24 +01:00
# 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.
2023-11-22 21:55:35 +01:00
## Registering Transformers
2023-11-22 18:27:24 +01:00
To register new transformers use the following code:
```php
2023-11-22 21:55:35 +01:00
function register_new_transformers( $transformers_manager ) {
2023-11-22 18:27:24 +01:00
2023-11-22 21:55:35 +01:00
require_once( __DIR__ . '/activitypub/transformer/name-1.php' );
require_once( __DIR__ . '/activitypub/transformer/name-2.php' );
2023-11-22 18:27:24 +01:00
2023-11-22 21:55:35 +01:00
$transformers_manager->register( new \Transformer_1() );
$transformers_manager->register( new \Transformer_2() );
2023-11-22 18:27:24 +01:00
}
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/).