Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions inc/class-blacklist-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,7 @@ public static function refresh_data() {
$args = array();
}

/* Output debug infos */
if ( defined( 'WP_DEBUG_LOG ' ) && WP_DEBUG_LOG ) {
error_log( 'Comment block list requested from GitHub' );
}
self::debug_log( 'Comment block list requested from GitHub' );

/* Start request */
$response = wp_remote_get(
Expand All @@ -123,26 +120,19 @@ public static function refresh_data() {

/* Exit on error */
if ( is_wp_error( $response ) ) {
if ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
error_log( 'Comment block list response error: ' . $response->get_error_message() );
}
self::debug_log( 'Comment block list response error: ' . $response->get_error_message() );

return;
}

/* Check response code */
if ( wp_remote_retrieve_response_code( $response ) !== 200 ) {
if ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
error_log( 'Comment block list is up to date' );
}
self::debug_log( 'Comment block list is up to date' );

return;
}

/* Output debug infos */
if ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
error_log( 'Comment block list successfully downloaded' );
}
self::debug_log( 'Comment block list successfully downloaded' );

/* Update list of disallowed keys */
update_option(
Expand All @@ -152,10 +142,7 @@ public static function refresh_data() {
wp_remote_retrieve_body( $response )
);

/* Output debug infos */
if ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
error_log( 'Comment block list successfully updated' );
}
self::debug_log( 'Comment block list successfully updated' );

/* Get & validate Etag */
$etag = preg_replace(
Expand Down Expand Up @@ -214,4 +201,16 @@ public static function plugin_meta( $input, $file ) {
)
);
}

/**
* Log error message, if WP_DEBUG is enabled.
*
* @param string $message Error message.
*/
private static function debug_log( $message ) {
if ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
error_log( $message );
}
}
}
Loading