Skip to content

Commit 7a19bde

Browse files
committed
log inbox requests
1 parent 46db447 commit 7a19bde

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

includes/class-debug.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
use WP_DEBUG;
55
use WP_DEBUG_LOG;
66

7+
use function Activitypub\object_to_uri;
8+
79
/**
810
* ActivityPub Debug Class
911
*
@@ -16,13 +18,25 @@ class Debug {
1618
public static function init() {
1719
if ( WP_DEBUG_LOG ) {
1820
\add_action( 'activitypub_safe_remote_post_response', array( self::class, 'log_remote_post_responses' ), 10, 4 );
21+
\add_action( 'activitypub_inbox', array( self::class, 'log_inbox' ), 10, 4 );
1922
}
2023
}
2124

2225
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
2326
public static function log_remote_post_responses( $response, $url, $body, $user_id ) {
2427
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r
25-
\error_log( "Request to: {$url} with response: " . \print_r( $response, true ) );
28+
\error_log( "[OUTBOX] Request to: {$url} with Response: " . \print_r( $response, true ) );
29+
}
30+
31+
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
32+
public static function log_inbox( $data, $user_id, $type, $activity ) {
33+
$type = strtolower( $type );
34+
35+
if ( 'delete' !== $type ) {
36+
$url = object_to_uri( $data['actor'] );
37+
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r
38+
\error_log( "[INBOX] Request From: {$url} with Activity: " . \print_r( $data, true ) );
39+
}
2640
}
2741

2842
public static function write_log( $log ) {

0 commit comments

Comments
 (0)