admin管理员组文章数量:1335446
I would like to add or update site options (like those shown in the screenshot) using update_site_option, but I have no idea (1) how to choose the correct site by its id? And where do I find the available (2) slugs for the options array?
I would like to add or update site options (like those shown in the screenshot) using update_site_option, but I have no idea (1) how to choose the correct site by its id? And where do I find the available (2) slugs for the options array?
Share Improve this question asked Jun 3, 2020 at 17:51 Robin AlexanderRobin Alexander 1538 bronze badges1 Answer
Reset to default 6update_site_option()
updates an option that's set for the entire network. If you're trying to update a specific site's option, eg blogname
, you'll need to do update_option()
instead.
If you're not sure of a site's ID, you can get its details using the site's slug with get_blog_details()
.
For example, if I wanted to change the admin_email
and some_other_option
options of the site at example/site-3:
$site_object = get_blog_details( 'site-3' );
if ( ! empty( $site_object ) ) {
switch_to_blog( $site_object->blog_id );
update_option( 'admin_email', '[email protected]' );
update_option( 'some_other_option', 'Some Other Option Value' );
restore_current_blog();
}
The confusion arises because when WordPress Multisite was initially developed, the terminology spoke of a site of blogs; later, though, it was updated to be a network of sites. The original terms still exist in function names like update_site_option()
and switch_to_blog()
.
References
update_site_option()
update_option()
get_blog_details()
switch_to_blog()
restore_current_blog()
本文标签: multisiteHow to updatesiteoption for specific site within network
版权声明:本文标题:multisite - How to update_site_option for specific site within network? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742377315a2463420.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论