Example #1
0
/**
 * Register default global settings.
 *
 * @since 1.0.0
 */
function audiotheme_dashboard_register_settings()
{
    $screen = add_audiotheme_settings_screen('audiotheme-settings', __('Settings', 'audiotheme'), array('menu_title' => is_network_admin() ? __('AudioTheme', 'audiotheme') : __('Settings', 'audiotheme'), 'option_group' => 'audiotheme_options', 'option_name' => array('audiotheme_options', 'audiotheme_license_key'), 'show_in_menu' => is_network_admin() ? 'settings.php' : 'audiotheme', 'capability' => is_network_admin() ? 'manage_network_options' : 'manage_options'));
    if (is_multisite() && !is_network_admin()) {
        return;
    }
    $screen->add_section('license', __('License', 'audiotheme'), array('priority' => 0, 'callback' => 'audiotheme_dashboard_settings_license_section'));
    $screen->add_field('audiotheme_license_key', __('License Key', 'audiotheme'), 'audiotheme_dashboard_license_input', array('option_name' => 'audiotheme_license_key'));
    // System Info Tab
    $screen->add_tab('system_info', __('System', 'audiotheme'));
    $screen->add_section('system_info', '', array('callback' => 'audiotheme_dashboard_settings_system_section'));
    $screen->add_field('system_info', __('Export Data', 'audiotheme'), 'html', array('label' => '', 'output' => '<textarea id="audiotheme-system-info-export" class="widefat">' . audiotheme_system_info(array('format' => 'plaintext')) . '</textarea>'));
}
/**
 * Initialize the settings object and related hooks, and add a Theme Options
 * screen if the current theme supports it.
 *
 * Hooked on 'init' in audiotheme_admin_setup().
 *
 * @since 1.0.0
 */
function audiotheme_settings_init()
{
    // Add theme options support.
    if (($support = get_audiotheme_theme_options_support()) && !empty($support['callback']) && function_exists($support['callback'])) {
        $settings = get_audiotheme_settings();
        $screen = add_audiotheme_settings_screen('audiotheme-theme-options', __('Theme Options', 'audiotheme'), array('menu_title' => $support['menu_title'], 'option_group' => 'audiotheme_theme_mods', 'option_name' => $support['option_name'], 'show_in_menu' => 'themes.php', 'capability' => 'edit_theme_options'));
        // Registering the callback like this ensures that an error isn't thrown if the framework isn't active.
        add_action('audiotheme_register_settings', $support['callback']);
    }
    // These must occur after the callback to register settings.
    add_action('customize_register', 'audiotheme_settings_register_customizer_settings');
    // Lower priority allows screens to be registered in the 'admin_menu' hook and still have the menu item display.
    add_action('admin_menu', 'audiotheme_settings_add_admin_menus', 20);
    add_action('network_admin_menu', 'audiotheme_settings_add_admin_menus', 20);
    // Settings should be registered before this.
    add_action('admin_init', 'audiotheme_settings_register_wp_settings_api', 20);
    add_action('admin_init', 'audiotheme_settings_save_network_options');
    // Custom settings should be registered during this hook.
    do_action('audiotheme_register_settings');
}