← All changes
|
includes/admin/importers/class-abstract-plugin-exporter.php
+46
-12
1.28.0
→
2.12.0
View file →
| @@ -152,8 +152,26 @@ | ||
| 152 | 152 | return []; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
| 156 | + * Records for a data type outside the fixed set above. | |
| 157 | + * | |
| 158 | + * Nothing to hand over by default. It exists so an exporter can gain a type | |
| 159 | + * (ThinkRank's own export lets Pro register its tables this way) without | |
| 160 | + * every subclass having to reimplement export_chunk()'s chunk writing and | |
| 161 | + * manifest bookkeeping. | |
| 162 | + * | |
| 163 | + * @since 2.2.0 | |
| 164 | + * | |
| 165 | + * @param string $type Data type | |
| 166 | + * @param int $page Page number (1-indexed) | |
| 167 | + * @return array Records | |
| 168 | + */ | |
| 169 | + protected function export_custom_type_page(string $type, int $page): array { | |
| 170 | + return []; | |
| 171 | + } | |
| 172 | + | |
| 173 | + /** | |
| 156 | 174 | * Capture the source plugin's Role Manager assignments: role slug => the |
| 157 | 175 | * capabilities that role holds whose name starts with $prefix. |
| 158 | 176 | * |
| 159 | 177 | * Shared by every exporter because role capabilities live on the roles |
| @@ -209,9 +227,9 @@ | ||
| 209 | 227 | * @param mixed $value Value potentially containing template variables |
| 210 | 228 | * @param int|null $post_id Post ID for context-specific variables |
| 211 | 229 | * @return string Converted string |
| 212 | 230 | */ |
| 213 | - abstract protected function convert_template_variables(mixed $value, ?int $post_id = null): string; | |
| 231 | + abstract protected function convert_template_variables($value, ?int $post_id = null): string; | |
| 214 | 232 | |
| 215 | 233 | /** |
| 216 | 234 | * Coerce a foreign settings/meta value into a template string. |
| 217 | 235 | * |
| @@ -223,9 +241,9 @@ | ||
| 223 | 241 | * |
| 224 | 242 | * @param mixed $value Raw value from the source plugin's storage. |
| 225 | 243 | * @return string Usable template string, possibly ''. |
| 226 | 244 | */ |
| 227 | - final protected function stringify_template_value(mixed $value): string { | |
| 245 | + final protected function stringify_template_value($value): string { | |
| 228 | 246 | if (is_string($value)) { |
| 229 | 247 | return $value; |
| 230 | 248 | } |
| 231 | 249 | |
| @@ -251,17 +269,30 @@ | ||
| 251 | 269 | // Reset before the page method runs; it (or its id helper) records the |
| 252 | 270 | // raw fetched-row count here. |
| 253 | 271 | $this->last_page_row_count = null; |
| 254 | 272 | |
| 255 | - $records = match ($type) { | |
| 256 | - 'postmeta' => $this->export_postmeta_page($page), | |
| 257 | - 'termmeta' => $this->export_termmeta_page($page), | |
| 258 | - 'usermeta' => $this->export_usermeta_page($page), | |
| 259 | - 'settings' => $this->export_settings(), | |
| 260 | - 'redirections' => $this->export_redirections_page($page), | |
| 261 | - '404_logs' => $this->export_404_logs_page($page), | |
| 262 | - default => [], | |
| 263 | - }; | |
| 273 | + switch ($type) { | |
| 274 | + case 'postmeta': | |
| 275 | + $records = $this->export_postmeta_page($page); | |
| 276 | + break; | |
| 277 | + case 'termmeta': | |
| 278 | + $records = $this->export_termmeta_page($page); | |
| 279 | + break; | |
| 280 | + case 'usermeta': | |
| 281 | + $records = $this->export_usermeta_page($page); | |
| 282 | + break; | |
| 283 | + case 'settings': | |
| 284 | + $records = $this->export_settings(); | |
| 285 | + break; | |
| 286 | + case 'redirections': | |
| 287 | + $records = $this->export_redirections_page($page); | |
| 288 | + break; | |
| 289 | + case '404_logs': | |
| 290 | + $records = $this->export_404_logs_page($page); | |
| 291 | + break; | |
| 292 | + default: | |
| 293 | + $records = $this->export_custom_type_page($type, $page); | |
| 294 | + } | |
| 264 | 295 | |
| 265 | 296 | $exported_count = count($records); |
| 266 | 297 | |
| 267 | 298 | // Write chunk to snapshot store |
| @@ -371,9 +402,9 @@ | ||
| 371 | 402 | $result = ['noindex' => 0, 'nofollow' => 0]; |
| 372 | 403 | |
| 373 | 404 | // Handle serialized array (Rank Math stores robots as serialized array) |
| 374 | 405 | if (is_string($noindex_value) && is_serialized($noindex_value)) { |
| 375 | - $noindex_value = maybe_unserialize($noindex_value); | |
| 406 | + $noindex_value = Safe_Unserializer::unserialize($noindex_value); | |
| 376 | 407 | } |
| 377 | 408 | |
| 378 | 409 | if (is_array($noindex_value)) { |
| 379 | 410 | // Rank Math format: serialized array with 'noindex', 'nofollow' as values |
| @@ -433,8 +464,9 @@ | ||
| 433 | 464 | // (oembed_cache, revisions, nav menu items, block/template CPTs, …) never |
| 434 | 465 | // enter the snapshot — SEO meta left on them is noise. Filtering in the |
| 435 | 466 | // query (rather than per-record) keeps the chunk-size based has_more |
| 436 | 467 | // pagination in export_chunk() accurate. |
| 468 | + // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber -- table name is $wpdb->prefix plus a literal, and every value is passed as a placeholder replacement. | |
| 437 | 469 | $sql = $wpdb->prepare( |
| 438 | 470 | "SELECT DISTINCT pm.post_id |
| 439 | 471 | FROM {$wpdb->postmeta} pm |
| 440 | 472 | INNER JOIN {$wpdb->posts} p ON p.ID = pm.post_id |
| @@ -447,9 +479,11 @@ | ||
| 447 | 479 | $post_types, |
| 448 | 480 | [$this->chunk_size, $offset] |
| 449 | 481 | ) |
| 450 | 482 | ); |
| 483 | + // phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared | |
| 451 | 484 | |
| 485 | + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- table name is $wpdb->prefix plus a literal, and every value is passed as a placeholder replacement. | |
| 452 | 486 | $ids = $wpdb->get_col($sql); |
| 453 | 487 | $this->last_page_row_count = count($ids); |
| 454 | 488 | |
| 455 | 489 | return $ids; |