| @@ -1,13 +1,16 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 3 | -$post = \get_post(); | |
| 3 | +$post = \get_post(); | |
| 4 | +$transformer = \Activitypub\Transformer\Factory::get_transformer( $post ); | |
| 4 | 5 | |
| 5 | -$object = new \Activitypub\Transformer\Post( $post ); | |
| 6 | -$json = \array_merge( array( '@context' => \Activitypub\get_context() ), $object->to_object()->to_array() ); | |
| 6 | +if ( \is_wp_error( $transformer ) ) { | |
| 7 | + \wp_die( | |
| 8 | + esc_html( $transformer->get_error_message() ), | |
| 9 | + 404 | |
| 10 | + ); | |
| 11 | +} | |
| 7 | 12 | |
| 8 | -// filter output | |
| 9 | -$json = \apply_filters( 'activitypub_json_post_array', $json ); | |
| 10 | 13 | |
| 11 | 14 | /* |
| 12 | 15 | * Action triggerd prior to the ActivityPub profile being created and sent to the client |
| 13 | 16 | */ |
| @@ -12,25 +15,10 @@ | ||
| 12 | 15 | * Action triggerd prior to the ActivityPub profile being created and sent to the client |
| 13 | 16 | */ |
| 14 | 17 | \do_action( 'activitypub_json_post_pre' ); |
| 15 | 18 | |
| 16 | -$options = 0; | |
| 17 | -// JSON_PRETTY_PRINT added in PHP 5.4 | |
| 18 | -if ( \get_query_var( 'pretty' ) ) { | |
| 19 | - $options |= \JSON_PRETTY_PRINT; // phpcs:ignore | |
| 20 | -} | |
| 21 | - | |
| 22 | -$options |= \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_QUOT; | |
| 23 | - | |
| 24 | -/* | |
| 25 | - * Options to be passed to json_encode() | |
| 26 | - * | |
| 27 | - * @param int $options The current options flags | |
| 28 | - */ | |
| 29 | -$options = \apply_filters( 'activitypub_json_post_options', $options ); | |
| 30 | - | |
| 31 | 19 | \header( 'Content-Type: application/activity+json' ); |
| 32 | -echo \wp_json_encode( $json, $options ); | |
| 20 | +echo $transformer->to_object()->to_json(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 33 | 21 | |
| 34 | 22 | /* |
| 35 | 23 | * Action triggerd after the ActivityPub profile has been created and sent to the client |
| 36 | 24 | */ |