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' ); $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' ), '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; } }