', $hidden, $name, $name, $dataset, $name, $labelBefore, $off, $on, $labelAfter ); } /** * @param int $ID * @param string $type * @return string */ function jvbRenderLinks(int $ID, string $type =''):string { $cache = Cache::for('user_links', WEEK_IN_SECONDS)->connect('post')->connect('taxonomy')->connect('user'); $cached = $cache->get($ID); if ($cached) { return $cached; } $meta = match($type){ 'post' => Meta::forPost($ID), 'term' => Meta::forTerm($ID), 'user' => Meta::forUser($ID), default => false }; if (!$meta) { $meta = jvbGetMeta($ID); } if (!$meta) { return ''; } $links = $meta->get('links'); $out = ''; if (!empty($links)) { $out = ''; } $cache->set($ID, $out); return $out; } /** * @param int $ID * @param string $type * * @return string */ function jvbRenderContactInfo(int $ID, string $type = ''):string { $cache = Cache::for('contact', WEEK_IN_SECONDS)->connect('post')->connect('taxonomy'); $cached = $cache->get($ID); if($cached){ return $cached; } $meta = match($type){ 'post' => Meta::forPost($ID), 'term' => Meta::forTerm($ID), 'user' => Meta::forUser($ID), default => false }; if (!$meta) { $meta = jvbGetMeta($ID); } if (!$meta) { return ''; } $preference = $meta->get('public_contact'); $preference = (is_array($preference)) ? $preference : explode(',', $preference); $out = ''; if (!empty($preference)) { $out = ''; } $cache->set($ID, $out); return $out; } /** * @param int $ID * @param string $type * @return string */ function jvbRenderSpecialtyField(int $ID, string $type = ''):string { $meta = match($type){ 'post' => Meta::forPost($ID), 'term' => Meta::forTerm($ID), 'user' => Meta::forUser($ID), default => false }; if (!$meta) { $meta = jvbGetMeta($ID); } if (!$meta) { return ''; } $out = ''; $specialties = $meta->get('specialties'); if (!empty($specialties)) { foreach ($specialties as $specialty) { $out .= '
  • '.$specialty['specialty'].''; if ($specialty['description'] !== '') { $out .= apply_filters('the_content', $specialty['description']); } $out .= '
  • '; } } if ($out !== '') { $out = ''; } return $out; } /** * @param int $ID * @param string $type = '' * @return string */ function jvbRenderAwardsField(int $ID, string $type = ''):string { $meta = match($type){ 'post' => Meta::forPost($ID), 'term' => Meta::forTerm($ID), 'user' => Meta::forUser($ID), default => false }; if (!$meta) { $meta = jvbGetMeta($ID); } if (!$meta) { return ''; } $out = ''; $awards = $meta->get('awards'); if (!empty($awards)) { foreach ($awards as $award) { $out .= '
  • '.$award['name'].''; $out .= ($award['presenter'] !== '') ? ' | '.$award['presenter'].'' : ''; $out .= ($award['year'] !== '') ? ', '.$award['year'] : ''; $out .= '
  • '; } } if ($out !== '') { $out = ''; } return $out; } /** * @param int $ID * @param string $type * @return string */ function jvbRenderReviewsField(int $ID, string $type = ''):string { $meta = match($type){ 'post' => Meta::forPost($ID), 'term' => Meta::forTerm($ID), 'user' => Meta::forUser($ID), default => false }; if (!$meta) { $meta = jvbGetMeta($ID); } if (!$meta) { return ''; } $out = ''; $reviews = $meta->get('reviews'); if (!empty($reviews)) { foreach ($reviews as $review) { if ($review['review'] === '') { continue; } $out .= '
  • '.apply_filters('the_content', $review['review']); if ($review['name'] !== '' || $review['rating'] !== 'none') { $date = $aOpen = $aClose = ''; if ($review['url']) { $aOpen = ''; $aClose = ''; } if ($review['date'] !== '') { $date = new Date('M j, Y', strtotime($review['date'])); } $out .= ''; if ($review['rating'] !== 'none') { $out .= jvbFormatStarRating($review['rating']); } if ($review['name'] !== '') { $out .= $aOpen.$review['name'].$aClose; } if ($date !== '') { $out .= $date; } $out .= ''; } $out .= '
  • '; } } if ($out !== '') { $out = ''; } return $out; } function jvbGetMeta(int $ID):Meta|false { if (term_exists($ID)) { return Meta::forTerm($ID); } elseif (get_post_status($ID)) { return Meta::forPost($ID); } elseif (get_userdata($ID)) { return Meta::forUser($ID); } else { return false; } } function jvbRenderTermList(array|bool|WP_Error $terms, string $label = ''):string { if (!$terms || is_wp_error($terms) || empty($terms)) { return ''; } $out = ($label === '') ? '' : '

    '.$label.'

    '; $out .= ''; return $out; } function jvbGetTermLink(int|WP_Term $term, string $taxonomy = ''):string { if (is_int($term)){ $term = get_term($term, jvbCheckBase($taxonomy)); if (is_wp_error($term)) { return ''; } } $cache = Cache::for($term->taxonomy.'_link')->connect('taxonomy'); $key = $term->term_id; return $cache->remember( $key, function() use ($term) { return ''. html_entity_decode($term->name). ''; } ); } add_action('wp_footer', 'jvbOutputImageTemplates'); function jvbOutputImageTemplates() { if (wp_script_is('jvb-form')) { jvbInlineStyles('forms'); ?> connect('taxonomy'); $key = $cache->generateKey($location); $cached = false; if ($cached) { return $cached; } $firstPart = [ $location['street'], $location['city'], $location['province'], $location['postal_code'], $location['country'], ]; $address = implode(', ',$firstPart); $coords = $location['lat'].','.$location['lng']; $googleAddress = urlencode($coords.','.$address); $appAddress = urlencode($address); $google_url = "https://www.google.com/maps/dir/?api=1&destination={$googleAddress}"; $apple_url = "https://maps.apple.com/?daddr={$appAddress}"; $apple = sprintf( '%s', $apple_url, jvbIcon('apple-logo') ); $google = sprintf( '%s', $google_url, jvbIcon('google-logo') ); $cached = '

    '.jvbIcon('map-pin').'Find us here: '.$google.$apple.'

    '; $cache->set($key, $cached); return $cached; } add_action('jvbRenderFormField', 'jvbFormFields', 10, 3); function jvbFormFields(string $name, array $config, mixed $value):void { switch ($name) { case 'hours': echo jvbCopyHoursTemplate(); break; } }