public function __construct($field_id, $field)
 {
     // Call parent constructor
     parent::__construct($field_id, $field);
     // Checkboxes need a custom wrapper class
     add_filter('wpas_cf_wrapper_class', array($this, 'wrapper_class'), 10, 2);
 }
 public function __construct($field_id, $field)
 {
     /* Call the parent constructor */
     parent::__construct($field_id, $field);
     /* Set the additional parameters */
     if (!isset($this->field_args['multiple'])) {
         $this->field_args['multiple'] = false;
     }
     /* Change the field name if multiple upload is enabled */
     add_filter('wpas_cf_field_atts', array($this, 'edit_field_atts'), 10, 3);
 }
 public function __construct($field_id, $field)
 {
     /* Call the parent constructor */
     parent::__construct($field_id, $field);
     // Set the additional parameters
     $this->field_args['multiple'] = isset($this->field_args['multiple']) ? (bool) $this->field_args['multiple'] : false;
     $this->field_args['select2'] = isset($this->field_args['select2']) ? (bool) $this->field_args['select2'] : false;
     /* Change the field name if multiple upload is enabled */
     if (true === $this->field_args['multiple']) {
         add_filter('wpas_cf_field_atts', array($this, 'edit_field_atts'), 10, 3);
     }
     if (true === $this->field_args['select2']) {
         add_filter('wpas_cf_field_class', array($this, 'add_select2_class'), 10, 2);
     }
 }
 public function __construct($field_id, $field)
 {
     /* Call the parent constructor */
     parent::__construct($field_id, $field);
     $args = func_get_args();
     call_user_func_array(array($this, 'parent::__construct'), $args);
     $this->terms = get_terms($this->field_id, array('hide_empty' => 0));
     $this->ordered_terms = array();
     if (!is_wp_error($this->terms)) {
         /**
          * Re-order the terms hierarchically.
          */
         wpas_sort_terms_hierarchicaly($this->terms, $this->ordered_terms);
     }
 }
 public function __construct($field_id, $field)
 {
     /* Call the parent constructor */
     parent::__construct($field_id, $field);
     $args = func_get_args();
     call_user_func_array(array($this, 'parent::__construct'), $args);
     $this->terms = get_terms($this->field_id, array('hide_empty' => 0));
     $this->ordered_terms = array();
     $this->field_args['select2'] = isset($this->field_args['select2']) ? (bool) $this->field_args['select2'] : false;
     if (!is_wp_error($this->terms)) {
         /**
          * Re-order the terms hierarchically.
          */
         wpas_sort_terms_hierarchicaly($this->terms, $this->ordered_terms);
     }
     if (true === $this->field_args['select2']) {
         add_filter('wpas_cf_field_class', array($this, 'add_select2_class'), 10, 2);
     }
 }
 /**
  * Add dropzone markup.
  * 
  * @return void
  */
 public function upload_field()
 {
     $filetypes = $this->get_allowed_filetypes();
     $filetypes = explode(',', $filetypes);
     $accept = array();
     foreach ($filetypes as $key => $type) {
         $filetypes[$key] = "<code>.{$type}</code>";
         array_push($accept, ".{$type}");
     }
     $filetypes = implode(', ', $filetypes);
     $accept = implode(',', $accept);
     /**
      * Output the upload field using a custom field
      */
     $attachments_args = apply_filters('wpas_ticket_attachments_field_args', array('name' => $this->index, 'args' => array('required' => false, 'capability' => 'edit_ticket', 'field_type' => 'upload', 'multiple' => true, 'label' => __('Attachments', 'awesome-support'), 'desc' => sprintf(__(' You can upload up to %d files (maximum %d MB each) of the following types: %s', 'awesome-support'), (int) wpas_get_option('attachments_max'), (int) wpas_get_option('filesize_max'), apply_filters('wpas_attachments_filetypes_display', $filetypes)))));
     $attachments = new WPAS_Custom_Field($this->index, $attachments_args);
     echo $attachments->get_output();
 }
    /**
     * Add dropzone markup.
     * 
     * @return void
     */
    public function upload_field()
    {
        $filetypes = $this->get_allowed_filetypes();
        $filetypes = explode(',', $filetypes);
        $accept = array();
        foreach ($filetypes as $key => $type) {
            $filetypes[$key] = "<code>.{$type}</code>";
            array_push($accept, ".{$type}");
        }
        $filetypes = implode(', ', $filetypes);
        $accept = implode(',', $accept);
        /**
         * Output the upload field using a custom field
         */
        $attachments_args = apply_filters('wpas_ticket_attachments_field_args', array('name' => $this->index, 'args' => array('required' => false, 'capability' => 'edit_ticket', 'field_type' => 'upload', 'multiple' => true, 'label' => __('Attachments', 'wpas'), 'desc' => sprintf(__(' You can upload up to %d files (maximum %d MB each) of the following types: %s', 'wpas'), (int) wpas_get_option('attachments_max'), (int) wpas_get_option('filesize_max'), apply_filters('wpas_attachments_filetypes_display', $filetypes)))));
        $attachments = new WPAS_Custom_Field($this->index, $attachments_args);
        echo $attachments->get_output();
        ?>

<!--		<div class="wpas-form-group wpas-attachment-container">-->
<!--			<label for="wpas-file-upload">--><?php 
        //_e( 'Attachments', 'wpas' );
        ?>
<!--</label>-->
<!--			<input type="file" name="--><?php 
        //echo $this->index;
        ?>
<!--[]" id="wpas-file-upload" class="wpas-form-control" accept="--><?php 
        //echo $accept;
        ?>
<!--" multiple>-->
<!--			<p class="wpas-help-block">--><?php 
        //printf( __( ' You can upload up to %d files (maximum %d MB each) of the following types: %s', 'wpas' ), (int) wpas_get_option( 'attachments_max' ), (int) wpas_get_option( 'filesize_max' ), apply_filters('wpas_attachments_filetypes_display', $filetypes ) );
        ?>
<!--</p>-->
<!--		</div>-->

	<?php 
    }
 /**
  * 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;
 }
Example #9
0
">
			<h3><?php 
    _e('Register', 'awesome-support');
    ?>
</h3>

			<?php 
    $first_name = new WPAS_Custom_Field('first_name', array('name' => 'first_name', 'args' => array('required' => true, 'field_type' => 'text', 'label' => __('First Name', 'awesome-support'), 'placeholder' => __('First Name', 'awesome-support'), 'sanitize' => 'sanitize_text_field')));
    echo $first_name->get_output();
    $last_name = new WPAS_Custom_Field('last_name', array('name' => 'last_name', 'args' => array('required' => true, 'field_type' => 'text', 'label' => __('Last Name', 'awesome-support'), 'placeholder' => __('Last Name', 'awesome-support'), 'sanitize' => 'sanitize_text_field')));
    echo $last_name->get_output();
    $email = new WPAS_Custom_Field('email', array('name' => 'email', 'args' => array('required' => true, 'field_type' => 'email', 'label' => __('Email', 'awesome-support'), 'placeholder' => __('Email', 'awesome-support'), 'sanitize' => 'sanitize_text_field')));
    echo $email->get_output();
    $pwd = new WPAS_Custom_Field('password', array('name' => 'password', 'args' => array('required' => true, 'field_type' => 'password', 'label' => __('Enter a password', 'awesome-support'), 'placeholder' => __('Password', 'awesome-support'), 'sanitize' => 'sanitize_text_field')));
    echo $pwd->get_output();
    $showpwd = new WPAS_Custom_Field('pwdshow', array('name' => 'pwdshow', 'args' => array('required' => false, 'field_type' => 'checkbox', 'sanitize' => 'sanitize_text_field', 'options' => array('1' => _x('Show Password', 'Login form', 'awesome-support')))));
    echo $showpwd->get_output();
    /**
     * wpas_after_registration_fields hook
     * 
     * @Awesome_Support::terms_and_conditions_checkbox()
     */
    do_action('wpas_after_registration_fields');
    wpas_do_field('register', $redirect_to);
    wp_nonce_field('register', 'user_registration', false, true);
    wpas_make_button(__('Create Account', 'awesome-support'), array('onsubmit' => __('Creating Account...', 'awesome-support')));
    ?>
		</form>
	<?php 
}
?>
Example #10
0
		<?php 
