/**
  * Media Uploader Using the WordPress Media Library.
  *
  * Parameters:
  * string $_id - A token to identify this field (the name).
  * string $_value - The value of the field, if present.
  * string $_desc - An optional description of the field.
  *
  * @since 1.0.0
  */
 static function hootoptions_uploader($_id, $_value, $_desc = '', $_name = '')
 {
     // Gets the unique option id
     $option_name = Hoot_Options::_get_option_name();
     $output = '';
     $id = '';
     $class = '';
     $int = '';
     $value = '';
     $name = '';
     $id = strip_tags(strtolower($_id));
     // If a value is passed and we don't have a stored value, use the value that's passed through.
     if ($_value != '' && $value == '') {
         $value = $_value;
     }
     if ($_name != '') {
         $name = $_name;
     } else {
         $name = $option_name . '[' . $id . ']';
     }
     if ($value) {
         $class = ' has-file';
     }
     $output .= '<input id="' . esc_attr($id) . '" class="upload' . $class . '" type="text" name="' . esc_attr($name) . '" value="' . $value . '" placeholder="' . __('No file chosen', 'dispatch') . '" />' . "\n";
     if (function_exists('wp_enqueue_media')) {
         if ($value == '') {
             $output .= '<input id="upload-' . esc_attr($id) . '" class="upload-button button" type="button" value="' . __('Upload', 'dispatch') . '" />' . "\n";
         } else {
             $output .= '<input id="remove-' . esc_attr($id) . '" class="remove-file button" type="button" value="' . __('Remove', 'dispatch') . '" />' . "\n";
         }
     } else {
         $output .= '<p><i>' . __('Upgrade your version of WordPress for full media support.', 'dispatch') . '</i></p>';
     }
     if ($_desc != '') {
         $output .= '<span class="hoot-of-metabox-desc">' . $_desc . '</span>' . "\n";
     }
     $output .= '<div class="screenshot" id="' . $id . '-image">' . "\n";
     if ($value != '') {
         $remove = '<a class="remove-image">Remove</a>';
         $image = preg_match('/(^.*\\.jpg|jpeg|png|gif|ico*)/i', $value);
         if ($image) {
             $output .= '<img src="' . $value . '" alt="" />' . $remove;
         } else {
             $parts = explode("/", $value);
             for ($i = 0; $i < sizeof($parts); ++$i) {
                 $title = $parts[$i];
             }
             // No output preview if it's not an image.
             $output .= '';
             // Standard generic output if it's not an image.
             $title = __('View File', 'dispatch');
             $output .= '<div class="no-image"><span class="file_link"><a href="' . $value . '" target="_blank" rel="external">' . $title . '</a></span></div>';
         }
     }
     $output .= '</div>' . "\n";
     return $output;
 }
Пример #2
0
    /**
     * Builds out the options panel.
     *
     * If we were using the Settings API as it was intended we would use
     * do_settings_sections here.  But as we don't want the settings wrapped in a table,
     * we'll call our own custom hootoptions_fields.  See hoot-options-interface.php
     * for specifics on how each individual field is generated.
     *
     * Nonces are provided using the settings_fields()
     *
     * @since 1.0.0
     */
    function options_page()
    {
        $name = Hoot_Options::_get_option_name();
        ?>

		<div class="hootoptions-intro-box">
			<div class="hootoptions-intro">
				<a class="hootoptions-intro-img" href="<?php 
        echo esc_url(THEME_AUTHOR_URI);
        ?>
" /><img src="<?php 
        echo trailingslashit(HOOT_IMAGES) . 'logo.png';
        ?>
"></a>
				<div class="hootoptions-intro-message">
					<p><?php 
        echo Hoot_Options_Interface::hootoptions_intro();
        ?>
</p>
				</div>
			</div>
		</div>

		<div id="hootoptions-wrap" class="hootoptions wrap">

		<?php 
        $menu = $this->menu_settings();
        ?>
		<h2><?php 
        echo esc_html($menu['page_title']);
        ?>
</h2>

		<?php 
        settings_errors('hoot-options');
        ?>

		<h2 class="nav-tab-wrapper">
			<?php 
        echo Hoot_Options_Interface::hootoptions_tabs();
        ?>
		</h2>

		<div id="hootoptions-box" class="metabox-holder">
			<div id="hootoptions" class="postbox">
				<form action="options.php" method="post">
				<?php 
        settings_fields($name);
        ?>
				<?php 
        Hoot_Options_Interface::hootoptions_fields();
        /* Settings */
        ?>
				<div id="hootoptions-submit">
					<input type="submit" class="button-primary" name="update" value="<?php 
        esc_attr_e('Save Options', 'dispatch');
        ?>
" />
					<input type="submit" class="reset-button button-secondary" name="reset" value="<?php 
        esc_attr_e('Restore Defaults', 'dispatch');
        ?>
" onclick="return confirm( '<?php 
        print esc_js(__('Click OK to reset. Any theme settings will be lost!', 'dispatch'));
        ?>
' );" />
					<div class="clear"></div>
				</div>
				</form>
			</div> <!-- / #container -->
		</div>
		<?php 
        do_action('hootoptions_after');
        ?>
		</div> <!-- / .wrap -->

	<?php 
    }
 /**
  * Generates the options fields that are used in the form.
  * This function displays options using theme options page settings if $is_options_page is true,
  * else, it can render option fields for any $options array with $settings value (example: meta fields).
  *
  * @since 1.0.0
  * @param bool $is_options_page If displaying options page
  * @param array $options Options array
  * @param array $settings Options values
  * @param string $prefix Options namespace
  */
 static function hootoptions_fields($is_options_page = true, $options = array(), $settings = array(), $prefix = '')
 {
     $prefix = $prefix ? $prefix : THEME_SLUG;
     $counter = $subcounter = 0;
     /* If this is the options page then use theme options. */
     if ($is_options_page === true) {
         $options = Hoot_Options::_hootoptions_options();
         $option_name = Hoot_Options::_get_option_name();
         $settings = self::$cache['settings'] = get_option($option_name);
         // For Settings API, the value array's name ($prefix) must be the same as
         // $option_name (as used in register_setting() )
         $prefix = $option_name;
     }
     if (empty($options)) {
         return;
     }
     foreach ($options as $field) {
         if (!isset($field['type'])) {
             continue;
             /* Heading for Navigation */
         } elseif ($field['type'] == 'heading') {
             if (!$is_options_page) {
                 echo '<div class="section-header"><p>' . esc_html($field['name']) . '</p></div>' . "\n";
                 continue;
             }
             // (Options Page only)
             $output = '';
             if ($subcounter) {
                 $output .= '</div>' . "\n";
             }
             $subcounter = 0;
             $counter++;
             if ($counter >= 2) {
                 $output .= '</div>' . "\n";
             }
             $class = $tab = '';
             $class = $tab = !empty($field['id']) ? $field['id'] : $field['name'];
             $class = preg_replace('/[^a-zA-Z0-9._\\-]/', '', strtolower($class));
             $output .= '<div id="tab-panel-' . $counter . '-panel" class="tab-panel ' . $class . '">';
             // Add heading if this tab doesnt contain any subtabs
             if (!empty(self::$subtabs[$tab]) && is_array(self::$subtabs[$tab])) {
                 $output .= '<div class="nav-subtab-wrapper">';
                 foreach (self::$subtabs[$tab] as $subkey => $subtab) {
                     $stc = $counter . '_' . ($subkey + 1);
                     $output .= '<div id="nav-subtab-' . $stc . '" class="nav-subtab" data-panel="' . esc_attr('#subtab-panel-' . $stc . '-panel') . '">' . esc_html($subtab) . '</div>';
                 }
                 $output .= '</div>' . "\n";
             } else {
                 $output .= '<div class="nav-subtab-wrapper"><p>' . esc_html($field['name']) . '</p></div>' . "\n";
             }
             echo $output;
             /* Subheadings for Navigation */
         } elseif ($field['type'] == 'subheading') {
             if (!$is_options_page) {
                 echo '<div class="section-header"><p>' . esc_html($field['name']) . '</p></div>' . "\n";
                 continue;
             }
             // (Options Page only)
             $output = '';
             $subcounter++;
             if ($subcounter >= 2) {
                 $output .= '</div>' . "\n";
             }
             $class = '';
             $class = !empty($field['id']) ? $field['id'] : $field['name'];
             $class = preg_replace('/[^a-zA-Z0-9_\\-]/', '', strtolower($class));
             $output .= '<div id="subtab-panel-' . $counter . '_' . $subcounter . '-panel" class="subtab-panel ' . $class . '">';
             echo $output;
             /* Raw HTML */
         } elseif ($field['type'] == 'html') {
             if (isset($field['std'])) {
             }
             echo $field['std'];
             /* Other Field Types */
         } else {
             $val = '';
             // Set default value to $val
             if (isset($field['std'])) {
                 $val = $field['std'];
             }
             // Set id for import/export
             if ($field['type'] == 'import') {
                 $field['id'] = 'import';
             }
             if ($field['type'] == 'export') {
                 $field['id'] = 'export';
             }
             // If the option is already saved, override $val
             if ($field['type'] != 'info') {
                 if (isset($settings[$field['id']])) {
                     $val = $settings[$field['id']];
                     // Striping slashes of non-array options and non-code options
                     if (!is_array($val) && !($field['type'] == 'textarea' && !empty($field['settings']['code']))) {
                         $val = stripslashes($val);
                     }
                 }
             }
             // Print the field HTML
             self::hootoptions_field($prefix, '', $field, $val, true);
         }
     }
     /* Outputs closing div if there subtabs in last tab (Options Page only) */
     if ($is_options_page && $subcounter) {
         echo '</div>';
     }
     /* Outputs closing div if there tabs (Options Page only) */
     if ($is_options_page && Hoot_Options_Interface::hootoptions_tabs() != '') {
         echo '</div>';
     }
 }