/** * Show a single client link field inputs. * * @since 1.21.0 * * @param $key * @param $field_name * @param $type * @param $field * @param bool|false $adding */ function wpmtst_view_field_link($key, $field_name, $type, $field, $adding = false) { if ($field_name) { $current_field = wpmtst_get_field_by_name($field_name); if (is_array($current_field)) { $field = array_merge($current_field, $field); } } $custom_fields = wpmtst_get_custom_fields(); // Add placeholder link_text and label to field in case we need to populate link_text if (!isset($field['link_text'])) { $field['link_text'] = 'field'; } if (!isset($field['link_text_custom'])) { $field['link_text_custom'] = ''; } $field['label'] = wpmtst_get_field_label($field); ?> <!-- the link text --> <div class="field-meta-row link-text"> <label for="view-fieldtext<?php echo $key; ?> ">Text</label> <select id="view-fieldtext<?php echo $key; ?> " name="view[data][client_section][<?php echo $key; ?> ][link_text]" class="if selectgroup"> <option value="value" <?php selected($field['link_text'], 'value'); ?> >this field's value</option> <option value="label" <?php selected($field['link_text'], 'label'); ?> >this field's label</option> <option value="custom" <?php selected($field['link_text'], 'custom'); ?> >custom text</option> </select> </div> <!-- the link text options --> <div class="field-meta-row link-text"> <div class="then_fieldtext<?php echo $key; ?> then_value then_not_label then_not_custom" style="display: none;"> <!-- placeholder --> </div> <div class="then_fieldtext<?php echo $key; ?> then_label then_not_value then_not_custom" style="display: none;"> <input type="text" id="view-fieldtext<?php echo $key; ?> -label" value="<?php echo $field['label']; ?> " readonly> </div> <div class="then_fieldtext<?php echo $key; ?> then_custom then_not_value then_not_label" style="display: none;"> <input type="text" id="view-fieldtext<?php echo $key; ?> -custom" name="view[data][client_section][<?php echo $key; ?> ][link_text_custom]" value="<?php echo $field['link_text_custom']; ?> "> </div> </div> <!-- the URL --> <?php if ('link' == $type) { // URL = another field ?> <div class="field-meta-row"> <label for="view-fieldurl<?php echo $key; ?> ">URL</label> <select id="view-fieldurl<?php echo $key; ?> " name="view[data][client_section][<?php echo $key; ?> ][url]" class="field-type-select"> <?php foreach ($custom_fields as $key2 => $field2) { ?> <?php if ('url' == $field2['input_type']) { ?> <option value="<?php echo $field2['name']; ?> " <?php selected($field2['name'], $field['url']); ?> ><?php echo $field2['name']; ?> </option> <?php } ?> <?php } ?> </select> </div> <?php } else { // URL = this field ?> <input type="hidden" name="view[data][client_section][<?php echo $key; ?> ][url]" value="<?php echo $field['name']; ?> "> <?php } ?> <!-- the URL options --> <div class="field-meta-row checkbox"> <label> <div class="new_tab"> <input type="checkbox" id="<?php echo $key; ?> -newtab" name="view[data][client_section][<?php echo $key; ?> ][new_tab]" value="1" <?php checked($field['new_tab']); ?> > <label for="<?php echo $key; ?> -newtab"> <?php _e('new tab', 'strong-testimonials'); ?> </label> </div> </label> </div> <?php }
/** * Client section * * @since 1.21.0 * @param array $client_section An array of client fields. * * @return mixed */ function wpmtst_client_section($client_section) { global $post; $html = ''; foreach ($client_section as $field) { // Get label. $field['label'] = wpmtst_get_field_label($field); switch ($field['type']) { case 'link': case 'link2': // use default if missing // TODO is this necessary? check after testing upgrade process if (!isset($field['link_text'])) { $field['link_text'] = 'field'; } /** * Get link text and an alternate in case the URL is empty; * e.g. display the domain if no company name given * but don't display 'LinkedIn' if no URL given. */ $text_if_no_url = ''; switch ($field['link_text']) { case 'custom': $text = $field['link_text_custom']; break; case 'label': $text = $field['label']; break; default: $text = get_post_meta($post->ID, $field['field'], true); $text_if_no_url = $text; } $url = get_post_meta($post->ID, $field['url'], true); if ($url) { $new_tab = isset($field['new_tab']) ? $field['new_tab'] : false; // TODO Make this a global plugin option. $nofollow = get_post_meta($post->ID, 'nofollow', true); // if field empty, use domain instead if ('' == $text) { $text = preg_replace('(^https?://)', '', $url); } $output = sprintf('<a href="%s"%s%s>%s</a>', $url, link_new_tab($new_tab, false), link_nofollow($nofollow, false), $text); } else { // if no URL, show the alternate (usually the field) $output = $text_if_no_url; } break; case 'date': $format = isset($field['format']) && $field['format'] ? $field['format'] : get_option('date_format'); if ('post_date' == $field['field']) { $the_date = mysql2date($format, $post->post_date); } else { $the_date = get_post_meta($post->ID, $field['field'], true); if (get_option('date_format') != $format) { // Requires PHP 5.3+ if (version_compare(PHP_VERSION, '5.3') >= 0) { $new_date = DateTime::createFromFormat(get_option('date_format'), $the_date); if ($new_date) { $the_date = $new_date->format($format); } } } } $output = apply_filters('wpmtst_the_date', $the_date, $format, $post); break; default: // text field $output = get_post_meta($post->ID, $field['field'], true); } if ($output) { $html .= '<div class="' . $field['class'] . '">' . $output . '</div>'; } } return $html; }