| 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 |
use Yoast\WP\SEO\Helpers\Aioseo_Helper; |
| 7 |
|
| 8 |
/** |
| 9 |
* Provides AISOEO search appearance robot settings. |
| 10 |
* |
| 11 |
* @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded |
| 12 |
*/ |
| 13 |
class Aioseo_Robots_Provider_Service { |
| 14 |
|
| 15 |
/** |
| 16 |
* The AIOSEO helper. |
| 17 |
* |
| 18 |
* @var Aioseo_Helper |
| 19 |
*/ |
| 20 |
protected $aioseo_helper; |
| 21 |
|
| 22 |
/** |
| 23 |
* Class constructor. |
| 24 |
* |
| 25 |
* @param Aioseo_Helper $aioseo_helper The AIOSEO helper. |
| 26 |
*/ |
| 27 |
public function __construct( |
| 28 |
Aioseo_Helper $aioseo_helper |
| 29 |
) { |
| 30 |
$this->aioseo_helper = $aioseo_helper; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Retrieves the robot setting set globally in AIOSEO. |
| 35 |
* |
| 36 |
* @param string $setting_name The name of the robot setting, eg. noindex. |
| 37 |
* |
| 38 |
* @return bool Whether global robot settings enable or not the specific setting. |
| 39 |
*/ |
| 40 |
public function get_global_robot_settings( $setting_name ) { |
| 41 |
$aioseo_settings = $this->aioseo_helper->get_global_option(); |
| 42 |
if ( empty( $aioseo_settings ) ) { |
| 43 |
return false; |
| 44 |
} |
| 45 |
|
| 46 |
$global_robot_settings = $aioseo_settings['searchAppearance']['advanced']['globalRobotsMeta']; |
| 47 |
if ( $global_robot_settings['default'] === true ) { |
| 48 |
return false; |
| 49 |
} |
| 50 |
|
| 51 |
return $global_robot_settings[ $setting_name ]; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Gets the subtype's robot setting from the db. |
| 56 |
* |
| 57 |
* @param array $mapping The mapping of the setting we're working with. |
| 58 |
* |
| 59 |
* @return bool The robot setting. |
| 60 |
*/ |
| 61 |
public function get_subtype_robot_setting( $mapping ) { |
| 62 |
$aioseo_settings = \json_decode( \get_option( $mapping['option_name'], '' ), true ); |
| 63 |
|
| 64 |
return $aioseo_settings['searchAppearance'][ $mapping['type'] ][ $mapping['subtype'] ]['advanced']['robotsMeta'][ $mapping['robot_type'] ]; |
| 65 |
} |
| 66 |
} |
| 67 |
|