diff --git a/functions.php b/functions.php index 280ed95..746542c 100644 --- a/functions.php +++ b/functions.php @@ -1,233 +1,242 @@ - __( 'Primary Menu', 'cs' ), - ) ); - - // Enable support for Post Formats. - add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link' ) ); - - // Setup the WordPress core custom background feature. - add_theme_support( 'custom-background', apply_filters( 'cs_custom_background_args', array( - 'default-color' => 'ffffff', - 'default-image' => '', - ) ) ); - - // Enable support for HTML5 markup. - add_theme_support( 'html5', array( - 'comment-list', - 'search-form', - 'comment-form', - 'gallery', - 'caption', - ) ); -} -endif; // cs_setup -add_action( 'after_setup_theme', 'cs_setup' ); - -/** - * Register widget area. - * - * @link http://codex.wordpress.org/Function_Reference/register_sidebar - */ -function cs_widgets_init() { - require get_template_directory() . '/inc/reg-sidebars.php'; -} -add_action( 'widgets_init', 'cs_widgets_init' ); - -/** - * Enqueue scripts and styles. - */ -function cs_scripts() { - - wp_enqueue_style( 'cs-style', get_stylesheet_uri()); - - wp_enqueue_script( 'cs-bootstrap-js', network_home_url().'wp-content/global/bootstrap-3.2.0-dist/js/bootstrap.min.js', array( 'jquery' )); - wp_enqueue_script( 'cs-modernizr', get_template_directory_uri() . '/js/cs-modernizr.js', array( 'jquery' )); - wp_enqueue_script( 'cs', get_template_directory_uri() . '/js/cs.js', array( 'jquery' )); - wp_enqueue_script( 'cs-navigation', get_template_directory_uri() . '/js/navigation.js', array( 'cs-bootstrap-js'), '20120206', true ); - wp_enqueue_script( 'cs-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true ); - - if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { - wp_enqueue_script( 'comment-reply' ); - } -} - -add_action( 'wp_enqueue_scripts', 'cs_scripts' ); - -function htmlShiv(){ - $template = get_template_directory_uri(); - echo ''; - - //needed for IE7 grid hack - /*echo ''; */ -} - -add_action( 'wp_head', htmlShiv, 1 ); - -function ieBootstrap(){ - $template = get_template_directory_uri(); - echo ''; - /* - echo ''; - */ -} -add_action( 'wp_head', ieBootstrap, 99 ); - -/** - * Implement the Custom Header feature. - */ -require get_template_directory() . '/inc/custom-header.php'; - -/** - * Custom template tags for this theme. - */ -require get_template_directory() . '/inc/template-tags.php'; - -/** - * Custom functions that act independently of the theme templates. - */ -require get_template_directory() . '/inc/extras.php'; - -/** - * Customizer additions. - */ -require get_template_directory() . '/inc/customizer.php'; - -/** - * Load Jetpack compatibility file. - */ -//require get_template_directory() . '/inc/jetpack.php'; - - -/** -* New versions of functions from Hale, added as includes -*/ -require get_template_directory() . '/inc/nav-walker.php'; - - -/** -* Bootstrap the comment form. -*/ -require get_template_directory() . '/inc/bootstrap-forms.php'; - - -// Change what's hidden by default -add_filter('default_hidden_meta_boxes', 'be_hidden_meta_boxes', 10, 2); -function be_hidden_meta_boxes($hidden, $screen) { - if ( 'post' == $screen->base || 'page' == $screen->base ) - $hidden = array('slugdiv', 'trackbacksdiv', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv'); - // removed 'postcustom', - return $hidden; -} - - -function load_custom_wp_admin_style($hook) { - wp_register_style( 'custom_wp_admin_css', get_template_directory_uri() . '/css/admin-style.css', false, '1.0.0' ); - wp_enqueue_style( 'custom_wp_admin_css' ); - - - wp_register_script('uc-admin-js', get_template_directory_uri() . '/js/admin-style.js', false, '1.0.0'); - wp_enqueue_script('uc-admin-js'); - - if( 'widgets.php' != $hook ) - return; - wp_register_style( 'css-widgets-area', get_template_directory_uri().'/css/widgets-area.php' ); - wp_enqueue_style( 'css-widgets-area' ); -} -add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' ); - -add_theme_support( 'post-thumbnails' ); - -//Bootstrap whitelist -function add_allowed_tags($tags) { - $newtags = array( - 'div', - 'ul', - 'li', - 'button', - 'a'); - $newattrs = array( - 'data-toggle' => true, - 'data-dismiss' => true, - 'data-target' => true, - 'data-spy' => true, - 'data-loading-text' => true, - 'data-parent' => true, - 'data-slide' => true, - 'data-slide-to' => true, - 'data-provide' => true, - 'data-interval' => true, - 'data-pause' => true, - 'data-animation' => true, - 'data-html' => true, - 'data-placement' => true, - 'data-selector' => true, - 'data-title' => true, - 'data-trigger' => true, - 'data-delay' => true, - 'data-container' => true); - - foreach($newtags as $newtag){ - if( isset($tags[$newtag]) && is_array($tags[$newtag])){ - $tags[$newtag] = array_merge($tags[$newtag], $newattrs); - } - else{ - $tags[$newtag] = $newattrs; - } - } - - return $tags; -} -add_filter('wp_kses_allowed_html', 'add_allowed_tags'); + __( 'Primary Menu', 'cs' ), + ) ); + + // Enable support for Post Formats. + add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link' ) ); + + // Setup the WordPress core custom background feature. + add_theme_support( 'custom-background', apply_filters( 'cs_custom_background_args', array( + 'default-color' => 'ffffff', + 'default-image' => '', + ) ) ); + + // Enable support for HTML5 markup. + add_theme_support( 'html5', array( + 'comment-list', + 'search-form', + 'comment-form', + 'gallery', + 'caption', + ) ); +} +endif; // cs_setup +add_action( 'after_setup_theme', 'cs_setup' ); + +/** + * Register widget area. + * + * @link http://codex.wordpress.org/Function_Reference/register_sidebar + */ +function cs_widgets_init() { + require get_template_directory() . '/inc/reg-sidebars.php'; +} +add_action( 'widgets_init', 'cs_widgets_init' ); + +/** + * Enqueue scripts and styles. + */ +function cs_scripts() { + + wp_enqueue_style( 'cs-style', get_stylesheet_uri()); + + wp_enqueue_script( 'cs-bootstrap-js', network_home_url().'wp-content/global/bootstrap-3.2.0-dist/js/bootstrap.min.js', array( 'jquery' )); + wp_enqueue_script( 'cs-modernizr', get_template_directory_uri() . '/js/cs-modernizr.js', array( 'jquery' )); + wp_enqueue_script( 'cs', get_template_directory_uri() . '/js/cs.js', array( 'jquery' )); + wp_enqueue_script( 'cs-navigation', get_template_directory_uri() . '/js/navigation.js', array( 'cs-bootstrap-js'), '20120206', true ); + wp_enqueue_script( 'cs-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true ); + + $outboundtracking = get_option( 'outbound_tracking',''); + if($outboundtracking == 'yes') wp_enqueue_script('uc-link-tracking', get_bloginfo('template_url').'/js/linktracking.js', array('jquery')); + + if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { + wp_enqueue_script( 'comment-reply' ); + } +} + +add_action( 'wp_enqueue_scripts', 'cs_scripts' ); + +function htmlShiv(){ + $template = get_template_directory_uri(); + echo ''; + + //needed for IE7 grid hack + /*echo ''; */ +} + +add_action( 'wp_head', htmlShiv, 1 ); + +function ieBootstrap(){ + $template = get_template_directory_uri(); + echo ''; + /* + echo ''; + */ +} +add_action( 'wp_head', ieBootstrap, 99 ); + +/** + * Implement the Custom Header feature. + */ +require get_template_directory() . '/inc/custom-header.php'; + +/** + * Custom template tags for this theme. + */ +require get_template_directory() . '/inc/template-tags.php'; + +/** + * Custom functions that act independently of the theme templates. + */ +require get_template_directory() . '/inc/extras.php'; + +/** + * Customizer additions. + */ +require get_template_directory() . '/inc/customizer.php'; + +/** + * Load Jetpack compatibility file. + */ +//require get_template_directory() . '/inc/jetpack.php'; + + +/** +* New versions of functions from Hale, added as includes +*/ +require get_template_directory() . '/inc/nav-walker.php'; + + +/** +* Bootstrap the comment form. +*/ +require get_template_directory() . '/inc/bootstrap-forms.php'; + + +/** +* Custom site settings +*/ +require get_template_directory() . '/inc/settings.php'; + + +// Change what's hidden by default +add_filter('default_hidden_meta_boxes', 'be_hidden_meta_boxes', 10, 2); +function be_hidden_meta_boxes($hidden, $screen) { + if ( 'post' == $screen->base || 'page' == $screen->base ) + $hidden = array('slugdiv', 'trackbacksdiv', 'postexcerpt', 'commentstatusdiv', 'commentsdiv', 'authordiv', 'revisionsdiv'); + // removed 'postcustom', + return $hidden; +} + + +function load_custom_wp_admin_style($hook) { + wp_register_style( 'custom_wp_admin_css', get_template_directory_uri() . '/css/admin-style.css', false, '1.0.0' ); + wp_enqueue_style( 'custom_wp_admin_css' ); + + + wp_register_script('uc-admin-js', get_template_directory_uri() . '/js/admin-style.js', false, '1.0.0'); + wp_enqueue_script('uc-admin-js'); + + if( 'widgets.php' != $hook ) + return; + wp_register_style( 'css-widgets-area', get_template_directory_uri().'/css/widgets-area.php' ); + wp_enqueue_style( 'css-widgets-area' ); +} +add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' ); + +add_theme_support( 'post-thumbnails' ); + +//Bootstrap whitelist +function add_allowed_tags($tags) { + $newtags = array( + 'div', + 'ul', + 'li', + 'button', + 'a'); + $newattrs = array( + 'data-toggle' => true, + 'data-dismiss' => true, + 'data-target' => true, + 'data-spy' => true, + 'data-loading-text' => true, + 'data-parent' => true, + 'data-slide' => true, + 'data-slide-to' => true, + 'data-provide' => true, + 'data-interval' => true, + 'data-pause' => true, + 'data-animation' => true, + 'data-html' => true, + 'data-placement' => true, + 'data-selector' => true, + 'data-title' => true, + 'data-trigger' => true, + 'data-delay' => true, + 'data-container' => true); + + foreach($newtags as $newtag){ + if( isset($tags[$newtag]) && is_array($tags[$newtag])){ + $tags[$newtag] = array_merge($tags[$newtag], $newattrs); + } + else{ + $tags[$newtag] = $newattrs; + } + } + + return $tags; +} +add_filter('wp_kses_allowed_html', 'add_allowed_tags'); ?> \ No newline at end of file diff --git a/inc/settings.php b/inc/settings.php new file mode 100644 index 0000000..5961aed --- /dev/null +++ b/inc/settings.php @@ -0,0 +1,37 @@ +' . __( 'Track Outbound Links' , 'outbound_tracking' ) . '', + array( &$this, 'fields_radio' ), + 'general' + ); + } + + /** + * HTML for extra settings + */ + public function fields_radio() { + $value = get_option( 'outbound_tracking', '' ); + echo ' No Yes '; + } + +} +new Add_Settings_Field(); +?> \ No newline at end of file diff --git a/js/linktracking.js b/js/linktracking.js new file mode 100644 index 0000000..9458a1f --- /dev/null +++ b/js/linktracking.js @@ -0,0 +1,30 @@ +/* Attach tracking to all download & external links */ +var _gaq = _gaq || []; + +function _gaLt(event){ + var el = event.srcElement || event.target; + + /* Loop up the tree through parent elements if clicked element is not a link (eg: an image in a link) */ + while(el && (typeof el.tagName == 'undefined' || el.tagName.toLowerCase() != 'a' || !el.href)) + el = el.parentNode; + + if(el && el.href){ + if(el.href.indexOf(location.host) == -1){ /* external link */ + _gaq.push(["_trackEvent", "Outgoing Links", el.href, document.location.pathname + document.location.search]); + /* if target not set then delay opening of window by 0.5s to allow tracking */ + if(!el.target || el.target.match(/^_(self|parent|top)$/i)){ + setTimeout(function(){ + document.location.href = el.href; + }.bind(el),500); + /* Prevent standard click */ + event.preventDefault ? event.preventDefault() : event.returnValue = !1; + } + } + + } +} + +/* Attach the event to all clicks in the document after page has loaded */ +var w = window; +w.addEventListener ? w.addEventListener("load",function(){document.body.addEventListener("click",_gaLt,!1)},!1) + : w.attachEvent && w.attachEvent("onload",function(){document.body.attachEvent("onclick",_gaLt)}); \ No newline at end of file