wordpress-activitypub/includes/class-debug.php

47 lines
1.7 KiB
PHP
Raw Normal View History

2019-09-27 08:12:59 +00:00
<?php
namespace Activitypub;
2023-04-20 13:22:11 +00:00
use WP_DEBUG;
use WP_DEBUG_LOG;
2024-08-17 18:17:47 +00:00
use function Activitypub\object_to_uri;
2019-09-27 08:12:59 +00:00
/**
* ActivityPub Debug Class
*
* @author Matthias Pfefferle
*/
class Debug {
/**
* Initialize the class, registering WordPress hooks
*/
public static function init() {
if ( WP_DEBUG_LOG ) {
2023-04-20 13:22:11 +00:00
\add_action( 'activitypub_safe_remote_post_response', array( self::class, 'log_remote_post_responses' ), 10, 4 );
2024-08-17 18:17:47 +00:00
\add_action( 'activitypub_inbox', array( self::class, 'log_inbox' ), 10, 4 );
2019-09-27 08:12:59 +00:00
}
}
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
2019-09-27 08:12:59 +00:00
public static function log_remote_post_responses( $response, $url, $body, $user_id ) {
2022-12-02 17:23:56 +00:00
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r
2024-08-17 18:17:47 +00:00
\error_log( "[OUTBOX] Request to: {$url} with Response: " . \print_r( $response, true ) );
}
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
public static function log_inbox( $data, $user_id, $type, $activity ) {
$type = strtolower( $type );
if ( 'delete' !== $type ) {
$url = object_to_uri( $data['actor'] );
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r
\error_log( "[INBOX] Request From: {$url} with Activity: " . \print_r( $data, true ) );
}
2019-09-27 08:12:59 +00:00
}
public static function write_log( $log ) {
2024-08-16 08:46:11 +00:00
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r
\error_log( \print_r( $log, true ) );
2019-09-27 08:12:59 +00:00
}
}