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

Controls the list of ports considered safe in HTTP API.

Description

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

Parameters

$allowed_portsint[]
Array of integers for valid ports.
$hoststring
Host name of the requested URL.
$urlstring
Requested URL.

Source

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

Changelog

VersionDescription
5.9.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    By default, WordPress considers ports 80, 8080 and 443 as “safe”.

    Example code snippet of changing allowed ports to 80, 8080, 443 and 3000:

    add_filter( 'http_allowed_safe_ports', 'wpdocs_allowed_ports' );
    
    function wpdocs_allowed_ports( $ports ) {
        $ports = array( 80, 443, 8080, 3000 );
    
        return $ports;
    }

You must log in before being able to contribute a note or feedback.