| 1 |
<?php |
| 2 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 3 |
namespace Yoast\WP\SEO\Schema_Aggregator\Infrastructure\Schema_Map; |
| 4 |
|
| 5 |
/** |
| 6 |
* Configuration for the Schema Map. |
| 7 |
*/ |
| 8 |
class Schema_Map_Config { |
| 9 |
|
| 10 |
private const ALLOWED_FREQUENCIES = [ |
| 11 |
'always', |
| 12 |
'hourly', |
| 13 |
'daily', |
| 14 |
'weekly', |
| 15 |
'monthly', |
| 16 |
'yearly', |
| 17 |
'never', |
| 18 |
]; |
| 19 |
|
| 20 |
/** |
| 21 |
* Get changefreq value from configuration |
| 22 |
* |
| 23 |
* @return string Valid changefreq value (always|hourly|daily|weekly|monthly|yearly|never). |
| 24 |
*/ |
| 25 |
public function get_changefreq(): string { |
| 26 |
$changefreq = \apply_filters( 'wpseo_schema_aggregator_schemamap_changefreq', 'daily' ); |
| 27 |
|
| 28 |
if ( ! \in_array( $changefreq, self::ALLOWED_FREQUENCIES, true ) ) { |
| 29 |
return 'daily'; |
| 30 |
} |
| 31 |
|
| 32 |
return $changefreq; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Get priority value from configuration |
| 37 |
* |
| 38 |
* @return string Priority value as string (float between 0.0 and 1.0). |
| 39 |
*/ |
| 40 |
public function get_priority(): string { |
| 41 |
$priority = \apply_filters( 'wpseo_schema_aggregator_schemamap_priority', '0.8' ); |
| 42 |
|
| 43 |
$priority_float = \is_numeric( $priority ) ? (float) $priority : 0.8; |
| 44 |
|
| 45 |
if ( $priority_float < 0.0 || $priority_float > 1.0 ) { |
| 46 |
return '0.8'; |
| 47 |
} |
| 48 |
|
| 49 |
return \number_format( $priority_float, 1, '.', '' ); |
| 50 |
} |
| 51 |
} |
| 52 |
|