wordpress, theme

How to Build a One-Click GPL Template Importer for Your WordPress Theme — Complete 2025 Guide

Learn step-by-step how to create a one-click GPL template importer for your WordPress block theme. Import demo content, global styles, and customizer settings automatically. Perfect for theme developers and GPL marketplaces.

Learn step-by-step how to create a one-click GPL template importer for your WordPress block theme. Import demo content, global styles, and customizer settings automatically. Perfect for theme developers and GPL marketplaces.

Introduction

The WordPress ecosystem thrives because of the GPL (General Public License) — empowering developers to modify, redistribute, and improve code freely. Many WordPress themes and plugins operate under this license, allowing open-source creativity to flourish.

However, one major challenge persists for users: importing demo templates easily. While commercial themes often provide “One-Click Demo Importers,” GPL theme users typically face manual import processes.

So, what if you could build your own one-click GPL template importer, just like premium themes — but 100% GPL-compliant?

This comprehensive guide will teach you how to create a fully functional One-Click Importer Plugin that installs demo content (WXR), imports customizer settings, menus, and global styles — all in one click.

What Is a One-Click Template Importer?

A One-Click Template Importer is a feature that lets users set up their theme exactly like the demo version — with

Instead of importing each element manually, a single click automates the entire process through a script or plugin.

GPL Licensing & Why It Matters

Before coding, it’s essential to understand GPL compliance.

Under the GPL License, you can

You cannot

Therefore, if your importer handles GPL templates, it must itself be GPL-licensed and include clear license declarations in the plugin header.

Folder Structure for Your GPL Template Importer

Create a new plugin folder in /wp-content/plugins/

/kaddora-gpl-importer/

├── kaddora-gpl-importer.php

├── /inc/

│   ├── class-import-controller.php

│   ├── class-import-ui.php

│   └── class-plugin-installer.php

├── /assets/

│   ├── css/admin.css

│   └── js/admin.js

└── /demos/

    ├── agency/

    │   ├── demo-content.xml

    │   ├── customizer.dat

    │   ├── menus.json

    │   └── global-styles.json

    └── organic/

        ├── demo-content.xml

        ├── customizer.dat

        ├── menus.json

        └── global-styles.json

Each demo has its own folder with assets for import.

Step 1: Create the Main Plugin File

File: kaddora-gpl-importer.php

<?php

/**

 * Plugin Name: Kaddora GPL Template Importer

 * Description: One-click importer for GPL WordPress themes and templates.

 * Version: 1.0

 * Author: Kaddora

 * License: GPLv2 or later

 * Text Domain: kaddora-gpl-importer

 */

 

if ( ! defined( 'ABSPATH' ) ) exit;

 

define( 'KADDORA_IMPORTER_DIR', plugin_dir_path( __FILE__ ) );

 

require_once KADDORA_IMPORTER_DIR . 'inc/class-import-controller.php';

require_once KADDORA_IMPORTER_DIR . 'inc/class-import-ui.php';

 

add_action( 'admin_menu', 'kaddora_importer_menu' );

function kaddora_importer_menu() {

    add_theme_page(

        __( 'GPL Template Importer', 'kaddora-gpl-importer' ),

        __( 'Template Importer', 'kaddora-gpl-importer' ),

        'manage_options',

        'kaddora-importer',

        ['Kaddora_Import_UI', 'render']

    );

}

Step 2: Build the Admin UI

File: /inc/class-import-ui.php

This creates the importer dashboard with demo selection and the import button.

<?php

class Kaddora_Import_UI {

 

    public static function render() {

        ?>

        <div class="wrap">

            <h1><?php esc_html_e('Kaddora One-Click GPL Template Importer', 'kaddora-gpl-importer'); ?></h1>

            <p><?php esc_html_e('Select a demo template below to import.', 'kaddora-gpl-importer'); ?></p>

 

            <div class="demo-list">

                <div class="demo-card">

                    <img src="<?php echo plugin_dir_url(__FILE__) . '../demos/agency/thumb.jpg'; ?>" alt="">

                    <h3>Agency Template</h3>

                    <button class="button-primary" data-slug="agency">Import Demo</button>

                </div>

                <div class="demo-card">

                    <img src="<?php echo plugin_dir_url(__FILE__) . '../demos/organic/thumb.jpg'; ?>" alt="">

                    <h3>Organic Store</h3>

                    <button class="button-primary" data-slug="organic">Import Demo</button>

                </div>

            </div>

        </div>

        <?php

    }

}

