| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPSEO plugin file. |
| 4 |
* |
| 5 |
* @package WPSEO\Inc |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Represents the post type utils. |
| 10 |
*/ |
| 11 |
class WPSEO_Post_Type { |
| 12 |
|
| 13 |
/** |
| 14 |
* Returns an array with the accessible post types. |
| 15 |
* |
| 16 |
* An accessible post type is a post type that is public and isn't set as no-index (robots). |
| 17 |
* |
| 18 |
* @return array Array with all the accessible post_types. |
| 19 |
*/ |
| 20 |
public static function get_accessible_post_types() { |
| 21 |
return YoastSEO()->helpers->post_type->get_accessible_post_types(); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Returns whether the passed post type is considered accessible. |
| 26 |
* |
| 27 |
* @param string $post_type The post type to check. |
| 28 |
* |
| 29 |
* @return bool Whether or not the post type is considered accessible. |
| 30 |
*/ |
| 31 |
public static function is_post_type_accessible( $post_type ) { |
| 32 |
return in_array( $post_type, self::get_accessible_post_types(), true ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Checks if the request post type is public and indexable. |
| 37 |
* |
| 38 |
* @param string $post_type_name The name of the post type to lookup. |
| 39 |
* |
| 40 |
* @return bool True when post type is set to index. |
| 41 |
*/ |
| 42 |
public static function is_post_type_indexable( $post_type_name ) { |
| 43 |
return YoastSEO()->helpers->post_type->is_indexable( $post_type_name ); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Filters the attachment post type from an array with post_types. |
| 48 |
* |
| 49 |
* @param array $post_types The array to filter the attachment post type from. |
| 50 |
* |
| 51 |
* @return array The filtered array. |
| 52 |
*/ |
| 53 |
public static function filter_attachment_post_type( array $post_types ) { |
| 54 |
unset( $post_types['attachment'] ); |
| 55 |
|
| 56 |
return $post_types; |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Checks if the post type is enabled in the REST API. |
| 61 |
* |
| 62 |
* @param string $post_type The post type to check. |
| 63 |
* |
| 64 |
* @return bool Whether or not the post type is available in the REST API. |
| 65 |
*/ |
| 66 |
public static function is_rest_enabled( $post_type ) { |
| 67 |
$post_type_object = get_post_type_object( $post_type ); |
| 68 |
|
| 69 |
if ( $post_type_object === null ) { |
| 70 |
return false; |
| 71 |
} |
| 72 |
|
| 73 |
return $post_type_object->show_in_rest === true; |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Checks if the current post type has an archive. |
| 78 |
* |
| 79 |
* Context: The has_archive value can be a string or a boolean. In most case it will be a boolean, |
| 80 |
* but it can be defined as a string. When it is a string the archive_slug will be overwritten to |
| 81 |
* define another endpoint. |
| 82 |
* |
| 83 |
* @param WP_Post_Type $post_type The post type object. |
| 84 |
* |
| 85 |
* @return bool True whether the post type has an archive. |
| 86 |
*/ |
| 87 |
public static function has_archive( $post_type ) { |
| 88 |
return YoastSEO()->helpers->post_type->has_archive( $post_type ); |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Checks if the Yoast Metabox has been enabled for the post type. |
| 93 |
* |
| 94 |
* @param string $post_type The post type name. |
| 95 |
* |
| 96 |
* @return bool True whether the metabox is enabled. |
| 97 |
*/ |
| 98 |
public static function has_metabox_enabled( $post_type ) { |
| 99 |
return WPSEO_Options::get( 'display-metabox-pt-' . $post_type, false ); |
| 100 |
} |
| 101 |
} |
| 102 |
|