Theme Integration Guide: PHP Configuration

Configuring the Demo Import with PHP

Once you’ve exported all necessary files and bundled them into a zip archive, the next step is configuring the demo importer using PHP. This involves creating a PHP configuration file that consolidates all required PHP code for your theme or plugin. This file serves as a repository for various configurations and settings essential for smooth functionality. You can seamlessly integrate this file into your theme, core plugin, or any other suitable location within your project structure.

Configuring demo imports is incredibly easy with the use of the plugin filter hook sd/edi/importer/config. Below, we provide sample configurations accompanied by detailed comments for clarity. Simply copy the provided code snippets and paste them into your PHP file.

For reference, a sample configuration file can be found in the plugin directory -> samples folder. You can download a sample demo import .zip file from here.

Define Basic Demos

Demo import can be configured to import a whole demo or individual demos from a multipurpose theme, along with the required plugins list.

Full Demo Import (Single Zip File)

Kindly check the below basic configuration for full site demo import, i.e. with the single import zip file.

// Sample Config for full site (single zip).
add_filter( 'sd/edi/importer/config', 'sd_edi_full_site_config' );

/**
 * Sample Config for full site (single zip).
 *
 * @return array
 */
function sd_edi_full_site_config() {
	return [
		// Name of the theme.
		'themeName'             => 'Theme Name',

		// Theme slug.
		'themeSlug'             => 'theme-slug',

		// Allow multiple zip files to false (for full site demo)
		'multipleZip'           => false,

		// URL to the demo content ZIP file.
		'demoZip'               => 'URL/of/the/demo-import.zip',

		// Slug for the blog page.
		'blogSlug'              => 'news',

		// Array of settings JSON data. You need to include these JSON files
		// in the demo zip file. The file names are representing
		// the option names.
		'settingsJson'          => [
			'example-options.json',
			'example-options-2.json',
		],

		// Associative array of menus and their names like:
		// menu_location => Menu Name.
		'menus'                 => [
			'primary' => 'Primary Menu',
			'footer'  => 'Footer Menu',
		],

		// Array of demo data consisting of demo name, demo preview image
		// and demo preview URL.
		'demoData'              => [
			// The array key needs to be the same as the home page slug to 
			// automatically setting it up as the home page.
			'home-1' => [
				'name'         => esc_html__( 'Home 1', 'text-domain' ),
				'previewImage' => 'URL/of/home-1/preview.jpg',
				'previewUrl'   => 'URL/of/home-1/preview/',
			],
			
			'home-2' => [
				'name'         => esc_html__( 'Home 2', 'text-domain' ),
				'previewImage' => 'URL/of/home-2/preview.jpg',
				'previewUrl'   => 'URL/of/home-2/preview/',
			],

			// Add more demo data as needed.
		],

		// Array of plugins to install.
		// Some example plugins are included here.
		// The array key needs to be the same as plugin slug.
		'plugins'               => [
			'elementor'   => [
				'name'     => 'Elementor Page Builder',           // Plugin name.
				'source'   => 'wordpress',                        // From the wordpress.org plugin repository.
				'filePath' => 'elementor/elementor.php',          // Plugin main file path.
			],
			'woocommerce' => [
				'name'     => 'WooCommerce',
				'source'   => 'wordpress',
				'filePath' => 'woocommerce/woocommerce.php',
			],

			// If you need to include bundled plugins, you can use as below.
			'theme-core' => [
				'name'     => 'Theme Core',                       // Plugin name.
				'source'   => 'bundled',                          // Source needs to be 'bundled'.
				'filePath' => 'theme-core/theme-core.php',        // Plugin main file path.
				'location' => trailingslashit( get_template_directory() ) . 'inc/plugins/theme-core.zip', // Plugin zip file location.
			],

			// Add more required plugins as needed.
		],
	];
}
PHP

Single Demo Import (Multiple Zip File)

A single demo import of a multipurpose theme is possible with our plugin. Below is a basic configuration for single site demo import, i.e. with the multiple import zip file, along with the associated required plugins list.

// Sample Config for single site (multiple zip).
add_filter( 'sd/edi/importer/config', 'sd_edi_single_site_config' );

/**
 * Sample Config for single site (multiple zip).
 *
 * @return array
 */
