Title: Theme Demo Import
Author: themely
Published: <strong>2016 年 10 月 28 日</strong>
Last modified: 2024 年 7 月 3 日

---

搜尋外掛

![](https://ps.w.org/theme-demo-import/assets/banner-772x250.png?rev=1523494)

這個外掛**並未在最新的 3 個 WordPress 主要版本上進行測試**。開發者可能不再對這個
外掛進行維護或提供技術支援，並可能會與更新版本的 WordPress 產生使用上的相容性問題。

![](https://ps.w.org/theme-demo-import/assets/icon-256x256.png?rev=1523494)

# Theme Demo Import

 由 [themely](https://profiles.wordpress.org/themely/) 開發

[下載](https://downloads.wordpress.org/plugin/theme-demo-import.zip)

 * [詳細資料](https://tw.wordpress.org/plugins/theme-demo-import/#description)
 * [使用者評論](https://tw.wordpress.org/plugins/theme-demo-import/#reviews)
 *  [安裝方式](https://tw.wordpress.org/plugins/theme-demo-import/#installation)
 * [開發資訊](https://tw.wordpress.org/plugins/theme-demo-import/#developers)

 [技術支援](https://wordpress.org/support/plugin/theme-demo-import/)

## 外掛說明

Quickly import demo content, widgets and settings for your new theme. This provides
a basic layout to build your website and speed up the development process.

This plugin will create a page in **APPEARANCE > Import Demo Content**.

If the theme you are using does not have any predefined import files, then you will
be presented with three file upload inputs.

First one is required and you will have to upload a demo content XML file, for the
actual demo import.

The second one is optional and will ask you for a WIE or JSON file for widgets import.
You create that file using the [Widget Importer & Exporter](https://wordpress.org/plugins/widget-importer-exporter/)
plugin.

The third one is also optional and will import the customizer settings, select the
DAT file which you can generate from [Customizer Export/Import](https://wordpress.org/plugins/customizer-export-import/)
plugin (the customizer settings will be imported only if the export file was created
from the same theme).

This plugin is based off the ‘One Click Demo Import’ plugin by @capuderg and @cyman,
https://github.com/proteusthemes/one-click-demo-import.

As well as the improved WP Import 2.0 plugin by @humanmade, https://github.com/humanmade/
WordPress-Importer.

### License

Theme Demo Import uses ‘One Click Demo Import’ plugin script
 https://github.com/
proteusthemes/one-click-demo-import (C) 2016 ProteusThemes.com Licensed under the
GNU General Public License v2.0, http://www.gnu.org/licenses/gpl-2.0.html

Theme Demo Import uses ‘WordPress Importer’ plugin script
 https://github.com/humanmade/
WordPress-Importer (C) 2016 @humanmade Licensed under the GNU General Public License
v2.0, http://www.gnu.org/licenses/gpl-2.0.html

### Copyright

Theme Demo Import, Copyright 2016 Ishmael ‘Hans’ Desjarlais

Theme Demo Import is distributed under the terms of the GNU GPL

This program is free software; you can redistribute it and/or modify
 it under the
terms of the GNU General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
 but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
 with this
program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
Fifth Floor, Boston, MA 02110-1301 USA.

## 安裝方式

**From your WordPress dashboard**

 1. Visit ‘Plugins > Add New’,
 2. Search for ‘Theme Demo Import’ and install the plugin.
 3. Activate ‘Theme Demo Import’ from your Plugins page.

Once the plugin is activated you will find the actual import page in **Appearance-
> Import Demo Content.**

## 常見問題集

### I have activated the plugin. Where is the “Import Demo Content” page?

You will find the import page in _wp-admin -> Appearance -> Import Demo Content_.

### Where are the demo import files and the log files saved?

The files used in the demo import will be saved to the default WordPress uploads
directory. An example of that directory would be: `../wp-content/uploads/2016/03/`.

The log file will also be registered in the _wp-admin -> Media_ section, so you 
can access it easily.

### How to predefine demo imports?

This question is for theme authors. To predefine demo imports, you just have to 
add the following code structure, with your own values to your theme (using the `
theme-demo-import/import_files` filter):

    ```
    function TDI_import_files() {
        return array(
            array(
                'import_file_name'           => 'Demo Import 1',
                'import_file_url'            => 'http://www.your_domain.com/tdi/demo-content.xml',
                'import_widget_file_url'     => 'http://www.your_domain.com/tdi/widgets.json',
                'import_customizer_file_url' => 'http://www.your_domain.com/tdi/customizer.dat',
                'import_preview_image_url'   => 'http://www.your_domain.com/tdi/preview_import_image1.jpg',
                'import_notice'              => __( 'After you import this demo, you will have to setup the slider separately.', 'your-textdomain' ),
            ),
            array(
                'import_file_name'           => 'Demo Import 2',
                'import_file_url'            => 'http://www.your_domain.com/tdi/demo-content2.xml',
                'import_widget_file_url'     => 'http://www.your_domain.com/tdi/widgets2.json',
                'import_customizer_file_url' => 'http://www.your_domain.com/tdi/customizer2.dat',
                'import_preview_image_url'   => 'http://www.your_domain.com/tdi/preview_import_image2.jpg',
                'import_notice'              => __( 'A special note for this import.', 'your-textdomain' ),
            ),
        );
    }
    add_filter( 'theme-demo-import/import_files', 'TDI_import_files' );
    ```

You can set content import, widgets, and customizer import files. You can also define
a preview image, which will be used only when multiple demo imports are defined,
so that the user will see the difference between imports.

### How to automatically assign “Front page”, “Posts page” and menu locations after the importer is done?

You can do that, with the `theme-demo-import/after_import` action hook. The code
would look something like this:

    ```
    function TDI_after_import_setup() {
        // Assign menus to their locations.
        $main_menu = get_term_by( 'name', 'Top Menu', 'nav_menu' );

        set_theme_mod( 'nav_menu_locations', array(
                'primary-menu' => $main_menu->term_id,
            )
        );

        // Assign front page and posts page (blog page).
        $front_page_id = get_page_by_title( 'Home' );
        $blog_page_id  = get_page_by_title( 'Blog' );

        update_option( 'show_on_front', 'page' );
        update_option( 'page_on_front', $front_page_id->ID );
        update_option( 'page_for_posts', $blog_page_id->ID );

    }
    add_action( 'theme-demo-import/after_import', 'TDI_after_import_setup' );
    ```

### What about using local import files (from theme folder)?

You have to use the same filter as in above example, but with a slightly different
array keys: `local_*`. The values have to be absolute paths (not URLs) to your import
files. To use local import files, that reside in your theme folder, please use the
below code. Note: make sure your import files are readable!

    ```
    function TDI_import_files() {
        return array(
            array(
                'import_file_name'             => 'Demo Import 1',
                'local_import_file'            => trailingslashit( get_template_directory() ) . 'tdi/demo-content.xml',
                'local_import_widget_file'     => trailingslashit( get_template_directory() ) . 'tdi/widgets.json',
                'local_import_customizer_file' => trailingslashit( get_template_directory() ) . 'tdi/customizer.dat',
                'import_preview_image_url'     => 'http://www.your_domain.com/tdi/preview_import_image1.jpg',
                'import_notice'                => __( 'After you import this demo, you will have to setup the slider separately.', 'your-textdomain' ),
            ),
            array(
                'import_file_name'             => 'Demo Import 2',
                'local_import_file'            => trailingslashit( get_template_directory() ) . 'tdi/demo-content2.xml',
                'local_import_widget_file'     => trailingslashit( get_template_directory() ) . 'tdi/widgets2.json',
                'local_import_customizer_file' => trailingslashit( get_template_directory() ) . 'tdi/customizer2.dat',
                'import_preview_image_url'     => 'http://www.your_domain.com/tdi/preview_import_image2.jpg',
                'import_notice'                => __( 'A special note for this import.', 'your-textdomain' ),
            ),
        );
    }
    add_filter( 'theme-demo-import/import_files', 'TDI_import_files' );
    ```

### How to handle different “after import setups” depending on which predefined import was selected?

This question might be asked by a theme author wanting to implement different after
import setups for multiple predefined demo imports. Lets say we have predefined 
two demo imports with the following names: ‘Demo Import 1’ and ‘Demo Import 2’, 
the code for after import setup would be (using the `theme-demo-import/after_import`
filter):

    ```
    function TDI_after_import( $selected_import ) {
        echo "This will be displayed on all after imports!";

        if ( 'Demo Import 1' === $selected_import['import_file_name'] ) {
            echo "This will be displayed only on after import if user selects Demo Import 1";

            // Set logo in customizer
            set_theme_mod( 'logo_img', get_template_directory_uri() . '/assets/images/logo1.png' );
        }
        elseif ( 'Demo Import 2' === $selected_import['import_file_name'] ) {
            echo "This will be displayed only on after import if user selects Demo Import 2";

            // Set logo in customizer
            set_theme_mod( 'logo_img', get_template_directory_uri() . '/assets/images/logo2.png' );
        }
    }
    add_action( 'theme-demo-import/after_import', 'TDI_after_import' );
    ```

### Can I add some code before the widgets get imported?

Of course you can, use the `theme-demo-import/before_widgets_import` action. You
can also target different predefined demo imports like in the example above. Here
is a simple example code of the `theme-demo-import/before_widgets_import` action:

    ```
    function TDI_before_widgets_import( $selected_import ) {
        echo "Add your code here that will be executed before the widgets get imported!";
    }
    add_action( 'theme-demo-import/before_widgets_import', 'TDI_before_widgets_import' );
    ```

### I’m a theme author and I want to change the plugin intro text, how can I do that?

You can change the plugin intro text by using the `theme-demo-import/plugin_intro_text`
filter:

    ```
    function TDI_plugin_intro_text( $default_text ) {
        $default_text .= '<div class="TDI__intro-text">This is a custom text added to this plugin intro text.</div>';

        return $default_text;
    }
    add_filter( 'theme-demo-import/plugin_intro_text', 'TDI_plugin_intro_text' );
    ```

To add some text in a separate “box”, you should wrap your text in a div with a 
class of ‘TDI__intro-text’, like in the code example above.

### How to disable generation of smaller images (thumbnails) during the content import

This will greatly improve the time needed to import the content (images), but only
the original sized images will be imported. You can disable it with a filter, so
just add this code to your theme function.php file:

    ```
    add_filter( 'theme-demo-import/regenerate_thumbnails_in_content_import', '__return_false' );
    ```

### How to change the location, title and other parameters of the plugin page?

As a theme author you do not like the location of the “Import Demo Content” plugin
page in _Appearance -> Import Demo Content_? You can change that with the filter
below. Apart from the location, you can also change the title or the page/menu and
some other parameters as well.

    ```
    function TDI_plugin_page_setup( $default_settings ) {
        $default_settings['parent_slug'] = 'themes.php';
        $default_settings['page_title']  = esc_html__( 'Theme Demo Import' , 'theme-demo-import' );
        $default_settings['menu_title']  = esc_html__( 'Import Demo Content' , 'theme-demo-import' );
        $default_settings['capability']  = 'import';
        $default_settings['menu_slug']   = 'theme-demo-import';

        return $default_settings;
    }
    add_filter( 'theme-demo-import/plugin_page_setup', 'TDI_plugin_page_setup' );
    ```

### I can’t activate the plugin, because of a fatal error, what can I do?

_Update: There is now a admin error notice, stating that the minimal PHP version
required for this plugin is 5.3.2._

You want to activate the plugin, but this error shows up:

_Plugin could not be activated because it triggered a fatal error_

This happens, because your hosting server is using a very old version of PHP. This
plugin requires PHP version of at least **5.3.x**, but we recommend version _5.6.
x_. Please contact your hosting company and ask them to update the PHP version for
your site.

## 使用者評論

![](https://secure.gravatar.com/avatar/89a977ff73672fe9ff9259d9c699797f42c29112a7ad500f60e330ecfbc5af4d?
s=60&d=retro&r=g)

### 󠀁[Elementor Page Layout Broken After Import](https://wordpress.org/support/topic/elementor-page-layout-broken-after-import/)󠁿

 [Anonymous User](https://profiles.wordpress.org/anonymized-23164375/) 2025 年 4
月 10 日

When I imported my Elementor-based site data, it inserted all the JSON code into
the Text Editor widget. As a result, the page doesn’t appear the same as it did 
in the XML file.

![](https://secure.gravatar.com/avatar/eeb7ea6f439bfc9fc4ad60178cbb342b23687095d4d79faa400c775ef85d7d1d?
s=60&d=retro&r=g)

### 󠀁[Site crashed after install](https://wordpress.org/support/topic/site-crashed-after-install-2/)󠁿

 [josflachs](https://profiles.wordpress.org/josflachs/) 2023 年 8 月 20 日

I installed the plugin, the site crashed immediately. Error message:Warning: The
magic method Theme_Demo_Import::__wakeup() must have public visibility in /yyy/zzz/
Local Sites/mega/app/public/wp-content/plugins/theme-demo-import/inc/class-tdi-main.
php on line 74 Fatal error: Cannot redeclare get_cli_args() (previously declared
in /home/jos/Local Sites/mega/app/public/wp-admin/includes/class-wp-importer.php:
276) in /yyy/zzz/Local Sites/mega/app/public/wp-admin/includes/class-wp-importer.
php on line 326

![](https://secure.gravatar.com/avatar/fbb4301cf05de13ec063bf62a7854d40a6bade2aaf08085d72890bb5f333d295?
s=60&d=retro&r=g)

### 󠀁[Perfect](https://wordpress.org/support/topic/perfect-9807/)󠁿

 [wowthemesnet](https://profiles.wordpress.org/wowthemesnet/) 2023 年 3 月 10 日

Simple and perfect. It does what it says drama free.

![](https://secure.gravatar.com/avatar/0fbdd5b2991dfe4d32c8d9ef9ef289991f292b63eba710f3385e6e7771a77950?
s=60&d=retro&r=g)

### 󠀁[Works great](https://wordpress.org/support/topic/works-great-3270/)󠁿

 [themely](https://profiles.wordpress.org/themely/) 2016 年 11 月 2 日

We’ve tested this plugin extensively and packaged it with our themes, it works flawlessly.

 [ 閱讀全部 4 則使用者評論 ](https://wordpress.org/support/plugin/theme-demo-import/reviews/)

## 參與者及開發者

以下人員參與了開源軟體〈Theme Demo Import〉的開發相關工作。

參與者

 *   [ themely ](https://profiles.wordpress.org/themely/)

〈Theme Demo Import〉外掛目前已有 1 個本地化語言版本。 感謝[全部譯者](https://translate.wordpress.org/projects/wp-plugins/theme-demo-import/contributors)
為這個外掛做出的貢獻。

[將〈Theme Demo Import〉外掛本地化為台灣繁體中文版](https://translate.wordpress.org/projects/wp-plugins/theme-demo-import)

### 對開發相關資訊感興趣？

任何人均可[瀏覽程式碼](https://plugins.trac.wordpress.org/browser/theme-demo-import/)、
查看 [SVN 存放庫](https://plugins.svn.wordpress.org/theme-demo-import/)，或透過 
[RSS](https://plugins.trac.wordpress.org/log/theme-demo-import/?limit=100&mode=stop_on_copy&format=rss)
訂閱[開發記錄](https://plugins.trac.wordpress.org/log/theme-demo-import/)。

## 變更記錄

**1.1.1 – November 2nd, 2022**

 * SECURITY FIX: Prevent uploading PHP files

**1.0.5 – March 29, 2019**

 * Removed extra $ on line 72 of class-tdi-helpers.php which was triggering a PHP
   7.0+ error

**1.0.2 – 10/25/2016**

 * Removed dependencies on 3rd party plugin
 * Renamed classes for HM files
 * Added license and copyright information to readme.txt file
 * Updated the plugin description

**1.0.1 – 10/15/2016**

 * Updated text strings
 * Updated styles (UI)
 * Removed unnecessary code

**1.0.0 – 10/10/2016**

 * INITIAL RELEASE

**1.1.2 – 06/24/2024**

 * Added stricter accept attributes in file upload inputs in /inc/class-tdi-main.
   php (lines 155, 160 and 165)
 * Added pattern attribute to file upload inputs in /inc/class-tdi-main.php (lines
   155, 160 and 165)

**1.1.3 – 07/3/2024**
 – Security: Improved file upload validation for widget imports.–
Security: Added server-side checks for file types, MIME types, and file sizes. –
Enhancement: Improved error handling and logging in AJAX file uploads. – Enhancement:
Added more detailed console logging for easier debugging. – Performance: Optimized
AJAX handling for smoother file uploads.

## 中繼資料

 *  版本 **1.1.3**
 *  最後更新 **2 年前**
 *  啟用安裝數 **5,000+**
 *  WordPress 版本需求 ** 4.7 或更新版本 **
 *  已測試相容的 WordPress 版本 **6.5.8**
 *  PHP 版本需求 ** 5.6 或更新版本 **
 *  語言
 * [Dutch](https://nl.wordpress.org/plugins/theme-demo-import/) 及 [English (US)](https://wordpress.org/plugins/theme-demo-import/).
 *  [將這個外掛本地化為你的母語版本](https://translate.wordpress.org/projects/wp-plugins/theme-demo-import)
 * 標籤:
 * [content](https://tw.wordpress.org/plugins/tags/content/)[data](https://tw.wordpress.org/plugins/tags/data/)
   [demo](https://tw.wordpress.org/plugins/tags/demo/)[import](https://tw.wordpress.org/plugins/tags/import/)
   [widgets](https://tw.wordpress.org/plugins/tags/widgets/)
 *  [進階檢視](https://tw.wordpress.org/plugins/theme-demo-import/advanced/)

## 評分

 3 星，滿分為 5 星

 *  [  2 個 5 星使用者評論     ](https://wordpress.org/support/plugin/theme-demo-import/reviews/?filter=5)
 *  [  0 個 4 星使用者評論     ](https://wordpress.org/support/plugin/theme-demo-import/reviews/?filter=4)
 *  [  0 個 3 星使用者評論     ](https://wordpress.org/support/plugin/theme-demo-import/reviews/?filter=3)
 *  [  0 個 2 星使用者評論     ](https://wordpress.org/support/plugin/theme-demo-import/reviews/?filter=2)
 *  [  2 個 1 星使用者評論     ](https://wordpress.org/support/plugin/theme-demo-import/reviews/?filter=1)

[Your review](https://wordpress.org/support/plugin/theme-demo-import/reviews/#new-post)

[查看全部使用者評論](https://wordpress.org/support/plugin/theme-demo-import/reviews/)

## 參與者

 *   [ themely ](https://profiles.wordpress.org/themely/)

## 技術支援

使用者可在技術支援論壇提出意見反應或使用問題。

 [檢視技術支援論壇](https://wordpress.org/support/plugin/theme-demo-import/)