Created
October 16, 2012 23:38
-
-
Save blobaugh/3902777 to your computer and use it in GitHub Desktop.
More efficient TEC organizer dropdown at scale
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
public static function facilitatorSelect( $name, $current, $special = false){ | |
if( $special ) { | |
$id = 'saved_organizer'; | |
} else { | |
$id = str_replace(array('[',']'),'',$name); | |
} | |
$current_user = wp_get_current_user(); | |
$s = '<select class="chosen organizer-dropdown" name="' . esc_attr( $name ) . '" id="'.$id.'">'; | |
$s .= '<option value="0">' . __( 'Use New Facilitator' , 'tribe-events-calendar-pro' ) . '</option>'; | |
$my_organizer_ids = array(); // Holds a list of organizers were current user is the author | |
// Grab a listing of all user's organizers | |
$args = array( | |
'post_type' => 'tribe_organizer', | |
'post_status' => 'any', | |
'author' => $current_user->ID | |
); | |
$organizers = new WP_Query( $args ); | |
$organizers = $organizers->get_posts(); | |
/* | |
* Build user's My Organizers group | |
*/ | |
$s .= '<optgroup label="My Facilitators">'; | |
foreach( $organizers AS $o ) { | |
$my_organizer_ids[] = $o->ID; | |
// Opening tag | |
$s .= "\n\t"; | |
$s .= '<option value="' . esc_attr( $o->ID ) .'"'; | |
$s .= selected( $current, $o->ID, false ); | |
$s .= ' >'; | |
// Content | |
$organizer_title = wp_kses( $o->post_title, array() ); | |
$s .= $organizer_title; | |
// If we are in wp-admin we also need to show the email address | |
if( is_admin() ) { | |
$s .= ' - ' . get_post_meta( $o->ID, '_OrganizerEmail', true); | |
} | |
// Closing tag | |
$s .= '</option>'; | |
} | |
$s .= '</optgroup>'; | |
// Grab a listing of the rest of the published organizers, not by this user | |
$args = array( | |
'post_type' => 'tribe_organizer', | |
'post_status' => 'publish', | |
'post__not_in' => $my_organizer_ids | |
); | |
$organizers = new WP_Query( $args ); | |
$organizers = $organizers->get_posts(); | |
$s .= '<optgroup label="Available Facilitators">'; | |
foreach( $organizers AS $o ) { | |
$my_organizer_ids[] = $o->ID; | |
// Opening tag | |
$s .= "\n\t"; | |
$s .= '<option value="' . esc_attr( $o->ID ) .'"'; | |
$s .= selected( $current, $o->ID, false ); | |
$s .= ' >'; | |
// Content | |
$organizer_title = wp_kses( $o->post_title, array() ); | |
$s .= $organizer_title; | |
// If we are in wp-admin we also need to show the email address | |
if( is_admin() ) { | |
$s .= ' - ' . get_post_meta( $o->ID, '_OrganizerEmail', true); | |
} | |
// Closing tag | |
$s .= '</option>'; | |
} | |
$s .= '</optgroup>'; | |
echo $s; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment