/** * 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; }
/** * Get the default values for all the theme options * * Get an array of all default values as set in * options.php. The 'id','std' and 'type' keys need * to be defined in the configuration array. In the * event that these keys are not present the option * will not be included in this function's output. * * @since 1.0.0 * @return array Re-keyed options configuration array. */ function get_default_values() { $output = array(); $config = Hoot_Options::_hootoptions_options(); foreach ((array) $config as $option) { if (!isset($option['id'])) { continue; } if (!isset($option['std'])) { continue; } if (!isset($option['type'])) { continue; } if (has_filter('hoot_of_sanitize_' . $option['type'])) { $output[$option['id']] = apply_filters('hoot_of_sanitize_' . $option['type'], $option['std'], $option); } } return $output; }
/** * 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>'; } }