Last active
August 29, 2015 14:26
-
-
Save alexandrascript/7a39bf97ba490f63523a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Plugin Name: Theme Settings | |
* Version: 1 | |
* Plugin URI: http://ieg.wnet.org/ | |
* Description: Create a theme settings page | |
* Author: Alexandra White | |
* Author URI: http://ieg.wnet.org/blog/author/whitea/ | |
* Requires at least: 3.6 | |
* Tested up to: 4.2.2 | |
* | |
* @package WordPress | |
* @author Alexandra White | |
* @since 1.0.0 | |
* | |
* This program is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation, either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License | |
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |
* | |
*/ | |
//Create the Theme Settings Page in the Main Dashboard Menu | |
function add_theme_menu_item() { | |
add_menu_page("Theme Settings", "Theme Settings", "manage_options", "aw-theme-settings", "awtheme_options_page", null, 99); | |
} | |
add_action("admin_menu", "add_theme_menu_item"); | |
//Register all of the settings for the settings page | |
function awtheme_register_settings() { | |
//Declare all options and if applicable, the default information | |
add_option( 'aw_google_cse', ''); | |
add_option( 'aw_google_tags', ''); | |
add_option( 'aw_homepage_zone', 'homepage-carousel'); | |
add_option( 'aw_social_facebook', 'http://www.facebook.com/wnet-thirteen'); | |
add_option( 'aw_social_twitter', 'https://twitter.com/thirteenny'); | |
add_option( 'aw_social_instagram', 'https://instagram.com'); | |
add_option( 'aw_footer1', 'Produced by <a href="http://www.thirteen.org">THIRTEEN</a> © 2015 <a href="http://www.wnet.org">WNET</a>. All rights reserved.'); | |
//Register all previously declared settings | |
register_setting( 'awthemesettings', 'aw_google_cse' ); | |
register_setting( 'awthemesettings', 'aw_google_tags' ); | |
register_setting( 'awthemesettings', 'aw_homepage_format' ); | |
register_setting( 'awthemesettings', 'aw_social_facebook'); | |
register_setting( 'awthemesettings', 'aw_social_twitter'); | |
register_setting( 'awthemesettings', 'aw_social_instagram'); | |
register_setting( 'awthemesettings', 'aw_footer1'); | |
} | |
add_action( 'admin_init', 'awtheme_register_settings' ); | |
//Build the theme options page | |
function awtheme_options_page() { ?> | |
<div class="wrap"> | |
<style> | |
/*** Make your theme page pretty by wrapping your inputs in divs and styling them ***/ | |
.wrap h2 {margin-bottom: .7em;} | |
.postbox {width: 100%; float: left; margin: 0 0 1% 0;} | |
.postbox h3 {padding: 1%; margin: 0;} | |
.postbox .inside {padding: 0 1% 1% 1%;} | |
.postbox .inside input[type='text'], .postbox .inside textarea {width: 100%;} | |
</style> | |
<div> | |
<h1>Theme Options</h1> | |
<form method="post" action="options.php"> | |
<?php settings_fields( 'awthemesettings' ); //do this before building the inputs for the settings ?> | |
<!-- Organize the different types of inputs in .postbox divs --> | |
<!-- API Keys --> | |
<div class="postbox" > | |
<h3>API Keys</h3> | |
<div class="inside"> | |
<label for="aw_google_cse">Google Custom Search KEY:</label><br> | |
<input type="text" id="aw_google_cse" name="aw_google_cse" value="<?php echo get_option('aw_google_cse'); ?>" /><br> | |
<label for="aw_google_tags">Google TAG Manager KEY:</label><br> | |
<input type="text" id="aw_google_tags" name="aw_google_tags" value="<?php echo get_option('aw_google_tags'); ?>" /> | |
</div> | |
</div> | |
<!-- end API Keys --> | |
<!-- homepage layout --> | |
<div class="postbox" > | |
<h3>Homepage Layout</h3> | |
<div class="inside"> | |
<label for="aw_homepage_format">Layout:</label><br> | |
<?php $selected = ' selected'; ?> | |
<?php $hp_type = get_option('aw_homepage_format'); ?> | |
<select name="aw_homepage_format"> | |
<option value="1"<?php if ( $hp_type == '1') echo $selected; ?>>Standard Grid</option> | |
<option value="2"<?php if ( $hp_type == '2') echo $selected; ?>>Dynamic Grid</option> | |
</select> | |
</div> | |
</div> | |
<!-- end homepage layout --> | |
<!-- social media --> | |
<div class="postbox" > | |
<h3>Social Media</h3> | |
<div class="inside"> | |
<!-- Remember to build a fallback if admins don't include the "http://" in the URL input wherever these options are used --> | |
<label for="aw_social_facebook">Facebook Full URL:</label><br> | |
<input type="text" id="aw_social_facebook" name="aw_social_facebook" value="<?php echo get_option('aw_social_facebook'); ?>" /><br><br> | |
<label for="aw_social_twitter">Twitter Full URL:</label><br> | |
<input type="text" id="aw_social_twitter" name="aw_social_twitter" value="<?php echo get_option('aw_social_twitter'); ?>" /> | |
<label for="aw_social_instagram">Instagram Full URL:</label><br> | |
<input type="text" id="aw_social_instagram" name="aw_social_instagram" value="<?php echo get_option('aw_social_instagram'); ?>" /><br><br> | |
</div> | |
</div> | |
<!-- end social --> | |
<!-- footer text --> | |
<div class="postbox" > | |
<h3>Footer</h3> | |
<div class="inside"> | |
<label for="aw_footer1">Footer (html):</label><br> | |
<textarea name="aw_footer1"><?php echo get_option('aw_footer1'); ?></textarea><br><br> | |
</div> | |
</div> | |
<!-- end footer text --> | |
<div style="clear: both;"></div> | |
<?php submit_button(); ?> | |
</form> | |
</div> | |
</div> | |
<?php | |
} //end options page | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment