/** * General function to output HTML for custom fields * * * @since 1.1.9 * * @param $field_slug * @param null $job_id * @param $field_value * @param array $args */ function the_custom_field_output_as($field_slug, $job_id = null, $field_value, $args = array()) { if ($field_value !== 0 && empty($field_value)) { return; } $tax_labels = array(); $label_show_colon = true; // Handle multiple values output (probably file upload) if (is_array($field_value) && isset($args['multiple']) && $args['multiple'] > 0) { // Put label in its own div for mutliple output if (!empty($args['output_show_label'])) { echo "<div id=\"jmfe-wrap-{$field_slug}-multi-label\" class=\"jmfe-custom-field-wrap jmfe-custom-field-multi-label\">"; echo "<strong id=\"jmfe-label-{$field_slug}\" class=\"jmfe-custom-field-label\">{$args['label']}:</strong> "; echo "</div>"; $args['output_show_label'] = 0; } foreach ($field_value as $single_value) { the_custom_field_output_as($field_slug, null, $single_value, $args); } return; } // Output array as comma separated values if (is_array($field_value)) { $field_value = implode(', ', $field_value); } $output_as = !empty($args['output_as']) ? $args['output_as'] : ''; $extra_classes = !empty($args['output_classes']) ? $args['output_classes'] : ''; $oembed_args = array(); $oembed_args['width'] = !empty($args['output_oembed_width']) ? $args['output_oembed_width'] : ''; $oembed_args['height'] = !empty($args['output_oembed_height']) ? $args['output_oembed_height'] : ''; $open_wrapper = "<div id=\"jmfe-wrap-{$field_slug}\" class=\"jmfe-custom-field-wrap\">"; $close_wrapper = "</div>"; // If li should be used, replace wrapper open and close HTML if (isset($args['li']) && !empty($args['li'])) { $open_wrapper = "<li id=\"jmfe-wrap-{$field_slug}\" class=\"jmfe-custom-field-wrap\">"; $close_wrapper = "</li>"; } // If output as is checkbox label only if checked, set output_show_label to true if ($output_as == 'checklabel' && (int) $field_value == 1) { $label_show_colon = false; $args['output_show_label'] = true; } $label = !empty($args['output_show_label']) && !empty($args['label']) ? $args['label'] : NULL; ob_start(); echo $open_wrapper; // Show label if set if ($label) { if ($label_show_colon) { $label .= ':'; } echo "<strong id=\"jmfe-label-{$field_slug}\" class=\"jmfe-custom-field-label\">{$label}</strong> "; } switch ($output_as) { case 'oembed': $oembed_html = wp_oembed_get($field_value, $oembed_args); // Exit and clear buffer if error with oembed if (!$oembed_html) { ob_end_clean(); return; } echo "<div id=\"jmfe-custom-{$field_slug}\" class=\"jmfe-custom-field {$extra_classes}\">"; echo $oembed_html; echo "</div>"; break; case 'video': $video_width = isset($args['output_video_width']) && !empty($args['output_video_width']) ? " width=\"" . $args['output_video_width'] . "\"" : ''; $video_height = isset($args['output_video_height']) && !empty($args['output_video_height']) ? " height=\"" . $args['output_video_height'] . "\"" : ''; $video_poster = isset($args['output_video_poster']) && !empty($args['output_video_poster']) ? " poster=\"" . $args['output_video_poster'] . "\"" : ''; echo "<div id=\"jmfe-custom-{$field_slug}\" class=\"jmfe-custom-field {$extra_classes}\">"; echo "<video src=\"{$field_value}\"{$video_width}{$video_height}{$video_poster} controls>"; _e("Sorry, your browser doesn't support embedded videos, you should upgrade to a modern browser.", 'wp-job-manager-field-editor'); if (isset($args['output_video_allowdl']) && !empty($args['output_video_allowdl'])) { echo "<br />" . __("Or you can", 'wp-job-manager-field-editor') . " <a href=\"{$field_value}\">" . __("Download The File", 'wp-job-manager-field-editor') . "</a>. " . __("(right click and select Save As)", 'wp-job-manager-field-editor'); } echo "</video></div>"; break; case 'link': if (empty($args['output_caption'])) { $args['output_caption'] = $field_value; } echo "<a target=\"_blank\" id=\"jmfe-custom-{$field_slug}\" href=\"{$field_value}\" class=\"jmfe-custom-field {$extra_classes}\">{$args['output_caption']}</a>"; break; case 'image': echo "<img id=\"jmfe-custom-{$field_slug}\" src=\"{$field_value}\" class=\"jmfe-custom-field {$extra_classes}\" />"; break; // Output checkbox label only if checked has no output besides the label // Output checkbox label only if checked has no output besides the label case 'checklabel': break; case 'checkcustom': $check_caption = ''; // Checked if ((int) $field_value == 1) { $check_caption = __('True', 'wp-job-manager-field-editor'); if (!empty($args['output_check_true'])) { $check_caption = $args['output_check_true']; } } // Unchecked if ((int) $field_value == 0) { $check_caption == __('False', 'wp-job-manager-field-editor'); if (!empty($args['output_check_false'])) { $check_caption = $args['output_check_false']; } } echo "<div id=\"jmfe-custom-{$field_slug}\" class=\"jmfe-custom-field {$extra_classes}\">{$check_caption}</div>"; break; default: echo "<div id=\"jmfe-custom-{$field_slug}\" class=\"jmfe-custom-field {$extra_classes}\">{$field_value}</div>"; break; } echo $close_wrapper; ob_end_flush(); }
/** * Echo Custom Field Value * * Same as get_custom_field except will echo out the value * * @since 1.1.8 * * @param $field_slug Meta key from post * @param null $job_id Optional, Post ID to get value from * @param array $args * * @internal param null $output_as * @internal param null $caption * @internal param null $extra_classes */ function the_custom_field($field_slug, $job_id = null, $args = array()) { $field_value = get_custom_field($field_slug, $job_id); if (isset($args['output_as']) && !empty($args['output_as'])) { the_custom_field_output_as($field_slug, $job_id, $field_value, $args); } else { echo $field_value; } }