ID, $field['id'], true); // Get data to display in field if (isset($option)) { $data = $option; } } else { // Get saved option $option_name .= $field['id']; $option = get_option($option_name); // Get data to display in field if (isset($option)) { $data = $option; } } // Show default data if no option saved and default is supplied if ($data === false && isset($field['default'])) { $data = $field['default']; } elseif ($data === false) { $data = ''; } $html = ''; switch ($field['type']) { case 'text': case 'url': case 'email': $html .= '' . "\n"; break; case 'password': case 'number': case 'hidden': $min = ''; if (isset($field['min'])) { $min = ' min="' . esc_attr($field['min']) . '"'; } $max = ''; if (isset($field['max'])) { $max = ' max="' . esc_attr($field['max']) . '"'; } $html .= '' . "\n"; break; case 'text_secret': $html .= '' . "\n"; break; case 'textarea': //var_dump($field);exit; $html .= '
' . "\n"; // wp_editor( $data, esc_attr($field['id']), esc_attr($option_name) ); break; case 'checkbox': $checked = ''; if ($data && 'on' == $data) { $checked = 'checked="checked"'; } $html .= '' . "\n"; break; case 'checkbox_multi': foreach ($field['options'] as $k => $v) { $checked = false; if (in_array($k, (array) $data)) { $checked = true; } $html .= '

'; } break; case 'radio': foreach ($field['options'] as $k => $v) { $checked = false; if ($k == $data) { $checked = true; } $html .= '

'; } break; case 'select': $html .= ' '; break; case 'select_multi': $html .= ' '; break; case 'image': $image_thumb = ''; if ($data) { $image_thumb = wp_get_attachment_thumb_url($data); } $html .= '
' . "\n"; $html .= '' . "\n"; $html .= '' . "\n"; $html .= '
' . "\n"; break; case 'color': ?>
$option_name, )); break; case 'button': $html .= '' . "\n"; break; // case 'catbutton': // $html .= '' . "\n"; // $html .= '
' . "\n"; // break; case 'tracker': ?>
post_type . '_custom_fields', array(), $post->post_type); if (!is_array($fields) || 0 == count($fields)) { return; } echo '
' . "\n"; foreach ($fields as $field) { if (!isset($field['metabox'])) { continue; } if (!is_array($field['metabox'])) { $field['metabox'] = array($field['metabox']); } if (in_array($args['id'], $field['metabox'])) { $this->display_meta_box_field($field, $post); } } echo '
' . "\n"; } /** * Dispay field in metabox * @param array $field Field data * @param object $post Post object * @return void */ public function display_meta_box_field($field = array(), $post) { if (!is_array($field) || 0 == count($field)) { return; } $field = '

' . $this->display_field($field, $post, false) . '

' . "\n"; echo $field; } /** * Save metabox fields * @param integer $post_id Post ID * @return void */ public function save_meta_boxes($post_id = 0) { if (!$post_id) { return; } $post_type = get_post_type($post_id); $fields = apply_filters($post_type . '_custom_fields', array(), $post_type); if (!is_array($fields) || 0 == count($fields)) { return; } foreach ($fields as $field) { if (isset($_REQUEST[$field['id']])) { update_post_meta($post_id, $field['id'], $this->validate_field(wc_clean($_REQUEST[$field['id']]), $field['type'])); } else { update_post_meta($post_id, $field['id'], ''); } } } }