From 8da983139da63315d50e41f79fd0e90d36d19e92 Mon Sep 17 00:00:00 2001 From: John Pennypacker Date: Fri, 23 Feb 2018 15:49:56 -0500 Subject: [PATCH 01/21] Added a template and code to use the template --- templates/single-program.php | 90 +++++++++++++++++++++++++++ uri-program-finder.php | 117 +++++++++++++++++++++++++++++++++++ 2 files changed, 207 insertions(+) create mode 100755 templates/single-program.php diff --git a/templates/single-program.php b/templates/single-program.php new file mode 100755 index 0000000..7479ce8 --- /dev/null +++ b/templates/single-program.php @@ -0,0 +1,90 @@ + + +
+ + + + + + + + +
> +
+ ', '' ); + else : + the_title( '

', '

' ); + endif; + ?> + + + + */ + ?> +
+ + +
+ →', 'uri-modern' ), array( 'span' => array( 'class' => array() ) ) ), + the_title( '"', '"', false ) + ) ); + + wp_link_pages( array( + 'before' => '', + ) ); + ?> + + + + Department Website + + + +
+ + + + +
+ +Template Name: '; +// var_dump( $template_name ); +// echo ''; + + // Set variable to search in woocommerce-plugin-templates folder of theme. + if ( ! $template_path ) : + $template_path = 'templates/'; + endif; + + // Set default plugin templates path. + if ( ! $default_path ) : + $default_path = plugin_dir_path( __FILE__ ) . 'templates/'; // Path to the template folder + endif; + + // Search template file in theme folder. + $template = locate_template( array( + $template_path . $template_name, + $template_name + ) ); + + // Get plugins template file. + if ( ! $template ) : + $template = $default_path . $template_name; + endif; + + return apply_filters( 'uri_program_finder_locate_template', $template, $template_name, $template_path, $default_path ); + +} + +/** + * Get template. + * + * Search for the template and include the file. + * + * @since 1.0.0 + * + * @see wcpt_locate_template() + * + * @param string $template_name Template to load. + * @param array $args Args passed for the template file. + * @param string $string $template_path Path to templates. + * @param string $default_path Default path to template files. + */ +function uri_program_finder_get_template( $template_name, $args = array(), $tempate_path = '', $default_path = '' ) { + + if ( is_array( $args ) && isset( $args ) ) : + extract( $args ); + endif; + + $template_file = uri_program_finder_locate_template( $template_name, $tempate_path, $default_path ); + + if ( ! file_exists( $template_file ) ) : + _doing_it_wrong( __FUNCTION__, sprintf( '%s does not exist.', $template_file ), '1.0.0' ); + return; + endif; + + + include $template_file; + +} + + +/** + * Template loader. + * + * The template loader will check if WP is loading a template + * for a specific Post Type and will try to load the template + * from out 'templates' directory. + * + * + * @param string $template Template file that is being loaded. + * @return string Template file that should be loaded. + */ +function uri_program_finder_template_loader( $template ) { + + if ( is_single() ) { // @todo: this is dangerous and bad. + + // if it's a people page, then override $template with the custom one + // use "people" instead of "person" for backwards compatability. + $file = 'single-program.php'; + + if ( file_exists( uri_program_finder_locate_template( $file ) ) ) { + $template = uri_program_finder_locate_template( $file ); + } + + } + + return $template; + +} +add_filter( 'template_include', 'uri_program_finder_template_loader', 99 ); + From 5345aa4273f10f5db25cd83083ac699397d0be90 Mon Sep 17 00:00:00 2001 From: John Pennypacker Date: Fri, 23 Feb 2018 16:02:15 -0500 Subject: [PATCH 02/21] coded custom fields, made less dangerous and bad. --- inc/uri-program-finder-fields.php | 123 ++++++++++++++++++++++++++++++ uri-program-finder.php | 54 ++++++++++++- 2 files changed, 176 insertions(+), 1 deletion(-) create mode 100755 inc/uri-program-finder-fields.php diff --git a/inc/uri-program-finder-fields.php b/inc/uri-program-finder-fields.php new file mode 100755 index 0000000..f035d53 --- /dev/null +++ b/inc/uri-program-finder-fields.php @@ -0,0 +1,123 @@ + 'acf_program-fields', + 'title' => 'Program Fields', + 'fields' => array ( + array ( + 'key' => 'field_5a907505aed60', + 'label' => 'Department Website', + 'name' => 'department_website', + 'type' => 'text', + 'default_value' => '', + 'placeholder' => 'https://uri.edu/department', + 'prepend' => '', + 'append' => '', + 'formatting' => 'none', + 'maxlength' => '', + ), + array ( + 'key' => 'field_5a90756aaed61', + 'label' => 'Catalog Info', + 'name' => 'catalog_info', + 'type' => 'text', + 'instructions' => 'Enter the URL of the corresponding catalog page.', + 'default_value' => '', + 'placeholder' => 'https://web.uri.edu/catalog/music/', + 'prepend' => '', + 'append' => '', + 'formatting' => 'html', + 'maxlength' => '', + ), + array ( + 'key' => 'field_5a9076e700469', + 'label' => 'Course Descriptions', + 'name' => 'course_descriptions', + 'type' => 'text', + 'default_value' => '', + 'placeholder' => '', + 'prepend' => '', + 'append' => '', + 'formatting' => 'html', + 'maxlength' => '', + ), + array ( + 'key' => 'field_5a907649020b1', + 'label' => 'Admission Info', + 'name' => 'admission_info', + 'type' => 'text', + 'instructions' => 'URL to admission information', + 'default_value' => 'https://uri.edu/admission', + 'placeholder' => '', + 'prepend' => '', + 'append' => '', + 'formatting' => 'html', + 'maxlength' => '', + ), + array ( + 'key' => 'field_5a907670020b2', + 'label' => 'Apply', + 'name' => 'apply', + 'type' => 'select', + 'choices' => array ( + 'undergraduate' => 'Undergraduate', + 'graduate' => 'Graduate', + ), + 'default_value' => 'undergraduate', + 'allow_null' => 0, + 'multiple' => 0, + ), + array ( + 'key' => 'field_5a9077420046a', + 'label' => 'Course Schedule', + 'name' => 'course_schedule', + 'type' => 'text', + 'instructions' => 'I\'m sorry.', + 'default_value' => 'https://uri.edu/course-schedule', + 'placeholder' => '', + 'prepend' => '', + 'append' => '', + 'formatting' => 'html', + 'maxlength' => '', + ), + array ( + 'key' => 'field_5a9078363b98f', + 'label' => 'Time to Completion', + 'name' => 'time_to_completion', + 'type' => 'wysiwyg', + 'default_value' => '', + 'toolbar' => 'full', + 'media_upload' => 'no', + ), + array ( + 'key' => 'field_5a90787f3b990', + 'label' => 'Application Deadline', + 'name' => 'application_deadline', + 'type' => 'wysiwyg', + 'default_value' => '', + 'toolbar' => 'full', + 'media_upload' => 'no', + ), + ), + 'location' => array ( + array ( + array ( + 'param' => 'post_type', + 'operator' => '==', + 'value' => 'program', + 'order_no' => 0, + 'group_no' => 0, + ), + ), + ), + 'options' => array ( + 'position' => 'normal', + 'layout' => 'default', + 'hide_on_screen' => array ( + ), + ), + 'menu_order' => 0, + )); +} diff --git a/uri-program-finder.php b/uri-program-finder.php index cb019ae..65238e4 100755 --- a/uri-program-finder.php +++ b/uri-program-finder.php @@ -17,6 +17,8 @@ include( plugin_dir_path( __FILE__ ) . 'inc/uri-program-finder-api.php'); +include( plugin_dir_path( __FILE__ ) . 'inc/uri-program-finder-fields.php'); + // This URL pull multiple categories (need to remove page title): // https://www.uri.edu/programs/?cat=24,26 @@ -384,7 +386,7 @@ function uri_program_finder_get_template( $template_name, $args = array(), $temp */ function uri_program_finder_template_loader( $template ) { - if ( is_single() ) { // @todo: this is dangerous and bad. + if ( is_single() && get_post_type() === 'program' ) { // if it's a people page, then override $template with the custom one // use "people" instead of "person" for backwards compatability. @@ -401,3 +403,53 @@ function uri_program_finder_template_loader( $template ) { } add_filter( 'template_include', 'uri_program_finder_template_loader', 99 ); + +function uri_program_finder_post_type_maker() { + + register_post_type('program', array( + 'label' => 'Program', + 'description' => 'Majors, etc.', + 'public' => true, + 'show_ui' => true, + 'show_in_menu' => true, + 'capability_type' => 'post', + 'hierarchical' => true, + 'rewrite' => array('slug' => 'program'), + 'query_var' => true, + 'has_archive' => true, + 'exclude_from_search' => false, + 'supports' => array('title','thumbnail','revisions','author'), // perhaps 'editor', 'excerpt' + 'labels' => array ( + 'name' => 'Program', + 'singular_name' => 'Programs', + 'menu_name' => 'Programs', + 'add_new' => 'Add Program', + 'add_new_item' => 'Add New Program', + 'edit' => 'Edit', + 'edit_item' => 'Edit Program', + 'new_item' => 'New Program', + 'view' => 'View Program', + 'view_item' => 'View Program', + 'search_items' => 'Search Program', + 'not_found' => 'No Programs Found', + 'not_found_in_trash' => 'No Programs Found in Trash', + 'parent' => 'Parent Program', + ), + 'menu_icon' => 'dashicons-id-alt', + )); + + register_taxonomy('careers', array ( + 0 => 'program' + ), array( + 'hierarchical' => true, + 'label' => 'Careers', + 'show_ui' => true, + 'query_var' => true, + 'rewrite' => array('slug' => 'programs'), + 'singular_label' => 'Career' + ) + ); + + +} +add_action('init', 'uri_program_finder_post_type_maker'); From fcb082b943e0451231fbb8efa3650b108918cf3d Mon Sep 17 00:00:00 2001 From: John Pennypacker Date: Fri, 23 Feb 2018 16:05:16 -0500 Subject: [PATCH 03/21] Added body (editor) field --- uri-program-finder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uri-program-finder.php b/uri-program-finder.php index 65238e4..7ca730e 100755 --- a/uri-program-finder.php +++ b/uri-program-finder.php @@ -418,7 +418,7 @@ function uri_program_finder_post_type_maker() { 'query_var' => true, 'has_archive' => true, 'exclude_from_search' => false, - 'supports' => array('title','thumbnail','revisions','author'), // perhaps 'editor', 'excerpt' + 'supports' => array('title','editor','excerpt','thumbnail','revisions','author'), // perhaps 'editor', 'excerpt' 'labels' => array ( 'name' => 'Program', 'singular_name' => 'Programs', From 986d90b9f78d8cfb0ec474d4a77f548589ad5596 Mon Sep 17 00:00:00 2001 From: John Pennypacker Date: Fri, 23 Feb 2018 16:29:07 -0500 Subject: [PATCH 04/21] genericifying the template --- templates/single-program.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/templates/single-program.php b/templates/single-program.php index 7479ce8..160ca25 100755 --- a/templates/single-program.php +++ b/templates/single-program.php @@ -8,18 +8,11 @@ */ get_header(); -get_template_part( 'template-parts/sitebar' ); ?>
- - Date: Sat, 24 Feb 2018 11:36:51 -0500 Subject: [PATCH 05/21] updated program icon, added categories and taxonomies --- inc/uri-program-finder-fields.php | 84 +++++++++++++++++++++++++++++++ uri-program-finder.php | 50 ------------------ 2 files changed, 84 insertions(+), 50 deletions(-) diff --git a/inc/uri-program-finder-fields.php b/inc/uri-program-finder-fields.php index f035d53..1ae95f4 100755 --- a/inc/uri-program-finder-fields.php +++ b/inc/uri-program-finder-fields.php @@ -1,4 +1,88 @@ 'Program', + 'description' => 'Majors, etc.', + 'public' => true, + 'show_ui' => true, + 'show_in_menu' => true, + 'capability_type' => 'post', + 'hierarchical' => true, + 'rewrite' => array('slug' => 'program'), + 'query_var' => true, + 'has_archive' => true, + 'exclude_from_search' => false, + 'supports' => array('title','editor','excerpt','thumbnail','revisions','author'), + 'taxonomies' => array('post_tag', 'category', 'careers' ), + 'labels' => array ( + 'name' => 'Program', + 'singular_name' => 'Programs', + 'menu_name' => 'Programs', + 'add_new' => 'Add Program', + 'add_new_item' => 'Add New Program', + 'edit' => 'Edit', + 'edit_item' => 'Edit Program', + 'new_item' => 'New Program', + 'view' => 'View Program', + 'view_item' => 'View Program', + 'search_items' => 'Search Program', + 'not_found' => 'No Programs Found', + 'not_found_in_trash' => 'No Programs Found in Trash', + 'parent' => 'Parent Program', + ), + 'menu_icon' => 'dashicons-welcome-learn-more', + )); + + + + $taxonomy_args = array( + 'hierarchical' => false, + 'labels' => array( + 'name' => _x( 'Careers', 'taxonomy general name', 'uri' ), + 'singular_name' => _x( 'Career', 'taxonomy singular name', 'textduriomain' ), + 'search_items' => __( 'Search Careers', 'uri' ), + 'popular_items' => __( 'Popular Careers', 'uri' ), + 'all_items' => __( 'All Careers', 'uri' ), + 'parent_item' => null, + 'parent_item_colon' => null, + 'edit_item' => __( 'Edit Career', 'uri' ), + 'update_item' => __( 'Update Career', 'uri' ), + 'add_new_item' => __( 'Add New Career', 'uri' ), + 'new_item_name' => __( 'New Career Name', 'uri' ), + 'separate_items_with_commas' => __( 'Separate careers with commas (like tags)', 'uri' ), + 'add_or_remove_items' => __( 'Add or remove careers', 'uri' ), + 'choose_from_most_used' => __( 'Choose from the most used careers', 'uri' ), + 'not_found' => __( 'No careers found.', 'uri' ), + 'menu_name' => __( 'Careers', 'uri' ), + ), + 'show_ui' => true, + 'show_admin_column' => true, + 'query_var' => true, + 'rewrite' => array('slug' => 'career'), + 'singular_label' => 'Career' + ); + + register_taxonomy('careers', array( 'program' ), $taxonomy_args); + + +} +add_action('init', 'uri_program_finder_post_type_maker'); + + + +/** + * Define the custom fields + */ if(function_exists("register_field_group")) { diff --git a/uri-program-finder.php b/uri-program-finder.php index 7ca730e..0b3243e 100755 --- a/uri-program-finder.php +++ b/uri-program-finder.php @@ -403,53 +403,3 @@ function uri_program_finder_template_loader( $template ) { } add_filter( 'template_include', 'uri_program_finder_template_loader', 99 ); - -function uri_program_finder_post_type_maker() { - - register_post_type('program', array( - 'label' => 'Program', - 'description' => 'Majors, etc.', - 'public' => true, - 'show_ui' => true, - 'show_in_menu' => true, - 'capability_type' => 'post', - 'hierarchical' => true, - 'rewrite' => array('slug' => 'program'), - 'query_var' => true, - 'has_archive' => true, - 'exclude_from_search' => false, - 'supports' => array('title','editor','excerpt','thumbnail','revisions','author'), // perhaps 'editor', 'excerpt' - 'labels' => array ( - 'name' => 'Program', - 'singular_name' => 'Programs', - 'menu_name' => 'Programs', - 'add_new' => 'Add Program', - 'add_new_item' => 'Add New Program', - 'edit' => 'Edit', - 'edit_item' => 'Edit Program', - 'new_item' => 'New Program', - 'view' => 'View Program', - 'view_item' => 'View Program', - 'search_items' => 'Search Program', - 'not_found' => 'No Programs Found', - 'not_found_in_trash' => 'No Programs Found in Trash', - 'parent' => 'Parent Program', - ), - 'menu_icon' => 'dashicons-id-alt', - )); - - register_taxonomy('careers', array ( - 0 => 'program' - ), array( - 'hierarchical' => true, - 'label' => 'Careers', - 'show_ui' => true, - 'query_var' => true, - 'rewrite' => array('slug' => 'programs'), - 'singular_label' => 'Career' - ) - ); - - -} -add_action('init', 'uri_program_finder_post_type_maker'); From 1707d8db51ee7e38ee25649289e9a41f05e9d88e Mon Sep 17 00:00:00 2001 From: John Pennypacker Date: Sat, 24 Feb 2018 11:59:01 -0500 Subject: [PATCH 06/21] renamed a few functions, made the plugin path a global to facilitate templating --- inc/uri-program-finder-api.php | 2 +- inc/uri-program-finder-fields.php | 17 +++- inc/uri-program-finder-templating.php | 123 +++++++++++++++++++++++++ templates/single-program.php | 32 ++----- uri-program-finder.php | 126 ++------------------------ 5 files changed, 152 insertions(+), 148 deletions(-) create mode 100755 inc/uri-program-finder-templating.php diff --git a/inc/uri-program-finder-api.php b/inc/uri-program-finder-api.php index 57ea316..b7df54b 100755 --- a/inc/uri-program-finder-api.php +++ b/inc/uri-program-finder-api.php @@ -24,7 +24,7 @@ function uri_program_finder_api_callback( $data ) { $location = uri_program_sanitize_ids($data['location']); $args = array( - 'post_type' => 'post', + 'post_type' => 'program', 's' => $search, 'orderby' => 'title', 'order' => 'ASC', diff --git a/inc/uri-program-finder-fields.php b/inc/uri-program-finder-fields.php index 1ae95f4..d57d644 100755 --- a/inc/uri-program-finder-fields.php +++ b/inc/uri-program-finder-fields.php @@ -3,12 +3,16 @@ * Define the custom post type, its taxonomy, and its fields. */ +// Block direct requests +if ( !defined('ABSPATH') ) + die('-1'); + /** * Declare the custom post type */ -function uri_program_finder_post_type_maker() { +function uri_program_finder_create_program_post_type() { register_post_type('program', array( 'label' => 'Program', @@ -43,8 +47,16 @@ function uri_program_finder_post_type_maker() { 'menu_icon' => 'dashicons-welcome-learn-more', )); + uri_program_finder_create_taxonomy(); + +} +add_action('init', 'uri_program_finder_create_program_post_type'); +/** + * Create a custom career taxonomy for programs + */ +function uri_program_finder_create_taxonomy() { $taxonomy_args = array( 'hierarchical' => false, 'labels' => array( @@ -73,10 +85,7 @@ function uri_program_finder_post_type_maker() { ); register_taxonomy('careers', array( 'program' ), $taxonomy_args); - - } -add_action('init', 'uri_program_finder_post_type_maker'); diff --git a/inc/uri-program-finder-templating.php b/inc/uri-program-finder-templating.php new file mode 100755 index 0000000..5cf64a3 --- /dev/null +++ b/inc/uri-program-finder-templating.php @@ -0,0 +1,123 @@ +Template Name: '; +// var_dump( $template_name ); +// echo ''; + + // Set variable to search in woocommerce-plugin-templates folder of theme. + if ( ! $template_path ) : + $template_path = 'templates/'; + endif; + + // Set default plugin templates path. + if ( ! $default_path ) : + $default_path = URI_PROGRAM_FINDER_PATH . 'templates/'; // Path to the template folder + endif; + + // Search template file in theme folder. + $template = locate_template( array( + $template_path . $template_name, + $template_name + ) ); + + // Get plugins template file. + if ( ! $template ) : + $template = $default_path . $template_name; + endif; + + return apply_filters( 'uri_program_finder_locate_template', $template, $template_name, $template_path, $default_path ); + +} + +/** + * Get template. + * + * Search for the template and include the file. + * + * @since 1.0.0 + * + * @see wcpt_locate_template() + * + * @param string $template_name Template to load. + * @param array $args Args passed for the template file. + * @param string $string $template_path Path to templates. + * @param string $default_path Default path to template files. + */ +function uri_program_finder_get_template( $template_name, $args = array(), $tempate_path = '', $default_path = '' ) { + + if ( is_array( $args ) && isset( $args ) ) : + extract( $args ); + endif; + + $template_file = uri_program_finder_locate_template( $template_name, $tempate_path, $default_path ); + + if ( ! file_exists( $template_file ) ) : + _doing_it_wrong( __FUNCTION__, sprintf( '%s does not exist.', $template_file ), '1.0.0' ); + return; + endif; + + + include $template_file; + +} + diff --git a/templates/single-program.php b/templates/single-program.php index 160ca25..744d49b 100755 --- a/templates/single-program.php +++ b/templates/single-program.php @@ -10,14 +10,9 @@ get_header(); ?> -
+
- - - - +
>
@@ -28,15 +23,6 @@ the_title( '

', '

' ); endif; ?> - - - - */ - ?>
@@ -54,30 +40,26 @@ 'after' => '', ) ); ?> - + - Department Website - + + - endwhile; // End of the loop. - ?> - -
+
Template Name: '; -// var_dump( $template_name ); -// echo ''; - - // Set variable to search in woocommerce-plugin-templates folder of theme. - if ( ! $template_path ) : - $template_path = 'templates/'; - endif; - - // Set default plugin templates path. - if ( ! $default_path ) : - $default_path = plugin_dir_path( __FILE__ ) . 'templates/'; // Path to the template folder - endif; - - // Search template file in theme folder. - $template = locate_template( array( - $template_path . $template_name, - $template_name - ) ); - - // Get plugins template file. - if ( ! $template ) : - $template = $default_path . $template_name; - endif; - - return apply_filters( 'uri_program_finder_locate_template', $template, $template_name, $template_path, $default_path ); - -} - -/** - * Get template. - * - * Search for the template and include the file. - * - * @since 1.0.0 - * - * @see wcpt_locate_template() - * - * @param string $template_name Template to load. - * @param array $args Args passed for the template file. - * @param string $string $template_path Path to templates. - * @param string $default_path Default path to template files. - */ -function uri_program_finder_get_template( $template_name, $args = array(), $tempate_path = '', $default_path = '' ) { - - if ( is_array( $args ) && isset( $args ) ) : - extract( $args ); - endif; - - $template_file = uri_program_finder_locate_template( $template_name, $tempate_path, $default_path ); - - if ( ! file_exists( $template_file ) ) : - _doing_it_wrong( __FUNCTION__, sprintf( '%s does not exist.', $template_file ), '1.0.0' ); - return; - endif; - - - include $template_file; - -} - - -/** - * Template loader. - * - * The template loader will check if WP is loading a template - * for a specific Post Type and will try to load the template - * from out 'templates' directory. - * - * - * @param string $template Template file that is being loaded. - * @return string Template file that should be loaded. - */ -function uri_program_finder_template_loader( $template ) { - - if ( is_single() && get_post_type() === 'program' ) { - - // if it's a people page, then override $template with the custom one - // use "people" instead of "person" for backwards compatability. - $file = 'single-program.php'; - - if ( file_exists( uri_program_finder_locate_template( $file ) ) ) { - $template = uri_program_finder_locate_template( $file ); - } - - } - - return $template; - -} -add_filter( 'template_include', 'uri_program_finder_template_loader', 99 ); - From 713ad57e6e1d332f7f745c328e9b52908f66647f Mon Sep 17 00:00:00 2001 From: John Pennypacker Date: Sat, 24 Feb 2018 12:15:25 -0500 Subject: [PATCH 07/21] Updated template to include custom fields. --- inc/uri-program-finder-fields.php | 4 +- inc/uri-program-finder-templating.php | 1 + templates/single-program.php | 56 +++++++++++++++++++++++++-- uri-program-finder.php | 16 ++++---- 4 files changed, 63 insertions(+), 14 deletions(-) diff --git a/inc/uri-program-finder-fields.php b/inc/uri-program-finder-fields.php index d57d644..d57e284 100755 --- a/inc/uri-program-finder-fields.php +++ b/inc/uri-program-finder-fields.php @@ -155,8 +155,8 @@ function uri_program_finder_create_taxonomy() { 'name' => 'apply', 'type' => 'select', 'choices' => array ( - 'undergraduate' => 'Undergraduate', - 'graduate' => 'Graduate', + 'https://apply.commonapp.org/Login?ma=376&tref=program-finder' => 'Undergraduate', + 'https://web.uri.edu/graduate-school/admission/' => 'Graduate', ), 'default_value' => 'undergraduate', 'allow_null' => 0, diff --git a/inc/uri-program-finder-templating.php b/inc/uri-program-finder-templating.php index 5cf64a3..93c8244 100755 --- a/inc/uri-program-finder-templating.php +++ b/inc/uri-program-finder-templating.php @@ -1,6 +1,7 @@ '', ) ); ?> + + +
+

Time to Completion

+ +
+ + + +
+

Application Deadline

+ +
+ + - - Department Website + + + + + + + + + + + + + + + + + + + + + +
+ Apply +
+ diff --git a/uri-program-finder.php b/uri-program-finder.php index b2d53bd..ff6f3ca 100755 --- a/uri-program-finder.php +++ b/uri-program-finder.php @@ -42,12 +42,12 @@ function uri_program_finder_scripts() { wp_register_script( $plugin_handle, plugins_url( '/js/program-finder.js', __FILE__ ) ); wp_localize_script( $plugin_handle, 'URIProgramFinder', $values ); - $chosen_handle = 'uri-program-finder-chosen-js'; - wp_register_script( $chosen_handle, plugins_url( '/chosen/chosen.jquery.min.js', __FILE__ ) ); + $chosen_handle = 'uri-program-finder-chosen-js'; + wp_register_script( $chosen_handle, plugins_url( '/chosen/chosen.jquery.min.js', __FILE__ ) ); // For either a plugin or a theme, you can then enqueue the script: wp_enqueue_script( $plugin_handle ); - wp_enqueue_script( $chosen_handle ); + wp_enqueue_script( $chosen_handle ); } @@ -55,11 +55,11 @@ function uri_program_finder_scripts() { * Loads up the css */ function uri_program_finder_styles() { - wp_register_style( 'uri-program-finder-chosen-css', plugins_url( '/chosen/chosen.min.css', __FILE__ ) ); - wp_register_style( 'uri-program-finder-chosen-css-customize', plugins_url( '/css/chosen.customize.css', __FILE__ ) ); - - wp_enqueue_style( 'uri-program-finder-chosen-css' ); - wp_enqueue_style( 'uri-program-finder-chosen-css-customize' ); + wp_register_style( 'uri-program-finder-chosen-css', plugins_url( '/chosen/chosen.min.css', __FILE__ ) ); + wp_register_style( 'uri-program-finder-chosen-css-customize', plugins_url( '/css/chosen.customize.css', __FILE__ ) ); + + wp_enqueue_style( 'uri-program-finder-chosen-css' ); + wp_enqueue_style( 'uri-program-finder-chosen-css-customize' ); } From fe80eac8d69e3ae21cdc698eb9f9b7cfd3916425 Mon Sep 17 00:00:00 2001 From: John Pennypacker Date: Sat, 24 Feb 2018 12:16:50 -0500 Subject: [PATCH 08/21] updated comments to be more accurate to the program finder. --- inc/uri-program-finder-templating.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/inc/uri-program-finder-templating.php b/inc/uri-program-finder-templating.php index 93c8244..3d9b57f 100755 --- a/inc/uri-program-finder-templating.php +++ b/inc/uri-program-finder-templating.php @@ -27,7 +27,6 @@ function uri_program_finder_template_loader( $template ) { if ( is_single() && get_post_type() === 'program' ) { // if it's a people page, then override $template with the custom one - // use "people" instead of "person" for backwards compatability. $file = 'single-program.php'; if ( file_exists( uri_program_finder_locate_template( $file ) ) ) { @@ -50,7 +49,7 @@ function uri_program_finder_template_loader( $template ) { * Search Order: * 1. /themes/theme/templates/$template_name * 2. /themes/theme/$template_name - * 3. /plugins/uri-people-tool/templates/$template_name. + * 3. /plugins/uri-program-finder/templates/$template_name. * * http://jeroensormani.com/how-to-add-template-files-in-your-plugin/ * From 5e0abc4e40b652821e7af50e343c46852e7a97e4 Mon Sep 17 00:00:00 2001 From: John Pennypacker Date: Sat, 24 Feb 2018 12:32:39 -0500 Subject: [PATCH 09/21] added the featured image --- templates/single-program.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/templates/single-program.php b/templates/single-program.php index 8d40540..8de87bc 100755 --- a/templates/single-program.php +++ b/templates/single-program.php @@ -25,6 +25,22 @@ ?> + + +
Date: Fri, 11 May 2018 11:27:34 -0400 Subject: [PATCH 10/21] Move rename template directory --- inc/uri-program-finder-templating.php | 10 +++++----- {templates => template-parts}/single-program.php | 0 2 files changed, 5 insertions(+), 5 deletions(-) rename {templates => template-parts}/single-program.php (100%) diff --git a/inc/uri-program-finder-templating.php b/inc/uri-program-finder-templating.php index 3d9b57f..0f9f9e6 100755 --- a/inc/uri-program-finder-templating.php +++ b/inc/uri-program-finder-templating.php @@ -16,7 +16,7 @@ * * The template loader will check if WP is loading a template * for a specific Post Type and will try to load the template - * from out 'templates' directory. + * from out 'template-parts' directory. * * * @param string $template Template file that is being loaded. @@ -47,9 +47,9 @@ function uri_program_finder_template_loader( $template ) { * * Locate the called template. * Search Order: - * 1. /themes/theme/templates/$template_name + * 1. /themes/theme/template-parts/$template_name * 2. /themes/theme/$template_name - * 3. /plugins/uri-program-finder/templates/$template_name. + * 3. /plugins/uri-program-finder/template-parts/$template_name. * * http://jeroensormani.com/how-to-add-template-files-in-your-plugin/ * @@ -66,12 +66,12 @@ function uri_program_finder_locate_template( $template_name, $template_path = '' // Set variable to search in woocommerce-plugin-templates folder of theme. if ( ! $template_path ) : - $template_path = 'templates/'; + $template_path = 'template-parts/'; endif; // Set default plugin templates path. if ( ! $default_path ) : - $default_path = URI_PROGRAM_FINDER_PATH . 'templates/'; // Path to the template folder + $default_path = URI_PROGRAM_FINDER_PATH . 'template-parts/'; // Path to the template folder endif; // Search template file in theme folder. diff --git a/templates/single-program.php b/template-parts/single-program.php similarity index 100% rename from templates/single-program.php rename to template-parts/single-program.php From 355c83f1e741e869ce1910304ead678f4e32f31b Mon Sep 17 00:00:00 2001 From: Brandon Fuller Date: Fri, 11 May 2018 11:31:44 -0400 Subject: [PATCH 11/21] Update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 62cca54..897b8ef 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# URI AutoUpdater +# URI Program Finder Add [programs-categories] to a page and a form magically appears. From 7028a11f77475c3b6da35a36d42b0a4c028fcbec Mon Sep 17 00:00:00 2001 From: Brandon Fuller Date: Fri, 11 May 2018 11:44:15 -0400 Subject: [PATCH 12/21] Add travis ci integration and local code sniffing files; fix code style errors --- .codesniffer.ruleset.xml | 43 ++ .gitattributes | 16 + .gitignore | 4 + .jscsrc | 8 + .sniff | 15 + .travis.yml | 77 ++++ inc/uri-program-finder-api.php | 66 +-- inc/uri-program-finder-fields.php | 314 +++++++------- inc/uri-program-finder-templating.php | 55 +-- js/program-finder.js | 579 +++++++++++++------------- template-parts/single-program.php | 67 +-- uri-program-finder.php | 245 +++++------ 12 files changed, 851 insertions(+), 638 deletions(-) create mode 100644 .codesniffer.ruleset.xml create mode 100644 .gitattributes create mode 100644 .jscsrc create mode 100755 .sniff create mode 100644 .travis.yml diff --git a/.codesniffer.ruleset.xml b/.codesniffer.ruleset.xml new file mode 100644 index 0000000..548ee4a --- /dev/null +++ b/.codesniffer.ruleset.xml @@ -0,0 +1,43 @@ + + + + + + + A custom set of code standard rules to check for WordPress themes. + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + 4 + + + + + 4 + + + \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..09b6dd6 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,16 @@ +# used to remove files from deployment using `git archive` +# git files +.github export-ignore +.gitattributes export-ignore +.gitignore export-ignore +# test files +.codesniffer.ruleset.xml export-ignore +.jscsrc export-ignore +.jshintignore export-ignore +.sniff export-ignore +.travis.yml export-ignore +# gulp files +gulpfile.js export-ignore +package.json export-ignore +# src files +src export-ignore \ No newline at end of file diff --git a/.gitignore b/.gitignore index e69de29..7f1f068 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,4 @@ +.DS_Store +.jshintignore +node_modules +work_files \ No newline at end of file diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 0000000..f2e9596 --- /dev/null +++ b/.jscsrc @@ -0,0 +1,8 @@ +{ + "preset": "wordpress", + "fileExtensions": [ ".js" ], + "excludeFiles": [ + "gulpfile.js", + "js/cl.built.js" + ] +} \ No newline at end of file diff --git a/.sniff b/.sniff new file mode 100755 index 0000000..cd082ad --- /dev/null +++ b/.sniff @@ -0,0 +1,15 @@ +#!/bin/bash + +ignore=node_modules,work_files,gulpfile.js,chosen +ruleset=.codesniffer.ruleset.xml +warn=-n + +echo Running php code beautifier... +phpcbf --standard=$ruleset --ignore=$ignore $warn . +echo done beautifying. + +echo Running php codesniffer... +phpcs --standard=$ruleset --ignore=$ignore $warn . +echo done sniffing. + +echo done with sniff. \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..9c4a27c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,77 @@ +# Declare project language and PHP versions to test against. +language: php + +# Declare versions of PHP to use. Use one decimal max. +php: + - "7.0" + - "5.6" + +# Ditch sudo and use containers. +# @link http://docs.travis-ci.com/user/migrating-from-legacy/#Why-migrate-to-container-based-infrastructure%3F +# @link http://docs.travis-ci.com/user/workers/container-based-infrastructure/#Routing-your-build-to-container-based-infrastructure +sudo: false + +# Declare which branches to build +branches: + only: + - master + - develop + - /^travis-.*$/ + +# Declare which versions of WordPress to test against. +env: + # Master + # @link https://github.com/WordPress/WordPress + - WP_VERSION=master WP_MULTISITE=1 + +# Disable XDebug +before_install: + - phpenv config-rm xdebug.ini + +# Use this to prepare your build for testing. +before_script: + # Set up WordPress installation. + - export WP_DEVELOP_DIR=/tmp/wordpress/ + - mkdir -p $WP_DEVELOP_DIR + # Use the Git mirror of WordPress. + - git clone --depth=1 --branch="$WP_VERSION" git://develop.git.wordpress.org/ $WP_DEVELOP_DIR + # Set up plugin information. + - plugin_slug=$(basename $(pwd)) + - plugin_dir=$WP_DEVELOP_DIR/src/wp-content/plugins/$plugin_slug + - cd .. + - mv $plugin_slug $plugin_dir + # Set up WordPress configuration. + - cd $WP_DEVELOP_DIR + - echo $WP_DEVELOP_DIR + - cp wp-tests-config-sample.php wp-tests-config.php + - sed -i "s/youremptytestdbnamehere/wordpress_test/" wp-tests-config.php + - sed -i "s/yourusernamehere/root/" wp-tests-config.php + - sed -i "s/yourpasswordhere//" wp-tests-config.php + # Create WordPress database. + - mysql -e 'CREATE DATABASE wordpress_test;' -uroot + # Install CodeSniffer for WordPress Coding Standards checks. + - mkdir php-codesniffer && curl -L https://github.com/squizlabs/PHP_CodeSniffer/archive/master.tar.gz | tar xz --strip-components=1 -C php-codesniffer + # Install WordPress Coding Standards. + - mkdir wordpress-coding-standards && curl -L https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/archive/master.tar.gz | tar xz --strip-components=1 -C wordpress-coding-standards + # Hop into CodeSniffer directory. + - cd php-codesniffer + # Set install path for WordPress Coding Standards + # @link https://github.com/squizlabs/PHP_CodeSniffer/blob/4237c2fc98cc838730b76ee9cee316f99286a2a7/CodeSniffer.php#L1941 + - bin/phpcs --config-set installed_paths ../wordpress-coding-standards + # Hop into plugins directory. + - cd $plugin_dir + # After CodeSniffer install you should refresh your path. + - phpenv rehash + # Install JSCS: JavaScript Code Style checker + - npm install -g jscs + +# Run test script commands. +script: + # Search plugin for PHP syntax errors. + - find . \( -name '*.php' \) -exec php -lf {} \; + # Run the plugin through JavaScript Code Style checker + - jscs . + # WordPress Coding Standards + # @link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards + # @link http://pear.php.net/package/PHP_CodeSniffer/ + - $WP_DEVELOP_DIR/php-codesniffer/bin/phpcs -p -s -v -n . --standard=./.codesniffer.ruleset.xml --extensions=php \ No newline at end of file diff --git a/inc/uri-program-finder-api.php b/inc/uri-program-finder-api.php index b7df54b..f59e4f6 100755 --- a/inc/uri-program-finder-api.php +++ b/inc/uri-program-finder-api.php @@ -1,12 +1,17 @@ * @author: Brandon Fuller */ // Block direct requests -if ( !defined('ABSPATH') ) - die('-1'); +if ( ! defined( 'ABSPATH' ) ) { + die( '-1' ); +} /** * Selects posts by category using AND instead of OR @@ -16,41 +21,40 @@ */ function uri_program_finder_api_callback( $data ) { - $search = ( isset ( $data['s'] ) ) ? sanitize_title ( $data['s'] ) : ''; + $search = ( isset( $data['s'] ) ) ? sanitize_title( $data['s'] ) : ''; $ids = uri_program_sanitize_ids( $data['ids'] ); - $program_type = uri_program_sanitize_ids($data['program-type']); - $interest_area = uri_program_sanitize_ids($data['interest-area']); - $location = uri_program_sanitize_ids($data['location']); - + $program_type = uri_program_sanitize_ids( $data['program-type'] ); + $interest_area = uri_program_sanitize_ids( $data['interest-area'] ); + $location = uri_program_sanitize_ids( $data['location'] ); + $args = array( 'post_type' => 'program', 's' => $search, 'orderby' => 'title', 'order' => 'ASC', - 'nopaging' => TRUE, + 'nopaging' => true, ); - + // https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters - if($ids !== FALSE) { + if ( false !== $ids ) { // if ids is passed, then select using ids across all categories $args['tax_query'] = array( 'relation' => 'AND', array( 'taxonomy' => 'category', 'field' => 'term_id', - 'terms' => explode(',', $ids), + 'terms' => explode( ',', $ids ), 'operator' => 'AND', ), ); } else { // if not ids, then test for other categories and search for those - - if(!empty($program_type) || !empty($interest_area) || !empty($location)) { + if ( ! empty( $program_type ) || ! empty( $interest_area ) || ! empty( $location ) ) { $args['tax_query'] = array( 'relation' => 'AND', ); - if(!empty($program_type)) { + if ( ! empty( $program_type ) ) { $args['tax_query'][] = array( 'taxonomy' => 'category', 'field' => 'term_id', @@ -58,7 +62,7 @@ function uri_program_finder_api_callback( $data ) { 'operator' => 'IN', ); } - if(!empty($interest_area)) { + if ( ! empty( $interest_area ) ) { $args['tax_query'][] = array( 'taxonomy' => 'category', 'field' => 'term_id', @@ -66,7 +70,7 @@ function uri_program_finder_api_callback( $data ) { 'operator' => 'IN', ); } - if(!empty($location)) { + if ( ! empty( $location ) ) { $args['tax_query'][] = array( 'taxonomy' => 'category', 'field' => 'term_id', @@ -77,9 +81,8 @@ function uri_program_finder_api_callback( $data ) { } } - $query = new WP_Query( $args ); - + $result = array(); // The Loop if ( $query->have_posts() ) { @@ -92,10 +95,10 @@ function uri_program_finder_api_callback( $data ) { 'excerpt' => get_the_excerpt(), 'link' => get_permalink(), 'program_types' => uri_program_finder_get_post_categories( get_the_ID() ), - 'image' => get_the_post_thumbnail() // accepts image size as argument + 'image' => get_the_post_thumbnail(), // accepts image size as argument ); } - + /* Restore original Post Data */ wp_reset_postdata(); } else { @@ -107,12 +110,13 @@ function uri_program_finder_api_callback( $data ) { } /** - * much like is_int, but allows commas too. - * @param str $str is a GET param - * @return str or bool false + * Much like is_int, but allows commas too. + * + * @param str $str is a GET param. + * @return str or bool false. */ -function uri_program_sanitize_ids($str) { - return ( preg_match('/[\d,]+/', $str) == 1 ) ? $str : FALSE; +function uri_program_sanitize_ids( $str ) { + return ( preg_match( '/[\d,]+/', $str ) == 1 ) ? $str : false; } /** @@ -120,11 +124,13 @@ function uri_program_sanitize_ids($str) { */ function uri_program_finder_register_api() { // accept category IDs and allow commas to delinieate multiple integers - //register_rest_route( 'uri-programs/v1', '/category/(?P[\d,]+)', array( - register_rest_route( 'uri-programs/v1', '/category', array( - 'methods' => 'GET', - 'callback' => 'uri_program_finder_api_callback', - ) ); + // register_rest_route( 'uri-programs/v1', '/category/(?P[\d,]+)', array( + register_rest_route( + 'uri-programs/v1', '/category', array( + 'methods' => 'GET', + 'callback' => 'uri_program_finder_api_callback', + ) + ); } add_action( 'rest_api_init', 'uri_program_finder_register_api' ); diff --git a/inc/uri-program-finder-fields.php b/inc/uri-program-finder-fields.php index d57e284..b5fa7f6 100755 --- a/inc/uri-program-finder-fields.php +++ b/inc/uri-program-finder-fields.php @@ -1,56 +1,60 @@ 'Program', - 'description' => 'Majors, etc.', - 'public' => true, - 'show_ui' => true, - 'show_in_menu' => true, - 'capability_type' => 'post', - 'hierarchical' => true, - 'rewrite' => array('slug' => 'program'), - 'query_var' => true, - 'has_archive' => true, - 'exclude_from_search' => false, - 'supports' => array('title','editor','excerpt','thumbnail','revisions','author'), - 'taxonomies' => array('post_tag', 'category', 'careers' ), - 'labels' => array ( - 'name' => 'Program', - 'singular_name' => 'Programs', - 'menu_name' => 'Programs', - 'add_new' => 'Add Program', - 'add_new_item' => 'Add New Program', - 'edit' => 'Edit', - 'edit_item' => 'Edit Program', - 'new_item' => 'New Program', - 'view' => 'View Program', - 'view_item' => 'View Program', - 'search_items' => 'Search Program', - 'not_found' => 'No Programs Found', - 'not_found_in_trash' => 'No Programs Found in Trash', - 'parent' => 'Parent Program', - ), - 'menu_icon' => 'dashicons-welcome-learn-more', - )); + register_post_type( + 'program', array( + 'label' => 'Program', + 'description' => 'Majors, etc.', + 'public' => true, + 'show_ui' => true, + 'show_in_menu' => true, + 'capability_type' => 'post', + 'hierarchical' => true, + 'rewrite' => array( 'slug' => 'program' ), + 'query_var' => true, + 'has_archive' => true, + 'exclude_from_search' => false, + 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'revisions', 'author' ), + 'taxonomies' => array( 'post_tag', 'category', 'careers' ), + 'labels' => array( + 'name' => 'Program', + 'singular_name' => 'Programs', + 'menu_name' => 'Programs', + 'add_new' => 'Add Program', + 'add_new_item' => 'Add New Program', + 'edit' => 'Edit', + 'edit_item' => 'Edit Program', + 'new_item' => 'New Program', + 'view' => 'View Program', + 'view_item' => 'View Program', + 'search_items' => 'Search Program', + 'not_found' => 'No Programs Found', + 'not_found_in_trash' => 'No Programs Found in Trash', + 'parent' => 'Parent Program', + ), + 'menu_icon' => 'dashicons-welcome-learn-more', + ) + ); uri_program_finder_create_taxonomy(); } -add_action('init', 'uri_program_finder_create_program_post_type'); +add_action( 'init', 'uri_program_finder_create_program_post_type' ); /** @@ -80,11 +84,11 @@ function uri_program_finder_create_taxonomy() { 'show_ui' => true, 'show_admin_column' => true, 'query_var' => true, - 'rewrite' => array('slug' => 'career'), - 'singular_label' => 'Career' + 'rewrite' => array( 'slug' => 'career' ), + 'singular_label' => 'Career', ); - - register_taxonomy('careers', array( 'program' ), $taxonomy_args); + + register_taxonomy( 'careers', array( 'program' ), $taxonomy_args ); } @@ -93,124 +97,124 @@ function uri_program_finder_create_taxonomy() { * Define the custom fields */ -if(function_exists("register_field_group")) -{ - register_field_group(array ( - 'id' => 'acf_program-fields', - 'title' => 'Program Fields', - 'fields' => array ( - array ( - 'key' => 'field_5a907505aed60', - 'label' => 'Department Website', - 'name' => 'department_website', - 'type' => 'text', - 'default_value' => '', - 'placeholder' => 'https://uri.edu/department', - 'prepend' => '', - 'append' => '', - 'formatting' => 'none', - 'maxlength' => '', - ), - array ( - 'key' => 'field_5a90756aaed61', - 'label' => 'Catalog Info', - 'name' => 'catalog_info', - 'type' => 'text', - 'instructions' => 'Enter the URL of the corresponding catalog page.', - 'default_value' => '', - 'placeholder' => 'https://web.uri.edu/catalog/music/', - 'prepend' => '', - 'append' => '', - 'formatting' => 'html', - 'maxlength' => '', - ), - array ( - 'key' => 'field_5a9076e700469', - 'label' => 'Course Descriptions', - 'name' => 'course_descriptions', - 'type' => 'text', - 'default_value' => '', - 'placeholder' => '', - 'prepend' => '', - 'append' => '', - 'formatting' => 'html', - 'maxlength' => '', - ), - array ( - 'key' => 'field_5a907649020b1', - 'label' => 'Admission Info', - 'name' => 'admission_info', - 'type' => 'text', - 'instructions' => 'URL to admission information', - 'default_value' => 'https://uri.edu/admission', - 'placeholder' => '', - 'prepend' => '', - 'append' => '', - 'formatting' => 'html', - 'maxlength' => '', - ), - array ( - 'key' => 'field_5a907670020b2', - 'label' => 'Apply', - 'name' => 'apply', - 'type' => 'select', - 'choices' => array ( - 'https://apply.commonapp.org/Login?ma=376&tref=program-finder' => 'Undergraduate', - 'https://web.uri.edu/graduate-school/admission/' => 'Graduate', +if ( function_exists( 'register_field_group' ) ) { + register_field_group( + array( + 'id' => 'acf_program-fields', + 'title' => 'Program Fields', + 'fields' => array( + array( + 'key' => 'field_5a907505aed60', + 'label' => 'Department Website', + 'name' => 'department_website', + 'type' => 'text', + 'default_value' => '', + 'placeholder' => 'https://uri.edu/department', + 'prepend' => '', + 'append' => '', + 'formatting' => 'none', + 'maxlength' => '', + ), + array( + 'key' => 'field_5a90756aaed61', + 'label' => 'Catalog Info', + 'name' => 'catalog_info', + 'type' => 'text', + 'instructions' => 'Enter the URL of the corresponding catalog page.', + 'default_value' => '', + 'placeholder' => 'https://web.uri.edu/catalog/music/', + 'prepend' => '', + 'append' => '', + 'formatting' => 'html', + 'maxlength' => '', + ), + array( + 'key' => 'field_5a9076e700469', + 'label' => 'Course Descriptions', + 'name' => 'course_descriptions', + 'type' => 'text', + 'default_value' => '', + 'placeholder' => '', + 'prepend' => '', + 'append' => '', + 'formatting' => 'html', + 'maxlength' => '', + ), + array( + 'key' => 'field_5a907649020b1', + 'label' => 'Admission Info', + 'name' => 'admission_info', + 'type' => 'text', + 'instructions' => 'URL to admission information', + 'default_value' => 'https://uri.edu/admission', + 'placeholder' => '', + 'prepend' => '', + 'append' => '', + 'formatting' => 'html', + 'maxlength' => '', + ), + array( + 'key' => 'field_5a907670020b2', + 'label' => 'Apply', + 'name' => 'apply', + 'type' => 'select', + 'choices' => array( + 'https://apply.commonapp.org/Login?ma=376&tref=program-finder' => 'Undergraduate', + 'https://web.uri.edu/graduate-school/admission/' => 'Graduate', + ), + 'default_value' => 'undergraduate', + 'allow_null' => 0, + 'multiple' => 0, + ), + array( + 'key' => 'field_5a9077420046a', + 'label' => 'Course Schedule', + 'name' => 'course_schedule', + 'type' => 'text', + 'instructions' => 'I\'m sorry.', + 'default_value' => 'https://uri.edu/course-schedule', + 'placeholder' => '', + 'prepend' => '', + 'append' => '', + 'formatting' => 'html', + 'maxlength' => '', + ), + array( + 'key' => 'field_5a9078363b98f', + 'label' => 'Time to Completion', + 'name' => 'time_to_completion', + 'type' => 'wysiwyg', + 'default_value' => '', + 'toolbar' => 'full', + 'media_upload' => 'no', + ), + array( + 'key' => 'field_5a90787f3b990', + 'label' => 'Application Deadline', + 'name' => 'application_deadline', + 'type' => 'wysiwyg', + 'default_value' => '', + 'toolbar' => 'full', + 'media_upload' => 'no', ), - 'default_value' => 'undergraduate', - 'allow_null' => 0, - 'multiple' => 0, - ), - array ( - 'key' => 'field_5a9077420046a', - 'label' => 'Course Schedule', - 'name' => 'course_schedule', - 'type' => 'text', - 'instructions' => 'I\'m sorry.', - 'default_value' => 'https://uri.edu/course-schedule', - 'placeholder' => '', - 'prepend' => '', - 'append' => '', - 'formatting' => 'html', - 'maxlength' => '', - ), - array ( - 'key' => 'field_5a9078363b98f', - 'label' => 'Time to Completion', - 'name' => 'time_to_completion', - 'type' => 'wysiwyg', - 'default_value' => '', - 'toolbar' => 'full', - 'media_upload' => 'no', - ), - array ( - 'key' => 'field_5a90787f3b990', - 'label' => 'Application Deadline', - 'name' => 'application_deadline', - 'type' => 'wysiwyg', - 'default_value' => '', - 'toolbar' => 'full', - 'media_upload' => 'no', ), - ), - 'location' => array ( - array ( - array ( - 'param' => 'post_type', - 'operator' => '==', - 'value' => 'program', - 'order_no' => 0, - 'group_no' => 0, + 'location' => array( + array( + array( + 'param' => 'post_type', + 'operator' => '==', + 'value' => 'program', + 'order_no' => 0, + 'group_no' => 0, + ), ), ), - ), - 'options' => array ( - 'position' => 'normal', - 'layout' => 'default', - 'hide_on_screen' => array ( + 'options' => array( + 'position' => 'normal', + 'layout' => 'default', + 'hide_on_screen' => array(), ), - ), - 'menu_order' => 0, - )); + 'menu_order' => 0, + ) + ); } diff --git a/inc/uri-program-finder-templating.php b/inc/uri-program-finder-templating.php index 0f9f9e6..268b5df 100755 --- a/inc/uri-program-finder-templating.php +++ b/inc/uri-program-finder-templating.php @@ -2,11 +2,14 @@ /** * Code to find the appropriate template * This allows templates to be included with the plugin, but overridden by a theme. + * + * @package uri-program-finder */ // Block direct requests -if ( !defined('ABSPATH') ) - die('-1'); +if ( ! defined( 'ABSPATH' ) ) { + die( '-1' ); +} @@ -18,21 +21,19 @@ * for a specific Post Type and will try to load the template * from out 'template-parts' directory. * - * - * @param string $template Template file that is being loaded. - * @return string Template file that should be loaded. + * @param string $template Template file that is being loaded. + * @return string Template file that should be loaded. */ function uri_program_finder_template_loader( $template ) { - + if ( is_single() && get_post_type() === 'program' ) { - + // if it's a people page, then override $template with the custom one $file = 'single-program.php'; if ( file_exists( uri_program_finder_locate_template( $file ) ) ) { $template = uri_program_finder_locate_template( $file ); } - } return $template; @@ -53,17 +54,16 @@ function uri_program_finder_template_loader( $template ) { * * http://jeroensormani.com/how-to-add-template-files-in-your-plugin/ * - * @param string $template_name Template to load. - * @param string $string $template_path Path to templates. - * @param string $default_path Default path to template files. - * @return string Path to the template file. + * @param string $template_name Template to load. + * @param string $template_path Path to templates. + * @param string $default_path Default path to template files. + * @return string Path to the template file. */ function uri_program_finder_locate_template( $template_name, $template_path = '', $default_path = '' ) { -// echo '
Template Name: ';
-// 	var_dump( $template_name );
-// 	echo '
'; - + // echo '
Template Name: ';
+	// var_dump( $template_name );
+	// echo '
'; // Set variable to search in woocommerce-plugin-templates folder of theme. if ( ! $template_path ) : $template_path = 'template-parts/'; @@ -75,10 +75,12 @@ function uri_program_finder_locate_template( $template_name, $template_path = '' endif; // Search template file in theme folder. - $template = locate_template( array( - $template_path . $template_name, - $template_name - ) ); + $template = locate_template( + array( + $template_path . $template_name, + $template_name, + ) + ); // Get plugins template file. if ( ! $template ) : @@ -98,25 +100,24 @@ function uri_program_finder_locate_template( $template_name, $template_path = '' * * @see wcpt_locate_template() * - * @param string $template_name Template to load. - * @param array $args Args passed for the template file. - * @param string $string $template_path Path to templates. - * @param string $default_path Default path to template files. + * @param string $template_name Template to load. + * @param array $args Args passed for the template file. + * @param string $template_path Path to templates. + * @param string $default_path Default path to template files. */ -function uri_program_finder_get_template( $template_name, $args = array(), $tempate_path = '', $default_path = '' ) { +function uri_program_finder_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { if ( is_array( $args ) && isset( $args ) ) : extract( $args ); endif; - $template_file = uri_program_finder_locate_template( $template_name, $tempate_path, $default_path ); + $template_file = uri_program_finder_locate_template( $template_name, $template_path, $default_path ); if ( ! file_exists( $template_file ) ) : _doing_it_wrong( __FUNCTION__, sprintf( '%s does not exist.', $template_file ), '1.0.0' ); return; endif; - include $template_file; } diff --git a/js/program-finder.js b/js/program-finder.js index 29a0cad..99fdac6 100644 --- a/js/program-finder.js +++ b/js/program-finder.js @@ -7,121 +7,128 @@ var timers = []; var searchTimer; // used to put a delay on keyup to slow down search requests var delay = 20; // set the delay between cards appearing on the page (in milliseconds) - window.addEventListener('load', initFinder, false); - - + window.addEventListener( 'load', initFinder, false ); + /** * Find program finder and set it up to be awesome. */ function initFinder() { - var el = document.getElementById('program-finder'); - convertForm(el); - - // Only load programs on startup if a URL query string exists - var querystring = getQueryString(); - if (querystring !== undefined) { - loadPrograms(); - } - } + var el = document.getElementById( 'program-finder' ); + convertForm( el ); + // Only load programs on startup if a URL query string exists + var querystring = getQueryString(); + if (querystring !== undefined) { + loadPrograms(); + } + } /** * Convert the exiting non-js form to something a little slicker + * * @param obj el the program finder parent element */ function convertForm(el) { var form, els, selects, textSearch, firstopt, blurs = 0; - - initResultsDiv(el); - initStatusDiv(el); - - els = el.querySelectorAll('.program-finder-nojs'); - for(var i=0; i
Loading...
'); + setStatus( 'loading','
Loading...
' ); } - - /** + + /** * Show the no results DIV */ function noResults() { - setStatus('empty','No matches found.'); + setStatus( 'empty','No matches found.' ); } - + /** * Clear the status div */ function clearStatus() { - statusDiv.className = ''; + statusDiv.className = ''; statusDiv.innerHTML = ''; } - /** * Create a result row's HTML + * * @param obj data * @return obj HTML element */ function createResultCard(data) { var result, i; - - result = document.createElement('a'); - result.setAttribute('class', 'cl-card'); - result.setAttribute('href', data.link); - //result.setAttribute('data-href', data.link); - result.setAttribute('data-id', data.id); - var badge, - badgeHtml = ''; - for (i=0; i' + badge[1] + ''; - } - } - - result.innerHTML = data.image; - result.innerHTML += '
    ' + badgeHtml + '
'; - result.innerHTML += '

' + data.title + '

'; - result.innerHTML += '
Explore
'; - + + result = document.createElement( 'a' ); + result.setAttribute( 'class', 'cl-card' ); + result.setAttribute( 'href', data.link ); + // result.setAttribute('data-href', data.link); + result.setAttribute( 'data-id', data.id ); + var badge, + badgeHtml = ''; + for (i = 0; i < data.program_types.length; i++) { + switch (data.program_types[i]['slug']) { + case 'bachelors': + badge = ['ba',"Bachelor's"]; + break; + case 'ph-d': + badge = ['phd','Ph.D.']; + break; + case 'graduate-certificate': + badge = ['cert','Certificate']; + break; + case 'masters': + badge = ['ma',"Master's"]; + break; + case 'professional-degree': + badge = ['pro','Professional']; + break; + default: + badge = []; + } + if (badge.length) { + badgeHtml += '
  • ' + badge[1] + '
  • '; + } + } + + result.innerHTML = data.image; + result.innerHTML += '
      ' + badgeHtml + '
    '; + result.innerHTML += '

    ' + data.title + '

    '; + result.innerHTML += '
    Explore
    '; + return result; } - /** * Listen for change events on the select menus + * * @param obj form the js form parent element * @param obj select the select element (what you'd expect to be "this") */ function changeListener(form, select) { - var selected, x; - - selected = getSelectedCategoryIds(form); - for (x in selected) { - updateQueryString(x,selected[x]); - } - loadPrograms(); + var selected, x; + + selected = getSelectedCategoryIds( form ); + for (x in selected) { + updateQueryString( x,selected[x] ); + } + loadPrograms(); } /** * Listen for change events on the select menus + * * @param obj input the input text element (what you'd expect to be "this") - * @param num blurs the number of input blur events + * @param num blurs the number of input blur events */ function textSearchListener(input, blurs) { - window.clearTimeout(searchTimer); - - if ($(input).is(':focus') == false && blurs > 1 || input.value != '') { - - searchTimer = window.setTimeout(function() { - updateQueryString('terms', input.value); - loadPrograms(); - }, 300); - - } + window.clearTimeout( searchTimer ); + + if ($( input ).is( ':focus' ) == false && blurs > 1 || input.value != '') { + + searchTimer = window.setTimeout( + function() { + updateQueryString( 'terms', input.value ); + loadPrograms(); + }, 300 + ); + + } + + } + + /** + * Clear the search form and load all programs + * + * @param obj form the js form parent element + * @param obj input the text search input + * @param obj selects the select menus + */ + function resetForm(form, input, selects) { + input.value = ''; + updateQueryString( 'terms', input.value ); + + $( selects ).each( + function() { + this.selectedIndex = -1; + $( this ).trigger( 'chosen:updated' ); + updateQueryString( $( this ).attr( 'name' ),'any' ); + } + ); + + $( '#js-form-reset' ).html( 'Clear' ); + + loadPrograms(); } - - - /** - * Clear the search form and load all programs - * @param obj form the js form parent element - * @param obj input the text search input - * @param obj selects the select menus - */ - function resetForm(form, input, selects) { - input.value = ''; - updateQueryString('terms', input.value); - - $(selects).each(function() { - this.selectedIndex = -1; - $(this).trigger('chosen:updated'); - updateQueryString($(this).attr('name'),'any'); - }); - - $('#js-form-reset').html('Clear'); - - loadPrograms(); - - } /** * Update the browser URL, and add the selection to the browser's history + * * @param str key is the querystring key * @param str value is the querystring value */ function updateQueryString(key, value) { var url, regex, separator, newURL; url = window.location.toString(); - regex = new RegExp("([?&])" + key + "=.*?(&|$)", "i"); - separator = url.indexOf('?') !== -1 ? "&" : "?"; - - if (url.match(regex)) { - newURL = url.replace(regex, '$1' + key + "=" + value + '$2'); - } - else { + regex = new RegExp( "([?&])" + key + "=.*?(&|$)", "i" ); + separator = url.indexOf( '?' ) !== -1 ? "&" : "?"; + + if (url.match( regex )) { + newURL = url.replace( regex, '$1' + key + "=" + value + '$2' ); + } else { newURL = url + separator + key + "=" + value; - } - + } + if (history.pushState) { - window.history.pushState({path:newURL}, '', newURL); + window.history.pushState( {path:newURL}, '', newURL ); } - - + } /** - * get the category ids from the select menus + * Get the category ids from the select menus + * * @param obj form the js form parent element * @return arr */ @@ -288,40 +300,41 @@ var cats, selects, vals, i; cats = {}; - selects = form.querySelectorAll('select'); - - for(i=0; i
    - - + +
    >
    @@ -30,11 +33,11 @@
    @@ -44,27 +47,31 @@
    →', 'uri-modern' ), array( 'span' => array( 'class' => array() ) ) ), the_title( '"', '"', false ) - ) ); - - wp_link_pages( array( - 'before' => '', - ) ); + ) + ); + + wp_link_pages( + array( + 'before' => '', + ) + ); ?> - +

    Time to Completion

    - +

    Application Deadline

    @@ -72,37 +79,37 @@ - + - + - + - + - + - + @@ -113,14 +120,14 @@ - + the_post_navigation(); + + // If comments are open or we have at least one comment, load up the comment template. + if ( comments_open() || get_comments_number() ) : + comments_template(); + endif; + ?> +
    diff --git a/uri-program-finder.php b/uri-program-finder.php index ff6f3ca..e5ad2cc 100755 --- a/uri-program-finder.php +++ b/uri-program-finder.php @@ -1,34 +1,33 @@ -@author: Brandon Fuller -*/ +/** + * Plugin Name: URI Program Finder + * Plugin URI: http://www.uri.edu + * Description: Program finder tools + * Version: 1.1.0 + * Author: URI Web Communications + * Author URI: + * + * @package uri-program-finder + * @author: John Pennypacker + * @author: Brandon Fuller + */ // Block direct requests -if ( !defined('ABSPATH') ) - die('-1'); +if ( ! defined( 'ABSPATH' ) ) { + die( '-1' ); +} define( 'URI_PROGRAM_FINDER_PATH', plugin_dir_path( __FILE__ ) ); -include( URI_PROGRAM_FINDER_PATH . 'inc/uri-program-finder-api.php'); +include( URI_PROGRAM_FINDER_PATH . 'inc/uri-program-finder-api.php' ); -include( URI_PROGRAM_FINDER_PATH . 'inc/uri-program-finder-fields.php'); +include( URI_PROGRAM_FINDER_PATH . 'inc/uri-program-finder-fields.php' ); -include( URI_PROGRAM_FINDER_PATH . 'inc/uri-program-finder-templating.php'); +include( URI_PROGRAM_FINDER_PATH . 'inc/uri-program-finder-templating.php' ); // This URL pull multiple categories (need to remove page title): // https://www.uri.edu/programs/?cat=24,26 - - - - /** * Loads up the javascript */ @@ -36,15 +35,15 @@ function uri_program_finder_scripts() { $values = array( 'base' => get_site_url(), ); - + $plugin_handle = 'uri-program-finder'; // Register the script like this for a plugin: wp_register_script( $plugin_handle, plugins_url( '/js/program-finder.js', __FILE__ ) ); wp_localize_script( $plugin_handle, 'URIProgramFinder', $values ); - + $chosen_handle = 'uri-program-finder-chosen-js'; wp_register_script( $chosen_handle, plugins_url( '/chosen/chosen.jquery.min.js', __FILE__ ) ); - + // For either a plugin or a theme, you can then enqueue the script: wp_enqueue_script( $plugin_handle ); wp_enqueue_script( $chosen_handle ); @@ -65,22 +64,22 @@ function uri_program_finder_styles() { /** * Get a top-level category id by name - * @param str the name of the category + * + * @param str $needle the name of the category. */ -function uri_program_finder_get_program_category_id( $needle='Program Type' ) { +function uri_program_finder_get_program_category_id( $needle = 'Program Type' ) { // return 136; //14 on local + static $parent = false; - static $parent = FALSE; - - if($parent !== FALSE) { + if ( false !== $parent ) { return $parent; } - + // get top-level categories - $categories = uri_program_finder_get_children(0); - - foreach($categories as $c) { - if($c['name'] == $needle) { + $categories = uri_program_finder_get_children( 0 ); + + foreach ( $categories as $c ) { + if ( $c['name'] == $needle ) { $parent = $c['id']; } } @@ -91,25 +90,26 @@ function uri_program_finder_get_program_category_id( $needle='Program Type' ) { /** * Get the program type categories for a given post - * @param int $id is the post id + * + * @param int $id is the post id. */ -function uri_program_finder_get_post_categories($id) { +function uri_program_finder_get_post_categories( $id ) { $args = array( - 'parent' => uri_program_finder_get_program_category_id() + 'parent' => uri_program_finder_get_program_category_id(), ); - $cats = wp_get_post_categories(get_the_ID(), $args); + $cats = wp_get_post_categories( get_the_ID(), $args ); $categories = array(); - foreach($cats as $c) { - $cat = get_term($c); + foreach ( $cats as $c ) { + $cat = get_term( $c ); $categories[] = array( 'term_id' => $cat->term_id, 'name' => $cat->name, 'description' => $cat->description, - 'slug' => $cat->slug + 'slug' => $cat->slug, ); } - + return $categories; } @@ -119,92 +119,96 @@ function uri_program_finder_get_post_categories($id) { /** * Shortcode callback -- generates a form, loads a script */ -function uri_program_finder_shortcode($attributes, $content, $shortcode) { +function uri_program_finder_shortcode( $attributes, $content, $shortcode ) { uri_program_finder_scripts(); - uri_program_finder_styles(); + uri_program_finder_styles(); // normalize attribute keys, lowercase - $attributes = array_change_key_case((array)$attributes, CASE_LOWER); - -// echo '
    ', print_r($attributes['categories'], TRUE), '
    '; + $attributes = array_change_key_case( (array) $attributes, CASE_LOWER ); + // echo '
    ', print_r($attributes['categories'], TRUE), '
    '; // override default attributes with user attributes - $attributes = shortcode_atts(array( - 'title' => 'Categories', // slug, slug2, slug3 - 'quote' => '', - 'citation' => '', - 'photo_id' => '' - ), $attributes, $shortcode); - + $attributes = shortcode_atts( + array( + 'title' => 'Categories', // slug, slug2, slug3 + 'quote' => '', + 'citation' => '', + 'photo_id' => '', + ), $attributes, $shortcode + ); $args = array( - 'before_widget' => '
    ', + 'before_widget' => '
    ', 'after_widget' => '
    ', 'before_title' => '

    ', - 'after_title' => '

    ' + 'after_title' => '', ); - + // specify what categories to remove, by slug $removecats = array( - 'college' + 'college', ); $exclude = array(); - foreach($removecats as $r) { - $exclude[] = get_term_by('slug', $r, 'category')->term_id; + foreach ( $removecats as $r ) { + $exclude[] = get_term_by( 'slug', $r, 'category' )->term_id; } - $categories = uri_program_finder_get_children(0, $exclude); - + $categories = uri_program_finder_get_children( 0, $exclude ); - // specify how the remaining categories should be sorted, by slug $catorder = array( - 'program-type', - 'interest-area', - 'location' + 'program-type', + 'interest-area', + 'location', ); - usort($categories, function ($a, $b) use ($catorder) { - $pos_a = array_search($a['slug'], $catorder); - $pos_b = array_search($b['slug'], $catorder); + usort( + $categories, function ( $a, $b ) use ( $catorder ) { + $pos_a = array_search( $a['slug'], $catorder ); + $pos_b = array_search( $b['slug'], $catorder ); return $pos_a - $pos_b; - }); - + } + ); - // build the form + // build the form return uri_program_finder_make_form( $categories ); - + } add_shortcode( 'programs-categories', 'uri_program_finder_shortcode' ); /** * Create the HTML for the form - * @param arr $categories arrays used to build select menus + * + * @param arr $categories arrays used to build select menus. * @return str */ -function uri_program_finder_make_form($categories) { +function uri_program_finder_make_form( $categories ) { // get the search string value from the url $query_value = ''; - if( isset($_GET['terms'])) { - $query_value = sanitize_title ( $_GET['terms'] ); + if ( isset( $_GET['terms'] ) ) { + $query_value = sanitize_title( $_GET['terms'] ); } - - $text_input = ''; + + $text_input = ''; $output = '
    '; $output .= '
    '; $output .= '
    '; - $output .= ''; + $output .= ''; $output .= $text_input; $output .= ''; $output .= '
    '; $output .= '
    '; - - foreach($categories as $c) { - $subcats = uri_program_finder_get_children($c['id']); - array_unshift( $subcats, array('id'=>'', 'name' => $c['name']) ); + foreach ( $categories as $c ) { + $subcats = uri_program_finder_get_children( $c['id'] ); + array_unshift( + $subcats, array( + 'id' => '', + 'name' => $c['name'], + ) + ); $output .= '
    '; $output .= '
    '; @@ -213,35 +217,40 @@ function uri_program_finder_make_form($categories) { $output .= '
    '; $output .= '
    '; } - - - // now create the js form - $output .= '