| 开发者 | postmagthemes |
|---|---|
| 更新时间 | 2026年11月24日 12:40 |
| PHP版本: | 5.6 及以上 |
| WordPress版本: | 7.1 |
| 版权: | GPLv2 or later |
| 版权网址: | 版权信息 |
functions.php. Add it at the top level of the file, not inside your own after_setup_theme callback, otherwise the demo may not appear. Replace theme-text-domain with your theme's text domain.
add_filter( 'pt-pmdi/import_files', function ( $import_files ) {
$import_files[] = array(
'import_file_name' => esc_html__( 'My Theme Demo name', 'theme-text-domain' ),
'categories' => array( esc_html__( 'Blog', 'theme-text-domain' ) ),
'import_file_url' => esc_url( 'https://example.com/demo/content.xml' ),
'import_widget_file_url' => esc_url( 'https://example.com/demo/widgets.wie' ),
'import_customizer_file_url' => esc_url( 'https://example.com/demo/customizer.dat' ),
'import_preview_image_url' => esc_url( 'https://example.com/demo/screenshot.png' ),
'preview_url' => esc_url( 'https://example.com/demo/' ),
'import_notice' => esc_html__( 'Optional note shown before import.', 'theme-text-domain' ),
);
return $import_files;
} );
Step 2: Recommend the plugin to your users
Add the following code to your theme's functions.php to show your users a notice with a link to install PostmagThemes Demo Import. Replace the your_theme_ prefix and the theme-text-domain text domain with your own.
function your_theme_demo_import_notice() {
// Hide if the plugin is already active or the user can't install plugins.
if ( class_exists( 'PMDI\OneClickDemoImport' ) || ! current_user_can( 'install_plugins' ) ) {
return;
}
$url = admin_url( 'plugin-install.php?s=postmagthemes-demo-import&tab=search&type=term' );
?>
<?php
}
add_action( 'admin_notices', 'your_theme_demo_import_notice' );
Step 3 (optional): Hide the PostmagThemes showcase
The Import Demo Data page shows PostmagThemes' free themes and plugins. If you prefer not to show them to your users, add this to your theme's functions.php:
add_filter( 'pt-pmdi/show_wporg_showcase', '__return_false' );
Are you a theme user?
Ask your theme developer to support this plugin. Let them know how easy it makes setting up a site with their theme's demo.
Note: By default, demo content is imported under the currently logged-in WordPress user. Before importing, you can choose a different existing user to be the author of the imported posts.
Contribute
PostmagThemes Demo Import is open source and developed on GitHub. Bug reports, feature ideas and pull requests are welcome:
For general help, please use the support forum.
Credits
Based on One Click Demo Import.
postmagthemes-demo-import.zip.postmagthemes-demo-import folder to /wp-content/plugins/.It imports a theme's demo content, widgets and customizer settings so your site matches the theme demo.
No. PostmagThemes themes get one-click import with a demo preview. For other themes, upload the .xml, .wie and .dat files provided by the theme author.
Go to Appearance > Import Demo Data in your WordPress dashboard.
Yes. By default, demo content is imported under the currently logged-in user. Before importing, you can choose a different existing user to be the author of the imported posts.
Register your demo files with the pt-pmdi/import_files filter in your theme's functions.php. See "Are you a theme developer?" in the Description for the code.
Visit the GitHub repository to report bugs, suggest features or send a pull request.
No. The importer adds the demo content alongside your existing content. We recommend importing on a fresh site for the best result.