115 lines
No EOL
2.5 KiB
Markdown
115 lines
No EOL
2.5 KiB
Markdown
## Folder Structure
|
|
You need at least two files. One file for the transformer itself and one file for registering it.
|
|
```
|
|
activitypub-tribe-transformer/
|
|
|
|
|
├─ activitypub/
|
|
| └─ transformer/
|
|
| └─ tribe.php
|
|
|
|
|
└─ activitypub-tribe-transformer.php
|
|
```
|
|
|
|
## Plugin Files
|
|
**activitypub-tribe-transformer-php**
|
|
```php
|
|
<?php
|
|
/**
|
|
* Plugin Name: ActivityPub Transformer for The Events Calendar
|
|
* Description: Transforms tribe_event posts to ActivityPub object of type Event.
|
|
* Plugin URI: https://event-federation.eu/
|
|
* Version: 1.0.0
|
|
* Author: WordPress ActivityPub Enthusiast
|
|
* Author URI: https://event-federation.eu
|
|
* Text Domain: activitypub-tribe-transformer
|
|
*
|
|
* ActivityPub tested up to: 1.2.0
|
|
*/
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit; // Exit if accessed directly.
|
|
}
|
|
|
|
/**
|
|
* Register Tribe Transformer.
|
|
*
|
|
* Include transformer file and register transformer class.
|
|
*
|
|
* @since 1.0.0
|
|
* @param \Activitypub\Transformer\Transformers_Manager $transformers_manager ActivtiyPub transformers manager.
|
|
* @return void
|
|
*/
|
|
function register_tribe_transformer( $transformers_manager ) {
|
|
require_once( __DIR__ . '/activitypub/transformer/tribe.php' );
|
|
$transformers_manager->register( new \Tribe() );
|
|
}
|
|
|
|
add_action( 'activitypub_transformers_register', 'register_tribe_transformer' );
|
|
```
|
|
|
|
**activtiypub/transformer/tribe.php**
|
|
```php
|
|
<?php
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
exit; // Exit if accessed directly.
|
|
}
|
|
|
|
/**
|
|
* ActivityPub Tribe Transformer
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
class Tribe extends \Activitypub\Transformer\Base {
|
|
|
|
/**
|
|
* Get widget name.
|
|
*
|
|
* Retrieve oEmbed widget name.
|
|
*
|
|
* @since 1.0.0
|
|
* @access public
|
|
* @return string Widget name.
|
|
*/
|
|
public function get_name() {
|
|
return 'activitypub-tribe/tribe';
|
|
}
|
|
|
|
/**
|
|
* Get widget title.
|
|
*
|
|
* Retrieve Transformer title.
|
|
*
|
|
* @since 1.0.0
|
|
* @access public
|
|
* @return string Widget title.
|
|
*/
|
|
public function get_label() {
|
|
return 'The Events Calendar';
|
|
}
|
|
|
|
/**
|
|
* Returns the ActivityStreams 2.0 Object-Type for an Event.
|
|
*
|
|
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-event
|
|
*
|
|
* @return string The Event Object-Type.
|
|
*/
|
|
protected function get_object_type() {
|
|
return 'Event';
|
|
}
|
|
|
|
/**
|
|
* Get supported post types.
|
|
*
|
|
* Retrieve the list of supported WordPress post types this transformer widget can handle.
|
|
*
|
|
* @since 1.0.0
|
|
* @access public
|
|
* @return array Widget categories.
|
|
*/
|
|
public function get_supported_post_types() {
|
|
return [ 'tribe_events' ];
|
|
}
|
|
|
|
}
|
|
``` |