From b52e752a1007726e28d1035fdff6f9cee699d19d Mon Sep 17 00:00:00 2001 From: Joshua Roy Date: Thu, 17 Dec 2015 15:43:54 -0500 Subject: [PATCH] Update to UC People --- acf-export.php | 38 ++++++++++++++++++++++++++++++++++++++ uc-people-widget.php | 24 +++++++++++++++++++++--- uc-people.php | 22 ++++++++++++---------- 3 files changed, 71 insertions(+), 13 deletions(-) diff --git a/acf-export.php b/acf-export.php index f4b6433..dede079 100644 --- a/acf-export.php +++ b/acf-export.php @@ -92,16 +92,20 @@ if(function_exists("register_field_group")) 'middle_name' => 'Middle Name', 'last_name' => 'Last Name', 'title' => 'Title', + 'department' => 'Department', 'about' => 'About', 'file' => 'Link to File', + //'filelabel' => 'File Label', 'email' => 'Email', 'phone' => 'Phone', 'phone_(alternate)' => 'Phone (Alternate)', 'fax' => 'Fax', 'mailing_address' => 'Mailing Address', 'office_location' => 'Office Location', + 'campus' => 'Campus', 'office_hours' => 'Office Hours', 'courses' => 'Courses', + 'url' => 'URL', ), 'default_value' => array('photo','first_name','last_name','email'), 'layout' => 'vertical', @@ -192,6 +196,18 @@ if(function_exists("register_field_group")) 'formatting' => 'html', 'maxlength' => '', ), + array ( + 'key' => 'field_department', + 'label' => 'Department', + 'name' => 'department', + 'type' => 'text', + 'default_value' => '', + 'placeholder' => '', + 'prepend' => '', + 'append' => '', + 'formatting' => 'html', + 'maxlength' => '', + ), array ( 'key' => 'field_about', 'label' => 'About', @@ -209,6 +225,16 @@ if(function_exists("register_field_group")) 'save_format' => 'object', 'library' => 'all', ), + array ( + 'key' => 'field_filelabel', + 'label' => 'File Label', + 'name' => 'filelabel', + 'type' => 'text', + 'default_value' => 'File', + 'placeholder' => '', + 'prepend' => '', + 'append' => '', + ), array ( 'key' => 'field_email', 'label' => 'Email', @@ -279,6 +305,18 @@ if(function_exists("register_field_group")) 'formatting' => 'html', 'maxlength' => '', ), + array ( + 'key' => 'field_campus', + 'label' => 'Campus', + 'name' => 'campus', + 'type' => 'text', + 'default_value' => '', + 'placeholder' => '', + 'prepend' => '', + 'append' => '', + 'formatting' => 'html', + 'maxlength' => '', + ), array ( 'key' => 'field_office_hours', 'label' => 'Office Hours', diff --git a/uc-people-widget.php b/uc-people-widget.php index 0b038d1..2f15f42 100644 --- a/uc-people-widget.php +++ b/uc-people-widget.php @@ -1,7 +1,7 @@ __CLASS__, 'description' => 'A widget to display People' ) ); @@ -52,7 +52,7 @@ Class UC_People_Widget extends WP_Widget { usort( $people, array('UC_People_Widget', 'sort_by_last_then_first') ); foreach( $people as $id ){ - $out .= '
'; + $out .= '
'; $out .= '
'; $out .= ''; @@ -87,8 +87,17 @@ Class UC_People_Widget extends WP_Widget { $out .= ( !empty($t) ? "{$t}
": "" ); } $out .= '

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

'; + $departmentPieces = explode(";", get_field('department', $id )); + foreach( $departmentPieces as $d ){ + $out .= ( !empty($d) ? "{$d}
": "" ); + } + $out .= '

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

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

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

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

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

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

'; @@ -178,9 +187,18 @@ Class UC_People_Widget extends WP_Widget { $out .= ( !empty($t) ? "{$t}
": "" ); } $out .= ''; + } else if( $f == 'department' && in_array('department', $information_to_display) ){ + $out .= ''; + $departmentPieces = explode(";", get_field('department', $id )); + foreach( $departmentPieces as $d ){ + $out .= ( !empty($d) ? "{$d}
": "" ); + } + $out .= ''; } else if( $f == 'mailing_address' && in_array('mailing_address', $information_to_display) ){ $out .= ''.str_replace(';','
',get_field($f, $id )).''; - } else { + } elseif( $f == 'url' && in_array( 'url', $information_to_display ) ){ + $out .= ''.get_field('url', $id ).''.''; + } else { $out .= $this->createTextCell($f, $information_to_display, $id ); } } diff --git a/uc-people.php b/uc-people.php index a2b4db3..89f6502 100644 --- a/uc-people.php +++ b/uc-people.php @@ -197,19 +197,21 @@ function importFile( $filename ){ 'courses' => 'Courses', 'about' => 'About', 'url' => 'Website', + 'author' => 'Author', ); 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 ); + //$postAuthorFlag = false; + if( $user != false && is_user_member_of_blog($v['Author'], get_current_blog_id() ) ){ + //$postAuthorFlag = true; + //$role = $v['Role']; + //if( $role == 'profile_user' ){ + $userObject = new WP_User( $v['Author'] ); + $userObject->remove_role('subscriber'); $userObject->remove_role('profile_user'); - $userObject->add_role('contributor'); - } + $userObject->add_role('contributornomedia'); + //} } $title = $v['First Name'].' '.$v['Last Name']; $args = array( @@ -218,13 +220,13 @@ 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() ), + 'post_author' => ( !empty($v['Author']) ? $v['Author']: 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' ){ + if( $l == 'netid' || $l == 'role' || $l == 'author' ){ continue; } update_field($l, $v[$w], $id);