PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.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 / editors / framework / site / term-site-information.php

term-site-information.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.5, at src/editors/framework/site/term-site-information.php

106 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong
4 namespace Yoast\WP\SEO\Editors\Framework\Site;
5
6 use WP_Taxonomy;
7 use WP_Term;
8
9 /**
10 * The Term_Site_Information class.
11 */
12 class Term_Site_Information extends Base_Site_Information {
13
14 /**
15 * The taxonomy.
16 *
17 * @var WP_Taxonomy|false
18 */
19 private $taxonomy;
20
21 /**
22 * The term.
23 *
24 * @var WP_Term|string|false
25 */
26 private $term;
27
28 /**
29 * Sets the term for the information object and retrieves its taxonomy.
30 *
31 * @param WP_Term|string|false $term The term.
32 *
33 * @return void
34 */
35 public function set_term( $term ) {
36 $this->term = $term;
37 $this->taxonomy = \get_taxonomy( $term->taxonomy );
38 }
39
40 /**
41 * Returns term specific site information together with the generic site information.
42 *
43 * @return array<string, string|string[]>
44 */
45 public function get_site_information(): array {
46 $data = [
47 'search_url' => $this->search_url(),
48 'post_edit_url' => $this->edit_url(),
49 'base_url' => $this->base_url_for_js(),
50 ];
51
52 return \array_merge_recursive( $data, parent::get_site_information() );
53 }
54
55 /**
56 * Returns term specific site information together with the generic site information.
57 *
58 * @return array<string, array<string, string>>
59 */
60 public function get_legacy_site_information(): array {
61 $data = [
62 'metabox' => [
63 'search_url' => $this->search_url(),
64 'post_edit_url' => $this->edit_url(),
65 'base_url' => $this->base_url_for_js(),
66 ],
67 ];
68
69 return \array_merge_recursive( $data, parent::get_legacy_site_information() );
70 }
71
72 /**
73 * Returns the url to search for keyword for the taxonomy.
74 *
75 * @return string
76 */
77 private function search_url(): string {
78 return \admin_url( 'edit-tags.php?taxonomy=' . $this->term->taxonomy . '&seo_kw_filter={keyword}' );
79 }
80
81 /**
82 * Returns the url to edit the taxonomy.
83 *
84 * @return string
85 */
86 private function edit_url(): string {
87 return \admin_url( 'term.php?action=edit&taxonomy=' . $this->term->taxonomy . '&tag_ID={id}' );
88 }
89
90 /**
91 * Returns a base URL for use in the JS, takes permalink structure into account.
92 *
93 * @return string
94 */
95 private function base_url_for_js(): string {
96 $base_url = \home_url( '/', null );
97 if ( ! $this->options_helper->get( 'stripcategorybase', false ) ) {
98 if ( $this->taxonomy->rewrite ) {
99 $base_url = \trailingslashit( $base_url . $this->taxonomy->rewrite['slug'] );
100 }
101 }
102
103 return $base_url;
104 }
105 }
106