| 1 |
<?php |
| 2 |
|
| 3 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Given it's a very specific case. |
| 4 |
namespace Yoast\WP\SEO\Services\Importing\Aioseo; |
| 5 |
|
| 6 |
/** |
| 7 |
* Transforms AISOEO search appearance robot settings. |
| 8 |
* |
| 9 |
* @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded |
| 10 |
*/ |
| 11 |
class Aioseo_Robots_Transformer_Service { |
| 12 |
|
| 13 |
/** |
| 14 |
* The robots transfomer service. |
| 15 |
* |
| 16 |
* @var Aioseo_Robots_Provider_Service |
| 17 |
*/ |
| 18 |
protected $robots_provider; |
| 19 |
|
| 20 |
/** |
| 21 |
* Class constructor. |
| 22 |
* |
| 23 |
* @param Aioseo_Robots_Provider_Service $robots_provider The robots provider service. |
| 24 |
*/ |
| 25 |
public function __construct( |
| 26 |
Aioseo_Robots_Provider_Service $robots_provider |
| 27 |
) { |
| 28 |
$this->robots_provider = $robots_provider; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Transforms the robot setting, taking into consideration whether they defer to global defaults. |
| 33 |
* |
| 34 |
* @param string $setting_name The name of the robot setting, eg. noindex. |
| 35 |
* @param bool $setting_value The value of the robot setting. |
| 36 |
* @param array $mapping The mapping of the setting we're working with. |
| 37 |
* |
| 38 |
* @return bool The transformed robot setting. |
| 39 |
*/ |
| 40 |
public function transform_robot_setting( $setting_name, $setting_value, $mapping ) { |
| 41 |
$aioseo_settings = \json_decode( \get_option( $mapping['option_name'], '' ), true ); |
| 42 |
|
| 43 |
// Let's check first if it defers to global robot settings. |
| 44 |
if ( empty( $aioseo_settings ) || ! isset( $aioseo_settings['searchAppearance'][ $mapping['type'] ][ $mapping['subtype'] ]['advanced']['robotsMeta']['default'] ) ) { |
| 45 |
return $setting_value; |
| 46 |
} |
| 47 |
|
| 48 |
$defers_to_defaults = $aioseo_settings['searchAppearance'][ $mapping['type'] ][ $mapping['subtype'] ]['advanced']['robotsMeta']['default']; |
| 49 |
|
| 50 |
if ( $defers_to_defaults ) { |
| 51 |
return $this->robots_provider->get_global_robot_settings( $setting_name ); |
| 52 |
} |
| 53 |
|
| 54 |
return $setting_value; |
| 55 |
} |
| 56 |
} |
| 57 |
|