From d0b11a69a2e4d8427576ae79a9bb78831e7fe124 Mon Sep 17 00:00:00 2001 From: szk11001 Date: Mon, 30 Nov 2015 13:21:44 -0500 Subject: [PATCH] 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 ){