/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. * Represents the post type utils.
  9. */
  10. class WPSEO_Post_Type {
  11. /**
  12. * Returns an array with the accessible post types.
  13. *
  14. * An accessible post type is a post type that is public and isn't set as no-index (robots).
  15. *
  16. * @return array Array with all the accessible post_types.
  17. */
  18. public static function get_accessible_post_types() {
  19. $post_types = get_post_types( array( 'public' => true ) );
  20. /**
  21. * Filter: 'wpseo_accessible_post_types' - Allow changing the accessible post types.
  22. *
  23. * @api array $post_types The public post types.
  24. */
  25. $post_types = apply_filters( 'wpseo_accessible_post_types', $post_types );
  26. // When the array gets messed up somewhere.
  27. if ( ! is_array( $post_types ) ) {
  28. return array();
  29. }
  30. return $post_types;
  31. }
  32. /**
  33. * Returns whether the passed post type is considered accessible.
  34. *
  35. * @param string $post_type The post type to check.
  36. *
  37. * @return bool Whether or not the post type is considered accessible.
  38. */
  39. public static function is_post_type_accessible( $post_type ) {
  40. return in_array( $post_type, self::get_accessible_post_types(), true );
  41. }
  42. /**
  43. * Checks if the request post type is public and indexable.
  44. *
  45. * @param string $post_type_name The name of the post type to lookup.
  46. *
  47. * @return bool True when post type is set to index.
  48. */
  49. public static function is_post_type_indexable( $post_type_name ) {
  50. if ( WPSEO_Options::get( 'disable-' . $post_type_name, false ) ) {
  51. return false;
  52. }
  53. return ( false === WPSEO_Options::get( 'noindex-' . $post_type_name, false ) );
  54. }
  55. /**
  56. * Filters the attachment post type from an array with post_types.
  57. *
  58. * @param array $post_types The array to filter the attachment post type from.
  59. *
  60. * @return array The filtered array.
  61. */
  62. public static function filter_attachment_post_type( array $post_types ) {
  63. unset( $post_types['attachment'] );
  64. return $post_types;
  65. }
  66. /**
  67. * Checks if the post type is enabled in the REST API.
  68. *
  69. * @param string $post_type The post type to check.
  70. *
  71. * @return bool Whether or not the post type is available in the REST API.
  72. */
  73. public static function is_rest_enabled( $post_type ) {
  74. $post_type_object = get_post_type_object( $post_type );
  75. if ( is_null( $post_type_object ) ) {
  76. return false;
  77. }
  78. return $post_type_object->show_in_rest === true;
  79. }
  80. }