PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.2
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.2
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / inc / class-post-type.php

class-post-type.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.2, at inc/class-post-type.php

134 lines 3.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 if ( WPSEO_Options::get( 'disable-attachment' ) === true ) {
55 unset( $post_types['attachment'] );
56 }
57
58 return $post_types;
59 }
60
61 /**
62 * Checks if the post type is enabled in the REST API.
63 *
64 * @param string $post_type The post type to check.
65 *
66 * @return bool Whether or not the post type is available in the REST API.
67 */
68 public static function is_rest_enabled( $post_type ) {
69 $post_type_object = get_post_type_object( $post_type );
70
71 if ( $post_type_object === null ) {
72 return false;
73 }
74
75 return $post_type_object->show_in_rest === true;
76 }
77
78 /**
79 * Checks if the current post type has an archive.
80 *
81 * Context: The has_archive value can be a string or a boolean. In most case it will be a boolean,
82 * but it can be defined as a string. When it is a string the archive_slug will be overwritten to
83 * define another endpoint.
84 *
85 * @param WP_Post_Type $post_type The post type object.
86 *
87 * @return bool True whether the post type has an archive.
88 */
89 public static function has_archive( $post_type ) {
90 return YoastSEO()->helpers->post_type->has_archive( $post_type );
91 }
92
93 /**
94 * Checks if the Yoast Metabox has been enabled for the post type.
95 *
96 * @param string $post_type The post type name.
97 *
98 * @return bool True whether the metabox is enabled.
99 */
100 public static function has_metabox_enabled( $post_type ) {
101 return WPSEO_Options::get( 'display-metabox-pt-' . $post_type, false );
102 }
103
104 /* ********************* DEPRECATED METHODS ********************* */
105
106 /**
107 * Removes the notification related to the post types which have been made public.
108 *
109 * @deprecated 20.10
110 * @codeCoverageIgnore
111 *
112 * @return void
113 */
114 public static function remove_post_types_made_public_notification() {
115 _deprecated_function( __METHOD__, 'Yoast SEO 20.10', 'Content_Type_Visibility_Dismiss_Notifications::dismiss_notifications' );
116 $notification_center = Yoast_Notification_Center::get();
117 $notification_center->remove_notification_by_id( 'post-types-made-public' );
118 }
119
120 /**
121 * Removes the notification related to the taxonomies which have been made public.
122 *
123 * @deprecated 20.10
124 * @codeCoverageIgnore
125 *
126 * @return void
127 */
128 public static function remove_taxonomies_made_public_notification() {
129 _deprecated_function( __METHOD__, 'Yoast SEO 20.10', 'Content_Type_Visibility_Dismiss_Notifications::dismiss_notifications' );
130 $notification_center = Yoast_Notification_Center::get();
131 $notification_center->remove_notification_by_id( 'taxonomies-made-public' );
132 }
133 }
134