PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.0
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.0
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / integrations / admin / import-integration.php

import-integration.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.0, at src/integrations/admin/import-integration.php

137 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Integrations\Admin;
4
5 use WPSEO_Admin_Asset_Manager;
6 use Yoast\WP\SEO\Conditionals\AIOSEO_V4_Importer_Conditional;
7 use Yoast\WP\SEO\Conditionals\Yoast_Tools_Page_Conditional;
8 use Yoast\WP\SEO\Conditionals\Import_Tool_Selected_Conditional;
9 use Yoast\WP\SEO\Integrations\Integration_Interface;
10 use Yoast\WP\SEO\Services\Importing\Importable_Detector;
11 use Yoast\WP\SEO\Routes\Importing_Route;
12
13 /**
14 * Loads import script when on the Tool's page.
15 */
16 class Import_Integration implements Integration_Interface {
17
18 /**
19 * Contains the asset manager.
20 *
21 * @var WPSEO_Admin_Asset_Manager
22 */
23 protected $asset_manager;
24
25 /**
26 * Represents the AIOSEO V4 Importer conditional.
27 *
28 * @var AIOSEO_V4_Importer_Conditional
29 */
30 protected $importer_conditional;
31
32 /**
33 * The Importable Detector service.
34 *
35 * @var Importable_Detector
36 */
37 protected $importable_detector;
38
39 /**
40 * The Importing Route class.
41 *
42 * @var Importing_Route
43 */
44 protected $importing_route;
45
46 /**
47 * Returns the conditionals based on which this loadable should be active.
48 *
49 * @return array
50 */
51 public static function get_conditionals() {
52 return [
53 AIOSEO_V4_Importer_Conditional::class,
54 Import_Tool_Selected_Conditional::class,
55 Yoast_Tools_Page_Conditional::class,
56 ];
57 }
58
59 /**
60 * Import Integration constructor.
61 *
62 * @param WPSEO_Admin_Asset_Manager $asset_manager The asset manager.
63 * @param AIOSEO_V4_Importer_Conditional $importer_conditional The AIOSEO V4 Importer conditional.
64 * @param Importable_Detector $importable_detector The importable detector.
65 * @param Importing_Route $importing_route The importing route.
66 */
67 public function __construct(
68 WPSEO_Admin_Asset_Manager $asset_manager,
69 AIOSEO_V4_Importer_Conditional $importer_conditional,
70 Importable_Detector $importable_detector,
71 Importing_Route $importing_route
72 ) {
73 $this->asset_manager = $asset_manager;
74 $this->importer_conditional = $importer_conditional;
75 $this->importable_detector = $importable_detector;
76 $this->importing_route = $importing_route;
77 }
78
79 /**
80 * Initializes the integration.
81 *
82 * This is the place to register hooks and filters.
83 *
84 * @return void
85 */
86 public function register_hooks() {
87 \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_import_script' ] );
88 }
89
90 /**
91 * Enqueues the Import script.
92 */
93 public function enqueue_import_script() {
94 \wp_enqueue_style( 'dashicons' );
95 $this->asset_manager->enqueue_script( 'import' );
96
97 $data = [
98 'restApi' => [
99 'root' => \esc_url_raw( \rest_url() ),
100 'importing_endpoints' => $this->get_importing_endpoints(),
101 'nonce' => \wp_create_nonce( 'wp_rest' ),
102 ],
103 'assets' => [
104 'loading_msg' => \esc_html__( 'The import can take a long time depending on your site\'s size', 'wordpress-seo' ),
105 'spinner' => \admin_url( 'images/loading.gif' ),
106 ],
107 ];
108
109 /**
110 * Filter: 'wpseo_importing_data' Filter to adapt the data used in the import process.
111 *
112 * @param array $data The import data to adapt.
113 */
114 $data = \apply_filters( 'wpseo_importing_data', $data );
115
116 $this->asset_manager->localize_script( 'import', 'yoastImportData', $data );
117 }
118
119 /**
120 * Retrieves a list of the importing endpoints to use.
121 *
122 * @return array The endpoints.
123 */
124 protected function get_importing_endpoints() {
125 $available_actions = $this->importable_detector->detect();
126 $importing_endpoints = [];
127
128 foreach ( $available_actions as $plugin => $types ) {
129 foreach ( $types as $type ) {
130 $importing_endpoints[ $plugin ][] = $this->importing_route->get_endpoint( $plugin, $type );
131 }
132 }
133
134 return $importing_endpoints;
135 }
136 }
137