PageRenderTime 18ms CodeModel.GetById 12ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/wp-content/plugins/wordpress-seo/inc/class-post-type.php

https://bitbucket.org/carloskikea/helpet
PHP | 93 lines | 31 code | 13 blank | 49 comment | 3 complexity | 975e803e3ee6065775d9d126fe381ece MD5 | raw file
 1<?php
 2/**
 3 * WPSEO plugin file.
 4 *
 5 * @package WPSEO\Inc
 6 */
 7
 8/**
 9 * Represents the post type utils.
10 */
11class 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		$post_types = get_post_types( array( 'public' => true ) );
22
23		/**
24		 * Filter: 'wpseo_accessible_post_types' - Allow changing the accessible post types.
25		 *
26		 * @api array $post_types The public post types.
27		 */
28		$post_types = apply_filters( 'wpseo_accessible_post_types', $post_types );
29
30		// When the array gets messed up somewhere.
31		if ( ! is_array( $post_types ) ) {
32			return array();
33		}
34
35		return $post_types;
36	}
37
38	/**
39	 * Returns whether the passed post type is considered accessible.
40	 *
41	 * @param string $post_type The post type to check.
42	 *
43	 * @return bool Whether or not the post type is considered accessible.
44	 */
45	public static function is_post_type_accessible( $post_type ) {
46		return in_array( $post_type, self::get_accessible_post_types(), true );
47	}
48
49	/**
50	 * Checks if the request post type is public and indexable.
51	 *
52	 * @param string $post_type_name The name of the post type to lookup.
53	 *
54	 * @return bool True when post type is set to index.
55	 */
56	public static function is_post_type_indexable( $post_type_name ) {
57		if ( WPSEO_Options::get( 'disable-' . $post_type_name, false ) ) {
58			return false;
59		}
60
61		return ( false === WPSEO_Options::get( 'noindex-' . $post_type_name, false ) );
62	}
63
64	/**
65	 * Filters the attachment post type from an array with post_types.
66	 *
67	 * @param array $post_types The array to filter the attachment post type from.
68	 *
69	 * @return array The filtered array.
70	 */
71	public static function filter_attachment_post_type( array $post_types ) {
72		unset( $post_types['attachment'] );
73
74		return $post_types;
75	}
76
77	/**
78	 * Checks if the post type is enabled in the REST API.
79	 *
80	 * @param string $post_type The post type to check.
81	 *
82	 * @return bool Whether or not the post type is available in the REST API.
83	 */
84	public static function is_rest_enabled( $post_type ) {
85		$post_type_object = get_post_type_object( $post_type );
86
87		if ( is_null( $post_type_object ) ) {
88			return false;
89		}
90
91		return $post_type_object->show_in_rest === true;
92	}
93}