Created
January 15, 2013 11:52
-
-
Save mjepson/4538108 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*----------------------------------------------------------------------------------- | |
TABLE OF CONTENTS | |
- Exclude categories from displaying on the "Blog" page template. | |
- Exclude categories from displaying on the homepage. | |
- Register WP Menus | |
- Page navigation | |
- Post Meta | |
- Subscribe & Connect | |
- Comment Form Fields | |
- Comment Form Settings | |
- Allow shortcodes in widgets | |
- Google fonts | |
- WooCommerce Check | |
-----------------------------------------------------------------------------------*/ | |
/*-----------------------------------------------------------------------------------*/ | |
/* Exclude categories from displaying on the "Blog" page template. | |
/*-----------------------------------------------------------------------------------*/ | |
// Exclude categories on the "Blog" page template. | |
add_filter( 'woo_blog_template_query_args', 'woo_exclude_categories_blogtemplate' ); | |
function woo_exclude_categories_blogtemplate ( $args ) { | |
if ( ! function_exists( 'woo_prepare_category_ids_from_option' ) ) { return $args; } | |
$excluded_cats = array(); | |
// Process the category data and convert all categories to IDs. | |
$excluded_cats = woo_prepare_category_ids_from_option( 'woo_exclude_cats_blog' ); | |
// Homepage logic. | |
if ( count( $excluded_cats ) > 0 ) { | |
// Setup the categories as a string, because "category__not_in" doesn't seem to work | |
// when using query_posts(). | |
foreach ( $excluded_cats as $k => $v ) { $excluded_cats[$k] = '-' . $v; } | |
$cats = join( ',', $excluded_cats ); | |
$args['cat'] = $cats; | |
} | |
return $args; | |
} // End woo_exclude_categories_blogtemplate() | |
/*-----------------------------------------------------------------------------------*/ | |
/* Exclude categories from displaying on the homepage. | |
/*-----------------------------------------------------------------------------------*/ | |
// Exclude categories on the homepage. | |
add_filter( 'pre_get_posts', 'woo_exclude_categories_homepage' ); | |
function woo_exclude_categories_homepage ( $query ) { | |
if ( ! function_exists( 'woo_prepare_category_ids_from_option' ) ) { return $query; } | |
$excluded_cats = array(); | |
// Process the category data and convert all categories to IDs. | |
$excluded_cats = woo_prepare_category_ids_from_option( 'woo_exclude_cats_home' ); | |
// Homepage logic. | |
if ( is_home() && ( count( $excluded_cats ) > 0 ) ) { | |
$query->set( 'category__not_in', $excluded_cats ); | |
} | |
$query->parse_query(); | |
return $query; | |
} // End woo_exclude_categories_homepage() | |
/*-----------------------------------------------------------------------------------*/ | |
/* Register WP Menus */ | |
/*-----------------------------------------------------------------------------------*/ | |
if ( function_exists( 'wp_nav_menu') ) { | |
add_theme_support( 'nav-menus' ); | |
register_nav_menus( array( 'primary-menu' => __( 'Primary Menu', 'woothemes' ) ) ); | |
register_nav_menus( array( 'top-menu' => __( 'Top Menu', 'woothemes' ) ) ); | |
} | |
/*-----------------------------------------------------------------------------------*/ | |
/* Page navigation */ | |
/*-----------------------------------------------------------------------------------*/ | |
if (!function_exists( 'woo_pagenav')) { | |
function woo_pagenav() { | |
global $woo_options; | |
// If the user has set the option to use simple paging links, display those. By default, display the pagination. | |
if ( array_key_exists( 'woo_pagination_type', $woo_options ) && $woo_options[ 'woo_pagination_type' ] == 'simple' ) { | |
if ( get_next_posts_link() || get_previous_posts_link() ) { | |
?> | |
<div class="nav-entries"> | |
<?php next_posts_link( '<span class="nav-prev fl">'. __( '<span class="meta-nav">←</span> Older posts', 'woothemes' ) . '</span>' ); ?> | |
<?php previous_posts_link( '<span class="nav-next fr">'. __( 'Newer posts <span class="meta-nav">→</span>', 'woothemes' ) . '</span>' ); ?> | |
<div class="fix"></div> | |
</div> | |
<?php | |
} | |
} else { | |
woo_pagination(); | |
} // End IF Statement | |
} // End woo_pagenav() | |
} // End IF Statement | |
/*-----------------------------------------------------------------------------------*/ | |
/* WooTabs - Popular Posts */ | |
/*-----------------------------------------------------------------------------------*/ | |
if (!function_exists( 'woo_tabs_popular')) { | |
function woo_tabs_popular( $posts = 5, $size = 45 ) { | |
global $post; | |
$popular = get_posts( 'ignore_sticky_posts=1&orderby=comment_count&showposts='.$posts); | |
foreach($popular as $post) : | |
setup_postdata($post); | |
?> | |
<li> | |
<?php if ($size <> 0) woo_image( 'height='.$size.'&width='.$size.'&class=thumbnail&single=true' ); ?> | |
<a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php the_title(); ?></a> | |
<span class="meta"><?php the_time( get_option( 'date_format' ) ); ?></span> | |
<div class="fix"></div> | |
</li> | |
<?php endforeach; | |
} | |
} | |
/*-----------------------------------------------------------------------------------*/ | |
/* Post Meta */ | |
/*-----------------------------------------------------------------------------------*/ | |
if (!function_exists( 'woo_post_meta')) { | |
function woo_post_meta( ) { | |
?> | |
<p class="post-meta"> | |
<span class="post-date"><span class="small"><?php _e( 'Posted on', 'woothemes' ) ?></span> <?php the_time( get_option( 'date_format' ) ); ?></span> | |
<span class="post-author"><span class="small"><?php _e( 'by', 'woothemes' ) ?></span> <?php the_author_posts_link(); ?></span> | |
<span class="post-category"><span class="small"><?php _e( 'in', 'woothemes' ) ?></span> <?php the_category( ', ') ?></span> | |
<?php edit_post_link( __( '{ Edit }', 'woothemes' ), '<span class="small">', '</span>' ); ?> | |
</p> | |
<?php | |
} | |
} | |
/*-----------------------------------------------------------------------------------*/ | |
/* Subscribe / Connect */ | |
/*-----------------------------------------------------------------------------------*/ | |
if (!function_exists( 'woo_subscribe_connect')) { | |
function woo_subscribe_connect($widget = 'false', $title = '', $form = '', $social = '') { | |
global $woo_options; | |
// Setup title | |
if ( $widget != 'true' ) | |
$title = $woo_options[ 'woo_connect_title' ]; | |
// Setup related post (not in widget) | |
$related_posts = ''; | |
if ( $woo_options[ 'woo_connect_related' ] == "true" AND $widget != "true" ) | |
$related_posts = do_shortcode( '[related_posts limit="5"]' ); | |
?> | |
<?php if ( $woo_options[ 'woo_connect' ] == "true" OR $widget == 'true' ) : ?> | |
<div id="connect"> | |
<h3><?php if ( $title ) echo apply_filters( 'widget_title', $title ); else _e('Subscribe','woothemes'); ?></h3> | |
<div <?php if ( $related_posts != '' ) echo 'class="col-left"'; ?>> | |
<p><?php if ($woo_options[ 'woo_connect_content' ] != '') echo stripslashes($woo_options[ 'woo_connect_content' ]); else _e( 'Subscribe to our e-mail newsletter to receive updates.', 'woothemes' ); ?></p> | |
<?php if ( $woo_options[ 'woo_connect_newsletter_id' ] != "" AND $form != 'on' ) : ?> | |
<form class="newsletter-form<?php if ( $related_posts == '' ) echo ' fl'; ?>" action="http://feedburner.google.com/fb/a/mailverify" method="post" target="popupwindow" onsubmit="window.open( 'http://feedburner.google.com/fb/a/mailverify?uri=<?php echo $woo_options[ 'woo_connect_newsletter_id' ]; ?>', 'popupwindow', 'scrollbars=yes,width=550,height=520' );return true"> | |
<input class="email" type="text" name="email" value="<?php esc_attr_e( 'E-mail', 'woothemes' ); ?>" onfocus="if (this.value == '<?php _e( 'E-mail', 'woothemes' ); ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e( 'E-mail', 'woothemes' ); ?>';}" /> | |
<input type="hidden" value="<?php echo $woo_options[ 'woo_connect_newsletter_id' ]; ?>" name="uri"/> | |
<input type="hidden" value="<?php bloginfo( 'name' ); ?>" name="title"/> | |
<input type="hidden" name="loc" value="en_US"/> | |
<input class="submit" type="submit" name="submit" value="<?php _e( 'Submit', 'woothemes' ); ?>" /> | |
</form> | |
<?php endif; ?> | |
<?php if ( $woo_options['woo_connect_mailchimp_list_url'] != "" AND $form != 'on' AND $woo_options['woo_connect_newsletter_id'] == "" ) : ?> | |
<!-- Begin MailChimp Signup Form --> | |
<div id="mc_embed_signup"> | |
<form class="newsletter-form<?php if ( $related_posts == '' ) echo ' fl'; ?>" action="<?php echo $woo_options['woo_connect_mailchimp_list_url']; ?>" method="post" target="popupwindow" onsubmit="window.open('<?php echo $woo_options['woo_connect_mailchimp_list_url']; ?>', 'popupwindow', 'scrollbars=yes,width=650,height=520');return true"> | |
<input type="text" name="EMAIL" class="required email" value="<?php _e('E-mail','woothemes'); ?>" id="mce-EMAIL" onfocus="if (this.value == '<?php _e('E-mail','woothemes'); ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e('E-mail','woothemes'); ?>';}"> | |
<input type="submit" value="<?php _e('Submit', 'woothemes'); ?>" name="subscribe" id="mc-embedded-subscribe" class="btn submit button"> | |
</form> | |
</div> | |
<!--End mc_embed_signup--> | |
<?php endif; ?> | |
<?php if ( $social != 'on' ) : ?> | |
<div class="social<?php if ( $related_posts == '' AND $woo_options[ 'woo_connect_newsletter_id' ] != "" ) echo ' fr'; ?>"> | |
<?php if ( $woo_options[ 'woo_connect_rss' ] == "true" ) { ?> | |
<a href="<?php if ( $woo_options['woo_feed_url'] ) { echo esc_url( $woo_options['woo_feed_url'] ); } else { echo get_bloginfo_rss('rss2_url'); } ?>" class="subscribe"><img src="<?php echo get_template_directory_uri(); ?>/images/ico-social-rss.png" title="<?php _e('Subscribe to our RSS feed', 'woothemes'); ?>" alt=""/></a> | |
<?php } if ( $woo_options[ 'woo_connect_twitter' ] != "" ) { ?> | |
<a href="<?php echo esc_url( $woo_options['woo_connect_twitter'] ); ?>" class="twitter"><img src="<?php echo get_template_directory_uri(); ?>/images/ico-social-twitter.png" title="<?php _e('Follow us on Twitter', 'woothemes'); ?>" alt=""/></a> | |
<?php } if ( $woo_options[ 'woo_connect_facebook' ] != "" ) { ?> | |
<a href="<?php echo esc_url( $woo_options['woo_connect_facebook'] ); ?>" class="facebook"><img src="<?php echo get_template_directory_uri(); ?>/images/ico-social-facebook.png" title="<?php _e('Connect on Facebook', 'woothemes'); ?>" alt=""/></a> | |
<?php } if ( $woo_options[ 'woo_connect_youtube' ] != "" ) { ?> | |
<a href="<?php echo esc_url( $woo_options['woo_connect_youtube'] ); ?>" class="youtube"><img src="<?php echo get_template_directory_uri(); ?>/images/ico-social-youtube.png" title="<?php _e('Watch on YouTube', 'woothemes'); ?>" alt=""/></a> | |
<?php } if ( $woo_options[ 'woo_connect_flickr' ] != "" ) { ?> | |
<a href="<?php echo esc_url( $woo_options['woo_connect_flickr'] ); ?>" class="flickr"><img src="<?php echo get_template_directory_uri(); ?>/images/ico-social-flickr.png" title="<?php _e('See photos on Flickr', 'woothemes'); ?>" alt=""/></a> | |
<?php } if ( $woo_options[ 'woo_connect_linkedin' ] != "" ) { ?> | |
<a href="<?php echo esc_url( $woo_options['woo_connect_linkedin'] ); ?>" class="linkedin"><img src="<?php echo get_template_directory_uri(); ?>/images/ico-social-linkedin.png" title="<?php _e('Connect on LinkedIn', 'woothemes'); ?>" alt=""/></a> | |
<?php } if ( $woo_options[ 'woo_connect_delicious' ] != "" ) { ?> | |
<a href="<?php echo esc_url( $woo_options['woo_connect_delicious'] ); ?>" class="delicious"><img src="<?php echo get_template_directory_uri(); ?>/images/ico-social-delicious.png" title="<?php _e('Discover on Delicious', 'woothemes'); ?>" alt=""/></a> | |
<?php } if ( $woo_options[ 'woo_connect_googleplus' ] != "" ) { ?> | |
<a href="<?php echo esc_url( $woo_options['woo_connect_googleplus'] ); ?>" class="googleplus"><img src="<?php echo get_template_directory_uri(); ?>/images/ico-social-googleplus.png" title="<?php _e('View Google+ profile', 'woothemes'); ?>" alt=""/></a> | |
<?php } ?> | |
</div> | |
<?php endif; ?> | |
</div><!-- col-left --> | |
<?php if ( $woo_options[ 'woo_connect_related' ] == "true" AND $related_posts != '' ) : ?> | |
<div class="related-posts col-right"> | |
<h4><?php _e( 'Related Posts:', 'woothemes' ); ?></h4> | |
<?php echo $related_posts; ?> | |
</div><!-- col-right --> | |
<?php wp_reset_query(); endif; ?> | |
<div class="fix"></div> | |
</div> | |
<?php endif; ?> | |
<?php | |
} | |
} | |
/*-----------------------------------------------------------------------------------*/ | |
/* Comment Form Fields */ | |
/*-----------------------------------------------------------------------------------*/ | |
add_filter( 'comment_form_default_fields', 'woo_comment_form_fields' ); | |
if ( ! function_exists( 'woo_comment_form_fields' ) ) { | |
function woo_comment_form_fields ( $fields ) { | |
$commenter = wp_get_current_commenter(); | |
$required_text = ' <span class="required">(' . __( 'Required', 'woothemes' ) . ')</span>'; | |
$req = get_option( 'require_name_email' ); | |
$aria_req = ( $req ? " aria-required='true'" : '' ); | |
$fields = array( | |
'author' => '<p class="comment-form-author">' . | |
'<input id="author" class="txt" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' />' . | |
'<label for="author">' . __( 'Name', 'woothemes' ) . ( $req ? $required_text : '' ) . '</label> ' . | |
'</p>', | |
'email' => '<p class="comment-form-email">' . | |
'<input id="email" class="txt" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' />' . | |
'<label for="email">' . __( 'Email', 'woothemes' ) . ( $req ? $required_text : '' ) . '</label> ' . | |
'</p>', | |
'url' => '<p class="comment-form-url">' . | |
'<input id="url" class="txt" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" />' . | |
'<label for="url">' . __( 'Website', 'woothemes' ) . '</label>' . | |
'</p>', | |
); | |
return $fields; | |
} // End woo_comment_form_fields() | |
} | |
/*-----------------------------------------------------------------------------------*/ | |
/* Comment Form Settings */ | |
/*-----------------------------------------------------------------------------------*/ | |
add_filter( 'comment_form_defaults', 'woo_comment_form_settings' ); | |
if ( ! function_exists( 'woo_comment_form_settings' ) ) { | |
function woo_comment_form_settings ( $settings ) { | |
$settings['comment_notes_before'] = ''; | |
$settings['comment_notes_after'] = ''; | |
$settings['label_submit'] = __( 'Submit Comment', 'woothemes' ); | |
$settings['cancel_reply_link'] = __( 'Click here to cancel reply.', 'woothemes' ); | |
return $settings; | |
} // End woo_comment_form_settings() | |
} | |
/*-----------------------------------------------------------------------------------*/ | |
/* Misc back compat */ | |
/*-----------------------------------------------------------------------------------*/ | |
// array_fill_keys doesn't exist in PHP < 5.2 | |
// Can remove this after PHP < 5.2 support is dropped | |
if ( !function_exists( 'array_fill_keys' ) ) { | |
function array_fill_keys( $keys, $value ) { | |
return array_combine( $keys, array_fill( 0, count( $keys ), $value ) ); | |
} | |
} | |
/*-----------------------------------------------------------------------------------*/ | |
/* Allow shortcodes in widgets */ | |
/*-----------------------------------------------------------------------------------*/ | |
add_filter('widget_text', 'do_shortcode'); | |
/*-----------------------------------------------------------------------------------*/ | |
/* Twitter */ | |
/*-----------------------------------------------------------------------------------*/ | |
function woocommerceframework_tweet(){ | |
$twitterID = get_option('woo_twitter_id'); | |
if (!$twitterID) return; | |
$rss = fetch_feed( "https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=" . $twitterID ); | |
if (!is_wp_error( $rss ) ) : | |
$maxitems = $rss->get_item_quantity(1); | |
$rss_items = $rss->get_items(0, $maxitems); | |
if ($maxitems>0) foreach ( $rss_items as $item ) : | |
?> | |
<p class="tweet"> | |
<?php echo esc_html( $item->get_title() ); ?> | |
<time><a href="<?php echo esc_url( $item->get_permalink() ); ?>"><?php echo human_time_diff( strtotime($item->get_date('j F Y g:i a')), current_time('timestamp', 1) ) ?> <?php _e('ago', 'woothemes'); ?></a></time> | |
</p> | |
<?php | |
endforeach; | |
endif; | |
} | |
/*-------------------------------------------------------------------------------------------*/ | |
/* WooCommerce Check */ | |
/*-------------------------------------------------------------------------------------------*/ | |
if (!function_exists('is_woocommerce_activated')) { | |
function is_woocommerce_activated() { | |
if ( class_exists( 'woocommerce' ) ) { return true; } else { return false; } | |
} | |
} | |
/*-----------------------------------------------------------------------------------*/ | |
/* END */ | |
/*-----------------------------------------------------------------------------------*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment