add draft for example transformer
This commit is contained in:
parent
dd5bd728c5
commit
d4ea449d3d
2 changed files with 119 additions and 4 deletions
|
@ -6,18 +6,18 @@ The WordPress ActivityPub plugin comes with a built-in transformer which lets yo
|
|||
|
||||
Other plugins can register new transformers and unregister existing ones.
|
||||
|
||||
* [Add New Transformer](./add-transformer/)
|
||||
* [Remove Transformer](./remove-transformer/)
|
||||
* [Add New Transformer](./add-transformer.md/)
|
||||
* [Remove Transformer](./remove-transformer.md/)
|
||||
|
||||
## Creating New Transformers
|
||||
|
||||
Learn more about transformer anatomy and how to create your own:
|
||||
|
||||
* [Transformer Structure](./transformer-structure/)
|
||||
* [Transformer Structure](./transformer-structure.md/)
|
||||
|
||||
|
||||
## Code Examples
|
||||
|
||||
See the following examples to see how easy it is.
|
||||
|
||||
* [The Events Calendar](./simple-example/)
|
||||
* [The Events Calendar](./the-events-calendar-example.md/)
|
||||
|
|
115
Transformers/the-events-calendar-example.md
Normal file
115
Transformers/the-events-calendar-example.md
Normal file
|
@ -0,0 +1,115 @@
|
|||
## 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' ];
|
||||
}
|
||||
|
||||
}
|
||||
```
|
Loading…
Reference in a new issue