Skip to content

Instantly share code, notes, and snippets.

@ameeker
Created November 5, 2015 01:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ameeker/383a74135c1cd9a1e34c to your computer and use it in GitHub Desktop.
Save ameeker/383a74135c1cd9a1e34c to your computer and use it in GitHub Desktop.
BDSRA Functions.php
<?php
//* Start the engine
include_once( get_template_directory() . '/lib/init.php' );
//* Set Localization (do not remove)
load_child_theme_textdomain( 'outreach', apply_filters( 'child_theme_textdomain', get_stylesheet_directory() . '/languages', 'outreach' ) );
//* Child theme (do not remove)
define( 'CHILD_THEME_NAME', __( 'Outreach Pro Theme', 'outreach' ) );
define( 'CHILD_THEME_URL', 'http://my.studiopress.com/themes/outreach/' );
define( 'CHILD_THEME_VERSION', '3.0.1' );
//* Add HTML5 markup structure
add_theme_support( 'html5' );
//* Add viewport meta tag for mobile browsers
add_theme_support( 'genesis-responsive-viewport' );
//* Add featured images for posts and pages
add_theme_support( 'post-thumbnails', array( 'post', 'page', 'family_profiles', 'clinical_news', 'product' ) );
add_filter('widget_text', 'do_shortcode');
//* Enqueue Google fonts
add_action( 'wp_enqueue_scripts', 'outreach_google_fonts' );
function outreach_google_fonts() {
wp_enqueue_style( 'google-fonts', '//fonts.googleapis.com/css?family=Lato:400,700', array(), CHILD_THEME_VERSION );
wp_enqueue_style( 'google-fonts', '//fonts.googleapis.com/css?family=Oswald:400,700', array(), CHILD_THEME_VERSION );
}
//* Enqueue Responsive Menu Script
add_action( 'wp_enqueue_scripts', 'outreach_enqueue_responsive_script' );
function outreach_enqueue_responsive_script() {
wp_enqueue_script( 'outreach-responsive-menu', get_bloginfo( 'stylesheet_directory' ) . '/js/responsive-menu.js', array( 'jquery' ), '1.0.0' );
}
remove_filter ('acf_the_content', 'wpautop');
/**
* The use of this snippet requires at least WooCommerce 2.2
*/
/**
* Alter the column headers for the orders CSV to split item_meta into separate columns
*
* Note that this change is only applied to the Default - One Row per Item format
*
* @param array $column_headers {
* column headers in key => name format
* to modify the column headers, ensure the keys match these and set your own values
* }
* @param WC_Customer_Order_CSV_Export_Generator $csv_generator, generator instance
* @return array column headers in column_key => column_name format
*/
function sv_wc_csv_export_order_headers_split_item_meta( $column_headers, $csv_generator ) {
if ( 'default_one_row_per_item' === $csv_generator->order_format ) {
// remove item_meta column
unset( $column_headers['item_meta'] );
// get all item meta
$all_item_meta = sv_wc_get_item_meta_for_orders( $csv_generator->ids );
$item_meta_headers = array();
foreach ( $all_item_meta as $meta_key ) {
$item_meta_headers[ $meta_key ] = $meta_key;
}
$column_headers = sv_wc_array_insert_after( $column_headers, 'item_total', $item_meta_headers );
}
return $column_headers;
}
add_filter( 'wc_customer_order_csv_export_order_headers', 'sv_wc_csv_export_order_headers_split_item_meta', 10, 2 );
/**
* CSV Order Export Line Item.
*
* Filter the individual line item entry to add the raw item for use in sv_wc_csv_export_order_row_one_row_per_item_split_item_meta()
*
* @param array $line_item {
* line item data in key => value format
* the keys are for convenience and not used for exporting. Make
* sure to prefix the values with the desired line item entry name
* }
*
* @param array $item WC order item data
* @return array $line_item
*/
function sv_wc_csv_export_order_line_item_add_raw_item( $line_item, $item, $product, $order, $csv_generator ) {
if ( 'default_one_row_per_item' === $csv_generator->order_format ) {
$line_item = array_merge( $line_item, array( 'raw_item' => $item ) );
}
return $line_item;
}
add_filter( 'wc_customer_order_csv_export_order_line_item', 'sv_wc_csv_export_order_line_item_add_raw_item', 10, 5 );
/**
* CSV Order Export Row for One Row per Item.
*
* Filter the individual row data for the order export to add data for each item meta key
*
* @param array $order_data {
* order data in key => value format
* to modify the row data, ensure the key matches any of the header keys and set your own value
* }
* @param array $item
* @param \WC_Order $order WC Order object
* @param \WC_Customer_Order_CSV_Export_Generator $csv_generator, generator instance
*/
function sv_wc_csv_export_order_row_one_row_per_item_split_item_meta( $order_data, $item, $order, $csv_generator ) {
$item_meta = new WC_Order_Item_Meta( $item['raw_item']['item_meta'] );
foreach ( $item_meta->get_formatted() as $meta_key => $values ) {
$order_data[ $meta_key ] = $values['value'];
}
return $order_data;
}
add_filter( 'wc_customer_order_csv_export_order_row_one_row_per_item', 'sv_wc_csv_export_order_row_one_row_per_item_split_item_meta', 10, 4 );
/** Helper Functions **********************************************************/
/**
* Get item meta for orders
*
* @param array $order_ids array of order ids
* @return array $all_item_meta array of all item meta keys for $order_ids
*/
function sv_wc_get_item_meta_for_orders( $order_ids ) {
$all_item_meta = array();
foreach ( $order_ids as $order_id ) {
$order = wc_get_order( $order_id );
// get line items
foreach ( $order->get_items() as $item ) {
$item_meta = new WC_Order_Item_Meta( $item['item_meta'] );
$all_item_meta = array_merge( $all_item_meta, array_keys( $item_meta->get_formatted() ) );
}
}
return $all_item_meta;
}
/**
* Insert the given element after the given key in the array
*
* @param array $array array to insert the given element into
* @param string $insert_key key to insert given element after
* @param array $element element to insert into array
* @return array
*/
function sv_wc_array_insert_after( Array $array, $insert_key, Array $element ) {
$new_array = array();
foreach ( $array as $key => $value ) {
$new_array[ $key ] = $value;
if ( $insert_key == $key ) {
foreach ( $element as $k => $v ) {
$new_array[ $k ] = $v;
}
}
}
return $new_array;
}
//* Enqueue Backstretch on homepage
// add_action( 'wp_enqueue_scripts', 'enqueue_backstretch' );
// function enqueue_backstretch() {
//if ( is_home() || is_front_page() ) {
// wp_enqueue_script( 'backstretch', get_stylesheet_directory_uri() . '/js/jquery.backstretch.min.js', array( // 'jquery' ), '', true );
// wp_enqueue_script( 'backstretch-init', get_stylesheet_directory_uri() . '/js/backstretch-init.js', array( // 'backstretch' ), '1.0.0', true );
// }
// }
//* Add new image sizes
add_image_size( 'home-mini', 100, 100, TRUE );
add_image_size( 'home-top', 250, 250, TRUE );
add_image_size( 'home-bottom', 355, 200, TRUE );
add_image_size( 'sidebar', 330, 150, TRUE );
add_image_size( 'staff-thumbnail', 140, 140, true );
add_image_size( 'related_thumbnail', 185, 185, true );
add_image_size( 'home-features', 285, 180, true );
/** Define a default post thumbnail */
add_filter('genesis_get_image', 'default_image_fallback', 10, 2);
function default_image_fallback($output, $args) {
global $post;
if( $output || $args['size'] == 'full' )
return $output;
$thumbnail = CHILD_URL.'/images/thumb.png';
switch($args['format']) {
case 'html' :
return '<img src="'.$thumbnail.'" class="attachment-'. $args['size'] .'" alt="'. get_the_title($post->ID) .'" />';
break;
case 'url' :
return $thumbnail;
break;
default :
return $output;
break;
}
}
//* Add support for custom header
add_theme_support( 'custom-header', array(
'header-selector' => '.site-title a',
'header-text' => false,
'height' => 160,
'width' => 160,
) );
//* Add support for custom background
add_theme_support( 'custom-background' );
//* Add support for additional color style options
add_theme_support( 'genesis-style-selector', array(
'outreach-pro-blue' => __( 'Outreach Pro Blue', 'outreach' ),
'outreach-pro-orange' => __( 'Outreach Pro Orange', 'outreach' ),
'outreach-pro-purple' => __( 'Outreach Pro Purple', 'outreach' ),
'outreach-pro-red' => __( 'Outreach Pro Red', 'outreach' ),
) );
//* Add support for structural wraps
add_theme_support( 'genesis-structural-wraps', array(
'header',
'home-top',
'horizontal-opt-in',
'home-special',
'home-middle',
'nav',
'subnav',
'site-inner',
'footer-widgets',
'footer',
) );
//* Add WooCommerce support
add_theme_support( 'genesis-connect-woocommerce' );
// Display 24 products per page. Goes in functions.php
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 24;' ), 20 );
//* Add support for 4-column footer widgets
add_theme_support( 'genesis-footer-widgets', 5 );
//* Remove the site footer
remove_action( 'genesis_footer', 'genesis_footer_markup_open', 5 );
remove_action( 'genesis_footer', 'genesis_do_footer' );
remove_action( 'genesis_footer', 'genesis_footer_markup_close', 15 );
//* Customize the site footer
add_action( 'genesis_footer', 'bg_custom_footer' );
function bg_custom_footer() { ?>
<div class="site-footer"><div class="wrap"><p>Batten Disease Support and Research Association | 1175 Dublin Road, Columbus, OH 43215 | (800) 448-4570
</p><p><a href="/privacy-policy/">Privacy Policy</a></p></div></div>
<?php
}
//* Display Horizontal Opt-in widget area after header + navigation on homepage
add_action( 'genesis_after_header', 'sk_horizontal_optin' );
function sk_horizontal_optin() {
if ( is_home() || is_front_page() ) {
genesis_widget_area( 'horizontal-opt-in', array(
'before' => '<div class="horizontal-opt-in widget-area"><div class="wrap">',
'after' => '</div></div>',
) );
}
}
//* Customize the entry meta in the entry header (requires HTML5 theme support)
add_filter( 'genesis_post_info', 'sp_post_info_filter' );
function sp_post_info_filter($post_info) {
$post_info = '[post_date] [post_comments] [post_edit]';
return $post_info;
}
//* Hook after post widget after the entry content
add_action( 'genesis_after_entry', 'outreach_after_entry', 5 );
function outreach_after_entry() {
if ( is_singular( 'post' ) )
genesis_widget_area( 'after-entry', array(
'before' => '<div class="after-entry widget-area"><div class="wrap">',
'after' => '</div></div>',
) );
}
//* Hook widget before content and sidebar area, below header
add_action( 'genesis_before_content_sidebar_wrap', 'outreach_leaderboard', 5 );
function outreach_leaderboard() {
if ( !is_home() || !is_front_page() ) {
genesis_widget_area( 'leaderboard', array(
'before' => '<div class="leaderboard widget-area"><div class="wrap">',
'after' => '</div></div>',
) );
}
}
//* Hook after post widget after the entry related content
add_action( 'genesis_after_entry', 'outreach_after_entry_related', 5 );
function outreach_after_entry_related() {
if ( is_singular( '' ) )
genesis_widget_area( 'after-entry-related', array(
'before' => '<div class="after-entry-related widget-area"><div class="wrap">',
'after' => '</div></div>',
) );
}
//* Modify the size of the Gravatar in the author box
add_filter( 'genesis_author_box_gravatar_size', 'outreach_author_box_gravatar_size' );
function outreach_author_box_gravatar_size( $size ) {
return '80';
}
//* Remove comment form allowed tags
add_filter( 'comment_form_defaults', 'outreach_remove_comment_form_allowed_tags' );
function outreach_remove_comment_form_allowed_tags( $defaults ) {
$defaults['comment_notes_after'] = '';
return $defaults;
}
//* Add the sub footer section
add_action( 'genesis_before_footer', 'outreach_sub_footer', 5 );
function outreach_sub_footer() {
if ( is_active_sidebar( 'sub-footer-left' ) || is_active_sidebar( 'sub-footer-right' ) ) {
echo '<div class="sub-footer"><div class="wrap">';
genesis_widget_area( 'sub-footer-left', array(
'before' => '<div class="sub-footer-left">',
'after' => '</div>',
) );
echo '</div><!-- end .wrap --></div><!-- end .sub-footer -->';
}
}
//* Add the after footer section
add_action( 'genesis_footer', 'outreach_after_footer', 3 );
function outreach_after_footer() {
if ( is_active_sidebar( 'after-footer' ) ) {
echo '<div class="after-footer"><div class="wrap">';
genesis_widget_area( 'after-footer', array(
'before' => '<div class="after-footer">',
'after' => '</div>',
) );
echo '</div><!-- end .wrap --></div><!-- end .after-footer -->';
}
}
/**
* Merge Tags as Dynamic Population Parameters for Gravity Forms Donation Start
* http://gravitywiz.com/dynamic-products-via-post-meta/
*/
add_filter('gform_pre_render', 'gw_prepopluate_merge_tags');
function gw_prepopluate_merge_tags($form) {
$filter_names = array();
foreach($form['fields'] as &$field) {
if(!rgar($field, 'allowsPrepopulate'))
continue;
// complex fields store inputName in the "name" property of the inputs array
if(is_array(rgar($field, 'inputs')) && $field['type'] != 'checkbox') {
foreach($field['inputs'] as $input) {
if(rgar($input, 'name'))
$filter_names[] = array('type' => $field['type'], 'name' => rgar($input, 'name'));
}
} else {
$filter_names[] = array('type' => $field['type'], 'name' => rgar($field, 'inputName'));
}
}
foreach($filter_names as $filter_name) {
$filtered_name = GFCommon::replace_variables_prepopulate($filter_name['name']);
if($filter_name['name'] == $filtered_name)
continue;
add_filter("gform_field_value_{$filter_name['name']}", create_function("", "return '$filtered_name';"));
}
return $form;
}
add_action( 'genesis_entry_header', 'single_post_featured_image', 15 );
function single_post_featured_image() {
if ( ! is_singular( 'family_profiles' ) )
return;
$img = genesis_get_image( array( 'format' => 'html', 'size' => genesis_get_option( 'image_size' ), 'attr' => array( 'class' => 'post-image' ) ) );
printf( '<a href="%s" title="%s">%s</a>', get_permalink(), the_title_attribute( 'echo=0' ), $img );
}
add_action( 'genesis_before_header', 'utility_bar' );
/**
* Add utility bar above header.
*
* @author Carrie Dils
* @copyright Copyright (c) 2013, Carrie Dils
* @license GPL-2.0+
*/
function utility_bar() {
echo '<div class="utility-bar"><div class="wrap">';
genesis_widget_area( 'utility-bar-left', array(
'before' => '<div class="utility-bar-left">',
'after' => '</div>',
) );
genesis_widget_area( 'utility-bar-right', array(
'before' => '<div class="utility-bar-right">',
'after' => '</div>',
) );
echo '</div></div>';
}
/** Register Utility Bar Widget Areas. */
genesis_register_sidebar( array(
'id' => 'utility-bar-left',
'name' => __( 'Utility Bar Left', 'theme-prefix' ),
'description' => __( 'This is the left utility bar above the header.', 'theme-prefix' ),
) );
genesis_register_sidebar( array(
'id' => 'utility-bar-right',
'name' => __( 'Utility Bar Right', 'theme-prefix' ),
'description' => __( 'This is the right utility bar above the header.', 'theme-prefix' ),
) );
/** Register Widget Areas. */
genesis_register_sidebar( array(
'id' => 'horizontal-opt-in',
'name' => __( 'Home', 'outreach' ),
'description' => __( 'This is the first section of the Home page.', 'outreach' ),
) );
genesis_register_sidebar( array(
'id' => 'home-top',
'name' => __( 'Home - Top', 'outreach' ),
'description' => __( 'This is the second section of the Home page, displaying the email newsletter.', 'outreach' ),
) );
genesis_register_sidebar( array(
'id' => 'home-special',
'name' => __( 'Home - Special', 'outreach' ),
'description' => __( 'This is the third section of the Home Page, a full width area for special content.', 'outreach' ),
) );
genesis_register_sidebar( array(
'id' => 'home-middle',
'name' => __( 'Home - Middle', 'outreach' ),
'description' => __( 'This is the fourth section of the Home page, displaying the video and .', 'outreach' ),
) );
genesis_register_sidebar( array(
'id' => 'home-bottom',
'name' => __( 'Home - Bottom', 'outreach' ),
'description' => __( 'This is the bottom section of the Home page.', 'outreach' ),
) );
genesis_register_sidebar( array(
'id' => 'after-entry',
'name' => __( 'After Entry', 'outreach' ),
'description' => __( 'This is the after entry widget area.', 'outreach' ),
) );
genesis_register_sidebar( array(
'id' => 'after-entry-related',
'name' => __( 'After Entry Related', 'outreach' ),
'description' => __( 'This is the related after entry widget area.', 'outreach' ),
) );
genesis_register_sidebar( array(
'id' => 'leaderboard',
'name' => __( 'Leaderboard', 'outreach' ),
'description' => __( 'This is the section below the header but above the content.', 'outreach' ),
) );
genesis_register_sidebar( array(
'id' => 'sub-footer-left',
'name' => __( 'Sub Footer', 'outreach' ),
'description' => __( 'This is the sub footer used for the donation start.', 'outreach' ),
) );
genesis_register_sidebar( array(
'id' => 'after-footer',
'name' => __( 'After Footer', 'outreach' ),
'description' => __( 'This is the after footer used for the logos.', 'outreach' ),
) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment