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

  • SOLVED

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 - https://github.com/DeoThemes/everse-starter-sites/
Here is the video that shows the issue - https://www.google.com/url?q=https://www.dropbox.com/s/bwo82nu3aufhsg0/ESS_contact_form_import.mp4?dl%3D0&sa=D&source=hangouts&ust=1605141238548000&usg=AFQjCNHs8SnMal7NlBgQx7js8BWJ10VmHw

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(
$api->name,
$this->log_file_path,
esc_html__( 'Installing Plugins' , 'everse-starter-sites' )
);

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

ESS_Helpers::log_error_and_send_ajax_response(
'There was an error installing '. $api->name .'.',
$this->log_file_path,
esc_html__( 'Installing Plugins', 'everse-starter-sites' )
);
}

Answers (3)

2020-11-11

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.

2020-11-14

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?

2020-11-11

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:

https://www.dropbox.com/s/bwo82nu3aufhsg0/ESS_contact_form_import.mp4?dl=0