reworked Trestle settings to separate metabox, include new settings - layout & link icons, cleaned up php

This commit is contained in:
Mickey Kay
2013-11-19 09:52:34 -08:00
parent 38a1146d8f
commit 5fe327f54c
5 changed files with 150 additions and 156 deletions
+51 -56
View File
@@ -5,20 +5,40 @@
* Modified from: http://www.billerickson.net/genesis-theme-options/
===========================================*/
/*===========================================
* Admin styles and scripts
===========================================*/
// Add admin scripts and styles
function trestle_admin_actions() {
// Add admin jQuery
wp_enqueue_script( 'trestle-admin-jquery', get_stylesheet_directory_uri() . '/lib/admin/admin.js', array( 'jquery' ), '1.0', true );
// Add admin jQuery
wp_enqueue_style( 'trestle-admin', get_stylesheet_directory_uri() . '/lib/admin/admin.css' );
// Add admin CSS (doesn't exist at present)
add_editor_style( get_stylesheet_directory_uri() . '/lib/admin/editor.css' );
}
/**
* Register Defaults
*
* @param array $defaults
* @return array $defaults updated defaults
* Do Trestle default settings
*
* @param array $defaults default Genesis settings
* @return array modified Genesis defaults array
*/
function trestle_custom_defaults( $defaults ) {
// Trestle default key/value pairs
$trestle_defaults = array(
'trestle_auto_nav' => '0',
'trestle_include_home_link' => '0',
'trestle_layout' => 'solid',
'trestle_auto_nav' => 0,
'trestle_include_home_link' => 0,
'trestle_nav_button_text' => __( '[icon name="icon-list-ul"] Navigation', 'trestle' ),
'trestle_link_icons' => 0,
);
// Populate Trestle settings with default values if they don't yet exist
@@ -34,21 +54,15 @@ function trestle_custom_defaults( $defaults ) {
}
update_option( GENESIS_SETTINGS_FIELD, $options );
//
// Return modified default array
return $defaults;
}
add_filter( 'genesis_theme_settings_defaults', 'trestle_custom_defaults' );
// Also perform
/**
* Sanitization
* Add sanitization functionality to Trestle options
*/
function trestle_register_social_sanitization_filters() {
// No HTML
@@ -56,8 +70,8 @@ function trestle_register_social_sanitization_filters() {
'no_html',
GENESIS_SETTINGS_FIELD,
array(
'auto_nav',
'include_home_link',
'trestle_auto_nav',
'trestle_include_home_link',
)
);
@@ -66,39 +80,40 @@ function trestle_register_social_sanitization_filters() {
'safe_html',
GENESIS_SETTINGS_FIELD,
array(
'nav_button_text',
'trestle_nav_button_text',
)
);
}
add_action( 'genesis_settings_sanitizer_init', 'trestle_register_social_sanitization_filters' );
/**
* Register Metabox
*
* @param string $_genesis_theme_settings_pagehook
* Register Trestle metabox
*/
function trestle_register_settings_box( $_genesis_theme_settings_pagehook ) {
global $_genesis_admin_settings;
// Remove default Genesis nav metabox
remove_meta_box('genesis-theme-settings-nav', $_genesis_admin_settings->pagehook, 'main');
// Call our own custom nav metabox which combines our own settings with Genesis'
add_meta_box('mm-navigation-settings', __( 'Navigation', 'trestle' ), 'trestle_navigation_settings_box', $_genesis_theme_settings_pagehook, 'main', 'high');
// Create Trestle settings metabox
add_meta_box( 'trestle-settings', __( 'Trestle Settings', 'trestle' ), 'trestle_settings_box', $_genesis_theme_settings_pagehook, 'main', 'high' );
}
add_action('genesis_theme_settings_metaboxes', 'trestle_register_settings_box');
/**
* Create Navigation Metabox
* Output Trestle metabox
*/
function trestle_navigation_settings_box() {
function trestle_settings_box() {
$img_path = get_stylesheet_directory_uri() . '/images/admin/';
?>
<h4><?php _e( 'Layout', 'trestle' ) ?></h4>
<p class="trestle-layout">
<img src="<?php echo $img_path; ?>icon-solid.gif" width="200" height="150" <?php echo 'solid' == genesis_get_option('trestle_layout') ? 'class="checked"' : '' ?> />
<input type="radio" name="<?php echo GENESIS_SETTINGS_FIELD; ?>[trestle_layout]" value="solid" <?php checked( esc_attr( genesis_get_option('trestle_layout') ), 'solid' ); ?> />
<img src="<?php echo $img_path; ?>icon-bubble.gif" width="200" height="150" <?php echo 'bubble' == genesis_get_option('trestle_layout') ? 'class="checked"' : '' ?> />
<input type="radio" name="<?php echo GENESIS_SETTINGS_FIELD; ?>[trestle_layout]" value="bubble" <?php checked( esc_attr( genesis_get_option('trestle_layout') ), 'bubble' ); ?> />
</p>
<h4><?php _e( 'Primary Navigation Options', 'trestle' ) ?></h4>
<p>
<input type="checkbox" id="<?php echo GENESIS_SETTINGS_FIELD; ?>[trestle_auto_nav]" name="<?php echo GENESIS_SETTINGS_FIELD; ?>[trestle_auto_nav]" value="1" <?php checked( esc_attr( genesis_get_option('trestle_auto_nav') ), 1); ?> /> <label for="<?php echo GENESIS_SETTINGS_FIELD; ?>[trestle_auto_nav]"><?php _e( 'Automatically generate nav menu (replaces custom/manual menu with auto-generated menu)', 'trestle' ); ?></label><br />
@@ -108,30 +123,10 @@ function trestle_navigation_settings_box() {
<?php _e('Text for mobile navigation button (shortcodes can be included):', 'trestle' ); ?></label><br />
<input class="widefat" type="text" id="<?php echo GENESIS_SETTINGS_FIELD; ?>[trestle_nav_button_text]" name="<?php echo GENESIS_SETTINGS_FIELD; ?>[trestle_nav_button_text]" value="<?php echo esc_attr( genesis_get_option('trestle_nav_button_text') ); ?>" /> <label for="<?php echo GENESIS_SETTINGS_FIELD; ?>[trestle_nav_button_text]">
</p>
<h4><?php _e( 'Additional Settings', 'trestle' ) ?></h4>
<p>
<input type="checkbox" id="<?php echo GENESIS_SETTINGS_FIELD; ?>[trestle_link_icons]" name="<?php echo GENESIS_SETTINGS_FIELD; ?>[trestle_link_icons]" value="1" <?php checked( esc_attr( genesis_get_option('trestle_link_icons') ), 1); ?> /> <label for="<?php echo GENESIS_SETTINGS_FIELD; ?>[trestle_link_icons]"><?php _e( 'Automatically add icons to external, email, pdf, and document links.', 'trestle' ); ?></label><br />
</p>
<?php
$trestle_nav_title = __( 'Trestle Auto Nav Placeholder', 'trestle' );
// Create placeholder menu for 'primary' spot if auto-nav is selected - this ensures that nav extras can be used even when no custom menu is formally set to primary
if ( 1 == genesis_get_option( 'auto_nav' ) && !wp_get_nav_menu_object( $trestle_nav_title ) && !has_nav_menu( 'primary' ) ) {
// Create placholder menu
wp_create_nav_menu( $trestle_nav_title );
// Assign placeholder menu to 'primary'
$menu_locations = get_theme_mod('nav_menu_locations');
$menu_locations['primary'] = wp_get_nav_menu_object( $trestle_nav_title )->term_id;
set_theme_mod( 'nav_menu_locations', $menu_locations );
}
// Remove placeholder menu if auto-nav is disabled
$menus = get_registered_nav_menus();
if ( 1 != genesis_get_option( 'auto_nav' ) && wp_get_nav_menu_object( $trestle_nav_title ) && $trestle_nav_title != $menus['primary'] )
wp_delete_nav_menu( $trestle_nav_title );
// Output default Genesis nav options
$genesis_settings_object = new Genesis_Admin_Settings;
$genesis_settings_object->nav_box();
}
+42 -13
View File
@@ -15,21 +15,11 @@ function trestle_header_actions() {
wp_enqueue_style( 'google-fonts', '//fonts.googleapis.com/css?family=Lato:300,700,900' );
// Custom jQuery
wp_enqueue_script( 'trestle_jquery', get_stylesheet_directory_uri() . '/lib/js/trestle-jquery.js', array( 'jquery' ), '1.0', true );
wp_enqueue_script( 'trestle-jquery', get_stylesheet_directory_uri() . '/lib/js/jquery.js', array( 'jquery' ), '1.0', true );
}
/*===========================================
* Admin styles and scripts
===========================================*/
// Add admin stylesheet (doesn't yet exist)
function trestle_admin_actions() {
add_editor_style( get_stylesheet_directory_uri() . '/lib/admin/admin.css' );
}
/*===========================================
* Load Required/Suggested Plugins
*
@@ -271,15 +261,54 @@ function trestle_add_mobile_nav() {
}
// Generate / remove Trestle Auto Nav placeholder menu as needed (necessary to enable Nav Extras)
function trestle_nav_placeholder() {
$trestle_nav_title = __( 'Trestle Auto Nav Placeholder', 'trestle' );
// Create placeholder menu for 'primary' spot if auto-nav is selected - this ensures that nav extras can be used even when no custom menu is formally set to primary
if ( 1 == genesis_get_option( 'trestle_auto_nav' ) && !wp_get_nav_menu_object( $trestle_nav_title ) && !has_nav_menu( 'primary' ) ) {
// Create placholder menu
wp_create_nav_menu( $trestle_nav_title );
// Assign placeholder menu to 'primary'
$menu_locations = get_theme_mod('nav_menu_locations');
$menu_locations['primary'] = wp_get_nav_menu_object( $trestle_nav_title )->term_id;
set_theme_mod( 'nav_menu_locations', $menu_locations );
}
// Remove placeholder menu if auto-nav is disabled
$menus = get_registered_nav_menus();
if ( 1 != genesis_get_option( 'trestle_auto_nav' ) && wp_get_nav_menu_object( $trestle_nav_title ) && $trestle_nav_title != $menus['primary'] )
wp_delete_nav_menu( $trestle_nav_title );
}
/*===========================================
* Actions & Filters
===========================================*/
// Add jquery class to body for styling nav if jQuery isn't enabled (jQuery will remove this class if enabled)
function no_jquery( $classes ) {
// Add body classes
function trestle_body_classes( $classes ) {
// Add 'no-jquery' class to be removed by jQuery if enabled
$classes[] = 'no-jquery';
// Add 'bubble' class
if ( 'bubble' == genesis_get_option( 'trestle_layout' ) )
$classes[] = 'bubble';
// Add 'link-icons' class
if ( genesis_get_option('trestle_link_icons') )
$classes[] = 'link-icons';
return $classes;
}
-54
View File
@@ -1,54 +0,0 @@
// Executes when the document is ready
jQuery(document).ready(function() {
// Remove .no-jquery body class
jQuery('body').removeClass('no-jquery');
// Get our URL
var h = window.location.host.toLowerCase();
// External Links
jQuery('[href^="http://"],[href^="https://"]').not('[href*="' + h + '"], .button, .menu-primary a').addClass('externalLink').attr("target", "_blank");
// Add classes to different types of media links
jQuery('a[href^="mailto:"]:not(.button)').addClass('emailLink');
jQuery('a[href*=".pdf"]:not(.button)').attr({"target":"_blank"}).addClass('pdfLink');
jQuery('a[href*=".doc"]:not(.button)').attr({"target":"_blank"}).addClass('docLink');
jQuery('img').parent('a:not(.button)').addClass('imageLink').removeClass('externalLink');
// Add classes to parts of lists
jQuery('li:last-child').addClass('last');
jQuery('li:first-child').addClass('first');
jQuery('ul, ol').parent('li').addClass('parent');
// Mobile navigation button
jQuery('#menu-button').click(function() {
var button = jQuery(this);
button.toggleClass('open');
jQuery('.menu-primary').slideToggle();
});
// Mobile navigation icons
var closedIcon = '+';
var openIcon = '-';
jQuery('.genesis-nav-menu .parent:not(.current-menu-item, .current_page_item, .current_page_parent, .current_page_ancestor) > a').after('<a class="sub-icon" href="javascript:void()">' + closedIcon + '</a>');
jQuery('.genesis-nav-menu .parent.current-menu-item > a, .genesis-nav-menu .parent.current_page_item > a, .genesis-nav-menu .parent.current_page_parent > a, .genesis-nav-menu .parent.current_page_ancestor > a').after('<a class="sub-icon" href="javscript: void()">' + openIcon + '</a>');
// Mobile navigation expand/contract functionality
jQuery('.sub-icon').click(function() {
var icon = jQuery(this);
icon.next('ul').slideToggle();
if ( icon.text().indexOf( closedIcon ) !== -1 )
icon.text(openIcon);
else if ( icon.text().indexOf( openIcon ) !== -1 )
icon.text(closedIcon);
});
}); /* end of as page load scripts */
// Executes when complete page is fully loaded, including all frames, objects, and images
jQuery(window).load(function() {
});