Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php 

$new_meta_boxes =

array(

"header_paragraph" => array("name" => "header_paragraph","std" => "","title" => "Header Paragraph:",

"description" => "This is the large floating paragraph just below the header area.", "type" => "text"),

"location" => array("name" => "location","std" => "","title" => "Location:", "type" => "textarea"),

);

function new_meta_boxes() {

global $post, $new_meta_boxes;



foreach($new_meta_boxes as $meta_box) {

$meta_box_value = get_post_meta($post->ID, $meta_box['name'].'_value', true);



if($meta_box_value == "")

$meta_box_value = $meta_box['std'];



echo'<input type="hidden" name="'.$meta_box['name'].'_noncename" id="'.$meta_box['name'].'_noncename" value="'.wp_create_nonce( plugin_basename(__FILE__) ).'" />';



if($meta_box['type'] == "text") {  

echo'<h2>'.$meta_box['title'].'</h2>';

echo'<p><label for="'.$meta_box['name'].'_value">'.$meta_box['description'].'</label></p>';

echo'<input type="text" name="'.$meta_box['name'].'_value" value="'.$meta_box_value.'" style="width: 97%;" /><br />';

}

elseif ( $meta_box['type'] == "textarea" ) {

echo'<h2>'.$meta_box['title'].'</h2>';

echo'<p><label for="'.$meta_box['name'].'_value">'.$meta_box['description'].'</label></p>';

echo'<textarea name="location" cols="60" rows="4" tabindex="30" style="width: 97%;" /></textarea>';
}

}

}

function create_meta_box() {

global $theme_name;

if ( function_exists('add_meta_box') ) {

add_meta_box( 'new-meta-boxes', 'Itinerary Page Template', 'new_meta_boxes', 'page', 'normal', 'high' );

}

}

function save_postdata( $post_id ) {

global $post, $new_meta_boxes;



foreach($new_meta_boxes as $meta_box) {

// Verify

if ( !wp_verify_nonce( $_POST[$meta_box['name'].'_noncename'], plugin_basename(__FILE__) )) {

return $post_id;

}



if ( 'page' == $_POST['post_type'] ) {

if ( !current_user_can( 'edit_page', $post_id ))

return $post_id;

} else {

if ( !current_user_can( 'edit_post', $post_id ))

return $post_id;

}



$data = $_POST[$meta_box['name'].'_value'];



if(get_post_meta($post_id, $meta_box['name'].'_value') == "")

add_post_meta($post_id, $meta_box['name'].'_value', $data, true);

elseif($data != get_post_meta($post_id, $meta_box['name'].'_value', true))

update_post_meta($post_id, $meta_box['name'].'_value', $data);

elseif($data == "")

delete_post_meta($post_id, $meta_box['name'].'_value', get_post_meta($post_id, $meta_box['name'].'_value', true));

}

}

add_action('admin_menu', 'create_meta_box');

add_action('save_post', 'save_postdata');

?>