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 / services / importing / aioseo-replacevar-handler.php

aioseo-replacevar-handler.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.0, at src/services/importing/aioseo-replacevar-handler.php

97 lines 3.1 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\Services\Importing;
4
5 /**
6 * Handles AISOEO replacevars.
7 */
8 class Aioseo_Replacevar_Handler {
9
10 /**
11 * Mapping between the AiOSEO replace vars and the Yoast replace vars.
12 *
13 * @var array
14 *
15 * @see https://yoast.com/help/list-available-snippet-variables-yoast-seo/
16 */
17 protected $replace_vars_map = [
18 // They key is the AiOSEO replace var, the value is the Yoast replace var (see class-wpseo-replace-vars).
19 '#archive_title' => '%%archive_title%%',
20 '#archive_date' => '%%date%%',
21 '#attachment_caption' => '%%caption%%',
22 '#author_bio' => '%%user_description%%',
23 '#author_first_name' => '%%author_first_name%%',
24 '#author_last_name' => '%%author_last_name%%',
25 '#author_name' => '%%name%%',
26 '#categories' => '%%category%%',
27 '#current_date' => '%%currentdate%%',
28 '#current_day' => '%%currentday%%',
29 '#current_month' => '%%currentmonth%%',
30 '#current_year' => '%%currentyear%%',
31 '#parent_title' => '%%parent_title%%',
32 '#page_number' => '%%pagenumber%%',
33 '#permalink' => '%%permalink%%',
34 '#post_content' => '%%post_content%%',
35 '#post_date' => '%%date%%',
36 '#post_day' => '%%post_day%%',
37 '#post_month' => '%%post_month%%',
38 '#post_title' => '%%title%%',
39 '#post_year' => '%%post_year%%',
40 '#post_excerpt_only' => '%%excerpt_only%%',
41 '#post_excerpt' => '%%excerpt%%',
42 '#search_term' => '%%searchphrase%%',
43 '#separator_sa' => '%%sep%%',
44 '#site_title' => '%%sitename%%',
45 '#tagline' => '%%sitedesc%%',
46 '#taxonomy_title' => '%%category_title%%',
47 '#taxonomy_description' => '%%term_description%%',
48 ];
49
50 /**
51 * Edits the replace_vars map of the class.
52 *
53 * @param string $aioseo_var The AIOSEO replacevar.
54 * @param string $yoast_var The Yoast replacevar.
55 *
56 * @return void.
57 */
58 public function compose_map( $aioseo_var, $yoast_var ) {
59 $map = $this->replace_vars_map;
60
61 $map[ $aioseo_var ] = $yoast_var;
62
63 $this->replace_vars_map = $map;
64 }
65
66 /**
67 * Transforms AIOSEO replacevars into Yoast replacevars.
68 *
69 * @param string $aioseo_replacevar The AIOSEO replacevar.
70 *
71 * @return string The Yoast replacevar.
72 */
73 public function transform( $aioseo_replacevar ) {
74 $yoast_replacevar = \str_replace( \array_keys( $this->replace_vars_map ), \array_values( $this->replace_vars_map ), $aioseo_replacevar );
75
76 // Transform the '#custom_field-<custom_field>' tags into '%%cf_<custom_field>%%' ones.
77 $yoast_replacevar = preg_replace_callback(
78 '/#custom_field-([a-zA-Z0-9_-]+)/',
79 function ( $cf_matches ) {
80 return '%%cf_' . $cf_matches[1] . '%%';
81 },
82 $yoast_replacevar
83 );
84
85 // Transform the '#tax_name-<custom-tax-name>' tags into '%%ct_<custom-tax-name>%%' ones.
86 $yoast_replacevar = preg_replace_callback(
87 '/#tax_name-([a-zA-Z0-9_-]+)/',
88 function ( $ct_matches ) {
89 return '%%ct_' . $ct_matches[1] . '%%';
90 },
91 $yoast_replacevar
92 );
93
94 return $yoast_replacevar;
95 }
96 }
97