Example #1
0
/**
 * Get the path to the sample content file
 *
 * @return string
 * @since 2.3.7
 */
function themify_get_sample_content_file()
{
    $resource_file = get_template_directory() . '/sample/sample-content.zip';
    $cache_dir = themify_get_cache_dir();
    $extract_file = $cache_dir['path'] . 'sample-content.xml';
    if (!file_exists($resource_file)) {
        // fallback
        $resource_file = get_template_directory() . '/sample/sample-content.gz';
        themify_uncompress_gzip($resource_file, $extract_file);
    } else {
        WP_Filesystem();
        if (1 == unzip_file($resource_file, $extract_file)) {
            $extract_file = $cache_dir['path'] . 'sample-content.xml/sample-content.xml';
        }
    }
    $parse_file = file_exists($extract_file) ? $extract_file : $resource_file;
    return $parse_file;
}
/**
 * Performs importing the sample contents to replicate the theme's demo site
 *
 * @since 1.7.6
 */
function themify_do_import_sample_contents()
{
    do_action('themify_before_demo_import');
    themify_import_sample_content_setup();
    $resource_file = get_template_directory() . '/sample/sample-content.gz';
    $cache_dir = themify_get_cache_dir();
    $extract_file = $cache_dir['path'] . 'sample-content.xml';
    themify_uncompress_gzip($resource_file, $extract_file);
    $parse_file = file_exists($extract_file) ? $extract_file : $resource_file;
    $import = new Themify_Import();
    $import->fetch_attachments = true;
    $import->import($parse_file);
    // remove extract file
    if (file_exists($extract_file)) {
        unlink($extract_file);
    }
    if (file_exists(THEME_DIR . '/sample/demo-settings.php')) {
        require_once THEME_DIR . '/sample/demo-settings.php';
    }
    do_action('themify_after_demo_import');
}