From 2ccd55db67d88722c93e0347b6c0aa2c79ec27cc Mon Sep 17 00:00:00 2001 From: szk11001 Date: Wed, 4 Nov 2015 13:45:19 -0500 Subject: [PATCH 1/5] Add UC People Widget -Add UC People widget, using same form UI as a Person post -Change Specific People field to return ID --Makes it easier to fill out the 'post__in' array value in $args array --- acf-export.php | 11 +- uc-people-widget.php | 257 +++++++++++++++++++++++++++++++++++++++++++ uc-people.php | 2 +- 3 files changed, 267 insertions(+), 3 deletions(-) create mode 100644 uc-people-widget.php diff --git a/acf-export.php b/acf-export.php index 34d0a2f..a8bce2b 100644 --- a/acf-export.php +++ b/acf-export.php @@ -28,7 +28,7 @@ if(function_exists("register_field_group")) 'name' => 'specific_people', 'type' => 'relationship', 'instructions' => 'Choose specific people to display. Leave right side blank to display all People.', - 'return_format' => 'object', + 'return_format' => 'id', 'post_type' => array ( 0 => 'person', ), @@ -120,6 +120,13 @@ if(function_exists("register_field_group")) 'group_no' => 0, ), ), + array ( + array ( + 'param' => 'widget', + 'operator' => '==', + 'value' => 'uc_people_widget', + ), + ), ), 'options' => array ( 'position' => 'normal', @@ -131,7 +138,7 @@ if(function_exists("register_field_group")) )); } -//adds boxes to the "People" pages. +//adds boxes to the "People" pages. if(function_exists("register_field_group")) { register_field_group(array ( diff --git a/uc-people-widget.php b/uc-people-widget.php new file mode 100644 index 0000000..e33a72b --- /dev/null +++ b/uc-people-widget.php @@ -0,0 +1,257 @@ + __CLASS__, 'description' => 'A widget to display People' ) ); + } + + private function get_people_grid( $args, $information_to_display ){ + $the_query = new WP_Query( $args ); + $out = ''; + if( $the_query->have_posts() ){ + $out = '
'; + $person_count = 1; + + while( $the_query->have_posts() ){ + $the_query->the_post(); + $out .= '
'; + $out .= '
'; + + $out .= ''; + if (in_array('photo', $information_to_display)) { + $out .= '
'.get_the_post_thumbnail('large').'
'; + }; + if (in_array('first_name', $information_to_display) || in_array('middle_name', $information_to_display) || in_array('last_name', $information_to_display)){ + $out .= '

'; + if (in_array('first_name', $information_to_display)) { + $out .= get_field('first_name').' '; + }; + if (in_array('middle_name', $information_to_display)) { + $out .= get_field('middle_name').' '; + }; + if (in_array('last_name', $information_to_display)) { + $out .= get_field('last_name'); + }; + $out .= '

'; + }; + $out .= '
'; + + foreach( $this->fields as $f ){ + if( $f == 'file' && in_array('file', $information_to_display) ){ + $file = get_field('file'); + $out .= '

'.$file[title].''.'

'; + } elseif( $f == 'email' && in_array( 'email', $information_to_display ) ){ + $out .= '

'.get_field('email').''.'

'; + } else if( $f == 'title' && in_array( 'title', $information_to_display ) ){ + $out .= '

'.get_field('title').'

'; + } else { + if ( in_array($f, $information_to_display) ) { + $out .= '

'.get_field($f).'

