Skip to main content

Basically, if you do not want to create your own network admin settings page, you will need to use both hooks mentioned separately in the other two answers:

add_filter( 'wpmu_options' , 'show_my_network_settings''show_network_settings' );
add_action( 'update_wpmu_options', 'save_my_network_settings''save_network_settings' );

function save_network_settings() {
  // checkbox example
  if( isset( $_POST['my_network_checkbox'] ) )
    update_site_option( 'my_network_checkbox', '1' );
 
  // textfield example
  if( isset( $_POST['my_network_textfield'] ) )
    update_site_option( 'my_network_textfield', sanitize_text_field($_POST['my_network_textfield']) );
}

function show_network_settings() {
    $checkbox = get_site_option('my_checkbox'); 
    $text = get_site_option('my_text'); 
    ?>
    <h3><?php _e('My Network Settings','my-plugin'); ?></h3>
    <table class="form-table">
        <tbody>
            <tr>
                <th scope="row"><?php _e('My Checkbox','my-plugin'); ?></th>
                <td>
                    <label>
                        <input type='checkbox' name='my_checkbox' value='1' <?php checked( $checkbox, '1' ); ?> /> 
                    <?php _e('Check my box.','my-plugin'); ?>
                    </label>
                </td>
            </tr>
            <tr>
                <th scope="row"><label for="my_text"><?php _e('My Text','my-plugin'); ?></label></th>
                <td>
                        <input type='text' name='my_text' value='<?php echo $text; ?>' />
                </td>
            </tr>
        </tbody>
    </table>
    <?php
}

For a very clear explanation and useful code sample see http://zao.is/2013/07/adding-settings-to-network-settings-for-wordpress-multisite/

Basically, if you do not want to create your own network admin settings page, you will need to use both hooks mentioned separately in the other two answers:

add_filter( 'wpmu_options' , 'show_my_network_settings' );
add_action( 'update_wpmu_options', 'save_my_network_settings' );

function save_network_settings() {
  // checkbox example
  if( isset( $_POST['my_network_checkbox'] ) )
    update_site_option( 'my_network_checkbox', '1' );
 
  // textfield example
  if( isset( $_POST['my_network_textfield'] ) )
    update_site_option( 'my_network_textfield', sanitize_text_field($_POST['my_network_textfield']) );
}

function show_network_settings() {
    $checkbox = get_site_option('my_checkbox'); 
    $text = get_site_option('my_text'); 
    ?>
    <h3><?php _e('My Network Settings','my-plugin'); ?></h3>
    <table class="form-table">
        <tbody>
            <tr>
                <th scope="row"><?php _e('My Checkbox','my-plugin'); ?></th>
                <td>
                    <label>
                        <input type='checkbox' name='my_checkbox' value='1' <?php checked( $checkbox, '1' ); ?> /> 
                    <?php _e('Check my box.','my-plugin'); ?>
                    </label>
                </td>
            </tr>
            <tr>
                <th scope="row"><label for="my_text"><?php _e('My Text','my-plugin'); ?></label></th>
                <td>
                        <input type='text' name='my_text' value='<?php echo $text; ?>' />
                </td>
            </tr>
        </tbody>
    </table>
    <?php
}

For a very clear explanation and useful code sample see http://zao.is/2013/07/adding-settings-to-network-settings-for-wordpress-multisite/

Basically, if you do not want to create your own network admin settings page, you will need to use both hooks mentioned separately in the other two answers:

add_filter( 'wpmu_options' , 'show_network_settings' );
add_action( 'update_wpmu_options', 'save_network_settings' );

function save_network_settings() {
  // checkbox example
  if( isset( $_POST['my_network_checkbox'] ) )
    update_site_option( 'my_network_checkbox', '1' );
 
  // textfield example
  if( isset( $_POST['my_network_textfield'] ) )
    update_site_option( 'my_network_textfield', sanitize_text_field($_POST['my_network_textfield']) );
}

function show_network_settings() {
    $checkbox = get_site_option('my_checkbox'); 
    $text = get_site_option('my_text'); 
    ?>
    <h3><?php _e('My Network Settings','my-plugin'); ?></h3>
    <table class="form-table">
        <tbody>
            <tr>
                <th scope="row"><?php _e('My Checkbox','my-plugin'); ?></th>
                <td>
                    <label>
                        <input type='checkbox' name='my_checkbox' value='1' <?php checked( $checkbox, '1' ); ?> /> 
                    <?php _e('Check my box.','my-plugin'); ?>
                    </label>
                </td>
            </tr>
            <tr>
                <th scope="row"><label for="my_text"><?php _e('My Text','my-plugin'); ?></label></th>
                <td>
                        <input type='text' name='my_text' value='<?php echo $text; ?>' />
                </td>
            </tr>
        </tbody>
    </table>
    <?php
}

For a very clear explanation and useful code sample see http://zao.is/2013/07/adding-settings-to-network-settings-for-wordpress-multisite/

Source Link
RavanH
  • 121
  • 2

Basically, if you do not want to create your own network admin settings page, you will need to use both hooks mentioned separately in the other two answers:

add_filter( 'wpmu_options' , 'show_my_network_settings' );
add_action( 'update_wpmu_options', 'save_my_network_settings' );

function save_network_settings() {
  // checkbox example
  if( isset( $_POST['my_network_checkbox'] ) )
    update_site_option( 'my_network_checkbox', '1' );
 
  // textfield example
  if( isset( $_POST['my_network_textfield'] ) )
    update_site_option( 'my_network_textfield', sanitize_text_field($_POST['my_network_textfield']) );
}

function show_network_settings() {
    $checkbox = get_site_option('my_checkbox'); 
    $text = get_site_option('my_text'); 
    ?>
    <h3><?php _e('My Network Settings','my-plugin'); ?></h3>
    <table class="form-table">
        <tbody>
            <tr>
                <th scope="row"><?php _e('My Checkbox','my-plugin'); ?></th>
                <td>
                    <label>
                        <input type='checkbox' name='my_checkbox' value='1' <?php checked( $checkbox, '1' ); ?> /> 
                    <?php _e('Check my box.','my-plugin'); ?>
                    </label>
                </td>
            </tr>
            <tr>
                <th scope="row"><label for="my_text"><?php _e('My Text','my-plugin'); ?></label></th>
                <td>
                        <input type='text' name='my_text' value='<?php echo $text; ?>' />
                </td>
            </tr>
        </tbody>
    </table>
    <?php
}

For a very clear explanation and useful code sample see http://zao.is/2013/07/adding-settings-to-network-settings-for-wordpress-multisite/