本文整理匯總了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;
}