函数文档

confirm_another_blog_signup()

💡 云策文档标注

概述

confirm_another_blog_signup() 函数用于显示新站点创建成功的确认消息,适用于多站点网络中的现有用户注册新站点场景。它生成包含站点链接和登录信息的HTML输出。

关键要点

  • 函数参数包括 $domain(域名)、$path(路径)、$blog_title(站点标题)、$user_name(用户名)、$user_email(用户邮箱)、$meta(额外元数据)和 $blog_id(站点ID)。
  • 根据 $blog_id 是否提供,使用 switch_to_blog() 或手动构建 URL 来获取 home_url 和 login_url。
  • 输出消息包含站点链接和登录提示,使用 esc_url() 和 __() 等函数确保安全性和可翻译性。
  • 触发 do_action('signup_finished') Hook,在站点或用户注册完成时执行相关操作。
  • 相关函数包括 untrailingslashit()、wp_login_url()、home_url() 等,用于URL处理和站点切换。

代码示例

confirm_another_blog_signup( $domain, $path, $blog_title, $user_name, $user_email = '', $meta = array(), $blog_id = 0 )

注意事项

  • 该函数主要用于多站点环境,需确保正确传递参数以避免URL构建错误。
  • 使用 esc_url() 和 __() 增强安全性和国际化支持。
  • 注意 $blog_id 参数的处理逻辑:如果提供,则切换博客获取URL;否则基于域名和路径构建。

📄 原文内容

Shows a message confirming that the new site has been created.

Parameters

$domainstringrequired
The domain URL.
$pathstringrequired
The site root path.
$blog_titlestringrequired
The site title.
$user_namestringrequired
The username.
$user_emailstringrequired
The user’s email address.
$metaarrayoptional
Any additional meta from the ‘add_signup_meta’ filter in validate_blog_signup() .

Default:array()

$blog_idintrequired
The site ID.

Source

function confirm_another_blog_signup( $domain, $path, $blog_title, $user_name, $user_email = '', $meta = array(), $blog_id = 0 ) {

if ( $blog_id ) {
switch_to_blog( $blog_id );
$home_url = home_url( '/' );
$login_url = wp_login_url();
restore_current_blog();
} else {
$home_url = 'http://' . $domain . $path;
$login_url = 'http://' . $domain . $path . 'wp-login.php';
}

$site = sprintf(
'<a href="%1$s">%2$s</a>',
esc_url( $home_url ),
$blog_title
);

?>
<h2>

</h2>
<p>
Log in</a> as “%3$s” using your existing password.' ),
sprintf(
'<a href="%s">%s</a>',
esc_url( $home_url ),
untrailingslashit( $domain . $path )
),
esc_url( $login_url ),
$user_name
);
?>
</p>
</pre><p class="wporg-dot-link-list"><a href="https://developer.wordpress.org/reference/files/wp-signup.php/">View all references</a> <a href="https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-signup.php#L530">View on Trac</a> <a href="https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-signup.php#L530-L577">View on GitHub</a></p></section>
<section class="wp-block-wporg-code-reference-hooks"><h2 id="hooks" class="is-toc-heading wp-block-heading has-heading-5-font-size" tabindex="-1" ><a href="#hooks">Hooks</a></h2> <dl><dt class="wp-block-wporg-code-reference-title has-normal-font-size"><a href="https://developer.wordpress.org/reference/hooks/signup_finished/"><span class="hook-func">do_action</span>( ‘signup_finished’ )</a></dt><dd><p>Fires when the site or user sign-up process is complete.</p>
</dd></dl></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/untrailingslashit/">untrailingslashit()</a><code>wp-includes/formatting.php

Removes trailing forward slashes and backslashes if they exist.

wp_login_url()wp-includes/general-template.php

Retrieves the login URL.

switch_to_blog()wp-includes/ms-blogs.php

Switches the current blog.

restore_current_blog()wp-includes/ms-blogs.php

Restores the current blog, after calling switch_to_blog() .

__()wp-includes/l10n.php

Retrieves the translation of $text.

esc_url()wp-includes/formatting.php

Checks and cleans a URL.

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

Retrieves the URL for the current site where the front end is accessible.

do_action()wp-includes/plugin.php

Calls the callback functions that have been added to an action hook.

Show 4 moreShow less

Used by Description
validate_another_blog_signup()wp-signup.php

Validates a new site sign-up for an existing user.

Changelog

Version Description
MU (3.0.0) MU (3.0.0)
4.4.0 Introduced.