函数文档

wp_welcome_panel()

💡 云策文档标注

概述

wp_welcome_panel() 函数用于在 WordPress 后台显示欢迎面板,向用户介绍 WordPress 功能。该函数根据当前 WordPress 版本、用户权限和主题类型动态生成面板内容。

关键要点

  • 函数 wp_welcome_panel() 显示欢迎面板,帮助新用户熟悉 WordPress。
  • 使用 wp_get_wp_version() 获取 WordPress 版本,wp_is_block_theme() 检测是否为块主题。
  • 根据 current_user_can('customize') 检查用户是否有自定义权限,以调整面板链接。
  • 面板内容包含指向自定义器、站点编辑器等管理页面的链接,使用 esc_url() 和 esc_html() 进行安全转义。
  • 从 WordPress 3.3.0 版本引入,5.9.0 版本更新为针对块主题用户显示站点编辑器链接。

📄 原文内容

Displays a welcome panel to introduce users to WordPress.

Source

function wp_welcome_panel() {
list( $display_version ) = explode( '-', wp_get_wp_version() );
$can_customize = current_user_can( 'customize' );
$is_block_theme = wp_is_block_theme();
?>
<div class="welcome-panel-content">
<div class="welcome-panel-header">
<div class="welcome-panel-header-image">

</div>
<h2></h2>
<p>
<a href="<?php echo esc_url( admin_url( 'about.php' ) ); ?>">

</a>
</p>
</div>
<div class="welcome-panel-column-container">
<div class="welcome-panel-column">
<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false">
<rect width="48" height="48" rx="4" fill="#1E1E1E"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M32.0668 17.0854L28.8221 13.9454L18.2008 24.671L16.8983 29.0827L21.4257 27.8309L32.0668 17.0854ZM16 32.75H24V31.25H16V32.75Z" fill="white"/>
</svg>
<div class="welcome-panel-column-content">
<h3></h3>
<p></p>
<a href="<?php echo esc_url( admin_url( 'post-new.php?post_type=page' ) ); ?>"></a>
</div>
</div>
<div class="welcome-panel-column">
<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false">
<rect width="48" height="48" rx="4" fill="#1E1E1E"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M18 16h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H18a2 2 0 0 1-2-2V18a2 2 0 0 1 2-2zm12 1.5H18a.5.5 0 0 0-.5.5v3h13v-3a.5.5 0 0 0-.5-.5zm.5 5H22v8h8a.5.5 0 0 0 .5-.5v-7.5zm-10 0h-3V30a.5.5 0 0 0 .5.5h2.5v-8z" fill="#fff"/>
</svg>
<div class="welcome-panel-column-content">

<h3></h3>
<p></p>
<a href="<?php echo esc_url( admin_url( 'site-editor.php' ) ); ?>"></a>

<h3></h3>
<p></p>

<a class="load-customize hide-if-no-customize" href="<?php echo wp_customize_url(); ?>"></a>

</div>
</div>
<div class="welcome-panel-column">
<svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false">
<rect width="48" height="48" rx="4" fill="#1E1E1E"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M31 24a7 7 0 0 1-7 7V17a7 7 0 0 1 7 7zm-7-8a8 8 0 1 1 0 16 8 8 0 0 1 0-16z" fill="#fff"/>
</svg>
<div class="welcome-panel-column-content">

<h3></h3>
<p></p>
<a href="<?php echo esc_url( admin_url( '/site-editor.php?path=%2Fwp_global_styles' ) ); ?>"></a>

<h3></h3>
<p></p>
<a href="<?php echo esc_url( __( 'https://wordpress.org/documentation/article/block-themes/' ) ); ?>"></a>

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

Returns the current WordPress version.

wp_is_block_theme()wp-includes/theme.php

Returns whether the active theme is a block-based theme or not.

wp_customize_url()wp-includes/theme.php

Returns a URL to load the Customizer.

current_user_can()wp-includes/capabilities.php

Returns whether the current user has the specified capability.

_e()wp-includes/l10n.php

Displays translated text.

__()wp-includes/l10n.php

Retrieves the translation of $text.

esc_url()wp-includes/formatting.php

Checks and cleans a URL.

esc_html()wp-includes/formatting.php

Escaping for HTML blocks.

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

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

Show 6 moreShow less

Changelog

Version Description
5.9.0 Send users to the Site Editor if the active theme is block-based.
3.3.0 Introduced.