Created
August 14, 2013 21:35
-
-
Save brycejacobson/6235913 to your computer and use it in GitHub Desktop.
Genesis Child Theme Settings Page
This file contains 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 | |
/** | |
* Creates the Child Theme Settings page. | |
* genesis/lib/admin/seo-settings.php | |
*/ | |
/** | |
* Registers a new admin page, providing content and corresponding menu item | |
* for the Child Theme Settings page. | |
*/ | |
// Specify a class | |
class ESG_Child_Theme_Settings extends Genesis_Admin_Boxes { | |
/** | |
* Create an admin menu item and settings page. | |
*/ | |
function __construct() { | |
// Specify a page_id | |
$page_id = 'esg-settings'; | |
// Specify a page_title and menu_title | |
$menu_ops = array( | |
'submenu' => array( | |
'parent_slug' => 'genesis', | |
'page_title' => __( 'Child Theme Settings', 'genesis' ), | |
'menu_title' => __( 'Child Theme Settings', 'genesis' ) | |
) | |
); | |
$page_ops = array( | |
'screen_icon' => 'options-general', | |
'save_button_text' => __( 'Save Settings', 'genesis' ), | |
'reset_button_text' => __( 'Reset Settings', 'genesis' ), | |
'saved_notice_text' => __( 'Settings saved.', 'genesis' ), | |
'reset_notice_text' => __( 'Settings reset.', 'genesis' ), | |
'error_notice_text' => __( 'Error saving settings.', 'genesis' ), | |
); | |
// Specify a settings field | |
// used by genesis_get_option( 'option_name', 'settings_field') | |
$settings_field = 'esg-child-theme-settings'; | |
// Set default values for options | |
$default_settings = array( | |
'esg-twitter' => 'http://www.twitter.com/', | |
'esg-facebook' => 'http://www.facebook.com/', | |
'esg-google-plus' => 'http://www.google.com/', | |
'esg-linkedin' => 'http://www.linkedin.com/', | |
); | |
$this->create( $page_id, $menu_ops, $page_ops, $settings_field, $default_settings ); | |
add_action( 'genesis_settings_sanitizer_init', array( $this, 'sanitizer_filters' ) ); | |
} | |
/** | |
* Registers each of the settings with a sanitization filter type. | |
*/ | |
public function sanitizer_filters() { | |
genesis_add_option_filter( | |
'no_html', | |
$this->settings_field, | |
array( | |
'esg-twitter', | |
'esg-facebook', | |
'esg-google-plus', | |
'esg-linkedin', | |
'esg-phone', | |
'esg-email', | |
'esg-address' | |
) | |
); | |
genesis_add_option_filter( | |
'safe_html', | |
$this->settings_field, | |
array( | |
'credits-text', | |
) | |
); | |
} | |
/** | |
* Register meta boxes on the Child Theme Settings page. | |
*/ | |
function metaboxes() { | |
// Add meta box and content display function below | |
add_meta_box( 'esg-custom-links', __( 'Custom Links', 'genesis' ), array( $this, 'esg_custom_links_box' ), $this->pagehook, 'main' ); | |
} | |
/** | |
* Callback for meta box. | |
*/ | |
function esg_custom_links_box() { | |
?> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'esg-twitter' ); ?>"><?php _e( 'Twitter URL:', 'genesis' ); ?></label> | |
<input type="text" name="<?php echo $this->get_field_name( 'esg-twitter' ); ?>" id="<?php echo $this->get_field_id( 'esg-twitter' ); ?>" value="<?php echo esc_attr( $this->get_field_value( 'esg-twitter' ) ); ?>" size="50" /> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'esg-facebook' ); ?>"><?php _e( 'Facebook URL:', 'genesis' ); ?></label> | |
<input type="text" name="<?php echo $this->get_field_name( 'esg-facebook' ); ?>" id="<?php echo $this->get_field_id( 'esg-facebook' ); ?>" value="<?php echo esc_attr( $this->get_field_value( 'esg-facebook' ) ); ?>" size="50" /> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'esg-google-plus' ); ?>"><?php _e( 'Google+ URL:', 'genesis' ); ?></label> | |
<input type="text" name="<?php echo $this->get_field_name( 'esg-google-plus' ); ?>" id="<?php echo $this->get_field_id( 'esg-google-plus' ); ?>" value="<?php echo esc_attr( $this->get_field_value( 'esg-google-plus' ) ); ?>" size="50" /> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'esg-linkedin' ); ?>"><?php _e( 'Linked In URL:', 'genesis' ); ?></label> | |
<input type="text" name="<?php echo $this->get_field_name( 'esg-linkedin' ); ?>" id="<?php echo $this->get_field_id( 'esg-linkedin' ); ?>" value="<?php echo esc_attr( $this->get_field_value( 'esg-linkedin' ) ); ?>" size="50" /> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'esg-phone' ); ?>"><?php _e( 'Phone #:', 'genesis' ); ?></label> | |
<input type="text" name="<?php echo $this->get_field_name( 'esg-phone' ); ?>" id="<?php echo $this->get_field_id( 'esg-phone' ); ?>" value="<?php echo esc_attr( $this->get_field_value( 'esg-phone' ) ); ?>" size="50" /> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'esg-email' ); ?>"><?php _e( 'Email Address:', 'genesis' ); ?></label> | |
<input type="text" name="<?php echo $this->get_field_name( 'esg-email' ); ?>" id="<?php echo $this->get_field_id( 'esg-email' ); ?>" value="<?php echo esc_attr( $this->get_field_value( 'esg-email' ) ); ?>" size="50" /> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_id( 'esg-address' ); ?>"><?php _e( 'Address:', 'genesis' ); ?></label> | |
<input type="text" name="<?php echo $this->get_field_name( 'esg-address' ); ?>" id="<?php echo $this->get_field_id( 'esg-address' ); ?>" value="<?php echo esc_attr( $this->get_field_value( 'esg-address' ) ); ?>" size="50" /> | |
</p> | |
<p> | |
<span class="description"><?php printf( 'Add custom links above to display on the front end in the header.', 'genesis' ); ?></span> | |
</p> | |
<?php | |
} | |
} | |
/** | |
* Adds submenu items under Genesis item in admin menu. | |
* genesis/lib/admin/menu.php | |
*/ | |
add_action( 'genesis_admin_menu', 'esg_add_admin_submenus' ); | |
function esg_add_admin_submenus() { | |
/** Do nothing, if not viewing the admin */ | |
if ( ! is_admin() ) | |
return; | |
/** Don't add submenu items if Genesis menu is disabled */ | |
if( ! current_theme_supports( 'genesis-admin-menu' ) ) | |
return; | |
/** Add submenu item using new class */ | |
global $_ESG_Child_Theme_Settings; | |
$_ESG_Child_Theme_Settings = new ESG_Child_Theme_Settings; | |
} |
This file contains 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 | |
/** Child Theme Settings */ | |
include_once( CHILD_DIR . '/lib/child-theme-settings.php'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment