| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Given it's a very specific case. |
| 4 |
namespace Yoast\WP\SEO\Actions\Importing\Aioseo; |
| 5 |
|
| 6 |
/** |
| 7 |
* Importing action for AIOSEO taxonomies settings data. |
| 8 |
*/ |
| 9 |
class Aioseo_Taxonomy_Settings_Importing_Action extends Abstract_Aioseo_Settings_Importing_Action { |
| 10 |
|
| 11 |
/** |
| 12 |
* The plugin of the action. |
| 13 |
*/ |
| 14 |
public const PLUGIN = 'aioseo'; |
| 15 |
|
| 16 |
/** |
| 17 |
* The type of the action. |
| 18 |
*/ |
| 19 |
public const TYPE = 'taxonomy_settings'; |
| 20 |
|
| 21 |
/** |
| 22 |
* The option_name of the AIOSEO option that contains the settings. |
| 23 |
*/ |
| 24 |
public const SOURCE_OPTION_NAME = 'aioseo_options_dynamic'; |
| 25 |
|
| 26 |
/** |
| 27 |
* The map of aioseo_options to yoast settings. |
| 28 |
* |
| 29 |
* @var array |
| 30 |
*/ |
| 31 |
protected $aioseo_options_to_yoast_map = []; |
| 32 |
|
| 33 |
/** |
| 34 |
* The tab of the aioseo settings we're working with. |
| 35 |
* |
| 36 |
* @var string |
| 37 |
*/ |
| 38 |
protected $settings_tab = 'taxonomies'; |
| 39 |
|
| 40 |
/** |
| 41 |
* Additional mapping between AiOSEO replace vars and Yoast replace vars. |
| 42 |
* |
| 43 |
* @see https://yoast.com/help/list-available-snippet-variables-yoast-seo/ |
| 44 |
* |
| 45 |
* @var array |
| 46 |
*/ |
| 47 |
protected $replace_vars_edited_map = [ |
| 48 |
'#breadcrumb_404_error_format' => '', // Empty string, as AIOSEO shows nothing for that tag. |
| 49 |
'#breadcrumb_archive_post_type_format' => '', // Empty string, as AIOSEO shows nothing for that tag. |
| 50 |
'#breadcrumb_archive_post_type_name' => '', // Empty string, as AIOSEO shows nothing for that tag. |
| 51 |
'#breadcrumb_author_display_name' => '', // Empty string, as AIOSEO shows nothing for that tag. |
| 52 |
'#breadcrumb_author_first_name' => '', // Empty string, as AIOSEO shows nothing for that tag. |
| 53 |
'#breadcrumb_blog_page_title' => '', // Empty string, as AIOSEO shows nothing for that tag. |
| 54 |
'#breadcrumb_label' => '', // Empty string, as AIOSEO shows nothing for that tag. |
| 55 |
'#breadcrumb_link' => '', // Empty string, as AIOSEO shows nothing for that tag. |
| 56 |
'#breadcrumb_search_result_format' => '', // Empty string, as AIOSEO shows nothing for that tag. |
| 57 |
'#breadcrumb_search_string' => '', // Empty string, as AIOSEO shows nothing for that tag. |
| 58 |
'#breadcrumb_separator' => '', // Empty string, as AIOSEO shows nothing for that tag. |
| 59 |
'#breadcrumb_taxonomy_title' => '', // Empty string, as AIOSEO shows nothing for that tag. |
| 60 |
'#taxonomy_title' => '%%term_title%%', |
| 61 |
]; |
| 62 |
|
| 63 |
/** |
| 64 |
* Builds the mapping that ties AOISEO option keys with Yoast ones and their data transformation method. |
| 65 |
* |
| 66 |
* @return void |
| 67 |
*/ |
| 68 |
protected function build_mapping() { |
| 69 |
$taxonomy_objects = \get_taxonomies( [ 'public' => true ], 'object' ); |
| 70 |
|
| 71 |
foreach ( $taxonomy_objects as $tax ) { |
| 72 |
// Use all the public taxonomies. |
| 73 |
$this->aioseo_options_to_yoast_map[ '/' . $tax->name . '/title' ] = [ |
| 74 |
'yoast_name' => 'title-tax-' . $tax->name, |
| 75 |
'transform_method' => 'simple_import', |
| 76 |
]; |
| 77 |
$this->aioseo_options_to_yoast_map[ '/' . $tax->name . '/metaDescription' ] = [ |
| 78 |
'yoast_name' => 'metadesc-tax-' . $tax->name, |
| 79 |
'transform_method' => 'simple_import', |
| 80 |
]; |
| 81 |
$this->aioseo_options_to_yoast_map[ '/' . $tax->name . '/advanced/robotsMeta/noindex' ] = [ |
| 82 |
'yoast_name' => 'noindex-tax-' . $tax->name, |
| 83 |
'transform_method' => 'import_noindex', |
| 84 |
'type' => 'taxonomies', |
| 85 |
'subtype' => $tax->name, |
| 86 |
'option_name' => 'aioseo_options_dynamic', |
| 87 |
]; |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Returns a setting map of the robot setting for post category taxonomies. |
| 93 |
* |
| 94 |
* @return array The setting map of the robot setting for post category taxonomies. |
| 95 |
*/ |
| 96 |
public function pluck_robot_setting_from_mapping() { |
| 97 |
$this->build_mapping(); |
| 98 |
|
| 99 |
foreach ( $this->aioseo_options_to_yoast_map as $setting ) { |
| 100 |
// Return the first archive setting map. |
| 101 |
if ( $setting['transform_method'] === 'import_noindex' && isset( $setting['subtype'] ) && $setting['subtype'] === 'category' ) { |
| 102 |
return $setting; |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
return []; |
| 107 |
} |
| 108 |
} |
| 109 |
|