asset_manager = $asset_manager;
$this->importer_conditional = $importer_conditional;
$this->importable_detector = $importable_detector;
$this->importing_route = $importing_route;
}
/**
* Initializes the integration.
*
* This is the place to register hooks and filters.
*
* @return void
*/
public function register_hooks() {
\add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_import_script' ] );
}
/**
* Enqueues the Import script.
*/
public function enqueue_import_script() {
\wp_enqueue_style( 'dashicons' );
$this->asset_manager->enqueue_script( 'import' );
$import_failure_alert = $this->get_import_failure_alert();
$data = [
'restApi' => [
'root' => \esc_url_raw( \rest_url() ),
'importing_endpoints' => $this->get_importing_endpoints(),
'nonce' => \wp_create_nonce( 'wp_rest' ),
],
'assets' => [
'loading_msg' => \esc_html__( 'The import can take a long time depending on your site\'s size.', 'wordpress-seo' ),
'select_placeholder' => \esc_html__( 'Select SEO plugin', 'wordpress-seo' ),
'no_data_msg' => \esc_html__( 'No data found from other SEO plugins.', 'wordpress-seo' ),
'import_failure' => $import_failure_alert,
'spinner' => \admin_url( 'images/loading.gif' ),
],
];
/**
* Filter: 'wpseo_importing_data' Filter to adapt the data used in the import process.
*
* @param array $data The import data to adapt.
*/
$data = \apply_filters( 'wpseo_importing_data', $data );
$this->asset_manager->localize_script( 'import', 'yoastImportData', $data );
}
/**
* Retrieves a list of the importing endpoints to use.
*
* @return array The endpoints.
*/
protected function get_importing_endpoints() {
$available_actions = $this->importable_detector->detect();
$importing_endpoints = [];
foreach ( $available_actions as $plugin => $types ) {
foreach ( $types as $type ) {
$importing_endpoints[ $plugin ][] = $this->importing_route->get_endpoint( $plugin, $type );
}
}
return $importing_endpoints;
}
/**
* Gets the import failure alert using the Alert_Presenter.
*
* @return string The import failure alert.
*/
protected function get_import_failure_alert() {
$content = \esc_html__( 'Import failed with the following error:', 'wordpress-seo' );
$content .= '
';
$content .= \esc_html( '%s' );
$import_failure_alert = new Alert_Presenter( $content, 'error' );
return $import_failure_alert->present();
}
}