wp/wp-content/themes/IN-MOTION-package-u1/in-motion/functions/custom-page.php
changeset 0 d970ebf37754
equal deleted inserted replaced
-1:000000000000 0:d970ebf37754
       
     1 <?php
       
     2 //page editing
       
     3 	add_action( 'admin_menu', 'hybrid_create_meta_box_page' );
       
     4    add_action( 'save_post', 'hybrid_save_meta_data_page' );
       
     5 
       
     6 
       
     7 
       
     8 function hybrid_create_meta_box_page() {
       
     9 	global $theme_name;
       
    10 
       
    11 	add_meta_box( 'page-meta-boxes', __('Page options','pego_tr'), 'page_meta_boxes', 'page', 'normal', 'high' );
       
    12 }
       
    13 
       
    14 
       
    15 
       
    16 function hybrid_page_meta_boxes() {
       
    17 
       
    18 	/* Array of the meta box options. */
       
    19 	$meta_boxes = array(
       
    20 			'show_page_in_menu' => array( 
       
    21 							'name' => 'show_page_in_menu',
       
    22 							'title' => __('Show page in menu?','pego_tr'), 
       
    23 							'description' => __('Select Yes if you want the page to be displayed in the menu. ','pego_tr'),
       
    24 							'type' => "select", 
       
    25 							'std' => 'No',
       
    26 							'options' => array('No', 'Yes')),
       
    27 			'page_template' => array( 
       
    28 							'name' => 'page_template',
       
    29 							'title' => __('Choose page template','pego_tr'), 
       
    30 							'description' => __('Choose a template if you want. ','pego_tr'),
       
    31 							'type' => "select", 
       
    32 							'std' => 'None',
       
    33 							'options' => array('None', 'Home', 'Portfolio', 'Contact', 'Blog', 'News')),
       
    34 		   'short_desc' => array( 
       
    35 							'name' => 'short_desc',
       
    36 							'title' => __('Short page description','pego_tr'), 
       
    37 							'description' => __('Enter a short page description. It will be added in the page title.','pego_tr'), 
       
    38 							'type' => 'text' ),	
       
    39 			'external_page_link' => array( 
       
    40 							'name' => 'external_page',
       
    41 							'title' => __('External page url:','pego_tr'),							
       
    42 							'description' => __('Isert link to have an external page in menu.','pego_tr'), 
       
    43 							'type' => 'text' )							
       
    44 	);
       
    45 
       
    46 	return apply_filters( 'hybrid_page_meta_boxes', $meta_boxes );
       
    47 }
       
    48 
       
    49 function page_meta_boxes() {
       
    50 	global $post;
       
    51 	$meta_boxes = hybrid_page_meta_boxes(); ?>
       
    52 
       
    53 	<table class="form-table">
       
    54 	<?php foreach ( $meta_boxes as $meta ) :
       
    55 
       
    56 		$value = stripslashes( get_post_meta( $post->ID, $meta['name'], true ) );
       
    57 
       
    58 		if ( $meta['type'] == 'text' )
       
    59 			get_meta_text_input_page( $meta, $value );
       
    60 		elseif ( $meta['type'] == 'textarea' )
       
    61 			get_meta_textarea_page( $meta, $value );
       
    62 		elseif ( $meta['type'] == 'select' )
       
    63 			get_meta_select_page( $meta, $value );
       
    64 
       
    65 	endforeach; ?>
       
    66 	</table>
       
    67 <?php
       
    68 }
       
    69 
       
    70 
       
    71 function get_meta_text_input_page( $args = array(), $value = false ) {
       
    72 
       
    73 	extract( $args ); ?>
       
    74 
       
    75 	<tr>
       
    76 		<th style="width:30%;">
       
    77 			<label for="<?php echo $name; ?>"><b><?php echo $title; ?></b><br/><span  style="color:#777777;"><?php echo $description; ?></span></label>
       
    78 		</th>
       
    79 		<td>
       
    80 			<input type="text" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo esc_html( $value ); ?>" size="30" tabindex="30" style="width: 97%;" />
       
    81 			<input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
       
    82 		</td>
       
    83 	</tr>
       
    84 	<?php
       
    85 }
       
    86 
       
    87 
       
    88 function get_meta_select_page( $args = array(), $value = false ) {
       
    89 
       
    90 	extract( $args ); ?>
       
    91 
       
    92 	<tr>
       
    93 		<th style="width:30%;">
       
    94 			<label for="<?php echo $name; ?>"><b><?php echo $title; ?></b><br/><span style="color:#777777;" ><?php echo $description; ?></span></label>
       
    95 		</th>
       
    96 		<td>
       
    97 			<select style="width:90px;" name="<?php echo $name; ?>" id="<?php echo $name; ?>">
       
    98 			<?php foreach ( $options as $option ) : ?>
       
    99 				<option <?php if ( htmlentities( $value, ENT_QUOTES ) == $option ) echo ' selected="selected"'; ?>>
       
   100 					<?php echo $option; ?>
       
   101 				</option>
       
   102 			<?php endforeach; ?>
       
   103 			</select>
       
   104 			<input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
       
   105 		</td>
       
   106 	</tr>
       
   107 	<?php
       
   108 }
       
   109 
       
   110 
       
   111 function get_meta_color_page( $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 
       
   133 function get_meta_textarea_page( $args = array(), $value = false ) {
       
   134 
       
   135 	extract( $args ); ?>
       
   136 
       
   137 	<tr>
       
   138 		<th style="width:30%;">
       
   139 			<label for="<?php echo $name; ?>"><b><?php echo $title; ?></b><br/><span style="color:#777777;"><?php echo $description; ?></span></label>
       
   140 		</th>
       
   141 		<td>
       
   142 			<textarea name="<?php echo $name; ?>" id="<?php echo $name; ?>" cols="60" rows="4" tabindex="30" style="width: 97%;"><?php echo esc_html( $value ); ?></textarea>
       
   143 			<input type="hidden" name="<?php echo $name; ?>_noncename" id="<?php echo $name; ?>_noncename" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
       
   144 		</td>
       
   145 	</tr>
       
   146 	<?php
       
   147 }
       
   148 
       
   149 function hybrid_save_meta_data_page( $post_id ) {
       
   150 	global $post;
       
   151 	
       
   152 	$meta_boxes = array_merge( hybrid_page_meta_boxes() );
       
   153 	foreach ( $meta_boxes as $meta_box ) :
       
   154 
       
   155 		if ( !wp_verify_nonce( $_POST[$meta_box['name'] . '_noncename'], plugin_basename( __FILE__ ) ) )
       
   156 			return $post_id;
       
   157 
       
   158 		if ( 'page' == $_POST['post_type'] && !current_user_can( 'edit_page', $post_id ) )
       
   159 			return $post_id;
       
   160 
       
   161 		elseif ( 'post' == $_POST['post_type'] && !current_user_can( 'edit_post', $post_id ) )
       
   162 			return $post_id;
       
   163 
       
   164 		$data = stripslashes( $_POST[$meta_box['name']] );
       
   165 
       
   166 		if ( get_post_meta( $post_id, $meta_box['name'] ) == '' )
       
   167 			add_post_meta( $post_id, $meta_box['name'], $data, true );
       
   168 
       
   169 		elseif ( $data != get_post_meta( $post_id, $meta_box['name'], true ) )
       
   170 			update_post_meta( $post_id, $meta_box['name'], $data );
       
   171 
       
   172 		elseif ( $data == '' )
       
   173 			delete_post_meta( $post_id, $meta_box['name'], get_post_meta( $post_id, $meta_box['name'], true ) );
       
   174 
       
   175 	endforeach;
       
   176 	
       
   177 }
       
   178 
       
   179 ?>