diff --git a/functions.php b/functions.php index af3743a..2329937 100644 --- a/functions.php +++ b/functions.php @@ -47,9 +47,9 @@ function trestle_theme_setup() { ===========================================*/ // Child theme definitions (do not remove). - define( 'CHILD_THEME_NAME', 'Trestle' ); - define( 'CHILD_THEME_URL', 'http://demo.mightyminnow.com/theme/trestle/' ); - define( 'CHILD_THEME_VERSION', '1.2.0' ); + define( 'TRESTLE_THEME_NAME', 'Trestle' ); + define( 'TRESTLE_THEME_URL', 'http://demo.mightyminnow.com/theme/trestle/' ); + define( 'TRESTLE_THEME_VERSION', '1.2.0' ); define( 'TRESTLE_SETTINGS_FIELD', 'trestle-settings' ); // Setup default theme settings. @@ -58,13 +58,4 @@ function trestle_theme_setup() { // Load theme text domain. load_theme_textdomain( 'trestle', get_stylesheet_directory() . '/languages' ); - // Add HTML5 markup structure. - add_theme_support( 'html5' ); - - // Add viewport meta tag for mobile browsers. - add_theme_support( 'genesis-responsive-viewport' ); - - // Add support for footer widgets if specified in Trestle settings. - $trestle_footer_widgets_number = esc_attr( genesis_get_option( 'footer_widgets_number', 'trestle-settings' ) ); - add_theme_support( 'genesis-footer-widgets', $trestle_footer_widgets_number ); } diff --git a/includes/admin/admin.php b/includes/admin/admin.php index 02a3c0a..440858c 100644 --- a/includes/admin/admin.php +++ b/includes/admin/admin.php @@ -7,23 +7,10 @@ * @package Trestle */ -add_action( 'admin_enqueue_scripts', 'trestle_admin_actions' ); /** - * Loads admin scripts and styles. + * Set up Trestle default settings. * - * @since 1.0.0 - */ -function trestle_admin_actions() { - - // Include the main stylesheet in the editor - add_editor_style( get_stylesheet_uri() ); -} - -//add_filter( 'after_setup_theme', 'trestle_settings_defaults' ); -/** - * Sets up Trestle default settings. - * - * @since 1.0.0 + * @since 2.0.0 * * @return array Genesis settings updated to include Trestle defaults. */ @@ -70,6 +57,37 @@ function trestle_settings_defaults() { // Update options with defaults. update_option( TRESTLE_SETTINGS_FIELD, $options ); + +} + +/** + * Wrapper function to get Trestle options. + * + * @since 2.0.0 + * @uses genesis_get_option() + * + * @return mixed Trestle option value. + */ +function trestle_get_option( $key, $setting = null, $use_cache = true ) { + + // Set default to TRESTLE_SETTINGS_FIELD. + $setting = $setting ? $setting : TRESTLE_SETTINGS_FIELD; + + return genesis_get_option( $key, $setting, false ); + +} + +add_action( 'admin_enqueue_scripts', 'trestle_admin_actions' ); +/** + * Loads admin scripts and styles. + * + * @since 1.0.0 + */ +function trestle_admin_actions() { + + // Include the main stylesheet in the editor + add_editor_style( get_stylesheet_uri() ); + } add_action( 'tgmpa_register', 'trestle_register_required_plugins' ); diff --git a/includes/admin/customizer.js b/includes/admin/customizer.js deleted file mode 100644 index 22d28e0..0000000 --- a/includes/admin/customizer.js +++ /dev/null @@ -1,147 +0,0 @@ -/** - * JavaScript for the Customizer Preview - * - * @since 1.0.0 - */ - -( function( $ ) { - - // Layout. - wp.customize( 'trestle-settings[layout]', function( value ) { - value.bind( function( value ) { - - var $body = $( 'body' ); - - switch ( value ) { - case 'solid': - $body.removeClass( 'bubble' ); - break; - case 'bubble': - $body.addClass( 'bubble' ); - break; - } - - }); - }); - - // Custom logo. - wp.customize( 'trestle-settings[logo_url]', function( value ) { - value.bind( function( url ) { - - var $body = $( 'body' ); - - if ( 0 === $.trim( url ).length ) { - $body.removeClass( 'has-logo' ); - $( '.site-title a.image-link' ).remove(); - } else { - $body.addClass( 'has-logo' ); - $( '.site-title a.image-link' ).remove(); - $( '.site-title' ).append( '' ); - } - - }); - }); - - // Favicon. - wp.customize( 'trestle-settings[favicon_url]', function( value ) { - value.bind( function( url ) { - - var $faviconElem = $( 'link[rel="Shortcut Icon"]' ); - $faviconElem.attr( 'href', url ); - - }); - }); - - // Primary Nav Location. - wp.customize( 'trestle-settings[nav_primary_location]', function( value ) { - value.bind( function( value ) { - - var $body = $( 'body' ); - var $nav = $( '.nav-primary' ); - - switch ( value ) { - case 'full': - $body.removeClass( 'nav-primary-location-header' ) - .addClass( 'nav-primary-location-full' ); - $nav.remove().insertAfter( '.site-header' ); - break; - case 'header': - $body.removeClass( 'nav-primary-location-full' ) - .addClass( 'nav-primary-location-header' ); - $nav.remove().appendTo( '.site-header .wrap' ); - break; - } - - }); - }); - - // Custom Read More Link Text. - wp.customize( 'trestle-settings[read_more_text]', function( value ) { - value.bind( function( value ) { - - $( 'a.more-link' ).html( value ); - - }); - }); - - // External Links. - wp.customize( 'trestle-settings[external_link_icons]', function( value ) { - value.bind( function( value ) { - - var $body = $( 'body' ); - - if ( value ) { - $body.addClass( 'external-link-icons' ); - } else { - $body.removeClass( 'external-link-icons' ); - } - - }); - }); - - // Email Links. - wp.customize( 'trestle-settings[email_link_icons]', function( value ) { - value.bind( function( value ) { - - var $body = $( 'body' ); - - if ( value ) { - $body.addClass( 'email-link-icons' ); - } else { - $body.removeClass( 'email-link-icons' ); - } - - }); - }); - - // PDF Links. - wp.customize( 'trestle-settings[pdf_link_icons]', function( value ) { - value.bind( function( value ) { - - var $body = $( 'body' ); - - if ( value ) { - $body.addClass( 'pdf-link-icons' ); - } else { - $body.removeClass( 'pdf-link-icons' ); - } - - }); - }); - - // Doc Links. - wp.customize( 'trestle-settings[doc_link_icons]', function( value ) { - value.bind( function( value ) { - - var $body = $( 'body' ); - - if ( value ) { - $body.addClass( 'doc-link-icons' ); - } else { - $body.removeClass( 'doc-link-icons' ); - } - - }); - }); - -})( jQuery ); diff --git a/includes/admin/customizer.php b/includes/admin/customizer.php index b4045a4..72d6cb3 100644 --- a/includes/admin/customizer.php +++ b/includes/admin/customizer.php @@ -2,33 +2,16 @@ /** * Trestle Customizer Controls. * - * @since 1.0.0 + * @since 2.0.0 * * @package Trestle */ -add_action( 'customize_preview_init', 'trestle_customizer_preview_js' ); -/** - * Enqueue scripts for the site preview iframe on the customizer screen. - * - * @since 1.0.0 - */ -function trestle_customizer_preview_js() { - - wp_enqueue_script( - 'trestle_customizer', - get_stylesheet_directory_uri() . '/includes/admin/customizer.js', - array( 'jquery', 'customize-preview' ), // Dependencies - null, // Version - true // Load in Footer - ); -} - add_action( 'customize_register', 'trestle_customizer_controls' ); /** * Register Trestle's controls. * - * @since 1.0.0 + * @since 2.0.0 * * @param $wp_customize The Customizer Object. */ @@ -51,9 +34,8 @@ function trestle_customizer_controls( $wp_customize ) { $wp_customize->add_setting( 'trestle-settings[layout]', array( - 'default' => genesis_get_option( 'layout', 'trestle-settings' ), + 'default' => trestle_get_option( 'layout' ), 'type' => 'option', - 'transport' => 'postMessage', 'capability' => 'edit_theme_options', ) ); @@ -75,9 +57,8 @@ function trestle_customizer_controls( $wp_customize ) { $wp_customize->add_setting( 'trestle-settings[logo_url]', array( - 'default' => genesis_get_option( 'logo_url', 'trestle-settings' ), + 'default' => trestle_get_option( 'logo_url' ), 'type' => 'option', - 'transport' => 'postMessage', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'esc_url_raw', ) @@ -98,9 +79,8 @@ function trestle_customizer_controls( $wp_customize ) { $wp_customize->add_setting( 'trestle-settings[logo_url_mobile]', array( - 'default' => genesis_get_option( 'logo_url_mobile', 'trestle-settings' ), + 'default' => trestle_get_option( 'logo_url_mobile' ), 'type' => 'option', - 'transport' => 'postMessage', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'esc_url_raw', ) @@ -121,9 +101,8 @@ function trestle_customizer_controls( $wp_customize ) { $wp_customize->add_setting( 'trestle-settings[favicon_url]', array( - 'default' => genesis_get_option( 'favicon_url', 'trestle-settings' ), + 'default' => trestle_get_option( 'favicon_url' ), 'type' => 'option', - 'transport' => 'postMessage', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'esc_url_raw', ) @@ -144,9 +123,8 @@ function trestle_customizer_controls( $wp_customize ) { $wp_customize->add_setting( 'trestle-settings[nav_primary_location]', array( - 'default' => genesis_get_option( 'nav_primary_location', 'trestle-settings' ), + 'default' => trestle_get_option( 'nav_primary_location' ), 'type' => 'option', - 'transport' => 'postMessage', 'capability' => 'edit_theme_options', ) ); @@ -168,9 +146,8 @@ function trestle_customizer_controls( $wp_customize ) { $wp_customize->add_setting( 'trestle-settings[search_in_nav]', array( - 'default' => genesis_get_option( 'search_in_nav', 'trestle-settings' ), + 'default' => trestle_get_option( 'search_in_nav' ), 'type' => 'option', - 'transport' => 'postMessage', 'capability' => 'edit_theme_options', ) ); @@ -188,9 +165,8 @@ function trestle_customizer_controls( $wp_customize ) { $wp_customize->add_setting( 'trestle-settings[read_more_text]', array( - 'default' => genesis_get_option( 'read_more_text', 'trestle-settings' ), + 'default' => trestle_get_option( 'read_more_text' ), 'type' => 'option', - 'transport' => 'postMessage', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'wp_kses_post', ) @@ -208,9 +184,8 @@ function trestle_customizer_controls( $wp_customize ) { $wp_customize->add_setting( 'trestle-settings[revisions_number]', array( - 'default' => genesis_get_option( 'revisions_number', 'trestle-settings' ), + 'default' => trestle_get_option( 'revisions_number' ), 'type' => 'option', - 'transport' => 'postMessage', 'capability' => 'edit_theme_options', ) ); @@ -242,9 +217,8 @@ function trestle_customizer_controls( $wp_customize ) { $wp_customize->add_setting( 'trestle-settings[footer_widgets_number]', array( - 'default' => genesis_get_option( 'footer_widgets_number', 'trestle-settings' ), + 'default' => trestle_get_option( 'footer_widgets_number' ), 'type' => 'option', - 'transport' => 'postMessage', 'capability' => 'edit_theme_options', ) ); @@ -289,9 +263,8 @@ function trestle_customizer_controls( $wp_customize ) { $wp_customize->add_setting( 'trestle-settings[external_link_icons]', array( - 'default' => genesis_get_option( 'external_link_icons', 'trestle-settings' ), + 'default' => trestle_get_option( 'external_link_icons' ), 'type' => 'option', - 'transport' => 'postMessage', 'capability' => 'edit_theme_options', ) ); @@ -309,9 +282,8 @@ function trestle_customizer_controls( $wp_customize ) { $wp_customize->add_setting( 'trestle-settings[email_link_icons]', array( - 'default' => genesis_get_option( 'email_link_icons', 'trestle-settings' ), + 'default' => trestle_get_option( 'email_link_icons' ), 'type' => 'option', - 'transport' => 'postMessage', 'capability' => 'edit_theme_options', ) ); @@ -329,9 +301,8 @@ function trestle_customizer_controls( $wp_customize ) { $wp_customize->add_setting( 'trestle-settings[pdf_link_icons]', array( - 'default' => genesis_get_option( 'pdf_link_icons', 'trestle-settings' ), + 'default' => trestle_get_option( 'pdf_link_icons' ), 'type' => 'option', - 'transport' => 'postMessage', 'capability' => 'edit_theme_options', ) ); @@ -349,9 +320,8 @@ function trestle_customizer_controls( $wp_customize ) { $wp_customize->add_setting( 'trestle-settings[doc_link_icons]', array( - 'default' => genesis_get_option( 'doc_link_icons', 'trestle-settings' ), + 'default' => trestle_get_option( 'doc_link_icons' ), 'type' => 'option', - 'transport' => 'postMessage', 'capability' => 'edit_theme_options', ) ); diff --git a/includes/functions/theme-functions.php b/includes/functions/theme-functions.php index 1e20c98..2e864a3 100644 --- a/includes/functions/theme-functions.php +++ b/includes/functions/theme-functions.php @@ -9,6 +9,28 @@ * @package Trestle */ +/*=========================================== + * Theme Setup +===========================================*/ +add_action( 'after_setup_theme', 'trestle_add_theme_support' ); +/** + * Initialize Trestle defaults and theme options. + * + * @since 2.0.0 + */ +function trestle_add_theme_support() { + + // Add HTML5 markup structure. + add_theme_support( 'html5' ); + + // Add viewport meta tag for mobile browsers. + add_theme_support( 'genesis-responsive-viewport' ); + + // Add support for footer widgets if specified in Trestle settings. + add_theme_support( 'genesis-footer-widgets', trestle_get_option( 'footer_widgets_number' ) ); + +} + /*=========================================== * 3rd Party Libraries ===========================================*/ @@ -53,7 +75,7 @@ function trestle_header_actions() { wp_enqueue_style( 'theme-google-fonts', '//fonts.googleapis.com/css?family=Lato:300,400,700' ); // Theme jQuery. - wp_enqueue_script( 'theme-jquery', get_stylesheet_directory_uri() . '/includes/js/theme-jquery.js', array( 'jquery' ), CHILD_THEME_VERSION, true ); + wp_enqueue_script( 'theme-jquery', get_stylesheet_directory_uri() . '/includes/js/theme-jquery.js', array( 'jquery' ), TRESTLE_THEME_VERSION, true ); // Get WP uploads directory. $upload_dir = wp_upload_dir(); @@ -68,7 +90,7 @@ function trestle_header_actions() { // Custom jQuery (if it exists). $custom_js_file = '/trestle/custom.js'; if ( is_readable( $upload_path . $custom_js_file ) ) - wp_enqueue_script( 'trestle-custom-jquery', $upload_url . $custom_js_file, array( 'jquery' ), CHILD_THEME_VERSION, true ); + wp_enqueue_script( 'trestle-custom-jquery', $upload_url . $custom_js_file, array( 'jquery' ), TRESTLE_THEME_VERSION, true ); } @@ -83,7 +105,9 @@ add_filter( 'genesis_pre_load_favicon', 'trestle_do_custom_favicon' ); * @return string Custom favicon URL (if specified), or the default URL. */ function trestle_do_custom_favicon( $favicon_url ) { - return genesis_get_option( 'favicon_url', 'trestle-settings' ) ? genesis_get_option( 'favicon_url', 'trestle-settings' ) : $favicon_url; + + $trestle_favicon_url = trestle_get_option( 'favicon_url' ); + return $trestle_favicon_url ? $trestle_favicon_url : $favicon_url; } /*=========================================== @@ -105,30 +129,45 @@ function trestle_body_classes( $classes ) { $classes[] = 'no-jquery'; // Add 'bubble' class. - if ( 'bubble' == genesis_get_option( 'layout', 'trestle-settings' ) ) + if ( 'bubble' == trestle_get_option( 'layout' ) ) $classes[] = 'bubble'; - // Add link icon classes. - if ( genesis_get_option( 'external_link_icons', 'trestle-settings' ) ) + /** + * Add link icon classes. + */ + + if ( trestle_get_option( 'external_link_icons' ) ) { $classes[] = 'external-link-icons'; - if ( genesis_get_option( 'email_link_icons', 'trestle-settings' ) ) + } + + if ( trestle_get_option( 'email_link_icons' ) ) { $classes[] = 'email-link-icons'; - if ( genesis_get_option( 'pdf_link_icons', 'trestle-settings' ) ) + } + + if ( trestle_get_option( 'pdf_link_icons' ) ) { $classes[] = 'pdf-link-icons'; - if ( genesis_get_option( 'doc_link_icons', 'trestle-settings' ) ) + } + + if ( trestle_get_option( 'doc_link_icons' ) ) { $classes[] = 'doc-link-icons'; + } // Add menu style class. - if ( genesis_get_option( 'nav_primary_location', 'trestle-settings' ) ) - $classes[] = 'nav-primary-location-' . esc_attr( genesis_get_option( 'nav_primary_location', 'trestle-settings' ) ); + $nav_primary_location = esc_attr( trestle_get_option( 'nav_primary_location' ) ); + if ( $nav_primary_location ) { + $classes[] = 'nav-primary-location-' . $nav_primary_location; + } // Add footer widget number class. - if ( genesis_get_option( 'footer_widgets_number', 'trestle-settings' ) ) - $classes[] = 'footer-widgets-number-' . esc_attr( genesis_get_option( 'footer_widgets_number', 'trestle-settings' ) ); + $footer_widgets_number = esc_attr( trestle_get_option( 'footer_widgets_number' ) ); + if ( $footer_widgets_number ) { + $classes[] = 'footer-widgets-number-' . $footer_widgets_number; + } // Add logo class. - if ( genesis_get_option( 'logo_url', 'trestle-settings' ) || genesis_get_option( 'logo_url_mobile', 'trestle-settings' ) ) + if ( trestle_get_option( 'logo_url' ) || trestle_get_option( 'logo_url_mobile' ) ) { $classes[] = 'has-logo'; + } return $classes; @@ -147,8 +186,8 @@ add_filter( 'genesis_seo_title', 'trestle_do_logos', 10, 3 ); */ function trestle_do_logos( $title, $inside, $wrap ) { - $logo_url = genesis_get_option( 'logo_url', 'trestle-settings' ); - $logo_url_mobile = genesis_get_option( 'logo_url_mobile', 'trestle-settings' ); + $logo_url = trestle_get_option( 'logo_url' ); + $logo_url_mobile = trestle_get_option( 'logo_url_mobile' ); $logo_html = ''; // Regular logo. @@ -199,6 +238,7 @@ function trestle_do_logos( $title, $inside, $wrap ) { // Echo (filtered). return $title; + } @@ -206,15 +246,18 @@ function trestle_do_logos( $title, $inside, $wrap ) { * Navigation ===========================================*/ -add_action( 'init', 'trestle_nav_primary_location' ); +add_action( 'wp_loaded', 'trestle_nav_primary_location' ); /** * Move primary navigation into the header if need be. * + * This is hooked on wp_loaded instead of init because for some reason init + * won't fire on the customizer preview. + * * @since 1.2.0 */ function trestle_nav_primary_location() { - if ( 'header' == genesis_get_option( 'nav_primary_location', 'trestle-settings' ) ) { + if ( 'header' == trestle_get_option( 'nav_primary_location' ) ) { remove_action( 'genesis_after_header', 'genesis_do_nav' ); add_action( 'genesis_header', 'genesis_do_nav', 12 ); } @@ -233,7 +276,7 @@ add_filter( 'wp_nav_menu_items', 'trestle_custom_nav_extras', 10, 2 ); */ function trestle_custom_nav_extras( $nav_items, stdClass $menu_args ) { - if ( 'primary' == $menu_args->theme_location && genesis_get_option( 'search_in_nav', 'trestle-settings' ) ) { + if ( 'primary' == $menu_args->theme_location && trestle_get_option( 'search_in_nav' ) ) { return $nav_items . '
  • ' . get_search_form( false ) . '
  • '; } @@ -256,10 +299,11 @@ add_filter( 'wp_revisions_to_keep', 'trestle_update_revisions_number', 10, 2 ); */ function trestle_update_revisions_number( $num ) { - $trestle_revisions_number = esc_attr( genesis_get_option( 'revisions_number', 'trestle-settings' ) ); + $trestle_revisions_number = esc_attr( trestle_get_option( 'revisions_number' ) ); - if ( isset( $trestle_revisions_number ) ) + if ( isset( $trestle_revisions_number ) ) { return $trestle_revisions_number; + } return $num; } @@ -303,7 +347,7 @@ add_filter( 'the_content_more_link', 'trestle_read_more_link' ); function trestle_read_more_link( $default_text ) { // Get Trestle custom "read more" link text. - $custom_text = esc_attr( genesis_get_option( 'read_more_text', 'trestle-settings' ) ); + $custom_text = esc_attr( trestle_get_option( 'read_more_text' ) ); if ( $custom_text ) { return '… ' . $custom_text . '';