/**
  * Renders an HTML Number field
  *
  * @since	1.0
  *
  * @param	arr		$args	Arguments for the text field
  * @return	str		Text field
  */
 public function number($args = array())
 {
     $defaults = array('id' => '', 'name' => isset($name) ? $name : 'text', 'value' => isset($value) ? $value : null, 'label' => isset($label) ? $label : null, 'desc' => isset($desc) ? $desc : null, 'placeholder' => '', 'class' => 'small-text', 'min' => '', 'max' => '', 'disabled' => false, 'autocomplete' => '', 'data' => false);
     $args = wp_parse_args($args, $defaults);
     $args['id'] = !empty($args['id']) ? $args['id'] : $args['name'];
     $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
     $disabled = '';
     if ($args['disabled']) {
         $disabled = ' disabled="disabled"';
     }
     $data = '';
     if (!empty($args['data'])) {
         foreach ($args['data'] as $key => $value) {
             $data .= 'data-' . kbs_sanitize_key($key) . '="' . esc_attr($value) . '" ';
         }
     }
     $min = !empty($args['min']) ? ' min="' . $args['min'] . '"' : '';
     $max = !empty($args['max']) ? ' max="' . $args['max'] . '"' : '';
     if ($max > 5) {
         $max = 5;
     }
     $output = '<span id="kbs-' . kbs_sanitize_key($args['name']) . '-wrap">';
     $output .= '<label class="kbs-label" for="' . kbs_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
     if (!empty($args['desc'])) {
         $output .= '<span class="kbs-description">' . esc_html($args['desc']) . '</span>';
     }
     $output .= '<input type="number" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . '' . $min . '' . $max . '' . $disabled . '/>';
     $output .= '</span>';
     return $output;
 }
