Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e3a9dd8

Browse files
committed
feat: simplify the code and use the flags for the method 'file' properly
1 parent 1319ad5 commit e3a9dd8

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

‎wp-http-blocklist.php‎

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,33 +42,24 @@ function pre_http_request( $flag, $parsed_args, $url ) {
4242

4343
$blocklist = [];
4444
if ( is_file( $blocklist_file ) && is_readable( $blocklist_file ) ) {
45-
$blocklist = file( $blocklist_file );
45+
$blocklist = file( $blocklist_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
4646
}
4747

48-
/**
49-
* Here we get the file values and they have a \n at the end.
50-
* Remove all useless caracters.
51-
*/
52-
$blocklist = array_map( 'trim', $blocklist );
53-
$blocklist = array_filter( $blocklist );
54-
5548
$blocklist = apply_filters( 'wp_http_blocklist', $blocklist );
56-
$blocklist = array_unique( $blocklist );
49+
$blocklist = array_unique( array_filter( array_map( 'trim', $blocklist ) ) );
5750

5851
if ( empty( $blocklist ) ) {
5952
return $flag;
6053
}
6154

62-
foreach ( $blocklist as $blocklist_domain ) {
63-
if ( $request_host === $blocklist_domain ) {
64-
// translators: First is the host blocked, second is the full url called
65-
$response = new \WP_Error( 'http_request_blocked', sprintf( __( 'Host %1$s is blocked from a deny list.', 'wp-http-blocklist' ), $request_host ) );
66-
/** This action is documented in wp-includes/class-http.php */
67-
do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url );
68-
69-
return $response;
70-
}
55+
if ( false === array_search( $request_host, $blocklist ) ) {
56+
return $flag;
7157
}
7258

73-
return $flag;
59+
// translators: First is the host blocked, second is the full url called
60+
$response = new \WP_Error( 'http_request_blocked', sprintf( __( 'Host %1$s is blocked from a deny list.', 'wp-http-blocklist' ), $request_host ) );
61+
/** This action is documented in wp-includes/class-http.php */
62+
do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url );
63+
64+
return $response;
7465
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /