Make WordPress Core

Opened 5 years ago

Closed 4 months ago

#45962 closed enhancement (wontfix)

Is LocalHost Check?

Reported by: bhubbard's profile bhubbard Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:


It would be useful if WordPress had its own function to check for localhost.

function wp_is_localhost() {
                        // Get remote IP.
                        $remote_ip = filter_input( INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP );

                        $local_ips = array(
                                '', // IPv4.
                                '::1',       // IPv6.

                        $local_ips = apply_filters( 'wp_localhost_ips', $local_ips );

                        return in_array( $remote_ip, $local_ips, true );

Change History (6)

#1 @swissspidy
5 years ago

Where in WordPress core itself could such a function be used? I don't see an immediate benefit here.

#2 @pento
5 years ago

  • Version trunk deleted

#3 @swissspidy
5 years ago

  • Keywords reporter-feedback added

#4 @bhubbard
5 years ago

I think having this would be useful to be part of the Health Check & Troubleshooting Plugin that is working its way into core. Many developers put checks in their plugins & themes to check when they are working locally, and display extra info or turn on debug mode for example. Devs & Hosting providers could also use it potentially to check for different setups when copying an install from one environment to another.

#5 @bhubbard
5 years ago

  • Keywords reporter-feedback removed

#6 @swissspidy
4 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

WordPress in the meantime added support for defining the environment type and setting development mode. I think this use case is covered by those.

Note: See TracTickets for help on using tickets.