web/wp-content/themes/selecta/functions/custom.php
changeset 1 0d28b7c10758
equal deleted inserted replaced
0:0d9a58d2c515 1:0d28b7c10758
       
     1 <?php 
       
     2 
       
     3 // Custom fields for WP write panel
       
     4 // This code is protected under Creative Commons License: http://creativecommons.org/licenses/by-nc-nd/3.0/
       
     5 
       
     6 $obox_metaboxes = array(
       
     7 		"media" => array (
       
     8 			"name"			=> "video_thumbnail",
       
     9 			"default" 		=> "",
       
    10 			"label" 		=> "Video Thumbnail url",
       
    11 			"desc"      	=> "Add an image using the  <img src='images/media-button-image.gif' alt='Add Button' /> button above the WYSIWYG, and paste url here.",
       
    12 			"input_type"  	=> "textarea"
       
    13 		),
       
    14 		"video" => array (
       
    15 			"name"			=> "main_video",
       
    16 			"default" 		=> "",
       
    17 			"label" 		=> "Video Object",
       
    18 			"desc"      	=> "Insert your video's <strong>embed</strong> code here.",
       
    19 			"input_type"  	=> "textarea"
       
    20 		),
       
    21 		"media" => array (
       
    22 			"name"			=> "other_media",
       
    23 			"default" 		=> "",
       
    24 			"label" 		=> "Image url",
       
    25 			"desc"      	=> "Add an image using the  <img src='images/media-button-image.gif' alt='Add Button' /> button above the WYSIWYG, and paste url here.",
       
    26 			"input_type"  	=> "textarea"
       
    27 		)
       
    28 	);
       
    29 	
       
    30 function create_meta_box_ui() {
       
    31 	global $post, $obox_metaboxes;
       
    32 	$meta_count = 0;
       
    33 	foreach ($obox_metaboxes as $obox_custom_metabox) {
       
    34 		$meta_count = ($meta_count + 1);
       
    35 		$obox_metabox_value = get_post_meta($post->ID,$obox_custom_metabox["name"],true);
       
    36 		
       
    37 		if ($obox_metabox_value == "" || !isset($obox_metabox_value)) {
       
    38 			$obox_metabox_value = $obox_custom_metabox['default'];
       
    39 		}
       
    40 		if($meta_count > 1) :
       
    41 ?>
       
    42 			<br />
       
    43 <?php 	endif ?>
       
    44 			
       
    45 		<table style="width: 100%;">
       
    46 			<tr>
       
    47 				<th style="text-align: left; vertical-align: top; padding-top: 5px; width: 100%;"><label for="<?php echo $obox_custom_metabox; ?>"><?php echo $obox_custom_metabox["label"]; ?></label></th>
       
    48 			</tr>
       
    49 			<tr>
       
    50             	<?php if($obox_custom_metabox["name"] == "main_video") : ?>
       
    51 					<td><textarea style="width: 100%;" rows="8" name="<?php echo "obox_".$obox_custom_metabox["name"]; ?>" id="'.$obox_custom_metabox.'"><?php echo $obox_metabox_value; ?></textarea></td>
       
    52 				<?php elseif($obox_custom_metabox["input_type"] == "textarea") : ?>
       
    53 					<td><textarea style="width: 100%;" rows="4" name="<?php echo "obox_".$obox_custom_metabox["name"]; ?>" id="'.$obox_custom_metabox.'"><?php echo $obox_metabox_value; ?></textarea></td>
       
    54 				<?php else : ?>
       
    55     	        	<td><input type="text" name="<?php echo "obox_".$obox_custom_metabox["name"]; ?>" id="<?php echo $obox_custom_metabox ?>" value="<?php echo $obox_metabox_value; ?>" size="<?php echo $obox_custom_metabox["input_size"] ?>" /></td>
       
    56 				<?php endif; ?>
       
    57 			</tr>
       
    58 			<tr><td style=" text-align: left;"><p style="font-size: 11px;"><?php echo $obox_custom_metabox["desc"] ?></p></td></tr>
       
    59 		</table>
       
    60 <?php
       
    61 	}
       
    62 }
       
    63 
       
    64 function insert_obox_metabox($pID) {
       
    65 	global $obox_metaboxes;
       
    66 	
       
    67 	foreach ($obox_metaboxes as $obox_custom_metabox) {
       
    68 		$var = "obox_".$obox_custom_metabox["name"];
       
    69 		if (isset($_POST[$var])) {
       
    70 			add_post_meta($pID,$obox_custom_metabox["name"],$_POST[$var],true) or update_post_meta($pID,$obox_custom_metabox["name"],$_POST[$var]);
       
    71 		}
       
    72 	}
       
    73 }
       
    74 
       
    75 function add_obox_meta_box() {
       
    76 	if ( function_exists('add_meta_box') ) {
       
    77 		add_meta_box('obox-meta-box',$GLOBALS['themename'].' Options','create_meta_box_ui','post','normal');
       
    78 	}
       
    79 }
       
    80 
       
    81 add_action('admin_menu', 'add_obox_meta_box');
       
    82 add_action('wp_insert_post', 'insert_obox_metabox');
       
    83 
       
    84 ?>