/** * Generate a child theme. * * @since 1.1.0 */ public function generate() { global $wp_filesystem; WP_Filesystem(); $parent = wp_get_theme($this->template); if (!$parent->exists()) { return new WP_Error('invalid_template', esc_html__('Invalid parent theme slug.', 'audiotheme-agent')); } $parts = explode('/', $parent->get_template()); $slug = sprintf('%s-child', reset($parts)); $directory = path_join($parent->get_theme_root(), $slug); if ($wp_filesystem->exists($directory)) { return new WP_Error('directory_exists', esc_html__('Child theme directory already exists.', 'audiotheme-agent')); } if (false === $wp_filesystem->mkdir($directory)) { return new WP_Error('fs_error', esc_html__('Could not create child theme directory.', 'audiotheme-agent')); } $source = audiotheme_agent()->get_path('data/child-theme/'); copy_dir($source, $directory); if ($parent->get_screenshot()) { $wp_filesystem->copy(path_join($parent->get_template_directory(), $parent->get_screenshot('relative')), path_join($directory, $parent->get_screenshot('relative'))); } $data = array('{{author}}' => wp_get_current_user()->display_name, '{{author_url}}' => wp_get_current_user()->user_url, '{{name}}' => $parent->get('Name'), '{{slug}}' => $parent->get_template(), '{{url}}' => esc_url(home_url())); $files = array('functions.php', 'style.css'); foreach ($files as $file) { $filename = path_join($directory, $file); $contents = $wp_filesystem->get_contents($filename); $contents = str_replace(array_keys($data), array_values($data), $contents); $wp_filesystem->put_contents($filename, $contents); } return true; }
public function setUp() { parent::setUp(); $this->theme_root = AUDIOTHEME_AGENT_TESTS_DIR . '/data/themes'; $this->original_stylesheet = get_stylesheet(); $this->original_theme_directories = $GLOBALS['wp_theme_directories']; // /themes is necessary as theme.php functions assume /themes is the root if there is only one root. $GLOBALS['wp_theme_directories'] = array(WP_CONTENT_DIR . '/themes', $this->theme_root); add_filter('theme_root', array($this, '_theme_root')); add_filter('stylesheet_root', array($this, '_theme_root')); add_filter('template_root', array($this, '_theme_root')); $this->plugin = audiotheme_agent(); }
* Retrieve the main plugin instance. * * @since 1.0.0 * * @return AudioTheme_Agent_Plugin */ function audiotheme_agent() { static $instance; if (null === $instance) { $upload_dir = wp_upload_dir(); $filename = path_join($upload_dir['basedir'], 'audiotheme/logs/agent.log'); $client = new AudioTheme_Agent_Client(); $logger = new AudioTheme_Agent_Logger($filename); $packages = new AudioTheme_Agent_PackageManager($client); $instance = new AudioTheme_Agent_Plugin($client, $packages); $instance->set_logger($logger); } return $instance; } $audiotheme_agent = audiotheme_agent()->set_basename(plugin_basename(__FILE__))->set_directory(plugin_dir_path(__FILE__))->set_file(__FILE__)->set_slug('audiotheme-agent')->set_url(plugin_dir_url(__FILE__))->register_hooks(new AudioTheme_Agent_Provider_Setup())->register_hooks(new AudioTheme_Agent_Provider_UpdateManager()); if (is_admin()) { $audiotheme_agent->register_hooks(new AudioTheme_Agent_Provider_I18n())->register_hooks(new AudioTheme_Agent_Provider_AJAX())->register_hooks(new AudioTheme_Agent_Screen_Main_Subscriptions())->register_hooks(new AudioTheme_Agent_Screen_Main_Support())->register_hooks(new AudioTheme_Agent_Provider_AudioThemeCompatibility()); if (defined('WP_DEBUG') && WP_DEBUG) { $audiotheme_agent->register_hooks(new AudioTheme_Agent_Screen_Main_Logs()); } } /** * Load the plugin. */ add_action('plugins_loaded', array($audiotheme_agent, 'load_plugin'));