'; + }; + } + } + $out .= '
'; // div.person and div.col-sm-3 + + // check to see if we need to close this row... + if ($person_count % 4 == 0){ + // if this is the 4th, 8th, 16th, etc person... + echo '
'; + } + $person_count++; + } //end of while posts + $out .= '
'; // div.row + } else { + + } //end of if posts + + return $out; + } + + private function createTextCell( $field, $information_to_display ){ + $cell = ''; + if (in_array($field, $information_to_display)) { + $cell .= ''.get_field($field).''; + } + return $cell; + } + + private function get_people_table( $args, $information_to_display ){ + $the_query = new WP_Query( $args ); + $out = ''; + if ( $the_query->have_posts() ) { + // how many columns? Based on what they chose to display. + $num_cols = count($information_to_display); + + $out .= ''; + $out.= 'List of People'; + $out .= ''; + + $nameCell = false; + foreach($information_to_display as $value){ + if ($value == 'first_name' || $value == 'middle_name' || $value == 'last_name'){ + if ($nameCell == false){ + $out .= ''; + $nameCell = true; + }; + } elseif ($value == 'photo') { + $out .= ''; + } else { + $arr = get_field_object('field_'.$value); + $label = $arr['label']; + $out .= ''; + } + } + $out .= ''; + $out .= ''; + + while ( $the_query->have_posts() ) { + $the_query->the_post(); + + $out .= ''; + if (in_array('photo', $information_to_display)) { + $out .= ''; + } + if (in_array('first_name', $information_to_display) || in_array('middle_name', $information_to_display) || in_array('last_name', $information_to_display)){ + $out .= ''; + } + + foreach( $this->fields as $f ){ + if( $f == 'file' && in_array('file', $information_to_display) ){ + $file = get_field('file'); + $out .= ''; + } else { + $out .= $this->createTextCell($f, $information_to_display); + } + } + $out .= ''; + } //end of posts + $out .= ''; + $out .= '
Name '.$label.'
'.the_post_thumbnail(array('65', '65')).''; + if (in_array('first_name', $information_to_display)) { + $out .= get_field('first_name'); + $out .= ' '; + }; + if (in_array('middle_name', $information_to_display)) { + $out .= get_field('middle_name'); + $out .= ' '; + }; + if (in_array('last_name', $information_to_display)) { + $out .= get_field('last_name'); + }; + $out .= ''.$file[title].''; + } else if( $f == 'email' && in_array('email', $information_to_display) ){ + $out .= ''.get_field('email').'
'; + } else { + // no posts found + } + return $out; + } + + public function widget( $args, $instance ){ + $settings = array( 'layout' => '', 'specific_people' => '', 'specific_groups' => '', 'specific_tags' => '', 'break_into_groups' => '', 'information_to_display' => ''); + foreach( $settings as $k => $v ){ + $settings[$k] = get_field( $k, 'widget_' . $args['widget_id'] ); + } + + $wpQueryArgs = array( + 'posts_per_page' => -1, + 'post_type' => 'person', + 'orderby' => 'menu_order title', + 'order' => 'ASC', + 'post__in' => ( ( !is_null($settings['specific_people']) ) ? $settings['specific_people'] : array() ) + ); + + if ( $settings['specific_groups'] != false || $settings['specific_tags'] != false ){ + $tax_query = array(); + + if ( $settings['specific_groups'] != false ) { + $tax_query[] = array( + 'taxonomy' => 'group', + 'field' => 'term_id', + 'terms' => $settings['specific_groups'] + ); + } + if ( $settings['specific_tags'] != false ) { + $tax_query[] = array( + 'taxonomy' => 'persontag', + 'field' => 'term_id', + 'terms' => $settings['specific_tags'] + ); + } + $wpQueryArgs['tax_query'] = $tax_query; + } + + if( $settings['break_into_groups'] != false ){ + // get all the people + $the_query = new WP_Query( $wpQueryArgs ); + + // focusing on just the people, not the rest of the query. + $people = $the_query->posts; + + // look at each person, and see each group used, use that to create a list of terms. + $groups_in_use = array(); + + foreach($people as $value){ + //$id = $value->ID; + $id = $value; + $terms = get_the_terms($id, 'group'); + if (is_array($terms)){ + foreach($terms as $key => $v){ + //duplicates will overwrite themselves... + $slug = $v->slug; + $groups_in_use[$slug]= $slug; + } + }; + } + + // sort the groups in use alphabetically + sort($groups_in_use); + + // for each item in the list of terms, do a new query, but this time we're going to limit it to ONLY items from that one group. + foreach($groups_in_use as $value){ + + // this sets up the query we'll need, and will overwrite any group queries from the original settings. + $tax_query = array(); + $group_query = array( + 'taxonomy' => 'group', + 'field' => 'slug', + 'terms' => $value + ); + array_push($tax_query, $group_query); + $wpQueryArgs['tax_query'] = $tax_query; + + // with $arg updated, let's do a new query. + echo '

'.get_term_by('slug', $value, 'group')->name.'

'; + + if( $settings['layout'] == 'grid' ){ + echo $this->get_people_grid( $wpQueryArgs, $settings['information_to_display'] ); + } else if( $settings['layout'] == 'table' ){ + echo $this->get_people_table( $wpQueryArgs, $settings['information_to_display'] ); + } + } + } else { + if( $settings['layout'] == 'grid' ){ + echo $this->get_people_grid( $wpQueryArgs, $settings['information_to_display'] ); + } else if( $settings['layout'] == 'table' ){ + echo $this->get_people_table( $wpQueryArgs, $settings['information_to_display'] ); + } + } + } + + public function form( $instance ){ + //Form is handled by ACF, code can be found in wp-content/plugins/uc-people/acf-export.php + } + + public function update( $new_instance, $old_instance ){ + //Update is handled by ACF + } +} + +function register_uc_people_widget(){ + register_widget( 'UC_People_Widget' ); +} +add_action( 'widgets_init', 'register_uc_people_widget' ); + +?> \ No newline at end of file diff --git a/uc-people.php b/uc-people.php index 6925df3..e86d172 100644 --- a/uc-people.php +++ b/uc-people.php @@ -12,7 +12,7 @@ if ( ! defined( 'WPINC' ) ) { } require 'acf-export.php'; require_once(WP_CONTENT_DIR . '/ldap.php'); - +include 'uc-people-widget.php'; function create_custom_custom_post_type(){ $labels = array( From a282f7b3258b018267f0883a8d5a7d7da4f7ff43 Mon Sep 17 00:00:00 2001 From: szk11001 Date: Mon, 9 Nov 2015 11:33:19 -0500 Subject: [PATCH 2/5] Fix for tags not working when grouping Previously, tags weren't working properly when breaking into groups --- uc-people-widget.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/uc-people-widget.php b/uc-people-widget.php index e33a72b..ede4233 100644 --- a/uc-people-widget.php +++ b/uc-people-widget.php @@ -165,20 +165,26 @@ Class UC_People_Widget extends WP_Widget { if ( $settings['specific_groups'] != false || $settings['specific_tags'] != false ){ $tax_query = array(); + $isGroupSet = false; + $isTagSet = false; if ( $settings['specific_groups'] != false ) { - $tax_query[] = array( + $isGroupSet = true; + $taxGroupArray = array( 'taxonomy' => 'group', 'field' => 'term_id', 'terms' => $settings['specific_groups'] ); + $tax_query[] = $taxGroupArray; } if ( $settings['specific_tags'] != false ) { - $tax_query[] = array( + $isTagSet = true; + $taxTagArray = array( 'taxonomy' => 'persontag', 'field' => 'term_id', 'terms' => $settings['specific_tags'] ); + $tax_query[] = $taxTagArray; } $wpQueryArgs['tax_query'] = $tax_query; } @@ -220,6 +226,12 @@ Class UC_People_Widget extends WP_Widget { 'terms' => $value ); array_push($tax_query, $group_query); + /*if( $isGroupSet != false ){ + array_push($tax_query, $taxGroupArray); + }*/ + if( $isTagSet != false ){ + array_push($tax_query, $taxTagArray); + } $wpQueryArgs['tax_query'] = $tax_query; // with $arg updated, let's do a new query. From 4e98304d06f90d1012577034043bd6105cefdbaa Mon Sep 17 00:00:00 2001 From: szk11001 Date: Wed, 11 Nov 2015 15:13:37 -0500 Subject: [PATCH 3/5] People Sorting in Widget & Clean URL's * Sort people in tables and grids by last name then first name * Change URL structure for viewing a person to base_url/person/firstname-lastname --- uc-people-widget.php | 117 ++++++++++++++++++++++++------------------- uc-people.php | 4 +- 2 files changed, 69 insertions(+), 52 deletions(-) diff --git a/uc-people-widget.php b/uc-people-widget.php index ede4233..8e265cc 100644 --- a/uc-people-widget.php +++ b/uc-people-widget.php @@ -14,25 +14,27 @@ Class UC_People_Widget extends WP_Widget { $out = '
'; $person_count = 1; - while( $the_query->have_posts() ){ - $the_query->the_post(); - $out .= '
'; + $people = $the_query->get_posts(); + usort( $people, array('UC_People_Widget', 'sort_by_last_then_first') ); + + foreach( $people as $id ){ + $out .= '
'; $out .= '
'; - $out .= ''; + $out .= ''; if (in_array('photo', $information_to_display)) { - $out .= '
'.get_the_post_thumbnail('large').'
'; + $out .= '
'.get_the_post_thumbnail( $id, 'large').'
'; }; if (in_array('first_name', $information_to_display) || in_array('middle_name', $information_to_display) || in_array('last_name', $information_to_display)){ $out .= '

'; if (in_array('first_name', $information_to_display)) { - $out .= get_field('first_name').' '; + $out .= get_field('first_name', $id ).' '; }; if (in_array('middle_name', $information_to_display)) { - $out .= get_field('middle_name').' '; + $out .= get_field('middle_name', $id ).' '; }; if (in_array('last_name', $information_to_display)) { - $out .= get_field('last_name'); + $out .= get_field('last_name', $id ); }; $out .= '

'; }; @@ -40,15 +42,15 @@ Class UC_People_Widget extends WP_Widget { foreach( $this->fields as $f ){ if( $f == 'file' && in_array('file', $information_to_display) ){ - $file = get_field('file'); + $file = get_field('file', $id ); $out .= '

'.$file[title].''.'

'; } elseif( $f == 'email' && in_array( 'email', $information_to_display ) ){ - $out .= '

'.get_field('email').''.'

'; + $out .= '

'.get_field('email', $id ).''.'

'; } else if( $f == 'title' && in_array( 'title', $information_to_display ) ){ - $out .= '

'.get_field('title').'

'; + $out .= '

'.get_field('title', $id ).'

'; } else { if ( in_array($f, $information_to_display) ) { - $out .= '

'.get_field($f).'

'; + $out .= '

'.get_field($f, $id ).'

'; }; } } @@ -60,7 +62,7 @@ Class UC_People_Widget extends WP_Widget { echo '
'; } $person_count++; - } //end of while posts + } $out .= '
'; // div.row } else { @@ -69,18 +71,31 @@ Class UC_People_Widget extends WP_Widget { return $out; } - private function createTextCell( $field, $information_to_display ){ + private static function sort_by_last_then_first($a,$b) { + setlocale(LC_CTYPE, 'en_US.UTF8'); + $r = strnatcasecmp( iconv('UTF-8', 'ASCII//TRANSLIT', get_field('last_name', $a)), iconv('UTF-8', 'ASCII//TRANSLIT', get_field('last_name', $b)) ); + if( $r === 0 ){ + $r = strnatcasecmp( iconv('UTF-8', 'ASCII//TRANSLIT', get_field('first_name', $a)), iconv('UTF-8', 'ASCII//TRANSLIT', get_field('first_name', $b)) ); + } + return $r; + } + + private function createTextCell( $field, $information_to_display, $id ){ $cell = ''; if (in_array($field, $information_to_display)) { - $cell .= ''.get_field($field).''; + $cell .= ''.get_field($field, $id ).''; } return $cell; } private function get_people_table( $args, $information_to_display ){ $the_query = new WP_Query( $args ); + $out = ''; if ( $the_query->have_posts() ) { + $people = $the_query->get_posts(); + usort( $people, array('UC_People_Widget', 'sort_by_last_then_first') ); + // how many columns? Based on what they chose to display. $num_cols = count($information_to_display); @@ -106,41 +121,39 @@ Class UC_People_Widget extends WP_Widget { $out .= ''; $out .= ''; - while ( $the_query->have_posts() ) { - $the_query->the_post(); - - $out .= ''; - if (in_array('photo', $information_to_display)) { - $out .= ''.the_post_thumbnail(array('65', '65')).''; - } - if (in_array('first_name', $information_to_display) || in_array('middle_name', $information_to_display) || in_array('last_name', $information_to_display)){ - $out .= ''; - if (in_array('first_name', $information_to_display)) { - $out .= get_field('first_name'); - $out .= ' '; - }; - if (in_array('middle_name', $information_to_display)) { - $out .= get_field('middle_name'); - $out .= ' '; - }; - if (in_array('last_name', $information_to_display)) { - $out .= get_field('last_name'); - }; - $out .= ''; - } + foreach( $people as $id ){ + $out .= ''; + if (in_array('photo', $information_to_display)) { + $out .= ''.get_the_post_thumbnail($id, array('65', '65')).''; + } + if (in_array('first_name', $information_to_display) || in_array('middle_name', $information_to_display) || in_array('last_name', $information_to_display)){ + $out .= ''; + if (in_array('first_name', $information_to_display)) { + $out .= get_field('first_name', $id ); + $out .= ' '; + }; + if (in_array('middle_name', $information_to_display)) { + $out .= get_field('middle_name', $id ); + $out .= ' '; + }; + if (in_array('last_name', $information_to_display)) { + $out .= get_field('last_name', $id ); + }; + $out .= ''; + } - foreach( $this->fields as $f ){ - if( $f == 'file' && in_array('file', $information_to_display) ){ - $file = get_field('file'); - $out .= ''.$file[title].''; - } else if( $f == 'email' && in_array('email', $information_to_display) ){ - $out .= ''.get_field('email').''; - } else { - $out .= $this->createTextCell($f, $information_to_display); - } + foreach( $this->fields as $f ){ + if( $f == 'file' && in_array('file', $information_to_display) ){ + $file = get_field('file', $id ); + $out .= ''.$file[title].''; + } else if( $f == 'email' && in_array('email', $information_to_display) ){ + $out .= ''.get_field('email', $id ).''; + } else { + $out .= $this->createTextCell($f, $information_to_display, $id ); } - $out .= ''; - } //end of posts + } + $out .= ''; + } $out .= ''; $out .= ''; } else { @@ -158,9 +171,11 @@ Class UC_People_Widget extends WP_Widget { $wpQueryArgs = array( 'posts_per_page' => -1, 'post_type' => 'person', - 'orderby' => 'menu_order title', - 'order' => 'ASC', - 'post__in' => ( ( !is_null($settings['specific_people']) ) ? $settings['specific_people'] : array() ) + //'orderby' => 'menu_order title', + //'order' => 'ASC', + //'order' => 'post__in', + 'post__in' => ( ( !is_null($settings['specific_people']) ) ? $settings['specific_people'] : array() ), + 'fields' => 'ids' ); if ( $settings['specific_groups'] != false || $settings['specific_tags'] != false ){ diff --git a/uc-people.php b/uc-people.php index e86d172..072c914 100644 --- a/uc-people.php +++ b/uc-people.php @@ -34,7 +34,9 @@ function create_custom_custom_post_type(){ 'menu_icon' => 'dashicons-groups', 'supports' => array( 'tags', 'thumbnail', 'revisions', 'page-attributes', 'author' ), 'has_archive' => true, - 'rewrite' => false + 'rewrite' => array( + 'slug' => '/person' + ) ); register_post_type( 'person', $args ); From d0b11a69a2e4d8427576ae79a9bb78831e7fe124 Mon Sep 17 00:00:00 2001 From: szk11001 Date: Mon, 30 Nov 2015 13:21:44 -0500 Subject: [PATCH 4/5] Add URL field to Person and sort groups by order * Allow users to add a URL that can also be imported via the UC People Importer * Sort groups by order --- acf-export.php | 16 +++++++++++++ uc-people-widget.php | 54 +++++++++++++++++++++++++++++--------------- uc-people.php | 46 +++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 18 deletions(-) diff --git a/acf-export.php b/acf-export.php index a8bce2b..9806066 100644 --- a/acf-export.php +++ b/acf-export.php @@ -306,6 +306,22 @@ if(function_exists("register_field_group")) 'formatting' => 'html', 'maxlength' => '', ), + array ( + 'key' => 'field_url', + 'label' => 'URL', + 'name' => 'url', + 'type' => 'url', + 'instructions' => '', + 'required' => 0, + 'conditional_logic' => 0, + 'wrapper' => array ( + 'width' => '', + 'class' => '', + 'id' => '', + ), + 'default_value' => '', + 'placeholder' => '', + ), ), 'location' => array ( array ( diff --git a/uc-people-widget.php b/uc-people-widget.php index 8e265cc..2efc742 100644 --- a/uc-people-widget.php +++ b/uc-people-widget.php @@ -7,6 +7,40 @@ Class UC_People_Widget extends WP_Widget { parent::__construct( 'uc_people_widget', 'UC People', array( 'classname' => __CLASS__, 'description' => 'A widget to display People' ) ); } + private static function sort_by_last_then_first($a,$b) { + setlocale(LC_CTYPE, 'en_US.UTF8'); // Using setlocale and iconv incase a name has an accent or other similar characters in them + $r = strnatcasecmp( iconv('UTF-8', 'ASCII//TRANSLIT', get_field('last_name', $a)), iconv('UTF-8', 'ASCII//TRANSLIT', get_field('last_name', $b)) ); + if( $r === 0 ){ + $r = strnatcasecmp( iconv('UTF-8', 'ASCII//TRANSLIT', get_field('first_name', $a)), iconv('UTF-8', 'ASCII//TRANSLIT', get_field('first_name', $b)) ); + } + return $r; + } + + private static function sort_group_by_order( $a, $b ){ + // Getting the order for groups $a and $b + $groupA = get_term_by('slug', $a, 'group')->term_id; + $array_orderGroupA = get_option( "taxonomy_{$groupA}" ); + $orderGroupA = $array_orderGroupA['group_order']; + + $groupB = get_term_by('slug', $b, 'group')->term_id; + $array_orderGroupB = get_option( "taxonomy_{$groupB}" ); + $orderGroupB = $array_orderGroupB['group_order']; + + $r = strnatcasecmp( $orderGroupA, $orderGroupB ); + if( $r === 0 ){ + $r = strnatcasecmp( $a, $b ); // If groups have the same order, group them by name alphabetically + } + return $r; + } + + private function createTextCell( $field, $information_to_display, $id ){ + $cell = ''; + if (in_array($field, $information_to_display)) { + $cell .= ''.get_field($field, $id ).''; + } + return $cell; + } + private function get_people_grid( $args, $information_to_display ){ $the_query = new WP_Query( $args ); $out = ''; @@ -71,23 +105,6 @@ Class UC_People_Widget extends WP_Widget { return $out; } - private static function sort_by_last_then_first($a,$b) { - setlocale(LC_CTYPE, 'en_US.UTF8'); - $r = strnatcasecmp( iconv('UTF-8', 'ASCII//TRANSLIT', get_field('last_name', $a)), iconv('UTF-8', 'ASCII//TRANSLIT', get_field('last_name', $b)) ); - if( $r === 0 ){ - $r = strnatcasecmp( iconv('UTF-8', 'ASCII//TRANSLIT', get_field('first_name', $a)), iconv('UTF-8', 'ASCII//TRANSLIT', get_field('first_name', $b)) ); - } - return $r; - } - - private function createTextCell( $field, $information_to_display, $id ){ - $cell = ''; - if (in_array($field, $information_to_display)) { - $cell .= ''.get_field($field, $id ).''; - } - return $cell; - } - private function get_people_table( $args, $information_to_display ){ $the_query = new WP_Query( $args ); @@ -228,7 +245,8 @@ Class UC_People_Widget extends WP_Widget { } // sort the groups in use alphabetically - sort($groups_in_use); + //sort($groups_in_use); + usort($groups_in_use, array('UC_People_Widget', 'sort_group_by_order') ); // for each item in the list of terms, do a new query, but this time we're going to limit it to ONLY items from that one group. foreach($groups_in_use as $value){ diff --git a/uc-people.php b/uc-people.php index 072c914..427ce24 100644 --- a/uc-people.php +++ b/uc-people.php @@ -79,6 +79,51 @@ function create_custom_custom_post_type(){ } add_action( 'init', 'create_custom_custom_post_type', 0 ); +// Add Order field to Add New Group Page +function uc_people_new_group_order_field(){ + ?> +
+ + +

Enter a value for this field or leave it blank

+
+ term_id}" ); + $order = $term_meta['group_order']; + ?> + + + + +

Enter a value for this field or leave it blank

+ + + 'Office Hours', 'courses' => 'Courses', 'about' => 'About', + 'url' => 'Website', ); foreach( $data as $k => $v ){ From aadfa2636f7233e552ad418714d30fb5db4b914d Mon Sep 17 00:00:00 2001 From: szk11001 Date: Wed, 2 Dec 2015 15:47:54 -0500 Subject: [PATCH 5/5] Set imported person as author & multiple titles support * If imported person is a user, then make them the author of their own Person page * Can now enter multiple titles, separated by a semicolon --- uc-people-widget.php | 18 +++++++++++++++--- uc-people.php | 25 ++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/uc-people-widget.php b/uc-people-widget.php index 2efc742..3748fbd 100644 --- a/uc-people-widget.php +++ b/uc-people-widget.php @@ -28,7 +28,7 @@ Class UC_People_Widget extends WP_Widget { $r = strnatcasecmp( $orderGroupA, $orderGroupB ); if( $r === 0 ){ - $r = strnatcasecmp( $a, $b ); // If groups have the same order, group them by name alphabetically + $r = strnatcasecmp( $a, $b ); } return $r; } @@ -81,7 +81,12 @@ Class UC_People_Widget extends WP_Widget { } elseif( $f == 'email' && in_array( 'email', $information_to_display ) ){ $out .= '

'.get_field('email', $id ).''.'

'; } else if( $f == 'title' && in_array( 'title', $information_to_display ) ){ - $out .= '

'.get_field('title', $id ).'

'; + $out .= '

'; + $titlePieces = explode(";", get_field('title', $id )); + foreach( $titlePieces as $t ){ + $out .= ( !empty($t) ? "{$t}
": "" ); + } + $out .= '

'; } else { if ( in_array($f, $information_to_display) ) { $out .= '

'.get_field($f, $id ).'

'; @@ -162,9 +167,16 @@ Class UC_People_Widget extends WP_Widget { foreach( $this->fields as $f ){ if( $f == 'file' && in_array('file', $information_to_display) ){ $file = get_field('file', $id ); - $out .= ''.$file[title].''; + $out .= ''.$file[title].''; } else if( $f == 'email' && in_array('email', $information_to_display) ){ $out .= ''.get_field('email', $id ).''; + } else if( $f == 'title' && in_array('title', $information_to_display) ){ + $out .= ''; + $titlePieces = explode(";", get_field('title', $id )); + foreach( $titlePieces as $t ){ + $out .= ( !empty($t) ? "{$t}
": "" ); + } + $out .= ''; } else { $out .= $this->createTextCell($f, $information_to_display, $id ); } diff --git a/uc-people.php b/uc-people.php index 427ce24..c36ca08 100644 --- a/uc-people.php +++ b/uc-people.php @@ -2,7 +2,7 @@ /** * Plugin Name: UC People * Description: Displays information about people, a replacement for UUP. - * Version: 1.0 + * Version: 1.1 * Author: Andrew Bacon and Salman Kaleem of UITS Web Dev */ @@ -11,7 +11,7 @@ if ( ! defined( 'WPINC' ) ) { die; } require 'acf-export.php'; -require_once(WP_CONTENT_DIR . '/ldap.php'); +//require_once(WP_CONTENT_DIR . '/ldap.php'); include 'uc-people-widget.php'; function create_custom_custom_post_type(){ @@ -32,7 +32,7 @@ function create_custom_custom_post_type(){ 'public' => true, 'menu_position' => 35, 'menu_icon' => 'dashicons-groups', - 'supports' => array( 'tags', 'thumbnail', 'revisions', 'page-attributes', 'author' ), + 'supports' => array( 'title', 'tags', 'thumbnail', 'revisions', 'page-attributes', 'author' ), 'has_archive' => true, 'rewrite' => array( 'slug' => '/person' @@ -181,6 +181,8 @@ function importFile( $filename ){ $data = processCSV( $uploadedFile['file'] ); $fields = array( + 'netid' => 'NetID', + 'role' => 'Role', 'first_name' => 'First Name', 'last_name' => 'Last Name', 'title' => 'Title', @@ -197,6 +199,17 @@ function importFile( $filename ){ ); foreach( $data as $k => $v ){ + $user = username_exists( $v['NetID'] ); + $postAuthorFlag = false; + if( $user != false && is_user_member_of_blog($user, get_current_blog_id() ) ){ + $postAuthorFlag = true; + $role = $v['Role']; + if( $role == 'profile_user' ){ + $userObject = new WP_User( $user ); + $userObject->remove_role('profile_user'); + $userObject->add_role('contributor'); + } + } $title = $v['First Name'].' '.$v['Last Name']; $args = array( 'post_title' => $title, @@ -204,11 +217,15 @@ function importFile( $filename ){ 'post_status' => 'publish', 'post_type' => 'person', 'menu_order' => ( !empty($v['Order']) ? $v['Order'] : 0 ), + 'post_author' => ( $postAuthorFlag == true ? $user: get_current_user_id() ), ); $id = wp_insert_post( $args, true ); wp_set_object_terms( $id, explode(' ', $v['Tags']), 'tag' ); set_post_thumbnail( $id, intval($v['Profile Image']) ); foreach ($fields as $l => $w) { + if( $l == 'netid' || $l == 'role' ){ + continue; + } update_field($l, $v[$w], $id); } } @@ -219,6 +236,8 @@ function importFile( $filename ){ } } + + function uc_people_settings_page_menu(){ add_submenu_page('tools.php', 'Import People', 'Import People', 'manage_options', 'uc-import-people', 'uc_people_settings_page' ); }