File: /home/mmickelson/martyknows.com/wp-content/themes/vertigo/functions.php
<?php
/**
* @package Vertigo
*/
// Set the content width based on the theme's design and stylesheet.
if ( ! isset( $content_width ) )
$content_width = 430;
/**
* Get theme options
* If empty, use the default values
* @return array
**/
function vertigo_get_theme_options() {
$default_options = vertigo_default_options();
return get_option( 'vertigo_theme_options', $default_options );
}
if ( ! function_exists( 'vertigo_setup' ) ):
function vertigo_setup() {
// Load theme options
require( get_template_directory() . '/inc/theme-options.php' );
// Make theme available for translation
// Translations can be filed in the /languages/ directory
load_theme_textdomain( 'vertigo', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head
add_theme_support( 'automatic-feed-links' );
// This theme uses wp_nav_menu() in one location.
register_nav_menu( 'primary', __( 'Primary Menu', 'vertigo' ) );
// Add support for Post Formats
add_theme_support( 'post-formats', array( 'aside', 'audio', 'chat', 'gallery', 'image', 'link', 'quote', 'status', 'video' ) );
}
endif;
// Tell WordPress to run vertigo_setup() when the 'after_setup_theme' hook is run.
add_action( 'after_setup_theme', 'vertigo_setup' );
// Add Vertigo colors
function vertigo_colors() {
?>
<style type="text/css">
/* <![CDATA[ */
/* Accent Color */
<?php $vertigocolors = get_template_directory() . '/inc/style.colors.php';
if ( is_file( $vertigocolors ) )
require( $vertigocolors );
?>
/* ]]> */
</style>
<?php }
add_action( 'wp_head', 'vertigo_colors' );
// Remove inline styles printed when the gallery shortcode is used.
add_filter( 'use_default_gallery_style', '__return_false' );
if ( ! function_exists( 'vertigo_comment' ) ) :
// Template for comments and pingbacks.
function vertigo_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case '' :
?>
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
<div id="comment-<?php comment_ID(); ?>">
<div class="comment-author vcard">
<?php echo get_avatar( $comment, 24 ); ?>
<?php printf( __( '%s ⋅', 'vertigo' ) . ' ', sprintf( '%s', get_comment_author_link() ) ); ?>
</div><!-- .comment-author .vcard -->
<?php if ( $comment->comment_approved == '0' ) : ?>
<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'vertigo' ); ?></em><br />
<?php endif; ?>
<div class="comment-meta commentmetadata">
<a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
<?php /* translators: 1: date, 2: time */
printf( __( '%1$s at %2$s', 'vertigo' ), get_comment_date(), get_comment_time() ); ?>
</a><?php edit_comment_link( __( '⋅ Edit', 'vertigo' ), ' ' ); ?>
</div><!-- .comment-meta .commentmetadata -->
<div class="comment-body"><?php comment_text(); ?></div>
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div><!-- .reply -->
</div><!-- #comment-## -->
<?php
break;
case 'pingback' :
case 'trackback' :
?>
<li class="pingback">
<p><?php _e( 'Pingback:', 'vertigo' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __( '⋅ EDIT', 'vertigo' ), ' ' ); ?></p>
<?php
break;
endswitch;
}
endif; // ends check for vertigo_comment()
// Enqueue scripts
function vertigo_scripts() {
wp_enqueue_style( 'vertigo-style', get_stylesheet_uri() );
wp_enqueue_script( 'vertigo-functions', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20121228' );
wp_localize_script( 'vertigo-functions', 'vertigo', array(
'search' => __( 'Search', 'vertigo' ),
) );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
$vertigo_options = vertigo_get_theme_options();
if ( 'true' == $vertigo_options['vertigo_font'] ) {
wp_enqueue_script( 'cufon', get_template_directory_uri() . '/js/cufon-yui.js', array( 'jquery' ), '1.09i' );
wp_enqueue_script( 'hitchcock', get_template_directory_uri() . '/js/hitchcock_500.font.js' );
wp_enqueue_script( 'cufon_activate', get_template_directory_uri() . '/js/cufon-activate.js' );
}
}
add_action( 'wp_enqueue_scripts', 'vertigo_scripts' );
/**
* Audio helper script.
*
* If an audio shortcode exists we will enqueue javascript
* that replaces all non-supported audio player instances
* with text links.
*
* @uses shortcode_exists();
*/
function vertigo_audio_script() {
if ( shortcode_exists( 'audio' ) )
return;
if ( ! is_singular() || has_post_format( 'audio' ) )
wp_enqueue_script( 'vertigo-audio', get_template_directory_uri() . '/js/audio.js', array(), '20130521' );
}
add_action( 'wp_enqueue_scripts', 'vertigo_audio_script' );
// Grab the first URL from a Link post
function vertigo_url_grabber() {
$first_url = '';
ob_start();
ob_end_clean();
$output = preg_match_all( '/<a.+href=[\'"]([^\'"]+)[\'"].*>/i', get_the_content(), $matches );
$first_url = $matches[1][0];
if ( empty( $first_url ) )
$first_url = apply_filters( 'the_permalink', get_permalink() );
return $first_url;
}
// Grab the first image from an Image post
function vertigo_image_grabber() {
ob_start();
ob_end_clean();
$output = preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', get_the_content(), $matches );
return isset( $matches[0][0] ) ? $matches[0][0] : '';
}
// Remove the first image the_content for display
function vertigo_content_wo_first_image() {
ob_start();
the_content();
$content_wo_first_image = preg_replace( '/<img[^>]+./','', ob_get_contents(), 1 );
ob_end_clean();
return $content_wo_first_image;
}
// Grab the URL the first audio attachment in a post
function vertigo_audio_grabber() {
$first_audio = '';
if ( function_exists( 'get_attached_media' ) )
$first_audio = array_shift( get_attached_media( 'audio', get_the_ID() ) )->guid;
if ( empty( $first_audio ) ) {
global $wpdb;
$first_audio = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'attachment' AND post_mime_type = 'audio/mpeg' ORDER BY menu_order ASC LIMIT 1", get_the_ID() ) );
if ( $first_audio )
$first_audio = wp_get_attachment_url( $first_audio[0]->ID );
}
return empty( $first_audio )? false : esc_url( $first_audio );
}
/**
* Get a short-form mime type for an audio file to display as a class attribute.
*
* @param int ID of an attachment
* @return string A short representation of the file's mime type.
*/
function vertigo_post_classes( $classes ) {
if ( has_post_format( 'audio' ) ) {
$audio = vertigo_audio_grabber();
if ( is_object( $audio ) ) {
$mime = str_replace( 'audio/', '', get_post_mime_type( $audio->ID ) );
if ( in_array( $mime, array( 'mp3', 'ogg', 'wav', ) ) )
$classes[] = $mime;
}
}
return $classes;
}
add_filter( 'post_class', 'vertigo_post_classes' );
if ( ! function_exists( 'the_post_format_audio' ) ) :
/**
* Shiv for the_post_format_audio().
*
* the_post_format_audio() was introduced to WordPress in version 3.6. To
* provide backward compatibility with previous versions, we will define our
* own version of this function.
*
* @todo Remove this function when WordPress 3.8 is released.
*
* @param string $name The name of the shortcode.
* @return bool True if shortcode exists; False otherwise.
*/
function the_post_format_audio() {
$audio = vertigo_audio_grabber();
if ( is_object( $audio ) ) :
$url = wp_get_attachment_url( $audio->ID );
?>
<div class="player">
<audio controls preload="auto" autobuffer id="audio-player-<?php the_ID(); ?>" src="<?php echo esc_url( $url ); ?>">
<source src="<?php echo esc_url( $url ); ?>" type="<?php echo esc_attr( get_post_mime_type( $audio->ID ) ); ?>" />
</audio>
<p class="audio-file-link"><?php printf( __( 'Download: %1$s', 'vertigo' ), sprintf( '<a href="%1$s">%2$s</a>', esc_url( $url ), get_the_title( $audio->ID ) ) ); ?></p>
</div>
<?php
endif;
}
endif;
if ( ! function_exists( 'shortcode_exists' ) ) :
/**
* Shiv for shortcode_exists().
*
* shortcode_exists() was introduced to WordPress in version 3.6. To
* provide backward compatibility with previous versions, we will define our
* own version of this function.
*
* @todo Remove this function when WordPress 3.8 is released.
*
* @param string $name The name of the shortcode.
* @return bool True if shortcode exists; False otherwise.
*/
function shortcode_exists( $tag ) {
global $shortcode_tags;
return array_key_exists( $tag, $shortcode_tags );
}
endif;
/**
* Deprecated.
*
* This function is kept just in case it has
* been used in a child theme. It does nothing.
*
* @deprecated 1.4
*/
function vertigo_add_audio_support() {
_deprecated_function( __FUNCTION__, '1.4' );
}
// Replaces "[...]" (appended to automatically generated excerpts) with an "Read more.".
function vertigo_auto_excerpt_more( $more ) {
return '... <a href="'. get_permalink() . '">' . __( 'Read more.', 'vertigo' ) . '</a>';
}
add_filter( 'excerpt_more', 'vertigo_auto_excerpt_more' );
// Show post-meta for use in loop
function vertigo_entry_meta() {
?>
<div class="entry-meta">
<?php edit_post_link( __( 'Edit', 'vertigo' ), '<span class="edit-link">', '</span><br /><br />' ); ?>
<?php if ( ! post_password_required() && ( comments_open() || '0' != get_comments_number() ) ) : ?>
<span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'vertigo' ), __( '1 Comment', 'vertigo' ), __( '% Comments', 'vertigo' ) ); ?></span>
<?php endif; ?>
</div><!-- .entry-meta -->
<?php
}
// Show post-info for use in loop
function vertigo_entry_info() {
?>
<footer class="entry-info">
<p class="permalink"><a href="<?php the_permalink(); ?>">*</a></p>
<div class="data">
<?php
printf( __( '<span class="posted">posted on <a href="%1$s" rel="bookmark"><time class="entry-date" datetime="%2$s" pubdate>%3$s</time></a><br /></span>by <a href="%4$s" title="%5$s">%6$s</a><br />', 'vertigo' ),
get_permalink(),
get_the_date( 'c' ),
get_the_time( get_option( 'date_format' ) ),
get_author_posts_url( get_the_author_meta( 'ID' ) ),
esc_attr( sprintf( __( 'View all posts by %s', 'vertigo' ), get_the_author() ) ),
get_the_author()
);
?>
<?php printf( __( 'filed under %s', 'vertigo' ), get_the_category_list( ', ' ) ); ?><br />
<?php the_tags( __( 'tagged as', 'vertigo' ) . ' ', ', ', '' ); ?>
</div><!-- .data -->
</footer><!-- #entry-info -->
<?php
}
/**
* Register our sidebars and widgetized areas.
*/
function vertigo_widgets_init() {
register_sidebar( array(
'name' => __( 'Footer Area One', 'vertigo' ),
'id' => 'sidebar-1',
'description' => __( 'An optional widget area for your site footer', 'vertigo' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
register_sidebar( array(
'name' => __( 'Footer Area Two', 'vertigo' ),
'id' => 'sidebar-2',
'description' => __( 'An optional widget area for your site footer', 'vertigo' ),
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h1 class="widget-title">',
'after_title' => '</h1>',
) );
}
add_action( 'widgets_init', 'vertigo_widgets_init' );
/**
* Count the number of footer sidebars to enable dynamic classes for the footer
*/
function vertigo_footer_sidebar_class() {
$count = 0;
if ( is_active_sidebar( 'sidebar-1' ) )
$count++;
if ( is_active_sidebar( 'sidebar-2' ) )
$count++;
$class = '';
switch ( $count ) {
case '1':
$class = 'one';
break;
case '2':
$class = 'two';
break;
}
if ( $class )
echo 'class="' . $class . '"';
}
/**
* Check number of pages available to display navigation
*/
function vertigo_pagination() {
global $wp_query, $paged;
$max_page = $wp_query->max_num_pages;
if ( 1 == $max_page )
return; // don't show when only one page
if ( empty( $paged ) )
$paged = 1;
echo '<p class="pages">' . sprintf( __( 'Page %1$s of %2$s', 'vertigo' ), $paged, $max_page ) . '</p> ';
}
/**
* Filters wp_title to print a neat <title> tag based on what is being viewed.
*
* @since Vertigo 1.1
*/
function vertigo_wp_title( $title, $sep ) {
global $page, $paged;
if ( is_feed() )
return $title;
// Add the blog name
$title .= get_bloginfo( 'name' );
// Add the blog description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page() ) )
$title .= " $sep $site_description";
// Add a page number if necessary:
if ( $paged >= 2 || $page >= 2 )
$title .= " $sep " . sprintf( __( 'Page %s', 'vertigo' ), max( $paged, $page ) );
return $title;
}
add_filter( 'wp_title', 'vertigo_wp_title', 10, 2 );
/**
* Implement the Custom Header feature
*/
require( get_template_directory() . '/inc/custom-header.php' );
/**
* This theme was built with PHP, Semantic HTML, CSS, love, and a Toolbox.
*/
/**
* Infinite Scroll Support
*
* Theme Name: Vertigo
*/
/**
* Add theme support for Infinite Scroll. The check for this is in ../infinity.php in settings_api_init().
*/
function vertigo_infinite_scroll_init() {
add_theme_support( 'infinite-scroll', 'content' );
}
add_action( 'init', 'vertigo_infinite_scroll_init' );
/**
* This is the IS loop. That is to say if this were, hypothetically, called by get_template_part() it would most likely be housed in a file
* named content-infinite-scroll.php or loop-infinite-scroll.php.
*
* For older themes, adjustments will most likely need to be made so that there is consistency between
* the primary loop in either home.php or index.php and the following loop, which should adhere to current
* standards of themeing (e.g. hiding comments).
*/
function vertigo_infinite_scroll_render() {
while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
endwhile;
}
add_action( 'infinite_scroll_render', 'vertigo_infinite_scroll_render' );
/**
* All IS-specific style overrides for individual themes will be in a CSS file named, appropriately, using the theme slug.
*/
function vertigo_infinite_scroll_enqueue_styles() {
wp_enqueue_style( 'infinity-vertigo', plugins_url( 'vertigo.css', __FILE__ ), array(), '20120626' );
}
add_action( 'template_redirect', 'vertigo_infinite_scroll_enqueue_styles', 25 );
/**
* infinite_scroll_has_footer_widgets() checks whether or not footer widgets are present. If they are present, then a button to
* 'Load more posts' will be displayed and IS will not be triggered unless a user manually clicks on that button.
*
* Vertigo supports two footer widgets.
*/
function infinite_scroll_has_footer_widgets() {
if ( is_active_sidebar( 'sidebar-1' ) || is_active_sidebar( 'sidebar-2' ) )
return true;
return false;
}