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