function sd_edi_single_site_config() {
	return [
		'themeName'   => 'Theme Name',
		'themeSlug'   => 'theme-slug',

		// Allow multiple zip files to true (for single site demo).
		'multipleZip' => true,
		
	    // Array of demo data.
		'demoData'    => [
			// Treat individual array as a separate demo.
			'demo-site-1' => [
				'name'                  => esc_html__( 'Demo Site 1', 'text-domain' ),
				'previewImage'          => 'URL/of/demo/site/1/preview.jpg',
				'previewUrl'            => 'URL/of/demo/site/1/preview/',
				'demoZip'               => 'URL/of/the/demo/site/1/demo-import.zip',
				'blogSlug'              => 'blog',
		        'settingsJson'          => [
                    'example-options.json',
			        'example-options-2.json',
		        ],
				'menus'                 => [
					'primary' => 'Main Menu',
					'footer'  => 'Secondary',
				],
				
				// Required plugins for this demo.
				'plugins'               => [
					'elementor'   => [
						'name'     => 'Elementor Page Builder',
						'source'   => 'wordpress',
						'filePath' => 'elementor/elementor.php',
					],
					'woocommerce' => [
						'name'     => 'WooCommerce',
						'source'   => 'wordpress',
						'filePath' => 'woocommerce/woocommerce.php',
					],
                    
                    // Add more required plugins as needed.
				],
			],

			'demo-site-2' => [
				'name'                  => esc_html__( 'Demo Site 2', 'text-domain' ),
				'previewImage'          => 'URL/of/demo/site/2/preview.jpg',
				'previewUrl'            => 'URL/of/demo/site/2/preview/',
				'demoZip'               => 'URL/of/the/demo/site/2/demo-import.zip',
				'blogSlug'              => 'news',
		        'settingsJson'          => [
                    'example-options-3.json',
			        'example-options-4.json',
		        ],
				'menus'                 => [
					'primary' => 'Header Menu',
					'footer'  => 'Social Menu',
				],
				
				// Required plugins for this demo.
				'plugins'               => [
					'elementor'   => [
						'name'     => 'Elementor Page Builder',
						'source'   => 'wordpress',
						'filePath' => 'elementor/elementor.php',
					],
					'theme-core' => [
				        'name'     => 'Theme Core',
				        'source'   => 'bundled',
				        'filePath' => 'theme-core/theme-core.php',
				        'location' => trailingslashit( get_template_directory() ) . 'inc/plugins/theme-core.zip',
			        ],
					
					// Add more required plugins as needed.
				],
			],

			// Add more demo data as needed.
		],
	];
}
PHP

Advanced Configuration

Easy Demo importer includes some advanced tools. Demo import can be configured to replace URL, replace commenter email, and Elementor taxonomy data mapping  in both full site and single site demo.

URL Replacement

Theme developers can configure the demo import so that the source URL can be replaced with the current site URL where the demo is being imported. To achieve this, simply use the urlToReplace array key and set its value to the URL you want to replace.

/**
 * Sample Config for full site (single zip).
 *
 * @return array
 */
function sd_edi_full_site_config() {
	return [
		
		[... Other codes...]

		// Source URL to replace in the content.
		'urlToReplace' => 'demo/site/URL/',

		[... Other codes...]

	];
}

/**
 * Sample Config for single site (multiple zip).
 *
 * @return array
 */
function sd_edi_single_site_config() {
 
    [... Other codes...]
    
    'demoData'    => [
        'demo-site-1' => [
        
            [... Other codes...]
            
            'urlToReplace' => 'demo/site/1/URL/',
            
            [... Other codes...]
        
        ],
        
        'demo-site-2' => [
        
            [... Other codes...]
            
            'urlToReplace' => 'demo/site/2/URL/',
            
            [... Other codes...]
        
        ],
    ],
    
    [... Other codes...]
 
}
PHP

Commenter Email Replacement

Similarly, developers can replace the commenter email. The email will be replaced with the current admin email address. Just need to pass the replaceCommenterEmail array key with the value of the email to replace.

/**
 * Sample Config for full site (single zip).
 *
 * @return array
 */
function sd_edi_full_site_config() {
	return [
		
		[... Other codes...]

		// Commenter email to replace.
		'replaceCommenterEmail' => 'email@example.com',

		[... Other codes...]

	];
}

/**
 * Sample Config for single site (multiple zip).
 *
 * @return array
 */
function sd_edi_single_site_config() {
 
    [... Other codes...]
    
    'demoData'    => [
        'demo-site-1' => [
        
            [... Other codes...]
            
		    // Commenter email to replace.
		    'replaceCommenterEmail' => 'email@example.com',
            
            [... Other codes...]
        
        ],
        
        'demo-site-2' => [
        
            [... Other codes...]
            
		    // Commenter email to replace.
		    'replaceCommenterEmail' => 'email@example.com',
            
            [... Other codes...]
        
        ],
    ],
    
    [... Other codes...]
 
}
PHP

Import Fluent Forms

To import Fluent Forms, ensure you include the Fluent Form export JSON files within the zip file. Then, as part of the import process, use the fluentFormsJson array key and set its value to the name of the JSON file.

/**
 * Sample Config for full site (single zip).
 *
 * @return array
 */
function sd_edi_full_site_config() {
	return [
		
		[... Other codes...]

		// JSON data file name for Fluent Forms.
		'fluentFormsJson' => 'fluentforms',

		[... Other codes...]

	];
}

/**
 * Sample Config for single site (multiple zip).
 *
 * @return array
 */
function sd_edi_single_site_config() {
 
    [... Other codes...]
    
    'demoData'    => [
        'demo-site-1' => [
        
            [... Other codes...]
            
		    // JSON data file name for Fluent Forms.
		    'fluentFormsJson' => 'fluentforms-1',
            
            [... Other codes...]
        
        ],
        
        'demo-site-2' => [
        
            [... Other codes...]
            
		    // JSON data file name for Fluent Forms.
		    'fluentFormsJson' => 'fluentforms-2',
            
            [... Other codes...]
        
        ],
    ],
    
    [... Other codes...]
 
}
PHP

Elementor Widget Taxonomy Data Mapping

Our Easy Demo Importer plugin features a special capability known as Elementor Widget Taxonomy Data Mapping. Before diving into the setup process, let’s grasp the essence of this functionality.

Understanding Taxonomy Data Import

When we import taxonomy data, the XML importer dynamically generates new taxonomy term IDs. This means that the term IDs on the source site will not align with the ones on the importing site. Consequently, if an Elementor addon widget employs a control to select taxonomy terms and retrieves term IDs, they won’t match.

The Role of Taxonomy Data Mapping

This is precisely where the taxonomy data mapping steps in. It acts like a bridge, connecting different term IDs and making sure Elementor addon widgets smoothly transition between sites. This ensures that when you import content, especially widgets relying on taxonomy term choices, everything fits together perfectly. It’s like a translator making sure everyone speaks the same language, making your import process super smooth.

Configuring the Data Mapping

Now that you have a grasp of the concept, let’s dive into the configuration process. The elementor_data_fix array key comes to the rescue. If you have an Elementor widget named show-categories (widget slug) and a control named filter_categories, you can configure it as follows:

/**
 * Sample Config for full site (single zip).
 *
 * @return array
 */
function sd_edi_full_site_config() {
	return [
		
		[... Other codes...]

		// Fix elementor taxonomy data.
		'elementor_data_fix' => [
			// Need to pass the Elementor widget name as key
			// and pass the control key as value.
			'show-categories' => [
				'filter_categories',
			],
		],

		[... Other codes...]

	];
}
PHP

If you have multiple controls to map, simply add the control names to the array. Similarly, if you’re dealing with multiple widgets, include their names in the array as well.

/**
 * Sample Config for full site (single zip).
 *
 * @return array
 */
function sd_edi_full_site_config() {
	return [
		
		[... Other codes...]

		// Fix elementor taxonomy data.
		'elementor_data_fix'         => [
			'show-categories' => [
				'filter_categories',
				'some_other_control',
			],

			'some-other-widget-slug' => [
				'some_other_control',
			],
		],

		[... Other codes...]

	];
}
PHP

For those dealing with a repeater control that incorporates a category selector control, we’ve got you covered. Simply include the prefix repeater_ before the repeater control name. For instance, if your repeater control is named some_repeater and the category selector control is named select_categories, then you should pass the repeater control name as repeater_some_repeater along with the corresponding key-value pair.

/**
 * Sample Config for full site (single zip).
 *
 * @return array
 */
function sd_edi_full_site_config() {
	return [
		
		[... Other codes...]

		// Fix elementor taxonomy data.
		'elementor_data_fix'                  => [
			'show-categories' => [
				'filter_categories',
				'some_other_control',
			],

			'some-other-widget-slug'          => [
				'some_other_control',
			],
			
			'some-widget-containing-repeater' => [
			    // Repeater control. Add 'repeater_' prefix. Ex: repeater_{control_name}.
				'repeater_some_repeater' => 'select_categories',
			],
		],

		[... Other codes...]

	];
}
PHP

What's Next?

Discover our advanced guide for precise demo site duplication with detailed configuration tips for your demo importer. Unlock enhanced functionality now!

Scroll to Top