function tb_create_meta_box($post, $meta_box) { if (!is_array($meta_box)) { return false; } if (isset($meta_box['description']) && $meta_box['description'] != '') { echo '<p class="meta-desc">' . $meta_box['description'] . '</p>'; } wp_nonce_field(basename(__FILE__), 'tb_meta_box_nonce'); foreach ($meta_box['fields'] as $field) { // Get current post meta data $meta = get_post_meta($post->ID, $field['id'], true); echo '<div class="tb_section clearfix">'; echo '<div class="tb_col-2">'; echo '<h4>' . $field['name'] . '</h4><div class="desc">' . $field['desc'] . '</div>'; echo '</div>'; echo '<div class="tb_col-2">'; echo '<div class="input ' . tb_to_slug($field['type']) . '">'; switch ($field['type']) { case 'text': echo '<input type="text" name="tb_meta[' . $field['id'] . ']" id="' . $field['id'] . '" value="' . ($meta ? $meta : $field['std']) . '" size="30" />'; break; case 'date': echo '<input type="date" name="tb_meta[' . $field['id'] . ']" id="' . $field['id'] . '" value="' . ($meta ? $meta : $field['std']) . '" size="30" />'; break; case 'time': echo '<input type="time" name="tb_meta[' . $field['id'] . ']" id="' . $field['id'] . '" value="' . ($meta ? $meta : $field['std']) . '" size="30" />'; break; case 'textarea': echo '<textarea name="tb_meta[' . $field['id'] . ']" id="' . $field['id'] . '" rows="8" cols="5">' . ($meta ? $meta : $field['std']) . '</textarea>'; break; case 'file': echo '<input type="text" name="tb_meta[' . $field['id'] . ']" id="' . $field['id'] . '" value="' . ($meta ? $meta : $field['std']) . '" class="tb_upload_file" />'; echo '<input type="button" class="tb_upload_file_button" name="' . $field['id'] . '_button" id="' . $field['id'] . '_button" value="Browse" />'; break; case 'images': echo '<input type="button" class="button" name="' . $field['id'] . '" id="tb_images_upload" value="' . $field['std'] . '" />'; break; case 'select': echo '<select name="tb_meta[' . $field['id'] . ']" id="' . $field['id'] . '">'; foreach ($field['options'] as $option) { echo '<option'; if ($meta) { if ($meta == $option) { echo ' selected="selected"'; } } else { if ($field['std'] == $option) { echo ' selected="selected"'; } } echo '>' . $option . '</option>'; } echo '</select>'; break; case 'radio': foreach ($field['options'] as $option) { echo '<label class="radio-label"><input type="radio" name="tb_meta[' . $field['id'] . ']" value="' . $option . '" class="radio"'; if ($meta) { if ($meta == $option) { echo ' checked="yes"'; } } else { if ($field['std'] == $option) { echo ' checked="yes"'; } } echo ' /> ' . $option . '</label> '; } break; case 'color': if (array_key_exists('val', $field)) { $val = ' value="' . $field['val'] . '"'; } if ($meta) { $val = ' value="' . $meta . '"'; } echo '<div class="colorpicker-wrapper">'; echo '<input type="text" id="' . $field['id'] . '_cp" name="tb_meta[' . $field['id'] . ']"' . $val . ' />'; echo '<div id="' . $field['id'] . '" class="colorpicker"></div>'; echo '</div>'; break; case 'checkbox': $val = ''; if ($meta) { if ($meta == 'on') { $val = ' checked="yes"'; } } else { if ($field['std'] == 'on') { $val = ' checked="yes"'; } } echo '<input type="hidden" name="tb_meta[' . $field['id'] . ']" value="off" /> <input type="checkbox" id="' . $field['id'] . '" name="tb_meta[' . $field['id'] . ']" value="on"' . $val . ' /> '; break; } echo '</div>'; echo '</div>'; echo '</div>'; } }
function tb_options_page() { global $tb_changelog_link, $tb_docs_link; $tb_options = get_option('tb_framework_options'); ksort($tb_options['tb_framework']); ?> <div id="tb-framework" class="clearfix"> <form action="<?php echo site_url() . '/wp-admin/admin-ajax.php'; ?> " method="post"> <div class="main clearfix"> <div class="nav"> <div class="header"> <h1><a href="https://s3bubble.com/" target="_blank">S3Bubble</a></h1> <small>Version <?php _e($tb_options['theme_version'], 'tb'); ?> </small> </div> <ul> <?php foreach ($tb_options['tb_framework'] as $page) { ?> <li><a href="#<?php echo tb_to_slug(key($page)); ?> "><?php _e(key($page), 'tb'); ?> </a></li> <?php } ?> </ul> </div> <div class="dark"></div> <?php if (isset($_GET['activated'])) { ?> <div class="activated"> <h1>High Five!</h1> <p>So you've just made the best decision of your life. Ok maybe just the best decision of your day but still it's a great one.</p> </div> <?php } ?> <div class="content clearfix"> <?php foreach ($tb_options['tb_framework'] as $page) { ?> <div id="page-<?php echo tb_to_slug(key($page)); ?> " class="page"> <h2><?php _e(key($page), 'tb'); ?> </h2> <p class="page-desc"><?php if (isset($page[key($page)]['description']) && $page[key($page)]['description'] != '') { _e($page[key($page)]['description'], 'tb'); } ?> </p> <?php foreach ($page[key($page)] as $item) { ?> <?php if (key((array) $item) == 'description') { continue; } ?> <div class="tb_section clearfix <?php echo tb_to_slug($item['title']); ?> "> <div class="tb_col-2"> <h3><?php _e($item['title'], 'tb'); ?> </h3> <?php if (isset($item['desc']) && $item['desc'] != '') { ?> <div class="desc"> <?php _e($item['desc'], 'tb'); ?> </div> <?php } ?> </div> <div class="tb_col-2"> <?php tb_create_input($item); ?> </div> </div> <?php } ?> </div> <?php } ?> </div> <div class="footer clearfix"> <input type="hidden" name="action" value="tb_framework_save" /> <input type="hidden" name="tb_noncename" id="tb_noncename" value="<?php echo wp_create_nonce('tb_framework_options'); ?> " /> <input type="button" value="<?php _e('Reset Options', 'tb'); ?> " class="button" id="reset-button" /> <input type="submit" value="<?php _e('Save All Changes', 'tb'); ?> " class="button-primary" id="save-button" /> </div> <div class="tb-clear"></div> </div> </form> </div> <?php if (TB_DEBUG) { ?> <div id="tb-debug"> <p><strong>Debug Output</strong></p> <textarea><?php echo '//tb_framework_values' . "\n"; print_r(get_option('tb_framework_values')); echo '//tb_framework_options' . "\n"; print_r($tb_options); echo '//misc' . "\n"; echo 'TEMPLATEPATH: ' . get_template_directory(); ?> </textarea> </div> <?php } }
function tb_create_input($item) { $tb_values = get_option('tb_framework_values'); echo '<div class="input ' . tb_to_slug($item['type']) . '">'; // Set the class $class = ''; if (array_key_exists('class', $item)) { $class = ' class="' . $item['class'] . '"'; } // Do we ignore this input? $prefix = 'settings'; if (array_key_exists('ignore', $item) && $item['ignore'] == true) { $prefix = 'ignore'; } // text input if ($item['type'] == 'text') { $val = ''; if (array_key_exists('val', $item)) { $val = ' value="' . $item['val'] . '"'; } if (array_key_exists($item['id'], $tb_values)) { $val = ' value="' . $tb_values[$item['id']] . '"'; } if (empty($tb_values[$item['id']]) && array_key_exists('default', $item)) { $val = ' value="' . $item['default'] . '"'; } echo '<input type="text" id="' . $item['id'] . '" name="' . $prefix . '[' . $item['id'] . ']"' . $val . $class . ' />'; } // textarea if ($item['type'] == 'textarea') { $val = ''; if (array_key_exists('val', $item)) { $val = $item['val']; } if (array_key_exists($item['id'], $tb_values)) { $val = $tb_values[$item['id']]; } if (empty($tb_values[$item['id']]) && array_key_exists('default', $item)) { $val = $item['default']; } echo '<textarea id="' . $item['id'] . '" name="' . $prefix . '[' . $item['id'] . ']"' . $class . '>' . stripslashes($val) . '</textarea>'; } // select if ($item['type'] == 'select' && array_key_exists('options', $item)) { echo '<select id="' . $item['id'] . '" name="' . $prefix . '[' . $item['id'] . ']"' . $class . '>'; foreach ($item['options'] as $key => $value) { $val = ''; if (array_key_exists($item['id'], $tb_values)) { if ($tb_values[$item['id']] == $key) { $val = ' selected="selected"'; } } else { if (array_key_exists('val', $item) && $item['val'] == $key) { $val = ' selected="selected"'; } } echo '<option value="' . $key . '"' . $val . '>' . __($value, 'tb') . '</option>'; } echo '</select>'; } // pages select if ($item['type'] == 'pages') { $tb_pages_obj = get_pages(); echo '<select id="' . $item['id'] . '" name="' . $prefix . '[' . $item['id'] . ']"' . $class . '>'; foreach ($tb_pages_obj as $tb_page) { $val = ''; if (array_key_exists($item['id'], $tb_values)) { if ($tb_values[$item['id']] == $tb_page->ID) { $val = ' selected="selected"'; } } else { if (array_key_exists('val', $item) && $item['val'] == $tb_page->ID) { $val = ' selected="selected"'; } } echo '<option value="' . $tb_page->ID . '"' . $val . '>' . __($tb_page->post_title, 'tb') . '</option>'; } echo '</select>'; } // category select if ($item['type'] == 'categories') { $tb_categories_obj = get_categories('hide_empty=0'); echo '<select id="' . $item['id'] . '" name="' . $prefix . '[' . $item['id'] . ']"' . $class . '>'; foreach ($tb_categories_obj as $tb_category) { $val = ''; if (array_key_exists($item['id'], $tb_values)) { if ($tb_values[$item['id']] == $tb_category->cat_ID) { $val = ' selected="selected"'; } } else { if (array_key_exists('val', $item) && $item['val'] == $tb_category->cat_ID) { $val = ' selected="selected"'; } } echo '<option value="' . $tb_category->cat_ID . '"' . $val . '>' . __($tb_category->cat_name, 'tb') . '</option>'; } echo '</select>'; } // radio if ($item['type'] == 'radio' && array_key_exists('options', $item)) { $i = 0; foreach ($item['options'] as $key => $value) { $val = ''; if (array_key_exists($item['id'], $tb_values)) { if ($tb_values[$item['id']] == $key) { $val = ' checked="checked"'; } } else { if (array_key_exists('val', $item) && $item['val'] == $key) { $val = ' checked="checked"'; } } echo '<label for="' . $item['id'] . '_' . $i . '"><input type="radio" id="' . $item['id'] . '_' . $i . '" name="' . $prefix . '[' . $item['id'] . ']" value="' . $key . '"' . $val . $class . '> ' . __($value, 'tb') . '</label><br />'; $i++; } } // checkbox if ($item['type'] == 'checkbox') { $val = ''; if (array_key_exists('val', $item) && $item['val'] == 'on') { $val = ' checked="yes"'; } if (array_key_exists($item['id'], $tb_values) && $tb_values[$item['id']] == 'on') { $val = ' checked="yes"'; } if (array_key_exists($item['id'], $tb_values) && $tb_values[$item['id']] != 'on') { $val = ''; } echo '<input type="hidden" name="' . $prefix . '[' . $item['id'] . ']" value="off" /> <input type="checkbox" id="' . $item['id'] . '" name="' . $prefix . '[' . $item['id'] . ']" value="on"' . $class . $val . ' /> '; if (array_key_exists('text', $item)) { _e($item['text'], 'tb'); } } // multi checkbox if ($item['type'] == 'multi_checkbox' && array_key_exists('options', $item)) { foreach ($item['options'] as $key => $value) { $val = ''; $id = $item['id'] . '_' . tb_to_slug($key); if ($value == 'on') { $val = ' checked="yes"'; } if (array_key_exists($id, $tb_values) && $tb_values[$id] == 'on') { $val = ' checked="yes"'; } if (array_key_exists($id, $tb_values) && $tb_values[$id] != 'on') { $val = ''; } echo '<input type="hidden" name="' . $prefix . '[' . $id . ']" value="off" /> <input type="checkbox" id="' . $id . '" name="' . $prefix . '[' . $id . ']" value="on"' . $class . $val . ' /> '; echo '<label for="' . $id . '">' . __($value, 'tb') . '</label><br />'; } } // file if ($item['type'] == 'file') { echo '<input id="' . $item['id'] . '" class="tb_upload_file" type="text" size="36" name="' . esc_attr($prefix . '[' . $item['id'] . ']') . '" value="' . esc_attr($tb_values[$item['id']]) . '" />'; echo '<input class="tb_upload_file_button" type="button" value="Browse" />'; } // colour input if ($item['type'] == 'colour') { $val = ''; if (array_key_exists('val', $item)) { $val = ' value="' . $item['val'] . '"'; } if (array_key_exists($item['id'], $tb_values)) { $val = ' value="' . $tb_values[$item['id']] . '"'; } echo '<input class="tb-color-picker" name="' . $prefix . '[' . $item['id'] . ']"' . $val . ' class="shorter" id="" type="text" value="' . esc_attr($val) . '" />'; } // html if ($item['type'] == 'html') { _e($item['val'], 'tb'); } // Custom if ($item['type'] == 'custom') { $func = ''; $args = array(); $id = ''; if (array_key_exists('function', $item)) { $func = $item['function']; } if (array_key_exists('args', $item)) { $args = $item['args']; } if (array_key_exists('id', $item)) { $id = $item['id']; } if ($func != '') { call_user_func($func, $id, $args); } } // after if (array_key_exists('after', $item) && $item['after'] != '') { echo $item['after']; } echo '</div>'; }