← All changes
|
includes/admin/importers/class-seopress-exporter.php
+77
-11
2.5.0
→
2.14.2
View file →
| @@ -140,10 +140,10 @@ | ||
| 140 | 140 | 'object_id' => $post_id, |
| 141 | 141 | 'object_type' => 'post', |
| 142 | 142 | 'source_plugin' => $this->plugin_slug, |
| 143 | 143 | 'data' => [ |
| 144 | - 'seo_title' => $this->convert_template_variables($meta['_seopress_titles_title'] ?? '', $post_id), | |
| 145 | - 'meta_description' => $this->convert_template_variables($meta['_seopress_titles_desc'] ?? '', $post_id), | |
| 144 | + 'seo_title' => $this->convert_post_value($meta['_seopress_titles_title'] ?? '', $post_id), | |
| 145 | + 'meta_description' => $this->convert_post_value($meta['_seopress_titles_desc'] ?? '', $post_id), | |
| 146 | 146 | 'focus_keyword' => $primary_keyword, |
| 147 | 147 | 'focus_keywords' => $focus_keywords, |
| 148 | 148 | 'canonical_url' => $meta['_seopress_robots_canonical'] ?? '', |
| 149 | 149 | 'noindex' => $noindex, |
| @@ -150,13 +150,13 @@ | ||
| 150 | 150 | 'nofollow' => $nofollow, |
| 151 | 151 | 'noarchive' => ($meta['_seopress_robots_archive'] ?? '') === 'yes' ? 1 : 0, |
| 152 | 152 | 'noimageindex' => ($meta['_seopress_robots_imageindex'] ?? '') === 'yes' ? 1 : 0, |
| 153 | 153 | 'nosnippet' => ($meta['_seopress_robots_snippet'] ?? '') === 'yes' ? 1 : 0, |
| 154 | - 'og_title' => $this->convert_template_variables($meta['_seopress_social_fb_title'] ?? '', $post_id), | |
| 155 | - 'og_description' => $this->convert_template_variables($meta['_seopress_social_fb_desc'] ?? '', $post_id), | |
| 154 | + 'og_title' => $this->convert_post_value($meta['_seopress_social_fb_title'] ?? '', $post_id), | |
| 155 | + 'og_description' => $this->convert_post_value($meta['_seopress_social_fb_desc'] ?? '', $post_id), | |
| 156 | 156 | 'og_image' => $meta['_seopress_social_fb_img'] ?? '', |
| 157 | - 'twitter_title' => $this->convert_template_variables($meta['_seopress_social_twitter_title'] ?? '', $post_id), | |
| 158 | - 'twitter_description' => $this->convert_template_variables($meta['_seopress_social_twitter_desc'] ?? '', $post_id), | |
| 157 | + 'twitter_title' => $this->convert_post_value($meta['_seopress_social_twitter_title'] ?? '', $post_id), | |
| 158 | + 'twitter_description' => $this->convert_post_value($meta['_seopress_social_twitter_desc'] ?? '', $post_id), | |
| 159 | 159 | 'twitter_image' => $meta['_seopress_social_twitter_img'] ?? '', |
| 160 | 160 | 'primary_category' => (int) ($meta['_seopress_robots_primary_cat'] ?? 0), |
| 161 | 161 | 'schema_type' => '', |
| 162 | 162 | ], |
| @@ -201,15 +201,15 @@ | ||
| 201 | 201 | 'object_id' => $term_id, |
| 202 | 202 | 'object_type' => 'term', |
| 203 | 203 | 'source_plugin' => $this->plugin_slug, |
| 204 | 204 | 'data' => [ |
| 205 | - 'seo_title' => $this->convert_template_variables($meta['_seopress_titles_title'] ?? ''), | |
| 206 | - 'meta_description' => $this->convert_template_variables($meta['_seopress_titles_desc'] ?? ''), | |
| 205 | + 'seo_title' => $this->convert_term_value($meta['_seopress_titles_title'] ?? ''), | |
| 206 | + 'meta_description' => $this->convert_term_value($meta['_seopress_titles_desc'] ?? ''), | |
| 207 | 207 | 'canonical_url' => $meta['_seopress_robots_canonical'] ?? '', |
| 208 | 208 | 'noindex' => $noindex, |
| 209 | 209 | 'nofollow' => $nofollow, |
| 210 | - 'og_title' => $this->convert_template_variables($meta['_seopress_social_fb_title'] ?? ''), | |
| 211 | - 'og_description' => $this->convert_template_variables($meta['_seopress_social_fb_desc'] ?? ''), | |
| 210 | + 'og_title' => $this->convert_term_value($meta['_seopress_social_fb_title'] ?? ''), | |
| 211 | + 'og_description' => $this->convert_term_value($meta['_seopress_social_fb_desc'] ?? ''), | |
| 212 | 212 | ], |
| 213 | 213 | 'extended' => [ |
| 214 | 214 | 'og_image' => $meta['_seopress_social_fb_img'] ?? '', |
| 215 | 215 | 'twitter_title' => $meta['_seopress_social_twitter_title'] ?? '', |
| @@ -622,8 +622,71 @@ | ||
| 622 | 622 | return $records; |
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | /** |
| 626 | + * SEOPress per-post tokens ThinkRank resolves per request (#886): kept as | |
| 627 | + * tags rather than frozen into text. Mirrors convert_seopress_global_template(). | |
| 628 | + */ | |
| 629 | + private const POST_TOKENS = [ | |
| 630 | + '%%post_title%%' => '%title%', | |
| 631 | + '%%title%%' => '%title%', | |
| 632 | + '%%sitetitle%%' => '%sitename%', | |
| 633 | + '%%sitename%%' => '%sitename%', | |
| 634 | + '%%sep%%' => '%sep%', | |
| 635 | + '%%post_excerpt%%' => '%excerpt%', | |
| 636 | + '%%excerpt%%' => '%excerpt%', | |
| 637 | + '%%post_date%%' => '%date%', | |
| 638 | + '%%post_modified_date%%' => '%modified%', | |
| 639 | + '%%post_author%%' => '%author%', | |
| 640 | + '%%post_category%%' => '%category%', | |
| 641 | + ]; | |
| 642 | + | |
| 643 | + /** | |
| 644 | + * SEOPress per-term tokens ThinkRank resolves on a term archive. The | |
| 645 | + * literal resolver only knows post context, so these were stripped. | |
| 646 | + */ | |
| 647 | + private const TERM_TOKENS = [ | |
| 648 | + '%%term_title%%' => '%term%', | |
| 649 | + '%%_category_title%%' => '%term%', | |
| 650 | + '%%tag_title%%' => '%term%', | |
| 651 | + '%%term_description%%' => '%excerpt%', | |
| 652 | + '%%_category_description%%' => '%excerpt%', | |
| 653 | + '%%tag_description%%' => '%excerpt%', | |
| 654 | + '%%sitetitle%%' => '%sitename%', | |
| 655 | + '%%sitename%%' => '%sitename%', | |
| 656 | + '%%sep%%' => '%sep%', | |
| 657 | + ]; | |
| 658 | + | |
| 659 | + /** | |
| 660 | + * A per-post SEOPress value: mapped tokens as ThinkRank tags, the rest literal. | |
| 661 | + * | |
| 662 | + * @param mixed $value Raw SEOPress value | |
| 663 | + * @param int $post_id Post ID | |
| 664 | + * @return string | |
| 665 | + */ | |
| 666 | + private function convert_post_value($value, int $post_id): string { | |
| 667 | + return $this->tokenize_object_template( | |
| 668 | + $this->stringify_template_value($value), | |
| 669 | + self::literal_token_patterns(self::POST_TOKENS), | |
| 670 | + fn(string $rest): string => $this->convert_template_variables($rest, $post_id) | |
| 671 | + ); | |
| 672 | + } | |
| 673 | + | |
| 674 | + /** | |
| 675 | + * A per-term SEOPress value: mapped tokens as ThinkRank tags, the rest literal. | |
| 676 | + * | |
| 677 | + * @param mixed $value Raw SEOPress value | |
| 678 | + * @return string | |
| 679 | + */ | |
| 680 | + private function convert_term_value($value): string { | |
| 681 | + return $this->tokenize_object_template( | |
| 682 | + $this->stringify_template_value($value), | |
| 683 | + self::literal_token_patterns(self::TERM_TOKENS), | |
| 684 | + fn(string $rest): string => $this->convert_template_variables($rest) | |
| 685 | + ); | |
| 686 | + } | |
| 687 | + | |
| 688 | + /** | |
| 626 | 689 | * {@inheritDoc} |
| 627 | 690 | */ |
| 628 | 691 | protected function convert_template_variables($value, ?int $post_id = null): string { |
| 629 | 692 | // Foreign data first: booleans/arrays in the source plugin's options |
| @@ -651,9 +714,12 @@ | ||
| 651 | 714 | $post = get_post($post_id); |
| 652 | 715 | if ($post) { |
| 653 | 716 | $replacements['%%post_title%%'] = $post->post_title; |
| 654 | 717 | $replacements['%%title%%'] = $post->post_title; |
| 655 | - $replacements['%%post_excerpt%%'] = wp_trim_words($post->post_excerpt ?: wp_trim_words(wp_strip_all_tags($post->post_content), 55), 55); | |
| 718 | + $replacements['%%post_excerpt%%'] = \ThinkRank\Core\Seo_Text::trim_words( | |
| 719 | + $post->post_excerpt ?: \ThinkRank\Core\Seo_Text::trim_words(wp_strip_all_tags($post->post_content), 55), | |
| 720 | + 55 | |
| 721 | + ); | |
| 656 | 722 | $replacements['%%post_date%%'] = get_the_date('', $post); |
| 657 | 723 | $replacements['%%post_modified_date%%'] = get_the_modified_date('', $post); |
| 658 | 724 | $replacements['%%post_author%%'] = get_the_author_meta('display_name', (int) $post->post_author); |
| 659 | 725 | |