From e3bd42a5f86c7b07ab5979c2e51c61ef878c644d Mon Sep 17 00:00:00 2001 From: Joshua Roy Date: Thu, 4 Dec 2014 10:28:39 -0500 Subject: [PATCH] Update to fix broken metaslider alt tags --- functions.php | 599 +++++++++++++++++++++++++------------------------- 1 file changed, 303 insertions(+), 296 deletions(-) diff --git a/functions.php b/functions.php index 56290cb..2dbfdba 100644 --- a/functions.php +++ b/functions.php @@ -1,297 +1,304 @@ - __( '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'); - -/*the fallback from wp_nav_menu, we want to replicate the output of wp_page_menu to be similar to wp_nav_menu -@param args, it comes from the wp_nav_menu arguments*/ -function hale_main_nav_fallback($args) { - $args['echo'] = 0; // don't echo the output yet. - $nav_menu = wp_page_menu($args); - if(!empty($nav_menu)){ - $doc = new DOMDocument(); - @$doc->loadHTML($nav_menu);//surpress the warnings - $data = $doc->getElementsByTagName('li'); - //the default behaviour of wp_page_menu is that it wraps the list items with a ul and div - //menu_class is for div in wp_page_menu, but is for the ul in wp_nav_menu - //create the container, if any - //container class and id come from wp_nav_menu arguments. Which is not used in wp_page_menu. - if($args['container'] != false) { - $attributes = (!empty($args['container_class'])?' class="'.$args['container_class'].'"':''); - $attributes .= (!empty($args['container_id'])?' id="'.$args['container_id'].'"':''); - if($args['container'] == 'nav') { - echo ''; - } else { - echo ''; - } - - } - $attributes = (!empty($args['menu_class'])?' class="'.$args['menu_class'].'"':''); - $attributes .= (!empty($args['menu_id'])?' id="'.$args['menu_id'].'"':''); - echo ''; - if($data->length > 0) { - foreach($data as $item) { - echo $item->ownerDocument->saveXML($item);//saveHTML wouldn't accept it as paramater. - } - } - echo ''; - //close the container, if any - if($args['container'] != false) { - if($args['container'] == 'nav') { - echo ''; - } else { - echo ''; - } - - } - } - return; -} - -function disable_comments_media_attachments( $open, $post_id ){ - $post = get_post_type( $post_id ); - if( $post == 'attachment' ) { - $open = false; - } - return $open; -} -add_filter('comments_open', 'disable_comments_media_attachments', 10 , 2); - + __( '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'); + +/*the fallback from wp_nav_menu, we want to replicate the output of wp_page_menu to be similar to wp_nav_menu +@param args, it comes from the wp_nav_menu arguments*/ +function hale_main_nav_fallback($args) { + $args['echo'] = 0; // don't echo the output yet. + $nav_menu = wp_page_menu($args); + if(!empty($nav_menu)){ + $doc = new DOMDocument(); + @$doc->loadHTML($nav_menu);//surpress the warnings + $data = $doc->getElementsByTagName('li'); + //the default behaviour of wp_page_menu is that it wraps the list items with a ul and div + //menu_class is for div in wp_page_menu, but is for the ul in wp_nav_menu + //create the container, if any + //container class and id come from wp_nav_menu arguments. Which is not used in wp_page_menu. + if($args['container'] != false) { + $attributes = (!empty($args['container_class'])?' class="'.$args['container_class'].'"':''); + $attributes .= (!empty($args['container_id'])?' id="'.$args['container_id'].'"':''); + if($args['container'] == 'nav') { + echo ''; + } else { + echo ''; + } + + } + $attributes = (!empty($args['menu_class'])?' class="'.$args['menu_class'].'"':''); + $attributes .= (!empty($args['menu_id'])?' id="'.$args['menu_id'].'"':''); + echo ''; + if($data->length > 0) { + foreach($data as $item) { + echo $item->ownerDocument->saveXML($item);//saveHTML wouldn't accept it as paramater. + } + } + echo ''; + //close the container, if any + if($args['container'] != false) { + if($args['container'] == 'nav') { + echo ''; + } else { + echo ''; + } + + } + } + return; +} + +function disable_comments_media_attachments( $open, $post_id ){ + $post = get_post_type( $post_id ); + if( $post == 'attachment' ) { + $open = false; + } + return $open; +} +add_filter('comments_open', 'disable_comments_media_attachments', 10 , 2); + +function metaslider_filmstrip_alt_tags( $list_item, $post, $url ) { + $alt = get_post_meta( $post->ID, '_wp_attachment_image_alt', true ); + $list_item = "
  • ID} post-{$post->ID}\" style=\"display: none;\">\"{$alt}
  • "; + return $list_item; +} +add_filter( 'metaslider_filmstrip_list_item', 'metaslider_filmstrip_alt_tags', 10, 3 ); + ?> \ No newline at end of file