wordpress-activitypub/templates/post-json.php

38 lines
1.1 KiB
PHP
Raw Permalink Normal View History

<?php
2022-12-02 20:44:56 +01:00
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
2019-09-27 11:36:52 +02:00
$post = \get_post();
$object = \Activitypub\Transformer\Transformer_Factory::instance()->transform( $post );
2023-11-29 23:46:13 +01:00
$json = \array_merge( array( '@context' => \Activitypub\get_context() ), $object->to_array() );
// filter output
2019-09-27 11:36:52 +02:00
$json = \apply_filters( 'activitypub_json_post_array', $json );
/*
* Action triggerd prior to the ActivityPub profile being created and sent to the client
*/
2019-09-27 11:36:52 +02:00
\do_action( 'activitypub_json_post_pre' );
$options = 0;
// JSON_PRETTY_PRINT added in PHP 5.4
2019-09-27 11:36:52 +02:00
if ( \get_query_var( 'pretty' ) ) {
$options |= \JSON_PRETTY_PRINT; // phpcs:ignore
}
2023-12-12 17:00:08 +01:00
$options |= ACTIVITYPUB_JSON_FORMAT_OPTIONS;
2019-02-02 23:56:05 +01:00
/*
* Options to be passed to json_encode()
*
* @param int $options The current options flags
*/
2019-09-27 11:36:52 +02:00
$options = \apply_filters( 'activitypub_json_post_options', $options );
2019-09-27 11:36:52 +02:00
\header( 'Content-Type: application/activity+json' );
echo \wp_json_encode( $json, $options );
/*
* Action triggerd after the ActivityPub profile has been created and sent to the client
*/
2019-09-27 11:36:52 +02:00
\do_action( 'activitypub_json_post_post' );