/** * 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; } ?> <select name="<?php echo esc_attr($field['name']); ?> " <?php echo beans_esc_attributes($field['attributes']); ?> > <?php foreach ($field['options'] as $value => $label) { ?> <option value="<?php echo esc_attr($value); ?> " <?php selected($value, $field['value']); ?> ><?php echo esc_html($label); ?> </option> <?php } ?> </select> <?php }
/** * 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) { ?> <input type="hidden" value="0" name="<?php echo esc_attr($field['name']); ?> " /> <input type="checkbox" name="<?php echo esc_attr($field['name']); ?> " value="1" <?php checked($field['value'], 1); ?> <?php echo beans_esc_attributes($field['attributes']); ?> /> <?php if ($checkbox_label = beans_get('checkbox_label', $field, __('Enable', 'tm-beans'))) { ?> <span class="bs-checkbox-label"><?php echo $checkbox_label; ?> </span> <?php } }
/** * 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']); ?> <fieldset> <?php $i = 0; foreach ($field['options'] as $id => $radio) { $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; ?> <label class="<?php echo esc_attr($has_image); ?> "> <?php if ($has_image) { ?> <img src="<?php echo esc_url($radio); ?> "/> <?php } ?> <input type="radio" name="<?php echo esc_attr($field['name']); ?> " value="<?php echo esc_attr($id); ?> " <?php checked($id, $field['value'], 1); ?> <?php echo beans_esc_attributes($field['attributes']); ?> /> <?php if (!$has_image) { ?> <?php echo $radio; ?> <?php } ?> </label> <?php $i++; } ?> </fieldset> <?php }
/** * 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) { ?> <input type="text" name="<?php echo esc_attr($field['name']); ?> " value="<?php echo esc_attr($field['value']); ?> " <?php echo beans_esc_attributes($field['attributes']); ?> > <?php }
/** * 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) { ?> <textarea name="<?php echo esc_attr($field['name']); ?> " <?php echo beans_esc_attributes($field['attributes']); ?> ><?php echo esc_textarea($field['value']); ?> </textarea> <?php }
/** * 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); ?> <div class="bs-slider-wrap" slider_min="<?php echo (int) $field['min']; ?> " slider_max="<?php echo (int) $field['max']; ?> " slider_interval="<?php echo (int) $field['interval']; ?> "> <?php // Don't make this a hidden field to prevent triggering issues with wp_customise. ?> <input type="text" value="<?php echo esc_attr($field['value']); ?> " name="<?php echo esc_attr($field['name']); ?> " <?php echo beans_esc_attributes($field['attributes']); ?> style="display: none;"/> </div> <span class="bs-slider-value"><?php echo $field['value']; ?> </span> <?php if ($field['unit']) { ?> <span class="bs-slider-unit"><?php echo $field['unit']; ?> </span> <?php } }
/** * 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) { ?> <input type="hidden" value="0" name="<?php echo esc_attr($field['name']); ?> " /> <input type="checkbox" name="<?php echo esc_attr($field['name']); ?> " value="1" <?php checked($field['value'], 1); ?> <?php echo beans_esc_attributes($field['attributes']); ?> /> <?php }
/** * 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_esc_attributes($attributes); }
/** * 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"' : ''; ?> <a href="#" class="bs-add-image button button-small" <?php echo $hide; ?> ><?php echo _n('Add Image', 'Add Images', $multiple ? 2 : 1, 'tm-beans'); ?> </a> <input type="hidden" name="<?php echo esc_attr($field['name']); ?> " value=""> <div class="bs-images-wrap" data-multiple="<?php echo esc_attr($multiple); ?> "> <?php 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 ('placeholder' == $id) { $class = 'bs-image-template'; $attributes = array_merge($attributes, array('disabled' => 'disabled', 'value' => false)); } ?> <div class="bs-image-wrap <?php echo esc_attr($class); ?> "> <input <?php echo beans_esc_attributes($attributes); ?> /> <img src="<?php echo esc_url(beans_get(0, $img)); ?> "> <div class="bs-toolbar"> <?php if ($multiple) { ?> <a href="#" class="dashicons dashicons-menu"></a> <?php } ?> <a href="#" class="dashicons dashicons-edit"></a> <a href="#" class="dashicons dashicons-post-trash"></a> </div> </div> <?php } ?> </div> <?php }
/** * Deprecated. Sanitize HTML attributes from array to string. * * This functions has been replaced with {@see beans_esc_attributes()}. * * @since 1.0.0 * @deprecated 1.3.1 * * @param array $attributes The array key defines the attribute name and the array value define the * attribute value. * * @return string The sanitized attributes. */ function beans_sanatize_attributes($attributes) { _deprecated_function(__FUNCTION__, '1.3.1', 'beans_esc_attributes()'); return beans_esc_attributes($attributes); }