2013-08-06 10:41:20 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* WooCommerce Meta Box Functions
|
|
|
|
*
|
|
|
|
* @author WooThemes
|
|
|
|
* @category Core
|
|
|
|
* @package WooCommerce/Admin/Functions
|
|
|
|
* @version 2.1.0
|
|
|
|
*/
|
2014-09-20 19:52:30 +00:00
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit; // Exit if accessed directly
|
|
|
|
}
|
2013-08-06 10:41:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Output a text input box.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param array $field
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function woocommerce_wp_text_input( $field ) {
|
2014-06-08 20:33:11 +00:00
|
|
|
global $thepostid, $post;
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2013-11-12 17:43:30 +00:00
|
|
|
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
|
|
|
|
$field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
|
|
|
|
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'short';
|
2013-08-06 10:41:20 +00:00
|
|
|
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
|
2013-11-12 17:43:30 +00:00
|
|
|
$field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
|
|
|
|
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
|
|
|
|
$field['type'] = isset( $field['type'] ) ? $field['type'] : 'text';
|
|
|
|
$data_type = empty( $field['data_type'] ) ? '' : $field['data_type'];
|
|
|
|
|
|
|
|
switch ( $data_type ) {
|
|
|
|
case 'price' :
|
|
|
|
$field['class'] .= ' wc_input_price';
|
|
|
|
$field['value'] = wc_format_localized_price( $field['value'] );
|
2014-10-28 20:37:53 +00:00
|
|
|
break;
|
2013-11-12 17:43:30 +00:00
|
|
|
case 'decimal' :
|
|
|
|
$field['class'] .= ' wc_input_decimal';
|
|
|
|
$field['value'] = wc_format_localized_decimal( $field['value'] );
|
2014-10-28 20:37:53 +00:00
|
|
|
break;
|
|
|
|
case 'stock' :
|
|
|
|
$field['class'] .= ' wc_input_stock';
|
|
|
|
$field['value'] = wc_stock_amount( $field['value'] );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default :
|
|
|
|
break;
|
2013-11-12 17:43:30 +00:00
|
|
|
}
|
2013-08-06 10:41:20 +00:00
|
|
|
|
|
|
|
// Custom attribute handling
|
|
|
|
$custom_attributes = array();
|
|
|
|
|
2014-08-01 04:24:55 +00:00
|
|
|
if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ){
|
|
|
|
foreach ( $field['custom_attributes'] as $attribute => $value ){
|
2013-08-06 10:41:20 +00:00
|
|
|
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
|
2014-08-01 04:24:55 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-06 10:41:20 +00:00
|
|
|
|
|
|
|
echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><input type="' . esc_attr( $field['type'] ) . '" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" ' . implode( ' ', $custom_attributes ) . ' /> ';
|
|
|
|
|
|
|
|
if ( ! empty( $field['description'] ) ) {
|
|
|
|
|
2013-09-03 15:22:59 +00:00
|
|
|
if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
|
2013-11-25 14:01:32 +00:00
|
|
|
echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( WC()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
|
2013-08-06 10:41:20 +00:00
|
|
|
} else {
|
|
|
|
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo '</p>';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Output a hidden input box.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param array $field
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function woocommerce_wp_hidden_input( $field ) {
|
|
|
|
global $thepostid, $post;
|
|
|
|
|
|
|
|
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
|
|
|
|
$field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
|
|
|
|
$field['class'] = isset( $field['class'] ) ? $field['class'] : '';
|
|
|
|
|
|
|
|
echo '<input type="hidden" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['id'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" /> ';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Output a textarea input box.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param array $field
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function woocommerce_wp_textarea_input( $field ) {
|
2014-06-08 20:33:11 +00:00
|
|
|
global $thepostid, $post;
|
2013-08-06 10:41:20 +00:00
|
|
|
|
|
|
|
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
|
|
|
|
$field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
|
|
|
|
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'short';
|
|
|
|
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
|
|
|
|
$field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
|
|
|
|
|
2014-11-13 11:26:52 +00:00
|
|
|
// Custom attribute handling
|
|
|
|
$custom_attributes = array();
|
|
|
|
|
|
|
|
if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ){
|
|
|
|
foreach ( $field['custom_attributes'] as $attribute => $value ){
|
|
|
|
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><textarea class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['id'] ) . '" id="' . esc_attr( $field['id'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" rows="2" cols="20" ' . implode( ' ', $custom_attributes ) . '>' . esc_textarea( $field['value'] ) . '</textarea> ';
|
2013-08-06 10:41:20 +00:00
|
|
|
|
|
|
|
if ( ! empty( $field['description'] ) ) {
|
|
|
|
|
2013-09-03 15:22:59 +00:00
|
|
|
if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
|
2013-11-25 14:01:32 +00:00
|
|
|
echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( WC()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
|
2013-08-06 10:41:20 +00:00
|
|
|
} else {
|
|
|
|
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo '</p>';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Output a checkbox input box.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param array $field
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function woocommerce_wp_checkbox( $field ) {
|
|
|
|
global $thepostid, $post;
|
|
|
|
|
2014-01-13 12:28:29 +00:00
|
|
|
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
|
|
|
|
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'checkbox';
|
2013-08-06 10:41:20 +00:00
|
|
|
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
|
2014-01-13 12:28:29 +00:00
|
|
|
$field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
|
|
|
|
$field['cbvalue'] = isset( $field['cbvalue'] ) ? $field['cbvalue'] : 'yes';
|
|
|
|
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-11-13 11:26:52 +00:00
|
|
|
// Custom attribute handling
|
|
|
|
$custom_attributes = array();
|
|
|
|
|
|
|
|
if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ){
|
|
|
|
foreach ( $field['custom_attributes'] as $attribute => $value ){
|
|
|
|
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><input type="checkbox" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['cbvalue'] ) . '" ' . checked( $field['value'], $field['cbvalue'], false ) . ' ' . implode( ' ', $custom_attributes ) . '/> ';
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-09-29 16:15:26 +00:00
|
|
|
if ( ! empty( $field['description'] ) ) {
|
|
|
|
if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
|
|
|
|
echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( WC()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
|
|
|
|
} else {
|
|
|
|
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
|
|
|
}
|
|
|
|
}
|
2013-08-06 10:41:20 +00:00
|
|
|
|
|
|
|
echo '</p>';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Output a select input box.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param array $field
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function woocommerce_wp_select( $field ) {
|
2014-06-08 20:33:11 +00:00
|
|
|
global $thepostid, $post;
|
2013-08-06 10:41:20 +00:00
|
|
|
|
|
|
|
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
|
|
|
|
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'select short';
|
|
|
|
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
|
|
|
|
$field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
|
|
|
|
|
2014-11-13 11:26:52 +00:00
|
|
|
// Custom attribute handling
|
|
|
|
$custom_attributes = array();
|
|
|
|
|
|
|
|
if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ){
|
|
|
|
foreach ( $field['custom_attributes'] as $attribute => $value ){
|
|
|
|
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><select id="' . esc_attr( $field['id'] ) . '" name="' . esc_attr( $field['id'] ) . '" class="' . esc_attr( $field['class'] ) . '" ' . implode( ' ', $custom_attributes ) . '>';
|
2013-08-06 10:41:20 +00:00
|
|
|
|
|
|
|
foreach ( $field['options'] as $key => $value ) {
|
|
|
|
echo '<option value="' . esc_attr( $key ) . '" ' . selected( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '</select> ';
|
|
|
|
|
|
|
|
if ( ! empty( $field['description'] ) ) {
|
|
|
|
|
2013-09-03 15:22:59 +00:00
|
|
|
if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
|
2013-11-25 14:01:32 +00:00
|
|
|
echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( WC()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
|
2013-08-06 10:41:20 +00:00
|
|
|
} else {
|
|
|
|
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo '</p>';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Output a radio input box.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param array $field
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function woocommerce_wp_radio( $field ) {
|
2014-06-08 20:33:11 +00:00
|
|
|
global $thepostid, $post;
|
2013-08-06 10:41:20 +00:00
|
|
|
|
|
|
|
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
|
|
|
|
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'select short';
|
|
|
|
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
|
|
|
|
$field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
|
2014-01-13 12:28:29 +00:00
|
|
|
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2013-12-27 13:26:37 +00:00
|
|
|
echo '<fieldset class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><legend>' . wp_kses_post( $field['label'] ) . '</legend><ul class="wc-radios">';
|
2013-08-06 10:41:20 +00:00
|
|
|
|
2014-08-01 04:24:55 +00:00
|
|
|
foreach ( $field['options'] as $key => $value ) {
|
2013-08-06 10:41:20 +00:00
|
|
|
|
|
|
|
echo '<li><label><input
|
2014-08-01 04:24:55 +00:00
|
|
|
name="' . esc_attr( $field['name'] ) . '"
|
|
|
|
value="' . esc_attr( $key ) . '"
|
|
|
|
type="radio"
|
|
|
|
class="' . esc_attr( $field['class'] ) . '"
|
|
|
|
' . checked( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '
|
|
|
|
/> ' . esc_html( $value ) . '</label>
|
|
|
|
</li>';
|
2013-08-06 10:41:20 +00:00
|
|
|
}
|
2014-08-01 04:24:55 +00:00
|
|
|
echo '</ul>';
|
2013-12-27 13:26:37 +00:00
|
|
|
|
2014-08-01 04:24:55 +00:00
|
|
|
if ( ! empty( $field['description'] ) ) {
|
2013-12-27 13:26:37 +00:00
|
|
|
|
|
|
|
if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) {
|
|
|
|
echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( WC()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />';
|
|
|
|
} else {
|
|
|
|
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '</fieldset>';
|
2014-09-20 19:52:30 +00:00
|
|
|
}
|