本文整理汇总了PHP中Translations::to_array方法的典型用法代码示例。如果您正苦于以下问题:PHP Translations::to_array方法的具体用法?PHP Translations::to_array怎么用?PHP Translations::to_array使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Translations
的用法示例。
在下文中一共展示了Translations::to_array方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* Renders an alternate language HTML link tag for each available translation into the HTML head.
*
* @since 3.0.0
* @wp-hook wp_head
*
* @return bool Whether or not headers have been sent.
*/
public function render()
{
$translations = $this->translations->to_array();
if (!$translations) {
return false;
}
array_walk($translations, function ($url, $language) {
$html_link_tag = sprintf('<link rel="alternate" hreflang="%1$s" href="%2$s">', esc_attr($language), esc_url($url));
/**
* Filters the output of the hreflang links in the HTML head.
*
* @since 3.0.0
*
* @param string $html_link_tag Alternate language HTML link tag.
* @param string $language HTTP language code (e.g., "en-US").
* @param string $url Target URL.
*/
echo apply_filters('multilingualpress.hreflang_html_link_tag', $html_link_tag, $language, $url);
});
return true;
}
示例2: send
/**
* Sends an alternate language HTTP header for each available translation.
*
* @since 3.0.0
* @wp-hook template_redirect
*
* @return bool Whether or not headers have been sent.
*/
public function send()
{
$translations = $this->translations->to_array();
if (!$translations) {
return false;
}
array_walk($translations, function ($url, $language) {
$header = sprintf('Link: <%1$s>; rel="alternate"; hreflang="%2$s"', esc_url($url), esc_attr($language));
/**
* Filters the output of the hreflang links in the HTTP header.
*
* @since 3.0.0
*
* @param string $header Alternate language HTTP header.
* @param string $language HTTP language code (e.g., "en-US").
* @param string $url Target URL.
*/
$header = (string) apply_filters('multilingualpress.hreflang_http_header', $header, $language, $url);
if ($header) {
header($header, false);
}
});
return true;
}