Include Template Based on User IP Address

template_include is a filter – it takes one argument and it should always return a value (a template to include).

Your function doesn’t do that. It doesn’t take any arguments and it returns value only if the condition is true – so if it’s not, it returns no value, so no template will be included in such case.

Here’s the fix:

add_action('template_include', 'restrict_user_access');
function restrict_user_access( $template ) {
    $ipAddress = $_SERVER['REMOTE_ADDR'];

        if($ipAddress === 'XX.XX.XXX.XXX') {
            return "home/www/html/blog/wp-content/themes/theme-child/restrictusers.php";
        }
    }

    return $template;
}

Another problem is that you should never use absolute paths in such filters. There are functions that will help you locate the template based on its file. So instead of this:

return "home/www/html/blog/wp-content/themes/theme-child/restrictusers.php";

You should do this:

$tpl = locate_template( array( 'restrictusers.php' ) );
if ( $tpl ) return $tpl;