| 1 |
<?php |
| 2 |
// phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure. |
| 3 |
namespace Yoast\WP\SEO\Schema_Aggregator\Infrastructure; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional; |
| 6 |
use Yoast\WP\SEO\Helpers\Post_Type_Helper; |
| 7 |
/** |
| 8 |
* Configuration for the Schema Aggregator. |
| 9 |
*/ |
| 10 |
class Aggregator_Config { |
| 11 |
/** |
| 12 |
* Default schema types to include (whitelist) |
| 13 |
* |
| 14 |
* @var array<string> |
| 15 |
*/ |
| 16 |
private const DEFAULT_SCHEMA_TYPES = [ |
| 17 |
'Recipe', |
| 18 |
'Article', |
| 19 |
'Product', |
| 20 |
'ProductGroup', |
| 21 |
'Event', |
| 22 |
'Person', |
| 23 |
'Organization', |
| 24 |
'WebSite', |
| 25 |
]; |
| 26 |
|
| 27 |
/** |
| 28 |
* The WooCommerce Conditional. |
| 29 |
* |
| 30 |
* @var WooCommerce_Conditional |
| 31 |
*/ |
| 32 |
private $woocommerce_conditional; |
| 33 |
|
| 34 |
/** |
| 35 |
* The Post Type Helper. |
| 36 |
* |
| 37 |
* @var Post_Type_Helper |
| 38 |
*/ |
| 39 |
private $post_type_helper; |
| 40 |
|
| 41 |
/** |
| 42 |
* Aggregator_Config constructor. |
| 43 |
* |
| 44 |
* @param WooCommerce_Conditional $woocommerce_conditional The WooCommerce Conditional. |
| 45 |
* @param Post_Type_Helper $post_type_helper The Post Type Helper. |
| 46 |
*/ |
| 47 |
public function __construct( WooCommerce_Conditional $woocommerce_conditional, Post_Type_Helper $post_type_helper ) { |
| 48 |
$this->woocommerce_conditional = $woocommerce_conditional; |
| 49 |
$this->post_type_helper = $post_type_helper; |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Get configured post types |
| 54 |
* |
| 55 |
* @return array<string> |
| 56 |
*/ |
| 57 |
public function get_allowed_post_types(): array { |
| 58 |
$default_post_types = $this->post_type_helper->get_indexable_post_types(); |
| 59 |
|
| 60 |
foreach ( $default_post_types as $key => $post_type ) { |
| 61 |
if ( ! $this->post_type_helper->is_indexable( $post_type ) ) { |
| 62 |
unset( $default_post_types[ $key ] ); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
// Reindex the array to avoid gaps. |
| 67 |
$default_post_types = \array_values( $default_post_types ); |
| 68 |
|
| 69 |
$post_types = \apply_filters( 'wpseo_schema_aggregator_post_types', $default_post_types ); |
| 70 |
|
| 71 |
if ( ! \is_array( $post_types ) ) { |
| 72 |
return $default_post_types; |
| 73 |
} |
| 74 |
|
| 75 |
return $post_types; |
| 76 |
} |
| 77 |
} |
| 78 |
|