isDir() && !$fileInfo->isDot()) { if (is_child_theme() && file_exists(get_stylesheet_directory() . '/data/' . $fileInfo->getFilename())) { $demos[$fileInfo->getFilename()] = array( 'dir' => get_stylesheet_directory() . '/data/' . $fileInfo->getFilename(), 'uri' => get_stylesheet_directory_uri() . '/data/' . $fileInfo->getFilename(), ); } else { if (!isset($demos[$fileInfo->getFilename()]) && file_exists(get_template_directory() . '/data/' . $fileInfo->getFilename())) { $demos[$fileInfo->getFilename()] = array( 'dir' => get_template_directory() . '/data/' . $fileInfo->getFilename(), 'uri' => get_template_directory_uri() . '/data/' . $fileInfo->getFilename(), ); } } } } } foreach ($demos as $name => $dir) { $content = $dir['dir'] . '/content.xml'; $redux = $dir['dir'] . '/configuration.json'; if (file_exists($content) || file_exists($redux)) { $theme = wp_get_theme(); $preview_image_url = $theme->get_screenshot(); if (file_exists($dir['dir'] . '/preview.jpg')) { $preview_image_url = $dir['uri'] . '/preview.jpg'; } $demo = array( 'import_file_name' => $name, 'import_preview_image_url' => $preview_image_url, ); if (file_exists($content)) { $demo['local_import_file'] = $content; } if (file_exists($redux)) { $demo['local_import_redux'] = array( array( 'file_path' => $redux, 'option_name' => AZEXO_FRAMEWORK, ), ); } $widgets = $dir['dir'] . '/widgets.json'; if (file_exists($widgets)) { $demo['local_import_widget_file'] = $content; } $import_files[] = $demo; } } } return $import_files; } add_action('pt-ocdi/before_content_import_execution', 'azexo_ocdi_before_import', 10, 3); function azexo_ocdi_before_import($import_files, $predefined_import_files, $predefined_index) { $demo = $predefined_import_files[$predefined_index]; if (isset($demo['options_url'])) { $response = wp_remote_get($demo['options_url']); if (is_array($response)) { $options = json_decode($response['body'], true); if (is_array($options)) { foreach ($options as $name => $option) { update_option($name, $option); } } } } } function azexo_ocdi_set_sidebar_azh_widget($widget_url, $sidebar) { $response = wp_remote_get($widget_url); if (is_array($response)) { $html = azh_uri_replace($response['body']); $azh_wxr_importer_url_remap = get_option('azh_wxr_importer_url_remap', array()); $html = str_replace(array_keys($azh_wxr_importer_url_remap), $azh_wxr_importer_url_remap, $html); if (!preg_match('/ data-section=[\'"]([^\'"]+)[\'"]/i', $html)) { $html = '
' . $html . '
'; } $parts = parse_url($widget_url); $post_id = azexo_create_azh_widget(str_replace('.html', '', basename($parts["path"])), $html); if ($post_id) { $sidebars = get_option('sidebars_widgets'); if (!$sidebars) { $sidebars = array(); } $sidebars[$sidebar] = array(); update_option('sidebars_widgets', $sidebars); azexo_pre_set_widget($sidebar, 'azh_widget', array('post' => $post_id)); return true; } } return false; } add_action('pt-ocdi/after_all_import_execution', 'azexo_ocdi_after_import', 10, 3); function azexo_ocdi_after_import($import_files, $predefined_import_files, $predefined_index) { $demo = $predefined_import_files[$predefined_index]; $header_footer = false; if (isset($demo['header_url'])) { if (azexo_ocdi_set_sidebar_azh_widget($demo['header_url'], 'header_sidebar')) { $header_footer = true; } } if (isset($demo['canvas_header_url'])) { if (azexo_ocdi_set_sidebar_azh_widget($demo['canvas_header_url'], 'azh_header')) { $header_footer = true; } } if (isset($demo['footer_url'])) { if (azexo_ocdi_set_sidebar_azh_widget($demo['footer_url'], 'footer_sidebar')) { $header_footer = true; } } if (isset($demo['canvas_footer_url'])) { if (azexo_ocdi_set_sidebar_azh_widget($demo['canvas_footer_url'], 'azh_footer')) { $header_footer = true; } } if ($header_footer) { $options = get_option(AZEXO_FRAMEWORK); $options['header'] = array(); $options['show_page_title'] = false; update_option(AZEXO_FRAMEWORK, $options); update_option('azexo_header_footer_installed', true); } $home = get_page_by_title('Home'); if (is_object($home)) { update_option('show_on_front', 'page'); update_option('page_on_front', $home->ID); } $blog = null; foreach (array('Blog', 'News', 'Journal') as $title) { $blog = get_page_by_title($title); if (is_object($blog)) { break; } } if (is_object($blog)) { update_option('show_on_front', 'page'); update_option('page_for_posts', $blog->ID); } }