Created
May 8, 2017 15:23
-
-
Save NickDeckerDevs/a4f5ab4e89946e09ebd965127b5a7714 to your computer and use it in GitHub Desktop.
the entire functions.php file for cora
This file contains hidden or 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 // ==== FUNCTIONS ==== // | |
| require_once( trailingslashit( get_stylesheet_directory() ) . 'Kint.class.php' ); | |
| // Load the configuration file for this installation; all options are set here | |
| if ( is_readable( trailingslashit( get_stylesheet_directory() ) . 'functions-config.php' ) ) | |
| require_once( trailingslashit( get_stylesheet_directory() ) . 'functions-config.php' ); | |
| // Load configuration defaults for this theme; anything not set in the custom configuration (above) will be set here | |
| require_once( trailingslashit( get_stylesheet_directory() ) . 'functions-config-defaults.php' ); | |
| // An example of how to manage loading front-end assets (scripts, styles, and fonts) | |
| require_once( trailingslashit( get_stylesheet_directory() ) . 'inc/assets.php' ); | |
| // Required to demonstrate WP AJAX Page Loader (as WordPress doesn't ship with even simple post navigation functions) | |
| require_once( trailingslashit( get_stylesheet_directory() ) . 'inc/navigation.php' ); | |
| // Require custom functions file for development | |
| require_once( trailingslashit( get_stylesheet_directory() ) . 'inc/custom_functions.php' ); | |
| // Only the bare minimum to get the theme up and running | |
| function voidx_setup() { | |
| // HTML5 support; mainly here to get rid of some nasty default styling that WordPress used to inject | |
| add_theme_support( 'html5', array( 'search-form', 'gallery' ) ); | |
| // Automatic feed links | |
| add_theme_support( 'automatic-feed-links' ); | |
| // $content_width limits the size of the largest image size available via the media uploader | |
| // It should be set once and left alone apart from that; don't do anything fancy with it; it is part of WordPress core | |
| global $content_width; | |
| $content_width = 960; | |
| // Register header and footer menus | |
| register_nav_menu( 'header', __( 'Header menu', 'voidx' ) ); | |
| register_nav_menu( 'footer', __( 'Footer menu', 'voidx' ) ); | |
| } | |
| add_action( 'after_setup_theme', 'voidx_setup', 11 ); | |
| // Sidebar declaration | |
| function voidx_widgets_init() { | |
| register_sidebar( array( | |
| 'name' => __( 'Main sidebar', 'voidx' ), | |
| 'id' => 'sidebar-main', | |
| 'description' => __( 'Appears to the right side of most posts and pages.', 'voidx' ), | |
| 'before_widget' => '<aside id="%1$s" class="widget %2$s">', | |
| 'after_widget' => '</aside>', | |
| 'before_title' => '<h2>', | |
| 'after_title' => '</h2>' | |
| ) ); | |
| register_sidebar( array( | |
| 'name' => __( 'News Sidebar', 'voidx' ), | |
| 'id' => 'sidebar-news', | |
| 'description' => __( 'Appears to the right side of the news pages.', 'voidx' ), | |
| 'before_widget' => '<aside id="%1$s" class="widget %2$s">', | |
| 'after_widget' => '</aside>', | |
| 'before_title' => '<h2>', | |
| 'after_title' => '</h2>' | |
| ) ); | |
| register_sidebar( array( | |
| 'name' => __( 'Business Page Sidebar', 'voidx' ), | |
| 'id' => 'sidebar-business', | |
| 'description' => __( 'Appears in the sidebars of the reusable business page templates.', 'voidx' ), | |
| 'before_widget' => '<aside id="%1$s" class="widget %2$s">', | |
| 'after_widget' => '</aside>', | |
| 'before_title' => '<h2>', | |
| 'after_title' => '</h2>' | |
| ) ); | |
| register_sidebar( array( | |
| 'name' => __( 'News Page Sidebar', 'voidx' ), | |
| 'id' => 'sidebar-news', | |
| 'description' => __( 'Appears in the sidebars of the news templates.', 'voidx' ), | |
| 'before_widget' => '<aside id="%1$s" class="widget %2$s">', | |
| 'after_widget' => '</aside>', | |
| 'before_title' => '<h2>', | |
| 'after_title' => '</h2>' | |
| ) ); | |
| $businessTypes = ['Physicians', 'Patients', 'Careers', 'Work Comp', 'Partners']; | |
| foreach ($businessTypes as $type) { | |
| $title = $type; | |
| $slug = sanitize_title($type); | |
| register_sidebar( array( | |
| 'name' => __( $title. ' Sub Page', 'voidx' ), | |
| 'id' => $slug.'-sidebar', | |
| 'description' => __( 'Appears in the sidebars of the '.$title.' sub pages.', 'voidx' ), | |
| 'before_widget' => '<aside id="%1$s" class="widget %2$s">', | |
| 'after_widget' => '</aside>', | |
| 'before_title' => '<h2>', | |
| 'after_title' => '</h2>' | |
| ) ); | |
| } | |
| } | |
| add_action( 'widgets_init', 'voidx_widgets_init' ); | |
| function getClinicData($query = '') { | |
| $serverName = "10.211.55.3\SQLEXPRESS,1433"; | |
| $connectionOptions = [ | |
| "Database" => "ComSite-CorpComm", | |
| "Uid" => "nick", | |
| "PWD" => "Jayceonly1" | |
| ]; | |
| $conn = sqlsrv_connect($serverName, $connectionOptions); | |
| if(!$conn) { | |
| d('error with connection'); | |
| ddd(FormatErrors(sqlsrv_errors())); | |
| } | |
| $tsql = $query == '' ? "SELECT * FROM dbo.CLINICS_DATA;" : $query; | |
| $getResults = sqlsrv_query($conn, $tsql); | |
| if($getResults == FALSE) { | |
| ddd(FormatErrors(sqlsrv_errors())); | |
| } | |
| $results = []; | |
| while ($row = sqlsrv_fetch_array($getResults, SQLSRV_FETCH_ASSOC)) { | |
| $results[] = $row; | |
| } | |
| return $results; | |
| } | |
| function getLocations($locationsArray) { | |
| $mapArray = []; | |
| $locationCount = 0; | |
| foreach($locationsArray as $item) { | |
| $clinicId = isset($item['CLINIC_ID']) ? $item['CLINIC_ID'] : $item[1]; | |
| $street = isset($item['STREET']) ? $item['STREET'] : $item[13]; | |
| $city = isset($item['CITY']) ? $item['CITY'] : $item[14]; | |
| $state = isset($item['STATE']) ? $item['STATE'] : $item[15]; | |
| $zip = isset($item['ZIP']) ? $item['ZIP'] : $item[16]; | |
| $phone = isset($item['PHONE']) ? $item['PHONE'] : $item[17]; | |
| $fax = isset($item['FAX']) ? $item['FAX'] : $item[18]; | |
| $image = isset($item['IMAGE_URL_MEDIUM']) ? $item['IMAGE_URL_MEDIUM'] : $item[9]; | |
| // $ = isset($item['']) ? isset($item['']) : $item[]; | |
| // $ = isset($item['']) ? isset($item['']) : $item[]; | |
| // $ = isset($item['']) ? isset($item['']) : $item[]; | |
| // $ = isset($item['']) ? isset($item['']) : $item[]; | |
| // $ = isset($item['']) ? isset($item['']) : $item[]; | |
| // $ = isset($item['']) ? isset($item['']) : $item[]; | |
| $name = isset($item['LOCATION_ID']) ? $item['LOCATION_ID'] : $item[0]; | |
| $latitude = isset($item['LAT']) ? $item['LAT'] : $item[11]; | |
| $longitude = isset($item['LNG']) ? $item['LNG'] : $item[12]; | |
| $mapArray[$locationCount] = [ | |
| 'id' => $clinicId, | |
| 'name' => $name, | |
| 'lat' => $latitude, | |
| 'long' => $longitude, | |
| 'rgb' => $locationCount, | |
| 'street' => $street, | |
| 'city' => $city, | |
| 'state' => $state, | |
| 'zip' => $zip, | |
| 'phone' => $phone, | |
| 'fax' => $fax, | |
| 'img' => $image | |
| ]; | |
| $locationCount++; | |
| } | |
| return $mapArray; | |
| } | |
| function FormatErrors($errors) { | |
| echo 'error info:<br>'; | |
| foreach($errors as $error) { | |
| echo 'sqlstate: '.$error['SQLSTATE'].'<br>'; | |
| echo 'code:'.$error['code'].'<br>'; | |
| echo 'msg:'.$error['message'].'<br>'; | |
| } | |
| } | |
| function servicesOffered($clinic) { | |
| $services = '<ul class="services-list">'; | |
| if($clinic['SURG']) $services .= '<li>Post-Surgery Rehabilitation</li>'; | |
| if($clinic['SENIOR']) $services .= '<li>Senior Rehabilitation Programs</li>'; | |
| if($clinic['ATHLETIC']) $services .= '<li>Athletic Training</li>'; | |
| if($clinic['WORK']) $services .= '<li>Work Injury Rehabilitation</li>'; | |
| if($clinic['ANODYNE']) $services .= '<li>Anodyne</li>'; | |
| if($clinic['BACK']) $services .= '<li>Back Stabilization</li>'; | |
| if($clinic['BALANCE']) $services .= '<li>Balance Training</li>'; | |
| if($clinic['FCE']) $services .= '<li>Functional Capacity Evaluations</li>'; | |
| if($clinic['HAND']) $services .= '<li>Hand Therapy</li>'; | |
| if($clinic['NEURO']) $services .= '<li>Neurological Rehabilitation</li>'; | |
| if($clinic['OCCUPAT']) $services .= '<li>Occupational Therapy</li>'; | |
| if($clinic['ORTHO']) $services .= '<li>Orthopedic Rehabilitation</li>'; | |
| if($clinic['PAIN']) $services .= '<li>Pain Management</li>'; | |
| if($clinic['PEDIATRIC']) $services .= '<li>Pediatric Therapy</li>'; | |
| if($clinic['PHYSTHER']) $services .= '<li>Physical Therapy</li>'; | |
| if($clinic['POET']) $services .= '<li>Post-Offer of Employment Test</li>'; | |
| //if($clinic['']) $services .= '<li>Pulsed Magnetic Therapy</li>'; | |
| if($clinic['VEST']) $services .= '<li>Vestibular Rehabilitation</li>'; | |
| if($clinic['BTE']) $services .= '<li>BTE Site</li>'; | |
| //if($clinic['KEY']) $services .= '<li>VALUE</li>'; | |
| $services .= '</ul>'; | |
| return $services; | |
| } | |
| function clincHours($clinic) { | |
| $hours[] = '<li><span>Monday</span>'.$clinic['HOURS_MON'].'</li>'; | |
| $hours[] = '<li><span>Tuesday</span>'.$clinic['HOURS_TUE'].'</li>'; | |
| $hours[] = '<li><span>Wednesday</span>'.$clinic['HOURS_WED'].'</li>'; | |
| $hours[] = '<li><span>Thursday</span>'.$clinic['HOURS_THU'].'</li>'; | |
| $hours[] = '<li><span>Friday</span>'.$clinic['HOURS_FRI'].'</li>'; | |
| $hours[] = '<li><span>Saturday</span>'.$clinic['HOURS_SAT'].'</li>'; | |
| $hours[] = '<li><span>Sunday</span>'.$clinic['HOURS_SUN'].'</li>'; | |
| $html = '<h5>Hours Of Operation</h5><ul class="hours">'; | |
| foreach($hours as $day) { | |
| $html .= $day; | |
| } | |
| $html .= '</ul>'; | |
| return $html; | |
| } | |
| add_filter( 'wp_get_nav_menu_items','sub_nav_filter', 11, 3 ); | |
| function sub_nav_filter( $items, $menu, $args ) { | |
| //is not primary menu | |
| // d($menu->slug); | |
| $newSlug = $menu->slug; | |
| if($newSlug == 'physicians') { | |
| $cleanTitle = sanitize_title(get_the_title()); | |
| // d($cleanTitle); | |
| if($cleanTitle == 'work-comp' || $_GET['parent'] == 'work-comp') { | |
| $newSlug = 'work-comp'; | |
| } | |
| } | |
| if($menu->term_id != 2) { | |
| foreach( $items as $item ) | |
| { | |
| $item->url .= '?parent='.$newSlug; | |
| } | |
| return $items; | |
| } else { | |
| return $items; | |
| } | |
| } | |
| function get_mobile_menu() { | |
| $mobile = '<ul><li id="physicans-mobile" class="mobile-section"><a class="mobile-parent" href="/physicians">Physicians<span class="caret"></span></a>'; | |
| $mobile .= wp_nav_menu( [ | |
| 'menu' => 'physicians', | |
| 'theme_location' => 'secondary', | |
| 'depth' => 3, | |
| 'container' => 'ul', | |
| 'container_id' => '', | |
| 'menu_class' => 'physicians-bg stop', | |
| 'fallback_cb' => 'wp_bootstrap_navwalker::fallback', | |
| 'walker' => new wp_bootstrap_navwalker(), | |
| 'echo' => false | |
| ] ); | |
| $mobile .= '</li><li id="patients-mobile" class="mobile-section"><a class="mobile-parent" href="/patients">Patients<span class="caret"></span></a>'; | |
| $mobile .= wp_nav_menu( [ | |
| 'menu' => 'patients', | |
| 'theme_location' => 'secondary', | |
| 'depth' => 3, | |
| 'container' => 'ul', | |
| 'container_id' => '', | |
| 'menu_class' => '', | |
| 'fallback_cb' => 'wp_bootstrap_navwalker::fallback', | |
| 'walker' => new wp_bootstrap_navwalker(), | |
| 'echo' => false | |
| ] ); | |
| $mobile .= '</li><li id="careers-mobile" class="mobile-section"><a class="mobile-parent" href="/careers">Careers<span class="caret"></span></a>'; | |
| $mobile .= wp_nav_menu( [ | |
| 'menu' => 'careers', | |
| 'theme_location' => 'secondary', | |
| 'depth' => 3, | |
| 'container' => 'ul', | |
| 'container_id' => '', | |
| 'menu_class' => '', | |
| 'fallback_cb' => 'wp_bootstrap_navwalker::fallback', | |
| 'walker' => new wp_bootstrap_navwalker(), | |
| 'echo' => false | |
| ] ); | |
| $mobile .= '</li><li id="work-comp-mobile" class="mobile-section"><a class="mobile-parent" href="/work-comp">Work Comp<span class="caret"></span></a>'; | |
| $mobile .= wp_nav_menu( [ | |
| 'menu' => 'physicians', | |
| 'theme_location' => 'secondary', | |
| 'depth' => 3, | |
| 'container' => 'ul', | |
| 'container_id' => '', | |
| 'menu_class' => '', | |
| 'fallback_cb' => 'wp_bootstrap_navwalker::fallback', | |
| 'walker' => new wp_bootstrap_navwalker(), | |
| 'echo' => false | |
| ] ); | |
| $mobile .= '</li><li id="partners-mobile" class="mobile-section"><a class="mobile-parent" href="/partners">Partners<span class="caret"></span></a>'; | |
| $mobile .= wp_nav_menu( [ | |
| 'menu' => 'partners', | |
| 'theme_location' => 'secondary', | |
| 'depth' => 3, | |
| 'container' => 'ul', | |
| 'container_id' => '', | |
| 'menu_class' => '', | |
| 'fallback_cb' => 'wp_bootstrap_navwalker::fallback', | |
| 'walker' => new wp_bootstrap_navwalker(), | |
| 'echo' => false | |
| ] ); | |
| $mobile .= '</li><li id="news-mobile" class="mobile-section"><a href="/news">News</a></li>'; | |
| return $mobile; | |
| } | |
| function getRegionsArray() { | |
| $regionsArray = []; | |
| $regionsData = getClinicData('select DISTINCT STATE_ID, REGION_1, REGION_2, REGION_3, STATE from dbo.CLINICS_DATA WHERE INCLUDEINSEARCH = 1 ORDER BY STATE_ID'); | |
| foreach($regionsData as $location) { | |
| // d($location); | |
| $state = $location['STATE_ID']; | |
| if(!array_key_exists($state, $regionsArray)) { | |
| $regionsArray[$state] = []; | |
| } | |
| foreach($location as $index => $value) { | |
| if(strpos($index, 'REGION') > -1) { | |
| if(!is_null($value) && $value != '' && $value != ' ') { | |
| if(!array_key_exists($value, $regionsArray[$state]) && !in_array($value, $regionsArray[$state])) { | |
| array_push($regionsArray[$state], $value); | |
| } | |
| } | |
| } | |
| } | |
| if(array_key_exists('STATE', $location)) { | |
| $regionsArray[$state]['abbr'] = $location['STATE']; | |
| } | |
| } | |
| return $regionsArray; | |
| } | |
| function getClinicRegionMenu() { | |
| $regions_data = getRegionsArray(); | |
| foreach($regions_data as $state => $regionArray ) { | |
| $state_short = $regionArray['abbr']; | |
| unset($regionArray['abbr']); | |
| ?> | |
| <p class="state"><?php echo $state; ?> <span>+</span></p> | |
| <ul style="display:none;"> | |
| <?php | |
| if(count($regionArray) > 0) { | |
| foreach($regionArray as $region) { | |
| ?> | |
| <li data-type="region" data-region="<?php echo $region; ?>"><?php echo $region; ?></li> | |
| <?php | |
| } | |
| } else { | |
| ?> | |
| <ul style="display:none;"> | |
| <li data-type="state" data-state="<?php echo $state_short; ?>">All <?php echo $state; ?> Clinics</li> | |
| </ul> | |
| <?php | |
| } | |
| ?> | |
| </ul> | |
| <?php | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment