PluginProbe
ActivityPub / 7.8.2
ActivityPub v7.8.2
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
← All changes | includes/class-debug.php +79 -17 1.3.07.8.2 View file →
@@ -1,36 +1,98 @@
1 1 <?php
2 +/**
3 + * Debug Class.
4 + *
5 + * @package Activitypub
6 + */
7 +
2 8 namespace Activitypub;
3 9
4 -use WP_DEBUG;
5 -use WP_DEBUG_LOG;
6 -
7 10 /**
8 - * ActivityPub Debug Class
11 + * ActivityPub Debug Class.
9 12 *
10 13 * @author Matthias Pfefferle
11 14 */
12 15 class Debug {
13 16 /**
14 - * Initialize the class, registering WordPress hooks
17 + * Initialize the class, registering WordPress hooks.
15 18 */
16 19 public static function init() {
17 - if ( WP_DEBUG && WP_DEBUG_LOG ) {
18 - \add_action( 'activitypub_safe_remote_post_response', array( self::class, 'log_remote_post_responses' ), 10, 4 );
20 + if ( \WP_DEBUG && \WP_DEBUG_LOG ) {
21 + \add_action( 'activitypub_safe_remote_post_response', array( self::class, 'log_remote_post_responses' ), 10, 2 );
22 +
23 + \add_action( 'activitypub_inbox', array( self::class, 'log_inbox' ), 10, 3 );
24 + \add_action( 'activitypub_rest_inbox_disallowed', array( self::class, 'log_inbox' ), 10, 3 );
25 +
26 + \add_action( 'activitypub_add_to_outbox_failed', array( self::class, 'log_outbox_error' ), 10, 4 );
27 +
28 + \add_action( 'activitypub_sent_to_inbox', array( self::class, 'log_sent_to_inbox' ), 10, 2 );
19 29 }
20 30 }
21 31
22 - public static function log_remote_post_responses( $response, $url, $body, $user_id ) {
23 - // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r
24 - \error_log( "Request to: {$url} with response: " . \print_r( $response, true ) );
32 + /**
33 + * Log the responses of remote post requests.
34 + *
35 + * @param array $response The response from the remote server.
36 + * @param string $url The URL of the remote server.
37 + */
38 + public static function log_remote_post_responses( $response, $url ) {
39 + // phpcs:ignore WordPress.PHP.DevelopmentFunctions
40 + \error_log( "[OUTBOX] Request to: {$url} with Response: " . \print_r( $response, true ) );
25 41 }
26 42
43 + /**
44 + * Log the inbox requests.
45 + *
46 + * @param array $data The Activity array.
47 + * @param int $user_id The ID of the local blog user.
48 + * @param string $type The type of the request.
49 + */
50 + public static function log_inbox( $data, $user_id, $type ) {
51 + $type = strtolower( $type );
52 +
53 + if ( 'delete' !== $type ) {
54 + $actor = $data['actor'] ?? '';
55 + $url = object_to_uri( $actor );
56 + // phpcs:ignore WordPress.PHP.DevelopmentFunctions
57 + \error_log( "[INBOX] Request from: {$url} with Activity: " . \print_r( $data, true ) );
58 + }
59 + }
60 +
61 + /**
62 + * Log failed outbox requests.
63 + *
64 + * @param false|\WP_Error $error The error object or false.
65 + * @param array $data The Activity array.
66 + * @param string $type The type of the request.
67 + * @param int $user_id The ID of the local blog user.
68 + */
69 + public static function log_outbox_error( $error, $data, $type, $user_id ) {
70 + $error_message = \is_wp_error( $error ) ? $error->get_error_message() : 'Unknown';
71 +
72 + // phpcs:ignore WordPress.PHP.DevelopmentFunctions
73 + \error_log( "[OUTBOX] Failed to add {$type}-Activity from: {$user_id} (Error: {$error_message}) with Activity: " . \print_r( $data, true ) );
74 + }
75 +
76 + /**
77 + * Logs Follower notifications.
78 + *
79 + * @param array $result The result of the remote post request.
80 + * @param string $inbox The inbox URL.
81 + */
82 + public static function log_sent_to_inbox( $result, $inbox ) {
83 + if ( \is_wp_error( $result ) ) {
84 + // phpcs:ignore WordPress.PHP.DevelopmentFunctions
85 + \error_log( "[DISPATCHER] Failed Request to: {$inbox} with Result: " . \print_r( $result, true ) );
86 + }
87 + }
88 +
89 + /**
90 + * Write a log entry.
91 + *
92 + * @param mixed $log The log entry.
93 + */
27 94 public static function write_log( $log ) {
28 - if ( \is_array( $log ) || \is_object( $log ) ) {
29 - // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r
30 - \error_log( \print_r( $log, true ) );
31 - } else {
32 - // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
33 - \error_log( $log );
34 - }
95 + // phpcs:ignore WordPress.PHP.DevelopmentFunctions
96 + \error_log( \print_r( $log, true ) );
35 97 }
36 98 }