term = $term;
$this->taxonomy = $taxonomy;
$this->taxonomy_tab_content = new WPSEO_Taxonomy_Fields_Presenter( $this->term );
}
/**
* Shows the Yoast SEO metabox for the term.
*/
public function display() {
$content_sections = $this->get_content_sections();
$product_title = 'Yoast SEO';
if ( file_exists( WPSEO_PATH . 'premium/' ) ) {
$product_title .= ' Premium';
}
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: $product_title is hardcoded.
printf( '
';
}
/**
* Returns the relevant metabox sections for the current view.
*
* @return WPSEO_Metabox_Section[]
*/
private function get_content_sections() {
$content_sections = [];
$content_sections[] = $this->get_seo_meta_section();
$readability_analysis = new WPSEO_Metabox_Analysis_Readability();
if ( $readability_analysis->is_enabled() ) {
$content_sections[] = $this->get_readability_meta_section();
}
$content_sections[] = $this->get_social_meta_section();
return $content_sections;
}
/**
* Returns the metabox section for the content analysis.
*
* @return WPSEO_Metabox_Section
*/
private function get_seo_meta_section() {
$taxonomy_content_fields = new WPSEO_Taxonomy_Content_Fields( $this->term );
$content = $this->taxonomy_tab_content->html( $taxonomy_content_fields->get( $this->term ) );
$seo_analysis = new WPSEO_Metabox_Analysis_SEO();
$label = __( 'SEO', 'wordpress-seo' );
if ( $seo_analysis->is_enabled() ) {
$label = '' . $label;
}
$html_after = '';
if ( WPSEO_Capability_Utils::current_user_can( 'wpseo_edit_advanced_metadata' ) || WPSEO_Options::get( 'disableadvanced_meta' ) === false ) {
$taxonomy_settings_fields = new WPSEO_Taxonomy_Settings_Fields( $this->term );
$advanced_collapsible = new WPSEO_Paper_Presenter(
__( 'Advanced', 'wordpress-seo' ),
null,
[
'collapsible' => true,
'class' => 'metabox wpseo-form wpseo-collapsible-container',
'content' => $this->taxonomy_tab_content->html( $taxonomy_settings_fields->get() ),
'paper_id' => 'collapsible-advanced-settings',
]
);
$html_after = '' . $advanced_collapsible->get_output() . '
';
}
return new WPSEO_Metabox_Section_React(
'content',
$label,
$content,
[
'html_after' => $html_after,
]
);
}
/**
* Returns the metabox section for the readability analysis.
*
* @return WPSEO_Metabox_Section
*/
private function get_readability_meta_section() {
return new WPSEO_Metabox_Section_Readability();
}
/**
* Returns the metabox section for the social settings.
*
* @return WPSEO_Metabox_Section
*/
private function get_social_meta_section() {
$this->taxonomy_social_fields = new WPSEO_Taxonomy_Social_Fields( $this->term );
$this->social_admin = new WPSEO_Social_Admin();
$collapsibles = [];
$collapsibles[] = $this->create_collapsible( 'facebook', 'opengraph', 'facebook-alt', __( 'Facebook', 'wordpress-seo' ) );
$collapsibles[] = $this->create_collapsible( 'twitter', 'twitter', 'twitter', __( 'Twitter', 'wordpress-seo' ) );
return new WPSEO_Metabox_Collapsibles_Sections(
'social',
'' . __( 'Social', 'wordpress-seo' ),
$collapsibles
);
}
/**
* Creates a social network tab.
*
* @param string $name The name of the tab.
* @param string $network The network of the tab.
* @param string $icon The icon for the tab.
* @param string $label The label for the tab.
*
* @return WPSEO_Metabox_Tab A WPSEO_Metabox_Tab instance.
*/
private function create_collapsible( $name, $network, $icon, $label ) {
if ( WPSEO_Options::get( $network ) !== true ) {
return new WPSEO_Metabox_Null_Tab();
}
$meta_fields = $this->taxonomy_social_fields->get_by_network( $network );
$content = $this->taxonomy_tab_content->html( $meta_fields );
/**
* If premium hide the form to show the social preview instead, we still need the fields to be output because
* the values of the social preview are saved in the hidden field.
*/
$features = new WPSEO_Features();
if ( $features->is_premium() ) {
$content = $this->hide_form( $content );
}
$tab_settings = new WPSEO_Metabox_Collapsible(
$name,
$this->social_admin->get_premium_notice( $network ) . $content,
$label
);
return $tab_settings;
}
/**
* Hides the given output when rendered to HTML.
*
* @param string $tab_content The social tab content.
*
* @return string The content.
*/
private function hide_form( $tab_content ) {
return '' . $tab_content . '
';
}
}