Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Some content doesn't get imported on custom importer / plugin activation script WordPress


I'm working on a starter sites plugin. It's based on One Click Demo Import script and native WordPress plugin-install.php and wp-admin/includes/class-wp-upgrader.php. When you select a demo, it shows the list of required plugins and if these plugins are installed or deactivated. The importer works well when the plugin is not installed but doesn't import content properly when the plugin is deactivated. Posts and pages content gets imported, but Contact Form 7 forms are not.

Here is the logic that is responsible for plugin installation / activation. However if you want to the see full code please refer to this Github repo -
Here is the video that shows the issue -

Not sure what I'm missing here.

if ( ! function_exists( 'plugins_api' ) ) {
require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );

$api = plugins_api( 'plugin_information', array(
'slug' => $plugin['slug'],

// needed for Plugin_Upgrader and Plugin_Installer_Skin
require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );

$upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin(
'api' => $api
) );

$skin = new WP_Ajax_Upgrader_Skin();
$upgrader = new Plugin_Upgrader( $skin );
$upgrader->install( $api->download_link );

if ( $api->name ) {

$log_added = ESS_Helpers::append_to_file(
esc_html__( 'Installing Plugins' , 'everse-starter-sites' )

activate_plugin( ESS_Plugins::get_instance()->get_plugin_basename_from_slug( $api->slug ) );
} else {

'There was an error installing '. $api->name .'.',
esc_html__( 'Installing Plugins', 'everse-starter-sites' )

Answers (3)


Reigel Gallarde answers:

I'm yet to check out the plugin, but looking at the video I can think that maybe version of contact form 7 is not the same. Just maybe.
I will try to look for answer in the plugin source code.

User179872 comments:

I'm using the latest Contact Form 7 plugin on my testing environment. In the video you can see that I test first with plugin deactivation, then reset my demo and test again with plugin deletion. In the second case import goes well (plugin is installed and activated) and it the end I get all the content properly imported, but not in the first case (plugin is deactivated).

Reigel Gallarde comments:

when you delete the cf7, after import, a new one gets installed and activated. is it same version with old cf7?

User179872 comments:

Yes, I'm sure it's the same version of CF7. I tested it about hundred times already and the plugin is always the same. And it's happening not only with CF7 but with other plugins as well. My guess is that content import is happening before the plugin activation.


Mohamed Ahmed answers:

In this case, it may be the content imported before the plugin activation.

User179872 comments:

Yes, that's exactly what I thought. But for some reason it works when the plugin is not installed. But how to prevent this issue from happening?


Francisco Javier Carazo Gil answers:

Have you check in the "Network" tab if in some ajax call it appear some error or problem in some of the steps the script does?

User179872 comments:

Yes, I checked and there are no errors in XHR calls, I got success in both cases.

Francisco Javier Carazo Gil comments:

Are you sure that there are forms in the content that are being imported?

User179872 comments:

Please check the video that I've attached, the second time that I test import, Business Contact Form is imported, but the first import with plugin activation doesn't have Business Contact Form: