/** * Echo radio field type. * * @since 1.0.0 * * @param array $field { * For best practices, pass the array of data obtained using {@see beans_get_fields()}. * * @type mixed $value The field value. * @type string $name The field name value. * @type array $attributes An array of attributes to add to the field. The array key defines the * attribute name and the array value defines the attribute value. Default array. * @type mixed $default The default value. Default false. * @type array $options An array used to populate the radio options. The array key defines radio * value and the array value defines the radio label or image path. * } */ function beans_field_radio($field) { if (empty($field['options'])) { return; } $field['default'] = isset($checkbox['default']) ? $checkbox['default'] : key($field['options']); echo '<fieldset>'; $i = 0; foreach ($field['options'] as $id => $radio) { $checked = $id == $field['value'] ? ' checked="checked"' : null; $extensions = array('jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico'); $has_image = in_array(beans_get('extension', pathinfo($radio)), $extensions) ? 'bs-has-image' : false; echo '<label class="' . $has_image . '">'; if ($has_image) { echo '<img src="' . $radio . '" />'; } echo '<input type="radio" name="' . $field['name'] . '" value="' . $id . '" ' . $checked . ' ' . beans_sanatize_attributes($field['attributes']) . '/>'; if (!$has_image) { echo $radio; } echo '</label>'; $i++; } echo '</fieldset>'; }
/** * Echo checkbox field type. * * @since 1.0.0 * * @param array $field { * For best practices, pass the array of data obtained using {@see beans_get_fields()}. * * @type mixed $value The field value. * @type string $name The field name value. * @type array $attributes An array of attributes to add to the field. The array key defines the * attribute name and the array value defines the attribute value. Default array. * @type mixed $default The default value. Default false. * @type string $checkbox_label The field checkbox label. Default 'Enable'. * } */ function beans_field_checkbox($field) { $checked = $field['value'] ? ' checked="checked"' : null; echo '<input type="hidden" value="0" name="' . $field['name'] . '" />'; echo '<input type="checkbox" name="' . $field['name'] . '" value="1" ' . $checked . ' ' . beans_sanatize_attributes($field['attributes']) . ' />'; if ($checkbox_label = beans_get('checkbox_label', $field, 'Enable')) { echo '<span class="bs-checkbox-label">' . $checkbox_label . '</span>'; } }
/** * Echo select field type. * * @since 1.0.0 * * @param array $field { * For best practices, pass the array of data obtained using {@see beans_get_fields()}. * * @type mixed $value The field value. * @type string $name The field name value. * @type array $attributes An array of attributes to add to the field. The array key defines the * attribute name and the array value defines the attribute value. Default array. * @type mixed $default The default value. Default false. * @type array $options An array used to populate the select options. The array key defines option * value and the array value defines the option label. * } */ function beans_field_select($field) { if (empty($field['options'])) { return; } echo '<select name="' . $field['name'] . '" ' . beans_sanatize_attributes($field['attributes']) . '>'; foreach ($field['options'] as $value => $label) { $selected = $value == $field['value'] ? ' selected="selected"' : null; echo '<option value="' . $value . '"' . $selected . '>' . $label . '</option>'; } echo '</select>'; }
/** * Echo slider field type. * * @since 1.0.0 * * @param array $field { * For best practices, pass the array of data obtained using {@see beans_get_fields()}. * * @type mixed $value The field value. * @type string $name The field name value. * @type array $attributes An array of attributes to add to the field. The array key defines the * attribute name and the array value defines the attribute value. Default array. * @type mixed $default The default value. Default false. * @type string $min The slider minimum value. Default 0. * @type string $max The slider maximum value. Default 100. * @type string $interval The slider interval. Default 1. * @type string $unit The slider unit. Default null. * } */ function beans_field_slider($field) { $defaults = array('min' => 0, 'max' => 100, 'interval' => 1, 'unit' => null); $field = array_merge($defaults, $field); echo '<div class="bs-slider-wrap" slider_min="' . $field['min'] . '" slider_max="' . $field['max'] . '" slider_interval="' . $field['interval'] . '">'; // Don't make this a hidden field to prevent triggering issues with wp_customise. echo '<input type="text" value="' . $field['value'] . '" name="' . $field['name'] . '" ' . beans_sanatize_attributes($field['attributes']) . ' style="display: none;"/>'; echo '</div>'; echo '<span class="bs-slider-value">' . $field['value'] . '</span>'; if ($field['unit']) { echo '<span class="bs-slider-unit">' . $field['unit'] . '</span>'; } }
/** * Echo image field type. * * @since 1.0.0 * * @param array $field { * For best practices, pass the array of data obtained using {@see beans_get_fields()}. * * @type mixed $value The field value. * @type string $name The field name value. * @type array $attributes An array of attributes to add to the field. The array key defines the * attribute name and the array value defines the attribute value. Default array. * @type mixed $default The default value. Default false. * @type string $multiple Set to true to enable mutliple images (gallery). Default false. * } */ function beans_field_image($field) { // Set the images variable and add placeholder to the array. $images = array_merge((array) $field['value'], array('placeholder')); // Is multiple set. $multiple = beans_get('multiple', $field); // Hide beans if it is a single image and an image already exists $hide = !$multiple && is_numeric($field['value']) ? 'style="display: none"' : ''; echo '<a href="#" class="bs-add-image button button-small" ' . $hide . '>'; echo _n('Add Image', 'Add Images', $multiple ? 2 : 1, 'beans'); echo '</a>'; echo '<input type="hidden" name="' . $field['name'] . '" value="">'; echo '<div class="bs-images-wrap" data-multiple="' . $multiple . '">'; foreach ($images as $id) { // Stop here if the id is false. if (!$id) { continue; } $class = ''; $img = wp_get_attachment_image_src($id, 'thumbnail'); $attributes = array_merge(array('class' => 'image-id', 'type' => 'hidden', 'name' => $multiple ? $field['name'] . '[]' : $field['name'], 'value' => $id), $field['attributes']); // Set placeholder. if ($id == 'placeholder') { $class = 'bs-image-template'; $attributes = array_merge($attributes, array('disabled' => 'disabled', 'value' => false)); } echo '<div class="bs-image-wrap ' . $class . '">'; echo '<input ' . beans_sanatize_attributes($attributes) . ' />'; echo '<img src="' . beans_get(0, $img) . '">'; echo '<div class="bs-toolbar">'; if ($multiple) { echo '<a href="#" class="dashicons dashicons-menu"></a>'; } echo '<a href="#" class="dashicons dashicons-edit"></a>'; echo '<a href="#" class="dashicons dashicons-post-trash"></a>'; echo '</div>'; echo '</div>'; } echo '</div>'; }
/** * Echo radio field type. * * @since 1.0.0 * * @param array $field { * For best practices, pass the array of data obtained using {@see beans_get_fields()}. * * @type mixed $value The field value. * @type string $name The field name value. * @type array $attributes An array of attributes to add to the field. The array key defines the * attribute name and the array value defines the attribute value. Default array. * @type mixed $default The default value. Default false. * @type array $options An array used to populate the radio options. The array key defines radio * value and the array value defines the radio label or image path. * } */ function beans_field_radio($field) { if (empty($field['options'])) { return; } $field['default'] = isset($checkbox['default']) ? $checkbox['default'] : key($field['options']); echo '<fieldset>'; $i = 0; foreach ($field['options'] as $id => $radio) { $checked = $id == $field['value'] ? ' checked="checked"' : null; $has_image = @getimagesize($radio) ? 'bs-has-image' : false; echo '<label class="' . $has_image . '">'; if ($has_image) { echo '<img src="' . $radio . '" />'; } echo '<input type="radio" name="' . $field['name'] . '" value="' . $id . '" ' . $checked . ' ' . beans_sanatize_attributes($field['attributes']) . '/>'; if (!$has_image) { echo $radio; } echo '</label>'; $i++; } echo '</fieldset>'; }
/** * Echo activation field type. * * @since 1.0.0 * * @param array $field { * For best practices, pass the array of data obtained using {@see beans_get_fields()}. * * @type string $description The field description. The description can be truncated using <!--more--> * as a delimiter. Default false. * @type mixed $value The field value. * @type string $name The field name value. * @type array $attributes An array of attributes to add to the field. The array key defines the * attribute name and the array value defines the attribute value. Default array. * @type mixed $default The default value. Default false. * } */ function beans_field_activation($field) { $checked = $field['value'] ? ' checked="checked"' : null; echo '<input type="hidden" value="0" name="' . $field['name'] . '" />'; echo '<input type="checkbox" name="' . $field['name'] . '" value="1" ' . $checked . ' ' . beans_sanatize_attributes($field['attributes']) . ' />'; }
/** * Echo text field type. * * @since 1.0.0 * * @param array $field { * For best practices, pass the array of data obtained using {@see beans_get_fields()}. * * @type mixed $value The field value. * @type string $name The field name value. * @type array $attributes An array of attributes to add to the field. The array key defines the * attribute name and the array value defines the attribute value. Default array. * @type mixed $default The default value. Default false. * } */ function beans_field_text($field) { echo '<input type="text" name="' . $field['name'] . '" value="' . esc_attr($field['value']) . '" ' . beans_sanatize_attributes($field['attributes']) . '>'; }
/** * Register attributes by ID. * * The Beans HTML "attributes" functions make it really easy to modify, replace, extend, * remove or hook into registered attributes. * * Since this function uses {@see beans_apply_filters()}, the $id argument may contain sub-hook(s). * * @since 1.0.0 * * @param string $id A unique string used as a reference. The $id argument may contain sub-hook(s). * @param string|array $attributes Optional. Query string or array of attributes. The array key defines the * attribute name and the array value define the attribute value. Setting * the array value to '' will display the attribute value as empty * (e.g. class=""). Setting it to 'false' will only display * the attribute name (e.g. data-example). Setting it to 'null' will not * display anything. * @param mixed $var Additional variables passed to the functions hooked to <tt>$id</tt>. * * @return string The HTML attributes. */ function beans_add_attributes($id, $attributes = array()) { $args = func_get_args(); $args[0] = $id . '_attributes'; if (!isset($args[1])) { $args[1] = array(); } $args[1] = wp_parse_args($args[1]); $attributes = call_user_func_array('beans_apply_filters', $args); return beans_sanatize_attributes($attributes); }
/** * Echo textarea field type. * * @since 1.0.0 * * @param array $field { * For best practices, pass the array of data obtained using {@see beans_get_fields()}. * * @type mixed $value The field value. * @type string $name The field name value. * @type array $attributes An array of attributes to add to the field. The array key defines the * attribute name and the array value defines the attribute value. Default array. * @type mixed $default The default value. Default false. * } */ function beans_field_textarea($field) { echo '<textarea name="' . $field['name'] . '" ' . beans_sanatize_attributes($field['attributes']) . '>' . esc_attr($field['value']) . '</textarea>'; }