I have situation where I want to update blog blog options during creation of new blog. I want to update options like, home, default_comment_status, default_ping_status permalinks structure, etc ...
So I created function:
function setup_multisite_action($data){
$blog_id = (int) $data->blog_id;
update_blog_option($blog_id, 'home', '');
update_blog_option($blog_id, 'default_comment_status', 'closed');
update_blog_option($blog_id, 'default_ping_status', 'closed');
}
add_action( 'wp_insert_site', 'setup_multisite_action', 50, 1 );
But it won't work. I tried to use hook wpmu_new_blog
and actually in this case this works!
function setup_multisite_action($blog_id){
update_blog_option($blog_id, 'home', '');
update_blog_option($blog_id, 'default_comment_status', 'closed');
update_blog_option($blog_id, 'default_ping_status', 'closed');
}
add_action( 'wpmu_new_blog', 'setup_multisite_action', 50, 1 );
BUT! this hook is deprecated and it telling me to use wp_insert_site
.
So what im doing wrong for hook wp_insert_site
?
I really have no clue how to solve my issue at this point. I spend some time to find solution but I was not able to, and it is important to work correctly. Because I have more stuff to update for new created blog so user don't have to do (actually he will be not able to do) :(
I have situation where I want to update blog blog options during creation of new blog. I want to update options like, home, default_comment_status, default_ping_status permalinks structure, etc ...
So I created function:
function setup_multisite_action($data){
$blog_id = (int) $data->blog_id;
update_blog_option($blog_id, 'home', 'https://test.local');
update_blog_option($blog_id, 'default_comment_status', 'closed');
update_blog_option($blog_id, 'default_ping_status', 'closed');
}
add_action( 'wp_insert_site', 'setup_multisite_action', 50, 1 );
But it won't work. I tried to use hook wpmu_new_blog
and actually in this case this works!
function setup_multisite_action($blog_id){
update_blog_option($blog_id, 'home', 'https://test.local');
update_blog_option($blog_id, 'default_comment_status', 'closed');
update_blog_option($blog_id, 'default_ping_status', 'closed');
}
add_action( 'wpmu_new_blog', 'setup_multisite_action', 50, 1 );
BUT! this hook is deprecated and it telling me to use wp_insert_site
.
So what im doing wrong for hook wp_insert_site
?
I really have no clue how to solve my issue at this point. I spend some time to find solution but I was not able to, and it is important to work correctly. Because I have more stuff to update for new created blog so user don't have to do (actually he will be not able to do) :(
Share Improve this question edited Oct 13, 2020 at 5:23 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Oct 12, 2020 at 15:09 IsuIsu 4075 silver badges9 bronze badges1 Answer
Reset to default 2The wpmu_new_blog
hook is indeed deprecated and shouldn't be used; however, it works because it runs after the new site has been initialized (see wp_initialize_site()
) which means the database tables for that site has been created and filled with the default options.
So because you are updating the site's options like default_comment_status
, then you should use the wp_initialize_site
hook and not wp_insert_site
:
add_action( 'wp_initialize_site', 'setup_multisite_action' ); // use this
//add_action( 'wp_insert_site', 'setup_multisite_action' ); // not this