Add basic CSS in /assets/css/admin.css to make the UI neat.

Step 3: Handle Import Logic

File: /inc/class-import-controller.php

This controls the actual data import.

<?php

class Kaddora_Import_Controller {

 

    public static function run_import( $slug ) {

        $demo_path = KADDORA_IMPORTER_DIR . 'demos/' . sanitize_text_field( $slug ) . '/';

 

        if ( ! file_exists( $demo_path . 'demo-content.xml' ) ) {

            return ['error' => 'Demo files missing.'];

        }

 

        // Import XML content

        if ( ! class_exists( 'WP_Import' ) ) {

            require_once ABSPATH. 'wp-admin/includes/class-wp-importer.php';

            require_once ABSPATH 'wp-admin/includes/import.php';

        }

 

        $importer = new WP_Import();

        $importer->fetch_attachments = true;

        $importer->import( $demo_path . 'demo-content.xml' );

 

        // Import customizer

        self::import_customizer( $demo_path . 'customizer.dat' );

 

        // Import menus and global styles

        self::import_json( $demo_path . 'menus.json', 'menus' );

        self::import_json( $demo_path . 'global-styles.json', 'styles' );

 

        return ['success' => 'Demo imported successfully!'];

    }

 

    private static function import_customizer( $file ) {

        if ( ! file_exists( $file ) ) return;

        $data = unserialize( file_get_contents( $file ) );

        foreach ( $data as $key => $value ) {

            set_theme_mod( $key, $value );

        }

    }

 

    private static function import_json( $file, $type ) {

        if ( ! file_exists( $file ) ) return;

        $data = json_decode( file_get_contents( $file ), true );

        // handle menu/style logic here

    }

}

Step 4: AJAX Trigger for One-Click

In admin.js, create an AJAX request on button click

jQuery(document).ready(function($) {

    $('.demo-card button').on('click', function() {

        const slug = $(this).data('slug');

        $(this).text('Importing...');

 

        $.post(ajaxurl, {

            action: 'kaddora_run_import',

            slug: slug,

            _ajax_nonce: kaddoraImporter.nonce

        }, function(response) {

            alert(response.data.message);

            location.reload();

        });

    });

});

 

PHP AJAX handler in your main plugin file:

add_action( 'wp_ajax_kaddora_run_import', function() {

    check_ajax_referer( 'kaddora_nonce', '_ajax_nonce' );

    $slug = sanitize_text_field( $_POST['slug'] );

    $result = Kaddora_Import_Controller::run_import( $slug );

 

    if ( isset( $result['success'] ) ) {

        wp_send_json_success( [ 'message' => $result['success'] ] );

    } else {

        wp_send_json_error( [ 'message' => $result['error'] ] );

    }

});

Step 5: Import WooCommerce Pages Automatically

To ensure WooCommerce-based demos work perfectly, you can pre-create standard pages

if ( class_exists( 'WooCommerce' ) ) {

    if ( ! get_option( 'woocommerce_shop_page_id' ) ) {

        $shop = wp_insert_post( ['post_title' => 'Shop', 'post_type' => 'page', 'post_status' => 'publish'] );

        update_option( 'woocommerce_shop_page_id', $shop );

    }

}

Step 6: Make It User-Friendly

Step 7: Ensure GPL Compliance

Include a LICENSE.txt in your plugin folder

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 any later version.

Always credit the original code sources if you use external GPL libraries.

Step 8: Distribute and Monetize via GPL Affiliate Programs

You can now share your importer with

Add affiliate tracking links for each demo source (theme, template, or plugin).

For example

<a href="https://yourgplaffiliate.com/?ref=kaddora" target="_blank">View GPL Source</a>

