public static function setupDefaults() { $staff_settings = StaffSettings::sharedInstance(); $current_template_slug = $staff_settings->getCurrentDefaultStaffTemplate(); if ($current_template_slug == '' || $current_template_slug == null) { $staff_settings->updateDefaultStaffTemplateSlug('list'); } else { if ($current_template_slug == 'custom' || get_option('staff_directory_html_template', '') != '') { $templates_array = array(); $templates_array[] = array('html' => get_option('staff_directory_html_template'), 'css' => get_option('staff_directory_css_template')); $staff_settings->updateCustomStaffTemplates($templates_array); $staff_settings->updateDefaultStaffTemplateSlug('custom_1'); delete_option('staff_directory_html_template'); delete_option('staff_directory_css_template'); } } }
static function settings() { $staff_settings = StaffSettings::sharedInstance(); if (isset($_GET['delete-template'])) { $staff_settings->deleteCustomTemplate($_GET['delete-template']); } if (isset($_POST['staff_templates']['slug'])) { $staff_settings->updateDefaultStaffTemplateSlug($_POST['staff_templates']['slug']); $did_update_options = true; } if (isset($_POST['custom_staff_templates'])) { $staff_settings->updateCustomStaffTemplates($_POST['custom_staff_templates']); $did_update_options = true; } if (isset($_POST['staff_meta_fields_labels'])) { $staff_settings->updateCustomStaffMetaFields($_POST['staff_meta_fields_labels'], $_POST['staff_meta_fields_types']); $did_update_options = true; } $current_template = $staff_settings->getCurrentDefaultStaffTemplate(); $custom_templates = $staff_settings->getCustomStaffTemplates(); require_once plugin_dir_path(__FILE__) . '../views/admin_settings.php'; }
static function html_for_custom_template($template_slug, $wp_query) { $staff_settings = StaffSettings::sharedInstance(); $output = ''; $template = $staff_settings->getCustomStaffTemplateForSlug($template_slug); $template_html = stripslashes($template['html']); $template_css = stripslashes($template['css']); $output .= "<style type=\"text/css\">{$template_css}</style>"; if (strpos($template_html, '[staff_loop]')) { $before_loop_markup = substr($template_html, 0, strpos($template_html, "[staff_loop]")); $after_loop_markup = substr($template_html, strpos($template_html, "[/staff_loop]") + strlen("[/staff_loop]"), strlen($template_html) - strpos($template_html, "[/staff_loop]")); $loop_markup = str_replace("[staff_loop]", "", substr($template_html, strpos($template_html, "[staff_loop]"), strpos($template_html, "[/staff_loop]") - strpos($template_html, "[staff_loop]"))); $output .= $before_loop_markup; } else { $loop_markup = $template_html; } while ($wp_query->have_posts()) { $wp_query->the_post(); $staff_name = get_the_title(); if (has_post_thumbnail()) { $attachment_array = wp_get_attachment_image_src(get_post_thumbnail_id()); $photo_url = $attachment_array[0]; $photo_tag = '<img src="' . $photo_url . '" />'; } else { $photo_url = ""; $photo_tag = ""; } $staff_email = get_post_meta(get_the_ID(), 'email', true); $staff_email_link = $staff_email != '' ? "<a href=\"mailto:{$staff_email}\">Email {$staff_name}</a>" : ""; $staff_phone_number = get_post_meta(get_the_ID(), 'phone_number', true); $staff_bio = get_the_content(); $staff_website = get_post_meta(get_the_ID(), 'website', true); $staff_website_link = $staff_website != '' ? "<a href=\"{$staff_website}\" target=\"_blank\">View website</a>" : ""; $staff_categories = wp_get_post_terms(get_the_ID(), 'staff_category'); $all_staff_categories = ""; if (count($staff_categories) > 0) { $staff_category = $staff_categories[0]->name; foreach ($staff_categories as $category) { $all_staff_categories .= $category->name . ", "; } $all_staff_categories = substr($all_staff_categories, 0, strlen($all_staff_categories) - 2); } else { $staff_category = ""; } $accepted_single_tags = array("[name]", "[photo_url]", "[bio]", "[category]", "[category all=true]"); $replace_single_values = array($staff_name, $photo_url, $staff_bio, $staff_category, $all_staff_categories); $accepted_formatted_tags = array("[name_header]", "[photo]", "[email_link]", "[bio_paragraph]", "[website_link]"); $replace_formatted_values = array("<h3>{$staff_name}</h3>", $photo_tag, $staff_email_link, "<p>{$staff_bio}</p>", $staff_website_link); $current_staff_markup = str_replace($accepted_single_tags, $replace_single_values, $loop_markup); $current_staff_markup = str_replace($accepted_formatted_tags, $replace_formatted_values, $current_staff_markup); preg_match_all("/\\[(.*?)\\]/", $current_staff_markup, $other_matches); $staff_meta_fields = get_option('staff_meta_fields'); if ($staff_meta_fields != '' && count($other_matches[0]) > 0) { foreach ($other_matches[0] as $match) { foreach ($staff_meta_fields as $field) { $meta_key = $field['slug']; $shortcode_without_brackets = substr($match, 1, strlen($match) - 2); if ($meta_key == $shortcode_without_brackets) { $meta_value = get_post_meta(get_the_ID(), $meta_key, true); $current_staff_markup = str_replace($match, $meta_value, $current_staff_markup); } } } } $output .= $current_staff_markup; } if (isset($after_loop_markup)) { $output .= $after_loop_markup; } return $output; }
static function staff_meta_box_output($post) { wp_nonce_field('staff_meta_box_nonce_action', 'staff_meta_box_nonce'); $staff_settings = StaffSettings::sharedInstance(); ?> <style type="text/css"> label.staff-label { float: left; line-height: 27px; width: 130px; } </style> <?php foreach ($staff_settings->getStaffDetailsFields() as $field) { ?> <p> <label for="staff[<?php echo $field['slug']; ?> ]" class="staff-label"><?php _e($field['name']); ?> :</label> <?php if ($field['type'] == 'text') { ?> <input type="text" name="staff_meta[<?php echo $field['slug']; ?> ]" value="<?php echo get_post_meta($post->ID, $field['slug'], true); ?> " /> <?php } elseif ($field['type'] == 'textarea') { ?> <textarea cols=40 rows=5 name="staff_meta[<?php echo $field['slug']; ?> ]"><?php echo get_post_meta($post->ID, $field['slug'], true); ?> </textarea> <?php } ?> </p> <?php } ?> <?php }
<?php $staff_settings = StaffSettings::sharedInstance(); ?> <style type="text/css"> #staff-categories-wrapper, #staff-order-wrapper, #staff-template-wrapper { margin: 20px 0px; } </style> <div id="staff-categories-wrapper"> <label for="staff-category">Staff Category</label> <select name="staff-category"> <option value=''>-- Select Category --</option> <?php foreach (get_terms('staff_category') as $cat) { ?> <option value="<?php echo $cat->term_id; ?> "><?php echo $cat->name; ?> </option> <?php } ?> </select>
static function set_default_templates_if_necessary() { if (get_option('staff_directory_template_slug') == '') { update_option('staff_directory_template_slug', 'list'); } $has_custom_templates = count(StaffSettings::sharedInstance()->getCustomStaffTemplates()) > 0; if (get_option('staff_directory_html_template') == '' && !$has_custom_templates) { $default_html_template = <<<EOT <div class="staff-directory"> [staff_loop] [name_header] [bio_paragraph] <div class="staff-directory-divider"></div> [/staff_loop] </div> EOT; update_option('staff_directory_html_template', $default_html_template); } if (get_option('staff_directory_css_template') == '' && !$has_custom_templates) { $default_css_template = <<<EOT .staff-directory-divider{ border-top: solid black thin; width: 90%; margin:15px 0; } EOT; update_option('staff_directory_css_template', $default_css_template); } }