PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.5
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
wordpress-seo / src / helpers / primary-term-helper.php

primary-term-helper.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.5, at src/helpers/primary-term-helper.php

48 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Helpers;
4
5 use stdClass;
6
7 /**
8 * A helper object for primary terms.
9 */
10 class Primary_Term_Helper {
11
12 /**
13 * Generate the primary term taxonomies.
14 *
15 * @param int $post_id ID of the post.
16 *
17 * @return array The taxonomies.
18 */
19 public function get_primary_term_taxonomies( $post_id ) {
20 $post_type = \get_post_type( $post_id );
21 $all_taxonomies = \get_object_taxonomies( $post_type, 'objects' );
22 $all_taxonomies = \array_filter( $all_taxonomies, [ $this, 'filter_hierarchical_taxonomies' ] );
23
24 /**
25 * Filters which taxonomies for which the user can choose the primary term.
26 *
27 * @param array $taxonomies An array of taxonomy objects that are primary_term enabled.
28 * @param string $post_type The post type for which to filter the taxonomies.
29 * @param array $all_taxonomies All taxonomies for this post types, even ones that don't have primary term
30 * enabled.
31 */
32 $taxonomies = (array) \apply_filters( 'wpseo_primary_term_taxonomies', $all_taxonomies, $post_type, $all_taxonomies );
33
34 return $taxonomies;
35 }
36
37 /**
38 * Returns whether or not a taxonomy is hierarchical.
39 *
40 * @param stdClass $taxonomy Taxonomy object.
41 *
42 * @return bool True for hierarchical taxonomy.
43 */
44 protected function filter_hierarchical_taxonomies( $taxonomy ) {
45 return (bool) $taxonomy->hierarchical;
46 }
47 }
48