コード例 #1
0
    /**
     * Implementation for the customer meta box
     */
    public static function bottom_customer_meta_box($post, $metabox)
    {
        $custom = get_post_custom($post->ID);
        // fill a new array with the existing values
        // very annoying conversions, but we could live with that.
        $meta_array = array();
        foreach (self::$fields as $key => $args) {
            if (!empty($custom[$key]) && is_array($custom[$key])) {
                $custom_value = $custom[$key][0];
                if (is_serialized($custom_value)) {
                    // I don't like the @ either, but sometimes it's just making the output safe.
                    $custom_value = maybe_unserialize($custom_value);
                    if (is_array($custom_value)) {
                        $custom_value = $custom_value[0];
                    }
                }
                $meta_array[$key] = $custom_value;
            }
        }
        $_POST = array_merge($_POST, $meta_array);
        wp_nonce_field('customer_nonce_save', 'customer_nonce');
        ?>
	
			<div id="dx-customer-meta-wrapper">
			<table class="form-table"> 
			<tbody>
			<?php 
        foreach (self::$fields as $item => $attributes) {
            echo DX_Form_Helper::html_element($item, $attributes, 'POST');
        }
        ?>
			</tbody>
			</table>
			</div>
		<?php 
    }
コード例 #2
0
    /**
     * Implementation for the arguments meta box
     */
    public static function bottom_invoice_meta_box($post, $metabox)
    {
        $custom = get_post_custom($post->ID);
        // fill a new array with the existing values
        // very annoying conversions, but we could live with that.
        $meta_array = array();
        foreach (self::$fields as $key => $args) {
            if (!empty($custom[$key]) && is_array($custom[$key])) {
                $custom_value = $custom[$key][0];
                if (is_serialized($custom_value)) {
                    // I don't like the @ either, but sometimes it's just making the output safe.
                    $custom_value = maybe_unserialize($custom_value);
                    if (is_array($custom_value)) {
                        $custom_value = $custom_value[0];
                    }
                }
                $meta_array[$key] = $custom_value;
            } else {
                if ($key == '_invoice_number') {
                    $invoice_title = get_option('dx_invoice_options');
                    $increment = !empty($invoice_title['increment']) ? $invoice_title['increment'] : 1;
                    $meta_array[$key] = !empty($invoice_title['invoice_num']) ? $invoice_title['invoice_num'] + $increment : 1;
                    // Check existing
                    $my_query = new WP_Query(array('post_type' => DX_INV_POST_TYPE, 'post__not_in' => array($post->ID), 'meta_query' => array(array('key' => '_invoice_number', 'value' => $meta_array[$key]))));
                    if (count($my_query->posts) != 0) {
                        global $wpdb;
                        $query = "SELECT max(meta_value) FROM wp_postmeta WHERE meta_key='_invoice_number'";
                        $the_max = $wpdb->get_var($query);
                        $meta_array[$key] = $the_max + $increment;
                    }
                }
            }
        }
        $_POST = array_merge($_POST, $meta_array);
        wp_nonce_field('invoice_nonce_save', 'invoice_nonce');
        ?>
	
		<div id="dx-invoice-meta-wrapper">
		<table class="form-table"> 
			<tbody>
		<?php 
        foreach (self::$fields as $item => $attributes) {
            echo DX_Form_Helper::html_element($item, $attributes, 'POST');
        }
        ?>
			</tbody>
		</table>
		</div>
	<?php 
    }