|bool|int>
*/
public function get_metabox_script_data() {
$permalink = $this->get_permalink();
$post_formatter = new WPSEO_Metabox_Formatter(
new WPSEO_Post_Metabox_Formatter( $this->get_metabox_post(), [], $permalink )
);
$values = $post_formatter->get_values();
/** This filter is documented in admin/filters/class-cornerstone-filter.php. */
$post_types = apply_filters( 'wpseo_cornerstone_post_types', WPSEO_Post_Type::get_accessible_post_types() );
if ( $values['cornerstoneActive'] && ! in_array( $this->get_metabox_post()->post_type, $post_types, true ) ) {
$values['cornerstoneActive'] = false;
}
if ( $values['semrushIntegrationActive'] && $this->post->post_type === 'attachment' ) {
$values['semrushIntegrationActive'] = 0;
}
if ( $values['wincherIntegrationActive'] && $this->post->post_type === 'attachment' ) {
$values['wincherIntegrationActive'] = 0;
}
return $values;
}
/**
* Determines whether or not the current post type has registered taxonomies.
*
* @return bool Whether the current post type has taxonomies.
*/
private function current_post_type_has_taxonomies() {
$post_taxonomies = get_object_taxonomies( get_post_type() );
return ! empty( $post_taxonomies );
}
/**
* Determines the scope based on the post type.
* This can be used by the replacevar plugin to determine if a replacement needs to be executed.
*
* @return string String describing the current scope.
*/
private function determine_scope() {
if ( $this->get_metabox_post()->post_type === 'page' ) {
return 'page';
}
return 'post';
}
/**
* Outputs the meta box.
*
* @return void
*/
public function meta_box() {
$this->render_hidden_fields();
$this->render_tabs();
}
/**
* Renders the metabox hidden fields.
*
* @return void
*/
protected function render_hidden_fields() {
wp_nonce_field( 'yoast_free_metabox', 'yoast_free_metabox_nonce' );
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output escaped in class.
echo new Meta_Fields_Presenter( $this->get_metabox_post(), 'general' );
if ( $this->is_advanced_metadata_enabled ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output escaped in class.
echo new Meta_Fields_Presenter( $this->get_metabox_post(), 'advanced' );
}
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output escaped in class.
echo new Meta_Fields_Presenter( $this->get_metabox_post(), 'schema', $this->get_metabox_post()->post_type );
if ( $this->social_is_enabled ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output escaped in class.
echo new Meta_Fields_Presenter( $this->get_metabox_post(), 'social' );
}
/**
* Filter: 'wpseo_content_meta_section_content' - Allow filtering the metabox content before outputting.
*
* @param string $post_content The metabox content string.
*/
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output should be escaped in the filter.
echo apply_filters( 'wpseo_content_meta_section_content', '' );
}
/**
* Renders the metabox tabs.
*
* @return void
*/
protected function render_tabs() {
echo '';
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Reason: $this->get_product_title() returns a hard-coded string.
printf( '';
foreach ( $tabs as $tab ) {
$tab->display_content();
}
echo '
';
}
/**
* Returns the relevant metabox tabs for the current view.
*
* @return WPSEO_Metabox_Section[]
*/
private function get_tabs() {
$tabs = [];
$label = __( 'SEO', 'wordpress-seo' );
if ( $this->seo_analysis->is_enabled() ) {
$label = '' . $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_advanced_metadata_enabled ) {
$tabs[] = new WPSEO_Metabox_Section_React(
'schema',
'' . __( 'Schema', 'wordpress-seo' ),
''
);
}
if ( $this->social_is_enabled ) {
$tabs[] = new WPSEO_Metabox_Section_React(
'social',
'' . __( 'Social', 'wordpress-seo' ),
'',
[
'html_after' => '',
]
);
}
$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_metabox_sections'.
*
* Meant for internal use only. Allows adding additional tabs to the Yoast SEO metabox.
*
* @since 11.9
*
* @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_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;
}
/**
* Adds a line in the meta box.
*
* @deprecated 23.5
* @codeCoverageIgnore
*
* @param string[] $meta_field_def Contains the vars based on which output is generated.
* @param string $key Internal key (without prefix).
*
* @return string
*/
public function do_meta_box( $meta_field_def, $key = '' ) {
_deprecated_function( __METHOD__, 'Yoast SEO 23.5' );
$content = '';
$esc_form_key = esc_attr( WPSEO_Meta::$form_prefix . $key );
$meta_value = WPSEO_Meta::get_value( $key, $this->get_metabox_post()->ID );
$class = '';
if ( isset( $meta_field_def['class'] ) && $meta_field_def['class'] !== '' ) {
$class = ' ' . $meta_field_def['class'];
}
$placeholder = '';
if ( isset( $meta_field_def['placeholder'] ) && $meta_field_def['placeholder'] !== '' ) {
$placeholder = $meta_field_def['placeholder'];
}
$aria_describedby = '';
$description = '';
if ( isset( $meta_field_def['description'] ) ) {
$aria_describedby = ' aria-describedby="' . $esc_form_key . '-desc"';
$description = '' . $meta_field_def['description'] . '
';
}
// Add a hide_on_pages option that returns nothing when the field is rendered on a page.
if ( isset( $meta_field_def['hide_on_pages'] ) && $meta_field_def['hide_on_pages'] && get_post_type() === 'page' ) {
return '';
}
switch ( $meta_field_def['type'] ) {
case 'text':
$ac = '';
if ( isset( $meta_field_def['autocomplete'] ) && $meta_field_def['autocomplete'] === false ) {
$ac = 'autocomplete="off" ';
}
if ( $placeholder !== '' ) {
$placeholder = ' placeholder="' . esc_attr( $placeholder ) . '"';
}
$content .= '';
break;
case 'url':
if ( $placeholder !== '' ) {
$placeholder = ' placeholder="' . esc_attr( $placeholder ) . '"';
}
$content .= '';
break;
case 'textarea':
$rows = 3;
if ( isset( $meta_field_def['rows'] ) && $meta_field_def['rows'] > 0 ) {
$rows = $meta_field_def['rows'];
}
$content .= '