wordpress-activitypub/includes/class-debug.php

34 lines
1 KiB
PHP
Raw Normal View History

2019-09-27 10:12:59 +02:00
<?php
namespace Activitypub;
/**
* ActivityPub Debug Class
*
* @author Matthias Pfefferle
*/
class Debug {
/**
* Initialize the class, registering WordPress hooks
*/
public static function init() {
2020-04-28 10:03:35 +02:00
if ( WP_DEBUG && WP_DEBUG_LOG ) {
2019-09-27 10:12:59 +02:00
\add_action( 'activitypub_safe_remote_post_response', array( '\Activitypub\Debug', 'log_remote_post_responses' ), 10, 4 );
}
}
public static function log_remote_post_responses( $response, $url, $body, $user_id ) {
2022-12-02 18:23:56 +01:00
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r
2019-09-28 14:17:58 +02:00
\error_log( "Request to: {$url} with response: " . \print_r( $response, true ) );
2019-09-27 10:12:59 +02:00
}
public static function write_log( $log ) {
if ( \is_array( $log ) || \is_object( $log ) ) {
2022-12-02 18:23:56 +01:00
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log, WordPress.PHP.DevelopmentFunctions.error_log_print_r
2019-09-27 10:12:59 +02:00
\error_log( \print_r( $log, true ) );
} else {
2022-12-02 18:23:56 +01:00
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
2019-09-27 10:12:59 +02:00
\error_log( $log );
}
}
}