sitepress = $sitepress; } private function get_seo_settings() { $seo_settings = $this->sitepress->get_setting( 'seo', array() ); if ( ! array_key_exists( 'head_langs', $seo_settings ) ) { $seo_settings['head_langs'] = 1; } if ( ! array_key_exists( 'head_langs_priority', $seo_settings ) ) { $seo_settings['head_langs_priority'] = 1; } return $seo_settings; } public function init_hooks() { if ( $this->sitepress->get_wp_api()->is_front_end() ) { $seo_settings = $this->get_seo_settings(); $head_langs = $seo_settings['head_langs']; if ( $head_langs ) { $priority = $seo_settings['head_langs_priority']; add_action( 'wp_head', array( $this, 'head_langs' ), $priority ); } } } function head_langs() { $languages = $this->sitepress->get_ls_languages( array( 'skip_missing' => true ) ); $languages = apply_filters( 'wpml_head_langs', $languages ); if ( $this->must_render( $languages ) ) { $hreflang_items = array(); foreach ( $languages as $lang ) { $alternate_hreflang = apply_filters( 'wpml_alternate_hreflang', $lang['url'], $lang['code'] ); $hreflang_code = $this->get_hreflang_code( $lang ); if ( $hreflang_code ) { $hreflang_items[ $hreflang_code ] = str_replace( '&', '&', $alternate_hreflang ); } } $hreflang_items = apply_filters( 'wpml_hreflangs', $hreflang_items ); $hreflang = ''; if ( is_array( $hreflang_items ) ) { foreach ( $hreflang_items as $hreflang_code => $hreflang_url ) { $hreflang .= '' . PHP_EOL; } echo apply_filters( 'wpml_hreflangs_html', $hreflang ); } } } function render_menu() { $seo = $this->get_seo_settings(); $options = array(); foreach ( array( 1, 10 ) as $priority ) { $label = __( 'As early as possible', 'sitepress' ); if ( $priority > 1 ) { $label = sprintf( esc_html__( 'Later in the head section (priority %d)', 'sitepress' ), $priority ); } $options[ $priority ] = array( 'selected' => ( $priority == $seo['head_langs_priority'] ), 'label' => $label, ); } ?>

value="1"/>

sitepress->get_wp_api()->get_post(); if ( $post ) { $post_id = $post ? $post->ID : false; $has_languages = is_array( $languages ) && count( $languages ) > 0 && $this->sitepress->is_translated_post_type( $post->post_type ); $is_single_or_page = $this->sitepress->get_wp_api()->is_single() || $this->sitepress->get_wp_api()->is_page(); $is_published = $is_single_or_page && $post_id && $this->sitepress->get_wp_api()->get_post_status( $post_id ) === 'publish'; } return $has_languages && ! $this->sitepress->get_wp_api()->is_paged() && ( $is_published || ( $this->sitepress->get_wp_api()->is_home() || $this->sitepress->get_wp_api()->is_front_page() || $this->sitepress->get_wp_api()->is_archive() ) ); } /** * @param array $lang * * @return string */ private function get_hreflang_code( $lang ) { $ordered_keys = array( 'tag', 'default_locale' ); $hreflang_code = ''; foreach ( $ordered_keys as $key ) { if ( array_key_exists( $key, $lang ) && trim( $lang[ $key ] ) ) { $hreflang_code = $lang[ $key ]; break; } } $hreflang_code = strtolower( str_replace( '_', '-', $hreflang_code ) ); if ( $this->is_valid_hreflang_code( $hreflang_code ) ) { return trim( $hreflang_code ); } return ''; } private function is_valid_hreflang_code( $code ) { return strlen( trim( $code ) ) >= 2; } }