<?php
/**
* Starkers functions and definitions
*
* @package WordPress
* @subpackage Starkers
* @since Starkers HTML5 3.0
*/
/** Tell WordPress to run starkers_setup() when the 'after_setup_theme' hook is run. */
add_action( 'after_setup_theme', 'starkers_setup' );
if ( ! function_exists( 'starkers_setup' ) ):
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* @since Starkers HTML5 3.0
*/
function starkers_setup() {
// This theme uses post thumbnails
add_theme_support( 'post-thumbnails' );
// Add default posts and comments RSS feed links to head
add_theme_support( 'automatic-feed-links' );
// Add support for visual editor stylesheet
add_editor_style('editor-style.css');
// Make theme available for translation
// Translations can be filed in the /languages/ directory
load_theme_textdomain( 'starkers', TEMPLATEPATH . '/languages' );
$locale = get_locale();
$locale_file = TEMPLATEPATH . "/languages/$locale.php";
if ( is_readable( $locale_file ) )
require_once( $locale_file );
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'primary' => __( 'Primary Navigation', 'starkers' ),
) );
}
endif;
function appglobe_jquery_enqueue() {
if (is_admin()) return;
global $wp_scripts;
$cdn_script_in_footer = false;
if (is_a($wp_scripts, 'WP_Scripts') && isset($wp_scripts->registered['jquery'])) {
$registered_jquery_version = $wp_scripts -> registered[jquery] -> ver;
if($registered_jquery_version) {
$google_jquery_url = ($_SERVER['SERVER_PORT'] == 443 ? "https" : "http") .
"://ajax.googleapis.com/ajax/libs/jquery/$registered_jquery_version/jquery.min.js";
if(200 === wp_remote_retrieve_response_code(wp_remote_head($google_jquery_url))) {
wp_deregister_script('jquery');
wp_register_script('jquery', $google_jquery_url , false, null, $cdn_script_in_footer);
}
}
}
wp_enqueue_script('jquery');
wp_enqueue_style('jscrollpane', get_bloginfo('template_directory') . '/js/jScrollPane.css' );
wp_enqueue_script('jscrollpane', get_bloginfo('template_directory') . '/js/jScrollPane.js', array('jquery') );
wp_enqueue_script('jscroll', get_bloginfo('template_directory') . '/js/jScroll.js', array('jquery') );
wp_enqueue_script('wpa_script', get_bloginfo('template_directory') . '/js/wpascript.js', array('jquery') );
}
add_action('wp_enqueue_scripts', 'appglobe_jquery_enqueue', 11);
/**
* Set our wp_nav_menu() fallback, starkers_menu().
*
* @since Starkers HTML5 3.0
*/
function starkers_menu() {
echo '<nav><ul><li><a href="'.get_bloginfo('url').'">Home</a></li>';
wp_list_pages('title_li=');
echo '</ul></nav>';
}
/**
* Remove inline styles printed when the gallery shortcode is used.
*
* @since Starkers HTML5 3.2
*/
add_filter( 'use_default_gallery_style', '__return_false' );
/**
* @since Starkers HTML5 3.0
* @deprecated in Starkers HTML5 3.2 for WordPress 3.1
*
* @return string The gallery style filter, with the styles themselves removed.
*/
function starkers_remove_gallery_css( $css ) {
return preg_replace( "#<style type='text/css'>(.*?)</style>#s", '', $css );
}
// Backwards compatibility with WordPress 3.0.
if ( version_compare( $GLOBALS['wp_version'], '3.1', '<' ) )
add_filter( 'gallery_style', 'starkers_remove_gallery_css' );
if ( ! function_exists( 'starkers_comment' ) ) :
/**
* Template for comments and pingbacks.
*
* @since Starkers HTML5 3.0
*/
function starkers_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case '' :
?>
<article <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">
<?php echo get_avatar( $comment, 40 ); ?>
<?php printf( __( '%s says:', 'starkers' ), sprintf( '%s', get_comment_author_link() ) ); ?>
<?php if ( $comment->comment_approved == '0' ) : ?>
<?php _e( 'Your comment is awaiting moderation.', 'starkers' ); ?>
<br />
<?php endif; ?>
<a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
<?php
/* translators: 1: date, 2: time */
printf( __( '%1$s at %2$s', 'starkers' ), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)', 'starkers' ), ' ' );
?>
<?php comment_text(); ?>
<?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
<?php
break;
case 'pingback' :
case 'trackback' :
?>
<article <?php comment_class(); ?> id="comment-<?php comment_ID() ?>">
<p><?php _e( 'Pingback:', 'starkers' ); ?> <?php comment_author_link(); ?><?php edit_comment_link( __('(Edit)', 'starkers'), ' ' ); ?></p>
<?php
break;
endswitch;
}
endif;
/**
* Closes comments and pingbacks with </article> instead of </li>.
*
* @since Starkers HTML5 3.0
*/
function starkers_comment_close() {
echo '</article>';
}
/**
* Adjusts the comment_form() input types for HTML5.
*
* @since Starkers HTML5 3.0
*/
function starkers_fields($fields) {
$commenter = wp_get_current_commenter();
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? " aria-required='true'" : '' );
$fields = array(
'author' => '<p><label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '*' : '' ) .
'<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
'email' => '<p><label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '*' : '' ) .
'<input id="email" name="email" type="email" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
'url' => '<p><label for="url">' . __( 'Website' ) . '</label>' .
'<input id="url" name="url" type="url" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
);
return $fields;
}
add_filter('comment_form_default_fields','starkers_fields');
/**
* Register widgetized areas.
*
* @since Starkers HTML5 3.0
*/
function starkers_widgets_init() {
register_sidebar( array(
'name' => __( 'Laurel Widget Area', 'starkers' ),
'id' => 'laurel-widget-area',
'description' => __( 'Laurels in the header - use one image, and make sure it is a transparent PNG no larger than 165px tall by 540px wide.', 'starkers' ),
'before_widget' => '<div id="laurels">',
'after_widget' => '</div><!-- #laurels -->',
'before_title' => '<h3>',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => __( 'Social Media Widget Area', 'starkers' ),
'id' => 'social-widget-area',
'description' => __( 'Social media icons in the navigation bar', 'starkers' ),
'before_widget' => '<div id="social-nav">',
'after_widget' => '</div><!-- #social-nav -->',
'before_title' => '<h3>',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => __( 'Donate Widget Area', 'starkers' ),
'id' => 'donate-widget-area',
'description' => __( 'The donate section of the page sidebar', 'starkers' ),
'before_widget' => '<div id="donate">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => __( 'Buy Widget Area', 'starkers' ),
'id' => 'buy-widget-area',
'description' => __( 'The buy DVD and soundtrack sections of the page sidebar', 'starkers' ),
'before_widget' => '<div class="buy">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => __( 'Blog Widget Area', 'starkers' ),
'id' => 'blog-widget-area',
'description' => __( 'Widgets that appear in the sidebar on blog pages', 'starkers' ),
'before_widget' => '<div class="blogwidget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
) );
register_sidebar( array(
'name' => __( 'Footer Widget Area', 'starkers' ),
'id' => 'footer-widget-area',
'description' => __( 'The footer widget area for logos of supporting organizations', 'starkers' ),
'before_widget' => '<div id="supporters">',
'after_widget' => '</div><!-- #supporters -->',
'before_title' => '<h3>',
'after_title' => '</h3>',
) );
}
/** Register sidebars by running starkers_widgets_init() on the widgets_init hook. */
add_action( 'widgets_init', 'starkers_widgets_init' );
/**
* Removes the default styles that are packaged with the Recent Comments widget.
*
* @updated Starkers HTML5 3.2
*/
function starkers_remove_recent_comments_style() {
add_filter( 'show_recent_comments_widget_style', '__return_false' );
}
add_action( 'widgets_init', 'starkers_remove_recent_comments_style' );
if ( ! function_exists( 'starkers_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post—date/time and author.
*
* @since Starkers HTML5 3.0
*/
function starkers_posted_on() {
printf( __( 'Posted on %2$s by %3$s', 'starkers' ),
'meta-prep meta-prep-author',
sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><time datetime="%3$s" pubdate>%4$s</time></a>',
get_permalink(),
esc_attr( get_the_time() ),
get_the_date('Y-m-d'),
get_the_date()
),
sprintf( '<a href="%1$s" title="%2$s">%3$s</a>',
get_author_posts_url( get_the_author_meta( 'ID' ) ),
sprintf( esc_attr__( 'View all posts by %s', 'starkers' ), get_the_author() ),
get_the_author()
)
);
}
endif;
if ( ! function_exists( 'starkers_posted_in' ) ) :
/**
* Prints HTML with meta information for the current post (category, tags and permalink).
*
* @since Starkers HTML5 3.0
*/
function starkers_posted_in() {
// Retrieves tag list of current post, separated by commas.
$tag_list = get_the_tag_list( '', ', ' );
if ( $tag_list ) {
$posted_in = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'starkers' );
} elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
$posted_in = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'starkers' );
} else {
$posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'starkers' );
}
// Prints the string, replacing the placeholders.
printf(
$posted_in,
get_the_category_list( ', ' ),
$tag_list,
get_permalink(),
the_title_attribute( 'echo=0' )
);
}
endif;
// change excerpt length
function custom_excerpt_length( $length ) {
return 50;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
function getTopParentPostID($myid){
$mypage = get_page($myid);
if ($mypage->post_parent == 0){
return $mypage->ID;
}
else{
return getTopParentPostID($mypage->post_parent);
}
}
function depthToRoot($myid,$depth){
$mypage = get_page($myid);
if ($mypage->post_parent == 0){
return $depth;
}
else{
$depth++;
return depthToRoot($mypage->post_parent, $depth);
}
}