| @@ -29,14 +29,14 @@ | ||
| 29 | 29 | * Taxonomy_Helper constructor. |
| 30 | 30 | * |
| 31 | 31 | * @codeCoverageIgnore It only sets dependencies. |
| 32 | 32 | * |
| 33 | - * @param Options_Helper $options The options helper. | |
| 34 | - * @param String_Helper $string The string helper. | |
| 33 | + * @param Options_Helper $options The options helper. | |
| 34 | + * @param String_Helper $string_helper The string helper. | |
| 35 | 35 | */ |
| 36 | - public function __construct( Options_Helper $options, String_Helper $string ) { | |
| 36 | + public function __construct( Options_Helper $options, String_Helper $string_helper ) { | |
| 37 | 37 | $this->options = $options; |
| 38 | - $this->string = $string; | |
| 38 | + $this->string = $string_helper; | |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * Checks if the requested term is indexable. |
| @@ -112,6 +112,71 @@ | ||
| 112 | 112 | * The type depends on the specified output variable. |
| 113 | 113 | */ |
| 114 | 114 | public function get_custom_taxonomies( $output = 'names' ) { |
| 115 | 115 | return \get_taxonomies( [ '_builtin' => false ], $output ); |
| 116 | + } | |
| 117 | + | |
| 118 | + /** | |
| 119 | + * Returns an array of taxonomies that are excluded from being indexed for the | |
| 120 | + * indexables. | |
| 121 | + * | |
| 122 | + * @return array The excluded taxonomies. | |
| 123 | + */ | |
| 124 | + public function get_excluded_taxonomies_for_indexables() { | |
| 125 | + /** | |
| 126 | + * Filter: 'wpseo_indexable_excluded_taxonomies' - Allow developers to prevent a certain taxonomy | |
| 127 | + * from being saved to the indexable table. | |
| 128 | + * | |
| 129 | + * @param array $excluded_taxonomies The currently excluded taxonomies. | |
| 130 | + */ | |
| 131 | + $excluded_taxonomies = \apply_filters( 'wpseo_indexable_excluded_taxonomies', [] ); | |
| 132 | + | |
| 133 | + // Failsafe, to always make sure that `excluded_taxonomies` is an array. | |
| 134 | + if ( ! \is_array( $excluded_taxonomies ) ) { | |
| 135 | + return []; | |
| 136 | + } | |
| 137 | + | |
| 138 | + return $excluded_taxonomies; | |
| 139 | + } | |
| 140 | + | |
| 141 | + /** | |
| 142 | + * Checks if the taxonomy is excluded. | |
| 143 | + * | |
| 144 | + * @param string $taxonomy The taxonomy to check. | |
| 145 | + * | |
| 146 | + * @return bool If the taxonomy is excluded. | |
| 147 | + */ | |
| 148 | + public function is_excluded( $taxonomy ) { | |
| 149 | + return \in_array( $taxonomy, $this->get_excluded_taxonomies_for_indexables(), true ); | |
| 150 | + } | |
| 151 | + | |
| 152 | + /** | |
| 153 | + * This builds a list of indexable taxonomies. | |
| 154 | + * | |
| 155 | + * @return array The indexable taxonomies. | |
| 156 | + */ | |
| 157 | + public function get_indexable_taxonomies() { | |
| 158 | + $public_taxonomies = $this->get_public_taxonomies(); | |
| 159 | + $excluded_taxonomies = $this->get_excluded_taxonomies_for_indexables(); | |
| 160 | + | |
| 161 | + // `array_values`, to make sure that the keys are reset. | |
| 162 | + return \array_values( \array_diff( $public_taxonomies, $excluded_taxonomies ) ); | |
| 163 | + } | |
| 164 | + | |
| 165 | + /** | |
| 166 | + * Returns an array of complete taxonomy objects for all indexable taxonomies. | |
| 167 | + * | |
| 168 | + * @return array List of indexable indexables objects. | |
| 169 | + */ | |
| 170 | + public function get_indexable_taxonomy_objects() { | |
| 171 | + $taxonomy_objects = []; | |
| 172 | + $indexable_taxonomies = $this->get_indexable_taxonomies(); | |
| 173 | + foreach ( $indexable_taxonomies as $taxonomy ) { | |
| 174 | + $taxonomy_object = \get_taxonomy( $taxonomy ); | |
| 175 | + if ( ! empty( $taxonomy_object ) ) { | |
| 176 | + $taxonomy_objects[ $taxonomy ] = $taxonomy_object; | |
| 177 | + } | |
| 178 | + } | |
| 179 | + | |
| 180 | + return $taxonomy_objects; | |
| 116 | 181 | } |
| 117 | 182 | } |