// Third-party WordPress plugin integration patterns. Use when adding new integrations, debugging compatibility with other plugins, or working with existing integrations.
| name | activitypub-integrations |
| description | Third-party WordPress plugin integration patterns. Use when adding new integrations, debugging compatibility with other plugins, or working with existing integrations. |
This skill provides guidance on integrating the ActivityPub plugin with other WordPress plugins.
All integrations live in the integration/ directory.
File naming: class-{plugin-name}.php (following PHP conventions)
For complete directory structure and naming conventions, see PHP Class Structure.
<?php
namespace Activitypub\Integration;
class Plugin_Name {
public static function init() {
\add_filter( 'activitypub_transformer', array( self::class, 'custom_transformer' ), 10, 2 );
\add_filter( 'activitypub_post_types', array( self::class, 'add_post_types' ) );
}
public static function custom_transformer( $transformer, $object ) {
// Return custom transformer if needed.
return $transformer;
}
public static function add_post_types( $post_types ) {
// Add plugin's post types.
$post_types[] = 'plugin_post_type';
return $post_types;
}
}
public static function add_post_types( $post_types ) {
$post_types[] = 'event';
$post_types[] = 'product';
return $post_types;
}
public static function transformer( $transformer, $object ) {
if ( 'custom_type' === get_post_type( $object ) ) {
require_once __DIR__ . '/transformer/class-custom.php';
return new Transformer\Custom( $object );
}
return $transformer;
}
\add_filter( 'activitypub_activity_object', function( $object, $post ) {
if ( 'product' === get_post_type( $post ) ) {
$object['type'] = 'Product';
$object['price'] = get_post_meta( $post->ID, 'price', true );
}
return $object;
}, 10, 2 );
// Check if integration is active.
if ( class_exists( '\Activitypub\Integration\Plugin_Name' ) ) {
// Integration loaded.
}
// Multiple detection methods.
if ( defined( 'PLUGIN_VERSION' ) ) { }
if ( function_exists( 'plugin_function' ) ) { }
if ( class_exists( 'Plugin_Class' ) ) { }
// Use appropriate priority.
add_filter( 'hook', 'callback', 20 ); // After plugin's filter.
// Use fully qualified names.
$object = new \Plugin\Namespace\Class();