Exemplo n.º 1
0
 /**
  * Get all the registered custom fields and display them
  * on the ticket submission form on the front-end.
  *
  * @since  3.0.0
  */
 public static function submission_form_fields()
 {
     /* Get all the registered fields from the $wpas_cf object */
     global $wpas_cf;
     $fields = $wpas_cf->get_custom_fields();
     if (!empty($fields)) {
         foreach ($fields as $name => $field) {
             /* Do not display core fields */
             if (true === $field['args']['core']) {
                 continue;
             }
             $title = !empty($field['args']['title']) ? $field['args']['title'] : wpas_get_title_from_id($name);
             $callback = !empty($field['args']['callback']) ? $field['args']['callback'] : 'text';
             /* Check for a custom function */
             if (function_exists($callback)) {
                 call_user_func($callback, $field);
             } elseif (method_exists('WPAS_Custom_Fields_Display', $callback)) {
                 call_user_func(array('WPAS_Custom_Fields_Display', $callback), $field);
             } else {
                 WPAS_Custom_Fields_Display::text($field);
             }
         }
     }
 }
/**
 * Get tickets list columns.
 *
 * Retrieve the columns to display on the list of tickets
 * in the client area. The columns include the 3 basic ones
 * (status, title and date), and also the custom fields that are
 * set to show on front-end (and that are not core CF).
 *
 * @since  3.0.0
 * @return array The list of columns with their title and callback
 */
function wpas_get_tickets_list_columns()
{
    global $wpas_cf;
    $custom_fields = $wpas_cf->get_custom_fields();
    $columns = array('status' => array('title' => __('Status', 'awesome-support'), 'callback' => 'wpas_cf_display_status'), 'title' => array('title' => __('Title', 'awesome-support'), 'callback' => 'title'), 'date' => array('title' => __('Date', 'awesome-support'), 'callback' => 'date'));
    foreach ($custom_fields as $field) {
        /* Don't display core fields */
        if (true === $field['args']['core']) {
            continue;
        }
        /* Don't display fields that aren't specifically designed to */
        if (true === $field['args']['show_column']) {
            $column_title = !empty($field['args']['title']) ? sanitize_text_field($field['args']['title']) : wpas_get_title_from_id($field['name']);
            $column_callback = 'taxonomy' === $field['args']['field_type'] && true === $field['args']['taxo_std'] ? 'taxonomy' : $field['args']['column_callback'];
            $columns[$field['name']] = array('title' => $column_title, 'callback' => $column_callback);
        }
    }
    return apply_filters('wpas_tickets_list_columns', $columns);
}
Exemplo n.º 3
0
function wpas_get_field_title($field)
{
    if (!empty($field['args']['title'])) {
        return sanitize_text_field($field['args']['title']);
    } else {
        return wpas_get_title_from_id($field['name']);
    }
}
 /**
  * Makes sure no required custom field is missing from the data passed.
  *
  * @since 3.2.0
  *
  * @param array $data Array of data to check
  *
  * @return bool|WP_Error False if no field is missing, WP_Error with the list of missing fields otherwise
  */
 public function is_field_missing($data = array())
 {
     if (empty($data) && !empty($_POST)) {
         $data = $_POST;
     }
     $fields = $this->get_custom_fields();
     /* Set the result as true by default, which is the "green light" value */
     $result = false;
     foreach ($fields as $field_id => $field) {
         /**
          * Get the custom field object.
          */
         $custom_field = new WPAS_Custom_Field($field_id, $field);
         /* Prepare the field name as used in the form */
         $field_name = $custom_field->get_field_id();
         if (true === $field['args']['required'] && false === $field['args']['core']) {
             if (!isset($data[$field_name]) || empty($data[$field_name])) {
                 /* Get field title */
                 $title = !empty($field['args']['title']) ? $field['args']['title'] : wpas_get_title_from_id($field['name']);
                 /* Add the error message for this field. */
                 if (!is_object($result)) {
                     $result = new WP_Error('required_field_missing', sprintf(__('The field %s is required.', 'wpas'), "<a href='#{$field_name}'><code>{$title}</code></a>", array('errors' => $field_name)));
                 } else {
                     $result->add('required_field_missing', sprintf(__('The field %s is required.', 'wpas'), "<code>{$title}</code>", array('errors' => $field_name)));
                 }
             }
         }
     }
     return $result;
 }
/**
 * Get the ticket header.
 *
 * @since  3.0.0
 * @param  array  $args Additional parameters
 * @return void
 */
function wpas_ticket_header($args = array())
{
    global $post;
    $default = array('container' => '', 'container_id' => '', 'container_class' => '', 'table_id' => "header-ticket-{$post->ID}", 'table_class' => 'wpas-table wpas-ticket-details-header');
    $args = wp_parse_args($args, $default);
    $custom_fields = WPAS()->custom_fields->get_custom_fields();
    $columns = array('id' => __('ID', 'awesome-support'), 'status' => __('Status', 'awesome-support'), 'date' => __('Date', 'awesome-support'));
    $columns_callbacks = array('id' => 'id', 'status' => 'wpas_cf_display_status', 'date' => 'date');
    foreach ($custom_fields as $field) {
        /* Don't display core fields */
        if (true === $field['args']['core']) {
            continue;
        }
        /* Don't display fields that aren't specifically designed to */
        if (true === $field['args']['show_column']) {
            $columns[$field['name']] = !empty($field['args']['title']) ? sanitize_text_field($field['args']['title']) : wpas_get_title_from_id($field['name']);
            $columns_callbacks[$field['name']] = 'taxonomy' === $field['args']['field_type'] && true === $field['args']['taxo_std'] ? 'taxonomy' : $field['args']['column_callback'];
        }
    }
    $columns = apply_filters('wpas_tickets_details_columns', $columns);
    $columns_callbacks = apply_filters('wpas_tickets_details_columns_callbacks', $columns_callbacks);
    ?>

	<?php 
    if (!empty($args['container'])) {
        ?>
<<?php 
        echo $args['container'];
        ?>
><?php 
    }
    ?>

		<table id="<?php 
    echo $args['table_id'];
    ?>
" class="<?php 
    echo $args['table_class'];
    ?>
">
			<thead>
				<tr>
					<?php 
    foreach ($columns as $column => $label) {
        ?>
						<th><?php 
        echo $label;
        ?>
</th>
					<?php 
    }
    ?>
				</tr>
			</thead>
			<tbody>
				<tr>
					<?php 
    foreach ($columns_callbacks as $column => $callback) {
        ?>
						<td>
							<?php 
        wpas_get_tickets_list_column_content($column, array('callback' => $callback));
        ?>
						</td>
					<?php 
    }
    ?>
				</tr>
			</tbody>
		</table>

	<?php 
    if (!empty($args['container'])) {
        ?>
</<?php 
        echo $args['container'];
        ?>
><?php 
    }
}
Exemplo n.º 6
0
 /**
  * Checks required custom fields.
  *
  * This function is hooked on the filter wpas_before_submit_new_ticket_checks
  * through the parent class. It checks all required custom fields
  * and if they were correctly filled. If one or more required field(s) is/are
  * missing then the submission process is stopped and an error message is returned.
  *
  * @since  3.0.0
  * @return mixed True if no error or a WP_Error otherwise
  */
 public function check_required_fields()
 {
     /* Get all registered custom fields */
     global $wpas_cf;
     $fields = $wpas_cf->get_custom_fields();
     /* Set the result as true by default, which is the "green light" value */
     $result = false;
     foreach ($fields as $field) {
         /* Prepare the field name as used in the form */
         $field_name = 'wpas_' . $field['name'];
         if (true === $field['args']['required'] && false === $field['args']['core']) {
             if (!isset($_POST[$field_name]) || empty($_POST[$field_name])) {
                 /* Get field title */
                 $title = !empty($field['args']['title']) ? $field['args']['title'] : wpas_get_title_from_id($field['name']);
                 /* Add the error message for this field. */
                 if (!is_object($result)) {
                     $result = new WP_Error('required_field_missing', sprintf(__('The field %s is required.', 'wpas'), "<code>{$title}</code>", array('errors' => $field_name)));
                 } else {
                     $result->add('required_field_missing', sprintf(__('The field %s is required.', 'wpas'), "<code>{$title}</code>", array('errors' => $field_name)));
                 }
                 /* Set the field as incorrect. */
                 if (!isset($_SESSION['wpas_submission_error'])) {
                     $_SESSION['wpas_submission_error'] = array();
                 }
                 if (!in_array($field_name, $_SESSION['wpas_submission_error'])) {
                     array_push($_SESSION['wpas_submission_error'], $field_name);
                 }
             }
         }
     }
     return $result;
 }