如何在插件开发过程中获取站点名称? [英] How to get the site name during plugin development?

查看:28
本文介绍了如何在插件开发过程中获取站点名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发我的第一个 wordpress 插件,我需要获取站点名称.

I am developing my first wordpress plugin, and i need to get the site name.

文档 说要使用 get_current_site_name( $current_site ) 函数.

这是我的脚本

myPlugin.php:

$site_data = get_current_site_name( $current_site );

但尚未定义 get_current_site_name() 函数.

but get_current_site_name() function is not defined yet.

也没有文档中所写的全局 $current_site 变量.

Also there is no global $current_site variable, as written in documentation.

我也尝试添加 wp_loaded 操作,让 wordpress 完全加载,但没有帮助.

I also try to add a wp_loaded action, to let the wordpress load fully, but it doesn't help.

function myfunction() {
     global $current_site;
     $site_data = get_current_site_name( $current_site );
}
add_action('wp_loaded', 'myfunction');

//Fatal error:  Call to undefined function get_current_site_name() in ...

我做错了什么?

谢谢

更新:

这个站点有一个错误,当我尝试在我的问题顶部写hello时,它会自动删除它.所以我写在这里 - 大家好 :)

There is a bug in this site, when i try to write hello at the top of my question, it strips it automatically. So i'm writing it here - Hello guys :)

推荐答案

该功能仅在网络模式下可用.它将返回站点的名称(您在创建站点时使用的名称),而不是您在选项中设置的标题.

That function is only available in network mode. It will return the name of the site (the one you use when you create the site), not the title that you set in the options.

您可能想要使用 get_bloginfo('name').这个返回站点标题.是的,我知道,命名不一致,全局变量......这是 WP :)

You probably want to use get_bloginfo('name'). This one returns the site title. Yeah I know, inconsistent naming, global variables ...it's WP :)

这篇关于如何在插件开发过程中获取站点名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