How to save values of a custom input field on the Network > Site Info screen

The problem was a redirect in site-info.php. After that the $_POST variable was empty in the code inserting in the admin_footer.

I just need to use a further hook ‘admin_init’ and save the value here.

add_action('admin_init', 'pg_save_custom_site_options');
function pg_save_custom_site_options(){

    global $pagenow;

    if( 'site-info.php' == $pagenow &&
        isset($_REQUEST['action']) &&
        'update-site' == $_REQUEST['action']
    ) {
        // Use a default value here if the field was not submitted.
        $new_field_value="0";

        if ( isset( $_POST['blog']['blog_order'] ) ) {
            $new_field_value = intval( $_POST['blog']['blog_order'] );

            // save option into the database
            if( is_int($new_field_value) ){
                update_blog_option( $_POST['id'], 'blog_order', $new_field_value );
            }

        }

    }
}

Leave a Comment