| @@ -113,5 +113,70 @@ | ||
| 113 | 113 | */ |
| 114 | 114 | public function get_custom_taxonomies( $output = 'names' ) { |
| 115 | 115 | return \get_taxonomies( [ '_builtin' => false ], $output ); |
| 116 | 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; | |
| 181 | + } | |
| 117 | 182 | } |