From 6c4eecbffafdac77191f44ba901369fcfe1ff6fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Menrath?= Date: Wed, 3 Jan 2024 19:14:12 +0100 Subject: [PATCH] Cleanup transformer registration --- activitypub-event-transformers.php | 77 ++++++++++++++---------------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/activitypub-event-transformers.php b/activitypub-event-transformers.php index 84df772..f8ffafd 100644 --- a/activitypub-event-transformers.php +++ b/activitypub-event-transformers.php @@ -9,7 +9,7 @@ * Text Domain: activitypub-event-transformers * License: AGPL-3.0-or-later * - * ActivityPub tested up to: 1.2.0 + * ActivityPub tested up to: 1.3.0 * * @package activitypub-event-transformer * @license AGPL-3.0-or-later @@ -20,36 +20,33 @@ if ( ! defined( 'ABSPATH' ) ) { } /** - * Register Event Transformers. - * - * Include fransformer class file and register the transformer class. - * - * @since 1.0.0 - * @param \Activitypub\Transformer\Factory $factory ActivtiyPub transformers factory. - * @return void + * Add the custom transformers for the events of several WordPress event plugins. */ -function register_event_transformers( $transformers_factory ) { - require_once __DIR__ . '/activitypub/transformer/class-tribe.php'; - $transformers_factory->register( new \Tribe() ); +add_filter( + 'activitypub_transformer', + function( $transformer, $object, $object_class ) { + /** + * VS Event List + * @see https://wordpress.org/plugins/very-simple-event-list/ + */ + if ( is_plugin_active( 'very-simple-event-list/vsel.php' ) && $object->post_type === 'event' ) { + require_once __DIR__ . '/activitypub/transformer/class-vs-event.php'; + return new \VS_Event( $object ); + } + // Return the default transformer. + return $transformer; + }, + 10, + 3 +); - require_once __DIR__ . '/activitypub/transformer/class-vs-event.php'; - $transformers_factory->register( new \VS_Event() ); -} - -add_action( 'activitypub_transformers_register', 'register_event_transformers' ); - -// Filter be object class -add_filter( 'activitypub_transformer', function( $transformer, $object, $object_class ) { - if ( $object->post_type === 'event' ) { - require_once __DIR__ . '/activitypub/transformer/class-vs-event.php'; - return new \VS_Event( $object ); - } - return $transformer; -}, 10, 3 ); - -// TODO Below here is temporary code needed to do local testing atm. - -// Add a filter for http_request_host_is_external +/** + * Add a filter for http_request_host_is_external + * + * TODO: Remove this. + * + * @todo This filter is temporary code needed to do local testing. + */ add_filter( 'http_request_host_is_external', 'custom_http_request_host_is_external', 10, 3 ); // Your custom callback function @@ -59,15 +56,15 @@ function custom_http_request_host_is_external( $is_external, $host, $url ) { return $is_external; } -// add_filter( 'rest_request_before_callbacks', 'change_relay_actor_to_blog_actor', 10, 3 ); +/** + * Don't verify ssl certs for testing. + * + * TODO: Remove this. + * + * @todo This filter is temporary code needed to do local testing. + */ +add_filter( 'https_ssl_verify', 'dont_verify_local_dev_https', 10, 3 ); -// function change_relay_actor_to_blog_actor( $response, $handler, $request ) { - -// } - -// add_filters( 'https_ssl_verify', 'dont_verify_local_dev_https', 10, 3); - - -// function dont_verify_local_dev_https($url) { -// return false; -// } +function dont_verify_local_dev_https( $url ) { + return false; +}