1

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' );

1 Answer 1

1

After some more research I found a solution, turned out that I had to use admin_init..

function pg_save_custom_site_options(){
    global $pagenow;
    if( 'site-info.php' == $pagenow && isset($_REQUEST['action']) && 'update-site' == $_REQUEST['action'] ) 
    {
        if ( isset( $_POST['blog']['custom_limit_amount'] ) ) 
        {
            $new_field_value = intval( $_POST['blog']['custom_limit_amount'] );
            if( is_int($new_field_value) ){
                update_blog_option( $_POST['id'], 'custom_limit_amount', $new_field_value );
            }
        }
    }
}
add_action('admin_init', 'pg_save_custom_site_options');
2
  • Good to hear your problem is resolved. Please mark your own answer as accepted.
    – Johansson
    Commented Jun 6, 2017 at 14:31
  • Will do, as soon as possible (in 2 days)
    – K. Tromp
    Commented Jun 6, 2017 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.