This builds passive income while offering users value.

SEO Optimization Tips for This Topic

  • Primary Keyword GPL Template Importer
  • LSI Keywords WordPress demo importer, one-click import, GPL themes, theme.json import, WXR import, WooCommerce demo importer.
  • Internal Links Link to your theme demos or documentation (e.g., /docs/import-guide/).
  • External Links Link to WordPress Codex and the GPL official page for credibility.
  • Rich Snippets Add FAQ schema markup for SEO boost.

Conclusion

Building a One-Click GPL Template Importer is a perfect blend of automation and open-source ethics. It empowers theme users with instant setup while keeping your project 100% GPL-compliant.

By combining custom PHP logic, AJAX, and WordPress importer classes, you can replicate the premium “demo importer” experience — and even monetize it ethically through GPL affiliate programs.

Top 15 FAQs

1. What is a GPL template importer in WordPress?

A GPL template importer is a WordPress tool that allows you to import GPL-licensed demo templates automatically, including posts, menus, and settings.

2. Is it legal to redistribute GPL WordPress templates?

Yes, as long as you maintain the GPL license and provide attribution where required.

3. Can I use this importer for non-GPL themes?

Technically, yes, but only with permission from the original author.

4. What’s the difference between WXR and JSON imports?

WXR imports WordPress content (pages/posts), while JSON imports global styles, menus, and settings.

5. Can I include WooCommerce demo data?

Yes. Add WooCommerce product XML files and hook them into your importer.

6. How does the importer handle images?

It can fetch and attach demo images via the WordPress media library if fetch_attachments is true.

7. Does the importer overwrite existing content?

No, unless your logic explicitly replaces existing pages or menus.

8. How can I show import progress visually?

Use AJAX with progress bars or loading spinners in the admin dashboard.

9. What if an XML file is corrupted?

Your importer should return an error message via wp_send_json_error() for graceful failure.

10. Can I import Gutenberg block patterns?

Yes, include block pattern files or register them during the import process.

11. Does it work with Full Site Editing (FSE) themes?

Yes — especially if you import theme.json and template parts correctly.

12. How do I export the template first?

Use a custom “Template Exporter” plugin to create demo-content.xml, customizer.dat, and JSON files.

13. Can users import templates without admin access?

No, only admins (manage_options capability) should have access.

14. Is this compatible with multisite installations?

Yes, but ensure each sub-site handles uploads and imports separately.

15. How can I monetize a GPL importer?

Offer curated GPL templates through affiliate links or membership subscriptions.

GPL Club Sites vs. Official Theme Developers (2025): Which WordPress Source Is Safe and Worth It?
08Nov

GPL Club Sites vs. Official Theme Developers (2025): Which WordPress Source Is Safe and Worth It?

When you start exploring WordPress themes, one term that quickly appears is “GPL.” You’ll also find GPL club websites promising…

Best Affiliate Marketing Networks & Offerings for GPL WordPress Themes & Plugins in the US/UK (2025)
06Nov

Best Affiliate Marketing Networks & Offerings for GPL WordPress Themes & Plugins in the US/UK (2025)

Looking to monetize GPL WordPress themes and plugins? This 2025 guide compares top affiliate networks (Awin, CJ, ShareASale, impact.com, PartnerStack)…

Best Practices for U.S. Affiliate Marketers Promoting GPL WordPress Themes & Plugins (2025 Guide)
04Nov

Best Practices for U.S. Affiliate Marketers Promoting GPL WordPress Themes & Plugins (2025 Guide)

Learn the top strategies for U.S. affiliate marketers to promote GPL-licensed WordPress themes and plugins ethically and profitably. Discover marketing…

Understanding GPL License in WordPress (2025): Complete Beginner’s Guide to Rights, Rules & Reuse
03Nov

Understanding GPL License in WordPress (2025): Complete Beginner’s Guide to Rights, Rules & Reuse

Introduction Learn everything about the GPL License in WordPress — what it means, why it matters, and how it impacts…

1 2 3 29

Leave a Reply

Your email address will not be published. Required fields are marked *