Skip to content

Instantly share code, notes, and snippets.

@clare485
Created November 20, 2013 15:53
Show Gist options
  • Save clare485/7565484 to your computer and use it in GitHub Desktop.
Save clare485/7565484 to your computer and use it in GitHub Desktop.
****** NOTE ******
$test_array should be deleted and will throw cautions on the theme options page of wordpress
<?php
/**
* A unique identifier is defined to store the options in the database and reference them from the theme.
* By default it uses the theme name, in lowercase and without spaces, but this can be changed if needed.
* If the identifier changes, it'll appear as if the options have been reset.
*/
function optionsframework_option_name() {
// This gets the theme name from the stylesheet
$themename = get_option('stylesheet');
$themename = preg_replace("/\W/", "_", strtolower($themename));
$optionsframework_settings = get_option('optionsframework');
$optionsframework_settings['id'] = $themename;
update_option('optionsframework', $optionsframework_settings);
}
/**
* Defines an array of options that will be used to generate the settings page and be saved in the database.
* When creating the 'id' fields, make sure to use all lowercase and no spaces.
*
* If you are making your theme translatable, you should replace 'options_framework_theme'
* with the actual text domain for your theme. Read more:
* http://codex.wordpress.org/Function_Reference/load_theme_textdomain
*/
function optionsframework_options() {
$options = array();
$options[] = array(
'name' => __('Basic Settings', 'options_framework_theme'),
'type' => 'heading');
$options[] = array(
'name' => __('Input Text Mini', 'options_framework_theme'),
'desc' => __('A mini text input field.', 'options_framework_theme'),
'id' => 'example_text_mini',
'std' => 'Default',
'class' => 'mini',
'type' => 'text');
$options[] = array(
'name' => __('Input Text', 'options_framework_theme'),
'desc' => __('A text input field.', 'options_framework_theme'),
'id' => 'example_text',
'std' => 'Default Value',
'type' => 'text');
$options[] = array(
'name' => __('Textarea', 'options_framework_theme'),
'desc' => __('Textarea description.', 'options_framework_theme'),
'id' => 'example_textarea',
'std' => 'Default Text',
'type' => 'textarea');
$options[] = array(
'name' => __('Input Select Small', 'options_framework_theme'),
'desc' => __('Small Select Box.', 'options_framework_theme'),
'id' => 'example_select',
'std' => 'three',
'type' => 'select',
'class' => 'mini', //mini, tiny, small
'options' => $test_array);
$options[] = array(
'name' => __('Input Select Wide', 'options_framework_theme'),
'desc' => __('A wider select box.', 'options_framework_theme'),
'id' => 'example_select_wide',
'std' => 'two',
'type' => 'select',
'options' => $test_array);
$options[] = array(
'name' => __('Select a Category', 'options_framework_theme'),
'desc' => __('Passed an array of categories with cat_ID and cat_name', 'options_framework_theme'),
'id' => 'example_select_categories',
'type' => 'select',
'options' => $options_categories);
if ($options_tags) {
$options[] = array(
'name' => __('Select a Tag', 'options_check'),
'desc' => __('Passed an array of tags with term_id and term_name', 'options_check'),
'id' => 'example_select_tags',
'type' => 'select',
'options' => $options_tags);
}
$options[] = array(
'name' => __('Select a Page', 'options_framework_theme'),
'desc' => __('Passed an pages with ID and post_title', 'options_framework_theme'),
'id' => 'example_select_pages',
'type' => 'select',
'options' => $options_pages);
$options[] = array(
'name' => __('Input Radio (one)', 'options_framework_theme'),
'desc' => __('Radio select with default options "one".', 'options_framework_theme'),
'id' => 'example_radio',
'std' => 'one',
'type' => 'radio',
'options' => $test_array);
$options[] = array(
'name' => __('Example Info', 'options_framework_theme'),
'desc' => __('This is just some example information you can put in the panel.', 'options_framework_theme'),
'type' => 'info');
$options[] = array(
'name' => __('Input Checkbox', 'options_framework_theme'),
'desc' => __('Example checkbox, defaults to true.', 'options_framework_theme'),
'id' => 'example_checkbox',
'std' => '1',
'type' => 'checkbox');
$options[] = array(
'name' => __('Advanced Settings', 'options_framework_theme'),
'type' => 'heading');
$options[] = array(
'name' => __('Check to Show a Hidden Text Input', 'options_framework_theme'),
'desc' => __('Click here and see what happens.', 'options_framework_theme'),
'id' => 'example_showhidden',
'type' => 'checkbox');
$options[] = array(
'name' => __('Hidden Text Input', 'options_framework_theme'),
'desc' => __('This option is hidden unless activated by a checkbox click.', 'options_framework_theme'),
'id' => 'example_text_hidden',
'std' => 'Hello',
'class' => 'hidden',
'type' => 'text');
$options[] = array(
'name' => __('Uploader Test', 'options_framework_theme'),
'desc' => __('This creates a full size uploader that previews the image.', 'options_framework_theme'),
'id' => 'example_uploader',
'type' => 'upload');
$options[] = array(
'name' => "Example Image Selector",
'desc' => "Images for layout.",
'id' => "example_images",
'std' => "2c-l-fixed",
'type' => "images",
'options' => array(
'1col-fixed' => $imagepath . '1col.png',
'2c-l-fixed' => $imagepath . '2cl.png',
'2c-r-fixed' => $imagepath . '2cr.png')
);
$options[] = array(
'name' => __('Example Background', 'options_framework_theme'),
'desc' => __('Change the background CSS.', 'options_framework_theme'),
'id' => 'example_background',
'std' => $background_defaults,
'type' => 'background');
$options[] = array(
'name' => __('Multicheck', 'options_framework_theme'),
'desc' => __('Multicheck description.', 'options_framework_theme'),
'id' => 'example_multicheck',
'std' => $multicheck_defaults, // These items get checked by default
'type' => 'multicheck',
'options' => $multicheck_array);
$options[] = array(
'name' => __('Colorpicker', 'options_framework_theme'),
'desc' => __('No color selected by default.', 'options_framework_theme'),
'id' => 'example_colorpicker',
'std' => '',
'type' => 'color');
$options[] = array('name' => __('Typography', 'options_framework_theme'),
'desc' => __('Example typography.', 'options_framework_theme'),
'id' => "example_typography",
'std' => $typography_defaults,
'type' => 'typography');
$options[] = array(
'name' => __('Custom Typography', 'options_framework_theme'),
'desc' => __('Custom typography options.', 'options_framework_theme'),
'id' => "custom_typography",
'std' => $typography_defaults,
'type' => 'typography',
'options' => $typography_options);
$options[] = array(
'name' => __('Text Editor', 'options_framework_theme'),
'type' => 'heading');
/**
* For $settings options see:
* http://codex.wordpress.org/Function_Reference/wp_editor
*
* 'media_buttons' are not supported as there is no post to attach items to
* 'textarea_name' is set by the 'id' you choose
*/
$wp_editor_settings = array(
'wpautop' => true, // Default
'textarea_rows' => 5,
'tinymce' => array('plugins' => 'wordpress')
);
$options[] = array(
'name' => __('Default Text Editor', 'options_framework_theme'),
'desc' => sprintf(__('You can also pass settings to the editor. Read more about wp_editor in <a href="%1$s" target="_blank">the WordPress codex</a>', 'options_framework_theme'), 'http://codex.wordpress.org/Function_Reference/wp_editor'),
'id' => 'example_editor',
'type' => 'editor',
'settings' => $wp_editor_settings);
return $options;
}
1)
Copy the /inc/ folder from the options framework theme directory in the web development/INTERNAL folder into the root of your child theme. Call ‘includes’ ‘inc’ from now on to save you having two folders.
2)
Copy options.php across and put it in the child theme root
3)
Put this in your functions.php (it’s in functions.php in the options framework folder just in case)
if ( !function_exists( 'optionsframework_init' ) ) {
define( 'OPTIONS_FRAMEWORK_DIRECTORY', get_stylesheet_directory_uri() . '/inc/' );
require_once dirname( __FILE__ ) . '/inc/options-framework.php';
}
4)
Set up options in your options.php using examples using the Options.php file above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment