Make WordPress Core

Opened 4 years ago

Last modified 4 years ago

#45962 new enhancement

Is LocalHost Check?

Reported by: bhubbard's profile bhubbard Owned by:
Milestone: Awaiting Review 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 (5)

#1 @swissspidy
4 years ago

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

#2 @pento
4 years ago

  • Version trunk deleted

#3 @swissspidy
4 years ago

  • Keywords reporter-feedback added

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

  • Keywords reporter-feedback removed
Note: See TracTickets for help on using tickets.