函数文档

wp_print_community_events_markup()

💡 云策文档标注

概述

wp_print_community_events_markup() 函数用于输出 Events and News Dashboard widget 中 Community Events 部分的 HTML 标记。它生成一个包含错误通知和事件列表的容器,依赖于 JavaScript 进行内容渲染。

关键要点

  • 函数输出 Community Events 部分的完整 HTML 结构,包括错误通知和事件列表容器。
  • 使用 wp_admin_notice() 显示 JavaScript 错误提示,并设置相关 CSS 类以控制显示。
  • HTML 结构包含隐藏的主元素,通过 JavaScript 动态加载内容。
  • 函数被 wp_dashboard_events_news() 调用,用于渲染 Events and News Dashboard widget。
  • 自 WordPress 4.8.0 版本引入。

代码示例

wp_admin_notice(
    $community_events_notice,
    array(
        'type'               => 'error',
        'additional_classes' => array( 'community-events-errors', 'inline', 'hide-if-js' ),
        'paragraph_wrap'     => false,
    )
);

注意事项

  • 函数依赖于 JavaScript(wp.communityEvents.renderEventsTemplate())来填充事件内容,初始加载时主元素被隐藏。
  • 错误通知使用 hide-if-js 类,仅在 JavaScript 不可用时显示。
  • 相关函数包括 wp_admin_notice()、submit_button()、esc_attr_e() 等,用于辅助输出和国际化。

📄 原文内容

Prints the markup for the Community Events section of the Events and News Dashboard widget.

Source

function wp_print_community_events_markup() {
$community_events_notice = '<p class="hide-if-js">' . ( 'This widget requires JavaScript.' ) . '</p>';
$community_events_notice .= '<p class="community-events-error-occurred" aria-hidden="true">' . __( 'An error occurred. Please try again.' ) . '</p>';
$community_events_notice .= '<p class="community-events-could-not-locate" aria-hidden="true"></p>';

wp_admin_notice(
$community_events_notice,
array(
'type' => 'error',
'additional_classes' => array( 'community-events-errors', 'inline', 'hide-if-js' ),
'paragraph_wrap' => false,
)
);

/*
* Hide the main element when the page first loads, because the content
* won't be ready until wp.communityEvents.renderEventsTemplate() has run.
*/
?>
<div id="community-events" class="community-events" aria-hidden="true">
<div class="activity-block">
<p>
<span id="community-events-location-message"></span>

<button class="button-link community-events-toggle-location" aria-expanded="false">
<span class="dashicons dashicons-location" aria-hidden="true"></span>
<span class="community-events-location-edit"></span>
</button>
</p>

<form class="community-events-form" aria-hidden="true" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" method="post">
<label for="community-events-location">

</label>

<input id="community-events-location" class="regular-text" type="text" name="community-events-location" placeholder="<?php esc_attr_e( 'Cincinnati' ); ?>" />

<button class="community-events-cancel button-link" type="button" aria-expanded="false">

</button>

<span class="spinner"></span>
</form>
</div>

<ul class="community-events-results activity-block last"></ul>
</div>

</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#L1356">View on Trac</a> <a href="https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/dashboard.php#L1356-L1416">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_admin_notice/">wp_admin_notice()</a><code>wp-includes/functions.php

Outputs an admin notice.

submit_button()wp-admin/includes/template.php

Echoes a submit button, with provided text and appropriate class(es).

esc_attr_e()wp-includes/l10n.php

Displays translated text that has been escaped for safe use in an attribute.

__()wp-includes/l10n.php

Retrieves the translation of $text.

_e()wp-includes/l10n.php

Displays translated text.

esc_url()wp-includes/formatting.php

Checks and cleans a URL.

admin_url()wp-includes/link-template.php

Retrieves the URL to the admin area for the current site.

Show 4 moreShow less

Used by Description
wp_dashboard_events_news()wp-admin/includes/dashboard.php

Renders the Events and News dashboard widget.

Changelog

Version Description
4.8.0 Introduced.