WPSEO_Replace_Vars::determine_pt_names()
Determine the post type names for the current post/page/cpt.
Метод класса: WPSEO_Replace_Vars{}
Хуков нет.
Возвращает
Строку|null
.
Использование
// private - только в коде основоного (родительского) класса $result = $this->determine_pt_names( $request );
- $request(строка)
- Either 'single'|'plural' - whether to return the single or plural form.
По умолчанию: 'single'
Код WPSEO_Replace_Vars::determine_pt_names() WPSEO Replace Vars::determine pt names Yoast 24.9
private function determine_pt_names( $request = 'single' ) { global $wp_query; $pt_single = null; $pt_plural = null; $post_type = ''; if ( isset( $wp_query->query_vars['post_type'] ) && ( ( is_string( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] !== '' ) || ( is_array( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] !== [] ) ) ) { $post_type = $wp_query->query_vars['post_type']; } elseif ( isset( $this->args->post_type ) && ( is_string( $this->args->post_type ) && $this->args->post_type !== '' ) ) { $post_type = $this->args->post_type; } else { // Make it work in preview mode. $post = $wp_query->get_queried_object(); if ( $post instanceof WP_Post ) { $post_type = $post->post_type; } } if ( is_array( $post_type ) ) { $post_type = reset( $post_type ); } if ( $post_type !== '' ) { $pt = get_post_type_object( $post_type ); $pt_single = $pt->name; $pt_plural = $pt->name; if ( isset( $pt->labels->singular_name ) ) { $pt_single = $pt->labels->singular_name; } if ( isset( $pt->labels->name ) ) { $pt_plural = $pt->labels->name; } } $return = null; switch ( $request ) { case 'single': $return = $pt_single; break; case 'plural': $return = $pt_plural; break; } return $return; }