wp_dashboard_events_news()
概述
wp_dashboard_events_news() 函数用于渲染 WordPress 仪表盘中的“事件和新闻”小工具。它输出社区事件标记和包含 Meetups、WordCamps、新闻链接的 HTML 结构。
关键要点
- 函数 wp_dashboard_events_news() 在 WordPress 4.8.0 版本引入,位于 wp-admin/includes/dashboard.php 文件中。
- 它调用 wp_print_community_events_markup() 来打印社区事件部分的标记。
- 输出包含三个链接:Meetups、WordCamps 和 News,分别指向相关页面,使用 __() 和 _x() 进行国际化翻译,esc_url() 清理 URL。
- 函数是 wp_dashboard_primary() 的一部分,用于构建“WordPress 事件和新闻”仪表盘小工具。
代码示例
注意事项
- 函数依赖于 JavaScript(hide-if-no-js 类),确保在启用 JS 的环境中正常工作。
- 链接使用 target="_blank" 在新标签页打开,并包含屏幕阅读器文本以提高可访问性。
- URL 处理使用 esc_url() 防止 XSS 攻击,翻译函数确保多语言支持。
Renders the Events and News dashboard widget.
Source
function wp_dashboard_events_news() {
wp_print_community_events_markup();
?>
<div class="wordpress-news hide-if-no-js">
</div>
<p class="community-events-footer">
%2$s <span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
'https://make.wordpress.org/community/meetups-landing-page',
__( 'Meetups' ),
/* translators: Hidden accessibility text. */
__( '(opens in a new tab)' )
);
?>
|
%2$s <span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
'https://central.wordcamp.org/schedule/',
__( 'WordCamps' ),
/* translators: Hidden accessibility text. */
__( '(opens in a new tab)' )
);
?>
|
%2$s <span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
/* translators: If a Rosetta site exists (e.g. https://es.wordpress.org/news/), then use that. Otherwise, leave untranslated. */
esc_url( _x( 'https://wordpress.org/news/', 'Events and News dashboard widget' ) ),
__( 'News' ),
/* translators: Hidden accessibility text. */
__( '(opens in a new tab)' )
);
?>
</p>
</pre><p class="wporg-dot-link-list"><a href="https://developer.wordpress.org/reference/files/wp-admin/includes/dashboard.php/">View all references</a> <a href="https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/dashboard.php#L1302">View on Trac</a> <a href="https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/dashboard.php#L1302-L1349">View on GitHub</a></p></section>
<section class="wp-block-wporg-code-reference-related" data-nosnippet="true"><h2 id="related" class="is-toc-heading wp-block-heading has-heading-5-font-size" tabindex="-1" ><a href="#related">Related</a></h2> <section style="margin-top:var(--wp--preset--spacing--20)" class="wp-block-wporg-code-table" id="uses"><figure class="wp-block-table "><table><thead><tr><th scope="col">Uses</th><th scope="col">Description</th></tr></thead><tbody><tr class=""><td><a href="https://developer.wordpress.org/reference/functions/wp_print_community_events_markup/">wp_print_community_events_markup()</a><code>wp-admin/includes/dashboard.php
Prints the markup for the Community Events section of the Events and News Dashboard widget.
wp_dashboard_primary()wp-admin/includes/dashboard.php
‘WordPress Events and News’ dashboard widget.
__()wp-includes/l10n.php
Retrieves the translation of $text.
_x()wp-includes/l10n.php
Retrieves translated string with gettext context.
esc_url()wp-includes/formatting.php
Checks and cleans a URL.
Changelog
| Version | Description |
|---|---|
| 4.8.0 | Introduced. |