0
|
1 |
<?php |
|
2 |
add_action( 'admin_init', 'vp_meta_boxes'); |
|
3 |
function vp_meta_boxes() { |
|
4 |
add_meta_box('vp_post_meta', 'SCRN Options', 'vp_post_meta', 'page', 'normal', 'high'); |
|
5 |
add_meta_box('vp_pagetemplates_meta', 'Page Template Settings', 'vp_pagetemplates_meta', 'page', 'side'); |
|
6 |
} |
|
7 |
function vp_post_meta() { |
|
8 |
global $post; |
|
9 |
$temp = maybe_unserialize(get_post_meta($post->ID,'vp_settings',true)); |
|
10 |
$background = isset($temp['background']) ? $temp['background'] : ''; |
|
11 |
$background_color = isset($temp['background_color']) ? $temp['background_color'] : ''; |
|
12 |
$slogan = isset($temp['slogan']) ? $temp['slogan'] : ''; |
|
13 |
$slogan_bg = isset($temp['slogan_bg']) ? $temp['slogan_bg'] : ''; |
|
14 |
$variation = isset($temp['variation']) ? $temp['variation'] : ''; |
|
15 |
?> |
|
16 |
<div> |
|
17 |
<div style="margin: 15px 0px 15px 4px" class="vp_bg"> |
|
18 |
<label style="font-weight: bold" for="vp_background">Background style:</label><br /> |
|
19 |
<select name="vp_bg_style" class="vp_bg_style"> |
|
20 |
<option value="1" <?php if($variation == '1' || !isset($variation) || $variation == '') echo 'selected="selected"';?>>White</option> |
|
21 |
<option value="2" <?php if($variation == '2') echo 'selected="selected"';?>>Dark</option> |
|
22 |
<option value="3" <?php if($variation == '3') echo 'selected="selected"';?>>Custom (defined below)</option> |
|
23 |
</select> |
|
24 |
</div> |
|
25 |
<div style="margin: 15px 0px 15px 4px" class="vp_custom_bg"> |
|
26 |
<label style="font-weight: bold" for="vp_background">Background image URL:</label><br /> |
|
27 |
<input type="text" name="vp_background" id="vp_background" value="<?php echo $background;?>" style="width: 40em" /> |
|
28 |
</div> |
|
29 |
<div style="margin: 15px 0px 15px 4px" class="vp_custom_bg"> |
|
30 |
<label style="font-weight: bold" for="vp_background_color">Background image color:</label>(use just the hex code, skip the "#" character. Will use just a color and not an image) <br /> |
|
31 |
<input type="text" name="vp_background_color" id="vp_background_color" value="<?php echo $background_color;?>" style="width: 40em" /> |
|
32 |
</div> |
|
33 |
<div style="margin: 15px 0px 15px 4px"> |
|
34 |
<label style="font-weight: bold" for="vp_slogan">Slogan text:</label><br /> |
|
35 |
<input type="text" name="vp_slogan" id="vp_slogan" value="<?php echo $slogan;?>" style="width: 40em" /> |
|
36 |
</div> |
|
37 |
<div style="margin: 15px 0px 15px 4px"> |
|
38 |
<label style="font-weight: bold" for="vp_sloganbg">Slogan background image url:</label><br /> |
|
39 |
<input type="text" name="vp_sloganbg" id="vp_sloganbg" value="<?php echo $slogan_bg;?>" style="width: 40em" /> |
|
40 |
</div> |
|
41 |
</div> |
|
42 |
<script type="text/javascript"> |
|
43 |
jQuery(document).ready(function() { |
|
44 |
var $bg_style = jQuery("select.vp_bg_style"); |
|
45 |
$bg_style.on("change", function() { |
|
46 |
var val = jQuery(this).val(); |
|
47 |
if(val == 3) { |
|
48 |
jQuery(".vp_custom_bg").show(400); |
|
49 |
} |
|
50 |
else { |
|
51 |
jQuery(".vp_custom_bg").hide(400); |
|
52 |
jQuery(".vp_background").val(""); |
|
53 |
jQuery(".vp_background_color").val(""); |
|
54 |
} |
|
55 |
}); |
|
56 |
$bg_style.trigger('change'); |
|
57 |
}); |
|
58 |
</script> |
|
59 |
<?php |
|
60 |
} |
|
61 |
add_action('save_post', 'vp_save_metadata', 10, 2); |
|
62 |
function vp_save_metadata($post_id, $post) |
|
63 |
{ |
|
64 |
// verify if this is an auto save routine. |
|
65 |
// If it is our form has not been submitted, so we dont want to do anything |
|
66 |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) |
|
67 |
return; |
|
68 |
// Check permissions |
|
69 |
if ( 'page' == $post->post_type ) |
|
70 |
{ |
|
71 |
if ( !current_user_can( 'edit_page', $post_id ) ) |
|
72 |
return; |
|
73 |
} |
|
74 |
else |
|
75 |
{ |
|
76 |
if ( !current_user_can( 'edit_post', $post_id ) ) |
|
77 |
return; |
|
78 |
} |
|
79 |
$temp['background'] = isset($_POST['vp_background']) ? esc_attr($_POST['vp_background']) : ''; |
|
80 |
$temp['background_color'] = isset($_POST['vp_background_color']) ? esc_attr($_POST['vp_background_color']) : ''; |
|
81 |
$temp['slogan'] = isset($_POST['vp_slogan']) ? $_POST['vp_slogan'] : ''; |
|
82 |
$temp['slogan_bg'] = isset($_POST['vp_sloganbg']) ? esc_attr($_POST['vp_sloganbg']) : ''; |
|
83 |
$temp['variation'] = isset($_POST['vp_bg_style']) ? esc_attr($_POST['vp_bg_style']) : ''; |
|
84 |
update_post_meta($post_id, 'vp_settings', $temp); |
|
85 |
} |
|
86 |
|
|
87 |
//*********** Page Templates Area ************** |
|
88 |
|
|
89 |
function vp_pagetemplates_meta() { |
|
90 |
global $post; |
|
91 |
$temp = maybe_unserialize(get_post_meta($post->ID,'vp_ptemplate_settings',true)); |
|
92 |
$categories = isset($temp['categories']) ? $temp['categories'] : ''; |
|
93 |
$blog_posts = isset($temp['blog_posts']) ? $temp['blog_posts'] : ''; |
|
94 |
?> |
|
95 |
Here you'll see some page template options(just for the theme specific page templates) |
|
96 |
<div style="margin: 15px 0px 15px 0px; display: none" class="blog"> |
|
97 |
<h4>Select categories to include: </h4> |
|
98 |
|
|
99 |
<?php $cats_array = get_categories('hide_empty=0'); |
|
100 |
foreach ($cats_array as $cat) { |
|
101 |
$checked = ''; |
|
102 |
|
|
103 |
if (!empty($categories)) { |
|
104 |
if (in_array($cat->cat_ID, $categories)) $checked = "checked=\"checked\""; |
|
105 |
} ?> |
|
106 |
|
|
107 |
<label style="padding-bottom: 5px; display: block" for="<?php echo 'cat-' . $cat->cat_ID; ?>"> |
|
108 |
<input type="checkbox" name="vp_categories[]" id="<?php echo 'cat-' . $cat->cat_ID; ?>" value="<?php echo $cat->cat_ID; ?>" <?php echo $checked; ?> /> |
|
109 |
<?php echo $cat->cat_name; ?> |
|
110 |
</label> |
|
111 |
<?php } ?> |
|
112 |
</div> |
|
113 |
|
|
114 |
<div style="margin: 15px 0px 15px 0px; display: none" class="blog"> |
|
115 |
<label style="font-weight: bold" for="vp_blogposts">Number of blog posts per page:</label> |
|
116 |
<input size="2" type="text" name="vp_blogposts" id="vp_blogposts" value="<?php if($blog_posts == '') echo '6'; else echo $blog_posts;?>" /> |
|
117 |
</div> |
|
118 |
<script type="text/javascript"> |
|
119 |
jQuery(document).ready(function() { |
|
120 |
var page_template = jQuery('select#page_template'), |
|
121 |
page_template_div = jQuery('#vp_pagetemplates_meta'); |
|
122 |
page_template.on('change', function() { |
|
123 |
page_template_div.find('.inside > div').css('display','none'); |
|
124 |
var ptval = jQuery(this).val(); |
|
125 |
if(ptval === "page-template-blog.php") |
|
126 |
jQuery("div.blog").show(400); |
|
127 |
}); |
|
128 |
page_template.trigger('change'); |
|
129 |
}); |
|
130 |
</script> |
|
131 |
<?php |
|
132 |
} |
|
133 |
add_action('save_post', 'vp_save_ptemplate_settings', 10, 2); |
|
134 |
function vp_save_ptemplate_settings($post_id, $post) |
|
135 |
{ |
|
136 |
// verify if this is an auto save routine. |
|
137 |
// If it is our form has not been submitted, so we dont want to do anything |
|
138 |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) |
|
139 |
return; |
|
140 |
// Check permissions |
|
141 |
if ( 'page' == $post->post_type ) |
|
142 |
{ |
|
143 |
if ( !current_user_can( 'edit_page', $post_id ) ) |
|
144 |
return; |
|
145 |
} |
|
146 |
else |
|
147 |
{ |
|
148 |
if ( !current_user_can( 'edit_post', $post_id ) ) |
|
149 |
return; |
|
150 |
} |
|
151 |
$temp = array(); |
|
152 |
if(isset($_POST['vp_categories'])) |
|
153 |
{ |
|
154 |
$temp['categories'] = (array)$_POST['vp_categories']; |
|
155 |
} |
|
156 |
else |
|
157 |
$temp['categories'] = ''; |
|
158 |
|
|
159 |
if(isset($_POST['vp_blogposts']) != '' && is_numeric($_POST['vp_blogposts']) ) |
|
160 |
$temp['blog_posts'] = (int)$_POST['vp_blogposts']; |
|
161 |
else |
|
162 |
$temp['blog_posts'] = 6; |
|
163 |
update_post_meta($post_id, 'vp_ptemplate_settings', $temp); |
|
164 |
} |
|
165 |
|
|
166 |
?> |