PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.5
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
← All changes | src/integrations/admin/import-integration.php +123 -32 18.128.5 View file →
@@ -2,15 +2,14 @@
2 2
3 3 namespace Yoast\WP\SEO\Integrations\Admin;
4 4
5 5 use WPSEO_Admin_Asset_Manager;
6 -use Yoast\WP\SEO\Conditionals\AIOSEO_V4_Importer_Conditional;
6 +use Yoast\WP\SEO\Conditionals\Import_Tool_Selected_Conditional;
7 7 use Yoast\WP\SEO\Conditionals\Yoast_Tools_Page_Conditional;
8 -use Yoast\WP\SEO\Conditionals\Import_Tool_Selected_Conditional;
9 8 use Yoast\WP\SEO\Integrations\Integration_Interface;
10 9 use Yoast\WP\SEO\Presenters\Admin\Alert_Presenter;
11 -use Yoast\WP\SEO\Services\Importing\Importable_Detector;
12 10 use Yoast\WP\SEO\Routes\Importing_Route;
11 +use Yoast\WP\SEO\Services\Importing\Importable_Detector_Service;
13 12
14 13 /**
15 14 * Loads import script when on the Tool's page.
16 15 */
@@ -23,18 +22,11 @@
23 22 */
24 23 protected $asset_manager;
25 24
26 25 /**
27 - * Represents the AIOSEO V4 Importer conditional.
28 - *
29 - * @var AIOSEO_V4_Importer_Conditional
30 - */
31 - protected $importer_conditional;
32 -
33 - /**
34 26 * The Importable Detector service.
35 27 *
36 - * @var Importable_Detector
28 + * @var Importable_Detector_Service
37 29 */
38 30 protected $importable_detector;
39 31
40 32 /**
@@ -50,9 +42,8 @@
50 42 * @return array
51 43 */
52 44 public static function get_conditionals() {
53 45 return [
54 - AIOSEO_V4_Importer_Conditional::class,
55 46 Import_Tool_Selected_Conditional::class,
56 47 Yoast_Tools_Page_Conditional::class,
57 48 ];
58 49 }
@@ -59,23 +50,20 @@
59 50
60 51 /**
61 52 * Import Integration constructor.
62 53 *
63 - * @param WPSEO_Admin_Asset_Manager $asset_manager The asset manager.
64 - * @param AIOSEO_V4_Importer_Conditional $importer_conditional The AIOSEO V4 Importer conditional.
65 - * @param Importable_Detector $importable_detector The importable detector.
66 - * @param Importing_Route $importing_route The importing route.
54 + * @param WPSEO_Admin_Asset_Manager $asset_manager The asset manager.
55 + * @param Importable_Detector_Service $importable_detector The importable detector.
56 + * @param Importing_Route $importing_route The importing route.
67 57 */
68 58 public function __construct(
69 59 WPSEO_Admin_Asset_Manager $asset_manager,
70 - AIOSEO_V4_Importer_Conditional $importer_conditional,
71 - Importable_Detector $importable_detector,
60 + Importable_Detector_Service $importable_detector,
72 61 Importing_Route $importing_route
73 62 ) {
74 - $this->asset_manager = $asset_manager;
75 - $this->importer_conditional = $importer_conditional;
76 - $this->importable_detector = $importable_detector;
77 - $this->importing_route = $importing_route;
63 + $this->asset_manager = $asset_manager;
64 + $this->importable_detector = $importable_detector;
65 + $this->importing_route = $importing_route;
78 66 }
79 67
80 68 /**
81 69 * Initializes the integration.
@@ -89,27 +77,58 @@
89 77 }
90 78
91 79 /**
92 80 * Enqueues the Import script.
81 + *
82 + * @return void
93 83 */
94 84 public function enqueue_import_script() {
95 85 \wp_enqueue_style( 'dashicons' );
96 86 $this->asset_manager->enqueue_script( 'import' );
97 87
98 - $import_failure_alert = $this->get_import_failure_alert();
99 -
100 88 $data = [
101 89 'restApi' => [
102 90 'root' => \esc_url_raw( \rest_url() ),
91 + 'cleanup_endpoints' => $this->get_cleanup_endpoints(),
103 92 'importing_endpoints' => $this->get_importing_endpoints(),
104 93 'nonce' => \wp_create_nonce( 'wp_rest' ),
105 94 ],
106 95 'assets' => [
107 - 'loading_msg' => \esc_html__( 'The import can take a long time depending on your site\'s size.', 'wordpress-seo' ),
108 - 'select_placeholder' => \esc_html__( 'Select SEO plugin', 'wordpress-seo' ),
109 - 'no_data_msg' => \esc_html__( 'No data found from other SEO plugins.', 'wordpress-seo' ),
110 - 'import_failure' => $import_failure_alert,
111 - 'spinner' => \admin_url( 'images/loading.gif' ),
96 + 'loading_msg_import' => \esc_html__( 'The import can take a long time depending on your site\'s size.', 'wordpress-seo' ),
97 + 'loading_msg_cleanup' => \esc_html__( 'The cleanup can take a long time depending on your site\'s size.', 'wordpress-seo' ),
98 + 'note' => \esc_html__( 'Note: ', 'wordpress-seo' ),
99 + 'cleanup_after_import_msg' => \esc_html__( 'After you\'ve imported data from another SEO plugin, please make sure to clean up all the original data from that plugin. (step 5)', 'wordpress-seo' ),
100 + 'select_placeholder' => \esc_html__( 'Select SEO plugin', 'wordpress-seo' ),
101 + 'no_data_msg' => \esc_html__( 'No data found from other SEO plugins.', 'wordpress-seo' ),
102 + 'validation_failure' => $this->get_validation_failure_alert(),
103 + 'import_failure' => $this->get_import_failure_alert( true ),
104 + 'cleanup_failure' => $this->get_import_failure_alert( false ),
105 + 'spinner' => \admin_url( 'images/loading.gif' ),
106 + 'replacing_texts' => [
107 + 'cleanup_button' => \esc_html__( 'Clean up', 'wordpress-seo' ),
108 + 'import_explanation' => \esc_html__( 'Please select an SEO plugin below to see what data can be imported.', 'wordpress-seo' ),
109 + 'cleanup_explanation' => \esc_html__( 'Once you\'re certain that your site is working properly with the imported data from another SEO plugin, you can clean up all the original data from that plugin.', 'wordpress-seo' ),
110 + /* translators: %s: expands to the name of the plugin that is selected to be imported */
111 + 'select_header' => \esc_html__( 'The import from %s includes:', 'wordpress-seo' ),
112 + 'plugins' => [
113 + 'aioseo' => [
114 + [
115 + 'data_name' => \esc_html__( 'Post metadata (SEO titles, descriptions, etc.)', 'wordpress-seo' ),
116 + 'data_note' => \esc_html__( 'Note: This metadata will only be imported if there is no existing Yoast SEO metadata yet.', 'wordpress-seo' ),
117 + ],
118 + [
119 + 'data_name' => \esc_html__( 'Default settings', 'wordpress-seo' ),
120 + 'data_note' => \esc_html__( 'Note: These settings will overwrite the default settings of Yoast SEO.', 'wordpress-seo' ),
121 + ],
122 + ],
123 + 'other' => [
124 + [
125 + 'data_name' => \esc_html__( 'Post metadata (SEO titles, descriptions, etc.)', 'wordpress-seo' ),
126 + 'data_note' => \esc_html__( 'Note: This metadata will only be imported if there is no existing Yoast SEO metadata yet.', 'wordpress-seo' ),
127 + ],
128 + ],
129 + ],
130 + ],
112 131 ],
113 132 ];
114 133
115 134 /**
@@ -127,11 +146,57 @@
127 146 *
128 147 * @return array The endpoints.
129 148 */
130 149 protected function get_importing_endpoints() {
131 - $available_actions = $this->importable_detector->detect();
150 + $available_actions = $this->importable_detector->detect_importers();
132 151 $importing_endpoints = [];
133 152
153 + $available_sorted_actions = $this->sort_actions( $available_actions );
154 +
155 + foreach ( $available_sorted_actions as $plugin => $types ) {
156 + foreach ( $types as $type ) {
157 + $importing_endpoints[ $plugin ][] = $this->importing_route->get_endpoint( $plugin, $type );
158 + }
159 + }
160 +
161 + return $importing_endpoints;
162 + }
163 +
164 + /**
165 + * Sorts the array of importing actions, by moving any validating actions to the start for every plugin.
166 + *
167 + * @param array $available_actions The array of actions that we want to sort.
168 + *
169 + * @return array The sorted array of actions.
170 + */
171 + protected function sort_actions( $available_actions ) {
172 + $first_action = 'validate_data';
173 + $available_sorted_actions = [];
174 +
175 + foreach ( $available_actions as $plugin => $plugin_available_actions ) {
176 +
177 + $validate_action_position = \array_search( $first_action, $plugin_available_actions, true );
178 +
179 + if ( ! empty( $validate_action_position ) ) {
180 + unset( $plugin_available_actions[ $validate_action_position ] );
181 + \array_unshift( $plugin_available_actions, $first_action );
182 + }
183 +
184 + $available_sorted_actions[ $plugin ] = $plugin_available_actions;
185 + }
186 +
187 + return $available_sorted_actions;
188 + }
189 +
190 + /**
191 + * Retrieves a list of the importing endpoints to use.
192 + *
193 + * @return array The endpoints.
194 + */
195 + protected function get_cleanup_endpoints() {
196 + $available_actions = $this->importable_detector->detect_cleanups();
197 + $importing_endpoints = [];
198 +
134 199 foreach ( $available_actions as $plugin => $types ) {
135 200 foreach ( $types as $type ) {
136 201 $importing_endpoints[ $plugin ][] = $this->importing_route->get_endpoint( $plugin, $type );
137 202 }
@@ -140,14 +205,40 @@
140 205 return $importing_endpoints;
141 206 }
142 207
143 208 /**
209 + * Gets the validation failure alert using the Alert_Presenter.
210 + *
211 + * @return string The validation failure alert.
212 + */
213 + protected function get_validation_failure_alert() {
214 + $content = \esc_html__( 'The AIOSEO import was cancelled because some AIOSEO data is missing. Please try and take the following steps to fix this:', 'wordpress-seo' );
215 + $content .= '<br/>';
216 + $content .= '<ol><li>';
217 + $content .= \esc_html__( 'If you have never saved any AIOSEO \'Search Appearance\' settings, please do that first and run the import again.', 'wordpress-seo' );
218 + $content .= '</li>';
219 + $content .= '<li>';
220 + $content .= \esc_html__( 'If you already have saved AIOSEO \'Search Appearance\' settings and the issue persists, please contact our support team so we can take a closer look.', 'wordpress-seo' );
221 + $content .= '</li></ol>';
222 +
223 + $validation_failure_alert = new Alert_Presenter( $content, 'error' );
224 +
225 + return $validation_failure_alert->present();
226 + }
227 +
228 + /**
144 229 * Gets the import failure alert using the Alert_Presenter.
145 230 *
231 + * @param bool $is_import Wether it's an import or not.
232 + *
146 233 * @return string The import failure alert.
147 234 */
148 - protected function get_import_failure_alert() {
149 - $content = \esc_html__( 'Import failed with the following error:', 'wordpress-seo' );
235 + protected function get_import_failure_alert( $is_import ) {
236 + $content = \esc_html__( 'Cleanup failed with the following error:', 'wordpress-seo' );
237 + if ( $is_import ) {
238 + $content = \esc_html__( 'Import failed with the following error:', 'wordpress-seo' );
239 + }
240 +
150 241 $content .= '<br/><br/>';
151 242 $content .= \esc_html( '%s' );
152 243
153 244 $import_failure_alert = new Alert_Presenter( $content, 'error' );