Esempio n. 1
0
function thesis_add_meta_boxes()
{
    $meta_boxes = thesis_meta_boxes();
    foreach ($meta_boxes as $meta_box) {
        add_meta_box($meta_box['id'], $meta_box['title'], $meta_box['function'], 'post', 'normal', 'high');
        add_meta_box($meta_box['id'], $meta_box['title'], $meta_box['function'], 'page', 'normal', 'high');
    }
    add_action('save_post', 'thesis_save_meta');
}
Esempio n. 2
0
function thesis_save_meta($post_id)
{
    $meta_boxes = thesis_meta_boxes();
    // We have to make sure all new data came from the proper Thesis entry fields
    foreach ($meta_boxes as $meta_box) {
        if (!wp_verify_nonce($_POST[$meta_box['noncename'] . '_noncename'], plugin_basename(__FILE__))) {
            return $post_id;
        }
    }
    if ($_POST['post_type'] == 'page') {
        if (!current_user_can('edit_page', $post_id)) {
            return $post_id;
        }
    } else {
        if (!current_user_can('edit_post', $post_id)) {
            return $post_id;
        }
    }
    // If we reach this point in the code, that means we're authenticated. Proceed with saving the new data
    foreach ($meta_boxes as $meta_box) {
        foreach ($meta_box['fields'] as $meta_field) {
            $current_data = get_post_meta($post_id, $meta_field['name'], true);
            $new_data = $_POST[$meta_field['name']];
            if ($current_data) {
                if ($new_data == '') {
                    delete_post_meta($post_id, $meta_field['name']);
                } elseif ($new_data == $meta_field['default']) {
                    delete_post_meta($post_id, $meta_field['name']);
                } elseif ($new_data != $current_data) {
                    update_post_meta($post_id, $meta_field['name'], $new_data);
                }
            } elseif ($new_data != '') {
                add_post_meta($post_id, $meta_field['name'], $new_data, true);
            }
        }
    }
}