/**
 * Register settings for the tab.
 */
function dg_register_settings()
{
    global $dg_options;
    include_once DG_PATH . 'inc/class-gallery.php';
    include_once DG_PATH . 'inc/class-gallery-sanitization.php';
    include_once DG_PATH . 'inc/class-thumber.php';
    $defaults = $dg_options['gallery'];
    $active = $dg_options['thumber']['active'];
    add_settings_section('gallery_defaults', __('Default Settings', 'document-gallery'), 'dg_render_default_settings_section', DG_OPTION_NAME);
    add_settings_section('thumbnail_generation', __('Thumbnail Generation', 'document-gallery'), 'dg_render_thumber_section', DG_OPTION_NAME);
    add_settings_section('css', __('Custom CSS', 'document-gallery'), 'dg_render_css_section', DG_OPTION_NAME);
    add_settings_field('gallery_defaults_attachment_pg', 'attachment_pg', array('DG_Admin', 'renderCheckboxField'), DG_OPTION_NAME, 'gallery_defaults', array('label_for' => 'label_gallery_defaults_attachment_pg', 'name' => 'gallery_defaults][attachment_pg', 'value' => esc_attr($defaults['attachment_pg']), 'option_name' => DG_OPTION_NAME, 'description' => __('Link to attachment page rather than to file.', 'document-gallery')));
    add_settings_field('gallery_defaults_columns', 'columns', array('DG_Admin', 'renderTextField'), DG_OPTION_NAME, 'gallery_defaults', array('label_for' => 'label_gallery_defaults_columns', 'name' => 'gallery_defaults][columns', 'value' => esc_attr($defaults['columns']), 'type' => 'number" min="1" step="1', 'option_name' => DG_OPTION_NAME, 'description' => __('The number of columns to display when not rendering descriptions.', 'document-gallery')));
    add_settings_field('gallery_defaults_descriptions', 'descriptions', array('DG_Admin', 'renderCheckboxField'), DG_OPTION_NAME, 'gallery_defaults', array('label_for' => 'label_gallery_defaults_descriptions', 'name' => 'gallery_defaults][descriptions', 'value' => esc_attr($defaults['descriptions']), 'option_name' => DG_OPTION_NAME, 'description' => __('Include document descriptions.', 'document-gallery')));
    add_settings_field('gallery_defaults_fancy', 'fancy', array('DG_Admin', 'renderCheckboxField'), DG_OPTION_NAME, 'gallery_defaults', array('label_for' => 'label_gallery_defaults_fancy', 'name' => 'gallery_defaults][fancy', 'value' => esc_attr($defaults['fancy']), 'option_name' => DG_OPTION_NAME, 'description' => __('Use auto-generated document thumbnails.', 'document-gallery')));
    add_settings_field('gallery_defaults_order', 'order', array('DG_Admin', 'renderSelectField'), DG_OPTION_NAME, 'gallery_defaults', array('label_for' => 'label_gallery_defaults_order', 'name' => 'gallery_defaults][order', 'value' => esc_attr($defaults['order']), 'options' => DG_GallerySanitization::getOrderOptions(), 'option_name' => DG_OPTION_NAME, 'description' => __('Ascending or descending sorting of documents.', 'document-gallery')));
    add_settings_field('gallery_defaults_orderby', 'orderby', array('DG_Admin', 'renderSelectField'), DG_OPTION_NAME, 'gallery_defaults', array('label_for' => 'label_gallery_defaults_orderby', 'name' => 'gallery_defaults][orderby', 'value' => esc_attr($defaults['orderby']), 'options' => DG_GallerySanitization::getOrderbyOptions(), 'option_name' => DG_OPTION_NAME, 'description' => __('Which field to order documents by.', 'document-gallery')));
    add_settings_field('gallery_defaults_relation', 'relation', array('DG_Admin', 'renderSelectField'), DG_OPTION_NAME, 'gallery_defaults', array('label_for' => 'label_gallery_defaults_relation', 'name' => 'gallery_defaults][relation', 'value' => esc_attr($defaults['relation']), 'options' => DG_GallerySanitization::getRelationOptions(), 'option_name' => DG_OPTION_NAME, 'description' => __('Whether matched documents must have all taxa_names (AND) or at least one (OR).', 'document-gallery')));
    add_settings_field('gallery_defaults_limit', 'limit', array('DG_Admin', 'renderTextField'), DG_OPTION_NAME, 'gallery_defaults', array('label_for' => 'label_gallery_defaults_limit', 'name' => 'gallery_defaults][limit', 'value' => esc_attr($defaults['limit']), 'type' => 'number" min="-1" step="1', 'option_name' => DG_OPTION_NAME, 'description' => __('Limit the number of documents included. -1 means no limit.', 'document-gallery')));
    add_settings_field('gallery_defaults_mime_types', 'mime_types', array('DG_Admin', 'renderTextField'), DG_OPTION_NAME, 'gallery_defaults', array('label_for' => 'label_gallery_defaults_mime_types', 'name' => 'gallery_defaults][mime_types', 'value' => esc_attr($defaults['mime_types']), 'type' => 'text', 'option_name' => DG_OPTION_NAME, 'description' => __('Comma-delimited list of <a href="http://en.wikipedia.org/wiki/Internet_media_type#List_of_common_media_types">MIME types</a>.', 'document-gallery')));
    add_settings_field('gallery_defaults_new_window', 'new_window', array('DG_Admin', 'renderCheckboxField'), DG_OPTION_NAME, 'gallery_defaults', array('label_for' => 'label_gallery_defaults_new_window', 'name' => 'gallery_defaults][new_window', 'value' => esc_attr($defaults['new_window']), 'option_name' => DG_OPTION_NAME, 'description' => __('Open thumbnail links in new window.', 'document-gallery')));
    add_settings_field('gallery_defaults_paginate', 'paginate', array('DG_Admin', 'renderCheckboxField'), DG_OPTION_NAME, 'gallery_defaults', array('label_for' => 'label_gallery_defaults_paginate', 'name' => 'gallery_defaults][paginate', 'value' => esc_attr($defaults['paginate']), 'option_name' => DG_OPTION_NAME, 'description' => __('When a limit exists, paginate rather than truncating gallery.', 'document-gallery')));
    add_settings_field('gallery_defaults_post_status', 'post_status', array('DG_Admin', 'renderSelectField'), DG_OPTION_NAME, 'gallery_defaults', array('label_for' => 'label_gallery_defaults_post_status', 'name' => 'gallery_defaults][post_status', 'value' => esc_attr($defaults['post_status']), 'options' => DG_GallerySanitization::getPostStatuses(), 'option_name' => DG_OPTION_NAME, 'description' => __('Which post status to look for when querying documents.', 'document-gallery')));
    add_settings_field('gallery_defaults_post_type', 'post_type', array('DG_Admin', 'renderSelectField'), DG_OPTION_NAME, 'gallery_defaults', array('label_for' => 'label_gallery_defaults_post_type', 'name' => 'gallery_defaults][post_type', 'value' => esc_attr($defaults['post_type']), 'options' => DG_GallerySanitization::getPostTypes(), 'option_name' => DG_OPTION_NAME, 'description' => __('Which post type to look for when querying documents.', 'document-gallery')));
    add_settings_field('thumbnail_generation_thumber-co', __('Thumber.co', 'document-gallery'), array('DG_Admin', 'renderCheckboxField'), DG_OPTION_NAME, 'thumbnail_generation', array('label_for' => 'label_thumbnail_generation_thumber-co', 'name' => 'thumbnail_generation][thumber-co', 'value' => esc_attr($active['thumber-co']), 'option_name' => DG_OPTION_NAME, 'description' => __('Use your <a href="http://thumber.co" target="_blank">Thumber.co</a> subscription to remotely generate document thumbnails.', 'document-gallery'), 'disabled' => !DG_ThumberCoThumber::isThumberCoAvailable()));
    add_settings_field('thumbnail_generation_av', __('Audio/Video', 'document-gallery'), array('DG_Admin', 'renderCheckboxField'), DG_OPTION_NAME, 'thumbnail_generation', array('label_for' => 'label_thumbnail_generation_av', 'name' => 'thumbnail_generation][av', 'value' => esc_attr($active['av']), 'option_name' => DG_OPTION_NAME, 'description' => esc_html__('Locally generate thumbnails for audio & video files.', 'document-gallery')));
    add_settings_field('thumbnail_generation_gs', 'Ghostscript', array('DG_Admin', 'renderCheckboxField'), DG_OPTION_NAME, 'thumbnail_generation', array('label_for' => 'label_thumbnail_generation_gs', 'name' => 'thumbnail_generation][gs', 'value' => esc_attr($active['gs']), 'option_name' => DG_OPTION_NAME, 'description' => DG_GhostscriptThumber::isGhostscriptAvailable() ? __('Use <a href="http://www.ghostscript.com/" target="_blank">Ghostscript</a> for faster local PDF processing (compared to Imagick).', 'document-gallery') : __('Your server is not configured to run <a href="http://www.ghostscript.com/" target="_blank">Ghostscript</a>.', 'document-gallery'), 'disabled' => !DG_GhostscriptThumber::isGhostscriptAvailable()));
    add_settings_field('thumbnail_generation_imagick', 'Imagick', array('DG_Admin', 'renderCheckboxField'), DG_OPTION_NAME, 'thumbnail_generation', array('label_for' => 'label_thumbnail_generation_imagick', 'name' => 'thumbnail_generation][imagick', 'value' => esc_attr($active['imagick']), 'option_name' => DG_OPTION_NAME, 'description' => DG_ImagickThumber::isImagickAvailable() ? __('Use <a href="http://www.php.net/manual/en/book.imagick.php" target="_blank">Imagick</a> to handle lots of filetypes locally.', 'document-gallery') : __('Your server is not configured to run <a href="http://www.php.net/manual/en/book.imagick.php" target="_blank">Imagick</a>.', 'document-gallery'), 'disabled' => !DG_ImagickThumber::isImagickAvailable()));
    add_settings_field('thumbnail_generation_width', __('Max Thumbnail Dimensions', 'document-gallery'), array('DG_Admin', 'renderMultiTextField'), DG_OPTION_NAME, 'thumbnail_generation', array(array('label_for' => 'label_advanced_width', 'name' => 'thumbnail_generation][width', 'value' => esc_attr($dg_options['thumber']['width']), 'type' => 'number" min="1" step="1', 'option_name' => DG_OPTION_NAME, 'description' => ' x '), array('label_for' => 'label_advanced_height', 'name' => 'thumbnail_generation][height', 'value' => esc_attr($dg_options['thumber']['height']), 'type' => 'number" min="1" step="1', 'option_name' => DG_OPTION_NAME, 'description' => __('The max width and height (in pixels) that thumbnails will be generated.', 'document-gallery'))));
}
 /**
  * Initializes static values for this class.
  */
 public static function init()
 {
     if (!isset(self::$unary_err)) {
         self::$unary_err = __('The %s value entered, "%s", is not valid.', 'document-gallery');
         self::$binary_err = __('The %s parameter may only be "%s" or "%s." You entered "%s."', 'document-gallery');
     }
 }
 /**
  * Returns a list of x, where x may be any of the fields within a
  * term object, when provided with a list of term names (not slugs).
  * (http://codex.wordpress.org/Function_Reference/get_term_by#Return_Values)
  *
  * Also appends an entry onto $errs if any invalid names are found.
  *
  * @param string $x Field to retrieve from matched term.
  * @param string $taxon The taxon these terms are a member of.
  * @param string[] $term_idents Terms to retrieve, identified by either slug or name.
  *
  * @return WP_Term[] All matched terms.
  */
 private function getTermXByNames($x, $taxon, $term_idents)
 {
     $ret = array();
     $valid = true;
     // taxons may optionally be prefixed by 'tax_' --
     // this is only useful when avoiding collisions with other attributes
     if (!taxonomy_exists($taxon)) {
         if (DG_Util::startsWith($taxon, 'tax_') && ($tmp = substr($taxon, 4)) && taxonomy_exists($tmp)) {
             $taxon = $tmp;
         } else {
             $this->errs[] = sprintf(DG_GallerySanitization::getUnaryErr(), 'taxon', $taxon);
             $valid = false;
         }
     }
     // only check terms if we first have a valid taxon
     if ($valid) {
         foreach ($term_idents as $ident) {
             $term = get_term_by('slug', $ident, $taxon);
             if (!$term) {
                 $term = get_term_by('name', $ident, $taxon);
             }
             if ($term) {
                 $ret[] = $term->{$x};
             } else {
                 $this->errs[] = sprintf(__('%s is not a valid term slug/name in %s.', 'document-gallery'), $ident, $taxon);
             }
         }
     }
     return $ret;
 }
				<?php 
}
?>
			</select></td>
		</tr></table>
	</label>

	<label class="setting">
		<table><tr>
			<td><span><?php 
_e('Ascending or descending sorting of documents', 'document-gallery');
?>
</span></td>
			<td><select data-setting="dgorder">
				<?php 
foreach (DG_GallerySanitization::getOrderOptions() as $i) {
    ?>
					<option value="<?php 
    echo esc_attr($i);
    ?>
" <#
						if ( '<?php 
    echo $i;
    ?>
' == wp.media.dgDefaults.dgorder ) {
							#>selected="selected"<#
						}
					#>><?php 
    echo esc_html($i);
    ?>
</option>