The content doesn’t get imported on custom importer / plugin activation script

Question

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. 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' )
    );
}
0
Alexander 2 months 0 Answers 11 views 0

Leave an answer