Exemplo n.º 2
0
 function kbs_license_key_callback($args)
 {
     global $kbs_options;
     $messages = array();
     $license = get_option($args['options']['is_valid_license_option']);
     if (isset($kbs_options[$args['id']])) {
         $value = $kbs_options[$args['id']];
     } else {
         $value = isset($args['std']) ? $args['std'] : '';
     }
     if (!empty($license) && is_object($license)) {
         // activate_license 'invalid' on anything other than valid, so if there was an error capture it
         if (false === $license->success) {
             switch ($license->error) {
                 case 'expired':
                     $class = 'error';
                     $messages[] = sprintf(__('Your license key expired on %s. Please <a href="%s" target="_blank" title="Renew your license key">renew your license key</a>.', 'kb-support'), date_i18n(get_option('date_format'), strtotime($license->expires, current_time('timestamp'))), 'http://kb-support.com/checkout/?edd_license_key=' . $value);
                     $license_status = 'license-' . $class . '-notice';
                     break;
                 case 'missing':
                     $class = 'error';
                     $messages[] = sprintf(__('Invalid license. Please <a href="%s" target="_blank" title="Visit account page">visit your account page</a> and verify it.', 'kb-support'), 'http://kb-support.com/your-account');
                     $license_status = 'license-' . $class . '-notice';
                     break;
                 case 'invalid':
                 case 'site_inactive':
                     $class = 'error';
                     $messages[] = sprintf(__('Your %s is not active for this URL. Please <a href="%s" target="_blank" title="Visit account page">visit your account page</a> to manage your license key URLs.', 'kb-support'), $args['name'], 'http://kb-support.com/your-account');
                     $license_status = 'license-' . $class . '-notice';
                     break;
                 case 'item_name_mismatch':
                     $class = 'error';
                     $messages[] = sprintf(__('This is not a %s.', 'kb-support'), $args['name']);
                     $license_status = 'license-' . $class . '-notice';
                     break;
                 case 'no_activations_left':
                     $class = 'error';
                     $messages[] = sprintf(__('Your license key has reached its activation limit. <a href="%s">View possible upgrades</a> now.', 'kb-support'), 'http://kb-support.com/your-account/');
                     $license_status = 'license-' . $class . '-notice';
                     break;
             }
         } else {
             switch ($license->license) {
                 case 'valid':
                 default:
                     $class = 'valid';
                     $now = current_time('timestamp');
                     $expiration = strtotime($license->expires, current_time('timestamp'));
                     if ('lifetime' === $license->expires) {
                         $messages[] = __('License key never expires.', 'kb-support');
                         $license_status = 'license-lifetime-notice';
                     } elseif ($expiration > $now && $expiration - $now < DAY_IN_SECONDS * 30) {
                         $messages[] = sprintf(__('Your license key expires soon! It expires on %s. <a href="%s" target="_blank" title="Renew license">Renew your license key</a>.', 'kb-support'), date_i18n(get_option('date_format'), strtotime($license->expires, current_time('timestamp'))), 'http://kb-support.com/checkout/?edd_license_key=' . $value);
                         $license_status = 'license-expires-soon-notice';
                     } else {
                         $messages[] = sprintf(__('Your license key expires on %s.', 'kb-support'), date_i18n(get_option('date_format'), strtotime($license->expires, current_time('timestamp'))));
                         $license_status = 'license-expiration-date-notice';
                     }
                     break;
             }
         }
     } else {
         $license_status = null;
     }
     $size = isset($args['size']) && !is_null($args['size']) ? $args['size'] : 'regular';
     $html = '<input type="text" class="' . sanitize_html_class($size) . '-text" id="kbs_settings[' . kbs_sanitize_key($args['id']) . ']" name="kbs_settings[' . kbs_sanitize_key($args['id']) . ']" value="' . esc_attr($value) . '"/>';
     if (is_object($license) && 'valid' == $license->license || 'valid' == $license) {
         $html .= '<input type="submit" class="button-secondary" name="' . $args['id'] . '_deactivate" value="' . __('Deactivate License', 'kb-support') . '"/>';
     }
     $html .= '<label for="kbs_settings[' . kbs_sanitize_key($args['id']) . ']"> ' . wp_kses_post($args['desc']) . '</label>';
     if (!empty($messages)) {
         foreach ($messages as $message) {
             $html .= '<div class="kbs-license-data kbs-license-' . $class . '">';
             $html .= '<p>' . $message . '</p>';
             $html .= '</div>';
         }
     }
     wp_nonce_field(kbs_sanitize_key($args['id']) . '-nonce', kbs_sanitize_key($args['id']) . '-nonce');
     if (isset($license_status)) {
         echo '<div class="' . $license_status . '">' . $html . '</div>';
     } else {
         echo '<div class="license-null">' . $html . '</div>';
     }
 }
Exemplo n.º 3
0
/**
 * Display a form checkbox list field
 *
 * @since	1.0
 * @param	obj			$field		Field post object
 * @param	arr			$settings	Field settings
 * @return	str			Field
 */
function kbs_display_form_checkbox_list_field($field, $settings)
{
    $class = !empty($settings['input_class']) ? ' class="' . esc_attr($settings['input_class']) . '"' : '';
    $options = $settings['select_options'];
    if (empty($options)) {
        return;
    }
    do_action('kbs_before_form_field', $field, $settings);
    do_action('kbs_before_form_' . $settings['type'] . '_field', $field, $settings);
    foreach ($options as $option) {
        $output[] = sprintf('<input type="checkbox" name="%1$s[]" id="%2$s"%3$s value="%4$s" /> %5$s', esc_attr($field->post_name), esc_attr(kbs_sanitize_key($option)), $class, esc_attr($option), '<label for="' . esc_attr(kbs_sanitize_key($option)) . '">' . esc_attr($option) . '</label>');
    }
    $output = apply_filters('kbs_display_form_checkbox_field', $output, $field, $settings);
    echo implode('<br />', $output);
    do_action('kbs_after_form_field', $field, $settings);
    do_action('kbs_after_form_' . $settings['type'] . '_field', $field, $settings);
}