← All changes
|
includes/admin/importers/class-import-detector.php
+106
-1
2.3.0
→
2.13.0
View file →
| @@ -68,8 +68,24 @@ | ||
| 68 | 68 | 'meta_prefix' => '', |
| 69 | 69 | 'option_keys' => ['aioseo_options'], |
| 70 | 70 | 'plugin_files' => ['all-in-one-seo-pack/all_in_one_seo_pack.php', 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php'], |
| 71 | 71 | ], |
| 72 | + 'squirrly' => [ | |
| 73 | + 'name' => 'Squirrly SEO', | |
| 74 | + // Squirrly keeps SEO in its own `qss` table, not postmeta (#740); | |
| 75 | + // `_sq_` only covers its few fallback meta keys. | |
| 76 | + 'meta_prefix' => '_sq_', | |
| 77 | + 'option_keys' => ['sq_options'], | |
| 78 | + 'plugin_files' => ['squirrly-seo/squirrly.php'], | |
| 79 | + ], | |
| 80 | + 'slimseo' => [ | |
| 81 | + 'name' => 'Slim SEO', | |
| 82 | + // One `slim_seo` meta array per post/term, plus primary-term keys | |
| 83 | + // and option-stored redirects (#886) — counted by the exporter. | |
| 84 | + 'meta_prefix' => 'slim_seo', | |
| 85 | + 'option_keys' => ['slim_seo', 'ss_redirects', 'slim_seo_pro', 'slim_seo_schemas'], | |
| 86 | + 'plugin_files' => ['slim-seo/slim-seo.php', 'slim-seo-pro/slim-seo-pro.php'], | |
| 87 | + ], | |
| 72 | 88 | ]; |
| 73 | 89 | |
| 74 | 90 | /** |
| 75 | 91 | * Detect all source plugins present in the database |
| @@ -158,10 +174,18 @@ | ||
| 158 | 174 | // Only surface source plugins that are currently installed AND active. |
| 159 | 175 | // Migrating from a plugin the user no longer runs isn't actionable, so |
| 160 | 176 | // leftover data from a deactivated/uninstalled plugin is intentionally |
| 161 | 177 | // excluded from the migration screen. |
| 178 | + // | |
| 179 | + // The one exception is Rank Math's FAQ / HowTo blocks. Those live in | |
| 180 | + // post_content, and deactivating Rank Math is precisely what breaks | |
| 181 | + // them: the blocks turn into "unsupported block" in the editor and lose | |
| 182 | + // their schema on the front end. Hiding the only screen that can repair | |
| 183 | + // them, at the exact moment they need repairing, left users with no way | |
| 184 | + // out at all (#777) — so an inactive Rank Math stays listed whenever | |
| 185 | + // convertible blocks remain, carrying that type and nothing else. | |
| 162 | 186 | if (!$this->is_source_active($config['plugin_files'] ?? [])) { |
| 163 | - return null; | |
| 187 | + return $this->detect_orphaned_blocks($slug, $config); | |
| 164 | 188 | } |
| 165 | 189 | |
| 166 | 190 | $counts = []; |
| 167 | 191 | $total = 0; |
| @@ -168,8 +192,15 @@ | ||
| 168 | 192 | |
| 169 | 193 | if ($slug === 'aioseo') { |
| 170 | 194 | // AIOSEO uses a custom table |
| 171 | 195 | $counts = $this->detect_aioseo(); |
| 196 | + } elseif ($slug === 'squirrly') { | |
| 197 | + // Squirrly uses a custom table too; the exporter classifies rows. | |
| 198 | + $counts = $this->detect_squirrly(); | |
| 199 | + } elseif ($slug === 'slimseo') { | |
| 200 | + // Slim SEO's redirects and 404 log live outside postmeta, and its | |
| 201 | + // primary terms under a second key; the exporter counts all of it. | |
| 202 | + $counts = $this->detect_slimseo(); | |
| 172 | 203 | } else { |
| 173 | 204 | // Standard postmeta-based plugins |
| 174 | 205 | $prefix = $config['meta_prefix']; |
| 175 | 206 | |
| @@ -203,8 +234,18 @@ | ||
| 203 | 234 | // when the exporter supports it (Rank Math Pro's redirects + 404 |
| 204 | 235 | // Monitor and Yoast Premium's redirects were never offered). |
| 205 | 236 | $counts = array_merge($counts, $this->detect_redirect_data($slug)); |
| 206 | 237 | |
| 238 | + // FAQ / HowTo blocks, offered while Rank Math is still active too, so | |
| 239 | + // the wizard converts them on the way out rather than leaving the user | |
| 240 | + // to discover the breakage after deactivation. | |
| 241 | + if ('rankmath' === $slug) { | |
| 242 | + $block_count = Block_Converter::count_posts(); | |
| 243 | + if ($block_count > 0) { | |
| 244 | + $counts[Block_Converter::TYPE] = $block_count; | |
| 245 | + } | |
| 246 | + } | |
| 247 | + | |
| 207 | 248 | // Check for settings |
| 208 | 249 | $has_settings = false; |
| 209 | 250 | foreach ($config['option_keys'] as $option_key) { |
| 210 | 251 | if (get_option($option_key, null) !== null) { |
| @@ -234,8 +275,39 @@ | ||
| 234 | 275 | ]; |
| 235 | 276 | } |
| 236 | 277 | |
| 237 | 278 | /** |
| 279 | + * Detection result for a deactivated source that has left convertible | |
| 280 | + * content blocks behind, or null when there is nothing to repair. | |
| 281 | + * | |
| 282 | + * Only the block type is reported. The plugin's postmeta and settings are | |
| 283 | + * deliberately still withheld: migrating those from a plugin the site no | |
| 284 | + * longer runs is the case the active-only rule exists to prevent, and it is | |
| 285 | + * not what broke. | |
| 286 | + * | |
| 287 | + * @param string $slug Plugin slug. | |
| 288 | + * @param array $config Plugin configuration. | |
| 289 | + * @return array|null | |
| 290 | + */ | |
| 291 | + private function detect_orphaned_blocks(string $slug, array $config): ?array { | |
| 292 | + if ('rankmath' !== $slug) { | |
| 293 | + return null; | |
| 294 | + } | |
| 295 | + | |
| 296 | + $count = Block_Converter::count_posts(); | |
| 297 | + if ($count < 1) { | |
| 298 | + return null; | |
| 299 | + } | |
| 300 | + | |
| 301 | + return [ | |
| 302 | + 'plugin' => $slug, | |
| 303 | + 'plugin_name' => $config['name'], | |
| 304 | + 'counts' => [Block_Converter::TYPE => $count], | |
| 305 | + 'total' => $count, | |
| 306 | + ]; | |
| 307 | + } | |
| 308 | + | |
| 309 | + /** | |
| 238 | 310 | * Whether any of a source plugin's known main files is active. |
| 239 | 311 | * |
| 240 | 312 | * Checks both single-site and network activation. A plugin that is merely |
| 241 | 313 | * installed but not active returns false. |
| @@ -303,8 +375,41 @@ | ||
| 303 | 375 | if ($redirects > 0) { |
| 304 | 376 | $counts['redirections'] = $redirects; |
| 305 | 377 | } |
| 306 | 378 | } |
| 379 | + // Squirrly's Advanced Pack redirects are counted by the exporter in | |
| 380 | + // detect_squirrly(), since only its `url` actions are redirects. | |
| 381 | + | |
| 382 | + return $counts; | |
| 383 | + } | |
| 384 | + | |
| 385 | + /** | |
| 386 | + * Detect Squirrly SEO data (custom `qss` table + Advanced Pack redirects). | |
| 387 | + * | |
| 388 | + * Delegated to the exporter: the table mixes posts, terms, author | |
| 389 | + * profiles and the homepage, and only the exporter knows how to tell | |
| 390 | + * them apart from the serialized `post` column. | |
| 391 | + * | |
| 392 | + * @return array Counts array | |
| 393 | + */ | |
| 394 | + private function detect_squirrly(): array { | |
| 395 | + $exporter = new Squirrly_Exporter(); | |
| 396 | + $counts = $exporter->get_available_types(); | |
| 397 | + // Settings are added by the caller from option_keys. | |
| 398 | + unset($counts['settings']); | |
| 399 | + | |
| 400 | + return $counts; | |
| 401 | + } | |
| 402 | + | |
| 403 | + /** | |
| 404 | + * Detect Slim SEO data: per-object meta, redirects and the 404 log. | |
| 405 | + * | |
| 406 | + * @return array Counts array | |
| 407 | + */ | |
| 408 | + private function detect_slimseo(): array { | |
| 409 | + $counts = (new Slim_SEO_Exporter())->get_available_types(); | |
| 410 | + // Settings are added by the caller from option_keys. | |
| 411 | + unset($counts['settings']); | |
| 307 | 412 | |
| 308 | 413 | return $counts; |
| 309 | 414 | } |
| 310 | 415 | |