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