Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action("admin_init", "cb_add_extrametafields");
- function cb_add_extrametafields(){
- //add_meta_box( $id, $title, $callback, $page, $context, $priority, $callback_args );
- add_meta_box( 'cbextrametafields', 'Extra Post Options', 'cb_add_extrametafields_html', 'product', 'normal', 'high');
- }
- function cb_add_extrametafields_html(){
- global $post;
- $custom = get_post_custom($post->ID);
- $jobzipcode = $custom["jobzipcode"][0]; //job location zipcode
- $jnchild = $custom["jnchild"][0]; //no. of children
- $jrate1 = $custom["jrate1"][0]; //rate start
- $jrate2 = $custom["jrate2"][0]; //rate end
- $jrateb = $custom["jrateb"][0]; //per hour/ per week
- $jstartdate = $custom["jstartdate"][0]; //per hour/ per week
- $jstartdate = convert_datetous($jstartdate); // yyyy-mm-dd to mm-dd-yyyy
- $appstatus = $custom["appstatus"][0]; //application status, open/close
- if($jrateb == ''){$jrateb = 'hour';}
- if($appstatus == ''){$appstatus = 'open';}
- // Use nonce for verification
- wp_nonce_field( plugin_basename( __FILE__ ), 'cb_extrametafields' );
- ?>
- <style type="text/css">
- .cblabel{
- display: inline-block;
- margin: 0 5px 5px 0;
- text-align: left;
- width: 150px;
- }
- </style>
- <div class="detail">
- <p><label class="cblabel">ZIP Code:</label><input size="20" name="jobzipcode" value="<?php echo $jobzipcode; ?>" /></p>
- <p><label class="cblabel">No. Children:</label><input size="20" name="jnchild" value="<?php echo $jnchild; ?>" /></p>
- <p>
- <label class="cblabel">Rate range (in whole dollars)::</label>From <input size="20" name="jrate1" value="<?php echo $jrate1; ?>" /> To <input size="20" name="jrate2" value="<?php echo $jrate2; ?>" /> per
- <select id="jrateb" name="jrateb" class="input">
- <option value="hour" <?php selected('hour',$jrateb); ?>>Hour</option>
- <option value="week" <?php selected('week',$jrateb); ?>>Week</option>
- </select>
- </p>
- <p><label class="cblabel">Job Start Date:</label><input size="20" name="jstartdate" value="<?php echo $jstartdate; ?>" />(Format: mm-dd-yyyy)</p>
- <p>
- <label class="appstatus">Application Status: </label>
- <select id="appstatus" name="appstatus" class="input">
- <option value="open" <?php selected('open',$appstatus); ?>>Open</option>
- <option value="close" <?php selected('close',$appstatus); ?>>Close</option>
- </select>
- </p>
- </div>
- <?php
- }
- function cb_update_extrametafields($post_id){
- global $post;
- // verify if this is an auto save routine.
- // If it is our form has not been submitted, so we dont want to do anything
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
- return;
- // verify this came from the our screen and with proper authorization,
- // because save_post can be triggered at other times
- if ( !wp_verify_nonce( $_POST['cb_extrametafields'], plugin_basename( __FILE__ ) ) )
- return;
- // Check permissions
- //var_dump($_POST['post_type']);
- if ( 'product' == $_POST['post_type'] )
- {
- if ( !current_user_can( 'edit_post', $post->id ) )
- return;
- }
- else { return; }
- // OK, we're authenticated: we need to find and save the data
- //$post_id, $meta_key, $meta_value, $prev_value = ''
- update_post_meta($post->ID, "jobzipcode", $_POST["jobzipcode"]);
- $latlng = zipcodes_latlng($_POST["jobzipcode"]);
- if($latlng != false){
- update_post_meta($post->ID, "latitude", $latlng->latitude);
- update_post_meta($post->ID, "longitude", $latlng->longitude);
- }
- update_post_meta($post->ID, "jnchild", $_POST["jnchild"]);
- update_post_meta($post->ID, "jrate1", $_POST["jrate1"]);
- update_post_meta($post->ID, "jrate2", $_POST["jrate2"]);
- update_post_meta($post->ID, "jrateb", $_POST["jrateb"]);
- $jstartdate = $_POST["jstartdate"];
- $jstartdate = convert_ustodate($jstartdate);
- update_post_meta($post->ID, "jstartdate", $jstartdate );
- update_post_meta($post->ID, "appstatus", $_POST["appstatus"]);
- }
- add_action("admin_init", "cb_add_extrametafields");
- add_action('save_post', 'cb_update_extrametafields');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement