| 1 |
<?php |
| 2 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 3 |
namespace Yoast\WP\SEO\Schema_Aggregator\Infrastructure\Enhancement; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Schema_Aggregator\Domain\Enhancement\Enhancement_Config_Interface; |
| 6 |
|
| 7 |
/** |
| 8 |
* The article config. |
| 9 |
*/ |
| 10 |
class Article_Config implements Enhancement_Config_Interface { |
| 11 |
|
| 12 |
public const DEFAULT_MAX_ARTICLE_BODY_LENGTH = 500; |
| 13 |
|
| 14 |
/** |
| 15 |
* Get configuration value |
| 16 |
* |
| 17 |
* @param string $key Configuration key. |
| 18 |
* @param string|int|bool $the_default Default value. |
| 19 |
* |
| 20 |
* @return string|int|bool Configuration value. |
| 21 |
*/ |
| 22 |
public function get_config_value( string $key, $the_default ) { |
| 23 |
return \apply_filters( "wpseo_article_enhance_config_{$key}", $the_default ); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Check if enhancement is enabled |
| 28 |
* |
| 29 |
* @param string $enhancement Enhancement name (e.g., 'article_body', 'keywords'). |
| 30 |
* |
| 31 |
* @return bool True if enabled. |
| 32 |
*/ |
| 33 |
public function is_enhancement_enabled( string $enhancement ): bool { |
| 34 |
$defaults = [ |
| 35 |
'article_body' => true, |
| 36 |
'use_excerpt' => true, |
| 37 |
'keywords' => true, |
| 38 |
]; |
| 39 |
|
| 40 |
$default = ( $defaults[ $enhancement ] ?? false ); |
| 41 |
|
| 42 |
return (bool) \apply_filters( "wpseo_article_enhance_{$enhancement}", $default ); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Determine if articleBody should be included |
| 47 |
* |
| 48 |
* Decision logic: |
| 49 |
* - If has excerpt AND article_body_when_excerpt_exists: include |
| 50 |
* - If no excerpt AND article_body_fallback: include |
| 51 |
* - Otherwise: skip |
| 52 |
* |
| 53 |
* @param bool $has_excerpt Whether post has valid excerpt. |
| 54 |
* |
| 55 |
* @return bool True if articleBody should be included. |
| 56 |
*/ |
| 57 |
public function should_include_article_body( bool $has_excerpt ): bool { |
| 58 |
if ( $has_excerpt ) { |
| 59 |
return (bool) \apply_filters( 'wpseo_article_enhance_body_when_excerpt_exists', false ); |
| 60 |
} |
| 61 |
|
| 62 |
return (bool) \apply_filters( 'wpseo_article_enhance_article_body_fallback', true ); |
| 63 |
} |
| 64 |
} |
| 65 |
|