Skip to content

Instantly share code, notes, and snippets.

@vajrasar
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vajrasar/ad4b8a996729afadf94e to your computer and use it in GitHub Desktop.
Save vajrasar/ad4b8a996729afadf94e to your computer and use it in GitHub Desktop.
Using Options Framework
<?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 (lowercase and without spaces)
$themename = get_option( 'stylesheet' );
$themename = preg_replace("/\W/", "_", strtolower($themename) );
$optionsframework_settings = get_option('optionsframework');
$optionsframework_settings['id'] = $themename;
update_option('optionsframework', $optionsframework_settings);
// echo $themename;
}
/**
* 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.
*
*/
function optionsframework_options() {
// Build multicheck for pages - this will be later used below in a checklist
$p_args = array(
'sort_column' => 'menu_order',
);
$options_pages_obj = get_pages( $p_args );
foreach ($options_pages_obj as $page) {
$page_list[$page->ID] = $page->post_title;
}
$multicheck_array = $page_list;
$options = array();
/*
* type = heading enables you to define tabs and the options[] you provide below
* it falls under that tab unless other tab is defined.
*/
$options[] = array(
'name' => 'Basic Settings',
'type' => 'heading'
);
$options[] = array(
'name' => 'Upload Header Image',
'id' => 'header_image',
'type' => 'upload');
$options[] = array(
'name' => 'Facebook Link',
'id' => 'fb_link',
'std' => '#',
'type' => 'text');
$options[] = array(
'name' => 'Twitter Link',
'id' => 'twitter_link',
'std' => '#',
'type' => 'text');
$options[] = array(
'name' => 'Google+ Link',
'id' => 'google_link',
'std' => '#',
'type' => 'text');
$options[] = array(
'name' => 'LinkedIn Link',
'id' => 'linkedin_link',
'std' => '#',
'type' => 'text');
$options[] = array(
'name' => 'Contact Number',
'id' => 'contact_numb',
'type' => 'text');
$options[] = array(
'name' => 'Email Id',
'id' => 'contact_email',
'type' => 'text');
// Here we use the multicheck_array that we created above in the code
$options[] = array(
'name' => 'Select Pages for Menu',
'id' => 'menu_pages',
'type' => 'multicheck',
'options' => $multicheck_array);
// Another Tab.
$options[] = array(
'name' => 'Footer Settings',
'type' => 'heading'
);
$options[] = array(
'name' => 'Welcome Text',
'id' => 'footer_welcome',
'type' => 'textarea');
$options[] = array(
'name' => 'Subscribe Text',
'id' => 'footer_subs',
'type' => 'textarea');
return $options;
}
<?php
// To use those options for displaying value
$fb_link = of_get_option('fb_link' );
$twitter_link = of_get_option('twitter_link' );
$linkedin_link = of_get_option('linkedin_link' );
$google_link = of_get_option('google_link' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment