/**
  * Output for Shortcode
  *
  * @since 1.1.9
  *
  * @param $atts
  *
  * @return mixed|null
  */
 function shortcode_output($atts)
 {
     $default_atts = array('key' => '', 'field' => '', 'job_id' => get_the_ID());
     $merged_atts = array_merge($default_atts, $atts);
     try {
         // Attributes
         $args = shortcode_atts($merged_atts, $atts, 'jmfe');
         if (empty($args['key']) && empty($args['field'])) {
             throw new Exception(__('Meta Key was not specified!', 'wp-job-manager-field-editor'));
         }
         if (empty($args['job_id'])) {
             throw new Exception(__('Unable to determine correct job/resume/post ID!', 'wp-job-manager-field-editor'));
         }
         if ($args['key']) {
             $meta_key = $args['key'];
         }
         if ($args['field']) {
             $meta_key = $args['field'];
         }
         ob_start();
         the_custom_field($meta_key, $args['job_id'], $args);
         $shortcode_output = ob_get_contents();
         ob_end_clean();
         return $shortcode_output;
     } catch (Exception $error) {
         error_log('Shortcode output error: ' . $error->getMessage());
     }
 }
Esempio n. 2
0
 /**
  * Front-end display of widget (Widget Output)
  *
  * @see WP_Widget::widget()
  *
  * @param array $args     Widget arguments.
  * @param array $config   Saved values from database.
  */
 public function widget($args, $config)
 {
     if (!function_exists('the_custom_field') || !function_exists('get_custom_field')) {
         return;
     }
     if (empty($config['meta_key'])) {
         return;
     }
     $meta_key = $config['meta_key'];
     // Set output_classes key to extra_classes value to be compatible with function
     $config['output_classes'] = $config['extra_classes'];
     // Set output_caption = caption to be compatible with function
     $config['output_caption'] = $config['caption'];
     $custom_fields = $this->jmfe()->get_custom_fields(TRUE);
     foreach ($custom_fields as $group => $fields) {
         if (array_key_exists($meta_key, $fields)) {
             $config = array_merge($custom_fields[$group][$meta_key], $config);
             break;
         }
     }
     // Exit if there is no value for field (to prevent widget output)
     $field_value = get_custom_field($config['meta_key'], get_the_id(), $config);
     if (empty($field_value)) {
         return;
     }
     $widget_styles = isset($config['widget_styles']) && !empty($config['widget_styles']) ? true : false;
     if ($widget_styles) {
         echo $args['before_widget'];
         if (!empty($config['title'])) {
             echo $args['before_title'] . apply_filters('widget_title', $config['title']) . $args['after_title'];
         }
     }
     the_custom_field($config['meta_key'], NULL, $config);
     if ($widget_styles) {
         echo $args['after_widget'];
     }
 }
 /**
  * Output using the_custom_field with configuration
  *
  *
  * @since 1.1.9
  *
  * @param array $fields Field configuration for auto output
  */
 function do_auto_output($fields = array())
 {
     $li_actions = array('single_job_listing_meta_start', 'single_job_listing_meta_end', 'single_resume_meta_start', 'single_resume_meta_end');
     $fieldSort = new WP_Job_Manager_Field_Editor_Sort($fields, 'output_priority');
     $fields = $fieldSort->float();
     foreach ($fields as $meta_key => $config) {
         if (in_array($config['output'], $li_actions)) {
             $config['li'] = true;
         }
         if (function_exists('the_custom_field')) {
             the_custom_field($config['meta_key'], NULL, $config);
         }
     }
 }