Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
szk11001 committed Dec 2, 2015
1 parent d0b11a6 commit aadfa26
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
18 changes: 15 additions & 3 deletions uc-people-widget.php
Expand Up @@ -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;
}
Expand Down Expand Up @@ -81,7 +81,12 @@ Class UC_People_Widget extends WP_Widget {
} elseif( $f == 'email' && in_array( 'email', $information_to_display ) ){
$out .= '<p class="person-email"><a href="mailto:'.get_field('email', $id ).'">'.get_field('email', $id ).'</a>'.'</p>';
} else if( $f == 'title' && in_array( 'title', $information_to_display ) ){
$out .= '<p class="person-title"><strong>'.get_field('title', $id ).'</strong></p>';
$out .= '<p class="person-title">';
$titlePieces = explode(";", get_field('title', $id ));
foreach( $titlePieces as $t ){
$out .= ( !empty($t) ? "<strong>{$t}</strong><br>": "" );
}
$out .= '</p>';
} else {
if ( in_array($f, $information_to_display) ) {
$out .= '<p class="person-'.$f.'">'.get_field($f, $id ).'</p>';
Expand Down Expand Up @@ -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 .= '<td class="person-file"><a href="'.$file[url].'">'.$file[title].'</a>';
$out .= '<td class="person-file"><a href="'.$file[url].'">'.$file[title].'</a></td>';
} else if( $f == 'email' && in_array('email', $information_to_display) ){
$out .= '<td class="person-email"><a href="mailto:'.get_field('email', $id ).'">'.get_field('email', $id ).'</a></td>';
} else if( $f == 'title' && in_array('title', $information_to_display) ){
$out .= '<td class="person-title">';
$titlePieces = explode(";", get_field('title', $id ));
foreach( $titlePieces as $t ){
$out .= ( !empty($t) ? "<strong>{$t}</strong><br>": "" );
}
$out .= '</td>';
} else {
$out .= $this->createTextCell($f, $information_to_display, $id );
}
Expand Down
25 changes: 22 additions & 3 deletions uc-people.php
Expand Up @@ -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
*/

Expand All @@ -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(){
Expand All @@ -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'
Expand Down Expand Up @@ -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',
Expand All @@ -197,18 +199,33 @@ 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,
'post_name' => strtolower($v['First Name']).'-'.strtolower($v['Last Name']),
'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);
}
}
Expand All @@ -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' );
}
Expand Down

0 comments on commit aadfa26

Please sign in to comment.