Last active
November 3, 2016 18:36
-
-
Save KinnaT/b0e3745d566c82e5dfe747bfb314b0bf to your computer and use it in GitHub Desktop.
EE4 People add-on - filter out all but current user's people, also show only people of that type in each type's metabox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This is a custom template for people metabox(es) content on the EE Event CPT page. | |
*/ | |
?> | |
<div id="cpt_to_people_container_<?php echo $people_type->get('term_taxonomy_id'); ?>"> | |
<p class="description"><?php echo $people_type->get('description'); ?></p> | |
<?php if ( empty( $people ) ) { ?> | |
<?php printf( __( 'There are no people in the system. Go ahead and %screate one now%s.', 'event_espresso' ), '<a href="' . $create_person_link . '" target="_blank">', '</a>' ); ?> | |
<?php } else { ?> | |
<table class="people-to-cpt-table"> | |
<thead> | |
<tr> | |
<th></th> | |
<th><?php _e('Order', 'event_espresso'); ?></th> | |
</tr> | |
</thead> | |
<?php | |
$assigned_people_ids = array(); | |
$order_count = 0; | |
$row_count = 0; | |
$current_user = get_current_user_id(); | |
// Get the term associated with the current metabox | |
$tax_id = $people_type->get('term_taxonomy_id'); | |
// Get array of people listed in that term | |
$term_people = get_objects_in_term( $tax_id, 'espresso_people_type' ); | |
// First we do the currently assigned people and list first. | |
foreach ( $assigned_people as $assigned_person ) { | |
?> | |
<tr> | |
<td> | |
<label class="selectit"> | |
<input value="<?php echo $assigned_person->ID(); ?>" type="checkbox" name="people_to_cpt[<?php echo $tax_id; ?>][<?php echo $row_count; ?>][PER_ID]" id="people-to-cpt-<?php echo $tax_id; ?>" checked="checked"> <?php echo $assigned_person->full_name(); ?> | |
</label> | |
</td> | |
<td> | |
<input class="PER_order" id="people-to-cpt-order-<?php echo $tax_id; ?>" value="<?php echo $order_count; ?>" type="text" name="people_to_cpt[<?php echo $tax_id; ?>][<?php echo $row_count; ?>][PER_order]"> | |
</td> | |
</tr> | |
<?php $assigned_people_ids[] = $assigned_person->ID(); $order_count++; $row_count++; } ?> | |
<?php | |
// Next we loop through ALL people | |
foreach ( $people as $person ) { | |
// Find author of person | |
$author = $person->wp_user(); | |
$per_id = $person->ID(); | |
// Grab list of terms associated with the person | |
$per_terms = get_the_terms( $per_id, 'espresso_people_type' ); | |
// If person is not already associated AND person is created by the current user AND person is in the current term's array | |
if ( !in_array( $per_id, $assigned_people_ids ) && $author == $current_user && in_array( $per_id, $term_people) ) { ?> | |
<tr> | |
<td> | |
<label class="selectit"> | |
<input value="<?php echo $per_id; ?>" type="checkbox" name="people_to_cpt[<?php echo $tax_id; ?>][<?php echo $row_count; ?>][PER_ID]" id="people-to-cpt-<?php echo $tax_id; ?>"> <?php echo $person->full_name(); ?> | |
</label> | |
</td> | |
<td> | |
<input class="PER_order" id="people-to-cpt-order-<?php echo $tax_id; ?>" value="" type="text" name="people_to_cpt[<?php echo $tax_id; ?>][<?php echo $row_count; ?>][PER_order]"> | |
</td> | |
</tr> | |
<?php } | |
$row_count++; | |
} ?> | |
</table> | |
<?php } ?> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment