wordpress-activitypub/templates/post-json.php
Jan Boddez 2b96c6efd2
Improve transformer (#731)
* Factory::get_transformer() may return a WP_Error instance

* Fix templates

* PHPDoc

* "Fix" conneg (for posts, at least)

* (Hopefully) fix conneg for comments, too

* Ugly, but works?

* Fix outboxes, collections

* Clean up a bit

* Use Factory

* Remove outdated `use`

* Use Transformer\Factory instead of Transformer\Post

* "Fix" _deprecated_function() call

* Remove superfluous transformer check

* Remove transformer check

* Call Transformer::get_transformer() only once per request

* PHPDoc

* this should be fine

a failing transformer is very unlikely because there are a lot of checks before `is_singular` or `is_comment` is valid.

* no longer used

---------

Co-authored-by: Matthias Pfefferle <pfefferle@users.noreply.github.com>
2024-05-16 15:14:31 +02:00

25 lines
728 B
PHP

<?php
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$post = \get_post();
$transformer = \Activitypub\Transformer\Factory::get_transformer( $post );
if ( \is_wp_error( $transformer ) ) {
\wp_die(
esc_html( $transformer->get_error_message() ),
404
);
}
/*
* Action triggerd prior to the ActivityPub profile being created and sent to the client
*/
\do_action( 'activitypub_json_post_pre' );
\header( 'Content-Type: application/activity+json' );
echo $transformer->to_object()->to_json(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
/*
* Action triggerd after the ActivityPub profile has been created and sent to the client
*/
\do_action( 'activitypub_json_post_post' );