WPSEO_Meta::get_meta_field_defs
Retrieve the meta box form field definitions for the given tab and post type.
Метод класса: WPSEO_Meta{}
Хуки из метода
Возвращает
Массив. Array containing the meta box field definitions.
Использование
$result = WPSEO_Meta::get_meta_field_defs( $tab, $post_type );
- $tab(строка) (обязательный)
- Tab for which to retrieve the field definitions.
- $post_type(строка)
- Post type of the current post.
По умолчанию:'post'
Код WPSEO_Meta::get_meta_field_defs() WPSEO Meta::get meta field defs Yoast 27.6
public static function get_meta_field_defs( $tab, $post_type = 'post' ) {
if ( ! isset( self::$meta_fields[ $tab ] ) ) {
return [];
}
$field_defs = self::$meta_fields[ $tab ];
switch ( $tab ) {
case 'non-form':
// Prevent non-form fields from being passed to forms.
$field_defs = [];
break;
case 'advanced':
global $post;
if ( ! WPSEO_Capability_Utils::current_user_can( 'wpseo_edit_advanced_metadata' ) && WPSEO_Options::get( 'disableadvanced_meta' ) ) {
return [];
}
$post_type = '';
if ( isset( $post->post_type ) ) {
$post_type = $post->post_type;
}
elseif ( ! isset( $post->post_type ) && isset( $_GET['post_type'] ) ) {
$post_type = sanitize_text_field( $_GET['post_type'] );
}
if ( $post_type === '' ) {
return [];
}
/* Don't show the breadcrumb title field if breadcrumbs aren't enabled. */
if ( WPSEO_Options::get( 'breadcrumbs-enable', false ) !== true && ! current_theme_supports( 'yoast-seo-breadcrumbs' ) ) {
unset( $field_defs['bctitle'] );
}
if ( empty( $post->ID ) || ( ! empty( $post->ID ) && self::get_value( 'redirect', $post->ID ) === '' ) ) {
unset( $field_defs['redirect'] );
}
break;
case 'schema':
if ( ! WPSEO_Capability_Utils::current_user_can( 'wpseo_edit_advanced_metadata' ) && WPSEO_Options::get( 'disableadvanced_meta' ) ) {
return [];
}
$field_defs['schema_page_type']['default'] = WPSEO_Options::get( 'schema-page-type-' . $post_type );
$article_helper = new Article_Helper();
if ( $article_helper->is_article_post_type( $post_type ) ) {
$default_schema_article_type = WPSEO_Options::get( 'schema-article-type-' . $post_type );
/** This filter is documented in inc/options/class-wpseo-option-titles.php */
$allowed_article_types = apply_filters( 'wpseo_schema_article_types', Schema_Types::ARTICLE_TYPES );
if ( ! array_key_exists( $default_schema_article_type, $allowed_article_types ) ) {
$default_schema_article_type = WPSEO_Options::get_default( 'wpseo_titles', 'schema-article-type-' . $post_type );
}
$field_defs['schema_article_type']['default'] = $default_schema_article_type;
}
else {
unset( $field_defs['schema_article_type'] );
}
break;
}
/**
* Filter the WPSEO metabox form field definitions for a tab.
* {tab} can be 'general', 'advanced' or 'social'.
*
* @param array $field_defs Metabox form field definitions.
* @param string $post_type Post type of the post the metabox is for, defaults to 'post'.
*
* @return array
*/
return apply_filters( 'wpseo_metabox_entries_' . $tab, $field_defs, $post_type );
}