I am currently using code to add a custom field to the site-info.php
& site-new.php
in the network admin management to add a custom option to the database, this does work when I create a new subsite, it gets set in the database and retrieves the value inside the input value.
But when I try to update the value of this custom option, while updating site-info
, this doesn't even reach the function, most likely because I'm using the (wrong) hook wpmu_new_blog
, because I am updating I've tried using wpmu_blog_updated
, wpmu_edit_blog
, wpmu_update_blog
, but I just can't get it to work.
Any help would be appreciated.
My code is as follows:
//Add custom field Site-options Network-admin
add_action('admin_footer', 'user16975_custom_options');
function user16975_custom_options(){
global $pagenow;
if( 'site-info.php' == $pagenow OR 'site-new.php' == $pagenow ) {
if(ctype_digit($_GET['id']))
$custom_limit_site_id = $_GET['id'];
else
$custom_limit_site_id ='';
?><table><tr id="user16975_custom_options">
<th scope="row">Maximaal aantal gebruikers</th>
<td><input type="text" name="blog[custom_limit_amount]" value="<?=get_blog_option( $custom_limit_site_id, 'custom_limit_amount', '10' );?>"/></td>
</tr></table>
<script>jQuery(function($){
$('.form-table tbody').append($('#user16975_custom_options'));
});</script><?php
}
}
function add_new_blog_field($blog_id, $user_id, $domain, $path, $site_id, $meta) {
switch_to_blog($blog_id);
$new_field_value = '10';
if ( !empty($_POST['blog']['custom_limit_amount']) )
$new_field_value = $_POST['blog']['custom_limit_amount'];
update_option( 'custom_limit_amount', $new_field_value);
restore_current_blog();
}
add_action( 'wpmu_new_blog', 'add_new_blog_field' );
function edit_blog_field($blog_id) {
if ( !empty($_POST['blog']['custom_limit_amount']) )
$new_field_value = $_POST['blog']['custom_limit_amount'];
update_blog_option ($blog_id, 'custom_limit_amount', $new_field_value);
restore_current_blog();
}
add_action( 'wpmu_blog_updated', 'edit_blog_field' );