Ejemplo n.º 1
0
function builder_create_child_theme($args = array())
{
    $default_args = array('child_directory' => false, 'overwrite_existing' => false, 'name' => false, 'source_directory' => get_template_directory(), 'source_type' => 'parent', 'parent_directory' => get_template_directory());
    extract(ITUtility::merge_defaults($args, $default_args));
    if (empty($name)) {
        $name = sprintf(__('%s - Custom', 'it-l10n-Builder-Paige'), $themes[basename($parent_directory)]->get('Name'));
    }
    $name = preg_replace('/^\\s+/', '', $name);
    $name = preg_replace('/\\s+$/', '', $name);
    $themes = wp_get_themes();
    $names = array();
    foreach ($themes as $theme) {
        $names[] = $theme->get('Name');
    }
    if (in_array($name, $names)) {
        $count = 2;
        while (in_array("{$name} {$count}", $names)) {
            $count++;
        }
        $name = "{$name} {$count}";
    }
    if (empty($child_directory)) {
        $child_directory = preg_replace('/[^a-z0-9]+/i', '-', ucfirst($name));
        if (!preg_match('/^builder/i', $child_directory)) {
            $child_directory = "Builder-{$child_directory}";
        }
        $child_directory = dirname($parent_directory) . "/{$child_directory}";
    }
    if (is_dir($child_directory) && !$overwrite_existing) {
        $count = 2;
        while (is_dir("{$child_directory}-{$count}")) {
            $count++;
        }
        $child_directory .= "-{$count}";
    }
    it_classes_load('it-file-utility.php');
    if ('copy' == $source_type) {
        ITFileUtility::copy($source_directory, $child_directory, array('folder_mode' => 0775, 'file_mode' => 0664));
        $stylesheet = file_get_contents("{$child_directory}/style.css");
        $stylesheet = preg_replace('/(Theme Name:\\s*).*/i', "\$1{$name}", $stylesheet);
        file_put_contents("{$child_directory}/style.css", $stylesheet);
    } else {
        ITFileUtility::mkdir($child_directory, array('create_index' => false));
        $files = array('style.css' => '', 'style-mobile.css' => '', 'style-tablet.css' => '', 'style-responsive.css' => '', 'rtl.css' => '', 'functions-child.php' => 'functions.php', 'screenshot.png' => '', 'screenshot.jpg' => '', 'screenshot.gif' => '', 'images' => '', 'lang' => '', 'plugin-features' => '');
        $files = apply_filters('builder-filter-files-to-copy-to-child', $files);
        $stylesheet_data_headers = array('name' => 'Theme Name', 'theme_uri' => 'Theme URI', 'description' => 'Description', 'author' => 'Author', 'author_uri' => 'Author URI', 'version' => 'Version', 'license' => 'License', 'license_uri' => 'License URI', 'tags' => 'Tags', 'text_domain' => 'Text Domain', 'domain_path' => 'Domain Path', 'template' => 'Template');
        $stylesheet_data = get_file_data("{$parent_directory}/style.css", $stylesheet_data_headers);
        $stylesheet_data['description'] = sprintf(__('This is a generated child theme for the %1$s theme. You should activate and modify this theme instead of %1$s. Doing so allows you to modify this child theme while allowing automatic upgrades for %1$s.', 'it-l10n-Builder-Paige'), $stylesheet_data['name']);
        $stylesheet_data['name'] = $name;
        $stylesheet_data['template'] = basename($parent_directory);
        $child_header = "/*\n";
        foreach ($stylesheet_data_headers as $index => $header) {
            $child_header .= "{$header}: {$stylesheet_data[$index]}\n";
        }
        $child_header .= '*/';
        if (isset($files['style.css'])) {
            $stylesheet = file_get_contents("{$parent_directory}/style.css");
            $stylesheet = preg_replace('|/\\*.*Theme Name:.*?\\*/|si', $child_header, $stylesheet);
        } else {
            $stylesheet = "{$child_header}\n\n\n@import url('../" . basename($parent_directory) . "/style.css');";
        }
        file_put_contents("{$child_directory}/style.css", $stylesheet);
        foreach ($files as $source => $destination) {
            if ('style.css' == $source) {
                continue;
            }
            if (!file_exists("{$parent_directory}/{$source}")) {
                continue;
            }
            if (empty($destination)) {
                $destination = $source;
            }
            ITFileUtility::copy("{$parent_directory}/{$source}", "{$child_directory}/{$destination}", array('folder_mode' => 0775, 'file_mode' => 0664));
        }
    }
    add_option('builder_manually_switched_theme', true);
    switch_theme(basename($child_directory));
}
Ejemplo n.º 2
0
 function _load_path_info()
 {
     $old_cache_base_path = '';
     //			delete_option( $this->_args['option_name'] );
     $path_info = $this->_get_path_info();
     if (!empty($path_info['path'])) {
         if (is_writable($path_info['path'])) {
             $path_info['url'] = ITUtility::get_url_from_file($path_info['path']);
             $this->_path = $path_info['path'];
             $this->_url = $path_info['url'];
             $this->_versions = $path_info['versions'];
             $this->_empty_types = $path_info['empty_types'];
             return;
         }
         if (is_dir($path_info['path'])) {
             $old_cache_path = $path_info['path'];
         }
     }
     it_classes_load('it-file-utility.php');
     $path_info = ITFileUtility::get_writable_uploads_directory('it-file-cache/' . $this->_args['base_path']);
     if (false === $path_info) {
         $this->_file_cache_enabled = false;
         return;
     }
     $path_info['versions'] = array();
     $path_info['empty_types'] = array();
     $this->_update_path_info($path_info);
     if (!empty($old_cache_base_path) && is_dir($old_cache_base_path)) {
         ITFileUtility::copy($old_cache_base_path . '/*', $this->_path);
     }
 }