| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Integrations; |
| 4 |
|
| 5 |
/** |
| 6 |
* Abstract class for excluding certain post types from being indexed. |
| 7 |
* |
| 8 |
* @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded |
| 9 |
*/ |
| 10 |
abstract class Abstract_Exclude_Post_Type implements Integration_Interface { |
| 11 |
|
| 12 |
/** |
| 13 |
* Initializes the integration. |
| 14 |
*/ |
| 15 |
public function register_hooks() { |
| 16 |
\add_filter( 'wpseo_indexable_excluded_post_types', [ $this, 'exclude_post_types' ] ); |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* Exclude the post type from the indexable table. |
| 21 |
* |
| 22 |
* @param array $excluded_post_types The excluded post types. |
| 23 |
* |
| 24 |
* @return array The excluded post types, including the specific post type. |
| 25 |
*/ |
| 26 |
public function exclude_post_types( $excluded_post_types ) { |
| 27 |
return \array_merge( $excluded_post_types, $this->get_post_type() ); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* This integration is only active when the child class's conditionals are met. |
| 32 |
* |
| 33 |
* @return array|string[] The conditionals. |
| 34 |
*/ |
| 35 |
public static function get_conditionals() { |
| 36 |
return []; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Returns the names of the post types to be excluded. |
| 41 |
* To be used in the wpseo_indexable_excluded_post_types filter. |
| 42 |
* |
| 43 |
* @return array The names of the post types. |
| 44 |
*/ |
| 45 |
abstract public function get_post_type(); |
| 46 |
} |
| 47 |
|