Cleanup transformer registration

This commit is contained in:
André Menrath 2024-01-03 19:14:12 +01:00
parent 056fb3d24f
commit 6c4eecbffa

View file

@ -9,7 +9,7 @@
* Text Domain: activitypub-event-transformers * Text Domain: activitypub-event-transformers
* License: AGPL-3.0-or-later * License: AGPL-3.0-or-later
* *
* ActivityPub tested up to: 1.2.0 * ActivityPub tested up to: 1.3.0
* *
* @package activitypub-event-transformer * @package activitypub-event-transformer
* @license AGPL-3.0-or-later * @license AGPL-3.0-or-later
@ -20,36 +20,33 @@ if ( ! defined( 'ABSPATH' ) ) {
} }
/** /**
* Register Event Transformers. * Add the custom transformers for the events of several WordPress event plugins.
*
* Include fransformer class file and register the transformer class.
*
* @since 1.0.0
* @param \Activitypub\Transformer\Factory $factory ActivtiyPub transformers factory.
* @return void
*/ */
function register_event_transformers( $transformers_factory ) { add_filter(
require_once __DIR__ . '/activitypub/transformer/class-tribe.php'; 'activitypub_transformer',
$transformers_factory->register( new \Tribe() ); function( $transformer, $object, $object_class ) {
/**
require_once __DIR__ . '/activitypub/transformer/class-vs-event.php'; * VS Event List
$transformers_factory->register( new \VS_Event() ); * @see https://wordpress.org/plugins/very-simple-event-list/
} */
if ( is_plugin_active( 'very-simple-event-list/vsel.php' ) && $object->post_type === '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'; require_once __DIR__ . '/activitypub/transformer/class-vs-event.php';
return new \VS_Event( $object ); return new \VS_Event( $object );
} }
// Return the default transformer.
return $transformer; return $transformer;
}, 10, 3 ); },
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 ); add_filter( 'http_request_host_is_external', 'custom_http_request_host_is_external', 10, 3 );
// Your custom callback function // Your custom callback function
@ -59,15 +56,15 @@ function custom_http_request_host_is_external( $is_external, $host, $url ) {
return $is_external; 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 ) { function dont_verify_local_dev_https( $url ) {
return false;
// } }
// add_filters( 'https_ssl_verify', 'dont_verify_local_dev_https', 10, 3);
// function dont_verify_local_dev_https($url) {
// return false;
// }