wp/wp-content/themes/IN-MOTION-package-u1/in-motion/functions/custom-post.php
changeset 0 d970ebf37754
equal deleted inserted replaced
-1:000000000000 0:d970ebf37754
       
     1 <?php
       
     2 //post editing
       
     3 
       
     4 
       
     5 	add_action( 'admin_menu', 'hybrid_create_meta_box' );
       
     6    add_action( 'save_post', 'hybrid_save_meta_data' );
       
     7 
       
     8 
       
     9 
       
    10 function hybrid_create_meta_box() {
       
    11 	global $theme_name;
       
    12 	add_meta_box( 'post-meta-boxes', __('General post options','pego_tr'), 'post_meta_boxes', 'post', 'normal', 'high' );
       
    13 }
       
    14 
       
    15 
       
    16 function hybrid_post_meta_boxes() {
       
    17 
       
    18 	/* Array of the meta box options. */
       
    19 	$meta_boxes = array(
       
    20 			'post_type_selected' => array( 
       
    21 							'name' => 'post_type_selected', 
       
    22 							'title' => __(' Post type:', 'pego_tr'), 
       
    23 							'description' => __('Choose the type of the post.','pego_tr'),
       
    24 							'type' => "select", 'std' => 'Image',
       
    25 							'options' => array('Image', 'Slideshow', 'Video', 'News')),
       
    26 			'post_video_url' => array( 
       
    27 							'name' => 'post_video_url',
       
    28 							'title' => __('Video URL:', 'pego_tr'), 
       
    29 							'description' => __('Enter the embedded code of the post.','pego_tr'),
       
    30 							'type' => 'textarea' )	
       
    31 );
       
    32 	return apply_filters( 'hybrid_post_meta_boxes', $meta_boxes );
       
    33 }
       
    34 
       
    35 function post_meta_boxes() {
       
    36 	global $post;
       
    37 	$meta_boxes = hybrid_post_meta_boxes(); ?>
       
    38 
       
    39 	<table class="form-table">
       
    40 	<?php foreach ( $meta_boxes as $meta ) :
       
    41 
       
    42 		$value = get_post_meta( $post->ID, $meta['name'], true );
       
    43 
       
    44 		if ( $meta['type'] == 'text' )
       
    45 			get_meta_text_input( $meta, $value );
       
    46 		elseif ( $meta['type'] == 'textarea' )
       
    47 			get_meta_textarea( $meta, $value );
       
    48 		elseif ( $meta['type'] == 'select' )
       
    49 			get_meta_select( $meta, $value );
       
    50 
       
    51 	endforeach; ?>
       
    52 	</table>
       
    53 <?php
       
    54 }
       
    55 
       
    56 function get_meta_text_input( $args = array(), $value = false ) {
       
    57 
       
    58 	extract( $args ); ?>
       
    59 
       
    60 	<tr>
       
    61 		<th style="width:30%;">
       
    62 			<label for="<?php echo $name; ?>"><b><?php echo $title; ?></b><br/><span  style="color:#777777;"><?php echo $description; ?></span></label>
       
    63 		</th>
       
    64 		<td>
       
    65 			<input type="text" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo esc_html( $value ); ?>" size="30" tabindex="30" style="width: 97%;" />
       
    66 			<input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
       
    67 		</td>
       
    68 	</tr>
       
    69 	<?php
       
    70 }
       
    71 
       
    72 function get_meta_select( $args = array(), $value = false ) {
       
    73 
       
    74 	extract( $args ); ?>
       
    75 
       
    76 	<tr>
       
    77 		<th style="width:30%;">
       
    78 			<label for="<?php echo $name; ?>"><b><?php echo $title; ?></b><br/><span  style="color:#777777;"><?php echo $description; ?></span></label>
       
    79 	
       
    80 		</th>
       
    81 		<td>
       
    82 			<select style="width:100px;" name="<?php echo $name; ?>" id="<?php echo $name; ?>">
       
    83 			<?php foreach ( $options as $option ) : ?>
       
    84 				<option <?php if ( htmlentities( $value, ENT_QUOTES ) == $option ) echo ' selected="selected"'; ?>>
       
    85 					<?php echo $option; ?>
       
    86 				</option>
       
    87 			<?php endforeach; ?>
       
    88 			</select>
       
    89 			<input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
       
    90 		</td>
       
    91 	</tr>
       
    92 	<?php
       
    93 }
       
    94 
       
    95 function get_meta_textarea( $args = array(), $value = false ) {
       
    96 
       
    97 	extract( $args ); ?>
       
    98 
       
    99 	<tr>
       
   100 		<th style="width:30%;">
       
   101 			<label for="<?php echo $name; ?>"><b><?php echo $title; ?></b><br/><span  style="color:#777777;"><?php echo $description; ?></span></label>
       
   102 		</th>
       
   103 		<td>
       
   104 			<textarea name="<?php echo $name; ?>" id="<?php echo $name; ?>" cols="60" rows="4" tabindex="30" style="width: 97%;"><?php echo esc_html( $value ); ?></textarea>
       
   105 			<input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
       
   106 		</td>
       
   107 	</tr>
       
   108 	<?php
       
   109 }
       
   110 
       
   111 function get_meta_color( $args = array(), $value = false ) {
       
   112 
       
   113 	extract( $args ); ?>
       
   114 
       
   115 	<tr>
       
   116 		<th style="width:30%;">
       
   117 			<label for="<?php echo $name; ?>"><b><?php echo $title; ?></b><br/><span style="color:#777777;" ><?php echo $description; ?></span></label>
       
   118 		</th>
       
   119 		<td>
       
   120 			<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/functions/css/colorpicker.css" type="text/css" media="screen" />
       
   121 			<script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/functions/js/jquery.js"></script>
       
   122 			<script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/functions/js/colorpicker.js"></script>	
       
   123 			<script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/functions/js/eye.js"></script>
       
   124 			<script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/functions/js/layout.js?ver=1.0.2"></script>
       
   125 		   #<input type="text" maxlength="6" size="6" name="<?php echo $name; ?>"  id="colorpickerField1" value="<?php echo esc_html( $value ); ?>"  />
       
   126 			<input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
       
   127 		</td>
       
   128 	</tr>
       
   129 	<?php
       
   130 }
       
   131 
       
   132 function hybrid_save_meta_data( $post_id ) {
       
   133 	global $post;
       
   134 
       
   135 
       
   136 		$meta_boxes = array_merge( hybrid_post_meta_boxes() );
       
   137 
       
   138 	foreach ( $meta_boxes as $meta_box ) :
       
   139 
       
   140 		if ( !wp_verify_nonce( $_POST[$meta_box['name'] . '_noncename'], plugin_basename( __FILE__ ) ) )
       
   141 			return $post_id;
       
   142 
       
   143 		if ( 'page' == $_POST['post_type'] && !current_user_can( 'edit_page', $post_id ) )
       
   144 			return $post_id;
       
   145 
       
   146 		elseif ( 'post' == $_POST['post_type'] && !current_user_can( 'edit_post', $post_id ) )
       
   147 			return $post_id;
       
   148 
       
   149 		$data = stripslashes( $_POST[$meta_box['name']] );
       
   150 
       
   151 		if ( get_post_meta( $post_id, $meta_box['name'] ) == '' )
       
   152 			add_post_meta( $post_id, $meta_box['name'], $data, true );
       
   153 
       
   154 		elseif ( $data != get_post_meta( $post_id, $meta_box['name'], true ) )
       
   155 			update_post_meta( $post_id, $meta_box['name'], $data );
       
   156 
       
   157 		elseif ( $data == '' )
       
   158 			delete_post_meta( $post_id, $meta_box['name'], get_post_meta( $post_id, $meta_box['name'], true ) );
       
   159 
       
   160 	endforeach;
       
   161 }
       
   162 
       
   163 ?>