admin管理员组文章数量:1278882
I'd like to run some custom validation code on attempts to create new sites on my MultiSite environment, particularly the /wp-admin/network/site-new.php page. I've explored site-new.php, and have found zero instances of do_action() and the only filter is for subdirectory_reserved_names.
I imagine I could write some overly general code that runs on something like every admin_init, check to see if this is the site-new page, see if the $_POST['action'] is set and equals 'site-new', verify the nonce, etc... but that really doesn't seem like it could be the best / proper way.
Any suggestions on how to add my own custom validation code before a new site is actually created?
Note that the hook wpmu_validate_blog_signup is available for when users are using the public-facing signup form, so validation against THAT form is pretty straightforward. It appears, though, that there is no easy way to do similar validation for sites created from the Network dashboard.
I'd like to run some custom validation code on attempts to create new sites on my MultiSite environment, particularly the /wp-admin/network/site-new.php page. I've explored site-new.php, and have found zero instances of do_action() and the only filter is for subdirectory_reserved_names.
I imagine I could write some overly general code that runs on something like every admin_init, check to see if this is the site-new page, see if the $_POST['action'] is set and equals 'site-new', verify the nonce, etc... but that really doesn't seem like it could be the best / proper way.
Any suggestions on how to add my own custom validation code before a new site is actually created?
Note that the hook wpmu_validate_blog_signup is available for when users are using the public-facing signup form, so validation against THAT form is pretty straightforward. It appears, though, that there is no easy way to do similar validation for sites created from the Network dashboard.
Share Improve this question edited Dec 30, 2013 at 15:26 MadtownLems asked Dec 27, 2013 at 18:59 MadtownLemsMadtownLems 4972 silver badges13 bronze badges1 Answer
Reset to default 1Doing something before wpmu_create_blog()
is called seems to be indeed hard. Not sure if I miss something …
You can hook into the action check_admin_referer
and print your own error message:
if ( is_network_admin()
&& isset ( $_REQUEST[ 'action' ] )
&& 'add-site' === $_REQUEST[ 'action' ] )
{
add_action( 'check_admin_referer', function( $action )
{
if ( 'add-blog' !== $action )
return;
die( 'Nope.' );
// inspect $_POST, do something.
// Change $_POST['blog'] to get the best matching error message
});
}
本文标签: How to Run Code Before a New Site is Created on MultiSite for Validation
版权声明:本文标题:How to Run Code Before a New Site is Created on MultiSite for Validation 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741281157a2370013.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论