* @copyright Copyright (c) 2013, Danny Ramirez * @link (Alku, http://demo.dronix.me/alku) * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GPL 2 or later */ /* Load Hybrid Core framework. */ require_once( trailingslashit( get_template_directory() ) . 'core/hybrid.php' ); new Hybrid(); /* Attach our theme setup to the 'after_setup_theme' hook. */ add_action( 'after_setup_theme', 'alku_theme_setup' ); /** * Theme setup function. * * This function adds support for theme features and the various extensions * and utilities of the Hybrid Core framework. It also defines the default * actions and filters. * * @since 0.1.0 */ function alku_theme_setup() { /* Get our theme's prefix. */ $prefix = hybrid_get_prefix(); /* Add theme support for Hybrid Core features. */ add_theme_support( 'hybrid-core-menus', array( 'primary' ) ); add_theme_support( 'hybrid-core-sidebars', array( 'primary' ) ); add_theme_support( 'hybrid-core-widgets' ); add_theme_support( 'hybrid-core-shortcodes' ); add_theme_support( 'hybrid-core-template-hierarchy' ); add_theme_support( 'hybrid-core-scripts', array( 'comment-reply' ) ); add_theme_support( 'hybrid-core-styles', array( 'gallery', 'parent', 'style' ) ); /* Add theme support for Hybrid Core extensions. */ add_theme_support( 'theme-layouts', array( '1c', '2c-l', '2c-r' ), array( 'default' => '2c-l' ) ); add_theme_support( 'post-stylesheets' ); add_theme_support( 'loop-pagination' ); add_theme_support( 'get-the-image' ); add_theme_support( 'cleaner-gallery' ); /* Add theme support for WordPress features. */ add_theme_support( 'automatic-feed-links' ); add_theme_support( 'post-formats', array( 'aside', 'audio', 'chat', 'image', 'gallery', 'link', 'quote', 'status', 'video') ); /* Add theme support for Alku features. */ add_theme_support( 'alku-custom-fonts' ); /* Lets make the visual editor match our theme styles. */ add_editor_style(); /* Add some custom styles and scripts. */ add_action( 'wp_enqueue_scripts', 'alku_scripts_styles' ); /* Lets add a custom body class. */ add_filter( 'body_class', 'alku_body_class' ); /* Lets add our own shortcodes. */ add_action( 'init', 'alku_register_shortcodes', 11 ); /* Filter the sidebar widgets. */ add_filter( 'sidebars_widgets', 'alku_disable_sidebars' ); add_action( 'template_redirect', 'alku_one_column' ); /* Add some custom User Profile fields. */ add_filter( 'user_contactmethods', 'alku_user_contact_methods' ); /* Set default embeds width. */ hybrid_set_content_width( 600 ); add_filter( 'embed_defaults', 'alku_embed_defaults' ); /* Lets filter `the_content`. */ add_filter( 'the_content', 'alku_extend_the_content' ); } /** * Registers and enqueues our custom stylesheets and javascripts. * * @since 0.1.0 */ function alku_scripts_styles() { /* Use the .min script if SCRIPT_DEBUG is turned off. */ $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; $protocol = is_ssl() ? 'https' : 'http'; $query_args = array( 'family' => 'Open+Sans:400italic,300,400,600,700,800' ); /* Register our fonts styles. */ wp_register_style( 'alku-fonts', add_query_arg( $query_args, "$protocol://fonts.googleapis.com/css" ), array(), null ); wp_register_style( 'alku-icon-fonts', trailingslashit( THEME_URI ) . "css/elusive-webfont{$suffix}.css", array(), null ); /* Enqueue our fonts if current theme supports Alku's custom fonts. */ if ( current_theme_supports( 'alku-custom-fonts' ) ) { wp_enqueue_style( 'alku-fonts' ); wp_enqueue_style( 'alku-icon-fonts' ); } /* Register our scripts */ wp_register_script( 'alku-flexslider', trailingslashit( THEME_URI ) . "js/jquery.flexslider{$suffix}.js", array( 'jquery' ), '20130101', true ); wp_register_script( 'alku-fitvids', trailingslashit( THEME_URI ) . "js/jquery.fitvids{$suffix}.js", array( 'jquery' ), '20130101', true ); wp_register_script( 'alku-custom-scripts', trailingslashit( THEME_URI ) . "js/jquery.custom.js", array( 'jquery' ), '20130101', true ); /* Enqueue our scripts. */ wp_enqueue_script( 'alku-fitvids' ); wp_enqueue_script( 'alku-flexslider' ); wp_enqueue_script( 'alku-custom-scripts' ); } /** * Creates an additional class * * @since 0.1.0 */ function alku_body_class( $classes ) { /* If Alku's custom fonts are enabled. */ if ( current_theme_supports( 'alku-custom-fonts' ) ) $classes[] = 'custom-font-enabled'; return $classes; } /** * Removes some of Hybrid Core default shortcodes with our own and creates * additional ones. * * @since 0.1.0 */ function alku_register_shortcodes() { /* Remove some of Hybrid Core shortcodes. */ remove_shortcode( 'comment-published' ); /* Add our own shortcodes. */ add_shortcode( 'comment-published', 'alku_comment_published_shortcode' ); add_shortcode( 'hc-link', 'alku_hc_link_shortcode' ); add_shortcode( 'author-info', 'alku_author_info_shortcode' ); add_shortcode( 'gallery-slider', 'alku_gallery_slider_shortcode' ); } /** * Shortcode for displaying the published date and time of an individual comment wrapped * in a link . * * @since 0.1.0 * @return string */ function alku_comment_published_shortcode() { global $comment; $link = '' . sprintf( '', esc_url( get_comment_link( $comment->comment_ID ) ), get_comment_time( 'c' ), sprintf( __( '%1$s at %2$s', 'alku' ), get_comment_date(), get_comment_time() ) ) . ''; return $link; } /** * Shortcode for displaying a link back to Hybrid Core. * * @since 0.1.0 */ function alku_hc_link_shortcode() { return '' . __( 'Hybrid Core', 'hybrid-core' ) . ''; } /** * Shortcode for displaying information regarding the * author of a post. * * @since 0.1.0 */ function alku_author_info_shortcode( $attr ) { $attr = shortcode_atts( array( 'container_class' => 'author-info', 'header_tag' => 'h2', 'header_class' => 'username', 'show_avatar' => true, 'github' => is_archive() ? get_user_meta( get_query_var( 'author' ), 'github', true ) : get_user_meta( get_the_author_meta( 'ID' ), 'github', true ), 'twitter' => is_archive() ? get_user_meta( get_query_var( 'author' ), 'twitter', true ) : get_user_meta( get_the_author_meta( 'ID' ), 'twitter', true ), 'dribbble' => is_archive() ? get_user_meta( get_query_var( 'author' ), 'dribbble', true ) : get_user_meta( get_the_author_meta( 'ID' ), 'dribbble', true ), 'avatar' => is_archive() ? get_avatar( get_query_var( 'author' ) ) : get_avatar( get_the_author_meta( 'ID' ) ), 'author_url' => is_archive() ? get_the_author_meta( 'user_url', get_query_var( 'author' ) ) : get_author_posts_url( get_the_author_meta( 'ID' ) ), 'author_description' => wpautop( get_the_author_meta( 'description', get_query_var( 'author' )) ) ), $attr ); extract( $attr ); if ( 'true' == $show_avatar ) $output = "
" . "{$avatar}<{$header_tag} class='{$header_class}'>" . get_the_author_meta( 'display_name', get_query_var( 'author' ) ) . "
{$github} {$dribbble}
{$author_description}
"; else $output = "
" . "<{$header_tag}>" . get_the_author_meta( 'display_name', get_query_var( 'author' ) ) . "{$author_description}
"; return $output; } /** * Shortcode based on the modified version of 'cleaner-gallery'. * This shortcode acts just like the default [gallery], the only difference is * the returned HTML. * @since 0.1.1 */ function alku_gallery_slider_shortcode( $attr ) { global $post; static $alku_gallery_slider_instance = 0; $alku_gallery_slider_instance++; /* We're not worried abut galleries in feeds, so just return the output here. */ if ( is_feed() ) return $output; if (!empty($attr['ids'])) { if (empty($attr['orderby'])) { $attr['orderby'] = 'post__in'; } $attr['include'] = $attr['ids']; } /* Apply filters to the default arguments. */ $output = apply_filters('alku_post_gallery_slider', '', $attr); /* Orderby. */ if ( isset( $attr['orderby'] ) ) { $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] ); if ( !$attr['orderby'] ) unset( $attr['orderby'] ); } /* Default gallery settings. */ $defaults = array( 'order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post->ID, 'container_class' => 'flexslider', 'list_class' => 'slides', 'list_tag' => 'ul', 'itemtag' => 'li', 'icontag' => '', 'captiontag' => '', 'columns' => 3, 'size' => 'full', 'ids' => '', 'include' => '', 'exclude' => '', 'numberposts' => -1, 'offset' => '' ); /* Apply filters to the default arguments. */ $defaults = apply_filters( 'alku_gallery_slider_defaults', $defaults ); /* Apply filters to the arguments. */ $attr = apply_filters( 'alku_gallery_slider_args', $attr ); /* Merge the defaults with user input. */ $attr = shortcode_atts( $defaults, $attr ); extract( $attr ); $id = intval( $id ); /* Arguments for get_children(). */ $children = array( 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'exclude' => $exclude, 'include' => $include, 'numberposts' => $numberposts, 'offset' => $offset, 'suppress_filters' => true ); /* Get image attachments. If none, return. */ if (!empty($include)) { $_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby)); $attachments = array(); foreach ($_attachments as $key => $val) { $attachments[$val->ID] = $_attachments[$key]; } } elseif (!empty($exclude)) { $attachments = get_children(array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby)); } else { $attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby)); } if (empty($attachments)) { return ''; } if (is_feed()) { $output = "\n"; foreach ($attachments as $att_id => $attachment) { $output .= wp_get_attachment_link($att_id, $size, true) . "\n"; } return $output; } /* Properly escape the gallery tags. */ $container_class = tag_escape( $container_class ); $list_class = tag_escape( $list_class ); $list_tag = tag_escape( $list_tag ); $itemtag = tag_escape( $itemtag ); $icontag = tag_escape( $icontag ); $captiontag = tag_escape( $captiontag ); $i = 0; /* Add opening wrapping and gallery
. */ $output = "