/**
 * Set basic settings on the activation of the plugin.
 * - Saved in 'options' table.
 * - Creating custom table for storing email addresses.
 * ------------------------------------------------------------------------------
 */
function nanodesigns_email_downloads_activate()
{
    /**
     * Creating a custom table.
     * @since 1.0.1
     * -----------
     */
    global $wpdb, $nano_db_version;
    $table = $wpdb->prefix . 'download_email';
    if ($wpdb->get_var("SHOW TABLES LIKE '{$table}'") != $table) {
        $sql = "CREATE TABLE {$table} (\n                  id mediumint(9) NOT NULL AUTO_INCREMENT,\n                  email tinytext NOT NULL,\n                  UNIQUE KEY id (id)\n                );";
        //reference to upgrade.php file
        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
        dbDelta($sql);
    }
    //endif($wpdb->get_var
    update_option("nano_ed_db_version", $nano_db_version);
    /**
     * Add the necessary default settings to the 'options table'.
     * @since 1.0.0
     * -----------
     */
    $noreply_email = noreply_email();
    $admin_email = get_option('admin_email');
    $admin_user = get_user_by('email', $admin_email);
    $ed_settings = array('ed_sender_email' => $noreply_email, 'ed_sender_name' => $admin_user->display_name);
    update_option('email_downloads_settings', $ed_settings);
}
function email_downloads_sender_name_render()
{
    $options = get_option('email_downloads_settings');
    $noreply_email = noreply_email();
    $admin_email = get_option('admin_email');
    $admin_user = get_user_by('email', $admin_email);
    ?>

	<input type="text" class="regular-text" name="email_downloads_settings[ed_sender_name]" value="<?php 
    echo $options['ed_sender_name'] ? $options['ed_sender_name'] : $admin_user->display_name;
    ?>
"> <em class="howto"><span class="dashicons dashicons-info"></span> <?php 
    _e("<strong>default:</strong> administrator's display name", "email-downloads");
    ?>
</em>

	<?php 
}