Title: http_allowed_safe_ports
Published: February 3, 2022
Last modified: May 20, 2026

---

# apply_filters( ‘http_allowed_safe_ports’, int[] $allowed_ports, string $host, string $url )

## In this article

 * [Description](https://developer.wordpress.org/reference/hooks/http_allowed_safe_ports/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/hooks/http_allowed_safe_ports/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/http_allowed_safe_ports/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/http_allowed_safe_ports/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/http_allowed_safe_ports/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/http_allowed_safe_ports/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/http_allowed_safe_ports/?output_format=md#wp--skip-link--target)

Controls the list of ports considered safe in HTTP API.

## 󠀁[Description](https://developer.wordpress.org/reference/hooks/http_allowed_safe_ports/?output_format=md#description)󠁿

Allows to change and allow external requests for the HTTP request.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/http_allowed_safe_ports/?output_format=md#parameters)󠁿

 `$allowed_ports`int[]

Array of integers for valid ports. Default allowed ports are 80, 443, and 8080.

`$host`string

Host name of the requested URL.

`$url`string

Requested URL.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/http_allowed_safe_ports/?output_format=md#source)󠁿

    ```php
    $allowed_ports = apply_filters( 'http_allowed_safe_ports', array( 80, 443, 8080 ), $host, $url );
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/http.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/http.php#L639)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/http.php#L639-L639)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/http_allowed_safe_ports/?output_format=md#related)󠁿

| Used by | Description | 
| [wp_http_validate_url()](https://developer.wordpress.org/reference/functions/wp_http_validate_url/)`wp-includes/http.php` |

Validates a URL as safe for use in the HTTP API.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/http_allowed_safe_ports/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.9.0](https://developer.wordpress.org/reference/since/5.9.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/http_allowed_safe_ports/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/hooks/http_allowed_safe_ports/?output_format=md#comment-content-6654)
 2.   [jarmot](https://profiles.wordpress.org/jarmot/)  [  3 years ago  ](https://developer.wordpress.org/reference/hooks/http_allowed_safe_ports/#comment-6654)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fhttp_allowed_safe_ports%2F%23comment-6654)
    Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fhttp_allowed_safe_ports%2F%23comment-6654)
 4. By default, WordPress considers ports 80, 8080 and 443 as “safe”.
 5. Example code snippet of changing allowed ports to 80, 8080, 443 and 3000:
 6.     ```php
        add_filter( 'http_allowed_safe_ports', 'wpdocs_allowed_ports' );
    
        function wpdocs_allowed_ports( $ports ) {
            $ports = array( 80, 443, 8080, 3000 );
    
            return $ports;
        }
        ```
    
 7.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fhttp_allowed_safe_ports%2F%3Freplytocom%3D6654%23feedback-editor-6654)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fhttp_allowed_safe_ports%2F)
before being able to contribute a note or feedback.