documentation/Transformers/add-transformer.md

1.1 KiB

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 Widgets

To register new transformers use the following code:

function register_new_transformers( $widgets_manager ) {

	require_once( __DIR__ . '/widgets/widget-1.php' );
	require_once( __DIR__ . '/widgets/widget-2.php' );

	$widgets_manager->register( new \Transformer_1() );
	$widgets_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.