PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
← All changes | src/helpers/taxonomy-helper.php +65 -0 19.0 → trunk View file →
@@ -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 }