/**
 * The wpas_submission_form_inside_before has to be placed
 * inside the form, right in between the form opening tag
 * and the subject field.
 *
 * @since  3.0.0
 */
do_action('wpas_submission_form_inside_before_subject');
/**
 * Filter the subject field arguments
 *
 * @since 3.2.0
 */
$subject_args = apply_filters('wpas_subject_field_args', array('name' => 'title', 'args' => array('required' => true, 'field_type' => 'text', 'label' => __('Complain (max 50 char)', 'wpas'), 'sanitize' => 'sanitize_text_field')));
$subject = new WPAS_Custom_Field('title', $subject_args);
echo $subject->get_output();
/**
 * The wpas_submission_form_inside_after_subject hook has to be placed
 * right after the subject field.
 *
 * This hook is very important as this is where the custom fields are hooked.
 * Without this hook custom fields would not display at all.
 *
 * @since  3.0.0
 */
do_action('wpas_submission_form_inside_after_subject');
/**
 * Filter the description field arguments
 *
 * @since 3.2.0
/**
 * Return a custom field value.
 *
 * @param  string  $name    Option name
 * @param  integer $post_id Post ID
 * @param  mixed   $default Default value
 *
 * @return mixed            Meta value
 * @since  3.0.0
 */
function wpas_get_cf_value($name, $post_id, $default = false)
{
    $field = new WPAS_Custom_Field($name);
    return $field->get_field_value($default, $post_id);
}
Example #12
0
 * @since  3.0.0
 */
do_action('wpas_submission_form_inside_before_subject');
$subject = new WPAS_Custom_Field('title', array('name' => 'title', 'args' => array('required' => true, 'field_type' => 'text', 'label' => 'Subject')));
echo $subject->get_output();
/**
 * The wpas_submission_form_inside_after_subject hook has to be placed
 * right after the subject field.
 *
 * This hook is very important as this is where the custom fields are hooked.
 * Without this hook custom fields would not display at all.
 *
 * @since  3.0.0
 */
do_action('wpas_submission_form_inside_after_subject');
$body = new WPAS_Custom_Field('message', array('name' => 'message', 'args' => array('required' => true, 'field_type' => 'wysiwyg', 'label' => 'Description')));
echo $body->get_output();
/**
 * The wpas_submission_form_inside_before hook has to be placed
 * right before the submission button.
 *
 * @since  3.0.0
 */
do_action('wpas_submission_form_inside_before_submit');
wp_nonce_field('new_ticket', 'wpas_nonce', false, true);
wpas_make_button(__('Submit ticket', 'wpas'), array('name' => 'wpas-submit', 'onsubmit' => __('Please Wait...', 'wpas')));
/**
 * The wpas_submission_form_inside_before hook has to be placed
 * right before the form closing tag.
 *
 * @since  3.0.0
/**
 * Add the terms and conditions checkbox.
 *
 * Adds a checkbox to the registration form if there are
 * terms and conditions set in the plugin settings.
 *
 * @since  3.0.0
 * @return void
 */
function wpas_terms_and_conditions_checkbox()
{
    $terms = wpas_get_option('terms_conditions', '');
    if (empty($terms)) {
        return;
    }
    $terms = new WPAS_Custom_Field('terms', array('name' => 'terms', 'args' => array('required' => true, 'field_type' => 'checkbox', 'sanitize' => 'sanitize_text_field', 'options' => array('1' => sprintf(__('I accept the %sterms and conditions%s', 'awesome-support'), '<a href="#wpas-modalterms" class="wpas-modal-trigger">', '</a>')))));
    echo $terms->get_output();
}
 public function test_get_field_class()
 {
     $this->assertEquals('wpas-form-control', $this->text_field->get_field_class());
     $this->assertEquals('wpas-form-control test', $this->text_field->get_field_class(array('test')));
 }