Created
November 20, 2012 00:24
-
-
Save joshfeck/4115124 to your computer and use it in GitHub Desktop.
Staff shortcode that displays the email address on the front-end of the site. Copy and paste into the custom files add-on's custom_functions.php file.
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
if (!function_exists('espresso_staff_sc')) { | |
function espresso_staff_sc($atts) { | |
global $wpdb, $espresso_premium, $this_event_id; | |
if ($espresso_premium != true) | |
return; | |
empty($atts) ? '' : extract($atts); | |
//Outside wrapper | |
$outside_wrapper_class = isset($outside_wrapper_class) ? 'class="' . $outside_wrapper_class . '"' : 'class="event_staff"'; | |
$wrapper_start = isset($outside_wrapper) ? '<' . $outside_wrapper . ' ' . $outside_wrapper_class : '<div ' . $outside_wrapper_class; | |
$wrapper_end = isset($outside_wrapper) ? '</' . $outside_wrapper . '>' : '</div>'; | |
//Persons title | |
$name_class = isset($name_class) ? 'class="' . $name_class . '"' : 'class="person_name"'; | |
$name_wrapper_start = isset($name_wrapper) ? '<' . $name_wrapper . ' ' . $name_class . '>' : '<strong ' . $name_class . '>'; | |
$name_wrapper_end = isset($name_wrapper) ? '</' . $name_wrapper . '>' : '</strong>'; | |
//Image class | |
$image_class = isset($image_class) ? 'class="' . $image_class . '"' : 'class="staff_image"'; | |
$image_wrapper_class = isset($image_wrapper_class) ? 'class="' . $image_wrapper_class . '"' : 'class="image_wrapper"'; | |
$image_wrapper_start = isset($image_wrapper) ? '<' . $image_wrapper . ' ' . $image_wrapper_class : '<p ' . $image_wrapper_class . '>'; | |
$image_wrapper_end = isset($image_wrapper) ? '</' . $image_wrapper . '>' : '</p>'; | |
//Inside wrappers | |
$inside_wrapper_class = isset($inside_wrapper_class) ? 'class="' . $inside_wrapper_class . '"' : 'class="event_person"'; | |
$inside_wrapper_before = isset($inside_wrapper) ? '<' . $inside_wrapper . ' ' . $inside_wrapper_class . '>' : '<p ' . $inside_wrapper_class . '>'; | |
$inside_wrapper_after = isset($inside_wrapper) ? '</' . $inside_wrapper . '>' : '</p>'; | |
//Show the persons title? | |
$show_staff_titles = isset($show_staff_titles) && $show_staff_titles == 'false' ? false : true; | |
//Show the persons role? | |
$show_staff_roles = isset($show_staff_roles) && $show_staff_roles == 'false' ? false : true; | |
//Show the persons details? | |
$show_staff_details = isset($show_staff_details) && $show_staff_details == 'false' ? false : true; | |
//Show image? | |
$show_image = isset($show_image) && $show_image == 'false' ? false : true; | |
//Show the description? | |
$show_description = isset($show_description) && $show_description == 'false' ? false : true; | |
//Find the event id | |
if (isset($event_id)) { | |
$event_id = $event_id; //Check to see if the event is used in the shortcode parameter | |
} elseif (isset($this_event_id)) { | |
$event_id = $this_event_id; //Check to see if the global event id is being used | |
} elseif (isset($_REQUEST['event_id'])) { | |
$event_id = $_REQUEST['event_id']; //If the first two are not being used, then get the event id from the url | |
} elseif (!isset($event_id) && !isset($id)) { | |
//_e('No event or staff id supplied!', 'event_espresso') ; | |
return; | |
} | |
$limit = isset($limit) && $limit > 0 ? " LIMIT 0," . $limit . " " : ''; | |
$sql = "SELECT s.id, s.name, s.role, s.email, s.meta "; | |
$sql .= " FROM " . EVENTS_PERSONNEL_TABLE . ' s '; | |
if (isset($id) && $id > 0) { | |
$sql .= " WHERE s.id ='" . $id . "' "; | |
} else { | |
$sql .= " JOIN " . EVENTS_PERSONNEL_REL_TABLE . " r ON r.person_id = s.id "; | |
$sql .= " WHERE r.event_id ='" . $event_id . "' "; | |
} | |
$sql .= $limit; | |
//echo $sql; | |
$event_personnel = $wpdb->get_results($sql); | |
$num_rows = $wpdb->num_rows; | |
if ($num_rows > 0) { | |
$html = ''; | |
foreach ($event_personnel as $person) { | |
$person_id = $person->id; | |
$person_name = $person->name; | |
$person_role = $person->role; | |
$person_email = $person->email; | |
$meta = unserialize($person->meta); | |
$html .= $wrapper_start . ' id="person_id_' . $person_id . '">'; | |
//Build the persons name/title | |
$html .= $inside_wrapper_before; | |
if ($show_staff_roles != false) { | |
$person_title = isset($person_role) && !empty($person_role) ? ' - ' . stripslashes_deep($person_role) : ''; | |
} | |
$html .= $name_wrapper_start . stripslashes_deep($person_name) . $name_wrapper_end . $person_title; | |
$html .= $inside_wrapper_after; | |
//Build the image | |
if ($show_image != false) { | |
$html .= isset($meta['image']) && !empty($meta['image']) ? $image_wrapper_start . '<img id="staff_image_' . $person_id . '" ' . $image_class . ' src="' . stripslashes_deep($meta['image']) . '" />' . $image_wrapper_end : ''; | |
} | |
//Build the description | |
if ($show_description != false) { | |
$html .= isset($meta['description']) && !empty($meta['description']) ? html_entity_decode(stripslashes_deep($meta['description'])) : ''; | |
} | |
//Build the additional details | |
if ($show_staff_details != false) { | |
$html .= $inside_wrapper_before; | |
$html .= isset($meta['organization']) && !empty($meta['organization']) ? __('Company:', 'event_espresso') . ' ' . stripslashes_deep($meta['organization']) . '<br />' : ''; | |
if ($show_staff_titles != false) { | |
$html .= isset($meta['title']) && !empty($meta['title']) ? __('Title:', 'event_espresso') . ' ' . stripslashes_deep($meta['title']) . '<br />' : ''; | |
} | |
$html .= isset($meta['industry']) && !empty($meta['industry']) ? __('Industry:', 'event_espresso') . ' ' . stripslashes_deep($meta['industry']) . '<br />' : ''; | |
$html .= isset($meta['city']) && !empty($meta['city']) ? __('City:', 'event_espresso') . ' ' . stripslashes_deep($meta['city']) . '<br />' : ''; | |
$html .= isset($meta['country']) && !empty($meta['country']) ? __('Country:', 'event_espresso') . ' ' . stripslashes_deep($meta['country']) . '<br />' : ''; | |
$html .= isset($meta['website']) && !empty($meta['website']) ? __('Website:', 'event_espresso') . ' <a href="' . stripslashes_deep($meta['website']) . '" target="_blank">' . stripslashes_deep($meta['website']) . '</a><br />' : ''; | |
$html .= isset($person_email) && !empty($person_email) ? __('Email Address:', 'event_espresso') . ' ' . stripslashes_deep($person_email) . '<br />' : ''; | |
$html .= isset($meta['twitter']) && !empty($meta['twitter']) ? __('Twitter:', 'event_espresso') . ' <a href="http://twitter.com/#!/' . stripslashes_deep($meta['twitter']) . '" target="_blank">@' . stripslashes_deep($meta['twitter']) . '</a><br />' : ''; | |
$html .= isset($meta['phone']) && !empty($meta['phone']) ? __('Phone:', 'event_espresso') . ' ' . stripslashes_deep($meta['phone']) . '<br />' : ''; | |
$html .= $inside_wrapper_after; | |
} | |
$html .= $wrapper_end; | |
} | |
} | |
ob_start(); | |
echo wpautop($html); | |
$buffer = ob_get_contents(); | |
ob_end_clean(); | |
return $buffer; | |
} | |
} | |
add_shortcode('ESPRESSO_STAFF', 'espresso_staff_sc'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment