Make WordPress Core

Opened 6 years ago

Closed 10 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:

Description

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

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

                        $local_ips = array(
                                '127.0.0.1', // 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
6 years ago

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

#2 @pento
6 years ago

  • Version trunk deleted

#3 @swissspidy
6 years ago

  • Keywords reporter-feedback added

#4 @bhubbard
6 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
6 years ago

  • Keywords reporter-feedback removed

#6 @swissspidy
10 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.