mirror of
https://github.com/10h30/trestle.git
synced 2026-07-11 18:56:07 +09:00
reworked Trestle settings to separate metabox, include new settings - layout & link icons, cleaned up php
This commit is contained in:
+22
-10
@@ -22,7 +22,7 @@ function trestle_theme_setup() {
|
||||
define( 'CHILD_THEME_VERSION', '1.0' );
|
||||
|
||||
// Load theme text domain
|
||||
load_theme_textdomain( 'trestle', get_template_directory() . '/languages');
|
||||
load_theme_textdomain( 'trestle', get_stylesheet_directory() . '/languages');
|
||||
|
||||
// Add HTML5 markup structure
|
||||
add_theme_support( 'html5' );
|
||||
@@ -58,13 +58,6 @@ function trestle_theme_setup() {
|
||||
add_action( 'wp_enqueue_scripts', 'trestle_header_actions');
|
||||
|
||||
|
||||
/*===========================================
|
||||
* Admin styles and scripts
|
||||
===========================================*/
|
||||
|
||||
add_action( 'init', 'trestle_admin_actions' );
|
||||
|
||||
|
||||
/*===========================================
|
||||
* Load Required/Suggested Plugins
|
||||
*
|
||||
@@ -82,13 +75,16 @@ function trestle_theme_setup() {
|
||||
// Implement auto-nav and mobile nav button
|
||||
add_action( 'init', 'trestle_nav_modifications' );
|
||||
|
||||
// Create / remove placeholder menu for Trestle auto nav
|
||||
add_action( 'init', 'trestle_nav_placeholder' );
|
||||
|
||||
|
||||
/*===========================================
|
||||
* Actions & Filters
|
||||
===========================================*/
|
||||
|
||||
// Add jquery class to body for styling nav if jQuery isn't enabled (jQuery will remove this class if enabled)
|
||||
add_filter('body_class','no_jquery');
|
||||
// Add body classes
|
||||
add_filter( 'body_class', 'trestle_body_classes' );
|
||||
|
||||
|
||||
/*===========================================
|
||||
@@ -98,4 +94,20 @@ function trestle_theme_setup() {
|
||||
// Add Trestle custom footer attribute to Mm
|
||||
add_filter( 'genesis_footer_output', 'trestle_custom_footer' );
|
||||
|
||||
/*===========================================
|
||||
* Admin Functionality
|
||||
===========================================*/
|
||||
|
||||
// Trestle admin scripts and styles
|
||||
add_action( 'admin_enqueue_scripts', 'trestle_admin_actions' );
|
||||
|
||||
// Trestle default settings
|
||||
add_filter( 'genesis_theme_settings_defaults', 'trestle_custom_defaults' );
|
||||
|
||||
// Sanitize settings
|
||||
add_action( 'genesis_settings_sanitizer_init', 'trestle_register_social_sanitization_filters' );
|
||||
|
||||
// Register Trestle settings metabox
|
||||
add_action( 'genesis_theme_settings_metaboxes', 'trestle_register_settings_box' );
|
||||
|
||||
}
|
||||
+51
-56
@@ -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();
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
});
|
||||
@@ -155,6 +155,15 @@ textarea:focus,
|
||||
-moz-appearance: none;
|
||||
}
|
||||
|
||||
|
||||
input[type=checkbox] {
|
||||
-webkit-appearance: checkbox;
|
||||
}
|
||||
|
||||
input[type=radio] {
|
||||
-webkit-appearance: radio;
|
||||
}
|
||||
|
||||
::-moz-selection {
|
||||
background-color: #333;
|
||||
color: #fff;
|
||||
@@ -175,25 +184,27 @@ a img {
|
||||
margin-bottom: -0.4rem;
|
||||
}
|
||||
|
||||
a.emailLink:before {
|
||||
/* Link Icons */
|
||||
|
||||
.link-icons a.emailLink:before {
|
||||
content: url(/wp-content/themes/trestle/images/email.png);
|
||||
margin: 0 4px 0 0;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
a.pdfLink:before {
|
||||
.link-icons a.pdfLink:before {
|
||||
content: url(/wp-content/themes/trestle/images/pdf.png);
|
||||
margin: 0 4px 0 0;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
a.docLink:before {
|
||||
.link-icons a.docLink:before {
|
||||
content: url(/wp-content/themes/trestle/images/doc.png);
|
||||
margin: 0 4px 0 0;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
a.externalLink:after {
|
||||
.link-icons a.externalLink:after {
|
||||
content: url(/wp-content/themes/trestle/images/external.png);
|
||||
margin: 0 0 0 4px;
|
||||
white-space: nowrap;
|
||||
@@ -1137,7 +1148,6 @@ Site Navigation
|
||||
position: absolute;
|
||||
z-index: 99;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
width: 50px;
|
||||
padding-left: 0;
|
||||
@@ -1580,10 +1590,6 @@ Media Queries
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
|
||||
body {
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.title-area {
|
||||
text-align: left;
|
||||
@@ -1644,28 +1650,29 @@ Media Queries
|
||||
width: 17.25%;
|
||||
}
|
||||
|
||||
/* Padding - remove padding in rules below for solid background */
|
||||
.entry,
|
||||
.sidebar .widget,
|
||||
.author-box,
|
||||
.comment-respond,
|
||||
.entry-comments,
|
||||
.entry-pings {
|
||||
/* Bubble Layout - padding and margins
|
||||
--------------------------------------------- */
|
||||
|
||||
body.bubble {
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.bubble .entry,
|
||||
.bubble .sidebar .widget,
|
||||
.bubble .author-box,
|
||||
.bubble .comment-respond,
|
||||
.bubble .entry-comments,
|
||||
.bubble .entry-pings {
|
||||
padding: 30px 40px;
|
||||
padding: 3rem 4rem;
|
||||
}
|
||||
|
||||
.footer-widgets-1 {
|
||||
margin-right: 40px;
|
||||
margin-right: 4rem;
|
||||
}
|
||||
|
||||
.archive-description {
|
||||
.bubble .archive-description {
|
||||
padding: 40px 40px 24px;
|
||||
padding: 4rem 4rem 2.4rem;
|
||||
}
|
||||
|
||||
.entry-footer .entry-meta {
|
||||
.bubble .entry-footer .entry-meta {
|
||||
border-top: 2px solid #f5f5f5;
|
||||
margin: 0 -40px;
|
||||
margin: 0 -4rem;
|
||||
@@ -1682,6 +1689,11 @@ Media Queries
|
||||
width: 30%;
|
||||
}
|
||||
|
||||
.footer-widgets-1,
|
||||
.footer-widgets-2 {
|
||||
margin-right: 5%;
|
||||
}
|
||||
|
||||
.five-sixths,
|
||||
.four-sixths,
|
||||
.one-fourth,
|
||||
|
||||
Reference in New Issue
Block a user