Created
January 4, 2023 11:49
-
-
Save akirk/9b81a09c0a9701e29926349ba210bc42 to your computer and use it in GitHub Desktop.
Log ActivityPub requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"generator":"Code Snippets v3.2.2","date_created":"2023-01-04 11:48","snippets":[{"name":"Log ActivityPub requests","scope":"global","code":"add_action(\n\t'plugins_loaded',\n\tfunction() {\n\t\tremove_action( 'activitypub_safe_remote_post_response', array( '\\Activitypub\\Debug', 'log_remote_post_responses' ), 10 );\n\t\tadd_action( 'activitypub_inbox',\n\t\t\tfunction ( $data, $user_id, $type ) {\n\t\t\t\tif ( ! defined( 'WP_DEBUG' ) ) {\n\t\t\t define( 'WP_DEBUG', true );\n\t\t\t\t}\n\n\t\t\t\terror_log( \"post to inbox {$user_id} type {$type} with response: \" . \\json_encode( $data, JSON_PRETTY_PRINT ) );\n\t\t\t},\n\t\t\t10,\n\t\t\t3\n\t\t);\n\n\t\tadd_action(\n\t\t\t'activitypub_safe_remote_post_response',\n\t\t\tfunction ( $response, $url, $body, $user_id ) {\n\t\t\t\tif ( ! defined( 'WP_DEBUG' ) ) {\n\t\t\t define( 'WP_DEBUG', true );\n\t\t\t\t}\n\t\t\t\terror_log( \"Request to: {$url} with response: \" . \\json_encode( $response, JSON_PRETTY_PRINT ) . \" body: {$body}\" );\n\t\t\t},\n\t\t\t10,\n\t\t\t4\n\t\t);\n\t\t\n\t\tadd_action( 'friends_activitypub_log', function( $message, $objects = array() ) {\n\t\t\tif ( ! defined( 'WP_DEBUG' ) ) {\n\t\t\t\tdefine( 'WP_DEBUG', true );\n\t\t\t}\n\t\t\tforeach ( $objects as $key => $obj ) {\n\t\t\t\t $message .= PHP_EOL . $key . ': ' . wp_json_encode( $obj, JSON_PRETTY_PRINT );\n\t\t\t}\n\t\t\t\n\t\t\terror_log( $message );\n\t\t}, 10, 2 );\n\t},\n\t20\n);","priority":"10"}]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment