Advanced Guide

Execute operations when importer initializes.

If you have custom codes to execute when the demo importer process initializes, you can use the action hook sd/edi/importer_init. This hook runs just after the database reset operation. This hook comes with the importer object parameter which provides access to the importer’s properties and methods to interact with the importer’s functionality. Kindly check the below example.

/**
 * Executes operations when importer initilizes.
 *
 * @param object $importer Import object.
 *
 * @return void
 */
function sd_edi_importer_init_actions( $importer ) {
    // Your custom codes.

}

/**
 * Hook into the importer init hook to execute your codes above.
 */
add_action( 'sd/edi/importer_init', 'sd_edi_importer_init_actions' );
PHP

Initiate the activation process for required plugins.

When you install a plugin, it might need to do some setup or database tasks when it’s activated. Our Easy Demo Importer plugin has a feature that automatically installs and activates required plugins. Sometimes, when these plugins activate, they need to run specific activation scripts.

To run a plugin’s activation script, you can use the sd/edi/plugin_activation_actions filter hook. Here’s an example with the WooCommerce plugin (no worries, it is included by default). It runs a method called install from the WC_Install class. Kindly note that you need to provide the plugin path when passing plugin data, for example, for WooCommerce it will be woocommerce/woocommerce.php.

/**
 * Run plugin activation actions after activation.
 *
 * @param array $actions Existing plugin activation actions.
 *
 * @return array
 */
function sd_edi_run_plugin_activation_actions( $actions ) {
    // Add WooCommerce plugin activation action.
    $actions['woocommerce/woocommerce.php'] = [
        'class'  => '\WC_Install',
        'action' => 'install',
    ];
    
    // Some other plugin activation actions.

    // Return the modified actions array.
    return $actions;
}

/**
 * Hook into the filter to run plugin activation actions.
 */
add_filter( 'sd/edi/activated_plugin_actions', 'sd_edi_run_plugin_activation_actions' );
PHP

Execute custom operations before import.

If you have custom codes to execute right before the demo import begins, consider utilizing the action hook sd/edi/before_import . This hook comes with the xmlFile parameter which represents the XML file that is being imported the importer object parameter which provides access to the importer’s properties and methods to interact with the importer’s functionality. Kindly check the below example.

/**
 * Executes operations before import.
 *
 * @param string $xmlFile  The XML file being imported.
 * @param object $importer Import object.
 *
 * @return void
 */
function sd_edi_before_import_actions( $xmlFile, $importer ) {
    // Example: Log the file being imported.
    error_log( 'Importing file: ' . $xmlFile );
    
    // Importing demo slug identifier.
    $demo_slug = $importer->demoSlug;
    
    // Example: Perform additional processing before import.
    if ( 'home-1' === $demo_slug ) {
        // Do something with the importer.

    }
}

/**
 * Hook into the before import hook to execute your codes above.
 */
add_action( 'sd/edi/importer_init', 'sd_edi_before_import_actions', 11 , 2 );
PHP

Temporarily boost server memory_limit.

If you have a large data to import, you can use our sd/edi/temp_boost_memory_limit filter to temporarily boost the server memory_limit. Please check the below example.

/**
 * Adjusts the memory limit for temporary import operations.
 *
 * @param string $memory_limit The current memory limit value.
 *
 * @return string
 */
function sd_edi_boost_memory_limit( $memory_limit ) {
    // Set a higher memory limit for temporary import operations.
    return '512M';
}

/**
 * Hook into the filter hook to execute your codes above.
 */
add_filter( 'sd/edi/temp_boost_memory_limit', 'sd_edi_boost_memory_limit' );
PHP

Execute custom operations after import.

If you have custom codes to execute after the demo import ends, you can use the action hook sd/edi/after_import. This hook comes with the importer object parameter which provides access to the importer’s properties and methods to interact with the importer’s functionality. Kindly check the below example.

/**
 * Executes operations after import.
 *
 * @param object $importer Import object.
 *
 * @return void
 */
function sd_edi_after_import_actions( $importer ) {
    // Your custom codes.

}

/**
 * Hook into the importer after import hook to execute your codes above.
 */
add_action( 'sd/edi/after_import', 'sd_edi_after_import_actions' );
PHP

Database Search & Replace Customization.

We provide a specialized tool for replacing source URLs. By default, it searches in specific database tables:

  • commentmeta
  • comments
  • fluentform_forms
  • options
  • postmeta
  • posts


If you want to modify or add to the above table list, you can utilize the sd/edi/db_search/tables filter hook. Please check the below example:

/**
 * Modify the list of tables used in database search and replace operation.
 *
 * @param array $tables The array of table names used in the search and replace operation.
 *
 * @return array
 */
function sd_edi_modify_db_table_list( $tables ) {
    global $wpdb;

    // Add a new table to the list.
    $tables[] = $wpdb->prefix . 'new_table_name';

    // Return the modified list of tables.
    return $tables;
}

/**
 * Hook the custom function to the filter hook.
 */
add_filter( 'sd/edi/db_search/tables', 'sd_edi_modify_db_table_list' );
PHP

How To's:

In this section you will learn how to set different options in different areas of demo import phase such as tweaking settings, changing texts etc.

Disable Elementor's Experimental Features.

Before initiating the demo import, you have the option to disable Elementor’s experimental features, such as Flexbox Container, Inline Font Icons, and others. Refer to the following code examples for instructions on implementing these changes.

/**
 * Updates some Elementor settings.
 *
 * @return void
 */
function sd_edi_before_import_actions() {
    // Disables Elementor's Flexbox Container feature.
    update_option( 'elementor_experiment-container', 'inactive' );
    
    // Disables Elementor's Inline Font Icons feature.
	update_option( 'elementor_experiment-e_font_icon_svg', 'inactive' );
	
    // Disables Elementor's Upgrade Swiper Library feature.
	update_option( 'elementor_experiment-e_swiper_latest', 'inactive' );
	
	// Some other settings as per your need.

}

/**
 * Hook the function into the before import action hook.
 */
add_filter( 'sd/edi/before_import', 'sd_edi_before_import_actions' );
PHP

Update Settings After Import.

After completing the demo import, you have the option to adjust your preferred settings. Refer to the following code examples for guidance on updating settings as needed.

/**
 * Updates some settings.
 *
 * @return void
 */
function sd_edi_after_import_actions() {
    // Update posts per page.
	update_option( 'posts_per_page', 8 );
	
	// Flushing Permalink.
	flush_rewrite_rules();
	
	// Some other settings as per your need.

}

/**
 * Hook the function into the after import action hook.
 */
add_filter( 'sd/edi/after_import', 'sd_edi_after_import_actions' );
PHP

Change Product Attribute Type.

During demo imports, WooCommerce product attributes are imported with the default ‘Select’ type. To customize attribute types based on your theme requirements, we provide a way. Review the following code examples for implementing this customization.

/**
 * Change attribute type in the WooCommerce attribute taxonomies table.
 *
 * @return void
 */
function sd_edi_change_attribute_type() {
	global $wpdb;

    // Change the array as per your attributes.
	$product_attributes = [
		'size'    => [
			'type' => 'button',
		],
		'color'   => [
			'type' => 'color',
		],
		'weight'  => [
			'type' => 'slider',
		],
	];

	foreach ( $product_attributes as $attribute_name => $attribute_data ) {
		$new_type   = $attribute_data['type'];
		$table_name = esc_sql( $wpdb->prefix . 'woocommerce_attribute_taxonomies' );
		$data       = [ 'attribute_type' => $new_type ];
		$where      = [ 'attribute_name' => $attribute_name ];

		// Run the query.
		// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
		$wpdb->update( $table_name, $data, $where, [ '%s' ], [ '%s' ] );

		flush_rewrite_rules();
		delete_transient( 'wc_attribute_taxonomies' );
	}
}

/**
 * Hook the function into the after import action hook.
 */
add_filter( 'sd/edi/after_import', 'sd_edi_change_attribute_type' );
PHP

If you wish to revert to the former layout of the dashboard’s demo importer page, which excludes tabbed categories and demo search functionalities, you can do so by implementing the following codes:

/**
 * Remove tabbed categories and demo search functionalities.
 *
 * @return bool
 */
add_filter( 'sd/edi/remove_tab_and_search', '__return_true' );
PHP

Modify Server Requirements Notification

To adjust the minimum requirements for the demo importer, utilize the sd/edi/server_requirements filter hook. Refer to the following code examples for guidance.

/**
 * Modify the server requirements for the demo importer.
 *
 * @param array $requirements An array containing default server requirements.
 *
 * @return array
 */
function sd_edi_modify_server_requirements( $requirements ) {
    $requirements['max_execution_time'] = '300';
    $requirements['max_input_time'] = '300';
    $requirements['upload_max_filesize'] = '256M';
    $requirements['post_max_size'] = '512M';
    $requirements['memory_limit'] = '256M';

    return $requirements;
}


/**
 * Hook the function into the filter hook.
 */
add_filter( 'sd/edi/server_requirements', 'sd_edi_modify_server_requirements' );
PHP

Change Texts:

On the demo importer page, there are some texts that you may want to change. Please follow the below reference codes.

Import Modal Texts.

/**
 * Modify the texts displayed during the import modal process.
 *
 * @param array $texts An array containing modal texts.
 *
 * @return array
 */
function sd_edi_modify_modal_texts( $texts ) {
	// Modify step one texts.
	$texts['stepOne']['introTopText']    = esc_html__( 'Your custom text goes here.', 'your-text-domain' );
	$texts['stepOne']['introBottomText'] = esc_html__( 'Your custom text goes here.', 'your-text-domain' );
	$texts['stepOne']['introExtraText']  = esc_html__( 'Your custom text goes here.', 'your-text-domain' );

	// Modify step two texts.
	$texts['stepTwo']['requiredPluginsIntro'] = esc_html__( 'Your custom text goes here.', 'your-text-domain' );

	return $texts;
}

/**
 * Hook the function into the filter hook.
 */
add_filter( 'sd/edi/import_modal_texts', 'sd_edi_modify_modal_texts' );
PHP

Support Texts.

/**
 * Modify the texts displayed in the support modal.
 *
 * @param array $texts An array containing modal texts.
 *
 * @return array
 */
function sd_edi_modify_support_texts( $texts ) {
    $texts['supportText'] = esc_html__( 'Your custom text goes here.', 'your-text-domain' );
    $texts['docText']     = esc_html__( 'Your custom text goes here.', 'your-text-domain' );
    $texts['docUrl']      = 'https://your-custom-doc-url.com';
    $texts['ticketUrl']   = 'https://your-custom-ticket-url.com';

    return $texts;
}


/**
 * Hook the function into the filter hook.
 */
add_filter( 'sd/edi/import_modal_texts', 'sd_edi_modify_support_texts' );
PHP

No Demo Found Message.

/**
 * Modify the message displayed when no demo configuration is found.
 *
 * @param array $message An array containing default message details.
 *
 * @return array
 */
function sd_edi_modify_message( $message ) {
    $message['text'] = esc_html__( 'Your custom message goes here.', 'your-text-domain' );
    
    // If you need to display a button.
    $message['btnUrl'] = 'https://your-custom-btn-url.com';
    $message['btnText'] = esc_html__( 'Your custom button text', 'your-text-domain' );

    return $message;
}


/**
 * Hook the function into the filter hook.
 */
add_filter( 'sd/edi/config/no_demo', 'sd_edi_modify_message' );
PHP
Scroll to Top