jrobinsonc
1/2/2017 - 6:07 PM

WordPress Development Assets

WordPress Development Assets

<?php

if ($_SERVER['HTTP_HOST'] === 'localhost')
    require get_template_directory() . '/inc/development-assets.php';
    
<?php

class DevelopmentAssets
{
    public function __construct()
    {
        $tags = array(
            // 'upload_dir',
            // 'plugins_url',
            // 'bloginfo',
            // 'stylesheet_directory_uri',
            // 'template_directory_uri',
            // 'script_loader_src',
            'style_loader_src'
        );

        foreach ($tags as $tag)
            add_filter($tag, array($this, 'clean_urls'));
    }

    public function clean_urls($content)
    {
        if (is_array($content))
        {
            var_dump($content);exit;
        }
        else
        {
            $url_info = parse_url($content);

            if (! in_array($url_info['host'], array('localhost')))
            {
                $content = str_replace($url_info['host'], "local.{$url_info['host']}", $content);
            }

            return $content;
        }
    }
}

new DevelopmentAssets;