PluginProbe
ActivityPub / 4.1.1
ActivityPub v4.1.1
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 4.1.1, at includes/class-debug.php

67 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Debug Class.
4 *
5 * @package Activitypub
6 */
7
8 namespace Activitypub;
9
10 use WP_DEBUG;
11 use WP_DEBUG_LOG;
12
13 /**
14 * ActivityPub Debug Class.
15 *
16 * @author Matthias Pfefferle
17 */
18 class Debug {
19 /**
20 * Initialize the class, registering WordPress hooks.
21 */
22 public static function init() {
23 if ( WP_DEBUG_LOG ) {
24 \add_action( 'activitypub_safe_remote_post_response', array( self::class, 'log_remote_post_responses' ), 10, 2 );
25 \add_action( 'activitypub_inbox', array( self::class, 'log_inbox' ), 10, 3 );
26 }
27 }
28
29 /**
30 * Log the responses of remote post requests.
31 *
32 * @param array $response The response from the remote server.
33 * @param string $url The URL of the remote server.
34 */
35 public static function log_remote_post_responses( $response, $url ) {
36 // phpcs:ignore WordPress.PHP.DevelopmentFunctions
37 \error_log( "[OUTBOX] Request to: {$url} with Response: " . \print_r( $response, true ) );
38 }
39
40 /**
41 * Log the inbox requests.
42 *
43 * @param array $data The Activity array.
44 * @param int $user_id The ID of the local blog user.
45 * @param string $type The type of the request.
46 */
47 public static function log_inbox( $data, $user_id, $type ) {
48 $type = strtolower( $type );
49
50 if ( 'delete' !== $type ) {
51 $url = object_to_uri( $data['actor'] );
52 // phpcs:ignore WordPress.PHP.DevelopmentFunctions
53 \error_log( "[INBOX] Request From: {$url} with Activity: " . \print_r( $data, true ) );
54 }
55 }
56
57 /**
58 * Write a log entry.
59 *
60 * @param mixed $log The log entry.
61 */
62 public static function write_log( $log ) {
63 // phpcs:ignore WordPress.PHP.DevelopmentFunctions
64 \error_log( \print_r( $log, true ) );
65 }
66 }
67