Skip to content
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
/*
Plugin Name: Grad School 2016
Description: Grandchild Plugin for Grad School
Author: Web Dev & Chris Cerrigione
Author URI: http://www.webdev.uconn.edu
Version: 1.0
*/
require_once( plugin_dir_path( __FILE__ ) . 'template-class.php' );
add_action( 'plugins_loaded', array( 'Page_Template_Plugin_grad2016', 'get_instance' ) );
// Adds our new file with styles
function grandchild_add_scripts_styles_grad2016() {
wp_register_script( 'grandchild-script', plugins_url( 'grandchild-scripts.js', __FILE__ ), array( 'jquery' ), '1.0' );
wp_enqueue_script( 'grandchild-script' );
wp_register_style( 'grandchild-style', plugins_url( 'grandchild-styles.css', __FILE__ ), array(), '1.0' );
wp_enqueue_style( 'grandchild-style' );
}
add_action( 'wp_enqueue_scripts', 'grandchild_add_scripts_styles_grad2016', 99999999 );
// Search for templates in plugin 'templates' dir, and load if exists
function grandchild_template_include_grad2016( $template ) {
if ( file_exists( untrailingslashit( plugin_dir_path( __FILE__ ) ) . '/templates/' . basename( $template ) ) )
$template = untrailingslashit( plugin_dir_path( __FILE__ ) ) . '/templates/' . basename( $template );
$post_types = array('courses');
if (is_singular($post_types)) {
$template = plugin_dir_path( __FILE__ ).'templates/single-courses.php';
}
elseif(is_tax('subjects')) {
$template = plugin_dir_path( __FILE__ ).'templates/taxonomy-subjects.php';
}
return $template;
}
add_filter( 'template_include', 'grandchild_template_include_grad2016', 11 );
function gradschool_breadcrumbs(){
$thisID = get_the_ID();
$ancestors = get_ancestors($thisID, 'page');
$ancestors = array_reverse($ancestors);
if ($ancestors) {
echo '<ol class="breadcrumb">';
if (wp_get_nav_menu_object('precrumbs')){
$defaults = array(
'menu' => 'Precrumbs',
'container' => false,
'items_wrap' => '%3$s',
'depth' => 1,
'fallback_cb' => false
);
wp_nav_menu( $defaults );
}
foreach ($ancestors as &$ancestor) {
$ancestor_link = get_permalink($ancestor);
$ancestor_title = get_the_title($ancestor);
echo '<li><a href="'.$ancestor_link.'">'.$ancestor_title.'</a></li>';
}
echo '<li class="active">'.get_the_title().'</li>';
echo '</ol>';
}
}
function filter_search($query) {
if ($query->is_search) {
// Get post types
$post_types = get_post_types(array('public' => true, 'exclude_from_search' => false), 'objects');
$searchable_types = array();
// Add available post types
if( $post_types ) {
foreach( $post_types as $type) {
$searchable_types[] = $type->name;
}
}
$query->set( 'post_type', $searchable_types );
};
return $query;
};
add_filter('pre_get_posts', 'filter_search');
function string_limit_words($string, $word_limit)
{
$words = explode(' ', $string, ($word_limit + 1));
if(count($words) > $word_limit)
array_pop($words);
return implode(' ', $words);
}
// ---------------- Custom Header ----------------
// We are hooking to the 'load_custom_header' filter
// and return a value of 'true' meaning that we want to
// load a custom header
add_filter( 'load_custom_header', '__return_true', 99 );
add_filter( 'get_custom_header', function( $header ) {
return plugin_dir_path( __FILE__ ).'templates/header.php';
}, 99 );
// ---------------- Register a new sidebar- creates widget in header for tagline -----------------
if ( function_exists('register_sidebar') ) {
register_sidebar( array(
'name' => __( 'Header - Tagline' ),
'id' => 'header-tagline',
'description' => __( 'Widgets in this area will be shown on the header.' ),
'before_title' => '<h1>',
'after_title' => '</h1>',
) );
}
if ( function_exists('register_sidebar') ) {
register_sidebar( array(
'name' => __( 'Footer - 1' ),
'id' => 'footer-1',
'description' => __( 'Widgets in this area will be shown on the left hand side of the footer.' ),
'before_title' => '<h2>',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => __( 'Footer - 2' ),
'id' => 'footer-2',
'description' => __( 'Widgets in this area will be shown on the right hand side of the footer.' ),
'before_title' => '<h2>',
'after_title' => '</h2>',
) );
register_sidebar( array(
'name' => __( 'Footer - 3' ),
'id' => 'footer-3',
'description' => __( 'Widgets in this area will be shown on the right hand side of the footer.' ),
'before_title' => '<h2>',
'after_title' => '</h2>',
) );
}
//---------------- Add templates to post loop drop down -----------------
/* function grandchild_postloop_template_include( $templates ) {
$templates[] = '../../plugins/grandchild-global-citizenship/templates/content-small-grid.php';
$templates[] = '../../plugins/grandchild-global-citizenship/templates/content-large-featured-story.php';
$templates[] = '../../plugins/grandchild-global-citizenship/templates/content-category-landing-grid.php';
return $templates;
}
add_filter( 'siteorigin_panels_postloop_templates', 'grandchild_postloop_template_include', 11 ); */
// ---------------- Custom Footer ----------------
add_filter( 'load_custom_footer', '__return_true', 99 );
add_filter( 'get_custom_footer', function( $footer ) {
return plugin_dir_path( __FILE__ ).'templates/footer.php';
}, 99 );
/********************************************************************
Register Custom Course Post Type
********************************************************************/
function create_course_post_type() {
register_post_type( 'courses', array(
'labels' => array(
'name' => __('Courses'),
'singular_name' => __('Course'),
'menu_name' => __('Courses'),
'name_admin_bar' => __('Course'),
'add_new' => __('Add New'),
'add_new_item' => __('Add New Course'),
),
'description' => 'Post Template for a course.',
'public' => true,
'has_archive' => true,
'rewrite' => array( 'slug' => "graduate-courses/%subjects%", 'with_front' => false),
'capability_type' => 'post',
'hierarchical' => false,
'supports' => array( 'title', 'editor', 'revisions' ), // Also author, thumbnail, excerpt, trackbacks, custom-fields, comments, page-attributes, post-formats
'query_var' => true,
'taxonomies' => array('subjects'),
) );
flush_rewrite_rules();
};
add_action('init', 'create_course_post_type');
// Registers the Course Subjects / Concentrations
function course_taxonomies() {
register_taxonomy('subjects', 'courses', array(
'labels' => array(
'name' => __('Subjects'),
'singular_name' => __('Subject'),
'search_items' => __('Search Course Subjects'),
'all_items' => __('All Course Subjects'),
'parent_item' => __('Subject'),
'parent_item_colon' => __('Subject:'),
'edit_item' => __('Edit Subject'),
'update_item' => __('Update Subject'),
'add_new_item' => __('Add New Subject'),
'new_item_name' => __('New Subject'),
'menu_name' => __('Course Subjects')
),
'hierarchical' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'graduate-courses', 'with_front' => true),
) );
}
add_action('init', 'course_taxonomies', 0);
function custom_rewrite_flush() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
add_action('init', 'custom_rewrite_flush');
/********************************************************************
Register Course Rewrites
********************************************************************/
function course_permalink($post_link, $post, $leavename) {
if (false !== strpos($post_link, '%subjects%' )) {
$subj_terms = get_the_terms($post->ID, 'subjects');
// $catnum = get_post_meta( $post->ID, 'catalog_number', true);
$subject = array_pop($subj_terms)->slug;
$post_link = str_replace( "%subjects%", $subject, $post_link);
// $post_link = str_replace( "%catalog_number%", $catnum, $post_link);
}
return $post_link;
}
add_filter('post_type_link', 'course_permalink', 10, 4);
// THIS IS THE CODE FOR THE GRAD SCHOOL COURSE SECTION
/********************************************************************
Register Catalog Number Box
********************************************************************/
// Registers Catalog Number Box
function catalog_number_box() {
add_meta_box(
'catalog_number_box',
__('Catalog Number'),
'catalog_number_box_content',
'courses',
'side',
'default'
);
}
// Registers Catalog Number Box Content
function catalog_number_box_content($post) {
wp_nonce_field( plugin_basename( __FILE__ ), 'catalog_number_box_content_nonce');
$catalog_number_val = get_post_meta($post->ID, 'catalog_number', true);
echo '<label for="catalog_number"></label>';
echo '<input style="width:100%" type="text" id="catalog_number" name="catalog_number" maxlength="5" placeholder="Ex. 1102" value="' . esc_attr($catalog_number_val) . '" />';
}
add_action('add_meta_boxes', 'catalog_number_box');
// Action for Catalog Number on save
function catalog_number_box_save($post_id) {
global $post;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return;
if (!wp_verify_nonce($_POST['catalog_number_box_content_nonce'], plugin_basename( __FILE__ )))
return $post_id;
if ('page' == $_POST['post_type']) {
if (!current_user_can('edit_page', $post_id))
return;
} else {
if (!current_user_can('edit_post', $post_id))
return;
}
$catalog_number = sanitize_text_field($_POST['catalog_number']);
$catalog_number_match = intval($catalog_number);
if(!$catalog_number_match) {
update_post_meta($post_id, 'catalog_number', '');
} else {
update_post_meta($post_id, 'catalog_number', $catalog_number);
}
}
add_action('save_post', 'catalog_number_box_save', 10, 2);
/********************************************************************
Register Minimum Units
********************************************************************/
// Registers Min Unit Box
function min_unit_box() {
add_meta_box(
'min_unit_box',
__('Minimum Units'),
'min_unit_box_content',
'courses',
'side',
'default'
);
}
// Registers Min Unit Box Content
function min_unit_box_content($post) {
wp_nonce_field( plugin_basename( __FILE__ ), 'min_unit_box_content_nonce');
$min_unit_val = get_post_meta($post->ID, 'min_unit', true);
echo '<label for="min_unit"></label>';
echo '<input style="width:100%" type="text" id="min_unit" name="min_unit" maxlength="4" placeholder="Ex. 3.00" value="' . esc_attr($min_unit_val) . '" />';
}
add_action('add_meta_boxes', 'min_unit_box');
// Action for Min Unit on save
function min_unit_box_save($post_id) {
global $post;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return;
if (!wp_verify_nonce($_POST['min_unit_box_content_nonce'], plugin_basename( __FILE__ )))
return $post_id;
if ('page' == $_POST['post_type']) {
if (!current_user_can('edit_page', $post_id))
return;
} else {
if (!current_user_can('edit_post', $post_id))
return;
}
$min_unit = sanitize_text_field($_POST['min_unit']);
$min_unit_match = floatval($min_unit);
if(!$min_unit_match) {
update_post_meta($post_id, 'min_unit', '0.00');
} else {
update_post_meta($post_id, 'min_unit', $min_unit);
}
}
add_action('save_post', 'min_unit_box_save', 10, 2);
/********************************************************************
Register Maximum Units
********************************************************************/
// Registers Max Unit Box
function max_unit_box() {
add_meta_box(
'max_unit_box',
__('Maximum Units'),
'max_unit_box_content',
'courses',
'side',
'default'
);
}
// Registers Max Unit Box Content
function max_unit_box_content($post) {
wp_nonce_field( plugin_basename( __FILE__ ), 'max_unit_box_content_nonce');
$max_unit_val = get_post_meta($post->ID, 'max_unit', true);
echo '<label for="max_unit"></label>';
echo '<input style="width:100%" type="text" id="max_unit" name="max_unit" maxlength="4" placeholder="Ex. 3.00" value="' . esc_attr($max_unit_val) . '" />';
}
add_action('add_meta_boxes', 'max_unit_box');
// Action for Max Unit on save
function max_unit_box_save($post_id) {
global $post;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return;
if (!wp_verify_nonce($_POST['max_unit_box_content_nonce'], plugin_basename( __FILE__ )))
return $post_id;
if ('page' == $_POST['post_type']) {
if (!current_user_can('edit_page', $post_id))
return;
} else {
if (!current_user_can('edit_post', $post_id))
return;
}
$max_unit = sanitize_text_field($_POST['max_unit']);
$max_unit_match = floatval($max_unit);
if(!$max_unit_match) {
update_post_meta($post_id, 'max_unit', '0.00');
} else {
update_post_meta($post_id, 'max_unit', $max_unit);
}
}
add_action('save_post', 'max_unit_box_save', 10, 2);
/********************************************************************
Register Prerequisites Box
********************************************************************/
// Registers Prerequisites Box
function prereq_box() {
add_meta_box(
'prereq_box',
__('Prerequisites'),
'prereq_box_content',
'courses',
'normal',
'high'
);
}
// Registers Prerequisites Box Content
function prereq_box_content($post) {
wp_nonce_field( plugin_basename( __FILE__ ), 'prereq_box_content_nonce');
$prereq_val = get_post_meta($post->ID, 'prereq', true);
echo '<label for="prereq"></label>';
echo '<textarea style="width:100%" id="prereq" name="prereq" rows="4" placeholder="Enter the Prerequisites">' . esc_attr($prereq_val) . '</textarea>';
}
add_action('add_meta_boxes', 'prereq_box');
// Action for Prerequisites on save
function prereq_box_save($post_id) {
global $post;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return;
if (!wp_verify_nonce($_POST['prereq_box_content_nonce'], plugin_basename( __FILE__ )))
return $post_id;
if ('page' == $_POST['post_type']) {
if (!current_user_can('edit_page', $post_id))
return;
} else {
if (!current_user_can('edit_post', $post_id))
return;
}
$prereq = sanitize_text_field($_POST['prereq']);
if($prereq)
update_post_meta($post_id, 'prereq', $prereq);
}
add_action('save_post', 'prereq_box_save', 10, 2);
/********************************************************************
Register Course Archives
********************************************************************/
function course_archives($query) {
if($query->is_tax('subjects') && $query->is_main_query() && !$query->is_singular('courses') ) {
$query->set( 'post_type', 'courses');
$query->set( 'nopaging', true);
$query->set( 'order', 'ASC' );
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'meta_key', 'catalog_number' );
};
return $query;
}
add_filter( 'pre_get_posts', 'course_archives' );
class UC_Grad{
//
// Create our hook for our create_post_type() method
// and hook our function to the 'init' action
//
public function __construct(){
add_action( $tag_action_hook = 'init',
$function_to_call = array( $this, 'create_post_type' ) ,
0);
}
//
// Register our new custom post type
//
public function create_post_type() {
$labels = array(
'name' => _x( 'Programs', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Program', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Programs', 'text_domain' ),
'parent_item_colon' => __( 'Parent Program:', 'text_domain' ),
'all_items' => __( 'All Programs', 'text_domain' ),
'view_item' => __( 'View Program', 'text_domain' ),
'add_new_item' => __( 'Add New Program', 'text_domain' ),
'add_new' => __( 'New Program', 'text_domain' ),
'edit_item' => __( 'Edit Program', 'text_domain' ),
'update_item' => __( 'Update Program', 'text_domain' ),
'search_items' => __( 'Search Program', 'text_domain' ),
'not_found' => __( 'No programs found', 'text_domain' ),
'not_found_in_trash' => __( 'No programs found in Trash', 'text_domain' ),
);
$args = array(
'label' => __( 'programs', 'text_domain' ),
'description' => __( 'Program Post Type', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'custom-fields', 'page-attributes', 'post-formats', 'categories' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => '',
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'query_var' => 'programs',
'capability_type' => 'page',
'taxonomies' => array('category', 'post_tag'),
'rewrite' => true
);
register_post_type( 'programs', $args );
flush_rewrite_rules();
} // create_post_type
} // Class
//
// Create a new instance of UC Abroad
//
$uc_abroad = new UC_Grad();
function program_archive_page_template( $archive_template ) {
if ( is_post_type_archive( 'programs' ) ) {
$archive_template = dirname( __FILE__ ) . '/templates/archive-programs.php';
}
return $archive_template;
}
add_filter( 'archive_template', 'program_archive_page_template' );
//Modify title
add_filter( 'pre_get_document_title', 'graduateschool_title', 50);
add_filter( 'wds_title', 'graduateschool_title', 50);
function graduateschool_title( $title ) {
if ( is_post_type_archive('programs') ) {
$title = 'Degree & Certificate Programs | '.get_bloginfo( 'name' );
}
return $title;
}
//Add title tag theme support
add_action( 'after_setup_theme', 'graduateschool_title_tag' );
function graduateschool_title_tag() {
add_theme_support( 'title-tag' );
}
//ACF Code
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array (
'key' => 'group_589b63448a751',
'title' => 'Programs',
'fields' => array (
array (
'key' => 'field_589b786dd6901',
'label' => 'Degree Filter',
'name' => 'degree_filter',
'type' => 'checkbox',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'choices' => array (
'masters' => 'Master\'s',
'doctoral' => 'Doctoral/PhD',
'certificate' => 'Certificate',
'online' => 'Online',
),
'default_value' => array (
),
'layout' => 'vertical',
'toggle' => 0,
'return_format' => 'value',
'allow_custom' => 0,
'save_custom' => 0,
),
array (
'key' => 'field_589b67cd3cc1f',
'label' => 'Area\'s of Interest Filter',
'name' => 'areas_of_interest_filter',
'type' => 'checkbox',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'choices' => array (
'agriculture' => 'Agriculture',
'business' => 'Business',
'education' => 'Education',
'engineering' => 'Engineering',
'fine-arts' => 'Fine Arts',
'health' => 'Health',
'humanities' => 'Humanities',
'natural-sciences' => 'Natural Sciences',
'social-sciences' => 'Social Sciences',
),
'default_value' => array (
),
'layout' => 'vertical',
'toggle' => 0,
'return_format' => 'value',
'allow_custom' => 0,
'save_custom' => 0,
),
array (
'key' => 'field_58a3644c7c370',
'label' => 'Area of Interest Color',
'name' => 'areas_of_interest_color',
'type' => 'select',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'choices' => array (
'agriculture' => 'Agriculture',
'business' => 'Business',
'education' => 'Education',
'engineering' => 'Engineering',
'fine-arts' => 'Fine Arts',
'health' => 'Health',
'humanities' => 'Humanities',
'natural-sciences' => 'Natural Sciences',
'social-sciences' => 'Social Sciences',
),
'default_value' => array (
),
'allow_null' => 1,
'multiple' => 0,
'ui' => 0,
'ajax' => 0,
'return_format' => 'value',
'placeholder' => '',
),
array (
'key' => 'field_589b6349b5862',
'label' => 'Program URL',
'name' => 'program_url',
'type' => 'url',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
),
array (
'key' => 'field_589b6369b5863',
'label' => 'Concentrations',
'name' => 'concentrations',
'type' => 'wysiwyg',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'tabs' => 'all',
'toolbar' => 'full',
'media_upload' => 1,
'delay' => 0,
),
array (
'key' => 'field_589b66f5d6681',
'label' => 'Phone Number',
'name' => 'phone_number',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
array (
'key' => 'field_58f7c4f744bd9',
'label' => 'Email',
'name' => 'email',
'type' => 'email',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
),
array (
'key' => 'field_589b64ce3c849',
'label' => 'Degrees',
'name' => 'degrees',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
),
'location' => array (
array (
array (
'param' => 'post_type',
'operator' => '==',
'value' => 'programs',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'default',
'label_placement' => 'top',
'instruction_placement' => 'label',
'hide_on_screen' => '',
'active' => 1,
'description' => '',
));
endif;
?>