File: /home/vmasmheia229/domains/overtoneband.com/html/wp-content/themes/bigcity/functions/meta_boxes.php
<?php
/*********************************************** HEADER ELEMENT CHOICE*********************************************************/
add_action( 'add_meta_boxes', 'page_opt_meta_box_add' );
function page_opt_meta_box_add() {
$post_types = get_post_types();
foreach ( $post_types as $post_type ) {
add_meta_box( 'page_option_choice', 'Page Options', 'page_opt_meta_box', $post_type, 'side', 'high' );
}
}
function page_opt_meta_box( $post )
{
$values = get_post_custom( $post->ID );
$selected = isset( $values['header_choice_select'] ) ? esc_attr( $values['header_choice_select'][0] ) : '';
wp_nonce_field( 'page_opt_meta_box_nonce', 'meta_box_nonce' );
?>
<p><span><strong>Select Header Element:</strong></span><br />
<select name="header_choice_select" id="header_choice_select">
<option value="" <?php selected( $selected, '' ); ?>>Page title</option>
<option value="post-slider" <?php selected( $selected, 'post-slider' ); ?>>Post Slider</option>
<option value="orbit-slider" <?php selected( $selected, 'orbit-slider' ); ?>>Orbit Slider</option>
<option value="custom-element" <?php selected( $selected, 'custom-element' ); ?>>Custom Header Element</option>
</select><br/>
<span style="font-size:11px; color:#999; line-height:1.3;">* To select header for blog go to BigCity / Theme Options / Blog Options</span>
</p>
<?php
}
add_action( 'save_post', 'cd_meta_box_save' );
function cd_meta_box_save( $post_id )
{
// Bail if we're doing an auto save
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
// if our nonce isn't there, or we can't verify it, bail
if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'page_opt_meta_box_nonce' ) ) return;
// if our current user can't edit this post, bail
if( !current_user_can( 'edit_post' ) ) return;
// now we can actually save the data
$allowed = array(
'a' => array( // on allow a tags
'href' => array() // and those anchords can only have href attribute
)
);
if( isset( $_POST['header_choice_select'] ) )
update_post_meta( $post_id, 'header_choice_select', esc_attr( $_POST['header_choice_select'] ) );
}
/*********************************************** CUSTOM HEADER IMAGE *********************************************/
add_action( 'add_meta_boxes', 'custom_header_img' );
function custom_header_img() {
$post_types = get_post_types();
foreach ( $post_types as $post_type ) {
add_meta_box( 'custom_header_img', 'Custom header image URL', 'custom_header_img_id', $post_type, 'normal', 'high' );
}
}
function custom_header_img_id( $post )
{
$cat_values = get_post_custom( $post->ID );
$img_id = isset( $cat_values['custom_header_img_id_value'] ) ? esc_attr( $cat_values['custom_header_img_id_value'][0] ) : '';
wp_nonce_field( 'custom_header_img_id_nonce', 'meta_box_nonce4' );
?>
<span style="font-size:11px; color:#999; line-height:1.3;">Enter image URL with http://</span>
<p><input type="text" name="custom_header_img_id_value" id="custom_header_img_id_value" value="<?php echo $img_id; ?>" style="width:100%;" /> </p>
<?php
}
add_action( 'save_post', 'custom_header_img_id_save' );
function custom_header_img_id_save( $post_id )
{
// Bail if we're doing an auto save
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
// if our nonce isn't there, or we can't verify it, bail
if( !isset( $_POST['meta_box_nonce4'] ) || !wp_verify_nonce( $_POST['meta_box_nonce4'], 'custom_header_img_id_nonce' ) ) return;
// if our current user can't edit this post, bail
if( !current_user_can( 'edit_post' ) ) return;
// now we can actually save the data
$allowed = array(
'a' => array( // on allow a tags
'href' => array() // and those anchords can only have href attribute
)
);
if( isset( $_POST['custom_header_img_id_value'] ) )
update_post_meta( $post_id, 'custom_header_img_id_value', wp_kses( $_POST['custom_header_img_id_value'], $allowed ) );
}
/*********************************************** CUSTOM HEADER HTML ****************************************************/
$meta_box = array(
'id' => 'custom_header_html_add',
'title' => 'Custom Header HTML, insert anything you want.',
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'name' => 'Textarea',
'desc' => 'Custom Header HTML will only work if "Custom Header Element" choosen. Supports Flash objects and shortcodes!',
'id' => 'custom_header_html',
'type' => 'textarea',
'std' => ''
)
)
);
add_action('admin_menu', 'mytheme_add_box');
// Add meta box
function mytheme_add_box() {
$post_types = get_post_types();
foreach ( $post_types as $post_type ) {
global $meta_box;
add_meta_box($meta_box['id'], $meta_box['title'], 'mytheme_show_box', $post_type, $meta_box['context'], $meta_box['priority']);
}
}
// Callback function to show fields in meta box
function mytheme_show_box() {
global $meta_box, $post;
if (function_exists('wp_nonce_field')) {
wp_nonce_field('mytheme_nonce_action','mytheme_nonce_field');
}
foreach ($meta_box['fields'] as $field) {
// get current post meta data
$meta = get_post_meta($post->ID, $field['id'], true);
switch ($field['type']) {
case 'textarea':
echo '<span style="font-size:11px; color:#999; line-height:1.3;">', $field['desc'],'</span><br/><br/><textarea name="', $field['id'], '" id="', $field['id'], '" rows="6" style="width:99%">', $meta , '</textarea>';
break;
}
}
}
add_action('save_post', 'mytheme_save_data');
// Save data from meta box
function mytheme_save_data($post_id) {
global $meta_box;
// verify nonce
if ( empty($_POST)
|| !wp_verify_nonce(isset($_POST['mytheme_nonce_field']) && $_POST['mytheme_nonce_field'],'mytheme_nonce_action')
|| defined('DOING_AJAX' )) {
return;
}
// check autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post_id;
}
// check permissions
if ('page' == $_POST['post_type']) {
if (!current_user_can('edit_page', $post_id)) {
return $post_id;
}
} elseif (!current_user_can('edit_post', $post_id)) {
return $post_id;
}
foreach ($meta_box['fields'] as $field) {
$old = get_post_meta($post_id, $field['id'], true);
$new = $_POST[$field['id']];
if ($new && $new != $old) {
update_post_meta($post_id, $field['id'], $new);
} elseif ('' == $new && $old) {
delete_post_meta($post_id, $field['id'], $old);
}
}
}
/*********************************************** PORTFOLIO CATEGORY CHOOSE *********************************/
add_action( 'add_meta_boxes', 'add_portfolio_cat' );
function add_portfolio_cat() {
add_meta_box( 'portfolio_cat', 'Portfolio categories to show in paged portfolio template', 'portfolio_cat_id', 'page', 'normal', 'default' );
}
function portfolio_cat_id( $post )
{
$cat_values = get_post_custom( $post->ID );
$cat_id = isset( $cat_values['portfolio_cat_id_value'] ) ? esc_attr( $cat_values['portfolio_cat_id_value'][0] ) : '';
wp_nonce_field( 'portfolio_cat_id_nonce', 'meta_box_nonce3' );
?>
<span style="font-size:11px; color:#999; line-height:1.3;">Enter <span style="color:red; font-weight:bold;">SLUG</span> names of categories (comma separated) you want to show in paged portfolio template or leave blank to show all.</span>
<p><input type="text" name="portfolio_cat_id_value" id="portfolio_cat_id_value" value="<?php echo $cat_id; ?>" style="width:100%;" /> </p>
<?php
}
add_action( 'save_post', 'portfolio_cat_id_save' );
function portfolio_cat_id_save( $post_id )
{
// Bail if we're doing an auto save
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
// if our nonce isn't there, or we can't verify it, bail
if( !isset( $_POST['meta_box_nonce3'] ) || !wp_verify_nonce( $_POST['meta_box_nonce3'], 'portfolio_cat_id_nonce' ) ) return;
// if our current user can't edit this post, bail
if( !current_user_can( 'edit_post' ) ) return;
// now we can actually save the data
$allowed = array(
'a' => array( // on allow a tags
'href' => array() // and those anchords can only have href attribute
)
);
if( isset( $_POST['portfolio_cat_id_value'] ) )
update_post_meta( $post_id, 'portfolio_cat_id_value', wp_kses( $_POST['portfolio_cat_id_value'], $allowed ) );
}
/*********************************************** PORTFOLIO META BOXES **************************************************/
add_action( 'add_meta_boxes', 'pf_meta_box_add' );
function pf_meta_box_add()
{
add_meta_box( 'portfolio_meta_box', 'Item Options', 'pf_meta_box', 'portfolio', 'normal', 'high' );
}
function pf_meta_box( $post )
{
$pf_values = get_post_custom( $post->ID );
$pf_text = isset( $pf_values['pf_meta_box_text'] ) ? esc_attr( $pf_values['pf_meta_box_text'][0] ) : 'Client:';
$pf_text2 = isset( $pf_values['pf_meta_box_text2'] ) ? esc_attr( $pf_values['pf_meta_box_text2'][0] ) : '';
$pf_text3 = isset( $pf_values['pf_meta_box_text3'] ) ? esc_attr( $pf_values['pf_meta_box_text3'][0] ) : 'Model:';
$pf_text4 = isset( $pf_values['pf_meta_box_text4'] ) ? esc_attr( $pf_values['pf_meta_box_text4'][0] ) : '';
$pf_text5 = isset( $pf_values['pf_meta_box_text5'] ) ? esc_attr( $pf_values['pf_meta_box_text5'][0] ) : 'URL:';
$pf_text6 = isset( $pf_values['pf_meta_box_text6'] ) ? esc_attr( $pf_values['pf_meta_box_text6'][0] ) : '';
$pf_text7 = isset( $pf_values['pf_meta_box_text7'] ) ? esc_attr( $pf_values['pf_meta_box_text7'][0] ) : '';
wp_nonce_field( 'pf_meta_box_nonce', 'meta_box_nonce2' );
?>
<p>
<label for="pf_meta_box_text"><strong>Details:</strong></label><br/>
<input type="text" name="pf_meta_box_text" id="pf_meta_box_text" value="<?php echo $pf_text; ?>" style="width:80px;" />
<input type="text" name="pf_meta_box_text2" id="pf_meta_box_text2" value="<?php echo $pf_text2; ?>" style="width:170px;" />
</p>
<p>
<input type="text" name="pf_meta_box_text3" id="pf_meta_box_text3" value="<?php echo $pf_text3; ?>" style="width:80px;" />
<input type="text" name="pf_meta_box_text4" id="pf_meta_box_text4" value="<?php echo $pf_text4; ?>" style="width:170px;" />
</p>
<p>
<input type="text" name="pf_meta_box_text5" id="pf_meta_box_text5" value="<?php echo $pf_text5; ?>" style="width:80px;" />
<input type="text" name="pf_meta_box_text6" id="pf_meta_box_text6" value="<?php echo $pf_text6; ?>" style="width:170px;" />
</p>
<span style="font-size:11px; color:#999; line-height:1.3;">Leave second field blank to disable corresponding string. Default detail titles are changeable.</span>
<br/>
<p>
<label for="pf_meta_box_phtml"><strong>HTML description for one column portfolio:</strong></label><br/>
<textarea name="pf_meta_box_text7" id="pf_meta_box_text7" rows="4" style="width:99%"><?php echo $pf_text7; ?></textarea>
</p>
<span style="font-size:11px; color:#999; line-height:1.3;">This content will be displayed next to thumbnail in portfolio one column view.</span>
<?php
}
add_action( 'save_post', 'pf_meta_box_save' );
function pf_meta_box_save( $post_id )
{
// Bail if we're doing an auto save
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
// if our nonce isn't there, or we can't verify it, bail
if( !isset( $_POST['meta_box_nonce2'] ) || !wp_verify_nonce( $_POST['meta_box_nonce2'], 'pf_meta_box_nonce' ) ) return;
// if our current user can't edit this post, bail
if( !current_user_can( 'edit_post' ) ) return;
// now we can actually save the data
$pf_allowed = array(
'a' => array( // on allow a tags
'href' => array() // and those anchords can only have href attribute
)
);
// Probably a good idea to make sure your data is set
if( isset( $_POST['pf_meta_box_text'] ) )
update_post_meta( $post_id, 'pf_meta_box_text', wp_kses( $_POST['pf_meta_box_text'], $pf_allowed ) );
if( isset( $_POST['pf_meta_box_text2'] ) )
update_post_meta( $post_id, 'pf_meta_box_text2', wp_kses( $_POST['pf_meta_box_text2'], $pf_allowed ) );
if( isset( $_POST['pf_meta_box_text3'] ) )
update_post_meta( $post_id, 'pf_meta_box_text3', wp_kses( $_POST['pf_meta_box_text3'], $pf_allowed ) );
if( isset( $_POST['pf_meta_box_text4'] ) )
update_post_meta( $post_id, 'pf_meta_box_text4', wp_kses( $_POST['pf_meta_box_text4'], $pf_allowed ) );
if( isset( $_POST['pf_meta_box_text5'] ) )
update_post_meta( $post_id, 'pf_meta_box_text5', wp_kses( $_POST['pf_meta_box_text5'], $pf_allowed ) );
if( isset( $_POST['pf_meta_box_text6'] ) )
update_post_meta( $post_id, 'pf_meta_box_text6', wp_kses( $_POST['pf_meta_box_text6'], $pf_allowed ) );
if( isset( $_POST['pf_meta_box_text7'] ) )
update_post_meta( $post_id, 'pf_meta_box_text7', esc_html( $_POST['pf_meta_box_text7'], $pf_allowed ) );
}
?>