class-wpseo-custom-taxonomies.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO
  6. */
  7. /**
  8. * WPSEO_Custom_Taxonomies
  9. */
  10. class WPSEO_Custom_Taxonomies {
  11. /**
  12. * @var array Cache the custom taxonomies.
  13. */
  14. protected static $custom_taxonomies = null;
  15. /**
  16. * Gets the names of the custom taxonomies, prepends 'ct_' and 'ct_desc', and returns them in an array.
  17. *
  18. * @return array The custom taxonomy prefixed names.
  19. */
  20. public static function get_custom_taxonomies() {
  21. // Use cached value if available.
  22. if ( ! is_null( self::$custom_taxonomies ) ) {
  23. return self::$custom_taxonomies;
  24. }
  25. self::$custom_taxonomies = array();
  26. $args = array(
  27. 'public' => true,
  28. '_builtin' => false,
  29. );
  30. $custom_taxonomies = get_taxonomies( $args, 'names', 'and' );
  31. if ( is_array( $custom_taxonomies ) ) {
  32. foreach ( $custom_taxonomies as $custom_taxonomy ) {
  33. array_push(
  34. self::$custom_taxonomies,
  35. self::add_custom_taxonomies_prefix( $custom_taxonomy ),
  36. self::add_custom_taxonomies_description_prefix( $custom_taxonomy )
  37. );
  38. }
  39. }
  40. return self::$custom_taxonomies;
  41. }
  42. /**
  43. * Adds the ct_ prefix to a taxonomy.
  44. *
  45. * @param string $taxonomy The taxonomy to prefix.
  46. *
  47. * @return string The prefixed taxonomy.
  48. */
  49. private static function add_custom_taxonomies_prefix( $taxonomy ) {
  50. return 'ct_' . $taxonomy;
  51. }
  52. /**
  53. * Adds the ct_desc_ prefix to a taxonomy.
  54. *
  55. * @param string $taxonomy The taxonomy to prefix.
  56. *
  57. * @return string The prefixed taxonomy.
  58. */
  59. private static function add_custom_taxonomies_description_prefix( $taxonomy ) {
  60. return 'ct_desc_' . $taxonomy;
  61. }
  62. }