'#ffffff' ) ); } /** * This function unregisters extra sidebars that are not used in this theme. It also modifies * the global $wp_registered_sidebars to change the output of the Primary Sidebar for the "tuck" effect (CSS). */ function widgets_init() { global $wp_registered_sidebars; // Primary Sidebar if ( isset( $wp_registered_sidebars['primary-sidebar'] ) ) { $wp_registered_sidebars['primary-sidebar']['before_widget'] .= '
'; $wp_registered_sidebars['primary-sidebar']['after_widget'] .= '
'; } // Unregister unused sidebars which are registered in SDS Core unregister_sidebar( 'front-page-slider-sidebar' ); unregister_sidebar( 'front-page-sidebar' ); unregister_sidebar( 'header-call-to-action-sidebar' ); unregister_sidebar( 'footer-sidebar' ); } /** * This function adds editor styles based on post type, before TinyMCE is initialized. * It will also enqueue the correct color scheme stylesheet to better match front-end display. */ function pre_get_posts() { global $sds_theme_options, $post; $protocol = is_ssl() ? 'https' : 'http'; // Admin only and if we have a post if ( is_admin() && ! empty( $post ) ) { add_editor_style( 'css/editor-style.css' ); // Add correct color scheme if selected if ( function_exists( 'sds_color_schemes' ) && ! empty( $sds_theme_options['color_scheme'] ) && $sds_theme_options['color_scheme'] !== 'default' ) { $color_schemes = sds_color_schemes(); add_editor_style( 'css/' . $color_schemes[$sds_theme_options['color_scheme']]['stylesheet'] ); } // Open Sans & Oswald Web Fonts (include only if a web font is not selected in Theme Options) if ( ! function_exists( 'sds_web_fonts' ) || empty( $sds_theme_options['web_font'] ) ) add_editor_style( $protocol . '://fonts.googleapis.com/css?family=Open+Sans|Oswald' ); // Google WebFonts (Open Sans & Oswald) } } /** * This function enqueues all styles and scripts (Main Stylesheet, Fonts, etc...). * Stylesheets can be conditionally included if needed */ function wp_enqueue_scripts() { global $sds_theme_options, $post; $is_mobile = wp_is_mobile(); // Determine if user is on a mobile device $protocol = is_ssl() ? 'https' : 'http'; // Determine current protocol // Capture (main stylesheet) wp_enqueue_style( 'capture', get_template_directory_uri() . '/style.css', false, self::CAPTURE_VERSION ); // Enqueue the child theme stylesheet only if a child theme is active if ( is_child_theme() ) wp_enqueue_style( 'capture-child', get_stylesheet_uri(), array( 'capture' ), self::CAPTURE_VERSION ); // Damion, Open Sans & Oswald Web Fonts (include only if a web font is not selected in Theme Options) if ( ! function_exists( 'sds_web_fonts' ) || empty( $sds_theme_options['web_font'] ) ) wp_enqueue_style( 'damion-open-sans-oswald-web-fonts', $protocol . '://fonts.googleapis.com/css?family=Damion|Open+Sans|Oswald', false, self::CAPTURE_VERSION ); // Google WebFonts (Damion, Open Sans & Oswald) // Font Awesome wp_enqueue_style( 'font-awesome-css-min', get_template_directory_uri() . '/includes/css/font-awesome.min.css' ); // Ensure jQuery is loaded on the front end for our footer script (@see wp_footer() below) wp_enqueue_script( 'jquery' ); // If we're not on a single attachment page if ( ! is_attachment() ) { // ImagesLoaded wp_enqueue_script( 'imagesloaded-min', get_template_directory_uri() . '/js/imagesloaded.min.js', array( 'jquery' ), self::CAPTURE_VERSION, true ); // Hammer if ( $is_mobile ) wp_enqueue_script( 'hammer-min', get_template_directory_uri() . '/js/hammer.min.js', false, self::CAPTURE_VERSION, true ); // Capture Slideshow wp_enqueue_script( 'capture-slideshow-min', get_template_directory_uri() . '/js/capture-slideshow.min.js', ( $is_mobile ) ? array( 'jquery', 'backbone', 'hammer-min' ) : array( 'jquery', 'backbone' ), self::CAPTURE_VERSION, true ); wp_localize_script( 'capture-slideshow-min', 'capture', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'capture_slideshow' ), 'permalinks' => ( get_option( 'permalink_structure' ) ) ? true : false, 'is_archive' => ( is_archive() || is_home() || is_search() ) ? true : false, 'is_mobile' => ( $is_mobile ) ? true : false ) ); } } /** * This function removes the default Jetpack Share Buttons output on single posts and * posts shown on the home, archive, and search page templates. */ function the_post( $post ) { if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'sharedaddy' ) && $post->post_type === 'post' && ( is_single() || is_home() || is_archive() || is_search() ) ) { remove_filter( 'the_content', 'sharing_display', 19 ); remove_filter( 'the_excerpt', 'sharing_display', 19 ); } } /** * This function prepends Jetpack Share Buttons to single post content. */ function the_content( $content ) { if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'sharedaddy' ) && is_single() ) $content = sharing_display() . $content; return $content; } /** * This function outputs the necessary Javascript for the responsive menus and Capture Slideshow. */ function wp_footer() { global $post; ?> get_setting( 'background_' . $prop )->transport = 'refresh'; } } } /** * This function sets the default color for the content area in the Theme Customizer. */ function theme_mod_content_color( $color ) { return $color ? $color : '#333333'; } /** * This function handles Ajax/Backbone requests for the Capture Slideshow */ function wp_ajax_capture_slideshow() { global $wpdb; // Make sure we have a valid request check_ajax_referer( 'capture_slideshow', 'nonce' ); // Determine protocol $protocol = is_ssl() ? 'https' : 'http'; // Select two previous, the current, and two next posts with featured images $current_post_id = ( isset( $_REQUEST['current_post_id'] ) ) ? abs( ( int ) $_REQUEST['current_post_id'] ) : false; $initial_post_id = ( isset( $_REQUEST['initial_post_id'] ) ) ? abs( ( int ) $_REQUEST['initial_post_id'] ) : false; $num_next_prev_posts = ( isset( $_REQUEST['num_next_prev_posts'] ) && ( int ) $_REQUEST['num_next_prev_posts'] <= 5 ) ? abs( ( int ) $_REQUEST['num_next_prev_posts'] ) : 2; if ( $current_post_id && $initial_post_id && $num_next_prev_posts ) { $capture_slideshow_posts = $wpdb->get_results( "( SELECT ID, post_title, post_date FROM $wpdb->posts INNER JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id ) WHERE post_date < ( SELECT post_date FROM $wpdb->posts WHERE ID = $current_post_id ) AND ( $wpdb->posts.post_type = 'post' ) AND ( $wpdb->posts.post_status = 'publish' ) AND ( $wpdb->postmeta.meta_key = '_thumbnail_id' ) GROUP BY $wpdb->posts.ID ORDER BY post_date DESC LIMIT $num_next_prev_posts ) UNION ( SELECT ID, post_title, post_date FROM $wpdb->posts INNER JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id ) WHERE ID = $current_post_id OR post_date > ( SELECT post_date AS current_post_date FROM $wpdb->posts WHERE ID = $current_post_id ) AND ( $wpdb->posts.post_type = 'post' ) AND ( $wpdb->posts.post_status = 'publish' ) AND ( $wpdb->postmeta.meta_key = '_thumbnail_id' ) GROUP BY $wpdb->posts.ID ORDER BY post_date LIMIT " . ( $num_next_prev_posts + 1 ) . " )" ); // Build Backbone Models (if we have posts) if ( ! empty( $capture_slideshow_posts ) && is_array( $capture_slideshow_posts ) ) { $models = array(); $current_image_index = 0; // Ensure we have an array ordered by post date DESC usort( $capture_slideshow_posts, function( $a, $b ) { return strnatcmp( strtotime( $b->post_date ), strtotime( $a->post_date ) ); } ); foreach( $capture_slideshow_posts as $post ) { $featured_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); // Capture Slideshow Model $model = array( 'img' => array( 'src' => $featured_image[0], 'width' => $featured_image[1], 'height' => $featured_image[2] ), 'post' => array( 'id' => $post->ID, 'title' => $post->post_title, 'date' => sprintf( __( 'Posted On %1$s', 'capture' ) , get_the_time( 'F jS, Y', $post->ID ) ), 'timestamp' => strtotime( $post->post_date ), 'permalink' => str_replace( $protocol . '://' . $_SERVER['SERVER_NAME'], '', get_permalink( $post->ID ) ) // Just return the URI ), ); // Append current post details to Capture Slideshow Model if ( ( int ) $post->ID === $current_post_id ) { $model['current_image'] = true; $current_image_index = count( $models ); } // Append initial post details to Capture Slideshow Model if ( ( int ) $post->ID === $initial_post_id ) $model['initial_image'] = true; $models[] = $model; // Append current model to model group } // Check to see if there are no more previous/next images if ( count( $models ) < ( $num_next_prev_posts * 2 + 1 ) ) { // No more previous images (current image is not in the middle) if ( $current_image_index < $num_next_prev_posts ) $models[0]['no_more_images'] = true; // No more next images if( ( count( $models ) - $current_image_index - 1 ) < $num_next_prev_posts ) $models[( count( $models ) - 1 )]['no_more_images'] = true; } // Check the database if necessary just to make sure if ( count( $models ) <= ( $num_next_prev_posts * 2 + 1 ) ) { if ( ! isset( $models[0]['no_more_images'] ) && ! ( $no_more_images = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts INNER JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id ) WHERE $wpdb->posts.post_date > ( SELECT post_date FROM $wpdb->posts WHERE ID = " . $models[0]['post']['id'] . " ) AND ( $wpdb->posts.post_type = 'post' ) AND ( $wpdb->posts.post_status = 'publish' ) AND ( $wpdb->postmeta.meta_key = '_thumbnail_id' )" ) ) ) $models[0]['no_more_images'] = true; if ( ! isset( $models[( count( $models ) - 1 )]['no_more_images'] ) && ! ( $no_more_images = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts INNER JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id ) WHERE post_date < ( SELECT post_date FROM $wpdb->posts WHERE ID = " . $models[( count( $models ) - 1 )]['post']['id'] . " ) AND ( $wpdb->posts.post_type = 'post' ) AND ( $wpdb->posts.post_status = 'publish' ) AND ( $wpdb->postmeta.meta_key = '_thumbnail_id' )" ) ) ) $models[( count( $models ) - 1 )]['no_more_images'] = true; } echo json_encode( $models ); // Return models to collection } } exit; } /** * This function adds a URL Endpoint for the Capture Slideshow lightbox. */ function init() { add_rewrite_endpoint( 'lightbox', EP_PERMALINK ); // http://example.com/permalink/lightbox/ } /** * This function modifies the request to ensure the above URL Endpoint functions as we desire. */ function request( $request ) { // Check to make sure our endpoint is set if( isset( $request['lightbox'] ) ) $request['lightbox'] = true; return $request; } /*********************** * Capture Theme Hooks * ***********************/ /** * This function outputs Jetpack Share Buttons in post footers. */ function capture_post_footer_right( $post ){ if( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'sharedaddy' ) && $post->post_type === 'post' ) echo sharing_display(); } /*************** * WooCommerce * ***************/ /** * This function alters the default WooCommerce content wrapper starting element. */ function woocommerce_before_main_content(){ ?>