Airplane_Mode_Core::block_script_load PHP Method

block_script_load() public method

Check the URL of a JS file and remove any that are not on the local URL.
public block_script_load ( string $source ) : string
$source string The source URL of the JS file.
return string $source The same URL, or null.
        public function block_script_load($source)
        {
            // Bail if disabled.
            if (!$this->enabled()) {
                return $source;
            }
            // Parse the URL being passed to pull out the host.
            $parsed = parse_url($source, PHP_URL_HOST);
            // First run the filter to allow a source host to get through.
            if (false === apply_filters('airplane_mode_parse_script', true, $parsed)) {
                return $source;
            }
            // If we don't share the same URL as the site itself, return null. Otherwise return the URL.
            return isset($parsed) && false === strpos(home_url(), $parsed) ? new Airplane_Mode_WP_Error('airplane_mode_enabled', __('Airplane Mode blocked script', 'airplane-mode'), array('return' => '', 'src' => $source)) : $source;
        }