Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
<?php
/* ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
HUSKYPRESS
July 2013
by UITS Web Lab andrew.bacon@uconn.edu
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ */
// register the menus
function register_my_menus() {
register_nav_menu( 'primary', __( 'Primary Menu', 'hale' ) );
}
add_action( 'init', 'register_my_menus' );
add_theme_support( 'post-thumbnails' );
// If no Menu is created, displays a home link, and starts listing pages across the top.
function huskypress_page_menu_args( $args ) {
if ( ! isset( $args['show_home'] ) )
$args['show_home'] = true;
$args['show_home'] = true;
return $args;
}
add_filter( 'wp_page_menu_args', 'huskypress_page_menu_args' );
if(!function_exists('is_parent_private')){
function is_parent_private($id){
$page = get_post($id);
if($page->post_parent > 0){
$parent = get_post($page->post_parent);
$private = get_post_meta($parent->ID, 'uc-private', true);
if($private == 'admins' || $private == 'users' || $private == 'list'){
return $parent->ID;
}
else return is_parent_private($parent->ID);
}
else{
return false;
}
}
}
/*
Disabled until theme supports these types... (AB June 26, 2013)
add_theme_support( 'post-formats', array( 'aside', 'image', 'link', 'quote', 'status' ) );
*/
if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name' => 'Sidebar',
'id' => 'sidebar',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Home1',
'id' => 'home1',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Home2',
'id' => 'home2',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Home3',
'id' => 'home3',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Home4',
'id' => 'home4',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Home5',
'id' => 'home5',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Home6',
'id' => 'home6',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => 'Home7',
'id' => 'home7',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
register_sidebar(array(
'name' => __( 'Mega Footer', 'theme_text_domain' ),
'id' => 'mega-footer',
'description' => 'Limited to 6 widgets. Will appear at the bottom of every page in the site.',
'before_widget' => '<aside class=""><div id="%1$s" class="%2$s widget">',
'after_widget' => ' </div></aside>',
'before_title' => '<div class="widget-head"><h2 class="widget-title">',
'after_title' => '</h2></div>',
'pages' => array(),
'children' => 'off',
'force' => true
));
}
function remove_some_widgets(){
for( $i=8; $i<61; $i++ ){
unregister_sidebar( 'home'.$i );
}
}
add_action( 'widgets_init', 'remove_some_widgets', 11 );
// if no title then add widget content wrapper to before widget
function check_sidebar_params( $params ) {
global $wp_registered_widgets;
$settings_getter = $wp_registered_widgets[ $params[0]['widget_id'] ]['callback'][0];
$settings = $settings_getter->get_settings();
$settings = $settings[ $params[1]['number'] ];
if ( $params[0][ 'after_widget' ] == '</div></aside>' && isset( $settings[ 'title' ] ) && empty( $settings[ 'title' ] ) ){
$params[0][ 'before_widget' ] .= '<div class="widget-content ccc">';
}
#Counts widgets in mega footer and adds column class accordingly
if( $params[0]['id'] == 'mega-footer' ){
$sidebars = get_option('sidebars_widgets');
$widgets = $sidebars['mega-footer'];
$count = count($widgets);
if( $count > 6 ){
$cols = 2;
} else {
$cols = floor(12 / $count);
}
$params[0]['before_widget'] = str_replace('aside class="', 'aside class="col-sm-' . $cols . ' span'.$cols , $params[0]['before_widget']);
}
return $params;
}
add_filter( 'dynamic_sidebar_params', 'check_sidebar_params' );
function mf_remove_extra( $sidebars_widgets ){
$widgets = $sidebars_widgets['mega-footer'];
if( is_array($sidebars_widgets['mega-footer']) ){
foreach ($sidebars_widgets['mega-footer'] as $i => $widget) {
if( $i > 5 ){
unset($sidebars_widgets['mega-footer'][$i]);
}
}
}
return $sidebars_widgets;
}
add_filter( 'sidebars_widgets', 'mf_remove_extra' );
// If no Menu is created, displays a home link, and starts listing pages across the top.
function hale_page_menu_args( $args ) {
if ( ! isset( $args['show_home'] ) )
$args['show_home'] = true;
$args['show_home'] = true;
return $args;
}
add_filter( 'wp_page_menu_args', 'hale_page_menu_args' );
function hale_enqueue_scripts() {
wp_enqueue_script('bootstrap-min', network_home_url().'wp-content/global/bootstrap-2.3.1/js/bootstrap.min.js', array('jquery'));
wp_enqueue_script('uc-hale-custom', get_bloginfo('template_url').'/js/custom.js', array('jquery'));
$outboundtracking = get_option( 'outbound_tracking','');
if($outboundtracking == 'yes') wp_enqueue_script('uc-link-tracking', get_bloginfo('template_url').'/js/linktracking.js', array('jquery'));
wp_enqueue_style('bootstrap-base', network_home_url().'wp-content/global/bootstrap-2.3.1/css/bootstrap.min.css');
wp_enqueue_style('bootstrap-responsive', network_home_url().'wp-content/global/bootstrap-2.3.1/css/bootstrap-responsive.min.css', 'bootstrap-base');
wp_enqueue_style('hale-style', get_bloginfo('stylesheet_url'), 'bootstrap-responsive');
wp_enqueue_style('hale-print', get_bloginfo('template_url').'/uc-print.css', 'hale-main', '1', 'print' );
wp_register_style( 'hale-red', get_stylesheet_directory_uri() .'/red.css', 'hale-style');
wp_register_style( 'hale-green', get_stylesheet_directory_uri() .'/green.css', 'hale-style');
wp_register_style( 'hale-orange', get_stylesheet_directory_uri() .'/orange.css', 'hale-style');
wp_register_style( 'hale-purple', get_stylesheet_directory_uri() .'/purple.css', 'hale-style');
$themeColor = get_theme_mod( 'themeColor','blue');
if($themeColor == 'red') {
wp_enqueue_style('hale-red');
} else if($themeColor == 'green') {
wp_enqueue_style('hale-green');
} else if($themeColor == 'orange') {
wp_enqueue_style('hale-orange');
} else if($themeColor == 'purple') {
wp_enqueue_style('hale-purple');
};
}
add_action('wp_enqueue_scripts', 'hale_enqueue_scripts');
function huskypress_customize_register( $wp_customize )
{
//1. Define a new section (if desired) to the Theme Customizer
$wp_customize->add_section( 'huskypress_options',
array(
'title' => __( 'Template Options', 'mytheme' ), //Visible title of section
'priority' => 35, //Determines what order this appears in
'capability' => 'edit_theme_options', //Capability needed to tweak
'description' => __('Allows you to customize header color and school, college, or division settings for Hale', 'huskypress'), //Descriptive tooltip
)
);
$wp_customize->add_setting( 'secondarytitle', //Give it a SERIALIZED name (so all theme settings can live under one db record)
array(
'type' => 'option', //Is this an 'option' or a 'theme_mod'?
'capability' => 'edit_theme_options', //Optional. Special permissions for accessing this setting.
'transport' => 'refresh', //What triggers a refresh of the setting? 'refresh' or 'postMessage' (instant)?
)
);
$wp_customize->add_control('secondarytitle', array(
'type' => 'text',
'label' => 'School, College, Division, Department, etc.',
'section' => 'huskypress_options'
)
);
$wp_customize->add_setting( 'secondarylink', //Give it a SERIALIZED name (so all theme settings can live under one db record)
array(
'type' => 'option', //Is this an 'option' or a 'theme_mod'?
'capability' => 'edit_theme_options', //Optional. Special permissions for accessing this setting.
'transport' => 'refresh', //What triggers a refresh of the setting? 'refresh' or 'postMessage' (instant)?
)
);
$wp_customize->add_control('secondarylink', array(
'type' => 'text',
'label' => 'Link To School, College, Division, Department (Must be UConn.edu or UCHC.edu)',
'section' => 'huskypress_options'
)
);
$wp_customize->add_setting( 'homepagelayout', //Give it a SERIALIZED name (so all theme settings can live under one db record)
array(
'default' => '3-3', //Default setting/value to save
'type' => 'theme_mod', //Is this an 'option' or a 'theme_mod'?
'capability' => 'edit_theme_options', //Optional. Special permissions for accessing this setting.
'transport' => 'refresh', //What triggers a refresh of the setting? 'refresh' or 'postMessage' (instant)?
)
);
// new stuff added
$wp_customize->add_setting( 'themeColor', //Give it a SERIALIZED name (so all theme settings can live under one db record)
array(
'default' => 'blue', //Default setting/value to save
'type' => 'theme_mod', //Is this an 'option' or a 'theme_mod'?
'capability' => 'edit_theme_options', //Optional. Special permissions for accessing this setting.
'transport' => 'refresh', //What triggers a refresh of the setting? 'refresh' or 'postMessage' (instant)?
)
);
$wp_customize->add_control('themeColor', array(
'type' => 'radio',
'label' => 'Theme Color',
'section' => 'huskypress_options',
'choices' => array(
'blue'=>'Dark Blue',
'red' => 'Red',
'orange' => 'Orange',
'green' => 'Green',
'purple'=>'Purple'
)
)
);
$wp_customize->add_control('homepagelayout', array(
'type' => 'radio',
'label' => 'Homepage Layout',
'section' => 'huskypress_options',
'choices' => array(
'2L'=>'Large left',
'2L_sub' => 'Large left, subdivided',
'2R'=>'Large right',
'2R_sub'=>'Large right, subdivided',
'3'=>'Three even',
'3W'=>'Three columns, wide center',
'3W_sub'=>'Three columns, wide center, subdivided',
'1-2'=>'Large top, two bottom',
'1-3'=>'Large top, three bottom',
'2L-3'=>'Large top left, three bottom',
'2R-3'=>'Large top right, three bottom',
'3-3'=>'Large center top, large center bottom',
'3-4'=>'Large center top, four bottom'
)
)
);
}
add_action( 'customize_register', 'huskypress_customize_register' );
function huskypress_navoption_register( $wp_customize )
{
$wp_customize->add_setting( 'navoption1', //Give it a SERIALIZED name (so all theme settings can live under one db record)
array(
'default' => 'textnav', //Default setting/value to save
'type' => 'theme_mod', //Is this an 'option' or a 'theme_mod'?
'capability' => 'edit_theme_options', //Optional. Special permissions for accessing this setting.
'transport' => 'refresh', //What triggers a refresh of the setting? 'refresh' or 'postMessage' (instant)?
)
);
$wp_customize->add_control('navoption1', array(
'type' => 'select',
'label' => 'Navigation Option 1',
'section' => 'nav',
'choices' => array(
'textnav'=>'Text',
'bar' => 'Bar',
'stack-top'=>'Tabs'
)
)
);
$wp_customize->add_setting( 'navoption2', //Give it a SERIALIZED name (so all theme settings can live under one db record)
array(
'default' => 'with-drop', //Default setting/value to save
'type' => 'theme_mod', //Is this an 'option' or a 'theme_mod'?
'capability' => 'edit_theme_options', //Optional. Special permissions for accessing this setting.
'transport' => 'refresh', //What triggers a refresh of the setting? 'refresh' or 'postMessage' (instant)?
)
);
$wp_customize->add_control('navoption2', array(
'type' => 'select',
'label' => 'Navigation Option 2',
'section' => 'nav',
'choices' => array(
'with-drop'=>'Dropdowns',
'with-left' => 'Left Nav'
)
)
);
}
add_action( 'customize_register', 'huskypress_navoption_register' );
/*the fallback from wp_nav_menu, we want to replicate the output of wp_page_menu to be similar to wp_nav_menu
@param args, it comes from the wp_nav_menu arguments*/
function hale_main_nav_fallback($args) {
$args['echo'] = 0; // don't echo the output yet.
$nav_menu = wp_page_menu($args);
if(!empty($nav_menu)){
$doc = new DOMDocument();
@$doc->loadHTML($nav_menu);//surpress the warnings
$data = $doc->getElementsByTagName('li');
//the default behaviour of wp_page_menu is that it wraps the list items with a ul and div
//menu_class is for div in wp_page_menu, but is for the ul in wp_nav_menu
//create the container, if any
//container class and id come from wp_nav_menu arguments. Which is not used in wp_page_menu.
if($args['container'] != false) {
$attributes = (!empty($args['container_class'])?' class="'.$args['container_class'].'"':'');
$attributes .= (!empty($args['container_id'])?' id="'.$args['container_id'].'"':'');
if($args['container'] == 'nav') {
echo '<nav'.$attributes.'>';
} else {
echo '<div'.$attributes.'>';
}
}
$attributes = (!empty($args['menu_class'])?' class="'.$args['menu_class'].'"':'');
$attributes .= (!empty($args['menu_id'])?' id="'.$args['menu_id'].'"':'');
echo '<ul'.$attributes.'>';
if($data->length > 0) {
foreach($data as $item) {
echo $item->ownerDocument->saveXML($item);//saveHTML wouldn't accept it as paramater.
}
}
echo '</ul>';
//close the container, if any
if($args['container'] != false) {
if($args['container'] == 'nav') {
echo '</nav>';
} else {
echo '</div>';
}
}
}
return;
}
function search_menu_item($items, $args){
// Reference: http://www.wpbeginner.com/wp-themes/how-to-add-custom-items-to-specific-wordpress-menus/
if ($args->theme_location == 'primary') {
$items = '
<li id="sitesearch">
<form id="searchForm" method="get" action="'.get_bloginfo('wpurl').'/search-results/">
<div class="input-append">
<input name="search" type="text" id="sitesearch-input" placeholder="Search this Site..."><button class="btn" type="button" value="Go" id="sbutton"><i class="icon-search"></i></button>
<input type="hidden" id="stype" name="stype" value="site">
</div>
</form>
</li>
' . $items;
}
return $items;
}
/*Nav Menu Walker*/
if(!class_exists('Bootstrap_Nav_Walker')) {
class Bootstrap_Nav_Walker extends Walker_Nav_Menu {
/*This was taken from 320press WP-Bootstrap theme. No licensing restriction given, and it said it was free. */
/* Skip private pages
*/
function skip( $item ) {
$parent = is_parent_private($item->ID);
if($parent !== false) $page = $parent;
else $page = $item->ID;
$private = get_post_meta($page, 'uc-private', true);
if($private == 'admins' || $private == 'users' || $private == 'list'){
return true;
}
else{
return false;
}
}
/* Start of the <ul>
*
* Note on $depth: Counterintuitively, $depth here means the "depth right before we start this menu".
* So basically add one to what you'd expect it to be
*/
function start_lvl(&$output, $depth, $args)
{
if(isset($args->with_search) && $args->with_search == true){
add_filter('wp_nav_menu_items', 'search_menu_item', 1, 2);
}
$tabs = str_repeat("\t", $depth);
// If we are about to start the first submenu, we need to give it a dropdown-menu class
if ($depth >= 0) { //really, level-1 or level-2, because $depth is misleading here (see note above)
$output .= "\n{$tabs}<ul class=\"dropdown-menu\">\n";
} else {
$output .= "\n{$tabs}<ul>\n";
}
return;
}
/* End of the <ul>
*
* Note on $depth: Counterintuitively, $depth here means the "depth right before we start this menu".
* So basically add one to what you'd expect it to be
*/
function end_lvl(&$output, $depth)
{
if ($depth == 0) { // This is actually the end of the level-1 submenu ($depth is misleading here too!)
// we don't have anything special for Bootstrap, so we'll just leave an HTML comment for now
$output .= '<!--.dropdown-->';
}
$tabs = str_repeat("\t", $depth);
$output .= "\n{$tabs}</ul>\n";
return;
}
/* Output the <li> and the containing <a>
* Note: $depth is "correct" at this level
*/
function start_el(&$output, $item, $depth, $args)
{
global $wp_query;
if ( $this->skip( $item ) ) return;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
/* If this item has a dropdown menu, add the 'dropdown' class for Bootstrap */
if($item->post_type == 'page') { //page has no classes..
$classes[] = 'menu-item';
}
if ($item->hasChildren) {
$classes[] = 'dropdown';
// level-1 menus also need the 'dropdown-submenu' class
if($depth > 0 ) {
$classes[] = 'dropdown-submenu';
}
}
/* This is the stock Wordpress code that builds the <li> with all of its attributes */
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
$class_names = ' class="' . esc_attr( $class_names ) . '"';
$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
if($item->post_type == 'page') {
$attributes .= ! empty( $item->guid ) ? ' href="' . esc_attr( $item->guid ) .'"' : '';
} else {
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
}
$item_output = "";
if($item->post_type == 'page') {
if ($item->hasChildren && $depth == 0) {
$item_output .= '<a'. $attributes .' class="dropdown-toggle" data-toggle="dropdown">';
} else {
$item_output .= '<a'. $attributes .'>';
}
$item_output .= apply_filters('the_title', $item->post_title, $item->ID);
if ($item->hasChildren && $depth == 0) {
$item_output .= '<b class="caret"></b></a>';
} else {
$item_output .= '</a>';
}
} else {
$item_output = $args->before;
/* If this item has a dropdown menu, make clicking on this link toggle it */
if ($item->hasChildren && $depth == 0) {
$item_output .= '<a'. $attributes .' class="dropdown-toggle" data-toggle="dropdown">';
} else {
$item_output .= '<a'. $attributes .'>';
}
//var_dump($item);
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
/* Output the actual caret for the user to click on to toggle the menu */
if ($item->hasChildren && $depth == 0) {
$item_output .= '<b class="caret"></b></a>';
} else {
$item_output .= '</a>';
}
$item_output .= $args->after;
}
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
return;
}
/* Close the <li>
* Note: the <a> is already closed
* Note 2: $depth is "correct" at this level
*/
function end_el (&$output, $item, $depth, $args)
{
if ( $this->skip( $item ) ) return;
$output .= '</li>';
return;
}
/* Add a 'hasChildren' property to the item
* Code from: http://wordpress.org/support/topic/how-do-i-know-if-a-menu-item-has-children-or-is-a-leaf#post-3139633
*/
function display_element ($element, &$children_elements, $max_depth, $depth = 0, $args, &$output)
{
/* if($element->post_type == 'page' && !isset($children_elements[$element->ID])) {
$children = get_children(array('post_parent' => $element->ID, 'numberposts' => -1, 'post_type' => 'page'));
$children_elements[$element->ID] = $children;
}*/
// check whether this item has children, and set $item->hasChildren accordingly
$element->hasChildren = isset($children_elements[$element->ID]) && !empty($children_elements[$element->ID]);
//var_dump($children_elements);
// var_dump($element);
/*if($element->hasChildren) {
$element2 = $children_elements[$element->ID];
$child2 = $children_elements[$element2->ID];
$element2->hasChildren = isset($child2[$element2->ID]) && !empty($child2[$element2->ID]);
}*/
// continue with normal behavior
return parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
}
}
}
//Bootstrap whitelist
function add_allowed_tags($tags) {
$newtags = array(
'div',
'ul',
'li',
'button',
'a');
$newattrs = array(
'data-toggle' => true,
'data-dismiss' => true,
'data-target' => true,
'data-spy' => true,
'data-loading-text' => true,
'data-parent' => true,
'data-slide' => true,
'data-slide-to' => true,
'data-provide' => true,
'data-interval' => true,
'data-pause' => true,
'data-animation' => true,
'data-html' => true,
'data-placement' => true,
'data-selector' => true,
'data-title' => true,
'data-trigger' => true,
'data-delay' => true,
'data-container' => true);
foreach($newtags as $newtag){
if( isset($tags[$newtag]) && is_array($tags[$newtag])){
$tags[$newtag] = array_merge($tags[$newtag], $newattrs);
}
else{
$tags[$newtag] = $newattrs;
}
}
return $tags;
}
add_filter('wp_kses_allowed_html', 'add_allowed_tags');
function uc_options_add_page() {
add_theme_page( 'Manage Sidebars', 'Manage Sidebars', 'edit_theme_options', 'uc_sidebars', 'uc_sidebars_do_page' );
//remove_submenu_page( 'themes.php', 'widgets.php' );
}
add_action( 'admin_menu', 'uc_options_add_page' );
/**
* Class for adding a link tracking to the options-general.php page
*/
class Add_Settings_Field {
/**
* Class constructor
*/
public function __construct() {
add_filter( 'admin_init' , array( &$this , 'register_fields' ) );
}
/**
* Add new fields to wp-admin/options-general.php page
*/
public function register_fields() {
register_setting( 'general', 'outbound_tracking', 'esc_attr' );
add_settings_field(
'fav_color',
'<label for="outbound_tracking">' . __( 'Track Outbound Links' , 'outbound_tracking' ) . '</label>',
array( &$this, 'fields_radio' ),
'general'
);
}
/**
* HTML for extra settings
*/
public function fields_radio() {
$value = get_option( 'outbound_tracking', '' );
echo '<input type="radio" id="outbound_tracking_no" name="outbound_tracking" value="no"'.(strlen(esc_attr( $value )) == 0 || esc_attr( $value ) == 'no'?' checked':'' ).' /> No <input type="radio" id="outbound_tracking_yes" name="outbound_tracking" value="yes"'.(esc_attr( $value ) == 'yes'?' checked':'' ).' /> Yes ';
}
}
new Add_Settings_Field();
function hale_setup() {
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
}
add_action( 'after_setup_theme', 'hale_setup' );
?>