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
wordpress-seo / admin / taxonomy / class-taxonomy-metabox.php

class-taxonomy-metabox.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI trunk, at admin/taxonomy/class-taxonomy-metabox.php

229 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPSEO plugin file.
4 *
5 * @package WPSEO\Admin
6 */
7
8 /**
9 * This class generates the metabox on the edit term page.
10 */
11 class WPSEO_Taxonomy_Metabox {
12
13 /**
14 * The term currently being edited.
15 *
16 * @var WP_Term
17 */
18 private $term;
19
20 /**
21 * The term's taxonomy.
22 *
23 * @var string
24 */
25 private $taxonomy;
26
27 /**
28 * Whether or not the social tab is enabled for this metabox.
29 *
30 * @var bool
31 */
32 private $is_social_enabled;
33
34 /**
35 * Helper to determine whether or not the SEO analysis is enabled.
36 *
37 * @var WPSEO_Metabox_Analysis_SEO
38 */
39 protected $seo_analysis;
40
41 /**
42 * Helper to determine whether or not the readability analysis is enabled.
43 *
44 * @var WPSEO_Metabox_Analysis_Readability
45 */
46 protected $readability_analysis;
47
48 /**
49 * Helper to determine whether or not the inclusive language analysis is enabled.
50 *
51 * @var WPSEO_Metabox_Analysis_Inclusive_Language
52 */
53 protected $inclusive_language_analysis;
54
55 /**
56 * The constructor.
57 *
58 * @param string $taxonomy The taxonomy.
59 * @param stdClass $term The term.
60 */
61 public function __construct( $taxonomy, $term ) {
62 $this->term = $term;
63 $this->taxonomy = $taxonomy;
64 $this->is_social_enabled = WPSEO_Options::get( 'opengraph', false ) || WPSEO_Options::get( 'twitter', false );
65
66 $this->seo_analysis = new WPSEO_Metabox_Analysis_SEO();
67 $this->readability_analysis = new WPSEO_Metabox_Analysis_Readability();
68 $this->inclusive_language_analysis = new WPSEO_Metabox_Analysis_Inclusive_Language();
69 }
70
71 /**
72 * Shows the Yoast SEO metabox for the term.
73 *
74 * @return void
75 */
76 public function display() {
77 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: $this->get_product_title() returns a hard-coded string.
78 printf( '<div id="wpseo_meta" class="postbox yoast wpseo-taxonomy-metabox-postbox"><h2><span>%1$s</span></h2>', $this->get_product_title() );
79
80 echo '<div class="inside">';
81
82 $this->render_hidden_fields();
83 $this->render_tabs();
84
85 echo '</div>';
86 echo '</div>';
87 }
88
89 /**
90 * Renders the metabox hidden fields.
91 *
92 * @return void
93 */
94 protected function render_hidden_fields() {
95 $fields_presenter = new WPSEO_Taxonomy_Fields_Presenter( $this->term );
96 $field_definitions = new WPSEO_Taxonomy_Fields();
97
98 echo $fields_presenter->html( $field_definitions->get( 'content' ) );
99 if ( WPSEO_Capability_Utils::current_user_can( 'wpseo_edit_advanced_metadata' ) || WPSEO_Options::get( 'disableadvanced_meta' ) === false ) {
100 echo $fields_presenter->html( $field_definitions->get( 'settings' ) );
101 }
102
103 if ( $this->is_social_enabled ) {
104 echo $fields_presenter->html( $field_definitions->get( 'social' ) );
105 }
106 }
107
108 /**
109 * Renders the metabox tabs.
110 *
111 * @return void
112 */
113 protected function render_tabs() {
114 echo '<div class="wpseo-metabox-content">';
115 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: $this->get_product_title() returns a hard-coded string.
116 printf( '<div class="wpseo-metabox-menu"><ul role="tablist" class="yoast-aria-tabs" aria-label="%s">', $this->get_product_title() );
117
118 $tabs = $this->get_tabs();
119
120 foreach ( $tabs as $tab ) {
121 $tab->display_link();
122 }
123
124 echo '</ul></div>';
125
126 foreach ( $tabs as $tab ) {
127 $tab->display_content();
128 }
129
130 echo '</div>';
131 }
132
133 /**
134 * Returns the relevant metabox sections for the current view.
135 *
136 * @return WPSEO_Metabox_Section[]
137 */
138 private function get_tabs() {
139 $tabs = [];
140
141 $label = __( 'SEO', 'wordpress-seo' );
142 if ( $this->seo_analysis->is_enabled() ) {
143 $label = '<span class="wpseo-score-icon-container" id="wpseo-seo-score-icon"></span>' . $label;
144 }
145
146 $tabs[] = new WPSEO_Metabox_Section_React( 'content', $label );
147
148 if ( $this->readability_analysis->is_enabled() ) {
149 $tabs[] = new WPSEO_Metabox_Section_Readability();
150 }
151
152 if ( $this->inclusive_language_analysis->is_enabled() ) {
153 $tabs[] = new WPSEO_Metabox_Section_Inclusive_Language();
154 }
155
156 if ( $this->is_social_enabled ) {
157 $tabs[] = new WPSEO_Metabox_Section_React(
158 'social',
159 '<span class="dashicons dashicons-share"></span>' . __( 'Social', 'wordpress-seo' ),
160 '',
161 [
162 'html_after' => '<div id="wpseo-section-social"></div>',
163 ],
164 );
165 }
166
167 $tabs = array_merge( $tabs, $this->get_additional_tabs() );
168
169 return $tabs;
170 }
171
172 /**
173 * Returns the metabox tabs that have been added by other plugins.
174 *
175 * @return WPSEO_Metabox_Section_Additional[]
176 */
177 protected function get_additional_tabs() {
178 $tabs = [];
179
180 /**
181 * Private filter: 'yoast_free_additional_taxonomy_metabox_sections'.
182 *
183 * Meant for internal use only. Allows adding additional tabs to the Yoast SEO metabox for taxonomies.
184 *
185 * @param array[] $tabs {
186 * An array of arrays with tab specifications.
187 *
188 * @type array $tab {
189 * A tab specification.
190 *
191 * @type string $name The name of the tab. Used in the HTML IDs, href and aria properties.
192 * @type string $link_content The content of the tab link.
193 * @type string $content The content of the tab.
194 * @type array $options {
195 * Optional. Extra options.
196 *
197 * @type string $link_class Optional. The class for the tab link.
198 * @type string $link_aria_label Optional. The aria label of the tab link.
199 * }
200 * }
201 * }
202 */
203 $requested_tabs = apply_filters( 'yoast_free_additional_taxonomy_metabox_sections', [] );
204
205 foreach ( $requested_tabs as $tab ) {
206 if ( is_array( $tab ) && array_key_exists( 'name', $tab ) && array_key_exists( 'link_content', $tab ) && array_key_exists( 'content', $tab ) ) {
207 $options = array_key_exists( 'options', $tab ) ? $tab['options'] : [];
208 $tabs[] = new WPSEO_Metabox_Section_Additional(
209 $tab['name'],
210 $tab['link_content'],
211 $tab['content'],
212 $options,
213 );
214 }
215 }
216
217 return $tabs;
218 }
219
220 /**
221 * Retrieves the product title.
222 *
223 * @return string The product title.
224 */
225 protected function get_product_title() {
226 return YoastSEO()->helpers->product->get_product_name();
227 }
228 }
229