Frontier Post – Add fields
You can add additional WordPress post fields by adding additional code to you functions.php in your child theme.
In below example the fields are added to the entry form by using hooks and filters:
- Comment status (open/closed)
- Trackback and Pingback status (open/closed)
- Publish time
For publish time, please be aware that future post is not supported by Frontier Post.
3 items are added:
- Register jquery script and css for Datepicker to work (datepicker is shipped with WordPress)
- Display the fields on the form using action: frontier_post_form_standard
- Save the result using filter: frontier_post_pre_update
Below code supports future posts (Future posts require Frontier Post version 3.8.1 or later) – Be aware that future posts can be tricky from a validation perspective.
The below code is for reference, and will not be supported. For Custom fields please see: Frontier Post – Custom Fields
//***************************************************************************************
//* load jquery datepicker
//***************************************************************************************
function register_my_datepick()
{
wp_enqueue_script('jquery-ui-datepicker');
wp_enqueue_style('e2b-admin-ui-css','http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.0/themes/base/jquery-ui.css',false,"1.9.0",false);
}
add_action('wp_enqueue_scripts', 'register_my_datepick');
//***************************************************************************************
//* Add fields to frontier post form
//***************************************************************************************
function fp_my_frontier_post_fields( $thispost, $tmp_task_new)
{
// js script to set class for datepicker
echo '<script>
jQuery(function() {
jQuery( ".datepicker" ).datepicker({
dateFormat : "yy-mm-dd"
});
});
</script>';
// New table cell containing additional fields
echo '<tr><td class="frontier_no_border">';
echo '<fieldset class="frontier_post_fieldset_additional">';
echo '<legend>Additional fields</legend>';
// a pable to held the fields and ensure alignment
echo '<table class="frontier_no_border"><tr>';
// Comment status field
$open = ( (isset($thispost->comment_status) && $thispost->comment_status == "open") ? "open" : "closed");
echo '<td class="frontier_no_border">'.__("Allow comments","frontier-post").":</td>";
echo '<td class="frontier_no_border">';
echo '<input class="fp_radioline" type="radio" id="fp_comment_status" name="fp_comment_status" value="open" '.($open == 'open' ? 'checked="checked"' : '').' >Open';
echo '<input class="fp_radioline" type="radio" id="fp_comment_status" name="fp_comment_status" value="closed" '.($open == 'closed' ? 'checked="checked"' : '').' >Closed';
echo '</td>';
echo '</tr><tr>';
// Ping status field
$open = ( (isset($thispost->ping_status) && $thispost->ping_status == "open") ? "open" : "closed");
echo '<td class="frontier_no_border">'.__("Allow track- & pingbacks","frontier-post").":</td>";
echo '<td class="frontier_no_border">';
echo '<input class="fp_radioline" type="radio" id="fp_ping_status" name="fp_ping_status" value="open" '.($open == 'open' ? 'checked="checked"' : '').' >Open';
echo '<input class="fp_radioline" type="radio" id="fp_ping_status" name="fp_ping_status" value="closed" '.($open == 'closed' ? 'checked="checked"' : '').' >Closed';
echo '</td>';
echo '</tr><tr>';
// Post date field
$tmp_post_date = ($thispost->post_date ? $thispost->post_date : date("Y-m-d h:i"));
$tmp_date = substr($tmp_post_date,0,10);
$tmp_hour = substr($tmp_post_date,11,2);
$tmp_minute = substr($tmp_post_date,14,2);
echo '<td class="frontier_no_border">Publish time:</td>';
echo '<td class="frontier_no_border">';
echo '<input name="fp_post_date" id="fp-post-date" value="'.$tmp_date.'" type="text" class="datepicker fp-post-date"/>';
echo ' ';
echo '<input name="fp_post_hour" id="fp_post_hour" value="'.$tmp_hour.'" type="text" class="fp-post-hour"/>';
echo ':';
echo '<input name="fp_post_minute" id="fp_post_minute" value="'.$tmp_minute.'" type="text" class="fp-post-minute"/>';
echo '</td>';
echo '</tr></table>';
echo '</fieldset>';
echo '</td></tr>';
}
// add the action
add_action( 'frontier_post_form_standard', 'fp_my_frontier_post_fields', 10, 2 );
// *** End display frontier post additional fields
//***************************************************************************************
//* Get additional field values, and parse them back to frontier post to save
//***************************************************************************************
function fp_save_my_fields($tmp_post, $tmp_task_new, $input_values )
{
// Comment status
if ( array_key_exists('fp_comment_status', $input_values) )
$tmp_post['comment_status'] = $input_values['fp_comment_status'];
// ping status
if ( array_key_exists('fp_ping_status', $input_values) )
$tmp_post['ping_status'] = $input_values['fp_ping_status'];
// post date
if ( array_key_exists('fp_post_date', $input_values) )
{
$tmp_post_date = $input_values['fp_post_date'];
$tmp_post_hour = zeroise(intval($input_values['fp_post_hour']),2);
$tmp_post_minute = zeroise(intval($input_values['fp_post_minute']),2);
$tmp_year = substr($tmp_post_date ,0,4);
$tmp_month = substr($tmp_post_date ,5,2);
$tmp_day = substr($tmp_post_date ,8,2);
$tmp_publish_time = $tmp_post_date." ".$tmp_post_hour.":".$tmp_post_minute;
// Check if valid date time
if ( !checkdate($tmp_month, $tmp_day, $tmp_year) || $tmp_post_hour>23 || $tmp_post_minute>59 )
{
frontier_post_set_msg('<div id="frontier-post-alert">post_date: Error Invalid date or time: '.$tmp_publish_time.'</div>');
}
else
{
$tmp_post['post_date'] = $tmp_publish_time;
// set status to future, if post_date is in the future
if ( strtotime(get_gmt_from_date($tmp_publish_time)) > strtotime('now') && in_array($tmp_post['post_status'], array('future', 'publish')) )
{
$tmp_post['post_status'] = 'future';
// edit_date & post_date_gmt is neccssary for future post scheduling to work, not logical, but WordPress :)
$tmp_post['edit_date'] = true;
$tmp_post['post_date_gmt'] = get_gmt_from_date( $tmp_post['post_date'] );
}
else
{
//If post status is Futue, but time is in the past we better publish the post
if ($tmp_post['post_status'] === 'future' )
{
$tmp_post['edit_date'] = true;
$tmp_post['post_status'] = 'publish';
}
}
} // end check date
} // end post_date
return $tmp_post;
}
add_filter('frontier_post_pre_update', 'fp_save_my_fields',10,3);
// ** end save additionl fields **
Comments
Frontier Post – Add fields — No Comments
HTML tags allowed in your comment: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>