PluginProbe
ActivityPub / 3.2.0
ActivityPub v3.2.0
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
activitypub / includes / class-debug.php

class-debug.php in ActivityPub 3.2.0, at includes/class-debug.php

47 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Activitypub;
3
4 use WP_DEBUG;
5 use WP_DEBUG_LOG;
6
7 use function Activitypub\object_to_uri;
8
9 /**
10 * ActivityPub Debug Class
11 *
12 * @author Matthias Pfefferle
13 */
14 class Debug {
15 /**
16 * Initialize the class, registering WordPress hooks
17 */
18 public static function init() {
19 if ( WP_DEBUG_LOG ) {
20 \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 );
22 }
23 }
24
25 // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
26 public static function log_remote_post_responses( $response, $url, $body, $user_id ) {
27 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r
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 }
40 }
41
42 public static function write_log( $log ) {
43 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r
44 \error_log( \print_r( $log, true ) );
45 }
46 }
47